]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: make deprecated_cmd_warning i18n friendly
authorAndrew Burgess <andrew.burgess@embecosm.com>
Thu, 10 Dec 2020 14:47:18 +0000 (14:47 +0000)
committerAndrew Burgess <andrew.burgess@embecosm.com>
Fri, 11 Dec 2020 22:10:50 +0000 (22:10 +0000)
Rewrite deprecated_cmd_warning to be i18n friendly.  While I'm going
through the function I also cleaned up some whitespace issues,
replaced uses of NULL with nullptr, and moved some comments to avoid
having to add { ... }.

Though the message being printed has a 'Warning: ' prefix I could have
changed from using printf_filtered to use warning, however, I haven't
done that in this commit as that would change what GDB outputs and I
wanted this commit NOT to change the output.

There should be no user visible changes after this commit.

gdb/ChangeLog:

* cli/cli-decode.c (deprecated_cmd_warning): Use nullptr instead
of NULL.  Don't print message piece by piece, but sentence at a
time to allow internationalisation.  Some whitespace cleanup.

gdb/ChangeLog
gdb/cli/cli-decode.c

index f01ba9951a0c11a2bd23804b6e41af6c8d096ace..5a35eb20f45619578941ba08f896c5c30bc4e327 100644 (file)
@@ -1,3 +1,9 @@
+2020-12-11  Andrew Burgess  <andrew.burgess@embecosm.com>
+
+       * cli/cli-decode.c (deprecated_cmd_warning): Use nullptr instead
+       of NULL.  Don't print message piece by piece, but sentence at a
+       time to allow internationalisation.  Some whitespace cleanup.
+
 2020-12-11  Andrew Burgess  <andrew.burgess@embecosm.com>
 
        PR cli/15104
index dc83f5560e6ddfb7f8d1a97acdcd762c2295a577..2ad7717fbc63664f8ccdac6701a1c2ad521eb282 100644 (file)
@@ -1686,6 +1686,7 @@ lookup_cmd_1 (const char **text, struct cmd_list_element *clist,
       if (found->deprecated_warn_user && !lookup_for_completion_p)
        deprecated_cmd_warning (line, clist);
 
+
       /* Return the default_args of the alias, not the default_args
         of the command it is pointing to.  */
       if (default_args != nullptr)
@@ -1899,59 +1900,57 @@ lookup_cmd (const char **line, struct cmd_list_element *list,
 void
 deprecated_cmd_warning (const char *text, struct cmd_list_element *list)
 {
-  struct cmd_list_element *alias = NULL;
-  struct cmd_list_element *prefix_cmd = NULL;
-  struct cmd_list_element *cmd = NULL;
+  struct cmd_list_element *alias = nullptr;
+  struct cmd_list_element *prefix_cmd = nullptr;
+  struct cmd_list_element *cmd = nullptr;
 
+  /* Return if text doesn't evaluate to a command.  */
   if (!lookup_cmd_composition_1 (text, &alias, &prefix_cmd, &cmd, list))
-    /* Return if text doesn't evaluate to a command.  */
     return;
 
-  if (!((alias ? alias->deprecated_warn_user : 0)
-      || cmd->deprecated_warn_user) ) 
-    /* Return if nothing is deprecated.  */
+  /* Return if nothing is deprecated.  */
+  if (!((alias != nullptr ? alias->deprecated_warn_user : 0)
+       || cmd->deprecated_warn_user))
     return;
-  
-  printf_filtered ("Warning:");
-  
-  if (alias && !cmd->cmd_deprecated)
-    printf_filtered (" '%s', an alias for the", alias->name);
-    
-  printf_filtered (" command '");
-  
-  if (prefix_cmd)
-    printf_filtered ("%s", prefix_cmd->prefixname);
-  
-  printf_filtered ("%s", cmd->name);
-
-  if (alias && cmd->cmd_deprecated)
-    printf_filtered ("' (%s) is deprecated.\n", alias->name);
-  else
-    printf_filtered ("' is deprecated.\n"); 
-  
 
-  /* If it is only the alias that is deprecated, we want to indicate
-     the new alias, otherwise we'll indicate the new command.  */
+  /* Join command prefix (if any) and the command name.  */
+  std::string tmp_cmd_str;
+  if (prefix_cmd != nullptr)
+    tmp_cmd_str += std::string (prefix_cmd->prefixname);
+  tmp_cmd_str += std::string (cmd->name);
 
-  if (alias && !cmd->cmd_deprecated)
-    {
-      if (alias->replacement)
-       printf_filtered ("Use '%s'.\n\n", alias->replacement);
-      else
-       printf_filtered ("No alternative known.\n\n");
-     }  
-  else
+  /* Display the appropriate first line, this warns that the thing the user
+     entered is deprecated.  */
+  if (alias != nullptr)
     {
-      if (cmd->replacement)
-       printf_filtered ("Use '%s'.\n\n", cmd->replacement);
+      if (cmd->cmd_deprecated)
+       printf_filtered (_("Warning: command '%s' (%s) is deprecated.\n"),
+                        tmp_cmd_str.c_str (), alias->name);
       else
-       printf_filtered ("No alternative known.\n\n");
+       printf_filtered (_("Warning: '%s', an alias for the command '%s' "
+                          "is deprecated.\n"),
+                        alias->name, tmp_cmd_str.c_str ());
     }
+  else
+    printf_filtered (_("Warning: command '%s' is deprecated.\n"),
+                    tmp_cmd_str.c_str ());
+
+  /* Now display a second line indicating what the user should use instead.
+     If it is only the alias that is deprecated, we want to indicate the
+     new alias, otherwise we'll indicate the new command.  */
+  const char *replacement;
+  if (alias != nullptr && !cmd->cmd_deprecated)
+    replacement = alias->replacement;
+  else
+    replacement = cmd->replacement;
+  if (replacement != nullptr)
+    printf_filtered (_("Use '%s'.\n\n"), replacement);
+  else
+    printf_filtered (_("No alternative known.\n\n"));
 
   /* We've warned you, now we'll keep quiet.  */
-  if (alias)
+  if (alias != nullptr)
     alias->deprecated_warn_user = 0;
-  
   cmd->deprecated_warn_user = 0;
 }