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