|
NAMEparse_opts - parse standard and user options for LTP test programsSYNOPSIS#include ”test.h” #include ”usctest.h” char *parse_opts(int argc, char *argv[], option_t option_array[], void (*user_help_func)()); DESCRIPTIONThe parse_opts() routine parses options from the command line, looking for user specified options or standard options (see below). Its arguments argc and argv are the argument count and array as passed to the main() function on program invocation. User options may be specified in the option_array argument. A help function may be specified in the user_help_func argument.option_array is a pointer to the first element of an array of option_t. If no additional options are needed, pass NULL. option_t is declared in usctest.h as
The meanings of the different fields are:
user_help_func is a pointer to a function that will be called when the -h option is found. This function should print help messages for the options in option_array to standard out. The standard help messages are formatted such that the option designator starts in column 3 and the description starts in column 11. STANDARD OPTIONSBelow is a list of the standard options defined in parse_opts():
The STD_* flags are used by system call test macros defined in usctest.h (see usctest(3)), or may be used in the user's code. RETURN VALUEparse_opts() returns a NULL pointer upon successful completion. If an error occurs a pointer to an error message is returned.EXAMPLEThe following example defines two options, one with an argument, one without.int fflag, Tflag; /* binary flags: opt or not */ char *Topt; /* option arguments */ option_t options[] = { { "F", &fflag, NULL }, /* No argument */ { "T:", &Tflag, &Topt }, /* argument required */ { NULL, NULL, NULL } /* NULL required to end array */ }; void help() { printf(" -F An option with no argument\n"); printf(" -T opt An option that requires an argument\n"); } int main(int argc, char *argv[]) { char *msg; if ((msg = parse_opts(argc, argv, options, &help)) != NULL) error_exit(msg); return 0; } The following example shows how to use parse_opts() without defining new options. int main(int argc, char *argv[]) { char *msg; if ((msg = parse_opts(argc, argv, NULL, NULL)) != NULL) error_exit(msg); return 0; } SEE ALSOusctest(3), getopt(3).
Visit the GSP FreeBSD Man Page Interface. |