# This Tcl script runs down the OLC source tree and produces index files for
# World Wide Web.  To run
#
# expect
#    source olc.tcl



proc OlcParseFile {rootdir index timestamp} {
  set indexfile [open $rootdir/.index r]
  set htmlfile [open "$index.html" w]

  puts stdout "Creating OLC $index.html from $rootdir/.index"
  puts $htmlfile "<TITLE>$index</TITLE>"
  puts $htmlfile "Index Created: $timestamp<P>"
  puts $htmlfile "<UL>"

  while {[gets $indexfile string] != -1} {
    set params [split $string :]
    set type [lindex $params 0]
    set entry [lindex $params 1]
    set node [lindex $params 2]
    set processed_name $node
    regsub -all {[./]+} $processed_name {} processed_name

    case $type {
        "directory" {
	    if {$index=="root"} {
		puts $htmlfile \
		    [format  "<LI><A NAME=%s HREF=%s.html>%s</A>" \
		     $processed_name $processed_name $entry]
		OlcParseFile $rootdir/$node $processed_name $timestamp
            } {
		puts $htmlfile \
		    [format "<LI><A NAME=%s HREF=%s.html>%s</A>" \
		     $index.$processed_name $index.$processed_name $entry]
		OlcParseFile $rootdir/$node $index.$processed_name $timestamp
            }
        }
        "entry" {
            puts $htmlfile \
		"<LI><A NAME=$processed_name HREF=$rootdir/$node>$entry</A>"
        }
      }
}


  puts $htmlfile "</UL>"
  close $htmlfile
  close $indexfile
}

set rootdir /afs/athena.mit.edu/astaff/reference/olc_stock-answers/stock_answers

OlcParseFile $rootdir "root" [exec date]
