1 /* Output generating routines for GDB CLI.
3 Copyright 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
5 Contributed by Cygnus Solutions.
6 Written by Fernando Nasser for Cygnus.
8 This file is part of GDB.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA. */
28 #include "gdb_string.h"
29 #include "gdb_assert.h"
33 struct ui_file
*stream
;
39 /* These are the CLI output functions */
41 static void tui_table_begin (struct ui_out
*uiout
, int nbrofcols
,
42 int nr_rows
, const char *tblid
);
43 static void tui_table_body (struct ui_out
*uiout
);
44 static void tui_table_end (struct ui_out
*uiout
);
45 static void tui_table_header (struct ui_out
*uiout
, int width
,
46 enum ui_align alig
, const char *col_name
,
48 static void tui_begin (struct ui_out
*uiout
, enum ui_out_type type
,
49 int level
, const char *lstid
);
50 static void tui_end (struct ui_out
*uiout
, enum ui_out_type type
, int level
);
51 static void tui_field_int (struct ui_out
*uiout
, int fldno
, int width
,
52 enum ui_align alig
, const char *fldname
, int value
);
53 static void tui_field_skip (struct ui_out
*uiout
, int fldno
, int width
,
54 enum ui_align alig
, const char *fldname
);
55 static void tui_field_string (struct ui_out
*uiout
, int fldno
, int width
,
56 enum ui_align alig
, const char *fldname
,
58 static void tui_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 tui_spaces (struct ui_out
*uiout
, int numspaces
);
63 static void tui_text (struct ui_out
*uiout
, const char *string
);
64 static void tui_message (struct ui_out
*uiout
, int verbosity
,
65 const char *format
, va_list args
);
66 static void tui_wrap_hint (struct ui_out
*uiout
, char *identstring
);
67 static void tui_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 tui_ui_out_impl
=
91 0, /* Does not need MI hacks (i.e. needs CLI hacks). */
94 /* Prototypes for local functions */
96 extern void _initialize_tui_out (void);
98 static void field_separator (void);
100 static void out_field_fmt (struct ui_out
*uiout
, int fldno
,
102 const char *format
,...);
104 /* local variables */
108 /* Mark beginning of a table */
111 tui_table_begin (struct ui_out
*uiout
, int nbrofcols
,
115 struct ui_out_data
*data
= ui_out_data (uiout
);
117 data
->suppress_output
= 1;
119 /* Only the table suppresses the output and, fortunatly, a table
120 is not a recursive data structure. */
121 gdb_assert (data
->suppress_output
== 0);
124 /* Mark beginning of a table body */
127 tui_table_body (struct ui_out
*uiout
)
129 struct ui_out_data
*data
= ui_out_data (uiout
);
130 if (data
->suppress_output
)
132 /* first, close the table header line */
133 tui_text (uiout
, "\n");
136 /* Mark end of a table */
139 tui_table_end (struct ui_out
*uiout
)
141 struct ui_out_data
*data
= ui_out_data (uiout
);
142 data
->suppress_output
= 0;
145 /* Specify table header */
148 tui_table_header (struct ui_out
*uiout
, int width
, enum ui_align alignment
,
149 const char *col_name
,
152 struct ui_out_data
*data
= ui_out_data (uiout
);
153 if (data
->suppress_output
)
155 tui_field_string (uiout
, 0, width
, alignment
, 0, colhdr
);
158 /* Mark beginning of a list */
161 tui_begin (struct ui_out
*uiout
,
162 enum ui_out_type type
,
166 struct ui_out_data
*data
= ui_out_data (uiout
);
167 if (data
->suppress_output
)
171 /* Mark end of a list */
174 tui_end (struct ui_out
*uiout
,
175 enum ui_out_type type
,
178 struct ui_out_data
*data
= ui_out_data (uiout
);
179 if (data
->suppress_output
)
183 /* output an int field */
186 tui_field_int (struct ui_out
*uiout
, int fldno
, int width
,
187 enum ui_align alignment
,
188 const char *fldname
, int value
)
190 char buffer
[20]; /* FIXME: how many chars long a %d can become? */
192 struct ui_out_data
*data
= ui_out_data (uiout
);
193 if (data
->suppress_output
)
196 /* Don't print line number, keep it for later. */
197 if (data
->start_of_line
== 0 && strcmp (fldname
, "line") == 0)
199 data
->start_of_line
++;
203 data
->start_of_line
++;
204 sprintf (buffer
, "%d", value
);
205 tui_field_string (uiout
, fldno
, width
, alignment
, fldname
, buffer
);
208 /* used to ommit a field */
211 tui_field_skip (struct ui_out
*uiout
, int fldno
, int width
,
212 enum ui_align alignment
,
215 struct ui_out_data
*data
= ui_out_data (uiout
);
216 if (data
->suppress_output
)
218 tui_field_string (uiout
, fldno
, width
, alignment
, fldname
, "");
221 /* other specific tui_field_* end up here so alignment and field
222 separators are both handled by tui_field_string */
225 tui_field_string (struct ui_out
*uiout
,
235 struct ui_out_data
*data
= ui_out_data (uiout
);
236 if (data
->suppress_output
)
239 if (fldname
&& data
->line
> 0 && strcmp (fldname
, "file") == 0)
241 data
->start_of_line
++;
244 tui_show_source (string
, data
->line
);
249 data
->start_of_line
++;
250 if ((align
!= ui_noalign
) && string
)
252 before
= width
- strlen (string
);
257 if (align
== ui_right
)
259 else if (align
== ui_left
)
274 ui_out_spaces (uiout
, before
);
276 out_field_fmt (uiout
, fldno
, fldname
, "%s", string
);
278 ui_out_spaces (uiout
, after
);
280 if (align
!= ui_noalign
)
284 /* This is the only field function that does not align */
287 tui_field_fmt (struct ui_out
*uiout
, int fldno
,
288 int width
, enum ui_align align
,
293 struct ui_out_data
*data
= ui_out_data (uiout
);
294 if (data
->suppress_output
)
297 data
->start_of_line
++;
298 vfprintf_filtered (data
->stream
, format
, args
);
300 if (align
!= ui_noalign
)
305 tui_spaces (struct ui_out
*uiout
, int numspaces
)
307 struct ui_out_data
*data
= ui_out_data (uiout
);
308 if (data
->suppress_output
)
310 print_spaces_filtered (numspaces
, data
->stream
);
314 tui_text (struct ui_out
*uiout
, const char *string
)
316 struct ui_out_data
*data
= ui_out_data (uiout
);
317 if (data
->suppress_output
)
319 data
->start_of_line
++;
322 if (strchr (string
, '\n') != 0)
325 data
->start_of_line
= 0;
329 if (strchr (string
, '\n'))
330 data
->start_of_line
= 0;
331 fputs_filtered (string
, data
->stream
);
335 tui_message (struct ui_out
*uiout
, int verbosity
,
336 const char *format
, va_list args
)
338 struct ui_out_data
*data
= ui_out_data (uiout
);
339 if (data
->suppress_output
)
341 if (ui_out_get_verblvl (uiout
) >= verbosity
)
342 vfprintf_unfiltered (data
->stream
, format
, args
);
346 tui_wrap_hint (struct ui_out
*uiout
, char *identstring
)
348 struct ui_out_data
*data
= ui_out_data (uiout
);
349 if (data
->suppress_output
)
351 wrap_here (identstring
);
355 tui_flush (struct ui_out
*uiout
)
357 struct ui_out_data
*data
= ui_out_data (uiout
);
358 gdb_flush (data
->stream
);
361 /* local functions */
363 /* Like tui_field_fmt, but takes a variable number of args
364 and makes a va_list and does not insert a separator */
368 out_field_fmt (struct ui_out
*uiout
, int fldno
,
370 const char *format
,...)
372 struct ui_out_data
*data
= ui_out_data (uiout
);
375 va_start (args
, format
);
376 vfprintf_filtered (data
->stream
, format
, args
);
381 /* access to ui_out format private members */
384 field_separator (void)
386 struct ui_out_data
*data
= ui_out_data (uiout
);
387 fputc_filtered (' ', data
->stream
);
390 /* initalize private members at startup */
393 tui_out_new (struct ui_file
*stream
)
397 struct ui_out_data
*data
= XMALLOC (struct ui_out_data
);
398 data
->stream
= stream
;
399 data
->suppress_output
= 0;
401 data
->start_of_line
= 0;
402 return ui_out_new (&tui_ui_out_impl
, data
, flags
);
405 /* standard gdb initialization hook */
407 _initialize_tui_out (void)
409 /* nothing needs to be done */