C language knowledge Supplements, struct option structure.
struct option
Indicates a long argument, often used in some console applications, you need to specify different parameters to run the program. As open source software webbench run ./webbench -h
there will be a number of options, the different parameters are specified, the program will make a different accordingly.
1 |
struct { |
Parameters:
name indicates the name of the parameter length;
has_arg indicating whether needs to follow after the argument name parameter, no_argument (0) need not, required_argument (1) must be used with parameters, optional_argument (2) may or may not;
In Flag determined getopt_long
the return value is NULL, this field returns the value val; if not NULL, it will point to the contents becomes a value in val, and return 0; if not found long option, then the same point;
val designated the default values.
Parsing long command parameters
1 |
int getopt_long(int argc, char * const argv[], |
Parameters: argc
and argv
is the command line parameters; optstring
a string consisting of option parameters, if a letter followed by a colon, such as the back t:
, then this option represents a required parameter; longopts
is a custom option structure needs; longindex
specify an index pointer.
Examples :
Original: Big Box struct-option structure c language