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"
28 /* Convenience macro for allocting typesafe memory. */
31 #define XMALLOC(TYPE) (TYPE*) xmalloc (sizeof (TYPE))
36 struct ui_file
*stream
;
39 /* These are the CLI output functions */
41 static void cli_table_begin (struct ui_out
*uiout
, int nbrofcols
, 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
, char *colhdr
);
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
, char *fldname
, int value
);
51 static void cli_field_skip (struct ui_out
*uiout
, int fldno
, int width
,
52 enum ui_align alig
, char *fldname
);
53 static void cli_field_string (struct ui_out
*uiout
, int fldno
, int width
,
54 enum ui_align alig
, char *fldname
,
56 static void cli_field_fmt (struct ui_out
*uiout
, int fldno
,
57 int width
, enum ui_align align
,
58 char *fldname
, char *format
, va_list args
);
59 static void cli_spaces (struct ui_out
*uiout
, int numspaces
);
60 static void cli_text (struct ui_out
*uiout
, char *string
);
61 static void cli_message (struct ui_out
*uiout
, int verbosity
, char *format
,
63 static void cli_wrap_hint (struct ui_out
*uiout
, char *identstring
);
64 static void cli_flush (struct ui_out
*uiout
);
66 /* This is the CLI ui-out implementation functions vector */
68 /* FIXME: This can be initialized dynamically after default is set to
69 handle initial output in main.c */
71 static struct ui_out_impl cli_ui_out_impl
=
90 /* Prototypes for local functions */
92 extern void _initialize_cli_out (void);
94 static void field_separator (void);
96 static void out_field_fmt (struct ui_out
*uiout
, int fldno
, char *fldname
,
103 /* Mark beginning of a table */
106 cli_table_begin (struct ui_out
*uiout
, int nbrofcols
, char *tblid
)
110 /* Mark beginning of a table body */
113 cli_table_body (struct ui_out
*uiout
)
115 /* first, close the table header line */
116 cli_text (uiout
, "\n");
119 /* Mark end of a table */
122 cli_table_end (struct ui_out
*uiout
)
126 /* Specify table header */
129 cli_table_header (struct ui_out
*uiout
, int width
, enum ui_align alignment
,
132 cli_field_string (uiout
, 0, width
, alignment
, 0, colhdr
);
135 /* Mark beginning of a list */
138 cli_begin (struct ui_out
*uiout
,
139 enum ui_out_type type
,
145 /* Mark end of a list */
148 cli_end (struct ui_out
*uiout
,
149 enum ui_out_type type
,
154 /* output an int field */
157 cli_field_int (struct ui_out
*uiout
, int fldno
, int width
,
158 enum ui_align alignment
, char *fldname
, int value
)
160 char buffer
[20]; /* FIXME: how many chars long a %d can become? */
162 sprintf (buffer
, "%d", value
);
163 cli_field_string (uiout
, fldno
, width
, alignment
, fldname
, buffer
);
166 /* used to ommit a field */
169 cli_field_skip (struct ui_out
*uiout
, int fldno
, int width
,
170 enum ui_align alignment
, char *fldname
)
172 cli_field_string (uiout
, fldno
, width
, alignment
, fldname
, "");
175 /* other specific cli_field_* end up here so alignment and field
176 separators are both handled by cli_field_string */
179 cli_field_string (struct ui_out
*uiout
,
189 if ((align
!= ui_noalign
) && string
)
191 before
= width
- strlen (string
);
196 if (align
== ui_right
)
198 else if (align
== ui_left
)
213 ui_out_spaces (uiout
, before
);
215 out_field_fmt (uiout
, fldno
, fldname
, "%s", string
);
217 ui_out_spaces (uiout
, after
);
219 if (align
!= ui_noalign
)
223 /* This is the only field function that does not align */
226 cli_field_fmt (struct ui_out
*uiout
, int fldno
,
227 int width
, enum ui_align align
,
228 char *fldname
, char *format
, va_list args
)
230 struct ui_out_data
*data
= ui_out_data (uiout
);
231 vfprintf_filtered (data
->stream
, format
, args
);
233 if (align
!= ui_noalign
)
238 cli_spaces (struct ui_out
*uiout
, int numspaces
)
240 struct ui_out_data
*data
= ui_out_data (uiout
);
241 print_spaces_filtered (numspaces
, data
->stream
);
245 cli_text (struct ui_out
*uiout
, char *string
)
247 struct ui_out_data
*data
= ui_out_data (uiout
);
248 fputs_filtered (string
, data
->stream
);
252 cli_message (struct ui_out
*uiout
, int verbosity
, char *format
, va_list args
)
254 struct ui_out_data
*data
= ui_out_data (uiout
);
255 if (ui_out_get_verblvl (uiout
) >= verbosity
)
256 vfprintf_unfiltered (data
->stream
, format
, args
);
260 cli_wrap_hint (struct ui_out
*uiout
, char *identstring
)
262 wrap_here (identstring
);
266 cli_flush (struct ui_out
*uiout
)
268 struct ui_out_data
*data
= ui_out_data (uiout
);
269 gdb_flush (data
->stream
);
272 /* local functions */
274 /* Like cli_field_fmt, but takes a variable number of args
275 and makes a va_list and does not insert a separator */
279 out_field_fmt (struct ui_out
*uiout
, int fldno
, char *fldname
,
282 struct ui_out_data
*data
= ui_out_data (uiout
);
285 va_start (args
, format
);
286 vfprintf_filtered (data
->stream
, format
, args
);
291 /* access to ui_out format private members */
294 field_separator (void)
296 struct ui_out_data
*data
= ui_out_data (uiout
);
297 fputc_filtered (' ', data
->stream
);
300 /* initalize private members at startup */
303 cli_out_new (struct ui_file
*stream
)
305 int flags
= ui_source_list
;
307 struct ui_out_data
*data
= XMALLOC (struct ui_out_data
);
308 data
->stream
= stream
;
309 return ui_out_new (&cli_ui_out_impl
, data
, flags
);
312 /* standard gdb initialization hook */
314 _initialize_cli_out (void)
316 /* nothing needs to be done */