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