1 /* Output generating routines for GDB CLI.
3 Copyright (C) 1999, 2000, 2001, 2002, 2003, 2005
4 Free Software Foundation, Inc.
6 Contributed by Cygnus Solutions.
7 Written by Fernando Nasser for Cygnus.
9 This file is part of GDB.
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 Boston, MA 02110-1301, USA. */
29 #include "gdb_string.h"
30 #include "gdb_assert.h"
34 struct ui_file
*stream
;
39 typedef struct ui_out_data tui_out_data
;
41 /* These are the CLI output functions */
43 static void tui_table_begin (struct ui_out
*uiout
, int nbrofcols
,
44 int nr_rows
, const char *tblid
);
45 static void tui_table_body (struct ui_out
*uiout
);
46 static void tui_table_end (struct ui_out
*uiout
);
47 static void tui_table_header (struct ui_out
*uiout
, int width
,
48 enum ui_align alig
, const char *col_name
,
50 static void tui_begin (struct ui_out
*uiout
, enum ui_out_type type
,
51 int level
, const char *lstid
);
52 static void tui_end (struct ui_out
*uiout
, enum ui_out_type type
, int level
);
53 static void tui_field_int (struct ui_out
*uiout
, int fldno
, int width
,
54 enum ui_align alig
, const char *fldname
, int value
);
55 static void tui_field_skip (struct ui_out
*uiout
, int fldno
, int width
,
56 enum ui_align alig
, const char *fldname
);
57 static void tui_field_string (struct ui_out
*uiout
, int fldno
, int width
,
58 enum ui_align alig
, const char *fldname
,
60 static void tui_field_fmt (struct ui_out
*uiout
, int fldno
,
61 int width
, enum ui_align align
,
62 const char *fldname
, const char *format
,
63 va_list args
) ATTR_FORMAT (printf
, 6, 0);
64 static void tui_spaces (struct ui_out
*uiout
, int numspaces
);
65 static void tui_text (struct ui_out
*uiout
, const char *string
);
66 static void tui_message (struct ui_out
*uiout
, int verbosity
,
67 const char *format
, va_list args
)
68 ATTR_FORMAT (printf
, 3, 0);
69 static void tui_wrap_hint (struct ui_out
*uiout
, char *identstring
);
70 static void tui_flush (struct ui_out
*uiout
);
72 /* This is the CLI ui-out implementation functions vector */
74 /* FIXME: This can be initialized dynamically after default is set to
75 handle initial output in main.c */
77 static struct ui_out_impl tui_ui_out_impl
=
95 0, /* Does not need MI hacks (i.e. needs CLI hacks). */
98 /* Prototypes for local functions */
100 extern void _initialize_tui_out (void);
102 static void field_separator (void);
104 static void out_field_fmt (struct ui_out
*uiout
, int fldno
,
106 const char *format
,...) ATTR_FORMAT (printf
, 4, 5);
108 /* local variables */
112 /* Mark beginning of a table */
115 tui_table_begin (struct ui_out
*uiout
, int nbrofcols
,
119 tui_out_data
*data
= ui_out_data (uiout
);
121 data
->suppress_output
= 1;
123 /* Only the table suppresses the output and, fortunately, a table
124 is not a recursive data structure. */
125 gdb_assert (data
->suppress_output
== 0);
128 /* Mark beginning of a table body */
131 tui_table_body (struct ui_out
*uiout
)
133 tui_out_data
*data
= ui_out_data (uiout
);
134 if (data
->suppress_output
)
136 /* first, close the table header line */
137 tui_text (uiout
, "\n");
140 /* Mark end of a table */
143 tui_table_end (struct ui_out
*uiout
)
145 tui_out_data
*data
= ui_out_data (uiout
);
146 data
->suppress_output
= 0;
149 /* Specify table header */
152 tui_table_header (struct ui_out
*uiout
, int width
, enum ui_align alignment
,
153 const char *col_name
,
156 tui_out_data
*data
= ui_out_data (uiout
);
157 if (data
->suppress_output
)
159 tui_field_string (uiout
, 0, width
, alignment
, 0, colhdr
);
162 /* Mark beginning of a list */
165 tui_begin (struct ui_out
*uiout
,
166 enum ui_out_type type
,
170 tui_out_data
*data
= ui_out_data (uiout
);
171 if (data
->suppress_output
)
175 /* Mark end of a list */
178 tui_end (struct ui_out
*uiout
,
179 enum ui_out_type type
,
182 tui_out_data
*data
= ui_out_data (uiout
);
183 if (data
->suppress_output
)
187 /* output an int field */
190 tui_field_int (struct ui_out
*uiout
, int fldno
, int width
,
191 enum ui_align alignment
,
192 const char *fldname
, int value
)
194 char buffer
[20]; /* FIXME: how many chars long a %d can become? */
196 tui_out_data
*data
= ui_out_data (uiout
);
197 if (data
->suppress_output
)
200 /* Don't print line number, keep it for later. */
201 if (data
->start_of_line
== 0 && strcmp (fldname
, "line") == 0)
203 data
->start_of_line
++;
207 data
->start_of_line
++;
208 sprintf (buffer
, "%d", value
);
209 tui_field_string (uiout
, fldno
, width
, alignment
, fldname
, buffer
);
212 /* used to ommit a field */
215 tui_field_skip (struct ui_out
*uiout
, int fldno
, int width
,
216 enum ui_align alignment
,
219 tui_out_data
*data
= ui_out_data (uiout
);
220 if (data
->suppress_output
)
222 tui_field_string (uiout
, fldno
, width
, alignment
, fldname
, "");
225 /* other specific tui_field_* end up here so alignment and field
226 separators are both handled by tui_field_string */
229 tui_field_string (struct ui_out
*uiout
,
239 tui_out_data
*data
= ui_out_data (uiout
);
240 if (data
->suppress_output
)
243 if (fldname
&& data
->line
> 0 && strcmp (fldname
, "file") == 0)
245 data
->start_of_line
++;
248 tui_show_source (string
, data
->line
);
253 data
->start_of_line
++;
254 if ((align
!= ui_noalign
) && string
)
256 before
= width
- strlen (string
);
261 if (align
== ui_right
)
263 else if (align
== ui_left
)
278 ui_out_spaces (uiout
, before
);
280 out_field_fmt (uiout
, fldno
, fldname
, "%s", string
);
282 ui_out_spaces (uiout
, after
);
284 if (align
!= ui_noalign
)
288 /* This is the only field function that does not align */
291 tui_field_fmt (struct ui_out
*uiout
, int fldno
,
292 int width
, enum ui_align align
,
297 tui_out_data
*data
= ui_out_data (uiout
);
298 if (data
->suppress_output
)
301 data
->start_of_line
++;
302 vfprintf_filtered (data
->stream
, format
, args
);
304 if (align
!= ui_noalign
)
309 tui_spaces (struct ui_out
*uiout
, int numspaces
)
311 tui_out_data
*data
= ui_out_data (uiout
);
312 if (data
->suppress_output
)
314 print_spaces_filtered (numspaces
, data
->stream
);
318 tui_text (struct ui_out
*uiout
, const char *string
)
320 tui_out_data
*data
= ui_out_data (uiout
);
321 if (data
->suppress_output
)
323 data
->start_of_line
++;
326 if (strchr (string
, '\n') != 0)
329 data
->start_of_line
= 0;
333 if (strchr (string
, '\n'))
334 data
->start_of_line
= 0;
335 fputs_filtered (string
, data
->stream
);
339 tui_message (struct ui_out
*uiout
, int verbosity
,
340 const char *format
, va_list args
)
342 tui_out_data
*data
= ui_out_data (uiout
);
343 if (data
->suppress_output
)
345 if (ui_out_get_verblvl (uiout
) >= verbosity
)
346 vfprintf_unfiltered (data
->stream
, format
, args
);
350 tui_wrap_hint (struct ui_out
*uiout
, char *identstring
)
352 tui_out_data
*data
= ui_out_data (uiout
);
353 if (data
->suppress_output
)
355 wrap_here (identstring
);
359 tui_flush (struct ui_out
*uiout
)
361 tui_out_data
*data
= ui_out_data (uiout
);
362 gdb_flush (data
->stream
);
365 /* local functions */
367 /* Like tui_field_fmt, but takes a variable number of args
368 and makes a va_list and does not insert a separator */
372 out_field_fmt (struct ui_out
*uiout
, int fldno
,
374 const char *format
,...)
376 tui_out_data
*data
= ui_out_data (uiout
);
379 va_start (args
, format
);
380 vfprintf_filtered (data
->stream
, format
, args
);
385 /* access to ui_out format private members */
388 field_separator (void)
390 tui_out_data
*data
= ui_out_data (uiout
);
391 fputc_filtered (' ', data
->stream
);
394 /* initalize private members at startup */
397 tui_out_new (struct ui_file
*stream
)
401 tui_out_data
*data
= XMALLOC (tui_out_data
);
402 data
->stream
= stream
;
403 data
->suppress_output
= 0;
405 data
->start_of_line
= 0;
406 return ui_out_new (&tui_ui_out_impl
, data
, flags
);
409 /* standard gdb initialization hook */
411 _initialize_tui_out (void)
413 /* nothing needs to be done */