Skip to content

Commit c100edb

Browse files
committed
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>
1 parent dc4ff19 commit c100edb

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

‎tools/perf/util/parse-options.c‎

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ static int get_value(struct parse_opt_ctx_t *p,
5959
case OPTION_GROUP:
6060
case OPTION_STRING:
6161
case OPTION_INTEGER:
62+
case OPTION_UINTEGER:
6263
case OPTION_LONG:
6364
case OPTION_U64:
6465
default:
@@ -126,6 +127,22 @@ static int get_value(struct parse_opt_ctx_t *p,
126127
return opterror(opt, "expects a numerical value", flags);
127128
return 0;
128129

130+
case OPTION_UINTEGER:
131+
if (unset) {
132+
*(unsigned int *)opt->value = 0;
133+
return 0;
134+
}
135+
if (opt->flags & PARSE_OPT_OPTARG && !p->opt) {
136+
*(unsigned int *)opt->value = opt->defval;
137+
return 0;
138+
}
139+
if (get_arg(p, opt, flags, &arg))
140+
return -1;
141+
*(unsigned int *)opt->value = strtol(arg, (char **)&s, 10);
142+
if (*s)
143+
return opterror(opt, "expects a numerical value", flags);
144+
return 0;
145+
129146
case OPTION_LONG:
130147
if (unset) {
131148
*(long *)opt->value = 0;
@@ -463,7 +480,10 @@ int usage_with_options_internal(const char * const *usagestr,
463480
switch (opts->type) {
464481
case OPTION_ARGUMENT:
465482
break;
483+
case OPTION_LONG:
484+
case OPTION_U64:
466485
case OPTION_INTEGER:
486+
case OPTION_UINTEGER:
467487
if (opts->flags & PARSE_OPT_OPTARG)
468488
if (opts->long_name)
469489
pos += fprintf(stderr, "[=<n>]");
@@ -503,8 +523,6 @@ int usage_with_options_internal(const char * const *usagestr,
503523
case OPTION_INCR:
504524
case OPTION_SET_INT:
505525
case OPTION_SET_PTR:
506-
case OPTION_LONG:
507-
case OPTION_U64:
508526
break;
509527
}
510528

‎tools/perf/util/parse-options.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ enum parse_opt_type {
1818
OPTION_LONG,
1919
OPTION_CALLBACK,
2020
OPTION_U64,
21+
OPTION_UINTEGER,
2122
};
2223

2324
enum parse_opt_flags {
@@ -101,6 +102,7 @@ struct option {
101102
#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) }
102103
#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) }
103104
#define OPT_INTEGER(s, l, v, h) { .type = OPTION_INTEGER, .short_name = (s), .long_name = (l), .value = (v), .help = (h) }
105+
#define OPT_UINTEGER(s, l, v, h) { .type = OPTION_UINTEGER, .short_name = (s), .long_name = (l), .value = (v), .help = (h) }
104106
#define OPT_LONG(s, l, v, h) { .type = OPTION_LONG, .short_name = (s), .long_name = (l), .value = (v), .help = (h) }
105107
#define OPT_U64(s, l, v, h) { .type = OPTION_U64, .short_name = (s), .long_name = (l), .value = (v), .help = (h) }
106108
#define OPT_STRING(s, l, v, a, h) { .type = OPTION_STRING, .short_name = (s), .long_name = (l), .value = (v), (a), .help = (h) }

0 commit comments

Comments
 (0)