File: syntax_txt.tcl

package info (click to toggle)
espresso 6.7-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 311,068 kB
  • sloc: f90: 447,429; ansic: 52,566; sh: 40,631; xml: 37,561; tcl: 20,077; lisp: 5,923; makefile: 4,503; python: 4,379; perl: 1,219; cpp: 761; fortran: 618; java: 568; awk: 128
file content (318 lines) | stat: -rw-r--r-- 5,861 bytes parent folder | download | duplicates (7)
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318

proc ::helpdoc::syntaxAppend {txt} {
    variable syntax
    
    if { [info exists syntax(count)] } {
	append syntax(txt) " "	
    } else {
	set syntax(count) 0
    }
    append syntax(txt) $txt
    incr syntax(count)    
}


proc ::helpdoc::syntaxFlush {} {
    variable syntax
    variable fid
    
    if { [info exists syntax] } {
	printf $syntax(txt)
	unset syntax
    }
}


proc ::helpdoc::manageRow {{add 0}} {
    variable rows

    set diff -1
    if { [string is integer $rows(start)] && [string is integer $rows(end)] } {
	set diff [expr $rows(end) - $rows(start)]
    }

    if { $diff > 0 } {

	# numerical arguments ...

	if { $diff < $add } {
	    return
	} elseif { $add == 2 } {
	    if { $diff > $add } { append rows(text) ". . .\n" }
	    manageRow_ $rows(end)
	} else {
	    manageRow_ [expr $rows(start) + $add]
	}
    } else {
    
	# string arguments ...
	
	if { ! [string is integer $rows(start)] } {        
	    if { $add == 0 } {
		set index $rows(start)
	    } elseif { $add < 2 } {
		set index "$rows(start)+$add"
	    } else {
		set index "$rows(end)"
		append rows(text) ". . .\n"
	    }
	    manageRow_ $index

	} elseif { ! [string is integer $rows(end)] } {

	    if { $add == 0 } {
		set index $rows(start)
	    } elseif { $add < 2 } {
		if { [string is integer $rows(start)] } {
		    set index [expr $rows(start)+$add]
		} else {
		    set index "$rows(start)+$add"
		}
	    } else {
		set index "$rows(end)"
		append rows(text) ". . .\n"
	    }
	    manageRow_ $index
	}
    }
}


proc ::helpdoc::manageRow_ {index} {
    variable rows

    foreach field $rows(line) {
	switch -- $field {
	    __conditional::begin__ {
		append rows(text) "\[ "
	    }
	    __conditional::end__ {
		append rows(text) "\] "
	    }
	    __optional::begin__ - __optional::end__ {		
		append rows(text) "$field "
	    }       
	    default {
		append rows(text) "${field}(${index}) "
	    }
	}
    }
    append rows(text) "\n"
}


proc ::helpdoc::printRows {} {
    variable rows 

    # scan $rows(text) for width

    foreach line [split $rows(text) \n] {
	
	set count 0
	
	foreach field $line {
	    
	    if { $field == "__optional::begin__" } {
		set field \{
	    }
	    if { $field == "__optional::end__" } {		
		set field \}
	    }	      

	    set len [string length $field]
	    
	    if { ! [info exists max($count)] } {
		set max($count) $len
	    } else { 
		if { $len > $max($count) } {
		    set max($count) $len
		}
	    }

	    incr count
	}
    }

    # now print

    foreach line [split $rows(text) \n] {

	set pl ""
	set count 0

	foreach field $line {
	    if { $field == "__optional::begin__" } {
		set field \{
	    }
	    if { $field == "__optional::end__" } {		
		set field \}
	    }	      

	    if { $field == "." } {
		append pl ". "
	    } else {
		append pl [format "%-$max($count)s  " $field]
	    }
	    incr count
	}

	printf ${pl}
    }
}


proc ::helpdoc::manageCol {{add 0}} {
    variable cols

    set diff -1
    if { [string is integer $cols(start)] && [string is integer $cols(end)] } {
	set diff [expr $cols(end) - $cols(start)]
    }

    if { $diff > 0 } {

	# numerical arguments ...

	if { $diff < $add } {
	    return
	} elseif { $add < 2 } {
	    lappend cols(indices) [expr $cols(start) + $add]
	} elseif { $add == 2 } {
	    if { $diff > $add } { lappend cols(indices) "..." }
	    lappend cols(indices) $cols(end)
	}
    } else {
	
	# string arguments ...
	
	if { ! [string is integer $cols(start)] } {        
	    if { $add == 0 } {
		lappend cols(indices) $cols(start)
	    } elseif { $add < 2 } {
		lappend cols(indices) "$cols(start)+$add"
	    } elseif { $add == 2 } {
		lappend cols(indices) ... 
		lappend cols(indices) $cols(end)
	    }
	} elseif { ! [string is integer $cols(end)] } {
	    
	    if { $add == 0 } {
		lappend cols(indices) $cols(start)
	    } elseif { $add < 2 } {
		lappend cols(indices) [expr $cols(start)+$add]
	    } elseif { $add == 2 } {
		lappend cols(indices) ...
		lappend cols(indices) $cols(end)
	    }
	}
    }
}


proc ::helpdoc::printCols {} {
    variable cols 

    # scan for field-width

    set extra 0

    foreach row $cols(vline) {

	switch -- $row {
	    __conditional::begin__ - __optional::begin__ {		
		incr extra 
		continue
	    }
	     __conditional::end__ - __optional::end__ {
		 continue
	     }
	}
	    
	set count 0
	
	foreach ind $cols(indices) {
	    	    
	    if { ! [info exists max($count)] } {
		set max($count) [string length ${row}(${cols(start)})]
	    }
	    
	    set _len [string length ${row}(${ind})]
	    if { $_len > $max($count) } {
		set max($count) $_len
	    }
	    incr count	    
	}	
    }

    # now print

    set ct ""
    set fie 0
    set newline 0
    foreach row $cols(vline) {
	
	if { $extra } {	    
	    switch -- $row {
		__conditional::begin__ {
		    set cbe 1
		    continue
		}
		__conditional::end__ {
		    set cen 1
		    append ct "\] "
		    continue
		}
		__optional::begin__ {		
		    set obe 1
		    continue
		}
		__optional::end__ {		
		    set oen 1
		    append ct "\} "
		    continue
		}

		default {

		    if { [info exists obe] } { incr fie } 
		    if { [info exists cbe] } { incr fie }					    
		}
	    }
	}
	 	

	if { $newline } {
	    append ct \n
	}
	append ct [::textutil::blank [expr ($extra - $fie) * 2]]
	if { [info exists obe] } { append ct "\{ " } 
	if { [info exists cbe] } { append ct "\[ " }			
	
	set count 0

	foreach ind $cols(indices) {	    
	    if { $ind == "..." } {
		append ct ". . .  "
	    } else {
		append ct [format "%-$max($count)s  " ${row}(${ind})]	    
	    }
	    incr count
	}
	
	foreach var {obe oen cbe cen} {
	    if { [info exists $var] } {
		unset $var
	    }
	}

	set fie 0
	set newline 1
    }

    # must be here, if "en" is the last row ...
    if { [info exists oen] || [info exists cen] } {
	append ct \n
    }

    printf $ct
}