- {
- if (options[j].long_option != NULL
- && (dashes == 2
- || (options[j].dash
- != options::One_option::EXACTLY_TWO_DASHES))
- && first == options[j].long_option[0]
- && strcmp(opt, options[j].long_option) == 0)
- {
- if (options[j].special)
- {
- // Restore the '=' we clobbered above.
- if (arg != NULL && skiparg == 0)
- arg[-1] = '=';
- i += options[j].special(argc - i, argv + i, opt, true, this);
- }
- else
- {
- if (!options[j].takes_argument())
- {
- if (argument_with_equals)
- this->usage(_("unexpected argument"), argv[i]);
- arg = NULL;
- skiparg = 0;
- }
- else
- {
- if (arg == NULL)
- this->usage(_("missing argument"), argv[i]);
- }
- this->apply_option(options[j], arg);
- i += skiparg + 1;
- }
- break;
- }
- }
- if (j < options_size)
- continue;
-
- // If we saw two dashes, we need to see a long option.
- if (dashes == 2)
- this->usage(_("unknown option"), argv[i]);
-
- // Look for a short option match. There may be more than one
- // short option in a given argument.
- bool done = false;
- char* s = argv[i] + 1;
- ++i;
- while (*s != '\0' && !done)
- {
- char opt = *s;
- int j;
- for (j = 0; j < options_size; ++j)
- {
- if (options[j].short_option == opt)
- {
- if (options[j].special)
- {
- // Undo the argument skip done above.
- --i;
- i += options[j].special(argc - i, argv + i, s, false,
- this);
- done = true;
- }
- else
- {
- arg = NULL;
- if (options[j].takes_argument())
- {
- if (s[1] != '\0')
- {
- arg = s + 1;
- done = true;
- }
- else if (i < argc)
- {
- arg = argv[i];
- ++i;
- }
- else
- this->usage(_("missing argument"), opt);
- }
- this->apply_option(options[j], arg);
- }
- break;
- }
- }
+ {
+ if (options[j].short_option == opt)
+ {
+ if (options[j].special)
+ {
+ // Undo the argument skip done above.
+ --i;
+ i += options[j].special(argc - i, argv + i, s, false,
+ this);
+ done = true;
+ }
+ else
+ {
+ arg = NULL;
+ if (options[j].takes_argument())
+ {
+ if (s[1] != '\0')
+ {
+ arg = s + 1;
+ done = true;
+ }
+ else if (i < argc)
+ {
+ arg = argv[i];
+ ++i;
+ }
+ else
+ this->usage(_("missing argument"), opt);
+ }
+ this->apply_option(options[j], arg);
+ }
+ break;
+ }
+ }
+
+ if (j >= options_size)
+ this->usage(_("unknown option"), *s);
+
+ ++s;
+ }
+ return i;
+}