1 /* Output generating routines for GDB CLI.
3 Copyright 1999, 2000, 2002, 2003 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
;
36 typedef struct ui_out_data cli_out_data
;
38 /* These are the CLI output functions */
40 static void cli_table_begin (struct ui_out
*uiout
, int nbrofcols
,
41 int nr_rows
, const char *tblid
);
42 static void cli_table_body (struct ui_out
*uiout
);
43 static void cli_table_end (struct ui_out
*uiout
);
44 static void cli_table_header (struct ui_out
*uiout
, int width
,
45 enum ui_align alig
, const char *col_name
,
47 static void cli_begin (struct ui_out
*uiout
, enum ui_out_type type
,
48 int level
, const char *lstid
);
49 static void cli_end (struct ui_out
*uiout
, enum ui_out_type type
, int level
);
50 static void cli_field_int (struct ui_out
*uiout
, int fldno
, int width
,
51 enum ui_align alig
, const char *fldname
, int value
);
52 static void cli_field_skip (struct ui_out
*uiout
, int fldno
, int width
,
53 enum ui_align alig
, const char *fldname
);
54 static void cli_field_string (struct ui_out
*uiout
, int fldno
, int width
,
55 enum ui_align alig
, const char *fldname
,
57 static void cli_field_fmt (struct ui_out
*uiout
, int fldno
,
58 int width
, enum ui_align align
,
59 const char *fldname
, const char *format
,
61 static void cli_spaces (struct ui_out
*uiout
, int numspaces
);
62 static void cli_text (struct ui_out
*uiout
, const char *string
);
63 static void cli_message (struct ui_out
*uiout
, int verbosity
,
64 const char *format
, va_list args
);
65 static void cli_wrap_hint (struct ui_out
*uiout
, char *identstring
);
66 static void cli_flush (struct ui_out
*uiout
);
68 /* This is the CLI ui-out implementation functions vector */
70 /* FIXME: This can be initialized dynamically after default is set to
71 handle initial output in main.c */
73 static struct ui_out_impl cli_ui_out_impl
=
90 0, /* Does not need MI hacks (i.e. needs CLI hacks). */
93 /* Prototypes for local functions */
95 extern void _initialize_cli_out (void);
97 static void field_separator (void);
99 static void out_field_fmt (struct ui_out
*uiout
, int fldno
,
101 const char *format
,...);
103 /* local variables */
107 /* Mark beginning of a table */
110 cli_table_begin (struct ui_out
*uiout
, int nbrofcols
,
114 cli_out_data
*data
= ui_out_data (uiout
);
116 data
->suppress_output
= 1;
118 /* Only the table suppresses the output and, fortunatly, a table
119 is not a recursive data structure. */
120 gdb_assert (data
->suppress_output
== 0);
123 /* Mark beginning of a table body */
126 cli_table_body (struct ui_out
*uiout
)
128 cli_out_data
*data
= ui_out_data (uiout
);
129 if (data
->suppress_output
)
131 /* first, close the table header line */
132 cli_text (uiout
, "\n");
135 /* Mark end of a table */
138 cli_table_end (struct ui_out
*uiout
)
140 cli_out_data
*data
= ui_out_data (uiout
);
141 data
->suppress_output
= 0;
144 /* Specify table header */
147 cli_table_header (struct ui_out
*uiout
, int width
, enum ui_align alignment
,
148 const char *col_name
,
151 cli_out_data
*data
= ui_out_data (uiout
);
152 if (data
->suppress_output
)
154 cli_field_string (uiout
, 0, width
, alignment
, 0, colhdr
);
157 /* Mark beginning of a list */
160 cli_begin (struct ui_out
*uiout
,
161 enum ui_out_type type
,
165 cli_out_data
*data
= ui_out_data (uiout
);
166 if (data
->suppress_output
)
170 /* Mark end of a list */
173 cli_end (struct ui_out
*uiout
,
174 enum ui_out_type type
,
177 cli_out_data
*data
= ui_out_data (uiout
);
178 if (data
->suppress_output
)
182 /* output an int field */
185 cli_field_int (struct ui_out
*uiout
, int fldno
, int width
,
186 enum ui_align alignment
,
187 const char *fldname
, int value
)
189 char buffer
[20]; /* FIXME: how many chars long a %d can become? */
191 cli_out_data
*data
= ui_out_data (uiout
);
192 if (data
->suppress_output
)
194 sprintf (buffer
, "%d", value
);
195 cli_field_string (uiout
, fldno
, width
, alignment
, fldname
, buffer
);
198 /* used to ommit a field */
201 cli_field_skip (struct ui_out
*uiout
, int fldno
, int width
,
202 enum ui_align alignment
,
205 cli_out_data
*data
= ui_out_data (uiout
);
206 if (data
->suppress_output
)
208 cli_field_string (uiout
, fldno
, width
, alignment
, fldname
, "");
211 /* other specific cli_field_* end up here so alignment and field
212 separators are both handled by cli_field_string */
215 cli_field_string (struct ui_out
*uiout
,
225 cli_out_data
*data
= ui_out_data (uiout
);
226 if (data
->suppress_output
)
229 if ((align
!= ui_noalign
) && string
)
231 before
= width
- strlen (string
);
236 if (align
== ui_right
)
238 else if (align
== ui_left
)
253 ui_out_spaces (uiout
, before
);
255 out_field_fmt (uiout
, fldno
, fldname
, "%s", string
);
257 ui_out_spaces (uiout
, after
);
259 if (align
!= ui_noalign
)
263 /* This is the only field function that does not align */
266 cli_field_fmt (struct ui_out
*uiout
, int fldno
,
267 int width
, enum ui_align align
,
272 cli_out_data
*data
= ui_out_data (uiout
);
273 if (data
->suppress_output
)
276 vfprintf_filtered (data
->stream
, format
, args
);
278 if (align
!= ui_noalign
)
283 cli_spaces (struct ui_out
*uiout
, int numspaces
)
285 cli_out_data
*data
= ui_out_data (uiout
);
286 if (data
->suppress_output
)
288 print_spaces_filtered (numspaces
, data
->stream
);
292 cli_text (struct ui_out
*uiout
, const char *string
)
294 cli_out_data
*data
= ui_out_data (uiout
);
295 if (data
->suppress_output
)
297 fputs_filtered (string
, data
->stream
);
301 cli_message (struct ui_out
*uiout
, int verbosity
,
302 const char *format
, va_list args
)
304 cli_out_data
*data
= ui_out_data (uiout
);
305 if (data
->suppress_output
)
307 if (ui_out_get_verblvl (uiout
) >= verbosity
)
308 vfprintf_unfiltered (data
->stream
, format
, args
);
312 cli_wrap_hint (struct ui_out
*uiout
, char *identstring
)
314 cli_out_data
*data
= ui_out_data (uiout
);
315 if (data
->suppress_output
)
317 wrap_here (identstring
);
321 cli_flush (struct ui_out
*uiout
)
323 cli_out_data
*data
= ui_out_data (uiout
);
324 gdb_flush (data
->stream
);
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
);
341 va_start (args
, format
);
342 vfprintf_filtered (data
->stream
, format
, args
);
347 /* access to ui_out format private members */
350 field_separator (void)
352 cli_out_data
*data
= ui_out_data (uiout
);
353 fputc_filtered (' ', data
->stream
);
356 /* initalize private members at startup */
359 cli_out_new (struct ui_file
*stream
)
361 int flags
= ui_source_list
;
363 cli_out_data
*data
= XMALLOC (cli_out_data
);
364 data
->stream
= stream
;
365 data
->suppress_output
= 0;
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
;
378 /* standard gdb initialization hook */
380 _initialize_cli_out (void)
382 /* nothing needs to be done */