b311480e |
1 | # Copyright (c) 1999-2012 OPEN CASCADE SAS |
2 | # |
3 | # The content of this file is subject to the Open CASCADE Technology Public |
4 | # License Version 6.5 (the "License"). You may not use the content of this file |
5 | # except in compliance with the License. Please obtain a copy of the License |
6 | # at http://www.opencascade.org and read it completely before using this file. |
7 | # |
8 | # The Initial Developer of the Original Code is Open CASCADE S.A.S., having its |
9 | # main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. |
10 | # |
11 | # The Original Code and all software distributed under the License is |
12 | # distributed on an "AS IS" basis, without warranty of any kind, and the |
13 | # Initial Developer hereby disclaims all such warranties, including without |
14 | # limitation, any warranties of merchantability, fitness for a particular |
15 | # purpose or non-infringement. Please see the License for the specific terms |
16 | # and conditions governing the rights and limitations under the License. |
17 | |
7fd59977 |
18 | # |
19 | # Documentation.tcl |
20 | # |
21 | # TCL procedures to process documentation files |
22 | # |
23 | |
24 | |
25 | |
26 | # |
27 | # Read a file |
28 | |
29 | # The array subTitles binds the subTitles for each title (or empty list) |
30 | # The array texts binds the text for each title |
31 | # |
32 | # Titles are of the form {Title subTitle subTitle} |
33 | # |
34 | |
35 | proc readFile {filename} { |
36 | global subTitles texts |
37 | if {! [file readable $filename]} return |
38 | |
39 | foreach ar {subTitles texts} {if [info exists $ar] {unset $ar}} |
40 | set title "Top" |
41 | set stitle "Top" |
42 | set subTitles($stitle) {} |
43 | set level 1 |
44 | set f [open $filename r] |
45 | while {[gets $f line] >= 0} { |
46 | |
47 | if [regexp {^[ ]*(\*+)[ ]*(.*$)} $line dummy s t] { |
48 | |
49 | # it is a new title |
50 | set l [string length $s] |
51 | |
52 | # at a deepest level go down enough levels |
53 | while {$level < $l} { |
54 | set up($title) $stitle |
55 | set stitle $title |
56 | lappend title $t |
57 | incr level |
58 | } |
59 | |
60 | # at an upper level go up enough level |
61 | while {$level > $l} { |
62 | set title stitle |
63 | set stitle $up($stitle) |
64 | incr level -1 |
65 | } |
66 | |
67 | # at the current level |
68 | lappend subTitles($stitle) $t |
69 | set title [concat $stitle $t] |
70 | set texts($title) "" |
71 | |
72 | } else { |
73 | |
74 | # it is a line for the current title |
75 | lappend texts($title) $line |
76 | } |
77 | } |
78 | close $f |
79 | } |
80 | |
81 | # |
82 | # call on each title : titleProc title level |
83 | # call on each text : textProc text |
84 | |
85 | proc dump {titleProc textProc {title Top} {level 1}} { |
86 | global subTitles texts |
87 | if [info exists texts($title)] {$textProc $texts($title)} |
88 | if [info exists subTitles($title)] { |
89 | set l $level |
90 | incr l |
91 | foreach t $subTitles($title) { |
92 | $titleProc $t $level |
93 | dump $titleProc $textProc [concat $title $t] $l |
94 | } |
95 | } |
96 | } |
97 | |
98 | # cut a text into sections |
99 | # and call on each section : sectionProc section text |
100 | |
101 | proc sectionText {aText aSectionProc} { |
102 | set section "" |
103 | set text {} |
104 | foreach line $aText { |
105 | |
106 | if {[string index $line 0] == "."} { |
107 | |
108 | $aSectionProc $section $text |
109 | set section $line |
110 | set text {} |
111 | } else { |
112 | lappend text $line |
113 | } |
114 | } |
115 | $aSectionProc $section $text |
116 | } |
117 | |