gdb/amd64: clean up unused variable
[binutils-gdb.git] / gdb / cli-out.c
index 9ffd6f01577548041739653032ee511d202e867d..fdbed6f5e91feb2d1950d38880ef6744e93ad55b 100644 (file)
@@ -1,6 +1,6 @@
 /* Output generating routines for GDB CLI.
 
-   Copyright (C) 1999-2018 Free Software Foundation, Inc.
+   Copyright (C) 1999-2022 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_file_style ());
 }
 
 /* Mark beginning of a list */
@@ -91,17 +93,27 @@ cli_ui_out::do_end (ui_out_type type)
 /* output an int field */
 
 void
-cli_ui_out::do_field_int (int fldno, int width, ui_align alignment,
-                         const char *fldname, int value)
+cli_ui_out::do_field_signed (int fldno, int width, ui_align alignment,
+                            const char *fldname, LONGEST value)
 {
-  char buffer[20];     /* FIXME: how many chars long a %d can become? */
-
   if (m_suppress_output)
     return;
 
-  xsnprintf (buffer, sizeof (buffer), "%d", value);
+  do_field_string (fldno, width, alignment, fldname, plongest (value),
+                  ui_file_style ());
+}
+
+/* output an unsigned field */
+
+void
+cli_ui_out::do_field_unsigned (int fldno, int width, ui_align alignment,
+                              const char *fldname, ULONGEST value)
+{
+  if (m_suppress_output)
+    return;
 
-  do_field_string (fldno, width, alignment, fldname, buffer);
+  do_field_string (fldno, width, alignment, fldname, pulongest (value),
+                  ui_file_style ());
 }
 
 /* used to omit a field */
@@ -113,7 +125,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_file_style ());
 }
 
 /* other specific cli_field_* end up here so alignment and field
@@ -121,7 +134,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,
+                            const ui_file_style &style)
 {
   int before = 0;
   int after = 0;
@@ -156,7 +170,12 @@ cli_ui_out::do_field_string (int fldno, int width, ui_align align,
     spaces (before);
 
   if (string)
-    fputs_filtered (string, m_streams.back ());
+    {
+      ui_file *stream = m_streams.back ();
+      stream->emit_style_escape (style);
+      stream->puts (string);
+      stream->emit_style_escape (ui_file_style ());
+    }
 
   if (after)
     spaces (after);
@@ -169,15 +188,15 @@ cli_ui_out::do_field_string (int fldno, int width, ui_align align,
 
 void
 cli_ui_out::do_field_fmt (int fldno, int width, ui_align align,
-                         const char *fldname, const char *format,
-                         va_list args)
+                         const char *fldname, const ui_file_style &style,
+                         const char *format, va_list args)
 {
   if (m_suppress_output)
     return;
 
   std::string str = string_vprintf (format, args);
 
-  do_field_string (fldno, width, align, fldname, str.c_str ());
+  do_field_string (fldno, width, align, fldname, str.c_str (), style);
 }
 
 void
@@ -186,7 +205,7 @@ cli_ui_out::do_spaces (int numspaces)
   if (m_suppress_output)
     return;
 
-  print_spaces_filtered (numspaces, m_streams.back ());
+  print_spaces (numspaces, m_streams.back ());
 }
 
 void
@@ -195,25 +214,33 @@ cli_ui_out::do_text (const char *string)
   if (m_suppress_output)
     return;
 
-  fputs_filtered (string, m_streams.back ());
+  gdb_puts (string, m_streams.back ());
 }
 
 void
-cli_ui_out::do_message (const char *format, va_list args)
+cli_ui_out::do_message (const ui_file_style &style,
+                       const char *format, va_list args)
 {
   if (m_suppress_output)
     return;
 
-  vfprintf_unfiltered (m_streams.back (), format, args);
+  std::string str = string_vprintf (format, args);
+  if (!str.empty ())
+    {
+      ui_file *stream = m_streams.back ();
+      stream->emit_style_escape (style);
+      stream->puts (str.c_str ());
+      stream->emit_style_escape (ui_file_style ());
+    }
 }
 
 void
-cli_ui_out::do_wrap_hint (const char *identstring)
+cli_ui_out::do_wrap_hint (int indent)
 {
   if (m_suppress_output)
     return;
 
-  wrap_here (identstring);
+  m_streams.back ()->wrap_here (indent);
 }
 
 void
@@ -235,12 +262,113 @@ cli_ui_out::do_redirect (ui_file *outstream)
     m_streams.pop_back ();
 }
 
+/* The cli_ui_out::do_progress_* functions result in the following:
+   - printed for tty, SHOULD_PRINT == true:
+     <NAME
+      [#####                      ]\r>
+   - printed for tty, SHOULD_PRINT == false:
+     <>
+   - printed for not-a-tty:
+     <NAME...
+     >
+*/
+
+void
+cli_ui_out::do_progress_start (const std::string &name, bool should_print)
+{
+  struct ui_file *stream = m_streams.back ();
+  cli_progress_info meter;
+
+  meter.last_value = 0;
+  meter.name = name;
+  if (!stream->isatty ())
+    {
+      gdb_printf (stream, "%s...", meter.name.c_str ());
+      gdb_flush (stream);
+      meter.printing = WORKING;
+    }
+  else
+    {
+      /* Don't actually emit anything until the first call notifies us
+        of progress.  This makes it so a second progress message can
+        be started before the first one has been notified, without
+        messy output.  */
+      meter.printing = should_print ? START : NO_PRINT;
+    }
+
+  m_meters.push_back (std::move (meter));
+}
+
+void
+cli_ui_out::do_progress_notify (double howmuch)
+{
+  struct ui_file *stream = m_streams.back ();
+  cli_progress_info &meter (m_meters.back ());
+
+  if (meter.printing == NO_PRINT)
+    return;
+
+  if (meter.printing == START)
+    {
+      gdb_printf (stream, "%s\n", meter.name.c_str ());
+      gdb_flush (stream);
+      meter.printing = WORKING;
+    }
+
+  if (meter.printing == WORKING && howmuch >= 1.0)
+    return;
+
+  if (!stream->isatty ())
+    return;
+
+  int chars_per_line = get_chars_per_line ();
+  if (chars_per_line > 0)
+    {
+      int i, max;
+      int width = chars_per_line - 3;
+
+      max = width * howmuch;
+      gdb_printf (stream, "\r[");
+      for (i = 0; i < width; ++i)
+       gdb_printf (stream, i < max ? "#" : " ");
+      gdb_printf (stream, "]");
+      gdb_flush (stream);
+      meter.printing = PROGRESS;
+    }
+}
+
+void
+cli_ui_out::do_progress_end ()
+{
+  struct ui_file *stream = m_streams.back ();
+  cli_progress_info &meter = m_meters.back ();
+
+  if (!stream->isatty ())
+    {
+      gdb_printf (stream, "\n");
+      gdb_flush (stream);
+    }
+  else if (meter.printing == PROGRESS)
+    {
+      int i;
+      int width = get_chars_per_line () - 3;
+
+      gdb_printf (stream, "\r");
+      for (i = 0; i < width + 2; ++i)
+       gdb_printf (stream, " ");
+      gdb_printf (stream, "\r");
+      gdb_flush (stream);
+    }
+
+  m_meters.pop_back ();
+}
+
 /* local functions */
 
 void
 cli_ui_out::field_separator ()
 {
-  fputc_filtered (' ', m_streams.back ());
+  gdb_putc (' ', m_streams.back ());
 }
 
 /* Constructor for cli_ui_out.  */
@@ -258,14 +386,6 @@ cli_ui_out::~cli_ui_out ()
 {
 }
 
-/* Initialize private members at startup.  */
-
-cli_ui_out *
-cli_out_new (struct ui_file *stream)
-{
-  return new cli_ui_out (stream, ui_source_list);
-}
-
 ui_file *
 cli_ui_out::set_stream (struct ui_file *stream)
 {
@@ -277,6 +397,12 @@ cli_ui_out::set_stream (struct ui_file *stream)
   return old;
 }
 
+bool
+cli_ui_out::can_emit_style_escape () const
+{
+  return m_streams.back ()->can_emit_style_escape ();
+}
+
 /* CLI interface to display tab-completion matches.  */
 
 /* CLI version of displayer.crlf.  */