📄 tcltk-man2html.tcl
字号:
} if {$invert([lindex $offsets 1]) == "tcl"} { set offsets [lreplace $offsets 1 1] } switch -exact $invert([lindex $offsets 1]) { end-quote { set head [string range $text 0 [expr {$offset(quote)-1}]] set body [string range $text [expr {$offset(quote)+2}] \ [expr {$offset(end-quote)-1}]] set tail [string range $text \ [expr {$offset(end-quote)+2}] end] return "$head``[cross-reference $body]''[insert-cross-references $tail]" } bold - anchor { set head [string range $text \ 0 [expr {$offset(end-quote)+1}]] set tail [string range $text \ [expr {$offset(end-quote)+2}] end] return "$head[insert-cross-references $tail]" } } return [reference-error "Uncaught quote case" $text] } bold { if {$offset(end-bold) < 0} { return $text } if {$invert([lindex $offsets 1]) == "tk"} { set offsets [lreplace $offsets 1 1] } if {$invert([lindex $offsets 1]) == "tcl"} { set offsets [lreplace $offsets 1 1] } switch -exact $invert([lindex $offsets 1]) { end-bold { set head [string range $text 0 [expr {$offset(bold)-1}]] set body [string range $text [expr {$offset(bold)+3}] \ [expr {$offset(end-bold)-1}]] set tail [string range $text \ [expr {$offset(end-bold)+4}] end] return "$head<B>[cross-reference $body]</B>[insert-cross-references $tail]" } anchor { set head [string range $text \ 0 [expr {$offset(end-bold)+3}]] set tail [string range $text \ [expr {$offset(end-bold)+4}] end] return "$head[insert-cross-references $tail]" } } return [reference-error "Uncaught bold case" $text] } tk { set head [string range $text 0 [expr {$offset(tk)-1}]] set tail [string range $text $offset(tk) end] if {![regexp {^(Tk_\w+)(.*)$} $tail all body tail]} { return [reference-error "Tk regexp failed" $text] } return $head[cross-reference $body][insert-cross-references $tail] } tcl { set head [string range $text 0 [expr {$offset(tcl)-1}]] set tail [string range $text $offset(tcl) end] if {![regexp {^(Tcl_\w+)(.*)$} $tail all body tail]} { return [reference-error {Tcl regexp failed} $text] } return $head[cross-reference $body][insert-cross-references $tail] } Tcl1 - Tcl2 { set off [lindex $offsets 0] set head [string range $text 0 [expr {$off-1}]] set body Tcl set tail [string range $text [expr {$off+3}] end] return $head[cross-reference $body][insert-cross-references $tail] } end-anchor - end-bold - end-quote { return [reference-error "Out of place $invert([lindex $offsets 0])" $text] } }}#### process formatting directives##proc output-directive {line} { global manual # process format directive split-directive $line code rest switch -exact $code { .BS - .BE { # man-puts <HR> } .SH { # drain any open lists # announce the subject set manual(section) $rest # start our own stack of stuff set manual($manual(name)-$manual(section)) {} lappend manual(has-$manual(section)) $manual(name) man-puts "<H3>[long-toc $manual(section)]</H3>" # some sections can simply free wheel their way through the text # some sections can be processed in their own loops switch -exact $manual(section) { NAME { if {[lsearch {CrtImgType.3 CrtItemType.3 CrtPhImgFmt.3} $manual(tail)] >= 0} { # these manual pages have two NAME sections if {[info exists manual($manual(tail)-NAME)]} { return } set manual($manual(tail)-NAME) 1 } set names {} while {1} { set line [next-text] if {[is-a-directive $line]} { backup-text 1 output-name [join $names { }] return } else { lappend names [string trim $line] } } } SYNOPSIS { lappend manual(section-toc) <DL> while {1} { if {[next-op-is .nf rest] || [next-op-is .br rest] || [next-op-is .fi rest]} { continue } if {[next-op-is .SH rest] || [next-op-is .BE rest] || [next-op-is .SO rest]} { backup-text 1 break } if {[next-op-is .sp rest]} { #man-puts <P> continue } set more [next-text] if {[is-a-directive $more]} { manerror "in SYNOPSIS found $more" backup-text 1 break } else { foreach more [split $more \n] { man-puts $more<BR> if {[lsearch {TclLib TkLib} $manual(wing-file)] < 0} { lappend manual(section-toc) <DD>$more } } } } lappend manual(section-toc) </DL> return } {SEE ALSO} { while {[more-text]} { if {[next-op-is .SH rest]} { backup-text 1 return } set more [next-text] if {[is-a-directive $more]} { manerror "$more" backup-text 1 return } set nmore {} foreach cr [split $more ,] { set cr [string trim $cr] if {![regexp {^<B>.*</B>$} $cr]} { set cr <B>$cr</B> } if {[regexp {^<B>(.*)\([13n]\)</B>$} $cr all name]} { set cr <B>$name</B> } lappend nmore $cr } man-puts [join $nmore {, }] } return } KEYWORDS { while {[more-text]} { if {[next-op-is .SH rest]} { backup-text 1 return } set more [next-text] if {[is-a-directive $more]} { manerror "$more" backup-text 1 return } set keys {} foreach key [split $more ,] { set key [string trim $key] lappend manual(keyword-$key) [list $manual(name) $manual(wing-file)/$manual(name).htm] set initial [string toupper [string index $key 0]] lappend keys "<A href=\"../Keywords/$initial.htm\#$key\">$key</A>" } man-puts [join $keys {, }] } return } } if {[next-op-is .IP rest]} { output-IP-list .SH .IP $rest return } if {[next-op-is .PP rest]} { return } return } .SO { if {[match-text @stuff .SE]} { output-directive {.SH STANDARD OPTIONS} set opts {} foreach line [split $stuff \n] { foreach option [split $line \t] { lappend opts $option } } man-puts <DL> lappend manual(section-toc) <DL> foreach option [lsort $opts] { man-puts "<DT><B>[std-option-toc $option]</B>" } man-puts </DL> lappend manual(section-toc) </DL> } else { manerror "unexpected .SO format:\n[expand-next-text 2]" } } .OP { output-widget-options $rest return } .IP { output-IP-list .IP .IP $rest return } .PP { man-puts <P> } .RS { output-RS-list return } .RE { manerror "unexpected .RE" return } .br { man-puts <BR> return } .DE { manerror "unexpected .DE" return } .DS { if {[next-op-is .ta rest]} { } if {[match-text @stuff .DE]} { man-puts <PRE>$stuff</PRE> } elseif {[match-text .fi @ul1 @ul2 .nf @stuff .DE]} { man-puts "<PRE>[lindex $ul1 1][lindex $ul2 1]\n$stuff</PRE>" } else { manerror "unexpected .DS format:\n[expand-next-text 2]" } return } .CS { if {[next-op-is .ta rest]} { } if {[match-text @stuff .CE]} { man-puts <PRE>$stuff</PRE> } else { manerror "unexpected .CS format:\n[expand-next-text 2]" } return } .CE { manerror "unexpected .CE" return } .sp { man-puts <P> } .ta { # these are tab stop settings for short tables switch -exact $manual(name):$manual(section) { {bind:MODIFIERS} - {bind:EVENT TYPES} - {bind:BINDING SCRIPTS AND SUBSTITUTIONS} - {expr:OPERANDS} - {expr:MATH FUNCTIONS} - {history:DESCRIPTION} - {history:HISTORY REVISION} - {switch:DESCRIPTION} - {upvar:DESCRIPTION} { return; # fix.me } default { manerror "ignoring $line" } } } .nf { if {[match-text @more .fi]} { foreach more [split $more \n] { man-puts $more<BR> } } elseif {[match-text .RS @more .RE .fi]} { man-puts <DL><DD> foreach more [split $more \n] { man-puts $more<BR> } man-puts </DL> } elseif {[match-text .RS @more .RS @more2 .RE .RE .fi]} { man-puts <DL><DD> foreach more [split $more \n] { man-puts $more<BR> } man-puts <DL><DD> foreach more2 [split $more2 \n] { man-puts $more2<BR> } man-puts </DL></DL> } elseif {[match-text .RS @more .RS @more2 .RE @more3 .RE .fi]} { man-puts <DL><DD> foreach more [split $more \n] { man-puts $more<BR> } man-puts <DL><DD> foreach more2 [split $more2 \n] { man-puts $more2<BR> } man-puts </DL><DD> foreach more3 [split $more3 \n] { man-puts $more3<BR> } man-puts </DL> } elseif {[match-text .sp .RS @more .RS @more2 .sp .RE .RE .fi]} { man-puts <P><DL><DD> foreach more [split $more \n] { man-puts $more<BR> } man-puts <DL><DD> foreach more2 [split $more2 \n] { man-puts $more2<BR> } man-puts </DL></DL><P> } elseif {[match-text .RS .sp @more .sp .RE .fi]} { man-puts <P><DL><DD> foreach more [split $more \n] { man-puts $more<BR> } man-puts </DL><P> } else { manerror "ignoring $line" } } .fi { manerror "ignoring $line" } .na - .ad - .UL - .ne { manerror "ignoring $line" } default { manerror "unrecognized format directive: $line" } }}#### merge copyright listings## proc merge-copyrights {l1 l2} { foreach copyright [concat $l1 $l2] { if {[regexp {^Copyright +\(c\) +(\d+) +(by +)?(\w.*)$} $copyright all date by who]} { lappend dates($who) $date continue } if {[regexp {^Copyright +\(c\) +(\d+)-(\d+) +(by +)?(\w.*)$} $copyright all from to by who]} { for {set date $from} {$date <= $to} {incr date} { lappend dates($who) $date } continue } if {[regexp {^Copyright +\(c\) +(\d+), *(\d+) +(by +)?(\w.*)$} $copyright all date1 date2 by who]} { lappend dates($who) $date1 $date2 continue } puts "oops: $copyright" } foreach who [array names dates] { set list [lsort $dates($who)] if {[llength $list] == 1 || [lindex $list 0] == [lrange $list end end]} { lappend merge "Copyright (c) [lindex $list 0] $who" } else { lappend merge "Copyright (c) [lindex $list 0]-[lrange $list end end] $who" } } return [lsort $merge]}proc makedirhier {dir} { if {![file isdirectory $dir] && \ [catch {file mkdir $dir} error]} { return -code error "cannot create directory $dir: $error" }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -