#!/usr/bin/tclsh # # This script processes raw page text into its final form for display. # Invoke this command as follows: # # tclsh wrap.tcl $(DOC) $(SRC) $(DEST) source1.in source2.in ... # # The $(DOC) and $(SRC) values are the names of directories containing # the documentation source and program source. $(DEST) is the name of # of the directory where generated HTML is written. sourceN.in is the # input file to be processed. The output is sourceN.html in the # local directory. # # Changes made to the source files: # # * An appropriate header is prepended to the file. # * Any ... in the input is moved into the prepended # header. # * An appropriate footer is appended. # * Scripts within ... are evaluated. Output that # is emitted from these scripts by "puts" appears in place of # the original script. # set DOC [lindex $argv 0] set SRC [lindex $argv 1] set DEST [lindex $argv 2] set HOMEDIR [pwd] ;# Also remember our home directory. # We are going to overload the puts command, so remember the # original puts command using an alternative name. rename puts real_puts proc puts {text} { real_puts $::OUT $text flush $::OUT } # putsin4 is like puts except that it removes the first 4 indentation # characters from each line. It also does variable substitution in # the namespace of its calling procedure. # proc putsin4 {text} { regsub -all "\n " $text \n text real_puts $::OUT [uplevel 1 [list subst -noback -nocom $text]] flush $::OUT } # A procedure to write the common header found on every HTML file on # the SQLite website. # proc PutsHeader {title {relpath {}}} { puts {} puts {} puts "$title" putsin4 { } puts {} putsin4 {
The World's Most Widely Used SQL Database.
Home About Documentation Download License Advocacy Developers News Support
} } # A procedure to write the common footer found at the bottom of # every HTML file. $srcfile is the name of the file that is the # source of the HTML content. The modification time of this file # is used to add the "last modified on" line at the bottom of the # file. # proc PutsFooter {srcfile} { puts {
} set mtime [file mtime $srcfile] set date [clock format $mtime -format {%Y/%m/%d %H:%M:%S UTC} -gmt 1] puts "This page last modified $date" puts {
} } # The following proc is used to ensure consistent formatting in the # HTML generated by lang.tcl and pragma.tcl. # proc Syntax {args} { puts {} foreach {rule body} $args { puts "" regsub -all < $body {%LT} body regsub -all > $body {%GT} body regsub -all %LT $body {} body regsub -all %GT $body {} body regsub -all {[]|[*?]} $body {&} body regsub -all "\n" [string trim $body] "
\n" body regsub -all "\n *" $body "\n\\ \\ \\ \\ " body regsub -all {[|,.*()]} $body {&} body regsub -all { = } $body { = } body regsub -all {STAR} $body {*} body ## These metacharacters must be handled to undo being ## treated as SQL punctuation characters above. regsub -all {RPPLUS} $body {
)+} body regsub -all {LP} $body {(} body regsub -all {RP} $body {)} body ## Place the left-hand side of the rule in the 2nd table column. puts "" } puts {
" puts "$rule ::=$body
} } # Loop over all input files and process them one by one # foreach infile [lrange $argv 3 end] { cd $HOMEDIR real_puts "Processing $infile" set fd [open $infile r] set in [read $fd] close $fd set title {No Title} regexp {([^\n]*)} $in all title regsub {[^\n]*} $in {} in set outfile [file root [file tail $infile]].html set ::OUT [open $::DEST/$outfile w] PutsHeader $title regsub -all {} $in "\175; eval \173" in regsub -all {} $in "\175; puts \173" in eval "puts \173$in\175" cd $::HOMEDIR PutsFooter $infile close $::OUT }