diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2018-10-18 14:24:07 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2018-10-19 10:56:58 -0400 |
commit | 4ba8b3ebf4f8f583c2c01da20e4d110a5881ffdd (patch) | |
tree | d3f336fe6e030373d13e25af7aca8134df77f0fe /tools/lib | |
parent | 389373d3306553896a9e218493e5b6175c844eb0 (diff) |
tools lib subcmd: Introduce OPTION_ULONG
For completeness, will be used in 'perf trace --max-events'.
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Kim Phillips <kim.phillips@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: https://lkml.kernel.org/n/tip-glaj3pwespxfj2fdjs9a20b6@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/lib')
-rw-r--r-- | tools/lib/subcmd/parse-options.c | 19 | ||||
-rw-r--r-- | tools/lib/subcmd/parse-options.h | 2 |
2 files changed, 21 insertions, 0 deletions
diff --git a/tools/lib/subcmd/parse-options.c b/tools/lib/subcmd/parse-options.c index cb7154eccbdc..dbb9efbf718a 100644 --- a/tools/lib/subcmd/parse-options.c +++ b/tools/lib/subcmd/parse-options.c | |||
@@ -116,6 +116,7 @@ static int get_value(struct parse_opt_ctx_t *p, | |||
116 | case OPTION_INTEGER: | 116 | case OPTION_INTEGER: |
117 | case OPTION_UINTEGER: | 117 | case OPTION_UINTEGER: |
118 | case OPTION_LONG: | 118 | case OPTION_LONG: |
119 | case OPTION_ULONG: | ||
119 | case OPTION_U64: | 120 | case OPTION_U64: |
120 | default: | 121 | default: |
121 | break; | 122 | break; |
@@ -166,6 +167,7 @@ static int get_value(struct parse_opt_ctx_t *p, | |||
166 | case OPTION_INTEGER: | 167 | case OPTION_INTEGER: |
167 | case OPTION_UINTEGER: | 168 | case OPTION_UINTEGER: |
168 | case OPTION_LONG: | 169 | case OPTION_LONG: |
170 | case OPTION_ULONG: | ||
169 | case OPTION_U64: | 171 | case OPTION_U64: |
170 | default: | 172 | default: |
171 | break; | 173 | break; |
@@ -295,6 +297,22 @@ static int get_value(struct parse_opt_ctx_t *p, | |||
295 | return opterror(opt, "expects a numerical value", flags); | 297 | return opterror(opt, "expects a numerical value", flags); |
296 | return 0; | 298 | return 0; |
297 | 299 | ||
300 | case OPTION_ULONG: | ||
301 | if (unset) { | ||
302 | *(unsigned long *)opt->value = 0; | ||
303 | return 0; | ||
304 | } | ||
305 | if (opt->flags & PARSE_OPT_OPTARG && !p->opt) { | ||
306 | *(unsigned long *)opt->value = opt->defval; | ||
307 | return 0; | ||
308 | } | ||
309 | if (get_arg(p, opt, flags, &arg)) | ||
310 | return -1; | ||
311 | *(unsigned long *)opt->value = strtoul(arg, (char **)&s, 10); | ||
312 | if (*s) | ||
313 | return opterror(opt, "expects a numerical value", flags); | ||
314 | return 0; | ||
315 | |||
298 | case OPTION_U64: | 316 | case OPTION_U64: |
299 | if (unset) { | 317 | if (unset) { |
300 | *(u64 *)opt->value = 0; | 318 | *(u64 *)opt->value = 0; |
@@ -703,6 +721,7 @@ static void print_option_help(const struct option *opts, int full) | |||
703 | case OPTION_ARGUMENT: | 721 | case OPTION_ARGUMENT: |
704 | break; | 722 | break; |
705 | case OPTION_LONG: | 723 | case OPTION_LONG: |
724 | case OPTION_ULONG: | ||
706 | case OPTION_U64: | 725 | case OPTION_U64: |
707 | case OPTION_INTEGER: | 726 | case OPTION_INTEGER: |
708 | case OPTION_UINTEGER: | 727 | case OPTION_UINTEGER: |
diff --git a/tools/lib/subcmd/parse-options.h b/tools/lib/subcmd/parse-options.h index 92fdbe1519f6..6ca2a8bfe716 100644 --- a/tools/lib/subcmd/parse-options.h +++ b/tools/lib/subcmd/parse-options.h | |||
@@ -25,6 +25,7 @@ enum parse_opt_type { | |||
25 | OPTION_STRING, | 25 | OPTION_STRING, |
26 | OPTION_INTEGER, | 26 | OPTION_INTEGER, |
27 | OPTION_LONG, | 27 | OPTION_LONG, |
28 | OPTION_ULONG, | ||
28 | OPTION_CALLBACK, | 29 | OPTION_CALLBACK, |
29 | OPTION_U64, | 30 | OPTION_U64, |
30 | OPTION_UINTEGER, | 31 | OPTION_UINTEGER, |
@@ -133,6 +134,7 @@ struct option { | |||
133 | #define OPT_INTEGER(s, l, v, h) { .type = OPTION_INTEGER, .short_name = (s), .long_name = (l), .value = check_vtype(v, int *), .help = (h) } | 134 | #define OPT_INTEGER(s, l, v, h) { .type = OPTION_INTEGER, .short_name = (s), .long_name = (l), .value = check_vtype(v, int *), .help = (h) } |
134 | #define OPT_UINTEGER(s, l, v, h) { .type = OPTION_UINTEGER, .short_name = (s), .long_name = (l), .value = check_vtype(v, unsigned int *), .help = (h) } | 135 | #define OPT_UINTEGER(s, l, v, h) { .type = OPTION_UINTEGER, .short_name = (s), .long_name = (l), .value = check_vtype(v, unsigned int *), .help = (h) } |
135 | #define OPT_LONG(s, l, v, h) { .type = OPTION_LONG, .short_name = (s), .long_name = (l), .value = check_vtype(v, long *), .help = (h) } | 136 | #define OPT_LONG(s, l, v, h) { .type = OPTION_LONG, .short_name = (s), .long_name = (l), .value = check_vtype(v, long *), .help = (h) } |
137 | #define OPT_ULONG(s, l, v, h) { .type = OPTION_ULONG, .short_name = (s), .long_name = (l), .value = check_vtype(v, unsigned long *), .help = (h) } | ||
136 | #define OPT_U64(s, l, v, h) { .type = OPTION_U64, .short_name = (s), .long_name = (l), .value = check_vtype(v, u64 *), .help = (h) } | 138 | #define OPT_U64(s, l, v, h) { .type = OPTION_U64, .short_name = (s), .long_name = (l), .value = check_vtype(v, u64 *), .help = (h) } |
137 | #define OPT_STRING(s, l, v, a, h) { .type = OPTION_STRING, .short_name = (s), .long_name = (l), .value = check_vtype(v, const char **), .argh = (a), .help = (h) } | 139 | #define OPT_STRING(s, l, v, a, h) { .type = OPTION_STRING, .short_name = (s), .long_name = (l), .value = check_vtype(v, const char **), .argh = (a), .help = (h) } |
138 | #define OPT_STRING_OPTARG(s, l, v, a, h, d) \ | 140 | #define OPT_STRING_OPTARG(s, l, v, a, h, d) \ |