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