os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/tools/man2html1.tcl
Update contrib.
3 # This file defines procedures that are used during the first pass of the
4 # man page to html conversion process. It is sourced by h.tcl.
6 # Copyright (c) 1996 by Sun Microsystems, Inc.
8 # SCCS: @(#) man2html1.tcl 1.2 96/03/21 10:48:29
11 # Global variables used by these scripts:
13 # state - state variable that controls action of text proc.
15 # curFile - tail of current man page.
17 # file - file pointer; for both xref.tcl and contents.html
19 # NAME_file - array indexed by NAME and containing file names used
22 # KEY_file - array indexed by KEYWORD and containing file names used
25 # lib - contains package name. Used to label section in contents.html
27 # inDT - in dictionary term.
33 # This procedure adds entries to the hypertext arrays NAME_file
36 # DT: might do this: if first word of $dt matches $name and [llength $name==1]
37 # and [llength $dt > 1], then add to NAME_file.
40 # string - Text to index.
44 global state curFile NAME_file KEY_file inDT
48 foreach i [split $string ","] {
49 lappend NAME_file([string trim $i]) $curFile
53 foreach i [split $string ","] {
54 lappend KEY_file([string trim $i]) $curFile
61 puts stderr "text: unknown state: $state"
69 # This procedure is invoked to process macro invocations that start
70 # with "." (instead of ').
73 # name - The name of the macro (without the ".").
74 # args - Any additional arguments to the macro.
76 proc macro {name args} {
83 if {$state == "INIT" } {
87 DESCRIPTION {set state DT}
88 INTRODUCTION {set state DT}
89 KEYWORDS {set state KEY}
90 default {set state OFF}
102 if {[llength $args] != 5} {
103 set args [join $args " "]
104 puts stderr "Bad .TH macro: .$name $args"
106 set lib [lindex $args 3] ;# Tcl or Tk
115 # This procedure is invoked to handle dash characters ("\-" in
116 # troff). It only function in pass1 is to terminate the NAME state.
123 if {$state == "NAME"} {
132 # This procedure is invoked to handle newlines in the troff input.
133 # It's only purpose is to terminate a DT (dictionary term).
146 # initGlobals, tab, font, char, macro2 --
148 # These procedures do nothing during the first pass.
153 proc initGlobals {} {}
157 proc macro2 {name args} {}
162 # Writes an ls like list to a file. Searches NAME_file for entries
163 # that match the input pattern.
166 # file - Output file pointer.
167 # pattern - glob style match pattern
169 proc doListing {file pattern} {
173 foreach name [lsort [array names NAME_file]] {
174 set ref $NAME_file($name)
175 if [string match $pattern $ref] {
177 if {[string length $name] > $max_len} {
178 set max_len [string length $name]
182 if [catch {llength $type} ] {
183 puts stderr " doListing: no names matched pattern ($pattern)"
187 set ncols [expr 90/$max_len]
188 set nrows [expr int( ceil( [llength $type] / $ncols. ) ) ]
190 # ? max_len ncols nrows
194 lappend row([expr $index % $nrows]) $f
198 puts -nonewline $file "<PRE>"
199 for {set i 0} {$i<$nrows} {incr i} {
200 foreach name $row($i) {
201 set str [format "%-*s" $max_len $name]
202 regsub $name $str "<A HREF=\"$NAME_file($name).html\">$name</A>" str
203 puts -nonewline $file $str
213 # Generates a HTML contents file using the NAME_file array
214 # as its input database.
217 # file - name of the contents file.
218 # packageName - string used in the title and sub-heads of the HTML page. Normally
219 # name of the package without version numbers.
221 proc doContents {file packageName} {
224 set file [open $file w]
226 puts $file "<HTML><HEAD><TITLE>$packageName Manual</TITLE></HEAD><BODY>"
227 puts $file "<H3>$packageName</H3>"
228 doListing $file "*.1"
230 puts $file "<HR><H3>$packageName Commands</H3>"
231 doListing $file "*.n"
233 puts $file "<HR><H3>$packageName Library</H3>"
234 doListing $file "*.3"
237 puts $file "</BODY></HTML>"
246 # This is the toplevel procedure that searches a man page
247 # for hypertext links. It builds a data base consisting of
248 # two arrays: NAME_file and KEY file. It runs the man2tcl
249 # program to turn the man page into a script, then it evals
253 # fileName - Name of the file to scan.
257 set curFile [file tail $fileName]
259 puts " Pass 1 -- $fileName"
261 if [catch {eval [exec man2tcl [glob $fileName]]} msg] {