Debian Codegraph @

tools/man2help2.tcl

raw
1 # man2help2.tcl --
2 #
3 # This file defines procedures that are used during the second pass of
4 # the man page conversion. It converts the man format input to rtf
5 # form suitable for use by the Windows help compiler.
6 #
7 # Copyright (c) 1996 Sun Microsystems, Inc.
8 #
9 # See the file "license.terms" for information on usage and redistribution
10 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
11
12 # Global variables used by these scripts:
13 #
14 # state - state variable that controls action of text proc.
15 #
16 # topics - array indexed by (package,section,topic) with value
17 # of topic ID.
18 #
19 # keywords - array indexed by keyword string with value of topic ID.
20 #
21 # curID - current topic ID, starts at 0 and is incremented for
22 # each new topic file.
23 #
24 # curPkg - current package name (e.g. Tcl).
25 #
26 # curSect - current section title (e.g. "Tcl Built-In Commands").
27 #
28
29 # initGlobals --
30 #
31 # This procedure is invoked to set the initial values of all of the
32 # global variables, before processing a man page.
33 #
34 # Arguments:
35 # None.
36
37 proc initGlobals {} {
38 uplevel \#0 unset state
39 global state chars
40
41 set state(paragraphPending) 0
42 set state(breakPending) 0
43 set state(firstIndent) 0
44 set state(leftIndent) 0
45
46 set state(inTP) 0
47 set state(paragraph) 0
48 set state(textState) 0
49 set state(curFont) ""
50 set state(startCode) "{\\b "
51 set state(startEmphasis) "{\\i "
52 set state(endCode) "}"
53 set state(endEmphasis) "}"
54 set state(noFill) 0
55 set state(charCnt) 0
56 set state(offset) [getTwips 0.5i]
57 set state(leftMargin) [getTwips 0.5i]
58 set state(nestingLevel) 0
59 set state(intl) 0
60 set state(sb) 0
61 setTabs 0.5i
62
63 # set up international character table
64
65 array set chars {
66 o^ F4
67 }
68 }
69
70
71 # beginFont --
72 #
73 # Arranges for future text to use a special font, rather than
74 # the default paragraph font.
75 #
76 # Arguments:
77 # font - Name of new font to use.
78
79 proc beginFont {font} {
80 global file state
81
82 textSetup
83 if {[string equal $state(curFont) $font]} {
84 return
85 }
86 endFont
87 puts -nonewline $file $state(start$font)
88 set state(curFont) $font
89 }
90
91
92 # endFont --
93 #
94 # Reverts to the default font for the paragraph type.
95 #
96 # Arguments:
97 # None.
98
99 proc endFont {} {
100 global state file
101
102 if {[string compare $state(curFont) ""]} {
103 puts -nonewline $file $state(end$state(curFont))
104 set state(curFont) ""
105 }
106 }
107
108
109 # textSetup --
110 #
111 # This procedure is called the first time that text is output for a
112 # paragraph. It outputs the header information for the paragraph.
113 #
114 # Arguments:
115 # None.
116
117 proc textSetup {} {
118 global file state
119
120 if $state(breakPending) {
121 puts $file "\\line"
122 }
123 if $state(paragraphPending) {
124 puts $file [format "\\par\n\\pard\\fi%.0f\\li%.0f" \
125 $state(firstIndent) $state(leftIndent)]
126 foreach tab $state(tabs) {
127 puts $file [format "\\tx%.0f" $tab]
128 }
129 set state(tabs) {}
130 if {$state(sb)} {
131 puts $file "\\sb$state(sb)"
132 set state(sb) 0
133 }
134 }
135 set state(breakPending) 0
136 set state(paragraphPending) 0
137 }
138
139
140 # text --
141 #
142 # This procedure adds text to the current state(paragraph). If this is
143 # the first text in the state(paragraph) then header information for the
144 # state(paragraph) is output before the text.
145 #
146 # Arguments:
147 # string - Text to output in the state(paragraph).
148
149 proc text {string} {
150 global file state chars
151
152 textSetup
153 set string [string map [list \
154 "\\" "\\\\" \
155 "\{" "\\\{" \
156 "\}" "\\\}" \
157 "\t" {\tab } \
158 '' "\\rdblquote " \
159 `` "\\ldblquote " \
160 "\xB7" "\\bullet " \
161 ] $string]
162
163 # Check if this is the beginning of an international character string.
164 # If so, look up the sequence in the chars table and substitute the
165 # appropriate hex value.
166
167 if {$state(intl)} {
168 if {[regexp {^'([^']*)'} $string dummy ch]} {
169 if {[info exists chars($ch)]} {
170 regsub {^'[^']*'} $string "\\\\'$chars($ch)" string
171 } else {
172 puts stderr "Unknown international character '$ch'"
173 }
174 }
175 set state(intl) 0
176 }
177
178 switch $state(textState) {
179 REF {
180 if {$state(inTP) == 0} {
181 set string [insertRef $string]
182 }
183 }
184 SEE {
185 global topics curPkg curSect
186 foreach i [split $string] {
187 if {![regexp -nocase {^[a-z_0-9]+} [string trim $i] i ]} {
188 continue
189 }
190 if {![catch {set ref $topics($curPkg,$curSect,$i)} ]} {
191 regsub $i $string [link $i $ref] string
192 }
193 }
194 }
195 KEY {
196 return
197 }
198 }
199 puts -nonewline $file "$string"
200 }
201
202
203
204 # insertRef --
205 #
206 # This procedure looks for a string in the cross reference table and
207 # generates a hot-link to the appropriate topic. Tries to find the
208 # nearest reference in the manual.
209 #
210 # Arguments:
211 # string - Text to output in the state(paragraph).
212
213 proc insertRef {string} {
214 global NAME_file curPkg curSect topics curID
215 set path {}
216 set string [string trim $string]
217 set ref {}
218 if {[info exists topics($curPkg,$curSect,$string)]} {
219 set ref $topics($curPkg,$curSect,$string)
220 } else {
221 set sites [array names topics "$curPkg,*,$string"]
222 set count [llength $sites]
223 if {$count > 0} {
224 set ref $topics([lindex $sites 0])
225 } else {
226 set sites [array names topics "*,*,$string"]
227 set count [llength $sites]
228 if {$count > 0} {
229 set ref $topics([lindex $sites 0])
230 }
231 }
232 }
233
234 if {($ref != "") && ($ref != $curID)} {
235 set string [link $string $ref]
236 }
237 return $string
238 }
239
240
241
242 # macro --
243 #
244 # This procedure is invoked to process macro invocations that start
245 # with "." (instead of ').
246 #
247 # Arguments:
248 # name - The name of the macro (without the ".").
249 # args - Any additional arguments to the macro.
250
251 proc macro {name args} {
252 global state file
253 switch $name {
254 AP {
255 if {[llength $args] != 3 && [llength $args] != 2} {
256 puts stderr "Bad .AP macro: .$name [join $args " "]"
257 }
258 newPara 3.75i -3.75i
259 setTabs {1.25i 2.5i 3.75i}
260 font B
261 text [lindex $args 0]
262 tab
263 font I
264 text [lindex $args 1]
265 tab
266 font R
267 if {[llength $args] == 3} {
268 text "([lindex $args 2])"
269 }
270 tab
271 }
272 AS {
273 # next page and previous page
274 }
275 br {
276 lineBreak
277 }
278 BS {}
279 BE {}
280 CE {
281 puts -nonewline $::file "\\f0\\fs20 "
282 set state(noFill) 0
283 set state(breakPending) 0
284 newPara ""
285 set state(leftIndent) [expr {$state(leftIndent) - $state(offset)}]
286 set state(sb) 80
287 }
288 CS {
289 # code section
290 set state(noFill) 1
291 newPara ""
292 set state(leftIndent) [expr {$state(leftIndent) + $state(offset)}]
293 set state(sb) 80
294 puts -nonewline $::file "\\f1\\fs18 "
295 }
296 DE {
297 set state(noFill) 0
298 decrNestingLevel
299 newPara 0i
300 }
301 DS {
302 set state(noFill) 1
303 incrNestingLevel
304 newPara 0i
305 }
306 fi {
307 set state(noFill) 0
308 }
309 IP {
310 IPmacro $args
311 }
312 LP {
313 newPara 0i
314 set state(sb) 80
315 }
316 ne {
317 }
318 nf {
319 set state(noFill) 1
320 }
321 OP {
322 if {[llength $args] != 3} {
323 puts stderr "Bad .OP macro: .$name [join $args " "]"
324 }
325 set state(nestingLevel) 0
326 newPara 0i
327 set state(sb) 120
328 setTabs 4c
329 text "Command-Line Name:"
330 tab
331 font B
332 set x [lindex $args 0]
333 regsub -all {\\-} $x - x
334 text $x
335 lineBreak
336 font R
337 text "Database Name:"
338 tab
339 font B
340 text [lindex $args 1]
341 lineBreak
342 font R
343 text "Database Class:"
344 tab
345 font B
346 text [lindex $args 2]
347 font R
348 set state(inTP) 0
349 newPara 0.5i
350 set state(sb) 80
351 }
352 PP {
353 newPara 0i
354 set state(sb) 120
355 }
356 RE {
357 decrNestingLevel
358 }
359 RS {
360 incrNestingLevel
361 }
362 SE {
363 font R
364 set state(noFill) 0
365 set state(nestingLevel) 0
366 newPara 0i
367 text "See the "
368 font B
369 set temp $state(textState)
370 set state(textState) REF
371 text options
372 set state(textState) $temp
373 font R
374 text " manual entry for detailed descriptions of the above options."
375 }
376 SH {
377 SHmacro $args
378 }
379 SS {
380 SHmacro $args subsection
381 }
382 SO {
383 SHmacro "STANDARD OPTIONS"
384 set state(nestingLevel) 0
385 newPara 0i
386 setTabs {4c 8c 12c}
387 font B
388 set state(noFill) 1
389 }
390 so {
391 if {$args ne "man.macros"} {
392 puts stderr "Unknown macro: .$name [join $args " "]"
393 }
394 }
395 sp { ;# needs work
396 if {$args eq ""} {
397 set count 1
398 } else {
399 set count [lindex $args 0]
400 }
401 while {$count > 0} {
402 lineBreak
403 incr count -1
404 }
405 }
406 ta {
407 setTabs $args
408 }
409 TH {
410 THmacro $args
411 }
412 TP {
413 TPmacro $args
414 }
415 UL { ;# underline
416 puts -nonewline $file "{\\ul "
417 text [lindex $args 0]
418 puts -nonewline $file "}"
419 if {[llength $args] == 2} {
420 text [lindex $args 1]
421 }
422 }
423 VE {}
424 VS {}
425 QW {
426 formattedText "``[lindex $args 0]''[lindex $args 1] "
427 }
428 MT {
429 text "``'' "
430 }
431 PQ {
432 formattedText \
433 "(``[lindex $args 0]''[lindex $args 1])[lindex $args 2] "
434 }
435 QR {
436 formattedText "``[lindex $args 0]"
437 dash
438 formattedText "[lindex $args 1]''[lindex $args 2] "
439 }
440 default {
441 puts stderr "Unknown macro: .$name [join $args " "]"
442 }
443 }
444 }
445
446
447 # link --
448 #
449 # This procedure returns the string for a hot link to a different
450 # context location.
451 #
452 # Arguments:
453 # label - String to display in hot-spot.
454 # id - Context string to jump to.
455
456 proc link {label id} {
457 return "{\\uldb $label}{\\v $id}"
458 }
459
460
461 # font --
462 #
463 # This procedure is invoked to handle font changes in the text
464 # being output.
465 #
466 # Arguments:
467 # type - Type of font: R, I, B, or S.
468
469 proc font {type} {
470 global state
471 switch $type {
472 P -
473 R {
474 endFont
475 if {$state(textState) eq "REF"} {
476 set state(textState) INSERT
477 }
478 }
479 C -
480 B {
481 beginFont Code
482 if {$state(textState) eq "INSERT"} {
483 set state(textState) REF
484 }
485 }
486 I {
487 beginFont Emphasis
488 }
489 S {
490 }
491 default {
492 puts stderr "Unknown font: $type"
493 }
494 }
495 }
496
497
498
499 # formattedText --
500 #
501 # Insert a text string that may also have \fB-style font changes
502 # and a few other backslash sequences in it.
503 #
504 # Arguments:
505 # text - Text to insert.
506
507 proc formattedText {text} {
508 global chars
509
510 while {$text ne ""} {
511 set index [string first \\ $text]
512 if {$index < 0} {
513 text $text
514 return
515 }
516 text [string range $text 0 [expr {$index-1}]]
517 set c [string index $text [expr {$index+1}]]
518 switch -- $c {
519 f {
520 font [string index $text [expr {$index+2}]]
521 set text [string range $text [expr {$index+3}] end]
522 }
523 e {
524 text "\\"
525 set text [string range $text [expr {$index+2}] end]
526 }
527 - {
528 dash
529 set text [string range $text [expr {$index+2}] end]
530 }
531 & - | {
532 set text [string range $text [expr {$index+2}] end]
533 }
534 ( {
535 char [string range $text $index [expr {$index+3}]]
536 set text [string range $text [expr {$index+4}] end]
537 }
538 default {
539 puts stderr "Unknown sequence: \\$c"
540 set text [string range $text [expr {$index+2}] end]
541 }
542 }
543 }
544 }
545
546
547 # dash --
548 #
549 # This procedure is invoked to handle dash characters ("\-" in
550 # troff). It outputs a special dash character.
551 #
552 # Arguments:
553 # None.
554
555 proc dash {} {
556 global state
557 if {[string equal $state(textState) "NAME"]} {
558 set state(textState) 0
559 }
560 text "-"
561 }
562
563
564 # tab --
565 #
566 # This procedure is invoked to handle tabs in the troff input.
567 # Right now it does nothing.
568 #
569 # Arguments:
570 # None.
571
572 proc tab {} {
573 global file
574
575 textSetup
576 puts -nonewline $file "\\tab "
577 }
578
579
580 # setTabs --
581 #
582 # This procedure handles the ".ta" macro, which sets tab stops.
583 #
584 # Arguments:
585 # tabList - List of tab stops in *roff format
586
587 proc setTabs {tabList} {
588 global file state
589
590 set state(tabs) {}
591 foreach arg $tabList {
592 if {[string match +* $arg]} {
593 set relativeTo [lindex $state(tabs) end]
594 set arg [string range $arg 1 end]
595 } else {
596 # Local left margin
597 set relativeTo [expr {$state(leftMargin) \
598 + ($state(offset) * $state(nestingLevel))}]
599 }
600 if {[regexp {^\\w'([^']*)'u$} $arg -> submatch]} {
601 # Magic factor!
602 set distance [expr {[string length $submatch] * 86.4}]
603 } else {
604 set distance [getTwips $arg]
605 }
606 lappend state(tabs) [expr {round($distance + $relativeTo)}]
607 }
608 }
609
610
611 # lineBreak --
612 #
613 # Generates a line break in the HTML output.
614 #
615 # Arguments:
616 # None.
617
618 proc lineBreak {} {
619 global state
620 textSetup
621 set state(breakPending) 1
622 }
623
624
625
626 # newline --
627 #
628 # This procedure is invoked to handle newlines in the troff input.
629 # It outputs either a space character or a newline character, depending
630 # on fill mode.
631 #
632 # Arguments:
633 # None.
634
635 proc newline {} {
636 global state
637
638 if {$state(inTP)} {
639 set state(inTP) 0
640 lineBreak
641 } elseif {$state(noFill)} {
642 lineBreak
643 } else {
644 text " "
645 }
646 }
647
648
649 # pageBreak --
650 #
651 # This procedure is invoked to generate a page break.
652 #
653 # Arguments:
654 # None.
655
656 proc pageBreak {} {
657 global file curVer
658 if {[string equal $curVer ""]} {
659 puts $file {\page}
660 } else {
661 puts $file {\par}
662 puts $file {\pard\sb400\qc}
663 puts $file "Last change: $curVer\\page"
664 }
665 }
666
667
668 # char --
669 #
670 # This procedure is called to handle a special character.
671 #
672 # Arguments:
673 # name - Special character named in troff \x or \(xx construct.
674
675 proc char {name} {
676 global file state
677
678 switch -exact $name {
679 {\o} {
680 set state(intl) 1
681 }
682 {\ } {
683 textSetup
684 puts -nonewline $file " "
685 }
686 {\0} {
687 textSetup
688 puts -nonewline $file " \\emspace "
689 }
690 {\\} - {\e} {
691 textSetup
692 puts -nonewline $file "\\\\"
693 }
694 {\(+-} {
695 textSetup
696 puts -nonewline $file "\\'b1 "
697 }
698 {\%} - {\|} {
699 }
700 {\(->} {
701 textSetup
702 puts -nonewline $file "->"
703 }
704 {\(bu} {
705 textSetup
706 puts -nonewline $file "\\bullet "
707 }
708 {\(co} {
709 textSetup
710 puts -nonewline $file "\\'a9 "
711 }
712 {\(mi} {
713 textSetup
714 puts -nonewline $file "-"
715 }
716 {\(mu} {
717 textSetup
718 puts -nonewline $file "\\'d7 "
719 }
720 {\(em} - {\(en} {
721 textSetup
722 puts -nonewline $file "-"
723 }
724 {\(fm} {
725 textSetup
726 puts -nonewline $file "\\'27 "
727 }
728 default {
729 puts stderr "Unknown character: $name"
730 }
731 }
732 }
733
734
735 # macro2 --
736 #
737 # This procedure handles macros that are invoked with a leading "'"
738 # character instead of space. Right now it just generates an
739 # error diagnostic.
740 #
741 # Arguments:
742 # name - The name of the macro (without the ".").
743 # args - Any additional arguments to the macro.
744
745 proc macro2 {name args} {
746 puts stderr "Unknown macro: '$name [join $args " "]"
747 }
748
749
750
751 # SHmacro --
752 #
753 # Subsection head; handles the .SH and .SS macros.
754 #
755 # Arguments:
756 # name - Section name.
757
758 proc SHmacro {argList {style section}} {
759 global file state
760
761 set args [join $argList " "]
762 if {[llength $argList] < 1} {
763 puts stderr "Bad .SH macro: .SH $args"
764 }
765
766 # control what the text proc does with text
767
768 switch $args {
769 NAME {set state(textState) NAME}
770 DESCRIPTION {set state(textState) INSERT}
771 INTRODUCTION {set state(textState) INSERT}
772 "WIDGET-SPECIFIC OPTIONS" {set state(textState) INSERT}
773 "SEE ALSO" {set state(textState) SEE}
774 KEYWORDS {set state(textState) KEY; return}
775 }
776
777 if {$state(breakPending) != -1} {
778 set state(breakPending) 1
779 } else {
780 set state(breakPending) 0
781 }
782 set state(noFill) 0
783 if {[string compare "subsection" $style] == 0} {
784 nextPara .25i
785 } else {
786 nextPara 0i
787 }
788 font B
789 text $args
790 font R
791 nextPara .5i
792 }
793
794 # IPmacro --
795 #
796 # This procedure is invoked to handle ".IP" macros, which may take any
797 # of the following forms:
798 #
799 # .IP [1] Translate to a "1Step" state(paragraph).
800 # .IP [x] (x > 1) Translate to a "Step" state(paragraph).
801 # .IP Translate to a "Bullet" state(paragraph).
802 # .IP text count Translate to a FirstBody state(paragraph) with special
803 # indent and tab stop based on "count", and tab after
804 # "text".
805 #
806 # Arguments:
807 # argList - List of arguments to the .IP macro.
808 #
809 # HTML limitations: 'count' in '.IP text count' is ignored.
810
811 proc IPmacro {argList} {
812 global file state
813
814 set length [llength $argList]
815 foreach {text indent} $argList break
816 if {$length > 2} {
817 puts stderr "Bad .IP macro: .IP [join $argList " "]"
818 }
819
820 if {$length == 0} {
821 set text {\(bu}
822 set indent 5
823 } elseif {$length == 1} {
824 set indent 5
825 }
826 if {$text == {\(bu}} {
827 set text "\xB7"
828 }
829
830 set tab [expr {$indent * 0.1}]i
831 newPara $tab -$tab
832 set state(sb) 80
833 setTabs $tab
834 formattedText $text
835 tab
836 }
837
838 # TPmacro --
839 #
840 # This procedure is invoked to handle ".TP" macros, which may take any
841 # of the following forms:
842 #
843 # .TP x Translate to an state(indent)ed state(paragraph) with the
844 # specified state(indent) (in 100 twip units).
845 # .TP Translate to an state(indent)ed state(paragraph) with
846 # default state(indent).
847 #
848 # Arguments:
849 # argList - List of arguments to the .IP macro.
850 #
851 # HTML limitations: 'x' in '.TP x' is ignored.
852
853 proc TPmacro {argList} {
854 global state
855 set length [llength $argList]
856 if {$length == 0} {
857 set val 0.5i
858 } else {
859 set val [expr {([lindex $argList 0] * 100.0)/1440}]i
860 }
861 newPara $val -$val
862 setTabs $val
863 set state(inTP) 1
864 set state(sb) 120
865 }
866
867
868 # THmacro --
869 #
870 # This procedure handles the .TH macro. It generates the non-scrolling
871 # header section for a given man page, and enters information into the
872 # table of contents. The .TH macro has the following form:
873 #
874 # .TH name section date footer header
875 #
876 # Arguments:
877 # argList - List of arguments to the .TH macro.
878
879 proc THmacro {argList} {
880 global file curPkg curSect curID id_keywords state curVer bitmap
881
882 if {[llength $argList] != 5} {
883 set args [join $argList " "]
884 puts stderr "Bad .TH macro: .TH $args"
885 }
886 incr curID
887 set name [lindex $argList 0] ;# Tcl_UpVar
888 set page [lindex $argList 1] ;# 3
889 set curVer [lindex $argList 2] ;# 7.4
890 set curPkg [lindex $argList 3] ;# Tcl
891 set curSect [lindex $argList 4] ;# {Tcl Library Procedures}
892
893 regsub -all {\\ } $curSect { } curSect ;# Clean up for [incr\ Tcl]
894
895 puts $file "#{\\footnote $curID}" ;# Context string
896 puts $file "\${\\footnote $name}" ;# Topic title
897 set browse "${curSect}${name}"
898 regsub -all {[ _-]} $browse {} browse
899 puts $file "+{\\footnote $browse}" ;# Browse sequence
900
901 # Suppress duplicates
902 foreach i $id_keywords($curID) {
903 set keys($i) 1
904 }
905 foreach i [array names keys] {
906 set i [string trim $i]
907 if {[string length $i] > 0} {
908 puts $file "K{\\footnote $i}" ;# Keyword strings
909 }
910 }
911 unset keys
912 puts $file "\\pard\\tx3000\\sb100\\sa100\\fs24\\keepn"
913 font B
914 text $name
915 tab
916 text $curSect
917 font R
918 if {[info exists bitmap]} {
919 # a right justified bitmap
920 puts $file "\\\{bmrt $bitmap\\\}"
921 }
922 puts $file "\\fs20"
923 set state(breakPending) -1
924 }
925
926 # nextPara --
927 #
928 # Set the indents for a new paragraph, and start a paragraph break
929 #
930 # Arguments:
931 # leftIndent - The new left margin for body lines.
932 # firstIndent - The offset from the left margin for the first line.
933
934 proc nextPara {leftIndent {firstIndent 0i}} {
935 global state
936 set state(leftIndent) [getTwips $leftIndent]
937 set state(firstIndent) [getTwips $firstIndent]
938 set state(paragraphPending) 1
939 }
940
941
942 # newPara --
943 #
944 # This procedure sets the left and hanging state(indent)s for a line.
945 # State(Indent)s are specified in units of inches or centimeters, and are
946 # relative to the current nesting level and left margin.
947 #
948 # Arguments:
949 # leftState(Indent) - The new left margin for lines after the first.
950 # firstState(Indent) - The new left margin for the first line of a state(paragraph).
951
952 proc newPara {leftIndent {firstIndent 0i}} {
953 global state file
954 if $state(paragraph) {
955 puts -nonewline $file "\\line\n"
956 }
957 if {$leftIndent ne ""} {
958 set state(leftIndent) [expr {$state(leftMargin) \
959 + ($state(offset) * $state(nestingLevel)) \
960 + [getTwips $leftIndent]}]
961 }
962 set state(firstIndent) [getTwips $firstIndent]
963 set state(paragraphPending) 1
964 }
965
966
967 # getTwips --
968 #
969 # This procedure converts a distance in inches or centimeters into
970 # twips (1/1440 of an inch).
971 #
972 # Arguments:
973 # arg - A number followed by "i" or "c"
974
975 proc getTwips {arg} {
976 if {[scan $arg "%f%s" distance units] != 2} {
977 puts stderr "bad distance \"$arg\""
978 return 0
979 }
980 if {[string length $units] > 1} {
981 puts stderr "additional characters after unit \"$arg\""
982 set units [string index $units 0]
983 }
984 switch -- $units {
985 c {
986 set distance [expr {$distance * 567}]
987 }
988 i {
989 set distance [expr {$distance * 1440}]
990 }
991 default {
992 puts stderr "bad units in distance \"$arg\""
993 return 0
994 }
995 }
996 return $distance
997 }
998
999 # incrNestingLevel --
1000 #
1001 # This procedure does the work of the .RS macro, which increments
1002 # the number of state(indent)ations that affect things like .PP.
1003 #
1004 # Arguments:
1005 # None.
1006
1007 proc incrNestingLevel {} {
1008 global state
1009
1010 incr state(nestingLevel)
1011 set oldp $state(paragraph)
1012 set state(paragraph) 0
1013 newPara 0i
1014 set state(paragraph) $oldp
1015 }
1016
1017 # decrNestingLevel --
1018 #
1019 # This procedure does the work of the .RE macro, which decrements
1020 # the number of indentations that affect things like .PP.
1021 #
1022 # Arguments:
1023 # None.
1024
1025 proc decrNestingLevel {} {
1026 global state
1027
1028 if {$state(nestingLevel) == 0} {
1029 puts stderr "Nesting level decremented below 0"
1030 } else {
1031 incr state(nestingLevel) -1
1032 }
1033 }