2 # The next line is executed by /bin/sh, but not Tcl \
3 exec tclsh $0 ${1+"$@"}
5 source $env(DRAWHOME)/Documentation.tcl
8 # format a documentation for troff
11 # proc ot manage keeping of lines together
13 global theFile keeping
21 global theFile keeping
28 proc troffTitle {title level} {
34 puts $theFile ".ds LH $title"
36 # try to keep command titles with their synopsis
39 puts $theFile ".NH $level"
42 for {set i 1} {$i <= $level} {incr i} {puts -nonewline $theFile " "}
47 proc putText {aText} {
50 regsub -all {\\} $line "\\e" l
55 proc troffSection {aSection aText} {
56 global theFile ExNumber fill
58 # check if text is empty
61 if {![regexp {^[ \t]*$} $line]} {
68 if {$aSection == ""} {
69 if {$fill} {puts $theFile ".PP"} else {puts $theFile ".LD\n.R"}
71 if {! $fill} {puts $theFile ".DE"}
78 puts $theFile ".LD\n.R"
84 puts $theFile ".B Purpose\n.PP"
86 # Synopsis and purpose are kept with command title
93 puts $theFile ".sp\n.B1\n.DS"
94 for {set i 1} {$i <= 80} {incr i} {puts -nonewline $theFile " "}
96 puts $theFile ".B \"Example $ExNumber\""
103 puts $theFile ".sp\n.B \"See also\"\n.PP"
108 puts $theFile ".sp\n.B Warnings\n.PP"
113 if {$fill} {puts $theFile ".PP"} else {puts $theFile ".LD\n.R"}
115 if {! $fill} {puts $theFile ".DE"}
119 foreach word $aText {
120 if {$word != ""} {puts $theFile ".IX $word"}
126 proc troffText {aText} {
127 sectionText $aText troffSection
131 global theFile texts ExNumber title
135 puts $theFile ".TL\n$title"
136 puts $theFile ".AU\nThe CAS.CADE Software Factory"
137 puts $theFile ".AI\nMatra-Datavision"
139 if [info exists texts(Top)] {
148 puts $theFile ".ds CH "
149 puts $theFile ".ds RH $title"
150 puts $theFile ".ds CF -%-"
151 puts $theFile ".ds LF Copyright Matra-Datavision"
153 dump troffTitle troffText
155 puts $theFile ".ds RH Contents"
156 puts $theFile ".bp\n.TL\nTable of contents\n.PX no"
159 # compare without case, used for sorting the index
161 return [string compare [string tolower $s1] [string tolower $s2]]
164 proc processIndex {fileindex filetr} {
165 # read the index file and create the index
166 # Try to keep together the letter an the first line
168 set f [open $fileindex r]
170 while {[gets $f line] >= 0} {
171 if [regexp {^(.*[^ ])[ ]*\.\.\. ([0-9]*)$} $line dummy word page] {
172 lappend sindex "$word $page"
176 set f [open $filetr w]
181 foreach line [lsort -command cmp $sindex] {
182 set l [string toupper [string index $line 0]]
185 puts $f "\n.KS\n.LG 2\n.B $letter\n.NL\n"
190 if {$count == 1} {puts $f ".KE"}
200 puts "tdoc docfile title [nofill]"
201 puts "format a doc file for printing in postscript"
202 puts "if nofill text are not justified"
206 set file [lindex $argv 0]
207 set title "CAS.CADE Documentation"
208 if {$argc > 1} {set title [lindex $argv 1]}
210 if {$argc > 2} {set fill 0}
213 if [file readable $file] {
215 set file [file rootname $file]
219 set theFile [open $filetr w]
223 exec troff -ms $filetr > $fileout 2> $fileindex
224 set fileindextr IT[pid]
225 processIndex $fileindex $fileindextr
226 exec troff -ms $fileindextr >> $fileout
227 exec /usr/lib/lp/postscript/dpost $fileout > $file.ps
228 exec rm -f $filetr $fileout $fileindex $fileindextr
229 puts "$file.ps created"
231 puts "Cannot open $file for reading"