1 /* Output generating routines for GDB CLI.
3 Copyright (C) 1999, 2000, 2002, 2003, 2005
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 2 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, write to the Free Software
23 Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 Boston, MA 02110-1301, USA. */
29 #include "gdb_string.h"
30 #include "gdb_assert.h"
34 struct ui_file
*stream
;
35 struct ui_file
*original_stream
;
38 typedef struct ui_out_data cli_out_data
;
40 /* These are the CLI output functions */
42 static void cli_table_begin (struct ui_out
*uiout
, int nbrofcols
,
43 int nr_rows
, const char *tblid
);
44 static void cli_table_body (struct ui_out
*uiout
);
45 static void cli_table_end (struct ui_out
*uiout
);
46 static void cli_table_header (struct ui_out
*uiout
, int width
,
47 enum ui_align alig
, const char *col_name
,
49 static void cli_begin (struct ui_out
*uiout
, enum ui_out_type type
,
50 int level
, const char *lstid
);
51 static void cli_end (struct ui_out
*uiout
, enum ui_out_type type
, int level
);
52 static void cli_field_int (struct ui_out
*uiout
, int fldno
, int width
,
53 enum ui_align alig
, const char *fldname
, int value
);
54 static void cli_field_skip (struct ui_out
*uiout
, int fldno
, int width
,
55 enum ui_align alig
, const char *fldname
);
56 static void cli_field_string (struct ui_out
*uiout
, int fldno
, int width
,
57 enum ui_align alig
, const char *fldname
,
59 static void cli_field_fmt (struct ui_out
*uiout
, int fldno
,
60 int width
, enum ui_align align
,
61 const char *fldname
, const char *format
,
62 va_list args
) ATTR_FORMAT (printf
, 6, 0);
63 static void cli_spaces (struct ui_out
*uiout
, int numspaces
);
64 static void cli_text (struct ui_out
*uiout
, const char *string
);
65 static void cli_message (struct ui_out
*uiout
, int verbosity
,
66 const char *format
, va_list args
)
67 ATTR_FORMAT (printf
, 3, 0);
68 static void cli_wrap_hint (struct ui_out
*uiout
, char *identstring
);
69 static void cli_flush (struct ui_out
*uiout
);
70 static int cli_redirect (struct ui_out
*uiout
, struct ui_file
*outstream
);
72 /* This is the CLI ui-out implementation functions vector */
74 /* FIXME: This can be initialized dynamically after default is set to
75 handle initial output in main.c */
77 static struct ui_out_impl cli_ui_out_impl
=
95 0, /* Does not need MI hacks (i.e. needs CLI hacks). */
98 /* Prototypes for local functions */
100 extern void _initialize_cli_out (void);
102 static void field_separator (void);
104 static void out_field_fmt (struct ui_out
*uiout
, int fldno
,
106 const char *format
,...) ATTR_FORMAT (printf
, 4, 5);
108 /* local variables */
112 /* Mark beginning of a table */
115 cli_table_begin (struct ui_out
*uiout
, int nbrofcols
,
119 cli_out_data
*data
= ui_out_data (uiout
);
121 data
->suppress_output
= 1;
123 /* Only the table suppresses the output and, fortunately, a table
124 is not a recursive data structure. */
125 gdb_assert (data
->suppress_output
== 0);
128 /* Mark beginning of a table body */
131 cli_table_body (struct ui_out
*uiout
)
133 cli_out_data
*data
= ui_out_data (uiout
);
134 if (data
->suppress_output
)
136 /* first, close the table header line */
137 cli_text (uiout
, "\n");
140 /* Mark end of a table */
143 cli_table_end (struct ui_out
*uiout
)
145 cli_out_data
*data
= ui_out_data (uiout
);
146 data
->suppress_output
= 0;
149 /* Specify table header */
152 cli_table_header (struct ui_out
*uiout
, int width
, enum ui_align alignment
,
153 const char *col_name
,
156 cli_out_data
*data
= ui_out_data (uiout
);
157 if (data
->suppress_output
)
159 cli_field_string (uiout
, 0, width
, alignment
, 0, colhdr
);
162 /* Mark beginning of a list */
165 cli_begin (struct ui_out
*uiout
,
166 enum ui_out_type type
,
170 cli_out_data
*data
= ui_out_data (uiout
);
171 if (data
->suppress_output
)
175 /* Mark end of a list */
178 cli_end (struct ui_out
*uiout
,
179 enum ui_out_type type
,
182 cli_out_data
*data
= ui_out_data (uiout
);
183 if (data
->suppress_output
)
187 /* output an int field */
190 cli_field_int (struct ui_out
*uiout
, int fldno
, int width
,
191 enum ui_align alignment
,
192 const char *fldname
, int value
)
194 char buffer
[20]; /* FIXME: how many chars long a %d can become? */
196 cli_out_data
*data
= ui_out_data (uiout
);
197 if (data
->suppress_output
)
199 sprintf (buffer
, "%d", value
);
200 cli_field_string (uiout
, fldno
, width
, alignment
, fldname
, buffer
);
203 /* used to ommit a field */
206 cli_field_skip (struct ui_out
*uiout
, int fldno
, int width
,
207 enum ui_align alignment
,
210 cli_out_data
*data
= ui_out_data (uiout
);
211 if (data
->suppress_output
)
213 cli_field_string (uiout
, fldno
, width
, alignment
, fldname
, "");
216 /* other specific cli_field_* end up here so alignment and field
217 separators are both handled by cli_field_string */
220 cli_field_string (struct ui_out
*uiout
,
230 cli_out_data
*data
= ui_out_data (uiout
);
231 if (data
->suppress_output
)
234 if ((align
!= ui_noalign
) && string
)
236 before
= width
- strlen (string
);
241 if (align
== ui_right
)
243 else if (align
== ui_left
)
258 ui_out_spaces (uiout
, before
);
260 out_field_fmt (uiout
, fldno
, fldname
, "%s", string
);
262 ui_out_spaces (uiout
, after
);
264 if (align
!= ui_noalign
)
268 /* This is the only field function that does not align. */
271 cli_field_fmt (struct ui_out
*uiout
, int fldno
,
272 int width
, enum ui_align align
,
277 cli_out_data
*data
= ui_out_data (uiout
);
278 if (data
->suppress_output
)
281 vfprintf_filtered (data
->stream
, format
, args
);
283 if (align
!= ui_noalign
)
288 cli_spaces (struct ui_out
*uiout
, int numspaces
)
290 cli_out_data
*data
= ui_out_data (uiout
);
291 if (data
->suppress_output
)
293 print_spaces_filtered (numspaces
, data
->stream
);
297 cli_text (struct ui_out
*uiout
, const char *string
)
299 cli_out_data
*data
= ui_out_data (uiout
);
300 if (data
->suppress_output
)
302 fputs_filtered (string
, data
->stream
);
306 cli_message (struct ui_out
*uiout
, int verbosity
,
307 const char *format
, va_list args
)
309 cli_out_data
*data
= ui_out_data (uiout
);
310 if (data
->suppress_output
)
312 if (ui_out_get_verblvl (uiout
) >= verbosity
)
313 vfprintf_unfiltered (data
->stream
, format
, args
);
317 cli_wrap_hint (struct ui_out
*uiout
, char *identstring
)
319 cli_out_data
*data
= ui_out_data (uiout
);
320 if (data
->suppress_output
)
322 wrap_here (identstring
);
326 cli_flush (struct ui_out
*uiout
)
328 cli_out_data
*data
= ui_out_data (uiout
);
329 gdb_flush (data
->stream
);
333 cli_redirect (struct ui_out
*uiout
, struct ui_file
*outstream
)
335 struct ui_out_data
*data
= ui_out_data (uiout
);
336 if (outstream
!= NULL
)
338 data
->original_stream
= data
->stream
;
339 data
->stream
= outstream
;
341 else if (data
->original_stream
!= NULL
)
343 data
->stream
= data
->original_stream
;
344 data
->original_stream
= NULL
;
350 /* local functions */
352 /* Like cli_field_fmt, but takes a variable number of args
353 and makes a va_list and does not insert a separator. */
357 out_field_fmt (struct ui_out
*uiout
, int fldno
,
359 const char *format
,...)
361 cli_out_data
*data
= ui_out_data (uiout
);
364 va_start (args
, format
);
365 vfprintf_filtered (data
->stream
, format
, args
);
370 /* Access to ui_out format private members. */
373 field_separator (void)
375 cli_out_data
*data
= ui_out_data (uiout
);
376 fputc_filtered (' ', data
->stream
);
379 /* Initalize private members at startup. */
382 cli_out_new (struct ui_file
*stream
)
384 int flags
= ui_source_list
;
386 cli_out_data
*data
= XMALLOC (cli_out_data
);
387 data
->stream
= stream
;
388 data
->original_stream
= NULL
;
389 data
->suppress_output
= 0;
390 return ui_out_new (&cli_ui_out_impl
, data
, flags
);
394 cli_out_set_stream (struct ui_out
*uiout
, struct ui_file
*stream
)
396 cli_out_data
*data
= ui_out_data (uiout
);
397 struct ui_file
*old
= data
->stream
;
398 data
->stream
= stream
;
402 /* Standard gdb initialization hook. */
404 _initialize_cli_out (void)
406 /* nothing needs to be done */