Rework make_usage to print the usage message immediately
[git/dscho.git] / parse-options.h
blob3006a769cdd561d8a66c3eaeab3307d2e8273ca3
1 #ifndef PARSE_OPTIONS_H
2 #define PARSE_OPTIONS_H
4 enum parse_opt_type {
5 OPTION_END,
6 OPTION_GROUP,
7 OPTION_BOOLEAN,
8 OPTION_STRING,
9 OPTION_INTEGER,
12 enum parse_opt_flags {
13 PARSE_OPT_KEEP_DASHDASH = 1,
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;
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) }
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[].
35 extern int parse_options(int argc, const char **argv,
36 const struct option *options,
37 const char * const usagestr[], int flags);
39 extern NORETURN void usage_with_options(const char * const *usagestr,
40 const struct option *options);
42 #endif