Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Draft of tcl_ref module (Tcl/Tk programming reference)

  • Loading branch information...
commit 3e53284fbc8b31271544d48203671abcb7602e5e 1 parent 60bc96c
@anoved authored
View
14 tcl_ref/README.md
@@ -0,0 +1,14 @@
+# Tcl/Tk 8.5 Manual Fathead #
+
+Programming reference for Tcl/Tk 8.5. Based on <http://www.tcl.tk/man/tcl8.5/>.
+
+Presently ignores the `namespace`, `details`, `type`, and `lang` fields described in the
+programming data file format section of the fathead readme. Provides only the first
+sentence of the `description` given for each command in the manual; this tends to be
+just right to confirm or suggest what the command is for, although the whole first
+paragraph would provide more `details`. The `synopsis` may contain multiple lines,
+separated by `<br />`.
+
+Some pages in the manual do not document specific commands. Most such pages are omitted.
+
+Parsing is accomplished with gnarly and not at all fragile regular expressions. Cowabunga.
View
61 tcl_ref/fetch.sh
@@ -0,0 +1,61 @@
+#!/bin/bash
+
+#
+# Retrieves Tcl/Tk 8.5 Manual pages from <http://www.tcl.tk/man/tcl8.5/>.
+# Rather than scrape the contents pages for links to download, we list specific commands.
+# Some manual pages do not document specific commands and have been omitted below.
+#
+
+#
+# Tcl/Tk Applications
+# <http://www.tcl.tk/man/tcl8.5/UserCmd/contents.htm>
+#
+dir="UserCmd"
+mkdir -p download/${dir}
+for cmd in tclsh wish
+do
+ curl "http://www.tcl.tk/man/tcl8.5/${dir}/${cmd}.htm" \
+ --output "download/${dir}/${cmd}.htm"
+done
+
+#
+# Tcl Commands
+# <http://www.tcl.tk/man/tcl8.5/TclCmd/contents.htm>
+#
+dir="TclCmd"
+mkdir -p download/${dir}
+for cmd in after append apply array bgerror binary break catch cd chan clock close \
+ concat continue dde dict encoding eof error eval exec exit expr fblocked \
+ fconfigure fcopy file fileevent flush for foreach format gets glob \
+ global history http if incr info interp join lappend lassign lindex \
+ linsert list llength load lrange lrepeat lreplace lreverse lsearch lset lsort \
+ mathfunc mathop memory msgcat namespace open package packagens pid pkgMkIndex \
+ platform platform_shell proc puts pwd read refchan regexp registry regsub rename \
+ return safe scan seek set socket source split string subst switch tcltest \
+ tclvars tell time tm trace unknown unload unset update uplevel upvar variable \
+ vwait while
+do
+ curl "http://www.tcl.tk/man/tcl8.5/${dir}/${cmd}.htm" \
+ --output "download/${dir}/${cmd}.htm"
+done
+
+#
+# Tk Commands
+# <http://www.tcl.tk/man/tcl8.5/TkCmd/contents.htm>
+#
+dir="TkCmd"
+mkdir -p download/${dir}
+for cmd in bell bind bindtags bitmap button canvas checkbutton chooseColor \
+ chooseDirectory clipboard colors console cursors destroy dialog entry event \
+ focus focusNext font frame getOpenFile grab grid image keysyms label labelframe \
+ listbox loadTk lower menu menubutton message messageBox option optionMenu \
+ options pack palette panedwindow photo place popup radiobutton raise scale \
+ scrollbar selection send spinbox text tk tkerror tkvars tkwait toplevel \
+ ttk_button ttk_checkbutton ttk_combobox ttk_entry ttk_frame ttk_image \
+ ttk_label ttk_labelframe ttk_menubutton ttk_notebook ttk_panedwindow \
+ ttk_progressbar ttk_radiobutton ttk_scale ttk_scrollbar ttk_separator \
+ ttk_sizegrip ttk_spinbox ttk_style ttk_treeview ttk_vsapi winfo wm
+do
+ curl "http://www.tcl.tk/man/tcl8.5/${dir}/${cmd}.htm" \
+ --output "download/${dir}/${cmd}.htm"
+done
View
9 tcl_ref/meta.txt
@@ -0,0 +1,9 @@
+Name: Tcl/Tk 8.5 Manual
+
+Domain: www.tcl.tk
+
+Type: Tcl
+
+MediaWiki: 0
+
+Keywords: tcl
View
5 tcl_ref/parse.sh
@@ -0,0 +1,5 @@
+#!/bin/bash
+
+tclsh parse.tcl "http://www.tcl.tk/man/tcl8.5/UserCmd/" download/UserCmd/*.htm > output.txt
+tclsh parse.tcl "http://www.tcl.tk/man/tcl8.5/TclCmd/" download/TclCmd/*.htm >> output.txt
+tclsh parse.tcl "http://www.tcl.tk/man/tcl8.5/TkCmd/" download/TkCmd/*.htm >> output.txt
View
86 tcl_ref/parse.tcl
@@ -0,0 +1,86 @@
+#!/usr/bin/tclsh
+
+package require Tcl 8.5
+
+if {[llength $argv] < 2} {
+ puts stderr "Usage: parse.tcl URL_PREFIX FILE1 ?FILE2 FILE3 ...?"
+ exit 1
+}
+
+set url_prefix [lindex $argv 0]
+
+foreach arg [lrange $argv 1 end] {
+
+ #
+ # Load the file. Report and skip if we can't.
+ #
+ if {[catch {open $arg} f]} {
+ puts stderr $f
+ continue
+ }
+ set t [read $f]
+ close $f
+
+ #
+ # Get the page name.
+ #
+ # For most commands, the name is followed by a dash (" - ") and a terse description.
+ # In some cases, however, multiple commands share a page and appear listed with commas.
+ # In such cases, we ignore all but the first (otherwise, hard to find appropriate desc.)
+ #
+ # Regexp: find the NAME header; take everything up to a "," or " - " from the next line.
+ #
+ set name {}
+ regexp {<H3><A NAME="M\d+">NAME</A></H3>\n((?:(?! - )[^,])*?)} $t match name
+
+ #
+ # Get the synopsis.
+ #
+ # Some pages don't have synopses. Most of those do not document specific commands, and
+ # should be omitted from fetch.sh. Some pages have multi-line synopses; some multi-line
+ # synopses are appropriate, since they show different forms of the same command. Some
+ # multi-line synopses are inappropriate, since they document different commands. At
+ # present, we show all multi-line synopses in their entirety, separated with <br />.
+ # Most pages with inappropriate multi-line synopses can probably be omitted.
+ #
+ # Regexp: find the SYNOPSIS header; starting at next line, take everything up to the next header.
+ # Tags are stripped (most would be helpful to keep). Newlines are replaced with <br />.
+ #
+ set synopsis {}
+ regexp {<H3><A NAME="M\d+">SYNOPSIS</A></H3>\n((?:(?!<H3>).)*)\n} $t match synopsis
+ set synopsis [regsub -all {<.*?>} $synopsis {}]
+ set synopsis [regsub -all {\n} $synopsis {<br />}]
+
+ #
+ # Get the description.
+ #
+ # A handful of pages have an INTRODUCTION instead of a DESCRIPTION. Most of these do
+ # not document specific commands and have been omitted, but there are some exceptions.
+ #
+ # Regexp: find the DESCRIPTION header; starting at next line, take everything up to ". "
+ # Tags are stripped (some, referencing synopsis, would be helpful to keep). Newlines
+ # are replaced with <br />.
+ #
+ set desc {}
+ regexp {<H3><A NAME="M\d+">DESCRIPTION</A></H3>\n((?:(?!\.\s).)*?\.)\s} $t match desc
+ set desc [regsub -all {<.*?>} $desc {}]
+ set desc [regsub -all {\n} $desc { }]
+
+ #
+ # Assemble the URL.
+ #
+ set url [format "%s%s" $url_prefix [file tail $arg]]
+
+ #
+ # Ignored fields. (What is the difference between description and details?)
+ #
+ set namespace ""
+ set details ""
+ set type ""
+ set lang ""
+
+ #
+ # Output this record.
+ #
+ puts [format "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s" $name $namespace $url $desc $synopsis $details $type $lang]
+}
View
19 tcl_ref/queries.txt
@@ -0,0 +1,19 @@
+#
+# Query:
+#
+# tcl split
+#
+# Expected Result:
+#
+# split (Tcl)
+#
+# split string ?splitChars?
+#
+# Returns a list created by splitting string at each character that is the in the splitChars argument.
+#
+# More at Tcl/Tk 8.5 Manual
+# <http://www.tcl.tk/man/tcl8.5/TclCmd/split.htm>
+#
+# (The example is based on the "perl split" example given in zeroclickinfo-fathead/README.md)
+#
+tcl split
Please sign in to comment.
Something went wrong with that request. Please try again.