Remove unused functions and declarations
[deliverable/binutils-gdb.git] / gdb / mi / mi-out.c
1 /* MI Command Set - output generating routines.
2
3 Copyright (C) 2000-2016 Free Software Foundation, Inc.
4
5 Contributed by Cygnus Solutions (a Red Hat company).
6
7 This file is part of GDB.
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21
22 #include "defs.h"
23 #include "ui-out.h"
24 #include "mi-out.h"
25 #include "vec.h"
26
27 typedef struct ui_file *ui_filep;
28 DEF_VEC_P (ui_filep);
29
30 struct ui_out_data
31 {
32 int suppress_field_separator;
33 int suppress_output;
34 int mi_version;
35 VEC (ui_filep) *streams;
36 };
37 typedef struct ui_out_data mi_out_data;
38
39 /* These are the MI output functions */
40
41 static void mi_out_data_dtor (struct ui_out *ui_out);
42 static void mi_table_begin (struct ui_out *uiout, int nbrofcols,
43 int nr_rows, const char *tblid);
44 static void mi_table_body (struct ui_out *uiout);
45 static void mi_table_end (struct ui_out *uiout);
46 static void mi_table_header (struct ui_out *uiout, int width,
47 enum ui_align alig, const char *col_name,
48 const char *colhdr);
49 static void mi_begin (struct ui_out *uiout, enum ui_out_type type,
50 int level, const char *id);
51 static void mi_end (struct ui_out *uiout, enum ui_out_type type, int level);
52 static void mi_field_int (struct ui_out *uiout, int fldno, int width,
53 enum ui_align alig, const char *fldname, int value);
54 static void mi_field_skip (struct ui_out *uiout, int fldno, int width,
55 enum ui_align alig, const char *fldname);
56 static void mi_field_string (struct ui_out *uiout, int fldno, int width,
57 enum ui_align alig, const char *fldname,
58 const char *string);
59 static void mi_field_fmt (struct ui_out *uiout, int fldno,
60 int width, enum ui_align align,
61 const char *fldname, const char *format,
62 va_list args) ATTRIBUTE_PRINTF (6, 0);
63 static void mi_spaces (struct ui_out *uiout, int numspaces);
64 static void mi_text (struct ui_out *uiout, const char *string);
65 static void mi_message (struct ui_out *uiout, int verbosity,
66 const char *format, va_list args)
67 ATTRIBUTE_PRINTF (3, 0);
68 static void mi_wrap_hint (struct ui_out *uiout, char *identstring);
69 static void mi_flush (struct ui_out *uiout);
70 static int mi_redirect (struct ui_out *uiout, struct ui_file *outstream);
71
72 /* This is the MI ui-out implementation functions vector */
73
74 static const struct ui_out_impl mi_ui_out_impl =
75 {
76 mi_table_begin,
77 mi_table_body,
78 mi_table_end,
79 mi_table_header,
80 mi_begin,
81 mi_end,
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 mi_redirect,
92 mi_out_data_dtor,
93 1, /* Needs MI hacks. */
94 };
95
96 /* Prototypes for local functions */
97
98 static void field_separator (struct ui_out *uiout);
99 static void mi_open (struct ui_out *uiout, const char *name,
100 enum ui_out_type type);
101 static void mi_close (struct ui_out *uiout, enum ui_out_type type);
102
103 /* Mark beginning of a table. */
104
105 void
106 mi_table_begin (struct ui_out *uiout,
107 int nr_cols,
108 int nr_rows,
109 const char *tblid)
110 {
111 mi_open (uiout, tblid, ui_out_type_tuple);
112 mi_field_int (uiout, -1, -1, ui_left, "nr_rows", nr_rows);
113 mi_field_int (uiout, -1, -1, ui_left, "nr_cols", nr_cols);
114 mi_open (uiout, "hdr", ui_out_type_list);
115 }
116
117 /* Mark beginning of a table body. */
118
119 void
120 mi_table_body (struct ui_out *uiout)
121 {
122 mi_out_data *data = (mi_out_data *) ui_out_data (uiout);
123
124 if (data->suppress_output)
125 return;
126 /* close the table header line if there were any headers */
127 mi_close (uiout, ui_out_type_list);
128 mi_open (uiout, "body", ui_out_type_list);
129 }
130
131 /* Mark end of a table. */
132
133 void
134 mi_table_end (struct ui_out *uiout)
135 {
136 mi_out_data *data = (mi_out_data *) ui_out_data (uiout);
137
138 data->suppress_output = 0;
139 mi_close (uiout, ui_out_type_list); /* body */
140 mi_close (uiout, ui_out_type_tuple);
141 }
142
143 /* Specify table header. */
144
145 void
146 mi_table_header (struct ui_out *uiout, int width, enum ui_align alignment,
147 const char *col_name, const char *colhdr)
148 {
149 mi_out_data *data = (mi_out_data *) ui_out_data (uiout);
150
151 if (data->suppress_output)
152 return;
153
154 mi_open (uiout, NULL, ui_out_type_tuple);
155 mi_field_int (uiout, 0, 0, ui_center, "width", width);
156 mi_field_int (uiout, 0, 0, ui_center, "alignment", alignment);
157 mi_field_string (uiout, 0, 0, ui_center, "col_name", col_name);
158 mi_field_string (uiout, 0, width, alignment, "colhdr", colhdr);
159 mi_close (uiout, ui_out_type_tuple);
160 }
161
162 /* Mark beginning of a list. */
163
164 void
165 mi_begin (struct ui_out *uiout, enum ui_out_type type, int level,
166 const char *id)
167 {
168 mi_out_data *data = (mi_out_data *) ui_out_data (uiout);
169
170 if (data->suppress_output)
171 return;
172
173 mi_open (uiout, id, type);
174 }
175
176 /* Mark end of a list. */
177
178 void
179 mi_end (struct ui_out *uiout, enum ui_out_type type, int level)
180 {
181 mi_out_data *data = (mi_out_data *) ui_out_data (uiout);
182
183 if (data->suppress_output)
184 return;
185
186 mi_close (uiout, type);
187 }
188
189 /* Output an int field. */
190
191 static void
192 mi_field_int (struct ui_out *uiout, int fldno, int width,
193 enum ui_align alignment, const char *fldname, int value)
194 {
195 char buffer[20]; /* FIXME: how many chars long a %d can become? */
196 mi_out_data *data = (mi_out_data *) ui_out_data (uiout);
197
198 if (data->suppress_output)
199 return;
200
201 xsnprintf (buffer, sizeof (buffer), "%d", value);
202 mi_field_string (uiout, fldno, width, alignment, fldname, buffer);
203 }
204
205 /* Used to omit a field. */
206
207 void
208 mi_field_skip (struct ui_out *uiout, int fldno, int width,
209 enum ui_align alignment, const char *fldname)
210 {
211 }
212
213 /* Other specific mi_field_* end up here so alignment and field
214 separators are both handled by mi_field_string. */
215
216 void
217 mi_field_string (struct ui_out *uiout, int fldno, int width,
218 enum ui_align align, const char *fldname, const char *string)
219 {
220 mi_out_data *data = (mi_out_data *) ui_out_data (uiout);
221 struct ui_file *stream;
222
223 if (data->suppress_output)
224 return;
225
226 stream = VEC_last (ui_filep, data->streams);
227 field_separator (uiout);
228 if (fldname)
229 fprintf_unfiltered (stream, "%s=", fldname);
230 fprintf_unfiltered (stream, "\"");
231 if (string)
232 fputstr_unfiltered (string, '"', stream);
233 fprintf_unfiltered (stream, "\"");
234 }
235
236 /* This is the only field function that does not align. */
237
238 void
239 mi_field_fmt (struct ui_out *uiout, int fldno, int width,
240 enum ui_align align, const char *fldname,
241 const char *format, va_list args)
242 {
243 mi_out_data *data = (mi_out_data *) ui_out_data (uiout);
244 struct ui_file *stream;
245
246 if (data->suppress_output)
247 return;
248
249 stream = VEC_last (ui_filep, data->streams);
250 field_separator (uiout);
251 if (fldname)
252 fprintf_unfiltered (stream, "%s=\"", fldname);
253 else
254 fputs_unfiltered ("\"", stream);
255 vfprintf_unfiltered (stream, format, args);
256 fputs_unfiltered ("\"", stream);
257 }
258
259 void
260 mi_spaces (struct ui_out *uiout, int numspaces)
261 {
262 }
263
264 void
265 mi_text (struct ui_out *uiout, const char *string)
266 {
267 }
268
269 void
270 mi_message (struct ui_out *uiout, int verbosity,
271 const char *format, va_list args)
272 {
273 }
274
275 void
276 mi_wrap_hint (struct ui_out *uiout, char *identstring)
277 {
278 wrap_here (identstring);
279 }
280
281 void
282 mi_flush (struct ui_out *uiout)
283 {
284 mi_out_data *data = (mi_out_data *) ui_out_data (uiout);
285 struct ui_file *stream = VEC_last (ui_filep, data->streams);
286
287 gdb_flush (stream);
288 }
289
290 int
291 mi_redirect (struct ui_out *uiout, struct ui_file *outstream)
292 {
293 mi_out_data *data = (mi_out_data *) ui_out_data (uiout);
294
295 if (outstream != NULL)
296 VEC_safe_push (ui_filep, data->streams, outstream);
297 else
298 VEC_pop (ui_filep, data->streams);
299
300 return 0;
301 }
302
303 /* local functions */
304
305 /* access to ui_out format private members */
306
307 static void
308 field_separator (struct ui_out *uiout)
309 {
310 mi_out_data *data = (mi_out_data *) ui_out_data (uiout);
311 struct ui_file *stream = VEC_last (ui_filep, data->streams);
312
313 if (data->suppress_field_separator)
314 data->suppress_field_separator = 0;
315 else
316 fputc_unfiltered (',', stream);
317 }
318
319 static void
320 mi_open (struct ui_out *uiout, const char *name, enum ui_out_type type)
321 {
322 mi_out_data *data = (mi_out_data *) ui_out_data (uiout);
323 struct ui_file *stream = VEC_last (ui_filep, data->streams);
324
325 field_separator (uiout);
326 data->suppress_field_separator = 1;
327 if (name)
328 fprintf_unfiltered (stream, "%s=", name);
329 switch (type)
330 {
331 case ui_out_type_tuple:
332 fputc_unfiltered ('{', stream);
333 break;
334 case ui_out_type_list:
335 fputc_unfiltered ('[', stream);
336 break;
337 default:
338 internal_error (__FILE__, __LINE__, _("bad switch"));
339 }
340 }
341
342 static void
343 mi_close (struct ui_out *uiout, enum ui_out_type type)
344 {
345 mi_out_data *data = (mi_out_data *) ui_out_data (uiout);
346 struct ui_file *stream = VEC_last (ui_filep, data->streams);
347
348 switch (type)
349 {
350 case ui_out_type_tuple:
351 fputc_unfiltered ('}', stream);
352 break;
353 case ui_out_type_list:
354 fputc_unfiltered (']', stream);
355 break;
356 default:
357 internal_error (__FILE__, __LINE__, _("bad switch"));
358 }
359 data->suppress_field_separator = 0;
360 }
361
362 /* Clear the buffer. */
363
364 void
365 mi_out_rewind (struct ui_out *uiout)
366 {
367 mi_out_data *data = (mi_out_data *) ui_out_data (uiout);
368 struct ui_file *stream = VEC_last (ui_filep, data->streams);
369
370 ui_file_rewind (stream);
371 }
372
373 /* Dump the buffer onto the specified stream. */
374
375 void
376 mi_out_put (struct ui_out *uiout, struct ui_file *stream)
377 {
378 mi_out_data *data = (mi_out_data *) ui_out_data (uiout);
379 struct ui_file *outstream = VEC_last (ui_filep, data->streams);
380
381 ui_file_put (outstream, ui_file_write_for_put, stream);
382 ui_file_rewind (outstream);
383 }
384
385 /* Return the current MI version. */
386
387 int
388 mi_version (struct ui_out *uiout)
389 {
390 mi_out_data *data = (mi_out_data *) ui_out_data (uiout);
391
392 return data->mi_version;
393 }
394
395 /* Constructor for an `mi_out_data' object. */
396
397 static void
398 mi_out_data_ctor (mi_out_data *self, int mi_version, struct ui_file *stream)
399 {
400 gdb_assert (stream != NULL);
401
402 self->streams = NULL;
403 VEC_safe_push (ui_filep, self->streams, stream);
404
405 self->suppress_field_separator = 0;
406 self->suppress_output = 0;
407 self->mi_version = mi_version;
408 }
409
410 /* The destructor. */
411
412 static void
413 mi_out_data_dtor (struct ui_out *ui_out)
414 {
415 mi_out_data *data = (mi_out_data *) ui_out_data (ui_out);
416
417 VEC_free (ui_filep, data->streams);
418 xfree (data);
419 }
420
421 /* Initialize private members at startup. */
422
423 struct ui_out *
424 mi_out_new (int mi_version)
425 {
426 int flags = 0;
427 mi_out_data *data = XNEW (mi_out_data);
428 struct ui_file *stream = mem_fileopen ();
429
430 mi_out_data_ctor (data, mi_version, stream);
431 return ui_out_new (&mi_ui_out_impl, data, flags);
432 }
This page took 0.038498 seconds and 5 git commands to generate.