From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26294 invoked by alias); 4 Mar 2011 06:22:49 -0000 Received: (qmail 26286 invoked by uid 22791); 4 Mar 2011 06:22:49 -0000 X-SWARE-Spam-Status: No, hits=-2.0 required=5.0 tests=AWL,BAYES_00,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 04 Mar 2011 06:22:45 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 678B22BAEB7; Fri, 4 Mar 2011 01:22:43 -0500 (EST) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id McUOlcktWuLX; Fri, 4 Mar 2011 01:22:43 -0500 (EST) Received: from kwai.gnat.com (kwai.gnat.com [205.232.38.4]) by rock.gnat.com (Postfix) with ESMTP id 5504C2BAE66; Fri, 4 Mar 2011 01:22:43 -0500 (EST) Received: by kwai.gnat.com (Postfix, from userid 4233) id 4BD8392A53; Fri, 4 Mar 2011 01:22:43 -0500 (EST) From: Joel Brobecker To: gdb-patches@sourceware.org Cc: Joel Brobecker Subject: [VxWorks 05/20] more parsing routines in cli/cli-utils Date: Fri, 04 Mar 2011 06:22:00 -0000 Message-Id: <1299219720-13398-6-git-send-email-brobecker@adacore.com> In-Reply-To: <1299219720-13398-1-git-send-email-brobecker@adacore.com> References: <1299219720-13398-1-git-send-email-brobecker@adacore.com> Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2011-03/txt/msg00256.txt.bz2 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