| 1 |
## |
| 2 |
## Utility functions for Man->HTML converter. Note that these |
| 3 |
## functions are specifically intended to work with the format as used |
| 4 |
## by Tcl and Tk; they do not cope with arbitrary nroff markup. |
| 5 |
## |
| 6 |
## Copyright (c) 1995-1997 Roger E. Critchlow Jr |
| 7 |
## Copyright (c) 2004-2011 Donal K. Fellows |
| 8 |
|
| 9 |
set ::manual(report-level) 1 |
| 10 |
|
| 11 |
proc manerror {msg} { |
| 12 |
global manual |
| 13 |
set name {} |
| 14 |
set subj {} |
| 15 |
set procname [lindex [info level -1] 0] |
| 16 |
if {[info exists manual(name)]} { |
| 17 |
set name $manual(name) |
| 18 |
} |
| 19 |
if {[info exists manual(section)] && [string length $manual(section)]} { |
| 20 |
puts stderr "$name: $manual(section): $procname: $msg" |
| 21 |
} else { |
| 22 |
puts stderr "$name: $procname: $msg" |
| 23 |
} |
| 24 |
} |
| 25 |
|
| 26 |
proc manreport {level msg} { |
| 27 |
global manual |
| 28 |
if {$level < $manual(report-level)} { |
| 29 |
uplevel 1 [list manerror $msg] |
| 30 |
} |
| 31 |
} |
| 32 |
|
| 33 |
proc fatal {msg} { |
| 34 |
global manual |
| 35 |
uplevel 1 [list manerror $msg] |
| 36 |
exit 1 |
| 37 |
} |
| 38 |
|
| 39 |
## |
| 40 |
## templating |
| 41 |
## |
| 42 |
proc indexfile {} { |
| 43 |
if {[info exists ::TARGET] && $::TARGET eq "devsite"} { |
| 44 |
return "index.tml" |
| 45 |
} else { |
| 46 |
return "contents.htm" |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
proc copyright {copyright {level {}}} { |
| 51 |
# We don't actually generate a separate copyright page anymore |
| 52 |
#set page "${level}copyright.htm" |
| 53 |
#return "<A HREF=\"$page\">Copyright</A> © [htmlize-text [lrange $copyright 2 end]]" |
| 54 |
# obfuscate any email addresses that may appear in name |
| 55 |
set who [string map {@ (at)} [lrange $copyright 2 end]] |
| 56 |
return "Copyright © [htmlize-text $who]" |
| 57 |
} |
| 58 |
|
| 59 |
proc copyout {copyrights {level {}}} { |
| 60 |
set count 0 |
| 61 |
set out "<div class=\"copy\">" |
| 62 |
foreach c $copyrights { |
| 63 |
if {$count > 0} { |
| 64 |
append out <BR> |
| 65 |
} |
| 66 |
append out "[copyright $c $level]\n" |
| 67 |
incr count |
| 68 |
} |
| 69 |
append out "</div>" |
| 70 |
return $out |
| 71 |
} |
| 72 |
|
| 73 |
proc CSS {{level ""}} { |
| 74 |
return "<link rel=\"stylesheet\" href=\"${level}$::CSSFILE\" type=\"text/css\" media=\"all\">\n" |
| 75 |
} |
| 76 |
|
| 77 |
proc DOCTYPE {} { |
| 78 |
return "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">" |
| 79 |
} |
| 80 |
|
| 81 |
proc htmlhead {title header args} { |
| 82 |
set level "" |
| 83 |
if {[lindex $args end] eq "../[indexfile]"} { |
| 84 |
# XXX hack - assume same level for CSS file |
| 85 |
set level "../" |
| 86 |
} |
| 87 |
set out "[DOCTYPE]\n<HTML>\n<HEAD><TITLE>$title</TITLE>\n[CSS $level]</HEAD>\n" |
| 88 |
foreach {uptitle url} $args { |
| 89 |
set header "<a href=\"$url\">$uptitle</a> <small>></small> $header" |
| 90 |
} |
| 91 |
append out "<BODY><H2>$header</H2>" |
| 92 |
global manual |
| 93 |
if {[info exists manual(subheader)]} { |
| 94 |
set subs {} |
| 95 |
foreach {name subdir} $manual(subheader) { |
| 96 |
if {$name eq $title} { |
| 97 |
lappend subs $name |
| 98 |
} else { |
| 99 |
lappend subs "<A HREF=\"${level}$subdir/[indexfile]\">$name</A>" |
| 100 |
} |
| 101 |
} |
| 102 |
append out "\n<H3>[join $subs { | }]</H3>" |
| 103 |
} |
| 104 |
return $out |
| 105 |
} |
| 106 |
|
| 107 |
## |
| 108 |
## parsing |
| 109 |
## |
| 110 |
proc unquote arg { |
| 111 |
return [string map [list \" {}] $arg] |
| 112 |
} |
| 113 |
|
| 114 |
proc parse-directive {line codename restname} { |
| 115 |
upvar 1 $codename code $restname rest |
| 116 |
return [regexp {^(\.[.a-zA-Z0-9]*) *(.*)} $line all code rest] |
| 117 |
} |
| 118 |
|
| 119 |
proc htmlize-text {text {charmap {}}} { |
| 120 |
# contains some extras for use in nroff->html processing |
| 121 |
# build on the list passed in, if any |
| 122 |
lappend charmap \ |
| 123 |
"–" "–" \ |
| 124 |
{&} {&} \ |
| 125 |
{\\} "\" \ |
| 126 |
{\e} "\" \ |
| 127 |
{\ } { } \ |
| 128 |
{\|} { } \ |
| 129 |
{\0} { } \ |
| 130 |
\" {"} \ |
| 131 |
{<} {<} \ |
| 132 |
{>} {>} \ |
| 133 |
\u201C "“" \ |
| 134 |
\u201D "”" |
| 135 |
|
| 136 |
return [string map $charmap $text] |
| 137 |
} |
| 138 |
|
| 139 |
proc process-text {text} { |
| 140 |
global manual |
| 141 |
# preprocess text; note that this is an incomplete map, and will probably |
| 142 |
# need to have things added to it as the manuals expand to use them. |
| 143 |
set charmap [list \ |
| 144 |
{\&} "\t" \ |
| 145 |
{\%} {} \ |
| 146 |
"\\\n" "\n" \ |
| 147 |
{\(r!} "¡" \ |
| 148 |
{\(ct} "¢" \ |
| 149 |
{\(Po} "£" \ |
| 150 |
{\(Cs} "¤" \ |
| 151 |
{\(Ye} "¥" \ |
| 152 |
{\(bb} "¦" \ |
| 153 |
{\(sc} "§" \ |
| 154 |
{\(ad} "¨" \ |
| 155 |
{\(co} "©" \ |
| 156 |
{\(Of} "ª" \ |
| 157 |
{\(Fo} "«" \ |
| 158 |
{\(no} "¬" \ |
| 159 |
{\(rg} "®" \ |
| 160 |
{\(a-} "¯" \ |
| 161 |
{\(de} "°" \ |
| 162 |
{\(+-} "±" \ |
| 163 |
{\(S2} "²" \ |
| 164 |
{\(S3} "³" \ |
| 165 |
{\(aa} "´" \ |
| 166 |
{\(mc} "µ" \ |
| 167 |
{\(ps} "¶" \ |
| 168 |
{\(pc} "·" \ |
| 169 |
{\(ac} "¸" \ |
| 170 |
{\(S1} "¹" \ |
| 171 |
{\(Om} "º" \ |
| 172 |
{\(Fc} "»" \ |
| 173 |
{\(14} "¼" \ |
| 174 |
{\(12} "½" \ |
| 175 |
{\(34} "¾" \ |
| 176 |
{\(r?} "¿" \ |
| 177 |
{\(AE} "Æ" \ |
| 178 |
{\(-D} "Ð" \ |
| 179 |
{\(mu} "×" \ |
| 180 |
{\(TP} "Þ" \ |
| 181 |
{\(ss} "ß" \ |
| 182 |
{\(ae} "æ" \ |
| 183 |
{\(Sd} "ð" \ |
| 184 |
{\(di} "÷" \ |
| 185 |
{\(Tp} "þ" \ |
| 186 |
{\(em} "—" \ |
| 187 |
{\(en} "–" \ |
| 188 |
{\(fm} "′" \ |
| 189 |
{\(mi} "−" \ |
| 190 |
{\(.i} "ı" \ |
| 191 |
{\(.j} "ȷ" \ |
| 192 |
{\(Fn} "ƒ" \ |
| 193 |
{\(OE} "Œ" \ |
| 194 |
{\(oe} "œ" \ |
| 195 |
{\(IJ} "IJ" \ |
| 196 |
{\(ij} "ij" \ |
| 197 |
{\(<-} "<font size=\"+1\">←</font>" \ |
| 198 |
{\(->} "<font size=\"+1\">→</font>" \ |
| 199 |
{\(eu} "€" \ |
| 200 |
{\fP} {\fR} \ |
| 201 |
{\.} . \ |
| 202 |
{\(bu} "•" \ |
| 203 |
{\*(qo} "ô" \ |
| 204 |
] |
| 205 |
# This might make a few invalid mappings, but we don't use them |
| 206 |
foreach c {a c e g i l n o s t u y z A C E G I L N O S T U Y Z} { |
| 207 |
foreach {prefix suffix} { |
| 208 |
o ring / slash : uml ' acute ^ circ ` grave ~ tilde , cedil v caron |
| 209 |
} { |
| 210 |
lappend charmap "\\\[${prefix}${c}\]" "&${c}${suffix};" |
| 211 |
lappend charmap "\\(${prefix}${c}" "&${c}${suffix};" |
| 212 |
} |
| 213 |
} |
| 214 |
lappend charmap {\-\|\-} -- ; # two hyphens |
| 215 |
lappend charmap {\-} - ; # a hyphen |
| 216 |
|
| 217 |
set text [htmlize-text $text $charmap] |
| 218 |
# General quoted entity |
| 219 |
regsub -all {\\N'(\d+)'} $text "\\&#\\1;" text |
| 220 |
while {[string first "\\" $text] >= 0} { |
| 221 |
# C R |
| 222 |
if {[regsub {^([^\\]*)\\fC([^\\]*)\\fR(.*)$} $text \ |
| 223 |
{\1<TT>\2</TT>\3} text]} continue |
| 224 |
# B R |
| 225 |
if {[regsub {^([^\\]*)\\fB([^\\]*)\\fR(.*)$} $text \ |
| 226 |
{\1<B>\2</B>\3} text]} continue |
| 227 |
# B I |
| 228 |
if {[regsub {^([^\\]*)\\fB([^\\]*)\\fI(.*)$} $text \ |
| 229 |
{\1<B>\2</B>\\fI\3} text]} continue |
| 230 |
# I R |
| 231 |
if {[regsub {^([^\\]*)\\fI([^\\]*)\\fR(.*)$} $text \ |
| 232 |
{\1<I>\2</I>\3} text]} continue |
| 233 |
# I B |
| 234 |
if {[regsub {^([^\\]*)\\fI([^\\]*)\\fB(.*)$} $text \ |
| 235 |
{\1<I>\2</I>\\fB\3} text]} continue |
| 236 |
# B B, I I, R R |
| 237 |
if { |
| 238 |
[regsub {^([^\\]*)\\fB([^\\]*)\\fB(.*)$} $text \ |
| 239 |
{\1\\fB\2\3} ntext] |
| 240 |
|| [regsub {^([^\\]*)\\fI([^\\]*)\\fI(.*)$} $text \ |
| 241 |
{\1\\fI\2\3} ntext] |
| 242 |
|| [regsub {^([^\\]*)\\fR([^\\]*)\\fR(.*)$} $text \ |
| 243 |
{\1\\fR\2\3} ntext] |
| 244 |
} { |
| 245 |
manerror "impotent font change: $text" |
| 246 |
set text $ntext |
| 247 |
continue |
| 248 |
} |
| 249 |
# unrecognized |
| 250 |
manerror "uncaught backslash: $text" |
| 251 |
set text [string map [list "\\" "\"] $text] |
| 252 |
} |
| 253 |
return $text |
| 254 |
} |
| 255 |
|
| 256 |
## |
| 257 |
## pass 2 text input and matching |
| 258 |
## |
| 259 |
proc open-text {} { |
| 260 |
global manual |
| 261 |
set manual(text-length) [llength $manual(text)] |
| 262 |
set manual(text-pointer) 0 |
| 263 |
} |
| 264 |
|
| 265 |
proc more-text {} { |
| 266 |
global manual |
| 267 |
return [expr {$manual(text-pointer) < $manual(text-length)}] |
| 268 |
} |
| 269 |
|
| 270 |
proc next-text {} { |
| 271 |
global manual |
| 272 |
if {[more-text]} { |
| 273 |
set text [lindex $manual(text) $manual(text-pointer)] |
| 274 |
incr manual(text-pointer) |
| 275 |
return $text |
| 276 |
} |
| 277 |
manerror "read past end of text" |
| 278 |
error "fatal" |
| 279 |
} |
| 280 |
|
| 281 |
proc is-a-directive {line} { |
| 282 |
return [string match .* $line] |
| 283 |
} |
| 284 |
|
| 285 |
proc split-directive {line opname restname} { |
| 286 |
upvar 1 $opname op $restname rest |
| 287 |
set op [string range $line 0 2] |
| 288 |
set rest [string trim [string range $line 3 end]] |
| 289 |
} |
| 290 |
|
| 291 |
proc next-op-is {op restname} { |
| 292 |
global manual |
| 293 |
upvar 1 $restname rest |
| 294 |
if {[more-text]} { |
| 295 |
set text [lindex $manual(text) $manual(text-pointer)] |
| 296 |
if {[string equal -length 3 $text $op]} { |
| 297 |
set rest [string range $text 4 end] |
| 298 |
incr manual(text-pointer) |
| 299 |
return 1 |
| 300 |
} |
| 301 |
} |
| 302 |
return 0 |
| 303 |
} |
| 304 |
|
| 305 |
proc backup-text {n} { |
| 306 |
global manual |
| 307 |
if {$manual(text-pointer)-$n >= 0} { |
| 308 |
incr manual(text-pointer) -$n |
| 309 |
} |
| 310 |
} |
| 311 |
|
| 312 |
proc match-text args { |
| 313 |
global manual |
| 314 |
set nargs [llength $args] |
| 315 |
if {$manual(text-pointer) + $nargs > $manual(text-length)} { |
| 316 |
return 0 |
| 317 |
} |
| 318 |
set nback 0 |
| 319 |
foreach arg $args { |
| 320 |
if {![more-text]} { |
| 321 |
backup-text $nback |
| 322 |
return 0 |
| 323 |
} |
| 324 |
set arg [string trim $arg] |
| 325 |
set targ [string trim [lindex $manual(text) $manual(text-pointer)]] |
| 326 |
if {$arg eq $targ} { |
| 327 |
incr nback |
| 328 |
incr manual(text-pointer) |
| 329 |
continue |
| 330 |
} |
| 331 |
if {[regexp {^@(\w+)$} $arg all name]} { |
| 332 |
upvar 1 $name var |
| 333 |
set var $targ |
| 334 |
incr nback |
| 335 |
incr manual(text-pointer) |
| 336 |
continue |
| 337 |
} |
| 338 |
if {[regexp -nocase {^(\.[A-Z][A-Z])@(\w+)$} $arg all op name]\ |
| 339 |
&& [string equal $op [lindex $targ 0]]} { |
| 340 |
upvar 1 $name var |
| 341 |
set var [lrange $targ 1 end] |
| 342 |
incr nback |
| 343 |
incr manual(text-pointer) |
| 344 |
continue |
| 345 |
} |
| 346 |
backup-text $nback |
| 347 |
return 0 |
| 348 |
} |
| 349 |
return 1 |
| 350 |
} |
| 351 |
|
| 352 |
proc expand-next-text {n} { |
| 353 |
global manual |
| 354 |
return [join [lrange $manual(text) $manual(text-pointer) \ |
| 355 |
[expr {$manual(text-pointer)+$n-1}]] \n\n] |
| 356 |
} |
| 357 |
|
| 358 |
## |
| 359 |
## pass 2 output |
| 360 |
## |
| 361 |
proc man-puts {text} { |
| 362 |
global manual |
| 363 |
lappend manual(output-$manual(wing-file)-$manual(name)) $text |
| 364 |
} |
| 365 |
|
| 366 |
## |
| 367 |
## build hypertext links to tables of contents |
| 368 |
## |
| 369 |
proc long-toc {text} { |
| 370 |
global manual |
| 371 |
set here M[incr manual(section-toc-n)] |
| 372 |
set manual($manual(name)-id-$text) $here |
| 373 |
set there L[incr manual(long-toc-n)] |
| 374 |
lappend manual(section-toc) \ |
| 375 |
"<DD><A HREF=\"$manual(name).htm#$here\" NAME=\"$there\">$text</A>" |
| 376 |
return "<A NAME=\"$here\">$text</A>" |
| 377 |
} |
| 378 |
|
| 379 |
proc option-toc {name class switch} { |
| 380 |
global manual |
| 381 |
# Special case handling, oh we hate it but must do it |
| 382 |
if {[string match "*OPTIONS" $manual(section)]} { |
| 383 |
if {$manual(name) ne "ttk_widget" && ($manual(name) ne "ttk_entry" || |
| 384 |
![string match validate* $name])} { |
| 385 |
# link the defined option into the long table of contents |
| 386 |
set link [long-toc "$switch, $name, $class"] |
| 387 |
regsub -- "$switch, $name, $class" $link "$switch" link |
| 388 |
return $link |
| 389 |
} |
| 390 |
} elseif {"$manual(name):$manual(section)" ne "options:DESCRIPTION"} { |
| 391 |
error "option-toc in $manual(name) section $manual(section)" |
| 392 |
} |
| 393 |
|
| 394 |
# link the defined standard option to the long table of contents and make |
| 395 |
# a target for the standard option references from other man pages. |
| 396 |
|
| 397 |
set first [lindex $switch 0] |
| 398 |
set here M$first |
| 399 |
set there L[incr manual(long-toc-n)] |
| 400 |
set manual(standard-option-$manual(name)-$first) \ |
| 401 |
"<A HREF=\"$manual(name).htm#$here\">$switch, $name, $class</A>" |
| 402 |
lappend manual(section-toc) \ |
| 403 |
"<DD><A HREF=\"$manual(name).htm#$here\" NAME=\"$there\">$switch, $name, $class</A>" |
| 404 |
return "<A NAME=\"$here\">$switch</A>" |
| 405 |
} |
| 406 |
|
| 407 |
proc std-option-toc {name page} { |
| 408 |
global manual |
| 409 |
if {[info exists manual(standard-option-$page-$name)]} { |
| 410 |
lappend manual(section-toc) <DD>$manual(standard-option-$page-$name) |
| 411 |
return $manual(standard-option-$page-$name) |
| 412 |
} |
| 413 |
manerror "missing reference to \"$name\" in $page.n" |
| 414 |
set here M[incr manual(section-toc-n)] |
| 415 |
set there L[incr manual(long-toc-n)] |
| 416 |
set other M$name |
| 417 |
lappend manual(section-toc) "<DD><A HREF=\"$page.htm#$other\">$name</A>" |
| 418 |
return "<A HREF=\"$page.htm#$other\">$name</A>" |
| 419 |
} |
| 420 |
|
| 421 |
## |
| 422 |
## process the widget option section |
| 423 |
## in widget and options man pages |
| 424 |
## |
| 425 |
proc output-widget-options {rest} { |
| 426 |
global manual |
| 427 |
man-puts <DL> |
| 428 |
lappend manual(section-toc) <DL> |
| 429 |
backup-text 1 |
| 430 |
set para {} |
| 431 |
while {[next-op-is .OP rest]} { |
| 432 |
switch -exact -- [llength $rest] { |
| 433 |
3 { |
| 434 |
lassign $rest switch name class |
| 435 |
} |
| 436 |
5 { |
| 437 |
set switch [lrange $rest 0 2] |
| 438 |
set name [lindex $rest 3] |
| 439 |
set class [lindex $rest 4] |
| 440 |
} |
| 441 |
default { |
| 442 |
fatal "bad .OP $rest" |
| 443 |
} |
| 444 |
} |
| 445 |
if {![regexp {^(<.>)([-\w ]+)(</.>)$} $switch \ |
| 446 |
all oswitch switch cswitch]} { |
| 447 |
if {![regexp {^(<.>)([-\w ]+) or ([-\w ]+)(</.>)$} $switch \ |
| 448 |
all oswitch switch1 switch2 cswitch]} { |
| 449 |
error "not Switch: $switch" |
| 450 |
} |
| 451 |
set switch "$switch1$cswitch or $oswitch$switch2" |
| 452 |
} |
| 453 |
if {![regexp {^(<.>)([\w]*)(</.>)$} $name all oname name cname]} { |
| 454 |
error "not Name: $name" |
| 455 |
} |
| 456 |
if {![regexp {^(<.>)([\w]*)(</.>)$} $class all oclass class cclass]} { |
| 457 |
error "not Class: $class" |
| 458 |
} |
| 459 |
man-puts "$para<DT>Command-Line Name: $oswitch[option-toc $name $class $switch]$cswitch" |
| 460 |
man-puts "<DT>Database Name: $oname$name$cname" |
| 461 |
man-puts "<DT>Database Class: $oclass$class$cclass" |
| 462 |
man-puts <DD>[next-text] |
| 463 |
set para <P> |
| 464 |
|
| 465 |
if {[next-op-is .RS rest]} { |
| 466 |
while {[more-text]} { |
| 467 |
set line [next-text] |
| 468 |
if {[is-a-directive $line]} { |
| 469 |
split-directive $line code rest |
| 470 |
switch -exact -- $code { |
| 471 |
.RE { |
| 472 |
break |
| 473 |
} |
| 474 |
.SH - .SS { |
| 475 |
manerror "unbalanced .RS at section end" |
| 476 |
backup-text 1 |
| 477 |
break |
| 478 |
} |
| 479 |
default { |
| 480 |
output-directive $line |
| 481 |
} |
| 482 |
} |
| 483 |
} else { |
| 484 |
man-puts $line |
| 485 |
} |
| 486 |
} |
| 487 |
} |
| 488 |
} |
| 489 |
man-puts </DL> |
| 490 |
lappend manual(section-toc) </DL> |
| 491 |
} |
| 492 |
|
| 493 |
## |
| 494 |
## process .RS lists |
| 495 |
## |
| 496 |
proc output-RS-list {} { |
| 497 |
global manual |
| 498 |
if {[next-op-is .IP rest]} { |
| 499 |
output-IP-list .RS .IP $rest |
| 500 |
if {[match-text .RE .sp .RS @rest .IP @rest2]} { |
| 501 |
man-puts <P>$rest |
| 502 |
output-IP-list .RS .IP $rest2 |
| 503 |
} |
| 504 |
if {[match-text .RE .sp .RS @rest .RE]} { |
| 505 |
man-puts <P>$rest |
| 506 |
return |
| 507 |
} |
| 508 |
if {[next-op-is .RE rest]} { |
| 509 |
return |
| 510 |
} |
| 511 |
} |
| 512 |
man-puts <DL><DD> |
| 513 |
while {[more-text]} { |
| 514 |
set line [next-text] |
| 515 |
if {[is-a-directive $line]} { |
| 516 |
split-directive $line code rest |
| 517 |
switch -exact -- $code { |
| 518 |
.RE { |
| 519 |
break |
| 520 |
} |
| 521 |
.SH - .SS { |
| 522 |
manerror "unbalanced .RS at section end" |
| 523 |
backup-text 1 |
| 524 |
break |
| 525 |
} |
| 526 |
default { |
| 527 |
output-directive $line |
| 528 |
} |
| 529 |
} |
| 530 |
} else { |
| 531 |
man-puts $line |
| 532 |
} |
| 533 |
} |
| 534 |
man-puts </DL> |
| 535 |
} |
| 536 |
|
| 537 |
## |
| 538 |
## process .IP lists which may be plain indents, |
| 539 |
## numeric lists, or definition lists |
| 540 |
## |
| 541 |
proc output-IP-list {context code rest} { |
| 542 |
global manual |
| 543 |
if {![string length $rest]} { |
| 544 |
# blank label, plain indent, no contents entry |
| 545 |
man-puts <DL><DD> |
| 546 |
while {[more-text]} { |
| 547 |
set line [next-text] |
| 548 |
if {[is-a-directive $line]} { |
| 549 |
split-directive $line code rest |
| 550 |
if {$code eq ".IP" && $rest eq {}} { |
| 551 |
man-puts "<P>" |
| 552 |
continue |
| 553 |
} |
| 554 |
if {$code in {.br .DS .RS}} { |
| 555 |
output-directive $line |
| 556 |
} else { |
| 557 |
backup-text 1 |
| 558 |
break |
| 559 |
} |
| 560 |
} else { |
| 561 |
man-puts $line |
| 562 |
} |
| 563 |
} |
| 564 |
man-puts </DL> |
| 565 |
} else { |
| 566 |
# labelled list, make contents |
| 567 |
if {$context ne ".SH" && $context ne ".SS"} { |
| 568 |
man-puts <P> |
| 569 |
} |
| 570 |
set dl "<DL class=\"[string tolower $manual(section)]\">" |
| 571 |
set enddl "</DL>" |
| 572 |
if {$code eq ".IP"} { |
| 573 |
if {[regexp {^\[[\da-f]+\]|\(?[\da-f]+\)$} $rest]} { |
| 574 |
set dl "<OL class=\"[string tolower $manual(section)]\">" |
| 575 |
set enddl "</OL>" |
| 576 |
} elseif {"•" eq $rest} { |
| 577 |
set dl "<UL class=\"[string tolower $manual(section)]\">" |
| 578 |
set enddl "</UL>" |
| 579 |
} |
| 580 |
} |
| 581 |
man-puts $dl |
| 582 |
lappend manual(section-toc) $dl |
| 583 |
backup-text 1 |
| 584 |
set accept_RE 0 |
| 585 |
set para {} |
| 586 |
while {[more-text]} { |
| 587 |
set line [next-text] |
| 588 |
if {[is-a-directive $line]} { |
| 589 |
split-directive $line code rest |
| 590 |
switch -exact -- $code { |
| 591 |
.IP { |
| 592 |
if {$accept_RE} { |
| 593 |
output-IP-list .IP $code $rest |
| 594 |
continue |
| 595 |
} |
| 596 |
if {$manual(section) eq "ARGUMENTS"} { |
| 597 |
man-puts "$para<DT>$rest<DD>" |
| 598 |
} elseif {[regexp {^\[([\da-f]+)\]$} $rest -> value]} { |
| 599 |
man-puts "$para<LI value=\"$value\">" |
| 600 |
} elseif {[regexp {^\(?([\da-f]+)\)$} $rest -> value]} { |
| 601 |
man-puts "$para<LI value=\"$value\">" |
| 602 |
} elseif {"•" eq $rest} { |
| 603 |
man-puts "$para<LI>" |
| 604 |
} else { |
| 605 |
man-puts "$para<DT>[long-toc $rest]<DD>" |
| 606 |
} |
| 607 |
} |
| 608 |
.sp - .br - .DS - .CS { |
| 609 |
output-directive $line |
| 610 |
} |
| 611 |
.RS { |
| 612 |
if {[match-text .RS]} { |
| 613 |
output-directive $line |
| 614 |
incr accept_RE 1 |
| 615 |
} elseif {[match-text .CS]} { |
| 616 |
output-directive .CS |
| 617 |
incr accept_RE 1 |
| 618 |
} elseif {[match-text .PP]} { |
| 619 |
output-directive .PP |
| 620 |
incr accept_RE 1 |
| 621 |
} elseif {[match-text .DS]} { |
| 622 |
output-directive .DS |
| 623 |
incr accept_RE 1 |
| 624 |
} else { |
| 625 |
output-directive $line |
| 626 |
} |
| 627 |
} |
| 628 |
.PP { |
| 629 |
if {[match-text @rest1 .br @rest2 .RS]} { |
| 630 |
# yet another nroff kludge as above |
| 631 |
man-puts "$para<DT>[long-toc $rest1]" |
| 632 |
man-puts "<DT>[long-toc $rest2]<DD>" |
| 633 |
incr accept_RE 1 |
| 634 |
} elseif {[match-text @rest .RE]} { |
| 635 |
# gad, this is getting ridiculous |
| 636 |
if {!$accept_RE} { |
| 637 |
man-puts "$enddl<P>$rest$dl" |
| 638 |
backup-text 1 |
| 639 |
set para {} |
| 640 |
break |
| 641 |
} |
| 642 |
man-puts "<P>$rest" |
| 643 |
incr accept_RE -1 |
| 644 |
} elseif {$accept_RE} { |
| 645 |
output-directive $line |
| 646 |
} else { |
| 647 |
backup-text 1 |
| 648 |
break |
| 649 |
} |
| 650 |
} |
| 651 |
.RE { |
| 652 |
if {!$accept_RE} { |
| 653 |
backup-text 1 |
| 654 |
break |
| 655 |
} |
| 656 |
incr accept_RE -1 |
| 657 |
} |
| 658 |
default { |
| 659 |
backup-text 1 |
| 660 |
break |
| 661 |
} |
| 662 |
} |
| 663 |
} else { |
| 664 |
man-puts $line |
| 665 |
} |
| 666 |
set para <P> |
| 667 |
} |
| 668 |
man-puts "$para$enddl" |
| 669 |
lappend manual(section-toc) $enddl |
| 670 |
if {$accept_RE} { |
| 671 |
manerror "missing .RE in output-IP-list" |
| 672 |
} |
| 673 |
} |
| 674 |
} |
| 675 |
|
| 676 |
## |
| 677 |
## handle the NAME section lines |
| 678 |
## there's only one line in the NAME section, |
| 679 |
## consisting of a comma separated list of names, |
| 680 |
## followed by a hyphen and a short description. |
| 681 |
## |
| 682 |
proc output-name {line} { |
| 683 |
global manual |
| 684 |
# split name line into pieces |
| 685 |
regexp {^([^-]+) - (.*)$} [regsub -all {[ \n\r\t]+} $line " "] -> head tail |
| 686 |
# output line to manual page untouched |
| 687 |
man-puts "$head — $tail" |
| 688 |
# output line to long table of contents |
| 689 |
lappend manual(section-toc) "<DL><DD>$head — $tail</DD></DL>" |
| 690 |
# separate out the names for future reference |
| 691 |
foreach name [split $head ,] { |
| 692 |
set name [string trim $name] |
| 693 |
if {[llength $name] > 1} { |
| 694 |
manerror "name has a space: {$name}\nfrom: $line" |
| 695 |
} |
| 696 |
lappend manual(wing-toc) $name |
| 697 |
lappend manual(name-$name) $manual(wing-file)/$manual(name) |
| 698 |
} |
| 699 |
set manual(tooltip-$manual(wing-file)/$manual(name).htm) $line |
| 700 |
} |
| 701 |
|
| 702 |
## |
| 703 |
## build a cross-reference link if appropriate |
| 704 |
## |
| 705 |
proc cross-reference {ref} { |
| 706 |
global manual remap_link_target |
| 707 |
global ensemble_commands exclude_refs_map exclude_when_followed_by_map |
| 708 |
set manname $manual(name) |
| 709 |
set mantail $manual(tail) |
| 710 |
if {[string match "Tcl_*" $ref] || [string match "Tk_*" $ref] || [string match "Ttk_*" $ref] || [string match "Itcl_*" $ref] || [string match "Tdbc_*" $ref]} { |
| 711 |
regexp {^\w+} $ref lref |
| 712 |
## |
| 713 |
## apply a link remapping if available |
| 714 |
## |
| 715 |
if {[info exists remap_link_target($lref)]} { |
| 716 |
set lref $remap_link_target($lref) |
| 717 |
} |
| 718 |
} elseif {$ref eq "Tcl"} { |
| 719 |
set lref $ref |
| 720 |
} elseif { |
| 721 |
[regexp {^[A-Z0-9 ?!]+$} $ref] |
| 722 |
&& [info exists manual($manname-id-$ref)] |
| 723 |
} { |
| 724 |
return "<A HREF=\"#$manual($manname-id-$ref)\">$ref</A>" |
| 725 |
} else { |
| 726 |
set lref [string tolower $ref] |
| 727 |
## |
| 728 |
## apply a link remapping if available |
| 729 |
## |
| 730 |
if {[info exists remap_link_target($lref)]} { |
| 731 |
set lref $remap_link_target($lref) |
| 732 |
} |
| 733 |
} |
| 734 |
## |
| 735 |
## nothing to reference |
| 736 |
## |
| 737 |
if {![info exists manual(name-$lref)]} { |
| 738 |
foreach name $ensemble_commands { |
| 739 |
if { |
| 740 |
[regexp "^$name \[a-z0-9]*\$" $lref] && |
| 741 |
[info exists manual(name-$name)] && |
| 742 |
$mantail ne "$name.n" && |
| 743 |
(![info exists exclude_refs_map($mantail)] || |
| 744 |
$manual(name-$name) ni $exclude_refs_map($mantail)) |
| 745 |
} { |
| 746 |
return "<A HREF=\"../$manual(name-$name).htm\">$ref</A>" |
| 747 |
} |
| 748 |
} |
| 749 |
if {$lref in {end}} { |
| 750 |
# no good place to send this tcl token? |
| 751 |
} |
| 752 |
return $ref |
| 753 |
} |
| 754 |
set manref $manual(name-$lref) |
| 755 |
## |
| 756 |
## would be a self reference |
| 757 |
## |
| 758 |
foreach name $manref { |
| 759 |
if {"$manual(wing-file)/$manname" in $name} { |
| 760 |
return $ref |
| 761 |
} |
| 762 |
} |
| 763 |
## |
| 764 |
## multiple choices for reference |
| 765 |
## |
| 766 |
if {[llength $manref] > 1} { |
| 767 |
set tcl_i [lsearch -glob $manref *TclCmd*] |
| 768 |
if {$tcl_i >= 0 && $manual(wing-file) eq "TclCmd" |
| 769 |
|| $manual(wing-file) eq "TclLib"} { |
| 770 |
set tcl_ref [lindex $manref $tcl_i] |
| 771 |
return "<A HREF=\"../$tcl_ref.htm\">$ref</A>" |
| 772 |
} |
| 773 |
set tk_i [lsearch -glob $manref *TkCmd*] |
| 774 |
if {$tk_i >= 0 && $manual(wing-file) eq "TkCmd" |
| 775 |
|| $manual(wing-file) eq "TkLib"} { |
| 776 |
set tk_ref [lindex $manref $tk_i] |
| 777 |
return "<A HREF=\"../$tk_ref.htm\">$ref</A>" |
| 778 |
} |
| 779 |
if {$lref eq "exit" && $mantail eq "tclsh.1" && $tcl_i >= 0} { |
| 780 |
set tcl_ref [lindex $manref $tcl_i] |
| 781 |
return "<A HREF=\"../$tcl_ref.htm\">$ref</A>" |
| 782 |
} |
| 783 |
puts stderr "multiple cross reference to $ref in $manref from $manual(wing-file)/$mantail" |
| 784 |
return $ref |
| 785 |
} |
| 786 |
## |
| 787 |
## exceptions, sigh, to the rule |
| 788 |
## |
| 789 |
if {[info exists exclude_when_followed_by_map($mantail)]} { |
| 790 |
upvar 1 text tail |
| 791 |
set following_word [lindex [regexp -inline {\S+} $tail] 0] |
| 792 |
foreach {this that} $exclude_when_followed_by_map($mantail) { |
| 793 |
# only a ref if $this is not followed by $that |
| 794 |
if {$lref eq $this && [string match $that* $following_word]} { |
| 795 |
return $ref |
| 796 |
} |
| 797 |
} |
| 798 |
} |
| 799 |
if { |
| 800 |
[info exists exclude_refs_map($mantail)] |
| 801 |
&& $lref in $exclude_refs_map($mantail) |
| 802 |
} { |
| 803 |
return $ref |
| 804 |
} |
| 805 |
## |
| 806 |
## return the cross reference |
| 807 |
## |
| 808 |
return "<A HREF=\"../$manref.htm\">$ref</A>" |
| 809 |
} |
| 810 |
|
| 811 |
## |
| 812 |
## reference generation errors |
| 813 |
## |
| 814 |
proc reference-error {msg text} { |
| 815 |
global manual |
| 816 |
puts stderr "$manual(tail): $msg: {$text}" |
| 817 |
return $text |
| 818 |
} |
| 819 |
|
| 820 |
## |
| 821 |
## insert as many cross references into this text string as are appropriate |
| 822 |
## |
| 823 |
proc insert-cross-references {text} { |
| 824 |
global manual |
| 825 |
set result "" |
| 826 |
|
| 827 |
while 1 { |
| 828 |
## |
| 829 |
## we identify cross references by: |
| 830 |
## ``quotation'' |
| 831 |
## <B>emboldening</B> |
| 832 |
## Tcl_ prefix |
| 833 |
## Tk_ prefix |
| 834 |
## [a-zA-Z0-9]+ manual entry |
| 835 |
## and we avoid messing with already anchored text |
| 836 |
## |
| 837 |
## |
| 838 |
## find where each item lives - EXPENSIVE - and accumulate a list |
| 839 |
## |
| 840 |
unset -nocomplain offsets |
| 841 |
foreach {name pattern} { |
| 842 |
anchor {<A } end-anchor {</A>} |
| 843 |
quote {``} end-quote {''} |
| 844 |
bold {<B>} end-bold {</B>} |
| 845 |
c.tcl {Tcl_} |
| 846 |
c.tk {Tk_} |
| 847 |
c.ttk {Ttk_} |
| 848 |
c.tdbc {Tdbc_} |
| 849 |
c.itcl {Itcl_} |
| 850 |
Tcl1 {Tcl manual entry} |
| 851 |
Tcl2 {Tcl overview manual entry} |
| 852 |
url {http://} |
| 853 |
} { |
| 854 |
set o [string first $pattern $text] |
| 855 |
if {[set offset($name) $o] >= 0} { |
| 856 |
set invert($o) $name |
| 857 |
lappend offsets $o |
| 858 |
} |
| 859 |
} |
| 860 |
## |
| 861 |
## if nothing, then we're done. |
| 862 |
## |
| 863 |
if {![info exists offsets]} { |
| 864 |
return [append result $text] |
| 865 |
} |
| 866 |
## |
| 867 |
## sort the offsets |
| 868 |
## |
| 869 |
set offsets [lsort -integer $offsets] |
| 870 |
## |
| 871 |
## see which we want to use |
| 872 |
## |
| 873 |
switch -exact -- $invert([lindex $offsets 0]) { |
| 874 |
anchor { |
| 875 |
if {$offset(end-anchor) < 0} { |
| 876 |
return [reference-error {Missing end anchor} $text] |
| 877 |
} |
| 878 |
append result [string range $text 0 $offset(end-anchor)] |
| 879 |
set text [string range $text[set text ""] \ |
| 880 |
[expr {$offset(end-anchor)+1}] end] |
| 881 |
continue |
| 882 |
} |
| 883 |
quote { |
| 884 |
if {$offset(end-quote) < 0} { |
| 885 |
return [reference-error "Missing end quote" $text] |
| 886 |
} |
| 887 |
if {$invert([lindex $offsets 1]) in {tcl tk ttk}} { |
| 888 |
set offsets [lreplace $offsets 1 1] |
| 889 |
} |
| 890 |
switch -exact -- $invert([lindex $offsets 1]) { |
| 891 |
end-quote { |
| 892 |
if {$offset(quote) > 0} { |
| 893 |
append result [string range $text 0 [expr {$offset(quote)-1}]] |
| 894 |
} |
| 895 |
set body [string range $text [expr {$offset(quote)+2}] \ |
| 896 |
[expr {$offset(end-quote)-1}]] |
| 897 |
set text [string range $text[set text ""] \ |
| 898 |
[expr {$offset(end-quote)+2}] end] |
| 899 |
append result `` [cross-reference $body] '' |
| 900 |
continue |
| 901 |
} |
| 902 |
bold - anchor { |
| 903 |
append result [string range $text \ |
| 904 |
0 [expr {$offset(end-quote)+1}]] |
| 905 |
set text [string range $text[set text ""] \ |
| 906 |
[expr {$offset(end-quote)+2}] end] |
| 907 |
continue |
| 908 |
} |
| 909 |
} |
| 910 |
return [reference-error "Uncaught quote case" $text] |
| 911 |
} |
| 912 |
bold { |
| 913 |
if {$offset(end-bold) < 0} { |
| 914 |
return [append result $text] |
| 915 |
} |
| 916 |
if {[string match "c.*" $invert([lindex $offsets 1])]} { |
| 917 |
set offsets [lreplace $offsets 1 1] |
| 918 |
} |
| 919 |
switch -exact -- $invert([lindex $offsets 1]) { |
| 920 |
url - end-bold { |
| 921 |
if {$offset(bold) > 0} { |
| 922 |
append result \ |
| 923 |
[string range $text 0 [expr {$offset(bold)-1}]] |
| 924 |
} |
| 925 |
set body [string range $text [expr {$offset(bold)+3}] \ |
| 926 |
[expr {$offset(end-bold)-1}]] |
| 927 |
set text [string range $text[set text ""] \ |
| 928 |
[expr {$offset(end-bold)+4}] end] |
| 929 |
regsub {http://[\w/.-]+} $body {<A HREF="&">&</A>} body |
| 930 |
append result <B> [cross-reference $body] </B> |
| 931 |
continue |
| 932 |
} |
| 933 |
anchor { |
| 934 |
append result \ |
| 935 |
[string range $text 0 [expr {$offset(end-bold)+3}]] |
| 936 |
set text [string range $text[set text ""] \ |
| 937 |
[expr {$offset(end-bold)+4}] end] |
| 938 |
continue |
| 939 |
} |
| 940 |
default { |
| 941 |
return [reference-error "Uncaught bold case" $text] |
| 942 |
} |
| 943 |
} |
| 944 |
} |
| 945 |
c.tk - c.ttk - c.tcl - c.tdbc - c.itcl { |
| 946 |
if {[lindex $offsets 0] > 0} { |
| 947 |
append result [string range $text 0 \ |
| 948 |
[expr {[lindex $offsets 0]-1}]] |
| 949 |
} |
| 950 |
regexp -indices -start [lindex $offsets 0] {\w+} $text range |
| 951 |
set body [string range $text {*}$range] |
| 952 |
set text [string range $text[set text ""] \ |
| 953 |
[expr {[lindex $range 1]+1}] end] |
| 954 |
append result [cross-reference $body] |
| 955 |
continue |
| 956 |
} |
| 957 |
Tcl1 - Tcl2 { |
| 958 |
set off [lindex $offsets 0] |
| 959 |
if {$off > 0} { |
| 960 |
append result [string range $text 0 [expr {$off-1}]] |
| 961 |
} |
| 962 |
set text [string range $text[set text ""] [expr {$off+3}] end] |
| 963 |
append result [cross-reference Tcl] |
| 964 |
continue |
| 965 |
} |
| 966 |
url { |
| 967 |
set off [lindex $offsets 0] |
| 968 |
if {$off > 0} { |
| 969 |
append result [string range $text 0 [expr {$off-1}]] |
| 970 |
} |
| 971 |
regexp -indices -start $off {http://[\w/.-]+} $text range |
| 972 |
set url [string range $text {*}$range] |
| 973 |
append result "<A HREF=\"[string trimright $url .]\">$url</A>" |
| 974 |
set text [string range $text[set text ""] \ |
| 975 |
[expr {[lindex $range 1]+1}] end] |
| 976 |
continue |
| 977 |
} |
| 978 |
end-anchor - end-bold - end-quote { |
| 979 |
return [reference-error "Out of place $invert([lindex $offsets 0])" $text] |
| 980 |
} |
| 981 |
} |
| 982 |
} |
| 983 |
} |
| 984 |
|
| 985 |
## |
| 986 |
## process formatting directives |
| 987 |
## |
| 988 |
proc output-directive {line} { |
| 989 |
global manual |
| 990 |
# process format directive |
| 991 |
split-directive $line code rest |
| 992 |
switch -exact -- $code { |
| 993 |
.BS - .BE { |
| 994 |
# man-puts <HR> |
| 995 |
} |
| 996 |
.SH - .SS { |
| 997 |
# drain any open lists |
| 998 |
# announce the subject |
| 999 |
set manual(section) $rest |
| 1000 |
# start our own stack of stuff |
| 1001 |
set manual($manual(name)-$manual(section)) {} |
| 1002 |
lappend manual(has-$manual(section)) $manual(name) |
| 1003 |
if {$code ne ".SS"} { |
| 1004 |
man-puts "<H3>[long-toc $manual(section)]</H3>" |
| 1005 |
} else { |
| 1006 |
man-puts "<H4>[long-toc $manual(section)]</H4>" |
| 1007 |
} |
| 1008 |
# some sections can simply free wheel their way through the text |
| 1009 |
# some sections can be processed in their own loops |
| 1010 |
switch -exact -- [string index $code end]:$manual(section) { |
| 1011 |
H:NAME { |
| 1012 |
set names {} |
| 1013 |
while {1} { |
| 1014 |
set line [next-text] |
| 1015 |
if {[is-a-directive $line]} { |
| 1016 |
backup-text 1 |
| 1017 |
if {[llength $names]} { |
| 1018 |
output-name [join $names { }] |
| 1019 |
} |
| 1020 |
return |
| 1021 |
} |
| 1022 |
lappend names [string trim $line] |
| 1023 |
} |
| 1024 |
} |
| 1025 |
H:SYNOPSIS { |
| 1026 |
lappend manual(section-toc) <DL> |
| 1027 |
while {1} { |
| 1028 |
if { |
| 1029 |
[next-op-is .nf rest] |
| 1030 |
|| [next-op-is .br rest] |
| 1031 |
|| [next-op-is .fi rest] |
| 1032 |
} { |
| 1033 |
continue |
| 1034 |
} |
| 1035 |
if { |
| 1036 |
[next-op-is .SH rest] |
| 1037 |
|| [next-op-is .SS rest] |
| 1038 |
|| [next-op-is .BE rest] |
| 1039 |
|| [next-op-is .SO rest] |
| 1040 |
} { |
| 1041 |
backup-text 1 |
| 1042 |
break |
| 1043 |
} |
| 1044 |
if {[next-op-is .sp rest]} { |
| 1045 |
#man-puts <P> |
| 1046 |
continue |
| 1047 |
} |
| 1048 |
set more [next-text] |
| 1049 |
if {[is-a-directive $more]} { |
| 1050 |
manerror "in SYNOPSIS found $more" |
| 1051 |
backup-text 1 |
| 1052 |
break |
| 1053 |
} |
| 1054 |
foreach more [split $more \n] { |
| 1055 |
regexp {^(\s*)(.*)} $more -> spaces more |
| 1056 |
set spaces [string map {" " " "} $spaces] |
| 1057 |
if {[string length $spaces]} { |
| 1058 |
set spaces <TT>$spaces</TT> |
| 1059 |
} |
| 1060 |
man-puts $spaces$more<BR> |
| 1061 |
if {$manual(wing-file) in {TclLib TkLib}} { |
| 1062 |
lappend manual(section-toc) <DD>$more |
| 1063 |
} |
| 1064 |
} |
| 1065 |
} |
| 1066 |
lappend manual(section-toc) </DL> |
| 1067 |
return |
| 1068 |
} |
| 1069 |
{H:SEE ALSO} { |
| 1070 |
while {[more-text]} { |
| 1071 |
if {[next-op-is .SH rest] || [next-op-is .SS rest]} { |
| 1072 |
backup-text 1 |
| 1073 |
return |
| 1074 |
} |
| 1075 |
set more [next-text] |
| 1076 |
if {[is-a-directive $more]} { |
| 1077 |
manerror "$more" |
| 1078 |
backup-text 1 |
| 1079 |
return |
| 1080 |
} |
| 1081 |
set nmore {} |
| 1082 |
foreach cr [split $more ,] { |
| 1083 |
set cr [string trim $cr] |
| 1084 |
if {![regexp {^<B>.*</B>$} $cr]} { |
| 1085 |
set cr <B>$cr</B> |
| 1086 |
} |
| 1087 |
if {[regexp {^<B>(.*)\([13n]\)</B>$} $cr all name]} { |
| 1088 |
set cr <B>$name</B> |
| 1089 |
} |
| 1090 |
lappend nmore $cr |
| 1091 |
} |
| 1092 |
man-puts [join $nmore {, }] |
| 1093 |
} |
| 1094 |
return |
| 1095 |
} |
| 1096 |
H:KEYWORDS { |
| 1097 |
while {[more-text]} { |
| 1098 |
if {[next-op-is .SH rest] || [next-op-is .SS rest]} { |
| 1099 |
backup-text 1 |
| 1100 |
return |
| 1101 |
} |
| 1102 |
set more [next-text] |
| 1103 |
if {[is-a-directive $more]} { |
| 1104 |
manerror "$more" |
| 1105 |
backup-text 1 |
| 1106 |
return |
| 1107 |
} |
| 1108 |
set keys {} |
| 1109 |
foreach key [split $more ,] { |
| 1110 |
set key [string trim $key] |
| 1111 |
lappend manual(keyword-$key) [list $manual(name) \ |
| 1112 |
$manual(wing-file)/$manual(name).htm] |
| 1113 |
set initial [string toupper [string index $key 0]] |
| 1114 |
lappend keys "<A href=\"../Keywords/$initial.htm\#$key\">$key</A>" |
| 1115 |
} |
| 1116 |
man-puts [join $keys {, }] |
| 1117 |
} |
| 1118 |
return |
| 1119 |
} |
| 1120 |
} |
| 1121 |
if {[next-op-is .IP rest]} { |
| 1122 |
output-IP-list $code .IP $rest |
| 1123 |
return |
| 1124 |
} |
| 1125 |
if {[next-op-is .PP rest]} { |
| 1126 |
return |
| 1127 |
} |
| 1128 |
return |
| 1129 |
} |
| 1130 |
.SO { |
| 1131 |
# When there's a sequence of multiple .SO chunks, process into one |
| 1132 |
set optslist {} |
| 1133 |
while 1 { |
| 1134 |
if {[match-text @stuff .SE]} { |
| 1135 |
foreach opt [split $stuff \n\t] { |
| 1136 |
lappend optslist [list $opt $rest] |
| 1137 |
} |
| 1138 |
} else { |
| 1139 |
manerror "unexpected .SO format:\n[expand-next-text 2]" |
| 1140 |
} |
| 1141 |
if {![next-op-is .SO rest]} { |
| 1142 |
break |
| 1143 |
} |
| 1144 |
} |
| 1145 |
output-directive {.SH STANDARD OPTIONS} |
| 1146 |
man-puts <DL> |
| 1147 |
lappend manual(section-toc) <DL> |
| 1148 |
foreach optionpair [lsort -dictionary -index 0 $optslist] { |
| 1149 |
lassign $optionpair option targetPage |
| 1150 |
man-puts "<DT><B>[std-option-toc $option $targetPage]</B>" |
| 1151 |
} |
| 1152 |
man-puts </DL> |
| 1153 |
lappend manual(section-toc) </DL> |
| 1154 |
} |
| 1155 |
.OP { |
| 1156 |
output-widget-options $rest |
| 1157 |
return |
| 1158 |
} |
| 1159 |
.IP { |
| 1160 |
output-IP-list .IP .IP $rest |
| 1161 |
return |
| 1162 |
} |
| 1163 |
.PP - .sp { |
| 1164 |
man-puts <P> |
| 1165 |
} |
| 1166 |
.RS { |
| 1167 |
output-RS-list |
| 1168 |
return |
| 1169 |
} |
| 1170 |
.br { |
| 1171 |
man-puts <BR> |
| 1172 |
return |
| 1173 |
} |
| 1174 |
.DS { |
| 1175 |
if {[next-op-is .ta rest]} { |
| 1176 |
# skip the leading .ta directive if it is there |
| 1177 |
} |
| 1178 |
if {[match-text @stuff .DE]} { |
| 1179 |
set td "<td><p class=\"tablecell\">" |
| 1180 |
set bodyText [string map [list \n <tr>$td \t $td] \n$stuff] |
| 1181 |
man-puts "<dl><dd><table border=\"0\">$bodyText</table></dl>" |
| 1182 |
#man-puts <PRE>$stuff</PRE> |
| 1183 |
} elseif {[match-text .fi @ul1 @ul2 .nf @stuff .DE]} { |
| 1184 |
man-puts "<PRE>[lindex $ul1 1][lindex $ul2 1]\n$stuff</PRE>" |
| 1185 |
} else { |
| 1186 |
manerror "unexpected .DS format:\n[expand-next-text 2]" |
| 1187 |
} |
| 1188 |
return |
| 1189 |
} |
| 1190 |
.CS { |
| 1191 |
if {[next-op-is .ta rest]} { |
| 1192 |
# ??? |
| 1193 |
} |
| 1194 |
if {[match-text @stuff .CE]} { |
| 1195 |
man-puts <PRE>$stuff</PRE> |
| 1196 |
} else { |
| 1197 |
manerror "unexpected .CS format:\n[expand-next-text 2]" |
| 1198 |
} |
| 1199 |
return |
| 1200 |
} |
| 1201 |
.nf { |
| 1202 |
if {[match-text @more .fi]} { |
| 1203 |
foreach more [split $more \n] { |
| 1204 |
man-puts $more<BR> |
| 1205 |
} |
| 1206 |
} elseif {[match-text .RS @more .RE .fi]} { |
| 1207 |
man-puts <DL><DD> |
| 1208 |
foreach more [split $more \n] { |
| 1209 |
man-puts $more<BR> |
| 1210 |
} |
| 1211 |
man-puts </DL> |
| 1212 |
} elseif {[match-text .RS @more .RS @more2 .RE .RE .fi]} { |
| 1213 |
man-puts <DL><DD> |
| 1214 |
foreach more [split $more \n] { |
| 1215 |
man-puts $more<BR> |
| 1216 |
} |
| 1217 |
man-puts <DL><DD> |
| 1218 |
foreach more2 [split $more2 \n] { |
| 1219 |
man-puts $more2<BR> |
| 1220 |
} |
| 1221 |
man-puts </DL></DL> |
| 1222 |
} elseif {[match-text .RS @more .RS @more2 .RE @more3 .RE .fi]} { |
| 1223 |
man-puts <DL><DD> |
| 1224 |
foreach more [split $more \n] { |
| 1225 |
man-puts $more<BR> |
| 1226 |
} |
| 1227 |
man-puts <DL><DD> |
| 1228 |
foreach more2 [split $more2 \n] { |
| 1229 |
man-puts $more2<BR> |
| 1230 |
} |
| 1231 |
man-puts </DL><DD> |
| 1232 |
foreach more3 [split $more3 \n] { |
| 1233 |
man-puts $more3<BR> |
| 1234 |
} |
| 1235 |
man-puts </DL> |
| 1236 |
} elseif {[match-text .sp .RS @more .RS @more2 .sp .RE .RE .fi]} { |
| 1237 |
man-puts <P><DL><DD> |
| 1238 |
foreach more [split $more \n] { |
| 1239 |
man-puts $more<BR> |
| 1240 |
} |
| 1241 |
man-puts <DL><DD> |
| 1242 |
foreach more2 [split $more2 \n] { |
| 1243 |
man-puts $more2<BR> |
| 1244 |
} |
| 1245 |
man-puts </DL></DL><P> |
| 1246 |
} elseif {[match-text .RS .sp @more .sp .RE .fi]} { |
| 1247 |
man-puts <P><DL><DD> |
| 1248 |
foreach more [split $more \n] { |
| 1249 |
man-puts $more<BR> |
| 1250 |
} |
| 1251 |
man-puts </DL><P> |
| 1252 |
} else { |
| 1253 |
manerror "ignoring $line" |
| 1254 |
} |
| 1255 |
} |
| 1256 |
.RE - .DE - .CE { |
| 1257 |
manerror "unexpected $code" |
| 1258 |
return |
| 1259 |
} |
| 1260 |
.ta - .fi - .na - .ad - .UL - .ie - .el - .ne { |
| 1261 |
manerror "ignoring $line" |
| 1262 |
} |
| 1263 |
default { |
| 1264 |
manerror "unrecognized format directive: $line" |
| 1265 |
} |
| 1266 |
} |
| 1267 |
} |
| 1268 |
|
| 1269 |
## |
| 1270 |
## merge copyright listings |
| 1271 |
## |
| 1272 |
proc merge-copyrights {l1 l2} { |
| 1273 |
set merge {} |
| 1274 |
set re1 {^Copyright +(?:\(c\)|\\\(co|©) +(\w.*?)(?:all rights reserved)?(?:\. )*$} |
| 1275 |
set re2 {^(\d+) +(?:by +)?(\w.*)$} ;# date who |
| 1276 |
set re3 {^(\d+)-(\d+) +(?:by +)?(\w.*)$} ;# from to who |
| 1277 |
set re4 {^(\d+), *(\d+) +(?:by +)?(\w.*)$} ;# date1 date2 who |
| 1278 |
foreach copyright [concat $l1 $l2] { |
| 1279 |
if {[regexp -nocase -- $re1 $copyright -> info]} { |
| 1280 |
set info [string trimright $info ". "] ; # remove extra period |
| 1281 |
if {[regexp -- $re2 $info -> date who]} { |
| 1282 |
lappend dates($who) $date |
| 1283 |
continue |
| 1284 |
} elseif {[regexp -- $re3 $info -> from to who]} { |
| 1285 |
for {set date $from} {$date <= $to} {incr date} { |
| 1286 |
lappend dates($who) $date |
| 1287 |
} |
| 1288 |
continue |
| 1289 |
} elseif {[regexp -- $re3 $info -> date1 date2 who]} { |
| 1290 |
lappend dates($who) $date1 $date2 |
| 1291 |
continue |
| 1292 |
} |
| 1293 |
} |
| 1294 |
puts "oops: $copyright" |
| 1295 |
} |
| 1296 |
foreach who [array names dates] { |
| 1297 |
set list [lsort -dictionary $dates($who)] |
| 1298 |
if {[llength $list] == 1 || [lindex $list 0] eq [lrange $list end end]} { |
| 1299 |
lappend merge "Copyright © [lindex $list 0] $who" |
| 1300 |
} else { |
| 1301 |
lappend merge "Copyright © [lindex $list 0]-[lrange $list end end] $who" |
| 1302 |
} |
| 1303 |
} |
| 1304 |
return [lsort -dictionary $merge] |
| 1305 |
} |
| 1306 |
|
| 1307 |
## |
| 1308 |
## foreach of the man pages in the section specified by |
| 1309 |
## sectionDescriptor, convert manpages into hypertext in |
| 1310 |
## the directory specified by outputDir. |
| 1311 |
## |
| 1312 |
proc make-manpage-section {outputDir sectionDescriptor} { |
| 1313 |
global manual overall_title tcltkdesc verbose |
| 1314 |
global excluded_pages forced_index_pages process_first_patterns |
| 1315 |
|
| 1316 |
set LQ \u201C |
| 1317 |
set RQ \u201D |
| 1318 |
|
| 1319 |
lassign $sectionDescriptor \ |
| 1320 |
manual(wing-glob) \ |
| 1321 |
manual(wing-name) \ |
| 1322 |
manual(wing-file) \ |
| 1323 |
manual(wing-description) |
| 1324 |
set manual(wing-copyrights) {} |
| 1325 |
makedirhier $outputDir/$manual(wing-file) |
| 1326 |
set manual(wing-toc-fp) [open $outputDir/$manual(wing-file)/[indexfile] w] |
| 1327 |
fconfigure $manual(wing-toc-fp) -translation lf -encoding utf-8 |
| 1328 |
# whistle |
| 1329 |
puts stderr "scanning section $manual(wing-name)" |
| 1330 |
# put the entry for this section into the short table of contents |
| 1331 |
if {[regexp {^(.+), version (.+)$} $manual(wing-name) -> name version]} { |
| 1332 |
puts $manual(short-toc-fp) "<DT><A HREF=\"$manual(wing-file)/[indexfile]\" TITLE=\"version $version\">$name</A></DT><DD>$manual(wing-description)</DD>" |
| 1333 |
} else { |
| 1334 |
puts $manual(short-toc-fp) "<DT><A HREF=\"$manual(wing-file)/[indexfile]\">$manual(wing-name)</A></DT><DD>$manual(wing-description)</DD>" |
| 1335 |
} |
| 1336 |
# initialize the wing table of contents |
| 1337 |
puts $manual(wing-toc-fp) [htmlhead $manual(wing-name) \ |
| 1338 |
$manual(wing-name) $overall_title "../[indexfile]"] |
| 1339 |
# initialize the short table of contents for this section |
| 1340 |
set manual(wing-toc) {} |
| 1341 |
# initialize the man directory for this section |
| 1342 |
makedirhier $outputDir/$manual(wing-file) |
| 1343 |
# initialize the long table of contents for this section |
| 1344 |
set manual(long-toc-n) 1 |
| 1345 |
# get the manual pages for this section |
| 1346 |
set manual(pages) [lsort -dictionary [glob -nocomplain $manual(wing-glob)]] |
| 1347 |
# Some pages have to go first so that their links override others |
| 1348 |
foreach pat $process_first_patterns { |
| 1349 |
set n [lsearch -glob $manual(pages) $pat] |
| 1350 |
if {$n >= 0} { |
| 1351 |
set f [lindex $manual(pages) $n] |
| 1352 |
puts stderr "shuffling [file tail $f] to front of processing queue" |
| 1353 |
set manual(pages) \ |
| 1354 |
[linsert [lreplace $manual(pages) $n $n] 0 $f] |
| 1355 |
} |
| 1356 |
} |
| 1357 |
# set manual(pages) [lrange $manual(pages) 0 5] |
| 1358 |
foreach manual_page $manual(pages) { |
| 1359 |
set manual(page) [file normalize $manual_page] |
| 1360 |
# whistle |
| 1361 |
if {$verbose} { |
| 1362 |
puts stderr "scanning page $manual(page)" |
| 1363 |
} else { |
| 1364 |
puts -nonewline stderr . |
| 1365 |
} |
| 1366 |
set manual(tail) [file tail $manual(page)] |
| 1367 |
set manual(name) [file root $manual(tail)] |
| 1368 |
set manual(section) {} |
| 1369 |
if {$manual(name) in $excluded_pages} { |
| 1370 |
# obsolete |
| 1371 |
if {!$verbose} { |
| 1372 |
puts stderr "" |
| 1373 |
} |
| 1374 |
manerror "discarding $manual(name)" |
| 1375 |
continue |
| 1376 |
} |
| 1377 |
set manual(infp) [open $manual(page)] |
| 1378 |
fconfigure $manual(infp) -encoding utf-8 |
| 1379 |
set manual(text) {} |
| 1380 |
set manual(partial-text) {} |
| 1381 |
foreach p {.RS .DS .CS .SO} { |
| 1382 |
set manual($p) 0 |
| 1383 |
} |
| 1384 |
set manual(stack) {} |
| 1385 |
set manual(section) {} |
| 1386 |
set manual(section-toc) {} |
| 1387 |
set manual(section-toc-n) 1 |
| 1388 |
set manual(copyrights) {} |
| 1389 |
lappend manual(all-pages) $manual(wing-file)/$manual(tail) |
| 1390 |
lappend manual(all-page-domains) $manual(wing-name) |
| 1391 |
manreport 100 $manual(name) |
| 1392 |
while {[gets $manual(infp) line] >= 0} { |
| 1393 |
manreport 100 $line |
| 1394 |
if {[regexp {^[`'][/\\]} $line]} { |
| 1395 |
if {[regexp {Copyright (?:\(c\)|\\\(co).*$} $line copyright]} { |
| 1396 |
lappend manual(copyrights) $copyright |
| 1397 |
} |
| 1398 |
# comment |
| 1399 |
continue |
| 1400 |
} |
| 1401 |
if {"$line" eq {'}} { |
| 1402 |
# comment |
| 1403 |
continue |
| 1404 |
} |
| 1405 |
if {![parse-directive $line code rest]} { |
| 1406 |
addbuffer $line |
| 1407 |
continue |
| 1408 |
} |
| 1409 |
switch -exact -- $code { |
| 1410 |
.if - .nr - .ti - .in - .ie - .el - |
| 1411 |
.ad - .na - .so - .ne - .AS - .HS - .VE - .VS - . { |
| 1412 |
# ignore |
| 1413 |
continue |
| 1414 |
} |
| 1415 |
} |
| 1416 |
switch -exact -- $code { |
| 1417 |
.SH - .SS { |
| 1418 |
flushbuffer |
| 1419 |
if {[llength $rest] == 0} { |
| 1420 |
gets $manual(infp) rest |
| 1421 |
} |
| 1422 |
lappend manual(text) "$code [unquote $rest]" |
| 1423 |
} |
| 1424 |
.TH { |
| 1425 |
flushbuffer |
| 1426 |
lappend manual(text) "$code [unquote $rest]" |
| 1427 |
} |
| 1428 |
.QW { |
| 1429 |
lassign [regexp -all -inline {\"(?:[^""]+)\"|\S+} $rest] \ |
| 1430 |
inQuote afterwards |
| 1431 |
addbuffer $LQ [unquote $inQuote] $RQ [unquote $afterwards] |
| 1432 |
} |
| 1433 |
.PQ { |
| 1434 |
lassign [regexp -all -inline {\"(?:[^""]+)\"|\S+} $rest] \ |
| 1435 |
inQuote punctuation afterwards |
| 1436 |
addbuffer ( $LQ [unquote $inQuote] $RQ \ |
| 1437 |
[unquote $punctuation] ) [unquote $afterwards] |
| 1438 |
} |
| 1439 |
.QR { |
| 1440 |
lassign [regexp -all -inline {\"(?:[^""]+)\"|\S+} $rest] \ |
| 1441 |
rangeFrom rangeTo afterwards |
| 1442 |
addbuffer $LQ [unquote $rangeFrom] "–" \ |
| 1443 |
[unquote $rangeTo] $RQ [unquote $afterwards] |
| 1444 |
} |
| 1445 |
.MT { |
| 1446 |
addbuffer $LQ$RQ |
| 1447 |
} |
| 1448 |
.HS - .UL - .ta { |
| 1449 |
flushbuffer |
| 1450 |
lappend manual(text) "$code [unquote $rest]" |
| 1451 |
} |
| 1452 |
.BS - .BE - .br - .fi - .sp - .nf { |
| 1453 |
flushbuffer |
| 1454 |
if {$rest ne ""} { |
| 1455 |
if {!$verbose} { |
| 1456 |
puts stderr "" |
| 1457 |
} |
| 1458 |
manerror "unexpected argument: $line" |
| 1459 |
} |
| 1460 |
lappend manual(text) $code |
| 1461 |
} |
| 1462 |
.AP { |
| 1463 |
flushbuffer |
| 1464 |
lappend manual(text) [concat .IP [process-text \ |
| 1465 |
"[lindex $rest 0] \\fB[lindex $rest 1]\\fR ([lindex $rest 2])"]] |
| 1466 |
} |
| 1467 |
.IP { |
| 1468 |
flushbuffer |
| 1469 |
regexp {^(.*) +\d+$} $rest all rest |
| 1470 |
lappend manual(text) ".IP [process-text \ |
| 1471 |
[unquote [string trim $rest]]]" |
| 1472 |
} |
| 1473 |
.TP { |
| 1474 |
flushbuffer |
| 1475 |
while {[is-a-directive [set next [gets $manual(infp)]]]} { |
| 1476 |
if {!$verbose} { |
| 1477 |
puts stderr "" |
| 1478 |
} |
| 1479 |
manerror "ignoring $next after .TP" |
| 1480 |
} |
| 1481 |
if {"$next" ne {'}} { |
| 1482 |
lappend manual(text) ".IP [process-text $next]" |
| 1483 |
} |
| 1484 |
} |
| 1485 |
.OP { |
| 1486 |
flushbuffer |
| 1487 |
lassign $rest cmdName dbName dbClass |
| 1488 |
lappend manual(text) [concat .OP [process-text \ |
| 1489 |
"\\fB$cmdName\\fR \\fB$dbName\\fR \\fB$dbClass\\fR"]] |
| 1490 |
} |
| 1491 |
.PP - .LP { |
| 1492 |
flushbuffer |
| 1493 |
lappend manual(text) {.PP} |
| 1494 |
} |
| 1495 |
.RS { |
| 1496 |
flushbuffer |
| 1497 |
incr manual(.RS) |
| 1498 |
lappend manual(text) $code |
| 1499 |
} |
| 1500 |
.RE { |
| 1501 |
flushbuffer |
| 1502 |
incr manual(.RS) -1 |
| 1503 |
lappend manual(text) $code |
| 1504 |
} |
| 1505 |
.SO { |
| 1506 |
flushbuffer |
| 1507 |
incr manual(.SO) |
| 1508 |
if {[llength $rest] == 0} { |
| 1509 |
lappend manual(text) "$code options" |
| 1510 |
} else { |
| 1511 |
lappend manual(text) "$code [unquote $rest]" |
| 1512 |
} |
| 1513 |
} |
| 1514 |
.SE { |
| 1515 |
flushbuffer |
| 1516 |
incr manual(.SO) -1 |
| 1517 |
lappend manual(text) $code |
| 1518 |
} |
| 1519 |
.DS { |
| 1520 |
flushbuffer |
| 1521 |
incr manual(.DS) |
| 1522 |
lappend manual(text) $code |
| 1523 |
} |
| 1524 |
.DE { |
| 1525 |
flushbuffer |
| 1526 |
incr manual(.DS) -1 |
| 1527 |
lappend manual(text) $code |
| 1528 |
} |
| 1529 |
.CS { |
| 1530 |
flushbuffer |
| 1531 |
incr manual(.CS) |
| 1532 |
lappend manual(text) $code |
| 1533 |
} |
| 1534 |
.CE { |
| 1535 |
flushbuffer |
| 1536 |
incr manual(.CS) -1 |
| 1537 |
lappend manual(text) $code |
| 1538 |
} |
| 1539 |
.de { |
| 1540 |
while {[gets $manual(infp) line] >= 0} { |
| 1541 |
if {[string match "..*" $line]} { |
| 1542 |
break |
| 1543 |
} |
| 1544 |
} |
| 1545 |
} |
| 1546 |
.. { |
| 1547 |
if {!$verbose} { |
| 1548 |
puts stderr "" |
| 1549 |
} |
| 1550 |
error "found .. outside of .de" |
| 1551 |
} |
| 1552 |
default { |
| 1553 |
if {!$verbose} { |
| 1554 |
puts stderr "" |
| 1555 |
} |
| 1556 |
flushbuffer |
| 1557 |
manerror "unrecognized format directive: $line" |
| 1558 |
} |
| 1559 |
} |
| 1560 |
} |
| 1561 |
flushbuffer |
| 1562 |
close $manual(infp) |
| 1563 |
# fixups |
| 1564 |
if {$manual(.RS) != 0} { |
| 1565 |
if {!$verbose} { |
| 1566 |
puts stderr "" |
| 1567 |
} |
| 1568 |
puts "unbalanced .RS .RE" |
| 1569 |
} |
| 1570 |
if {$manual(.DS) != 0} { |
| 1571 |
if {!$verbose} { |
| 1572 |
puts stderr "" |
| 1573 |
} |
| 1574 |
puts "unbalanced .DS .DE" |
| 1575 |
} |
| 1576 |
if {$manual(.CS) != 0} { |
| 1577 |
if {!$verbose} { |
| 1578 |
puts stderr "" |
| 1579 |
} |
| 1580 |
puts "unbalanced .CS .CE" |
| 1581 |
} |
| 1582 |
if {$manual(.SO) != 0} { |
| 1583 |
if {!$verbose} { |
| 1584 |
puts stderr "" |
| 1585 |
} |
| 1586 |
puts "unbalanced .SO .SE" |
| 1587 |
} |
| 1588 |
# output conversion |
| 1589 |
open-text |
| 1590 |
set haserror 0 |
| 1591 |
if {[next-op-is .HS rest]} { |
| 1592 |
set manual($manual(wing-file)-$manual(name)-title) \ |
| 1593 |
"[join [lrange $rest 1 end] { }] [lindex $rest 0] manual page" |
| 1594 |
} elseif {[next-op-is .TH rest]} { |
| 1595 |
set manual($manual(wing-file)-$manual(name)-title) \ |
| 1596 |
"[lindex $rest 0] manual page - [join [lrange $rest 4 end] { }]" |
| 1597 |
} else { |
| 1598 |
set haserror 1 |
| 1599 |
if {!$verbose} { |
| 1600 |
puts stderr "" |
| 1601 |
} |
| 1602 |
manerror "no .HS or .TH record found" |
| 1603 |
} |
| 1604 |
if {!$haserror} { |
| 1605 |
while {[more-text]} { |
| 1606 |
set line [next-text] |
| 1607 |
if {[is-a-directive $line]} { |
| 1608 |
output-directive $line |
| 1609 |
} else { |
| 1610 |
man-puts $line |
| 1611 |
} |
| 1612 |
} |
| 1613 |
man-puts [copyout $manual(copyrights) "../"] |
| 1614 |
set manual(wing-copyrights) [merge-copyrights \ |
| 1615 |
$manual(wing-copyrights) $manual(copyrights)] |
| 1616 |
} |
| 1617 |
# |
| 1618 |
# make the long table of contents for this page |
| 1619 |
# |
| 1620 |
set manual(toc-$manual(wing-file)-$manual(name)) \ |
| 1621 |
[concat <DL> $manual(section-toc) </DL>] |
| 1622 |
} |
| 1623 |
if {!$verbose} { |
| 1624 |
puts stderr "" |
| 1625 |
} |
| 1626 |
|
| 1627 |
if {![llength $manual(wing-toc)]} { |
| 1628 |
fatal "not table of contents." |
| 1629 |
} |
| 1630 |
|
| 1631 |
# |
| 1632 |
# make the wing table of contents for the section |
| 1633 |
# |
| 1634 |
set width 0 |
| 1635 |
foreach name $manual(wing-toc) { |
| 1636 |
if {[string length $name] > $width} { |
| 1637 |
set width [string length $name] |
| 1638 |
} |
| 1639 |
} |
| 1640 |
set perline [expr {118 / $width}] |
| 1641 |
set nrows [expr {([llength $manual(wing-toc)]+$perline)/$perline}] |
| 1642 |
set n 0 |
| 1643 |
catch {unset rows} |
| 1644 |
foreach name [lsort -dictionary $manual(wing-toc)] { |
| 1645 |
set tail $manual(name-$name) |
| 1646 |
if {[llength $tail] > 1} { |
| 1647 |
manerror "$name is defined in more than one file: $tail" |
| 1648 |
set tail [lindex $tail [expr {[llength $tail]-1}]] |
| 1649 |
} |
| 1650 |
set tail [file tail $tail] |
| 1651 |
if {[info exists manual(tooltip-$manual(wing-file)/$tail.htm)]} { |
| 1652 |
set tooltip $manual(tooltip-$manual(wing-file)/$tail.htm) |
| 1653 |
set tooltip [string map {[ {\[} ] {\]} $ {\$} \\ \\\\} $tooltip] |
| 1654 |
regsub {^[^-]+-\s*(.)} $tooltip {[string totitle \1]} tooltip |
| 1655 |
append rows([expr {$n%$nrows}]) \ |
| 1656 |
"<td> <a href=\"$tail.htm\" title=\"[subst $tooltip]\">$name</a> </td>" |
| 1657 |
} else { |
| 1658 |
append rows([expr {$n%$nrows}]) \ |
| 1659 |
"<td> <a href=\"$tail.htm\">$name</a> </td>" |
| 1660 |
} |
| 1661 |
incr n |
| 1662 |
} |
| 1663 |
puts $manual(wing-toc-fp) <table> |
| 1664 |
foreach row [lsort -integer [array names rows]] { |
| 1665 |
puts $manual(wing-toc-fp) <tr>$rows($row)</tr> |
| 1666 |
} |
| 1667 |
puts $manual(wing-toc-fp) </table> |
| 1668 |
|
| 1669 |
# |
| 1670 |
# insert wing copyrights |
| 1671 |
# |
| 1672 |
puts $manual(wing-toc-fp) [copyout $manual(wing-copyrights) "../"] |
| 1673 |
puts $manual(wing-toc-fp) "</BODY></HTML>" |
| 1674 |
close $manual(wing-toc-fp) |
| 1675 |
set manual(merge-copyrights) \ |
| 1676 |
[merge-copyrights $manual(merge-copyrights) $manual(wing-copyrights)] |
| 1677 |
} |
| 1678 |
|
| 1679 |
proc makedirhier {dir} { |
| 1680 |
try { |
| 1681 |
if {![file isdirectory $dir]} { |
| 1682 |
file mkdir $dir |
| 1683 |
} |
| 1684 |
} on error msg { |
| 1685 |
return -code error "cannot create directory $dir: $msg" |
| 1686 |
} |
| 1687 |
} |
| 1688 |
|
| 1689 |
proc addbuffer {args} { |
| 1690 |
global manual |
| 1691 |
if {$manual(partial-text) ne ""} { |
| 1692 |
append manual(partial-text) \n |
| 1693 |
} |
| 1694 |
append manual(partial-text) [join $args ""] |
| 1695 |
} |
| 1696 |
proc flushbuffer {} { |
| 1697 |
global manual |
| 1698 |
if {$manual(partial-text) ne ""} { |
| 1699 |
lappend manual(text) [process-text $manual(partial-text)] |
| 1700 |
set manual(partial-text) "" |
| 1701 |
} |
| 1702 |
} |
| 1703 |
|
| 1704 |
return |