* gas/cfi/cfi-i386.d: Use objdump -Wf instead of readelf.
[deliverable/binutils-gdb.git] / gdb / cli-out.c
CommitLineData
8b93c638 1/* Output generating routines for GDB CLI.
349c5d5f 2
4c38e0a4 3 Copyright (C) 1999, 2000, 2002, 2003, 2005, 2007, 2008, 2009, 2010
bee0189a 4 Free Software Foundation, Inc.
349c5d5f 5
8b93c638
JM
6 Contributed by Cygnus Solutions.
7 Written by Fernando Nasser for Cygnus.
8
9 This file is part of GDB.
10
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
a9762ec7 13 the Free Software Foundation; either version 3 of the License, or
8b93c638
JM
14 (at your option) any later version.
15
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.
20
21 You should have received a copy of the GNU General Public License
a9762ec7 22 along with this program. If not, see <http://www.gnu.org/licenses/>. */
8b93c638
JM
23
24#include "defs.h"
25#include "ui-out.h"
26#include "cli-out.h"
1d1358b6 27#include "gdb_string.h"
698384cd 28#include "gdb_assert.h"
8b93c638 29
0a8fce9a 30typedef struct cli_ui_out_data cli_out_data;
8b93c638 31
8b93c638
JM
32
33/* Prototypes for local functions */
34
02a45ac0 35static void cli_text (struct ui_out *uiout, const char *string);
8b93c638
JM
36
37static void field_separator (void);
38
e2e11a41
AC
39static void out_field_fmt (struct ui_out *uiout, int fldno,
40 const char *fldname,
a0b31db1 41 const char *format,...) ATTRIBUTE_PRINTF (4, 5);
8b93c638 42
02a45ac0
PA
43/* These are the CLI output functions */
44
8b93c638
JM
45/* Mark beginning of a table */
46
02a45ac0 47static void
e2e11a41 48cli_table_begin (struct ui_out *uiout, int nbrofcols,
d63f1d40 49 int nr_rows,
e2e11a41 50 const char *tblid)
8b93c638 51{
1248ede2 52 cli_out_data *data = ui_out_data (uiout);
c5504eaf 53
698384cd
AC
54 if (nr_rows == 0)
55 data->suppress_output = 1;
56 else
ce2826aa 57 /* Only the table suppresses the output and, fortunately, a table
30fdc99f 58 is not a recursive data structure. */
698384cd 59 gdb_assert (data->suppress_output == 0);
8b93c638
JM
60}
61
62/* Mark beginning of a table body */
63
02a45ac0 64static void
fba45db2 65cli_table_body (struct ui_out *uiout)
8b93c638 66{
1248ede2 67 cli_out_data *data = ui_out_data (uiout);
c5504eaf 68
698384cd
AC
69 if (data->suppress_output)
70 return;
8b93c638
JM
71 /* first, close the table header line */
72 cli_text (uiout, "\n");
73}
74
75/* Mark end of a table */
76
02a45ac0 77static void
fba45db2 78cli_table_end (struct ui_out *uiout)
8b93c638 79{
1248ede2 80 cli_out_data *data = ui_out_data (uiout);
c5504eaf 81
698384cd 82 data->suppress_output = 0;
8b93c638
JM
83}
84
85/* Specify table header */
86
02a45ac0 87static void
fba45db2 88cli_table_header (struct ui_out *uiout, int width, enum ui_align alignment,
b25959ec 89 const char *col_name,
e2e11a41 90 const char *colhdr)
8b93c638 91{
1248ede2 92 cli_out_data *data = ui_out_data (uiout);
c5504eaf 93
698384cd
AC
94 if (data->suppress_output)
95 return;
0a8fce9a
PA
96
97 /* Always go through the function pointer (virtual function call).
98 We may have been extended. */
99 uo_field_string (uiout, 0, width, alignment, 0, colhdr);
8b93c638
JM
100}
101
102/* Mark beginning of a list */
103
02a45ac0 104static void
631ec795
AC
105cli_begin (struct ui_out *uiout,
106 enum ui_out_type type,
107 int level,
108 const char *id)
8b93c638 109{
1248ede2 110 cli_out_data *data = ui_out_data (uiout);
c5504eaf 111
698384cd
AC
112 if (data->suppress_output)
113 return;
8b93c638
JM
114}
115
116/* Mark end of a list */
117
02a45ac0 118static void
631ec795
AC
119cli_end (struct ui_out *uiout,
120 enum ui_out_type type,
121 int level)
8b93c638 122{
1248ede2 123 cli_out_data *data = ui_out_data (uiout);
c5504eaf 124
698384cd
AC
125 if (data->suppress_output)
126 return;
8b93c638
JM
127}
128
129/* output an int field */
130
02a45ac0 131static void
fba45db2 132cli_field_int (struct ui_out *uiout, int fldno, int width,
e2e11a41
AC
133 enum ui_align alignment,
134 const char *fldname, int value)
8b93c638 135{
c5504eaf 136 char buffer[20]; /* FIXME: how many chars long a %d can become? */
1248ede2 137 cli_out_data *data = ui_out_data (uiout);
c5504eaf 138
698384cd
AC
139 if (data->suppress_output)
140 return;
8b93c638 141 sprintf (buffer, "%d", value);
0a8fce9a
PA
142
143 /* Always go through the function pointer (virtual function call).
144 We may have been extended. */
145 uo_field_string (uiout, fldno, width, alignment, fldname, buffer);
8b93c638
JM
146}
147
148/* used to ommit a field */
149
02a45ac0 150static void
fba45db2 151cli_field_skip (struct ui_out *uiout, int fldno, int width,
e2e11a41
AC
152 enum ui_align alignment,
153 const char *fldname)
8b93c638 154{
1248ede2 155 cli_out_data *data = ui_out_data (uiout);
c5504eaf 156
698384cd
AC
157 if (data->suppress_output)
158 return;
0a8fce9a
PA
159
160 /* Always go through the function pointer (virtual function call).
161 We may have been extended. */
162 uo_field_string (uiout, fldno, width, alignment, fldname, "");
8b93c638
JM
163}
164
165/* other specific cli_field_* end up here so alignment and field
166 separators are both handled by cli_field_string */
167
02a45ac0 168static void
8b93c638
JM
169cli_field_string (struct ui_out *uiout,
170 int fldno,
171 int width,
55555bbc 172 enum ui_align align,
e2e11a41 173 const char *fldname,
8b93c638
JM
174 const char *string)
175{
176 int before = 0;
177 int after = 0;
1248ede2 178 cli_out_data *data = ui_out_data (uiout);
c5504eaf 179
698384cd
AC
180 if (data->suppress_output)
181 return;
182
8b93c638
JM
183 if ((align != ui_noalign) && string)
184 {
185 before = width - strlen (string);
186 if (before <= 0)
187 before = 0;
188 else
189 {
190 if (align == ui_right)
191 after = 0;
192 else if (align == ui_left)
193 {
194 after = before;
195 before = 0;
196 }
197 else
198 /* ui_center */
199 {
200 after = before / 2;
201 before -= after;
202 }
203 }
204 }
205
206 if (before)
207 ui_out_spaces (uiout, before);
208 if (string)
209 out_field_fmt (uiout, fldno, fldname, "%s", string);
210 if (after)
211 ui_out_spaces (uiout, after);
212
213 if (align != ui_noalign)
214 field_separator ();
215}
216
30fdc99f 217/* This is the only field function that does not align. */
8b93c638 218
a0b31db1 219static void ATTRIBUTE_PRINTF (6, 0)
8b93c638
JM
220cli_field_fmt (struct ui_out *uiout, int fldno,
221 int width, enum ui_align align,
e2e11a41
AC
222 const char *fldname,
223 const char *format,
224 va_list args)
8b93c638 225{
1248ede2 226 cli_out_data *data = ui_out_data (uiout);
c5504eaf 227
698384cd
AC
228 if (data->suppress_output)
229 return;
230
8b93c638
JM
231 vfprintf_filtered (data->stream, format, args);
232
233 if (align != ui_noalign)
234 field_separator ();
235}
236
02a45ac0 237static void
fba45db2 238cli_spaces (struct ui_out *uiout, int numspaces)
8b93c638 239{
1248ede2 240 cli_out_data *data = ui_out_data (uiout);
c5504eaf 241
698384cd
AC
242 if (data->suppress_output)
243 return;
8b93c638
JM
244 print_spaces_filtered (numspaces, data->stream);
245}
246
02a45ac0 247static void
e2e11a41 248cli_text (struct ui_out *uiout, const char *string)
8b93c638 249{
1248ede2 250 cli_out_data *data = ui_out_data (uiout);
c5504eaf 251
698384cd
AC
252 if (data->suppress_output)
253 return;
8b93c638
JM
254 fputs_filtered (string, data->stream);
255}
256
a0b31db1 257static void ATTRIBUTE_PRINTF (3, 0)
e2e11a41
AC
258cli_message (struct ui_out *uiout, int verbosity,
259 const char *format, va_list args)
8b93c638 260{
1248ede2 261 cli_out_data *data = ui_out_data (uiout);
c5504eaf 262
698384cd
AC
263 if (data->suppress_output)
264 return;
8b93c638
JM
265 if (ui_out_get_verblvl (uiout) >= verbosity)
266 vfprintf_unfiltered (data->stream, format, args);
267}
268
02a45ac0 269static void
fba45db2 270cli_wrap_hint (struct ui_out *uiout, char *identstring)
8b93c638 271{
1248ede2 272 cli_out_data *data = ui_out_data (uiout);
c5504eaf 273
698384cd
AC
274 if (data->suppress_output)
275 return;
8b93c638
JM
276 wrap_here (identstring);
277}
278
02a45ac0 279static void
fba45db2 280cli_flush (struct ui_out *uiout)
8b93c638 281{
1248ede2 282 cli_out_data *data = ui_out_data (uiout);
c5504eaf 283
8b93c638
JM
284 gdb_flush (data->stream);
285}
286
02a45ac0 287static int
0fac0b41
DJ
288cli_redirect (struct ui_out *uiout, struct ui_file *outstream)
289{
0a8fce9a 290 cli_out_data *data = ui_out_data (uiout);
c5504eaf 291
0fac0b41
DJ
292 if (outstream != NULL)
293 {
294 data->original_stream = data->stream;
295 data->stream = outstream;
296 }
297 else if (data->original_stream != NULL)
298 {
299 data->stream = data->original_stream;
300 data->original_stream = NULL;
301 }
302
303 return 0;
304}
305
8b93c638
JM
306/* local functions */
307
308/* Like cli_field_fmt, but takes a variable number of args
30fdc99f 309 and makes a va_list and does not insert a separator. */
8b93c638
JM
310
311/* VARARGS */
312static void
e2e11a41
AC
313out_field_fmt (struct ui_out *uiout, int fldno,
314 const char *fldname,
315 const char *format,...)
8b93c638 316{
1248ede2 317 cli_out_data *data = ui_out_data (uiout);
8b93c638
JM
318 va_list args;
319
320 va_start (args, format);
321 vfprintf_filtered (data->stream, format, args);
322
323 va_end (args);
324}
325
30fdc99f 326/* Access to ui_out format private members. */
8b93c638
JM
327
328static void
fba45db2 329field_separator (void)
8b93c638 330{
1248ede2 331 cli_out_data *data = ui_out_data (uiout);
c5504eaf 332
8b93c638
JM
333 fputc_filtered (' ', data->stream);
334}
335
02a45ac0
PA
336/* This is the CLI ui-out implementation functions vector */
337
338/* FIXME: This can be initialized dynamically after default is set to
339 handle initial output in main.c */
340
341struct ui_out_impl cli_ui_out_impl =
342{
343 cli_table_begin,
344 cli_table_body,
345 cli_table_end,
346 cli_table_header,
347 cli_begin,
348 cli_end,
349 cli_field_int,
350 cli_field_skip,
351 cli_field_string,
352 cli_field_fmt,
353 cli_spaces,
354 cli_text,
355 cli_message,
356 cli_wrap_hint,
357 cli_flush,
358 cli_redirect,
359 0, /* Does not need MI hacks (i.e. needs CLI hacks). */
360};
361
0a8fce9a
PA
362/* Constructor for a `cli_out_data' object. */
363
364void
365cli_out_data_ctor (cli_out_data *self, struct ui_file *stream)
366{
367 self->stream = stream;
368 self->original_stream = NULL;
369 self->suppress_output = 0;
370}
371
372/* Initialize private members at startup. */
8b93c638
JM
373
374struct ui_out *
375cli_out_new (struct ui_file *stream)
376{
377 int flags = ui_source_list;
1248ede2 378 cli_out_data *data = XMALLOC (cli_out_data);
c5504eaf 379
0a8fce9a 380 cli_out_data_ctor (data, stream);
8b93c638
JM
381 return ui_out_new (&cli_ui_out_impl, data, flags);
382}
383
4389a95a
AC
384struct ui_file *
385cli_out_set_stream (struct ui_out *uiout, struct ui_file *stream)
386{
1248ede2 387 cli_out_data *data = ui_out_data (uiout);
4389a95a 388 struct ui_file *old = data->stream;
c5504eaf 389
4389a95a
AC
390 data->stream = stream;
391 return old;
392}
This page took 1.103131 seconds and 4 git commands to generate.