1 /* Output generating routines for GDB CLI.
3 Copyright (C) 1999, 2000, 2001, 2002, 2003, 2005, 2007, 2008, 2009
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 3 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, see <http://www.gnu.org/licenses/>. */
27 #include "gdb_string.h"
28 #include "gdb_assert.h"
32 struct ui_file
*stream
;
37 typedef struct ui_out_data tui_out_data
;
39 /* These are the CLI output functions. */
41 static void tui_table_begin (struct ui_out
*uiout
,
42 int nbrofcols
, int nr_rows
,
44 static void tui_table_body (struct ui_out
*uiout
);
45 static void tui_table_end (struct ui_out
*uiout
);
46 static void tui_table_header (struct ui_out
*uiout
,
47 int width
, enum ui_align alig
,
50 static void tui_begin (struct ui_out
*uiout
,
51 enum ui_out_type type
,
52 int level
, const char *lstid
);
53 static void tui_end (struct ui_out
*uiout
,
54 enum ui_out_type type
, int level
);
55 static void tui_field_int (struct ui_out
*uiout
,
58 const char *fldname
, int value
);
59 static void tui_field_skip (struct ui_out
*uiout
,
63 static void tui_field_string (struct ui_out
*uiout
,
68 static void tui_field_fmt (struct ui_out
*uiout
, int fldno
,
69 int width
, enum ui_align align
,
73 ATTR_FORMAT (printf
, 6, 0);
74 static void tui_spaces (struct ui_out
*uiout
, int numspaces
);
75 static void tui_text (struct ui_out
*uiout
, const char *string
);
76 static void tui_message (struct ui_out
*uiout
, int verbosity
,
77 const char *format
, va_list args
)
78 ATTR_FORMAT (printf
, 3, 0);
79 static void tui_wrap_hint (struct ui_out
*uiout
,
81 static void tui_flush (struct ui_out
*uiout
);
83 /* This is the CLI ui-out implementation functions vector. */
85 /* FIXME: This can be initialized dynamically after default is set to
86 handle initial output in main.c. */
88 static struct ui_out_impl tui_ui_out_impl
= {
105 0, /* Does not need MI hacks (i.e. needs CLI hacks). */
108 /* Prototypes for local functions. */
110 extern void _initialize_tui_out (void);
112 static void field_separator (void);
114 static void out_field_fmt (struct ui_out
*uiout
,
117 const char *format
,...)
118 ATTR_FORMAT (printf
, 4, 5);
120 /* local variables */
124 /* Mark beginning of a table. */
127 tui_table_begin (struct ui_out
*uiout
,
132 tui_out_data
*data
= ui_out_data (uiout
);
134 data
->suppress_output
= 1;
136 /* Only the table suppresses the output and, fortunately, a table
137 is not a recursive data structure. */
138 gdb_assert (data
->suppress_output
== 0);
141 /* Mark beginning of a table body. */
144 tui_table_body (struct ui_out
*uiout
)
146 tui_out_data
*data
= ui_out_data (uiout
);
147 if (data
->suppress_output
)
149 /* First, close the table header line. */
150 tui_text (uiout
, "\n");
153 /* Mark end of a table. */
156 tui_table_end (struct ui_out
*uiout
)
158 tui_out_data
*data
= ui_out_data (uiout
);
159 data
->suppress_output
= 0;
162 /* Specify table header. */
165 tui_table_header (struct ui_out
*uiout
,
167 enum ui_align alignment
,
168 const char *col_name
,
171 tui_out_data
*data
= ui_out_data (uiout
);
172 if (data
->suppress_output
)
174 tui_field_string (uiout
, 0, width
, alignment
, 0, colhdr
);
177 /* Mark beginning of a list. */
180 tui_begin (struct ui_out
*uiout
,
181 enum ui_out_type type
,
185 tui_out_data
*data
= ui_out_data (uiout
);
186 if (data
->suppress_output
)
190 /* Mark end of a list. */
193 tui_end (struct ui_out
*uiout
,
194 enum ui_out_type type
,
197 tui_out_data
*data
= ui_out_data (uiout
);
198 if (data
->suppress_output
)
202 /* Output an int field. */
205 tui_field_int (struct ui_out
*uiout
,
206 int fldno
, int width
,
207 enum ui_align alignment
,
211 char buffer
[20]; /* FIXME: how many chars long a %d can become? */
213 tui_out_data
*data
= ui_out_data (uiout
);
214 if (data
->suppress_output
)
217 /* Don't print line number, keep it for later. */
218 if (data
->start_of_line
== 0 && strcmp (fldname
, "line") == 0)
220 data
->start_of_line
++;
224 data
->start_of_line
++;
225 sprintf (buffer
, "%d", value
);
226 tui_field_string (uiout
, fldno
, width
, alignment
, fldname
, buffer
);
229 /* Used to ommit a field. */
232 tui_field_skip (struct ui_out
*uiout
,
233 int fldno
, int width
,
234 enum ui_align alignment
,
237 tui_out_data
*data
= ui_out_data (uiout
);
238 if (data
->suppress_output
)
240 tui_field_string (uiout
, fldno
, width
, alignment
, fldname
, "");
243 /* Other specific tui_field_* end up here so alignment and field
244 separators are both handled by tui_field_string. */
247 tui_field_string (struct ui_out
*uiout
,
248 int fldno
, int width
,
256 tui_out_data
*data
= ui_out_data (uiout
);
257 if (data
->suppress_output
)
260 if (fldname
&& data
->line
> 0 && strcmp (fldname
, "file") == 0)
262 data
->start_of_line
++;
265 tui_show_source (string
, data
->line
);
270 data
->start_of_line
++;
271 if ((align
!= ui_noalign
) && string
)
273 before
= width
- strlen (string
);
278 if (align
== ui_right
)
280 else if (align
== ui_left
)
295 ui_out_spaces (uiout
, before
);
297 out_field_fmt (uiout
, fldno
, fldname
, "%s", string
);
299 ui_out_spaces (uiout
, after
);
301 if (align
!= ui_noalign
)
305 /* This is the only field function that does not align. */
308 tui_field_fmt (struct ui_out
*uiout
, int fldno
,
309 int width
, enum ui_align align
,
314 tui_out_data
*data
= ui_out_data (uiout
);
315 if (data
->suppress_output
)
318 data
->start_of_line
++;
319 vfprintf_filtered (data
->stream
, format
, args
);
321 if (align
!= ui_noalign
)
326 tui_spaces (struct ui_out
*uiout
, int numspaces
)
328 tui_out_data
*data
= ui_out_data (uiout
);
329 if (data
->suppress_output
)
331 print_spaces_filtered (numspaces
, data
->stream
);
335 tui_text (struct ui_out
*uiout
, const char *string
)
337 tui_out_data
*data
= ui_out_data (uiout
);
338 if (data
->suppress_output
)
340 data
->start_of_line
++;
343 if (strchr (string
, '\n') != 0)
346 data
->start_of_line
= 0;
350 if (strchr (string
, '\n'))
351 data
->start_of_line
= 0;
352 fputs_filtered (string
, data
->stream
);
356 tui_message (struct ui_out
*uiout
,
361 tui_out_data
*data
= ui_out_data (uiout
);
362 if (data
->suppress_output
)
364 if (ui_out_get_verblvl (uiout
) >= verbosity
)
365 vfprintf_unfiltered (data
->stream
, format
, args
);
369 tui_wrap_hint (struct ui_out
*uiout
, char *identstring
)
371 tui_out_data
*data
= ui_out_data (uiout
);
372 if (data
->suppress_output
)
374 wrap_here (identstring
);
378 tui_flush (struct ui_out
*uiout
)
380 tui_out_data
*data
= ui_out_data (uiout
);
381 gdb_flush (data
->stream
);
384 /* Local functions. */
386 /* Like tui_field_fmt, but takes a variable number of args and makes a
387 va_list and does not insert a separator. */
391 out_field_fmt (struct ui_out
*uiout
,
394 const char *format
,...)
396 tui_out_data
*data
= ui_out_data (uiout
);
399 va_start (args
, format
);
400 vfprintf_filtered (data
->stream
, format
, args
);
405 /* Access to ui_out format private members. */
408 field_separator (void)
410 tui_out_data
*data
= ui_out_data (uiout
);
411 fputc_filtered (' ', data
->stream
);
414 /* Initalize private members at startup. */
417 tui_out_new (struct ui_file
*stream
)
421 tui_out_data
*data
= XMALLOC (tui_out_data
);
422 data
->stream
= stream
;
423 data
->suppress_output
= 0;
425 data
->start_of_line
= 0;
426 return ui_out_new (&tui_ui_out_impl
, data
, flags
);
429 /* Standard gdb initialization hook. */
431 _initialize_tui_out (void)
433 /* Nothing needs to be done. */