From: Frederic Weisbecker <fweisbec@gmail.com>
To: Ingo Molnar <mingo@elte.hu>
Cc: LKML <linux-kernel@vger.kernel.org>,
Peter Zijlstra <a.p.zijlstra@chello.nl>,
Mike Galbraith <efault@gmx.de>, Paul Mackerras <paulus@samba.org>,
Anton Blanchard <anton@samba.org>,
Arnaldo Carvalho de Melo <acme@redhat.com>,
Frederic Weisbecker <fweisbec@gmail.com>
Subject: [PATCH 2/3] perfcounter: bring new OPT_CALLBACK_DEFAULT option
Date: Thu, 2 Jul 2009 17:58:20 +0200 [thread overview]
Message-ID: <1246550301-8954-2-git-send-email-fweisbec@gmail.com> (raw)
In-Reply-To: <1246550301-8954-1-git-send-email-fweisbec@gmail.com>
There is no predefined macro to create an option that can
have a custom value or a default one if none is given.
This patch provides a new helper OPT_CALLBACK_DEFAULT() which
defines such kind of option.
For example, considering an option -c, we want to get the default
value in the following cases:
./perf command -c -d
./perf command -d -c
And the foo value when it's given:
./perf command -c foo -d
./perf command -d -c foo
That's also why PARSE_OPT_LASTARG_DEFAULT is extended here
to support default values whatever the position of the option, not
only in the end.
Should it now be renamed to PARSE_OPT_ARG_DEFAULT ?
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
---
tools/perf/util/parse-options.c | 3 ++-
tools/perf/util/parse-options.h | 2 ++
2 files changed, 4 insertions(+), 1 deletions(-)
diff --git a/tools/perf/util/parse-options.c b/tools/perf/util/parse-options.c
index 9a897b7..1bf6719 100644
--- a/tools/perf/util/parse-options.c
+++ b/tools/perf/util/parse-options.c
@@ -20,7 +20,8 @@ static int get_arg(struct parse_opt_ctx_t *p, const struct option *opt,
if (p->opt) {
*arg = p->opt;
p->opt = NULL;
- } else if (p->argc == 1 && (opt->flags & PARSE_OPT_LASTARG_DEFAULT)) {
+ } else if ((opt->flags & PARSE_OPT_LASTARG_DEFAULT) && (p->argc == 1 ||
+ **(p->argv + 1) == '-')) {
*arg = (const char *)opt->defval;
} else if (p->argc > 1) {
p->argc--;
diff --git a/tools/perf/util/parse-options.h b/tools/perf/util/parse-options.h
index 15c8aba..8aa3464 100644
--- a/tools/perf/util/parse-options.h
+++ b/tools/perf/util/parse-options.h
@@ -104,6 +104,8 @@ struct option {
{ .type = OPTION_CALLBACK, .short_name = (s), .long_name = (l), .value = (v), .argh = "time", .help = (h), .callback = parse_opt_approxidate_cb }
#define OPT_CALLBACK(s, l, v, a, h, f) \
{ .type = OPTION_CALLBACK, .short_name = (s), .long_name = (l), .value = (v), (a), .help = (h), .callback = (f) }
+#define OPT_CALLBACK_DEFAULT(s, l, v, a, h, f, d) \
+ { .type = OPTION_CALLBACK, .short_name = (s), .long_name = (l), .value = (v), (a), .help = (h), .callback = (f), .defval = (intptr_t)d, .flags = PARSE_OPT_LASTARG_DEFAULT }
/* parse_options() will filter out the processed options and leave the
* non-option argments in argv[].
--
1.6.2.3
next prev parent reply other threads:[~2009-07-02 16:06 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-07-02 15:58 [PATCH 1/3] perfcounter: create new chain_for_each_child() iterator Frederic Weisbecker
2009-07-02 15:58 ` Frederic Weisbecker [this message]
2009-07-02 18:58 ` [tip:perfcounters/urgent] perf_counter tools: Add new OPT_CALLBACK_DEFAULT option tip-bot for Frederic Weisbecker
2009-07-02 15:58 ` [PATCH 3/3] perfcounter: Add support for callchain graph output Frederic Weisbecker
2009-07-02 18:58 ` [tip:perfcounters/urgent] perf report: " tip-bot for Frederic Weisbecker
2009-07-02 18:57 ` [tip:perfcounters/urgent] perf_counter tools: Create new chain_for_each_child() iterator tip-bot for Frederic Weisbecker
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1246550301-8954-2-git-send-email-fweisbec@gmail.com \
--to=fweisbec@gmail.com \
--cc=a.p.zijlstra@chello.nl \
--cc=acme@redhat.com \
--cc=anton@samba.org \
--cc=efault@gmx.de \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=paulus@samba.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox