#!/usr/local/bin/tcl # # Commence Version nunmbering now 1.0 # # # This script takes a database file, an html file, and a description # and produces as output html which includes references to the # Images described in the original text, but as HTML elements. # # # This first version of the Fields of interest is as per Mike Greenhalgh posting #set Fields {O I II III IV BIa BIb BII BIII BIV DO DB DBIb DBII DBIII DBIV} # This version is enhanced with what I see in the file #set Fields {O I II III IV Ia Ib} #lappend Fields BIa BIb BII BIII BIV #lappend Fields IBa IBb IIB IIIB IVB #lappend Fields "B I" "B II" "B III" "B IV" #lappend Fields "I B" "II B" "III B" "IV B" proc DS {args} { puts [clock format [clock seconds] -format "%r [join $args]" ] } # Iff necessary, declare the lassign command, from tclx if {[info command lassign] != "lassign"} { proc lassign {l1 args} { uplevel foreach \"[join $args]\" \"$l1\" break } } # # This procedure loads key value pair which define the relationship # between an entry in the text, and what will be returned from the DB # proc Add_Text_Key {Key Value} { global Text_Key upvar $Text_Key Local lappend Local($Key) $Value } # Because we are expecting the resultant file to be VERY BIG, we must # split up the output as we go, we will do this by taking X chunks # from a file and splitting it at the next paragrpah marker after that # X & Chunks are yet to be defined, we will try 250 & lines # We don't want to break up any tables or lists when we do this, and we will # want links forward and backward in the Chain, plus an index proc Generate_Output {Base_File Text} { set Line_Count 0 set File_Count 1 set M_Count 0 set File ${Base_File}.${File_Count}.html set output [open $File w] lappend File_List "$File" # Strip out punctuation following our TABLE inserts regsub -all -- "\[ \n\t\]*\[-,.!@#$%&*()^\]*" $Text {} Text set Protected_Level 0 foreach line_orig [split $Text "\n"] { set line $line_orig incr Line_Count incr M_Count regsub -all -- {\[} $line {%5B} line regsub -all -- {\]} $line {%5D} line regsub -all -nocase -- {} $line {[incr Protected_Level -1]} line regsub -all -nocase -- {