global env
#!/usr/local/bin/tcl
# (or whatever flavour of Tcl you like to run)
# This boilerplate goes at the top of your cgi script. For a working
# example of this code see http://www.ucolick.org/epbook.html
#
# lifted this kludge directly from Jackson@stsci -- it works.
proc unescape {v} {
# This a kludge
regsub -all {\%25} $v {XXXPERCENTXXX} v
set nv $v
while {[regexp {%[0-9A-F][0-9A-F]} $v blah]} {
scan $blah "%%%x" cv
if {[ctype char $cv]=="&"} {
regsub -all $blah $v \\& nv
} else {
regsub -all $blah $v [ctype char $cv] nv
}
set v $nv
}
regsub -all {XXXPERCENTXXX} $v {%} v
return $v
}
#
if [info exists env(CONTENT_LENGTH)] then {
set message [split [read stdin $env(CONTENT_LENGTH)] &]
foreach pair $message {
set name [lindex [split $pair =] 0]
set val [lindex [split $pair =] 1]
regsub -all {\+} $val { } val
set val [unescape $val]
set val [string trim $val]
if [info exists value($name)] then {
lappend value($name) $val
} else {
set value($name) $val
}
}
# If you have just one input widget called input, then you could do this:
# set input $value(input)
} else {
# puts $ofp "Did not find CONTENT_LENGTH"
# In this case value came in argv
set input $argv
# puts $ofp "got input $input"
}
# otherwise you would want to do [array names value] and do a loop to
# set each array index (as a variable) to $value(name).. so if you
# had an input widget called voice and another called fax,
# set voice $value(voice)
# set fax $value(fax)
#
# From here on you are on your own. Enjoy.
#