Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf options: Introduce OPT_UINTEGER

For unsigned int options to be parsed, next patches will make use of it.

Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Stephane Eranian <eranian@google.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
LKML-Reference: <new-submission>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

+22 -2
+20 -2
tools/perf/util/parse-options.c
··· 59 59 case OPTION_GROUP: 60 60 case OPTION_STRING: 61 61 case OPTION_INTEGER: 62 + case OPTION_UINTEGER: 62 63 case OPTION_LONG: 63 64 case OPTION_U64: 64 65 default: ··· 123 122 if (get_arg(p, opt, flags, &arg)) 124 123 return -1; 125 124 *(int *)opt->value = strtol(arg, (char **)&s, 10); 125 + if (*s) 126 + return opterror(opt, "expects a numerical value", flags); 127 + return 0; 128 + 129 + case OPTION_UINTEGER: 130 + if (unset) { 131 + *(unsigned int *)opt->value = 0; 132 + return 0; 133 + } 134 + if (opt->flags & PARSE_OPT_OPTARG && !p->opt) { 135 + *(unsigned int *)opt->value = opt->defval; 136 + return 0; 137 + } 138 + if (get_arg(p, opt, flags, &arg)) 139 + return -1; 140 + *(unsigned int *)opt->value = strtol(arg, (char **)&s, 10); 126 141 if (*s) 127 142 return opterror(opt, "expects a numerical value", flags); 128 143 return 0; ··· 480 463 switch (opts->type) { 481 464 case OPTION_ARGUMENT: 482 465 break; 466 + case OPTION_LONG: 467 + case OPTION_U64: 483 468 case OPTION_INTEGER: 469 + case OPTION_UINTEGER: 484 470 if (opts->flags & PARSE_OPT_OPTARG) 485 471 if (opts->long_name) 486 472 pos += fprintf(stderr, "[=<n>]"); ··· 523 503 case OPTION_INCR: 524 504 case OPTION_SET_INT: 525 505 case OPTION_SET_PTR: 526 - case OPTION_LONG: 527 - case OPTION_U64: 528 506 break; 529 507 } 530 508
+2
tools/perf/util/parse-options.h
··· 18 18 OPTION_LONG, 19 19 OPTION_CALLBACK, 20 20 OPTION_U64, 21 + OPTION_UINTEGER, 21 22 }; 22 23 23 24 enum parse_opt_flags { ··· 102 101 #define OPT_SET_INT(s, l, v, h, i) { .type = OPTION_SET_INT, .short_name = (s), .long_name = (l), .value = (v), .help = (h), .defval = (i) } 103 102 #define OPT_SET_PTR(s, l, v, h, p) { .type = OPTION_SET_PTR, .short_name = (s), .long_name = (l), .value = (v), .help = (h), .defval = (p) } 104 103 #define OPT_INTEGER(s, l, v, h) { .type = OPTION_INTEGER, .short_name = (s), .long_name = (l), .value = (v), .help = (h) } 104 + #define OPT_UINTEGER(s, l, v, h) { .type = OPTION_UINTEGER, .short_name = (s), .long_name = (l), .value = (v), .help = (h) } 105 105 #define OPT_LONG(s, l, v, h) { .type = OPTION_LONG, .short_name = (s), .long_name = (l), .value = (v), .help = (h) } 106 106 #define OPT_U64(s, l, v, h) { .type = OPTION_U64, .short_name = (s), .long_name = (l), .value = (v), .help = (h) } 107 107 #define OPT_STRING(s, l, v, a, h) { .type = OPTION_STRING, .short_name = (s), .long_name = (l), .value = (v), (a), .help = (h) }