aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2010-05-17 14:30:00 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2010-05-17 14:30:00 -0400
commitc100edbee8dbf033ec4095a976a74c1c75c9fc1d (patch)
treeff4d16bfe5fb31c78e78fb6f99a297000ee07353 /tools
parentdc4ff19341126155c5714119396efbae62ab40bf (diff)
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>
Diffstat (limited to 'tools')
-rw-r--r--tools/perf/util/parse-options.c22
-rw-r--r--tools/perf/util/parse-options.h2
2 files changed, 22 insertions, 2 deletions
diff --git a/tools/perf/util/parse-options.c b/tools/perf/util/parse-options.c
index b05d51df2ce7..36d955e49422 100644
--- a/tools/perf/util/parse-options.c
+++ b/tools/perf/util/parse-options.c
@@ -59,6 +59,7 @@ static int get_value(struct parse_opt_ctx_t *p,
59 case OPTION_GROUP: 59 case OPTION_GROUP:
60 case OPTION_STRING: 60 case OPTION_STRING:
61 case OPTION_INTEGER: 61 case OPTION_INTEGER:
62 case OPTION_UINTEGER:
62 case OPTION_LONG: 63 case OPTION_LONG:
63 case OPTION_U64: 64 case OPTION_U64:
64 default: 65 default:
@@ -126,6 +127,22 @@ static int get_value(struct parse_opt_ctx_t *p,
126 return opterror(opt, "expects a numerical value", flags); 127 return opterror(opt, "expects a numerical value", flags);
127 return 0; 128 return 0;
128 129
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
129 case OPTION_LONG: 146 case OPTION_LONG:
130 if (unset) { 147 if (unset) {
131 *(long *)opt->value = 0; 148 *(long *)opt->value = 0;
@@ -463,7 +480,10 @@ int usage_with_options_internal(const char * const *usagestr,
463 switch (opts->type) { 480 switch (opts->type) {
464 case OPTION_ARGUMENT: 481 case OPTION_ARGUMENT:
465 break; 482 break;
483 case OPTION_LONG:
484 case OPTION_U64:
466 case OPTION_INTEGER: 485 case OPTION_INTEGER:
486 case OPTION_UINTEGER:
467 if (opts->flags & PARSE_OPT_OPTARG) 487 if (opts->flags & PARSE_OPT_OPTARG)
468 if (opts->long_name) 488 if (opts->long_name)
469 pos += fprintf(stderr, "[=<n>]"); 489 pos += fprintf(stderr, "[=<n>]");
@@ -503,8 +523,6 @@ int usage_with_options_internal(const char * const *usagestr,
503 case OPTION_INCR: 523 case OPTION_INCR:
504 case OPTION_SET_INT: 524 case OPTION_SET_INT:
505 case OPTION_SET_PTR: 525 case OPTION_SET_PTR:
506 case OPTION_LONG:
507 case OPTION_U64:
508 break; 526 break;
509 } 527 }
510 528
diff --git a/tools/perf/util/parse-options.h b/tools/perf/util/parse-options.h
index e301e96b9d17..c6aa4eed5edc 100644
--- a/tools/perf/util/parse-options.h
+++ b/tools/perf/util/parse-options.h
@@ -18,6 +18,7 @@ enum parse_opt_type {
18 OPTION_LONG, 18 OPTION_LONG,
19 OPTION_CALLBACK, 19 OPTION_CALLBACK,
20 OPTION_U64, 20 OPTION_U64,
21 OPTION_UINTEGER,
21}; 22};
22 23
23enum parse_opt_flags { 24enum parse_opt_flags {
@@ -101,6 +102,7 @@ struct option {
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) } 102#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) }
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) } 103#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) }
103#define OPT_INTEGER(s, l, v, h) { .type = OPTION_INTEGER, .short_name = (s), .long_name = (l), .value = (v), .help = (h) } 104#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) }
104#define OPT_LONG(s, l, v, h) { .type = OPTION_LONG, .short_name = (s), .long_name = (l), .value = (v), .help = (h) } 106#define OPT_LONG(s, l, v, h) { .type = OPTION_LONG, .short_name = (s), .long_name = (l), .value = (v), .help = (h) }
105#define OPT_U64(s, l, v, h) { .type = OPTION_U64, .short_name = (s), .long_name = (l), .value = (v), .help = (h) } 107#define OPT_U64(s, l, v, h) { .type = OPTION_U64, .short_name = (s), .long_name = (l), .value = (v), .help = (h) }
106#define OPT_STRING(s, l, v, a, h) { .type = OPTION_STRING, .short_name = (s), .long_name = (l), .value = (v), (a), .help = (h) } 108#define OPT_STRING(s, l, v, a, h) { .type = OPTION_STRING, .short_name = (s), .long_name = (l), .value = (v), (a), .help = (h) }