xref: /dflybsd-src/contrib/gdb-7/gdb/mi/mi-out.c (revision de8e141f24382815c10a4012d209bbbf7abf1112)
15796c8dcSSimon Schubert /* MI Command Set - output generating routines.
25796c8dcSSimon Schubert 
3*ef5ccd6cSJohn Marino    Copyright (C) 2000-2013 Free Software Foundation, Inc.
45796c8dcSSimon Schubert 
55796c8dcSSimon Schubert    Contributed by Cygnus Solutions (a Red Hat company).
65796c8dcSSimon Schubert 
75796c8dcSSimon Schubert    This file is part of GDB.
85796c8dcSSimon Schubert 
95796c8dcSSimon Schubert    This program is free software; you can redistribute it and/or modify
105796c8dcSSimon Schubert    it under the terms of the GNU General Public License as published by
115796c8dcSSimon Schubert    the Free Software Foundation; either version 3 of the License, or
125796c8dcSSimon Schubert    (at your option) any later version.
135796c8dcSSimon Schubert 
145796c8dcSSimon Schubert    This program is distributed in the hope that it will be useful,
155796c8dcSSimon Schubert    but WITHOUT ANY WARRANTY; without even the implied warranty of
165796c8dcSSimon Schubert    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
175796c8dcSSimon Schubert    GNU General Public License for more details.
185796c8dcSSimon Schubert 
195796c8dcSSimon Schubert    You should have received a copy of the GNU General Public License
205796c8dcSSimon Schubert    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
215796c8dcSSimon Schubert 
225796c8dcSSimon Schubert #include "defs.h"
235796c8dcSSimon Schubert #include "ui-out.h"
245796c8dcSSimon Schubert #include "mi-out.h"
255796c8dcSSimon Schubert 
265796c8dcSSimon Schubert struct ui_out_data
275796c8dcSSimon Schubert   {
285796c8dcSSimon Schubert     int suppress_field_separator;
295796c8dcSSimon Schubert     int suppress_output;
305796c8dcSSimon Schubert     int mi_version;
315796c8dcSSimon Schubert     struct ui_file *buffer;
32a45ae5f8SJohn Marino     struct ui_file *original_buffer;
335796c8dcSSimon Schubert   };
345796c8dcSSimon Schubert typedef struct ui_out_data mi_out_data;
355796c8dcSSimon Schubert 
365796c8dcSSimon Schubert /* These are the MI output functions */
375796c8dcSSimon Schubert 
385796c8dcSSimon Schubert static void mi_table_begin (struct ui_out *uiout, int nbrofcols,
395796c8dcSSimon Schubert 			    int nr_rows, const char *tblid);
405796c8dcSSimon Schubert static void mi_table_body (struct ui_out *uiout);
415796c8dcSSimon Schubert static void mi_table_end (struct ui_out *uiout);
425796c8dcSSimon Schubert static void mi_table_header (struct ui_out *uiout, int width,
435796c8dcSSimon Schubert 			     enum ui_align alig, const char *col_name,
445796c8dcSSimon Schubert 			     const char *colhdr);
455796c8dcSSimon Schubert static void mi_begin (struct ui_out *uiout, enum ui_out_type type,
465796c8dcSSimon Schubert 		      int level, const char *id);
475796c8dcSSimon Schubert static void mi_end (struct ui_out *uiout, enum ui_out_type type, int level);
485796c8dcSSimon Schubert static void mi_field_int (struct ui_out *uiout, int fldno, int width,
495796c8dcSSimon Schubert 			  enum ui_align alig, const char *fldname, int value);
505796c8dcSSimon Schubert static void mi_field_skip (struct ui_out *uiout, int fldno, int width,
515796c8dcSSimon Schubert 			   enum ui_align alig, const char *fldname);
525796c8dcSSimon Schubert static void mi_field_string (struct ui_out *uiout, int fldno, int width,
535796c8dcSSimon Schubert 			     enum ui_align alig, const char *fldname,
545796c8dcSSimon Schubert 			     const char *string);
555796c8dcSSimon Schubert static void mi_field_fmt (struct ui_out *uiout, int fldno,
565796c8dcSSimon Schubert 			  int width, enum ui_align align,
575796c8dcSSimon Schubert 			  const char *fldname, const char *format,
58cf7f2e2dSJohn Marino 			  va_list args) ATTRIBUTE_PRINTF (6, 0);
595796c8dcSSimon Schubert static void mi_spaces (struct ui_out *uiout, int numspaces);
605796c8dcSSimon Schubert static void mi_text (struct ui_out *uiout, const char *string);
615796c8dcSSimon Schubert static void mi_message (struct ui_out *uiout, int verbosity,
625796c8dcSSimon Schubert 			const char *format, va_list args)
63cf7f2e2dSJohn Marino      ATTRIBUTE_PRINTF (3, 0);
645796c8dcSSimon Schubert static void mi_wrap_hint (struct ui_out *uiout, char *identstring);
655796c8dcSSimon Schubert static void mi_flush (struct ui_out *uiout);
66a45ae5f8SJohn Marino static int mi_redirect (struct ui_out *uiout, struct ui_file *outstream);
675796c8dcSSimon Schubert 
685796c8dcSSimon Schubert /* This is the MI ui-out implementation functions vector */
695796c8dcSSimon Schubert 
705796c8dcSSimon Schubert /* FIXME: This can be initialized dynamically after default is set to
715796c8dcSSimon Schubert    handle initial output in main.c */
725796c8dcSSimon Schubert 
735796c8dcSSimon Schubert struct ui_out_impl mi_ui_out_impl =
745796c8dcSSimon Schubert {
755796c8dcSSimon Schubert   mi_table_begin,
765796c8dcSSimon Schubert   mi_table_body,
775796c8dcSSimon Schubert   mi_table_end,
785796c8dcSSimon Schubert   mi_table_header,
795796c8dcSSimon Schubert   mi_begin,
805796c8dcSSimon Schubert   mi_end,
815796c8dcSSimon Schubert   mi_field_int,
825796c8dcSSimon Schubert   mi_field_skip,
835796c8dcSSimon Schubert   mi_field_string,
845796c8dcSSimon Schubert   mi_field_fmt,
855796c8dcSSimon Schubert   mi_spaces,
865796c8dcSSimon Schubert   mi_text,
875796c8dcSSimon Schubert   mi_message,
885796c8dcSSimon Schubert   mi_wrap_hint,
895796c8dcSSimon Schubert   mi_flush,
90a45ae5f8SJohn Marino   mi_redirect,
91*ef5ccd6cSJohn Marino   0,
925796c8dcSSimon Schubert   1, /* Needs MI hacks.  */
935796c8dcSSimon Schubert };
945796c8dcSSimon Schubert 
955796c8dcSSimon Schubert /* Prototypes for local functions */
965796c8dcSSimon Schubert 
975796c8dcSSimon Schubert extern void _initialize_mi_out (void);
985796c8dcSSimon Schubert static void field_separator (struct ui_out *uiout);
995796c8dcSSimon Schubert static void mi_open (struct ui_out *uiout, const char *name,
1005796c8dcSSimon Schubert 		     enum ui_out_type type);
1015796c8dcSSimon Schubert static void mi_close (struct ui_out *uiout, enum ui_out_type type);
1025796c8dcSSimon Schubert 
103*ef5ccd6cSJohn Marino /* Mark beginning of a table.  */
1045796c8dcSSimon Schubert 
1055796c8dcSSimon Schubert void
mi_table_begin(struct ui_out * uiout,int nr_cols,int nr_rows,const char * tblid)1065796c8dcSSimon Schubert mi_table_begin (struct ui_out *uiout,
1075796c8dcSSimon Schubert 		int nr_cols,
1085796c8dcSSimon Schubert 		int nr_rows,
1095796c8dcSSimon Schubert 		const char *tblid)
1105796c8dcSSimon Schubert {
1115796c8dcSSimon Schubert   mi_open (uiout, tblid, ui_out_type_tuple);
112*ef5ccd6cSJohn Marino   mi_field_int (uiout, -1, -1, -1, "nr_rows", nr_rows);
113*ef5ccd6cSJohn Marino   mi_field_int (uiout, -1, -1, -1, "nr_cols", nr_cols);
1145796c8dcSSimon Schubert   mi_open (uiout, "hdr", ui_out_type_list);
1155796c8dcSSimon Schubert }
1165796c8dcSSimon Schubert 
117*ef5ccd6cSJohn Marino /* Mark beginning of a table body.  */
1185796c8dcSSimon Schubert 
1195796c8dcSSimon Schubert void
mi_table_body(struct ui_out * uiout)1205796c8dcSSimon Schubert mi_table_body (struct ui_out *uiout)
1215796c8dcSSimon Schubert {
1225796c8dcSSimon Schubert   mi_out_data *data = ui_out_data (uiout);
123cf7f2e2dSJohn Marino 
1245796c8dcSSimon Schubert   if (data->suppress_output)
1255796c8dcSSimon Schubert     return;
1265796c8dcSSimon Schubert   /* close the table header line if there were any headers */
1275796c8dcSSimon Schubert   mi_close (uiout, ui_out_type_list);
1285796c8dcSSimon Schubert   mi_open (uiout, "body", ui_out_type_list);
1295796c8dcSSimon Schubert }
1305796c8dcSSimon Schubert 
131*ef5ccd6cSJohn Marino /* Mark end of a table.  */
1325796c8dcSSimon Schubert 
1335796c8dcSSimon Schubert void
mi_table_end(struct ui_out * uiout)1345796c8dcSSimon Schubert mi_table_end (struct ui_out *uiout)
1355796c8dcSSimon Schubert {
1365796c8dcSSimon Schubert   mi_out_data *data = ui_out_data (uiout);
137cf7f2e2dSJohn Marino 
1385796c8dcSSimon Schubert   data->suppress_output = 0;
1395796c8dcSSimon Schubert   mi_close (uiout, ui_out_type_list); /* body */
1405796c8dcSSimon Schubert   mi_close (uiout, ui_out_type_tuple);
1415796c8dcSSimon Schubert }
1425796c8dcSSimon Schubert 
143*ef5ccd6cSJohn Marino /* Specify table header.  */
1445796c8dcSSimon Schubert 
1455796c8dcSSimon Schubert void
mi_table_header(struct ui_out * uiout,int width,enum ui_align alignment,const char * col_name,const char * colhdr)1465796c8dcSSimon Schubert mi_table_header (struct ui_out *uiout, int width, enum ui_align alignment,
147*ef5ccd6cSJohn Marino 		 const char *col_name, const char *colhdr)
1485796c8dcSSimon Schubert {
1495796c8dcSSimon Schubert   mi_out_data *data = ui_out_data (uiout);
150cf7f2e2dSJohn Marino 
1515796c8dcSSimon Schubert   if (data->suppress_output)
1525796c8dcSSimon Schubert     return;
153*ef5ccd6cSJohn Marino 
1545796c8dcSSimon Schubert   mi_open (uiout, NULL, ui_out_type_tuple);
1555796c8dcSSimon Schubert   mi_field_int (uiout, 0, 0, 0, "width", width);
1565796c8dcSSimon Schubert   mi_field_int (uiout, 0, 0, 0, "alignment", alignment);
1575796c8dcSSimon Schubert   mi_field_string (uiout, 0, 0, 0, "col_name", col_name);
1585796c8dcSSimon Schubert   mi_field_string (uiout, 0, width, alignment, "colhdr", colhdr);
1595796c8dcSSimon Schubert   mi_close (uiout, ui_out_type_tuple);
1605796c8dcSSimon Schubert }
1615796c8dcSSimon Schubert 
162*ef5ccd6cSJohn Marino /* Mark beginning of a list.  */
1635796c8dcSSimon Schubert 
1645796c8dcSSimon Schubert void
mi_begin(struct ui_out * uiout,enum ui_out_type type,int level,const char * id)165*ef5ccd6cSJohn Marino mi_begin (struct ui_out *uiout, enum ui_out_type type, int level,
1665796c8dcSSimon Schubert 	  const char *id)
1675796c8dcSSimon Schubert {
1685796c8dcSSimon Schubert   mi_out_data *data = ui_out_data (uiout);
169cf7f2e2dSJohn Marino 
1705796c8dcSSimon Schubert   if (data->suppress_output)
1715796c8dcSSimon Schubert     return;
172*ef5ccd6cSJohn Marino 
1735796c8dcSSimon Schubert   mi_open (uiout, id, type);
1745796c8dcSSimon Schubert }
1755796c8dcSSimon Schubert 
176*ef5ccd6cSJohn Marino /* Mark end of a list.  */
1775796c8dcSSimon Schubert 
1785796c8dcSSimon Schubert void
mi_end(struct ui_out * uiout,enum ui_out_type type,int level)179*ef5ccd6cSJohn Marino mi_end (struct ui_out *uiout, enum ui_out_type type, int level)
1805796c8dcSSimon Schubert {
1815796c8dcSSimon Schubert   mi_out_data *data = ui_out_data (uiout);
182cf7f2e2dSJohn Marino 
1835796c8dcSSimon Schubert   if (data->suppress_output)
1845796c8dcSSimon Schubert     return;
185*ef5ccd6cSJohn Marino 
1865796c8dcSSimon Schubert   mi_close (uiout, type);
1875796c8dcSSimon Schubert }
1885796c8dcSSimon Schubert 
189*ef5ccd6cSJohn Marino /* Output an int field.  */
1905796c8dcSSimon Schubert 
191*ef5ccd6cSJohn Marino static void
mi_field_int(struct ui_out * uiout,int fldno,int width,enum ui_align alignment,const char * fldname,int value)1925796c8dcSSimon Schubert mi_field_int (struct ui_out *uiout, int fldno, int width,
1935796c8dcSSimon Schubert               enum ui_align alignment, const char *fldname, int value)
1945796c8dcSSimon Schubert {
1955796c8dcSSimon Schubert   char buffer[20];	/* FIXME: how many chars long a %d can become? */
1965796c8dcSSimon Schubert   mi_out_data *data = ui_out_data (uiout);
197cf7f2e2dSJohn Marino 
1985796c8dcSSimon Schubert   if (data->suppress_output)
1995796c8dcSSimon Schubert     return;
2005796c8dcSSimon Schubert 
201*ef5ccd6cSJohn Marino   xsnprintf (buffer, sizeof (buffer), "%d", value);
2025796c8dcSSimon Schubert   mi_field_string (uiout, fldno, width, alignment, fldname, buffer);
2035796c8dcSSimon Schubert }
2045796c8dcSSimon Schubert 
205*ef5ccd6cSJohn Marino /* Used to omit a field.  */
2065796c8dcSSimon Schubert 
2075796c8dcSSimon Schubert void
mi_field_skip(struct ui_out * uiout,int fldno,int width,enum ui_align alignment,const char * fldname)2085796c8dcSSimon Schubert mi_field_skip (struct ui_out *uiout, int fldno, int width,
2095796c8dcSSimon Schubert                enum ui_align alignment, const char *fldname)
2105796c8dcSSimon Schubert {
2115796c8dcSSimon Schubert }
2125796c8dcSSimon Schubert 
213*ef5ccd6cSJohn Marino /* Other specific mi_field_* end up here so alignment and field
214*ef5ccd6cSJohn Marino    separators are both handled by mi_field_string. */
2155796c8dcSSimon Schubert 
2165796c8dcSSimon Schubert void
mi_field_string(struct ui_out * uiout,int fldno,int width,enum ui_align align,const char * fldname,const char * string)217*ef5ccd6cSJohn Marino mi_field_string (struct ui_out *uiout, int fldno, int width,
218*ef5ccd6cSJohn Marino 		 enum ui_align align, const char *fldname, const char *string)
2195796c8dcSSimon Schubert {
2205796c8dcSSimon Schubert   mi_out_data *data = ui_out_data (uiout);
221cf7f2e2dSJohn Marino 
2225796c8dcSSimon Schubert   if (data->suppress_output)
2235796c8dcSSimon Schubert     return;
224*ef5ccd6cSJohn Marino 
2255796c8dcSSimon Schubert   field_separator (uiout);
2265796c8dcSSimon Schubert   if (fldname)
2275796c8dcSSimon Schubert     fprintf_unfiltered (data->buffer, "%s=", fldname);
2285796c8dcSSimon Schubert   fprintf_unfiltered (data->buffer, "\"");
2295796c8dcSSimon Schubert   if (string)
2305796c8dcSSimon Schubert     fputstr_unfiltered (string, '"', data->buffer);
2315796c8dcSSimon Schubert   fprintf_unfiltered (data->buffer, "\"");
2325796c8dcSSimon Schubert }
2335796c8dcSSimon Schubert 
234*ef5ccd6cSJohn Marino /* This is the only field function that does not align.  */
2355796c8dcSSimon Schubert 
2365796c8dcSSimon Schubert void
mi_field_fmt(struct ui_out * uiout,int fldno,int width,enum ui_align align,const char * fldname,const char * format,va_list args)237*ef5ccd6cSJohn Marino mi_field_fmt (struct ui_out *uiout, int fldno, int width,
238*ef5ccd6cSJohn Marino 	      enum ui_align align, const char *fldname,
239*ef5ccd6cSJohn Marino 	      const char *format, va_list args)
2405796c8dcSSimon Schubert {
2415796c8dcSSimon Schubert   mi_out_data *data = ui_out_data (uiout);
242cf7f2e2dSJohn Marino 
2435796c8dcSSimon Schubert   if (data->suppress_output)
2445796c8dcSSimon Schubert     return;
245*ef5ccd6cSJohn Marino 
2465796c8dcSSimon Schubert   field_separator (uiout);
2475796c8dcSSimon Schubert   if (fldname)
2485796c8dcSSimon Schubert     fprintf_unfiltered (data->buffer, "%s=\"", fldname);
2495796c8dcSSimon Schubert   else
2505796c8dcSSimon Schubert     fputs_unfiltered ("\"", data->buffer);
2515796c8dcSSimon Schubert   vfprintf_unfiltered (data->buffer, format, args);
2525796c8dcSSimon Schubert   fputs_unfiltered ("\"", data->buffer);
2535796c8dcSSimon Schubert }
2545796c8dcSSimon Schubert 
2555796c8dcSSimon Schubert void
mi_spaces(struct ui_out * uiout,int numspaces)2565796c8dcSSimon Schubert mi_spaces (struct ui_out *uiout, int numspaces)
2575796c8dcSSimon Schubert {
2585796c8dcSSimon Schubert }
2595796c8dcSSimon Schubert 
2605796c8dcSSimon Schubert void
mi_text(struct ui_out * uiout,const char * string)2615796c8dcSSimon Schubert mi_text (struct ui_out *uiout, const char *string)
2625796c8dcSSimon Schubert {
2635796c8dcSSimon Schubert }
2645796c8dcSSimon Schubert 
2655796c8dcSSimon Schubert void
mi_message(struct ui_out * uiout,int verbosity,const char * format,va_list args)2665796c8dcSSimon Schubert mi_message (struct ui_out *uiout, int verbosity,
267*ef5ccd6cSJohn Marino 	    const char *format, va_list args)
2685796c8dcSSimon Schubert {
2695796c8dcSSimon Schubert }
2705796c8dcSSimon Schubert 
2715796c8dcSSimon Schubert void
mi_wrap_hint(struct ui_out * uiout,char * identstring)2725796c8dcSSimon Schubert mi_wrap_hint (struct ui_out *uiout, char *identstring)
2735796c8dcSSimon Schubert {
2745796c8dcSSimon Schubert   wrap_here (identstring);
2755796c8dcSSimon Schubert }
2765796c8dcSSimon Schubert 
2775796c8dcSSimon Schubert void
mi_flush(struct ui_out * uiout)2785796c8dcSSimon Schubert mi_flush (struct ui_out *uiout)
2795796c8dcSSimon Schubert {
2805796c8dcSSimon Schubert   mi_out_data *data = ui_out_data (uiout);
281cf7f2e2dSJohn Marino 
2825796c8dcSSimon Schubert   gdb_flush (data->buffer);
2835796c8dcSSimon Schubert }
2845796c8dcSSimon Schubert 
285a45ae5f8SJohn Marino int
mi_redirect(struct ui_out * uiout,struct ui_file * outstream)286a45ae5f8SJohn Marino mi_redirect (struct ui_out *uiout, struct ui_file *outstream)
287a45ae5f8SJohn Marino {
288a45ae5f8SJohn Marino   mi_out_data *data = ui_out_data (uiout);
289a45ae5f8SJohn Marino 
290a45ae5f8SJohn Marino   if (outstream != NULL)
291a45ae5f8SJohn Marino     {
292a45ae5f8SJohn Marino       data->original_buffer = data->buffer;
293a45ae5f8SJohn Marino       data->buffer = outstream;
294a45ae5f8SJohn Marino     }
295a45ae5f8SJohn Marino   else if (data->original_buffer != NULL)
296a45ae5f8SJohn Marino     {
297a45ae5f8SJohn Marino       data->buffer = data->original_buffer;
298a45ae5f8SJohn Marino       data->original_buffer = NULL;
299a45ae5f8SJohn Marino     }
300a45ae5f8SJohn Marino 
301a45ae5f8SJohn Marino   return 0;
302a45ae5f8SJohn Marino }
303a45ae5f8SJohn Marino 
3045796c8dcSSimon Schubert /* local functions */
3055796c8dcSSimon Schubert 
3065796c8dcSSimon Schubert /* access to ui_out format private members */
3075796c8dcSSimon Schubert 
3085796c8dcSSimon Schubert static void
field_separator(struct ui_out * uiout)3095796c8dcSSimon Schubert field_separator (struct ui_out *uiout)
3105796c8dcSSimon Schubert {
3115796c8dcSSimon Schubert   mi_out_data *data = ui_out_data (uiout);
312cf7f2e2dSJohn Marino 
3135796c8dcSSimon Schubert   if (data->suppress_field_separator)
3145796c8dcSSimon Schubert     data->suppress_field_separator = 0;
3155796c8dcSSimon Schubert   else
3165796c8dcSSimon Schubert     fputc_unfiltered (',', data->buffer);
3175796c8dcSSimon Schubert }
3185796c8dcSSimon Schubert 
3195796c8dcSSimon Schubert static void
mi_open(struct ui_out * uiout,const char * name,enum ui_out_type type)320*ef5ccd6cSJohn Marino mi_open (struct ui_out *uiout, const char *name, enum ui_out_type type)
3215796c8dcSSimon Schubert {
3225796c8dcSSimon Schubert   mi_out_data *data = ui_out_data (uiout);
323cf7f2e2dSJohn Marino 
3245796c8dcSSimon Schubert   field_separator (uiout);
3255796c8dcSSimon Schubert   data->suppress_field_separator = 1;
3265796c8dcSSimon Schubert   if (name)
3275796c8dcSSimon Schubert     fprintf_unfiltered (data->buffer, "%s=", name);
3285796c8dcSSimon Schubert   switch (type)
3295796c8dcSSimon Schubert     {
3305796c8dcSSimon Schubert     case ui_out_type_tuple:
3315796c8dcSSimon Schubert       fputc_unfiltered ('{', data->buffer);
3325796c8dcSSimon Schubert       break;
3335796c8dcSSimon Schubert     case ui_out_type_list:
3345796c8dcSSimon Schubert       fputc_unfiltered ('[', data->buffer);
3355796c8dcSSimon Schubert       break;
3365796c8dcSSimon Schubert     default:
3375796c8dcSSimon Schubert       internal_error (__FILE__, __LINE__, _("bad switch"));
3385796c8dcSSimon Schubert     }
3395796c8dcSSimon Schubert }
3405796c8dcSSimon Schubert 
3415796c8dcSSimon Schubert static void
mi_close(struct ui_out * uiout,enum ui_out_type type)342*ef5ccd6cSJohn Marino mi_close (struct ui_out *uiout, enum ui_out_type type)
3435796c8dcSSimon Schubert {
3445796c8dcSSimon Schubert   mi_out_data *data = ui_out_data (uiout);
345cf7f2e2dSJohn Marino 
3465796c8dcSSimon Schubert   switch (type)
3475796c8dcSSimon Schubert     {
3485796c8dcSSimon Schubert     case ui_out_type_tuple:
3495796c8dcSSimon Schubert       fputc_unfiltered ('}', data->buffer);
3505796c8dcSSimon Schubert       break;
3515796c8dcSSimon Schubert     case ui_out_type_list:
3525796c8dcSSimon Schubert       fputc_unfiltered (']', data->buffer);
3535796c8dcSSimon Schubert       break;
3545796c8dcSSimon Schubert     default:
3555796c8dcSSimon Schubert       internal_error (__FILE__, __LINE__, _("bad switch"));
3565796c8dcSSimon Schubert     }
3575796c8dcSSimon Schubert   data->suppress_field_separator = 0;
3585796c8dcSSimon Schubert }
3595796c8dcSSimon Schubert 
360*ef5ccd6cSJohn Marino /* Add a string to the buffer.  */
3615796c8dcSSimon Schubert 
3625796c8dcSSimon Schubert void
mi_out_buffered(struct ui_out * uiout,char * string)3635796c8dcSSimon Schubert mi_out_buffered (struct ui_out *uiout, char *string)
3645796c8dcSSimon Schubert {
3655796c8dcSSimon Schubert   mi_out_data *data = ui_out_data (uiout);
366cf7f2e2dSJohn Marino 
3675796c8dcSSimon Schubert   fprintf_unfiltered (data->buffer, "%s", string);
3685796c8dcSSimon Schubert }
3695796c8dcSSimon Schubert 
370*ef5ccd6cSJohn Marino /* Clear the buffer.  */
3715796c8dcSSimon Schubert 
3725796c8dcSSimon Schubert void
mi_out_rewind(struct ui_out * uiout)3735796c8dcSSimon Schubert mi_out_rewind (struct ui_out *uiout)
3745796c8dcSSimon Schubert {
3755796c8dcSSimon Schubert   mi_out_data *data = ui_out_data (uiout);
376cf7f2e2dSJohn Marino 
3775796c8dcSSimon Schubert   ui_file_rewind (data->buffer);
3785796c8dcSSimon Schubert }
3795796c8dcSSimon Schubert 
380*ef5ccd6cSJohn Marino /* Dump the buffer onto the specified stream.  */
3815796c8dcSSimon Schubert 
3825796c8dcSSimon Schubert static void
do_write(void * data,const char * buffer,long length_buffer)3835796c8dcSSimon Schubert do_write (void *data, const char *buffer, long length_buffer)
3845796c8dcSSimon Schubert {
3855796c8dcSSimon Schubert   ui_file_write (data, buffer, length_buffer);
3865796c8dcSSimon Schubert }
3875796c8dcSSimon Schubert 
3885796c8dcSSimon Schubert void
mi_out_put(struct ui_out * uiout,struct ui_file * stream)389*ef5ccd6cSJohn Marino mi_out_put (struct ui_out *uiout, struct ui_file *stream)
3905796c8dcSSimon Schubert {
3915796c8dcSSimon Schubert   mi_out_data *data = ui_out_data (uiout);
392cf7f2e2dSJohn Marino 
3935796c8dcSSimon Schubert   ui_file_put (data->buffer, do_write, stream);
3945796c8dcSSimon Schubert   ui_file_rewind (data->buffer);
3955796c8dcSSimon Schubert }
3965796c8dcSSimon Schubert 
397*ef5ccd6cSJohn Marino /* Return the current MI version.  */
3985796c8dcSSimon Schubert 
3995796c8dcSSimon Schubert int
mi_version(struct ui_out * uiout)4005796c8dcSSimon Schubert mi_version (struct ui_out *uiout)
4015796c8dcSSimon Schubert {
4025796c8dcSSimon Schubert   mi_out_data *data = ui_out_data (uiout);
403cf7f2e2dSJohn Marino 
4045796c8dcSSimon Schubert   return data->mi_version;
4055796c8dcSSimon Schubert }
4065796c8dcSSimon Schubert 
407*ef5ccd6cSJohn Marino /* Initialize private members at startup.  */
4085796c8dcSSimon Schubert 
4095796c8dcSSimon Schubert struct ui_out *
mi_out_new(int mi_version)4105796c8dcSSimon Schubert mi_out_new (int mi_version)
4115796c8dcSSimon Schubert {
4125796c8dcSSimon Schubert   int flags = 0;
413cf7f2e2dSJohn Marino 
4145796c8dcSSimon Schubert   mi_out_data *data = XMALLOC (mi_out_data);
4155796c8dcSSimon Schubert   data->suppress_field_separator = 0;
4165796c8dcSSimon Schubert   data->suppress_output = 0;
4175796c8dcSSimon Schubert   data->mi_version = mi_version;
4185796c8dcSSimon Schubert   /* FIXME: This code should be using a ``string_file'' and not the
4195796c8dcSSimon Schubert      TUI buffer hack. */
4205796c8dcSSimon Schubert   data->buffer = mem_fileopen ();
4215796c8dcSSimon Schubert   return ui_out_new (&mi_ui_out_impl, data, flags);
4225796c8dcSSimon Schubert }
423