]> git.notmuchmail.org Git - notmuch/blob - command-line-arguments.h
ff51abceb117dbac79da53c728c8555d56d37263
[notmuch] / command-line-arguments.h
1 #ifndef NOTMUCH_OPTS_H
2 #define NOTMUCH_OPTS_H
3
4 #include "notmuch.h"
5
6 /*
7  * Describe one of the possibilities for a keyword option
8  * 'value' will be copied to the output variable
9  */
10
11 typedef struct notmuch_keyword {
12     const char *name;
13     int value;
14 } notmuch_keyword_t;
15
16 /* Describe one option. */
17 typedef struct notmuch_opt_desc {
18     /* One and only one of opt_* must be set. */
19     const struct notmuch_opt_desc *opt_inherit;
20     notmuch_bool_t *opt_bool;
21     int *opt_int;
22     int *opt_keyword;
23     int *opt_flags;
24     const char **opt_string;
25     const char **opt_position;
26
27     /* Must be set except for opt_inherit and opt_position. */
28     const char *name;
29
30     /* Must be set for opt_keyword and opt_flags. */
31     const struct notmuch_keyword *keywords;
32 } notmuch_opt_desc_t;
33
34
35 /*
36   This is the main entry point for command line argument parsing.
37
38   Parse command line arguments according to structure options,
39   starting at position opt_index.
40
41   All output of parsed values is via pointers in options.
42
43   Parsing stops at -- (consumed) or at the (k+1)st argument
44   not starting with -- (a "positional argument") if options contains
45   k positional argument descriptors.
46
47   Returns the index of first non-parsed argument, or -1 in case of error.
48
49 */
50 int
51 parse_arguments (int argc, char **argv, const notmuch_opt_desc_t *options, int opt_index);
52
53 /*
54  * If the argument parsing loop provided by parse_arguments is not
55  * flexible enough, then the user might be interested in the following
56  * routines, but note that the API to parse_option might have to
57  * change. See command-line-arguments.c for descriptions of these
58  * functions.
59  */
60
61 int
62 parse_option (int argc, char **argv, const notmuch_opt_desc_t* options, int opt_index);
63
64 notmuch_bool_t
65 parse_position_arg (const char *arg,
66                     int position_arg_index,
67                     const notmuch_opt_desc_t* options);
68
69
70 #endif