#! /usr/local/bin/tclsh

set html [open index.html w+]
set w 480
set h 320
set dir [file tail [pwd]]

if {![catch {set dbfile [open database.txt r]}]} {
    for {set line [gets $dbfile]} {$line != ""} {set line [gets $dbfile]} {
	set list [split $line ":"]
	set db([lindex $list 0]) [lindex $list 1]
    }
}

puts $html "<html><head><title>index of pictures in $dir</title></head>"
puts $html "<body>"
puts $html "<h1>Index of pictures in $dir</h1><hr>"

set desc [lindex [array get db "*comments*"] 1]
if {$desc != ""} {
    puts $html "$desc"
    puts $html "<hr>"
}

foreach jpg [lsort [glob *.jpg *.JPG]] {
    puts $html "<a href=$jpg><img src=$jpg width=$w height=$h border=0
    align=left></a>"
    
    set desc [lindex [array get db $jpg] 1]
    if {$desc == ""} {set desc "no description"}

    puts $html "$jpg: $desc"
    puts $html "<br clear=left><p>"
    puts $html "\n\n"
}

puts $html "<hr>This page automatically generated by a dumb script <a href=mailto:magi@cs.stanford.edu>Matt</a> wrote.<p>"
puts $html "</body></html>"

close $html
