+
+ if (! try->name)
+ continue;
+
+ char next;
+ const char *value;
+ bool negate = false;
+
+ if (strncmp (arg, try->name, strlen (try->name)) == 0) {
+ next = arg[strlen (try->name)];
+ value = arg + strlen (try->name) + 1;
+ } else if (negative_arg && (try->opt_bool || try->opt_flags) &&
+ strncmp (negative_arg, try->name, strlen (try->name)) == 0) {
+ next = negative_arg[strlen (try->name)];
+ value = negative_arg + strlen (try->name) + 1;
+ /* The argument part of --no-argument matches, negate the result. */
+ negate = true;
+ } else {
+ continue;
+ }
+
+ /*
+ * If we have not reached the end of the argument (i.e. the
+ * next character is not a space or delimiter) then the
+ * argument could still match a longer option name later in
+ * the option table.
+ */
+ if (next != '=' && next != ':' && next != '\0')
+ continue;
+
+ bool lookahead = (next == '\0' && next_arg != NULL && ! try->opt_bool);
+
+ if (lookahead) {
+ next = ' ';
+ value = next_arg;
+ opt_index++;
+ }
+
+ opt_handled opt_status = OPT_FAILED;
+ if (try->opt_keyword || try->opt_flags)
+ opt_status = _process_keyword_arg (try, next, value, negate);
+ else if (try->opt_bool)
+ opt_status = _process_boolean_arg (try, next, value, negate);
+ else if (try->opt_int)
+ opt_status = _process_int_arg (try, next, value);
+ else if (try->opt_string)
+ opt_status = _process_string_arg (try, next, value);
+ else
+ INTERNAL_ERROR ("unknown or unhandled option \"%s\"", try->name);
+
+ if (opt_status == OPT_FAILED)
+ return -1;
+
+ if (lookahead && opt_status == OPT_GIVEBACK)
+ opt_index--;
+
+ if (try->present)
+ *try->present = true;
+
+ return opt_index + 1;