home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tk42r2x.zip / TclTk / bin / man2ipf2.tcl < prev    next >
Text File  |  1999-07-27  |  21KB  |  916 lines

  1. # man2ipf2.tcl --
  2. #
  3. # This file defines procedures that are used during the second pass of the
  4. # man page to IPF conversion process. It is sourced by man2ipf.tcl.
  5. #
  6. # Copyright (c) 1996 by Sun Microsystems, Inc.
  7. # Copyright (c) 1999 by Illya Vaes
  8. #
  9. # SCCS: @(#) man2ipf2.tcl 1.2 96/03/21 10:48:30
  10. #
  11.  
  12. # Global variables used by these scripts:
  13. #
  14. # NAME_file -    array indexed by NAME and containing file names used
  15. #        for hyperlinks.
  16. #
  17. # textState -    state variable defining action of 'text' proc.
  18. #
  19. # nestStk -    stack oriented list containing currently active
  20. #        HTML tags (UL, OL, DL). Local to 'nest' proc.
  21. #
  22. # inDT -    set by 'TPmacro', cleared by 'newline'. Used to insert
  23. #        the <DT> tag while in a dictionary list <DL>.
  24. #
  25. # curFont -    Name of special font that is currently in
  26. #        use.  Null means the default paragraph font
  27. #        is being used.
  28. #
  29. # file -    Where to output the generated HTML.
  30. #
  31. # fontStart -    Array to map font names to starting sequences.
  32. #
  33. # fontEnd -    Array to map font names to ending sequences.
  34. #
  35. # noFillCount -    Non-zero means don't fill the next $noFillCount
  36. #        lines: force a line break at each newline.  Zero
  37. #        means filling is enabled, so don't output line
  38. #        breaks for each newline.
  39. #
  40. # footer -    info inserted at bottom of each page. Normally read
  41. #        from the xref.tcl file
  42.     
  43. # initGlobals --
  44. #
  45. # This procedure is invoked to set the initial values of all of the
  46. # global variables, before processing a man page.
  47. #
  48. # Arguments:
  49. # None.
  50.  
  51. proc initGlobals {} {
  52.     global file noFillCount textState
  53.     global fontStart fontEnd curFont inPRE charCnt
  54.  
  55.     nest init
  56.     set inPRE 0
  57.     set textState 0
  58.     set curFont ""
  59.     set fontStart(Code) ":hp2."
  60.     set fontStart(Emphasis) ":hp1."
  61.     set fontEnd(Code) ":ehp2."
  62.     set fontEnd(Emphasis) ":ehp1."
  63.     set noFillCount 0
  64.     set charCnt 0
  65.     setTabs 0.5i
  66. }
  67.  
  68.  
  69. # beginFont --
  70. #
  71. # Arranges for future text to use a special font, rather than
  72. # the default paragraph font.
  73. #
  74. # Arguments:
  75. # font -        Name of new font to use.
  76.  
  77. proc beginFont font {
  78.     global curFont file fontStart
  79.  
  80.     if {$curFont == $font} {
  81.     return
  82.     }
  83.     endFont
  84.     puts -nonewline $file $fontStart($font)
  85.     set curFont $font
  86. }
  87.  
  88.  
  89. # endFont --
  90. #
  91. # Reverts to the default font for the paragraph type.
  92. #
  93. # Arguments:
  94. # None.
  95.  
  96. proc endFont {} {
  97.     global curFont file fontEnd
  98.  
  99.     if {$curFont != ""} {
  100.     puts -nonewline $file $fontEnd($curFont)
  101.     set curFont ""
  102.     }
  103. }
  104.  
  105.  
  106.  
  107. # text --
  108. #
  109. # This procedure adds text to the current paragraph.  If this is
  110. # the first text in the paragraph then header information for the
  111. # paragraph is output before the text.
  112. # Keep length of lines below 255.
  113. #
  114. # Arguments:
  115. # string -        Text to output in the paragraph.
  116.  
  117. proc text string {
  118.     global file textState inDT charCnt beforeSynopsis
  119.  
  120.     set pos [string first "\t" $string]
  121.     if {$pos >= 0} {
  122.         text [string range $string 0 [expr $pos-1]]
  123.         tab
  124.         text [string range $string [expr $pos+1] end]
  125.     return        
  126.     }
  127.     incr charCnt [string length $string]
  128.     regsub -all {&} $string {\&.}  string
  129.     regsub -all {\.\.\.} $string {\&period.\&period.\&period.}  string
  130.     regsub -all {<} $string {\<.}  string
  131.     regsub -all {>} $string {\>.}  string
  132.     regsub -all {``} $string {\&odq.}  string
  133.     regsub -all {''} $string {\&cdq.}  string
  134.     regsub -all {"} $string {\&cdq.}  string
  135.     regsub -all {:} $string {\&colon.}  string
  136.     switch $textState {
  137.         NAME {
  138.             # Only put in index if the is the "NAME" section before SYNOPSIS
  139.             if {$beforeSynopsis} {
  140.                 foreach i [split $string ","] {
  141. #                    lappend NAME_file([string trim $i]) $curFile
  142.                      puts $file ":i1.[string trim $i]"
  143.                 }
  144.             }
  145.         }
  146.     REF { 
  147.         if {$inDT == {}} {
  148.         set string [insertRef $string]
  149.         }
  150.     }
  151.     SEE { 
  152.         global NAME_file
  153.         foreach i [split $string] {
  154.         if ![regexp -nocase {^[a-z_]+} [string trim $i] i ] {
  155. #             puts "Warning: $i in SEE ALSO not found"
  156.             continue
  157.         }
  158.         if ![catch {set ref $NAME_file($i)} ] {
  159.             regsub $i $string ":link reftype=hd refid=$ref.$i:elink." string
  160.         }
  161.         }
  162.     }
  163.     }
  164.     # Don't puts more than 255 characters, since IPFC can't handle that
  165.     # but break on a space
  166.     # string length on the list of functions in the manpage of CrtChannel.3
  167.     # returns 248 while it is > 255, so use 176.
  168.     while {[string length $string] > 176} {
  169.         set indexSpace [ string last { } [string range $string 0 175] ]
  170.         puts $file [ string range $string 0 [ expr $indexSpace - 1]]
  171.         set string [ string range $string $indexSpace end]
  172.     }
  173.     puts -nonewline $file "$string"
  174. }
  175.  
  176.  
  177.  
  178. # insertRef --
  179. #
  180. #
  181. # Arguments:
  182. # string -        Text to output in the paragraph.
  183.  
  184. proc insertRef string {
  185.     global NAME_file self
  186.     set path {}
  187.     if ![catch {set ref $NAME_file([string trim $string])} ] {
  188.     if {"$ref" != $self} {
  189.         set string ":link reftype=hd ref='$ref'.$string:elink."
  190. #        puts "insertRef: $self $ref.html ---$string--"
  191.     }
  192.     }
  193.     return $string
  194. }
  195.  
  196.  
  197.  
  198. # macro --
  199. #
  200. # This procedure is invoked to process macro invocations that start
  201. # with "." (instead of ').
  202. #
  203. # Arguments:
  204. # name -        The name of the macro (without the ".").
  205. # args -        Any additional arguments to the macro.
  206.  
  207. proc macro {name args} {
  208.     switch $name {
  209.     AP {
  210.         if {[llength $args] != 3} {
  211.         puts stderr "Bad .AP macro: .$name [join $args " "]"
  212.         }
  213.         setTabs {1.25i 2.5i 3.75i}
  214.         TPmacro {}
  215.         font B
  216.         text "[lindex $args 0]  "
  217.         font I
  218.         text "[lindex $args 1]"
  219.         font R
  220.         text " ([lindex $args 2])"
  221.         newline
  222.     }
  223.     AS {}                ;# next page and previous page
  224.     br {
  225.         lineBreak    
  226.     }
  227.     BS {}
  228.     BE {}
  229.     CE {
  230.         global file noFillCount inPRE
  231.         puts $file ":ecgraphic."
  232.         set inPRE 0
  233.     }
  234.     CS {                ;# code section
  235.         global file noFillCount inPRE
  236.         puts -nonewline $file ":cgraphic."
  237.         set inPRE 1
  238.     }
  239.     DE {
  240.         global file noFillCount inPRE
  241.         puts $file ":ecgraphic."
  242.         set inPRE 0
  243.         set noFillCount 0
  244.     }
  245.     DS {
  246.         global file noFillCount inPRE
  247.         puts -nonewline $file ":cgraphic."
  248.         set noFillCount 10000000
  249.         set inPRE 1
  250.     }
  251.     fi {
  252.         global noFillCount
  253.         set noFillCount 0
  254.     }
  255.     IP {
  256.         IPmacro $args
  257.     }
  258.     LP {
  259.         nest decr
  260.         nest incr
  261.         newPara
  262.     }
  263.     ne {
  264.     }
  265.     nf {
  266.         global noFillCount
  267.         set noFillCount 1000000
  268.     }
  269.     OP {
  270.         global inDT file inPRE 
  271.         if {[llength $args] != 3} {
  272.         puts stderr "Bad .OP macro: .$name [join $args " "]"
  273.         }
  274.         nest para dl dt
  275.         set inPRE 1
  276.         puts -nonewline $file ":cgraphic."
  277.         setTabs 4c
  278.         text "Command-Line Name:"
  279.         tab
  280.         font B
  281.         set x [lindex $args 0]
  282.         regsub -all {\\-} $x - x
  283.         text $x
  284.         newline
  285.         font R
  286.         text "Database Name:"
  287.         tab
  288.         font B
  289.         text [lindex $args 1]
  290.         newline
  291.         font R
  292.         text "Database Class:"
  293.         tab
  294.         font B
  295.         text [lindex $args 2]
  296.         font R
  297.         puts -nonewline $file ":ecgraphic.\n.br"
  298.         set inDT "\n:dd."            ;# next newline writes inDT 
  299.         set inPRE 0
  300.         newline
  301.     }
  302.     PP {
  303.         nest decr
  304.         nest incr
  305.         newPara
  306.     }
  307.     RE {
  308.         nest decr    
  309.     }
  310.     RS {
  311.         nest incr
  312.     }
  313.     SE {
  314.         global noFillCount textState inPRE file
  315.  
  316.         font R
  317.         puts -nonewline $file ":ecgraphic."
  318.         set inPRE 0
  319.         set noFillCount 0
  320.         nest reset
  321.         newPara
  322.         text "See the "
  323.         font B
  324.         set temp $textState
  325.         set textState REF
  326.         text options
  327.         set textState $temp
  328.         font R
  329.         text " manual entry for detailed descriptions of the above options."
  330.     }
  331.     SH {
  332.         SHmacro $args
  333.     }
  334.     SO {
  335.         global noFillCount inPRE file
  336.  
  337.         SHmacro "STANDARD OPTIONS"
  338.         setTabs {4c 8c 12c}
  339.         set noFillCount 1000000
  340.         puts -nonewline $file ":cgraphic."
  341.         set inPRE 1
  342.         font B
  343.     }
  344.     so {
  345.         if {$args != "man.macros"} {
  346.         puts stderr "Unknown macro: .$name [join $args " "]"
  347.         }
  348.     }
  349.     sp {                    ;# needs work
  350.         if {$args == ""} {
  351.         set count 1
  352.         } else {
  353.         set count [lindex $args 0]
  354.         }
  355.         while {$count > 0} {
  356.         lineBreak
  357.         incr count -1
  358.         }
  359.     }
  360.     ta {
  361.         setTabs $args
  362.     }
  363.     TH {
  364.         THmacro $args
  365.     }
  366.     TP {
  367.         TPmacro $args
  368.     }
  369.     UL {                    ;# underline
  370.         global file
  371.         puts -nonewline $file ":hp7."    ;# Bold and underlined
  372.         text [lindex $args 0]
  373.         puts -nonewline $file ":ehp7."
  374.         if {[llength $args] == 2} {
  375.         text [lindex $args 1]
  376.         }
  377.     }
  378.     VE {
  379. #        global file
  380. #        puts -nonewline $file "</FONT>"
  381.     }
  382.     VS {
  383. #        global file
  384. #        if {[llength $args] > 0} {
  385. #        puts -nonewline $file "<BR>"
  386. #        }
  387. #        puts -nonewline $file "<FONT COLOR=\"GREEN\">"
  388.     }
  389.     default {
  390.         puts stderr "Unknown macro: .$name [join $args " "]"
  391.     }
  392.     }
  393.  
  394. #    global nestStk; puts "$name [format "%-20s" $args] $nestStk"
  395. #    flush stdout; flush stderr
  396. }
  397.  
  398.  
  399. # font --
  400. #
  401. # This procedure is invoked to handle font changes in the text
  402. # being output.
  403. #
  404. # Arguments:
  405. # type -        Type of font: R, I, B, or S.
  406.  
  407. proc font type {
  408.     global textState
  409.     switch $type {
  410.     P -
  411.     R {
  412.         endFont
  413.         if {$textState == "REF"} {
  414.         set textState INSERT
  415.         }
  416.     }
  417.     B {
  418.         beginFont Code
  419.         if {$textState == "INSERT"} {
  420.         set textState REF
  421.         }
  422.     }
  423.     I {
  424.         beginFont Emphasis
  425.     }
  426.     S {
  427.     }
  428.     default {
  429.         puts stderr "Unknown font: $type"
  430.     }
  431.     }
  432. }
  433.  
  434.  
  435.  
  436. # formattedText --
  437. #
  438. # Insert a text string that may also have \fB-style font changes
  439. # and a few other backslash sequences in it.
  440. #
  441. # Arguments:
  442. # text -        Text to insert.
  443.  
  444. proc formattedText text {
  445. #    puts "formattedText: $text"
  446.     while {$text != ""} {
  447.     set index [string first \\ $text]
  448.     if {$index < 0} {
  449.         text $text
  450.         return
  451.     }
  452.     text [string range $text 0 [expr $index-1]]
  453.     set c [string index $text [expr $index+1]]
  454.     switch -- $c {
  455.         f {
  456.         font [string index $text [expr $index+2]]
  457.         set text [string range $text [expr $index+3] end]
  458.         }
  459.         e {
  460.         text \\
  461.         set text [string range $text [expr $index+2] end]
  462.         }
  463.         - {
  464.         dash
  465.         set text [string range $text [expr $index+2] end]
  466.         }
  467.         | {
  468.         set text [string range $text [expr $index+2] end]
  469.         }
  470.         default {
  471.         puts stderr "Unknown sequence: \\$c"
  472.         set text [string range $text [expr $index+2] end]
  473.         }
  474.     }
  475.     }
  476. }
  477.  
  478.  
  479.  
  480. # dash --
  481. #
  482. # This procedure is invoked to handle dash characters ("\-" in
  483. # troff).  It outputs a special dash character.
  484. #
  485. # Arguments:
  486. # None.
  487.  
  488. proc dash {} {
  489.     global textState charCnt
  490.     if {$textState == "NAME"} {
  491.         set textState 0
  492.     }
  493.     incr charCnt
  494.     text "-"
  495. }
  496.  
  497.  
  498. # tab --
  499. #
  500. # This procedure is invoked to handle tabs in the troff input.
  501. # Right now it does nothing.
  502. #
  503. # Arguments:
  504. # None.
  505.  
  506. proc tab {} {
  507.     global inPRE charCnt tabString
  508. #    ? charCnt
  509.     if {$inPRE == 1} {
  510.     set pos [expr $charCnt % [string length $tabString] ]
  511.     set spaces [string first "1" [string range $tabString $pos end] ]
  512.     text [format "%*s" [incr spaces] " "]
  513.     } else {
  514. #    puts "tab: found tab outside of <PRE> block"
  515.     }
  516. }
  517.  
  518.  
  519. # setTabs --
  520. #
  521. # This procedure handles the ".ta" macro, which sets tab stops.
  522. #
  523. # Arguments:
  524. # tabList -    List of tab stops, each consisting of a number
  525. #            followed by "i" (inch) or "c" (cm).
  526.  
  527. proc setTabs {tabList} {
  528.     global file breakPending tabString
  529.  
  530. #    puts "setTabs: --$tabList--"
  531.     set last 0
  532.     set tabString {}
  533.     set charsPerInch 14.
  534.     set numTabs [llength $tabList]
  535.     foreach arg $tabList {
  536.     if {[scan $arg "%f%s" distance units] != 2} {
  537.         puts stderr "bad distance \"$arg\""
  538.         return 0
  539.         }
  540.     switch -- $units {
  541.         c    {
  542.         set distance [expr $distance * $charsPerInch / 2.54 ]
  543.         }
  544.         i    {
  545.         set distance [expr $distance * $charsPerInch]
  546.         }
  547.         default {
  548.         puts stderr "bad units in distance \"$arg\""
  549.         continue
  550.         }
  551.         }
  552. #        ? distance
  553.         lappend tabString [format "%*s1" [expr round($distance-$last-1)] " "]
  554.         set last $distance
  555.     }
  556.     set tabString [join $tabString {}]
  557. #    puts "setTabs: --$tabString--"
  558. }
  559.  
  560.  
  561.  
  562. # lineBreak --
  563. #
  564. # Generates a line break in the HTML output.
  565. #
  566. # Arguments:
  567. # None.
  568.  
  569. proc lineBreak {} {
  570.     global file inPRE
  571.  
  572.     if {$inPRE} {
  573.         puts $file "\n"
  574.     } else {
  575.         puts $file "\n.br\n"
  576.     }
  577. }
  578.  
  579.  
  580.  
  581. # newline --
  582. #
  583. # This procedure is invoked to handle newlines in the troff input.
  584. # It outputs either a space character or a newline character, depending
  585. # on fill mode.
  586. #
  587. # Arguments:
  588. # None.
  589.  
  590. proc newline {} {
  591.     global noFillCount file inDT inPRE charCnt
  592.  
  593.     if {$inDT != {} } {
  594.         puts $file "\n$inDT"
  595.         set inDT {}
  596.     } elseif {$noFillCount == 0 || $inPRE == 1} {
  597.     puts $file {}
  598.     } else {
  599.     lineBreak
  600.     incr noFillCount -1
  601.     }
  602.     set charCnt 0
  603. }
  604.  
  605.  
  606.  
  607. # char --
  608. #
  609. # This procedure is called to handle a special character.
  610. #
  611. # Arguments:
  612. # name -        Special character named in troff \x or \(xx construct.
  613.  
  614. proc char name {
  615.     global file charCnt
  616.  
  617.     incr charCnt
  618. #    puts "char: $name"
  619.     # In comments explanations from NROFF/TROFF User's Manual (Oct.11, 1976)
  620.     switch -exact $name {
  621.     \\0 { ; # Digit width space
  622.         puts -nonewline $file " "
  623.     }
  624.     \\\\ { ; # Escaped backslash
  625.         puts -nonewline $file "\\"
  626.     }
  627.     \\(+- { ; # Character named +- (plusminus)
  628.         puts -nonewline $file "&plusmin."
  629.     }
  630.     \\% - ; # Default optionale hyphenation character
  631.     \\| { ; # 1/6 em narrow space character (zero width in NROFF)
  632.     }
  633.     default {
  634.         puts stderr "Unknown character: $name"
  635.     }
  636.     }
  637. }
  638.  
  639.  
  640. # macro2 --
  641. #
  642. # This procedure handles macros that are invoked with a leading "'"
  643. # character instead of space.  Right now it just generates an
  644. # error diagnostic.
  645. #
  646. # Arguments:
  647. # name -        The name of the macro (without the ".").
  648. # args -        Any additional arguments to the macro.
  649.  
  650. proc macro2 {name args} {
  651.     puts stderr "Unknown macro: '$name [join $args " "]"
  652. }
  653.  
  654.  
  655.  
  656. # SHmacro --
  657. #
  658. # Subsection head; handles the .SH macro.
  659. #
  660. # Arguments:
  661. # name -        Section name.
  662.  
  663. proc SHmacro argList {
  664.     global file noFillCount textState charCnt beforeSynopsis
  665.  
  666.     set args [join $argList " "]
  667.     if {[llength $argList] < 1} {
  668.     puts stderr "Bad .SH macro: .$name $args"
  669.     }
  670.  
  671.     set noFillCount 0
  672.     nest reset
  673.  
  674.     if {$args != {NAME} || !$beforeSynopsis} {
  675.         puts -nonewline $file ":p."
  676.     }
  677.     puts -nonewline $file ":hp4."
  678.     text  $args
  679.     puts $file ":ehp4.\n:p."
  680.  
  681. #    ? args textState
  682.  
  683.     # control what the text proc does with text
  684.     
  685.     switch $args {
  686.     NAME {set textState NAME}
  687.     DESCRIPTION {set textState INSERT}
  688.     INTRODUCTION {set textState INSERT}
  689.     "WIDGET-SPECIFIC OPTIONS" {set textState INSERT}
  690.     "SEE ALSO" {set textState SEE}
  691.     KEYWORDS {set textState 0}
  692.         SYNOPSIS {set beforeSynopsis 0}
  693.     }
  694.     set charCnt 0
  695. }
  696.  
  697.  
  698.  
  699. # IPmacro --
  700. #
  701. # This procedure is invoked to handle ".IP" macros, which may take any
  702. # of the following forms:
  703. #
  704. # .IP [1]            Translate to a "1Step" paragraph.
  705. # .IP [x] (x > 1)    Translate to a "Step" paragraph.
  706. # .IP                Translate to a "Bullet" paragraph.
  707. # .IP text count    Translate to a FirstBody paragraph with special
  708. #                    indent and tab stop based on "count", and tab after
  709. #                    "text".
  710. #
  711. # Arguments:
  712. # argList -        List of arguments to the .IP macro.
  713. #
  714. # HTML limitations: 'count' in '.IP text count' is ignored.
  715.  
  716. proc IPmacro argList {
  717.     global file
  718.  
  719.     setTabs 0.5i
  720.     set length [llength $argList]
  721.     if {$length == 0} {
  722.         nest para UL LI
  723.     return
  724.     }
  725.     if {$length == 1} {
  726.         nest para OL LI
  727.         return
  728.     }
  729.     if {$length > 1} {
  730.         nest para dl dt
  731.         formattedText [lindex $argList 0]
  732.         puts $file "\n:dd."
  733.         return
  734.     }
  735.     puts stderr "Bad .IP macro: .IP [join $argList " "]"
  736. }
  737.  
  738.  
  739. # TPmacro --
  740. #
  741. # This procedure is invoked to handle ".TP" macros, which may take any
  742. # of the following forms:
  743. #
  744. # .TP x        Translate to an indented paragraph with the
  745. #             specified indent (in 100 twip units).
  746. # .TP        Translate to an indented paragraph with
  747. #             default indent.
  748. #
  749. # Arguments:
  750. # argList -        List of arguments to the .IP macro.
  751. #
  752. # HTML limitations: 'x' in '.TP x' is ignored.
  753.  
  754.  
  755. proc TPmacro {argList} {
  756.     global inDT file
  757.     nest para dl dt
  758.     set inDT "\n:dd."            ;# next newline writes inDT 
  759.     setTabs 0.5i
  760. }
  761.  
  762.  
  763.  
  764. # THmacro --
  765. #
  766. # This procedure handles the .TH macro.  It generates the non-scrolling
  767. # header section for a given man page, and enters information into the
  768. # table of contents.  The .TH macro has the following form:
  769. #
  770. # .TH name section date footer header
  771. #
  772. # Arguments:
  773. # argList -        List of arguments to the .TH macro.
  774.  
  775. proc THmacro {argList} {
  776.     global file nextres res beforeSynopsis
  777.  
  778.     if {[llength $argList] != 5} {
  779.     set args [join $argList " "]
  780.     puts stderr "Bad .TH macro: .$name $args"
  781.     }
  782.     set name  [lindex $argList 0]        ;# Tcl_UpVar
  783.     set page  [lindex $argList 1]        ;# 3
  784.     set vers  [lindex $argList 2]        ;# 7.4
  785.     set lib   [lindex $argList 3]        ;# Tcl
  786.     set pname [lindex $argList 4]        ;# {Tcl Library Procedures}
  787.     set beforeSynopsis 1
  788. #puts "name \[$name\] page \[$page\] vers \[$vers\] lib \[$lib\] pname \[$pname\]"
  789.     
  790.     # This is what gets put in the contents of the INF-file
  791. #    set res($name) $nextres
  792. #    puts -nonewline $file "\n:h1 res=$nextres."
  793.     puts -nonewline $file "\n:h2 name='$name'."
  794. #    set nextres [ expr $nextres + 1 ]
  795.     text $name
  796.     puts $file "\n"
  797.  
  798. #    if {$vers != {}} {
  799. #        puts $file ":i1.$name ($page) - $lib v$vers"
  800. #    } else {
  801. #        puts $file ":i1.$name ($page) - $lib"
  802. #    }
  803. #    puts $file ":link reftype=hd refid=$res($name).:elink."
  804. #    puts $file ":link reftype=hd refid='$pname'.:elink."
  805. }
  806.  
  807.  
  808.  
  809. # newPara --
  810. #
  811. # This procedure sets the left and hanging indents for a line.
  812. # Indents are specified in units of inches or centimeters, and are
  813. # relative to the current nesting level and left margin.
  814. #
  815. # Arguments:
  816. # None
  817.  
  818. proc newPara {} {
  819.     global file nestStk
  820.     
  821.     if {[lindex $nestStk end] != "NEW" } {
  822.     nest decr    
  823.     }
  824.     puts -nonewline $file ":p."
  825. }
  826.  
  827.  
  828.  
  829. # nest --
  830. #
  831. # This procedure takes care of inserting the tags associated with the
  832. # IP, TP, RS, RE, LP and PP macros. Only 'nest para' takes arguments.
  833. #
  834. # Arguments:
  835. # op -                operation: para, incr, decr, reset, init
  836. # listStart -        begin list tag: OL, UL, DL.
  837. # listItem -        item tag:       LI, LI, DT.
  838.  
  839. proc nest {op {listStart "NEW"} {listItem {} } } {
  840.     global file nestStk inDT charCnt
  841. #    puts "nest: $op $listStart $listItem"
  842.     switch $op {
  843.     para {
  844.         set top [lindex $nestStk end]
  845.         if {$top == "NEW" } {
  846.         set nestStk [lreplace $nestStk end end $listStart]
  847.         puts $file ":$listStart."
  848.         } elseif {$top != $listStart} {
  849.         puts stderr "nest para: bad stack"
  850.         exit 1
  851.         }
  852.         puts $file ":$listItem."
  853.         set charCnt 0
  854.     }
  855.     incr {
  856.        lappend nestStk NEW
  857.     }
  858.     decr {
  859.         if {[llength $nestStk] == 0} {
  860.         puts stderr "nest error: nest length is zero"
  861.         set nestStk NEW
  862.         }
  863.         set tag [lindex $nestStk end]
  864.         if {$tag != "NEW"} {
  865.         puts $file ":e$tag."
  866.         }
  867.         set nestStk [lreplace $nestStk end end]
  868.     }
  869.     reset {
  870.         while {[llength $nestStk] > 0} {
  871.         nest decr
  872.         }
  873.         set nestStk NEW
  874.     }
  875.     init {
  876.         set nestStk NEW
  877.         set inDT {}
  878.     }
  879.     }
  880.     set charCnt 0
  881. }
  882.  
  883.  
  884.  
  885. # do --
  886. #
  887. # This is the toplevel procedure that translates a man page
  888. # to Frame.  It runs the man2tcl program to turn the man page
  889. # into a script, then it evals that script.
  890. #
  891. # Arguments:
  892. # fileName -        Name of the file to translate.
  893.  
  894. proc do fileName {
  895.     global file self html_dir package footer
  896.     set self "[file tail $fileName]"
  897. #    set file [open "$html_dir/$package/$self" w]
  898. #    puts "  Pass 2 -- $fileName"
  899.     flush stdout
  900.     initGlobals
  901.     if [catch {eval [exec man2tcl [glob $fileName]]} msg] {
  902.     global errorInfo
  903.     puts stderr $msg
  904.     puts "in"
  905.     puts stderr $errorInfo
  906.     exit 1
  907.     }
  908.     nest reset
  909. #    puts $file $footer
  910. #    puts $file "</BODY></HTML>"
  911. #    close $file
  912. }
  913.  
  914.  
  915.  
  916.