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