#ifndef OPT_H #define OPT_H struct option { const char *name; unsigned int has_arg : 1; }; enum { OPT_ERROR_SUCCESS, OPT_ERROR_UNRECOGNIZED_OPTION, OPT_ERROR_AMBIGUOUS_OPTION, OPT_ERROR_MISSING_ARGUMENT, OPT_ERROR_UNKNOWN, OPT_NR_ERRORS }; /* * *argsp: * points to command line arguments * args[0] is the first argument (not program name) * * options: * array of struct option. terminated with { NULL, 0 } * * option_handler: * arguments: * opt - index to options array * arg - argument to the option or NULL * returns 0 on success, -1 on error * * error_handler: * if NULL then standard error handler is used * arguments: * args - command line arguments (args[0] is where the error is) * error - OPT_ERROR_* * * returns number of arguments parsed */ int options_parse(char ***argsp, const struct option *options, int (*option_handler)(int opt, const char *arg), int (*error_handler)(char **args, int error)); #endif