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