1 /* Output generating routines for GDB CLI.
3 Copyright (C) 1999-2014 Free Software Foundation, Inc.
5 Contributed by Cygnus Solutions.
6 Written by Fernando Nasser for Cygnus.
8 This file is part of GDB.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>. */
28 typedef struct cli_ui_out_data cli_out_data
;
31 /* Prototypes for local functions */
33 static void cli_text (struct ui_out
*uiout
, const char *string
);
35 static void field_separator (void);
37 static void out_field_fmt (struct ui_out
*uiout
, int fldno
,
39 const char *format
,...) ATTRIBUTE_PRINTF (4, 5);
44 cli_uiout_dtor (struct ui_out
*ui_out
)
46 cli_out_data
*data
= ui_out_data (ui_out
);
48 VEC_free (ui_filep
, data
->streams
);
52 /* These are the CLI output functions */
54 /* Mark beginning of a table */
57 cli_table_begin (struct ui_out
*uiout
, int nbrofcols
,
61 cli_out_data
*data
= ui_out_data (uiout
);
64 data
->suppress_output
= 1;
66 /* Only the table suppresses the output and, fortunately, a table
67 is not a recursive data structure. */
68 gdb_assert (data
->suppress_output
== 0);
71 /* Mark beginning of a table body */
74 cli_table_body (struct ui_out
*uiout
)
76 cli_out_data
*data
= ui_out_data (uiout
);
78 if (data
->suppress_output
)
80 /* first, close the table header line */
81 cli_text (uiout
, "\n");
84 /* Mark end of a table */
87 cli_table_end (struct ui_out
*uiout
)
89 cli_out_data
*data
= ui_out_data (uiout
);
91 data
->suppress_output
= 0;
94 /* Specify table header */
97 cli_table_header (struct ui_out
*uiout
, int width
, enum ui_align alignment
,
101 cli_out_data
*data
= ui_out_data (uiout
);
103 if (data
->suppress_output
)
106 /* Always go through the function pointer (virtual function call).
107 We may have been extended. */
108 uo_field_string (uiout
, 0, width
, alignment
, 0, colhdr
);
111 /* Mark beginning of a list */
114 cli_begin (struct ui_out
*uiout
,
115 enum ui_out_type type
,
119 cli_out_data
*data
= ui_out_data (uiout
);
121 if (data
->suppress_output
)
125 /* Mark end of a list */
128 cli_end (struct ui_out
*uiout
,
129 enum ui_out_type type
,
132 cli_out_data
*data
= ui_out_data (uiout
);
134 if (data
->suppress_output
)
138 /* output an int field */
141 cli_field_int (struct ui_out
*uiout
, int fldno
, int width
,
142 enum ui_align alignment
,
143 const char *fldname
, int value
)
145 char buffer
[20]; /* FIXME: how many chars long a %d can become? */
146 cli_out_data
*data
= ui_out_data (uiout
);
148 if (data
->suppress_output
)
150 xsnprintf (buffer
, sizeof (buffer
), "%d", value
);
152 /* Always go through the function pointer (virtual function call).
153 We may have been extended. */
154 uo_field_string (uiout
, fldno
, width
, alignment
, fldname
, buffer
);
157 /* used to ommit a field */
160 cli_field_skip (struct ui_out
*uiout
, int fldno
, int width
,
161 enum ui_align alignment
,
164 cli_out_data
*data
= ui_out_data (uiout
);
166 if (data
->suppress_output
)
169 /* Always go through the function pointer (virtual function call).
170 We may have been extended. */
171 uo_field_string (uiout
, fldno
, width
, alignment
, fldname
, "");
174 /* other specific cli_field_* end up here so alignment and field
175 separators are both handled by cli_field_string */
178 cli_field_string (struct ui_out
*uiout
,
187 cli_out_data
*data
= ui_out_data (uiout
);
189 if (data
->suppress_output
)
192 if ((align
!= ui_noalign
) && string
)
194 before
= width
- strlen (string
);
199 if (align
== ui_right
)
201 else if (align
== ui_left
)
216 ui_out_spaces (uiout
, before
);
218 out_field_fmt (uiout
, fldno
, fldname
, "%s", string
);
220 ui_out_spaces (uiout
, after
);
222 if (align
!= ui_noalign
)
226 /* This is the only field function that does not align. */
228 static void ATTRIBUTE_PRINTF (6, 0)
229 cli_field_fmt (struct ui_out
*uiout
, int fldno
,
230 int width
, enum ui_align align
,
235 cli_out_data
*data
= ui_out_data (uiout
);
236 struct ui_file
*stream
;
238 if (data
->suppress_output
)
241 stream
= VEC_last (ui_filep
, data
->streams
);
242 vfprintf_filtered (stream
, format
, args
);
244 if (align
!= ui_noalign
)
249 cli_spaces (struct ui_out
*uiout
, int numspaces
)
251 cli_out_data
*data
= ui_out_data (uiout
);
252 struct ui_file
*stream
;
254 if (data
->suppress_output
)
257 stream
= VEC_last (ui_filep
, data
->streams
);
258 print_spaces_filtered (numspaces
, stream
);
262 cli_text (struct ui_out
*uiout
, const char *string
)
264 cli_out_data
*data
= ui_out_data (uiout
);
265 struct ui_file
*stream
;
267 if (data
->suppress_output
)
270 stream
= VEC_last (ui_filep
, data
->streams
);
271 fputs_filtered (string
, stream
);
274 static void ATTRIBUTE_PRINTF (3, 0)
275 cli_message (struct ui_out
*uiout
, int verbosity
,
276 const char *format
, va_list args
)
278 cli_out_data
*data
= ui_out_data (uiout
);
280 if (data
->suppress_output
)
283 if (ui_out_get_verblvl (uiout
) >= verbosity
)
285 struct ui_file
*stream
= VEC_last (ui_filep
, data
->streams
);
287 vfprintf_unfiltered (stream
, format
, args
);
292 cli_wrap_hint (struct ui_out
*uiout
, char *identstring
)
294 cli_out_data
*data
= ui_out_data (uiout
);
296 if (data
->suppress_output
)
298 wrap_here (identstring
);
302 cli_flush (struct ui_out
*uiout
)
304 cli_out_data
*data
= ui_out_data (uiout
);
305 struct ui_file
*stream
= VEC_last (ui_filep
, data
->streams
);
310 /* OUTSTREAM as non-NULL will push OUTSTREAM on the stack of output streams
311 and make it therefore active. OUTSTREAM as NULL will pop the last pushed
312 output stream; it is an internal error if it does not exist. */
315 cli_redirect (struct ui_out
*uiout
, struct ui_file
*outstream
)
317 cli_out_data
*data
= ui_out_data (uiout
);
319 if (outstream
!= NULL
)
320 VEC_safe_push (ui_filep
, data
->streams
, outstream
);
322 VEC_pop (ui_filep
, data
->streams
);
327 /* local functions */
329 /* Like cli_field_fmt, but takes a variable number of args
330 and makes a va_list and does not insert a separator. */
334 out_field_fmt (struct ui_out
*uiout
, int fldno
,
336 const char *format
,...)
338 cli_out_data
*data
= ui_out_data (uiout
);
339 struct ui_file
*stream
= VEC_last (ui_filep
, data
->streams
);
342 va_start (args
, format
);
343 vfprintf_filtered (stream
, format
, args
);
348 /* Access to ui_out format private members. */
351 field_separator (void)
353 cli_out_data
*data
= ui_out_data (current_uiout
);
354 struct ui_file
*stream
= VEC_last (ui_filep
, data
->streams
);
356 fputc_filtered (' ', stream
);
359 /* This is the CLI ui-out implementation functions vector */
361 const struct ui_out_impl cli_ui_out_impl
=
380 0, /* Does not need MI hacks (i.e. needs CLI hacks). */
383 /* Constructor for a `cli_out_data' object. */
386 cli_out_data_ctor (cli_out_data
*self
, struct ui_file
*stream
)
388 gdb_assert (stream
!= NULL
);
390 self
->streams
= NULL
;
391 VEC_safe_push (ui_filep
, self
->streams
, stream
);
393 self
->suppress_output
= 0;
396 /* Initialize private members at startup. */
399 cli_out_new (struct ui_file
*stream
)
401 int flags
= ui_source_list
;
402 cli_out_data
*data
= XNEW (cli_out_data
);
404 cli_out_data_ctor (data
, stream
);
405 return ui_out_new (&cli_ui_out_impl
, data
, flags
);
409 cli_out_set_stream (struct ui_out
*uiout
, struct ui_file
*stream
)
411 cli_out_data
*data
= ui_out_data (uiout
);
414 old
= VEC_pop (ui_filep
, data
->streams
);
415 VEC_quick_push (ui_filep
, data
->streams
, stream
);