]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Use skip_spaces in more places
authorTom Tromey <tromey@adacore.com>
Fri, 12 Dec 2025 18:45:42 +0000 (11:45 -0700)
committerTom Tromey <tromey@adacore.com>
Mon, 15 Dec 2025 14:25:56 +0000 (07:25 -0700)
I looked through gdb for instance of:

      while (*p == ' ' || *p == '\t')
p++;

... and replaced these with a call to skip_spaces.

In some cases this might slightly change the semantics, as now other
whitespace (like \r or \f) will be considered.  However I don't think
this matters.

Regression tested on x86-64 Fedora 41.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
15 files changed:
gdb/c-exp.y
gdb/cli/cli-cmds.c
gdb/cli/cli-decode.c
gdb/cli/cli-script.c
gdb/completer.c
gdb/d-exp.y
gdb/event-top.c
gdb/go-exp.y
gdb/infcmd.c
gdb/objc-lang.c
gdb/p-exp.y
gdb/rust-parse.c
gdb/symtab.c
gdb/top.c
gdb/utils.c

index d321e815ca4017c704852b2255ce688b4b3e6ead..271f823ca8d3acaa8f7c68ede40400bc34e1d0da 100644 (file)
@@ -3038,10 +3038,7 @@ lex_one_token (struct parser_state *par_state, bool *is_quoted_name)
       && (tokstart[namelen] == ' ' || tokstart[namelen] == '\t')
       && ! scanning_macro_expansion ())
     {
-      const char *p = tokstart + namelen + 1;
-
-      while (*p == ' ' || *p == '\t')
-       p++;
+      const char *p = skip_spaces (tokstart + namelen + 1);
       if (*p >= '0' && *p <= '9')
        return 0;
     }
index cf5571c541974992d5b3d3e84594a41301c360ad..362f239f896f233d2558cbb2ed18c2280e5aba2f 100644 (file)
@@ -1402,8 +1402,7 @@ list_command (const char *arg, int from_tty)
   const char *beg = arg;
   size_t beg_len = arg1 - beg;
 
-  while (*arg1 == ' ' || *arg1 == '\t')
-    arg1++;
+  arg1 = skip_spaces (arg1);
   if (*arg1 == ',')
     {
       no_end = 0;
@@ -1415,8 +1414,7 @@ list_command (const char *arg, int from_tty)
          return;
        }
       arg1++;
-      while (*arg1 == ' ' || *arg1 == '\t')
-       arg1++;
+      arg1 = skip_spaces (arg1);
       if (*arg1 == 0)
        dummy_end = 1;
       else
index 6a7d07ae29cba1334da66f60c0a5cd90856a7985..62f2a8b21423785b11913c1b62822fc3619a3b5b 100644 (file)
@@ -2267,8 +2267,7 @@ lookup_cmd_1 (const char **text, struct cmd_list_element *clist,
   bool found_alias = false;
   const char *line = *text;
 
-  while (**text == ' ' || **text == '\t')
-    (*text)++;
+  *text = skip_spaces (*text);
 
   /* Identify the name of the command.  */
   len = find_command_name_length (*text);
@@ -2499,8 +2498,7 @@ lookup_cmd (const char **line, struct cmd_list_element *list,
 
       /* We've got something.  It may still not be what the caller
         wants (if this command *needs* a subcommand).  */
-      while (**line == ' ' || **line == '\t')
-       (*line)++;
+      *line = skip_spaces (*line);
 
       if (c->is_prefix () && **line && !c->allow_unknown)
        undef_cmd_error (c->prefixname ().c_str (), *line);
index 31be1141871db6f5d87e0247bccf4fe5cf599c3e..9fa5ec2956925db26ba205f0a1a734fff1b2dc45 100644 (file)
@@ -776,8 +776,7 @@ user_args::user_args (const char *command_line)
       int bsquote = 0;
 
       /* Strip whitespace.  */
-      while (*p == ' ' || *p == '\t')
-       p++;
+      p = skip_spaces (p);
 
       /* P now points to an argument.  */
       start_arg = p;
index 677b9d1565029a379eb51d4cb14548187944a148..194ab8a21a1253db86f68057305928528bd943e3 100644 (file)
@@ -1698,10 +1698,7 @@ complete_line_internal_1 (completion_tracker &tracker,
                      true);
 
   /* Move p up to the next interesting thing.  */
-  while (*p == ' ' || *p == '\t')
-    {
-      p++;
-    }
+  p = skip_spaces (p);
 
   tracker.advance_custom_word_point_by (p - tmp_command);
 
index f6b56296b22e5b2eb1c3e94b750b3f897f296f2d..15a55e33eb574f4605b6957ed0a6ce141f2eb558 100644 (file)
@@ -1247,10 +1247,7 @@ lex_one_token (struct parser_state *par_state)
          || strncmp (tokstart, "task", namelen) == 0)
       && (tokstart[namelen] == ' ' || tokstart[namelen] == '\t'))
     {
-      const char *p = tokstart + namelen + 1;
-
-      while (*p == ' ' || *p == '\t')
-       p++;
+      const char *p = skip_spaces (tokstart + namelen + 1);
       if (*p >= '0' && *p <= '9')
        return 0;
     }
index 3138e8c88866849e4aa3d42aab4f91ecddef0eda..23c2f1c03795810a59c8fb682f5fa81c87d83393 100644 (file)
@@ -598,7 +598,6 @@ void
 command_handler (const char *command)
 {
   struct ui *ui = current_ui;
-  const char *c;
 
   if (ui->instream == ui->stdin_stream)
     reinitialize_more_filter ();
@@ -606,8 +605,7 @@ command_handler (const char *command)
   scoped_command_stats stat_reporter (true);
 
   /* Do not execute commented lines.  */
-  for (c = command; *c == ' ' || *c == '\t'; c++)
-    ;
+  const char *c = skip_spaces (command);
   if (c[0] != '#')
     {
       execute_command (command, ui->instream == ui->stdin_stream);
@@ -717,9 +715,7 @@ handle_line_of_input (std::string &cmd_line_buffer,
 
   /* If we just got an empty line, and that is supposed to repeat the
      previous command, return the previously saved command.  */
-  const char *p1;
-  for (p1 = cmd_line_buffer.c_str (); *p1 == ' ' || *p1 == '\t'; p1++)
-    ;
+  const char *p1 = skip_spaces (cmd_line_buffer.c_str ());
   if (repeat && *p1 == '\0')
     return get_saved_command_line ();
 
index 5da8cefd64b0ce8d88c7b5fa25754d152cc11729..fe95fad0a9e400e8de4b2aab97ecaa9c12b04160 100644 (file)
@@ -1202,10 +1202,7 @@ lex_one_token (struct parser_state *par_state)
       && strncmp (tokstart, "thread", namelen) == 0
       && (tokstart[namelen] == ' ' || tokstart[namelen] == '\t'))
     {
-      const char *p = tokstart + namelen + 1;
-
-      while (*p == ' ' || *p == '\t')
-       p++;
+      const char *p = skip_spaces (tokstart + namelen + 1);
       if (*p >= '0' && *p <= '9')
        return 0;
     }
index ed1fa74dc37d0b5f47c010bc2c184e645768a2fa..246dadffcd9b6f6cc23907ea442a50f0278f474c 100644 (file)
@@ -2097,9 +2097,7 @@ set_var_in_environment (gdb_environ *env, const char *arg)
   else
     {
       /* Not setting variable value to null.  */
-      val = p + 1;
-      while (*val == ' ' || *val == '\t')
-       val++;
+      val = skip_spaces (p + 1);
     }
 
   while (p != arg && (p[-1] == ' ' || p[-1] == '\t'))
index 9804f2c3963a9c8ae6cc039db85983ab71eae20a..3b05607f3be4011d45da4346eb1d59394e8f527b 100644 (file)
@@ -569,8 +569,7 @@ info_selectors_command (const char *regexp, int from_tty)
       if (*regexp == '+' || *regexp == '-')
        { /* User wants only class methods or only instance methods.  */
          plusminus = *regexp++;
-         while (*regexp == ' ' || *regexp == '\t')
-           regexp++;
+         regexp = skip_spaces (regexp);
        }
       if (*regexp == '\0')
        strcpy(myregexp, ".*]");
index ff84e7726ecb55b446ec452316252a156ded659b..f9885052368569aaf1b1c50ea2b18277f29e409e 100644 (file)
@@ -1559,15 +1559,13 @@ yylex (void)
          while (1)
            {
              /* Skip whitespace.  */
-             while (*p == ' ' || *p == '\t' || *p == '\n')
-               ++p;
+             p = skip_spaces (p);
              if (*p == ':' && p[1] == ':')
                {
                  /* Skip the `::'.  */
                  p += 2;
                  /* Skip whitespace.  */
-                 while (*p == ' ' || *p == '\t' || *p == '\n')
-                   ++p;
+                 p = skip_spaces (p);
                  namestart = p;
                  while (*p == '_' || *p == '$' || (*p >= '0' && *p <= '9')
                         || (*p >= 'a' && *p <= 'z')
index b740d5a7b16e260cfe9213ad6e4f784c2ab5476d..2256cf89aa487c998b2424f4e5fa1570c12d6709 100644 (file)
@@ -761,10 +761,8 @@ rust_parser::lex_string ()
 static bool
 space_then_number (const char *string)
 {
-  const char *p = string;
+  const char *p = skip_spaces (string);
 
-  while (p[0] == ' ' || p[0] == '\t')
-    ++p;
   if (p == string)
     return false;
 
@@ -1072,11 +1070,7 @@ int
 rust_parser::lex_one_token (bool decimal_only)
 {
   /* Skip all leading whitespace.  */
-  while (pstate->lexptr[0] == ' '
-        || pstate->lexptr[0] == '\t'
-        || pstate->lexptr[0] == '\r'
-        || pstate->lexptr[0] == '\n')
-    ++pstate->lexptr;
+  pstate->lexptr = skip_spaces (pstate->lexptr);
 
   /* If we hit EOF and we're completing, then return COMPLETE -- maybe
      we're completing an empty string at the end of a field_expr.
index 5754d944b6c6a77345284d37b3d8d3d34e977e3d..2eda0da532df4cc7cd745966f2e520b6185f8245 100644 (file)
@@ -4117,8 +4117,7 @@ operator_chars (const char *p, const char **end)
     return *end;
 
   /* Allow some whitespace between `operator' and the operator symbol.  */
-  while (*p == ' ' || *p == '\t')
-    p++;
+  p = skip_spaces (p);
 
   /* Recognize 'operator TYPENAME'.  */
 
index 1214101ad18e3df6c301342dff4386de473d4cad..4f689255907d575a0474ce690d902f6669f77252 100644 (file)
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -467,8 +467,7 @@ execute_command (const char *p, int from_tty)
 
   target_log_command (p);
 
-  while (*p == ' ' || *p == '\t')
-    p++;
+  p = skip_spaces (p);
   if (*p)
     {
       const char *cmd = p;
index ffe0d639e3a768bf8d4410b156dbd5e631f5c555..d06ebc0014b87958e1bafc7fd71ea74aa75b0a81 100644 (file)
@@ -1473,10 +1473,8 @@ pager_file::prompt_for_continue ()
 
   if (ignore != NULL)
     {
-      char *p = ignore.get ();
+      char *p = skip_spaces (ignore.get ());
 
-      while (*p == ' ' || *p == '\t')
-       ++p;
       if (p[0] == 'q')
        /* Do not call quit here; there is no possibility of SIGINT.  */
        throw_quit ("Quit");