Documentation Source Text

Artifact Content
Login

Artifact c0b71421f39bc891080b442116abb0291bc41599:


#!/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 <title>...</title> in the input is moved into the prepended
#        header.
#     *  An appropriate footer is appended.
#     *  Scripts within <tcl>...</tcl> 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
}

set Sitemap {
  { "Home" index.html {
       "Feature List" about.html
       "Well-know Users" famous.html
       "Developer Vitas" crew.html
  }}
  { "Sitemap" sitemap.html {} }
  { "Documentation" docs.html {
       "Frequently Asked Questions" faq.html 
       "SQLite In 5 Minutes Or Less" quickstart.html 
       "C/C++ Interface Spec" c3ref/intro.html 
       "SQL Syntax" lang.html 
       "Appropriate Uses For SQLite" whentouse.html 
       "Distinctive Features" different.html 
  }}
  { "Download" download.html {} }
  { "License" copyright.html {} }
  { "News" news.html {
       "Older News" oldnews.html
  }}
  { "Developers" http://www.sqlite.org/cvstrac/index.html {} }
  { "Support" support.html {} }
}

# A procedure to write the common header found on every HTML file on
# the SQLite website.
#
proc PutsHeader {title {path {}}} {
  puts {<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">}
  puts {<html><head>}
  puts "<title>$title</title>"
  putsin4 {<style type="text/css">
    body {
        margin: auto;
        font-family: "Verdana" "sans-serif";
        line-height: 1.5em;
        padding: 8px 1%;
    }
    
    a { color: #734559 }
    a:visited { color: #45735f }
    
    .logo { position:absolute; margin:3px; }
    .tagline {
      float:right;
      text-align:right;
      font-style:italic;
      width:240px;
      margin:12px;
      margin-top:58px;
    }
    
    .toolbar {
      font-variant: small-caps;
      text-align: center;
      line-height: 1.6em;
      margin: 0;
      padding:1px 8px;
    }
    .toolbar a { color: white; text-decoration: none; padding: 6px 12px; }
    .toolbar a:visited { color: white; }
    .toolbar a:hover { color: #80a796; background: white; }
    
    .content    { margin: 5%; }
    .content dt { font-weight:bold; }
    .content dd { margin-bottom: 25px; margin-left:20%; }
    .content ul { padding:0px; padding-left: 15px; margin:0px; }
    
    /* rounded corners */
    .se  { background: url(${path}images/se.png) 100% 100% no-repeat #80a796}
    .sw  { background: url(${path}images/sw.png) 0% 100% no-repeat }
    .ne  { background: url(${path}images/ne.png) 100% 0% no-repeat }
    .nw  { background: url(${path}images/nw.png) 0% 0% no-repeat }

    /* CSS for drop down menus */
    .menu {
      float:left;
    }
    .pulldown {
      left:0px;
      top:100%;
      margin-top:0px;
      display: none;
      position: absolute;
      z-index: 1;
      border: 2px solid #80a796;
      background: #80a796;
      text-align: left;
    }
    .pulldown a { display: block; white-space: nowrap; }
    .toolbar table, .toolbar tbody, .toolbar tr, .toolbar td { 
      padding: 0; border-spacing: 0
    }

    .over .pulldown, .menu:hover .pulldown { display: block; }
    .over .pulldown, .menu:hover .pulldown { display: block; }

    </style>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">

    <script type="text/javascript">

      var current_menu_id = null
      var current_timeout = null

      function menu_mouseover () {
        menu_mouseout_delayed()
        this.className += " over"
        current_menu_id = this.id
      }
      function menu_mouseout () {
        current_timeout = window.setTimeout('menu_mouseout_delayed()', 500)
      }
      function menu_mouseout_delayed (id) {
        var elem = document.getElementById(current_menu_id)
        if (elem) {
          elem.className = elem.className.replace(" over", "")
        }
        if (current_timeout) {
          window.clearTimeout(current_timeout)
        }
        current_menu_id = null
        current_timeout = null
      }

      window.onload = function() {
        var collection = document.getElementsByTagName("div")
        var ii
        for (ii = 0; ii < collection.length; ii++) {
          var span = collection.item(ii)
          if (span.className == "menu") {
            span.onmouseover = menu_mouseover
            span.onmouseout  = menu_mouseout
            span.id  = "menu" + ii
          }
        }
      }
    </script>
  }
  puts {</head>}
  putsin4 {<body>
    <div><!-- container div to satisfy validator -->
    
    <a href="${path}index.html">
    <img class="logo" src="${path}images/SQLite.gif" alt="SQLite Logo"
     border="0"></a>
    <div><!-- IE hack to prevent disappearing logo--></div>
    <div class="tagline">The World's Most Widely Used SQL Database.</div>
    
    <table width=100% style="clear:both"><tr><td>
      <div class="se"><div class="sw"><div class="ne"><div class="nw">
      <div class="toolbar">
        <table style="margin:auto"><tr><td>
  }
  foreach menuitem $::Sitemap {
    foreach {caption uri menucontents} $menuitem break
    putsin4 {<div class="menu"><div style="position:relative"><a href="${uri}">$caption</a>}
    if {$menucontents ne ""} {
      puts {<div class="pulldown">}
      foreach {caption uri} $menucontents {
        putsin4 {<a href="${uri}">$caption</a>}
      }
      putsin4 {</div>}
    }
    putsin4 {</div></div>}
  }
  putsin4 {
        </tr></table>
      </div></div></div></div></div>
    </td></tr></table>
  }
}

# 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 {<hr><small><i>}
  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 {</i></small></div></body></html>}
}

# The following proc is used to ensure consistent formatting in the 
# HTML generated by lang.tcl and pragma.tcl.
#
proc Syntax {args} {
  puts {<table cellpadding="10" class=pdf_syntax>}
  foreach {rule body} $args {
    puts "<tr><td align=\"right\" valign=\"top\">"
    puts "<i><font color=\"#ff3434\">$rule</font></i>&nbsp;::=</td>"
    regsub -all < $body {%LT} body
    regsub -all > $body {%GT} body
    regsub -all %LT $body {</font></b><i><font color="#ff3434">} body
    regsub -all %GT $body {</font></i><b><font color="#2c2cf0">} body
    regsub -all {[]|[*?]} $body {</font></b>&<b><font color="#2c2cf0">} body
    regsub -all "\n" [string trim $body] "<br>\n" body
    regsub -all "\n  *" $body "\n\\&nbsp;\\&nbsp;\\&nbsp;\\&nbsp;" body
    regsub -all {[|,.*()]} $body {<big>&</big>} body
    regsub -all { = } $body { <big>=</big> } body
    regsub -all {STAR} $body {<big>*</big>} body
    ## These metacharacters must be handled to undo being
    ## treated as SQL punctuation characters above.
    regsub -all {RPPLUS} $body {</font></b>)+<b><font color="#2c2cf0">} body
    regsub -all {LP} $body {</font></b>(<b><font color="#2c2cf0">} body
    regsub -all {RP} $body {</font></b>)<b><font color="#2c2cf0">} body
    ## Place the left-hand side of the rule in the 2nd table column.
    puts "<td><b><font color=\"#2c2cf0\">$body</font></b></td></tr>"
  }
  puts {</table>}
}

# 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 {<title>([^\n]*)</title>} $in all title
  regsub {<title>[^\n]*</title>} $in {} in
  set outfile [file root [file tail $infile]].html
  set ::OUT [open $::DEST/$outfile w]
  PutsHeader $title
  regsub -all {<tcl>} $in "\175; eval \173" in
  regsub -all {</tcl>} $in "\175; puts \173" in
  eval "puts \173$in\175"
  cd $::HOMEDIR
  PutsFooter $infile
  close $::OUT
}