# rename this grind-pages.tcl if you want AOLserver to execute it
# instead of just xfer the code to Netscape
# grind before we do perl processing
# at once time I thought I'd look up the execs in the database but it was taking
# something like 10 minutes to convert a few files. The regular expressions was
# just too much for feeble Tcl so I'm going to write a file for that real man's language..
# PERL
# # it takes forever to REGEXP for the miexecs so you may want to forget
# # it by setting this to 0
# set lookup_execs 1
# proc grind_lookup_exec {db execWeb_id} {
# set sql "select execWeb_executable from execWeb where execWeb_id = '[DoubleApos $execWeb_id]'"
# set selection [ns_db 0or1row $db $sql]
# if { $selection == "" } {
# return "Could not find $execWeb_id in the execWeb table"
# } else {
# return [ns_set value $selection 0]
# }
# }
# # we're also going to try to find the miexecs and replace the EXECUTE
# # keys with the actual Unix paths
# while { $lookup_execs == 1 && [regexp -nocase {(.*)<\?miexec(.*)execute[ ]*=[ "]*([^ >]*)"*([^>]*)>(.*)} $object_minus_returns match before tag_interior_1 execWeb_id tag_interior_2 after] == 1 } {
# ns_log Notice "regexp'd successfully for an miexec in $ID"
# # there is an miexec, look up tag in the database
# # make sure that we use the other database connection so we don't
# # screw up our cursor
# set full_unix_pathname [grind_lookup_exec $db_sub $execWeb_id]
# # we use "UNIXSUCKS" as a delimeter because there could be almost
# # anything inside a exec, including string quotes or >
# set object_minus_returns "$before$after"
# }
set destination_dir "/local/home/philg/tclpages970305/"
ReturnHeaders $conn
ns_write $conn "
Grinding WebBlade to Basic Tcl Files
Grinding WebBlade to Basic Tcl Files
into $destination_dir (for subsequent Perl processing)
"
#set db_pools [ns_db gethandle [philg_server_default_pool] 2]
#set db [lindex $db_pools 0]
# we thought we'd use the subquery pool to figure out what miexec is doing
#set db_sub [lindex $db_pools 1]
# we only need the one connection now
set db [ns_db gethandle]
set date [database_to_tcl_string $db "return current_date"]
# add a WHERE clause to this
# where project in ('project_1','project_2')
# if you want just one set of pages
set selection [ns_db select $db "select object, ID from webPages
order by ID"]
while {[ns_db getrow $db $selection]} {
set_variables_after_query
# now object and id are set
# object is full of ugly control-Ms so let's kill them
regsub -all "\015" $object {} object_minus_returns
set filename "$destination_dir$ID.tcl"
set stream [open $filename w]
ns_write $conn "- Writing $ID.\n"
puts $stream "# $ID grabbed from webPages table on $date\n"
puts $stream $object_minus_returns
close $stream
}
ns_write $conn "
"
set exec_map_filename "${destination_dir}exec_map.text"
set exec_stream [open $exec_map_filename w]
set selection [ns_db select $db "select * from execWeb
order by execWeb_id"]
# format is key, full_unix_path, replace_with_function_call_instead_p (0 for no, 1 for yes)
# the last flag is there because a lot of these execs are necessary
# because the WebBlade has such feeble procedural capabilities
# you don't have to suffer the forking overhead and source
# control problems if you just convert it to a Tcl function
# call (this assumes that someone is going to rewrite these scripts
# as Tcl instead of Perl or whatever they were)
while {[ns_db getrow $db $selection]} {
set_variables_after_query
# use UNIXSUCKSROCKS as a delimiter
puts $exec_stream "${execWeb_id}UNIXSUCKSROCKS${execWeb_executable}UNIXSUCKSROCKS0"
}
close $exec_stream
ns_write $conn "Wrote $exec_map_filename with the exec function mappings
philg@mit.edu
"