gdb: Allow quoting around string options in the gdb::option framework
[deliverable/binutils-gdb.git] / gdb / cli-out.c
index af983a1a1ff9a1311a52f86e8a625b5837a9a837..55c8d2b3b1bb2084fdde7ecbd6b745e86619d02d 100644 (file)
@@ -1,6 +1,6 @@
 /* Output generating routines for GDB CLI.
 
-   Copyright (C) 1999-2016 Free Software Foundation, Inc.
+   Copyright (C) 1999-2019 Free Software Foundation, Inc.
 
    Contributed by Cygnus Solutions.
    Written by Fernando Nasser for Cygnus.
@@ -25,6 +25,7 @@
 #include "cli-out.h"
 #include "completer.h"
 #include "readline/readline.h"
+#include "cli/cli-style.h"
 
 /* These are the CLI output functions */
 
@@ -71,7 +72,8 @@ cli_ui_out::do_table_header (int width, ui_align alignment,
   if (m_suppress_output)
     return;
 
-  do_field_string (0, width, alignment, 0, col_hdr.c_str ());
+  do_field_string (0, width, alignment, 0, col_hdr.c_str (),
+                  ui_out_style_kind::DEFAULT);
 }
 
 /* Mark beginning of a list */
@@ -94,14 +96,13 @@ void
 cli_ui_out::do_field_int (int fldno, int width, ui_align alignment,
                          const char *fldname, int value)
 {
-  char buffer[20];     /* FIXME: how many chars long a %d can become? */
-
   if (m_suppress_output)
     return;
 
-  xsnprintf (buffer, sizeof (buffer), "%d", value);
+  std::string str = string_printf ("%d", value);
 
-  do_field_string (fldno, width, alignment, fldname, buffer);
+  do_field_string (fldno, width, alignment, fldname, str.c_str (),
+                  ui_out_style_kind::DEFAULT);
 }
 
 /* used to omit a field */
@@ -113,7 +114,8 @@ cli_ui_out::do_field_skip (int fldno, int width, ui_align alignment,
   if (m_suppress_output)
     return;
 
-  do_field_string (fldno, width, alignment, fldname, "");
+  do_field_string (fldno, width, alignment, fldname, "",
+                  ui_out_style_kind::DEFAULT);
 }
 
 /* other specific cli_field_* end up here so alignment and field
@@ -121,7 +123,8 @@ cli_ui_out::do_field_skip (int fldno, int width, ui_align alignment,
 
 void
 cli_ui_out::do_field_string (int fldno, int width, ui_align align,
-                            const char *fldname, const char *string)
+                            const char *fldname, const char *string,
+                            ui_out_style_kind style)
 {
   int before = 0;
   int after = 0;
@@ -156,7 +159,31 @@ cli_ui_out::do_field_string (int fldno, int width, ui_align align,
     spaces (before);
 
   if (string)
-    out_field_fmt (fldno, fldname, "%s", string);
+    {
+      ui_file_style fstyle;
+      switch (style)
+       {
+       case ui_out_style_kind::DEFAULT:
+         /* Nothing.  */
+         break;
+       case ui_out_style_kind::FILE:
+         /* Nothing.  */
+         fstyle = file_name_style.style ();
+         break;
+       case ui_out_style_kind::FUNCTION:
+         fstyle = function_name_style.style ();
+         break;
+       case ui_out_style_kind::VARIABLE:
+         fstyle = variable_name_style.style ();
+         break;
+       case ui_out_style_kind::ADDRESS:
+         fstyle = address_style.style ();
+         break;
+       default:
+         gdb_assert_not_reached ("missing case");
+       }
+      fputs_styled (string, fstyle, m_streams.back ());
+    }
 
   if (after)
     spaces (after);
@@ -165,7 +192,7 @@ cli_ui_out::do_field_string (int fldno, int width, ui_align align,
     field_separator ();
 }
 
-/* This is the only field function that does not align.  */
+/* Output field containing ARGS using printf formatting in FORMAT.  */
 
 void
 cli_ui_out::do_field_fmt (int fldno, int width, ui_align align,
@@ -175,10 +202,10 @@ cli_ui_out::do_field_fmt (int fldno, int width, ui_align align,
   if (m_suppress_output)
     return;
 
-  vfprintf_filtered (m_streams.back (), format, args);
+  std::string str = string_vprintf (format, args);
 
-  if (align != ui_noalign)
-    field_separator ();
+  do_field_string (fldno, width, align, fldname, str.c_str (),
+                  ui_out_style_kind::DEFAULT);
 }
 
 void
@@ -227,35 +254,17 @@ cli_ui_out::do_flush ()
    and make it therefore active.  OUTSTREAM as NULL will pop the last pushed
    output stream; it is an internal error if it does not exist.  */
 
-int
+void
 cli_ui_out::do_redirect (ui_file *outstream)
 {
   if (outstream != NULL)
     m_streams.push_back (outstream);
   else
     m_streams.pop_back ();
-
-  return 0;
 }
 
 /* local functions */
 
-/* Like cli_ui_out::do_field_fmt, but takes a variable number of args
-   and makes a va_list and does not insert a separator.  */
-
-/* VARARGS */
-void
-cli_ui_out::out_field_fmt (int fldno, const char *fldname,
-                          const char *format, ...)
-{
-  va_list args;
-
-  va_start (args, format);
-  vfprintf_filtered (m_streams.back (), format, args);
-
-  va_end (args);
-}
-
 void
 cli_ui_out::field_separator ()
 {
This page took 0.035805 seconds and 4 git commands to generate.