-
Notifications
You must be signed in to change notification settings - Fork 1
ReadArgs
Srinivas Nayak edited this page Dec 23, 2014
·
5 revisions
NAME
ReadArgs - Parse the command line input.
SYNOPSIS
result = ReadArgs(template, array);
struct RDArgs * ReadArgs(STRPTR, LONG *);
FUNCTION
Parses command line input (argument string) according to a template.
It gets the arguments by reading buffered IO from Input().
MUST be matched by a call to FreeArgs().
ReadArgs() parses the command line according to a template that is
passed to it. Template specifies different command line options and
their types. A template consists of a list of options. Options are
better named in "full" names (for example, "Quick" instead of
"Q"). Abbreviations not supported (for example, "Q=Quick").
Templates can't be empty.
Options in the template are separated by commas. To get the results
of ReadArgs(), you examine the array of longwords you passed to it
(one entry per option in the template). This array should be cleared
(or initialized to your default values) before passing to ReadArgs().
Exactly what is put in a given entry by ReadArgs() depends on the type
of option. The default is a string (a sequence of non-whitespace
characters, or delimited by quotes, which will be stripped by
ReadArgs()), in which case the entry will be a pointer.
Options can be followed by modifiers, which specify things such as
the type of the option. Modifiers are specified by following the
option with a '/' and a single character modifier. Multiple modifiers
can be specified by using multiple '/'s. Valid modifiers are:
/S - Switch. This is considered a boolean variable, and will be
set if the option name appears in the command line. The entry
is the boolean (0 for not set, non-zero for set).
/K - Keyword. This means that the option will not be filled unless
the keyword appears. For example if the template is "Name/K",
then unless "Name=<string>" or "Name <string>" appears in the
command line, Name will not be filled.
/N - Number. This parameter is considered a decimal number, and will
be converted by ReadArgs. If an invalid number is specified,
an error will be returned. The entry will be a pointer to a
longword number.
/A - Required. This keyword must be given a value during command line
processing, or an error is returned.
/M - Multiple strings. This means the argument will take any number
of strings, returning them as an array of strings.
Only one /M should be specified in a template. Example:
for a template "Dir/M,All/S" the command-line "foo bar all qwe"
will set the boolean "all", and return an array consisting of
"foo", "bar", and "qwe". The entry in the array will be a pointer
to an array of string pointers, the last of which will be NULL.
The /M modifier when specified with /N option, this means
the argument will take any number of numbers, returning them as
an array of numbers. The entry in the array will be a pointer
to an array of numbers, the first of which will be the count of
numbers present in the array.
There is an interaction between /M parameter and /A parameter.
If there is an unfilled /A parameter after parsing, it will grab
a string from the end of a previous /M parameter list to fill the
/A. This is used for things like Copy ("From/A/M,To/A").
ReadArgs() returns a struct RDArgs if it succeeds. This serves as an
"anchor" to allow FreeArgs() to free the associated memory.
INPUTS
template - formatting string
array - array of longwords for results, 1 per template entry
RESULT
result - a struct RDArgs or NULL for failure.
SEE ALSO