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