Test for 0022778: Bug in BRepMesh
[occt.git] / src / DrawResources / tdoc
1 #!/bin/sh
2 # The next line is executed by /bin/sh, but not Tcl \
3   exec tclsh $0 ${1+"$@"}
4
5 source $env(DRAWHOME)/Documentation.tcl
6
7 #
8 # format a documentation for troff
9 #
10
11 # proc ot manage keeping of lines together
12 proc keep {} {
13     global theFile keeping
14     if {! $keeping} {
15         puts $theFile ".KS"
16     }
17     set keeping 1
18 }
19
20 proc endkeep {} {
21     global theFile keeping
22     if {$keeping} {
23         puts $theFile ".KE"
24     }
25     set keeping 0
26 }
27
28 proc troffTitle {title level} {
29     global theFile
30
31     endkeep
32
33     # set the header
34     puts $theFile ".ds LH $title"
35
36     # try to keep command titles with their synopsis
37     if {$level == 3} keep
38
39     puts $theFile ".NH $level"
40     puts $theFile $title
41     puts $theFile ".XS"
42     for {set i 1} {$i <= $level} {incr i} {puts -nonewline $theFile "  "}
43     puts $theFile $title
44     puts $theFile ".XE"
45 }
46
47 proc putText {aText} {
48     global theFile
49     foreach line $aText {
50         regsub -all {\\} $line "\\e" l
51         puts $theFile $l
52     }
53 }
54
55 proc troffSection {aSection aText} {
56     global theFile ExNumber fill
57
58     # check if text is empty
59     set empty 1
60     foreach line $aText {
61         if {![regexp {^[ \t]*$} $line]} {
62             set empty 0
63             break
64         }
65     }
66     if $empty return
67
68     if {$aSection == ""} {
69         if {$fill} {puts $theFile ".PP"} else {puts $theFile ".LD\n.R"}
70         putText $aText
71         if {! $fill} {puts $theFile ".DE"}
72         return
73     }
74
75     switch $aSection {
76                 
77         .Synopsis  {
78             puts $theFile ".LD\n.R"
79             putText $aText
80             puts $theFile ".DE"
81         }
82         
83         .Purpose   {
84             puts $theFile ".B Purpose\n.PP"
85             putText $aText
86             # Synopsis and purpose are kept with command title
87             endkeep
88         }
89         
90         .Example    {
91             endkeep
92             incr ExNumber
93             puts $theFile ".sp\n.B1\n.DS"         
94             for {set i 1} {$i <= 80} {incr i} {puts -nonewline $theFile " "}
95             puts $theFile " "
96             puts $theFile ".B \"Example $ExNumber\""
97             putText $aText
98             puts $theFile ".DE"
99             puts $theFile ".B2"
100         }
101         
102         ".See also" {
103             puts $theFile ".sp\n.B \"See also\"\n.PP"
104             putText $aText
105         }
106         
107         .Warning    {
108             puts $theFile ".sp\n.B Warnings\n.PP"
109             putText $aText
110         }
111         
112         .Text   {
113             if {$fill} {puts $theFile ".PP"} else {puts $theFile ".LD\n.R"}
114             putText $aText
115             if {! $fill} {puts $theFile ".DE"}
116         }
117         
118         .Index      {
119             foreach word $aText {
120                 if {$word != ""} {puts $theFile ".IX $word"}
121             }
122         }
123     }
124 }
125
126 proc troffText {aText} {
127         sectionText $aText troffSection
128 }
129
130 proc troff {} {
131     global theFile texts ExNumber title
132     set ExNumber 0
133
134     puts $theFile ".RP"
135     puts $theFile ".TL\n$title"
136     puts $theFile ".AU\nThe CAS.CADE Software Factory"
137     puts $theFile ".AI\nMatra-Datavision"
138
139     if [info exists texts(Top)] {
140         # Abstract
141         puts $theFile ".AB"
142         putText $texts(Top)
143         puts $theFile ".AE"
144         set text(Top) {}
145     }
146
147     # header and footer
148     puts $theFile ".ds CH "
149     puts $theFile ".ds RH $title"
150     puts $theFile ".ds CF -%-"
151     puts $theFile ".ds LF Copyright Matra-Datavision"
152
153     dump troffTitle troffText
154
155     puts $theFile ".ds RH Contents"
156     puts $theFile ".bp\n.TL\nTable of contents\n.PX no"
157 }
158
159 # compare without case, used for sorting the index
160 proc cmp {s1 s2} {
161     return [string compare [string tolower $s1] [string tolower $s2]]
162 }
163
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
167
168     set f [open $fileindex r]
169     set sindex {}
170     while {[gets $f line] >= 0} {
171         if [regexp {^(.*[^      ])[     ]*\.\.\. ([0-9]*)$} $line dummy word page] {
172             lappend sindex "$word $page"
173         }
174     }
175     close $f
176     set f [open $filetr w]
177     puts $f ".TL\nIndex"
178     puts $f ".2C\n.LD"
179     set letter ""
180     set count 0
181     foreach line [lsort -command cmp $sindex] {
182         set l [string toupper [string index $line 0]]
183         if {$l != $letter} {
184             set letter $l
185             puts $f "\n.KS\n.LG 2\n.B $letter\n.NL\n"
186             set count 0
187         }
188         puts $f $line
189         incr count
190         if {$count == 1} {puts $f ".KE"}
191     }
192     close $f
193 }
194
195 #
196 # process arguments
197 #
198
199 if {$argc < 1} {
200     puts "tdoc docfile title [nofill]"
201     puts "format a doc file for printing in postscript"
202     puts "if nofill text are not justified"
203     exit
204 }
205
206 set file   [lindex $argv 0]
207 set title  "CAS.CADE Documentation"
208 if {$argc > 1} {set title [lindex $argv 1]}
209 set fill 1
210 if {$argc > 2} {set fill 0}
211
212
213 if [file readable $file] {
214     readFile $file
215     set file [file rootname $file]
216     set filetr    F[pid]
217     set fileout   O[pid]
218     set fileindex I[pid]
219     set theFile [open $filetr w]
220     set keeping 0
221     troff
222     close $theFile
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"
230 } else {
231         puts "Cannot open $file for reading"
232 }