Skip to content
Snippets Groups Projects
Commit 82acdced authored by Fredrik Hübinette (Hubbe)'s avatar Fredrik Hübinette (Hubbe)
Browse files

doc for find_option

Rev: doc/simulated/find_option:1.1
parent ff3e7503
No related branches found
No related tags found
No related merge requests found
NAME
find_option - find command line options
SYNTAX
#include <getopt.h>
mixed find_option(string *argv,
string shortform,
string longform,
string envvar,
mixed def);
DESCRIPTION
This is a generic function to parse command line options of the
type '-f', '--foo' or '--foo=bar'. The first argument should be
the array of strings that is sent as second argument to your
main() function, the second is a string with the short form of
your option. The short form must be only one character long.
The 'longform' is an alternative and maybe more readable way to
give the same option. If you give "foo" as longform your program
will accept --foo as argument. The envvar argument specifies what
environment variable can be used to specify the same option. The
envvar option exists to make it easier to custimizer program usage.
The 'def' has two functions: It specifies that the option takes an
argument and it tells find_option what to return if the option is
not present. If 'def' is given and the option does not have an
argument find_option will print an error message and exit the program.
Also, as an extra bonus: shortform, longform and envvar can all be
arrays, in which case either of the options in the array will be
accpted.
NOTA BENE
find_option modifies argv.
EXAMPLE
int main(int argc, string *argv)
{
if(find_option(argv,"f","foo"))
werror("The FOO option was given.\n");
werror("The BAR option got the "+
find_option(argv,"b","bar","BAR_OPTION","default")+
" argument.\n");
}
SEE ALSO
get_args
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment