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