Remove obsolete comments from field_fmt
[deliverable/binutils-gdb.git] / gdb / mi / mi-out.c
1 /* MI Command Set - output generating routines.
2
3 Copyright (C) 2000-2018 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 <vector>
26
27 /* Mark beginning of a table. */
28
29 void
30 mi_ui_out::do_table_begin (int nr_cols, int nr_rows,
31 const char *tblid)
32 {
33 open (tblid, ui_out_type_tuple);
34 do_field_int (-1, -1, ui_left, "nr_rows", nr_rows);
35 do_field_int (-1, -1, ui_left, "nr_cols", nr_cols);
36 open ("hdr", ui_out_type_list);
37 }
38
39 /* Mark beginning of a table body. */
40
41 void
42 mi_ui_out::do_table_body ()
43 {
44 /* close the table header line if there were any headers */
45 close (ui_out_type_list);
46 open ("body", ui_out_type_list);
47 }
48
49 /* Mark end of a table. */
50
51 void
52 mi_ui_out::do_table_end ()
53 {
54 close (ui_out_type_list); /* body */
55 close (ui_out_type_tuple);
56 }
57
58 /* Specify table header. */
59
60 void
61 mi_ui_out::do_table_header (int width, ui_align alignment,
62 const std::string &col_name,
63 const std::string &col_hdr)
64 {
65 open (NULL, ui_out_type_tuple);
66 do_field_int (0, 0, ui_center, "width", width);
67 do_field_int (0, 0, ui_center, "alignment", alignment);
68 do_field_string (0, 0, ui_center, "col_name", col_name.c_str ());
69 do_field_string (0, width, alignment, "colhdr", col_hdr.c_str ());
70 close (ui_out_type_tuple);
71 }
72
73 /* Mark beginning of a list. */
74
75 void
76 mi_ui_out::do_begin (ui_out_type type, const char *id)
77 {
78 open (id, type);
79 }
80
81 /* Mark end of a list. */
82
83 void
84 mi_ui_out::do_end (ui_out_type type)
85 {
86 close (type);
87 }
88
89 /* Output an int field. */
90
91 void
92 mi_ui_out::do_field_int (int fldno, int width, ui_align alignment,
93 const char *fldname, int value)
94 {
95 char buffer[20]; /* FIXME: how many chars long a %d can become? */
96
97 xsnprintf (buffer, sizeof (buffer), "%d", value);
98 do_field_string (fldno, width, alignment, fldname, buffer);
99 }
100
101 /* Used to omit a field. */
102
103 void
104 mi_ui_out::do_field_skip (int fldno, int width, ui_align alignment,
105 const char *fldname)
106 {
107 }
108
109 /* Other specific mi_field_* end up here so alignment and field
110 separators are both handled by mi_field_string. */
111
112 void
113 mi_ui_out::do_field_string (int fldno, int width, ui_align align,
114 const char *fldname, const char *string)
115 {
116 ui_file *stream = m_streams.back ();
117 field_separator ();
118
119 if (fldname)
120 fprintf_unfiltered (stream, "%s=", fldname);
121 fprintf_unfiltered (stream, "\"");
122 if (string)
123 fputstr_unfiltered (string, '"', stream);
124 fprintf_unfiltered (stream, "\"");
125 }
126
127 void
128 mi_ui_out::do_field_fmt (int fldno, int width, ui_align align,
129 const char *fldname, const char *format,
130 va_list args)
131 {
132 ui_file *stream = m_streams.back ();
133 field_separator ();
134
135 if (fldname)
136 fprintf_unfiltered (stream, "%s=\"", fldname);
137 else
138 fputs_unfiltered ("\"", stream);
139 vfprintf_unfiltered (stream, format, args);
140 fputs_unfiltered ("\"", stream);
141 }
142
143 void
144 mi_ui_out::do_spaces (int numspaces)
145 {
146 }
147
148 void
149 mi_ui_out::do_text (const char *string)
150 {
151 }
152
153 void
154 mi_ui_out::do_message (const char *format, va_list args)
155 {
156 }
157
158 void
159 mi_ui_out::do_wrap_hint (const char *identstring)
160 {
161 wrap_here (identstring);
162 }
163
164 void
165 mi_ui_out::do_flush ()
166 {
167
168 gdb_flush (m_streams.back ());
169 }
170
171 void
172 mi_ui_out::do_redirect (ui_file *outstream)
173 {
174 if (outstream != NULL)
175 m_streams.push_back (outstream);
176 else
177 m_streams.pop_back ();
178 }
179
180 void
181 mi_ui_out::field_separator ()
182 {
183 if (m_suppress_field_separator)
184 m_suppress_field_separator = false;
185 else
186 fputc_unfiltered (',', m_streams.back ());
187 }
188
189 void
190 mi_ui_out::open (const char *name, ui_out_type type)
191 {
192 ui_file *stream = m_streams.back ();
193
194 field_separator ();
195 m_suppress_field_separator = true;
196
197 if (name)
198 fprintf_unfiltered (stream, "%s=", name);
199
200 switch (type)
201 {
202 case ui_out_type_tuple:
203 fputc_unfiltered ('{', stream);
204 break;
205
206 case ui_out_type_list:
207 fputc_unfiltered ('[', stream);
208 break;
209
210 default:
211 internal_error (__FILE__, __LINE__, _("bad switch"));
212 }
213 }
214
215 void
216 mi_ui_out::close (ui_out_type type)
217 {
218 ui_file *stream = m_streams.back ();
219
220 switch (type)
221 {
222 case ui_out_type_tuple:
223 fputc_unfiltered ('}', stream);
224 break;
225
226 case ui_out_type_list:
227 fputc_unfiltered (']', stream);
228 break;
229
230 default:
231 internal_error (__FILE__, __LINE__, _("bad switch"));
232 }
233
234 m_suppress_field_separator = false;
235 }
236
237 string_file *
238 mi_ui_out::main_stream ()
239 {
240 gdb_assert (m_streams.size () == 1);
241
242 return (string_file *) m_streams.back ();
243 }
244
245 /* Clear the buffer. */
246
247 void
248 mi_ui_out::rewind ()
249 {
250 main_stream ()->clear ();
251 }
252
253 /* Dump the buffer onto the specified stream. */
254
255 void
256 mi_ui_out::put (ui_file *where)
257 {
258 string_file *mi_stream = main_stream ();
259
260 where->write (mi_stream->data (), mi_stream->size ());
261 mi_stream->clear ();
262 }
263
264 /* Return the current MI version. */
265
266 int
267 mi_ui_out::version ()
268 {
269 return m_mi_version;
270 }
271
272 /* Constructor for an `mi_out_data' object. */
273
274 mi_ui_out::mi_ui_out (int mi_version)
275 : m_suppress_field_separator (false),
276 m_suppress_output (false),
277 m_mi_version (mi_version)
278 {
279 string_file *stream = new string_file ();
280 m_streams.push_back (stream);
281 }
282
283 mi_ui_out::~mi_ui_out ()
284 {
285 }
286
287 /* Initialize private members at startup. */
288
289 mi_ui_out *
290 mi_out_new (int mi_version)
291 {
292 return new mi_ui_out (mi_version);
293 }
294
295 /* Helper function to return the given UIOUT as an mi_ui_out. It is an error
296 to call this function with an ui_out that is not an MI. */
297
298 static mi_ui_out *
299 as_mi_ui_out (ui_out *uiout)
300 {
301 mi_ui_out *mi_uiout = dynamic_cast<mi_ui_out *> (uiout);
302
303 gdb_assert (mi_uiout != NULL);
304
305 return mi_uiout;
306 }
307
308 int
309 mi_version (ui_out *uiout)
310 {
311 return as_mi_ui_out (uiout)->version ();
312 }
313
314 void
315 mi_out_put (ui_out *uiout, struct ui_file *stream)
316 {
317 return as_mi_ui_out (uiout)->put (stream);
318 }
319
320 void
321 mi_out_rewind (ui_out *uiout)
322 {
323 return as_mi_ui_out (uiout)->rewind ();
324 }
This page took 0.053723 seconds and 5 git commands to generate.