1 2proc ::helpdoc::syntaxAppend {txt} { 3 variable syntax 4 5 if { [info exists syntax(count)] } { 6 append syntax(txt) " " 7 } else { 8 set syntax(count) 0 9 } 10 append syntax(txt) $txt 11 incr syntax(count) 12} 13 14 15proc ::helpdoc::syntaxFlush {} { 16 variable syntax 17 variable fid 18 19 if { [info exists syntax] } { 20 printf $syntax(txt) 21 unset syntax 22 } 23} 24 25 26proc ::helpdoc::manageRow {{add 0}} { 27 variable rows 28 29 set diff -1 30 if { [string is integer $rows(start)] && [string is integer $rows(end)] } { 31 set diff [expr $rows(end) - $rows(start)] 32 } 33 34 if { $diff > 0 } { 35 36 # numerical arguments ... 37 38 if { $diff < $add } { 39 return 40 } elseif { $add == 2 } { 41 if { $diff > $add } { append rows(text) ". . .\n" } 42 manageRow_ $rows(end) 43 } else { 44 manageRow_ [expr $rows(start) + $add] 45 } 46 } else { 47 48 # string arguments ... 49 50 if { ! [string is integer $rows(start)] } { 51 if { $add == 0 } { 52 set index $rows(start) 53 } elseif { $add < 2 } { 54 set index "$rows(start)+$add" 55 } else { 56 set index "$rows(end)" 57 append rows(text) ". . .\n" 58 } 59 manageRow_ $index 60 61 } elseif { ! [string is integer $rows(end)] } { 62 63 if { $add == 0 } { 64 set index $rows(start) 65 } elseif { $add < 2 } { 66 if { [string is integer $rows(start)] } { 67 set index [expr $rows(start)+$add] 68 } else { 69 set index "$rows(start)+$add" 70 } 71 } else { 72 set index "$rows(end)" 73 append rows(text) ". . .\n" 74 } 75 manageRow_ $index 76 } 77 } 78} 79 80 81proc ::helpdoc::manageRow_ {index} { 82 variable rows 83 84 foreach field $rows(line) { 85 switch -- $field { 86 __conditional::begin__ { 87 append rows(text) "\[ " 88 } 89 __conditional::end__ { 90 append rows(text) "\] " 91 } 92 __optional::begin__ - __optional::end__ { 93 append rows(text) "$field " 94 } 95 default { 96 append rows(text) "${field}(${index}) " 97 } 98 } 99 } 100 append rows(text) "\n" 101} 102 103 104proc ::helpdoc::printRows {} { 105 variable rows 106 107 # scan $rows(text) for width 108 109 foreach line [split $rows(text) \n] { 110 111 set count 0 112 113 foreach field $line { 114 115 if { $field == "__optional::begin__" } { 116 set field \{ 117 } 118 if { $field == "__optional::end__" } { 119 set field \} 120 } 121 122 set len [string length $field] 123 124 if { ! [info exists max($count)] } { 125 set max($count) $len 126 } else { 127 if { $len > $max($count) } { 128 set max($count) $len 129 } 130 } 131 132 incr count 133 } 134 } 135 136 # now print 137 138 foreach line [split $rows(text) \n] { 139 140 set pl "" 141 set count 0 142 143 foreach field $line { 144 if { $field == "__optional::begin__" } { 145 set field \{ 146 } 147 if { $field == "__optional::end__" } { 148 set field \} 149 } 150 151 if { $field == "." } { 152 append pl ". " 153 } else { 154 append pl [format "%-$max($count)s " $field] 155 } 156 incr count 157 } 158 159 printf ${pl} 160 } 161} 162 163 164proc ::helpdoc::manageCol {{add 0}} { 165 variable cols 166 167 set diff -1 168 if { [string is integer $cols(start)] && [string is integer $cols(end)] } { 169 set diff [expr $cols(end) - $cols(start)] 170 } 171 172 if { $diff > 0 } { 173 174 # numerical arguments ... 175 176 if { $diff < $add } { 177 return 178 } elseif { $add < 2 } { 179 lappend cols(indices) [expr $cols(start) + $add] 180 } elseif { $add == 2 } { 181 if { $diff > $add } { lappend cols(indices) "..." } 182 lappend cols(indices) $cols(end) 183 } 184 } else { 185 186 # string arguments ... 187 188 if { ! [string is integer $cols(start)] } { 189 if { $add == 0 } { 190 lappend cols(indices) $cols(start) 191 } elseif { $add < 2 } { 192 lappend cols(indices) "$cols(start)+$add" 193 } elseif { $add == 2 } { 194 lappend cols(indices) ... 195 lappend cols(indices) $cols(end) 196 } 197 } elseif { ! [string is integer $cols(end)] } { 198 199 if { $add == 0 } { 200 lappend cols(indices) $cols(start) 201 } elseif { $add < 2 } { 202 lappend cols(indices) [expr $cols(start)+$add] 203 } elseif { $add == 2 } { 204 lappend cols(indices) ... 205 lappend cols(indices) $cols(end) 206 } 207 } 208 } 209} 210 211 212proc ::helpdoc::printCols {} { 213 variable cols 214 215 # scan for field-width 216 217 set extra 0 218 219 foreach row $cols(vline) { 220 221 switch -- $row { 222 __conditional::begin__ - __optional::begin__ { 223 incr extra 224 continue 225 } 226 __conditional::end__ - __optional::end__ { 227 continue 228 } 229 } 230 231 set count 0 232 233 foreach ind $cols(indices) { 234 235 if { ! [info exists max($count)] } { 236 set max($count) [string length ${row}(${cols(start)})] 237 } 238 239 set _len [string length ${row}(${ind})] 240 if { $_len > $max($count) } { 241 set max($count) $_len 242 } 243 incr count 244 } 245 } 246 247 # now print 248 249 set ct "" 250 set fie 0 251 set newline 0 252 foreach row $cols(vline) { 253 254 if { $extra } { 255 switch -- $row { 256 __conditional::begin__ { 257 set cbe 1 258 continue 259 } 260 __conditional::end__ { 261 set cen 1 262 append ct "\] " 263 continue 264 } 265 __optional::begin__ { 266 set obe 1 267 continue 268 } 269 __optional::end__ { 270 set oen 1 271 append ct "\} " 272 continue 273 } 274 275 default { 276 277 if { [info exists obe] } { incr fie } 278 if { [info exists cbe] } { incr fie } 279 } 280 } 281 } 282 283 284 if { $newline } { 285 append ct \n 286 } 287 append ct [::textutil::blank [expr ($extra - $fie) * 2]] 288 if { [info exists obe] } { append ct "\{ " } 289 if { [info exists cbe] } { append ct "\[ " } 290 291 set count 0 292 293 foreach ind $cols(indices) { 294 if { $ind == "..." } { 295 append ct ". . . " 296 } else { 297 append ct [format "%-$max($count)s " ${row}(${ind})] 298 } 299 incr count 300 } 301 302 foreach var {obe oen cbe cen} { 303 if { [info exists $var] } { 304 unset $var 305 } 306 } 307 308 set fie 0 309 set newline 1 310 } 311 312 # must be here, if "en" is the last row ... 313 if { [info exists oen] || [info exists cen] } { 314 append ct \n 315 } 316 317 printf $ct 318} 319