xref: /dflybsd-src/contrib/gdb-7/gdb/ui-out.c (revision cf7f2e2d389e8012d562650bd94d7e433f449d6e)
15796c8dcSSimon Schubert /* Output generating routines for GDB.
25796c8dcSSimon Schubert 
3*cf7f2e2dSJohn Marino    Copyright (C) 1999, 2000, 2001, 2002, 2004, 2005, 2007, 2008, 2009, 2010
45796c8dcSSimon Schubert    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 
47*cf7f2e2dSJohn Marino enum { MAX_UI_OUT_LEVELS = 8 };
485796c8dcSSimon Schubert 
495796c8dcSSimon Schubert struct ui_out_level
505796c8dcSSimon Schubert   {
515796c8dcSSimon Schubert     /* 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
965796c8dcSSimon Schubert    of the default uiout, which is statically initialized */
975796c8dcSSimon Schubert 
985796c8dcSSimon Schubert struct ui_out
995796c8dcSSimon Schubert   {
1005796c8dcSSimon Schubert     int flags;
1015796c8dcSSimon Schubert     /* specific implementation of ui-out */
1025796c8dcSSimon Schubert     struct ui_out_impl *impl;
103*cf7f2e2dSJohn 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;
127*cf7f2e2dSJohn 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 
1515796c8dcSSimon Schubert /* 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,
181*cf7f2e2dSJohn 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,
186*cf7f2e2dSJohn 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 
1905796c8dcSSimon Schubert /* 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
2235796c8dcSSimon Schubert    or top.c */
2245796c8dcSSimon Schubert 
2255796c8dcSSimon Schubert struct ui_out *uiout = &def_uiout;
2265796c8dcSSimon Schubert 
2275796c8dcSSimon Schubert /* 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)
249*cf7f2e2dSJohn 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)
254*cf7f2e2dSJohn 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 
2735796c8dcSSimon Schubert /* 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;
375*cf7f2e2dSJohn 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;
392*cf7f2e2dSJohn 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);
412*cf7f2e2dSJohn 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;
426*cf7f2e2dSJohn 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;
436*cf7f2e2dSJohn 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 {
4955796c8dcSSimon Schubert   char addstr[20];
4965796c8dcSSimon Schubert   int addr_bit = gdbarch_addr_bit (gdbarch);
4975796c8dcSSimon Schubert 
4985796c8dcSSimon Schubert   if (addr_bit < (sizeof (CORE_ADDR) * HOST_CHAR_BIT))
4995796c8dcSSimon Schubert     address &= ((CORE_ADDR) 1 << addr_bit) - 1;
5005796c8dcSSimon Schubert 
5015796c8dcSSimon Schubert   /* FIXME: cagney/2002-05-03: Need local_address_string() function
5025796c8dcSSimon Schubert      that returns the language localized string formatted to a width
5035796c8dcSSimon Schubert      based on gdbarch_addr_bit.  */
5045796c8dcSSimon Schubert   if (addr_bit <= 32)
5055796c8dcSSimon Schubert     strcpy (addstr, hex_string_custom (address, 8));
5065796c8dcSSimon Schubert   else
5075796c8dcSSimon Schubert     strcpy (addstr, hex_string_custom (address, 16));
5085796c8dcSSimon Schubert 
5095796c8dcSSimon Schubert   ui_out_field_string (uiout, fldname, addstr);
5105796c8dcSSimon Schubert }
5115796c8dcSSimon Schubert 
5125796c8dcSSimon Schubert void
5135796c8dcSSimon Schubert ui_out_field_stream (struct ui_out *uiout,
5145796c8dcSSimon Schubert 		     const char *fldname,
5155796c8dcSSimon Schubert 		     struct ui_stream *buf)
5165796c8dcSSimon Schubert {
5175796c8dcSSimon Schubert   long length;
5185796c8dcSSimon Schubert   char *buffer = ui_file_xstrdup (buf->stream, &length);
5195796c8dcSSimon Schubert   struct cleanup *old_cleanup = make_cleanup (xfree, buffer);
520*cf7f2e2dSJohn Marino 
5215796c8dcSSimon Schubert   if (length > 0)
5225796c8dcSSimon Schubert     ui_out_field_string (uiout, fldname, buffer);
5235796c8dcSSimon Schubert   else
5245796c8dcSSimon Schubert     ui_out_field_skip (uiout, fldname);
5255796c8dcSSimon Schubert   ui_file_rewind (buf->stream);
5265796c8dcSSimon Schubert   do_cleanups (old_cleanup);
5275796c8dcSSimon Schubert }
5285796c8dcSSimon Schubert 
5295796c8dcSSimon Schubert /* used to ommit a field */
5305796c8dcSSimon Schubert 
5315796c8dcSSimon Schubert void
5325796c8dcSSimon Schubert ui_out_field_skip (struct ui_out *uiout,
5335796c8dcSSimon Schubert 		   const char *fldname)
5345796c8dcSSimon Schubert {
5355796c8dcSSimon Schubert   int fldno;
5365796c8dcSSimon Schubert   int width;
5375796c8dcSSimon Schubert   int align;
5385796c8dcSSimon Schubert 
5395796c8dcSSimon Schubert   verify_field (uiout, &fldno, &width, &align);
5405796c8dcSSimon Schubert 
5415796c8dcSSimon Schubert   uo_field_skip (uiout, fldno, width, align, fldname);
5425796c8dcSSimon Schubert }
5435796c8dcSSimon Schubert 
5445796c8dcSSimon Schubert void
5455796c8dcSSimon Schubert ui_out_field_string (struct ui_out *uiout,
5465796c8dcSSimon Schubert 		     const char *fldname,
5475796c8dcSSimon Schubert 		     const char *string)
5485796c8dcSSimon Schubert {
5495796c8dcSSimon Schubert   int fldno;
5505796c8dcSSimon Schubert   int width;
5515796c8dcSSimon Schubert   int align;
5525796c8dcSSimon Schubert 
5535796c8dcSSimon Schubert   verify_field (uiout, &fldno, &width, &align);
5545796c8dcSSimon Schubert 
5555796c8dcSSimon Schubert   uo_field_string (uiout, fldno, width, align, fldname, string);
5565796c8dcSSimon Schubert }
5575796c8dcSSimon Schubert 
5585796c8dcSSimon Schubert /* VARARGS */
5595796c8dcSSimon Schubert void
5605796c8dcSSimon Schubert ui_out_field_fmt (struct ui_out *uiout,
5615796c8dcSSimon Schubert 		  const char *fldname,
5625796c8dcSSimon Schubert 		  const char *format, ...)
5635796c8dcSSimon Schubert {
5645796c8dcSSimon Schubert   va_list args;
5655796c8dcSSimon Schubert   int fldno;
5665796c8dcSSimon Schubert   int width;
5675796c8dcSSimon Schubert   int align;
5685796c8dcSSimon Schubert 
5695796c8dcSSimon Schubert   /* will not align, but has to call anyway */
5705796c8dcSSimon Schubert   verify_field (uiout, &fldno, &width, &align);
5715796c8dcSSimon Schubert 
5725796c8dcSSimon Schubert   va_start (args, format);
5735796c8dcSSimon Schubert 
5745796c8dcSSimon Schubert   uo_field_fmt (uiout, fldno, width, align, fldname, format, args);
5755796c8dcSSimon Schubert 
5765796c8dcSSimon Schubert   va_end (args);
5775796c8dcSSimon Schubert }
5785796c8dcSSimon Schubert 
5795796c8dcSSimon Schubert void
5805796c8dcSSimon Schubert ui_out_spaces (struct ui_out *uiout, int numspaces)
5815796c8dcSSimon Schubert {
5825796c8dcSSimon Schubert   uo_spaces (uiout, numspaces);
5835796c8dcSSimon Schubert }
5845796c8dcSSimon Schubert 
5855796c8dcSSimon Schubert void
5865796c8dcSSimon Schubert ui_out_text (struct ui_out *uiout,
5875796c8dcSSimon Schubert 	     const char *string)
5885796c8dcSSimon Schubert {
5895796c8dcSSimon Schubert   uo_text (uiout, string);
5905796c8dcSSimon Schubert }
5915796c8dcSSimon Schubert 
5925796c8dcSSimon Schubert void
5935796c8dcSSimon Schubert ui_out_message (struct ui_out *uiout, int verbosity,
5945796c8dcSSimon Schubert 		const char *format,...)
5955796c8dcSSimon Schubert {
5965796c8dcSSimon Schubert   va_list args;
5975796c8dcSSimon Schubert 
5985796c8dcSSimon Schubert   va_start (args, format);
5995796c8dcSSimon Schubert   uo_message (uiout, verbosity, format, args);
6005796c8dcSSimon Schubert   va_end (args);
6015796c8dcSSimon Schubert }
6025796c8dcSSimon Schubert 
6035796c8dcSSimon Schubert struct ui_stream *
6045796c8dcSSimon Schubert ui_out_stream_new (struct ui_out *uiout)
6055796c8dcSSimon Schubert {
6065796c8dcSSimon Schubert   struct ui_stream *tempbuf;
6075796c8dcSSimon Schubert 
6085796c8dcSSimon Schubert   tempbuf = XMALLOC (struct ui_stream);
6095796c8dcSSimon Schubert   tempbuf->uiout = uiout;
6105796c8dcSSimon Schubert   tempbuf->stream = mem_fileopen ();
6115796c8dcSSimon Schubert   return tempbuf;
6125796c8dcSSimon Schubert }
6135796c8dcSSimon Schubert 
6145796c8dcSSimon Schubert void
6155796c8dcSSimon Schubert ui_out_stream_delete (struct ui_stream *buf)
6165796c8dcSSimon Schubert {
6175796c8dcSSimon Schubert   ui_file_delete (buf->stream);
6185796c8dcSSimon Schubert   xfree (buf);
6195796c8dcSSimon Schubert }
6205796c8dcSSimon Schubert 
6215796c8dcSSimon Schubert static void
6225796c8dcSSimon Schubert do_stream_delete (void *buf)
6235796c8dcSSimon Schubert {
6245796c8dcSSimon Schubert   ui_out_stream_delete (buf);
6255796c8dcSSimon Schubert }
6265796c8dcSSimon Schubert 
6275796c8dcSSimon Schubert struct cleanup *
6285796c8dcSSimon Schubert make_cleanup_ui_out_stream_delete (struct ui_stream *buf)
6295796c8dcSSimon Schubert {
6305796c8dcSSimon Schubert   return make_cleanup (do_stream_delete, buf);
6315796c8dcSSimon Schubert }
6325796c8dcSSimon Schubert 
6335796c8dcSSimon Schubert 
6345796c8dcSSimon Schubert void
6355796c8dcSSimon Schubert ui_out_wrap_hint (struct ui_out *uiout, char *identstring)
6365796c8dcSSimon Schubert {
6375796c8dcSSimon Schubert   uo_wrap_hint (uiout, identstring);
6385796c8dcSSimon Schubert }
6395796c8dcSSimon Schubert 
6405796c8dcSSimon Schubert void
6415796c8dcSSimon Schubert ui_out_flush (struct ui_out *uiout)
6425796c8dcSSimon Schubert {
6435796c8dcSSimon Schubert   uo_flush (uiout);
6445796c8dcSSimon Schubert }
6455796c8dcSSimon Schubert 
6465796c8dcSSimon Schubert int
6475796c8dcSSimon Schubert ui_out_redirect (struct ui_out *uiout, struct ui_file *outstream)
6485796c8dcSSimon Schubert {
6495796c8dcSSimon Schubert   return uo_redirect (uiout, outstream);
6505796c8dcSSimon Schubert }
6515796c8dcSSimon Schubert 
6525796c8dcSSimon Schubert /* set the flags specified by the mask given */
6535796c8dcSSimon Schubert int
6545796c8dcSSimon Schubert ui_out_set_flags (struct ui_out *uiout, int mask)
6555796c8dcSSimon Schubert {
6565796c8dcSSimon Schubert   int oldflags = uiout->flags;
6575796c8dcSSimon Schubert 
6585796c8dcSSimon Schubert   uiout->flags |= mask;
6595796c8dcSSimon Schubert   return oldflags;
6605796c8dcSSimon Schubert }
6615796c8dcSSimon Schubert 
6625796c8dcSSimon Schubert /* clear the flags specified by the mask given */
6635796c8dcSSimon Schubert int
6645796c8dcSSimon Schubert ui_out_clear_flags (struct ui_out *uiout, int mask)
6655796c8dcSSimon Schubert {
6665796c8dcSSimon Schubert   int oldflags = uiout->flags;
6675796c8dcSSimon Schubert 
6685796c8dcSSimon Schubert   uiout->flags &= ~mask;
6695796c8dcSSimon Schubert   return oldflags;
6705796c8dcSSimon Schubert }
6715796c8dcSSimon Schubert 
6725796c8dcSSimon Schubert /* test the flags against the mask given */
6735796c8dcSSimon Schubert int
6745796c8dcSSimon Schubert ui_out_test_flags (struct ui_out *uiout, int mask)
6755796c8dcSSimon Schubert {
6765796c8dcSSimon Schubert   return (uiout->flags & mask);
6775796c8dcSSimon Schubert }
6785796c8dcSSimon Schubert 
6795796c8dcSSimon Schubert /* obtain the current verbosity level (as stablished by the
6805796c8dcSSimon Schubert    'set verbositylevel' command */
6815796c8dcSSimon Schubert 
6825796c8dcSSimon Schubert int
6835796c8dcSSimon Schubert ui_out_get_verblvl (struct ui_out *uiout)
6845796c8dcSSimon Schubert {
6855796c8dcSSimon Schubert   /* FIXME: not implemented yet */
6865796c8dcSSimon Schubert   return 0;
6875796c8dcSSimon Schubert }
6885796c8dcSSimon Schubert 
6895796c8dcSSimon Schubert #if 0
6905796c8dcSSimon Schubert void
6915796c8dcSSimon Schubert ui_out_result_begin (struct ui_out *uiout, char *class)
6925796c8dcSSimon Schubert {
6935796c8dcSSimon Schubert }
6945796c8dcSSimon Schubert 
6955796c8dcSSimon Schubert void
6965796c8dcSSimon Schubert ui_out_result_end (struct ui_out *uiout)
6975796c8dcSSimon Schubert {
6985796c8dcSSimon Schubert }
6995796c8dcSSimon Schubert 
7005796c8dcSSimon Schubert void
7015796c8dcSSimon Schubert ui_out_info_begin (struct ui_out *uiout, char *class)
7025796c8dcSSimon Schubert {
7035796c8dcSSimon Schubert }
7045796c8dcSSimon Schubert 
7055796c8dcSSimon Schubert void
7065796c8dcSSimon Schubert ui_out_info_end (struct ui_out *uiout)
7075796c8dcSSimon Schubert {
7085796c8dcSSimon Schubert }
7095796c8dcSSimon Schubert 
7105796c8dcSSimon Schubert void
7115796c8dcSSimon Schubert ui_out_notify_begin (struct ui_out *uiout, char *class)
7125796c8dcSSimon Schubert {
7135796c8dcSSimon Schubert }
7145796c8dcSSimon Schubert 
7155796c8dcSSimon Schubert void
7165796c8dcSSimon Schubert ui_out_notify_end (struct ui_out *uiout)
7175796c8dcSSimon Schubert {
7185796c8dcSSimon Schubert }
7195796c8dcSSimon Schubert 
7205796c8dcSSimon Schubert void
7215796c8dcSSimon Schubert ui_out_error_begin (struct ui_out *uiout, char *class)
7225796c8dcSSimon Schubert {
7235796c8dcSSimon Schubert }
7245796c8dcSSimon Schubert 
7255796c8dcSSimon Schubert void
7265796c8dcSSimon Schubert ui_out_error_end (struct ui_out *uiout)
7275796c8dcSSimon Schubert {
7285796c8dcSSimon Schubert }
7295796c8dcSSimon Schubert #endif
7305796c8dcSSimon Schubert 
7315796c8dcSSimon Schubert #if 0
7325796c8dcSSimon Schubert void
7335796c8dcSSimon Schubert gdb_error (ui_out * uiout, int severity, char *format,...)
7345796c8dcSSimon Schubert {
7355796c8dcSSimon Schubert   va_list args;
7365796c8dcSSimon Schubert }
7375796c8dcSSimon Schubert 
7385796c8dcSSimon Schubert void
7395796c8dcSSimon Schubert gdb_query (struct ui_out *uiout, int qflags, char *qprompt)
7405796c8dcSSimon Schubert {
7415796c8dcSSimon Schubert }
7425796c8dcSSimon Schubert #endif
7435796c8dcSSimon Schubert 
7445796c8dcSSimon Schubert int
7455796c8dcSSimon Schubert ui_out_is_mi_like_p (struct ui_out *uiout)
7465796c8dcSSimon Schubert {
7475796c8dcSSimon Schubert   return uiout->impl->is_mi_like_p;
7485796c8dcSSimon Schubert }
7495796c8dcSSimon Schubert 
7505796c8dcSSimon Schubert /* default gdb-out hook functions */
7515796c8dcSSimon Schubert 
7525796c8dcSSimon Schubert static void
7535796c8dcSSimon Schubert default_table_begin (struct ui_out *uiout, int nbrofcols,
7545796c8dcSSimon Schubert 		     int nr_rows,
7555796c8dcSSimon Schubert 		     const char *tblid)
7565796c8dcSSimon Schubert {
7575796c8dcSSimon Schubert }
7585796c8dcSSimon Schubert 
7595796c8dcSSimon Schubert static void
7605796c8dcSSimon Schubert default_table_body (struct ui_out *uiout)
7615796c8dcSSimon Schubert {
7625796c8dcSSimon Schubert }
7635796c8dcSSimon Schubert 
7645796c8dcSSimon Schubert static void
7655796c8dcSSimon Schubert default_table_end (struct ui_out *uiout)
7665796c8dcSSimon Schubert {
7675796c8dcSSimon Schubert }
7685796c8dcSSimon Schubert 
7695796c8dcSSimon Schubert static void
7705796c8dcSSimon Schubert default_table_header (struct ui_out *uiout, int width, enum ui_align alignment,
7715796c8dcSSimon Schubert 		      const char *col_name,
7725796c8dcSSimon Schubert 		      const char *colhdr)
7735796c8dcSSimon Schubert {
7745796c8dcSSimon Schubert }
7755796c8dcSSimon Schubert 
7765796c8dcSSimon Schubert static void
7775796c8dcSSimon Schubert default_begin (struct ui_out *uiout,
7785796c8dcSSimon Schubert 	       enum ui_out_type type,
7795796c8dcSSimon Schubert 	       int level,
7805796c8dcSSimon Schubert 	       const char *id)
7815796c8dcSSimon Schubert {
7825796c8dcSSimon Schubert }
7835796c8dcSSimon Schubert 
7845796c8dcSSimon Schubert static void
7855796c8dcSSimon Schubert default_end (struct ui_out *uiout,
7865796c8dcSSimon Schubert 	     enum ui_out_type type,
7875796c8dcSSimon Schubert 	     int level)
7885796c8dcSSimon Schubert {
7895796c8dcSSimon Schubert }
7905796c8dcSSimon Schubert 
7915796c8dcSSimon Schubert static void
7925796c8dcSSimon Schubert default_field_int (struct ui_out *uiout, int fldno, int width,
7935796c8dcSSimon Schubert 		   enum ui_align align,
7945796c8dcSSimon Schubert 		   const char *fldname, int value)
7955796c8dcSSimon Schubert {
7965796c8dcSSimon Schubert }
7975796c8dcSSimon Schubert 
7985796c8dcSSimon Schubert static void
7995796c8dcSSimon Schubert default_field_skip (struct ui_out *uiout, int fldno, int width,
8005796c8dcSSimon Schubert 		    enum ui_align align, const char *fldname)
8015796c8dcSSimon Schubert {
8025796c8dcSSimon Schubert }
8035796c8dcSSimon Schubert 
8045796c8dcSSimon Schubert static void
8055796c8dcSSimon Schubert default_field_string (struct ui_out *uiout,
8065796c8dcSSimon Schubert 		      int fldno,
8075796c8dcSSimon Schubert 		      int width,
8085796c8dcSSimon Schubert 		      enum ui_align align,
8095796c8dcSSimon Schubert 		      const char *fldname,
8105796c8dcSSimon Schubert 		      const char *string)
8115796c8dcSSimon Schubert {
8125796c8dcSSimon Schubert }
8135796c8dcSSimon Schubert 
8145796c8dcSSimon Schubert static void
8155796c8dcSSimon Schubert default_field_fmt (struct ui_out *uiout, int fldno, int width,
8165796c8dcSSimon Schubert 		   enum ui_align align,
8175796c8dcSSimon Schubert 		   const char *fldname,
8185796c8dcSSimon Schubert 		   const char *format,
8195796c8dcSSimon Schubert 		   va_list args)
8205796c8dcSSimon Schubert {
8215796c8dcSSimon Schubert }
8225796c8dcSSimon Schubert 
8235796c8dcSSimon Schubert static void
8245796c8dcSSimon Schubert default_spaces (struct ui_out *uiout, int numspaces)
8255796c8dcSSimon Schubert {
8265796c8dcSSimon Schubert }
8275796c8dcSSimon Schubert 
8285796c8dcSSimon Schubert static void
8295796c8dcSSimon Schubert default_text (struct ui_out *uiout, const char *string)
8305796c8dcSSimon Schubert {
8315796c8dcSSimon Schubert }
8325796c8dcSSimon Schubert 
8335796c8dcSSimon Schubert static void
8345796c8dcSSimon Schubert default_message (struct ui_out *uiout, int verbosity,
8355796c8dcSSimon Schubert 		 const char *format,
8365796c8dcSSimon Schubert 		 va_list args)
8375796c8dcSSimon Schubert {
8385796c8dcSSimon Schubert }
8395796c8dcSSimon Schubert 
8405796c8dcSSimon Schubert static void
8415796c8dcSSimon Schubert default_wrap_hint (struct ui_out *uiout, char *identstring)
8425796c8dcSSimon Schubert {
8435796c8dcSSimon Schubert }
8445796c8dcSSimon Schubert 
8455796c8dcSSimon Schubert static void
8465796c8dcSSimon Schubert default_flush (struct ui_out *uiout)
8475796c8dcSSimon Schubert {
8485796c8dcSSimon Schubert }
8495796c8dcSSimon Schubert 
8505796c8dcSSimon Schubert /* Interface to the implementation functions */
8515796c8dcSSimon Schubert 
8525796c8dcSSimon Schubert void
8535796c8dcSSimon Schubert uo_table_begin (struct ui_out *uiout, int nbrofcols,
8545796c8dcSSimon Schubert 		int nr_rows,
8555796c8dcSSimon Schubert 		const char *tblid)
8565796c8dcSSimon Schubert {
8575796c8dcSSimon Schubert   if (!uiout->impl->table_begin)
8585796c8dcSSimon Schubert     return;
8595796c8dcSSimon Schubert   uiout->impl->table_begin (uiout, nbrofcols, nr_rows, tblid);
8605796c8dcSSimon Schubert }
8615796c8dcSSimon Schubert 
8625796c8dcSSimon Schubert void
8635796c8dcSSimon Schubert uo_table_body (struct ui_out *uiout)
8645796c8dcSSimon Schubert {
8655796c8dcSSimon Schubert   if (!uiout->impl->table_body)
8665796c8dcSSimon Schubert     return;
8675796c8dcSSimon Schubert   uiout->impl->table_body (uiout);
8685796c8dcSSimon Schubert }
8695796c8dcSSimon Schubert 
8705796c8dcSSimon Schubert void
8715796c8dcSSimon Schubert uo_table_end (struct ui_out *uiout)
8725796c8dcSSimon Schubert {
8735796c8dcSSimon Schubert   if (!uiout->impl->table_end)
8745796c8dcSSimon Schubert     return;
8755796c8dcSSimon Schubert   uiout->impl->table_end (uiout);
8765796c8dcSSimon Schubert }
8775796c8dcSSimon Schubert 
8785796c8dcSSimon Schubert void
8795796c8dcSSimon Schubert uo_table_header (struct ui_out *uiout, int width, enum ui_align align,
8805796c8dcSSimon Schubert 		 const char *col_name,
8815796c8dcSSimon Schubert 		 const char *colhdr)
8825796c8dcSSimon Schubert {
8835796c8dcSSimon Schubert   if (!uiout->impl->table_header)
8845796c8dcSSimon Schubert     return;
8855796c8dcSSimon Schubert   uiout->impl->table_header (uiout, width, align, col_name, colhdr);
8865796c8dcSSimon Schubert }
8875796c8dcSSimon Schubert 
8885796c8dcSSimon Schubert void
8895796c8dcSSimon Schubert uo_begin (struct ui_out *uiout,
8905796c8dcSSimon Schubert 	  enum ui_out_type type,
8915796c8dcSSimon Schubert 	  int level,
8925796c8dcSSimon Schubert 	  const char *id)
8935796c8dcSSimon Schubert {
8945796c8dcSSimon Schubert   if (uiout->impl->begin == NULL)
8955796c8dcSSimon Schubert     return;
8965796c8dcSSimon Schubert   uiout->impl->begin (uiout, type, level, id);
8975796c8dcSSimon Schubert }
8985796c8dcSSimon Schubert 
8995796c8dcSSimon Schubert void
9005796c8dcSSimon Schubert uo_end (struct ui_out *uiout,
9015796c8dcSSimon Schubert 	enum ui_out_type type,
9025796c8dcSSimon Schubert 	int level)
9035796c8dcSSimon Schubert {
9045796c8dcSSimon Schubert   if (uiout->impl->end == NULL)
9055796c8dcSSimon Schubert     return;
9065796c8dcSSimon Schubert   uiout->impl->end (uiout, type, level);
9075796c8dcSSimon Schubert }
9085796c8dcSSimon Schubert 
9095796c8dcSSimon Schubert void
9105796c8dcSSimon Schubert uo_field_int (struct ui_out *uiout, int fldno, int width, enum ui_align align,
9115796c8dcSSimon Schubert 	      const char *fldname,
9125796c8dcSSimon Schubert 	      int value)
9135796c8dcSSimon Schubert {
9145796c8dcSSimon Schubert   if (!uiout->impl->field_int)
9155796c8dcSSimon Schubert     return;
9165796c8dcSSimon Schubert   uiout->impl->field_int (uiout, fldno, width, align, fldname, value);
9175796c8dcSSimon Schubert }
9185796c8dcSSimon Schubert 
9195796c8dcSSimon Schubert void
9205796c8dcSSimon Schubert uo_field_skip (struct ui_out *uiout, int fldno, int width, enum ui_align align,
9215796c8dcSSimon Schubert 	       const char *fldname)
9225796c8dcSSimon Schubert {
9235796c8dcSSimon Schubert   if (!uiout->impl->field_skip)
9245796c8dcSSimon Schubert     return;
9255796c8dcSSimon Schubert   uiout->impl->field_skip (uiout, fldno, width, align, fldname);
9265796c8dcSSimon Schubert }
9275796c8dcSSimon Schubert 
9285796c8dcSSimon Schubert void
9295796c8dcSSimon Schubert uo_field_string (struct ui_out *uiout, int fldno, int width,
9305796c8dcSSimon Schubert 		 enum ui_align align,
9315796c8dcSSimon Schubert 		 const char *fldname,
9325796c8dcSSimon Schubert 		 const char *string)
9335796c8dcSSimon Schubert {
9345796c8dcSSimon Schubert   if (!uiout->impl->field_string)
9355796c8dcSSimon Schubert     return;
9365796c8dcSSimon Schubert   uiout->impl->field_string (uiout, fldno, width, align, fldname, string);
9375796c8dcSSimon Schubert }
9385796c8dcSSimon Schubert 
9395796c8dcSSimon Schubert void
9405796c8dcSSimon Schubert uo_field_fmt (struct ui_out *uiout, int fldno, int width, enum ui_align align,
9415796c8dcSSimon Schubert 	      const char *fldname,
9425796c8dcSSimon Schubert 	      const char *format,
9435796c8dcSSimon Schubert 	      va_list args)
9445796c8dcSSimon Schubert {
9455796c8dcSSimon Schubert   if (!uiout->impl->field_fmt)
9465796c8dcSSimon Schubert     return;
9475796c8dcSSimon Schubert   uiout->impl->field_fmt (uiout, fldno, width, align, fldname, format, args);
9485796c8dcSSimon Schubert }
9495796c8dcSSimon Schubert 
9505796c8dcSSimon Schubert void
9515796c8dcSSimon Schubert uo_spaces (struct ui_out *uiout, int numspaces)
9525796c8dcSSimon Schubert {
9535796c8dcSSimon Schubert   if (!uiout->impl->spaces)
9545796c8dcSSimon Schubert     return;
9555796c8dcSSimon Schubert   uiout->impl->spaces (uiout, numspaces);
9565796c8dcSSimon Schubert }
9575796c8dcSSimon Schubert 
9585796c8dcSSimon Schubert void
9595796c8dcSSimon Schubert uo_text (struct ui_out *uiout,
9605796c8dcSSimon Schubert 	 const char *string)
9615796c8dcSSimon Schubert {
9625796c8dcSSimon Schubert   if (!uiout->impl->text)
9635796c8dcSSimon Schubert     return;
9645796c8dcSSimon Schubert   uiout->impl->text (uiout, string);
9655796c8dcSSimon Schubert }
9665796c8dcSSimon Schubert 
9675796c8dcSSimon Schubert void
9685796c8dcSSimon Schubert uo_message (struct ui_out *uiout, int verbosity,
9695796c8dcSSimon Schubert 	    const char *format,
9705796c8dcSSimon Schubert 	    va_list args)
9715796c8dcSSimon Schubert {
9725796c8dcSSimon Schubert   if (!uiout->impl->message)
9735796c8dcSSimon Schubert     return;
9745796c8dcSSimon Schubert   uiout->impl->message (uiout, verbosity, format, args);
9755796c8dcSSimon Schubert }
9765796c8dcSSimon Schubert 
9775796c8dcSSimon Schubert void
9785796c8dcSSimon Schubert uo_wrap_hint (struct ui_out *uiout, char *identstring)
9795796c8dcSSimon Schubert {
9805796c8dcSSimon Schubert   if (!uiout->impl->wrap_hint)
9815796c8dcSSimon Schubert     return;
9825796c8dcSSimon Schubert   uiout->impl->wrap_hint (uiout, identstring);
9835796c8dcSSimon Schubert }
9845796c8dcSSimon Schubert 
9855796c8dcSSimon Schubert void
9865796c8dcSSimon Schubert uo_flush (struct ui_out *uiout)
9875796c8dcSSimon Schubert {
9885796c8dcSSimon Schubert   if (!uiout->impl->flush)
9895796c8dcSSimon Schubert     return;
9905796c8dcSSimon Schubert   uiout->impl->flush (uiout);
9915796c8dcSSimon Schubert }
9925796c8dcSSimon Schubert 
9935796c8dcSSimon Schubert int
9945796c8dcSSimon Schubert uo_redirect (struct ui_out *uiout, struct ui_file *outstream)
9955796c8dcSSimon Schubert {
9965796c8dcSSimon Schubert   if (!uiout->impl->redirect)
9975796c8dcSSimon Schubert     return -1;
9985796c8dcSSimon Schubert   uiout->impl->redirect (uiout, outstream);
9995796c8dcSSimon Schubert   return 0;
10005796c8dcSSimon Schubert }
10015796c8dcSSimon Schubert 
10025796c8dcSSimon Schubert /* local functions */
10035796c8dcSSimon Schubert 
10045796c8dcSSimon Schubert /* list of column headers manipulation routines */
10055796c8dcSSimon Schubert 
10065796c8dcSSimon Schubert static void
10075796c8dcSSimon Schubert clear_header_list (struct ui_out *uiout)
10085796c8dcSSimon Schubert {
10095796c8dcSSimon Schubert   while (uiout->table.header_first != NULL)
10105796c8dcSSimon Schubert     {
10115796c8dcSSimon Schubert       uiout->table.header_next = uiout->table.header_first;
10125796c8dcSSimon Schubert       uiout->table.header_first = uiout->table.header_first->next;
10135796c8dcSSimon Schubert       if (uiout->table.header_next->colhdr != NULL)
10145796c8dcSSimon Schubert 	xfree (uiout->table.header_next->colhdr);
10155796c8dcSSimon Schubert       xfree (uiout->table.header_next);
10165796c8dcSSimon Schubert     }
10175796c8dcSSimon Schubert   gdb_assert (uiout->table.header_first == NULL);
10185796c8dcSSimon Schubert   uiout->table.header_last = NULL;
10195796c8dcSSimon Schubert   uiout->table.header_next = NULL;
10205796c8dcSSimon Schubert }
10215796c8dcSSimon Schubert 
10225796c8dcSSimon Schubert static void
10235796c8dcSSimon Schubert append_header_to_list (struct ui_out *uiout,
10245796c8dcSSimon Schubert 		       int width,
10255796c8dcSSimon Schubert 		       int alignment,
10265796c8dcSSimon Schubert 		       const char *col_name,
10275796c8dcSSimon Schubert 		       const char *colhdr)
10285796c8dcSSimon Schubert {
10295796c8dcSSimon Schubert   struct ui_out_hdr *temphdr;
10305796c8dcSSimon Schubert 
10315796c8dcSSimon Schubert   temphdr = XMALLOC (struct ui_out_hdr);
10325796c8dcSSimon Schubert   temphdr->width = width;
10335796c8dcSSimon Schubert   temphdr->alignment = alignment;
10345796c8dcSSimon Schubert   /* We have to copy the column title as the original may be an
10355796c8dcSSimon Schubert      automatic.  */
10365796c8dcSSimon Schubert   if (colhdr != NULL)
10375796c8dcSSimon Schubert     temphdr->colhdr = xstrdup (colhdr);
10385796c8dcSSimon Schubert   else
10395796c8dcSSimon Schubert     temphdr->colhdr = NULL;
10405796c8dcSSimon Schubert 
10415796c8dcSSimon Schubert   if (col_name != NULL)
10425796c8dcSSimon Schubert     temphdr->col_name = xstrdup (col_name);
10435796c8dcSSimon Schubert   else if (colhdr != NULL)
10445796c8dcSSimon Schubert     temphdr->col_name = xstrdup (colhdr);
10455796c8dcSSimon Schubert   else
10465796c8dcSSimon Schubert     temphdr->col_name = NULL;
10475796c8dcSSimon Schubert 
10485796c8dcSSimon Schubert   temphdr->next = NULL;
10495796c8dcSSimon Schubert   if (uiout->table.header_first == NULL)
10505796c8dcSSimon Schubert     {
10515796c8dcSSimon Schubert       temphdr->colno = 1;
10525796c8dcSSimon Schubert       uiout->table.header_first = temphdr;
10535796c8dcSSimon Schubert       uiout->table.header_last = temphdr;
10545796c8dcSSimon Schubert     }
10555796c8dcSSimon Schubert   else
10565796c8dcSSimon Schubert     {
10575796c8dcSSimon Schubert       temphdr->colno = uiout->table.header_last->colno + 1;
10585796c8dcSSimon Schubert       uiout->table.header_last->next = temphdr;
10595796c8dcSSimon Schubert       uiout->table.header_last = temphdr;
10605796c8dcSSimon Schubert     }
10615796c8dcSSimon Schubert   uiout->table.header_next = uiout->table.header_last;
10625796c8dcSSimon Schubert }
10635796c8dcSSimon Schubert 
10645796c8dcSSimon Schubert /* Extract the format information for the NEXT header and and advance
10655796c8dcSSimon Schubert    the header pointer.  Return 0 if there was no next header.  */
10665796c8dcSSimon Schubert 
10675796c8dcSSimon Schubert static int
10685796c8dcSSimon Schubert get_next_header (struct ui_out *uiout,
10695796c8dcSSimon Schubert 		 int *colno,
10705796c8dcSSimon Schubert 		 int *width,
10715796c8dcSSimon Schubert 		 int *alignment,
10725796c8dcSSimon Schubert 		 char **colhdr)
10735796c8dcSSimon Schubert {
10745796c8dcSSimon Schubert   /* There may be no headers at all or we may have used all columns.  */
10755796c8dcSSimon Schubert   if (uiout->table.header_next == NULL)
10765796c8dcSSimon Schubert     return 0;
10775796c8dcSSimon Schubert   *colno = uiout->table.header_next->colno;
10785796c8dcSSimon Schubert   *width = uiout->table.header_next->width;
10795796c8dcSSimon Schubert   *alignment = uiout->table.header_next->alignment;
10805796c8dcSSimon Schubert   *colhdr = uiout->table.header_next->colhdr;
10815796c8dcSSimon Schubert   /* Advance the header pointer to the next entry.  */
10825796c8dcSSimon Schubert   uiout->table.header_next = uiout->table.header_next->next;
10835796c8dcSSimon Schubert   return 1;
10845796c8dcSSimon Schubert }
10855796c8dcSSimon Schubert 
10865796c8dcSSimon Schubert 
10875796c8dcSSimon Schubert /* Verify that the field/tuple/list is correctly positioned.  Return
10885796c8dcSSimon Schubert    the field number and corresponding alignment (if
10895796c8dcSSimon Schubert    available/applicable).  */
10905796c8dcSSimon Schubert 
10915796c8dcSSimon Schubert static void
10925796c8dcSSimon Schubert verify_field (struct ui_out *uiout, int *fldno, int *width, int *align)
10935796c8dcSSimon Schubert {
10945796c8dcSSimon Schubert   struct ui_out_level *current = current_level (uiout);
10955796c8dcSSimon Schubert   char *text;
10965796c8dcSSimon Schubert 
10975796c8dcSSimon Schubert   if (uiout->table.flag)
10985796c8dcSSimon Schubert     {
10995796c8dcSSimon Schubert       if (!uiout->table.body_flag)
11005796c8dcSSimon Schubert 	internal_error (__FILE__, __LINE__,
11015796c8dcSSimon Schubert 			_("table_body missing; table fields must be \
11025796c8dcSSimon Schubert specified after table_body and inside a list."));
11035796c8dcSSimon Schubert       /* NOTE: cagney/2001-12-08: There was a check here to ensure
11045796c8dcSSimon Schubert 	 that this code was only executed when uiout->level was
11055796c8dcSSimon Schubert 	 greater than zero.  That no longer applies - this code is run
11065796c8dcSSimon Schubert 	 before each table row tuple is started and at that point the
11075796c8dcSSimon Schubert 	 level is zero.  */
11085796c8dcSSimon Schubert     }
11095796c8dcSSimon Schubert 
11105796c8dcSSimon Schubert   current->field_count += 1;
11115796c8dcSSimon Schubert 
11125796c8dcSSimon Schubert   if (uiout->table.body_flag
11135796c8dcSSimon Schubert       && uiout->table.entry_level == uiout->level
11145796c8dcSSimon Schubert       && get_next_header (uiout, fldno, width, align, &text))
11155796c8dcSSimon Schubert     {
11165796c8dcSSimon Schubert       if (*fldno != current->field_count)
11175796c8dcSSimon Schubert 	internal_error (__FILE__, __LINE__,
11185796c8dcSSimon Schubert 			_("ui-out internal error in handling headers."));
11195796c8dcSSimon Schubert     }
11205796c8dcSSimon Schubert   else
11215796c8dcSSimon Schubert     {
11225796c8dcSSimon Schubert       *width = 0;
11235796c8dcSSimon Schubert       *align = ui_noalign;
11245796c8dcSSimon Schubert       *fldno = current->field_count;
11255796c8dcSSimon Schubert     }
11265796c8dcSSimon Schubert }
11275796c8dcSSimon Schubert 
11285796c8dcSSimon Schubert 
11295796c8dcSSimon Schubert /* access to ui_out format private members */
11305796c8dcSSimon Schubert 
11315796c8dcSSimon Schubert void
11325796c8dcSSimon Schubert ui_out_get_field_separator (struct ui_out *uiout)
11335796c8dcSSimon Schubert {
11345796c8dcSSimon Schubert }
11355796c8dcSSimon Schubert 
11365796c8dcSSimon Schubert /* Access to ui-out members data */
11375796c8dcSSimon Schubert 
1138*cf7f2e2dSJohn Marino void *
11395796c8dcSSimon Schubert ui_out_data (struct ui_out *uiout)
11405796c8dcSSimon Schubert {
11415796c8dcSSimon Schubert   return uiout->data;
11425796c8dcSSimon Schubert }
11435796c8dcSSimon Schubert 
11445796c8dcSSimon Schubert /* initalize private members at startup */
11455796c8dcSSimon Schubert 
11465796c8dcSSimon Schubert struct ui_out *
1147*cf7f2e2dSJohn Marino ui_out_new (struct ui_out_impl *impl, void *data,
11485796c8dcSSimon Schubert 	    int flags)
11495796c8dcSSimon Schubert {
11505796c8dcSSimon Schubert   struct ui_out *uiout = XMALLOC (struct ui_out);
1151*cf7f2e2dSJohn Marino 
11525796c8dcSSimon Schubert   uiout->data = data;
11535796c8dcSSimon Schubert   uiout->impl = impl;
11545796c8dcSSimon Schubert   uiout->flags = flags;
11555796c8dcSSimon Schubert   uiout->table.flag = 0;
11565796c8dcSSimon Schubert   uiout->table.body_flag = 0;
11575796c8dcSSimon Schubert   uiout->level = 0;
11585796c8dcSSimon Schubert   memset (uiout->levels, 0, sizeof (uiout->levels));
11595796c8dcSSimon Schubert   uiout->table.header_first = NULL;
11605796c8dcSSimon Schubert   uiout->table.header_last = NULL;
11615796c8dcSSimon Schubert   uiout->table.header_next = NULL;
11625796c8dcSSimon Schubert   return uiout;
11635796c8dcSSimon Schubert }
11645796c8dcSSimon Schubert 
11655796c8dcSSimon Schubert /* standard gdb initialization hook */
11665796c8dcSSimon Schubert 
11675796c8dcSSimon Schubert void
11685796c8dcSSimon Schubert _initialize_ui_out (void)
11695796c8dcSSimon Schubert {
11705796c8dcSSimon Schubert   /* nothing needs to be done */
11715796c8dcSSimon Schubert }
1172