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