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. */
27 /* Convenience macro for allocting typesafe memory. */
30 #define XMALLOC(TYPE) (TYPE*) xmalloc (sizeof (TYPE))
35 struct ui_file *stream;
38 /* These are the CLI output functions */
40 static void cli_table_begin (struct ui_out *uiout, int nbrofcols, 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, char *colhdr);
45 static void cli_list_begin (struct ui_out *uiout, int list_flag, char *lstid);
46 static void cli_list_end (struct ui_out *uiout, int list_flag);
47 static void cli_field_int (struct ui_out *uiout, int fldno, int width,
48 enum ui_align alig, char *fldname, int value);
49 static void cli_field_skip (struct ui_out *uiout, int fldno, int width,
50 enum ui_align alig, char *fldname);
51 static void cli_field_string (struct ui_out *uiout, int fldno, int width,
52 enum ui_align alig, char *fldname,
54 static void cli_field_fmt (struct ui_out *uiout, int fldno,
55 int width, enum ui_align align,
56 char *fldname, char *format, va_list args);
57 static void cli_spaces (struct ui_out *uiout, int numspaces);
58 static void cli_text (struct ui_out *uiout, char *string);
59 static void cli_message (struct ui_out *uiout, int verbosity, char *format,
61 static void cli_wrap_hint (struct ui_out *uiout, char *identstring);
62 static void cli_flush (struct ui_out *uiout);
64 /* This is the CLI ui-out implementation functions vector */
66 /* FIXME: This can be initialized dynamically after default is set to
67 handle initial output in main.c */
69 static struct ui_out_impl cli_ui_out_impl =
88 /* Prototypes for local functions */
90 extern void _initialize_cli_out PARAMS ((void));
92 static void field_separator (void);
94 static void out_field_fmt (struct ui_out *uiout, int fldno, char *fldname,
101 /* Mark beginning of a table */
104 cli_table_begin (uiout, nbrofcols, tblid)
105 struct ui_out *uiout;
111 /* Mark beginning of a table body */
114 cli_table_body (uiout)
115 struct ui_out *uiout;
117 /* first, close the table header line */
118 cli_text (uiout, "\n");
121 /* Mark end of a table */
124 cli_table_end (uiout)
125 struct ui_out *uiout;
129 /* Specify table header */
132 cli_table_header (uiout, width, alignment, colhdr)
133 struct ui_out *uiout;
135 enum ui_align alignment;
138 cli_field_string (uiout, 0, width, alignment, 0, colhdr);
141 /* Mark beginning of a list */
144 cli_list_begin (uiout, list_flag, lstid)
145 struct ui_out *uiout;
151 /* Mark end of a list */
154 cli_list_end (uiout, list_flag)
155 struct ui_out *uiout;
160 /* output an int field */
163 cli_field_int (uiout, fldno, width, alignment, fldname, value)
164 struct ui_out *uiout;
167 enum ui_align alignment;
171 char buffer[20]; /* FIXME: how many chars long a %d can become? */
173 sprintf (buffer, "%d", value);
174 cli_field_string (uiout, fldno, width, alignment, fldname, buffer);
177 /* used to ommit a field */
180 cli_field_skip (uiout, fldno, width, alignment, fldname)
181 struct ui_out *uiout;
184 enum ui_align alignment;
187 cli_field_string (uiout, fldno, width, alignment, fldname, "");
190 /* other specific cli_field_* end up here so alignment and field
191 separators are both handled by cli_field_string */
194 cli_field_string (struct ui_out *uiout,
204 if ((align != ui_noalign) && string)
206 before = width - strlen (string);
211 if (align == ui_right)
213 else if (align == ui_left)
228 ui_out_spaces (uiout, before);
230 out_field_fmt (uiout, fldno, fldname, "%s", string);
232 ui_out_spaces (uiout, after);
234 if (align != ui_noalign)
238 /* This is the only field function that does not align */
241 cli_field_fmt (struct ui_out *uiout, int fldno,
242 int width, enum ui_align align,
243 char *fldname, char *format, va_list args)
245 struct ui_out_data *data = ui_out_data (uiout);
246 vfprintf_filtered (data->stream, format, args);
248 if (align != ui_noalign)
253 cli_spaces (uiout, numspaces)
254 struct ui_out *uiout;
257 struct ui_out_data *data = ui_out_data (uiout);
258 print_spaces_filtered (numspaces, data->stream);
262 cli_text (uiout, string)
263 struct ui_out *uiout;
266 struct ui_out_data *data = ui_out_data (uiout);
267 fputs_filtered (string, data->stream);
271 cli_message (struct ui_out *uiout, int verbosity, char *format, va_list args)
273 struct ui_out_data *data = ui_out_data (uiout);
274 if (ui_out_get_verblvl (uiout) >= verbosity)
275 vfprintf_unfiltered (data->stream, format, args);
279 cli_wrap_hint (uiout, identstring)
280 struct ui_out *uiout;
283 wrap_here (identstring);
288 struct ui_out *uiout;
290 struct ui_out_data *data = ui_out_data (uiout);
291 gdb_flush (data->stream);
294 /* local functions */
296 /* Like cli_field_fmt, but takes a variable number of args
297 and makes a va_list and does not insert a separator */
301 out_field_fmt (struct ui_out *uiout, int fldno, char *fldname,
304 struct ui_out_data *data = ui_out_data (uiout);
307 va_start (args, format);
308 vfprintf_filtered (data->stream, format, args);
313 /* access to ui_out format private members */
318 struct ui_out_data *data = ui_out_data (uiout);
319 fputc_filtered (' ', data->stream);
322 /* initalize private members at startup */
325 cli_out_new (struct ui_file *stream)
327 int flags = ui_source_list;
329 struct ui_out_data *data = XMALLOC (struct ui_out_data);
330 data->stream = stream;
331 return ui_out_new (&cli_ui_out_impl, data, flags);
334 /* standard gdb initialization hook */
336 _initialize_cli_out ()
338 /* nothing needs to be done */