Add a simple option parser.
[git/dscho.git] / parse-options.h
blob76d73b299f8fdfb2dcdcf881f4e813cc14ad4db5
1 #ifndef PARSE_OPTIONS_H
2 #define PARSE_OPTIONS_H
4 enum parse_opt_type {
5 OPTION_END,
6 OPTION_BOOLEAN,
7 OPTION_STRING,
8 OPTION_INTEGER,
9 };
11 enum parse_opt_flags {
12 PARSE_OPT_KEEP_DASHDASH = 1,
15 struct option {
16 enum parse_opt_type type;
17 int short_name;
18 const char *long_name;
19 void *value;
22 #define OPT_END() { OPTION_END }
23 #define OPT_BOOLEAN(s, l, v, h) { OPTION_BOOLEAN, (s), (l), (v) }
24 #define OPT_INTEGER(s, l, v, h) { OPTION_INTEGER, (s), (l), (v) }
25 #define OPT_STRING(s, l, v, a, h) { OPTION_STRING, (s), (l), (v) }
27 /* parse_options() will filter out the processed options and leave the
28 * non-option argments in argv[].
29 * Returns the number of arguments left in argv[].
31 extern int parse_options(int argc, const char **argv,
32 const struct option *options,
33 const char *usagestr, int flags);
35 #endif