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