Commit | Line | Data |
---|---|---|
8b93c638 | 1 | /* Output generating routines for GDB. |
349c5d5f | 2 | |
618f726f | 3 | Copyright (C) 1999-2016 Free Software Foundation, Inc. |
349c5d5f | 4 | |
8b93c638 JM |
5 | Contributed by Cygnus Solutions. |
6 | Written by Fernando Nasser for Cygnus. | |
7 | ||
8 | This file is part of GDB. | |
9 | ||
10 | This program is free software; you can redistribute it and/or modify | |
11 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 12 | the Free Software Foundation; either version 3 of the License, or |
8b93c638 JM |
13 | (at your option) any later version. |
14 | ||
15 | This program is distributed in the hope that it will be useful, | |
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | GNU General Public License for more details. | |
19 | ||
20 | You should have received a copy of the GNU General Public License | |
a9762ec7 | 21 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
8b93c638 JM |
22 | |
23 | #include "defs.h" | |
8b93c638 JM |
24 | #include "expression.h" /* For language.h */ |
25 | #include "language.h" | |
26 | #include "ui-out.h" | |
27 | ||
8b93c638 JM |
28 | /* table header structures */ |
29 | ||
30 | struct ui_out_hdr | |
31 | { | |
32 | int colno; | |
33 | int width; | |
f486487f | 34 | enum ui_align alignment; |
b25959ec | 35 | char *col_name; |
8b93c638 JM |
36 | char *colhdr; |
37 | struct ui_out_hdr *next; | |
38 | }; | |
39 | ||
80f49b30 AC |
40 | struct ui_out_level |
41 | { | |
581e13c1 | 42 | /* Count each field; the first element is for non-list fields. */ |
80f49b30 | 43 | int field_count; |
581e13c1 | 44 | /* The type of this level. */ |
631ec795 | 45 | enum ui_out_type type; |
80f49b30 AC |
46 | }; |
47 | ||
54eb231c PM |
48 | /* Define uiout->level vector types and operations. */ |
49 | typedef struct ui_out_level *ui_out_level_p; | |
50 | DEF_VEC_P (ui_out_level_p); | |
51 | ||
bafdd3b3 AC |
52 | /* Tables are special. Maintain a separate structure that tracks |
53 | their state. At present an output can only contain a single table | |
54 | but that restriction might eventually be lifted. */ | |
55 | ||
56 | struct ui_out_table | |
57 | { | |
58 | /* If on, a table is being generated. */ | |
59 | int flag; | |
60 | ||
61 | /* If on, the body of a table is being generated. If off, the table | |
62 | header is being generated. */ | |
63 | int body_flag; | |
64 | ||
a6c47c14 AC |
65 | /* The level at which each entry of the table is to be found. A row |
66 | (a tuple) is made up of entries. Consequently ENTRY_LEVEL is one | |
67 | above that of the table. */ | |
68 | int entry_level; | |
69 | ||
bafdd3b3 AC |
70 | /* Number of table columns (as specified in the table_begin call). */ |
71 | int columns; | |
72 | ||
73 | /* String identifying the table (as specified in the table_begin | |
74 | call). */ | |
75 | char *id; | |
76 | ||
77 | /* Points to the first table header (if any). */ | |
78 | struct ui_out_hdr *header_first; | |
79 | ||
80 | /* Points to the last table header (if any). */ | |
81 | struct ui_out_hdr *header_last; | |
82 | ||
83 | /* Points to header of NEXT column to format. */ | |
84 | struct ui_out_hdr *header_next; | |
85 | ||
86 | }; | |
87 | ||
88 | ||
8b93c638 | 89 | /* The ui_out structure */ |
8b93c638 JM |
90 | |
91 | struct ui_out | |
92 | { | |
93 | int flags; | |
581e13c1 | 94 | /* Specific implementation of ui-out. */ |
89de4da4 | 95 | const struct ui_out_impl *impl; |
0a8fce9a | 96 | void *data; |
8b93c638 | 97 | |
54eb231c | 98 | /* Current level. */ |
80f49b30 | 99 | int level; |
54eb231c PM |
100 | |
101 | /* Vector to store and track the ui-out levels. */ | |
102 | VEC (ui_out_level_p) *levels; | |
8b93c638 | 103 | |
bafdd3b3 AC |
104 | /* A table, if any. At present only a single table is supported. */ |
105 | struct ui_out_table table; | |
8b93c638 JM |
106 | }; |
107 | ||
581e13c1 | 108 | /* The current (inner most) level. */ |
80f49b30 AC |
109 | static struct ui_out_level * |
110 | current_level (struct ui_out *uiout) | |
111 | { | |
54eb231c | 112 | return VEC_index (ui_out_level_p, uiout->levels, uiout->level); |
80f49b30 AC |
113 | } |
114 | ||
581e13c1 | 115 | /* Create a new level, of TYPE. Return the new level's index. */ |
80f49b30 AC |
116 | static int |
117 | push_level (struct ui_out *uiout, | |
49d06418 | 118 | enum ui_out_type type) |
80f49b30 AC |
119 | { |
120 | struct ui_out_level *current; | |
5d502164 | 121 | |
80f49b30 | 122 | uiout->level++; |
70ba0933 | 123 | current = XNEW (struct ui_out_level); |
80f49b30 | 124 | current->field_count = 0; |
631ec795 | 125 | current->type = type; |
54eb231c | 126 | VEC_safe_push (ui_out_level_p, uiout->levels, current); |
80f49b30 AC |
127 | return uiout->level; |
128 | } | |
129 | ||
130 | /* Discard the current level, return the discarded level's index. | |
581e13c1 | 131 | TYPE is the type of the level being discarded. */ |
80f49b30 | 132 | static int |
631ec795 AC |
133 | pop_level (struct ui_out *uiout, |
134 | enum ui_out_type type) | |
80f49b30 | 135 | { |
54eb231c PM |
136 | struct ui_out_level *current; |
137 | ||
581e13c1 | 138 | /* We had better not underflow the buffer. */ |
54eb231c | 139 | gdb_assert (uiout->level > 0); |
631ec795 | 140 | gdb_assert (current_level (uiout)->type == type); |
54eb231c PM |
141 | current = VEC_pop (ui_out_level_p, uiout->levels); |
142 | xfree (current); | |
80f49b30 AC |
143 | uiout->level--; |
144 | return uiout->level + 1; | |
145 | } | |
146 | ||
581e13c1 | 147 | /* These are the interfaces to implementation functions. */ |
8b93c638 | 148 | |
88379baf | 149 | static void uo_table_begin (struct ui_out *uiout, int nbrofcols, |
d63f1d40 | 150 | int nr_rows, const char *tblid); |
8b93c638 JM |
151 | static void uo_table_body (struct ui_out *uiout); |
152 | static void uo_table_end (struct ui_out *uiout); | |
153 | static void uo_table_header (struct ui_out *uiout, int width, | |
b25959ec AC |
154 | enum ui_align align, const char *col_name, |
155 | const char *colhdr); | |
631ec795 AC |
156 | static void uo_begin (struct ui_out *uiout, |
157 | enum ui_out_type type, | |
158 | int level, const char *id); | |
159 | static void uo_end (struct ui_out *uiout, | |
160 | enum ui_out_type type, | |
161 | int level); | |
8b93c638 | 162 | static void uo_field_int (struct ui_out *uiout, int fldno, int width, |
88379baf | 163 | enum ui_align align, const char *fldname, int value); |
8b93c638 | 164 | static void uo_field_skip (struct ui_out *uiout, int fldno, int width, |
88379baf | 165 | enum ui_align align, const char *fldname); |
8b93c638 | 166 | static void uo_field_fmt (struct ui_out *uiout, int fldno, int width, |
88379baf | 167 | enum ui_align align, const char *fldname, |
bee0189a | 168 | const char *format, va_list args) |
a0b31db1 | 169 | ATTRIBUTE_PRINTF (6, 0); |
8b93c638 | 170 | static void uo_spaces (struct ui_out *uiout, int numspaces); |
88379baf | 171 | static void uo_text (struct ui_out *uiout, const char *string); |
8b93c638 | 172 | static void uo_message (struct ui_out *uiout, int verbosity, |
bee0189a | 173 | const char *format, va_list args) |
a0b31db1 | 174 | ATTRIBUTE_PRINTF (3, 0); |
d2c0eef4 | 175 | static void uo_wrap_hint (struct ui_out *uiout, const char *identstring); |
8b93c638 | 176 | static void uo_flush (struct ui_out *uiout); |
0fac0b41 | 177 | static int uo_redirect (struct ui_out *uiout, struct ui_file *outstream); |
8b93c638 JM |
178 | |
179 | /* Prototypes for local functions */ | |
180 | ||
88379baf | 181 | static void append_header_to_list (struct ui_out *uiout, int width, |
f486487f | 182 | enum ui_align alignment, const char *col_name, |
b25959ec | 183 | const char *colhdr); |
bafdd3b3 | 184 | static int get_next_header (struct ui_out *uiout, int *colno, int *width, |
f486487f | 185 | enum ui_align *alignment, char **colhdr); |
8b93c638 | 186 | static void clear_header_list (struct ui_out *uiout); |
b65a2bd9 | 187 | static void clear_table (struct ui_out *uiout); |
a6c47c14 | 188 | static void verify_field (struct ui_out *uiout, int *fldno, int *width, |
f486487f | 189 | enum ui_align *align); |
8b93c638 | 190 | |
8b93c638 JM |
191 | /* exported functions (ui_out API) */ |
192 | ||
581e13c1 | 193 | /* Mark beginning of a table. */ |
8b93c638 | 194 | |
3b31d625 | 195 | static void |
88379baf | 196 | ui_out_table_begin (struct ui_out *uiout, int nbrofcols, |
d63f1d40 | 197 | int nr_rows, |
88379baf | 198 | const char *tblid) |
8b93c638 | 199 | { |
bafdd3b3 | 200 | if (uiout->table.flag) |
8e65ff28 | 201 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 AC |
202 | _("tables cannot be nested; table_begin found before \ |
203 | previous table_end.")); | |
8b93c638 | 204 | |
bafdd3b3 AC |
205 | uiout->table.flag = 1; |
206 | uiout->table.body_flag = 0; | |
a6c47c14 | 207 | uiout->table.entry_level = uiout->level + 1; |
bafdd3b3 | 208 | uiout->table.columns = nbrofcols; |
8b93c638 | 209 | if (tblid != NULL) |
bafdd3b3 | 210 | uiout->table.id = xstrdup (tblid); |
8b93c638 | 211 | else |
bafdd3b3 | 212 | uiout->table.id = NULL; |
8b93c638 JM |
213 | clear_header_list (uiout); |
214 | ||
bafdd3b3 | 215 | uo_table_begin (uiout, nbrofcols, nr_rows, uiout->table.id); |
8b93c638 JM |
216 | } |
217 | ||
218 | void | |
fba45db2 | 219 | ui_out_table_body (struct ui_out *uiout) |
8b93c638 | 220 | { |
bafdd3b3 | 221 | if (!uiout->table.flag) |
8e65ff28 | 222 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 AC |
223 | _("table_body outside a table is not valid; it must be \ |
224 | after a table_begin and before a table_end.")); | |
bafdd3b3 | 225 | if (uiout->table.body_flag) |
8e65ff28 | 226 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 AC |
227 | _("extra table_body call not allowed; there must be \ |
228 | only one table_body after a table_begin and before a table_end.")); | |
bafdd3b3 | 229 | if (uiout->table.header_next->colno != uiout->table.columns) |
8e65ff28 | 230 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 AC |
231 | _("number of headers differ from number of table \ |
232 | columns.")); | |
8b93c638 | 233 | |
bafdd3b3 AC |
234 | uiout->table.body_flag = 1; |
235 | uiout->table.header_next = uiout->table.header_first; | |
8b93c638 JM |
236 | |
237 | uo_table_body (uiout); | |
238 | } | |
239 | ||
3b31d625 | 240 | static void |
fba45db2 | 241 | ui_out_table_end (struct ui_out *uiout) |
8b93c638 | 242 | { |
bafdd3b3 | 243 | if (!uiout->table.flag) |
8e65ff28 | 244 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 245 | _("misplaced table_end or missing table_begin.")); |
8b93c638 | 246 | |
a6c47c14 | 247 | uiout->table.entry_level = 0; |
bafdd3b3 AC |
248 | uiout->table.body_flag = 0; |
249 | uiout->table.flag = 0; | |
8b93c638 JM |
250 | |
251 | uo_table_end (uiout); | |
b65a2bd9 | 252 | clear_table (uiout); |
8b93c638 JM |
253 | } |
254 | ||
255 | void | |
fba45db2 | 256 | ui_out_table_header (struct ui_out *uiout, int width, enum ui_align alignment, |
b25959ec | 257 | const char *col_name, |
88379baf | 258 | const char *colhdr) |
8b93c638 | 259 | { |
bafdd3b3 | 260 | if (!uiout->table.flag || uiout->table.body_flag) |
8e65ff28 | 261 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 AC |
262 | _("table header must be specified after table_begin \ |
263 | and before table_body.")); | |
8b93c638 | 264 | |
b25959ec | 265 | append_header_to_list (uiout, width, alignment, col_name, colhdr); |
8b93c638 | 266 | |
b25959ec | 267 | uo_table_header (uiout, width, alignment, col_name, colhdr); |
8b93c638 JM |
268 | } |
269 | ||
3b31d625 EZ |
270 | static void |
271 | do_cleanup_table_end (void *data) | |
272 | { | |
19ba03f4 | 273 | struct ui_out *ui_out = (struct ui_out *) data; |
3b31d625 EZ |
274 | |
275 | ui_out_table_end (ui_out); | |
276 | } | |
277 | ||
278 | struct cleanup * | |
279 | make_cleanup_ui_out_table_begin_end (struct ui_out *ui_out, int nr_cols, | |
280 | int nr_rows, const char *tblid) | |
281 | { | |
282 | ui_out_table_begin (ui_out, nr_cols, nr_rows, tblid); | |
283 | return make_cleanup (do_cleanup_table_end, ui_out); | |
284 | } | |
285 | ||
8b93c638 | 286 | void |
631ec795 AC |
287 | ui_out_begin (struct ui_out *uiout, |
288 | enum ui_out_type type, | |
289 | const char *id) | |
8b93c638 | 290 | { |
80f49b30 | 291 | int new_level; |
5d502164 | 292 | |
bafdd3b3 | 293 | if (uiout->table.flag && !uiout->table.body_flag) |
8e65ff28 | 294 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 AC |
295 | _("table header or table_body expected; lists must be \ |
296 | specified after table_body.")); | |
a6c47c14 AC |
297 | |
298 | /* Be careful to verify the ``field'' before the new tuple/list is | |
299 | pushed onto the stack. That way the containing list/table/row is | |
300 | verified and not the newly created tuple/list. This verification | |
301 | is needed (at least) for the case where a table row entry | |
302 | contains either a tuple/list. For that case bookkeeping such as | |
303 | updating the column count or advancing to the next heading still | |
304 | needs to be performed. */ | |
305 | { | |
306 | int fldno; | |
307 | int width; | |
f486487f | 308 | enum ui_align align; |
5d502164 | 309 | |
a6c47c14 AC |
310 | verify_field (uiout, &fldno, &width, &align); |
311 | } | |
312 | ||
49d06418 | 313 | new_level = push_level (uiout, type); |
a6c47c14 AC |
314 | |
315 | /* If the push puts us at the same level as a table row entry, we've | |
316 | got a new table row. Put the header pointer back to the start. */ | |
317 | if (uiout->table.body_flag | |
318 | && uiout->table.entry_level == new_level) | |
bafdd3b3 | 319 | uiout->table.header_next = uiout->table.header_first; |
a6c47c14 | 320 | |
631ec795 AC |
321 | uo_begin (uiout, type, new_level, id); |
322 | } | |
323 | ||
631ec795 AC |
324 | void |
325 | ui_out_end (struct ui_out *uiout, | |
326 | enum ui_out_type type) | |
327 | { | |
328 | int old_level = pop_level (uiout, type); | |
5d502164 | 329 | |
631ec795 | 330 | uo_end (uiout, type, old_level); |
8b93c638 JM |
331 | } |
332 | ||
127431f9 AC |
333 | struct ui_out_end_cleanup_data |
334 | { | |
335 | struct ui_out *uiout; | |
336 | enum ui_out_type type; | |
337 | }; | |
338 | ||
e6e0bfab | 339 | static void |
127431f9 AC |
340 | do_cleanup_end (void *data) |
341 | { | |
19ba03f4 SM |
342 | struct ui_out_end_cleanup_data *end_cleanup_data |
343 | = (struct ui_out_end_cleanup_data *) data; | |
5d502164 | 344 | |
127431f9 AC |
345 | ui_out_end (end_cleanup_data->uiout, end_cleanup_data->type); |
346 | xfree (end_cleanup_data); | |
347 | } | |
348 | ||
349 | static struct cleanup * | |
350 | make_cleanup_ui_out_end (struct ui_out *uiout, | |
351 | enum ui_out_type type) | |
352 | { | |
353 | struct ui_out_end_cleanup_data *end_cleanup_data; | |
5d502164 | 354 | |
70ba0933 | 355 | end_cleanup_data = XNEW (struct ui_out_end_cleanup_data); |
127431f9 AC |
356 | end_cleanup_data->uiout = uiout; |
357 | end_cleanup_data->type = type; | |
358 | return make_cleanup (do_cleanup_end, end_cleanup_data); | |
359 | } | |
360 | ||
e6e0bfab | 361 | struct cleanup * |
666547aa AC |
362 | make_cleanup_ui_out_tuple_begin_end (struct ui_out *uiout, |
363 | const char *id) | |
364 | { | |
3b31d625 | 365 | ui_out_begin (uiout, ui_out_type_tuple, id); |
666547aa AC |
366 | return make_cleanup_ui_out_end (uiout, ui_out_type_tuple); |
367 | } | |
368 | ||
369 | struct cleanup * | |
6b28c186 AC |
370 | make_cleanup_ui_out_list_begin_end (struct ui_out *uiout, |
371 | const char *id) | |
e6e0bfab | 372 | { |
3b31d625 | 373 | ui_out_begin (uiout, ui_out_type_list, id); |
127431f9 | 374 | return make_cleanup_ui_out_end (uiout, ui_out_type_list); |
e6e0bfab MK |
375 | } |
376 | ||
8b93c638 | 377 | void |
88379baf AC |
378 | ui_out_field_int (struct ui_out *uiout, |
379 | const char *fldname, | |
380 | int value) | |
8b93c638 JM |
381 | { |
382 | int fldno; | |
383 | int width; | |
f486487f | 384 | enum ui_align align; |
8b93c638 | 385 | |
a6c47c14 | 386 | verify_field (uiout, &fldno, &width, &align); |
8b93c638 JM |
387 | |
388 | uo_field_int (uiout, fldno, width, align, fldname, value); | |
389 | } | |
390 | ||
52c6a6ac JJ |
391 | void |
392 | ui_out_field_fmt_int (struct ui_out *uiout, | |
393 | int input_width, | |
394 | enum ui_align input_align, | |
395 | const char *fldname, | |
396 | int value) | |
397 | { | |
398 | int fldno; | |
399 | int width; | |
f486487f | 400 | enum ui_align align; |
52c6a6ac JJ |
401 | |
402 | verify_field (uiout, &fldno, &width, &align); | |
403 | ||
404 | uo_field_int (uiout, fldno, input_width, input_align, fldname, value); | |
405 | } | |
406 | ||
15230f37 TJB |
407 | /* Documented in ui-out.h. */ |
408 | ||
8b93c638 | 409 | void |
88379baf AC |
410 | ui_out_field_core_addr (struct ui_out *uiout, |
411 | const char *fldname, | |
5af949e3 | 412 | struct gdbarch *gdbarch, |
88379baf | 413 | CORE_ADDR address) |
8b93c638 | 414 | { |
f1310107 TJB |
415 | ui_out_field_string (uiout, fldname, |
416 | print_core_address (gdbarch, address)); | |
8b93c638 JM |
417 | } |
418 | ||
419 | void | |
88379baf AC |
420 | ui_out_field_stream (struct ui_out *uiout, |
421 | const char *fldname, | |
f99d8bf4 | 422 | struct ui_file *stream) |
8b93c638 | 423 | { |
56dbf317 | 424 | std::string buffer = ui_file_as_string (stream); |
5d502164 | 425 | |
56dbf317 PA |
426 | if (!buffer.empty ()) |
427 | ui_out_field_string (uiout, fldname, buffer.c_str ()); | |
8b93c638 JM |
428 | else |
429 | ui_out_field_skip (uiout, fldname); | |
f99d8bf4 | 430 | ui_file_rewind (stream); |
8b93c638 JM |
431 | } |
432 | ||
581e13c1 | 433 | /* Used to omit a field. */ |
8b93c638 JM |
434 | |
435 | void | |
88379baf AC |
436 | ui_out_field_skip (struct ui_out *uiout, |
437 | const char *fldname) | |
8b93c638 JM |
438 | { |
439 | int fldno; | |
440 | int width; | |
f486487f | 441 | enum ui_align align; |
8b93c638 | 442 | |
a6c47c14 | 443 | verify_field (uiout, &fldno, &width, &align); |
8b93c638 JM |
444 | |
445 | uo_field_skip (uiout, fldno, width, align, fldname); | |
446 | } | |
447 | ||
448 | void | |
449 | ui_out_field_string (struct ui_out *uiout, | |
88379baf | 450 | const char *fldname, |
8b93c638 JM |
451 | const char *string) |
452 | { | |
453 | int fldno; | |
454 | int width; | |
f486487f | 455 | enum ui_align align; |
8b93c638 | 456 | |
a6c47c14 | 457 | verify_field (uiout, &fldno, &width, &align); |
8b93c638 JM |
458 | |
459 | uo_field_string (uiout, fldno, width, align, fldname, string); | |
460 | } | |
461 | ||
462 | /* VARARGS */ | |
463 | void | |
88379baf AC |
464 | ui_out_field_fmt (struct ui_out *uiout, |
465 | const char *fldname, | |
466 | const char *format, ...) | |
8b93c638 JM |
467 | { |
468 | va_list args; | |
469 | int fldno; | |
470 | int width; | |
f486487f | 471 | enum ui_align align; |
8b93c638 | 472 | |
581e13c1 | 473 | /* Will not align, but has to call anyway. */ |
a6c47c14 | 474 | verify_field (uiout, &fldno, &width, &align); |
8b93c638 JM |
475 | |
476 | va_start (args, format); | |
477 | ||
478 | uo_field_fmt (uiout, fldno, width, align, fldname, format, args); | |
479 | ||
480 | va_end (args); | |
481 | } | |
482 | ||
483 | void | |
fba45db2 | 484 | ui_out_spaces (struct ui_out *uiout, int numspaces) |
8b93c638 JM |
485 | { |
486 | uo_spaces (uiout, numspaces); | |
487 | } | |
488 | ||
489 | void | |
88379baf AC |
490 | ui_out_text (struct ui_out *uiout, |
491 | const char *string) | |
8b93c638 JM |
492 | { |
493 | uo_text (uiout, string); | |
494 | } | |
495 | ||
496 | void | |
88379baf AC |
497 | ui_out_message (struct ui_out *uiout, int verbosity, |
498 | const char *format,...) | |
8b93c638 JM |
499 | { |
500 | va_list args; | |
501 | ||
502 | va_start (args, format); | |
8b93c638 | 503 | uo_message (uiout, verbosity, format, args); |
8b93c638 JM |
504 | va_end (args); |
505 | } | |
506 | ||
8b93c638 | 507 | void |
d2c0eef4 | 508 | ui_out_wrap_hint (struct ui_out *uiout, const char *identstring) |
8b93c638 JM |
509 | { |
510 | uo_wrap_hint (uiout, identstring); | |
511 | } | |
512 | ||
513 | void | |
fba45db2 | 514 | ui_out_flush (struct ui_out *uiout) |
8b93c638 JM |
515 | { |
516 | uo_flush (uiout); | |
517 | } | |
518 | ||
0fac0b41 DJ |
519 | int |
520 | ui_out_redirect (struct ui_out *uiout, struct ui_file *outstream) | |
521 | { | |
522 | return uo_redirect (uiout, outstream); | |
523 | } | |
524 | ||
581e13c1 | 525 | /* Test the flags against the mask given. */ |
8b93c638 | 526 | int |
fba45db2 | 527 | ui_out_test_flags (struct ui_out *uiout, int mask) |
8b93c638 JM |
528 | { |
529 | return (uiout->flags & mask); | |
530 | } | |
531 | ||
581e13c1 MS |
532 | /* Obtain the current verbosity level (as stablished by the |
533 | 'set verbositylevel' command. */ | |
8b93c638 JM |
534 | |
535 | int | |
fba45db2 | 536 | ui_out_get_verblvl (struct ui_out *uiout) |
8b93c638 | 537 | { |
581e13c1 | 538 | /* FIXME: not implemented yet. */ |
8b93c638 JM |
539 | return 0; |
540 | } | |
541 | ||
9dc5e2a9 AC |
542 | int |
543 | ui_out_is_mi_like_p (struct ui_out *uiout) | |
544 | { | |
545 | return uiout->impl->is_mi_like_p; | |
546 | } | |
547 | ||
581e13c1 | 548 | /* Interface to the implementation functions. */ |
8b93c638 JM |
549 | |
550 | void | |
88379baf | 551 | uo_table_begin (struct ui_out *uiout, int nbrofcols, |
d63f1d40 | 552 | int nr_rows, |
88379baf | 553 | const char *tblid) |
8b93c638 JM |
554 | { |
555 | if (!uiout->impl->table_begin) | |
556 | return; | |
d63f1d40 | 557 | uiout->impl->table_begin (uiout, nbrofcols, nr_rows, tblid); |
8b93c638 JM |
558 | } |
559 | ||
560 | void | |
561 | uo_table_body (struct ui_out *uiout) | |
562 | { | |
563 | if (!uiout->impl->table_body) | |
564 | return; | |
565 | uiout->impl->table_body (uiout); | |
566 | } | |
567 | ||
568 | void | |
569 | uo_table_end (struct ui_out *uiout) | |
570 | { | |
571 | if (!uiout->impl->table_end) | |
572 | return; | |
573 | uiout->impl->table_end (uiout); | |
574 | } | |
575 | ||
576 | void | |
88379baf | 577 | uo_table_header (struct ui_out *uiout, int width, enum ui_align align, |
b25959ec | 578 | const char *col_name, |
88379baf | 579 | const char *colhdr) |
8b93c638 JM |
580 | { |
581 | if (!uiout->impl->table_header) | |
582 | return; | |
b25959ec | 583 | uiout->impl->table_header (uiout, width, align, col_name, colhdr); |
8b93c638 JM |
584 | } |
585 | ||
b65a2bd9 SCR |
586 | /* Clear the table associated with UIOUT. */ |
587 | ||
588 | static void | |
589 | clear_table (struct ui_out *uiout) | |
590 | { | |
9c1fcd01 TT |
591 | xfree (uiout->table.id); |
592 | uiout->table.id = NULL; | |
b65a2bd9 SCR |
593 | clear_header_list (uiout); |
594 | } | |
595 | ||
8b93c638 | 596 | void |
631ec795 AC |
597 | uo_begin (struct ui_out *uiout, |
598 | enum ui_out_type type, | |
599 | int level, | |
600 | const char *id) | |
8b93c638 | 601 | { |
631ec795 | 602 | if (uiout->impl->begin == NULL) |
8b93c638 | 603 | return; |
631ec795 | 604 | uiout->impl->begin (uiout, type, level, id); |
8b93c638 JM |
605 | } |
606 | ||
607 | void | |
631ec795 AC |
608 | uo_end (struct ui_out *uiout, |
609 | enum ui_out_type type, | |
610 | int level) | |
8b93c638 | 611 | { |
631ec795 | 612 | if (uiout->impl->end == NULL) |
8b93c638 | 613 | return; |
631ec795 | 614 | uiout->impl->end (uiout, type, level); |
8b93c638 JM |
615 | } |
616 | ||
617 | void | |
88379baf AC |
618 | uo_field_int (struct ui_out *uiout, int fldno, int width, enum ui_align align, |
619 | const char *fldname, | |
620 | int value) | |
8b93c638 JM |
621 | { |
622 | if (!uiout->impl->field_int) | |
623 | return; | |
624 | uiout->impl->field_int (uiout, fldno, width, align, fldname, value); | |
625 | } | |
626 | ||
627 | void | |
88379baf AC |
628 | uo_field_skip (struct ui_out *uiout, int fldno, int width, enum ui_align align, |
629 | const char *fldname) | |
8b93c638 JM |
630 | { |
631 | if (!uiout->impl->field_skip) | |
632 | return; | |
633 | uiout->impl->field_skip (uiout, fldno, width, align, fldname); | |
634 | } | |
635 | ||
636 | void | |
637 | uo_field_string (struct ui_out *uiout, int fldno, int width, | |
88379baf AC |
638 | enum ui_align align, |
639 | const char *fldname, | |
640 | const char *string) | |
8b93c638 JM |
641 | { |
642 | if (!uiout->impl->field_string) | |
643 | return; | |
644 | uiout->impl->field_string (uiout, fldno, width, align, fldname, string); | |
645 | } | |
646 | ||
647 | void | |
88379baf AC |
648 | uo_field_fmt (struct ui_out *uiout, int fldno, int width, enum ui_align align, |
649 | const char *fldname, | |
650 | const char *format, | |
651 | va_list args) | |
8b93c638 JM |
652 | { |
653 | if (!uiout->impl->field_fmt) | |
654 | return; | |
655 | uiout->impl->field_fmt (uiout, fldno, width, align, fldname, format, args); | |
656 | } | |
657 | ||
658 | void | |
659 | uo_spaces (struct ui_out *uiout, int numspaces) | |
660 | { | |
661 | if (!uiout->impl->spaces) | |
662 | return; | |
663 | uiout->impl->spaces (uiout, numspaces); | |
664 | } | |
665 | ||
666 | void | |
88379baf AC |
667 | uo_text (struct ui_out *uiout, |
668 | const char *string) | |
8b93c638 JM |
669 | { |
670 | if (!uiout->impl->text) | |
671 | return; | |
672 | uiout->impl->text (uiout, string); | |
673 | } | |
674 | ||
675 | void | |
88379baf AC |
676 | uo_message (struct ui_out *uiout, int verbosity, |
677 | const char *format, | |
678 | va_list args) | |
8b93c638 JM |
679 | { |
680 | if (!uiout->impl->message) | |
681 | return; | |
682 | uiout->impl->message (uiout, verbosity, format, args); | |
683 | } | |
684 | ||
685 | void | |
d2c0eef4 | 686 | uo_wrap_hint (struct ui_out *uiout, const char *identstring) |
8b93c638 JM |
687 | { |
688 | if (!uiout->impl->wrap_hint) | |
689 | return; | |
690 | uiout->impl->wrap_hint (uiout, identstring); | |
691 | } | |
692 | ||
693 | void | |
694 | uo_flush (struct ui_out *uiout) | |
695 | { | |
696 | if (!uiout->impl->flush) | |
697 | return; | |
698 | uiout->impl->flush (uiout); | |
699 | } | |
700 | ||
0fac0b41 DJ |
701 | int |
702 | uo_redirect (struct ui_out *uiout, struct ui_file *outstream) | |
703 | { | |
704 | if (!uiout->impl->redirect) | |
705 | return -1; | |
82bbe65a | 706 | return uiout->impl->redirect (uiout, outstream); |
0fac0b41 DJ |
707 | } |
708 | ||
8b93c638 JM |
709 | /* local functions */ |
710 | ||
581e13c1 | 711 | /* List of column headers manipulation routines. */ |
8b93c638 JM |
712 | |
713 | static void | |
fba45db2 | 714 | clear_header_list (struct ui_out *uiout) |
8b93c638 | 715 | { |
bafdd3b3 | 716 | while (uiout->table.header_first != NULL) |
8b93c638 | 717 | { |
bafdd3b3 AC |
718 | uiout->table.header_next = uiout->table.header_first; |
719 | uiout->table.header_first = uiout->table.header_first->next; | |
71bdabee KS |
720 | xfree (uiout->table.header_next->colhdr); |
721 | xfree (uiout->table.header_next->col_name); | |
bafdd3b3 | 722 | xfree (uiout->table.header_next); |
8b93c638 | 723 | } |
bafdd3b3 AC |
724 | gdb_assert (uiout->table.header_first == NULL); |
725 | uiout->table.header_last = NULL; | |
726 | uiout->table.header_next = NULL; | |
8b93c638 JM |
727 | } |
728 | ||
729 | static void | |
730 | append_header_to_list (struct ui_out *uiout, | |
731 | int width, | |
f486487f | 732 | enum ui_align alignment, |
b25959ec | 733 | const char *col_name, |
88379baf | 734 | const char *colhdr) |
8b93c638 JM |
735 | { |
736 | struct ui_out_hdr *temphdr; | |
737 | ||
70ba0933 | 738 | temphdr = XNEW (struct ui_out_hdr); |
8b93c638 JM |
739 | temphdr->width = width; |
740 | temphdr->alignment = alignment; | |
44db85f8 MS |
741 | /* We have to copy the column title as the original may be an |
742 | automatic. */ | |
8b93c638 | 743 | if (colhdr != NULL) |
b25959ec AC |
744 | temphdr->colhdr = xstrdup (colhdr); |
745 | else | |
746 | temphdr->colhdr = NULL; | |
44db85f8 | 747 | |
b25959ec | 748 | if (col_name != NULL) |
44db85f8 MS |
749 | temphdr->col_name = xstrdup (col_name); |
750 | else if (colhdr != NULL) | |
b25959ec AC |
751 | temphdr->col_name = xstrdup (colhdr); |
752 | else | |
44db85f8 MS |
753 | temphdr->col_name = NULL; |
754 | ||
8b93c638 | 755 | temphdr->next = NULL; |
bafdd3b3 | 756 | if (uiout->table.header_first == NULL) |
8b93c638 JM |
757 | { |
758 | temphdr->colno = 1; | |
bafdd3b3 AC |
759 | uiout->table.header_first = temphdr; |
760 | uiout->table.header_last = temphdr; | |
8b93c638 JM |
761 | } |
762 | else | |
763 | { | |
bafdd3b3 AC |
764 | temphdr->colno = uiout->table.header_last->colno + 1; |
765 | uiout->table.header_last->next = temphdr; | |
766 | uiout->table.header_last = temphdr; | |
8b93c638 | 767 | } |
bafdd3b3 | 768 | uiout->table.header_next = uiout->table.header_last; |
8b93c638 JM |
769 | } |
770 | ||
7a9dd1b2 | 771 | /* Extract the format information for the NEXT header and advance |
bafdd3b3 | 772 | the header pointer. Return 0 if there was no next header. */ |
8b93c638 JM |
773 | |
774 | static int | |
bafdd3b3 | 775 | get_next_header (struct ui_out *uiout, |
8b93c638 JM |
776 | int *colno, |
777 | int *width, | |
f486487f | 778 | enum ui_align *alignment, |
8b93c638 JM |
779 | char **colhdr) |
780 | { | |
bafdd3b3 AC |
781 | /* There may be no headers at all or we may have used all columns. */ |
782 | if (uiout->table.header_next == NULL) | |
8b93c638 | 783 | return 0; |
bafdd3b3 AC |
784 | *colno = uiout->table.header_next->colno; |
785 | *width = uiout->table.header_next->width; | |
786 | *alignment = uiout->table.header_next->alignment; | |
787 | *colhdr = uiout->table.header_next->colhdr; | |
788 | /* Advance the header pointer to the next entry. */ | |
789 | uiout->table.header_next = uiout->table.header_next->next; | |
8b93c638 JM |
790 | return 1; |
791 | } | |
792 | ||
a6c47c14 AC |
793 | |
794 | /* Verify that the field/tuple/list is correctly positioned. Return | |
795 | the field number and corresponding alignment (if | |
796 | available/applicable). */ | |
8b93c638 JM |
797 | |
798 | static void | |
f486487f SM |
799 | verify_field (struct ui_out *uiout, int *fldno, int *width, |
800 | enum ui_align *align) | |
8b93c638 | 801 | { |
a6c47c14 AC |
802 | struct ui_out_level *current = current_level (uiout); |
803 | char *text; | |
804 | ||
bafdd3b3 | 805 | if (uiout->table.flag) |
8b93c638 | 806 | { |
bafdd3b3 | 807 | if (!uiout->table.body_flag) |
8e65ff28 | 808 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 AC |
809 | _("table_body missing; table fields must be \ |
810 | specified after table_body and inside a list.")); | |
a6c47c14 AC |
811 | /* NOTE: cagney/2001-12-08: There was a check here to ensure |
812 | that this code was only executed when uiout->level was | |
813 | greater than zero. That no longer applies - this code is run | |
814 | before each table row tuple is started and at that point the | |
815 | level is zero. */ | |
8b93c638 | 816 | } |
8b93c638 | 817 | |
a6c47c14 | 818 | current->field_count += 1; |
8b93c638 | 819 | |
a6c47c14 AC |
820 | if (uiout->table.body_flag |
821 | && uiout->table.entry_level == uiout->level | |
822 | && get_next_header (uiout, fldno, width, align, &text)) | |
8b93c638 | 823 | { |
a6c47c14 | 824 | if (*fldno != current->field_count) |
8e65ff28 | 825 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 826 | _("ui-out internal error in handling headers.")); |
8b93c638 JM |
827 | } |
828 | else | |
829 | { | |
830 | *width = 0; | |
831 | *align = ui_noalign; | |
a6c47c14 | 832 | *fldno = current->field_count; |
8b93c638 JM |
833 | } |
834 | } | |
835 | ||
a6c47c14 | 836 | |
581e13c1 | 837 | /* Access to ui-out members data. */ |
8b93c638 | 838 | |
0a8fce9a | 839 | void * |
8b93c638 JM |
840 | ui_out_data (struct ui_out *uiout) |
841 | { | |
842 | return uiout->data; | |
843 | } | |
844 | ||
170b53b2 UW |
845 | /* Access table field parameters. */ |
846 | int | |
847 | ui_out_query_field (struct ui_out *uiout, int colno, | |
848 | int *width, int *alignment, char **col_name) | |
849 | { | |
850 | struct ui_out_hdr *hdr; | |
851 | ||
852 | if (!uiout->table.flag) | |
853 | return 0; | |
854 | ||
855 | for (hdr = uiout->table.header_first; hdr; hdr = hdr->next) | |
856 | if (hdr->colno == colno) | |
857 | { | |
858 | *width = hdr->width; | |
859 | *alignment = hdr->alignment; | |
860 | *col_name = hdr->col_name; | |
861 | return 1; | |
862 | } | |
863 | ||
864 | return 0; | |
865 | } | |
866 | ||
26c4b26f | 867 | /* Initialize private members at startup. */ |
8b93c638 JM |
868 | |
869 | struct ui_out * | |
89de4da4 | 870 | ui_out_new (const struct ui_out_impl *impl, void *data, |
8b93c638 JM |
871 | int flags) |
872 | { | |
70ba0933 TT |
873 | struct ui_out *uiout = XNEW (struct ui_out); |
874 | struct ui_out_level *current = XNEW (struct ui_out_level); | |
5d502164 | 875 | |
8b93c638 JM |
876 | uiout->data = data; |
877 | uiout->impl = impl; | |
878 | uiout->flags = flags; | |
bafdd3b3 AC |
879 | uiout->table.flag = 0; |
880 | uiout->table.body_flag = 0; | |
80f49b30 | 881 | uiout->level = 0; |
54eb231c PM |
882 | uiout->levels = NULL; |
883 | ||
884 | /* Create uiout->level 0, the default level. */ | |
885 | current->type = ui_out_type_tuple; | |
886 | current->field_count = 0; | |
887 | VEC_safe_push (ui_out_level_p, uiout->levels, current); | |
888 | ||
9c1fcd01 | 889 | uiout->table.id = NULL; |
bafdd3b3 AC |
890 | uiout->table.header_first = NULL; |
891 | uiout->table.header_last = NULL; | |
892 | uiout->table.header_next = NULL; | |
8b93c638 JM |
893 | return uiout; |
894 | } |