MCPcopy Index your code
hub / github.com/git/git / parse_long_opt

Function parse_long_opt

parse-options.c:519–594  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

517}
518
519static enum parse_opt_result parse_long_opt(
520 struct parse_opt_ctx_t *p, const char *arg,
521 const struct option *options)
522{
523 const char *arg_end = strchrnul(arg, '=');
524 const char *arg_start = arg;
525 enum opt_parsed flags = OPT_LONG;
526 int arg_starts_with_no_no = 0;
527 struct parsed_option abbrev = { .option = NULL, .flags = OPT_LONG };
528 struct parsed_option ambiguous = { .option = NULL, .flags = OPT_LONG };
529
530 if (skip_prefix(arg_start, "no-", &arg_start)) {
531 if (skip_prefix(arg_start, "no-", &arg_start))
532 arg_starts_with_no_no = 1;
533 else
534 flags |= OPT_UNSET;
535 }
536
537 for (; options->type != OPTION_END; options++) {
538 const char *rest, *long_name = options->long_name;
539 enum opt_parsed opt_flags = OPT_LONG;
540 int allow_unset = !(options->flags & PARSE_OPT_NONEG);
541
542 if (options->type == OPTION_SUBCOMMAND)
543 continue;
544 if (!long_name)
545 continue;
546
547 if (skip_prefix(long_name, "no-", &long_name))
548 opt_flags |= OPT_UNSET;
549 else if (arg_starts_with_no_no)
550 continue;
551
552 if (((flags ^ opt_flags) & OPT_UNSET) && !allow_unset)
553 continue;
554
555 if (skip_prefix(arg_start, long_name, &rest)) {
556 if (*rest == '=')
557 p->opt = rest + 1;
558 else if (*rest)
559 continue;
560 return get_value(p, options, flags ^ opt_flags);
561 }
562
563 /* abbreviated? */
564 if (!strncmp(long_name, arg_start, arg_end - arg_start))
565 register_abbrev(p, options, flags ^ opt_flags,
566 &abbrev, &ambiguous);
567
568 /* negated and abbreviated very much? */
569 if (allow_unset && starts_with("no-", arg))
570 register_abbrev(p, options, OPT_UNSET ^ opt_flags,
571 &abbrev, &ambiguous);
572 }
573
574 if (disallow_abbreviated_options && (ambiguous.option || abbrev.option))
575 die("disallowed abbreviated or ambiguous option '%.*s'",
576 (int)(arg_end - arg), arg);

Callers 1

parse_options_stepFunction · 0.70

Calls 5

register_abbrevFunction · 0.85
starts_withFunction · 0.85
errorFunction · 0.85
get_valueFunction · 0.70
dieFunction · 0.70

Tested by

no test coverage detected