{jparseargs.tcl

Introduction
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.

Usage
Accessing the Library
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.

Credits and Copyright
Author
Jay Sekora 
js@calumet.org
http://shore.net/~js/

Copyright
The library is copyright © 1992-1995 by Jay Sekora, but may be freely redistributed under the conditions at the top of the file.

Overview
Procedures
j:parse_args - parse option list in parent procedure
j:parse_argv - parse argv variable (options to script)

j:parse_args
Usage
	proc procname { args } {
	  j:parse_args arglist
	...}
Argument
	arglist - list of {option default} pairs
Example
	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
	}

Description
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_argv
Usage
	j:parse_args arglist
Argument
	arglist - list of {option default} pairs
Example
	j:parse_argv {
	  {font Courier10}
	  {headerfont Times-Bold12}
	  {columns 1}
	  {orient portrait}
	}

Description
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.

Future Directions
* 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.
} {{{jdoc:xref:link {4.57 4.64 10.215 10.236 10.244 10.261 10.265 10.286 23.0 23.12 24.0 24.12 66.38 66.50}} {jdoc:xref:manpage {10.131 10.138 48.218 48.222 50.28 50.34 70.64 70.68 70.75 70.80}} {jdoc:anchor:anchorname {3.0 4.0 8.0 9.0 12.0 13.0 21.0 22.0 26.0 27.0 52.0 53.0}} {richtext:font:roman {2.0 3.0 4.0 4.4 4.18 4.57 4.64 4.160 4.173 6.24 6.38 8.0 10.0 10.20 10.34 10.107 10.116 10.131 10.138 10.219 10.226 10.248 10.253 10.265 10.286 12.0 14.0 15.0 15.14 16.0 16.21 18.0 19.0 21.0 23.12 24.0 24.12 24.21 24.25 26.0 32.0 32.1 32.8 32.19 32.35 33.0 46.0 47.0 48.0 48.61 48.73 48.114 48.118 48.218 48.222 48.264 48.268 48.307 48.323 48.363 48.367 48.410 48.416 48.462 48.468 48.473 48.478 48.481 48.493 48.508 48.514 48.628 48.634 48.730 48.735 48.775 48.781 48.786 48.791 48.830 48.836 48.869 48.876 50.28 50.34 52.0 56.0 56.1 56.8 56.19 56.35 57.0 64.0 65.0 66.0 66.38 66.50 66.79 66.83 66.130 66.134 68.39 68.43 68.54 68.58 68.76 68.80 70.31 70.35 70.40 70.44 70.64 70.68 70.75 70.80 72.0 73.0 73.83 73.86 73.103 73.115 75.103 75.104 75.125 75.126 76.0}} {richtext:font:italic {4.168 4.173 29.16 29.23 32.1 32.8 32.20 32.26 32.27 32.34 48.308 48.314 48.315 48.322 48.410 48.416 48.462 48.468 48.628 48.634 48.830 48.836 48.869 48.876 54.14 54.21 56.1 56.8 56.20 56.26 56.27 56.34}} {richtext:font:bold {4.4 4.18 4.57 4.64 6.24 6.38 10.20 10.34 10.219 10.226 48.61 48.73}} {richtext:font:bolditalic {10.248 10.253 10.265 10.286}} {richtext:font:typewriter {4.160 4.168 10.107 10.116 10.131 10.138 15.0 15.14 16.0 16.21 23.0 23.12 24.0 24.12 24.21 24.25 28.0 29.16 29.23 31.0 32.19 32.20 32.26 32.27 32.34 32.35 34.0 46.0 48.114 48.118 48.218 48.222 48.264 48.268 48.307 48.308 48.314 48.315 48.322 48.323 48.363 48.367 48.473 48.478 48.481 48.493 48.508 48.514 48.730 48.735 48.775 48.781 48.786 48.791 50.28 50.34 54.0 54.14 54.21 55.0 56.19 56.20 56.26 56.27 56.34 56.35 58.0 64.0 66.38 66.50 66.79 66.83 66.130 66.134 68.39 68.43 68.54 68.58 68.76 68.80 70.31 70.35 70.40 70.44 70.64 70.68 70.75 70.80 73.83 73.86 73.103 73.115 75.103 75.104 75.125 75.126}} {richtext:font:heading0 {1.0 2.0}} {richtext:font:heading1 {3.0 4.0 8.0 9.0 12.0 13.0 21.0 22.0 26.0 27.0 52.0 53.0 72.0 73.0}} {richtext:font:heading2 {9.0 10.0 13.0 14.0 18.0 19.0 22.0 23.0 27.0 28.0 31.0 32.0 33.0 34.0 47.0 48.0 53.0 54.0 55.0 56.0 57.0 58.0 65.0 66.0}} {jdoc:link:jstools.jdoc {4.57 4.64}} {jdoc:manpage:tclvars {10.131 10.138}} {jdoc:link:jslibraries.tcl {10.215 10.236}} {jdoc:link:jslibraries.jdoc#Usage {10.244 10.261}} {jdoc:link:jslibraries.jdoc {10.265 10.286}} {{} {12.0 19.0 22.0 22.10}} {jdoc:manpage:proc {48.218 48.222}} {jdoc:manpage:getopt {50.28 50.34}} {jdoc:anchorname:j:parse_args {26.0 27.0}} {jdoc:anchorname:Overview {21.0 22.0}} {jdoc:anchorname:Credits_and_Copyright {12.0 13.0}} {jdoc:anchorname:Usage {8.0 9.0}} {jdoc:anchorname:Introduction {3.0 4.0}} {jdoc:anchorname:j:parse_argv {52.0 53.0}} {jdoc:link:#j:parse_args {23.0 23.12 66.38 66.50}} {jdoc:link:#j:parse_argv {24.0 24.12}} {jdoc:manpage:tclsh {70.75 70.80}} {jdoc:manpage:wish {70.64 70.68}}} {{abbrevstart 76.0} {richptr 76.0} {abbrevend 76.0} {insert 1.0} {anchor 1.0} {current 1.0}}}