Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Joel Brobecker <brobecker@adacore.com>
To: gdb-patches@sourceware.org
Cc: Joel Brobecker <brobecker@adacore.com>
Subject: [PATCH 03/18] New general purpose routines in utils.c
Date: Thu, 24 Feb 2011 17:50:00 -0000	[thread overview]
Message-ID: <1298569763-18784-4-git-send-email-brobecker@adacore.com> (raw)
In-Reply-To: <1298569763-18784-1-git-send-email-brobecker@adacore.com>

These are some general-purpose routines that were added for the VxWorks
port...  Hopefully other parts of the GDB code will make use of them.

gdb/ChangeLog:

        * utils.c (have_dos_based_filesystem, is_regular_file)
        (skip_whitespace, skip_until_character, skip_until_whitespace)
        (skip_space_delimited_token, get_space_delimited_token): New functions.
        * source.c (is_regular_file): Delete.  Moved to utils.c.
        * defs.h (have_dos_based_filesystem, is_regular_file)
        (skip_whitespace, skip_until_character, skip_space_delimited_token)
        (get_space_delimited_token): Add declaration.
---
 gdb/defs.h   |   12 ++++++
 gdb/source.c |   18 ---------
 gdb/utils.c  |  109 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 121 insertions(+), 18 deletions(-)

diff --git a/gdb/defs.h b/gdb/defs.h
index 9409dde..908d956 100644
--- a/gdb/defs.h
+++ b/gdb/defs.h
@@ -421,6 +421,18 @@ extern const char *gdb_bfd_errmsg (bfd_error_type error_tag, char **matching);
 
 extern int parse_pid_to_attach (char *args);
 
+extern int have_dos_based_filesystem (void);
+
+extern int is_regular_file (const char *name);
+
+extern char *skip_whitespace (char *str);
+
+extern char *skip_until_character (char *str, char delimiter);
+
+extern char *skip_space_delimited_token (char *str);
+
+extern char *get_space_delimited_token (char *str, char **token);
+
 /* From demangle.c */
 
 extern void set_demangling_style (char *);
diff --git a/gdb/source.c b/gdb/source.c
index a14a802..9e35dd9 100644
--- a/gdb/source.c
+++ b/gdb/source.c
@@ -657,24 +657,6 @@ source_info (char *ignore, int from_tty)
 }
 \f
 
-/* Return True if the file NAME exists and is a regular file.  */
-static int
-is_regular_file (const char *name)
-{
-  struct stat st;
-  const int status = stat (name, &st);
-
-  /* Stat should never fail except when the file does not exist.
-     If stat fails, analyze the source of error and return True
-     unless the file does not exist, to avoid returning false results
-     on obscure systems where stat does not work as expected.  */
-
-  if (status != 0)
-    return (errno != ENOENT);
-
-  return S_ISREG (st.st_mode);
-}
-
 /* Open a file named STRING, searching path PATH (dir names sep by some char)
    using mode MODE in the calls to open.  You cannot use this function to
    create files (O_CREAT).
diff --git a/gdb/utils.c b/gdb/utils.c
index 82e3adb..6f8926c 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -3982,6 +3982,115 @@ parse_pid_to_attach (char *args)
   return pid;
 }
 
+/* Return non-zero if the host has a dos-based file system.  */
+
+int
+have_dos_based_filesystem (void)
+{
+#ifdef HAVE_DOS_BASED_FILE_SYSTEM
+  return 1;
+#else
+  return 0;
+#endif
+}
+
+/* Return True if the file NAME exists and is a regular file.  */
+
+int
+is_regular_file (const char *name)
+{
+  struct stat st;
+  const int status = stat (name, &st);
+
+  /* Stat should never fail except when the file does not exist.
+     If stat fails, analyze the source of error and return True
+     unless the file does not exist, to avoid returning false results
+     on obscure systems where stat does not work as expected.  */
+  if (status != 0)
+    return (errno != ENOENT);
+
+  return S_ISREG (st.st_mode);
+}
+
+/* Return a pointer to the first non-whitepace character found
+   in the string.  A whitespace is either a space or a tab.  */
+
+char *
+skip_whitespace (char *str)
+{
+  char *index = str;
+
+  while (*index == ' ' || *index == '\t')
+    index++;
+
+  return index;
+}
+
+/* Return a pointer to the first DELIMITER character in the given
+   string.  Return a pointer to the end-of-line character if
+   DELIMITER was not found.  */
+
+char *
+skip_until_character (char *str, char delimiter)
+{
+  char *index = str;
+
+  while (*index != delimiter && *index != '\0')
+    index++;
+
+  return index;
+}
+
+/* return a pointer to the first whitespace character.  If no whitespace
+   is found before the end of string, a pointer to the end of string
+   is returned.  A whitespace is either a space or a tab.  */
+
+static char *
+skip_until_whitespace (char *str)
+{
+  char *index = str;
+
+  while (*index != ' ' && *index != '\t' && *index != '\0')
+    index++;
+
+  return index;
+}
+
+/* Return a pointer to the first white space after the next
+   whitespace-delimited token.  */
+
+char *
+skip_space_delimited_token (char *str)
+{
+  char *index = str;
+
+  index = skip_whitespace (index);
+  index = skip_until_whitespace (index);
+
+  return index;
+}
+
+/* Copy the next whitespace token into TOKEN.  This string will be
+   allocated using malloc, and must be dealocated later.  */
+
+char *
+get_space_delimited_token (char *str, char **token)
+{
+  char *start;
+  char *end;
+  char tmp;
+
+  start = skip_whitespace (str);
+  end = skip_until_whitespace (start);
+
+  tmp = *end;
+  *end = '\0';
+  *token = xstrdup (start);
+  *end = tmp;
+
+  return end;
+}
+
 /* Provide a prototype to silence -Wmissing-prototypes.  */
 extern initialize_file_ftype _initialize_utils;
 
-- 
1.7.0.4


  parent reply	other threads:[~2011-02-24 17:50 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-24 17:49 Add support for VxWorks 5.x, 6.x and 653 Joel Brobecker
2011-02-24 17:49 ` [PATCH 01/18] Some ada-lang/ada-tasks routines needed by the VxWorks target Joel Brobecker
2011-02-24 17:50 ` [PATCH 02/18] New command_post observer Joel Brobecker
2011-02-24 18:58   ` Tom Tromey
2011-02-24 17:50 ` [PATCH 04/18] add new "unload" command (symetry of existing "load" command) Joel Brobecker
2011-02-24 19:22   ` Eli Zaretskii
2011-02-24 17:50 ` Joel Brobecker [this message]
2011-02-24 19:06   ` [PATCH 03/18] New general purpose routines in utils.c Tom Tromey
2011-02-24 17:51 ` [PATCH 05/18] new struct bp_target_info target_private_data field Joel Brobecker
2011-02-24 17:54 ` [PATCH 08/18] Add options to control Vxworks related settings Joel Brobecker
2011-02-24 17:54 ` [PATCH 09/18] VxWorks breakpoint-handling module Joel Brobecker
2011-02-24 17:54 ` [PATCH 06/18] New module remote-wtx-utils Joel Brobecker
2011-02-24 19:26   ` Tom Tromey
2011-02-24 17:55 ` [PATCH 10/18] "multi-tasks-mode" support Joel Brobecker
2011-02-24 17:56 ` [PATCH 11/18] Add partition support Joel Brobecker
2011-02-25 16:17   ` Tom Tromey
2011-02-24 17:56 ` [PATCH 07/18] remote-wtxapi: The WTX API abstraction layer Joel Brobecker
2011-02-24 19:44   ` Tom Tromey
2011-02-24 17:57 ` [PATCH 14/18] WTX-TCL support module Joel Brobecker
2011-02-25 15:59   ` Tom Tromey
2011-02-25 18:58     ` Joel Brobecker
2011-02-28 15:37       ` Tom Tromey
2011-02-24 17:57 ` [PATCH 12/18] remote-wtx-hw: register fetch/store support Joel Brobecker
2011-02-24 17:57 ` [PATCH 13/18] Add new "wtx" target Joel Brobecker
2011-02-25 16:15   ` Tom Tromey
2011-02-25 17:38     ` Joel Brobecker
2011-02-24 17:58 ` [PATCH 15/18] Add support for VxWorks 6 Joel Brobecker
2011-02-24 17:59 ` [PATCH 16/18] Add tdep files for x86 and powerpc Joel Brobecker
2011-02-24 18:58   ` Mark Kettenis
2011-02-25  8:29     ` Joel Brobecker
2011-02-24 17:59 ` [PATCH 17/18] Configury and Makefile updates for VxWorks Joel Brobecker
2011-02-24 18:04 ` [PATCH 18/18] document the new VxWorks port Joel Brobecker
2011-02-24 20:27   ` Eli Zaretskii
2011-02-25 11:12     ` Jerome Guitton
2011-02-25 11:27       ` Eli Zaretskii
2011-02-25 11:38         ` Jerome Guitton
2011-02-25 11:38           ` Joel Brobecker
2011-02-25 12:08             ` Eli Zaretskii
2011-02-25 13:26               ` Jerome Guitton
2011-02-25 11:44           ` Eli Zaretskii
2011-02-25 11:49             ` Joel Brobecker
2011-02-25 11:55               ` Jerome Guitton
2011-02-25 11:56                 ` Joel Brobecker
2011-02-25 12:01                   ` Pedro Alves
2011-02-25 14:21                     ` Joel Brobecker
2011-02-25 14:44                       ` Pedro Alves
2011-02-25 15:15                         ` Joel Brobecker
2011-02-25 12:05                   ` Jerome Guitton
2011-02-25 12:15                     ` Eli Zaretskii
2011-02-25 12:56                       ` Joel Brobecker
2011-02-25 13:20                         ` Eli Zaretskii
2011-02-25 14:11                           ` Jerome Guitton
2011-03-03 12:16     ` Joel Brobecker
2011-03-03 13:44       ` Eli Zaretskii

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=1298569763-18784-4-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