1 /* Output generating routines for GDB CLI.
2 Copyright 1999, 2000 Free Software Foundation, Inc.
3 Contributed by Cygnus Solutions.
4 Written by Fernando Nasser for Cygnus.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
26 #include "gdb_string.h"
27 #include "gdb_assert.h"
29 /* Convenience macro for allocting typesafe memory. */
32 #define XMALLOC(TYPE) (TYPE*) xmalloc (sizeof (TYPE))
37 struct ui_file
*stream
;
41 /* These are the CLI output functions */
43 static void cli_table_begin (struct ui_out
*uiout
, int nbrofcols
,
44 int nr_rows
, const char *tblid
);
45 static void cli_table_body (struct ui_out
*uiout
);
46 static void cli_table_end (struct ui_out
*uiout
);
47 static void cli_table_header (struct ui_out
*uiout
, int width
,
50 static void cli_begin (struct ui_out
*uiout
, enum ui_out_type type
,
51 int level
, const char *lstid
);
52 static void cli_end (struct ui_out
*uiout
, enum ui_out_type type
, int level
);
53 static void cli_field_int (struct ui_out
*uiout
, int fldno
, int width
,
54 enum ui_align alig
, const char *fldname
, int value
);
55 static void cli_field_skip (struct ui_out
*uiout
, int fldno
, int width
,
56 enum ui_align alig
, const char *fldname
);
57 static void cli_field_string (struct ui_out
*uiout
, int fldno
, int width
,
58 enum ui_align alig
, const char *fldname
,
60 static void cli_field_fmt (struct ui_out
*uiout
, int fldno
,
61 int width
, enum ui_align align
,
62 const char *fldname
, const char *format
,
64 static void cli_spaces (struct ui_out
*uiout
, int numspaces
);
65 static void cli_text (struct ui_out
*uiout
, const char *string
);
66 static void cli_message (struct ui_out
*uiout
, int verbosity
,
67 const char *format
, va_list args
);
68 static void cli_wrap_hint (struct ui_out
*uiout
, char *identstring
);
69 static void cli_flush (struct ui_out
*uiout
);
71 /* This is the CLI ui-out implementation functions vector */
73 /* FIXME: This can be initialized dynamically after default is set to
74 handle initial output in main.c */
76 static struct ui_out_impl cli_ui_out_impl
=
95 /* Prototypes for local functions */
97 extern void _initialize_cli_out (void);
99 static void field_separator (void);
101 static void out_field_fmt (struct ui_out
*uiout
, int fldno
,
103 const char *format
,...);
105 /* local variables */
109 /* Mark beginning of a table */
112 cli_table_begin (struct ui_out
*uiout
, int nbrofcols
,
116 struct ui_out_data
*data
= ui_out_data (uiout
);
118 data
->suppress_output
= 1;
120 /* Only the table suppresses the output and, fortunatly, a table
121 is not a recursive data structure. */
122 gdb_assert (data
->suppress_output
== 0);
125 /* Mark beginning of a table body */
128 cli_table_body (struct ui_out
*uiout
)
130 struct ui_out_data
*data
= ui_out_data (uiout
);
131 if (data
->suppress_output
)
133 /* first, close the table header line */
134 cli_text (uiout
, "\n");
137 /* Mark end of a table */
140 cli_table_end (struct ui_out
*uiout
)
142 struct ui_out_data
*data
= ui_out_data (uiout
);
143 data
->suppress_output
= 0;
146 /* Specify table header */
149 cli_table_header (struct ui_out
*uiout
, int width
, enum ui_align alignment
,
152 struct ui_out_data
*data
= ui_out_data (uiout
);
153 if (data
->suppress_output
)
155 cli_field_string (uiout
, 0, width
, alignment
, 0, colhdr
);
158 /* Mark beginning of a list */
161 cli_begin (struct ui_out
*uiout
,
162 enum ui_out_type type
,
166 struct ui_out_data
*data
= ui_out_data (uiout
);
167 if (data
->suppress_output
)
171 /* Mark end of a list */
174 cli_end (struct ui_out
*uiout
,
175 enum ui_out_type type
,
178 struct ui_out_data
*data
= ui_out_data (uiout
);
179 if (data
->suppress_output
)
183 /* output an int field */
186 cli_field_int (struct ui_out
*uiout
, int fldno
, int width
,
187 enum ui_align alignment
,
188 const char *fldname
, int value
)
190 char buffer
[20]; /* FIXME: how many chars long a %d can become? */
192 struct ui_out_data
*data
= ui_out_data (uiout
);
193 if (data
->suppress_output
)
195 sprintf (buffer
, "%d", value
);
196 cli_field_string (uiout
, fldno
, width
, alignment
, fldname
, buffer
);
199 /* used to ommit a field */
202 cli_field_skip (struct ui_out
*uiout
, int fldno
, int width
,
203 enum ui_align alignment
,
206 struct ui_out_data
*data
= ui_out_data (uiout
);
207 if (data
->suppress_output
)
209 cli_field_string (uiout
, fldno
, width
, alignment
, fldname
, "");
212 /* other specific cli_field_* end up here so alignment and field
213 separators are both handled by cli_field_string */
216 cli_field_string (struct ui_out
*uiout
,
226 struct ui_out_data
*data
= ui_out_data (uiout
);
227 if (data
->suppress_output
)
230 if ((align
!= ui_noalign
) && string
)
232 before
= width
- strlen (string
);
237 if (align
== ui_right
)
239 else if (align
== ui_left
)
254 ui_out_spaces (uiout
, before
);
256 out_field_fmt (uiout
, fldno
, fldname
, "%s", string
);
258 ui_out_spaces (uiout
, after
);
260 if (align
!= ui_noalign
)
264 /* This is the only field function that does not align */
267 cli_field_fmt (struct ui_out
*uiout
, int fldno
,
268 int width
, enum ui_align align
,
273 struct ui_out_data
*data
= ui_out_data (uiout
);
274 if (data
->suppress_output
)
277 vfprintf_filtered (data
->stream
, format
, args
);
279 if (align
!= ui_noalign
)
284 cli_spaces (struct ui_out
*uiout
, int numspaces
)
286 struct ui_out_data
*data
= ui_out_data (uiout
);
287 if (data
->suppress_output
)
289 print_spaces_filtered (numspaces
, data
->stream
);
293 cli_text (struct ui_out
*uiout
, const char *string
)
295 struct ui_out_data
*data
= ui_out_data (uiout
);
296 if (data
->suppress_output
)
298 fputs_filtered (string
, data
->stream
);
302 cli_message (struct ui_out
*uiout
, int verbosity
,
303 const char *format
, va_list args
)
305 struct ui_out_data
*data
= ui_out_data (uiout
);
306 if (data
->suppress_output
)
308 if (ui_out_get_verblvl (uiout
) >= verbosity
)
309 vfprintf_unfiltered (data
->stream
, format
, args
);
313 cli_wrap_hint (struct ui_out
*uiout
, char *identstring
)
315 struct ui_out_data
*data
= ui_out_data (uiout
);
316 if (data
->suppress_output
)
318 wrap_here (identstring
);
322 cli_flush (struct ui_out
*uiout
)
324 struct ui_out_data
*data
= ui_out_data (uiout
);
325 gdb_flush (data
->stream
);
328 /* local functions */
330 /* Like cli_field_fmt, but takes a variable number of args
331 and makes a va_list and does not insert a separator */
335 out_field_fmt (struct ui_out
*uiout
, int fldno
,
337 const char *format
,...)
339 struct ui_out_data
*data
= ui_out_data (uiout
);
342 va_start (args
, format
);
343 vfprintf_filtered (data
->stream
, format
, args
);
348 /* access to ui_out format private members */
351 field_separator (void)
353 struct ui_out_data
*data
= ui_out_data (uiout
);
354 fputc_filtered (' ', data
->stream
);
357 /* initalize private members at startup */
360 cli_out_new (struct ui_file
*stream
)
362 int flags
= ui_source_list
;
364 struct ui_out_data
*data
= XMALLOC (struct ui_out_data
);
365 data
->stream
= stream
;
366 return ui_out_new (&cli_ui_out_impl
, data
, flags
);
369 /* standard gdb initialization hook */
371 _initialize_cli_out (void)
373 /* nothing needs to be done */