1 /* Output generating routines for GDB CLI.
3 Copyright 1999, 2000, 2002 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 2 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, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA. */
28 #include "gdb_string.h"
29 #include "gdb_assert.h"
33 struct ui_file
*stream
;
37 /* These are the CLI output functions */
39 static void cli_table_begin (struct ui_out
*uiout
, int nbrofcols
,
40 int nr_rows
, const char *tblid
);
41 static void cli_table_body (struct ui_out
*uiout
);
42 static void cli_table_end (struct ui_out
*uiout
);
43 static void cli_table_header (struct ui_out
*uiout
, int width
,
44 enum ui_align alig
, const char *col_name
,
46 static void cli_begin (struct ui_out
*uiout
, enum ui_out_type type
,
47 int level
, const char *lstid
);
48 static void cli_end (struct ui_out
*uiout
, enum ui_out_type type
, int level
);
49 static void cli_field_int (struct ui_out
*uiout
, int fldno
, int width
,
50 enum ui_align alig
, const char *fldname
, int value
);
51 static void cli_field_skip (struct ui_out
*uiout
, int fldno
, int width
,
52 enum ui_align alig
, const char *fldname
);
53 static void cli_field_string (struct ui_out
*uiout
, int fldno
, int width
,
54 enum ui_align alig
, const char *fldname
,
56 static void cli_field_fmt (struct ui_out
*uiout
, int fldno
,
57 int width
, enum ui_align align
,
58 const char *fldname
, const char *format
,
60 static void cli_spaces (struct ui_out
*uiout
, int numspaces
);
61 static void cli_text (struct ui_out
*uiout
, const char *string
);
62 static void cli_message (struct ui_out
*uiout
, int verbosity
,
63 const char *format
, va_list args
);
64 static void cli_wrap_hint (struct ui_out
*uiout
, char *identstring
);
65 static void cli_flush (struct ui_out
*uiout
);
67 /* This is the CLI ui-out implementation functions vector */
69 /* FIXME: This can be initialized dynamically after default is set to
70 handle initial output in main.c */
72 static struct ui_out_impl cli_ui_out_impl
=
89 0, /* Does not need MI hacks (i.e. needs CLI hacks). */
92 /* Prototypes for local functions */
94 extern void _initialize_cli_out (void);
96 static void field_separator (void);
98 static void out_field_fmt (struct ui_out
*uiout
, int fldno
,
100 const char *format
,...);
102 /* local variables */
106 /* Mark beginning of a table */
109 cli_table_begin (struct ui_out
*uiout
, int nbrofcols
,
113 struct ui_out_data
*data
= ui_out_data (uiout
);
115 data
->suppress_output
= 1;
117 /* Only the table suppresses the output and, fortunatly, a table
118 is not a recursive data structure. */
119 gdb_assert (data
->suppress_output
== 0);
122 /* Mark beginning of a table body */
125 cli_table_body (struct ui_out
*uiout
)
127 struct ui_out_data
*data
= ui_out_data (uiout
);
128 if (data
->suppress_output
)
130 /* first, close the table header line */
131 cli_text (uiout
, "\n");
134 /* Mark end of a table */
137 cli_table_end (struct ui_out
*uiout
)
139 struct ui_out_data
*data
= ui_out_data (uiout
);
140 data
->suppress_output
= 0;
143 /* Specify table header */
146 cli_table_header (struct ui_out
*uiout
, int width
, enum ui_align alignment
,
147 const char *col_name
,
150 struct ui_out_data
*data
= ui_out_data (uiout
);
151 if (data
->suppress_output
)
153 cli_field_string (uiout
, 0, width
, alignment
, 0, colhdr
);
156 /* Mark beginning of a list */
159 cli_begin (struct ui_out
*uiout
,
160 enum ui_out_type type
,
164 struct ui_out_data
*data
= ui_out_data (uiout
);
165 if (data
->suppress_output
)
169 /* Mark end of a list */
172 cli_end (struct ui_out
*uiout
,
173 enum ui_out_type type
,
176 struct ui_out_data
*data
= ui_out_data (uiout
);
177 if (data
->suppress_output
)
181 /* output an int field */
184 cli_field_int (struct ui_out
*uiout
, int fldno
, int width
,
185 enum ui_align alignment
,
186 const char *fldname
, int value
)
188 char buffer
[20]; /* FIXME: how many chars long a %d can become? */
190 struct ui_out_data
*data
= ui_out_data (uiout
);
191 if (data
->suppress_output
)
193 sprintf (buffer
, "%d", value
);
194 cli_field_string (uiout
, fldno
, width
, alignment
, fldname
, buffer
);
197 /* used to ommit a field */
200 cli_field_skip (struct ui_out
*uiout
, int fldno
, int width
,
201 enum ui_align alignment
,
204 struct ui_out_data
*data
= ui_out_data (uiout
);
205 if (data
->suppress_output
)
207 cli_field_string (uiout
, fldno
, width
, alignment
, fldname
, "");
210 /* other specific cli_field_* end up here so alignment and field
211 separators are both handled by cli_field_string */
214 cli_field_string (struct ui_out
*uiout
,
224 struct ui_out_data
*data
= ui_out_data (uiout
);
225 if (data
->suppress_output
)
228 if ((align
!= ui_noalign
) && string
)
230 before
= width
- strlen (string
);
235 if (align
== ui_right
)
237 else if (align
== ui_left
)
252 ui_out_spaces (uiout
, before
);
254 out_field_fmt (uiout
, fldno
, fldname
, "%s", string
);
256 ui_out_spaces (uiout
, after
);
258 if (align
!= ui_noalign
)
262 /* This is the only field function that does not align */
265 cli_field_fmt (struct ui_out
*uiout
, int fldno
,
266 int width
, enum ui_align align
,
271 struct ui_out_data
*data
= ui_out_data (uiout
);
272 if (data
->suppress_output
)
275 vfprintf_filtered (data
->stream
, format
, args
);
277 if (align
!= ui_noalign
)
282 cli_spaces (struct ui_out
*uiout
, int numspaces
)
284 struct ui_out_data
*data
= ui_out_data (uiout
);
285 if (data
->suppress_output
)
287 print_spaces_filtered (numspaces
, data
->stream
);
291 cli_text (struct ui_out
*uiout
, const char *string
)
293 struct ui_out_data
*data
= ui_out_data (uiout
);
294 if (data
->suppress_output
)
296 fputs_filtered (string
, data
->stream
);
300 cli_message (struct ui_out
*uiout
, int verbosity
,
301 const char *format
, va_list args
)
303 struct ui_out_data
*data
= ui_out_data (uiout
);
304 if (data
->suppress_output
)
306 if (ui_out_get_verblvl (uiout
) >= verbosity
)
307 vfprintf_unfiltered (data
->stream
, format
, args
);
311 cli_wrap_hint (struct ui_out
*uiout
, char *identstring
)
313 struct ui_out_data
*data
= ui_out_data (uiout
);
314 if (data
->suppress_output
)
316 wrap_here (identstring
);
320 cli_flush (struct ui_out
*uiout
)
322 struct ui_out_data
*data
= ui_out_data (uiout
);
323 gdb_flush (data
->stream
);
326 /* local functions */
328 /* Like cli_field_fmt, but takes a variable number of args
329 and makes a va_list and does not insert a separator */
333 out_field_fmt (struct ui_out
*uiout
, int fldno
,
335 const char *format
,...)
337 struct ui_out_data
*data
= ui_out_data (uiout
);
340 va_start (args
, format
);
341 vfprintf_filtered (data
->stream
, format
, args
);
346 /* access to ui_out format private members */
349 field_separator (void)
351 struct ui_out_data
*data
= ui_out_data (uiout
);
352 fputc_filtered (' ', data
->stream
);
355 /* initalize private members at startup */
358 cli_out_new (struct ui_file
*stream
)
360 int flags
= ui_source_list
;
362 struct ui_out_data
*data
= XMALLOC (struct ui_out_data
);
363 data
->stream
= stream
;
364 data
->suppress_output
= 0;
365 return ui_out_new (&cli_ui_out_impl
, data
, flags
);
368 /* standard gdb initialization hook */
370 _initialize_cli_out (void)
372 /* nothing needs to be done */