# rename this to grind-funcs.tcl if you want AOLserver to execute it
# grind the magic Web Blade custom tag defs to Unix files
set destination_dir "/local/home/philg/tclfuncs/"
ReturnHeaders $conn
ns_write $conn "
Grinding webTags to Tcl
Grinding webTags to Tcl
into $destination_dir
"
set db [ns_db gethandle]
set selection [ns_db select $db "select ID, parameters, class, description, content from webTags
order by ID"]
while {[ns_db getrow $db $selection]} {
set_variables_after_query
# content is full of ugly control-Ms so let's kill them
regsub -all "\015" $content {} content_minus_returns
set param_list [split $parameters "&"]
# WebBlade brain damage is to refer to a function arg as @foobar@
foreach param $param_list {
regsub -all "@$param@" $content_minus_returns "\$$param" content_minus_returns
}
set db_access_required_p [regexp -nocase {misql} $content_minus_returns]
set filename "$destination_dir$ID.tcl"
set stream [open $filename w]
ns_write $conn "- Writing $ID.\n"
puts $stream "# translated webTag $ID"
puts $stream "# args: $parameters"
puts $stream "# $description\n"
puts $stream "proc $ID {[join $param_list " "]} {"
if { $db_access_required_p == 1 } {
puts $stream "set db \[ns_db gethandle subquery 1\]"
}
puts $stream $content_minus_returns
puts $stream "}"
close $stream
}
ns_write $conn "
philg@mit.edu
"