#include <stdio.h>
#include "error_util.h"
#include "command-line-arguments.h"
+#include "string-util.h"
/*
Search the array of keywords for a given argument, assigning the
return FALSE;
}
+/*
+ An arguments composed of comma-separated flags is parsed and the
+ output variable is assigned the ORed flag values. Return FALSE in
+ case of error.
+*/
+static notmuch_bool_t
+_process_flags_arg (const notmuch_opt_desc_t *arg_desc, char next, const char *arg_str) {
+
+ const notmuch_keyword_t *keyword;
+ const char *flag = arg_str;
+ size_t flen = 0;
+ notmuch_bool_t match;
+
+ if (next == '\0' || *arg_str == '\0') {
+ /* No flag given */
+ fprintf (stderr, "Option \"%s\" needs an flags argument.\n", arg_desc->name);
+ return FALSE;
+ }
+
+ while ((flag = strtok_len_c (flag + flen, ",", &flen))) {
+ for (keyword = arg_desc->keywords, match = FALSE; keyword->name; keyword++) {
+ if (strncmp (flag, keyword->name, flen) == 0 &&
+ flen == strlen (keyword->name)) {
+ *((int *)arg_desc->output_var) |= keyword->value;
+ match = TRUE;
+ break;
+ }
+ }
+ if (! match) {
+ fprintf (stderr, "Unknown flag argument \"%.*s\" for option \"%s\".\n", (int)flen, flag, arg_desc->name);
+ return FALSE;
+ }
+ }
+ return TRUE;
+}
+
+
static notmuch_bool_t
_process_boolean_arg (const notmuch_opt_desc_t *arg_desc, char next, const char *arg_str) {
switch (try->opt_type) {
case NOTMUCH_OPT_KEYWORD:
return _process_keyword_arg (try, next, value);
+ case NOTMUCH_OPT_FLAGS:
+ return _process_flags_arg (try, next, value);
case NOTMUCH_OPT_BOOLEAN:
return _process_boolean_arg (try, next, value);
case NOTMUCH_OPT_INT: