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