| 1 | #ifndef PARSE_OPTIONS_H |
| 2 | #define PARSE_OPTIONS_H |
| 3 | |
| 4 | enum parse_opt_type { |
| 5 | OPTION_END, |
| 6 | OPTION_GROUP, |
| 7 | OPTION_BOOLEAN, |
| 8 | OPTION_STRING, |
| 9 | OPTION_INTEGER, |
| 10 | }; |
| 11 | |
| 12 | enum parse_opt_flags { |
| 13 | PARSE_OPT_KEEP_DASHDASH = 1, |
| 14 | }; |
| 15 | |
| 16 | struct option { |
| 17 | enum parse_opt_type type; |
| 18 | int short_name; |
| 19 | const char *long_name; |
| 20 | void *value; |
| 21 | const char *argh; |
| 22 | const char *help; |
| 23 | }; |
| 24 | |
| 25 | #define OPT_END() { OPTION_END } |
| 26 | #define OPT_GROUP(h) { OPTION_GROUP, 0, NULL, NULL, NULL, (h) } |
| 27 | #define OPT_BOOLEAN(s, l, v, h) { OPTION_BOOLEAN, (s), (l), (v), NULL, (h) } |
| 28 | #define OPT_INTEGER(s, l, v, h) { OPTION_INTEGER, (s), (l), (v), NULL, (h) } |
| 29 | #define OPT_STRING(s, l, v, a, h) { OPTION_STRING, (s), (l), (v), (a), (h) } |
| 30 | |
| 31 | /* parse_options() will filter out the processed options and leave the |
| 32 | * non-option argments in argv[]. |
| 33 | * Returns the number of arguments left in argv[]. |
| 34 | */ |
| 35 | extern int parse_options(int argc, const char **argv, |
| 36 | const struct option *options, |
| 37 | const char * const usagestr[], int flags); |
| 38 | |
| 39 | extern NORETURN void usage_with_options(const char * const *usagestr, |
| 40 | const struct option *options); |
| 41 | |
| 42 | #endif |