From 82acdcedc072703e7c5e225f5bbb3c89849cfe06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20H=C3=BCbinette=20=28Hubbe=29?= <hubbe@hubbe.net> Date: Tue, 15 Oct 1996 05:53:08 +0200 Subject: [PATCH] doc for find_option Rev: doc/simulated/find_option:1.1 --- doc/simulated/find_option | 48 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 doc/simulated/find_option diff --git a/doc/simulated/find_option b/doc/simulated/find_option new file mode 100644 index 0000000000..83671cf06a --- /dev/null +++ b/doc/simulated/find_option @@ -0,0 +1,48 @@ +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 -- GitLab