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
,
43 static void cli_table_body (struct ui_out
*uiout
);
44 static void cli_table_end (struct ui_out
*uiout
);
45 static void cli_table_header (struct ui_out
*uiout
, int width
,
48 static void cli_begin (struct ui_out
*uiout
, enum ui_out_type type
,
49 int level
, const char *lstid
);
50 static void cli_end (struct ui_out
*uiout
, enum ui_out_type type
, int level
);
51 static void cli_field_int (struct ui_out
*uiout
, int fldno
, int width
,
52 enum ui_align alig
, const char *fldname
, int value
);
53 static void cli_field_skip (struct ui_out
*uiout
, int fldno
, int width
,
54 enum ui_align alig
, const char *fldname
);
55 static void cli_field_string (struct ui_out
*uiout
, int fldno
, int width
,
56 enum ui_align alig
, const char *fldname
,
58 static void cli_field_fmt (struct ui_out
*uiout
, int fldno
,
59 int width
, enum ui_align align
,
60 const char *fldname
, const char *format
,
62 static void cli_spaces (struct ui_out
*uiout
, int numspaces
);
63 static void cli_text (struct ui_out
*uiout
, const char *string
);
64 static void cli_message (struct ui_out
*uiout
, int verbosity
,
65 const char *format
, va_list args
);
66 static void cli_wrap_hint (struct ui_out
*uiout
, char *identstring
);
67 static void cli_flush (struct ui_out
*uiout
);
69 /* This is the CLI ui-out implementation functions vector */
71 /* FIXME: This can be initialized dynamically after default is set to
72 handle initial output in main.c */
74 static struct ui_out_impl cli_ui_out_impl
=
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
,
115 /* Mark beginning of a table body */
118 cli_table_body (struct ui_out
*uiout
)
120 /* first, close the table header line */
121 cli_text (uiout
, "\n");
124 /* Mark end of a table */
127 cli_table_end (struct ui_out
*uiout
)
131 /* Specify table header */
134 cli_table_header (struct ui_out
*uiout
, int width
, enum ui_align alignment
,
137 cli_field_string (uiout
, 0, width
, alignment
, 0, colhdr
);
140 /* Mark beginning of a list */
143 cli_begin (struct ui_out
*uiout
,
144 enum ui_out_type type
,
150 /* Mark end of a list */
153 cli_end (struct ui_out
*uiout
,
154 enum ui_out_type type
,
159 /* output an int field */
162 cli_field_int (struct ui_out
*uiout
, int fldno
, int width
,
163 enum ui_align alignment
,
164 const char *fldname
, int value
)
166 char buffer
[20]; /* FIXME: how many chars long a %d can become? */
168 sprintf (buffer
, "%d", value
);
169 cli_field_string (uiout
, fldno
, width
, alignment
, fldname
, buffer
);
172 /* used to ommit a field */
175 cli_field_skip (struct ui_out
*uiout
, int fldno
, int width
,
176 enum ui_align alignment
,
179 cli_field_string (uiout
, fldno
, width
, alignment
, fldname
, "");
182 /* other specific cli_field_* end up here so alignment and field
183 separators are both handled by cli_field_string */
186 cli_field_string (struct ui_out
*uiout
,
196 if ((align
!= ui_noalign
) && string
)
198 before
= width
- strlen (string
);
203 if (align
== ui_right
)
205 else if (align
== ui_left
)
220 ui_out_spaces (uiout
, before
);
222 out_field_fmt (uiout
, fldno
, fldname
, "%s", string
);
224 ui_out_spaces (uiout
, after
);
226 if (align
!= ui_noalign
)
230 /* This is the only field function that does not align */
233 cli_field_fmt (struct ui_out
*uiout
, int fldno
,
234 int width
, enum ui_align align
,
239 struct ui_out_data
*data
= ui_out_data (uiout
);
240 vfprintf_filtered (data
->stream
, format
, args
);
242 if (align
!= ui_noalign
)
247 cli_spaces (struct ui_out
*uiout
, int numspaces
)
249 struct ui_out_data
*data
= ui_out_data (uiout
);
250 print_spaces_filtered (numspaces
, data
->stream
);
254 cli_text (struct ui_out
*uiout
, const char *string
)
256 struct ui_out_data
*data
= ui_out_data (uiout
);
257 fputs_filtered (string
, data
->stream
);
261 cli_message (struct ui_out
*uiout
, int verbosity
,
262 const char *format
, va_list args
)
264 struct ui_out_data
*data
= ui_out_data (uiout
);
265 if (ui_out_get_verblvl (uiout
) >= verbosity
)
266 vfprintf_unfiltered (data
->stream
, format
, args
);
270 cli_wrap_hint (struct ui_out
*uiout
, char *identstring
)
272 wrap_here (identstring
);
276 cli_flush (struct ui_out
*uiout
)
278 struct ui_out_data
*data
= ui_out_data (uiout
);
279 gdb_flush (data
->stream
);
282 /* local functions */
284 /* Like cli_field_fmt, but takes a variable number of args
285 and makes a va_list and does not insert a separator */
289 out_field_fmt (struct ui_out
*uiout
, int fldno
,
291 const char *format
,...)
293 struct ui_out_data
*data
= ui_out_data (uiout
);
296 va_start (args
, format
);
297 vfprintf_filtered (data
->stream
, format
, args
);
302 /* access to ui_out format private members */
305 field_separator (void)
307 struct ui_out_data
*data
= ui_out_data (uiout
);
308 fputc_filtered (' ', data
->stream
);
311 /* initalize private members at startup */
314 cli_out_new (struct ui_file
*stream
)
316 int flags
= ui_source_list
;
318 struct ui_out_data
*data
= XMALLOC (struct ui_out_data
);
319 data
->stream
= stream
;
320 return ui_out_new (&cli_ui_out_impl
, data
, flags
);
323 /* standard gdb initialization hook */
325 _initialize_cli_out (void)
327 /* nothing needs to be done */