Skip to content

Commit 4ba8b3e

Browse files
committed
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>
1 parent 389373d commit 4ba8b3e

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

‎tools/lib/subcmd/parse-options.c‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ static int get_value(struct parse_opt_ctx_t *p,
116116
case OPTION_INTEGER:
117117
case OPTION_UINTEGER:
118118
case OPTION_LONG:
119+
case OPTION_ULONG:
119120
case OPTION_U64:
120121
default:
121122
break;
@@ -166,6 +167,7 @@ static int get_value(struct parse_opt_ctx_t *p,
166167
case OPTION_INTEGER:
167168
case OPTION_UINTEGER:
168169
case OPTION_LONG:
170+
case OPTION_ULONG:
169171
case OPTION_U64:
170172
default:
171173
break;
@@ -295,6 +297,22 @@ static int get_value(struct parse_opt_ctx_t *p,
295297
return opterror(opt, "expects a numerical value", flags);
296298
return 0;
297299

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+
298316
case OPTION_U64:
299317
if (unset) {
300318
*(u64 *)opt->value = 0;
@@ -703,6 +721,7 @@ static void print_option_help(const struct option *opts, int full)
703721
case OPTION_ARGUMENT:
704722
break;
705723
case OPTION_LONG:
724+
case OPTION_ULONG:
706725
case OPTION_U64:
707726
case OPTION_INTEGER:
708727
case OPTION_UINTEGER:

‎tools/lib/subcmd/parse-options.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ enum parse_opt_type {
2525
OPTION_STRING,
2626
OPTION_INTEGER,
2727
OPTION_LONG,
28+
OPTION_ULONG,
2829
OPTION_CALLBACK,
2930
OPTION_U64,
3031
OPTION_UINTEGER,
@@ -133,6 +134,7 @@ struct option {
133134
#define OPT_INTEGER(s, l, v, h) { .type = OPTION_INTEGER, .short_name = (s), .long_name = (l), .value = check_vtype(v, int *), .help = (h) }
134135
#define OPT_UINTEGER(s, l, v, h) { .type = OPTION_UINTEGER, .short_name = (s), .long_name = (l), .value = check_vtype(v, unsigned int *), .help = (h) }
135136
#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) }
136138
#define OPT_U64(s, l, v, h) { .type = OPTION_U64, .short_name = (s), .long_name = (l), .value = check_vtype(v, u64 *), .help = (h) }
137139
#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) }
138140
#define OPT_STRING_OPTARG(s, l, v, a, h, d) \

0 commit comments

Comments
 (0)