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