html2cgi htmlfile
The typical use of html2cgi is to create an HTML file with a
WYSIWYG HTML editor. This file will typically contain some comments that
contain raw Tcl code that is used directly in the CGI script. In this way,
the static part of a CGI script can be created with the help of a WYSIWYG
HTML editor.
The resulting CGI script will use Don Libes's cgi library. The first thing that the resulting CGI script will do is try to load this package. If this fails, the functions that are used from this library must be defined in another way.
One can instruct the resulting CGI script to source certain files immediately
after trying to load Don Libes's cgi library. This is done with
the meta tag cgi_source_files which is a tcl list containing the
file names to be sourced. This can be used to define the functions that
file names to be sourced. This can be used to define the functions that
normally would come from Don Libes's cgi library. It is also a good
opportunity to source files containing functions that one often uses in
ones Tcl CGI scripts.
If a comment starts with CGI then the comment is interpreted
as raw Tcl code that must be inserted at the corresponding position in
the CGI script.
html2cgi foo.html
will produce an executable file foo.cgi
If the file foo.cgi already exists, it will be overwritten without
warning unless noclobber is set in .cshrc.
If foo.html contains the following
<html>then foo.cgi will contain
<head>
<Title>Foo Home Page</Title>
<Meta name="cgi_interpreter" content="/usr/bin/tclsh8.3">
<Meta name="cgi_source_files" content="/home/msj/public_html/lib/myprocs.tcl /home/msj/public_html/donsprocs.t cl">
</head>
<body>
<H1>Welcome!</H1><br>
<!-- CGI for {set i 0} {$i < 10} {incr i} { -->
<!-- CGI puts "$i : " -->
<b>Out of cash</b><br>
<!-- CGI } -->
<!-- CGI foreach name [cgi_import_list] {
puts "<b>$name :</b> [cgi_import $name]<br>"
} --></body>
</html>
#!/usr/bin/tclsh8.3If this CGI script was called from a submit button in a form with two fields name and age with the values John and 52 respectively, then the resulting output in a browser would look like the content below the following line
lappend auto_path /usr/local/lib
catch {package require cgi}
catch {source /home/msj/public_html/lib/myprocs.tcl} out
if {"$out" != ""} {puts stderr $out}
catch {source /home/msj/public_html/donsprocs.tcl} out
if {"$out" != ""} {puts stderr $out}
cgi_input
puts "Content-Type: text/html"
puts ""
puts {<html>
}
puts {<head>
}
puts {<Title>Foo Home Page}
puts {</Title>
}
puts {<Meta name="cgi_interpreter" content="/usr/bin/tclsh8.3">
}
puts {<Meta name="cgi_source_files" content="/home/msj/public_html/lib/myprocs.tcl
/home/msj/public_html/donsprocs.tcl" >
}
puts {</head>
}
puts {<body>
}
puts {<H1>Welcome!}
puts {</H1>}
puts {<br>
}
for {set i 0} {$i < 10} {incr i} {
puts "$i : "
puts {<b>Out of cash}
puts {</b>}
puts {<br>
}
}
foreach name [cgi_import_list] {
puts "<b>$name :</b> [cgi_import $name]<br>"
}
puts {</body>
}
puts {</html> }