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