]> git.notmuchmail.org Git - notmuch/blob - command-line-arguments.h
lib: check talloc success in compact
[notmuch] / command-line-arguments.h
1 #ifndef NOTMUCH_OPTS_H
2 #define NOTMUCH_OPTS_H
3
4 #include "notmuch.h"
5
6 enum notmuch_opt_type {
7     NOTMUCH_OPT_END = 0,
8     NOTMUCH_OPT_BOOLEAN,        /* --verbose              */
9     NOTMUCH_OPT_INT,            /* --frob=8               */
10     NOTMUCH_OPT_KEYWORD,        /* --format=raw|json|text */
11     NOTMUCH_OPT_STRING,         /* --file=/tmp/gnarf.txt  */
12     NOTMUCH_OPT_POSITION        /* notmuch dump pos_arg   */
13 };
14
15 /*
16  * Describe one of the possibilities for a keyword option
17  * 'value' will be copied to the output variable
18  */
19
20 typedef struct notmuch_keyword {
21     const char *name;
22     int value;
23 } notmuch_keyword_t;
24
25 /*
26  * Describe one option.
27  *
28  * First two parameters are mandatory.
29  *
30  * name is mandatory _except_ for positional arguments.
31  *
32  * arg_id is currently unused, but could define short arguments.
33  *
34  * keywords is a (possibly NULL) pointer to an array of keywords
35  */
36 typedef struct notmuch_opt_desc {
37     enum notmuch_opt_type opt_type;
38     void *output_var;
39     const char *name;
40     int  arg_id;
41     const struct notmuch_keyword *keywords;
42 } notmuch_opt_desc_t;
43
44
45 /*
46   This is the main entry point for command line argument parsing.
47
48   Parse command line arguments according to structure options,
49   starting at position opt_index.
50
51   All output of parsed values is via pointers in options.
52
53   Parsing stops at -- (consumed) or at the (k+1)st argument
54   not starting with -- (a "positional argument") if options contains
55   k positional argument descriptors.
56
57   Returns the index of first non-parsed argument, or -1 in case of error.
58
59 */
60 int
61 parse_arguments (int argc, char **argv, const notmuch_opt_desc_t *options, int opt_index);
62
63 /*
64  * If the argument parsing loop provided by parse_arguments is not
65  * flexible enough, then the user might be interested in the following
66  * routines, but note that the API to parse_option might have to
67  * change. See command-line-arguments.c for descriptions of these
68  * functions.
69  */
70
71 notmuch_bool_t
72 parse_option (const char *arg, const notmuch_opt_desc_t* options);
73
74 notmuch_bool_t
75 parse_position_arg (const char *arg,
76                     int position_arg_index,
77                     const notmuch_opt_desc_t* options);
78
79
80 #endif