Create a cmdopt object for parsing command-line options
Usage
obj = cmdopt_new (Ref_Type error_routine)
Description
This function creates an returns an object that may be used by the
cmdopt_process function to parse command line arguments. The
cmdopt_new function takes a reference to an error handling
function that will get called upon error. In most cases, this
function should print out the error message, display a usage
message, and then call exit. If the error handler is NULL,
or it returns instead of calling exit, then an exception will be thrown.
The error handler must be defined to take a single string argument
(the error message) and must return nothing.
This function parses the command line arguments in the string array
argv according to the rules specified by the optobj
object, previously allocated by cmdopt_new. The array of
strings is processed starting at the index specified by
istart. The function returns the index of the array element
where parsing stopped. Upon error, the function will call the error
handler established by the prior call to cmdopt_new.
This function adds support for a command-line option to
optobj and specifies how that option should be handled.
Handling an option involves setting the value of a variable
associated with the option, or by calling a function upon its
behalf.
For clarity, assume a command-line option can be specified using the
single character f or by the longer name foo. Then the
rules for calling cmdopt_add for the various flavors options
supported by this interface and how the option may be specified on
the command line are as follows:
cmdopt_add (optobj, "f|foo", &v; type="string", optional=DFLT);
cmdline: pgm -f ... % set v to DFLT
cmdline: pgm -fVAL ... % set v to VAL
cmdline: pgm --foo ... % set v to DFLT
cmdline: pgm --foo=VAL ... % set v to VAL
For the latter two cases, if the append qualifier is used,
then instead of assigning the value to the specified variable, the
value will be appended to a list assigned to the variable, e.g.,
As the above examples illustrate, the data-type of the value assigned
to a variable must be specified using the type qualifier.
Currently the type must be set to one of the following values: