Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1549604
| From | Jiri Olsa <jolsa@kernel.org> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH 1/7] tools lib subcmd: Add OPT_STRING_OPTARG_SET option |
| Date | 2017-01-03 09:30 +0100 |
| Message-ID | <sVsDM-3nL-19@gated-at.bofh.it> (permalink) |
| References | <sVsDM-3nL-5@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
To allow string options with default argument and
variable set when the option is used.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Link: http://lkml.kernel.org/n/tip-xqtj0dy6t4bzah3jqi20tz43@git.kernel.org
---
tools/lib/subcmd/parse-options.c | 3 +++
tools/lib/subcmd/parse-options.h | 5 +++++
2 files changed, 8 insertions(+)
diff --git a/tools/lib/subcmd/parse-options.c b/tools/lib/subcmd/parse-options.c
index 3284bb14ae78..8aad81151d50 100644
--- a/tools/lib/subcmd/parse-options.c
+++ b/tools/lib/subcmd/parse-options.c
@@ -213,6 +213,9 @@ static int get_value(struct parse_opt_ctx_t *p,
else
err = get_arg(p, opt, flags, (const char **)opt->value);
+ if (opt->set)
+ *(bool *)opt->set = true;
+
/* PARSE_OPT_NOEMPTY: Allow NULL but disallow empty string. */
if (opt->flags & PARSE_OPT_NOEMPTY) {
const char *val = *(const char **)opt->value;
diff --git a/tools/lib/subcmd/parse-options.h b/tools/lib/subcmd/parse-options.h
index 8866ac438b34..11c3be3bcce7 100644
--- a/tools/lib/subcmd/parse-options.h
+++ b/tools/lib/subcmd/parse-options.h
@@ -137,6 +137,11 @@ struct option {
{ .type = OPTION_STRING, .short_name = (s), .long_name = (l), \
.value = check_vtype(v, const char **), (a), .help = (h), \
.flags = PARSE_OPT_OPTARG, .defval = (intptr_t)(d) }
+#define OPT_STRING_OPTARG_SET(s, l, v, os, a, h, d) \
+ { .type = OPTION_STRING, .short_name = (s), .long_name = (l), \
+ .value = check_vtype(v, const char **), (a), .help = (h), \
+ .flags = PARSE_OPT_OPTARG, .defval = (intptr_t)(d), \
+ .set = check_vtype(os, bool *)}
#define OPT_STRING_NOEMPTY(s, l, v, a, h) { .type = OPTION_STRING, .short_name = (s), .long_name = (l), .value = check_vtype(v, const char **), (a), .help = (h), .flags = PARSE_OPT_NOEMPTY}
#define OPT_DATE(s, l, v, h) \
{ .type = OPTION_CALLBACK, .short_name = (s), .long_name = (l), .value = (v), .argh = "time", .help = (h), .callback = parse_opt_approxidate_cb }
--
2.7.4
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH 0/7] perf tools: Add switch-output size and time threshold options Jiri Olsa <jolsa@kernel.org> - 2017-01-03 09:30 +0100
[PATCH 1/7] tools lib subcmd: Add OPT_STRING_OPTARG_SET option Jiri Olsa <jolsa@kernel.org> - 2017-01-03 09:30 +0100
[tip:perf/urgent] tools lib subcmd: Add OPT_STRING_OPTARG_SET option tip-bot for Jiri Olsa <tipbot@zytor.com> - 2017-01-05 09:00 +0100
[PATCH 4/7] perf record: Add struct switch_output Jiri Olsa <jolsa@kernel.org> - 2017-01-03 09:30 +0100
[PATCH 5/7] perf record: Change switch-output option to take optional argument Jiri Olsa <jolsa@kernel.org> - 2017-01-03 09:30 +0100
Re: [PATCH 0/7] perf tools: Add switch-output size and time threshold options "Wangnan (F)" <wangnan0@huawei.com> - 2017-01-03 11:00 +0100
Re: [PATCH 0/7] perf tools: Add switch-output size and time threshold options Jiri Olsa <jolsa@redhat.com> - 2017-01-03 11:40 +0100
Re: [PATCH 0/7] perf tools: Add switch-output size and time threshold options Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-01-10 14:40 +0100
Re: [PATCH 0/7] perf tools: Add switch-output size and time threshold options Jiri Olsa <jolsa@redhat.com> - 2017-01-10 19:50 +0100
csiph-web