os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/tools/man2html2.tcl
First public contribution.
3 # This file defines procedures that are used during the second pass of the
4 # man page to html conversion process. It is sourced by man2html.tcl.
6 # Copyright (c) 1996 by Sun Microsystems, Inc.
8 # SCCS: @(#) man2html2.tcl 1.2 96/03/21 10:48:30
11 # Global variables used by these scripts:
13 # NAME_file - array indexed by NAME and containing file names used
16 # textState - state variable defining action of 'text' proc.
18 # nestStk - stack oriented list containing currently active
19 # HTML tags (UL, OL, DL). Local to 'nest' proc.
21 # inDT - set by 'TPmacro', cleared by 'newline'. Used to insert
22 # the <DT> tag while in a dictionary list <DL>.
24 # curFont - Name of special font that is currently in
25 # use. Null means the default paragraph font
28 # file - Where to output the generated HTML.
30 # fontStart - Array to map font names to starting sequences.
32 # fontEnd - Array to map font names to ending sequences.
34 # noFillCount - Non-zero means don't fill the next $noFillCount
35 # lines: force a line break at each newline. Zero
36 # means filling is enabled, so don't output line
37 # breaks for each newline.
39 # footer - info inserted at bottom of each page. Normally read
40 # from the xref.tcl file
44 # This procedure is invoked to set the initial values of all of the
45 # global variables, before processing a man page.
51 global file noFillCount textState
52 global fontStart fontEnd curFont inPRE charCnt
58 set fontStart(Code) "<B>"
59 set fontStart(Emphasis) "<I>"
60 set fontEnd(Code) "</B>"
61 set fontEnd(Emphasis) "</I>"
70 # Arranges for future text to use a special font, rather than
71 # the default paragraph font.
74 # font - Name of new font to use.
77 global curFont file fontStart
79 if {$curFont == $font} {
83 puts -nonewline $file $fontStart($font)
90 # Reverts to the default font for the paragraph type.
96 global curFont file fontEnd
99 puts -nonewline $file $fontEnd($curFont)
108 # This procedure adds text to the current paragraph. If this is
109 # the first text in the paragraph then header information for the
110 # paragraph is output before the text.
113 # string - Text to output in the paragraph.
116 global file textState inDT charCnt
118 set pos [string first "\t" $string]
120 text [string range $string 0 [expr $pos-1]]
122 text [string range $string [expr $pos+1] end]
125 incr charCnt [string length $string]
126 regsub -all {&} $string {\&} string
127 regsub -all {<} $string {\<} string
128 regsub -all {>} $string {\>} string
129 regsub -all {"} $string {\"} string
133 set string [insertRef $string]
138 foreach i [split $string] {
139 if ![regexp -nocase {^[a-z_]+} [string trim $i] i ] {
140 # puts "Warning: $i in SEE ALSO not found"
143 if ![catch {set ref $NAME_file($i)} ] {
144 regsub $i $string "<A HREF=\"$ref.html\">$i</A>" string
149 puts -nonewline $file "$string"
158 # string - Text to output in the paragraph.
160 proc insertRef string {
161 global NAME_file self
163 if ![catch {set ref $NAME_file([string trim $string])} ] {
164 if {"$ref.html" != $self} {
165 set string "<A HREF=\"${path}$ref.html\">$string</A>"
166 # puts "insertRef: $self $ref.html ---$string--"
176 # This procedure is invoked to process macro invocations that start
177 # with "." (instead of ').
180 # name - The name of the macro (without the ".").
181 # args - Any additional arguments to the macro.
183 proc macro {name args} {
186 if {[llength $args] != 3} {
187 puts stderr "Bad .AP macro: .$name [join $args " "]"
189 setTabs {1.25i 2.5i 3.75i}
192 text "[lindex $args 0] "
194 text "[lindex $args 1]"
196 text " ([lindex $args 2])"
199 AS {} ;# next page and previous page
206 global file noFillCount inPRE
207 puts $file </PRE></BLOCKQUOTE>
211 global file noFillCount inPRE
212 puts -nonewline $file <BLOCKQUOTE><PRE>
216 global file noFillCount inPRE
217 puts $file </PRE></BLOCKQUOTE>
222 global file noFillCount inPRE
223 puts -nonewline $file <BLOCKQUOTE><PRE>
224 set noFillCount 10000000
243 set noFillCount 1000000
246 global inDT file inPRE
247 if {[llength $args] != 3} {
248 puts stderr "Bad .OP macro: .$name [join $args " "]"
252 puts -nonewline $file <PRE>
254 text "Command-Line Name:"
257 set x [lindex $args 0]
258 regsub -all {\\-} $x - x
262 text "Database Name:"
265 text [lindex $args 1]
268 text "Database Class:"
271 text [lindex $args 2]
273 puts -nonewline $file </PRE>
274 set inDT "\n<DD>" ;# next newline writes inDT
290 global noFillCount textState inPRE file
293 puts -nonewline $file </PRE>
305 text " manual entry for detailed descriptions of the above options."
311 global noFillCount inPRE file
313 SHmacro "STANDARD OPTIONS"
315 set noFillCount 1000000
316 puts -nonewline $file <PRE>
321 if {$args != "man.macros"} {
322 puts stderr "Unknown macro: .$name [join $args " "]"
329 set count [lindex $args 0]
347 puts -nonewline $file "<B><U>"
348 text [lindex $args 0]
349 puts -nonewline $file "</U></B>"
350 if {[llength $args] == 2} {
351 text [lindex $args 1]
356 # puts -nonewline $file "</FONT>"
360 # if {[llength $args] > 0} {
361 # puts -nonewline $file "<BR>"
363 # puts -nonewline $file "<FONT COLOR=\"GREEN\">"
366 puts stderr "Unknown macro: .$name [join $args " "]"
370 # global nestStk; puts "$name [format "%-20s" $args] $nestStk"
371 # flush stdout; flush stderr
377 # This procedure is invoked to handle font changes in the text
381 # type - Type of font: R, I, B, or S.
389 if {$textState == "REF"} {
395 if {$textState == "INSERT"} {
405 puts stderr "Unknown font: $type"
414 # Insert a text string that may also have \fB-style font changes
415 # and a few other backslash sequences in it.
418 # text - Text to insert.
420 proc formattedText text {
421 # puts "formattedText: $text"
422 while {$text != ""} {
423 set index [string first \\ $text]
428 text [string range $text 0 [expr $index-1]]
429 set c [string index $text [expr $index+1]]
432 font [string index $text [expr $index+2]]
433 set text [string range $text [expr $index+3] end]
437 set text [string range $text [expr $index+2] end]
441 set text [string range $text [expr $index+2] end]
444 set text [string range $text [expr $index+2] end]
447 puts stderr "Unknown sequence: \\$c"
448 set text [string range $text [expr $index+2] end]
458 # This procedure is invoked to handle dash characters ("\-" in
459 # troff). It outputs a special dash character.
465 global textState charCnt
466 if {$textState == "NAME"} {
476 # This procedure is invoked to handle tabs in the troff input.
477 # Right now it does nothing.
483 global inPRE charCnt tabString
486 set pos [expr $charCnt % [string length $tabString] ]
487 set spaces [string first "1" [string range $tabString $pos end] ]
488 text [format "%*s" [incr spaces] " "]
490 # puts "tab: found tab outside of <PRE> block"
497 # This procedure handles the ".ta" macro, which sets tab stops.
500 # tabList - List of tab stops, each consisting of a number
501 # followed by "i" (inch) or "c" (cm).
503 proc setTabs {tabList} {
504 global file breakPending tabString
506 # puts "setTabs: --$tabList--"
510 set numTabs [llength $tabList]
511 foreach arg $tabList {
512 if {[scan $arg "%f%s" distance units] != 2} {
513 puts stderr "bad distance \"$arg\""
518 set distance [expr $distance * $charsPerInch / 2.54 ]
521 set distance [expr $distance * $charsPerInch]
524 puts stderr "bad units in distance \"$arg\""
529 lappend tabString [format "%*s1" [expr round($distance-$last-1)] " "]
532 set tabString [join $tabString {}]
533 # puts "setTabs: --$tabString--"
540 # Generates a line break in the HTML output.
554 # This procedure is invoked to handle newlines in the troff input.
555 # It outputs either a space character or a newline character, depending
562 global noFillCount file inDT inPRE charCnt
567 } elseif {$noFillCount == 0 || $inPRE == 1} {
580 # This procedure is called to handle a special character.
583 # name - Special character named in troff \x or \(xx construct.
590 switch -exact $name {
592 puts -nonewline $file " "
595 puts -nonewline $file "\\"
598 puts -nonewline $file "±"
604 puts stderr "Unknown character: $name"
612 # This procedure handles macros that are invoked with a leading "'"
613 # character instead of space. Right now it just generates an
617 # name - The name of the macro (without the ".").
618 # args - Any additional arguments to the macro.
620 proc macro2 {name args} {
621 puts stderr "Unknown macro: '$name [join $args " "]"
628 # Subsection head; handles the .SH macro.
631 # name - Section name.
633 proc SHmacro argList {
634 global file noFillCount textState charCnt
636 set args [join $argList " "]
637 if {[llength $argList] < 1} {
638 puts stderr "Bad .SH macro: .$name $args"
644 puts -nonewline $file "<H3>"
650 # control what the text proc does with text
653 NAME {set textState NAME}
654 DESCRIPTION {set textState INSERT}
655 INTRODUCTION {set textState INSERT}
656 "WIDGET-SPECIFIC OPTIONS" {set textState INSERT}
657 "SEE ALSO" {set textState SEE}
658 KEYWORDS {set textState 0}
667 # This procedure is invoked to handle ".IP" macros, which may take any
668 # of the following forms:
670 # .IP [1] Translate to a "1Step" paragraph.
671 # .IP [x] (x > 1) Translate to a "Step" paragraph.
672 # .IP Translate to a "Bullet" paragraph.
673 # .IP text count Translate to a FirstBody paragraph with special
674 # indent and tab stop based on "count", and tab after
678 # argList - List of arguments to the .IP macro.
680 # HTML limitations: 'count' in '.IP text count' is ignored.
682 proc IPmacro argList {
686 set length [llength $argList]
697 formattedText [lindex $argList 0]
701 puts stderr "Bad .IP macro: .IP [join $argList " "]"
707 # This procedure is invoked to handle ".TP" macros, which may take any
708 # of the following forms:
710 # .TP x Translate to an indented paragraph with the
711 # specified indent (in 100 twip units).
712 # .TP Translate to an indented paragraph with
716 # argList - List of arguments to the .IP macro.
718 # HTML limitations: 'x' in '.TP x' is ignored.
721 proc TPmacro {argList} {
724 set inDT "\n<DD>" ;# next newline writes inDT
732 # This procedure handles the .TH macro. It generates the non-scrolling
733 # header section for a given man page, and enters information into the
734 # table of contents. The .TH macro has the following form:
736 # .TH name section date footer header
739 # argList - List of arguments to the .TH macro.
741 proc THmacro {argList} {
744 if {[llength $argList] != 5} {
745 set args [join $argList " "]
746 puts stderr "Bad .TH macro: .$name $args"
748 set name [lindex $argList 0] ;# Tcl_UpVar
749 set page [lindex $argList 1] ;# 3
750 set vers [lindex $argList 2] ;# 7.4
751 set lib [lindex $argList 3] ;# Tcl
752 set pname [lindex $argList 4] ;# {Tcl Library Procedures}
754 puts -nonewline $file "<HTML><HEAD><TITLE>"
755 text "$lib - $name ($page)"
756 puts $file "</TITLE></HEAD><BODY>\n"
758 puts -nonewline $file "<H1><CENTER>"
760 puts $file "</CENTER></H1>\n"
767 # This procedure sets the left and hanging indents for a line.
768 # Indents are specified in units of inches or centimeters, and are
769 # relative to the current nesting level and left margin.
777 if {[lindex $nestStk end] != "NEW" } {
780 puts -nonewline $file "<P>"
787 # This procedure takes care of inserting the tags associated with the
788 # IP, TP, RS, RE, LP and PP macros. Only 'nest para' takes arguments.
791 # op - operation: para, incr, decr, reset, init
792 # listStart - begin list tag: OL, UL, DL.
793 # listItem - item tag: LI, LI, DT.
795 proc nest {op {listStart "NEW"} {listItem {} } } {
796 global file nestStk inDT charCnt
797 # puts "nest: $op $listStart $listItem"
800 set top [lindex $nestStk end]
801 if {$top == "NEW" } {
802 set nestStk [lreplace $nestStk end end $listStart]
803 puts $file "<$listStart>"
804 } elseif {$top != $listStart} {
805 puts stderr "nest para: bad stack"
808 puts $file "\n<$listItem>"
815 if {[llength $nestStk] == 0} {
816 puts stderr "nest error: nest length is zero"
819 set tag [lindex $nestStk end]
823 set nestStk [lreplace $nestStk end end]
826 while {[llength $nestStk] > 0} {
843 # This is the toplevel procedure that translates a man page
844 # to Frame. It runs the man2tcl program to turn the man page
845 # into a script, then it evals that script.
848 # fileName - Name of the file to translate.
851 global file self html_dir package footer
852 set self "[file tail $fileName].html"
853 set file [open "$html_dir/$package/$self" w]
854 puts " Pass 2 -- $fileName"
857 if [catch {eval [exec man2tcl [glob $fileName]]} msg] {
861 puts stderr $errorInfo
866 puts $file "</BODY></HTML>"