Switch the license of all .c files to GPLv3.
[deliverable/binutils-gdb.git] / gdb / ui-out.c
CommitLineData
8b93c638 1/* Output generating routines for GDB.
349c5d5f 2
6aba47ca 3 Copyright (C) 1999, 2000, 2001, 2002, 2004, 2005, 2007
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 "gdb_string.h"
26#include "expression.h" /* For language.h */
27#include "language.h"
28#include "ui-out.h"
80f49b30 29#include "gdb_assert.h"
8b93c638 30
8b93c638
JM
31/* table header structures */
32
33struct ui_out_hdr
34 {
35 int colno;
36 int width;
37 int alignment;
b25959ec 38 char *col_name;
8b93c638
JM
39 char *colhdr;
40 struct ui_out_hdr *next;
41 };
42
80f49b30
AC
43/* Maintain a stack so that the info applicable to the inner most list
44 is always available. Stack/nested level 0 is reserved for the
45 top-level result. */
46
a3edc55b 47enum { MAX_UI_OUT_LEVELS = 6 };
80f49b30
AC
48
49struct ui_out_level
50 {
51 /* Count each field; the first element is for non-list fields */
52 int field_count;
631ec795
AC
53 /* The type of this level. */
54 enum ui_out_type type;
80f49b30
AC
55 };
56
bafdd3b3
AC
57/* Tables are special. Maintain a separate structure that tracks
58 their state. At present an output can only contain a single table
59 but that restriction might eventually be lifted. */
60
61struct ui_out_table
62{
63 /* If on, a table is being generated. */
64 int flag;
65
66 /* If on, the body of a table is being generated. If off, the table
67 header is being generated. */
68 int body_flag;
69
a6c47c14
AC
70 /* The level at which each entry of the table is to be found. A row
71 (a tuple) is made up of entries. Consequently ENTRY_LEVEL is one
72 above that of the table. */
73 int entry_level;
74
bafdd3b3
AC
75 /* Number of table columns (as specified in the table_begin call). */
76 int columns;
77
78 /* String identifying the table (as specified in the table_begin
79 call). */
80 char *id;
81
82 /* Points to the first table header (if any). */
83 struct ui_out_hdr *header_first;
84
85 /* Points to the last table header (if any). */
86 struct ui_out_hdr *header_last;
87
88 /* Points to header of NEXT column to format. */
89 struct ui_out_hdr *header_next;
90
91};
92
93
8b93c638
JM
94/* The ui_out structure */
95/* Any change here requires a corresponding one in the initialization
96 of the default uiout, which is statically initialized */
97
98struct ui_out
99 {
100 int flags;
101 /* specific implementation of ui-out */
102 struct ui_out_impl *impl;
103 struct ui_out_data *data;
104
bafdd3b3 105 /* Sub structure tracking the ui-out depth. */
80f49b30
AC
106 int level;
107 struct ui_out_level levels[MAX_UI_OUT_LEVELS];
8b93c638 108
bafdd3b3
AC
109 /* A table, if any. At present only a single table is supported. */
110 struct ui_out_table table;
8b93c638
JM
111 };
112
80f49b30
AC
113/* The current (inner most) level. */
114static struct ui_out_level *
115current_level (struct ui_out *uiout)
116{
117 return &uiout->levels[uiout->level];
118}
119
120/* Create a new level, of TYPE. Return the new level's index. */
121static int
122push_level (struct ui_out *uiout,
631ec795 123 enum ui_out_type type,
80f49b30
AC
124 const char *id)
125{
126 struct ui_out_level *current;
127 /* We had better not overflow the buffer. */
128 uiout->level++;
631ec795 129 gdb_assert (uiout->level >= 0 && uiout->level < MAX_UI_OUT_LEVELS);
80f49b30
AC
130 current = current_level (uiout);
131 current->field_count = 0;
631ec795 132 current->type = type;
80f49b30
AC
133 return uiout->level;
134}
135
136/* Discard the current level, return the discarded level's index.
137 TYPE is the type of the level being discarded. */
138static int
631ec795
AC
139pop_level (struct ui_out *uiout,
140 enum ui_out_type type)
80f49b30
AC
141{
142 /* We had better not underflow the buffer. */
143 gdb_assert (uiout->level > 0 && uiout->level < MAX_UI_OUT_LEVELS);
631ec795 144 gdb_assert (current_level (uiout)->type == type);
80f49b30
AC
145 uiout->level--;
146 return uiout->level + 1;
147}
148
149
8b93c638
JM
150/* These are the default implementation functions */
151
152static void default_table_begin (struct ui_out *uiout, int nbrofcols,
d63f1d40 153 int nr_rows, const char *tblid);
8b93c638
JM
154static void default_table_body (struct ui_out *uiout);
155static void default_table_end (struct ui_out *uiout);
156static void default_table_header (struct ui_out *uiout, int width,
b25959ec 157 enum ui_align alig, const char *col_name,
e2e11a41 158 const char *colhdr);
631ec795
AC
159static void default_begin (struct ui_out *uiout,
160 enum ui_out_type type,
161 int level, const char *id);
162static void default_end (struct ui_out *uiout,
163 enum ui_out_type type,
164 int level);
8b93c638 165static void default_field_int (struct ui_out *uiout, int fldno, int width,
e2e11a41
AC
166 enum ui_align alig,
167 const char *fldname,
168 int value);
8b93c638 169static void default_field_skip (struct ui_out *uiout, int fldno, int width,
e2e11a41
AC
170 enum ui_align alig,
171 const char *fldname);
8b93c638 172static void default_field_string (struct ui_out *uiout, int fldno, int width,
e2e11a41
AC
173 enum ui_align align,
174 const char *fldname,
8b93c638
JM
175 const char *string);
176static void default_field_fmt (struct ui_out *uiout, int fldno,
177 int width, enum ui_align align,
e2e11a41
AC
178 const char *fldname,
179 const char *format,
bee0189a 180 va_list args) ATTR_FORMAT (printf, 6, 0);
8b93c638 181static void default_spaces (struct ui_out *uiout, int numspaces);
e2e11a41
AC
182static void default_text (struct ui_out *uiout, const char *string);
183static void default_message (struct ui_out *uiout, int verbosity,
184 const char *format,
bee0189a 185 va_list args) ATTR_FORMAT (printf, 3, 0);
8b93c638
JM
186static void default_wrap_hint (struct ui_out *uiout, char *identstring);
187static void default_flush (struct ui_out *uiout);
188
189/* This is the default ui-out implementation functions vector */
190
191struct ui_out_impl default_ui_out_impl =
192{
193 default_table_begin,
194 default_table_body,
195 default_table_end,
196 default_table_header,
631ec795
AC
197 default_begin,
198 default_end,
8b93c638
JM
199 default_field_int,
200 default_field_skip,
201 default_field_string,
202 default_field_fmt,
203 default_spaces,
204 default_text,
205 default_message,
206 default_wrap_hint,
9dc5e2a9 207 default_flush,
0fac0b41 208 NULL,
9dc5e2a9 209 0, /* Does not need MI hacks. */
8b93c638
JM
210};
211
212/* The default ui_out */
213
214struct ui_out def_uiout =
215{
216 0, /* flags */
217 &default_ui_out_impl, /* impl */
218};
219
220/* Pointer to current ui_out */
221/* FIXME: This should not be a global, but something passed down from main.c
222 or top.c */
223
224struct ui_out *uiout = &def_uiout;
225
226/* These are the interfaces to implementation functions */
227
88379baf 228static void uo_table_begin (struct ui_out *uiout, int nbrofcols,
d63f1d40 229 int nr_rows, const char *tblid);
8b93c638
JM
230static void uo_table_body (struct ui_out *uiout);
231static void uo_table_end (struct ui_out *uiout);
232static void uo_table_header (struct ui_out *uiout, int width,
b25959ec
AC
233 enum ui_align align, const char *col_name,
234 const char *colhdr);
631ec795
AC
235static void uo_begin (struct ui_out *uiout,
236 enum ui_out_type type,
237 int level, const char *id);
238static void uo_end (struct ui_out *uiout,
239 enum ui_out_type type,
240 int level);
8b93c638 241static void uo_field_int (struct ui_out *uiout, int fldno, int width,
88379baf 242 enum ui_align align, const char *fldname, int value);
8b93c638 243static void uo_field_skip (struct ui_out *uiout, int fldno, int width,
88379baf 244 enum ui_align align, const char *fldname);
8b93c638 245static void uo_field_string (struct ui_out *uiout, int fldno, int width,
88379baf
AC
246 enum ui_align align, const char *fldname,
247 const char *string);
8b93c638 248static void uo_field_fmt (struct ui_out *uiout, int fldno, int width,
88379baf 249 enum ui_align align, const char *fldname,
bee0189a
DJ
250 const char *format, va_list args)
251 ATTR_FORMAT (printf, 6, 0);
8b93c638 252static void uo_spaces (struct ui_out *uiout, int numspaces);
88379baf 253static void uo_text (struct ui_out *uiout, const char *string);
8b93c638 254static void uo_message (struct ui_out *uiout, int verbosity,
bee0189a
DJ
255 const char *format, va_list args)
256 ATTR_FORMAT (printf, 3, 0);
8b93c638
JM
257static void uo_wrap_hint (struct ui_out *uiout, char *identstring);
258static void uo_flush (struct ui_out *uiout);
0fac0b41 259static int uo_redirect (struct ui_out *uiout, struct ui_file *outstream);
8b93c638
JM
260
261/* Prototypes for local functions */
262
263extern void _initialize_ui_out (void);
88379baf 264static void append_header_to_list (struct ui_out *uiout, int width,
b25959ec
AC
265 int alignment, const char *col_name,
266 const char *colhdr);
bafdd3b3 267static int get_next_header (struct ui_out *uiout, int *colno, int *width,
8b93c638
JM
268 int *alignment, char **colhdr);
269static void clear_header_list (struct ui_out *uiout);
a6c47c14
AC
270static void verify_field (struct ui_out *uiout, int *fldno, int *width,
271 int *align);
8b93c638 272
8b93c638
JM
273/* exported functions (ui_out API) */
274
275/* Mark beginning of a table */
276
3b31d625 277static void
88379baf 278ui_out_table_begin (struct ui_out *uiout, int nbrofcols,
d63f1d40 279 int nr_rows,
88379baf 280 const char *tblid)
8b93c638 281{
bafdd3b3 282 if (uiout->table.flag)
8e65ff28 283 internal_error (__FILE__, __LINE__,
e2e0b3e5
AC
284 _("tables cannot be nested; table_begin found before \
285previous table_end."));
8b93c638 286
bafdd3b3
AC
287 uiout->table.flag = 1;
288 uiout->table.body_flag = 0;
a6c47c14 289 uiout->table.entry_level = uiout->level + 1;
bafdd3b3 290 uiout->table.columns = nbrofcols;
8b93c638 291 if (tblid != NULL)
bafdd3b3 292 uiout->table.id = xstrdup (tblid);
8b93c638 293 else
bafdd3b3 294 uiout->table.id = NULL;
8b93c638
JM
295 clear_header_list (uiout);
296
bafdd3b3 297 uo_table_begin (uiout, nbrofcols, nr_rows, uiout->table.id);
8b93c638
JM
298}
299
300void
fba45db2 301ui_out_table_body (struct ui_out *uiout)
8b93c638 302{
bafdd3b3 303 if (!uiout->table.flag)
8e65ff28 304 internal_error (__FILE__, __LINE__,
e2e0b3e5
AC
305 _("table_body outside a table is not valid; it must be \
306after a table_begin and before a table_end."));
bafdd3b3 307 if (uiout->table.body_flag)
8e65ff28 308 internal_error (__FILE__, __LINE__,
e2e0b3e5
AC
309 _("extra table_body call not allowed; there must be \
310only one table_body after a table_begin and before a table_end."));
bafdd3b3 311 if (uiout->table.header_next->colno != uiout->table.columns)
8e65ff28 312 internal_error (__FILE__, __LINE__,
e2e0b3e5
AC
313 _("number of headers differ from number of table \
314columns."));
8b93c638 315
bafdd3b3
AC
316 uiout->table.body_flag = 1;
317 uiout->table.header_next = uiout->table.header_first;
8b93c638
JM
318
319 uo_table_body (uiout);
320}
321
3b31d625 322static void
fba45db2 323ui_out_table_end (struct ui_out *uiout)
8b93c638 324{
bafdd3b3 325 if (!uiout->table.flag)
8e65ff28 326 internal_error (__FILE__, __LINE__,
e2e0b3e5 327 _("misplaced table_end or missing table_begin."));
8b93c638 328
a6c47c14 329 uiout->table.entry_level = 0;
bafdd3b3
AC
330 uiout->table.body_flag = 0;
331 uiout->table.flag = 0;
8b93c638
JM
332
333 uo_table_end (uiout);
334
bafdd3b3
AC
335 if (uiout->table.id)
336 xfree (uiout->table.id);
8b93c638
JM
337 clear_header_list (uiout);
338}
339
340void
fba45db2 341ui_out_table_header (struct ui_out *uiout, int width, enum ui_align alignment,
b25959ec 342 const char *col_name,
88379baf 343 const char *colhdr)
8b93c638 344{
bafdd3b3 345 if (!uiout->table.flag || uiout->table.body_flag)
8e65ff28 346 internal_error (__FILE__, __LINE__,
e2e0b3e5
AC
347 _("table header must be specified after table_begin \
348and before table_body."));
8b93c638 349
b25959ec 350 append_header_to_list (uiout, width, alignment, col_name, colhdr);
8b93c638 351
b25959ec 352 uo_table_header (uiout, width, alignment, col_name, colhdr);
8b93c638
JM
353}
354
3b31d625
EZ
355static void
356do_cleanup_table_end (void *data)
357{
358 struct ui_out *ui_out = data;
359
360 ui_out_table_end (ui_out);
361}
362
363struct cleanup *
364make_cleanup_ui_out_table_begin_end (struct ui_out *ui_out, int nr_cols,
365 int nr_rows, const char *tblid)
366{
367 ui_out_table_begin (ui_out, nr_cols, nr_rows, tblid);
368 return make_cleanup (do_cleanup_table_end, ui_out);
369}
370
8b93c638 371void
631ec795
AC
372ui_out_begin (struct ui_out *uiout,
373 enum ui_out_type type,
374 const char *id)
8b93c638 375{
80f49b30 376 int new_level;
bafdd3b3 377 if (uiout->table.flag && !uiout->table.body_flag)
8e65ff28 378 internal_error (__FILE__, __LINE__,
e2e0b3e5
AC
379 _("table header or table_body expected; lists must be \
380specified after table_body."));
a6c47c14
AC
381
382 /* Be careful to verify the ``field'' before the new tuple/list is
383 pushed onto the stack. That way the containing list/table/row is
384 verified and not the newly created tuple/list. This verification
385 is needed (at least) for the case where a table row entry
386 contains either a tuple/list. For that case bookkeeping such as
387 updating the column count or advancing to the next heading still
388 needs to be performed. */
389 {
390 int fldno;
391 int width;
392 int align;
393 verify_field (uiout, &fldno, &width, &align);
394 }
395
631ec795 396 new_level = push_level (uiout, type, id);
a6c47c14
AC
397
398 /* If the push puts us at the same level as a table row entry, we've
399 got a new table row. Put the header pointer back to the start. */
400 if (uiout->table.body_flag
401 && uiout->table.entry_level == new_level)
bafdd3b3 402 uiout->table.header_next = uiout->table.header_first;
a6c47c14 403
631ec795
AC
404 uo_begin (uiout, type, new_level, id);
405}
406
631ec795
AC
407void
408ui_out_end (struct ui_out *uiout,
409 enum ui_out_type type)
410{
411 int old_level = pop_level (uiout, type);
412 uo_end (uiout, type, old_level);
8b93c638
JM
413}
414
127431f9
AC
415struct ui_out_end_cleanup_data
416{
417 struct ui_out *uiout;
418 enum ui_out_type type;
419};
420
e6e0bfab 421static void
127431f9
AC
422do_cleanup_end (void *data)
423{
424 struct ui_out_end_cleanup_data *end_cleanup_data = data;
425 ui_out_end (end_cleanup_data->uiout, end_cleanup_data->type);
426 xfree (end_cleanup_data);
427}
428
429static struct cleanup *
430make_cleanup_ui_out_end (struct ui_out *uiout,
431 enum ui_out_type type)
432{
433 struct ui_out_end_cleanup_data *end_cleanup_data;
434 end_cleanup_data = XMALLOC (struct ui_out_end_cleanup_data);
435 end_cleanup_data->uiout = uiout;
436 end_cleanup_data->type = type;
437 return make_cleanup (do_cleanup_end, end_cleanup_data);
438}
439
e6e0bfab 440struct cleanup *
666547aa
AC
441make_cleanup_ui_out_tuple_begin_end (struct ui_out *uiout,
442 const char *id)
443{
3b31d625 444 ui_out_begin (uiout, ui_out_type_tuple, id);
666547aa
AC
445 return make_cleanup_ui_out_end (uiout, ui_out_type_tuple);
446}
447
448struct cleanup *
6b28c186
AC
449make_cleanup_ui_out_list_begin_end (struct ui_out *uiout,
450 const char *id)
e6e0bfab 451{
3b31d625 452 ui_out_begin (uiout, ui_out_type_list, id);
127431f9 453 return make_cleanup_ui_out_end (uiout, ui_out_type_list);
e6e0bfab
MK
454}
455
8b93c638 456void
88379baf
AC
457ui_out_field_int (struct ui_out *uiout,
458 const char *fldname,
459 int value)
8b93c638
JM
460{
461 int fldno;
462 int width;
463 int align;
80f49b30 464 struct ui_out_level *current = current_level (uiout);
8b93c638 465
a6c47c14 466 verify_field (uiout, &fldno, &width, &align);
8b93c638
JM
467
468 uo_field_int (uiout, fldno, width, align, fldname, value);
469}
470
52c6a6ac
JJ
471void
472ui_out_field_fmt_int (struct ui_out *uiout,
473 int input_width,
474 enum ui_align input_align,
475 const char *fldname,
476 int value)
477{
478 int fldno;
479 int width;
480 int align;
481 struct ui_out_level *current = current_level (uiout);
482
483 verify_field (uiout, &fldno, &width, &align);
484
485 uo_field_int (uiout, fldno, input_width, input_align, fldname, value);
486}
487
8b93c638 488void
88379baf
AC
489ui_out_field_core_addr (struct ui_out *uiout,
490 const char *fldname,
491 CORE_ADDR address)
8b93c638
JM
492{
493 char addstr[20];
17a912b6 494 int addr_bit = gdbarch_addr_bit (current_gdbarch);
a72d8a8e
MR
495
496 /* Truncate address to match deprecated_print_address_numeric(). */
497 if (addr_bit < (sizeof (CORE_ADDR) * HOST_CHAR_BIT))
498 address &= ((CORE_ADDR) 1 << addr_bit) - 1;
8b93c638 499
535c96ce
AC
500 /* FIXME: cagney/2002-05-03: Need local_address_string() function
501 that returns the language localized string formatted to a width
17a912b6 502 based on gdbarch_addr_bit. */
66bf4b3a 503 /* deprecated_print_address_numeric (address, 1, local_stream); */
a72d8a8e 504 if (addr_bit <= 32)
bb599908 505 strcpy (addstr, hex_string_custom (address, 8));
535c96ce 506 else
bb599908 507 strcpy (addstr, hex_string_custom (address, 16));
8b93c638
JM
508
509 ui_out_field_string (uiout, fldname, addstr);
510}
511
512void
88379baf
AC
513ui_out_field_stream (struct ui_out *uiout,
514 const char *fldname,
515 struct ui_stream *buf)
8b93c638
JM
516{
517 long length;
518 char *buffer = ui_file_xstrdup (buf->stream, &length);
b8c9b27d 519 struct cleanup *old_cleanup = make_cleanup (xfree, buffer);
8b93c638
JM
520 if (length > 0)
521 ui_out_field_string (uiout, fldname, buffer);
522 else
523 ui_out_field_skip (uiout, fldname);
524 ui_file_rewind (buf->stream);
525 do_cleanups (old_cleanup);
526}
527
528/* used to ommit a field */
529
530void
88379baf
AC
531ui_out_field_skip (struct ui_out *uiout,
532 const char *fldname)
8b93c638
JM
533{
534 int fldno;
535 int width;
536 int align;
8b93c638 537
a6c47c14 538 verify_field (uiout, &fldno, &width, &align);
8b93c638
JM
539
540 uo_field_skip (uiout, fldno, width, align, fldname);
541}
542
543void
544ui_out_field_string (struct ui_out *uiout,
88379baf 545 const char *fldname,
8b93c638
JM
546 const char *string)
547{
548 int fldno;
549 int width;
550 int align;
8b93c638 551
a6c47c14 552 verify_field (uiout, &fldno, &width, &align);
8b93c638
JM
553
554 uo_field_string (uiout, fldno, width, align, fldname, string);
555}
556
557/* VARARGS */
558void
88379baf
AC
559ui_out_field_fmt (struct ui_out *uiout,
560 const char *fldname,
561 const char *format, ...)
8b93c638
JM
562{
563 va_list args;
564 int fldno;
565 int width;
566 int align;
8b93c638
JM
567
568 /* will not align, but has to call anyway */
a6c47c14 569 verify_field (uiout, &fldno, &width, &align);
8b93c638
JM
570
571 va_start (args, format);
572
573 uo_field_fmt (uiout, fldno, width, align, fldname, format, args);
574
575 va_end (args);
576}
577
578void
fba45db2 579ui_out_spaces (struct ui_out *uiout, int numspaces)
8b93c638
JM
580{
581 uo_spaces (uiout, numspaces);
582}
583
584void
88379baf
AC
585ui_out_text (struct ui_out *uiout,
586 const char *string)
8b93c638
JM
587{
588 uo_text (uiout, string);
589}
590
591void
88379baf
AC
592ui_out_message (struct ui_out *uiout, int verbosity,
593 const char *format,...)
8b93c638
JM
594{
595 va_list args;
596
597 va_start (args, format);
598
599 uo_message (uiout, verbosity, format, args);
600
601 va_end (args);
602}
603
604struct ui_stream *
fba45db2 605ui_out_stream_new (struct ui_out *uiout)
8b93c638
JM
606{
607 struct ui_stream *tempbuf;
608
609 tempbuf = XMALLOC (struct ui_stream);
610 tempbuf->uiout = uiout;
611 tempbuf->stream = mem_fileopen ();
612 return tempbuf;
613}
614
615void
fba45db2 616ui_out_stream_delete (struct ui_stream *buf)
8b93c638
JM
617{
618 ui_file_delete (buf->stream);
b8c9b27d 619 xfree (buf);
8b93c638
JM
620}
621
622static void
623do_stream_delete (void *buf)
624{
625 ui_out_stream_delete (buf);
626}
627
628struct cleanup *
629make_cleanup_ui_out_stream_delete (struct ui_stream *buf)
630{
631 return make_cleanup (do_stream_delete, buf);
632}
633
634
635void
fba45db2 636ui_out_wrap_hint (struct ui_out *uiout, char *identstring)
8b93c638
JM
637{
638 uo_wrap_hint (uiout, identstring);
639}
640
641void
fba45db2 642ui_out_flush (struct ui_out *uiout)
8b93c638
JM
643{
644 uo_flush (uiout);
645}
646
0fac0b41
DJ
647int
648ui_out_redirect (struct ui_out *uiout, struct ui_file *outstream)
649{
650 return uo_redirect (uiout, outstream);
651}
652
8b93c638
JM
653/* set the flags specified by the mask given */
654int
fba45db2 655ui_out_set_flags (struct ui_out *uiout, int mask)
8b93c638 656{
5bfb05ca 657 int oldflags = uiout->flags;
8b93c638 658
b8d86de3 659 uiout->flags |= mask;
8b93c638
JM
660
661 return oldflags;
662}
663
664/* clear the flags specified by the mask given */
665int
fba45db2 666ui_out_clear_flags (struct ui_out *uiout, int mask)
8b93c638 667{
5bfb05ca 668 int oldflags = uiout->flags;
8b93c638
JM
669
670 uiout->flags &= ~mask;
671
672 return oldflags;
673}
674
675/* test the flags against the mask given */
676int
fba45db2 677ui_out_test_flags (struct ui_out *uiout, int mask)
8b93c638
JM
678{
679 return (uiout->flags & mask);
680}
681
682/* obtain the current verbosity level (as stablished by the
683 'set verbositylevel' command */
684
685int
fba45db2 686ui_out_get_verblvl (struct ui_out *uiout)
8b93c638
JM
687{
688 /* FIXME: not implemented yet */
689 return 0;
690}
691
692#if 0
693void
fba45db2 694ui_out_result_begin (struct ui_out *uiout, char *class)
8b93c638
JM
695{
696}
697
698void
fba45db2 699ui_out_result_end (struct ui_out *uiout)
8b93c638
JM
700{
701}
702
703void
fba45db2 704ui_out_info_begin (struct ui_out *uiout, char *class)
8b93c638
JM
705{
706}
707
708void
fba45db2 709ui_out_info_end (struct ui_out *uiout)
8b93c638
JM
710{
711}
712
713void
fba45db2 714ui_out_notify_begin (struct ui_out *uiout, char *class)
8b93c638
JM
715{
716}
717
718void
fba45db2 719ui_out_notify_end (struct ui_out *uiout)
8b93c638
JM
720{
721}
722
723void
fba45db2 724ui_out_error_begin (struct ui_out *uiout, char *class)
8b93c638
JM
725{
726}
727
728void
fba45db2 729ui_out_error_end (struct ui_out *uiout)
8b93c638
JM
730{
731}
732#endif
733
734#if 0
735void
736gdb_error (ui_out * uiout, int severity, char *format,...)
737{
738 va_list args;
739}
740
741void
10689f25 742gdb_query (struct ui_out *uiout, int qflags, char *qprompt)
8b93c638
JM
743{
744}
745#endif
746
9dc5e2a9
AC
747int
748ui_out_is_mi_like_p (struct ui_out *uiout)
749{
750 return uiout->impl->is_mi_like_p;
751}
752
8b93c638
JM
753/* default gdb-out hook functions */
754
755static void
d63f1d40
AC
756default_table_begin (struct ui_out *uiout, int nbrofcols,
757 int nr_rows,
758 const char *tblid)
8b93c638
JM
759{
760}
761
762static void
fba45db2 763default_table_body (struct ui_out *uiout)
8b93c638
JM
764{
765}
766
767static void
fba45db2 768default_table_end (struct ui_out *uiout)
8b93c638
JM
769{
770}
771
772static void
fba45db2 773default_table_header (struct ui_out *uiout, int width, enum ui_align alignment,
b25959ec 774 const char *col_name,
e2e11a41 775 const char *colhdr)
8b93c638
JM
776{
777}
778
779static void
631ec795
AC
780default_begin (struct ui_out *uiout,
781 enum ui_out_type type,
782 int level,
783 const char *id)
8b93c638
JM
784{
785}
786
787static void
631ec795
AC
788default_end (struct ui_out *uiout,
789 enum ui_out_type type,
790 int level)
8b93c638
JM
791{
792}
793
794static void
fba45db2 795default_field_int (struct ui_out *uiout, int fldno, int width,
e2e11a41
AC
796 enum ui_align align,
797 const char *fldname, int value)
8b93c638
JM
798{
799}
800
801static void
fba45db2 802default_field_skip (struct ui_out *uiout, int fldno, int width,
e2e11a41 803 enum ui_align align, const char *fldname)
8b93c638
JM
804{
805}
806
807static void
808default_field_string (struct ui_out *uiout,
809 int fldno,
810 int width,
811 enum ui_align align,
e2e11a41 812 const char *fldname,
8b93c638
JM
813 const char *string)
814{
815}
816
817static void
fba45db2 818default_field_fmt (struct ui_out *uiout, int fldno, int width,
e2e11a41
AC
819 enum ui_align align,
820 const char *fldname,
821 const char *format,
fba45db2 822 va_list args)
8b93c638
JM
823{
824}
825
826static void
fba45db2 827default_spaces (struct ui_out *uiout, int numspaces)
8b93c638
JM
828{
829}
830
831static void
e2e11a41 832default_text (struct ui_out *uiout, const char *string)
8b93c638
JM
833{
834}
835
836static void
e2e11a41
AC
837default_message (struct ui_out *uiout, int verbosity,
838 const char *format,
fba45db2 839 va_list args)
8b93c638
JM
840{
841}
842
843static void
fba45db2 844default_wrap_hint (struct ui_out *uiout, char *identstring)
8b93c638
JM
845{
846}
847
848static void
fba45db2 849default_flush (struct ui_out *uiout)
8b93c638
JM
850{
851}
852
853/* Interface to the implementation functions */
854
855void
88379baf 856uo_table_begin (struct ui_out *uiout, int nbrofcols,
d63f1d40 857 int nr_rows,
88379baf 858 const char *tblid)
8b93c638
JM
859{
860 if (!uiout->impl->table_begin)
861 return;
d63f1d40 862 uiout->impl->table_begin (uiout, nbrofcols, nr_rows, tblid);
8b93c638
JM
863}
864
865void
866uo_table_body (struct ui_out *uiout)
867{
868 if (!uiout->impl->table_body)
869 return;
870 uiout->impl->table_body (uiout);
871}
872
873void
874uo_table_end (struct ui_out *uiout)
875{
876 if (!uiout->impl->table_end)
877 return;
878 uiout->impl->table_end (uiout);
879}
880
881void
88379baf 882uo_table_header (struct ui_out *uiout, int width, enum ui_align align,
b25959ec 883 const char *col_name,
88379baf 884 const char *colhdr)
8b93c638
JM
885{
886 if (!uiout->impl->table_header)
887 return;
b25959ec 888 uiout->impl->table_header (uiout, width, align, col_name, colhdr);
8b93c638
JM
889}
890
891void
631ec795
AC
892uo_begin (struct ui_out *uiout,
893 enum ui_out_type type,
894 int level,
895 const char *id)
8b93c638 896{
631ec795 897 if (uiout->impl->begin == NULL)
8b93c638 898 return;
631ec795 899 uiout->impl->begin (uiout, type, level, id);
8b93c638
JM
900}
901
902void
631ec795
AC
903uo_end (struct ui_out *uiout,
904 enum ui_out_type type,
905 int level)
8b93c638 906{
631ec795 907 if (uiout->impl->end == NULL)
8b93c638 908 return;
631ec795 909 uiout->impl->end (uiout, type, level);
8b93c638
JM
910}
911
912void
88379baf
AC
913uo_field_int (struct ui_out *uiout, int fldno, int width, enum ui_align align,
914 const char *fldname,
915 int value)
8b93c638
JM
916{
917 if (!uiout->impl->field_int)
918 return;
919 uiout->impl->field_int (uiout, fldno, width, align, fldname, value);
920}
921
922void
88379baf
AC
923uo_field_skip (struct ui_out *uiout, int fldno, int width, enum ui_align align,
924 const char *fldname)
8b93c638
JM
925{
926 if (!uiout->impl->field_skip)
927 return;
928 uiout->impl->field_skip (uiout, fldno, width, align, fldname);
929}
930
931void
932uo_field_string (struct ui_out *uiout, int fldno, int width,
88379baf
AC
933 enum ui_align align,
934 const char *fldname,
935 const char *string)
8b93c638
JM
936{
937 if (!uiout->impl->field_string)
938 return;
939 uiout->impl->field_string (uiout, fldno, width, align, fldname, string);
940}
941
942void
88379baf
AC
943uo_field_fmt (struct ui_out *uiout, int fldno, int width, enum ui_align align,
944 const char *fldname,
945 const char *format,
946 va_list args)
8b93c638
JM
947{
948 if (!uiout->impl->field_fmt)
949 return;
950 uiout->impl->field_fmt (uiout, fldno, width, align, fldname, format, args);
951}
952
953void
954uo_spaces (struct ui_out *uiout, int numspaces)
955{
956 if (!uiout->impl->spaces)
957 return;
958 uiout->impl->spaces (uiout, numspaces);
959}
960
961void
88379baf
AC
962uo_text (struct ui_out *uiout,
963 const char *string)
8b93c638
JM
964{
965 if (!uiout->impl->text)
966 return;
967 uiout->impl->text (uiout, string);
968}
969
970void
88379baf
AC
971uo_message (struct ui_out *uiout, int verbosity,
972 const char *format,
973 va_list args)
8b93c638
JM
974{
975 if (!uiout->impl->message)
976 return;
977 uiout->impl->message (uiout, verbosity, format, args);
978}
979
980void
981uo_wrap_hint (struct ui_out *uiout, char *identstring)
982{
983 if (!uiout->impl->wrap_hint)
984 return;
985 uiout->impl->wrap_hint (uiout, identstring);
986}
987
988void
989uo_flush (struct ui_out *uiout)
990{
991 if (!uiout->impl->flush)
992 return;
993 uiout->impl->flush (uiout);
994}
995
0fac0b41
DJ
996int
997uo_redirect (struct ui_out *uiout, struct ui_file *outstream)
998{
999 if (!uiout->impl->redirect)
1000 return -1;
1001 uiout->impl->redirect (uiout, outstream);
1002 return 0;
1003}
1004
8b93c638
JM
1005/* local functions */
1006
1007/* list of column headers manipulation routines */
1008
1009static void
fba45db2 1010clear_header_list (struct ui_out *uiout)
8b93c638 1011{
bafdd3b3 1012 while (uiout->table.header_first != NULL)
8b93c638 1013 {
bafdd3b3
AC
1014 uiout->table.header_next = uiout->table.header_first;
1015 uiout->table.header_first = uiout->table.header_first->next;
1016 if (uiout->table.header_next->colhdr != NULL)
1017 xfree (uiout->table.header_next->colhdr);
1018 xfree (uiout->table.header_next);
8b93c638 1019 }
bafdd3b3
AC
1020 gdb_assert (uiout->table.header_first == NULL);
1021 uiout->table.header_last = NULL;
1022 uiout->table.header_next = NULL;
8b93c638
JM
1023}
1024
1025static void
1026append_header_to_list (struct ui_out *uiout,
1027 int width,
1028 int alignment,
b25959ec 1029 const char *col_name,
88379baf 1030 const char *colhdr)
8b93c638
JM
1031{
1032 struct ui_out_hdr *temphdr;
1033
1034 temphdr = XMALLOC (struct ui_out_hdr);
1035 temphdr->width = width;
1036 temphdr->alignment = alignment;
44db85f8
MS
1037 /* We have to copy the column title as the original may be an
1038 automatic. */
8b93c638 1039 if (colhdr != NULL)
b25959ec
AC
1040 temphdr->colhdr = xstrdup (colhdr);
1041 else
1042 temphdr->colhdr = NULL;
44db85f8 1043
b25959ec 1044 if (col_name != NULL)
44db85f8
MS
1045 temphdr->col_name = xstrdup (col_name);
1046 else if (colhdr != NULL)
b25959ec
AC
1047 temphdr->col_name = xstrdup (colhdr);
1048 else
44db85f8
MS
1049 temphdr->col_name = NULL;
1050
8b93c638 1051 temphdr->next = NULL;
bafdd3b3 1052 if (uiout->table.header_first == NULL)
8b93c638
JM
1053 {
1054 temphdr->colno = 1;
bafdd3b3
AC
1055 uiout->table.header_first = temphdr;
1056 uiout->table.header_last = temphdr;
8b93c638
JM
1057 }
1058 else
1059 {
bafdd3b3
AC
1060 temphdr->colno = uiout->table.header_last->colno + 1;
1061 uiout->table.header_last->next = temphdr;
1062 uiout->table.header_last = temphdr;
8b93c638 1063 }
bafdd3b3 1064 uiout->table.header_next = uiout->table.header_last;
8b93c638
JM
1065}
1066
bafdd3b3
AC
1067/* Extract the format information for the NEXT header and and advance
1068 the header pointer. Return 0 if there was no next header. */
8b93c638
JM
1069
1070static int
bafdd3b3 1071get_next_header (struct ui_out *uiout,
8b93c638
JM
1072 int *colno,
1073 int *width,
1074 int *alignment,
1075 char **colhdr)
1076{
bafdd3b3
AC
1077 /* There may be no headers at all or we may have used all columns. */
1078 if (uiout->table.header_next == NULL)
8b93c638 1079 return 0;
bafdd3b3
AC
1080 *colno = uiout->table.header_next->colno;
1081 *width = uiout->table.header_next->width;
1082 *alignment = uiout->table.header_next->alignment;
1083 *colhdr = uiout->table.header_next->colhdr;
1084 /* Advance the header pointer to the next entry. */
1085 uiout->table.header_next = uiout->table.header_next->next;
8b93c638
JM
1086 return 1;
1087}
1088
a6c47c14
AC
1089
1090/* Verify that the field/tuple/list is correctly positioned. Return
1091 the field number and corresponding alignment (if
1092 available/applicable). */
8b93c638
JM
1093
1094static void
a6c47c14 1095verify_field (struct ui_out *uiout, int *fldno, int *width, int *align)
8b93c638 1096{
a6c47c14
AC
1097 struct ui_out_level *current = current_level (uiout);
1098 char *text;
1099
bafdd3b3 1100 if (uiout->table.flag)
8b93c638 1101 {
bafdd3b3 1102 if (!uiout->table.body_flag)
8e65ff28 1103 internal_error (__FILE__, __LINE__,
e2e0b3e5
AC
1104 _("table_body missing; table fields must be \
1105specified after table_body and inside a list."));
a6c47c14
AC
1106 /* NOTE: cagney/2001-12-08: There was a check here to ensure
1107 that this code was only executed when uiout->level was
1108 greater than zero. That no longer applies - this code is run
1109 before each table row tuple is started and at that point the
1110 level is zero. */
8b93c638 1111 }
8b93c638 1112
a6c47c14 1113 current->field_count += 1;
8b93c638 1114
a6c47c14
AC
1115 if (uiout->table.body_flag
1116 && uiout->table.entry_level == uiout->level
1117 && get_next_header (uiout, fldno, width, align, &text))
8b93c638 1118 {
a6c47c14 1119 if (*fldno != current->field_count)
8e65ff28 1120 internal_error (__FILE__, __LINE__,
e2e0b3e5 1121 _("ui-out internal error in handling headers."));
8b93c638
JM
1122 }
1123 else
1124 {
1125 *width = 0;
1126 *align = ui_noalign;
a6c47c14 1127 *fldno = current->field_count;
8b93c638
JM
1128 }
1129}
1130
a6c47c14 1131
8b93c638
JM
1132/* access to ui_out format private members */
1133
1134void
fba45db2 1135ui_out_get_field_separator (struct ui_out *uiout)
8b93c638
JM
1136{
1137}
1138
1139/* Access to ui-out members data */
1140
1141struct ui_out_data *
1142ui_out_data (struct ui_out *uiout)
1143{
1144 return uiout->data;
1145}
1146
1147/* initalize private members at startup */
1148
1149struct ui_out *
1150ui_out_new (struct ui_out_impl *impl,
1151 struct ui_out_data *data,
1152 int flags)
1153{
1154 struct ui_out *uiout = XMALLOC (struct ui_out);
1155 uiout->data = data;
1156 uiout->impl = impl;
1157 uiout->flags = flags;
bafdd3b3
AC
1158 uiout->table.flag = 0;
1159 uiout->table.body_flag = 0;
80f49b30
AC
1160 uiout->level = 0;
1161 memset (uiout->levels, 0, sizeof (uiout->levels));
bafdd3b3
AC
1162 uiout->table.header_first = NULL;
1163 uiout->table.header_last = NULL;
1164 uiout->table.header_next = NULL;
8b93c638
JM
1165 return uiout;
1166}
1167
1168/* standard gdb initialization hook */
1169
1170void
fba45db2 1171_initialize_ui_out (void)
8b93c638
JM
1172{
1173 /* nothing needs to be done */
1174}
This page took 0.723146 seconds and 4 git commands to generate.