blob: f5c203209b0b5c4f0fb8946df68296855feb1b6c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
#!/bin/sh
# The next line is executed by /bin/sh, but not Tcl \
exec tclsh $0 ${1+"$@"}
source $env(DRAWHOME)/Documentation.tcl
#
# format a documentation for info
#
proc putText {aText} {
global theFile
foreach line $aText {puts $theFile $line}
}
proc infoSection {aSection aText} {
global theFile index theTitle
# check if text is empty
set empty 1
foreach line $aText {
if {![regexp {^[ \t]*$} $line]} {
set empty 0
break
}
}
if $empty return
if {$aSection == ""} {
putText $aText
return
}
switch $aSection {
.Synopsis {
puts $theFile "\nSYNOPSIS\n"
putText $aText
}
.Purpose {
puts $theFile "\nPURPOSE\n"
putText $aText
}
.Example {
puts $theFile "\nEXAMPLE\n"
putText $aText
}
".See also" {
puts $theFile "\nSEE ALSO\n"
putText $aText
}
.Warning {
puts $theFile "\nWARNINGS\n"
putText $aText
}
.Warning {
puts "\n"
putText $aText
}
.Text {
putText $aText
}
.Index {
foreach word $aText {
if {$word != ""} {
set index($word) $theTitle
}
}
}
}
}
proc dumpInfo {title ftitle up prev next} {
global theFile subTitles texts
global theTitle
if {![info exists texts($ftitle)] &&
![info exists subTitles($ftitle)]} return
set theTitle $title
puts $theFile ""
puts $theFile "Node: $title, Prev: $prev, Next: $next, Up: $up,"
puts $theFile ""
if [info exists texts($ftitle)] {
sectionText $texts($ftitle) infoSection
}
if [info exists subTitles($ftitle)] {
puts $theFile "\n\n* Menu:\n"
foreach t $subTitles($ftitle) {
puts $theFile "* $t::"
}
puts $theFile ""
set p ""
set l [lrange $subTitles($ftitle) 1 end]
foreach t $subTitles($ftitle) {
dumpInfo $t [concat $ftitle $t] $title $p [lindex $l 0]
set p $t
set l [lrange $l 1 end]
}
}
}
# compare without case, used for sorting the index
proc cmp {s1 s2} {
return [string compare [string tolower $s1] [string tolower $s2]]
}
proc dumpIndex {} {
global index theFile
puts $theFile ""
puts $theFile "Node: Index, Up: Top,"
puts $theFile ""
if [info exists index] {
set l 0
foreach word [array names index] {
set ll [string length $word]
if {$ll > $l} {set l $ll}
}
incr l 2
set letter ""
foreach word [lsort -command cmp [array names index]] {
puts -nonewline $theFile $word
for {set ll [string length $word]} {$ll < $l} {incr ll} {
puts -nonewline $theFile " "
}
puts $theFile "*Note $index($word)::"
}
}
}
#
# process arguments
#
if {$argc < 1} {
puts "idoc docfile upnode"
puts "create an info file form a doc file, upnode is the up node of Top"
exit
}
set file [lindex $argv 0]
set up ""
if {$argc > 1} {set up [lindex $argv 1]}
if [file readable $file] {
readFile $file
set file [file rootname $file]
# add a menu for the index
lappend subTitles(Top) Index
global theFile
set theFile [open $file.info "w"]
puts $theFile ""
dumpInfo Top Top $up "" ""
dumpIndex
close $theFile
puts "$file.info created"
} else {
puts "Cannot open $file for reading"
}
|