2 # The next line is executed by /bin/sh, but not tcl \
3 exec tclsh8.2 "$0" ${1+"$@"}
5 package require Tcl 8.2
7 # Convert Ousterhout format man pages into highly crosslinked
10 # Along the way detect many unmatched font changes and other odd
13 # Note well, this program is a hack rather than a piece of software
14 # engineering. In that sense it's probably a good example of things
15 # that a scripting language, like Tcl, can do well. It is offered as
16 # an example of how someone might convert a specific set of man pages
17 # into hypertext, not as a general solution to the problem. If you
18 # try to use this, you'll be very much on your own.
20 # Copyright (c) 1995-1997 Roger E. Critchlow Jr
22 # The authors hereby grant permission to use, copy, modify, distribute,
23 # and license this software and its documentation for any purpose, provided
24 # that existing copyright notices are retained in all copies and that this
25 # notice is included verbatim in any distributions. No written agreement,
26 # license, or royalty fee is required for any of the authorized uses.
27 # Modifications to this software may be copyrighted by their authors
28 # and need not follow the licensing terms described here, provided that
29 # the new terms are clearly indicated on the first page of each file where
32 # IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY
33 # FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
34 # ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY
35 # DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE
36 # POSSIBILITY OF SUCH DAMAGE.
38 # THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES,
39 # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
40 # FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. THIS SOFTWARE
41 # IS PROVIDED ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE
42 # NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
46 # May 15, 1995 - initial release
47 # May 16, 1995 - added a back to home link to toplevel table of
49 # May 18, 1995 - broke toplevel table of contents into separate
50 # pages for each section, and broke long table of contents
51 # into a one page for each man page.
52 # Mar 10, 1996 - updated for tcl7.5b3/tk4.1b3
53 # Apr 14, 1996 - incorporated command line parsing from Tom Tromey,
54 # <tromey@creche.cygnus.com> -- thanks Tom.
55 # - updated for tcl7.5/tk4.1 final release.
56 # - converted to same copyright as the man pages.
57 # Sep 14, 1996 - made various modifications for tcl7.6b1/tk4.2b1
58 # Oct 18, 1996 - added tcl7.6/tk4.2 to the list of distributions.
59 # Oct 22, 1996 - major hacking on indentation code and elsewhere.
61 # May 28, 1997 - added tcl8.0b1/tk8.0b1 to the list of distributions
62 # - cleaned source for tclsh8.0 execution
63 # - renamed output files for windoze installation
64 # - added spaces to tables
65 # Oct 24, 1997 - moved from 8.0b1 to 8.0 release
70 proc parse_command_line {} {
73 # These variables determine where the man pages come from and where
74 # the converted pages go to.
75 global tcltkdir tkdir tcldir webdir
77 # Set defaults based on original code.
83 # Directory names for Tcl and Tk, in priority order.
84 set tclDirList {tcl8.4 tcl8.3 tcl8.2 tcl8.1 tcl8.0 tcl}
85 set tkDirList {tk8.4 tk8.3 tk8.2 tk8.1 tk8.0 tk}
87 # Handle arguments a la GNU:
93 foreach option $argv {
94 switch -glob -- $option {
96 puts "tcltk-man-html $Version"
101 puts "usage: tcltk-man-html \[OPTION\] ...\n"
102 puts " --help print this help, then exit"
103 puts " --version print version number, then exit"
104 puts " --srcdir=DIR find tcl and tk source below DIR"
105 puts " --htmldir=DIR put generated HTML in DIR"
110 # length of "--srcdir=" is 9.
111 set tcltkdir [string range $option 9 end]
115 # length of "--htmldir=" is 10
116 set webdir [string range $option 10 end]
120 puts stderr "tcltk-man-html: unrecognized option -- `$option'"
127 foreach dir $tclDirList {
128 if {[file isdirectory $tcltkdir/$dir]} then {
133 if {$tcldir == ""} then {
134 puts stderr "tcltk-man-html: couldn't find Tcl below $tcltkdir"
139 foreach dir $tkDirList {
140 if {[file isdirectory $tcltkdir/$dir]} then {
145 if {$tkdir == ""} then {
146 puts stderr "tcltk-man-html: couldn't find Tk below $tcltkdir"
150 # the title for the man pages overall
152 set overall_title "[capitalize $tcldir]/[capitalize $tkdir] Manual"
155 proc capitalize {string} {
156 return [string toupper $string 0]
162 set manual(report-level) 1
164 proc manerror {msg} {
168 if {[info exists manual(name)]} {
169 set name $manual(name)
171 if {[info exists manual(section)] && [string length $manual(section)]} {
172 puts stderr "$name: $manual(section): $msg"
174 puts stderr "$name: $msg"
178 proc manreport {level msg} {
180 if {$level < $manual(report-level)} {
194 return [string map [list \" {}] $arg]
197 proc parse-directive {line codename restname} {
198 upvar $codename code $restname rest
199 return [regexp {^(\.[.a-zA-Z0-9]*) *(.*)} $line all code rest]
202 proc process-text {text} {
205 set text [string map [list \
222 regsub -all {\\o'o\^'} $text {\ô} text; # o-circumflex in re_syntax.n
223 regsub -all {\\-\\\|\\-} $text -- text; # two hyphens
224 regsub -all -- {\\-\\\^\\-} $text -- text; # two hyphens
225 regsub -all {\\-} $text - text; # a hyphen
226 regsub -all "\\\\\n" $text "\\\\n" text; # backslashed newline
227 while {[string first "\\" $text] >= 0} {
229 if {[regsub {^([^\\]*)\\fC([^\\]*)\\fR(.*)$} $text \
230 {\1<TT>\2</TT>\3} text]} continue
232 if {[regsub {^([^\\]*)\\fB([^\\]*)\\fR(.*)$} $text \
233 {\1<B>\2</B>\3} text]} continue
235 if {[regsub {^([^\\]*)\\fB([^\\]*)\\fI(.*)$} $text \
236 {\1<B>\2</B>\\fI\3} text]} continue
238 if {[regsub {^([^\\]*)\\fI([^\\]*)\\fR(.*)$} $text \
239 {\1<I>\2</I>\3} text]} continue
241 if {[regsub {^([^\\]*)\\fI([^\\]*)\\fB(.*)$} $text \
242 {\1<I>\2</I>\\fB\3} text]} continue
244 if {[regsub {^([^\\]*)\\fB([^\\]*)\\fB(.*)$} $text \
246 || [regsub {^([^\\]*)\\fI([^\\]*)\\fI(.*)$} $text \
248 || [regsub {^([^\\]*)\\fR([^\\]*)\\fR(.*)$} $text \
249 {\1\\fR\2\3} ntext]} {
250 manerror "process-text: impotent font change: $text"
255 manerror "process-text: uncaught backslash: $text"
256 set text [string map [list "\\" "#92;"] $text]
261 ## pass 2 text input and matching
265 set manual(text-length) [llength $manual(text)]
266 set manual(text-pointer) 0
270 return [expr {$manual(text-pointer) < $manual(text-length)}]
275 set text [lindex $manual(text) $manual(text-pointer)]
276 incr manual(text-pointer)
279 manerror "read past end of text"
282 proc is-a-directive {line} {
283 return [string match .* $line]
285 proc split-directive {line opname restname} {
286 upvar $opname op $restname rest
287 set op [string range $line 0 2]
288 set rest [string trim [string range $line 3 end]]
290 proc next-op-is {op restname} {
294 set text [lindex $manual(text) $manual(text-pointer)]
295 if {[string equal -length 3 $text $op]} {
296 set rest [string range $text 4 end]
297 incr manual(text-pointer)
303 proc backup-text {n} {
305 if {$manual(text-pointer)-$n >= 0} {
306 incr manual(text-pointer) -$n
309 proc match-text args {
311 set nargs [llength $args]
312 if {$manual(text-pointer) + $nargs > $manual(text-length)} {
321 set arg [string trim $arg]
322 set targ [string trim [lindex $manual(text) $manual(text-pointer)]]
323 if {[string equal $arg $targ]} {
325 incr manual(text-pointer)
328 if {[regexp {^@(\w+)$} $arg all name]} {
332 incr manual(text-pointer)
335 if {[regexp -nocase {^(\.[A-Z][A-Z])@(\w+)$} $arg all op name]\
336 && [string equal $op [lindex $targ 0]]} {
338 set var [lrange $targ 1 end]
340 incr manual(text-pointer)
348 proc expand-next-text {n} {
350 return [join [lrange $manual(text) $manual(text-pointer) \
351 [expr {$manual(text-pointer)+$n-1}]] \n\n]
356 proc man-puts {text} {
358 lappend manual(output-$manual(wing-file)-$manual(name)) $text
362 ## build hypertext links to tables of contents
364 proc long-toc {text} {
366 set here M[incr manual(section-toc-n)]
367 set there L[incr manual(long-toc-n)]
368 lappend manual(section-toc) \
369 "<DD><A HREF=\"$manual(name).htm#$here\" NAME=\"$there\">$text</A>"
370 return "<A NAME=\"$here\">$text</A>"
372 proc option-toc {name class switch} {
374 if {[string equal $manual(section) "WIDGET-SPECIFIC OPTIONS"]} {
375 # link the defined option into the long table of contents
376 set link [long-toc "$switch, $name, $class"]
377 regsub -- "$switch, $name, $class" $link "$switch" link
379 } elseif {[string equal $manual(name):$manual(section) \
380 "options:DESCRIPTION"]} {
381 # link the defined standard option to the long table of
382 # contents and make a target for the standard option references
383 # from other man pages.
384 set first [lindex $switch 0]
386 set there L[incr manual(long-toc-n)]
387 set manual(standard-option-$first) "<A HREF=\"$manual(name).htm#$here\">$switch, $name, $class</A>"
388 lappend manual(section-toc) "<DD><A HREF=\"$manual(name).htm#$here\" NAME=\"$there\">$switch, $name, $class</A>"
389 return "<A NAME=\"$here\">$switch</A>"
391 error "option-toc in $manual(name) section $manual(section)"
394 proc std-option-toc {name} {
396 if {[info exists manual(standard-option-$name)]} {
397 lappend manual(section-toc) <DD>$manual(standard-option-$name)
398 return $manual(standard-option-$name)
400 set here M[incr manual(section-toc-n)]
401 set there L[incr manual(long-toc-n)]
403 lappend manual(section-toc) "<DD><A HREF=\"options.htm#$other\">$name</A>"
404 return "<A HREF=\"options.htm#$other\">$name</A>"
407 ## process the widget option section
408 ## in widget and options man pages
410 proc output-widget-options {rest} {
413 lappend manual(section-toc) <DL>
416 while {[next-op-is .OP rest]} {
417 switch -exact [llength $rest] {
418 3 { foreach {switch name class} $rest { break } }
420 set switch [lrange $rest 0 2]
421 set name [lindex $rest 3]
422 set class [lindex $rest 4]
425 fatal "bad .OP $rest"
428 if {![regexp {^(<.>)([-\w ]+)(</.>)$} $switch all oswitch switch cswitch]} {
429 if {![regexp {^(<.>)([-\w ]+) or ([-\w ]+)(</.>)$} $switch all oswitch switch1 switch2 cswitch]} {
430 error "not Switch: $switch"
432 set switch "$switch1$cswitch or $oswitch$switch2"
435 if {![regexp {^(<.>)([\w]*)(</.>)$} $name all oname name cname]} {
436 error "not Name: $name"
438 if {![regexp {^(<.>)([\w]*)(</.>)$} $class all oclass class cclass]} {
439 error "not Class: $class"
441 man-puts "$para<DT>Command-Line Name: $oswitch[option-toc $name $class $switch]$cswitch"
442 man-puts "<DT>Database Name: $oname$name$cname"
443 man-puts "<DT>Database Class: $oclass$class$cclass"
444 man-puts <DD>[next-text]
448 lappend manual(section-toc) </DL>
454 proc output-RS-list {} {
456 if {[next-op-is .IP rest]} {
457 output-IP-list .RS .IP $rest
458 if {[match-text .RE .sp .RS @rest .IP @rest2]} {
460 output-IP-list .RS .IP $rest2
462 if {[match-text .RE .sp .RS @rest .RE]} {
466 if {[next-op-is .RE rest]} {
471 while {[more-text]} {
473 if {[is-a-directive $line]} {
474 split-directive $line code rest
475 switch -exact $code {
480 manerror "unbalanced .RS at section end"
485 output-directive $line
496 ## process .IP lists which may be plain indents,
497 ## numeric lists, or definition lists
499 proc output-IP-list {context code rest} {
501 if {![string length $rest]} {
502 # blank label, plain indent, no contents entry
504 while {[more-text]} {
506 if {[is-a-directive $line]} {
507 split-directive $line code rest
508 if {[string equal $code ".IP"] && [string equal $rest {}]} {
512 if {[lsearch {.br .DS .RS} $code] >= 0} {
513 output-directive $line
524 # labelled list, make contents
525 if {[string compare $context ".SH"]} {
529 lappend manual(section-toc) <DL>
532 while {[more-text]} {
534 if {[is-a-directive $line]} {
535 split-directive $line code rest
536 switch -exact $code {
539 output-IP-list .IP $code $rest
542 if {[string equal $manual(section) "ARGUMENTS"] || \
543 [regexp {^\[\d+\]$} $rest]} {
544 man-puts "<P><DT>$rest<DD>"
546 man-puts "<P><DT>[long-toc $rest]<DD>"
548 if {[string equal $manual(name):$manual(section) \
549 "selection:DESCRIPTION"]} {
550 if {[match-text .RE @rest .RS .RS]} {
551 man-puts <DT>[long-toc $rest]<DD>
559 output-directive $line
562 if {[match-text .RS]} {
563 output-directive $line
565 } elseif {[match-text .CS]} {
568 } elseif {[match-text .PP]} {
571 } elseif {[match-text .DS]} {
575 output-directive $line
579 if {[match-text @rest1 .br @rest2 .RS]} {
580 # yet another nroff kludge as above
581 man-puts "<P><DT>[long-toc $rest1]"
582 man-puts "<DT>[long-toc $rest2]<DD>"
584 } elseif {[match-text @rest .RE]} {
585 # gad, this is getting ridiculous
587 man-puts "</DL><P>$rest<DL>"
594 } elseif {$accept_RE} {
595 output-directive $line
618 lappend manual(section-toc) </DL>
620 manerror "missing .RE in output-IP-list"
625 ## handle the NAME section lines
626 ## there's only one line in the NAME section,
627 ## consisting of a comma separated list of names,
628 ## followed by a hyphen and a short description.
630 proc output-name {line} {
632 # split name line into pieces
633 regexp {^([^-]+) - (.*)$} $line all head tail
634 # output line to manual page untouched
636 # output line to long table of contents
637 lappend manual(section-toc) <DL><DD>$line</DL>
638 # separate out the names for future reference
639 foreach name [split $head ,] {
640 set name [string trim $name]
641 if {[llength $name] > 1} {
642 manerror "name has a space: {$name}\nfrom: $line"
644 lappend manual(wing-toc) $name
645 lappend manual(name-$name) $manual(wing-file)/$manual(name)
649 ## build a cross-reference link if appropriate
651 proc cross-reference {ref} {
653 if {[string match Tcl_* $ref]} {
655 } elseif {[string match Tk_* $ref]} {
657 } elseif {[string equal $ref "Tcl"]} {
660 set lref [string tolower $ref]
663 ## nothing to reference
665 if {![info exists manual(name-$lref)]} {
666 foreach name {array file history info interp string trace
667 after clipboard grab image option pack place selection tk tkwait update winfo wm} {
668 if {[regexp "^$name \[a-z0-9]*\$" $lref] && \
669 [string compare $manual(tail) "$name.n"]} {
670 return "<A HREF=\"../$manual(name-$name).htm\">$ref</A>"
673 if {[lsearch {stdin stdout stderr end} $lref] >= 0} {
674 # no good place to send these
681 ## would be a self reference
683 foreach name $manual(name-$lref) {
684 if {[lsearch $name $manual(wing-file)/$manual(name)] >= 0} {
689 ## multiple choices for reference
691 if {[llength $manual(name-$lref)] > 1} {
692 set tcl_i [lsearch -glob $manual(name-$lref) *TclCmd*]
693 set tcl_ref [lindex $manual(name-$lref) $tcl_i]
694 set tk_i [lsearch -glob $manual(name-$lref) *TkCmd*]
695 set tk_ref [lindex $manual(name-$lref) $tk_i]
696 if {$tcl_i >= 0 && "$manual(wing-file)" == {TclCmd} \
697 || "$manual(wing-file)" == {TclLib}} {
698 return "<A HREF=\"../$tcl_ref.htm\">$ref</A>"
700 if {$tk_i >= 0 && "$manual(wing-file)" == {TkCmd} \
701 || "$manual(wing-file)" == {TkLib}} {
702 return "<A HREF=\"../$tk_ref.htm\">$ref</A>"
704 if {"$lref" == {exit} && "$manual(tail)" == {tclsh.1} && $tcl_i >= 0} {
705 return "<A HREF=\"../$tcl_ref.htm\">$ref</A>"
707 puts stderr "multiple cross reference to $ref in $manual(name-$lref) from $manual(wing-file)/$manual(tail)"
711 ## exceptions, sigh, to the rule
713 switch $manual(tail) {
715 if {$lref == {focus}} {
717 set clue [string first command $tail]
718 if {$clue < 0 || $clue > 5} {
722 if {[lsearch {bitmap image text} $lref] >= 0} {
728 if {[lsearch {image} $lref] >= 0} {
733 if {[lsearch {checkbutton radiobutton} $lref] >= 0} {
738 if {[lsearch {bitmap image set} $lref] >= 0} {
743 if {[lsearch {string} $lref] >= 0} {
748 if {[lsearch {text} $lref] >= 0} {
753 if {[lsearch {exec} $lref] >= 0} {
758 if {[lsearch {error continue break} $lref] >= 0} {
763 if {[lsearch {set} $lref] >= 0} {
769 ## return the cross reference
771 return "<A HREF=\"../$manual(name-$lref).htm\">$ref</A>"
774 ## reference generation errors
776 proc reference-error {msg text} {
778 puts stderr "$manual(tail): $msg: {$text}"
782 ## insert as many cross references into this text string as are appropriate
784 proc insert-cross-references {text} {
787 ## we identify cross references by:
789 ## <B>emboldening</B>
792 ## [a-zA-Z0-9]+ manual entry
793 ## and we avoid messing with already anchored text
796 ## find where each item lives
798 array set offset [list \
799 anchor [string first {<A } $text] \
800 end-anchor [string first {</A>} $text] \
801 quote [string first {``} $text] \
802 end-quote [string first {''} $text] \
803 bold [string first {<B>} $text] \
804 end-bold [string first {</B>} $text] \
805 tcl [string first {Tcl_} $text] \
806 tk [string first {Tk_} $text] \
807 Tcl1 [string first {Tcl manual entry} $text] \
808 Tcl2 [string first {Tcl overview manual entry} $text] \
813 foreach name [array names offset] {
814 if {$offset($name) >= 0} {
815 set invert($offset($name)) $name
816 lappend offsets $offset($name)
820 ## if nothing, then we're done.
822 if {![info exists offsets]} {
828 set offsets [lsort -integer $offsets]
830 ## see which we want to use
832 switch -exact $invert([lindex $offsets 0]) {
834 if {$offset(end-anchor) < 0} {
835 return [reference-error {Missing end anchor} $text]
837 set head [string range $text 0 $offset(end-anchor)]
838 set tail [string range $text [expr {$offset(end-anchor)+1}] end]
839 return $head[insert-cross-references $tail]
842 if {$offset(end-quote) < 0} {
843 return [reference-error "Missing end quote" $text]
845 if {$invert([lindex $offsets 1]) == "tk"} {
846 set offsets [lreplace $offsets 1 1]
848 if {$invert([lindex $offsets 1]) == "tcl"} {
849 set offsets [lreplace $offsets 1 1]
851 switch -exact $invert([lindex $offsets 1]) {
853 set head [string range $text 0 [expr {$offset(quote)-1}]]
854 set body [string range $text [expr {$offset(quote)+2}] \
855 [expr {$offset(end-quote)-1}]]
856 set tail [string range $text \
857 [expr {$offset(end-quote)+2}] end]
858 return "$head``[cross-reference $body]''[insert-cross-references $tail]"
862 set head [string range $text \
863 0 [expr {$offset(end-quote)+1}]]
864 set tail [string range $text \
865 [expr {$offset(end-quote)+2}] end]
866 return "$head[insert-cross-references $tail]"
869 return [reference-error "Uncaught quote case" $text]
872 if {$offset(end-bold) < 0} { return $text }
873 if {$invert([lindex $offsets 1]) == "tk"} {
874 set offsets [lreplace $offsets 1 1]
876 if {$invert([lindex $offsets 1]) == "tcl"} {
877 set offsets [lreplace $offsets 1 1]
879 switch -exact $invert([lindex $offsets 1]) {
881 set head [string range $text 0 [expr {$offset(bold)-1}]]
882 set body [string range $text [expr {$offset(bold)+3}] \
883 [expr {$offset(end-bold)-1}]]
884 set tail [string range $text \
885 [expr {$offset(end-bold)+4}] end]
886 return "$head<B>[cross-reference $body]</B>[insert-cross-references $tail]"
889 set head [string range $text \
890 0 [expr {$offset(end-bold)+3}]]
891 set tail [string range $text \
892 [expr {$offset(end-bold)+4}] end]
893 return "$head[insert-cross-references $tail]"
896 return [reference-error "Uncaught bold case" $text]
899 set head [string range $text 0 [expr {$offset(tk)-1}]]
900 set tail [string range $text $offset(tk) end]
901 if {![regexp {^(Tk_\w+)(.*)$} $tail all body tail]} {
902 return [reference-error "Tk regexp failed" $text]
904 return $head[cross-reference $body][insert-cross-references $tail]
907 set head [string range $text 0 [expr {$offset(tcl)-1}]]
908 set tail [string range $text $offset(tcl) end]
909 if {![regexp {^(Tcl_\w+)(.*)$} $tail all body tail]} {
910 return [reference-error {Tcl regexp failed} $text]
912 return $head[cross-reference $body][insert-cross-references $tail]
916 set off [lindex $offsets 0]
917 set head [string range $text 0 [expr {$off-1}]]
919 set tail [string range $text [expr {$off+3}] end]
920 return $head[cross-reference $body][insert-cross-references $tail]
925 return [reference-error "Out of place $invert([lindex $offsets 0])" $text]
930 ## process formatting directives
932 proc output-directive {line} {
934 # process format directive
935 split-directive $line code rest
936 switch -exact $code {
942 # drain any open lists
943 # announce the subject
944 set manual(section) $rest
945 # start our own stack of stuff
946 set manual($manual(name)-$manual(section)) {}
947 lappend manual(has-$manual(section)) $manual(name)
948 man-puts "<H3>[long-toc $manual(section)]</H3>"
949 # some sections can simply free wheel their way through the text
950 # some sections can be processed in their own loops
951 switch -exact $manual(section) {
953 if {[lsearch {CrtImgType.3 CrtItemType.3 CrtPhImgFmt.3} $manual(tail)] >= 0} {
954 # these manual pages have two NAME sections
955 if {[info exists manual($manual(tail)-NAME)]} {
958 set manual($manual(tail)-NAME) 1
963 if {[is-a-directive $line]} {
965 output-name [join $names { }]
968 lappend names [string trim $line]
973 lappend manual(section-toc) <DL>
975 if {[next-op-is .nf rest]
976 || [next-op-is .br rest]
977 || [next-op-is .fi rest]} {
980 if {[next-op-is .SH rest]
981 || [next-op-is .BE rest]
982 || [next-op-is .SO rest]} {
986 if {[next-op-is .sp rest]} {
991 if {[is-a-directive $more]} {
992 manerror "in SYNOPSIS found $more"
996 foreach more [split $more \n] {
998 if {[lsearch {TclLib TkLib} $manual(wing-file)] < 0} {
999 lappend manual(section-toc) <DD>$more
1004 lappend manual(section-toc) </DL>
1008 while {[more-text]} {
1009 if {[next-op-is .SH rest]} {
1013 set more [next-text]
1014 if {[is-a-directive $more]} {
1020 foreach cr [split $more ,] {
1021 set cr [string trim $cr]
1022 if {![regexp {^<B>.*</B>$} $cr]} {
1025 if {[regexp {^<B>(.*)\([13n]\)</B>$} $cr all name]} {
1030 man-puts [join $nmore {, }]
1035 while {[more-text]} {
1036 if {[next-op-is .SH rest]} {
1040 set more [next-text]
1041 if {[is-a-directive $more]} {
1047 foreach key [split $more ,] {
1048 set key [string trim $key]
1049 lappend manual(keyword-$key) [list $manual(name) $manual(wing-file)/$manual(name).htm]
1050 set initial [string toupper [string index $key 0]]
1051 lappend keys "<A href=\"../Keywords/$initial.htm\#$key\">$key</A>"
1053 man-puts [join $keys {, }]
1058 if {[next-op-is .IP rest]} {
1059 output-IP-list .SH .IP $rest
1062 if {[next-op-is .PP rest]} {
1068 if {[match-text @stuff .SE]} {
1069 output-directive {.SH STANDARD OPTIONS}
1071 foreach line [split $stuff \n] {
1072 foreach option [split $line \t] {
1073 lappend opts $option
1077 lappend manual(section-toc) <DL>
1078 foreach option [lsort $opts] {
1079 man-puts "<DT><B>[std-option-toc $option]</B>"
1082 lappend manual(section-toc) </DL>
1084 manerror "unexpected .SO format:\n[expand-next-text 2]"
1088 output-widget-options $rest
1092 output-IP-list .IP .IP $rest
1103 manerror "unexpected .RE"
1111 manerror "unexpected .DE"
1115 if {[next-op-is .ta rest]} {
1118 if {[match-text @stuff .DE]} {
1119 man-puts <PRE>$stuff</PRE>
1120 } elseif {[match-text .fi @ul1 @ul2 .nf @stuff .DE]} {
1121 man-puts "<PRE>[lindex $ul1 1][lindex $ul2 1]\n$stuff</PRE>"
1123 manerror "unexpected .DS format:\n[expand-next-text 2]"
1128 if {[next-op-is .ta rest]} {
1131 if {[match-text @stuff .CE]} {
1132 man-puts <PRE>$stuff</PRE>
1134 manerror "unexpected .CS format:\n[expand-next-text 2]"
1139 manerror "unexpected .CE"
1146 # these are tab stop settings for short tables
1147 switch -exact $manual(name):$manual(section) {
1149 {bind:EVENT TYPES} -
1150 {bind:BINDING SCRIPTS AND SUBSTITUTIONS} -
1152 {expr:MATH FUNCTIONS} -
1153 {history:DESCRIPTION} -
1154 {history:HISTORY REVISION} -
1155 {switch:DESCRIPTION} -
1156 {upvar:DESCRIPTION} {
1160 manerror "ignoring $line"
1165 if {[match-text @more .fi]} {
1166 foreach more [split $more \n] {
1169 } elseif {[match-text .RS @more .RE .fi]} {
1171 foreach more [split $more \n] {
1175 } elseif {[match-text .RS @more .RS @more2 .RE .RE .fi]} {
1177 foreach more [split $more \n] {
1181 foreach more2 [split $more2 \n] {
1185 } elseif {[match-text .RS @more .RS @more2 .RE @more3 .RE .fi]} {
1187 foreach more [split $more \n] {
1191 foreach more2 [split $more2 \n] {
1195 foreach more3 [split $more3 \n] {
1199 } elseif {[match-text .sp .RS @more .RS @more2 .sp .RE .RE .fi]} {
1200 man-puts <P><DL><DD>
1201 foreach more [split $more \n] {
1205 foreach more2 [split $more2 \n] {
1208 man-puts </DL></DL><P>
1209 } elseif {[match-text .RS .sp @more .sp .RE .fi]} {
1210 man-puts <P><DL><DD>
1211 foreach more [split $more \n] {
1216 manerror "ignoring $line"
1220 manerror "ignoring $line"
1226 manerror "ignoring $line"
1229 manerror "unrecognized format directive: $line"
1234 ## merge copyright listings
1236 proc merge-copyrights {l1 l2} {
1237 foreach copyright [concat $l1 $l2] {
1238 if {[regexp {^Copyright +\(c\) +(\d+) +(by +)?(\w.*)$} $copyright all date by who]} {
1239 lappend dates($who) $date
1242 if {[regexp {^Copyright +\(c\) +(\d+)-(\d+) +(by +)?(\w.*)$} $copyright all from to by who]} {
1243 for {set date $from} {$date <= $to} {incr date} {
1244 lappend dates($who) $date
1248 if {[regexp {^Copyright +\(c\) +(\d+), *(\d+) +(by +)?(\w.*)$} $copyright all date1 date2 by who]} {
1249 lappend dates($who) $date1 $date2
1252 puts "oops: $copyright"
1254 foreach who [array names dates] {
1255 set list [lsort $dates($who)]
1256 if {[llength $list] == 1 || [lindex $list 0] == [lrange $list end end]} {
1257 lappend merge "Copyright (c) [lindex $list 0] $who"
1259 lappend merge "Copyright (c) [lindex $list 0]-[lrange $list end end] $who"
1262 return [lsort $merge]
1265 proc makedirhier {dir} {
1266 if {![file isdirectory $dir] && \
1267 [catch {file mkdir $dir} error]} {
1268 return -code error "cannot create directory $dir: $error"
1273 ## foreach of the man directories specified by args
1274 ## convert manpages into hypertext in the directory
1275 ## specified by html.
1277 proc make-man-pages {html args} {
1278 global env manual overall_title
1280 set manual(short-toc-n) 1
1281 set manual(short-toc-fp) [open $html/contents.htm w]
1282 puts $manual(short-toc-fp) "<HTML><HEAD><TITLE>$overall_title</TITLE></HEAD>"
1283 puts $manual(short-toc-fp) "<BODY><HR><H3>$overall_title</H3><HR><DL>"
1284 set manual(merge-copyrights) {}
1286 set manual(wing-glob) [lindex $arg 0]
1287 set manual(wing-name) [lindex $arg 1]
1288 set manual(wing-file) [lindex $arg 2]
1289 set manual(wing-description) [lindex $arg 3]
1290 set manual(wing-copyrights) {}
1291 makedirhier $html/$manual(wing-file)
1292 set manual(wing-toc-fp) [open $html/$manual(wing-file)/contents.htm w]
1294 puts stderr "scanning section $manual(wing-name)"
1295 # put the entry for this section into the short table of contents
1296 puts $manual(short-toc-fp) "<DT><A HREF=\"$manual(wing-file)/contents.htm\">$manual(wing-name)</A><DD>$manual(wing-description)"
1297 # initialize the wing table of contents
1298 puts $manual(wing-toc-fp) "<HTML><HEAD><TITLE>$manual(wing-name) Manual</TITLE></HEAD>"
1299 puts $manual(wing-toc-fp) "<BODY><HR><H3>$manual(wing-name)</H3><HR>"
1300 # initialize the short table of contents for this section
1301 set manual(wing-toc) {}
1302 # initialize the man directory for this section
1303 makedirhier $html/$manual(wing-file)
1304 # initialize the long table of contents for this section
1305 set manual(long-toc-n) 1
1306 # get the manual pages for this section
1307 set manual(pages) [lsort [glob $manual(wing-glob)]]
1308 if {[lsearch -glob $manual(pages) */options.n] >= 0} {
1309 set n [lsearch $manual(pages) */options.n]
1310 set manual(pages) "[lindex $manual(pages) $n] [lreplace $manual(pages) $n $n]"
1312 # set manual(pages) [lrange $manual(pages) 0 5]
1313 foreach manual(page) $manual(pages) {
1315 puts stderr "scanning page $manual(page)"
1316 set manual(tail) [file tail $manual(page)]
1317 set manual(name) [file root $manual(tail)]
1318 set manual(section) {}
1319 if {[lsearch {case pack-old menubar} $manual(name)] >= 0} {
1321 manerror "discarding $manual(name)"
1324 set manual(infp) [open $manual(page)]
1326 set manual(partial-text) {}
1327 foreach p {.RS .DS .CS .SO} {
1330 set manual(stack) {}
1331 set manual(section) {}
1332 set manual(section-toc) {}
1333 set manual(section-toc-n) 1
1334 set manual(copyrights) {}
1335 lappend manual(all-pages) $manual(wing-file)/$manual(tail)
1336 manreport 100 $manual(name)
1337 while {[gets $manual(infp) line] >= 0} {
1339 if {[regexp {^[`'][/\\]} $line]} {
1340 if {[regexp {Copyright \(c\).*$} $line copyright]} {
1341 lappend manual(copyrights) $copyright
1346 if {"$line" == {'}} {
1350 if {[parse-directive $line code rest]} {
1351 switch -exact $code {
1352 .ad - .na - .so - .ne - .AS - .VE - .VS -
1358 if {"$manual(partial-text)" != {}} {
1359 lappend manual(text) [process-text $manual(partial-text)]
1360 set manual(partial-text) {}
1362 switch -exact $code {
1364 if {[llength $rest] == 0} {
1365 gets $manual(infp) rest
1367 lappend manual(text) ".SH [unquote $rest]"
1370 lappend manual(text) "$code [unquote $rest]"
1374 lappend manual(text) "$code [unquote $rest]"
1376 .BS - .BE - .br - .fi - .sp -
1378 if {"$rest" != {}} {
1379 manerror "unexpected argument: $line"
1381 lappend manual(text) $code
1384 lappend manual(text) [concat .IP [process-text "[lindex $rest 0] \\fB[lindex $rest 1]\\fR ([lindex $rest 2])"]]
1387 regexp {^(.*) +\d+$} $rest all rest
1388 lappend manual(text) ".IP [process-text [unquote [string trim $rest]]]"
1391 set next [gets $manual(infp)]
1392 if {"$next" != {'}} {
1393 lappend manual(text) ".IP [process-text $next]"
1397 lappend manual(text) [concat .OP [process-text \
1398 "\\fB[lindex $rest 0]\\fR \\fB[lindex $rest 1]\\fR \\fB[lindex $rest 2]\\fR"]]
1402 lappend manual(text) {.PP}
1406 lappend manual(text) $code
1410 lappend manual(text) $code
1414 lappend manual(text) $code
1418 lappend manual(text) $code
1422 lappend manual(text) $code
1426 lappend manual(text) $code
1430 lappend manual(text) $code
1434 lappend manual(text) $code
1437 while {[gets $manual(infp) line] >= 0} {
1438 if {[string match "..*" $line]} {
1444 error "found .. outside of .de"
1447 manerror "unrecognized format directive: $line"
1451 if {$manual(partial-text) == ""} {
1452 set manual(partial-text) $line
1454 append manual(partial-text) \n$line
1458 if {$manual(partial-text) != ""} {
1459 lappend manual(text) [process-text $manual(partial-text)]
1463 if {$manual(.RS) != 0} {
1464 if {$manual(name) != "selection"} {
1465 puts "unbalanced .RS .RE"
1468 if {$manual(.DS) != 0} {
1469 puts "unbalanced .DS .DE"
1471 if {$manual(.CS) != 0} {
1472 puts "unbalanced .CS .CE"
1474 if {$manual(.SO) != 0} {
1475 puts "unbalanced .SO .SE"
1479 if {[next-op-is .HS rest]} {
1480 set manual($manual(name)-title) \
1481 "[lrange $rest 1 end] [lindex $rest 0] manual page"
1482 while {[more-text]} {
1483 set line [next-text]
1484 if {[is-a-directive $line]} {
1485 output-directive $line
1491 foreach copyright $manual(copyrights) {
1492 man-puts "<A HREF=\"../copyright.htm\">Copyright</A> © [lrange $copyright 2 end]"
1494 man-puts "<A HREF=\"../copyright.htm\">Copyright</A> © 1995-1997 Roger E. Critchlow Jr.</PRE>"
1495 set manual(wing-copyrights) [merge-copyrights $manual(wing-copyrights) $manual(copyrights)]
1496 } elseif {[next-op-is .TH rest]} {
1497 set manual($manual(name)-title) "[lrange $rest 4 end] - [lindex $rest 0] manual page"
1498 while {[more-text]} {
1499 set line [next-text]
1500 if {[is-a-directive $line]} {
1501 output-directive $line
1507 foreach copyright $manual(copyrights) {
1508 man-puts "<A HREF=\"../copyright.htm\">Copyright</A> © [lrange $copyright 2 end]"
1510 man-puts "<A HREF=\"../copyright.htm\">Copyright</A> © 1995-1997 Roger E. Critchlow Jr.</PRE>"
1511 set manual(wing-copyrights) [merge-copyrights $manual(wing-copyrights) $manual(copyrights)]
1513 manerror "no .HS or .TH record found"
1516 # make the long table of contents for this page
1518 set manual(toc-$manual(wing-file)-$manual(name)) [concat <DL> $manual(section-toc) </DL><HR>]
1522 # make the wing table of contents for the section
1525 foreach name $manual(wing-toc) {
1526 if {[string length $name] > $width} {
1527 set width [string length $name]
1530 set perline [expr {120 / $width}]
1531 set nrows [expr {([llength $manual(wing-toc)]+$perline)/$perline}]
1534 foreach name [lsort $manual(wing-toc)] {
1535 set tail $manual(name-$name)
1536 if {[llength $tail] > 1} {
1537 manerror "$name is defined in more than one file: $tail"
1538 set tail [lindex $tail [expr {[llength $tail]-1}]]
1540 set tail [file tail $tail]
1541 append rows([expr {$n%$nrows}]) \
1542 "<td> <a href=\"$tail.htm\">$name</a>"
1545 puts $manual(wing-toc-fp) <table>
1546 foreach row [lsort -integer [array names rows]] {
1547 puts $manual(wing-toc-fp) <tr>$rows($row)</tr>
1549 puts $manual(wing-toc-fp) </table>
1552 # insert wing copyrights
1554 puts $manual(wing-toc-fp) "<HR><PRE>"
1555 foreach copyright $manual(wing-copyrights) {
1556 puts $manual(wing-toc-fp) "<A HREF=\"../copyright.htm\">Copyright</A> © [lrange $copyright 2 end]"
1558 puts $manual(wing-toc-fp) "<A HREF=\"../copyright.htm\">Copyright</A> © 1995-1997 Roger E. Critchlow Jr."
1559 puts $manual(wing-toc-fp) "</PRE></BODY></HTML>"
1560 close $manual(wing-toc-fp)
1561 set manual(merge-copyrights) [merge-copyrights $manual(merge-copyrights) $manual(wing-copyrights)]
1565 ## build the keyword index.
1567 proc strcasecmp {a b} { return [string compare -nocase $a $b] }
1568 set keys [lsort -command strcasecmp [array names manual keyword-*]]
1569 makedirhier $html/Keywords
1570 catch {eval file delete -- [glob $html/Keywords/*]}
1571 puts $manual(short-toc-fp) {<DT><A HREF="Keywords/contents.htm">Keywords</A><DD>The keywords from the Tcl/Tk man pages.}
1572 set keyfp [open $html/Keywords/contents.htm w]
1573 puts $keyfp "<HTML><HEAD><TITLE>Tcl/Tk Keywords</TITLE></HEAD>"
1574 puts $keyfp "<BODY><HR><H3>Tcl/Tk Keywords</H3><HR><H2>"
1575 foreach a {A B C D E F G H I J K L M N O P Q R S T U V W X Y Z} {
1576 puts $keyfp "<A HREF=\"$a.htm\">$a</A>"
1577 set afp [open $html/Keywords/$a.htm w]
1578 puts $afp "<HTML><HEAD><TITLE>Tcl/Tk Keywords - $a</TITLE></HEAD>"
1579 puts $afp "<BODY><HR><H3>Tcl/Tk Keywords - $a</H3><HR><H2>"
1580 foreach b {A B C D E F G H I J K L M N O P Q R S T U V W X Y Z} {
1581 puts $afp "<A HREF=\"$b.htm\">$b</A>"
1583 puts $afp "</H2><HR><DL>"
1585 if {[regexp -nocase -- "^keyword-$a" $k]} {
1586 set k [string range $k 8 end]
1587 puts $afp "<DT><A NAME=\"$k\">$k</A><DD>"
1589 foreach man $manual(keyword-$k) {
1590 set name [lindex $man 0]
1591 set file [lindex $man 1]
1592 lappend refs "<A HREF=\"../$file\">$name</A>"
1594 puts $afp [join $refs {, }]
1597 puts $afp "</DL><HR><PRE>"
1598 # insert merged copyrights
1599 foreach copyright $manual(merge-copyrights) {
1600 puts $afp "<A HREF=\"copyright.htm\">Copyright</A> © [lrange $copyright 2 end]"
1602 puts $afp "<A HREF=\"copyright.htm\">Copyright</A> © 1995-1997 Roger E. Critchlow Jr."
1603 puts $afp "</PRE></BODY></HTML>"
1606 puts $keyfp "</H2><HR><PRE>"
1608 # insert merged copyrights
1609 foreach copyright $manual(merge-copyrights) {
1610 puts $keyfp "<A HREF=\"copyright.htm\">Copyright</A> © [lrange $copyright 2 end]"
1612 puts $keyfp "<A HREF=\"copyright.htm\">Copyright</A> © 1995-1997 Roger E. Critchlow Jr."
1613 puts $keyfp </PRE><HR></BODY></HTML>
1617 ## finish off short table of contents
1619 puts $manual(short-toc-fp) {<DT><A HREF="http://www.elf.org">Source</A><DD>More information about these man pages.}
1620 puts $manual(short-toc-fp) "</DL><HR><PRE>"
1621 # insert merged copyrights
1622 foreach copyright $manual(merge-copyrights) {
1623 puts $manual(short-toc-fp) "<A HREF=\"copyright.htm\">Copyright</A> © [lrange $copyright 2 end]"
1625 puts $manual(short-toc-fp) "<A HREF=\"copyright.htm\">Copyright</A> © 1995-1997 Roger E. Critchlow Jr."
1626 puts $manual(short-toc-fp) "</PRE></BODY></HTML>"
1627 close $manual(short-toc-fp)
1632 unset manual(section)
1633 foreach path $manual(all-pages) {
1634 set manual(wing-file) [file dirname $path]
1635 set manual(tail) [file tail $path]
1636 set manual(name) [file root $manual(tail)]
1637 set text $manual(output-$manual(wing-file)-$manual(name))
1639 foreach item $text {
1640 incr ntext [llength [split $item \n]]
1643 set toc $manual(toc-$manual(wing-file)-$manual(name))
1646 incr ntoc [llength [split $item \n]]
1649 puts stderr "rescanning page $manual(name) $ntoc/$ntext"
1650 set manual(outfp) [open $html/$manual(wing-file)/$manual(name).htm w]
1651 puts $manual(outfp) "<HTML><HEAD><TITLE>$manual($manual(name)-title)</TITLE></HEAD><BODY>"
1652 if {($ntext > 60) && ($ntoc > 32) || [lsearch {
1653 Hash LinkVar SetVar TraceVar ConfigWidg CrtImgType CrtItemType
1654 CrtPhImgFmt DoOneEvent GetBitmap GetColor GetCursor GetDash
1655 GetJustify GetPixels GetVisual ParseArgv QueueEvent
1656 } $manual(tail)] >= 0} {
1658 puts $manual(outfp) $item
1661 foreach item $text {
1662 puts $manual(outfp) [insert-cross-references $item]
1664 puts $manual(outfp) </BODY></HTML>
1665 close $manual(outfp)
1670 set usercmddesc {The interpreters which implement Tcl and Tk.}
1671 set tclcmddesc {The commands which the <B>tclsh</B> interpreter implements.}
1672 set tkcmddesc {The additional commands which the <B>wish</B> interpreter implements.}
1673 set tcllibdesc {The C functions which a Tcl extended C program may use.}
1674 set tklibdesc {The additional C functions which a Tk extended C program may use.}
1680 make-man-pages $webdir \
1681 "$tcltkdir/{$tkdir,$tcldir}/doc/*.1 {Tcl/Tk Applications} UserCmd {$usercmddesc}" \
1682 "$tcltkdir/$tcldir/doc/*.n {Tcl Commands} TclCmd {$tclcmddesc}" \
1683 "$tcltkdir/$tkdir/doc/*.n {Tk Commands} TkCmd {$tkcmddesc}" \
1684 "$tcltkdir/$tcldir/doc/*.3 {Tcl Library} TclLib {$tcllibdesc}" \
1685 "$tcltkdir/$tkdir/doc/*.3 {Tk Library} TkLib {$tklibdesc}"
1687 puts $error\n$errorInfo