15796c8dcSSimon Schubert /* Output generating routines for GDB. 25796c8dcSSimon Schubert 3*c50c785cSJohn Marino Copyright (C) 1999, 2000, 2001, 2002, 2004, 2005, 2007, 2008, 2009, 2010, 4*c50c785cSJohn Marino 2011 Free Software Foundation, Inc. 55796c8dcSSimon Schubert 65796c8dcSSimon Schubert Contributed by Cygnus Solutions. 75796c8dcSSimon Schubert Written by Fernando Nasser for Cygnus. 85796c8dcSSimon Schubert 95796c8dcSSimon Schubert This file is part of GDB. 105796c8dcSSimon Schubert 115796c8dcSSimon Schubert This program is free software; you can redistribute it and/or modify 125796c8dcSSimon Schubert it under the terms of the GNU General Public License as published by 135796c8dcSSimon Schubert the Free Software Foundation; either version 3 of the License, or 145796c8dcSSimon Schubert (at your option) any later version. 155796c8dcSSimon Schubert 165796c8dcSSimon Schubert This program is distributed in the hope that it will be useful, 175796c8dcSSimon Schubert but WITHOUT ANY WARRANTY; without even the implied warranty of 185796c8dcSSimon Schubert MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 195796c8dcSSimon Schubert GNU General Public License for more details. 205796c8dcSSimon Schubert 215796c8dcSSimon Schubert You should have received a copy of the GNU General Public License 225796c8dcSSimon Schubert along with this program. If not, see <http://www.gnu.org/licenses/>. */ 235796c8dcSSimon Schubert 245796c8dcSSimon Schubert #include "defs.h" 255796c8dcSSimon Schubert #include "gdb_string.h" 265796c8dcSSimon Schubert #include "expression.h" /* For language.h */ 275796c8dcSSimon Schubert #include "language.h" 285796c8dcSSimon Schubert #include "ui-out.h" 295796c8dcSSimon Schubert #include "gdb_assert.h" 305796c8dcSSimon Schubert 315796c8dcSSimon Schubert /* table header structures */ 325796c8dcSSimon Schubert 335796c8dcSSimon Schubert struct ui_out_hdr 345796c8dcSSimon Schubert { 355796c8dcSSimon Schubert int colno; 365796c8dcSSimon Schubert int width; 375796c8dcSSimon Schubert int alignment; 385796c8dcSSimon Schubert char *col_name; 395796c8dcSSimon Schubert char *colhdr; 405796c8dcSSimon Schubert struct ui_out_hdr *next; 415796c8dcSSimon Schubert }; 425796c8dcSSimon Schubert 435796c8dcSSimon Schubert /* Maintain a stack so that the info applicable to the inner most list 445796c8dcSSimon Schubert is always available. Stack/nested level 0 is reserved for the 455796c8dcSSimon Schubert top-level result. */ 465796c8dcSSimon Schubert 47cf7f2e2dSJohn Marino enum { MAX_UI_OUT_LEVELS = 8 }; 485796c8dcSSimon Schubert 495796c8dcSSimon Schubert struct ui_out_level 505796c8dcSSimon Schubert { 51*c50c785cSJohn Marino /* Count each field; the first element is for non-list fields. */ 525796c8dcSSimon Schubert int field_count; 535796c8dcSSimon Schubert /* The type of this level. */ 545796c8dcSSimon Schubert enum ui_out_type type; 555796c8dcSSimon Schubert }; 565796c8dcSSimon Schubert 575796c8dcSSimon Schubert /* Tables are special. Maintain a separate structure that tracks 585796c8dcSSimon Schubert their state. At present an output can only contain a single table 595796c8dcSSimon Schubert but that restriction might eventually be lifted. */ 605796c8dcSSimon Schubert 615796c8dcSSimon Schubert struct ui_out_table 625796c8dcSSimon Schubert { 635796c8dcSSimon Schubert /* If on, a table is being generated. */ 645796c8dcSSimon Schubert int flag; 655796c8dcSSimon Schubert 665796c8dcSSimon Schubert /* If on, the body of a table is being generated. If off, the table 675796c8dcSSimon Schubert header is being generated. */ 685796c8dcSSimon Schubert int body_flag; 695796c8dcSSimon Schubert 705796c8dcSSimon Schubert /* The level at which each entry of the table is to be found. A row 715796c8dcSSimon Schubert (a tuple) is made up of entries. Consequently ENTRY_LEVEL is one 725796c8dcSSimon Schubert above that of the table. */ 735796c8dcSSimon Schubert int entry_level; 745796c8dcSSimon Schubert 755796c8dcSSimon Schubert /* Number of table columns (as specified in the table_begin call). */ 765796c8dcSSimon Schubert int columns; 775796c8dcSSimon Schubert 785796c8dcSSimon Schubert /* String identifying the table (as specified in the table_begin 795796c8dcSSimon Schubert call). */ 805796c8dcSSimon Schubert char *id; 815796c8dcSSimon Schubert 825796c8dcSSimon Schubert /* Points to the first table header (if any). */ 835796c8dcSSimon Schubert struct ui_out_hdr *header_first; 845796c8dcSSimon Schubert 855796c8dcSSimon Schubert /* Points to the last table header (if any). */ 865796c8dcSSimon Schubert struct ui_out_hdr *header_last; 875796c8dcSSimon Schubert 885796c8dcSSimon Schubert /* Points to header of NEXT column to format. */ 895796c8dcSSimon Schubert struct ui_out_hdr *header_next; 905796c8dcSSimon Schubert 915796c8dcSSimon Schubert }; 925796c8dcSSimon Schubert 935796c8dcSSimon Schubert 945796c8dcSSimon Schubert /* The ui_out structure */ 955796c8dcSSimon Schubert /* Any change here requires a corresponding one in the initialization 96*c50c785cSJohn Marino of the default uiout, which is statically initialized. */ 975796c8dcSSimon Schubert 985796c8dcSSimon Schubert struct ui_out 995796c8dcSSimon Schubert { 1005796c8dcSSimon Schubert int flags; 101*c50c785cSJohn Marino /* Specific implementation of ui-out. */ 1025796c8dcSSimon Schubert struct ui_out_impl *impl; 103cf7f2e2dSJohn Marino void *data; 1045796c8dcSSimon Schubert 1055796c8dcSSimon Schubert /* Sub structure tracking the ui-out depth. */ 1065796c8dcSSimon Schubert int level; 1075796c8dcSSimon Schubert struct ui_out_level levels[MAX_UI_OUT_LEVELS]; 1085796c8dcSSimon Schubert 1095796c8dcSSimon Schubert /* A table, if any. At present only a single table is supported. */ 1105796c8dcSSimon Schubert struct ui_out_table table; 1115796c8dcSSimon Schubert }; 1125796c8dcSSimon Schubert 1135796c8dcSSimon Schubert /* The current (inner most) level. */ 1145796c8dcSSimon Schubert static struct ui_out_level * 1155796c8dcSSimon Schubert current_level (struct ui_out *uiout) 1165796c8dcSSimon Schubert { 1175796c8dcSSimon Schubert return &uiout->levels[uiout->level]; 1185796c8dcSSimon Schubert } 1195796c8dcSSimon Schubert 1205796c8dcSSimon Schubert /* Create a new level, of TYPE. Return the new level's index. */ 1215796c8dcSSimon Schubert static int 1225796c8dcSSimon Schubert push_level (struct ui_out *uiout, 1235796c8dcSSimon Schubert enum ui_out_type type, 1245796c8dcSSimon Schubert const char *id) 1255796c8dcSSimon Schubert { 1265796c8dcSSimon Schubert struct ui_out_level *current; 127cf7f2e2dSJohn Marino 1285796c8dcSSimon Schubert /* We had better not overflow the buffer. */ 1295796c8dcSSimon Schubert uiout->level++; 1305796c8dcSSimon Schubert gdb_assert (uiout->level >= 0 && uiout->level < MAX_UI_OUT_LEVELS); 1315796c8dcSSimon Schubert current = current_level (uiout); 1325796c8dcSSimon Schubert current->field_count = 0; 1335796c8dcSSimon Schubert current->type = type; 1345796c8dcSSimon Schubert return uiout->level; 1355796c8dcSSimon Schubert } 1365796c8dcSSimon Schubert 1375796c8dcSSimon Schubert /* Discard the current level, return the discarded level's index. 1385796c8dcSSimon Schubert TYPE is the type of the level being discarded. */ 1395796c8dcSSimon Schubert static int 1405796c8dcSSimon Schubert pop_level (struct ui_out *uiout, 1415796c8dcSSimon Schubert enum ui_out_type type) 1425796c8dcSSimon Schubert { 1435796c8dcSSimon Schubert /* We had better not underflow the buffer. */ 1445796c8dcSSimon Schubert gdb_assert (uiout->level > 0 && uiout->level < MAX_UI_OUT_LEVELS); 1455796c8dcSSimon Schubert gdb_assert (current_level (uiout)->type == type); 1465796c8dcSSimon Schubert uiout->level--; 1475796c8dcSSimon Schubert return uiout->level + 1; 1485796c8dcSSimon Schubert } 1495796c8dcSSimon Schubert 1505796c8dcSSimon Schubert 151*c50c785cSJohn Marino /* These are the default implementation functions. */ 1525796c8dcSSimon Schubert 1535796c8dcSSimon Schubert static void default_table_begin (struct ui_out *uiout, int nbrofcols, 1545796c8dcSSimon Schubert int nr_rows, const char *tblid); 1555796c8dcSSimon Schubert static void default_table_body (struct ui_out *uiout); 1565796c8dcSSimon Schubert static void default_table_end (struct ui_out *uiout); 1575796c8dcSSimon Schubert static void default_table_header (struct ui_out *uiout, int width, 1585796c8dcSSimon Schubert enum ui_align alig, const char *col_name, 1595796c8dcSSimon Schubert const char *colhdr); 1605796c8dcSSimon Schubert static void default_begin (struct ui_out *uiout, 1615796c8dcSSimon Schubert enum ui_out_type type, 1625796c8dcSSimon Schubert int level, const char *id); 1635796c8dcSSimon Schubert static void default_end (struct ui_out *uiout, 1645796c8dcSSimon Schubert enum ui_out_type type, 1655796c8dcSSimon Schubert int level); 1665796c8dcSSimon Schubert static void default_field_int (struct ui_out *uiout, int fldno, int width, 1675796c8dcSSimon Schubert enum ui_align alig, 1685796c8dcSSimon Schubert const char *fldname, 1695796c8dcSSimon Schubert int value); 1705796c8dcSSimon Schubert static void default_field_skip (struct ui_out *uiout, int fldno, int width, 1715796c8dcSSimon Schubert enum ui_align alig, 1725796c8dcSSimon Schubert const char *fldname); 1735796c8dcSSimon Schubert static void default_field_string (struct ui_out *uiout, int fldno, int width, 1745796c8dcSSimon Schubert enum ui_align align, 1755796c8dcSSimon Schubert const char *fldname, 1765796c8dcSSimon Schubert const char *string); 1775796c8dcSSimon Schubert static void default_field_fmt (struct ui_out *uiout, int fldno, 1785796c8dcSSimon Schubert int width, enum ui_align align, 1795796c8dcSSimon Schubert const char *fldname, 1805796c8dcSSimon Schubert const char *format, 181cf7f2e2dSJohn Marino va_list args) ATTRIBUTE_PRINTF (6, 0); 1825796c8dcSSimon Schubert static void default_spaces (struct ui_out *uiout, int numspaces); 1835796c8dcSSimon Schubert static void default_text (struct ui_out *uiout, const char *string); 1845796c8dcSSimon Schubert static void default_message (struct ui_out *uiout, int verbosity, 1855796c8dcSSimon Schubert const char *format, 186cf7f2e2dSJohn Marino va_list args) ATTRIBUTE_PRINTF (3, 0); 1875796c8dcSSimon Schubert static void default_wrap_hint (struct ui_out *uiout, char *identstring); 1885796c8dcSSimon Schubert static void default_flush (struct ui_out *uiout); 1895796c8dcSSimon Schubert 190*c50c785cSJohn 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, 2105796c8dcSSimon Schubert 0, /* Does not need MI hacks. */ 2115796c8dcSSimon Schubert }; 2125796c8dcSSimon Schubert 2135796c8dcSSimon Schubert /* The default ui_out */ 2145796c8dcSSimon Schubert 2155796c8dcSSimon Schubert struct ui_out def_uiout = 2165796c8dcSSimon Schubert { 2175796c8dcSSimon Schubert 0, /* flags */ 2185796c8dcSSimon Schubert &default_ui_out_impl, /* impl */ 2195796c8dcSSimon Schubert }; 2205796c8dcSSimon Schubert 2215796c8dcSSimon Schubert /* Pointer to current ui_out */ 2225796c8dcSSimon Schubert /* FIXME: This should not be a global, but something passed down from main.c 223*c50c785cSJohn Marino or top.c. */ 2245796c8dcSSimon Schubert 2255796c8dcSSimon Schubert struct ui_out *uiout = &def_uiout; 2265796c8dcSSimon Schubert 227*c50c785cSJohn Marino /* These are the interfaces to implementation functions. */ 2285796c8dcSSimon Schubert 2295796c8dcSSimon Schubert static void uo_table_begin (struct ui_out *uiout, int nbrofcols, 2305796c8dcSSimon Schubert int nr_rows, const char *tblid); 2315796c8dcSSimon Schubert static void uo_table_body (struct ui_out *uiout); 2325796c8dcSSimon Schubert static void uo_table_end (struct ui_out *uiout); 2335796c8dcSSimon Schubert static void uo_table_header (struct ui_out *uiout, int width, 2345796c8dcSSimon Schubert enum ui_align align, const char *col_name, 2355796c8dcSSimon Schubert const char *colhdr); 2365796c8dcSSimon Schubert static void uo_begin (struct ui_out *uiout, 2375796c8dcSSimon Schubert enum ui_out_type type, 2385796c8dcSSimon Schubert int level, const char *id); 2395796c8dcSSimon Schubert static void uo_end (struct ui_out *uiout, 2405796c8dcSSimon Schubert enum ui_out_type type, 2415796c8dcSSimon Schubert int level); 2425796c8dcSSimon Schubert static void uo_field_int (struct ui_out *uiout, int fldno, int width, 2435796c8dcSSimon Schubert enum ui_align align, const char *fldname, int value); 2445796c8dcSSimon Schubert static void uo_field_skip (struct ui_out *uiout, int fldno, int width, 2455796c8dcSSimon Schubert enum ui_align align, const char *fldname); 2465796c8dcSSimon Schubert static void uo_field_fmt (struct ui_out *uiout, int fldno, int width, 2475796c8dcSSimon Schubert enum ui_align align, const char *fldname, 2485796c8dcSSimon Schubert const char *format, va_list args) 249cf7f2e2dSJohn Marino ATTRIBUTE_PRINTF (6, 0); 2505796c8dcSSimon Schubert static void uo_spaces (struct ui_out *uiout, int numspaces); 2515796c8dcSSimon Schubert static void uo_text (struct ui_out *uiout, const char *string); 2525796c8dcSSimon Schubert static void uo_message (struct ui_out *uiout, int verbosity, 2535796c8dcSSimon Schubert const char *format, va_list args) 254cf7f2e2dSJohn Marino ATTRIBUTE_PRINTF (3, 0); 2555796c8dcSSimon Schubert static void uo_wrap_hint (struct ui_out *uiout, char *identstring); 2565796c8dcSSimon Schubert static void uo_flush (struct ui_out *uiout); 2575796c8dcSSimon Schubert static int uo_redirect (struct ui_out *uiout, struct ui_file *outstream); 2585796c8dcSSimon Schubert 2595796c8dcSSimon Schubert /* Prototypes for local functions */ 2605796c8dcSSimon Schubert 2615796c8dcSSimon Schubert extern void _initialize_ui_out (void); 2625796c8dcSSimon Schubert static void append_header_to_list (struct ui_out *uiout, int width, 2635796c8dcSSimon Schubert int alignment, const char *col_name, 2645796c8dcSSimon Schubert const char *colhdr); 2655796c8dcSSimon Schubert static int get_next_header (struct ui_out *uiout, int *colno, int *width, 2665796c8dcSSimon Schubert int *alignment, char **colhdr); 2675796c8dcSSimon Schubert static void clear_header_list (struct ui_out *uiout); 2685796c8dcSSimon Schubert static void verify_field (struct ui_out *uiout, int *fldno, int *width, 2695796c8dcSSimon Schubert int *align); 2705796c8dcSSimon Schubert 2715796c8dcSSimon Schubert /* exported functions (ui_out API) */ 2725796c8dcSSimon Schubert 273*c50c785cSJohn Marino /* Mark beginning of a table. */ 2745796c8dcSSimon Schubert 2755796c8dcSSimon Schubert static void 2765796c8dcSSimon Schubert ui_out_table_begin (struct ui_out *uiout, int nbrofcols, 2775796c8dcSSimon Schubert int nr_rows, 2785796c8dcSSimon Schubert const char *tblid) 2795796c8dcSSimon Schubert { 2805796c8dcSSimon Schubert if (uiout->table.flag) 2815796c8dcSSimon Schubert internal_error (__FILE__, __LINE__, 2825796c8dcSSimon Schubert _("tables cannot be nested; table_begin found before \ 2835796c8dcSSimon Schubert previous table_end.")); 2845796c8dcSSimon Schubert 2855796c8dcSSimon Schubert uiout->table.flag = 1; 2865796c8dcSSimon Schubert uiout->table.body_flag = 0; 2875796c8dcSSimon Schubert uiout->table.entry_level = uiout->level + 1; 2885796c8dcSSimon Schubert uiout->table.columns = nbrofcols; 2895796c8dcSSimon Schubert if (tblid != NULL) 2905796c8dcSSimon Schubert uiout->table.id = xstrdup (tblid); 2915796c8dcSSimon Schubert else 2925796c8dcSSimon Schubert uiout->table.id = NULL; 2935796c8dcSSimon Schubert clear_header_list (uiout); 2945796c8dcSSimon Schubert 2955796c8dcSSimon Schubert uo_table_begin (uiout, nbrofcols, nr_rows, uiout->table.id); 2965796c8dcSSimon Schubert } 2975796c8dcSSimon Schubert 2985796c8dcSSimon Schubert void 2995796c8dcSSimon Schubert ui_out_table_body (struct ui_out *uiout) 3005796c8dcSSimon Schubert { 3015796c8dcSSimon Schubert if (!uiout->table.flag) 3025796c8dcSSimon Schubert internal_error (__FILE__, __LINE__, 3035796c8dcSSimon Schubert _("table_body outside a table is not valid; it must be \ 3045796c8dcSSimon Schubert after a table_begin and before a table_end.")); 3055796c8dcSSimon Schubert if (uiout->table.body_flag) 3065796c8dcSSimon Schubert internal_error (__FILE__, __LINE__, 3075796c8dcSSimon Schubert _("extra table_body call not allowed; there must be \ 3085796c8dcSSimon Schubert only one table_body after a table_begin and before a table_end.")); 3095796c8dcSSimon Schubert if (uiout->table.header_next->colno != uiout->table.columns) 3105796c8dcSSimon Schubert internal_error (__FILE__, __LINE__, 3115796c8dcSSimon Schubert _("number of headers differ from number of table \ 3125796c8dcSSimon Schubert columns.")); 3135796c8dcSSimon Schubert 3145796c8dcSSimon Schubert uiout->table.body_flag = 1; 3155796c8dcSSimon Schubert uiout->table.header_next = uiout->table.header_first; 3165796c8dcSSimon Schubert 3175796c8dcSSimon Schubert uo_table_body (uiout); 3185796c8dcSSimon Schubert } 3195796c8dcSSimon Schubert 3205796c8dcSSimon Schubert static void 3215796c8dcSSimon Schubert ui_out_table_end (struct ui_out *uiout) 3225796c8dcSSimon Schubert { 3235796c8dcSSimon Schubert if (!uiout->table.flag) 3245796c8dcSSimon Schubert internal_error (__FILE__, __LINE__, 3255796c8dcSSimon Schubert _("misplaced table_end or missing table_begin.")); 3265796c8dcSSimon Schubert 3275796c8dcSSimon Schubert uiout->table.entry_level = 0; 3285796c8dcSSimon Schubert uiout->table.body_flag = 0; 3295796c8dcSSimon Schubert uiout->table.flag = 0; 3305796c8dcSSimon Schubert 3315796c8dcSSimon Schubert uo_table_end (uiout); 3325796c8dcSSimon Schubert 3335796c8dcSSimon Schubert if (uiout->table.id) 3345796c8dcSSimon Schubert xfree (uiout->table.id); 3355796c8dcSSimon Schubert clear_header_list (uiout); 3365796c8dcSSimon Schubert } 3375796c8dcSSimon Schubert 3385796c8dcSSimon Schubert void 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 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 * 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 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 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 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 * 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 * 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 * 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 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 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 4895796c8dcSSimon Schubert void 4905796c8dcSSimon Schubert ui_out_field_core_addr (struct ui_out *uiout, 4915796c8dcSSimon Schubert const char *fldname, 4925796c8dcSSimon Schubert struct gdbarch *gdbarch, 4935796c8dcSSimon Schubert CORE_ADDR address) 4945796c8dcSSimon Schubert { 495*c50c785cSJohn Marino ui_out_field_string (uiout, fldname, 496*c50c785cSJohn Marino print_core_address (gdbarch, address)); 4975796c8dcSSimon Schubert } 4985796c8dcSSimon Schubert 4995796c8dcSSimon Schubert void 5005796c8dcSSimon Schubert ui_out_field_stream (struct ui_out *uiout, 5015796c8dcSSimon Schubert const char *fldname, 5025796c8dcSSimon Schubert struct ui_stream *buf) 5035796c8dcSSimon Schubert { 5045796c8dcSSimon Schubert long length; 5055796c8dcSSimon Schubert char *buffer = ui_file_xstrdup (buf->stream, &length); 5065796c8dcSSimon Schubert struct cleanup *old_cleanup = make_cleanup (xfree, buffer); 507cf7f2e2dSJohn Marino 5085796c8dcSSimon Schubert if (length > 0) 5095796c8dcSSimon Schubert ui_out_field_string (uiout, fldname, buffer); 5105796c8dcSSimon Schubert else 5115796c8dcSSimon Schubert ui_out_field_skip (uiout, fldname); 5125796c8dcSSimon Schubert ui_file_rewind (buf->stream); 5135796c8dcSSimon Schubert do_cleanups (old_cleanup); 5145796c8dcSSimon Schubert } 5155796c8dcSSimon Schubert 516*c50c785cSJohn Marino /* Used to omit a field. */ 5175796c8dcSSimon Schubert 5185796c8dcSSimon Schubert void 5195796c8dcSSimon Schubert ui_out_field_skip (struct ui_out *uiout, 5205796c8dcSSimon Schubert const char *fldname) 5215796c8dcSSimon Schubert { 5225796c8dcSSimon Schubert int fldno; 5235796c8dcSSimon Schubert int width; 5245796c8dcSSimon Schubert int align; 5255796c8dcSSimon Schubert 5265796c8dcSSimon Schubert verify_field (uiout, &fldno, &width, &align); 5275796c8dcSSimon Schubert 5285796c8dcSSimon Schubert uo_field_skip (uiout, fldno, width, align, fldname); 5295796c8dcSSimon Schubert } 5305796c8dcSSimon Schubert 5315796c8dcSSimon Schubert void 5325796c8dcSSimon Schubert ui_out_field_string (struct ui_out *uiout, 5335796c8dcSSimon Schubert const char *fldname, 5345796c8dcSSimon Schubert const char *string) 5355796c8dcSSimon Schubert { 5365796c8dcSSimon Schubert int fldno; 5375796c8dcSSimon Schubert int width; 5385796c8dcSSimon Schubert int align; 5395796c8dcSSimon Schubert 5405796c8dcSSimon Schubert verify_field (uiout, &fldno, &width, &align); 5415796c8dcSSimon Schubert 5425796c8dcSSimon Schubert uo_field_string (uiout, fldno, width, align, fldname, string); 5435796c8dcSSimon Schubert } 5445796c8dcSSimon Schubert 5455796c8dcSSimon Schubert /* VARARGS */ 5465796c8dcSSimon Schubert void 5475796c8dcSSimon Schubert ui_out_field_fmt (struct ui_out *uiout, 5485796c8dcSSimon Schubert const char *fldname, 5495796c8dcSSimon Schubert const char *format, ...) 5505796c8dcSSimon Schubert { 5515796c8dcSSimon Schubert va_list args; 5525796c8dcSSimon Schubert int fldno; 5535796c8dcSSimon Schubert int width; 5545796c8dcSSimon Schubert int align; 5555796c8dcSSimon Schubert 556*c50c785cSJohn Marino /* Will not align, but has to call anyway. */ 5575796c8dcSSimon Schubert verify_field (uiout, &fldno, &width, &align); 5585796c8dcSSimon Schubert 5595796c8dcSSimon Schubert va_start (args, format); 5605796c8dcSSimon Schubert 5615796c8dcSSimon Schubert uo_field_fmt (uiout, fldno, width, align, fldname, format, args); 5625796c8dcSSimon Schubert 5635796c8dcSSimon Schubert va_end (args); 5645796c8dcSSimon Schubert } 5655796c8dcSSimon Schubert 5665796c8dcSSimon Schubert void 5675796c8dcSSimon Schubert ui_out_spaces (struct ui_out *uiout, int numspaces) 5685796c8dcSSimon Schubert { 5695796c8dcSSimon Schubert uo_spaces (uiout, numspaces); 5705796c8dcSSimon Schubert } 5715796c8dcSSimon Schubert 5725796c8dcSSimon Schubert void 5735796c8dcSSimon Schubert ui_out_text (struct ui_out *uiout, 5745796c8dcSSimon Schubert const char *string) 5755796c8dcSSimon Schubert { 5765796c8dcSSimon Schubert uo_text (uiout, string); 5775796c8dcSSimon Schubert } 5785796c8dcSSimon Schubert 5795796c8dcSSimon Schubert void 5805796c8dcSSimon Schubert ui_out_message (struct ui_out *uiout, int verbosity, 5815796c8dcSSimon Schubert const char *format,...) 5825796c8dcSSimon Schubert { 5835796c8dcSSimon Schubert va_list args; 5845796c8dcSSimon Schubert 5855796c8dcSSimon Schubert va_start (args, format); 5865796c8dcSSimon Schubert uo_message (uiout, verbosity, format, args); 5875796c8dcSSimon Schubert va_end (args); 5885796c8dcSSimon Schubert } 5895796c8dcSSimon Schubert 5905796c8dcSSimon Schubert struct ui_stream * 5915796c8dcSSimon Schubert ui_out_stream_new (struct ui_out *uiout) 5925796c8dcSSimon Schubert { 5935796c8dcSSimon Schubert struct ui_stream *tempbuf; 5945796c8dcSSimon Schubert 5955796c8dcSSimon Schubert tempbuf = XMALLOC (struct ui_stream); 5965796c8dcSSimon Schubert tempbuf->uiout = uiout; 5975796c8dcSSimon Schubert tempbuf->stream = mem_fileopen (); 5985796c8dcSSimon Schubert return tempbuf; 5995796c8dcSSimon Schubert } 6005796c8dcSSimon Schubert 6015796c8dcSSimon Schubert void 6025796c8dcSSimon Schubert ui_out_stream_delete (struct ui_stream *buf) 6035796c8dcSSimon Schubert { 6045796c8dcSSimon Schubert ui_file_delete (buf->stream); 6055796c8dcSSimon Schubert xfree (buf); 6065796c8dcSSimon Schubert } 6075796c8dcSSimon Schubert 6085796c8dcSSimon Schubert static void 6095796c8dcSSimon Schubert do_stream_delete (void *buf) 6105796c8dcSSimon Schubert { 6115796c8dcSSimon Schubert ui_out_stream_delete (buf); 6125796c8dcSSimon Schubert } 6135796c8dcSSimon Schubert 6145796c8dcSSimon Schubert struct cleanup * 6155796c8dcSSimon Schubert make_cleanup_ui_out_stream_delete (struct ui_stream *buf) 6165796c8dcSSimon Schubert { 6175796c8dcSSimon Schubert return make_cleanup (do_stream_delete, buf); 6185796c8dcSSimon Schubert } 6195796c8dcSSimon Schubert 6205796c8dcSSimon Schubert 6215796c8dcSSimon Schubert void 6225796c8dcSSimon Schubert ui_out_wrap_hint (struct ui_out *uiout, char *identstring) 6235796c8dcSSimon Schubert { 6245796c8dcSSimon Schubert uo_wrap_hint (uiout, identstring); 6255796c8dcSSimon Schubert } 6265796c8dcSSimon Schubert 6275796c8dcSSimon Schubert void 6285796c8dcSSimon Schubert ui_out_flush (struct ui_out *uiout) 6295796c8dcSSimon Schubert { 6305796c8dcSSimon Schubert uo_flush (uiout); 6315796c8dcSSimon Schubert } 6325796c8dcSSimon Schubert 6335796c8dcSSimon Schubert int 6345796c8dcSSimon Schubert ui_out_redirect (struct ui_out *uiout, struct ui_file *outstream) 6355796c8dcSSimon Schubert { 6365796c8dcSSimon Schubert return uo_redirect (uiout, outstream); 6375796c8dcSSimon Schubert } 6385796c8dcSSimon Schubert 639*c50c785cSJohn Marino /* Set the flags specified by the mask given. */ 6405796c8dcSSimon Schubert int 6415796c8dcSSimon Schubert ui_out_set_flags (struct ui_out *uiout, int mask) 6425796c8dcSSimon Schubert { 6435796c8dcSSimon Schubert int oldflags = uiout->flags; 6445796c8dcSSimon Schubert 6455796c8dcSSimon Schubert uiout->flags |= mask; 6465796c8dcSSimon Schubert return oldflags; 6475796c8dcSSimon Schubert } 6485796c8dcSSimon Schubert 649*c50c785cSJohn Marino /* Clear the flags specified by the mask given. */ 6505796c8dcSSimon Schubert int 6515796c8dcSSimon Schubert ui_out_clear_flags (struct ui_out *uiout, int mask) 6525796c8dcSSimon Schubert { 6535796c8dcSSimon Schubert int oldflags = uiout->flags; 6545796c8dcSSimon Schubert 6555796c8dcSSimon Schubert uiout->flags &= ~mask; 6565796c8dcSSimon Schubert return oldflags; 6575796c8dcSSimon Schubert } 6585796c8dcSSimon Schubert 659*c50c785cSJohn Marino /* Test the flags against the mask given. */ 6605796c8dcSSimon Schubert int 6615796c8dcSSimon Schubert ui_out_test_flags (struct ui_out *uiout, int mask) 6625796c8dcSSimon Schubert { 6635796c8dcSSimon Schubert return (uiout->flags & mask); 6645796c8dcSSimon Schubert } 6655796c8dcSSimon Schubert 666*c50c785cSJohn Marino /* Obtain the current verbosity level (as stablished by the 667*c50c785cSJohn Marino 'set verbositylevel' command. */ 6685796c8dcSSimon Schubert 6695796c8dcSSimon Schubert int 6705796c8dcSSimon Schubert ui_out_get_verblvl (struct ui_out *uiout) 6715796c8dcSSimon Schubert { 672*c50c785cSJohn Marino /* FIXME: not implemented yet. */ 6735796c8dcSSimon Schubert return 0; 6745796c8dcSSimon Schubert } 6755796c8dcSSimon Schubert 6765796c8dcSSimon Schubert #if 0 6775796c8dcSSimon Schubert void 6785796c8dcSSimon Schubert ui_out_result_begin (struct ui_out *uiout, char *class) 6795796c8dcSSimon Schubert { 6805796c8dcSSimon Schubert } 6815796c8dcSSimon Schubert 6825796c8dcSSimon Schubert void 6835796c8dcSSimon Schubert ui_out_result_end (struct ui_out *uiout) 6845796c8dcSSimon Schubert { 6855796c8dcSSimon Schubert } 6865796c8dcSSimon Schubert 6875796c8dcSSimon Schubert void 6885796c8dcSSimon Schubert ui_out_info_begin (struct ui_out *uiout, char *class) 6895796c8dcSSimon Schubert { 6905796c8dcSSimon Schubert } 6915796c8dcSSimon Schubert 6925796c8dcSSimon Schubert void 6935796c8dcSSimon Schubert ui_out_info_end (struct ui_out *uiout) 6945796c8dcSSimon Schubert { 6955796c8dcSSimon Schubert } 6965796c8dcSSimon Schubert 6975796c8dcSSimon Schubert void 6985796c8dcSSimon Schubert ui_out_notify_begin (struct ui_out *uiout, char *class) 6995796c8dcSSimon Schubert { 7005796c8dcSSimon Schubert } 7015796c8dcSSimon Schubert 7025796c8dcSSimon Schubert void 7035796c8dcSSimon Schubert ui_out_notify_end (struct ui_out *uiout) 7045796c8dcSSimon Schubert { 7055796c8dcSSimon Schubert } 7065796c8dcSSimon Schubert 7075796c8dcSSimon Schubert void 7085796c8dcSSimon Schubert ui_out_error_begin (struct ui_out *uiout, char *class) 7095796c8dcSSimon Schubert { 7105796c8dcSSimon Schubert } 7115796c8dcSSimon Schubert 7125796c8dcSSimon Schubert void 7135796c8dcSSimon Schubert ui_out_error_end (struct ui_out *uiout) 7145796c8dcSSimon Schubert { 7155796c8dcSSimon Schubert } 7165796c8dcSSimon Schubert #endif 7175796c8dcSSimon Schubert 7185796c8dcSSimon Schubert #if 0 7195796c8dcSSimon Schubert void 7205796c8dcSSimon Schubert gdb_error (ui_out * uiout, int severity, char *format,...) 7215796c8dcSSimon Schubert { 7225796c8dcSSimon Schubert va_list args; 7235796c8dcSSimon Schubert } 7245796c8dcSSimon Schubert 7255796c8dcSSimon Schubert void 7265796c8dcSSimon Schubert gdb_query (struct ui_out *uiout, int qflags, char *qprompt) 7275796c8dcSSimon Schubert { 7285796c8dcSSimon Schubert } 7295796c8dcSSimon Schubert #endif 7305796c8dcSSimon Schubert 7315796c8dcSSimon Schubert int 7325796c8dcSSimon Schubert ui_out_is_mi_like_p (struct ui_out *uiout) 7335796c8dcSSimon Schubert { 7345796c8dcSSimon Schubert return uiout->impl->is_mi_like_p; 7355796c8dcSSimon Schubert } 7365796c8dcSSimon Schubert 737*c50c785cSJohn Marino /* Default gdb-out hook functions. */ 7385796c8dcSSimon Schubert 7395796c8dcSSimon Schubert static void 7405796c8dcSSimon Schubert default_table_begin (struct ui_out *uiout, int nbrofcols, 7415796c8dcSSimon Schubert int nr_rows, 7425796c8dcSSimon Schubert const char *tblid) 7435796c8dcSSimon Schubert { 7445796c8dcSSimon Schubert } 7455796c8dcSSimon Schubert 7465796c8dcSSimon Schubert static void 7475796c8dcSSimon Schubert default_table_body (struct ui_out *uiout) 7485796c8dcSSimon Schubert { 7495796c8dcSSimon Schubert } 7505796c8dcSSimon Schubert 7515796c8dcSSimon Schubert static void 7525796c8dcSSimon Schubert default_table_end (struct ui_out *uiout) 7535796c8dcSSimon Schubert { 7545796c8dcSSimon Schubert } 7555796c8dcSSimon Schubert 7565796c8dcSSimon Schubert static void 7575796c8dcSSimon Schubert default_table_header (struct ui_out *uiout, int width, enum ui_align alignment, 7585796c8dcSSimon Schubert const char *col_name, 7595796c8dcSSimon Schubert const char *colhdr) 7605796c8dcSSimon Schubert { 7615796c8dcSSimon Schubert } 7625796c8dcSSimon Schubert 7635796c8dcSSimon Schubert static void 7645796c8dcSSimon Schubert default_begin (struct ui_out *uiout, 7655796c8dcSSimon Schubert enum ui_out_type type, 7665796c8dcSSimon Schubert int level, 7675796c8dcSSimon Schubert const char *id) 7685796c8dcSSimon Schubert { 7695796c8dcSSimon Schubert } 7705796c8dcSSimon Schubert 7715796c8dcSSimon Schubert static void 7725796c8dcSSimon Schubert default_end (struct ui_out *uiout, 7735796c8dcSSimon Schubert enum ui_out_type type, 7745796c8dcSSimon Schubert int level) 7755796c8dcSSimon Schubert { 7765796c8dcSSimon Schubert } 7775796c8dcSSimon Schubert 7785796c8dcSSimon Schubert static void 7795796c8dcSSimon Schubert default_field_int (struct ui_out *uiout, int fldno, int width, 7805796c8dcSSimon Schubert enum ui_align align, 7815796c8dcSSimon Schubert const char *fldname, int value) 7825796c8dcSSimon Schubert { 7835796c8dcSSimon Schubert } 7845796c8dcSSimon Schubert 7855796c8dcSSimon Schubert static void 7865796c8dcSSimon Schubert default_field_skip (struct ui_out *uiout, int fldno, int width, 7875796c8dcSSimon Schubert enum ui_align align, const char *fldname) 7885796c8dcSSimon Schubert { 7895796c8dcSSimon Schubert } 7905796c8dcSSimon Schubert 7915796c8dcSSimon Schubert static void 7925796c8dcSSimon Schubert default_field_string (struct ui_out *uiout, 7935796c8dcSSimon Schubert int fldno, 7945796c8dcSSimon Schubert int width, 7955796c8dcSSimon Schubert enum ui_align align, 7965796c8dcSSimon Schubert const char *fldname, 7975796c8dcSSimon Schubert const char *string) 7985796c8dcSSimon Schubert { 7995796c8dcSSimon Schubert } 8005796c8dcSSimon Schubert 8015796c8dcSSimon Schubert static void 8025796c8dcSSimon Schubert default_field_fmt (struct ui_out *uiout, int fldno, int width, 8035796c8dcSSimon Schubert enum ui_align align, 8045796c8dcSSimon Schubert const char *fldname, 8055796c8dcSSimon Schubert const char *format, 8065796c8dcSSimon Schubert va_list args) 8075796c8dcSSimon Schubert { 8085796c8dcSSimon Schubert } 8095796c8dcSSimon Schubert 8105796c8dcSSimon Schubert static void 8115796c8dcSSimon Schubert default_spaces (struct ui_out *uiout, int numspaces) 8125796c8dcSSimon Schubert { 8135796c8dcSSimon Schubert } 8145796c8dcSSimon Schubert 8155796c8dcSSimon Schubert static void 8165796c8dcSSimon Schubert default_text (struct ui_out *uiout, const char *string) 8175796c8dcSSimon Schubert { 8185796c8dcSSimon Schubert } 8195796c8dcSSimon Schubert 8205796c8dcSSimon Schubert static void 8215796c8dcSSimon Schubert default_message (struct ui_out *uiout, int verbosity, 8225796c8dcSSimon Schubert const char *format, 8235796c8dcSSimon Schubert va_list args) 8245796c8dcSSimon Schubert { 8255796c8dcSSimon Schubert } 8265796c8dcSSimon Schubert 8275796c8dcSSimon Schubert static void 8285796c8dcSSimon Schubert default_wrap_hint (struct ui_out *uiout, char *identstring) 8295796c8dcSSimon Schubert { 8305796c8dcSSimon Schubert } 8315796c8dcSSimon Schubert 8325796c8dcSSimon Schubert static void 8335796c8dcSSimon Schubert default_flush (struct ui_out *uiout) 8345796c8dcSSimon Schubert { 8355796c8dcSSimon Schubert } 8365796c8dcSSimon Schubert 837*c50c785cSJohn Marino /* Interface to the implementation functions. */ 8385796c8dcSSimon Schubert 8395796c8dcSSimon Schubert void 8405796c8dcSSimon Schubert uo_table_begin (struct ui_out *uiout, int nbrofcols, 8415796c8dcSSimon Schubert int nr_rows, 8425796c8dcSSimon Schubert const char *tblid) 8435796c8dcSSimon Schubert { 8445796c8dcSSimon Schubert if (!uiout->impl->table_begin) 8455796c8dcSSimon Schubert return; 8465796c8dcSSimon Schubert uiout->impl->table_begin (uiout, nbrofcols, nr_rows, tblid); 8475796c8dcSSimon Schubert } 8485796c8dcSSimon Schubert 8495796c8dcSSimon Schubert void 8505796c8dcSSimon Schubert uo_table_body (struct ui_out *uiout) 8515796c8dcSSimon Schubert { 8525796c8dcSSimon Schubert if (!uiout->impl->table_body) 8535796c8dcSSimon Schubert return; 8545796c8dcSSimon Schubert uiout->impl->table_body (uiout); 8555796c8dcSSimon Schubert } 8565796c8dcSSimon Schubert 8575796c8dcSSimon Schubert void 8585796c8dcSSimon Schubert uo_table_end (struct ui_out *uiout) 8595796c8dcSSimon Schubert { 8605796c8dcSSimon Schubert if (!uiout->impl->table_end) 8615796c8dcSSimon Schubert return; 8625796c8dcSSimon Schubert uiout->impl->table_end (uiout); 8635796c8dcSSimon Schubert } 8645796c8dcSSimon Schubert 8655796c8dcSSimon Schubert void 8665796c8dcSSimon Schubert uo_table_header (struct ui_out *uiout, int width, enum ui_align align, 8675796c8dcSSimon Schubert const char *col_name, 8685796c8dcSSimon Schubert const char *colhdr) 8695796c8dcSSimon Schubert { 8705796c8dcSSimon Schubert if (!uiout->impl->table_header) 8715796c8dcSSimon Schubert return; 8725796c8dcSSimon Schubert uiout->impl->table_header (uiout, width, align, col_name, colhdr); 8735796c8dcSSimon Schubert } 8745796c8dcSSimon Schubert 8755796c8dcSSimon Schubert void 8765796c8dcSSimon Schubert uo_begin (struct ui_out *uiout, 8775796c8dcSSimon Schubert enum ui_out_type type, 8785796c8dcSSimon Schubert int level, 8795796c8dcSSimon Schubert const char *id) 8805796c8dcSSimon Schubert { 8815796c8dcSSimon Schubert if (uiout->impl->begin == NULL) 8825796c8dcSSimon Schubert return; 8835796c8dcSSimon Schubert uiout->impl->begin (uiout, type, level, id); 8845796c8dcSSimon Schubert } 8855796c8dcSSimon Schubert 8865796c8dcSSimon Schubert void 8875796c8dcSSimon Schubert uo_end (struct ui_out *uiout, 8885796c8dcSSimon Schubert enum ui_out_type type, 8895796c8dcSSimon Schubert int level) 8905796c8dcSSimon Schubert { 8915796c8dcSSimon Schubert if (uiout->impl->end == NULL) 8925796c8dcSSimon Schubert return; 8935796c8dcSSimon Schubert uiout->impl->end (uiout, type, level); 8945796c8dcSSimon Schubert } 8955796c8dcSSimon Schubert 8965796c8dcSSimon Schubert void 8975796c8dcSSimon Schubert uo_field_int (struct ui_out *uiout, int fldno, int width, enum ui_align align, 8985796c8dcSSimon Schubert const char *fldname, 8995796c8dcSSimon Schubert int value) 9005796c8dcSSimon Schubert { 9015796c8dcSSimon Schubert if (!uiout->impl->field_int) 9025796c8dcSSimon Schubert return; 9035796c8dcSSimon Schubert uiout->impl->field_int (uiout, fldno, width, align, fldname, value); 9045796c8dcSSimon Schubert } 9055796c8dcSSimon Schubert 9065796c8dcSSimon Schubert void 9075796c8dcSSimon Schubert uo_field_skip (struct ui_out *uiout, int fldno, int width, enum ui_align align, 9085796c8dcSSimon Schubert const char *fldname) 9095796c8dcSSimon Schubert { 9105796c8dcSSimon Schubert if (!uiout->impl->field_skip) 9115796c8dcSSimon Schubert return; 9125796c8dcSSimon Schubert uiout->impl->field_skip (uiout, fldno, width, align, fldname); 9135796c8dcSSimon Schubert } 9145796c8dcSSimon Schubert 9155796c8dcSSimon Schubert void 9165796c8dcSSimon Schubert uo_field_string (struct ui_out *uiout, int fldno, int width, 9175796c8dcSSimon Schubert enum ui_align align, 9185796c8dcSSimon Schubert const char *fldname, 9195796c8dcSSimon Schubert const char *string) 9205796c8dcSSimon Schubert { 9215796c8dcSSimon Schubert if (!uiout->impl->field_string) 9225796c8dcSSimon Schubert return; 9235796c8dcSSimon Schubert uiout->impl->field_string (uiout, fldno, width, align, fldname, string); 9245796c8dcSSimon Schubert } 9255796c8dcSSimon Schubert 9265796c8dcSSimon Schubert void 9275796c8dcSSimon Schubert uo_field_fmt (struct ui_out *uiout, int fldno, int width, enum ui_align align, 9285796c8dcSSimon Schubert const char *fldname, 9295796c8dcSSimon Schubert const char *format, 9305796c8dcSSimon Schubert va_list args) 9315796c8dcSSimon Schubert { 9325796c8dcSSimon Schubert if (!uiout->impl->field_fmt) 9335796c8dcSSimon Schubert return; 9345796c8dcSSimon Schubert uiout->impl->field_fmt (uiout, fldno, width, align, fldname, format, args); 9355796c8dcSSimon Schubert } 9365796c8dcSSimon Schubert 9375796c8dcSSimon Schubert void 9385796c8dcSSimon Schubert uo_spaces (struct ui_out *uiout, int numspaces) 9395796c8dcSSimon Schubert { 9405796c8dcSSimon Schubert if (!uiout->impl->spaces) 9415796c8dcSSimon Schubert return; 9425796c8dcSSimon Schubert uiout->impl->spaces (uiout, numspaces); 9435796c8dcSSimon Schubert } 9445796c8dcSSimon Schubert 9455796c8dcSSimon Schubert void 9465796c8dcSSimon Schubert uo_text (struct ui_out *uiout, 9475796c8dcSSimon Schubert const char *string) 9485796c8dcSSimon Schubert { 9495796c8dcSSimon Schubert if (!uiout->impl->text) 9505796c8dcSSimon Schubert return; 9515796c8dcSSimon Schubert uiout->impl->text (uiout, string); 9525796c8dcSSimon Schubert } 9535796c8dcSSimon Schubert 9545796c8dcSSimon Schubert void 9555796c8dcSSimon Schubert uo_message (struct ui_out *uiout, int verbosity, 9565796c8dcSSimon Schubert const char *format, 9575796c8dcSSimon Schubert va_list args) 9585796c8dcSSimon Schubert { 9595796c8dcSSimon Schubert if (!uiout->impl->message) 9605796c8dcSSimon Schubert return; 9615796c8dcSSimon Schubert uiout->impl->message (uiout, verbosity, format, args); 9625796c8dcSSimon Schubert } 9635796c8dcSSimon Schubert 9645796c8dcSSimon Schubert void 9655796c8dcSSimon Schubert uo_wrap_hint (struct ui_out *uiout, char *identstring) 9665796c8dcSSimon Schubert { 9675796c8dcSSimon Schubert if (!uiout->impl->wrap_hint) 9685796c8dcSSimon Schubert return; 9695796c8dcSSimon Schubert uiout->impl->wrap_hint (uiout, identstring); 9705796c8dcSSimon Schubert } 9715796c8dcSSimon Schubert 9725796c8dcSSimon Schubert void 9735796c8dcSSimon Schubert uo_flush (struct ui_out *uiout) 9745796c8dcSSimon Schubert { 9755796c8dcSSimon Schubert if (!uiout->impl->flush) 9765796c8dcSSimon Schubert return; 9775796c8dcSSimon Schubert uiout->impl->flush (uiout); 9785796c8dcSSimon Schubert } 9795796c8dcSSimon Schubert 9805796c8dcSSimon Schubert int 9815796c8dcSSimon Schubert uo_redirect (struct ui_out *uiout, struct ui_file *outstream) 9825796c8dcSSimon Schubert { 9835796c8dcSSimon Schubert if (!uiout->impl->redirect) 9845796c8dcSSimon Schubert return -1; 9855796c8dcSSimon Schubert uiout->impl->redirect (uiout, outstream); 9865796c8dcSSimon Schubert return 0; 9875796c8dcSSimon Schubert } 9885796c8dcSSimon Schubert 9895796c8dcSSimon Schubert /* local functions */ 9905796c8dcSSimon Schubert 991*c50c785cSJohn Marino /* List of column headers manipulation routines. */ 9925796c8dcSSimon Schubert 9935796c8dcSSimon Schubert static void 9945796c8dcSSimon Schubert clear_header_list (struct ui_out *uiout) 9955796c8dcSSimon Schubert { 9965796c8dcSSimon Schubert while (uiout->table.header_first != NULL) 9975796c8dcSSimon Schubert { 9985796c8dcSSimon Schubert uiout->table.header_next = uiout->table.header_first; 9995796c8dcSSimon Schubert uiout->table.header_first = uiout->table.header_first->next; 10005796c8dcSSimon Schubert if (uiout->table.header_next->colhdr != NULL) 10015796c8dcSSimon Schubert xfree (uiout->table.header_next->colhdr); 10025796c8dcSSimon Schubert xfree (uiout->table.header_next); 10035796c8dcSSimon Schubert } 10045796c8dcSSimon Schubert gdb_assert (uiout->table.header_first == NULL); 10055796c8dcSSimon Schubert uiout->table.header_last = NULL; 10065796c8dcSSimon Schubert uiout->table.header_next = NULL; 10075796c8dcSSimon Schubert } 10085796c8dcSSimon Schubert 10095796c8dcSSimon Schubert static void 10105796c8dcSSimon Schubert append_header_to_list (struct ui_out *uiout, 10115796c8dcSSimon Schubert int width, 10125796c8dcSSimon Schubert int alignment, 10135796c8dcSSimon Schubert const char *col_name, 10145796c8dcSSimon Schubert const char *colhdr) 10155796c8dcSSimon Schubert { 10165796c8dcSSimon Schubert struct ui_out_hdr *temphdr; 10175796c8dcSSimon Schubert 10185796c8dcSSimon Schubert temphdr = XMALLOC (struct ui_out_hdr); 10195796c8dcSSimon Schubert temphdr->width = width; 10205796c8dcSSimon Schubert temphdr->alignment = alignment; 10215796c8dcSSimon Schubert /* We have to copy the column title as the original may be an 10225796c8dcSSimon Schubert automatic. */ 10235796c8dcSSimon Schubert if (colhdr != NULL) 10245796c8dcSSimon Schubert temphdr->colhdr = xstrdup (colhdr); 10255796c8dcSSimon Schubert else 10265796c8dcSSimon Schubert temphdr->colhdr = NULL; 10275796c8dcSSimon Schubert 10285796c8dcSSimon Schubert if (col_name != NULL) 10295796c8dcSSimon Schubert temphdr->col_name = xstrdup (col_name); 10305796c8dcSSimon Schubert else if (colhdr != NULL) 10315796c8dcSSimon Schubert temphdr->col_name = xstrdup (colhdr); 10325796c8dcSSimon Schubert else 10335796c8dcSSimon Schubert temphdr->col_name = NULL; 10345796c8dcSSimon Schubert 10355796c8dcSSimon Schubert temphdr->next = NULL; 10365796c8dcSSimon Schubert if (uiout->table.header_first == NULL) 10375796c8dcSSimon Schubert { 10385796c8dcSSimon Schubert temphdr->colno = 1; 10395796c8dcSSimon Schubert uiout->table.header_first = temphdr; 10405796c8dcSSimon Schubert uiout->table.header_last = temphdr; 10415796c8dcSSimon Schubert } 10425796c8dcSSimon Schubert else 10435796c8dcSSimon Schubert { 10445796c8dcSSimon Schubert temphdr->colno = uiout->table.header_last->colno + 1; 10455796c8dcSSimon Schubert uiout->table.header_last->next = temphdr; 10465796c8dcSSimon Schubert uiout->table.header_last = temphdr; 10475796c8dcSSimon Schubert } 10485796c8dcSSimon Schubert uiout->table.header_next = uiout->table.header_last; 10495796c8dcSSimon Schubert } 10505796c8dcSSimon Schubert 10515796c8dcSSimon Schubert /* Extract the format information for the NEXT header and and advance 10525796c8dcSSimon Schubert the header pointer. Return 0 if there was no next header. */ 10535796c8dcSSimon Schubert 10545796c8dcSSimon Schubert static int 10555796c8dcSSimon Schubert get_next_header (struct ui_out *uiout, 10565796c8dcSSimon Schubert int *colno, 10575796c8dcSSimon Schubert int *width, 10585796c8dcSSimon Schubert int *alignment, 10595796c8dcSSimon Schubert char **colhdr) 10605796c8dcSSimon Schubert { 10615796c8dcSSimon Schubert /* There may be no headers at all or we may have used all columns. */ 10625796c8dcSSimon Schubert if (uiout->table.header_next == NULL) 10635796c8dcSSimon Schubert return 0; 10645796c8dcSSimon Schubert *colno = uiout->table.header_next->colno; 10655796c8dcSSimon Schubert *width = uiout->table.header_next->width; 10665796c8dcSSimon Schubert *alignment = uiout->table.header_next->alignment; 10675796c8dcSSimon Schubert *colhdr = uiout->table.header_next->colhdr; 10685796c8dcSSimon Schubert /* Advance the header pointer to the next entry. */ 10695796c8dcSSimon Schubert uiout->table.header_next = uiout->table.header_next->next; 10705796c8dcSSimon Schubert return 1; 10715796c8dcSSimon Schubert } 10725796c8dcSSimon Schubert 10735796c8dcSSimon Schubert 10745796c8dcSSimon Schubert /* Verify that the field/tuple/list is correctly positioned. Return 10755796c8dcSSimon Schubert the field number and corresponding alignment (if 10765796c8dcSSimon Schubert available/applicable). */ 10775796c8dcSSimon Schubert 10785796c8dcSSimon Schubert static void 10795796c8dcSSimon Schubert verify_field (struct ui_out *uiout, int *fldno, int *width, int *align) 10805796c8dcSSimon Schubert { 10815796c8dcSSimon Schubert struct ui_out_level *current = current_level (uiout); 10825796c8dcSSimon Schubert char *text; 10835796c8dcSSimon Schubert 10845796c8dcSSimon Schubert if (uiout->table.flag) 10855796c8dcSSimon Schubert { 10865796c8dcSSimon Schubert if (!uiout->table.body_flag) 10875796c8dcSSimon Schubert internal_error (__FILE__, __LINE__, 10885796c8dcSSimon Schubert _("table_body missing; table fields must be \ 10895796c8dcSSimon Schubert specified after table_body and inside a list.")); 10905796c8dcSSimon Schubert /* NOTE: cagney/2001-12-08: There was a check here to ensure 10915796c8dcSSimon Schubert that this code was only executed when uiout->level was 10925796c8dcSSimon Schubert greater than zero. That no longer applies - this code is run 10935796c8dcSSimon Schubert before each table row tuple is started and at that point the 10945796c8dcSSimon Schubert level is zero. */ 10955796c8dcSSimon Schubert } 10965796c8dcSSimon Schubert 10975796c8dcSSimon Schubert current->field_count += 1; 10985796c8dcSSimon Schubert 10995796c8dcSSimon Schubert if (uiout->table.body_flag 11005796c8dcSSimon Schubert && uiout->table.entry_level == uiout->level 11015796c8dcSSimon Schubert && get_next_header (uiout, fldno, width, align, &text)) 11025796c8dcSSimon Schubert { 11035796c8dcSSimon Schubert if (*fldno != current->field_count) 11045796c8dcSSimon Schubert internal_error (__FILE__, __LINE__, 11055796c8dcSSimon Schubert _("ui-out internal error in handling headers.")); 11065796c8dcSSimon Schubert } 11075796c8dcSSimon Schubert else 11085796c8dcSSimon Schubert { 11095796c8dcSSimon Schubert *width = 0; 11105796c8dcSSimon Schubert *align = ui_noalign; 11115796c8dcSSimon Schubert *fldno = current->field_count; 11125796c8dcSSimon Schubert } 11135796c8dcSSimon Schubert } 11145796c8dcSSimon Schubert 11155796c8dcSSimon Schubert 1116*c50c785cSJohn Marino /* Access to ui_out format private members. */ 11175796c8dcSSimon Schubert 11185796c8dcSSimon Schubert void 11195796c8dcSSimon Schubert ui_out_get_field_separator (struct ui_out *uiout) 11205796c8dcSSimon Schubert { 11215796c8dcSSimon Schubert } 11225796c8dcSSimon Schubert 1123*c50c785cSJohn Marino /* Access to ui-out members data. */ 11245796c8dcSSimon Schubert 1125cf7f2e2dSJohn Marino void * 11265796c8dcSSimon Schubert ui_out_data (struct ui_out *uiout) 11275796c8dcSSimon Schubert { 11285796c8dcSSimon Schubert return uiout->data; 11295796c8dcSSimon Schubert } 11305796c8dcSSimon Schubert 1131*c50c785cSJohn Marino /* Access table field parameters. */ 1132*c50c785cSJohn Marino int 1133*c50c785cSJohn Marino ui_out_query_field (struct ui_out *uiout, int colno, 1134*c50c785cSJohn Marino int *width, int *alignment, char **col_name) 1135*c50c785cSJohn Marino { 1136*c50c785cSJohn Marino struct ui_out_hdr *hdr; 1137*c50c785cSJohn Marino 1138*c50c785cSJohn Marino if (!uiout->table.flag) 1139*c50c785cSJohn Marino return 0; 1140*c50c785cSJohn Marino 1141*c50c785cSJohn Marino for (hdr = uiout->table.header_first; hdr; hdr = hdr->next) 1142*c50c785cSJohn Marino if (hdr->colno == colno) 1143*c50c785cSJohn Marino { 1144*c50c785cSJohn Marino *width = hdr->width; 1145*c50c785cSJohn Marino *alignment = hdr->alignment; 1146*c50c785cSJohn Marino *col_name = hdr->col_name; 1147*c50c785cSJohn Marino return 1; 1148*c50c785cSJohn Marino } 1149*c50c785cSJohn Marino 1150*c50c785cSJohn Marino return 0; 1151*c50c785cSJohn Marino } 1152*c50c785cSJohn Marino 1153*c50c785cSJohn Marino /* Initalize private members at startup. */ 11545796c8dcSSimon Schubert 11555796c8dcSSimon Schubert struct ui_out * 1156cf7f2e2dSJohn Marino ui_out_new (struct ui_out_impl *impl, void *data, 11575796c8dcSSimon Schubert int flags) 11585796c8dcSSimon Schubert { 11595796c8dcSSimon Schubert struct ui_out *uiout = XMALLOC (struct ui_out); 1160cf7f2e2dSJohn Marino 11615796c8dcSSimon Schubert uiout->data = data; 11625796c8dcSSimon Schubert uiout->impl = impl; 11635796c8dcSSimon Schubert uiout->flags = flags; 11645796c8dcSSimon Schubert uiout->table.flag = 0; 11655796c8dcSSimon Schubert uiout->table.body_flag = 0; 11665796c8dcSSimon Schubert uiout->level = 0; 11675796c8dcSSimon Schubert memset (uiout->levels, 0, sizeof (uiout->levels)); 11685796c8dcSSimon Schubert uiout->table.header_first = NULL; 11695796c8dcSSimon Schubert uiout->table.header_last = NULL; 11705796c8dcSSimon Schubert uiout->table.header_next = NULL; 11715796c8dcSSimon Schubert return uiout; 11725796c8dcSSimon Schubert } 11735796c8dcSSimon Schubert 1174*c50c785cSJohn Marino /* Standard gdb initialization hook. */ 11755796c8dcSSimon Schubert 11765796c8dcSSimon Schubert void 11775796c8dcSSimon Schubert _initialize_ui_out (void) 11785796c8dcSSimon Schubert { 11795796c8dcSSimon Schubert /* nothing needs to be done */ 11805796c8dcSSimon Schubert } 1181