Oops. Clean up changelog entry.
[deliverable/binutils-gdb.git] / gdb / mi / mi-out.c
CommitLineData
fb40c209 1/* MI Command Set - output generating routines.
b6ba6518 2 Copyright 2000 Free Software Foundation, Inc.
ab91fdd5 3 Contributed by Cygnus Solutions (a Red Hat company).
fb40c209
AC
4
5 This file is part of GDB.
6
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.
11
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.
16
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. */
21
22#include "defs.h"
23#include "ui-out.h"
24#include "mi-out.h"
25
26/* Convenience macro for allocting typesafe memory. */
27
28#ifndef XMALLOC
29#define XMALLOC(TYPE) (TYPE*) xmalloc (sizeof (TYPE))
30#endif
31
32struct ui_out_data
33 {
34 int supress_field_separator;
35 int first_header;
36 struct ui_file *buffer;
37 };
38
39/* These are the MI output functions */
40
e2e11a41
AC
41static void mi_table_begin (struct ui_out *uiout, int nbrofcols,
42 const char *tblid);
fb40c209
AC
43static void mi_table_body (struct ui_out *uiout);
44static void mi_table_end (struct ui_out *uiout);
45static void mi_table_header (struct ui_out *uiout, int width,
e2e11a41
AC
46 enum ui_align alig,
47 const char *colhdr);
631ec795
AC
48static void mi_begin (struct ui_out *uiout, enum ui_out_type type,
49 int level, const char *id);
50static void mi_end (struct ui_out *uiout, enum ui_out_type type, int level);
fb40c209 51static void mi_field_int (struct ui_out *uiout, int fldno, int width,
e2e11a41 52 enum ui_align alig, const char *fldname, int value);
fb40c209 53static void mi_field_skip (struct ui_out *uiout, int fldno, int width,
e2e11a41 54 enum ui_align alig, const char *fldname);
fb40c209 55static void mi_field_string (struct ui_out *uiout, int fldno, int width,
e2e11a41 56 enum ui_align alig, const char *fldname,
fb40c209
AC
57 const char *string);
58static void mi_field_fmt (struct ui_out *uiout, int fldno,
59 int width, enum ui_align align,
e2e11a41
AC
60 const char *fldname, const char *format,
61 va_list args);
fb40c209 62static void mi_spaces (struct ui_out *uiout, int numspaces);
e2e11a41
AC
63static void mi_text (struct ui_out *uiout, const char *string);
64static void mi_message (struct ui_out *uiout, int verbosity,
65 const char *format, va_list args);
fb40c209
AC
66static void mi_wrap_hint (struct ui_out *uiout, char *identstring);
67static void mi_flush (struct ui_out *uiout);
68
69/* This is the MI ui-out implementation functions vector */
70
71/* FIXME: This can be initialized dynamically after default is set to
72 handle initial output in main.c */
73
74struct ui_out_impl mi_ui_out_impl =
75{
76 mi_table_begin,
77 mi_table_body,
78 mi_table_end,
79 mi_table_header,
631ec795
AC
80 mi_begin,
81 mi_end,
fb40c209
AC
82 mi_field_int,
83 mi_field_skip,
84 mi_field_string,
85 mi_field_fmt,
86 mi_spaces,
87 mi_text,
88 mi_message,
89 mi_wrap_hint,
90 mi_flush
91};
92
93/* Prototypes for local functions */
94
a14ed312 95extern void _initialize_mi_out (void);
fb40c209 96static void field_separator (struct ui_out *uiout);
9a0f0643
AC
97static void mi_open (struct ui_out *uiout, enum ui_out_type type);
98static void mi_close (struct ui_out *uiout, enum ui_out_type type);
fb40c209
AC
99
100static void out_field_fmt (struct ui_out *uiout, int fldno, char *fldname,
101 char *format,...);
102
103/* Mark beginning of a table */
104
105void
e2e11a41
AC
106mi_table_begin (struct ui_out *uiout, int nbrofcols,
107 const char *tblid)
fb40c209
AC
108{
109 struct ui_out_data *data = ui_out_data (uiout);
110 field_separator (uiout);
111 if (tblid)
112 fprintf_unfiltered (data->buffer, "%s=", tblid);
666547aa 113 mi_open (uiout, ui_out_type_tuple);
fb40c209
AC
114 data->first_header = 0;
115 data->supress_field_separator = 1;
116}
117
118/* Mark beginning of a table body */
119
120void
fba45db2 121mi_table_body (struct ui_out *uiout)
fb40c209
AC
122{
123 struct ui_out_data *data = ui_out_data (uiout);
124 /* close the table header line if there were any headers */
125 if (data->first_header)
666547aa 126 mi_close (uiout, ui_out_type_tuple);
fb40c209
AC
127}
128
129/* Mark end of a table */
130
131void
fba45db2 132mi_table_end (struct ui_out *uiout)
fb40c209
AC
133{
134 struct ui_out_data *data = ui_out_data (uiout);
666547aa 135 mi_close (uiout, ui_out_type_tuple);
fb40c209
AC
136 /* If table was empty this flag did not get reset yet */
137 data->supress_field_separator = 0;
138}
139
140/* Specify table header */
141
142void
e2e11a41
AC
143mi_table_header (struct ui_out *uiout, int width, int alignment,
144 const char *colhdr)
fb40c209
AC
145{
146 struct ui_out_data *data = ui_out_data (uiout);
147 if (!data->first_header++)
148 {
149 fputs_unfiltered ("hdr=", data->buffer);
666547aa 150 mi_open (uiout, ui_out_type_tuple);
fb40c209
AC
151 }
152 mi_field_string (uiout, 0, width, alignment, 0, colhdr);
153}
154
155/* Mark beginning of a list */
156
157void
631ec795
AC
158mi_begin (struct ui_out *uiout,
159 enum ui_out_type type,
160 int level,
9a0f0643 161 const char *id)
fb40c209
AC
162{
163 struct ui_out_data *data = ui_out_data (uiout);
164 field_separator (uiout);
165 data->supress_field_separator = 1;
9a0f0643
AC
166 if (id)
167 fprintf_unfiltered (data->buffer, "%s=", id);
168 mi_open (uiout, type);
fb40c209
AC
169}
170
171/* Mark end of a list */
172
173void
631ec795
AC
174mi_end (struct ui_out *uiout,
175 enum ui_out_type type,
176 int level)
fb40c209
AC
177{
178 struct ui_out_data *data = ui_out_data (uiout);
9a0f0643 179 mi_close (uiout, type);
fb40c209
AC
180 /* If list was empty this flag did not get reset yet */
181 data->supress_field_separator = 0;
182}
183
184/* output an int field */
185
186void
fba45db2 187mi_field_int (struct ui_out *uiout, int fldno, int width, int alignment,
e2e11a41 188 const char *fldname, int value)
fb40c209
AC
189{
190 char buffer[20]; /* FIXME: how many chars long a %d can become? */
191
192 sprintf (buffer, "%d", value);
193 mi_field_string (uiout, fldno, width, alignment, fldname, buffer);
194}
195
196/* used to ommit a field */
197
198void
fba45db2 199mi_field_skip (struct ui_out *uiout, int fldno, int width, int alignment,
e2e11a41 200 const char *fldname)
fb40c209
AC
201{
202 mi_field_string (uiout, fldno, width, alignment, fldname, "");
203}
204
205/* other specific mi_field_* end up here so alignment and field
206 separators are both handled by mi_field_string */
207
208void
209mi_field_string (struct ui_out *uiout,
210 int fldno,
211 int width,
212 int align,
e2e11a41 213 const char *fldname,
fb40c209
AC
214 const char *string)
215{
216 struct ui_out_data *data = ui_out_data (uiout);
217 field_separator (uiout);
218 if (fldname)
219 fprintf_unfiltered (data->buffer, "%s=", fldname);
220 fprintf_unfiltered (data->buffer, "\"");
221 if (string)
222 fputstr_unfiltered (string, '"', data->buffer);
223 fprintf_unfiltered (data->buffer, "\"");
224}
225
226/* This is the only field function that does not align */
227
228void
229mi_field_fmt (struct ui_out *uiout, int fldno,
230 int width, enum ui_align align,
e2e11a41
AC
231 const char *fldname,
232 const char *format,
233 va_list args)
fb40c209
AC
234{
235 struct ui_out_data *data = ui_out_data (uiout);
236 field_separator (uiout);
237 if (fldname)
238 fprintf_unfiltered (data->buffer, "%s=\"", fldname);
239 else
240 fputs_unfiltered ("\"", data->buffer);
241 vfprintf_unfiltered (data->buffer, format, args);
242 fputs_unfiltered ("\"", data->buffer);
243}
244
245void
fba45db2 246mi_spaces (struct ui_out *uiout, int numspaces)
fb40c209
AC
247{
248}
249
250void
e2e11a41 251mi_text (struct ui_out *uiout, const char *string)
fb40c209
AC
252{
253}
254
255void
e2e11a41
AC
256mi_message (struct ui_out *uiout, int verbosity,
257 const char *format,
258 va_list args)
fb40c209
AC
259{
260}
261
262void
fba45db2 263mi_wrap_hint (struct ui_out *uiout, char *identstring)
fb40c209
AC
264{
265 wrap_here (identstring);
266}
267
268void
fba45db2 269mi_flush (struct ui_out *uiout)
fb40c209
AC
270{
271 struct ui_out_data *data = ui_out_data (uiout);
272 gdb_flush (data->buffer);
273}
274
275/* local functions */
276
277/* Like mi_field_fmt, but takes a variable number of args
278 and makes a va_list and does not insert a separator */
279
280/* VARARGS */
281static void
282out_field_fmt (struct ui_out *uiout, int fldno, char *fldname,
283 char *format,...)
284{
285 struct ui_out_data *data = ui_out_data (uiout);
286 va_list args;
287
288 field_separator (uiout);
289 if (fldname)
290 fprintf_unfiltered (data->buffer, "%s=\"", fldname);
291 else
292 fputs_unfiltered ("\"", data->buffer);
293
294 va_start (args, format);
295 vfprintf_unfiltered (data->buffer, format, args);
296
297 fputs_unfiltered ("\"", data->buffer);
298
299 va_end (args);
300}
301
302/* access to ui_out format private members */
303
304static void
305field_separator (struct ui_out *uiout)
306{
307 struct ui_out_data *data = ui_out_data (uiout);
308 if (data->supress_field_separator)
309 data->supress_field_separator = 0;
310 else
311 fputc_unfiltered (',', data->buffer);
312}
313
314static void
9a0f0643
AC
315mi_open (struct ui_out *uiout,
316 enum ui_out_type type)
fb40c209
AC
317{
318 struct ui_out_data *data = ui_out_data (uiout);
5a9aa5dc
AC
319 switch (type)
320 {
321 case ui_out_type_tuple:
322 fputc_unfiltered ('{', data->buffer);
323 break;
324 case ui_out_type_list:
325 fputc_unfiltered ('[', data->buffer);
326 break;
327 default:
328 internal_error (__FILE__, __LINE__, "bad switch");
329 }
fb40c209
AC
330}
331
332static void
9a0f0643
AC
333mi_close (struct ui_out *uiout,
334 enum ui_out_type type)
fb40c209
AC
335{
336 struct ui_out_data *data = ui_out_data (uiout);
5a9aa5dc
AC
337 switch (type)
338 {
339 case ui_out_type_tuple:
340 fputc_unfiltered ('}', data->buffer);
341 break;
342 case ui_out_type_list:
343 fputc_unfiltered (']', data->buffer);
344 break;
345 default:
346 internal_error (__FILE__, __LINE__, "bad switch");
347 }
fb40c209
AC
348}
349
350/* add a string to the buffer */
351
352void
353mi_out_buffered (struct ui_out *uiout, char *string)
354{
355 struct ui_out_data *data = ui_out_data (uiout);
356 fprintf_unfiltered (data->buffer, "%s", string);
357}
358
359/* clear the buffer */
360
361void
362mi_out_rewind (struct ui_out *uiout)
363{
364 struct ui_out_data *data = ui_out_data (uiout);
365 ui_file_rewind (data->buffer);
366}
367
368/* dump the buffer onto the specified stream */
369
370static void
371do_write (void *data, const char *buffer, long length_buffer)
372{
373 ui_file_write (data, buffer, length_buffer);
374}
375
376void
377mi_out_put (struct ui_out *uiout,
378 struct ui_file *stream)
379{
380 struct ui_out_data *data = ui_out_data (uiout);
381 ui_file_put (data->buffer, do_write, stream);
382 ui_file_rewind (data->buffer);
383}
384
385/* initalize private members at startup */
386
387struct ui_out *
388mi_out_new (void)
389{
390 int flags = 0;
391 struct ui_out_data *data = XMALLOC (struct ui_out_data);
392 data->supress_field_separator = 0;
393 /* FIXME: This code should be using a ``string_file'' and not the
394 TUI buffer hack. */
395 data->buffer = mem_fileopen ();
396 return ui_out_new (&mi_ui_out_impl, data, flags);
397}
398
399/* standard gdb initialization hook */
400void
fba45db2 401_initialize_mi_out (void)
fb40c209
AC
402{
403 /* nothing happens here */
404}
This page took 0.104982 seconds and 4 git commands to generate.