]> git.notmuchmail.org Git - notmuch/blob - command-line-arguments.h
dfc808bdab7838c81746f7671ba2fa8b3b904ce9
[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     /* Optional, if non-NULL, set to TRUE if the option is present. */
31     notmuch_bool_t *present;
32
33     /* Must be set for opt_keyword and opt_flags. */
34     const struct notmuch_keyword *keywords;
35 } notmuch_opt_desc_t;
36
37
38 /*
39   This is the main entry point for command line argument parsing.
40
41   Parse command line arguments according to structure options,
42   starting at position opt_index.
43
44   All output of parsed values is via pointers in options.
45
46   Parsing stops at -- (consumed) or at the (k+1)st argument
47   not starting with -- (a "positional argument") if options contains
48   k positional argument descriptors.
49
50   Returns the index of first non-parsed argument, or -1 in case of error.
51
52 */
53 int
54 parse_arguments (int argc, char **argv, const notmuch_opt_desc_t *options, int opt_index);
55
56 /*
57  * If the argument parsing loop provided by parse_arguments is not
58  * flexible enough, then the user might be interested in the following
59  * routines, but note that the API to parse_option might have to
60  * change. See command-line-arguments.c for descriptions of these
61  * functions.
62  */
63
64 int
65 parse_option (int argc, char **argv, const notmuch_opt_desc_t* options, int opt_index);
66
67 notmuch_bool_t
68 parse_position_arg (const char *arg,
69                     int position_arg_index,
70                     const notmuch_opt_desc_t* options);
71
72
73 #endif