15796c8dcSSimon Schubert /* Output generating routines for GDB.
25796c8dcSSimon Schubert
3*ef5ccd6cSJohn Marino Copyright (C) 1999-2013 Free Software Foundation, Inc.
45796c8dcSSimon Schubert
55796c8dcSSimon Schubert Contributed by Cygnus Solutions.
65796c8dcSSimon Schubert Written by Fernando Nasser for Cygnus.
75796c8dcSSimon Schubert
85796c8dcSSimon Schubert This file is part of GDB.
95796c8dcSSimon Schubert
105796c8dcSSimon Schubert This program is free software; you can redistribute it and/or modify
115796c8dcSSimon Schubert it under the terms of the GNU General Public License as published by
125796c8dcSSimon Schubert the Free Software Foundation; either version 3 of the License, or
135796c8dcSSimon Schubert (at your option) any later version.
145796c8dcSSimon Schubert
155796c8dcSSimon Schubert This program is distributed in the hope that it will be useful,
165796c8dcSSimon Schubert but WITHOUT ANY WARRANTY; without even the implied warranty of
175796c8dcSSimon Schubert MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
185796c8dcSSimon Schubert GNU General Public License for more details.
195796c8dcSSimon Schubert
205796c8dcSSimon Schubert You should have received a copy of the GNU General Public License
215796c8dcSSimon Schubert along with this program. If not, see <http://www.gnu.org/licenses/>. */
225796c8dcSSimon Schubert
235796c8dcSSimon Schubert #include "defs.h"
245796c8dcSSimon Schubert #include "gdb_string.h"
255796c8dcSSimon Schubert #include "expression.h" /* For language.h */
265796c8dcSSimon Schubert #include "language.h"
275796c8dcSSimon Schubert #include "ui-out.h"
285796c8dcSSimon Schubert #include "gdb_assert.h"
295796c8dcSSimon Schubert
305796c8dcSSimon Schubert /* table header structures */
315796c8dcSSimon Schubert
325796c8dcSSimon Schubert struct ui_out_hdr
335796c8dcSSimon Schubert {
345796c8dcSSimon Schubert int colno;
355796c8dcSSimon Schubert int width;
365796c8dcSSimon Schubert int alignment;
375796c8dcSSimon Schubert char *col_name;
385796c8dcSSimon Schubert char *colhdr;
395796c8dcSSimon Schubert struct ui_out_hdr *next;
405796c8dcSSimon Schubert };
415796c8dcSSimon Schubert
425796c8dcSSimon Schubert /* Maintain a stack so that the info applicable to the inner most list
435796c8dcSSimon Schubert is always available. Stack/nested level 0 is reserved for the
445796c8dcSSimon Schubert top-level result. */
455796c8dcSSimon Schubert
46cf7f2e2dSJohn Marino enum { MAX_UI_OUT_LEVELS = 8 };
475796c8dcSSimon Schubert
485796c8dcSSimon Schubert struct ui_out_level
495796c8dcSSimon Schubert {
50c50c785cSJohn Marino /* Count each field; the first element is for non-list fields. */
515796c8dcSSimon Schubert int field_count;
525796c8dcSSimon Schubert /* The type of this level. */
535796c8dcSSimon Schubert enum ui_out_type type;
545796c8dcSSimon Schubert };
555796c8dcSSimon Schubert
565796c8dcSSimon Schubert /* Tables are special. Maintain a separate structure that tracks
575796c8dcSSimon Schubert their state. At present an output can only contain a single table
585796c8dcSSimon Schubert but that restriction might eventually be lifted. */
595796c8dcSSimon Schubert
605796c8dcSSimon Schubert struct ui_out_table
615796c8dcSSimon Schubert {
625796c8dcSSimon Schubert /* If on, a table is being generated. */
635796c8dcSSimon Schubert int flag;
645796c8dcSSimon Schubert
655796c8dcSSimon Schubert /* If on, the body of a table is being generated. If off, the table
665796c8dcSSimon Schubert header is being generated. */
675796c8dcSSimon Schubert int body_flag;
685796c8dcSSimon Schubert
695796c8dcSSimon Schubert /* The level at which each entry of the table is to be found. A row
705796c8dcSSimon Schubert (a tuple) is made up of entries. Consequently ENTRY_LEVEL is one
715796c8dcSSimon Schubert above that of the table. */
725796c8dcSSimon Schubert int entry_level;
735796c8dcSSimon Schubert
745796c8dcSSimon Schubert /* Number of table columns (as specified in the table_begin call). */
755796c8dcSSimon Schubert int columns;
765796c8dcSSimon Schubert
775796c8dcSSimon Schubert /* String identifying the table (as specified in the table_begin
785796c8dcSSimon Schubert call). */
795796c8dcSSimon Schubert char *id;
805796c8dcSSimon Schubert
815796c8dcSSimon Schubert /* Points to the first table header (if any). */
825796c8dcSSimon Schubert struct ui_out_hdr *header_first;
835796c8dcSSimon Schubert
845796c8dcSSimon Schubert /* Points to the last table header (if any). */
855796c8dcSSimon Schubert struct ui_out_hdr *header_last;
865796c8dcSSimon Schubert
875796c8dcSSimon Schubert /* Points to header of NEXT column to format. */
885796c8dcSSimon Schubert struct ui_out_hdr *header_next;
895796c8dcSSimon Schubert
905796c8dcSSimon Schubert };
915796c8dcSSimon Schubert
925796c8dcSSimon Schubert
935796c8dcSSimon Schubert /* The ui_out structure */
945796c8dcSSimon Schubert /* Any change here requires a corresponding one in the initialization
95c50c785cSJohn Marino of the default uiout, which is statically initialized. */
965796c8dcSSimon Schubert
975796c8dcSSimon Schubert struct ui_out
985796c8dcSSimon Schubert {
995796c8dcSSimon Schubert int flags;
100c50c785cSJohn Marino /* Specific implementation of ui-out. */
1015796c8dcSSimon Schubert struct ui_out_impl *impl;
102cf7f2e2dSJohn Marino void *data;
1035796c8dcSSimon Schubert
1045796c8dcSSimon Schubert /* Sub structure tracking the ui-out depth. */
1055796c8dcSSimon Schubert int level;
1065796c8dcSSimon Schubert struct ui_out_level levels[MAX_UI_OUT_LEVELS];
1075796c8dcSSimon Schubert
1085796c8dcSSimon Schubert /* A table, if any. At present only a single table is supported. */
1095796c8dcSSimon Schubert struct ui_out_table table;
1105796c8dcSSimon Schubert };
1115796c8dcSSimon Schubert
1125796c8dcSSimon Schubert /* The current (inner most) level. */
1135796c8dcSSimon Schubert static struct ui_out_level *
current_level(struct ui_out * uiout)1145796c8dcSSimon Schubert current_level (struct ui_out *uiout)
1155796c8dcSSimon Schubert {
1165796c8dcSSimon Schubert return &uiout->levels[uiout->level];
1175796c8dcSSimon Schubert }
1185796c8dcSSimon Schubert
1195796c8dcSSimon Schubert /* Create a new level, of TYPE. Return the new level's index. */
1205796c8dcSSimon Schubert static int
push_level(struct ui_out * uiout,enum ui_out_type type,const char * id)1215796c8dcSSimon Schubert push_level (struct ui_out *uiout,
1225796c8dcSSimon Schubert enum ui_out_type type,
1235796c8dcSSimon Schubert const char *id)
1245796c8dcSSimon Schubert {
1255796c8dcSSimon Schubert struct ui_out_level *current;
126cf7f2e2dSJohn Marino
1275796c8dcSSimon Schubert /* We had better not overflow the buffer. */
1285796c8dcSSimon Schubert uiout->level++;
1295796c8dcSSimon Schubert gdb_assert (uiout->level >= 0 && uiout->level < MAX_UI_OUT_LEVELS);
1305796c8dcSSimon Schubert current = current_level (uiout);
1315796c8dcSSimon Schubert current->field_count = 0;
1325796c8dcSSimon Schubert current->type = type;
1335796c8dcSSimon Schubert return uiout->level;
1345796c8dcSSimon Schubert }
1355796c8dcSSimon Schubert
1365796c8dcSSimon Schubert /* Discard the current level, return the discarded level's index.
1375796c8dcSSimon Schubert TYPE is the type of the level being discarded. */
1385796c8dcSSimon Schubert static int
pop_level(struct ui_out * uiout,enum ui_out_type type)1395796c8dcSSimon Schubert pop_level (struct ui_out *uiout,
1405796c8dcSSimon Schubert enum ui_out_type type)
1415796c8dcSSimon Schubert {
1425796c8dcSSimon Schubert /* We had better not underflow the buffer. */
1435796c8dcSSimon Schubert gdb_assert (uiout->level > 0 && uiout->level < MAX_UI_OUT_LEVELS);
1445796c8dcSSimon Schubert gdb_assert (current_level (uiout)->type == type);
1455796c8dcSSimon Schubert uiout->level--;
1465796c8dcSSimon Schubert return uiout->level + 1;
1475796c8dcSSimon Schubert }
1485796c8dcSSimon Schubert
1495796c8dcSSimon Schubert
150c50c785cSJohn Marino /* These are the default implementation functions. */
1515796c8dcSSimon Schubert
1525796c8dcSSimon Schubert static void default_table_begin (struct ui_out *uiout, int nbrofcols,
1535796c8dcSSimon Schubert int nr_rows, const char *tblid);
1545796c8dcSSimon Schubert static void default_table_body (struct ui_out *uiout);
1555796c8dcSSimon Schubert static void default_table_end (struct ui_out *uiout);
1565796c8dcSSimon Schubert static void default_table_header (struct ui_out *uiout, int width,
1575796c8dcSSimon Schubert enum ui_align alig, const char *col_name,
1585796c8dcSSimon Schubert const char *colhdr);
1595796c8dcSSimon Schubert static void default_begin (struct ui_out *uiout,
1605796c8dcSSimon Schubert enum ui_out_type type,
1615796c8dcSSimon Schubert int level, const char *id);
1625796c8dcSSimon Schubert static void default_end (struct ui_out *uiout,
1635796c8dcSSimon Schubert enum ui_out_type type,
1645796c8dcSSimon Schubert int level);
1655796c8dcSSimon Schubert static void default_field_int (struct ui_out *uiout, int fldno, int width,
1665796c8dcSSimon Schubert enum ui_align alig,
1675796c8dcSSimon Schubert const char *fldname,
1685796c8dcSSimon Schubert int value);
1695796c8dcSSimon Schubert static void default_field_skip (struct ui_out *uiout, int fldno, int width,
1705796c8dcSSimon Schubert enum ui_align alig,
1715796c8dcSSimon Schubert const char *fldname);
1725796c8dcSSimon Schubert static void default_field_string (struct ui_out *uiout, int fldno, int width,
1735796c8dcSSimon Schubert enum ui_align align,
1745796c8dcSSimon Schubert const char *fldname,
1755796c8dcSSimon Schubert const char *string);
1765796c8dcSSimon Schubert static void default_field_fmt (struct ui_out *uiout, int fldno,
1775796c8dcSSimon Schubert int width, enum ui_align align,
1785796c8dcSSimon Schubert const char *fldname,
1795796c8dcSSimon Schubert const char *format,
180cf7f2e2dSJohn Marino va_list args) ATTRIBUTE_PRINTF (6, 0);
1815796c8dcSSimon Schubert static void default_spaces (struct ui_out *uiout, int numspaces);
1825796c8dcSSimon Schubert static void default_text (struct ui_out *uiout, const char *string);
1835796c8dcSSimon Schubert static void default_message (struct ui_out *uiout, int verbosity,
1845796c8dcSSimon Schubert const char *format,
185cf7f2e2dSJohn Marino va_list args) ATTRIBUTE_PRINTF (3, 0);
1865796c8dcSSimon Schubert static void default_wrap_hint (struct ui_out *uiout, char *identstring);
1875796c8dcSSimon Schubert static void default_flush (struct ui_out *uiout);
188*ef5ccd6cSJohn Marino static void default_data_destroy (struct ui_out *uiout);
1895796c8dcSSimon Schubert
190c50c785cSJohn Marino /* This is the default ui-out implementation functions vector. */
1915796c8dcSSimon Schubert
1925796c8dcSSimon Schubert struct ui_out_impl default_ui_out_impl =
1935796c8dcSSimon Schubert {
1945796c8dcSSimon Schubert default_table_begin,
1955796c8dcSSimon Schubert default_table_body,
1965796c8dcSSimon Schubert default_table_end,
1975796c8dcSSimon Schubert default_table_header,
1985796c8dcSSimon Schubert default_begin,
1995796c8dcSSimon Schubert default_end,
2005796c8dcSSimon Schubert default_field_int,
2015796c8dcSSimon Schubert default_field_skip,
2025796c8dcSSimon Schubert default_field_string,
2035796c8dcSSimon Schubert default_field_fmt,
2045796c8dcSSimon Schubert default_spaces,
2055796c8dcSSimon Schubert default_text,
2065796c8dcSSimon Schubert default_message,
2075796c8dcSSimon Schubert default_wrap_hint,
2085796c8dcSSimon Schubert default_flush,
2095796c8dcSSimon Schubert NULL,
210*ef5ccd6cSJohn Marino default_data_destroy,
2115796c8dcSSimon Schubert 0, /* Does not need MI hacks. */
2125796c8dcSSimon Schubert };
2135796c8dcSSimon Schubert
2145796c8dcSSimon Schubert /* The default ui_out */
2155796c8dcSSimon Schubert
2165796c8dcSSimon Schubert struct ui_out def_uiout =
2175796c8dcSSimon Schubert {
2185796c8dcSSimon Schubert 0, /* flags */
2195796c8dcSSimon Schubert &default_ui_out_impl, /* impl */
2205796c8dcSSimon Schubert };
2215796c8dcSSimon Schubert
2225796c8dcSSimon Schubert /* Pointer to current ui_out */
2235796c8dcSSimon Schubert /* FIXME: This should not be a global, but something passed down from main.c
224c50c785cSJohn Marino or top.c. */
2255796c8dcSSimon Schubert
226a45ae5f8SJohn Marino struct ui_out *current_uiout = &def_uiout;
2275796c8dcSSimon Schubert
228c50c785cSJohn Marino /* These are the interfaces to implementation functions. */
2295796c8dcSSimon Schubert
2305796c8dcSSimon Schubert static void uo_table_begin (struct ui_out *uiout, int nbrofcols,
2315796c8dcSSimon Schubert int nr_rows, const char *tblid);
2325796c8dcSSimon Schubert static void uo_table_body (struct ui_out *uiout);
2335796c8dcSSimon Schubert static void uo_table_end (struct ui_out *uiout);
2345796c8dcSSimon Schubert static void uo_table_header (struct ui_out *uiout, int width,
2355796c8dcSSimon Schubert enum ui_align align, const char *col_name,
2365796c8dcSSimon Schubert const char *colhdr);
2375796c8dcSSimon Schubert static void uo_begin (struct ui_out *uiout,
2385796c8dcSSimon Schubert enum ui_out_type type,
2395796c8dcSSimon Schubert int level, const char *id);
2405796c8dcSSimon Schubert static void uo_end (struct ui_out *uiout,
2415796c8dcSSimon Schubert enum ui_out_type type,
2425796c8dcSSimon Schubert int level);
2435796c8dcSSimon Schubert static void uo_field_int (struct ui_out *uiout, int fldno, int width,
2445796c8dcSSimon Schubert enum ui_align align, const char *fldname, int value);
2455796c8dcSSimon Schubert static void uo_field_skip (struct ui_out *uiout, int fldno, int width,
2465796c8dcSSimon Schubert enum ui_align align, const char *fldname);
2475796c8dcSSimon Schubert static void uo_field_fmt (struct ui_out *uiout, int fldno, int width,
2485796c8dcSSimon Schubert enum ui_align align, const char *fldname,
2495796c8dcSSimon Schubert const char *format, va_list args)
250cf7f2e2dSJohn Marino ATTRIBUTE_PRINTF (6, 0);
2515796c8dcSSimon Schubert static void uo_spaces (struct ui_out *uiout, int numspaces);
2525796c8dcSSimon Schubert static void uo_text (struct ui_out *uiout, const char *string);
2535796c8dcSSimon Schubert static void uo_message (struct ui_out *uiout, int verbosity,
2545796c8dcSSimon Schubert const char *format, va_list args)
255cf7f2e2dSJohn Marino ATTRIBUTE_PRINTF (3, 0);
2565796c8dcSSimon Schubert static void uo_wrap_hint (struct ui_out *uiout, char *identstring);
2575796c8dcSSimon Schubert static void uo_flush (struct ui_out *uiout);
2585796c8dcSSimon Schubert static int uo_redirect (struct ui_out *uiout, struct ui_file *outstream);
259*ef5ccd6cSJohn Marino static void uo_data_destroy (struct ui_out *uiout);
2605796c8dcSSimon Schubert
2615796c8dcSSimon Schubert /* Prototypes for local functions */
2625796c8dcSSimon Schubert
2635796c8dcSSimon Schubert extern void _initialize_ui_out (void);
2645796c8dcSSimon Schubert static void append_header_to_list (struct ui_out *uiout, int width,
2655796c8dcSSimon Schubert int alignment, const char *col_name,
2665796c8dcSSimon Schubert const char *colhdr);
2675796c8dcSSimon Schubert static int get_next_header (struct ui_out *uiout, int *colno, int *width,
2685796c8dcSSimon Schubert int *alignment, char **colhdr);
2695796c8dcSSimon Schubert static void clear_header_list (struct ui_out *uiout);
270*ef5ccd6cSJohn Marino static void clear_table (struct ui_out *uiout);
2715796c8dcSSimon Schubert static void verify_field (struct ui_out *uiout, int *fldno, int *width,
2725796c8dcSSimon Schubert int *align);
2735796c8dcSSimon Schubert
2745796c8dcSSimon Schubert /* exported functions (ui_out API) */
2755796c8dcSSimon Schubert
276c50c785cSJohn Marino /* Mark beginning of a table. */
2775796c8dcSSimon Schubert
2785796c8dcSSimon Schubert static void
ui_out_table_begin(struct ui_out * uiout,int nbrofcols,int nr_rows,const char * tblid)2795796c8dcSSimon Schubert ui_out_table_begin (struct ui_out *uiout, int nbrofcols,
2805796c8dcSSimon Schubert int nr_rows,
2815796c8dcSSimon Schubert const char *tblid)
2825796c8dcSSimon Schubert {
2835796c8dcSSimon Schubert if (uiout->table.flag)
2845796c8dcSSimon Schubert internal_error (__FILE__, __LINE__,
2855796c8dcSSimon Schubert _("tables cannot be nested; table_begin found before \
2865796c8dcSSimon Schubert previous table_end."));
2875796c8dcSSimon Schubert
2885796c8dcSSimon Schubert uiout->table.flag = 1;
2895796c8dcSSimon Schubert uiout->table.body_flag = 0;
2905796c8dcSSimon Schubert uiout->table.entry_level = uiout->level + 1;
2915796c8dcSSimon Schubert uiout->table.columns = nbrofcols;
2925796c8dcSSimon Schubert if (tblid != NULL)
2935796c8dcSSimon Schubert uiout->table.id = xstrdup (tblid);
2945796c8dcSSimon Schubert else
2955796c8dcSSimon Schubert uiout->table.id = NULL;
2965796c8dcSSimon Schubert clear_header_list (uiout);
2975796c8dcSSimon Schubert
2985796c8dcSSimon Schubert uo_table_begin (uiout, nbrofcols, nr_rows, uiout->table.id);
2995796c8dcSSimon Schubert }
3005796c8dcSSimon Schubert
3015796c8dcSSimon Schubert void
ui_out_table_body(struct ui_out * uiout)3025796c8dcSSimon Schubert ui_out_table_body (struct ui_out *uiout)
3035796c8dcSSimon Schubert {
3045796c8dcSSimon Schubert if (!uiout->table.flag)
3055796c8dcSSimon Schubert internal_error (__FILE__, __LINE__,
3065796c8dcSSimon Schubert _("table_body outside a table is not valid; it must be \
3075796c8dcSSimon Schubert after a table_begin and before a table_end."));
3085796c8dcSSimon Schubert if (uiout->table.body_flag)
3095796c8dcSSimon Schubert internal_error (__FILE__, __LINE__,
3105796c8dcSSimon Schubert _("extra table_body call not allowed; there must be \
3115796c8dcSSimon Schubert only one table_body after a table_begin and before a table_end."));
3125796c8dcSSimon Schubert if (uiout->table.header_next->colno != uiout->table.columns)
3135796c8dcSSimon Schubert internal_error (__FILE__, __LINE__,
3145796c8dcSSimon Schubert _("number of headers differ from number of table \
3155796c8dcSSimon Schubert columns."));
3165796c8dcSSimon Schubert
3175796c8dcSSimon Schubert uiout->table.body_flag = 1;
3185796c8dcSSimon Schubert uiout->table.header_next = uiout->table.header_first;
3195796c8dcSSimon Schubert
3205796c8dcSSimon Schubert uo_table_body (uiout);
3215796c8dcSSimon Schubert }
3225796c8dcSSimon Schubert
3235796c8dcSSimon Schubert static void
ui_out_table_end(struct ui_out * uiout)3245796c8dcSSimon Schubert ui_out_table_end (struct ui_out *uiout)
3255796c8dcSSimon Schubert {
3265796c8dcSSimon Schubert if (!uiout->table.flag)
3275796c8dcSSimon Schubert internal_error (__FILE__, __LINE__,
3285796c8dcSSimon Schubert _("misplaced table_end or missing table_begin."));
3295796c8dcSSimon Schubert
3305796c8dcSSimon Schubert uiout->table.entry_level = 0;
3315796c8dcSSimon Schubert uiout->table.body_flag = 0;
3325796c8dcSSimon Schubert uiout->table.flag = 0;
3335796c8dcSSimon Schubert
3345796c8dcSSimon Schubert uo_table_end (uiout);
335*ef5ccd6cSJohn Marino clear_table (uiout);
3365796c8dcSSimon Schubert }
3375796c8dcSSimon Schubert
3385796c8dcSSimon Schubert void
ui_out_table_header(struct ui_out * uiout,int width,enum ui_align alignment,const char * col_name,const char * colhdr)3395796c8dcSSimon Schubert ui_out_table_header (struct ui_out *uiout, int width, enum ui_align alignment,
3405796c8dcSSimon Schubert const char *col_name,
3415796c8dcSSimon Schubert const char *colhdr)
3425796c8dcSSimon Schubert {
3435796c8dcSSimon Schubert if (!uiout->table.flag || uiout->table.body_flag)
3445796c8dcSSimon Schubert internal_error (__FILE__, __LINE__,
3455796c8dcSSimon Schubert _("table header must be specified after table_begin \
3465796c8dcSSimon Schubert and before table_body."));
3475796c8dcSSimon Schubert
3485796c8dcSSimon Schubert append_header_to_list (uiout, width, alignment, col_name, colhdr);
3495796c8dcSSimon Schubert
3505796c8dcSSimon Schubert uo_table_header (uiout, width, alignment, col_name, colhdr);
3515796c8dcSSimon Schubert }
3525796c8dcSSimon Schubert
3535796c8dcSSimon Schubert static void
do_cleanup_table_end(void * data)3545796c8dcSSimon Schubert do_cleanup_table_end (void *data)
3555796c8dcSSimon Schubert {
3565796c8dcSSimon Schubert struct ui_out *ui_out = data;
3575796c8dcSSimon Schubert
3585796c8dcSSimon Schubert ui_out_table_end (ui_out);
3595796c8dcSSimon Schubert }
3605796c8dcSSimon Schubert
3615796c8dcSSimon Schubert struct cleanup *
make_cleanup_ui_out_table_begin_end(struct ui_out * ui_out,int nr_cols,int nr_rows,const char * tblid)3625796c8dcSSimon Schubert make_cleanup_ui_out_table_begin_end (struct ui_out *ui_out, int nr_cols,
3635796c8dcSSimon Schubert int nr_rows, const char *tblid)
3645796c8dcSSimon Schubert {
3655796c8dcSSimon Schubert ui_out_table_begin (ui_out, nr_cols, nr_rows, tblid);
3665796c8dcSSimon Schubert return make_cleanup (do_cleanup_table_end, ui_out);
3675796c8dcSSimon Schubert }
3685796c8dcSSimon Schubert
3695796c8dcSSimon Schubert void
ui_out_begin(struct ui_out * uiout,enum ui_out_type type,const char * id)3705796c8dcSSimon Schubert ui_out_begin (struct ui_out *uiout,
3715796c8dcSSimon Schubert enum ui_out_type type,
3725796c8dcSSimon Schubert const char *id)
3735796c8dcSSimon Schubert {
3745796c8dcSSimon Schubert int new_level;
375cf7f2e2dSJohn Marino
3765796c8dcSSimon Schubert if (uiout->table.flag && !uiout->table.body_flag)
3775796c8dcSSimon Schubert internal_error (__FILE__, __LINE__,
3785796c8dcSSimon Schubert _("table header or table_body expected; lists must be \
3795796c8dcSSimon Schubert specified after table_body."));
3805796c8dcSSimon Schubert
3815796c8dcSSimon Schubert /* Be careful to verify the ``field'' before the new tuple/list is
3825796c8dcSSimon Schubert pushed onto the stack. That way the containing list/table/row is
3835796c8dcSSimon Schubert verified and not the newly created tuple/list. This verification
3845796c8dcSSimon Schubert is needed (at least) for the case where a table row entry
3855796c8dcSSimon Schubert contains either a tuple/list. For that case bookkeeping such as
3865796c8dcSSimon Schubert updating the column count or advancing to the next heading still
3875796c8dcSSimon Schubert needs to be performed. */
3885796c8dcSSimon Schubert {
3895796c8dcSSimon Schubert int fldno;
3905796c8dcSSimon Schubert int width;
3915796c8dcSSimon Schubert int align;
392cf7f2e2dSJohn Marino
3935796c8dcSSimon Schubert verify_field (uiout, &fldno, &width, &align);
3945796c8dcSSimon Schubert }
3955796c8dcSSimon Schubert
3965796c8dcSSimon Schubert new_level = push_level (uiout, type, id);
3975796c8dcSSimon Schubert
3985796c8dcSSimon Schubert /* If the push puts us at the same level as a table row entry, we've
3995796c8dcSSimon Schubert got a new table row. Put the header pointer back to the start. */
4005796c8dcSSimon Schubert if (uiout->table.body_flag
4015796c8dcSSimon Schubert && uiout->table.entry_level == new_level)
4025796c8dcSSimon Schubert uiout->table.header_next = uiout->table.header_first;
4035796c8dcSSimon Schubert
4045796c8dcSSimon Schubert uo_begin (uiout, type, new_level, id);
4055796c8dcSSimon Schubert }
4065796c8dcSSimon Schubert
4075796c8dcSSimon Schubert void
ui_out_end(struct ui_out * uiout,enum ui_out_type type)4085796c8dcSSimon Schubert ui_out_end (struct ui_out *uiout,
4095796c8dcSSimon Schubert enum ui_out_type type)
4105796c8dcSSimon Schubert {
4115796c8dcSSimon Schubert int old_level = pop_level (uiout, type);
412cf7f2e2dSJohn Marino
4135796c8dcSSimon Schubert uo_end (uiout, type, old_level);
4145796c8dcSSimon Schubert }
4155796c8dcSSimon Schubert
4165796c8dcSSimon Schubert struct ui_out_end_cleanup_data
4175796c8dcSSimon Schubert {
4185796c8dcSSimon Schubert struct ui_out *uiout;
4195796c8dcSSimon Schubert enum ui_out_type type;
4205796c8dcSSimon Schubert };
4215796c8dcSSimon Schubert
4225796c8dcSSimon Schubert static void
do_cleanup_end(void * data)4235796c8dcSSimon Schubert do_cleanup_end (void *data)
4245796c8dcSSimon Schubert {
4255796c8dcSSimon Schubert struct ui_out_end_cleanup_data *end_cleanup_data = data;
426cf7f2e2dSJohn Marino
4275796c8dcSSimon Schubert ui_out_end (end_cleanup_data->uiout, end_cleanup_data->type);
4285796c8dcSSimon Schubert xfree (end_cleanup_data);
4295796c8dcSSimon Schubert }
4305796c8dcSSimon Schubert
4315796c8dcSSimon Schubert static struct cleanup *
make_cleanup_ui_out_end(struct ui_out * uiout,enum ui_out_type type)4325796c8dcSSimon Schubert make_cleanup_ui_out_end (struct ui_out *uiout,
4335796c8dcSSimon Schubert enum ui_out_type type)
4345796c8dcSSimon Schubert {
4355796c8dcSSimon Schubert struct ui_out_end_cleanup_data *end_cleanup_data;
436cf7f2e2dSJohn Marino
4375796c8dcSSimon Schubert end_cleanup_data = XMALLOC (struct ui_out_end_cleanup_data);
4385796c8dcSSimon Schubert end_cleanup_data->uiout = uiout;
4395796c8dcSSimon Schubert end_cleanup_data->type = type;
4405796c8dcSSimon Schubert return make_cleanup (do_cleanup_end, end_cleanup_data);
4415796c8dcSSimon Schubert }
4425796c8dcSSimon Schubert
4435796c8dcSSimon Schubert struct cleanup *
make_cleanup_ui_out_tuple_begin_end(struct ui_out * uiout,const char * id)4445796c8dcSSimon Schubert make_cleanup_ui_out_tuple_begin_end (struct ui_out *uiout,
4455796c8dcSSimon Schubert const char *id)
4465796c8dcSSimon Schubert {
4475796c8dcSSimon Schubert ui_out_begin (uiout, ui_out_type_tuple, id);
4485796c8dcSSimon Schubert return make_cleanup_ui_out_end (uiout, ui_out_type_tuple);
4495796c8dcSSimon Schubert }
4505796c8dcSSimon Schubert
4515796c8dcSSimon Schubert struct cleanup *
make_cleanup_ui_out_list_begin_end(struct ui_out * uiout,const char * id)4525796c8dcSSimon Schubert make_cleanup_ui_out_list_begin_end (struct ui_out *uiout,
4535796c8dcSSimon Schubert const char *id)
4545796c8dcSSimon Schubert {
4555796c8dcSSimon Schubert ui_out_begin (uiout, ui_out_type_list, id);
4565796c8dcSSimon Schubert return make_cleanup_ui_out_end (uiout, ui_out_type_list);
4575796c8dcSSimon Schubert }
4585796c8dcSSimon Schubert
4595796c8dcSSimon Schubert void
ui_out_field_int(struct ui_out * uiout,const char * fldname,int value)4605796c8dcSSimon Schubert ui_out_field_int (struct ui_out *uiout,
4615796c8dcSSimon Schubert const char *fldname,
4625796c8dcSSimon Schubert int value)
4635796c8dcSSimon Schubert {
4645796c8dcSSimon Schubert int fldno;
4655796c8dcSSimon Schubert int width;
4665796c8dcSSimon Schubert int align;
4675796c8dcSSimon Schubert
4685796c8dcSSimon Schubert verify_field (uiout, &fldno, &width, &align);
4695796c8dcSSimon Schubert
4705796c8dcSSimon Schubert uo_field_int (uiout, fldno, width, align, fldname, value);
4715796c8dcSSimon Schubert }
4725796c8dcSSimon Schubert
4735796c8dcSSimon Schubert void
ui_out_field_fmt_int(struct ui_out * uiout,int input_width,enum ui_align input_align,const char * fldname,int value)4745796c8dcSSimon Schubert ui_out_field_fmt_int (struct ui_out *uiout,
4755796c8dcSSimon Schubert int input_width,
4765796c8dcSSimon Schubert enum ui_align input_align,
4775796c8dcSSimon Schubert const char *fldname,
4785796c8dcSSimon Schubert int value)
4795796c8dcSSimon Schubert {
4805796c8dcSSimon Schubert int fldno;
4815796c8dcSSimon Schubert int width;
4825796c8dcSSimon Schubert int align;
4835796c8dcSSimon Schubert
4845796c8dcSSimon Schubert verify_field (uiout, &fldno, &width, &align);
4855796c8dcSSimon Schubert
4865796c8dcSSimon Schubert uo_field_int (uiout, fldno, input_width, input_align, fldname, value);
4875796c8dcSSimon Schubert }
4885796c8dcSSimon Schubert
489a45ae5f8SJohn Marino /* Documented in ui-out.h. */
490a45ae5f8SJohn Marino
4915796c8dcSSimon Schubert void
ui_out_field_core_addr(struct ui_out * uiout,const char * fldname,struct gdbarch * gdbarch,CORE_ADDR address)4925796c8dcSSimon Schubert ui_out_field_core_addr (struct ui_out *uiout,
4935796c8dcSSimon Schubert const char *fldname,
4945796c8dcSSimon Schubert struct gdbarch *gdbarch,
4955796c8dcSSimon Schubert CORE_ADDR address)
4965796c8dcSSimon Schubert {
497c50c785cSJohn Marino ui_out_field_string (uiout, fldname,
498c50c785cSJohn Marino print_core_address (gdbarch, address));
4995796c8dcSSimon Schubert }
5005796c8dcSSimon Schubert
5015796c8dcSSimon Schubert void
ui_out_field_stream(struct ui_out * uiout,const char * fldname,struct ui_file * stream)5025796c8dcSSimon Schubert ui_out_field_stream (struct ui_out *uiout,
5035796c8dcSSimon Schubert const char *fldname,
504*ef5ccd6cSJohn Marino struct ui_file *stream)
5055796c8dcSSimon Schubert {
5065796c8dcSSimon Schubert long length;
507*ef5ccd6cSJohn Marino char *buffer = ui_file_xstrdup (stream, &length);
5085796c8dcSSimon Schubert struct cleanup *old_cleanup = make_cleanup (xfree, buffer);
509cf7f2e2dSJohn Marino
5105796c8dcSSimon Schubert if (length > 0)
5115796c8dcSSimon Schubert ui_out_field_string (uiout, fldname, buffer);
5125796c8dcSSimon Schubert else
5135796c8dcSSimon Schubert ui_out_field_skip (uiout, fldname);
514*ef5ccd6cSJohn Marino ui_file_rewind (stream);
5155796c8dcSSimon Schubert do_cleanups (old_cleanup);
5165796c8dcSSimon Schubert }
5175796c8dcSSimon Schubert
518c50c785cSJohn Marino /* Used to omit a field. */
5195796c8dcSSimon Schubert
5205796c8dcSSimon Schubert void
ui_out_field_skip(struct ui_out * uiout,const char * fldname)5215796c8dcSSimon Schubert ui_out_field_skip (struct ui_out *uiout,
5225796c8dcSSimon Schubert const char *fldname)
5235796c8dcSSimon Schubert {
5245796c8dcSSimon Schubert int fldno;
5255796c8dcSSimon Schubert int width;
5265796c8dcSSimon Schubert int align;
5275796c8dcSSimon Schubert
5285796c8dcSSimon Schubert verify_field (uiout, &fldno, &width, &align);
5295796c8dcSSimon Schubert
5305796c8dcSSimon Schubert uo_field_skip (uiout, fldno, width, align, fldname);
5315796c8dcSSimon Schubert }
5325796c8dcSSimon Schubert
5335796c8dcSSimon Schubert void
ui_out_field_string(struct ui_out * uiout,const char * fldname,const char * string)5345796c8dcSSimon Schubert ui_out_field_string (struct ui_out *uiout,
5355796c8dcSSimon Schubert const char *fldname,
5365796c8dcSSimon Schubert const char *string)
5375796c8dcSSimon Schubert {
5385796c8dcSSimon Schubert int fldno;
5395796c8dcSSimon Schubert int width;
5405796c8dcSSimon Schubert int align;
5415796c8dcSSimon Schubert
5425796c8dcSSimon Schubert verify_field (uiout, &fldno, &width, &align);
5435796c8dcSSimon Schubert
5445796c8dcSSimon Schubert uo_field_string (uiout, fldno, width, align, fldname, string);
5455796c8dcSSimon Schubert }
5465796c8dcSSimon Schubert
5475796c8dcSSimon Schubert /* VARARGS */
5485796c8dcSSimon Schubert void
ui_out_field_fmt(struct ui_out * uiout,const char * fldname,const char * format,...)5495796c8dcSSimon Schubert ui_out_field_fmt (struct ui_out *uiout,
5505796c8dcSSimon Schubert const char *fldname,
5515796c8dcSSimon Schubert const char *format, ...)
5525796c8dcSSimon Schubert {
5535796c8dcSSimon Schubert va_list args;
5545796c8dcSSimon Schubert int fldno;
5555796c8dcSSimon Schubert int width;
5565796c8dcSSimon Schubert int align;
5575796c8dcSSimon Schubert
558c50c785cSJohn Marino /* Will not align, but has to call anyway. */
5595796c8dcSSimon Schubert verify_field (uiout, &fldno, &width, &align);
5605796c8dcSSimon Schubert
5615796c8dcSSimon Schubert va_start (args, format);
5625796c8dcSSimon Schubert
5635796c8dcSSimon Schubert uo_field_fmt (uiout, fldno, width, align, fldname, format, args);
5645796c8dcSSimon Schubert
5655796c8dcSSimon Schubert va_end (args);
5665796c8dcSSimon Schubert }
5675796c8dcSSimon Schubert
5685796c8dcSSimon Schubert void
ui_out_spaces(struct ui_out * uiout,int numspaces)5695796c8dcSSimon Schubert ui_out_spaces (struct ui_out *uiout, int numspaces)
5705796c8dcSSimon Schubert {
5715796c8dcSSimon Schubert uo_spaces (uiout, numspaces);
5725796c8dcSSimon Schubert }
5735796c8dcSSimon Schubert
5745796c8dcSSimon Schubert void
ui_out_text(struct ui_out * uiout,const char * string)5755796c8dcSSimon Schubert ui_out_text (struct ui_out *uiout,
5765796c8dcSSimon Schubert const char *string)
5775796c8dcSSimon Schubert {
5785796c8dcSSimon Schubert uo_text (uiout, string);
5795796c8dcSSimon Schubert }
5805796c8dcSSimon Schubert
5815796c8dcSSimon Schubert void
ui_out_message(struct ui_out * uiout,int verbosity,const char * format,...)5825796c8dcSSimon Schubert ui_out_message (struct ui_out *uiout, int verbosity,
5835796c8dcSSimon Schubert const char *format,...)
5845796c8dcSSimon Schubert {
5855796c8dcSSimon Schubert va_list args;
5865796c8dcSSimon Schubert
5875796c8dcSSimon Schubert va_start (args, format);
5885796c8dcSSimon Schubert uo_message (uiout, verbosity, format, args);
5895796c8dcSSimon Schubert va_end (args);
5905796c8dcSSimon Schubert }
5915796c8dcSSimon Schubert
5925796c8dcSSimon Schubert void
ui_out_wrap_hint(struct ui_out * uiout,char * identstring)5935796c8dcSSimon Schubert ui_out_wrap_hint (struct ui_out *uiout, char *identstring)
5945796c8dcSSimon Schubert {
5955796c8dcSSimon Schubert uo_wrap_hint (uiout, identstring);
5965796c8dcSSimon Schubert }
5975796c8dcSSimon Schubert
5985796c8dcSSimon Schubert void
ui_out_flush(struct ui_out * uiout)5995796c8dcSSimon Schubert ui_out_flush (struct ui_out *uiout)
6005796c8dcSSimon Schubert {
6015796c8dcSSimon Schubert uo_flush (uiout);
6025796c8dcSSimon Schubert }
6035796c8dcSSimon Schubert
6045796c8dcSSimon Schubert int
ui_out_redirect(struct ui_out * uiout,struct ui_file * outstream)6055796c8dcSSimon Schubert ui_out_redirect (struct ui_out *uiout, struct ui_file *outstream)
6065796c8dcSSimon Schubert {
6075796c8dcSSimon Schubert return uo_redirect (uiout, outstream);
6085796c8dcSSimon Schubert }
6095796c8dcSSimon Schubert
610c50c785cSJohn Marino /* Set the flags specified by the mask given. */
6115796c8dcSSimon Schubert int
ui_out_set_flags(struct ui_out * uiout,int mask)6125796c8dcSSimon Schubert ui_out_set_flags (struct ui_out *uiout, int mask)
6135796c8dcSSimon Schubert {
6145796c8dcSSimon Schubert int oldflags = uiout->flags;
6155796c8dcSSimon Schubert
6165796c8dcSSimon Schubert uiout->flags |= mask;
6175796c8dcSSimon Schubert return oldflags;
6185796c8dcSSimon Schubert }
6195796c8dcSSimon Schubert
620c50c785cSJohn Marino /* Clear the flags specified by the mask given. */
6215796c8dcSSimon Schubert int
ui_out_clear_flags(struct ui_out * uiout,int mask)6225796c8dcSSimon Schubert ui_out_clear_flags (struct ui_out *uiout, int mask)
6235796c8dcSSimon Schubert {
6245796c8dcSSimon Schubert int oldflags = uiout->flags;
6255796c8dcSSimon Schubert
6265796c8dcSSimon Schubert uiout->flags &= ~mask;
6275796c8dcSSimon Schubert return oldflags;
6285796c8dcSSimon Schubert }
6295796c8dcSSimon Schubert
630c50c785cSJohn Marino /* Test the flags against the mask given. */
6315796c8dcSSimon Schubert int
ui_out_test_flags(struct ui_out * uiout,int mask)6325796c8dcSSimon Schubert ui_out_test_flags (struct ui_out *uiout, int mask)
6335796c8dcSSimon Schubert {
6345796c8dcSSimon Schubert return (uiout->flags & mask);
6355796c8dcSSimon Schubert }
6365796c8dcSSimon Schubert
637c50c785cSJohn Marino /* Obtain the current verbosity level (as stablished by the
638c50c785cSJohn Marino 'set verbositylevel' command. */
6395796c8dcSSimon Schubert
6405796c8dcSSimon Schubert int
ui_out_get_verblvl(struct ui_out * uiout)6415796c8dcSSimon Schubert ui_out_get_verblvl (struct ui_out *uiout)
6425796c8dcSSimon Schubert {
643c50c785cSJohn Marino /* FIXME: not implemented yet. */
6445796c8dcSSimon Schubert return 0;
6455796c8dcSSimon Schubert }
6465796c8dcSSimon Schubert
6475796c8dcSSimon Schubert int
ui_out_is_mi_like_p(struct ui_out * uiout)6485796c8dcSSimon Schubert ui_out_is_mi_like_p (struct ui_out *uiout)
6495796c8dcSSimon Schubert {
6505796c8dcSSimon Schubert return uiout->impl->is_mi_like_p;
6515796c8dcSSimon Schubert }
6525796c8dcSSimon Schubert
653c50c785cSJohn Marino /* Default gdb-out hook functions. */
6545796c8dcSSimon Schubert
6555796c8dcSSimon Schubert static void
default_table_begin(struct ui_out * uiout,int nbrofcols,int nr_rows,const char * tblid)6565796c8dcSSimon Schubert default_table_begin (struct ui_out *uiout, int nbrofcols,
6575796c8dcSSimon Schubert int nr_rows,
6585796c8dcSSimon Schubert const char *tblid)
6595796c8dcSSimon Schubert {
6605796c8dcSSimon Schubert }
6615796c8dcSSimon Schubert
6625796c8dcSSimon Schubert static void
default_table_body(struct ui_out * uiout)6635796c8dcSSimon Schubert default_table_body (struct ui_out *uiout)
6645796c8dcSSimon Schubert {
6655796c8dcSSimon Schubert }
6665796c8dcSSimon Schubert
6675796c8dcSSimon Schubert static void
default_table_end(struct ui_out * uiout)6685796c8dcSSimon Schubert default_table_end (struct ui_out *uiout)
6695796c8dcSSimon Schubert {
6705796c8dcSSimon Schubert }
6715796c8dcSSimon Schubert
6725796c8dcSSimon Schubert static void
default_table_header(struct ui_out * uiout,int width,enum ui_align alignment,const char * col_name,const char * colhdr)6735796c8dcSSimon Schubert default_table_header (struct ui_out *uiout, int width, enum ui_align alignment,
6745796c8dcSSimon Schubert const char *col_name,
6755796c8dcSSimon Schubert const char *colhdr)
6765796c8dcSSimon Schubert {
6775796c8dcSSimon Schubert }
6785796c8dcSSimon Schubert
6795796c8dcSSimon Schubert static void
default_begin(struct ui_out * uiout,enum ui_out_type type,int level,const char * id)6805796c8dcSSimon Schubert default_begin (struct ui_out *uiout,
6815796c8dcSSimon Schubert enum ui_out_type type,
6825796c8dcSSimon Schubert int level,
6835796c8dcSSimon Schubert const char *id)
6845796c8dcSSimon Schubert {
6855796c8dcSSimon Schubert }
6865796c8dcSSimon Schubert
6875796c8dcSSimon Schubert static void
default_end(struct ui_out * uiout,enum ui_out_type type,int level)6885796c8dcSSimon Schubert default_end (struct ui_out *uiout,
6895796c8dcSSimon Schubert enum ui_out_type type,
6905796c8dcSSimon Schubert int level)
6915796c8dcSSimon Schubert {
6925796c8dcSSimon Schubert }
6935796c8dcSSimon Schubert
6945796c8dcSSimon Schubert static void
default_field_int(struct ui_out * uiout,int fldno,int width,enum ui_align align,const char * fldname,int value)6955796c8dcSSimon Schubert default_field_int (struct ui_out *uiout, int fldno, int width,
6965796c8dcSSimon Schubert enum ui_align align,
6975796c8dcSSimon Schubert const char *fldname, int value)
6985796c8dcSSimon Schubert {
6995796c8dcSSimon Schubert }
7005796c8dcSSimon Schubert
7015796c8dcSSimon Schubert static void
default_field_skip(struct ui_out * uiout,int fldno,int width,enum ui_align align,const char * fldname)7025796c8dcSSimon Schubert default_field_skip (struct ui_out *uiout, int fldno, int width,
7035796c8dcSSimon Schubert enum ui_align align, const char *fldname)
7045796c8dcSSimon Schubert {
7055796c8dcSSimon Schubert }
7065796c8dcSSimon Schubert
7075796c8dcSSimon Schubert static void
default_field_string(struct ui_out * uiout,int fldno,int width,enum ui_align align,const char * fldname,const char * string)7085796c8dcSSimon Schubert default_field_string (struct ui_out *uiout,
7095796c8dcSSimon Schubert int fldno,
7105796c8dcSSimon Schubert int width,
7115796c8dcSSimon Schubert enum ui_align align,
7125796c8dcSSimon Schubert const char *fldname,
7135796c8dcSSimon Schubert const char *string)
7145796c8dcSSimon Schubert {
7155796c8dcSSimon Schubert }
7165796c8dcSSimon Schubert
7175796c8dcSSimon Schubert static void
default_field_fmt(struct ui_out * uiout,int fldno,int width,enum ui_align align,const char * fldname,const char * format,va_list args)7185796c8dcSSimon Schubert default_field_fmt (struct ui_out *uiout, int fldno, int width,
7195796c8dcSSimon Schubert enum ui_align align,
7205796c8dcSSimon Schubert const char *fldname,
7215796c8dcSSimon Schubert const char *format,
7225796c8dcSSimon Schubert va_list args)
7235796c8dcSSimon Schubert {
7245796c8dcSSimon Schubert }
7255796c8dcSSimon Schubert
7265796c8dcSSimon Schubert static void
default_spaces(struct ui_out * uiout,int numspaces)7275796c8dcSSimon Schubert default_spaces (struct ui_out *uiout, int numspaces)
7285796c8dcSSimon Schubert {
7295796c8dcSSimon Schubert }
7305796c8dcSSimon Schubert
7315796c8dcSSimon Schubert static void
default_text(struct ui_out * uiout,const char * string)7325796c8dcSSimon Schubert default_text (struct ui_out *uiout, const char *string)
7335796c8dcSSimon Schubert {
7345796c8dcSSimon Schubert }
7355796c8dcSSimon Schubert
7365796c8dcSSimon Schubert static void
default_message(struct ui_out * uiout,int verbosity,const char * format,va_list args)7375796c8dcSSimon Schubert default_message (struct ui_out *uiout, int verbosity,
7385796c8dcSSimon Schubert const char *format,
7395796c8dcSSimon Schubert va_list args)
7405796c8dcSSimon Schubert {
7415796c8dcSSimon Schubert }
7425796c8dcSSimon Schubert
7435796c8dcSSimon Schubert static void
default_wrap_hint(struct ui_out * uiout,char * identstring)7445796c8dcSSimon Schubert default_wrap_hint (struct ui_out *uiout, char *identstring)
7455796c8dcSSimon Schubert {
7465796c8dcSSimon Schubert }
7475796c8dcSSimon Schubert
7485796c8dcSSimon Schubert static void
default_flush(struct ui_out * uiout)7495796c8dcSSimon Schubert default_flush (struct ui_out *uiout)
7505796c8dcSSimon Schubert {
7515796c8dcSSimon Schubert }
7525796c8dcSSimon Schubert
753*ef5ccd6cSJohn Marino static void
default_data_destroy(struct ui_out * uiout)754*ef5ccd6cSJohn Marino default_data_destroy (struct ui_out *uiout)
755*ef5ccd6cSJohn Marino {
756*ef5ccd6cSJohn Marino }
757*ef5ccd6cSJohn Marino
758c50c785cSJohn Marino /* Interface to the implementation functions. */
7595796c8dcSSimon Schubert
7605796c8dcSSimon Schubert void
uo_table_begin(struct ui_out * uiout,int nbrofcols,int nr_rows,const char * tblid)7615796c8dcSSimon Schubert uo_table_begin (struct ui_out *uiout, int nbrofcols,
7625796c8dcSSimon Schubert int nr_rows,
7635796c8dcSSimon Schubert const char *tblid)
7645796c8dcSSimon Schubert {
7655796c8dcSSimon Schubert if (!uiout->impl->table_begin)
7665796c8dcSSimon Schubert return;
7675796c8dcSSimon Schubert uiout->impl->table_begin (uiout, nbrofcols, nr_rows, tblid);
7685796c8dcSSimon Schubert }
7695796c8dcSSimon Schubert
7705796c8dcSSimon Schubert void
uo_table_body(struct ui_out * uiout)7715796c8dcSSimon Schubert uo_table_body (struct ui_out *uiout)
7725796c8dcSSimon Schubert {
7735796c8dcSSimon Schubert if (!uiout->impl->table_body)
7745796c8dcSSimon Schubert return;
7755796c8dcSSimon Schubert uiout->impl->table_body (uiout);
7765796c8dcSSimon Schubert }
7775796c8dcSSimon Schubert
7785796c8dcSSimon Schubert void
uo_table_end(struct ui_out * uiout)7795796c8dcSSimon Schubert uo_table_end (struct ui_out *uiout)
7805796c8dcSSimon Schubert {
7815796c8dcSSimon Schubert if (!uiout->impl->table_end)
7825796c8dcSSimon Schubert return;
7835796c8dcSSimon Schubert uiout->impl->table_end (uiout);
7845796c8dcSSimon Schubert }
7855796c8dcSSimon Schubert
7865796c8dcSSimon Schubert void
uo_table_header(struct ui_out * uiout,int width,enum ui_align align,const char * col_name,const char * colhdr)7875796c8dcSSimon Schubert uo_table_header (struct ui_out *uiout, int width, enum ui_align align,
7885796c8dcSSimon Schubert const char *col_name,
7895796c8dcSSimon Schubert const char *colhdr)
7905796c8dcSSimon Schubert {
7915796c8dcSSimon Schubert if (!uiout->impl->table_header)
7925796c8dcSSimon Schubert return;
7935796c8dcSSimon Schubert uiout->impl->table_header (uiout, width, align, col_name, colhdr);
7945796c8dcSSimon Schubert }
7955796c8dcSSimon Schubert
796*ef5ccd6cSJohn Marino /* Clear the table associated with UIOUT. */
797*ef5ccd6cSJohn Marino
798*ef5ccd6cSJohn Marino static void
clear_table(struct ui_out * uiout)799*ef5ccd6cSJohn Marino clear_table (struct ui_out *uiout)
800*ef5ccd6cSJohn Marino {
801*ef5ccd6cSJohn Marino if (uiout->table.id)
802*ef5ccd6cSJohn Marino xfree (uiout->table.id);
803*ef5ccd6cSJohn Marino clear_header_list (uiout);
804*ef5ccd6cSJohn Marino }
805*ef5ccd6cSJohn Marino
8065796c8dcSSimon Schubert void
uo_begin(struct ui_out * uiout,enum ui_out_type type,int level,const char * id)8075796c8dcSSimon Schubert uo_begin (struct ui_out *uiout,
8085796c8dcSSimon Schubert enum ui_out_type type,
8095796c8dcSSimon Schubert int level,
8105796c8dcSSimon Schubert const char *id)
8115796c8dcSSimon Schubert {
8125796c8dcSSimon Schubert if (uiout->impl->begin == NULL)
8135796c8dcSSimon Schubert return;
8145796c8dcSSimon Schubert uiout->impl->begin (uiout, type, level, id);
8155796c8dcSSimon Schubert }
8165796c8dcSSimon Schubert
8175796c8dcSSimon Schubert void
uo_end(struct ui_out * uiout,enum ui_out_type type,int level)8185796c8dcSSimon Schubert uo_end (struct ui_out *uiout,
8195796c8dcSSimon Schubert enum ui_out_type type,
8205796c8dcSSimon Schubert int level)
8215796c8dcSSimon Schubert {
8225796c8dcSSimon Schubert if (uiout->impl->end == NULL)
8235796c8dcSSimon Schubert return;
8245796c8dcSSimon Schubert uiout->impl->end (uiout, type, level);
8255796c8dcSSimon Schubert }
8265796c8dcSSimon Schubert
8275796c8dcSSimon Schubert void
uo_field_int(struct ui_out * uiout,int fldno,int width,enum ui_align align,const char * fldname,int value)8285796c8dcSSimon Schubert uo_field_int (struct ui_out *uiout, int fldno, int width, enum ui_align align,
8295796c8dcSSimon Schubert const char *fldname,
8305796c8dcSSimon Schubert int value)
8315796c8dcSSimon Schubert {
8325796c8dcSSimon Schubert if (!uiout->impl->field_int)
8335796c8dcSSimon Schubert return;
8345796c8dcSSimon Schubert uiout->impl->field_int (uiout, fldno, width, align, fldname, value);
8355796c8dcSSimon Schubert }
8365796c8dcSSimon Schubert
8375796c8dcSSimon Schubert void
uo_field_skip(struct ui_out * uiout,int fldno,int width,enum ui_align align,const char * fldname)8385796c8dcSSimon Schubert uo_field_skip (struct ui_out *uiout, int fldno, int width, enum ui_align align,
8395796c8dcSSimon Schubert const char *fldname)
8405796c8dcSSimon Schubert {
8415796c8dcSSimon Schubert if (!uiout->impl->field_skip)
8425796c8dcSSimon Schubert return;
8435796c8dcSSimon Schubert uiout->impl->field_skip (uiout, fldno, width, align, fldname);
8445796c8dcSSimon Schubert }
8455796c8dcSSimon Schubert
8465796c8dcSSimon Schubert void
uo_field_string(struct ui_out * uiout,int fldno,int width,enum ui_align align,const char * fldname,const char * string)8475796c8dcSSimon Schubert uo_field_string (struct ui_out *uiout, int fldno, int width,
8485796c8dcSSimon Schubert enum ui_align align,
8495796c8dcSSimon Schubert const char *fldname,
8505796c8dcSSimon Schubert const char *string)
8515796c8dcSSimon Schubert {
8525796c8dcSSimon Schubert if (!uiout->impl->field_string)
8535796c8dcSSimon Schubert return;
8545796c8dcSSimon Schubert uiout->impl->field_string (uiout, fldno, width, align, fldname, string);
8555796c8dcSSimon Schubert }
8565796c8dcSSimon Schubert
8575796c8dcSSimon Schubert void
uo_field_fmt(struct ui_out * uiout,int fldno,int width,enum ui_align align,const char * fldname,const char * format,va_list args)8585796c8dcSSimon Schubert uo_field_fmt (struct ui_out *uiout, int fldno, int width, enum ui_align align,
8595796c8dcSSimon Schubert const char *fldname,
8605796c8dcSSimon Schubert const char *format,
8615796c8dcSSimon Schubert va_list args)
8625796c8dcSSimon Schubert {
8635796c8dcSSimon Schubert if (!uiout->impl->field_fmt)
8645796c8dcSSimon Schubert return;
8655796c8dcSSimon Schubert uiout->impl->field_fmt (uiout, fldno, width, align, fldname, format, args);
8665796c8dcSSimon Schubert }
8675796c8dcSSimon Schubert
8685796c8dcSSimon Schubert void
uo_spaces(struct ui_out * uiout,int numspaces)8695796c8dcSSimon Schubert uo_spaces (struct ui_out *uiout, int numspaces)
8705796c8dcSSimon Schubert {
8715796c8dcSSimon Schubert if (!uiout->impl->spaces)
8725796c8dcSSimon Schubert return;
8735796c8dcSSimon Schubert uiout->impl->spaces (uiout, numspaces);
8745796c8dcSSimon Schubert }
8755796c8dcSSimon Schubert
8765796c8dcSSimon Schubert void
uo_text(struct ui_out * uiout,const char * string)8775796c8dcSSimon Schubert uo_text (struct ui_out *uiout,
8785796c8dcSSimon Schubert const char *string)
8795796c8dcSSimon Schubert {
8805796c8dcSSimon Schubert if (!uiout->impl->text)
8815796c8dcSSimon Schubert return;
8825796c8dcSSimon Schubert uiout->impl->text (uiout, string);
8835796c8dcSSimon Schubert }
8845796c8dcSSimon Schubert
8855796c8dcSSimon Schubert void
uo_message(struct ui_out * uiout,int verbosity,const char * format,va_list args)8865796c8dcSSimon Schubert uo_message (struct ui_out *uiout, int verbosity,
8875796c8dcSSimon Schubert const char *format,
8885796c8dcSSimon Schubert va_list args)
8895796c8dcSSimon Schubert {
8905796c8dcSSimon Schubert if (!uiout->impl->message)
8915796c8dcSSimon Schubert return;
8925796c8dcSSimon Schubert uiout->impl->message (uiout, verbosity, format, args);
8935796c8dcSSimon Schubert }
8945796c8dcSSimon Schubert
8955796c8dcSSimon Schubert void
uo_wrap_hint(struct ui_out * uiout,char * identstring)8965796c8dcSSimon Schubert uo_wrap_hint (struct ui_out *uiout, char *identstring)
8975796c8dcSSimon Schubert {
8985796c8dcSSimon Schubert if (!uiout->impl->wrap_hint)
8995796c8dcSSimon Schubert return;
9005796c8dcSSimon Schubert uiout->impl->wrap_hint (uiout, identstring);
9015796c8dcSSimon Schubert }
9025796c8dcSSimon Schubert
9035796c8dcSSimon Schubert void
uo_flush(struct ui_out * uiout)9045796c8dcSSimon Schubert uo_flush (struct ui_out *uiout)
9055796c8dcSSimon Schubert {
9065796c8dcSSimon Schubert if (!uiout->impl->flush)
9075796c8dcSSimon Schubert return;
9085796c8dcSSimon Schubert uiout->impl->flush (uiout);
9095796c8dcSSimon Schubert }
9105796c8dcSSimon Schubert
9115796c8dcSSimon Schubert int
uo_redirect(struct ui_out * uiout,struct ui_file * outstream)9125796c8dcSSimon Schubert uo_redirect (struct ui_out *uiout, struct ui_file *outstream)
9135796c8dcSSimon Schubert {
9145796c8dcSSimon Schubert if (!uiout->impl->redirect)
9155796c8dcSSimon Schubert return -1;
9165796c8dcSSimon Schubert uiout->impl->redirect (uiout, outstream);
9175796c8dcSSimon Schubert return 0;
9185796c8dcSSimon Schubert }
9195796c8dcSSimon Schubert
920*ef5ccd6cSJohn Marino void
uo_data_destroy(struct ui_out * uiout)921*ef5ccd6cSJohn Marino uo_data_destroy (struct ui_out *uiout)
922*ef5ccd6cSJohn Marino {
923*ef5ccd6cSJohn Marino if (!uiout->impl->data_destroy)
924*ef5ccd6cSJohn Marino return;
925*ef5ccd6cSJohn Marino
926*ef5ccd6cSJohn Marino uiout->impl->data_destroy (uiout);
927*ef5ccd6cSJohn Marino }
928*ef5ccd6cSJohn Marino
9295796c8dcSSimon Schubert /* local functions */
9305796c8dcSSimon Schubert
931c50c785cSJohn Marino /* List of column headers manipulation routines. */
9325796c8dcSSimon Schubert
9335796c8dcSSimon Schubert static void
clear_header_list(struct ui_out * uiout)9345796c8dcSSimon Schubert clear_header_list (struct ui_out *uiout)
9355796c8dcSSimon Schubert {
9365796c8dcSSimon Schubert while (uiout->table.header_first != NULL)
9375796c8dcSSimon Schubert {
9385796c8dcSSimon Schubert uiout->table.header_next = uiout->table.header_first;
9395796c8dcSSimon Schubert uiout->table.header_first = uiout->table.header_first->next;
9405796c8dcSSimon Schubert xfree (uiout->table.header_next->colhdr);
941*ef5ccd6cSJohn Marino xfree (uiout->table.header_next->col_name);
9425796c8dcSSimon Schubert xfree (uiout->table.header_next);
9435796c8dcSSimon Schubert }
9445796c8dcSSimon Schubert gdb_assert (uiout->table.header_first == NULL);
9455796c8dcSSimon Schubert uiout->table.header_last = NULL;
9465796c8dcSSimon Schubert uiout->table.header_next = NULL;
9475796c8dcSSimon Schubert }
9485796c8dcSSimon Schubert
9495796c8dcSSimon Schubert static void
append_header_to_list(struct ui_out * uiout,int width,int alignment,const char * col_name,const char * colhdr)9505796c8dcSSimon Schubert append_header_to_list (struct ui_out *uiout,
9515796c8dcSSimon Schubert int width,
9525796c8dcSSimon Schubert int alignment,
9535796c8dcSSimon Schubert const char *col_name,
9545796c8dcSSimon Schubert const char *colhdr)
9555796c8dcSSimon Schubert {
9565796c8dcSSimon Schubert struct ui_out_hdr *temphdr;
9575796c8dcSSimon Schubert
9585796c8dcSSimon Schubert temphdr = XMALLOC (struct ui_out_hdr);
9595796c8dcSSimon Schubert temphdr->width = width;
9605796c8dcSSimon Schubert temphdr->alignment = alignment;
9615796c8dcSSimon Schubert /* We have to copy the column title as the original may be an
9625796c8dcSSimon Schubert automatic. */
9635796c8dcSSimon Schubert if (colhdr != NULL)
9645796c8dcSSimon Schubert temphdr->colhdr = xstrdup (colhdr);
9655796c8dcSSimon Schubert else
9665796c8dcSSimon Schubert temphdr->colhdr = NULL;
9675796c8dcSSimon Schubert
9685796c8dcSSimon Schubert if (col_name != NULL)
9695796c8dcSSimon Schubert temphdr->col_name = xstrdup (col_name);
9705796c8dcSSimon Schubert else if (colhdr != NULL)
9715796c8dcSSimon Schubert temphdr->col_name = xstrdup (colhdr);
9725796c8dcSSimon Schubert else
9735796c8dcSSimon Schubert temphdr->col_name = NULL;
9745796c8dcSSimon Schubert
9755796c8dcSSimon Schubert temphdr->next = NULL;
9765796c8dcSSimon Schubert if (uiout->table.header_first == NULL)
9775796c8dcSSimon Schubert {
9785796c8dcSSimon Schubert temphdr->colno = 1;
9795796c8dcSSimon Schubert uiout->table.header_first = temphdr;
9805796c8dcSSimon Schubert uiout->table.header_last = temphdr;
9815796c8dcSSimon Schubert }
9825796c8dcSSimon Schubert else
9835796c8dcSSimon Schubert {
9845796c8dcSSimon Schubert temphdr->colno = uiout->table.header_last->colno + 1;
9855796c8dcSSimon Schubert uiout->table.header_last->next = temphdr;
9865796c8dcSSimon Schubert uiout->table.header_last = temphdr;
9875796c8dcSSimon Schubert }
9885796c8dcSSimon Schubert uiout->table.header_next = uiout->table.header_last;
9895796c8dcSSimon Schubert }
9905796c8dcSSimon Schubert
991a45ae5f8SJohn Marino /* Extract the format information for the NEXT header and advance
9925796c8dcSSimon Schubert the header pointer. Return 0 if there was no next header. */
9935796c8dcSSimon Schubert
9945796c8dcSSimon Schubert static int
get_next_header(struct ui_out * uiout,int * colno,int * width,int * alignment,char ** colhdr)9955796c8dcSSimon Schubert get_next_header (struct ui_out *uiout,
9965796c8dcSSimon Schubert int *colno,
9975796c8dcSSimon Schubert int *width,
9985796c8dcSSimon Schubert int *alignment,
9995796c8dcSSimon Schubert char **colhdr)
10005796c8dcSSimon Schubert {
10015796c8dcSSimon Schubert /* There may be no headers at all or we may have used all columns. */
10025796c8dcSSimon Schubert if (uiout->table.header_next == NULL)
10035796c8dcSSimon Schubert return 0;
10045796c8dcSSimon Schubert *colno = uiout->table.header_next->colno;
10055796c8dcSSimon Schubert *width = uiout->table.header_next->width;
10065796c8dcSSimon Schubert *alignment = uiout->table.header_next->alignment;
10075796c8dcSSimon Schubert *colhdr = uiout->table.header_next->colhdr;
10085796c8dcSSimon Schubert /* Advance the header pointer to the next entry. */
10095796c8dcSSimon Schubert uiout->table.header_next = uiout->table.header_next->next;
10105796c8dcSSimon Schubert return 1;
10115796c8dcSSimon Schubert }
10125796c8dcSSimon Schubert
10135796c8dcSSimon Schubert
10145796c8dcSSimon Schubert /* Verify that the field/tuple/list is correctly positioned. Return
10155796c8dcSSimon Schubert the field number and corresponding alignment (if
10165796c8dcSSimon Schubert available/applicable). */
10175796c8dcSSimon Schubert
10185796c8dcSSimon Schubert static void
verify_field(struct ui_out * uiout,int * fldno,int * width,int * align)10195796c8dcSSimon Schubert verify_field (struct ui_out *uiout, int *fldno, int *width, int *align)
10205796c8dcSSimon Schubert {
10215796c8dcSSimon Schubert struct ui_out_level *current = current_level (uiout);
10225796c8dcSSimon Schubert char *text;
10235796c8dcSSimon Schubert
10245796c8dcSSimon Schubert if (uiout->table.flag)
10255796c8dcSSimon Schubert {
10265796c8dcSSimon Schubert if (!uiout->table.body_flag)
10275796c8dcSSimon Schubert internal_error (__FILE__, __LINE__,
10285796c8dcSSimon Schubert _("table_body missing; table fields must be \
10295796c8dcSSimon Schubert specified after table_body and inside a list."));
10305796c8dcSSimon Schubert /* NOTE: cagney/2001-12-08: There was a check here to ensure
10315796c8dcSSimon Schubert that this code was only executed when uiout->level was
10325796c8dcSSimon Schubert greater than zero. That no longer applies - this code is run
10335796c8dcSSimon Schubert before each table row tuple is started and at that point the
10345796c8dcSSimon Schubert level is zero. */
10355796c8dcSSimon Schubert }
10365796c8dcSSimon Schubert
10375796c8dcSSimon Schubert current->field_count += 1;
10385796c8dcSSimon Schubert
10395796c8dcSSimon Schubert if (uiout->table.body_flag
10405796c8dcSSimon Schubert && uiout->table.entry_level == uiout->level
10415796c8dcSSimon Schubert && get_next_header (uiout, fldno, width, align, &text))
10425796c8dcSSimon Schubert {
10435796c8dcSSimon Schubert if (*fldno != current->field_count)
10445796c8dcSSimon Schubert internal_error (__FILE__, __LINE__,
10455796c8dcSSimon Schubert _("ui-out internal error in handling headers."));
10465796c8dcSSimon Schubert }
10475796c8dcSSimon Schubert else
10485796c8dcSSimon Schubert {
10495796c8dcSSimon Schubert *width = 0;
10505796c8dcSSimon Schubert *align = ui_noalign;
10515796c8dcSSimon Schubert *fldno = current->field_count;
10525796c8dcSSimon Schubert }
10535796c8dcSSimon Schubert }
10545796c8dcSSimon Schubert
10555796c8dcSSimon Schubert
1056c50c785cSJohn Marino /* Access to ui-out members data. */
10575796c8dcSSimon Schubert
1058cf7f2e2dSJohn Marino void *
ui_out_data(struct ui_out * uiout)10595796c8dcSSimon Schubert ui_out_data (struct ui_out *uiout)
10605796c8dcSSimon Schubert {
10615796c8dcSSimon Schubert return uiout->data;
10625796c8dcSSimon Schubert }
10635796c8dcSSimon Schubert
1064c50c785cSJohn Marino /* Access table field parameters. */
1065c50c785cSJohn Marino int
ui_out_query_field(struct ui_out * uiout,int colno,int * width,int * alignment,char ** col_name)1066c50c785cSJohn Marino ui_out_query_field (struct ui_out *uiout, int colno,
1067c50c785cSJohn Marino int *width, int *alignment, char **col_name)
1068c50c785cSJohn Marino {
1069c50c785cSJohn Marino struct ui_out_hdr *hdr;
1070c50c785cSJohn Marino
1071c50c785cSJohn Marino if (!uiout->table.flag)
1072c50c785cSJohn Marino return 0;
1073c50c785cSJohn Marino
1074c50c785cSJohn Marino for (hdr = uiout->table.header_first; hdr; hdr = hdr->next)
1075c50c785cSJohn Marino if (hdr->colno == colno)
1076c50c785cSJohn Marino {
1077c50c785cSJohn Marino *width = hdr->width;
1078c50c785cSJohn Marino *alignment = hdr->alignment;
1079c50c785cSJohn Marino *col_name = hdr->col_name;
1080c50c785cSJohn Marino return 1;
1081c50c785cSJohn Marino }
1082c50c785cSJohn Marino
1083c50c785cSJohn Marino return 0;
1084c50c785cSJohn Marino }
1085c50c785cSJohn Marino
1086c50c785cSJohn Marino /* Initalize private members at startup. */
10875796c8dcSSimon Schubert
10885796c8dcSSimon Schubert struct ui_out *
ui_out_new(struct ui_out_impl * impl,void * data,int flags)1089cf7f2e2dSJohn Marino ui_out_new (struct ui_out_impl *impl, void *data,
10905796c8dcSSimon Schubert int flags)
10915796c8dcSSimon Schubert {
10925796c8dcSSimon Schubert struct ui_out *uiout = XMALLOC (struct ui_out);
1093cf7f2e2dSJohn Marino
10945796c8dcSSimon Schubert uiout->data = data;
10955796c8dcSSimon Schubert uiout->impl = impl;
10965796c8dcSSimon Schubert uiout->flags = flags;
10975796c8dcSSimon Schubert uiout->table.flag = 0;
10985796c8dcSSimon Schubert uiout->table.body_flag = 0;
10995796c8dcSSimon Schubert uiout->level = 0;
11005796c8dcSSimon Schubert memset (uiout->levels, 0, sizeof (uiout->levels));
11015796c8dcSSimon Schubert uiout->table.header_first = NULL;
11025796c8dcSSimon Schubert uiout->table.header_last = NULL;
11035796c8dcSSimon Schubert uiout->table.header_next = NULL;
11045796c8dcSSimon Schubert return uiout;
11055796c8dcSSimon Schubert }
11065796c8dcSSimon Schubert
1107*ef5ccd6cSJohn Marino /* Free UIOUT and the memory areas it references. */
1108*ef5ccd6cSJohn Marino
1109*ef5ccd6cSJohn Marino void
ui_out_destroy(struct ui_out * uiout)1110*ef5ccd6cSJohn Marino ui_out_destroy (struct ui_out *uiout)
1111*ef5ccd6cSJohn Marino {
1112*ef5ccd6cSJohn Marino uo_data_destroy (uiout);
1113*ef5ccd6cSJohn Marino clear_table (uiout);
1114*ef5ccd6cSJohn Marino xfree (uiout);
1115*ef5ccd6cSJohn Marino }
1116*ef5ccd6cSJohn Marino
1117c50c785cSJohn Marino /* Standard gdb initialization hook. */
11185796c8dcSSimon Schubert
11195796c8dcSSimon Schubert void
_initialize_ui_out(void)11205796c8dcSSimon Schubert _initialize_ui_out (void)
11215796c8dcSSimon Schubert {
11225796c8dcSSimon Schubert /* nothing needs to be done */
11235796c8dcSSimon Schubert }
1124