1 /* MI Command Set - output generating routines.
2 Copyright (C) 2000, Free Software Foundation, Inc.
3 Contributed by Cygnus Solutions (a Red Hat company).
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
26 /* Convenience macro for allocting typesafe memory. */
29 #define XMALLOC(TYPE) (TYPE*) xmalloc (sizeof (TYPE))
34 int supress_field_separator
;
36 struct ui_file
*buffer
;
39 /* These are the MI output functions */
41 static void mi_table_begin (struct ui_out
*uiout
, int nbrofcols
, char *tblid
);
42 static void mi_table_body (struct ui_out
*uiout
);
43 static void mi_table_end (struct ui_out
*uiout
);
44 static void mi_table_header (struct ui_out
*uiout
, int width
,
45 enum ui_align alig
, char *colhdr
);
46 static void mi_list_begin (struct ui_out
*uiout
, int list_flag
, char *lstid
);
47 static void mi_list_end (struct ui_out
*uiout
, int list_flag
);
48 static void mi_field_int (struct ui_out
*uiout
, int fldno
, int width
,
49 enum ui_align alig
, char *fldname
, int value
);
50 static void mi_field_skip (struct ui_out
*uiout
, int fldno
, int width
,
51 enum ui_align alig
, char *fldname
);
52 static void mi_field_string (struct ui_out
*uiout
, int fldno
, int width
,
53 enum ui_align alig
, char *fldname
,
55 static void mi_field_fmt (struct ui_out
*uiout
, int fldno
,
56 int width
, enum ui_align align
,
57 char *fldname
, char *format
, va_list args
);
58 static void mi_spaces (struct ui_out
*uiout
, int numspaces
);
59 static void mi_text (struct ui_out
*uiout
, char *string
);
60 static void mi_message (struct ui_out
*uiout
, int verbosity
, char *format
,
62 static void mi_wrap_hint (struct ui_out
*uiout
, char *identstring
);
63 static void mi_flush (struct ui_out
*uiout
);
65 /* This is the MI ui-out implementation functions vector */
67 /* FIXME: This can be initialized dynamically after default is set to
68 handle initial output in main.c */
70 struct ui_out_impl mi_ui_out_impl
=
89 /* Prototypes for local functions */
91 extern void _initialize_mi_out (void);
92 static void field_separator (struct ui_out
*uiout
);
93 static void list_open (struct ui_out
*uiout
);
94 static void list_close (struct ui_out
*uiout
);
96 static void out_field_fmt (struct ui_out
*uiout
, int fldno
, char *fldname
,
99 /* Mark beginning of a table */
102 mi_table_begin (uiout
, nbrofcols
, tblid
)
103 struct ui_out
*uiout
;
107 struct ui_out_data
*data
= ui_out_data (uiout
);
108 field_separator (uiout
);
110 fprintf_unfiltered (data
->buffer
, "%s=", tblid
);
112 data
->first_header
= 0;
113 data
->supress_field_separator
= 1;
116 /* Mark beginning of a table body */
119 mi_table_body (uiout
)
120 struct ui_out
*uiout
;
122 struct ui_out_data
*data
= ui_out_data (uiout
);
123 /* close the table header line if there were any headers */
124 if (data
->first_header
)
128 /* Mark end of a table */
132 struct ui_out
*uiout
;
134 struct ui_out_data
*data
= ui_out_data (uiout
);
136 /* If table was empty this flag did not get reset yet */
137 data
->supress_field_separator
= 0;
140 /* Specify table header */
143 mi_table_header (uiout
, width
, alignment
, colhdr
)
144 struct ui_out
*uiout
;
149 struct ui_out_data
*data
= ui_out_data (uiout
);
150 if (!data
->first_header
++)
152 fputs_unfiltered ("hdr=", data
->buffer
);
155 mi_field_string (uiout
, 0, width
, alignment
, 0, colhdr
);
158 /* Mark beginning of a list */
161 mi_list_begin (uiout
, list_flag
, lstid
)
162 struct ui_out
*uiout
;
166 struct ui_out_data
*data
= ui_out_data (uiout
);
167 field_separator (uiout
);
168 data
->supress_field_separator
= 1;
170 fprintf_unfiltered (data
->buffer
, "%s=", lstid
);
174 /* Mark end of a list */
177 mi_list_end (uiout
, list_flag
)
178 struct ui_out
*uiout
;
181 struct ui_out_data
*data
= ui_out_data (uiout
);
183 /* If list was empty this flag did not get reset yet */
184 data
->supress_field_separator
= 0;
187 /* output an int field */
190 mi_field_int (uiout
, fldno
, width
, alignment
, fldname
, value
)
191 struct ui_out
*uiout
;
198 char buffer
[20]; /* FIXME: how many chars long a %d can become? */
200 sprintf (buffer
, "%d", value
);
201 mi_field_string (uiout
, fldno
, width
, alignment
, fldname
, buffer
);
204 /* used to ommit a field */
207 mi_field_skip (uiout
, fldno
, width
, alignment
, fldname
)
208 struct ui_out
*uiout
;
214 mi_field_string (uiout
, fldno
, width
, alignment
, fldname
, "");
217 /* other specific mi_field_* end up here so alignment and field
218 separators are both handled by mi_field_string */
221 mi_field_string (struct ui_out
*uiout
,
228 struct ui_out_data
*data
= ui_out_data (uiout
);
229 field_separator (uiout
);
231 fprintf_unfiltered (data
->buffer
, "%s=", fldname
);
232 fprintf_unfiltered (data
->buffer
, "\"");
234 fputstr_unfiltered (string
, '"', data
->buffer
);
235 fprintf_unfiltered (data
->buffer
, "\"");
238 /* This is the only field function that does not align */
241 mi_field_fmt (struct ui_out
*uiout
, int fldno
,
242 int width
, enum ui_align align
,
243 char *fldname
, char *format
, va_list args
)
245 struct ui_out_data
*data
= ui_out_data (uiout
);
246 field_separator (uiout
);
248 fprintf_unfiltered (data
->buffer
, "%s=\"", fldname
);
250 fputs_unfiltered ("\"", data
->buffer
);
251 vfprintf_unfiltered (data
->buffer
, format
, args
);
252 fputs_unfiltered ("\"", data
->buffer
);
256 mi_spaces (uiout
, numspaces
)
257 struct ui_out
*uiout
;
263 mi_text (uiout
, string
)
264 struct ui_out
*uiout
;
270 mi_message (struct ui_out
*uiout
, int verbosity
, char *format
, va_list args
)
275 mi_wrap_hint (uiout
, identstring
)
276 struct ui_out
*uiout
;
279 wrap_here (identstring
);
284 struct ui_out
*uiout
;
286 struct ui_out_data
*data
= ui_out_data (uiout
);
287 gdb_flush (data
->buffer
);
290 /* local functions */
292 /* Like mi_field_fmt, but takes a variable number of args
293 and makes a va_list and does not insert a separator */
297 out_field_fmt (struct ui_out
*uiout
, int fldno
, char *fldname
,
300 struct ui_out_data
*data
= ui_out_data (uiout
);
303 field_separator (uiout
);
305 fprintf_unfiltered (data
->buffer
, "%s=\"", fldname
);
307 fputs_unfiltered ("\"", data
->buffer
);
309 va_start (args
, format
);
310 vfprintf_unfiltered (data
->buffer
, format
, args
);
312 fputs_unfiltered ("\"", data
->buffer
);
317 /* access to ui_out format private members */
320 field_separator (struct ui_out
*uiout
)
322 struct ui_out_data
*data
= ui_out_data (uiout
);
323 if (data
->supress_field_separator
)
324 data
->supress_field_separator
= 0;
326 fputc_unfiltered (',', data
->buffer
);
330 list_open (struct ui_out
*uiout
)
332 struct ui_out_data
*data
= ui_out_data (uiout
);
333 fputc_unfiltered ('{', data
->buffer
);
337 list_close (struct ui_out
*uiout
)
339 struct ui_out_data
*data
= ui_out_data (uiout
);
340 fputc_unfiltered ('}', data
->buffer
);
343 /* add a string to the buffer */
346 mi_out_buffered (struct ui_out
*uiout
, char *string
)
348 struct ui_out_data
*data
= ui_out_data (uiout
);
349 fprintf_unfiltered (data
->buffer
, "%s", string
);
352 /* clear the buffer */
355 mi_out_rewind (struct ui_out
*uiout
)
357 struct ui_out_data
*data
= ui_out_data (uiout
);
358 ui_file_rewind (data
->buffer
);
361 /* dump the buffer onto the specified stream */
364 do_write (void *data
, const char *buffer
, long length_buffer
)
366 ui_file_write (data
, buffer
, length_buffer
);
370 mi_out_put (struct ui_out
*uiout
,
371 struct ui_file
*stream
)
373 struct ui_out_data
*data
= ui_out_data (uiout
);
374 ui_file_put (data
->buffer
, do_write
, stream
);
375 ui_file_rewind (data
->buffer
);
378 /* initalize private members at startup */
384 struct ui_out_data
*data
= XMALLOC (struct ui_out_data
);
385 data
->supress_field_separator
= 0;
386 /* FIXME: This code should be using a ``string_file'' and not the
388 data
->buffer
= mem_fileopen ();
389 return ui_out_new (&mi_ui_out_impl
, data
, flags
);
392 /* standard gdb initialization hook */
394 _initialize_mi_out ()
396 /* nothing happens here */