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