The jparseargs.tcl library is distributed as part of the jstools package. It consists of procedures to procedure and application arguments in the typical Tcl `-option value' format.
This document describes jparseargs.tcl version 4.0/4.0.
In order to use the jparseargs.tcl library, it (and any other libraries it depends on) must be in your Tcl auto_path, described in tclvars(n). Information about how to arrange that, and other conventions common to the jstools libraries, is in the Usage section of The jstools Libraries.
Jay Sekora
js@calumet.org
http://shore.net/~js/
The library is copyright © 1992-1995 by Jay Sekora, but may be freely redistributed under the conditions at the top of the file.
j:parse_args - parse option list in parent procedure
j:parse_argv - parse argv variable (options to script)
proc procname { args } {
j:parse_args
...}
arglist - list of {option default} pairs
proc alert { args } {
j:parse_args {
{title "Alert"}
{text "Alert!"}
{ok "OK"}
}
toplevel .foo
wm title .foo $title
message .foo.msg -text $text
button .foo.btn -text $ok -command {destroy .foo}
pack .foo.msg .foo.btn
}
This procedure is used by almost all the other procedures in jlibrary.tcl. It extracts options from the variable args in the parent procedure, and sets corresponding variables, also in the parent procedure. (See the proc(1) manual page for an explanation of the args variable.) Its argument is a list of {option default} sublists. For each pair, the parent's args variable is scanned for elements matching option, preceded by a hyphen. (For instance, if an option is `title', j:parse_args searches for `-title'.) If a match is found, the following word is used as the value of that parameter, and a variable with the name option is set to that value in the parent procedure. (To continue the example, the parent's variable title would be set to the element following `-title' in $args.) If no match is found, the parent's option variable is set to the value of default.
Although not as flexible as getopt(3), this procedure makes it fairly easy to process lists of optional arguments.
j:parse_args
arglist
arglist - list of {option default} pairs
j:parse_argv {
{font Courier10}
{headerfont Times-Bold12}
{columns 1}
{orient portrait}
}
This procedure is almost identical to j:parse_args, but instead of parsing the args variable in a procedure, it parses the global argv variable. I.e., instead of parsing procedure arguments, it parses script arguments.
It removes any items it processes from argv, and sets argc to the length of argv when it's done.
For more information about the argv and argc variables, see the wish(1) or tclsh(1) manual page.
* There should be a way to make aliases for existing options, in the same way that -bd is an alias for -borderwidth in Tk.
* There should be a way to specify boolean options which don't take an argument, but set a variable to 1 if they appear, and 0 otherwise.