+
+ *arg_desc->opt_bool = negate ? !value : value;
+
+ return OPT_OK;
+}
+
+static opt_handled
+_process_int_arg (const notmuch_opt_desc_t *arg_desc, char next, const char *arg_str) {
+
+ char *endptr;
+ if (next == '\0' || arg_str[0] == '\0') {
+ fprintf (stderr, "Option \"%s\" needs an integer argument.\n", arg_desc->name);
+ return OPT_FAILED;
+ }
+
+ *arg_desc->opt_int = strtol (arg_str, &endptr, 10);
+ if (*endptr == '\0')
+ return OPT_OK;
+
+ fprintf (stderr, "Unable to parse argument \"%s\" for option \"%s\" as an integer.\n",
+ arg_str, arg_desc->name);
+ return OPT_FAILED;
+}
+
+static opt_handled
+_process_string_arg (const notmuch_opt_desc_t *arg_desc, char next, const char *arg_str) {
+
+ if (next == '\0') {
+ fprintf (stderr, "Option \"%s\" needs a string argument.\n", arg_desc->name);
+ return OPT_FAILED;
+ }
+ if (arg_str[0] == '\0' && ! arg_desc->allow_empty) {
+ fprintf (stderr, "String argument for option \"%s\" must be non-empty.\n", arg_desc->name);
+ return OPT_FAILED;
+ }
+ *arg_desc->opt_string = arg_str;
+ return OPT_OK;
+}
+
+/* Return number of non-NULL opt_* fields in opt_desc. */
+static int _opt_set_count (const notmuch_opt_desc_t *opt_desc)
+{
+ return
+ !!opt_desc->opt_inherit +
+ !!opt_desc->opt_bool +
+ !!opt_desc->opt_int +
+ !!opt_desc->opt_keyword +
+ !!opt_desc->opt_flags +
+ !!opt_desc->opt_string +
+ !!opt_desc->opt_position;
+}
+
+/* Return true if opt_desc is valid. */
+static bool _opt_valid (const notmuch_opt_desc_t *opt_desc)
+{
+ int n = _opt_set_count (opt_desc);
+
+ if (n > 1)
+ INTERNAL_ERROR ("more than one non-NULL opt_* field for argument \"%s\"",
+ opt_desc->name);
+
+ return n > 0;