From: Joel Brobecker <brobecker@adacore.com>
To: gdb-patches@sourceware.org
Subject: [RFA 2/3] New function cli-utils.c:extract_arg_const
Date: Mon, 11 Nov 2013 06:39:00 -0000 [thread overview]
Message-ID: <1384151855-12926-2-git-send-email-brobecker@adacore.com> (raw)
In-Reply-To: <1384151855-12926-1-git-send-email-brobecker@adacore.com>
Hello,
This function provides the exact same functionality as extract_arg,
except that it takes a "const char**" instead of a "char **". This
will be useful in the context of my next patch.
gdb/ChangeLog:
* cli/cli-utils.h (extract_arg_const): Add declaration.
* cli/cli-utils.c (extract_arg_const): New function.
Tested on x86_64-linux. OK to push?
Thank you,
--
Joel
---
gdb/cli/cli-utils.c | 30 ++++++++++++++++++++++++++++++
gdb/cli/cli-utils.h | 7 +++++++
2 files changed, 37 insertions(+)
diff --git a/gdb/cli/cli-utils.c b/gdb/cli/cli-utils.c
index f74e6b1..98afe1f 100644
--- a/gdb/cli/cli-utils.c
+++ b/gdb/cli/cli-utils.c
@@ -289,6 +289,36 @@ extract_arg (char **arg)
/* See documentation in cli-utils.h. */
+char *
+extract_arg_const (const char **arg)
+{
+ const char *result;
+ char *copy;
+
+ if (!*arg)
+ return NULL;
+
+ /* Find the start of the argument. */
+ *arg = skip_spaces_const (*arg);
+ if (!**arg)
+ return NULL;
+ result = *arg;
+
+ /* Find the end of the argument. */
+ *arg = skip_to_space_const (*arg + 1);
+
+ if (result == *arg)
+ return NULL;
+
+ copy = xmalloc (*arg - result + 1);
+ memcpy (copy, result, *arg - result);
+ copy[*arg - result] = '\0';
+
+ return copy;
+}
+
+/* See documentation in cli-utils.h. */
+
int
check_for_argument (char **str, char *arg, int arg_len)
{
diff --git a/gdb/cli/cli-utils.h b/gdb/cli/cli-utils.h
index 152fb89..ebae2d2 100644
--- a/gdb/cli/cli-utils.h
+++ b/gdb/cli/cli-utils.h
@@ -118,6 +118,13 @@ extern char *remove_trailing_whitespace (const char *start, char *s);
extern char *extract_arg (char **arg);
+/* A const-correct version of "extract_arg".
+
+ Since the returned value is xmalloc'd, it eventually needs to be
+ xfree'ed, which prevents us from making it const as well. */
+
+extern char *extract_arg_const (const char **arg);
+
/* A helper function that looks for an argument at the start of a
string. The argument must also either be at the end of the string,
or be followed by whitespace. Returns 1 if it finds the argument,
--
1.8.1.2
next prev parent reply other threads:[~2013-11-11 6:38 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-11 6:38 [RFA/commit 1/3] language.h: Add "symtab.h" #include Joel Brobecker
2013-11-11 6:39 ` Joel Brobecker [this message]
2013-11-13 19:35 ` [RFA 2/3] New function cli-utils.c:extract_arg_const Pedro Alves
2013-11-14 10:55 ` pushed: " Joel Brobecker
2013-11-11 6:55 ` [RFC 3/3] GDB/MI: Add new "--language LANG" command option Joel Brobecker
2013-11-11 7:02 ` Joel Brobecker
2013-11-11 17:20 ` Eli Zaretskii
2013-11-11 16:29 ` Eli Zaretskii
2013-11-13 19:49 ` Pedro Alves
2013-11-14 11:17 ` Joel Brobecker
2013-11-13 19:34 ` [PATCH] New "make check-headers" rule. (was: Re: [RFA/commit 1/3] language.h: Add "symtab.h" #include) Pedro Alves
2013-11-14 10:00 ` Joel Brobecker
2013-11-14 21:32 ` [PATCH] New "make check-headers" rule Tom Tromey
2014-01-13 19:42 ` Pedro Alves
2013-11-14 10:55 ` pushed: [RFA/commit 1/3] language.h: Add "symtab.h" #include Joel Brobecker
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=1384151855-12926-2-git-send-email-brobecker@adacore.com \
--to=brobecker@adacore.com \
--cc=gdb-patches@sourceware.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