1 /* Output generating routines for GDB CLI.
3 Copyright 1999, 2000, 2001, 2002, 2003 Free Software Foundation,
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., 59 Temple Place - Suite 330,
24 Boston, MA 02111-1307, 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
,
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 static void tui_wrap_hint (struct ui_out
*uiout
, char *identstring
);
69 static void tui_flush (struct ui_out
*uiout
);
71 /* This is the CLI ui-out implementation functions vector */
73 /* FIXME: This can be initialized dynamically after default is set to
74 handle initial output in main.c */
76 static struct ui_out_impl tui_ui_out_impl
=
94 0, /* Does not need MI hacks (i.e. needs CLI hacks). */
97 /* Prototypes for local functions */
99 extern void _initialize_tui_out (void);
101 static void field_separator (void);
103 static void out_field_fmt (struct ui_out
*uiout
, int fldno
,
105 const char *format
,...);
107 /* local variables */
111 /* Mark beginning of a table */
114 tui_table_begin (struct ui_out
*uiout
, int nbrofcols
,
118 tui_out_data
*data
= ui_out_data (uiout
);
120 data
->suppress_output
= 1;
122 /* Only the table suppresses the output and, fortunately, a table
123 is not a recursive data structure. */
124 gdb_assert (data
->suppress_output
== 0);
127 /* Mark beginning of a table body */
130 tui_table_body (struct ui_out
*uiout
)
132 tui_out_data
*data
= ui_out_data (uiout
);
133 if (data
->suppress_output
)
135 /* first, close the table header line */
136 tui_text (uiout
, "\n");
139 /* Mark end of a table */
142 tui_table_end (struct ui_out
*uiout
)
144 tui_out_data
*data
= ui_out_data (uiout
);
145 data
->suppress_output
= 0;
148 /* Specify table header */
151 tui_table_header (struct ui_out
*uiout
, int width
, enum ui_align alignment
,
152 const char *col_name
,
155 tui_out_data
*data
= ui_out_data (uiout
);
156 if (data
->suppress_output
)
158 tui_field_string (uiout
, 0, width
, alignment
, 0, colhdr
);
161 /* Mark beginning of a list */
164 tui_begin (struct ui_out
*uiout
,
165 enum ui_out_type type
,
169 tui_out_data
*data
= ui_out_data (uiout
);
170 if (data
->suppress_output
)
174 /* Mark end of a list */
177 tui_end (struct ui_out
*uiout
,
178 enum ui_out_type type
,
181 tui_out_data
*data
= ui_out_data (uiout
);
182 if (data
->suppress_output
)
186 /* output an int field */
189 tui_field_int (struct ui_out
*uiout
, int fldno
, int width
,
190 enum ui_align alignment
,
191 const char *fldname
, int value
)
193 char buffer
[20]; /* FIXME: how many chars long a %d can become? */
195 tui_out_data
*data
= ui_out_data (uiout
);
196 if (data
->suppress_output
)
199 /* Don't print line number, keep it for later. */
200 if (data
->start_of_line
== 0 && strcmp (fldname
, "line") == 0)
202 data
->start_of_line
++;
206 data
->start_of_line
++;
207 sprintf (buffer
, "%d", value
);
208 tui_field_string (uiout
, fldno
, width
, alignment
, fldname
, buffer
);
211 /* used to ommit a field */
214 tui_field_skip (struct ui_out
*uiout
, int fldno
, int width
,
215 enum ui_align alignment
,
218 tui_out_data
*data
= ui_out_data (uiout
);
219 if (data
->suppress_output
)
221 tui_field_string (uiout
, fldno
, width
, alignment
, fldname
, "");
224 /* other specific tui_field_* end up here so alignment and field
225 separators are both handled by tui_field_string */
228 tui_field_string (struct ui_out
*uiout
,
238 tui_out_data
*data
= ui_out_data (uiout
);
239 if (data
->suppress_output
)
242 if (fldname
&& data
->line
> 0 && strcmp (fldname
, "file") == 0)
244 data
->start_of_line
++;
247 tui_show_source (string
, data
->line
);
252 data
->start_of_line
++;
253 if ((align
!= ui_noalign
) && string
)
255 before
= width
- strlen (string
);
260 if (align
== ui_right
)
262 else if (align
== ui_left
)
277 ui_out_spaces (uiout
, before
);
279 out_field_fmt (uiout
, fldno
, fldname
, "%s", string
);
281 ui_out_spaces (uiout
, after
);
283 if (align
!= ui_noalign
)
287 /* This is the only field function that does not align */
290 tui_field_fmt (struct ui_out
*uiout
, int fldno
,
291 int width
, enum ui_align align
,
296 tui_out_data
*data
= ui_out_data (uiout
);
297 if (data
->suppress_output
)
300 data
->start_of_line
++;
301 vfprintf_filtered (data
->stream
, format
, args
);
303 if (align
!= ui_noalign
)
308 tui_spaces (struct ui_out
*uiout
, int numspaces
)
310 tui_out_data
*data
= ui_out_data (uiout
);
311 if (data
->suppress_output
)
313 print_spaces_filtered (numspaces
, data
->stream
);
317 tui_text (struct ui_out
*uiout
, const char *string
)
319 tui_out_data
*data
= ui_out_data (uiout
);
320 if (data
->suppress_output
)
322 data
->start_of_line
++;
325 if (strchr (string
, '\n') != 0)
328 data
->start_of_line
= 0;
332 if (strchr (string
, '\n'))
333 data
->start_of_line
= 0;
334 fputs_filtered (string
, data
->stream
);
338 tui_message (struct ui_out
*uiout
, int verbosity
,
339 const char *format
, va_list args
)
341 tui_out_data
*data
= ui_out_data (uiout
);
342 if (data
->suppress_output
)
344 if (ui_out_get_verblvl (uiout
) >= verbosity
)
345 vfprintf_unfiltered (data
->stream
, format
, args
);
349 tui_wrap_hint (struct ui_out
*uiout
, char *identstring
)
351 tui_out_data
*data
= ui_out_data (uiout
);
352 if (data
->suppress_output
)
354 wrap_here (identstring
);
358 tui_flush (struct ui_out
*uiout
)
360 tui_out_data
*data
= ui_out_data (uiout
);
361 gdb_flush (data
->stream
);
364 /* local functions */
366 /* Like tui_field_fmt, but takes a variable number of args
367 and makes a va_list and does not insert a separator */
371 out_field_fmt (struct ui_out
*uiout
, int fldno
,
373 const char *format
,...)
375 tui_out_data
*data
= ui_out_data (uiout
);
378 va_start (args
, format
);
379 vfprintf_filtered (data
->stream
, format
, args
);
384 /* access to ui_out format private members */
387 field_separator (void)
389 tui_out_data
*data
= ui_out_data (uiout
);
390 fputc_filtered (' ', data
->stream
);
393 /* initalize private members at startup */
396 tui_out_new (struct ui_file
*stream
)
400 tui_out_data
*data
= XMALLOC (tui_out_data
);
401 data
->stream
= stream
;
402 data
->suppress_output
= 0;
404 data
->start_of_line
= 0;
405 return ui_out_new (&tui_ui_out_impl
, data
, flags
);
408 /* standard gdb initialization hook */
410 _initialize_tui_out (void)
412 /* nothing needs to be done */