This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[VxWorks 05/20] more parsing routines in cli/cli-utils


These are used to parse various messages received from the target
server, or to parse the output of some TCL commands.  But they might
be useful to others as well.

gdb/ChangeLog:

        * cli/cli-utils.h (skip_token, get_token): Add declarations.
        * cli/cli-utils.c (skip_token, get_token): New functions.
---
 gdb/cli/cli-utils.c |   33 +++++++++++++++++++++++++++++++++
 gdb/cli/cli-utils.h |   16 ++++++++++++++++
 2 files changed, 49 insertions(+), 0 deletions(-)

diff --git a/gdb/cli/cli-utils.c b/gdb/cli/cli-utils.c
index 133ac53..3e872b3 100644
--- a/gdb/cli/cli-utils.c
+++ b/gdb/cli/cli-utils.c
@@ -226,3 +226,36 @@ skip_to_space (char *chp)
     chp++;
   return chp;
 }
+
+/* See documentation in cli-utils.h.  */
+
+char *
+skip_token (char *chp)
+{
+  chp = skip_spaces (chp);
+  chp = skip_to_space (chp);
+  return chp;
+}
+
+/* See documentation in cli-utils.h.  */
+
+char *
+get_token (char *chp, char **token)
+{
+  char *start;
+  char *end;
+  char tmp;
+
+  if (chp == NULL)
+    return NULL;
+
+  start = skip_spaces (chp);
+  end = skip_to_space (start);
+
+  tmp = *end;
+  *end = '\0';
+  *token = xstrdup (start);
+  *end = tmp;
+
+  return end;
+}
diff --git a/gdb/cli/cli-utils.h b/gdb/cli/cli-utils.h
index 8f0b46e..5f2fab9 100644
--- a/gdb/cli/cli-utils.h
+++ b/gdb/cli/cli-utils.h
@@ -65,4 +65,20 @@ extern char *skip_spaces (char *chp);
 
 extern char *skip_to_space (char *chp);
 
+/* Skip the first space-delimited token in CHP, returning a pointer to
+   the character immediately following that token (either a whitespace,
+   or an end-of-line character).  If CHP is NULL, return NULL.  */
+
+extern char *skip_token (char *chp);
+
+/* Copy the first space-delimited token from CHP into TOKEN, and
+   return a pointer to the character immediately following that token
+   (either a whitespace, or an end-of-line character).  If CHP is NULL,
+   then do nothing and return NULL.
+
+   The string containing the token is allocated on the heap, and
+   must be deallocated later.  */
+
+extern char *get_token (char *chp, char **token);
+
 #endif /* CLI_UTILS_H */
-- 
1.7.0.4


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]