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