Sync config.sub,config.guess with upstream.
[deliverable/binutils-gdb.git] / gdb / ui-out.c
CommitLineData
8b93c638 1/* Output generating routines for GDB.
349c5d5f 2
618f726f 3 Copyright (C) 1999-2016 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
a9762ec7 12 the Free Software Foundation; either version 3 of the License, or
8b93c638
JM
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
a9762ec7 21 along with this program. If not, see <http://www.gnu.org/licenses/>. */
8b93c638
JM
22
23#include "defs.h"
8b93c638
JM
24#include "expression.h" /* For language.h */
25#include "language.h"
26#include "ui-out.h"
27
8b93c638
JM
28/* table header structures */
29
30struct ui_out_hdr
31 {
32 int colno;
33 int width;
f486487f 34 enum ui_align alignment;
b25959ec 35 char *col_name;
8b93c638
JM
36 char *colhdr;
37 struct ui_out_hdr *next;
38 };
39
80f49b30
AC
40struct ui_out_level
41 {
581e13c1 42 /* Count each field; the first element is for non-list fields. */
80f49b30 43 int field_count;
581e13c1 44 /* The type of this level. */
631ec795 45 enum ui_out_type type;
80f49b30
AC
46 };
47
54eb231c
PM
48/* Define uiout->level vector types and operations. */
49typedef struct ui_out_level *ui_out_level_p;
50DEF_VEC_P (ui_out_level_p);
51
bafdd3b3
AC
52/* Tables are special. Maintain a separate structure that tracks
53 their state. At present an output can only contain a single table
54 but that restriction might eventually be lifted. */
55
56struct ui_out_table
57{
58 /* If on, a table is being generated. */
59 int flag;
60
61 /* If on, the body of a table is being generated. If off, the table
62 header is being generated. */
63 int body_flag;
64
a6c47c14
AC
65 /* The level at which each entry of the table is to be found. A row
66 (a tuple) is made up of entries. Consequently ENTRY_LEVEL is one
67 above that of the table. */
68 int entry_level;
69
bafdd3b3
AC
70 /* Number of table columns (as specified in the table_begin call). */
71 int columns;
72
73 /* String identifying the table (as specified in the table_begin
74 call). */
75 char *id;
76
77 /* Points to the first table header (if any). */
78 struct ui_out_hdr *header_first;
79
80 /* Points to the last table header (if any). */
81 struct ui_out_hdr *header_last;
82
83 /* Points to header of NEXT column to format. */
84 struct ui_out_hdr *header_next;
85
86};
87
88
8b93c638
JM
89/* The ui_out structure */
90/* Any change here requires a corresponding one in the initialization
581e13c1 91 of the default uiout, which is statically initialized. */
8b93c638
JM
92
93struct ui_out
94 {
95 int flags;
581e13c1 96 /* Specific implementation of ui-out. */
89de4da4 97 const struct ui_out_impl *impl;
0a8fce9a 98 void *data;
8b93c638 99
54eb231c 100 /* Current level. */
80f49b30 101 int level;
54eb231c
PM
102
103 /* Vector to store and track the ui-out levels. */
104 VEC (ui_out_level_p) *levels;
8b93c638 105
bafdd3b3
AC
106 /* A table, if any. At present only a single table is supported. */
107 struct ui_out_table table;
8b93c638
JM
108 };
109
581e13c1 110/* The current (inner most) level. */
80f49b30
AC
111static struct ui_out_level *
112current_level (struct ui_out *uiout)
113{
54eb231c 114 return VEC_index (ui_out_level_p, uiout->levels, uiout->level);
80f49b30
AC
115}
116
581e13c1 117/* Create a new level, of TYPE. Return the new level's index. */
80f49b30
AC
118static int
119push_level (struct ui_out *uiout,
49d06418 120 enum ui_out_type type)
80f49b30
AC
121{
122 struct ui_out_level *current;
5d502164 123
80f49b30 124 uiout->level++;
70ba0933 125 current = XNEW (struct ui_out_level);
80f49b30 126 current->field_count = 0;
631ec795 127 current->type = type;
54eb231c 128 VEC_safe_push (ui_out_level_p, uiout->levels, current);
80f49b30
AC
129 return uiout->level;
130}
131
132/* Discard the current level, return the discarded level's index.
581e13c1 133 TYPE is the type of the level being discarded. */
80f49b30 134static int
631ec795
AC
135pop_level (struct ui_out *uiout,
136 enum ui_out_type type)
80f49b30 137{
54eb231c
PM
138 struct ui_out_level *current;
139
581e13c1 140 /* We had better not underflow the buffer. */
54eb231c 141 gdb_assert (uiout->level > 0);
631ec795 142 gdb_assert (current_level (uiout)->type == type);
54eb231c
PM
143 current = VEC_pop (ui_out_level_p, uiout->levels);
144 xfree (current);
80f49b30
AC
145 uiout->level--;
146 return uiout->level + 1;
147}
148
581e13c1 149/* These are the interfaces to implementation functions. */
8b93c638 150
88379baf 151static void uo_table_begin (struct ui_out *uiout, int nbrofcols,
d63f1d40 152 int nr_rows, const char *tblid);
8b93c638
JM
153static void uo_table_body (struct ui_out *uiout);
154static void uo_table_end (struct ui_out *uiout);
155static void uo_table_header (struct ui_out *uiout, int width,
b25959ec
AC
156 enum ui_align align, const char *col_name,
157 const char *colhdr);
631ec795
AC
158static void uo_begin (struct ui_out *uiout,
159 enum ui_out_type type,
160 int level, const char *id);
161static void uo_end (struct ui_out *uiout,
162 enum ui_out_type type,
163 int level);
8b93c638 164static void uo_field_int (struct ui_out *uiout, int fldno, int width,
88379baf 165 enum ui_align align, const char *fldname, int value);
8b93c638 166static void uo_field_skip (struct ui_out *uiout, int fldno, int width,
88379baf 167 enum ui_align align, const char *fldname);
8b93c638 168static void uo_field_fmt (struct ui_out *uiout, int fldno, int width,
88379baf 169 enum ui_align align, const char *fldname,
bee0189a 170 const char *format, va_list args)
a0b31db1 171 ATTRIBUTE_PRINTF (6, 0);
8b93c638 172static void uo_spaces (struct ui_out *uiout, int numspaces);
88379baf 173static void uo_text (struct ui_out *uiout, const char *string);
8b93c638 174static void uo_message (struct ui_out *uiout, int verbosity,
bee0189a 175 const char *format, va_list args)
a0b31db1 176 ATTRIBUTE_PRINTF (3, 0);
8b93c638
JM
177static void uo_wrap_hint (struct ui_out *uiout, char *identstring);
178static void uo_flush (struct ui_out *uiout);
0fac0b41 179static int uo_redirect (struct ui_out *uiout, struct ui_file *outstream);
b65a2bd9 180static void uo_data_destroy (struct ui_out *uiout);
8b93c638
JM
181
182/* Prototypes for local functions */
183
184extern void _initialize_ui_out (void);
88379baf 185static void append_header_to_list (struct ui_out *uiout, int width,
f486487f 186 enum ui_align alignment, const char *col_name,
b25959ec 187 const char *colhdr);
bafdd3b3 188static int get_next_header (struct ui_out *uiout, int *colno, int *width,
f486487f 189 enum ui_align *alignment, char **colhdr);
8b93c638 190static void clear_header_list (struct ui_out *uiout);
b65a2bd9 191static void clear_table (struct ui_out *uiout);
a6c47c14 192static void verify_field (struct ui_out *uiout, int *fldno, int *width,
f486487f 193 enum ui_align *align);
8b93c638 194
8b93c638
JM
195/* exported functions (ui_out API) */
196
581e13c1 197/* Mark beginning of a table. */
8b93c638 198
3b31d625 199static void
88379baf 200ui_out_table_begin (struct ui_out *uiout, int nbrofcols,
d63f1d40 201 int nr_rows,
88379baf 202 const char *tblid)
8b93c638 203{
bafdd3b3 204 if (uiout->table.flag)
8e65ff28 205 internal_error (__FILE__, __LINE__,
e2e0b3e5
AC
206 _("tables cannot be nested; table_begin found before \
207previous table_end."));
8b93c638 208
bafdd3b3
AC
209 uiout->table.flag = 1;
210 uiout->table.body_flag = 0;
a6c47c14 211 uiout->table.entry_level = uiout->level + 1;
bafdd3b3 212 uiout->table.columns = nbrofcols;
8b93c638 213 if (tblid != NULL)
bafdd3b3 214 uiout->table.id = xstrdup (tblid);
8b93c638 215 else
bafdd3b3 216 uiout->table.id = NULL;
8b93c638
JM
217 clear_header_list (uiout);
218
bafdd3b3 219 uo_table_begin (uiout, nbrofcols, nr_rows, uiout->table.id);
8b93c638
JM
220}
221
222void
fba45db2 223ui_out_table_body (struct ui_out *uiout)
8b93c638 224{
bafdd3b3 225 if (!uiout->table.flag)
8e65ff28 226 internal_error (__FILE__, __LINE__,
e2e0b3e5
AC
227 _("table_body outside a table is not valid; it must be \
228after a table_begin and before a table_end."));
bafdd3b3 229 if (uiout->table.body_flag)
8e65ff28 230 internal_error (__FILE__, __LINE__,
e2e0b3e5
AC
231 _("extra table_body call not allowed; there must be \
232only one table_body after a table_begin and before a table_end."));
bafdd3b3 233 if (uiout->table.header_next->colno != uiout->table.columns)
8e65ff28 234 internal_error (__FILE__, __LINE__,
e2e0b3e5
AC
235 _("number of headers differ from number of table \
236columns."));
8b93c638 237
bafdd3b3
AC
238 uiout->table.body_flag = 1;
239 uiout->table.header_next = uiout->table.header_first;
8b93c638
JM
240
241 uo_table_body (uiout);
242}
243
3b31d625 244static void
fba45db2 245ui_out_table_end (struct ui_out *uiout)
8b93c638 246{
bafdd3b3 247 if (!uiout->table.flag)
8e65ff28 248 internal_error (__FILE__, __LINE__,
e2e0b3e5 249 _("misplaced table_end or missing table_begin."));
8b93c638 250
a6c47c14 251 uiout->table.entry_level = 0;
bafdd3b3
AC
252 uiout->table.body_flag = 0;
253 uiout->table.flag = 0;
8b93c638
JM
254
255 uo_table_end (uiout);
b65a2bd9 256 clear_table (uiout);
8b93c638
JM
257}
258
259void
fba45db2 260ui_out_table_header (struct ui_out *uiout, int width, enum ui_align alignment,
b25959ec 261 const char *col_name,
88379baf 262 const char *colhdr)
8b93c638 263{
bafdd3b3 264 if (!uiout->table.flag || uiout->table.body_flag)
8e65ff28 265 internal_error (__FILE__, __LINE__,
e2e0b3e5
AC
266 _("table header must be specified after table_begin \
267and before table_body."));
8b93c638 268
b25959ec 269 append_header_to_list (uiout, width, alignment, col_name, colhdr);
8b93c638 270
b25959ec 271 uo_table_header (uiout, width, alignment, col_name, colhdr);
8b93c638
JM
272}
273
3b31d625
EZ
274static void
275do_cleanup_table_end (void *data)
276{
19ba03f4 277 struct ui_out *ui_out = (struct ui_out *) data;
3b31d625
EZ
278
279 ui_out_table_end (ui_out);
280}
281
282struct cleanup *
283make_cleanup_ui_out_table_begin_end (struct ui_out *ui_out, int nr_cols,
284 int nr_rows, const char *tblid)
285{
286 ui_out_table_begin (ui_out, nr_cols, nr_rows, tblid);
287 return make_cleanup (do_cleanup_table_end, ui_out);
288}
289
8b93c638 290void
631ec795
AC
291ui_out_begin (struct ui_out *uiout,
292 enum ui_out_type type,
293 const char *id)
8b93c638 294{
80f49b30 295 int new_level;
5d502164 296
bafdd3b3 297 if (uiout->table.flag && !uiout->table.body_flag)
8e65ff28 298 internal_error (__FILE__, __LINE__,
e2e0b3e5
AC
299 _("table header or table_body expected; lists must be \
300specified after table_body."));
a6c47c14
AC
301
302 /* Be careful to verify the ``field'' before the new tuple/list is
303 pushed onto the stack. That way the containing list/table/row is
304 verified and not the newly created tuple/list. This verification
305 is needed (at least) for the case where a table row entry
306 contains either a tuple/list. For that case bookkeeping such as
307 updating the column count or advancing to the next heading still
308 needs to be performed. */
309 {
310 int fldno;
311 int width;
f486487f 312 enum ui_align align;
5d502164 313
a6c47c14
AC
314 verify_field (uiout, &fldno, &width, &align);
315 }
316
49d06418 317 new_level = push_level (uiout, type);
a6c47c14
AC
318
319 /* If the push puts us at the same level as a table row entry, we've
320 got a new table row. Put the header pointer back to the start. */
321 if (uiout->table.body_flag
322 && uiout->table.entry_level == new_level)
bafdd3b3 323 uiout->table.header_next = uiout->table.header_first;
a6c47c14 324
631ec795
AC
325 uo_begin (uiout, type, new_level, id);
326}
327
631ec795
AC
328void
329ui_out_end (struct ui_out *uiout,
330 enum ui_out_type type)
331{
332 int old_level = pop_level (uiout, type);
5d502164 333
631ec795 334 uo_end (uiout, type, old_level);
8b93c638
JM
335}
336
127431f9
AC
337struct ui_out_end_cleanup_data
338{
339 struct ui_out *uiout;
340 enum ui_out_type type;
341};
342
e6e0bfab 343static void
127431f9
AC
344do_cleanup_end (void *data)
345{
19ba03f4
SM
346 struct ui_out_end_cleanup_data *end_cleanup_data
347 = (struct ui_out_end_cleanup_data *) data;
5d502164 348
127431f9
AC
349 ui_out_end (end_cleanup_data->uiout, end_cleanup_data->type);
350 xfree (end_cleanup_data);
351}
352
353static struct cleanup *
354make_cleanup_ui_out_end (struct ui_out *uiout,
355 enum ui_out_type type)
356{
357 struct ui_out_end_cleanup_data *end_cleanup_data;
5d502164 358
70ba0933 359 end_cleanup_data = XNEW (struct ui_out_end_cleanup_data);
127431f9
AC
360 end_cleanup_data->uiout = uiout;
361 end_cleanup_data->type = type;
362 return make_cleanup (do_cleanup_end, end_cleanup_data);
363}
364
e6e0bfab 365struct cleanup *
666547aa
AC
366make_cleanup_ui_out_tuple_begin_end (struct ui_out *uiout,
367 const char *id)
368{
3b31d625 369 ui_out_begin (uiout, ui_out_type_tuple, id);
666547aa
AC
370 return make_cleanup_ui_out_end (uiout, ui_out_type_tuple);
371}
372
373struct cleanup *
6b28c186
AC
374make_cleanup_ui_out_list_begin_end (struct ui_out *uiout,
375 const char *id)
e6e0bfab 376{
3b31d625 377 ui_out_begin (uiout, ui_out_type_list, id);
127431f9 378 return make_cleanup_ui_out_end (uiout, ui_out_type_list);
e6e0bfab
MK
379}
380
8b93c638 381void
88379baf
AC
382ui_out_field_int (struct ui_out *uiout,
383 const char *fldname,
384 int value)
8b93c638
JM
385{
386 int fldno;
387 int width;
f486487f 388 enum ui_align align;
8b93c638 389
a6c47c14 390 verify_field (uiout, &fldno, &width, &align);
8b93c638
JM
391
392 uo_field_int (uiout, fldno, width, align, fldname, value);
393}
394
52c6a6ac
JJ
395void
396ui_out_field_fmt_int (struct ui_out *uiout,
397 int input_width,
398 enum ui_align input_align,
399 const char *fldname,
400 int value)
401{
402 int fldno;
403 int width;
f486487f 404 enum ui_align align;
52c6a6ac
JJ
405
406 verify_field (uiout, &fldno, &width, &align);
407
408 uo_field_int (uiout, fldno, input_width, input_align, fldname, value);
409}
410
15230f37
TJB
411/* Documented in ui-out.h. */
412
8b93c638 413void
88379baf
AC
414ui_out_field_core_addr (struct ui_out *uiout,
415 const char *fldname,
5af949e3 416 struct gdbarch *gdbarch,
88379baf 417 CORE_ADDR address)
8b93c638 418{
f1310107
TJB
419 ui_out_field_string (uiout, fldname,
420 print_core_address (gdbarch, address));
8b93c638
JM
421}
422
423void
88379baf
AC
424ui_out_field_stream (struct ui_out *uiout,
425 const char *fldname,
f99d8bf4 426 struct ui_file *stream)
8b93c638
JM
427{
428 long length;
f99d8bf4 429 char *buffer = ui_file_xstrdup (stream, &length);
b8c9b27d 430 struct cleanup *old_cleanup = make_cleanup (xfree, buffer);
5d502164 431
8b93c638
JM
432 if (length > 0)
433 ui_out_field_string (uiout, fldname, buffer);
434 else
435 ui_out_field_skip (uiout, fldname);
f99d8bf4 436 ui_file_rewind (stream);
8b93c638
JM
437 do_cleanups (old_cleanup);
438}
439
581e13c1 440/* Used to omit a field. */
8b93c638
JM
441
442void
88379baf
AC
443ui_out_field_skip (struct ui_out *uiout,
444 const char *fldname)
8b93c638
JM
445{
446 int fldno;
447 int width;
f486487f 448 enum ui_align align;
8b93c638 449
a6c47c14 450 verify_field (uiout, &fldno, &width, &align);
8b93c638
JM
451
452 uo_field_skip (uiout, fldno, width, align, fldname);
453}
454
455void
456ui_out_field_string (struct ui_out *uiout,
88379baf 457 const char *fldname,
8b93c638
JM
458 const char *string)
459{
460 int fldno;
461 int width;
f486487f 462 enum ui_align align;
8b93c638 463
a6c47c14 464 verify_field (uiout, &fldno, &width, &align);
8b93c638
JM
465
466 uo_field_string (uiout, fldno, width, align, fldname, string);
467}
468
469/* VARARGS */
470void
88379baf
AC
471ui_out_field_fmt (struct ui_out *uiout,
472 const char *fldname,
473 const char *format, ...)
8b93c638
JM
474{
475 va_list args;
476 int fldno;
477 int width;
f486487f 478 enum ui_align align;
8b93c638 479
581e13c1 480 /* Will not align, but has to call anyway. */
a6c47c14 481 verify_field (uiout, &fldno, &width, &align);
8b93c638
JM
482
483 va_start (args, format);
484
485 uo_field_fmt (uiout, fldno, width, align, fldname, format, args);
486
487 va_end (args);
488}
489
490void
fba45db2 491ui_out_spaces (struct ui_out *uiout, int numspaces)
8b93c638
JM
492{
493 uo_spaces (uiout, numspaces);
494}
495
496void
88379baf
AC
497ui_out_text (struct ui_out *uiout,
498 const char *string)
8b93c638
JM
499{
500 uo_text (uiout, string);
501}
502
503void
88379baf
AC
504ui_out_message (struct ui_out *uiout, int verbosity,
505 const char *format,...)
8b93c638
JM
506{
507 va_list args;
508
509 va_start (args, format);
8b93c638 510 uo_message (uiout, verbosity, format, args);
8b93c638
JM
511 va_end (args);
512}
513
8b93c638 514void
fba45db2 515ui_out_wrap_hint (struct ui_out *uiout, char *identstring)
8b93c638
JM
516{
517 uo_wrap_hint (uiout, identstring);
518}
519
520void
fba45db2 521ui_out_flush (struct ui_out *uiout)
8b93c638
JM
522{
523 uo_flush (uiout);
524}
525
0fac0b41
DJ
526int
527ui_out_redirect (struct ui_out *uiout, struct ui_file *outstream)
528{
529 return uo_redirect (uiout, outstream);
530}
531
581e13c1 532/* Set the flags specified by the mask given. */
8b93c638 533int
fba45db2 534ui_out_set_flags (struct ui_out *uiout, int mask)
8b93c638 535{
5bfb05ca 536 int oldflags = uiout->flags;
8b93c638 537
b8d86de3 538 uiout->flags |= mask;
8b93c638
JM
539 return oldflags;
540}
541
581e13c1 542/* Clear the flags specified by the mask given. */
8b93c638 543int
fba45db2 544ui_out_clear_flags (struct ui_out *uiout, int mask)
8b93c638 545{
5bfb05ca 546 int oldflags = uiout->flags;
8b93c638
JM
547
548 uiout->flags &= ~mask;
8b93c638
JM
549 return oldflags;
550}
551
581e13c1 552/* Test the flags against the mask given. */
8b93c638 553int
fba45db2 554ui_out_test_flags (struct ui_out *uiout, int mask)
8b93c638
JM
555{
556 return (uiout->flags & mask);
557}
558
581e13c1
MS
559/* Obtain the current verbosity level (as stablished by the
560 'set verbositylevel' command. */
8b93c638
JM
561
562int
fba45db2 563ui_out_get_verblvl (struct ui_out *uiout)
8b93c638 564{
581e13c1 565 /* FIXME: not implemented yet. */
8b93c638
JM
566 return 0;
567}
568
9dc5e2a9
AC
569int
570ui_out_is_mi_like_p (struct ui_out *uiout)
571{
572 return uiout->impl->is_mi_like_p;
573}
574
581e13c1 575/* Interface to the implementation functions. */
8b93c638
JM
576
577void
88379baf 578uo_table_begin (struct ui_out *uiout, int nbrofcols,
d63f1d40 579 int nr_rows,
88379baf 580 const char *tblid)
8b93c638
JM
581{
582 if (!uiout->impl->table_begin)
583 return;
d63f1d40 584 uiout->impl->table_begin (uiout, nbrofcols, nr_rows, tblid);
8b93c638
JM
585}
586
587void
588uo_table_body (struct ui_out *uiout)
589{
590 if (!uiout->impl->table_body)
591 return;
592 uiout->impl->table_body (uiout);
593}
594
595void
596uo_table_end (struct ui_out *uiout)
597{
598 if (!uiout->impl->table_end)
599 return;
600 uiout->impl->table_end (uiout);
601}
602
603void
88379baf 604uo_table_header (struct ui_out *uiout, int width, enum ui_align align,
b25959ec 605 const char *col_name,
88379baf 606 const char *colhdr)
8b93c638
JM
607{
608 if (!uiout->impl->table_header)
609 return;
b25959ec 610 uiout->impl->table_header (uiout, width, align, col_name, colhdr);
8b93c638
JM
611}
612
b65a2bd9
SCR
613/* Clear the table associated with UIOUT. */
614
615static void
616clear_table (struct ui_out *uiout)
617{
9c1fcd01
TT
618 xfree (uiout->table.id);
619 uiout->table.id = NULL;
b65a2bd9
SCR
620 clear_header_list (uiout);
621}
622
8b93c638 623void
631ec795
AC
624uo_begin (struct ui_out *uiout,
625 enum ui_out_type type,
626 int level,
627 const char *id)
8b93c638 628{
631ec795 629 if (uiout->impl->begin == NULL)
8b93c638 630 return;
631ec795 631 uiout->impl->begin (uiout, type, level, id);
8b93c638
JM
632}
633
634void
631ec795
AC
635uo_end (struct ui_out *uiout,
636 enum ui_out_type type,
637 int level)
8b93c638 638{
631ec795 639 if (uiout->impl->end == NULL)
8b93c638 640 return;
631ec795 641 uiout->impl->end (uiout, type, level);
8b93c638
JM
642}
643
644void
88379baf
AC
645uo_field_int (struct ui_out *uiout, int fldno, int width, enum ui_align align,
646 const char *fldname,
647 int value)
8b93c638
JM
648{
649 if (!uiout->impl->field_int)
650 return;
651 uiout->impl->field_int (uiout, fldno, width, align, fldname, value);
652}
653
654void
88379baf
AC
655uo_field_skip (struct ui_out *uiout, int fldno, int width, enum ui_align align,
656 const char *fldname)
8b93c638
JM
657{
658 if (!uiout->impl->field_skip)
659 return;
660 uiout->impl->field_skip (uiout, fldno, width, align, fldname);
661}
662
663void
664uo_field_string (struct ui_out *uiout, int fldno, int width,
88379baf
AC
665 enum ui_align align,
666 const char *fldname,
667 const char *string)
8b93c638
JM
668{
669 if (!uiout->impl->field_string)
670 return;
671 uiout->impl->field_string (uiout, fldno, width, align, fldname, string);
672}
673
674void
88379baf
AC
675uo_field_fmt (struct ui_out *uiout, int fldno, int width, enum ui_align align,
676 const char *fldname,
677 const char *format,
678 va_list args)
8b93c638
JM
679{
680 if (!uiout->impl->field_fmt)
681 return;
682 uiout->impl->field_fmt (uiout, fldno, width, align, fldname, format, args);
683}
684
685void
686uo_spaces (struct ui_out *uiout, int numspaces)
687{
688 if (!uiout->impl->spaces)
689 return;
690 uiout->impl->spaces (uiout, numspaces);
691}
692
693void
88379baf
AC
694uo_text (struct ui_out *uiout,
695 const char *string)
8b93c638
JM
696{
697 if (!uiout->impl->text)
698 return;
699 uiout->impl->text (uiout, string);
700}
701
702void
88379baf
AC
703uo_message (struct ui_out *uiout, int verbosity,
704 const char *format,
705 va_list args)
8b93c638
JM
706{
707 if (!uiout->impl->message)
708 return;
709 uiout->impl->message (uiout, verbosity, format, args);
710}
711
712void
713uo_wrap_hint (struct ui_out *uiout, char *identstring)
714{
715 if (!uiout->impl->wrap_hint)
716 return;
717 uiout->impl->wrap_hint (uiout, identstring);
718}
719
720void
721uo_flush (struct ui_out *uiout)
722{
723 if (!uiout->impl->flush)
724 return;
725 uiout->impl->flush (uiout);
726}
727
0fac0b41
DJ
728int
729uo_redirect (struct ui_out *uiout, struct ui_file *outstream)
730{
731 if (!uiout->impl->redirect)
732 return -1;
733 uiout->impl->redirect (uiout, outstream);
734 return 0;
735}
736
b65a2bd9
SCR
737void
738uo_data_destroy (struct ui_out *uiout)
739{
740 if (!uiout->impl->data_destroy)
741 return;
742
743 uiout->impl->data_destroy (uiout);
744}
745
8b93c638
JM
746/* local functions */
747
581e13c1 748/* List of column headers manipulation routines. */
8b93c638
JM
749
750static void
fba45db2 751clear_header_list (struct ui_out *uiout)
8b93c638 752{
bafdd3b3 753 while (uiout->table.header_first != NULL)
8b93c638 754 {
bafdd3b3
AC
755 uiout->table.header_next = uiout->table.header_first;
756 uiout->table.header_first = uiout->table.header_first->next;
71bdabee
KS
757 xfree (uiout->table.header_next->colhdr);
758 xfree (uiout->table.header_next->col_name);
bafdd3b3 759 xfree (uiout->table.header_next);
8b93c638 760 }
bafdd3b3
AC
761 gdb_assert (uiout->table.header_first == NULL);
762 uiout->table.header_last = NULL;
763 uiout->table.header_next = NULL;
8b93c638
JM
764}
765
766static void
767append_header_to_list (struct ui_out *uiout,
768 int width,
f486487f 769 enum ui_align alignment,
b25959ec 770 const char *col_name,
88379baf 771 const char *colhdr)
8b93c638
JM
772{
773 struct ui_out_hdr *temphdr;
774
70ba0933 775 temphdr = XNEW (struct ui_out_hdr);
8b93c638
JM
776 temphdr->width = width;
777 temphdr->alignment = alignment;
44db85f8
MS
778 /* We have to copy the column title as the original may be an
779 automatic. */
8b93c638 780 if (colhdr != NULL)
b25959ec
AC
781 temphdr->colhdr = xstrdup (colhdr);
782 else
783 temphdr->colhdr = NULL;
44db85f8 784
b25959ec 785 if (col_name != NULL)
44db85f8
MS
786 temphdr->col_name = xstrdup (col_name);
787 else if (colhdr != NULL)
b25959ec
AC
788 temphdr->col_name = xstrdup (colhdr);
789 else
44db85f8
MS
790 temphdr->col_name = NULL;
791
8b93c638 792 temphdr->next = NULL;
bafdd3b3 793 if (uiout->table.header_first == NULL)
8b93c638
JM
794 {
795 temphdr->colno = 1;
bafdd3b3
AC
796 uiout->table.header_first = temphdr;
797 uiout->table.header_last = temphdr;
8b93c638
JM
798 }
799 else
800 {
bafdd3b3
AC
801 temphdr->colno = uiout->table.header_last->colno + 1;
802 uiout->table.header_last->next = temphdr;
803 uiout->table.header_last = temphdr;
8b93c638 804 }
bafdd3b3 805 uiout->table.header_next = uiout->table.header_last;
8b93c638
JM
806}
807
7a9dd1b2 808/* Extract the format information for the NEXT header and advance
bafdd3b3 809 the header pointer. Return 0 if there was no next header. */
8b93c638
JM
810
811static int
bafdd3b3 812get_next_header (struct ui_out *uiout,
8b93c638
JM
813 int *colno,
814 int *width,
f486487f 815 enum ui_align *alignment,
8b93c638
JM
816 char **colhdr)
817{
bafdd3b3
AC
818 /* There may be no headers at all or we may have used all columns. */
819 if (uiout->table.header_next == NULL)
8b93c638 820 return 0;
bafdd3b3
AC
821 *colno = uiout->table.header_next->colno;
822 *width = uiout->table.header_next->width;
823 *alignment = uiout->table.header_next->alignment;
824 *colhdr = uiout->table.header_next->colhdr;
825 /* Advance the header pointer to the next entry. */
826 uiout->table.header_next = uiout->table.header_next->next;
8b93c638
JM
827 return 1;
828}
829
a6c47c14
AC
830
831/* Verify that the field/tuple/list is correctly positioned. Return
832 the field number and corresponding alignment (if
833 available/applicable). */
8b93c638
JM
834
835static void
f486487f
SM
836verify_field (struct ui_out *uiout, int *fldno, int *width,
837 enum ui_align *align)
8b93c638 838{
a6c47c14
AC
839 struct ui_out_level *current = current_level (uiout);
840 char *text;
841
bafdd3b3 842 if (uiout->table.flag)
8b93c638 843 {
bafdd3b3 844 if (!uiout->table.body_flag)
8e65ff28 845 internal_error (__FILE__, __LINE__,
e2e0b3e5
AC
846 _("table_body missing; table fields must be \
847specified after table_body and inside a list."));
a6c47c14
AC
848 /* NOTE: cagney/2001-12-08: There was a check here to ensure
849 that this code was only executed when uiout->level was
850 greater than zero. That no longer applies - this code is run
851 before each table row tuple is started and at that point the
852 level is zero. */
8b93c638 853 }
8b93c638 854
a6c47c14 855 current->field_count += 1;
8b93c638 856
a6c47c14
AC
857 if (uiout->table.body_flag
858 && uiout->table.entry_level == uiout->level
859 && get_next_header (uiout, fldno, width, align, &text))
8b93c638 860 {
a6c47c14 861 if (*fldno != current->field_count)
8e65ff28 862 internal_error (__FILE__, __LINE__,
e2e0b3e5 863 _("ui-out internal error in handling headers."));
8b93c638
JM
864 }
865 else
866 {
867 *width = 0;
868 *align = ui_noalign;
a6c47c14 869 *fldno = current->field_count;
8b93c638
JM
870 }
871}
872
a6c47c14 873
581e13c1 874/* Access to ui-out members data. */
8b93c638 875
0a8fce9a 876void *
8b93c638
JM
877ui_out_data (struct ui_out *uiout)
878{
879 return uiout->data;
880}
881
170b53b2
UW
882/* Access table field parameters. */
883int
884ui_out_query_field (struct ui_out *uiout, int colno,
885 int *width, int *alignment, char **col_name)
886{
887 struct ui_out_hdr *hdr;
888
889 if (!uiout->table.flag)
890 return 0;
891
892 for (hdr = uiout->table.header_first; hdr; hdr = hdr->next)
893 if (hdr->colno == colno)
894 {
895 *width = hdr->width;
896 *alignment = hdr->alignment;
897 *col_name = hdr->col_name;
898 return 1;
899 }
900
901 return 0;
902}
903
26c4b26f 904/* Initialize private members at startup. */
8b93c638
JM
905
906struct ui_out *
89de4da4 907ui_out_new (const struct ui_out_impl *impl, void *data,
8b93c638
JM
908 int flags)
909{
70ba0933
TT
910 struct ui_out *uiout = XNEW (struct ui_out);
911 struct ui_out_level *current = XNEW (struct ui_out_level);
5d502164 912
8b93c638
JM
913 uiout->data = data;
914 uiout->impl = impl;
915 uiout->flags = flags;
bafdd3b3
AC
916 uiout->table.flag = 0;
917 uiout->table.body_flag = 0;
80f49b30 918 uiout->level = 0;
54eb231c
PM
919 uiout->levels = NULL;
920
921 /* Create uiout->level 0, the default level. */
922 current->type = ui_out_type_tuple;
923 current->field_count = 0;
924 VEC_safe_push (ui_out_level_p, uiout->levels, current);
925
9c1fcd01 926 uiout->table.id = NULL;
bafdd3b3
AC
927 uiout->table.header_first = NULL;
928 uiout->table.header_last = NULL;
929 uiout->table.header_next = NULL;
8b93c638
JM
930 return uiout;
931}
932
b65a2bd9
SCR
933/* Free UIOUT and the memory areas it references. */
934
935void
936ui_out_destroy (struct ui_out *uiout)
937{
54eb231c
PM
938 int i;
939 struct ui_out_level *current;
940
941 /* Make sure that all levels are freed in the case where levels have
942 been pushed, but not popped before the ui_out object is
943 destroyed. */
944 for (i = 0;
945 VEC_iterate (ui_out_level_p, uiout->levels, i, current);
946 ++i)
947 xfree (current);
948
949 VEC_free (ui_out_level_p, uiout->levels);
b65a2bd9
SCR
950 uo_data_destroy (uiout);
951 clear_table (uiout);
952 xfree (uiout);
953}
954
581e13c1 955/* Standard gdb initialization hook. */
8b93c638
JM
956
957void
fba45db2 958_initialize_ui_out (void)
8b93c638
JM
959{
960 /* nothing needs to be done */
961}
This page took 1.904752 seconds and 4 git commands to generate.