Processing of CGI GET script arguments under Tcl

From changing htbin scripts to CGI scripts:
CGI stands for the Common Gateway Interface. It is the next generation of the script interface, called Common because many of the major HTTP servers will be implementing it.
For more info about CGI, look here.

The appropriate way to process arguments is to do

http_proc_cgi_args
near the beginning of your Tcl script. http_proc_cgi_args splits the PATH_INFO and QUERY_STRING shell environment variables and assigns the values to the global Tcl array ar.

For example, if the script argument assignment foo=bar was passed in, you would access the value bar through $ar(foo). Other CGI specific variables, such as REMOTE_HOST and REMOTE_USER are available through the global Tcl array env.

Processing of old GET script arguments under Tcl

The old method of passing arguments to scripts is described here. The appropriate command to parse arguments is to call
http_proc_args argv
at the beginning of your script. The call assigns the values to the global Tcl array ar as in CGI.

Both methods (old and CGI)--handling of list arguments

If your form contains a SELECT input type that supports multiple selection, called var, the arguments will be passed to the script from Mosaic this way:
var=value1&var=value2 ...
If there is only one selection, then only one var=value assignment will be passed to the script. Because of the following reasons: you need to declare that an argument is supposed to be a list before calling http_proc_cgi_args or http_proc_args. In this example, you would do either:
set artype(var) list
http_proc_cgi_args
or
set artype(var) list
http_proc_args argv
Then, [lindex $ar(var) 0] will return the right value when values contain spaces.

Passing on Values via the URL

If you have an array attributes and you wish to pass on each of the values in attributes to a script, you need to encode them in the URL by appending /attr1=val1/attr2=val2/... to the script.

The function pkg_attrs does this. Example usage is:

<A href="/htbin/script-foo[pkg_attrs attributes]">Do script</A>