+
+ *arg_desc->opt_int = strtol (arg_str, &endptr, 10);
+ if (*endptr == '\0')
+ return true;
+
+ fprintf (stderr, "Unable to parse argument \"%s\" for option \"%s\" as an integer.\n",
+ arg_str, arg_desc->name);
+ return false;
+}
+
+static bool
+_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 false;
+ }
+ if (arg_str[0] == '\0') {
+ fprintf (stderr, "String argument for option \"%s\" must be non-empty.\n", arg_desc->name);
+ return false;
+ }
+ *arg_desc->opt_string = arg_str;
+ return true;
+}
+
+/* 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;