* ui-out.c (struct ui_out_table): Add field entry_level.
[deliverable/binutils-gdb.git] / gdb / ui-out.c
1 /* Output generating routines for GDB.
2 Copyright 1999, 2000, 2001 Free Software Foundation, Inc.
3 Contributed by Cygnus Solutions.
4 Written by Fernando Nasser for Cygnus.
5
6 This file is part of GDB.
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
22
23 #include "defs.h"
24 #include "gdb_string.h"
25 #include "expression.h" /* For language.h */
26 #include "language.h"
27 #include "ui-out.h"
28 #include "gdb_assert.h"
29
30 /* Convenience macro for allocting typesafe memory. */
31
32 #undef XMALLOC
33 #define XMALLOC(TYPE) (TYPE*) xmalloc (sizeof (TYPE))
34
35 /* table header structures */
36
37 struct ui_out_hdr
38 {
39 int colno;
40 int width;
41 int alignment;
42 char *col_name;
43 char *colhdr;
44 struct ui_out_hdr *next;
45 };
46
47 /* Maintain a stack so that the info applicable to the inner most list
48 is always available. Stack/nested level 0 is reserved for the
49 top-level result. */
50
51 enum { MAX_UI_OUT_LEVELS = 5 };
52
53 struct ui_out_level
54 {
55 /* Count each field; the first element is for non-list fields */
56 int field_count;
57 /* The type of this level. */
58 enum ui_out_type type;
59 };
60
61 /* Tables are special. Maintain a separate structure that tracks
62 their state. At present an output can only contain a single table
63 but that restriction might eventually be lifted. */
64
65 struct ui_out_table
66 {
67 /* If on, a table is being generated. */
68 int flag;
69
70 /* If on, the body of a table is being generated. If off, the table
71 header is being generated. */
72 int body_flag;
73
74 /* The level at which each entry of the table is to be found. A row
75 (a tuple) is made up of entries. Consequently ENTRY_LEVEL is one
76 above that of the table. */
77 int entry_level;
78
79 /* Number of table columns (as specified in the table_begin call). */
80 int columns;
81
82 /* String identifying the table (as specified in the table_begin
83 call). */
84 char *id;
85
86 /* Points to the first table header (if any). */
87 struct ui_out_hdr *header_first;
88
89 /* Points to the last table header (if any). */
90 struct ui_out_hdr *header_last;
91
92 /* Points to header of NEXT column to format. */
93 struct ui_out_hdr *header_next;
94
95 };
96
97
98 /* The ui_out structure */
99 /* Any change here requires a corresponding one in the initialization
100 of the default uiout, which is statically initialized */
101
102 struct ui_out
103 {
104 int flags;
105 /* specific implementation of ui-out */
106 struct ui_out_impl *impl;
107 struct ui_out_data *data;
108
109 /* Sub structure tracking the ui-out depth. */
110 int level;
111 struct ui_out_level levels[MAX_UI_OUT_LEVELS];
112
113 /* A table, if any. At present only a single table is supported. */
114 struct ui_out_table table;
115 };
116
117 /* The current (inner most) level. */
118 static struct ui_out_level *
119 current_level (struct ui_out *uiout)
120 {
121 return &uiout->levels[uiout->level];
122 }
123
124 /* Create a new level, of TYPE. Return the new level's index. */
125 static int
126 push_level (struct ui_out *uiout,
127 enum ui_out_type type,
128 const char *id)
129 {
130 struct ui_out_level *current;
131 /* We had better not overflow the buffer. */
132 uiout->level++;
133 gdb_assert (uiout->level >= 0 && uiout->level < MAX_UI_OUT_LEVELS);
134 current = current_level (uiout);
135 current->field_count = 0;
136 current->type = type;
137 return uiout->level;
138 }
139
140 /* Discard the current level, return the discarded level's index.
141 TYPE is the type of the level being discarded. */
142 static int
143 pop_level (struct ui_out *uiout,
144 enum ui_out_type type)
145 {
146 /* We had better not underflow the buffer. */
147 gdb_assert (uiout->level > 0 && uiout->level < MAX_UI_OUT_LEVELS);
148 gdb_assert (current_level (uiout)->type == type);
149 uiout->level--;
150 return uiout->level + 1;
151 }
152
153
154 /* These are the default implementation functions */
155
156 static void default_table_begin (struct ui_out *uiout, int nbrofcols,
157 int nr_rows, const char *tblid);
158 static void default_table_body (struct ui_out *uiout);
159 static void default_table_end (struct ui_out *uiout);
160 static void default_table_header (struct ui_out *uiout, int width,
161 enum ui_align alig, const char *col_name,
162 const char *colhdr);
163 static void default_begin (struct ui_out *uiout,
164 enum ui_out_type type,
165 int level, const char *id);
166 static void default_end (struct ui_out *uiout,
167 enum ui_out_type type,
168 int level);
169 static void default_field_int (struct ui_out *uiout, int fldno, int width,
170 enum ui_align alig,
171 const char *fldname,
172 int value);
173 static void default_field_skip (struct ui_out *uiout, int fldno, int width,
174 enum ui_align alig,
175 const char *fldname);
176 static void default_field_string (struct ui_out *uiout, int fldno, int width,
177 enum ui_align align,
178 const char *fldname,
179 const char *string);
180 static void default_field_fmt (struct ui_out *uiout, int fldno,
181 int width, enum ui_align align,
182 const char *fldname,
183 const char *format,
184 va_list args);
185 static void default_spaces (struct ui_out *uiout, int numspaces);
186 static void default_text (struct ui_out *uiout, const char *string);
187 static void default_message (struct ui_out *uiout, int verbosity,
188 const char *format,
189 va_list args);
190 static void default_wrap_hint (struct ui_out *uiout, char *identstring);
191 static void default_flush (struct ui_out *uiout);
192
193 /* This is the default ui-out implementation functions vector */
194
195 struct ui_out_impl default_ui_out_impl =
196 {
197 default_table_begin,
198 default_table_body,
199 default_table_end,
200 default_table_header,
201 default_begin,
202 default_end,
203 default_field_int,
204 default_field_skip,
205 default_field_string,
206 default_field_fmt,
207 default_spaces,
208 default_text,
209 default_message,
210 default_wrap_hint,
211 default_flush,
212 0, /* Does not need MI hacks. */
213 };
214
215 /* The default ui_out */
216
217 struct ui_out def_uiout =
218 {
219 0, /* flags */
220 &default_ui_out_impl, /* impl */
221 };
222
223 /* Pointer to current ui_out */
224 /* FIXME: This should not be a global, but something passed down from main.c
225 or top.c */
226
227 struct ui_out *uiout = &def_uiout;
228
229 /* These are the interfaces to implementation functions */
230
231 static void uo_table_begin (struct ui_out *uiout, int nbrofcols,
232 int nr_rows, const char *tblid);
233 static void uo_table_body (struct ui_out *uiout);
234 static void uo_table_end (struct ui_out *uiout);
235 static void uo_table_header (struct ui_out *uiout, int width,
236 enum ui_align align, const char *col_name,
237 const char *colhdr);
238 static void uo_begin (struct ui_out *uiout,
239 enum ui_out_type type,
240 int level, const char *id);
241 static void uo_end (struct ui_out *uiout,
242 enum ui_out_type type,
243 int level);
244 static void uo_field_int (struct ui_out *uiout, int fldno, int width,
245 enum ui_align align, const char *fldname, int value);
246 static void uo_field_skip (struct ui_out *uiout, int fldno, int width,
247 enum ui_align align, const char *fldname);
248 static void uo_field_string (struct ui_out *uiout, int fldno, int width,
249 enum ui_align align, const char *fldname,
250 const char *string);
251 static void uo_field_fmt (struct ui_out *uiout, int fldno, int width,
252 enum ui_align align, const char *fldname,
253 const char *format, va_list args);
254 static void uo_spaces (struct ui_out *uiout, int numspaces);
255 static void uo_text (struct ui_out *uiout, const char *string);
256 static void uo_message (struct ui_out *uiout, int verbosity,
257 const char *format, va_list args);
258 static void uo_wrap_hint (struct ui_out *uiout, char *identstring);
259 static void uo_flush (struct ui_out *uiout);
260
261 /* Prototypes for local functions */
262
263 extern void _initialize_ui_out (void);
264 static void append_header_to_list (struct ui_out *uiout, int width,
265 int alignment, const char *col_name,
266 const char *colhdr);
267 static int get_next_header (struct ui_out *uiout, int *colno, int *width,
268 int *alignment, char **colhdr);
269 static void clear_header_list (struct ui_out *uiout);
270 static void verify_field (struct ui_out *uiout, int *fldno, int *width,
271 int *align);
272
273 static void init_ui_out_state (struct ui_out *uiout);
274
275 /* exported functions (ui_out API) */
276
277 /* Mark beginning of a table */
278
279 void
280 ui_out_table_begin (struct ui_out *uiout, int nbrofcols,
281 int nr_rows,
282 const char *tblid)
283 {
284 if (uiout->table.flag)
285 internal_error (__FILE__, __LINE__,
286 "tables cannot be nested; table_begin found before \
287 previous table_end.");
288
289 uiout->table.flag = 1;
290 uiout->table.body_flag = 0;
291 uiout->table.entry_level = uiout->level + 1;
292 uiout->table.columns = nbrofcols;
293 if (tblid != NULL)
294 uiout->table.id = xstrdup (tblid);
295 else
296 uiout->table.id = NULL;
297 clear_header_list (uiout);
298
299 uo_table_begin (uiout, nbrofcols, nr_rows, uiout->table.id);
300 }
301
302 void
303 ui_out_table_body (struct ui_out *uiout)
304 {
305 if (!uiout->table.flag)
306 internal_error (__FILE__, __LINE__,
307 "table_body outside a table is not valid; it must be \
308 after a table_begin and before a table_end.");
309 if (uiout->table.body_flag)
310 internal_error (__FILE__, __LINE__,
311 "extra table_body call not allowed; there must be \
312 only one table_body after a table_begin and before a table_end.");
313 if (uiout->table.header_next->colno != uiout->table.columns)
314 internal_error (__FILE__, __LINE__,
315 "number of headers differ from number of table \
316 columns.");
317
318 uiout->table.body_flag = 1;
319 uiout->table.header_next = uiout->table.header_first;
320
321 uo_table_body (uiout);
322 }
323
324 void
325 ui_out_table_end (struct ui_out *uiout)
326 {
327 if (!uiout->table.flag)
328 internal_error (__FILE__, __LINE__,
329 "misplaced table_end or missing table_begin.");
330
331 uiout->table.entry_level = 0;
332 uiout->table.body_flag = 0;
333 uiout->table.flag = 0;
334
335 uo_table_end (uiout);
336
337 if (uiout->table.id)
338 xfree (uiout->table.id);
339 clear_header_list (uiout);
340 }
341
342 void
343 ui_out_table_header (struct ui_out *uiout, int width, enum ui_align alignment,
344 const char *col_name,
345 const char *colhdr)
346 {
347 if (!uiout->table.flag || uiout->table.body_flag)
348 internal_error (__FILE__, __LINE__,
349 "table header must be specified after table_begin \
350 and before table_body.");
351
352 append_header_to_list (uiout, width, alignment, col_name, colhdr);
353
354 uo_table_header (uiout, width, alignment, col_name, colhdr);
355 }
356
357 void
358 ui_out_begin (struct ui_out *uiout,
359 enum ui_out_type type,
360 const char *id)
361 {
362 int new_level;
363 if (uiout->table.flag && !uiout->table.body_flag)
364 internal_error (__FILE__, __LINE__,
365 "table header or table_body expected; lists must be \
366 specified after table_body.");
367
368 /* Be careful to verify the ``field'' before the new tuple/list is
369 pushed onto the stack. That way the containing list/table/row is
370 verified and not the newly created tuple/list. This verification
371 is needed (at least) for the case where a table row entry
372 contains either a tuple/list. For that case bookkeeping such as
373 updating the column count or advancing to the next heading still
374 needs to be performed. */
375 {
376 int fldno;
377 int width;
378 int align;
379 verify_field (uiout, &fldno, &width, &align);
380 }
381
382 new_level = push_level (uiout, type, id);
383
384 /* If the push puts us at the same level as a table row entry, we've
385 got a new table row. Put the header pointer back to the start. */
386 if (uiout->table.body_flag
387 && uiout->table.entry_level == new_level)
388 uiout->table.header_next = uiout->table.header_first;
389
390 uo_begin (uiout, type, new_level, id);
391 }
392
393 void
394 ui_out_list_begin (struct ui_out *uiout,
395 const char *id)
396 {
397 ui_out_begin (uiout, ui_out_type_list, id);
398 }
399
400 void
401 ui_out_tuple_begin (struct ui_out *uiout, const char *id)
402 {
403 ui_out_begin (uiout, ui_out_type_tuple, id);
404 }
405
406 void
407 ui_out_end (struct ui_out *uiout,
408 enum ui_out_type type)
409 {
410 int old_level = pop_level (uiout, type);
411 uo_end (uiout, type, old_level);
412 }
413
414 void
415 ui_out_list_end (struct ui_out *uiout)
416 {
417 ui_out_end (uiout, ui_out_type_list);
418 }
419
420 void
421 ui_out_tuple_end (struct ui_out *uiout)
422 {
423 ui_out_end (uiout, ui_out_type_tuple);
424 }
425
426 struct ui_out_end_cleanup_data
427 {
428 struct ui_out *uiout;
429 enum ui_out_type type;
430 };
431
432 static void
433 do_cleanup_end (void *data)
434 {
435 struct ui_out_end_cleanup_data *end_cleanup_data = data;
436 ui_out_end (end_cleanup_data->uiout, end_cleanup_data->type);
437 xfree (end_cleanup_data);
438 }
439
440 static struct cleanup *
441 make_cleanup_ui_out_end (struct ui_out *uiout,
442 enum ui_out_type type)
443 {
444 struct ui_out_end_cleanup_data *end_cleanup_data;
445 end_cleanup_data = XMALLOC (struct ui_out_end_cleanup_data);
446 end_cleanup_data->uiout = uiout;
447 end_cleanup_data->type = type;
448 return make_cleanup (do_cleanup_end, end_cleanup_data);
449 }
450
451 struct cleanup *
452 make_cleanup_ui_out_begin_end (struct ui_out *uiout,
453 enum ui_out_type type,
454 const char *id)
455 {
456 ui_out_begin (uiout, type, id);
457 return make_cleanup_ui_out_end (uiout, type);
458 }
459
460 struct cleanup *
461 make_cleanup_ui_out_tuple_begin_end (struct ui_out *uiout,
462 const char *id)
463 {
464 ui_out_tuple_begin (uiout, id);
465 return make_cleanup_ui_out_end (uiout, ui_out_type_tuple);
466 }
467
468 struct cleanup *
469 make_cleanup_ui_out_list_begin_end (struct ui_out *uiout,
470 const char *id)
471 {
472 ui_out_list_begin (uiout, id);
473 return make_cleanup_ui_out_end (uiout, ui_out_type_list);
474 }
475
476 void
477 ui_out_field_int (struct ui_out *uiout,
478 const char *fldname,
479 int value)
480 {
481 int fldno;
482 int width;
483 int align;
484 struct ui_out_level *current = current_level (uiout);
485
486 verify_field (uiout, &fldno, &width, &align);
487
488 uo_field_int (uiout, fldno, width, align, fldname, value);
489 }
490
491 void
492 ui_out_field_core_addr (struct ui_out *uiout,
493 const char *fldname,
494 CORE_ADDR address)
495 {
496 char addstr[20];
497
498 /* FIXME-32x64: need a print_address_numeric with field width */
499 /* print_address_numeric (address, 1, local_stream); */
500 strcpy (addstr, local_hex_string_custom ((unsigned long) address, "08l"));
501
502 ui_out_field_string (uiout, fldname, addstr);
503 }
504
505 void
506 ui_out_field_stream (struct ui_out *uiout,
507 const char *fldname,
508 struct ui_stream *buf)
509 {
510 long length;
511 char *buffer = ui_file_xstrdup (buf->stream, &length);
512 struct cleanup *old_cleanup = make_cleanup (xfree, buffer);
513 if (length > 0)
514 ui_out_field_string (uiout, fldname, buffer);
515 else
516 ui_out_field_skip (uiout, fldname);
517 ui_file_rewind (buf->stream);
518 do_cleanups (old_cleanup);
519 }
520
521 /* used to ommit a field */
522
523 void
524 ui_out_field_skip (struct ui_out *uiout,
525 const char *fldname)
526 {
527 int fldno;
528 int width;
529 int align;
530
531 verify_field (uiout, &fldno, &width, &align);
532
533 uo_field_skip (uiout, fldno, width, align, fldname);
534 }
535
536 void
537 ui_out_field_string (struct ui_out *uiout,
538 const char *fldname,
539 const char *string)
540 {
541 int fldno;
542 int width;
543 int align;
544
545 verify_field (uiout, &fldno, &width, &align);
546
547 uo_field_string (uiout, fldno, width, align, fldname, string);
548 }
549
550 /* VARARGS */
551 void
552 ui_out_field_fmt (struct ui_out *uiout,
553 const char *fldname,
554 const char *format, ...)
555 {
556 va_list args;
557 int fldno;
558 int width;
559 int align;
560
561 /* will not align, but has to call anyway */
562 verify_field (uiout, &fldno, &width, &align);
563
564 va_start (args, format);
565
566 uo_field_fmt (uiout, fldno, width, align, fldname, format, args);
567
568 va_end (args);
569 }
570
571 void
572 ui_out_spaces (struct ui_out *uiout, int numspaces)
573 {
574 uo_spaces (uiout, numspaces);
575 }
576
577 void
578 ui_out_text (struct ui_out *uiout,
579 const char *string)
580 {
581 uo_text (uiout, string);
582 }
583
584 void
585 ui_out_message (struct ui_out *uiout, int verbosity,
586 const char *format,...)
587 {
588 va_list args;
589
590 va_start (args, format);
591
592 uo_message (uiout, verbosity, format, args);
593
594 va_end (args);
595 }
596
597 struct ui_stream *
598 ui_out_stream_new (struct ui_out *uiout)
599 {
600 struct ui_stream *tempbuf;
601
602 tempbuf = XMALLOC (struct ui_stream);
603 tempbuf->uiout = uiout;
604 tempbuf->stream = mem_fileopen ();
605 return tempbuf;
606 }
607
608 void
609 ui_out_stream_delete (struct ui_stream *buf)
610 {
611 ui_file_delete (buf->stream);
612 xfree (buf);
613 }
614
615 static void
616 do_stream_delete (void *buf)
617 {
618 ui_out_stream_delete (buf);
619 }
620
621 struct cleanup *
622 make_cleanup_ui_out_stream_delete (struct ui_stream *buf)
623 {
624 return make_cleanup (do_stream_delete, buf);
625 }
626
627
628 void
629 ui_out_wrap_hint (struct ui_out *uiout, char *identstring)
630 {
631 uo_wrap_hint (uiout, identstring);
632 }
633
634 void
635 ui_out_flush (struct ui_out *uiout)
636 {
637 uo_flush (uiout);
638 }
639
640 /* set the flags specified by the mask given */
641 int
642 ui_out_set_flags (struct ui_out *uiout, int mask)
643 {
644 int oldflags = uiout->flags;
645
646 uiout->flags |= mask;
647
648 return oldflags;
649 }
650
651 /* clear the flags specified by the mask given */
652 int
653 ui_out_clear_flags (struct ui_out *uiout, int mask)
654 {
655 int oldflags = uiout->flags;
656
657 uiout->flags &= ~mask;
658
659 return oldflags;
660 }
661
662 /* test the flags against the mask given */
663 int
664 ui_out_test_flags (struct ui_out *uiout, int mask)
665 {
666 return (uiout->flags & mask);
667 }
668
669 /* obtain the current verbosity level (as stablished by the
670 'set verbositylevel' command */
671
672 int
673 ui_out_get_verblvl (struct ui_out *uiout)
674 {
675 /* FIXME: not implemented yet */
676 return 0;
677 }
678
679 #if 0
680 void
681 ui_out_result_begin (struct ui_out *uiout, char *class)
682 {
683 }
684
685 void
686 ui_out_result_end (struct ui_out *uiout)
687 {
688 }
689
690 void
691 ui_out_info_begin (struct ui_out *uiout, char *class)
692 {
693 }
694
695 void
696 ui_out_info_end (struct ui_out *uiout)
697 {
698 }
699
700 void
701 ui_out_notify_begin (struct ui_out *uiout, char *class)
702 {
703 }
704
705 void
706 ui_out_notify_end (struct ui_out *uiout)
707 {
708 }
709
710 void
711 ui_out_error_begin (struct ui_out *uiout, char *class)
712 {
713 }
714
715 void
716 ui_out_error_end (struct ui_out *uiout)
717 {
718 }
719 #endif
720
721 #if 0
722 void
723 gdb_error (ui_out * uiout, int severity, char *format,...)
724 {
725 va_list args;
726 }
727
728 void
729 gdb_query (struct ui_out *uiout, int qflags, char *qprompt)
730 {
731 }
732 #endif
733
734 int
735 ui_out_is_mi_like_p (struct ui_out *uiout)
736 {
737 return uiout->impl->is_mi_like_p;
738 }
739
740 /* default gdb-out hook functions */
741
742 static void
743 default_table_begin (struct ui_out *uiout, int nbrofcols,
744 int nr_rows,
745 const char *tblid)
746 {
747 }
748
749 static void
750 default_table_body (struct ui_out *uiout)
751 {
752 }
753
754 static void
755 default_table_end (struct ui_out *uiout)
756 {
757 }
758
759 static void
760 default_table_header (struct ui_out *uiout, int width, enum ui_align alignment,
761 const char *col_name,
762 const char *colhdr)
763 {
764 }
765
766 static void
767 default_begin (struct ui_out *uiout,
768 enum ui_out_type type,
769 int level,
770 const char *id)
771 {
772 }
773
774 static void
775 default_end (struct ui_out *uiout,
776 enum ui_out_type type,
777 int level)
778 {
779 }
780
781 static void
782 default_field_int (struct ui_out *uiout, int fldno, int width,
783 enum ui_align align,
784 const char *fldname, int value)
785 {
786 }
787
788 static void
789 default_field_skip (struct ui_out *uiout, int fldno, int width,
790 enum ui_align align, const char *fldname)
791 {
792 }
793
794 static void
795 default_field_string (struct ui_out *uiout,
796 int fldno,
797 int width,
798 enum ui_align align,
799 const char *fldname,
800 const char *string)
801 {
802 }
803
804 static void
805 default_field_fmt (struct ui_out *uiout, int fldno, int width,
806 enum ui_align align,
807 const char *fldname,
808 const char *format,
809 va_list args)
810 {
811 }
812
813 static void
814 default_spaces (struct ui_out *uiout, int numspaces)
815 {
816 }
817
818 static void
819 default_text (struct ui_out *uiout, const char *string)
820 {
821 }
822
823 static void
824 default_message (struct ui_out *uiout, int verbosity,
825 const char *format,
826 va_list args)
827 {
828 }
829
830 static void
831 default_wrap_hint (struct ui_out *uiout, char *identstring)
832 {
833 }
834
835 static void
836 default_flush (struct ui_out *uiout)
837 {
838 }
839
840 /* Interface to the implementation functions */
841
842 void
843 uo_table_begin (struct ui_out *uiout, int nbrofcols,
844 int nr_rows,
845 const char *tblid)
846 {
847 if (!uiout->impl->table_begin)
848 return;
849 uiout->impl->table_begin (uiout, nbrofcols, nr_rows, tblid);
850 }
851
852 void
853 uo_table_body (struct ui_out *uiout)
854 {
855 if (!uiout->impl->table_body)
856 return;
857 uiout->impl->table_body (uiout);
858 }
859
860 void
861 uo_table_end (struct ui_out *uiout)
862 {
863 if (!uiout->impl->table_end)
864 return;
865 uiout->impl->table_end (uiout);
866 }
867
868 void
869 uo_table_header (struct ui_out *uiout, int width, enum ui_align align,
870 const char *col_name,
871 const char *colhdr)
872 {
873 if (!uiout->impl->table_header)
874 return;
875 uiout->impl->table_header (uiout, width, align, col_name, colhdr);
876 }
877
878 void
879 uo_begin (struct ui_out *uiout,
880 enum ui_out_type type,
881 int level,
882 const char *id)
883 {
884 if (uiout->impl->begin == NULL)
885 return;
886 uiout->impl->begin (uiout, type, level, id);
887 }
888
889 void
890 uo_end (struct ui_out *uiout,
891 enum ui_out_type type,
892 int level)
893 {
894 if (uiout->impl->end == NULL)
895 return;
896 uiout->impl->end (uiout, type, level);
897 }
898
899 void
900 uo_field_int (struct ui_out *uiout, int fldno, int width, enum ui_align align,
901 const char *fldname,
902 int value)
903 {
904 if (!uiout->impl->field_int)
905 return;
906 uiout->impl->field_int (uiout, fldno, width, align, fldname, value);
907 }
908
909 void
910 uo_field_skip (struct ui_out *uiout, int fldno, int width, enum ui_align align,
911 const char *fldname)
912 {
913 if (!uiout->impl->field_skip)
914 return;
915 uiout->impl->field_skip (uiout, fldno, width, align, fldname);
916 }
917
918 void
919 uo_field_string (struct ui_out *uiout, int fldno, int width,
920 enum ui_align align,
921 const char *fldname,
922 const char *string)
923 {
924 if (!uiout->impl->field_string)
925 return;
926 uiout->impl->field_string (uiout, fldno, width, align, fldname, string);
927 }
928
929 void
930 uo_field_fmt (struct ui_out *uiout, int fldno, int width, enum ui_align align,
931 const char *fldname,
932 const char *format,
933 va_list args)
934 {
935 if (!uiout->impl->field_fmt)
936 return;
937 uiout->impl->field_fmt (uiout, fldno, width, align, fldname, format, args);
938 }
939
940 void
941 uo_spaces (struct ui_out *uiout, int numspaces)
942 {
943 if (!uiout->impl->spaces)
944 return;
945 uiout->impl->spaces (uiout, numspaces);
946 }
947
948 void
949 uo_text (struct ui_out *uiout,
950 const char *string)
951 {
952 if (!uiout->impl->text)
953 return;
954 uiout->impl->text (uiout, string);
955 }
956
957 void
958 uo_message (struct ui_out *uiout, int verbosity,
959 const char *format,
960 va_list args)
961 {
962 if (!uiout->impl->message)
963 return;
964 uiout->impl->message (uiout, verbosity, format, args);
965 }
966
967 void
968 uo_wrap_hint (struct ui_out *uiout, char *identstring)
969 {
970 if (!uiout->impl->wrap_hint)
971 return;
972 uiout->impl->wrap_hint (uiout, identstring);
973 }
974
975 void
976 uo_flush (struct ui_out *uiout)
977 {
978 if (!uiout->impl->flush)
979 return;
980 uiout->impl->flush (uiout);
981 }
982
983 /* local functions */
984
985 /* list of column headers manipulation routines */
986
987 static void
988 clear_header_list (struct ui_out *uiout)
989 {
990 while (uiout->table.header_first != NULL)
991 {
992 uiout->table.header_next = uiout->table.header_first;
993 uiout->table.header_first = uiout->table.header_first->next;
994 if (uiout->table.header_next->colhdr != NULL)
995 xfree (uiout->table.header_next->colhdr);
996 xfree (uiout->table.header_next);
997 }
998 gdb_assert (uiout->table.header_first == NULL);
999 uiout->table.header_last = NULL;
1000 uiout->table.header_next = NULL;
1001 }
1002
1003 static void
1004 append_header_to_list (struct ui_out *uiout,
1005 int width,
1006 int alignment,
1007 const char *col_name,
1008 const char *colhdr)
1009 {
1010 struct ui_out_hdr *temphdr;
1011
1012 temphdr = XMALLOC (struct ui_out_hdr);
1013 temphdr->width = width;
1014 temphdr->alignment = alignment;
1015 /* we have to copy the column title as the original may be an automatic */
1016 if (colhdr != NULL)
1017 temphdr->colhdr = xstrdup (colhdr);
1018 else
1019 temphdr->colhdr = NULL;
1020 if (col_name != NULL)
1021 temphdr->col_name = xstrdup (colhdr);
1022 else
1023 temphdr->col_name = xstrdup (colhdr);
1024 temphdr->next = NULL;
1025 if (uiout->table.header_first == NULL)
1026 {
1027 temphdr->colno = 1;
1028 uiout->table.header_first = temphdr;
1029 uiout->table.header_last = temphdr;
1030 }
1031 else
1032 {
1033 temphdr->colno = uiout->table.header_last->colno + 1;
1034 uiout->table.header_last->next = temphdr;
1035 uiout->table.header_last = temphdr;
1036 }
1037 uiout->table.header_next = uiout->table.header_last;
1038 }
1039
1040 /* Extract the format information for the NEXT header and and advance
1041 the header pointer. Return 0 if there was no next header. */
1042
1043 static int
1044 get_next_header (struct ui_out *uiout,
1045 int *colno,
1046 int *width,
1047 int *alignment,
1048 char **colhdr)
1049 {
1050 /* There may be no headers at all or we may have used all columns. */
1051 if (uiout->table.header_next == NULL)
1052 return 0;
1053 *colno = uiout->table.header_next->colno;
1054 *width = uiout->table.header_next->width;
1055 *alignment = uiout->table.header_next->alignment;
1056 *colhdr = uiout->table.header_next->colhdr;
1057 /* Advance the header pointer to the next entry. */
1058 uiout->table.header_next = uiout->table.header_next->next;
1059 return 1;
1060 }
1061
1062
1063 /* Verify that the field/tuple/list is correctly positioned. Return
1064 the field number and corresponding alignment (if
1065 available/applicable). */
1066
1067 static void
1068 verify_field (struct ui_out *uiout, int *fldno, int *width, int *align)
1069 {
1070 struct ui_out_level *current = current_level (uiout);
1071 char *text;
1072
1073 if (uiout->table.flag)
1074 {
1075 if (!uiout->table.body_flag)
1076 internal_error (__FILE__, __LINE__,
1077 "table_body missing; table fields must be \
1078 specified after table_body and inside a list.");
1079 /* NOTE: cagney/2001-12-08: There was a check here to ensure
1080 that this code was only executed when uiout->level was
1081 greater than zero. That no longer applies - this code is run
1082 before each table row tuple is started and at that point the
1083 level is zero. */
1084 }
1085
1086 current->field_count += 1;
1087
1088 if (uiout->table.body_flag
1089 && uiout->table.entry_level == uiout->level
1090 && get_next_header (uiout, fldno, width, align, &text))
1091 {
1092 if (*fldno != current->field_count)
1093 internal_error (__FILE__, __LINE__,
1094 "ui-out internal error in handling headers.");
1095 }
1096 else
1097 {
1098 *width = 0;
1099 *align = ui_noalign;
1100 *fldno = current->field_count;
1101 }
1102 }
1103
1104
1105 /* access to ui_out format private members */
1106
1107 void
1108 ui_out_get_field_separator (struct ui_out *uiout)
1109 {
1110 }
1111
1112 /* Access to ui-out members data */
1113
1114 struct ui_out_data *
1115 ui_out_data (struct ui_out *uiout)
1116 {
1117 return uiout->data;
1118 }
1119
1120 /* initalize private members at startup */
1121
1122 struct ui_out *
1123 ui_out_new (struct ui_out_impl *impl,
1124 struct ui_out_data *data,
1125 int flags)
1126 {
1127 struct ui_out *uiout = XMALLOC (struct ui_out);
1128 uiout->data = data;
1129 uiout->impl = impl;
1130 uiout->flags = flags;
1131 uiout->table.flag = 0;
1132 uiout->table.body_flag = 0;
1133 uiout->level = 0;
1134 memset (uiout->levels, 0, sizeof (uiout->levels));
1135 uiout->table.header_first = NULL;
1136 uiout->table.header_last = NULL;
1137 uiout->table.header_next = NULL;
1138 return uiout;
1139 }
1140
1141 /* standard gdb initialization hook */
1142
1143 void
1144 _initialize_ui_out (void)
1145 {
1146 /* nothing needs to be done */
1147 }
This page took 0.055152 seconds and 5 git commands to generate.