aboutsummaryrefslogtreecommitdiffstats
path: root/tools/lib/subcmd/parse-options.c
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2017-07-20 14:27:39 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2017-07-20 14:46:10 -0400
commit8e99b6d4533cf3f49dcd813155a513a5b572baef (patch)
treef3f082ab6d3e1916353b59e7f70735183cc72722 /tools/lib/subcmd/parse-options.c
parent082ab9a18e532864d1ceecfb50221df62b1d5a92 (diff)
tools include: Adopt strstarts() from the kernel
Replacing prefixcmp(), same purpose, inverted result, so standardize on the kernel variant, to reduce silly differences among tools/ and the kernel sources, making it easier for people to work in both codebases. And then doing: if (strstarts(option, "no-")) Looks clearer than doing: if (!prefixcmp(option, "no-")) To figure out if option starts witn "no-". Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: David Ahern <dsahern@gmail.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Josh Poimboeuf <jpoimboe@redhat.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Rusty Russell <rusty@rustcorp.com.au> Cc: Wang Nan <wangnan0@huawei.com> Link: http://lkml.kernel.org/n/tip-kaei42gi7lpa8subwtv7eug8@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/lib/subcmd/parse-options.c')
-rw-r--r--tools/lib/subcmd/parse-options.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/tools/lib/subcmd/parse-options.c b/tools/lib/subcmd/parse-options.c
index 359bfa77f39c..2bd6fd0c1d40 100644
--- a/tools/lib/subcmd/parse-options.c
+++ b/tools/lib/subcmd/parse-options.c
@@ -368,7 +368,7 @@ retry:
368 return 0; 368 return 0;
369 } 369 }
370 if (!rest) { 370 if (!rest) {
371 if (!prefixcmp(options->long_name, "no-")) { 371 if (strstarts(options->long_name, "no-")) {
372 /* 372 /*
373 * The long name itself starts with "no-", so 373 * The long name itself starts with "no-", so
374 * accept the option without "no-" so that users 374 * accept the option without "no-" so that users
@@ -381,7 +381,7 @@ retry:
381 goto match; 381 goto match;
382 } 382 }
383 /* Abbreviated case */ 383 /* Abbreviated case */
384 if (!prefixcmp(options->long_name + 3, arg)) { 384 if (strstarts(options->long_name + 3, arg)) {
385 flags |= OPT_UNSET; 385 flags |= OPT_UNSET;
386 goto is_abbreviated; 386 goto is_abbreviated;
387 } 387 }
@@ -406,7 +406,7 @@ is_abbreviated:
406 continue; 406 continue;
407 } 407 }
408 /* negated and abbreviated very much? */ 408 /* negated and abbreviated very much? */
409 if (!prefixcmp("no-", arg)) { 409 if (strstarts("no-", arg)) {
410 flags |= OPT_UNSET; 410 flags |= OPT_UNSET;
411 goto is_abbreviated; 411 goto is_abbreviated;
412 } 412 }
@@ -416,7 +416,7 @@ is_abbreviated:
416 flags |= OPT_UNSET; 416 flags |= OPT_UNSET;
417 rest = skip_prefix(arg + 3, options->long_name); 417 rest = skip_prefix(arg + 3, options->long_name);
418 /* abbreviated and negated? */ 418 /* abbreviated and negated? */
419 if (!rest && !prefixcmp(options->long_name, arg + 3)) 419 if (!rest && strstarts(options->long_name, arg + 3))
420 goto is_abbreviated; 420 goto is_abbreviated;
421 if (!rest) 421 if (!rest)
422 continue; 422 continue;
@@ -456,7 +456,7 @@ static void check_typos(const char *arg, const struct option *options)
456 if (strlen(arg) < 3) 456 if (strlen(arg) < 3)
457 return; 457 return;
458 458
459 if (!prefixcmp(arg, "no-")) { 459 if (strstarts(arg, "no-")) {
460 fprintf(stderr, " Error: did you mean `--%s` (with two dashes ?)", arg); 460 fprintf(stderr, " Error: did you mean `--%s` (with two dashes ?)", arg);
461 exit(129); 461 exit(129);
462 } 462 }
@@ -464,7 +464,7 @@ static void check_typos(const char *arg, const struct option *options)
464 for (; options->type != OPTION_END; options++) { 464 for (; options->type != OPTION_END; options++) {
465 if (!options->long_name) 465 if (!options->long_name)
466 continue; 466 continue;
467 if (!prefixcmp(options->long_name, arg)) { 467 if (strstarts(options->long_name, arg)) {
468 fprintf(stderr, " Error: did you mean `--%s` (with two dashes ?)", arg); 468 fprintf(stderr, " Error: did you mean `--%s` (with two dashes ?)", arg);
469 exit(129); 469 exit(129);
470 } 470 }
@@ -933,10 +933,10 @@ opt:
933 if (opts->long_name == NULL) 933 if (opts->long_name == NULL)
934 continue; 934 continue;
935 935
936 if (!prefixcmp(opts->long_name, optstr)) 936 if (strstarts(opts->long_name, optstr))
937 print_option_help(opts, 0); 937 print_option_help(opts, 0);
938 if (!prefixcmp("no-", optstr) && 938 if (strstarts("no-", optstr) &&
939 !prefixcmp(opts->long_name, optstr + 3)) 939 strstarts(opts->long_name, optstr + 3))
940 print_option_help(opts, 0); 940 print_option_help(opts, 0);
941 } 941 }
942 942