1 /* Output generating routines for GDB.
3 Copyright (C) 1999, 2000, 2001, 2002, 2004, 2005, 2007, 2008, 2009, 2010
4 Free Software Foundation, Inc.
6 Contributed by Cygnus Solutions.
7 Written by Fernando Nasser for Cygnus.
9 This file is part of GDB.
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 3 of the License, or
14 (at your option) any later version.
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.
21 You should have received a copy of the GNU General Public License
22 along with this program. If not, see <http://www.gnu.org/licenses/>. */
25 #include "gdb_string.h"
26 #include "expression.h" /* For language.h */
29 #include "gdb_assert.h"
31 /* table header structures */
40 struct ui_out_hdr
*next
;
43 /* Maintain a stack so that the info applicable to the inner most list
44 is always available. Stack/nested level 0 is reserved for the
47 enum { MAX_UI_OUT_LEVELS
= 8 };
51 /* Count each field; the first element is for non-list fields */
53 /* The type of this level. */
54 enum ui_out_type type
;
57 /* Tables are special. Maintain a separate structure that tracks
58 their state. At present an output can only contain a single table
59 but that restriction might eventually be lifted. */
63 /* If on, a table is being generated. */
66 /* If on, the body of a table is being generated. If off, the table
67 header is being generated. */
70 /* The level at which each entry of the table is to be found. A row
71 (a tuple) is made up of entries. Consequently ENTRY_LEVEL is one
72 above that of the table. */
75 /* Number of table columns (as specified in the table_begin call). */
78 /* String identifying the table (as specified in the table_begin
82 /* Points to the first table header (if any). */
83 struct ui_out_hdr
*header_first
;
85 /* Points to the last table header (if any). */
86 struct ui_out_hdr
*header_last
;
88 /* Points to header of NEXT column to format. */
89 struct ui_out_hdr
*header_next
;
94 /* The ui_out structure */
95 /* Any change here requires a corresponding one in the initialization
96 of the default uiout, which is statically initialized */
101 /* specific implementation of ui-out */
102 struct ui_out_impl
*impl
;
103 struct ui_out_data
*data
;
105 /* Sub structure tracking the ui-out depth. */
107 struct ui_out_level levels
[MAX_UI_OUT_LEVELS
];
109 /* A table, if any. At present only a single table is supported. */
110 struct ui_out_table table
;
113 /* The current (inner most) level. */
114 static struct ui_out_level
*
115 current_level (struct ui_out
*uiout
)
117 return &uiout
->levels
[uiout
->level
];
120 /* Create a new level, of TYPE. Return the new level's index. */
122 push_level (struct ui_out
*uiout
,
123 enum ui_out_type type
,
126 struct ui_out_level
*current
;
127 /* We had better not overflow the buffer. */
129 gdb_assert (uiout
->level
>= 0 && uiout
->level
< MAX_UI_OUT_LEVELS
);
130 current
= current_level (uiout
);
131 current
->field_count
= 0;
132 current
->type
= type
;
136 /* Discard the current level, return the discarded level's index.
137 TYPE is the type of the level being discarded. */
139 pop_level (struct ui_out
*uiout
,
140 enum ui_out_type type
)
142 /* We had better not underflow the buffer. */
143 gdb_assert (uiout
->level
> 0 && uiout
->level
< MAX_UI_OUT_LEVELS
);
144 gdb_assert (current_level (uiout
)->type
== type
);
146 return uiout
->level
+ 1;
150 /* These are the default implementation functions */
152 static void default_table_begin (struct ui_out
*uiout
, int nbrofcols
,
153 int nr_rows
, const char *tblid
);
154 static void default_table_body (struct ui_out
*uiout
);
155 static void default_table_end (struct ui_out
*uiout
);
156 static void default_table_header (struct ui_out
*uiout
, int width
,
157 enum ui_align alig
, const char *col_name
,
159 static void default_begin (struct ui_out
*uiout
,
160 enum ui_out_type type
,
161 int level
, const char *id
);
162 static void default_end (struct ui_out
*uiout
,
163 enum ui_out_type type
,
165 static void default_field_int (struct ui_out
*uiout
, int fldno
, int width
,
169 static void default_field_skip (struct ui_out
*uiout
, int fldno
, int width
,
171 const char *fldname
);
172 static void default_field_string (struct ui_out
*uiout
, int fldno
, int width
,
176 static void default_field_fmt (struct ui_out
*uiout
, int fldno
,
177 int width
, enum ui_align align
,
180 va_list args
) ATTR_FORMAT (printf
, 6, 0);
181 static void default_spaces (struct ui_out
*uiout
, int numspaces
);
182 static void default_text (struct ui_out
*uiout
, const char *string
);
183 static void default_message (struct ui_out
*uiout
, int verbosity
,
185 va_list args
) ATTR_FORMAT (printf
, 3, 0);
186 static void default_wrap_hint (struct ui_out
*uiout
, char *identstring
);
187 static void default_flush (struct ui_out
*uiout
);
189 /* This is the default ui-out implementation functions vector */
191 struct ui_out_impl default_ui_out_impl
=
196 default_table_header
,
201 default_field_string
,
209 0, /* Does not need MI hacks. */
212 /* The default ui_out */
214 struct ui_out def_uiout
=
217 &default_ui_out_impl
, /* impl */
220 /* Pointer to current ui_out */
221 /* FIXME: This should not be a global, but something passed down from main.c
224 struct ui_out
*uiout
= &def_uiout
;
226 /* These are the interfaces to implementation functions */
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
,
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
,
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
,
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 ATTR_FORMAT (printf
, 6, 0);
252 static void uo_spaces (struct ui_out
*uiout
, int numspaces
);
253 static void uo_text (struct ui_out
*uiout
, const char *string
);
254 static void uo_message (struct ui_out
*uiout
, int verbosity
,
255 const char *format
, va_list args
)
256 ATTR_FORMAT (printf
, 3, 0);
257 static void uo_wrap_hint (struct ui_out
*uiout
, char *identstring
);
258 static void uo_flush (struct ui_out
*uiout
);
259 static int uo_redirect (struct ui_out
*uiout
, struct ui_file
*outstream
);
261 /* Prototypes for local functions */
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
,
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
,
273 /* exported functions (ui_out API) */
275 /* Mark beginning of a table */
278 ui_out_table_begin (struct ui_out
*uiout
, int nbrofcols
,
282 if (uiout
->table
.flag
)
283 internal_error (__FILE__
, __LINE__
,
284 _("tables cannot be nested; table_begin found before \
285 previous table_end."));
287 uiout
->table
.flag
= 1;
288 uiout
->table
.body_flag
= 0;
289 uiout
->table
.entry_level
= uiout
->level
+ 1;
290 uiout
->table
.columns
= nbrofcols
;
292 uiout
->table
.id
= xstrdup (tblid
);
294 uiout
->table
.id
= NULL
;
295 clear_header_list (uiout
);
297 uo_table_begin (uiout
, nbrofcols
, nr_rows
, uiout
->table
.id
);
301 ui_out_table_body (struct ui_out
*uiout
)
303 if (!uiout
->table
.flag
)
304 internal_error (__FILE__
, __LINE__
,
305 _("table_body outside a table is not valid; it must be \
306 after a table_begin and before a table_end."));
307 if (uiout
->table
.body_flag
)
308 internal_error (__FILE__
, __LINE__
,
309 _("extra table_body call not allowed; there must be \
310 only one table_body after a table_begin and before a table_end."));
311 if (uiout
->table
.header_next
->colno
!= uiout
->table
.columns
)
312 internal_error (__FILE__
, __LINE__
,
313 _("number of headers differ from number of table \
316 uiout
->table
.body_flag
= 1;
317 uiout
->table
.header_next
= uiout
->table
.header_first
;
319 uo_table_body (uiout
);
323 ui_out_table_end (struct ui_out
*uiout
)
325 if (!uiout
->table
.flag
)
326 internal_error (__FILE__
, __LINE__
,
327 _("misplaced table_end or missing table_begin."));
329 uiout
->table
.entry_level
= 0;
330 uiout
->table
.body_flag
= 0;
331 uiout
->table
.flag
= 0;
333 uo_table_end (uiout
);
336 xfree (uiout
->table
.id
);
337 clear_header_list (uiout
);
341 ui_out_table_header (struct ui_out
*uiout
, int width
, enum ui_align alignment
,
342 const char *col_name
,
345 if (!uiout
->table
.flag
|| uiout
->table
.body_flag
)
346 internal_error (__FILE__
, __LINE__
,
347 _("table header must be specified after table_begin \
348 and before table_body."));
350 append_header_to_list (uiout
, width
, alignment
, col_name
, colhdr
);
352 uo_table_header (uiout
, width
, alignment
, col_name
, colhdr
);
356 do_cleanup_table_end (void *data
)
358 struct ui_out
*ui_out
= data
;
360 ui_out_table_end (ui_out
);
364 make_cleanup_ui_out_table_begin_end (struct ui_out
*ui_out
, int nr_cols
,
365 int nr_rows
, const char *tblid
)
367 ui_out_table_begin (ui_out
, nr_cols
, nr_rows
, tblid
);
368 return make_cleanup (do_cleanup_table_end
, ui_out
);
372 ui_out_begin (struct ui_out
*uiout
,
373 enum ui_out_type type
,
377 if (uiout
->table
.flag
&& !uiout
->table
.body_flag
)
378 internal_error (__FILE__
, __LINE__
,
379 _("table header or table_body expected; lists must be \
380 specified after table_body."));
382 /* Be careful to verify the ``field'' before the new tuple/list is
383 pushed onto the stack. That way the containing list/table/row is
384 verified and not the newly created tuple/list. This verification
385 is needed (at least) for the case where a table row entry
386 contains either a tuple/list. For that case bookkeeping such as
387 updating the column count or advancing to the next heading still
388 needs to be performed. */
393 verify_field (uiout
, &fldno
, &width
, &align
);
396 new_level
= push_level (uiout
, type
, id
);
398 /* If the push puts us at the same level as a table row entry, we've
399 got a new table row. Put the header pointer back to the start. */
400 if (uiout
->table
.body_flag
401 && uiout
->table
.entry_level
== new_level
)
402 uiout
->table
.header_next
= uiout
->table
.header_first
;
404 uo_begin (uiout
, type
, new_level
, id
);
408 ui_out_end (struct ui_out
*uiout
,
409 enum ui_out_type type
)
411 int old_level
= pop_level (uiout
, type
);
412 uo_end (uiout
, type
, old_level
);
415 struct ui_out_end_cleanup_data
417 struct ui_out
*uiout
;
418 enum ui_out_type type
;
422 do_cleanup_end (void *data
)
424 struct ui_out_end_cleanup_data
*end_cleanup_data
= data
;
425 ui_out_end (end_cleanup_data
->uiout
, end_cleanup_data
->type
);
426 xfree (end_cleanup_data
);
429 static struct cleanup
*
430 make_cleanup_ui_out_end (struct ui_out
*uiout
,
431 enum ui_out_type type
)
433 struct ui_out_end_cleanup_data
*end_cleanup_data
;
434 end_cleanup_data
= XMALLOC (struct ui_out_end_cleanup_data
);
435 end_cleanup_data
->uiout
= uiout
;
436 end_cleanup_data
->type
= type
;
437 return make_cleanup (do_cleanup_end
, end_cleanup_data
);
441 make_cleanup_ui_out_tuple_begin_end (struct ui_out
*uiout
,
444 ui_out_begin (uiout
, ui_out_type_tuple
, id
);
445 return make_cleanup_ui_out_end (uiout
, ui_out_type_tuple
);
449 make_cleanup_ui_out_list_begin_end (struct ui_out
*uiout
,
452 ui_out_begin (uiout
, ui_out_type_list
, id
);
453 return make_cleanup_ui_out_end (uiout
, ui_out_type_list
);
457 ui_out_field_int (struct ui_out
*uiout
,
464 struct ui_out_level
*current
= current_level (uiout
);
466 verify_field (uiout
, &fldno
, &width
, &align
);
468 uo_field_int (uiout
, fldno
, width
, align
, fldname
, value
);
472 ui_out_field_fmt_int (struct ui_out
*uiout
,
474 enum ui_align input_align
,
481 struct ui_out_level
*current
= current_level (uiout
);
483 verify_field (uiout
, &fldno
, &width
, &align
);
485 uo_field_int (uiout
, fldno
, input_width
, input_align
, fldname
, value
);
489 ui_out_field_core_addr (struct ui_out
*uiout
,
491 struct gdbarch
*gdbarch
,
495 int addr_bit
= gdbarch_addr_bit (gdbarch
);
497 if (addr_bit
< (sizeof (CORE_ADDR
) * HOST_CHAR_BIT
))
498 address
&= ((CORE_ADDR
) 1 << addr_bit
) - 1;
500 /* FIXME: cagney/2002-05-03: Need local_address_string() function
501 that returns the language localized string formatted to a width
502 based on gdbarch_addr_bit. */
504 strcpy (addstr
, hex_string_custom (address
, 8));
506 strcpy (addstr
, hex_string_custom (address
, 16));
508 ui_out_field_string (uiout
, fldname
, addstr
);
512 ui_out_field_stream (struct ui_out
*uiout
,
514 struct ui_stream
*buf
)
517 char *buffer
= ui_file_xstrdup (buf
->stream
, &length
);
518 struct cleanup
*old_cleanup
= make_cleanup (xfree
, buffer
);
520 ui_out_field_string (uiout
, fldname
, buffer
);
522 ui_out_field_skip (uiout
, fldname
);
523 ui_file_rewind (buf
->stream
);
524 do_cleanups (old_cleanup
);
527 /* used to ommit a field */
530 ui_out_field_skip (struct ui_out
*uiout
,
537 verify_field (uiout
, &fldno
, &width
, &align
);
539 uo_field_skip (uiout
, fldno
, width
, align
, fldname
);
543 ui_out_field_string (struct ui_out
*uiout
,
551 verify_field (uiout
, &fldno
, &width
, &align
);
553 uo_field_string (uiout
, fldno
, width
, align
, fldname
, string
);
558 ui_out_field_fmt (struct ui_out
*uiout
,
560 const char *format
, ...)
567 /* will not align, but has to call anyway */
568 verify_field (uiout
, &fldno
, &width
, &align
);
570 va_start (args
, format
);
572 uo_field_fmt (uiout
, fldno
, width
, align
, fldname
, format
, args
);
578 ui_out_spaces (struct ui_out
*uiout
, int numspaces
)
580 uo_spaces (uiout
, numspaces
);
584 ui_out_text (struct ui_out
*uiout
,
587 uo_text (uiout
, string
);
591 ui_out_message (struct ui_out
*uiout
, int verbosity
,
592 const char *format
,...)
596 va_start (args
, format
);
598 uo_message (uiout
, verbosity
, format
, args
);
604 ui_out_stream_new (struct ui_out
*uiout
)
606 struct ui_stream
*tempbuf
;
608 tempbuf
= XMALLOC (struct ui_stream
);
609 tempbuf
->uiout
= uiout
;
610 tempbuf
->stream
= mem_fileopen ();
615 ui_out_stream_delete (struct ui_stream
*buf
)
617 ui_file_delete (buf
->stream
);
622 do_stream_delete (void *buf
)
624 ui_out_stream_delete (buf
);
628 make_cleanup_ui_out_stream_delete (struct ui_stream
*buf
)
630 return make_cleanup (do_stream_delete
, buf
);
635 ui_out_wrap_hint (struct ui_out
*uiout
, char *identstring
)
637 uo_wrap_hint (uiout
, identstring
);
641 ui_out_flush (struct ui_out
*uiout
)
647 ui_out_redirect (struct ui_out
*uiout
, struct ui_file
*outstream
)
649 return uo_redirect (uiout
, outstream
);
652 /* set the flags specified by the mask given */
654 ui_out_set_flags (struct ui_out
*uiout
, int mask
)
656 int oldflags
= uiout
->flags
;
658 uiout
->flags
|= mask
;
663 /* clear the flags specified by the mask given */
665 ui_out_clear_flags (struct ui_out
*uiout
, int mask
)
667 int oldflags
= uiout
->flags
;
669 uiout
->flags
&= ~mask
;
674 /* test the flags against the mask given */
676 ui_out_test_flags (struct ui_out
*uiout
, int mask
)
678 return (uiout
->flags
& mask
);
681 /* obtain the current verbosity level (as stablished by the
682 'set verbositylevel' command */
685 ui_out_get_verblvl (struct ui_out
*uiout
)
687 /* FIXME: not implemented yet */
693 ui_out_result_begin (struct ui_out
*uiout
, char *class)
698 ui_out_result_end (struct ui_out
*uiout
)
703 ui_out_info_begin (struct ui_out
*uiout
, char *class)
708 ui_out_info_end (struct ui_out
*uiout
)
713 ui_out_notify_begin (struct ui_out
*uiout
, char *class)
718 ui_out_notify_end (struct ui_out
*uiout
)
723 ui_out_error_begin (struct ui_out
*uiout
, char *class)
728 ui_out_error_end (struct ui_out
*uiout
)
735 gdb_error (ui_out
* uiout
, int severity
, char *format
,...)
741 gdb_query (struct ui_out
*uiout
, int qflags
, char *qprompt
)
747 ui_out_is_mi_like_p (struct ui_out
*uiout
)
749 return uiout
->impl
->is_mi_like_p
;
752 /* default gdb-out hook functions */
755 default_table_begin (struct ui_out
*uiout
, int nbrofcols
,
762 default_table_body (struct ui_out
*uiout
)
767 default_table_end (struct ui_out
*uiout
)
772 default_table_header (struct ui_out
*uiout
, int width
, enum ui_align alignment
,
773 const char *col_name
,
779 default_begin (struct ui_out
*uiout
,
780 enum ui_out_type type
,
787 default_end (struct ui_out
*uiout
,
788 enum ui_out_type type
,
794 default_field_int (struct ui_out
*uiout
, int fldno
, int width
,
796 const char *fldname
, int value
)
801 default_field_skip (struct ui_out
*uiout
, int fldno
, int width
,
802 enum ui_align align
, const char *fldname
)
807 default_field_string (struct ui_out
*uiout
,
817 default_field_fmt (struct ui_out
*uiout
, int fldno
, int width
,
826 default_spaces (struct ui_out
*uiout
, int numspaces
)
831 default_text (struct ui_out
*uiout
, const char *string
)
836 default_message (struct ui_out
*uiout
, int verbosity
,
843 default_wrap_hint (struct ui_out
*uiout
, char *identstring
)
848 default_flush (struct ui_out
*uiout
)
852 /* Interface to the implementation functions */
855 uo_table_begin (struct ui_out
*uiout
, int nbrofcols
,
859 if (!uiout
->impl
->table_begin
)
861 uiout
->impl
->table_begin (uiout
, nbrofcols
, nr_rows
, tblid
);
865 uo_table_body (struct ui_out
*uiout
)
867 if (!uiout
->impl
->table_body
)
869 uiout
->impl
->table_body (uiout
);
873 uo_table_end (struct ui_out
*uiout
)
875 if (!uiout
->impl
->table_end
)
877 uiout
->impl
->table_end (uiout
);
881 uo_table_header (struct ui_out
*uiout
, int width
, enum ui_align align
,
882 const char *col_name
,
885 if (!uiout
->impl
->table_header
)
887 uiout
->impl
->table_header (uiout
, width
, align
, col_name
, colhdr
);
891 uo_begin (struct ui_out
*uiout
,
892 enum ui_out_type type
,
896 if (uiout
->impl
->begin
== NULL
)
898 uiout
->impl
->begin (uiout
, type
, level
, id
);
902 uo_end (struct ui_out
*uiout
,
903 enum ui_out_type type
,
906 if (uiout
->impl
->end
== NULL
)
908 uiout
->impl
->end (uiout
, type
, level
);
912 uo_field_int (struct ui_out
*uiout
, int fldno
, int width
, enum ui_align align
,
916 if (!uiout
->impl
->field_int
)
918 uiout
->impl
->field_int (uiout
, fldno
, width
, align
, fldname
, value
);
922 uo_field_skip (struct ui_out
*uiout
, int fldno
, int width
, enum ui_align align
,
925 if (!uiout
->impl
->field_skip
)
927 uiout
->impl
->field_skip (uiout
, fldno
, width
, align
, fldname
);
931 uo_field_string (struct ui_out
*uiout
, int fldno
, int width
,
936 if (!uiout
->impl
->field_string
)
938 uiout
->impl
->field_string (uiout
, fldno
, width
, align
, fldname
, string
);
942 uo_field_fmt (struct ui_out
*uiout
, int fldno
, int width
, enum ui_align align
,
947 if (!uiout
->impl
->field_fmt
)
949 uiout
->impl
->field_fmt (uiout
, fldno
, width
, align
, fldname
, format
, args
);
953 uo_spaces (struct ui_out
*uiout
, int numspaces
)
955 if (!uiout
->impl
->spaces
)
957 uiout
->impl
->spaces (uiout
, numspaces
);
961 uo_text (struct ui_out
*uiout
,
964 if (!uiout
->impl
->text
)
966 uiout
->impl
->text (uiout
, string
);
970 uo_message (struct ui_out
*uiout
, int verbosity
,
974 if (!uiout
->impl
->message
)
976 uiout
->impl
->message (uiout
, verbosity
, format
, args
);
980 uo_wrap_hint (struct ui_out
*uiout
, char *identstring
)
982 if (!uiout
->impl
->wrap_hint
)
984 uiout
->impl
->wrap_hint (uiout
, identstring
);
988 uo_flush (struct ui_out
*uiout
)
990 if (!uiout
->impl
->flush
)
992 uiout
->impl
->flush (uiout
);
996 uo_redirect (struct ui_out
*uiout
, struct ui_file
*outstream
)
998 if (!uiout
->impl
->redirect
)
1000 uiout
->impl
->redirect (uiout
, outstream
);
1004 /* local functions */
1006 /* list of column headers manipulation routines */
1009 clear_header_list (struct ui_out
*uiout
)
1011 while (uiout
->table
.header_first
!= NULL
)
1013 uiout
->table
.header_next
= uiout
->table
.header_first
;
1014 uiout
->table
.header_first
= uiout
->table
.header_first
->next
;
1015 if (uiout
->table
.header_next
->colhdr
!= NULL
)
1016 xfree (uiout
->table
.header_next
->colhdr
);
1017 xfree (uiout
->table
.header_next
);
1019 gdb_assert (uiout
->table
.header_first
== NULL
);
1020 uiout
->table
.header_last
= NULL
;
1021 uiout
->table
.header_next
= NULL
;
1025 append_header_to_list (struct ui_out
*uiout
,
1028 const char *col_name
,
1031 struct ui_out_hdr
*temphdr
;
1033 temphdr
= XMALLOC (struct ui_out_hdr
);
1034 temphdr
->width
= width
;
1035 temphdr
->alignment
= alignment
;
1036 /* We have to copy the column title as the original may be an
1039 temphdr
->colhdr
= xstrdup (colhdr
);
1041 temphdr
->colhdr
= NULL
;
1043 if (col_name
!= NULL
)
1044 temphdr
->col_name
= xstrdup (col_name
);
1045 else if (colhdr
!= NULL
)
1046 temphdr
->col_name
= xstrdup (colhdr
);
1048 temphdr
->col_name
= NULL
;
1050 temphdr
->next
= NULL
;
1051 if (uiout
->table
.header_first
== NULL
)
1054 uiout
->table
.header_first
= temphdr
;
1055 uiout
->table
.header_last
= temphdr
;
1059 temphdr
->colno
= uiout
->table
.header_last
->colno
+ 1;
1060 uiout
->table
.header_last
->next
= temphdr
;
1061 uiout
->table
.header_last
= temphdr
;
1063 uiout
->table
.header_next
= uiout
->table
.header_last
;
1066 /* Extract the format information for the NEXT header and and advance
1067 the header pointer. Return 0 if there was no next header. */
1070 get_next_header (struct ui_out
*uiout
,
1076 /* There may be no headers at all or we may have used all columns. */
1077 if (uiout
->table
.header_next
== NULL
)
1079 *colno
= uiout
->table
.header_next
->colno
;
1080 *width
= uiout
->table
.header_next
->width
;
1081 *alignment
= uiout
->table
.header_next
->alignment
;
1082 *colhdr
= uiout
->table
.header_next
->colhdr
;
1083 /* Advance the header pointer to the next entry. */
1084 uiout
->table
.header_next
= uiout
->table
.header_next
->next
;
1089 /* Verify that the field/tuple/list is correctly positioned. Return
1090 the field number and corresponding alignment (if
1091 available/applicable). */
1094 verify_field (struct ui_out
*uiout
, int *fldno
, int *width
, int *align
)
1096 struct ui_out_level
*current
= current_level (uiout
);
1099 if (uiout
->table
.flag
)
1101 if (!uiout
->table
.body_flag
)
1102 internal_error (__FILE__
, __LINE__
,
1103 _("table_body missing; table fields must be \
1104 specified after table_body and inside a list."));
1105 /* NOTE: cagney/2001-12-08: There was a check here to ensure
1106 that this code was only executed when uiout->level was
1107 greater than zero. That no longer applies - this code is run
1108 before each table row tuple is started and at that point the
1112 current
->field_count
+= 1;
1114 if (uiout
->table
.body_flag
1115 && uiout
->table
.entry_level
== uiout
->level
1116 && get_next_header (uiout
, fldno
, width
, align
, &text
))
1118 if (*fldno
!= current
->field_count
)
1119 internal_error (__FILE__
, __LINE__
,
1120 _("ui-out internal error in handling headers."));
1125 *align
= ui_noalign
;
1126 *fldno
= current
->field_count
;
1131 /* access to ui_out format private members */
1134 ui_out_get_field_separator (struct ui_out
*uiout
)
1138 /* Access to ui-out members data */
1140 struct ui_out_data
*
1141 ui_out_data (struct ui_out
*uiout
)
1146 /* initalize private members at startup */
1149 ui_out_new (struct ui_out_impl
*impl
,
1150 struct ui_out_data
*data
,
1153 struct ui_out
*uiout
= XMALLOC (struct ui_out
);
1156 uiout
->flags
= flags
;
1157 uiout
->table
.flag
= 0;
1158 uiout
->table
.body_flag
= 0;
1160 memset (uiout
->levels
, 0, sizeof (uiout
->levels
));
1161 uiout
->table
.header_first
= NULL
;
1162 uiout
->table
.header_last
= NULL
;
1163 uiout
->table
.header_next
= NULL
;
1167 /* standard gdb initialization hook */
1170 _initialize_ui_out (void)
1172 /* nothing needs to be done */