1 /* Output generating routines for GDB CLI.
3 Copyright (C) 1999, 2000, 2002, 2003, 2005, 2007, 2008, 2009, 2010
4 Free Software Foundation, Inc.
6 Contributed by Cygnus Solutions.
7 Written by Fernando Nasser for Cygnus.
9 This file is part of GDB.
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 3 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program. If not, see <http://www.gnu.org/licenses/>. */
27 #include "gdb_string.h"
28 #include "gdb_assert.h"
30 typedef struct cli_ui_out_data cli_out_data;
33 /* Prototypes for local functions */
35 static void cli_text (struct ui_out *uiout, const char *string);
37 static void field_separator (void);
39 static void out_field_fmt (struct ui_out *uiout, int fldno,
41 const char *format,...) ATTR_FORMAT (printf, 4, 5);
43 /* These are the CLI output functions */
45 /* Mark beginning of a table */
48 cli_table_begin (struct ui_out *uiout, int nbrofcols,
52 cli_out_data *data = ui_out_data (uiout);
54 data->suppress_output = 1;
56 /* Only the table suppresses the output and, fortunately, a table
57 is not a recursive data structure. */
58 gdb_assert (data->suppress_output == 0);
61 /* Mark beginning of a table body */
64 cli_table_body (struct ui_out *uiout)
66 cli_out_data *data = ui_out_data (uiout);
67 if (data->suppress_output)
69 /* first, close the table header line */
70 cli_text (uiout, "\n");
73 /* Mark end of a table */
76 cli_table_end (struct ui_out *uiout)
78 cli_out_data *data = ui_out_data (uiout);
79 data->suppress_output = 0;
82 /* Specify table header */
85 cli_table_header (struct ui_out *uiout, int width, enum ui_align alignment,
89 cli_out_data *data = ui_out_data (uiout);
90 if (data->suppress_output)
93 /* Always go through the function pointer (virtual function call).
94 We may have been extended. */
95 uo_field_string (uiout, 0, width, alignment, 0, colhdr);
98 /* Mark beginning of a list */
101 cli_begin (struct ui_out *uiout,
102 enum ui_out_type type,
106 cli_out_data *data = ui_out_data (uiout);
107 if (data->suppress_output)
111 /* Mark end of a list */
114 cli_end (struct ui_out *uiout,
115 enum ui_out_type type,
118 cli_out_data *data = ui_out_data (uiout);
119 if (data->suppress_output)
123 /* output an int field */
126 cli_field_int (struct ui_out *uiout, int fldno, int width,
127 enum ui_align alignment,
128 const char *fldname, int value)
130 char buffer[20]; /* FIXME: how many chars long a %d can become? */
132 cli_out_data *data = ui_out_data (uiout);
133 if (data->suppress_output)
135 sprintf (buffer, "%d", value);
137 /* Always go through the function pointer (virtual function call).
138 We may have been extended. */
139 uo_field_string (uiout, fldno, width, alignment, fldname, buffer);
142 /* used to ommit a field */
145 cli_field_skip (struct ui_out *uiout, int fldno, int width,
146 enum ui_align alignment,
149 cli_out_data *data = ui_out_data (uiout);
150 if (data->suppress_output)
153 /* Always go through the function pointer (virtual function call).
154 We may have been extended. */
155 uo_field_string (uiout, fldno, width, alignment, fldname, "");
158 /* other specific cli_field_* end up here so alignment and field
159 separators are both handled by cli_field_string */
162 cli_field_string (struct ui_out *uiout,
172 cli_out_data *data = ui_out_data (uiout);
173 if (data->suppress_output)
176 if ((align != ui_noalign) && string)
178 before = width - strlen (string);
183 if (align == ui_right)
185 else if (align == ui_left)
200 ui_out_spaces (uiout, before);
202 out_field_fmt (uiout, fldno, fldname, "%s", string);
204 ui_out_spaces (uiout, after);
206 if (align != ui_noalign)
210 /* This is the only field function that does not align. */
213 cli_field_fmt (struct ui_out *uiout, int fldno,
214 int width, enum ui_align align,
219 cli_out_data *data = ui_out_data (uiout);
220 if (data->suppress_output)
223 vfprintf_filtered (data->stream, format, args);
225 if (align != ui_noalign)
230 cli_spaces (struct ui_out *uiout, int numspaces)
232 cli_out_data *data = ui_out_data (uiout);
233 if (data->suppress_output)
235 print_spaces_filtered (numspaces, data->stream);
239 cli_text (struct ui_out *uiout, const char *string)
241 cli_out_data *data = ui_out_data (uiout);
242 if (data->suppress_output)
244 fputs_filtered (string, data->stream);
247 static void ATTR_FORMAT (printf, 3,0)
248 cli_message (struct ui_out *uiout, int verbosity,
249 const char *format, va_list args)
251 cli_out_data *data = ui_out_data (uiout);
252 if (data->suppress_output)
254 if (ui_out_get_verblvl (uiout) >= verbosity)
255 vfprintf_unfiltered (data->stream, format, args);
259 cli_wrap_hint (struct ui_out *uiout, char *identstring)
261 cli_out_data *data = ui_out_data (uiout);
262 if (data->suppress_output)
264 wrap_here (identstring);
268 cli_flush (struct ui_out *uiout)
270 cli_out_data *data = ui_out_data (uiout);
271 gdb_flush (data->stream);
275 cli_redirect (struct ui_out *uiout, struct ui_file *outstream)
277 cli_out_data *data = ui_out_data (uiout);
278 if (outstream != NULL)
280 data->original_stream = data->stream;
281 data->stream = outstream;
283 else if (data->original_stream != NULL)
285 data->stream = data->original_stream;
286 data->original_stream = NULL;
292 /* local functions */
294 /* Like cli_field_fmt, but takes a variable number of args
295 and makes a va_list and does not insert a separator. */
299 out_field_fmt (struct ui_out *uiout, int fldno,
301 const char *format,...)
303 cli_out_data *data = ui_out_data (uiout);
306 va_start (args, format);
307 vfprintf_filtered (data->stream, format, args);
312 /* Access to ui_out format private members. */
315 field_separator (void)
317 cli_out_data *data = ui_out_data (uiout);
318 fputc_filtered (' ', data->stream);
321 /* This is the CLI ui-out implementation functions vector */
323 /* FIXME: This can be initialized dynamically after default is set to
324 handle initial output in main.c */
326 struct ui_out_impl cli_ui_out_impl =
344 0, /* Does not need MI hacks (i.e. needs CLI hacks). */
347 /* Constructor for a `cli_out_data' object. */
350 cli_out_data_ctor (cli_out_data *self, struct ui_file *stream)
352 self->stream = stream;
353 self->original_stream = NULL;
354 self->suppress_output = 0;
357 /* Initialize private members at startup. */
360 cli_out_new (struct ui_file *stream)
362 int flags = ui_source_list;
364 cli_out_data *data = XMALLOC (cli_out_data);
365 cli_out_data_ctor (data, stream);
366 return ui_out_new (&cli_ui_out_impl, data, flags);
370 cli_out_set_stream (struct ui_out *uiout, struct ui_file *stream)
372 cli_out_data *data = ui_out_data (uiout);
373 struct ui_file *old = data->stream;
374 data->stream = stream;