This file contains GNU's externs/structs/prototypes. More...
Go to the source code of this file.
Classes | |
struct | gk_option |
The structure that stores the information about the command-line options. More... | |
Macros | |
#define | no_argument 0 |
#define | optional_argument 2 |
#define | required_argument 1 |
Functions | |
int | gk_getopt (int __argc, char **__argv, char *__shortopts) |
Parse command-line arguments. More... | |
int | gk_getopt_long (int __argc, char **__argv, char *__shortopts, struct gk_option *__longopts, int *__longind) |
Parse command-line arguments with long options. More... | |
int | gk_getopt_long_only (int __argc, char **__argv, char *__shortopts, struct gk_option *__longopts, int *__longind) |
Parse command-line arguments with only long options. More... | |
Variables | |
char * | gk_optarg |
For communication arguments to the caller. More... | |
int | gk_opterr |
Controls error reporting for unrecognized options. More... | |
int | gk_optind |
Index in ARGV of the next element to be scanned. More... | |
int | gk_optopt |
Stores unknown option characters. More... | |
This file contains GNU's externs/structs/prototypes.
$Id: gk_getopt.h 10711 2011-08-31 22:23:04Z karypis $
Definition in file gk_getopt.h.
#define no_argument 0 |
Definition at line 49 of file gk_getopt.h.
#define optional_argument 2 |
Definition at line 51 of file gk_getopt.h.
#define required_argument 1 |
Definition at line 50 of file gk_getopt.h.
Parse command-line arguments.
The gk_getopt() function gets the next option argument from the argument list specified by the argv
and argc
arguments. Normally these values come directly from the arguments received by main().
argc | is the number of command line arguments passed to main(). |
argv | is an array of strings storing the above command line arguments. |
options | is a string that specifies the option characters that are valid for this program. An option character in this string can be followed by a colon (`:') to indicate that it takes a required argument. If an option character is followed by two colons (`::'), its argument is optional; this is a GNU extension. |
argc
parameter to check this.argv
array, not into a static area that might be overwritten.argv
that was not included in options, or a missing option argument, it returns `?' and sets the external variable gk_optopt to the actual option character. If the first character of options is a colon (`:'), then gk_getopt() returns `:' instead of `?' to indicate a missing option argument. In addition, if the external variable gk_opterr is nonzero (which is the default), gk_getopt() prints an error message. This variable is set by gk_getopt() to point at the value of the option argument, for those options that accept arguments.gk_getopt() has three ways to deal with options that follow non-options argv
elements. The special argument `–'
forces in all cases the end of option scanning.
argv
while scanning it so that eventually all the non-options are at the end. This allows options to be given in any order, even with programs that were not written to expect this.int gk_getopt_long | ( | int | argc, |
char ** | argv, | ||
char * | options, | ||
struct gk_option * | long_options, | ||
int * | opt_index | ||
) |
Parse command-line arguments with long options.
This function accepts GNU-style long options as well as single-character options.
argc | is the number of command line arguments passed to main(). |
argv | is an array of strings storing the above command line arguments. |
options | describes the short options to accept, just as it does in gk_getopt(). |
long_options | describes the long options to accept. See the defintion of gk_option for more information. |
opt_index | this is a returned variable. For any long option, gk_getopt_long() tells you the index in the array long_options of the options definition, by storing it into *opt_index . You can get the name of the option with longopts[*opt_index].name . So you can distinguish among long options either by the values in their val fields or by their indices. You can also distinguish in this way among long options that set flags. |
int gk_getopt_long_only | ( | int | argc, |
char ** | argv, | ||
char * | options, | ||
struct gk_option * | long_options, | ||
int * | opt_index | ||
) |
Parse command-line arguments with only long options.
Like gk_getopt_long(), but '-' as well as '–' can indicate a long option. If an option that starts with '-' (not '–') doesn't match a long option, but does match a short option, it is parsed as a short option instead.
char* gk_optarg |
int gk_opterr |
Controls error reporting for unrecognized options.
If the value of this variable is nonzero, then getopt prints an error message to the standard error stream if it encounters an unknown option character or an option with a missing required argument. This is the default behavior. If you set this variable to zero, getopt does not print any messages, but it still returns the character ? to indicate an error.
int gk_optind |
Index in ARGV of the next element to be scanned.
This variable is set by getopt to the index of the next element of the argv array to be processed. Once getopt has found all of the option arguments, you can use this variable to determine where the remaining non-option arguments begin.