1 /* Output generating routines for GDB CLI.
3 Copyright (C) 1999-2000, 2002-2003, 2005, 2007-2012 Free Software
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"
31 typedef struct cli_ui_out_data cli_out_data
;
34 /* Prototypes for local functions */
36 static void cli_text (struct ui_out
*uiout
, const char *string
);
38 static void field_separator (void);
40 static void out_field_fmt (struct ui_out
*uiout
, int fldno
,
42 const char *format
,...) ATTRIBUTE_PRINTF (4, 5);
44 /* These are the CLI output functions */
46 /* Mark beginning of a table */
49 cli_table_begin (struct ui_out
*uiout
, int nbrofcols
,
53 cli_out_data
*data
= ui_out_data (uiout
);
56 data
->suppress_output
= 1;
58 /* Only the table suppresses the output and, fortunately, a table
59 is not a recursive data structure. */
60 gdb_assert (data
->suppress_output
== 0);
63 /* Mark beginning of a table body */
66 cli_table_body (struct ui_out
*uiout
)
68 cli_out_data
*data
= ui_out_data (uiout
);
70 if (data
->suppress_output
)
72 /* first, close the table header line */
73 cli_text (uiout
, "\n");
76 /* Mark end of a table */
79 cli_table_end (struct ui_out
*uiout
)
81 cli_out_data
*data
= ui_out_data (uiout
);
83 data
->suppress_output
= 0;
86 /* Specify table header */
89 cli_table_header (struct ui_out
*uiout
, int width
, enum ui_align alignment
,
93 cli_out_data
*data
= ui_out_data (uiout
);
95 if (data
->suppress_output
)
98 /* Always go through the function pointer (virtual function call).
99 We may have been extended. */
100 uo_field_string (uiout
, 0, width
, alignment
, 0, colhdr
);
103 /* Mark beginning of a list */
106 cli_begin (struct ui_out
*uiout
,
107 enum ui_out_type type
,
111 cli_out_data
*data
= ui_out_data (uiout
);
113 if (data
->suppress_output
)
117 /* Mark end of a list */
120 cli_end (struct ui_out
*uiout
,
121 enum ui_out_type type
,
124 cli_out_data
*data
= ui_out_data (uiout
);
126 if (data
->suppress_output
)
130 /* output an int field */
133 cli_field_int (struct ui_out
*uiout
, int fldno
, int width
,
134 enum ui_align alignment
,
135 const char *fldname
, int value
)
137 char buffer
[20]; /* FIXME: how many chars long a %d can become? */
138 cli_out_data
*data
= ui_out_data (uiout
);
140 if (data
->suppress_output
)
142 sprintf (buffer
, "%d", value
);
144 /* Always go through the function pointer (virtual function call).
145 We may have been extended. */
146 uo_field_string (uiout
, fldno
, width
, alignment
, fldname
, buffer
);
149 /* used to ommit a field */
152 cli_field_skip (struct ui_out
*uiout
, int fldno
, int width
,
153 enum ui_align alignment
,
156 cli_out_data
*data
= ui_out_data (uiout
);
158 if (data
->suppress_output
)
161 /* Always go through the function pointer (virtual function call).
162 We may have been extended. */
163 uo_field_string (uiout
, fldno
, width
, alignment
, fldname
, "");
166 /* other specific cli_field_* end up here so alignment and field
167 separators are both handled by cli_field_string */
170 cli_field_string (struct ui_out
*uiout
,
179 cli_out_data
*data
= ui_out_data (uiout
);
181 if (data
->suppress_output
)
184 if ((align
!= ui_noalign
) && string
)
186 before
= width
- strlen (string
);
191 if (align
== ui_right
)
193 else if (align
== ui_left
)
208 ui_out_spaces (uiout
, before
);
210 out_field_fmt (uiout
, fldno
, fldname
, "%s", string
);
212 ui_out_spaces (uiout
, after
);
214 if (align
!= ui_noalign
)
218 /* This is the only field function that does not align. */
220 static void ATTRIBUTE_PRINTF (6, 0)
221 cli_field_fmt (struct ui_out
*uiout
, int fldno
,
222 int width
, enum ui_align align
,
227 cli_out_data
*data
= ui_out_data (uiout
);
228 struct ui_file
*stream
;
230 if (data
->suppress_output
)
233 stream
= VEC_last (ui_filep
, data
->streams
);
234 vfprintf_filtered (stream
, format
, args
);
236 if (align
!= ui_noalign
)
241 cli_spaces (struct ui_out
*uiout
, int numspaces
)
243 cli_out_data
*data
= ui_out_data (uiout
);
244 struct ui_file
*stream
;
246 if (data
->suppress_output
)
249 stream
= VEC_last (ui_filep
, data
->streams
);
250 print_spaces_filtered (numspaces
, stream
);
254 cli_text (struct ui_out
*uiout
, const char *string
)
256 cli_out_data
*data
= ui_out_data (uiout
);
257 struct ui_file
*stream
;
259 if (data
->suppress_output
)
262 stream
= VEC_last (ui_filep
, data
->streams
);
263 fputs_filtered (string
, stream
);
266 static void ATTRIBUTE_PRINTF (3, 0)
267 cli_message (struct ui_out
*uiout
, int verbosity
,
268 const char *format
, va_list args
)
270 cli_out_data
*data
= ui_out_data (uiout
);
272 if (data
->suppress_output
)
275 if (ui_out_get_verblvl (uiout
) >= verbosity
)
277 struct ui_file
*stream
= VEC_last (ui_filep
, data
->streams
);
279 vfprintf_unfiltered (stream
, format
, args
);
284 cli_wrap_hint (struct ui_out
*uiout
, char *identstring
)
286 cli_out_data
*data
= ui_out_data (uiout
);
288 if (data
->suppress_output
)
290 wrap_here (identstring
);
294 cli_flush (struct ui_out
*uiout
)
296 cli_out_data
*data
= ui_out_data (uiout
);
297 struct ui_file
*stream
= VEC_last (ui_filep
, data
->streams
);
302 /* OUTSTREAM as non-NULL will push OUTSTREAM on the stack of output streams
303 and make it therefore active. OUTSTREAM as NULL will pop the last pushed
304 output stream; it is an internal error if it does not exist. */
307 cli_redirect (struct ui_out
*uiout
, struct ui_file
*outstream
)
309 cli_out_data
*data
= ui_out_data (uiout
);
311 if (outstream
!= NULL
)
312 VEC_safe_push (ui_filep
, data
->streams
, outstream
);
314 VEC_pop (ui_filep
, data
->streams
);
319 /* local functions */
321 /* Like cli_field_fmt, but takes a variable number of args
322 and makes a va_list and does not insert a separator. */
326 out_field_fmt (struct ui_out
*uiout
, int fldno
,
328 const char *format
,...)
330 cli_out_data
*data
= ui_out_data (uiout
);
331 struct ui_file
*stream
= VEC_last (ui_filep
, data
->streams
);
334 va_start (args
, format
);
335 vfprintf_filtered (stream
, format
, args
);
340 /* Access to ui_out format private members. */
343 field_separator (void)
345 cli_out_data
*data
= ui_out_data (current_uiout
);
346 struct ui_file
*stream
= VEC_last (ui_filep
, data
->streams
);
348 fputc_filtered (' ', stream
);
351 /* This is the CLI ui-out implementation functions vector */
353 /* FIXME: This can be initialized dynamically after default is set to
354 handle initial output in main.c */
356 struct ui_out_impl cli_ui_out_impl
=
374 0, /* Does not need MI hacks (i.e. needs CLI hacks). */
377 /* Constructor for a `cli_out_data' object. */
380 cli_out_data_ctor (cli_out_data
*self
, struct ui_file
*stream
)
382 gdb_assert (stream
!= NULL
);
384 self
->streams
= NULL
;
385 VEC_safe_push (ui_filep
, self
->streams
, stream
);
387 self
->suppress_output
= 0;
390 /* Initialize private members at startup. */
393 cli_out_new (struct ui_file
*stream
)
395 int flags
= ui_source_list
;
396 cli_out_data
*data
= XMALLOC (cli_out_data
);
398 cli_out_data_ctor (data
, stream
);
399 return ui_out_new (&cli_ui_out_impl
, data
, flags
);
403 cli_out_set_stream (struct ui_out
*uiout
, struct ui_file
*stream
)
405 cli_out_data
*data
= ui_out_data (uiout
);
408 old
= VEC_pop (ui_filep
, data
->streams
);
409 VEC_quick_push (ui_filep
, data
->streams
, stream
);