diff options
Diffstat (limited to 'tools/perf/util/parse-options.c')
-rw-r--r-- | tools/perf/util/parse-options.c | 48 |
1 files changed, 42 insertions, 6 deletions
diff --git a/tools/perf/util/parse-options.c b/tools/perf/util/parse-options.c index ed887642460c..99d02aa57dbf 100644 --- a/tools/perf/util/parse-options.c +++ b/tools/perf/util/parse-options.c | |||
@@ -51,7 +51,7 @@ static int get_value(struct parse_opt_ctx_t *p, | |||
51 | case OPTION_BOOLEAN: | 51 | case OPTION_BOOLEAN: |
52 | case OPTION_INCR: | 52 | case OPTION_INCR: |
53 | case OPTION_BIT: | 53 | case OPTION_BIT: |
54 | case OPTION_SET_INT: | 54 | case OPTION_SET_UINT: |
55 | case OPTION_SET_PTR: | 55 | case OPTION_SET_PTR: |
56 | return opterror(opt, "takes no value", flags); | 56 | return opterror(opt, "takes no value", flags); |
57 | case OPTION_END: | 57 | case OPTION_END: |
@@ -59,7 +59,9 @@ 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: |
64 | case OPTION_U64: | ||
63 | default: | 65 | default: |
64 | break; | 66 | break; |
65 | } | 67 | } |
@@ -81,8 +83,8 @@ static int get_value(struct parse_opt_ctx_t *p, | |||
81 | *(int *)opt->value = unset ? 0 : *(int *)opt->value + 1; | 83 | *(int *)opt->value = unset ? 0 : *(int *)opt->value + 1; |
82 | return 0; | 84 | return 0; |
83 | 85 | ||
84 | case OPTION_SET_INT: | 86 | case OPTION_SET_UINT: |
85 | *(int *)opt->value = unset ? 0 : opt->defval; | 87 | *(unsigned int *)opt->value = unset ? 0 : opt->defval; |
86 | return 0; | 88 | return 0; |
87 | 89 | ||
88 | case OPTION_SET_PTR: | 90 | case OPTION_SET_PTR: |
@@ -125,6 +127,22 @@ static int get_value(struct parse_opt_ctx_t *p, | |||
125 | return opterror(opt, "expects a numerical value", flags); | 127 | return opterror(opt, "expects a numerical value", flags); |
126 | return 0; | 128 | return 0; |
127 | 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 | |||
128 | case OPTION_LONG: | 146 | case OPTION_LONG: |
129 | if (unset) { | 147 | if (unset) { |
130 | *(long *)opt->value = 0; | 148 | *(long *)opt->value = 0; |
@@ -141,6 +159,22 @@ static int get_value(struct parse_opt_ctx_t *p, | |||
141 | return opterror(opt, "expects a numerical value", flags); | 159 | return opterror(opt, "expects a numerical value", flags); |
142 | return 0; | 160 | return 0; |
143 | 161 | ||
162 | case OPTION_U64: | ||
163 | if (unset) { | ||
164 | *(u64 *)opt->value = 0; | ||
165 | return 0; | ||
166 | } | ||
167 | if (opt->flags & PARSE_OPT_OPTARG && !p->opt) { | ||
168 | *(u64 *)opt->value = opt->defval; | ||
169 | return 0; | ||
170 | } | ||
171 | if (get_arg(p, opt, flags, &arg)) | ||
172 | return -1; | ||
173 | *(u64 *)opt->value = strtoull(arg, (char **)&s, 10); | ||
174 | if (*s) | ||
175 | return opterror(opt, "expects a numerical value", flags); | ||
176 | return 0; | ||
177 | |||
144 | case OPTION_END: | 178 | case OPTION_END: |
145 | case OPTION_ARGUMENT: | 179 | case OPTION_ARGUMENT: |
146 | case OPTION_GROUP: | 180 | case OPTION_GROUP: |
@@ -446,7 +480,10 @@ int usage_with_options_internal(const char * const *usagestr, | |||
446 | switch (opts->type) { | 480 | switch (opts->type) { |
447 | case OPTION_ARGUMENT: | 481 | case OPTION_ARGUMENT: |
448 | break; | 482 | break; |
483 | case OPTION_LONG: | ||
484 | case OPTION_U64: | ||
449 | case OPTION_INTEGER: | 485 | case OPTION_INTEGER: |
486 | case OPTION_UINTEGER: | ||
450 | if (opts->flags & PARSE_OPT_OPTARG) | 487 | if (opts->flags & PARSE_OPT_OPTARG) |
451 | if (opts->long_name) | 488 | if (opts->long_name) |
452 | pos += fprintf(stderr, "[=<n>]"); | 489 | pos += fprintf(stderr, "[=<n>]"); |
@@ -478,15 +515,14 @@ int usage_with_options_internal(const char * const *usagestr, | |||
478 | pos += fprintf(stderr, " ..."); | 515 | pos += fprintf(stderr, " ..."); |
479 | } | 516 | } |
480 | break; | 517 | break; |
481 | default: /* OPTION_{BIT,BOOLEAN,SET_INT,SET_PTR} */ | 518 | default: /* OPTION_{BIT,BOOLEAN,SET_UINT,SET_PTR} */ |
482 | case OPTION_END: | 519 | case OPTION_END: |
483 | case OPTION_GROUP: | 520 | case OPTION_GROUP: |
484 | case OPTION_BIT: | 521 | case OPTION_BIT: |
485 | case OPTION_BOOLEAN: | 522 | case OPTION_BOOLEAN: |
486 | case OPTION_INCR: | 523 | case OPTION_INCR: |
487 | case OPTION_SET_INT: | 524 | case OPTION_SET_UINT: |
488 | case OPTION_SET_PTR: | 525 | case OPTION_SET_PTR: |
489 | case OPTION_LONG: | ||
490 | break; | 526 | break; |
491 | } | 527 | } |
492 | 528 | ||