diff options
Diffstat (limited to 'tools/perf/util/parse-options.c')
-rw-r--r-- | tools/perf/util/parse-options.c | 55 |
1 files changed, 49 insertions, 6 deletions
diff --git a/tools/perf/util/parse-options.c b/tools/perf/util/parse-options.c index efebd5b476b3..99d02aa57dbf 100644 --- a/tools/perf/util/parse-options.c +++ b/tools/perf/util/parse-options.c | |||
@@ -49,8 +49,9 @@ static int get_value(struct parse_opt_ctx_t *p, | |||
49 | break; | 49 | break; |
50 | /* FALLTHROUGH */ | 50 | /* FALLTHROUGH */ |
51 | case OPTION_BOOLEAN: | 51 | case OPTION_BOOLEAN: |
52 | case OPTION_INCR: | ||
52 | case OPTION_BIT: | 53 | case OPTION_BIT: |
53 | case OPTION_SET_INT: | 54 | case OPTION_SET_UINT: |
54 | case OPTION_SET_PTR: | 55 | case OPTION_SET_PTR: |
55 | return opterror(opt, "takes no value", flags); | 56 | return opterror(opt, "takes no value", flags); |
56 | case OPTION_END: | 57 | case OPTION_END: |
@@ -58,7 +59,9 @@ static int get_value(struct parse_opt_ctx_t *p, | |||
58 | case OPTION_GROUP: | 59 | case OPTION_GROUP: |
59 | case OPTION_STRING: | 60 | case OPTION_STRING: |
60 | case OPTION_INTEGER: | 61 | case OPTION_INTEGER: |
62 | case OPTION_UINTEGER: | ||
61 | case OPTION_LONG: | 63 | case OPTION_LONG: |
64 | case OPTION_U64: | ||
62 | default: | 65 | default: |
63 | break; | 66 | break; |
64 | } | 67 | } |
@@ -73,11 +76,15 @@ static int get_value(struct parse_opt_ctx_t *p, | |||
73 | return 0; | 76 | return 0; |
74 | 77 | ||
75 | case OPTION_BOOLEAN: | 78 | case OPTION_BOOLEAN: |
79 | *(bool *)opt->value = unset ? false : true; | ||
80 | return 0; | ||
81 | |||
82 | case OPTION_INCR: | ||
76 | *(int *)opt->value = unset ? 0 : *(int *)opt->value + 1; | 83 | *(int *)opt->value = unset ? 0 : *(int *)opt->value + 1; |
77 | return 0; | 84 | return 0; |
78 | 85 | ||
79 | case OPTION_SET_INT: | 86 | case OPTION_SET_UINT: |
80 | *(int *)opt->value = unset ? 0 : opt->defval; | 87 | *(unsigned int *)opt->value = unset ? 0 : opt->defval; |
81 | return 0; | 88 | return 0; |
82 | 89 | ||
83 | case OPTION_SET_PTR: | 90 | case OPTION_SET_PTR: |
@@ -120,6 +127,22 @@ static int get_value(struct parse_opt_ctx_t *p, | |||
120 | return opterror(opt, "expects a numerical value", flags); | 127 | return opterror(opt, "expects a numerical value", flags); |
121 | return 0; | 128 | return 0; |
122 | 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 | |||
123 | case OPTION_LONG: | 146 | case OPTION_LONG: |
124 | if (unset) { | 147 | if (unset) { |
125 | *(long *)opt->value = 0; | 148 | *(long *)opt->value = 0; |
@@ -136,6 +159,22 @@ static int get_value(struct parse_opt_ctx_t *p, | |||
136 | return opterror(opt, "expects a numerical value", flags); | 159 | return opterror(opt, "expects a numerical value", flags); |
137 | return 0; | 160 | return 0; |
138 | 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 | |||
139 | case OPTION_END: | 178 | case OPTION_END: |
140 | case OPTION_ARGUMENT: | 179 | case OPTION_ARGUMENT: |
141 | case OPTION_GROUP: | 180 | case OPTION_GROUP: |
@@ -441,7 +480,10 @@ int usage_with_options_internal(const char * const *usagestr, | |||
441 | switch (opts->type) { | 480 | switch (opts->type) { |
442 | case OPTION_ARGUMENT: | 481 | case OPTION_ARGUMENT: |
443 | break; | 482 | break; |
483 | case OPTION_LONG: | ||
484 | case OPTION_U64: | ||
444 | case OPTION_INTEGER: | 485 | case OPTION_INTEGER: |
486 | case OPTION_UINTEGER: | ||
445 | if (opts->flags & PARSE_OPT_OPTARG) | 487 | if (opts->flags & PARSE_OPT_OPTARG) |
446 | if (opts->long_name) | 488 | if (opts->long_name) |
447 | pos += fprintf(stderr, "[=<n>]"); | 489 | pos += fprintf(stderr, "[=<n>]"); |
@@ -473,14 +515,14 @@ int usage_with_options_internal(const char * const *usagestr, | |||
473 | pos += fprintf(stderr, " ..."); | 515 | pos += fprintf(stderr, " ..."); |
474 | } | 516 | } |
475 | break; | 517 | break; |
476 | default: /* OPTION_{BIT,BOOLEAN,SET_INT,SET_PTR} */ | 518 | default: /* OPTION_{BIT,BOOLEAN,SET_UINT,SET_PTR} */ |
477 | case OPTION_END: | 519 | case OPTION_END: |
478 | case OPTION_GROUP: | 520 | case OPTION_GROUP: |
479 | case OPTION_BIT: | 521 | case OPTION_BIT: |
480 | case OPTION_BOOLEAN: | 522 | case OPTION_BOOLEAN: |
481 | case OPTION_SET_INT: | 523 | case OPTION_INCR: |
524 | case OPTION_SET_UINT: | ||
482 | case OPTION_SET_PTR: | 525 | case OPTION_SET_PTR: |
483 | case OPTION_LONG: | ||
484 | break; | 526 | break; |
485 | } | 527 | } |
486 | 528 | ||
@@ -500,6 +542,7 @@ int usage_with_options_internal(const char * const *usagestr, | |||
500 | void usage_with_options(const char * const *usagestr, | 542 | void usage_with_options(const char * const *usagestr, |
501 | const struct option *opts) | 543 | const struct option *opts) |
502 | { | 544 | { |
545 | exit_browser(false); | ||
503 | usage_with_options_internal(usagestr, opts, 0); | 546 | usage_with_options_internal(usagestr, opts, 0); |
504 | exit(129); | 547 | exit(129); |
505 | } | 548 | } |