From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Josh Triplett <josh@joshtriplett.org>,
linux-kernel@vger.kernel.org, linux-sparse@vger.kernel.org
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Subject: [PATCH v2 1/2] lib.c: introduce split_value_from_arg helper
Date: Tue, 17 Jun 2014 12:11:45 +0300 [thread overview]
Message-ID: <1402996306-6811-2-git-send-email-andriy.shevchenko@linux.intel.com> (raw)
In-Reply-To: <1402996306-6811-1-git-send-email-andriy.shevchenko@linux.intel.com>
The function tries to split a key / value from the given argument where
delimiter can be either ' ' (space) or '=' (equal sign).
It will be useful later as well.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
lib.c | 23 ++++++++++++++---------
1 file changed, 14 insertions(+), 9 deletions(-)
diff --git a/lib.c b/lib.c
index bf3e91c..4e5a846 100644
--- a/lib.c
+++ b/lib.c
@@ -275,14 +275,8 @@ void add_pre_buffer(const char *fmt, ...)
pre_buffer_end = end;
}
-static char **handle_switch_D(char *arg, char **next)
+static const char *split_value_from_arg(char *arg, const char *def)
{
- const char *name = arg + 1;
- const char *value = "1";
-
- if (!*name || isspace(*name))
- die("argument to `-D' is missing");
-
for (;;) {
char c;
c = *++arg;
@@ -290,10 +284,21 @@ static char **handle_switch_D(char *arg, char **next)
break;
if (isspace((unsigned char)c) || c == '=') {
*arg = '\0';
- value = arg + 1;
- break;
+ return arg + 1;
}
}
+ return def;
+}
+
+static char **handle_switch_D(char *arg, char **next)
+{
+ const char *name = arg + 1;
+ const char *value = "1";
+
+ if (!*name || isspace(*name))
+ die("argument to `-D' is missing");
+
+ value = split_value_from_arg(arg, value);
add_pre_buffer("#define %s %s\n", name, value);
return next;
}
--
2.0.0
next prev parent reply other threads:[~2014-06-17 9:11 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-17 9:11 [PATCH v2 0/2] fix for --param GCC's command line option Andy Shevchenko
2014-06-17 9:11 ` Andy Shevchenko [this message]
2014-06-17 9:11 ` [PATCH v2 2/2] lib.c: skip --param parameters Andy Shevchenko
2014-06-28 16:23 ` Christopher Li
2014-06-28 16:59 ` Christopher Li
2014-06-29 7:19 ` Christopher Li
2014-06-29 19:01 ` Christopher Li
2014-06-30 8:32 ` Andy Shevchenko
2014-06-30 8:51 ` Christopher Li
2014-06-30 8:56 ` Andy Shevchenko
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=1402996306-6811-2-git-send-email-andriy.shevchenko@linux.intel.com \
--to=andriy.shevchenko@linux.intel.com \
--cc=josh@joshtriplett.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sparse@vger.kernel.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;
as well as URLs for NNTP newsgroup(s).