]>
Commit | Line | Data |
---|---|---|
8b93c638 | 1 | /* Output generating routines for GDB. |
8e65ff28 | 2 | Copyright 1999, 2000, 2001 Free Software Foundation, Inc. |
8b93c638 JM |
3 | Contributed by Cygnus Solutions. |
4 | Written by Fernando Nasser for Cygnus. | |
5 | ||
6 | This file is part of GDB. | |
7 | ||
8 | This program is free software; you can redistribute it and/or modify | |
9 | it under the terms of the GNU General Public License as published by | |
10 | the Free Software Foundation; either version 2 of the License, or | |
11 | (at your option) any later version. | |
12 | ||
13 | This program is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
19 | along with this program; if not, write to the Free Software | |
20 | Foundation, Inc., 59 Temple Place - Suite 330, | |
21 | Boston, MA 02111-1307, USA. */ | |
22 | ||
23 | #include "defs.h" | |
24 | #include "gdb_string.h" | |
25 | #include "expression.h" /* For language.h */ | |
26 | #include "language.h" | |
27 | #include "ui-out.h" | |
80f49b30 | 28 | #include "gdb_assert.h" |
8b93c638 JM |
29 | |
30 | /* Convenience macro for allocting typesafe memory. */ | |
31 | ||
32 | #undef XMALLOC | |
33 | #define XMALLOC(TYPE) (TYPE*) xmalloc (sizeof (TYPE)) | |
34 | ||
35 | /* table header structures */ | |
36 | ||
37 | struct ui_out_hdr | |
38 | { | |
39 | int colno; | |
40 | int width; | |
41 | int alignment; | |
b25959ec | 42 | char *col_name; |
8b93c638 JM |
43 | char *colhdr; |
44 | struct ui_out_hdr *next; | |
45 | }; | |
46 | ||
80f49b30 AC |
47 | /* Maintain a stack so that the info applicable to the inner most list |
48 | is always available. Stack/nested level 0 is reserved for the | |
49 | top-level result. */ | |
50 | ||
51 | enum { MAX_UI_OUT_LEVELS = 5 }; | |
52 | ||
53 | struct ui_out_level | |
54 | { | |
55 | /* Count each field; the first element is for non-list fields */ | |
56 | int field_count; | |
631ec795 AC |
57 | /* The type of this level. */ |
58 | enum ui_out_type type; | |
80f49b30 AC |
59 | }; |
60 | ||
8b93c638 JM |
61 | /* The ui_out structure */ |
62 | /* Any change here requires a corresponding one in the initialization | |
63 | of the default uiout, which is statically initialized */ | |
64 | ||
65 | struct ui_out | |
66 | { | |
67 | int flags; | |
68 | /* specific implementation of ui-out */ | |
69 | struct ui_out_impl *impl; | |
70 | struct ui_out_data *data; | |
71 | ||
72 | /* if on, a table is being generated */ | |
73 | int table_flag; | |
74 | ||
75 | /* if on, the body of a table is being generated */ | |
76 | int body_flag; | |
77 | ||
78 | /* number of table columns (as specified in the table_begin call) */ | |
79 | int table_columns; | |
80 | ||
81 | /* strinf identifying the table (as specified in the table_begin call) */ | |
82 | char *table_id; | |
83 | ||
80f49b30 AC |
84 | /* Sub structure tracking the table depth. */ |
85 | int level; | |
86 | struct ui_out_level levels[MAX_UI_OUT_LEVELS]; | |
8b93c638 JM |
87 | |
88 | /* points to the first header (if any) */ | |
89 | struct ui_out_hdr *headerfirst; | |
90 | ||
91 | /* points to the last header (if any) */ | |
92 | struct ui_out_hdr *headerlast; | |
93 | ||
94 | /* points to header of next column to format */ | |
95 | struct ui_out_hdr *headercurr; | |
96 | ||
97 | }; | |
98 | ||
80f49b30 AC |
99 | /* The current (inner most) level. */ |
100 | static struct ui_out_level * | |
101 | current_level (struct ui_out *uiout) | |
102 | { | |
103 | return &uiout->levels[uiout->level]; | |
104 | } | |
105 | ||
106 | /* Create a new level, of TYPE. Return the new level's index. */ | |
107 | static int | |
108 | push_level (struct ui_out *uiout, | |
631ec795 | 109 | enum ui_out_type type, |
80f49b30 AC |
110 | const char *id) |
111 | { | |
112 | struct ui_out_level *current; | |
113 | /* We had better not overflow the buffer. */ | |
114 | uiout->level++; | |
631ec795 | 115 | gdb_assert (uiout->level >= 0 && uiout->level < MAX_UI_OUT_LEVELS); |
80f49b30 AC |
116 | current = current_level (uiout); |
117 | current->field_count = 0; | |
631ec795 | 118 | current->type = type; |
80f49b30 AC |
119 | return uiout->level; |
120 | } | |
121 | ||
122 | /* Discard the current level, return the discarded level's index. | |
123 | TYPE is the type of the level being discarded. */ | |
124 | static int | |
631ec795 AC |
125 | pop_level (struct ui_out *uiout, |
126 | enum ui_out_type type) | |
80f49b30 AC |
127 | { |
128 | /* We had better not underflow the buffer. */ | |
129 | gdb_assert (uiout->level > 0 && uiout->level < MAX_UI_OUT_LEVELS); | |
631ec795 | 130 | gdb_assert (current_level (uiout)->type == type); |
80f49b30 AC |
131 | uiout->level--; |
132 | return uiout->level + 1; | |
133 | } | |
134 | ||
135 | ||
8b93c638 JM |
136 | /* These are the default implementation functions */ |
137 | ||
138 | static void default_table_begin (struct ui_out *uiout, int nbrofcols, | |
d63f1d40 | 139 | int nr_rows, const char *tblid); |
8b93c638 JM |
140 | static void default_table_body (struct ui_out *uiout); |
141 | static void default_table_end (struct ui_out *uiout); | |
142 | static void default_table_header (struct ui_out *uiout, int width, | |
b25959ec | 143 | enum ui_align alig, const char *col_name, |
e2e11a41 | 144 | const char *colhdr); |
631ec795 AC |
145 | static void default_begin (struct ui_out *uiout, |
146 | enum ui_out_type type, | |
147 | int level, const char *id); | |
148 | static void default_end (struct ui_out *uiout, | |
149 | enum ui_out_type type, | |
150 | int level); | |
8b93c638 | 151 | static void default_field_int (struct ui_out *uiout, int fldno, int width, |
e2e11a41 AC |
152 | enum ui_align alig, |
153 | const char *fldname, | |
154 | int value); | |
8b93c638 | 155 | static void default_field_skip (struct ui_out *uiout, int fldno, int width, |
e2e11a41 AC |
156 | enum ui_align alig, |
157 | const char *fldname); | |
8b93c638 | 158 | static void default_field_string (struct ui_out *uiout, int fldno, int width, |
e2e11a41 AC |
159 | enum ui_align align, |
160 | const char *fldname, | |
8b93c638 JM |
161 | const char *string); |
162 | static void default_field_fmt (struct ui_out *uiout, int fldno, | |
163 | int width, enum ui_align align, | |
e2e11a41 AC |
164 | const char *fldname, |
165 | const char *format, | |
166 | va_list args); | |
8b93c638 | 167 | static void default_spaces (struct ui_out *uiout, int numspaces); |
e2e11a41 AC |
168 | static void default_text (struct ui_out *uiout, const char *string); |
169 | static void default_message (struct ui_out *uiout, int verbosity, | |
170 | const char *format, | |
8b93c638 JM |
171 | va_list args); |
172 | static void default_wrap_hint (struct ui_out *uiout, char *identstring); | |
173 | static void default_flush (struct ui_out *uiout); | |
174 | ||
175 | /* This is the default ui-out implementation functions vector */ | |
176 | ||
177 | struct ui_out_impl default_ui_out_impl = | |
178 | { | |
179 | default_table_begin, | |
180 | default_table_body, | |
181 | default_table_end, | |
182 | default_table_header, | |
631ec795 AC |
183 | default_begin, |
184 | default_end, | |
8b93c638 JM |
185 | default_field_int, |
186 | default_field_skip, | |
187 | default_field_string, | |
188 | default_field_fmt, | |
189 | default_spaces, | |
190 | default_text, | |
191 | default_message, | |
192 | default_wrap_hint, | |
9dc5e2a9 AC |
193 | default_flush, |
194 | 0, /* Does not need MI hacks. */ | |
8b93c638 JM |
195 | }; |
196 | ||
197 | /* The default ui_out */ | |
198 | ||
199 | struct ui_out def_uiout = | |
200 | { | |
201 | 0, /* flags */ | |
202 | &default_ui_out_impl, /* impl */ | |
203 | }; | |
204 | ||
205 | /* Pointer to current ui_out */ | |
206 | /* FIXME: This should not be a global, but something passed down from main.c | |
207 | or top.c */ | |
208 | ||
209 | struct ui_out *uiout = &def_uiout; | |
210 | ||
211 | /* These are the interfaces to implementation functions */ | |
212 | ||
88379baf | 213 | static void uo_table_begin (struct ui_out *uiout, int nbrofcols, |
d63f1d40 | 214 | int nr_rows, const char *tblid); |
8b93c638 JM |
215 | static void uo_table_body (struct ui_out *uiout); |
216 | static void uo_table_end (struct ui_out *uiout); | |
217 | static void uo_table_header (struct ui_out *uiout, int width, | |
b25959ec AC |
218 | enum ui_align align, const char *col_name, |
219 | const char *colhdr); | |
631ec795 AC |
220 | static void uo_begin (struct ui_out *uiout, |
221 | enum ui_out_type type, | |
222 | int level, const char *id); | |
223 | static void uo_end (struct ui_out *uiout, | |
224 | enum ui_out_type type, | |
225 | int level); | |
8b93c638 | 226 | static void uo_field_int (struct ui_out *uiout, int fldno, int width, |
88379baf | 227 | enum ui_align align, const char *fldname, int value); |
8b93c638 | 228 | static void uo_field_skip (struct ui_out *uiout, int fldno, int width, |
88379baf | 229 | enum ui_align align, const char *fldname); |
8b93c638 | 230 | static void uo_field_string (struct ui_out *uiout, int fldno, int width, |
88379baf AC |
231 | enum ui_align align, const char *fldname, |
232 | const char *string); | |
8b93c638 | 233 | static void uo_field_fmt (struct ui_out *uiout, int fldno, int width, |
88379baf AC |
234 | enum ui_align align, const char *fldname, |
235 | const char *format, va_list args); | |
8b93c638 | 236 | static void uo_spaces (struct ui_out *uiout, int numspaces); |
88379baf | 237 | static void uo_text (struct ui_out *uiout, const char *string); |
8b93c638 | 238 | static void uo_message (struct ui_out *uiout, int verbosity, |
88379baf | 239 | const char *format, va_list args); |
8b93c638 JM |
240 | static void uo_wrap_hint (struct ui_out *uiout, char *identstring); |
241 | static void uo_flush (struct ui_out *uiout); | |
242 | ||
243 | /* Prototypes for local functions */ | |
244 | ||
245 | extern void _initialize_ui_out (void); | |
88379baf | 246 | static void append_header_to_list (struct ui_out *uiout, int width, |
b25959ec AC |
247 | int alignment, const char *col_name, |
248 | const char *colhdr); | |
8b93c638 JM |
249 | static int get_curr_header (struct ui_out *uiout, int *colno, int *width, |
250 | int *alignment, char **colhdr); | |
251 | static void clear_header_list (struct ui_out *uiout); | |
252 | static void verify_field_proper_position (struct ui_out *uiout); | |
253 | static void verify_field_alignment (struct ui_out *uiout, int fldno, int *width, int *alignment); | |
254 | ||
255 | static void init_ui_out_state (struct ui_out *uiout); | |
256 | ||
257 | /* exported functions (ui_out API) */ | |
258 | ||
259 | /* Mark beginning of a table */ | |
260 | ||
261 | void | |
88379baf | 262 | ui_out_table_begin (struct ui_out *uiout, int nbrofcols, |
d63f1d40 | 263 | int nr_rows, |
88379baf | 264 | const char *tblid) |
8b93c638 JM |
265 | { |
266 | if (uiout->table_flag) | |
8e65ff28 AC |
267 | internal_error (__FILE__, __LINE__, |
268 | "tables cannot be nested; table_begin found before \ | |
8b93c638 JM |
269 | previous table_end."); |
270 | ||
271 | uiout->table_flag = 1; | |
272 | uiout->table_columns = nbrofcols; | |
273 | if (tblid != NULL) | |
274 | uiout->table_id = xstrdup (tblid); | |
275 | else | |
276 | uiout->table_id = NULL; | |
277 | clear_header_list (uiout); | |
278 | ||
d63f1d40 | 279 | uo_table_begin (uiout, nbrofcols, nr_rows, uiout->table_id); |
8b93c638 JM |
280 | } |
281 | ||
282 | void | |
fba45db2 | 283 | ui_out_table_body (struct ui_out *uiout) |
8b93c638 JM |
284 | { |
285 | if (!uiout->table_flag) | |
8e65ff28 AC |
286 | internal_error (__FILE__, __LINE__, |
287 | "table_body outside a table is not valid; it must be \ | |
8b93c638 JM |
288 | after a table_begin and before a table_end."); |
289 | if (uiout->body_flag) | |
8e65ff28 AC |
290 | internal_error (__FILE__, __LINE__, |
291 | "extra table_body call not allowed; there must be \ | |
8b93c638 JM |
292 | only one table_body after a table_begin and before a table_end."); |
293 | if (uiout->headercurr->colno != uiout->table_columns) | |
8e65ff28 AC |
294 | internal_error (__FILE__, __LINE__, |
295 | "number of headers differ from number of table \ | |
8b93c638 JM |
296 | columns."); |
297 | ||
298 | uiout->body_flag = 1; | |
299 | uiout->headercurr = uiout->headerfirst; | |
300 | ||
301 | uo_table_body (uiout); | |
302 | } | |
303 | ||
304 | void | |
fba45db2 | 305 | ui_out_table_end (struct ui_out *uiout) |
8b93c638 JM |
306 | { |
307 | if (!uiout->table_flag) | |
8e65ff28 AC |
308 | internal_error (__FILE__, __LINE__, |
309 | "misplaced table_end or missing table_begin."); | |
8b93c638 JM |
310 | |
311 | uiout->body_flag = 0; | |
312 | uiout->table_flag = 0; | |
313 | ||
314 | uo_table_end (uiout); | |
315 | ||
316 | if (uiout->table_id) | |
b8c9b27d | 317 | xfree (uiout->table_id); |
8b93c638 JM |
318 | clear_header_list (uiout); |
319 | } | |
320 | ||
321 | void | |
fba45db2 | 322 | ui_out_table_header (struct ui_out *uiout, int width, enum ui_align alignment, |
b25959ec | 323 | const char *col_name, |
88379baf | 324 | const char *colhdr) |
8b93c638 JM |
325 | { |
326 | if (!uiout->table_flag || uiout->body_flag) | |
8e65ff28 AC |
327 | internal_error (__FILE__, __LINE__, |
328 | "table header must be specified after table_begin \ | |
8b93c638 JM |
329 | and before table_body."); |
330 | ||
b25959ec | 331 | append_header_to_list (uiout, width, alignment, col_name, colhdr); |
8b93c638 | 332 | |
b25959ec | 333 | uo_table_header (uiout, width, alignment, col_name, colhdr); |
8b93c638 JM |
334 | } |
335 | ||
336 | void | |
631ec795 AC |
337 | ui_out_begin (struct ui_out *uiout, |
338 | enum ui_out_type type, | |
339 | const char *id) | |
8b93c638 | 340 | { |
80f49b30 | 341 | int new_level; |
8b93c638 | 342 | if (uiout->table_flag && !uiout->body_flag) |
8e65ff28 AC |
343 | internal_error (__FILE__, __LINE__, |
344 | "table header or table_body expected; lists must be \ | |
8b93c638 | 345 | specified after table_body."); |
631ec795 | 346 | new_level = push_level (uiout, type, id); |
80f49b30 | 347 | if (uiout->table_flag && (new_level == 1)) |
8b93c638 | 348 | uiout->headercurr = uiout->headerfirst; |
631ec795 AC |
349 | uo_begin (uiout, type, new_level, id); |
350 | } | |
351 | ||
352 | void | |
6b28c186 AC |
353 | ui_out_list_begin (struct ui_out *uiout, |
354 | const char *id) | |
631ec795 | 355 | { |
6b28c186 | 356 | ui_out_begin (uiout, ui_out_type_list, id); |
666547aa AC |
357 | } |
358 | ||
359 | void | |
360 | ui_out_tuple_begin (struct ui_out *uiout, const char *id) | |
361 | { | |
362 | ui_out_begin (uiout, ui_out_type_tuple, id); | |
631ec795 AC |
363 | } |
364 | ||
365 | void | |
366 | ui_out_end (struct ui_out *uiout, | |
367 | enum ui_out_type type) | |
368 | { | |
369 | int old_level = pop_level (uiout, type); | |
370 | uo_end (uiout, type, old_level); | |
8b93c638 JM |
371 | } |
372 | ||
373 | void | |
fba45db2 | 374 | ui_out_list_end (struct ui_out *uiout) |
8b93c638 | 375 | { |
631ec795 | 376 | ui_out_end (uiout, ui_out_type_list); |
8b93c638 JM |
377 | } |
378 | ||
666547aa AC |
379 | void |
380 | ui_out_tuple_end (struct ui_out *uiout) | |
381 | { | |
382 | ui_out_end (uiout, ui_out_type_tuple); | |
383 | } | |
384 | ||
127431f9 AC |
385 | struct ui_out_end_cleanup_data |
386 | { | |
387 | struct ui_out *uiout; | |
388 | enum ui_out_type type; | |
389 | }; | |
390 | ||
e6e0bfab | 391 | static void |
127431f9 AC |
392 | do_cleanup_end (void *data) |
393 | { | |
394 | struct ui_out_end_cleanup_data *end_cleanup_data = data; | |
395 | ui_out_end (end_cleanup_data->uiout, end_cleanup_data->type); | |
396 | xfree (end_cleanup_data); | |
397 | } | |
398 | ||
399 | static struct cleanup * | |
400 | make_cleanup_ui_out_end (struct ui_out *uiout, | |
401 | enum ui_out_type type) | |
402 | { | |
403 | struct ui_out_end_cleanup_data *end_cleanup_data; | |
404 | end_cleanup_data = XMALLOC (struct ui_out_end_cleanup_data); | |
405 | end_cleanup_data->uiout = uiout; | |
406 | end_cleanup_data->type = type; | |
407 | return make_cleanup (do_cleanup_end, end_cleanup_data); | |
408 | } | |
409 | ||
410 | struct cleanup * | |
411 | make_cleanup_ui_out_begin_end (struct ui_out *uiout, | |
412 | enum ui_out_type type, | |
413 | const char *id) | |
e6e0bfab | 414 | { |
127431f9 AC |
415 | ui_out_begin (uiout, type, id); |
416 | return make_cleanup_ui_out_end (uiout, type); | |
e6e0bfab MK |
417 | } |
418 | ||
419 | struct cleanup * | |
666547aa AC |
420 | make_cleanup_ui_out_tuple_begin_end (struct ui_out *uiout, |
421 | const char *id) | |
422 | { | |
423 | ui_out_tuple_begin (uiout, id); | |
424 | return make_cleanup_ui_out_end (uiout, ui_out_type_tuple); | |
425 | } | |
426 | ||
427 | struct cleanup * | |
6b28c186 AC |
428 | make_cleanup_ui_out_list_begin_end (struct ui_out *uiout, |
429 | const char *id) | |
e6e0bfab | 430 | { |
6b28c186 | 431 | ui_out_list_begin (uiout, id); |
127431f9 | 432 | return make_cleanup_ui_out_end (uiout, ui_out_type_list); |
e6e0bfab MK |
433 | } |
434 | ||
8b93c638 | 435 | void |
88379baf AC |
436 | ui_out_field_int (struct ui_out *uiout, |
437 | const char *fldname, | |
438 | int value) | |
8b93c638 JM |
439 | { |
440 | int fldno; | |
441 | int width; | |
442 | int align; | |
80f49b30 | 443 | struct ui_out_level *current = current_level (uiout); |
8b93c638 JM |
444 | |
445 | verify_field_proper_position (uiout); | |
446 | ||
80f49b30 AC |
447 | current->field_count += 1; |
448 | fldno = current->field_count; | |
8b93c638 JM |
449 | |
450 | verify_field_alignment (uiout, fldno, &width, &align); | |
451 | ||
452 | uo_field_int (uiout, fldno, width, align, fldname, value); | |
453 | } | |
454 | ||
455 | void | |
88379baf AC |
456 | ui_out_field_core_addr (struct ui_out *uiout, |
457 | const char *fldname, | |
458 | CORE_ADDR address) | |
8b93c638 JM |
459 | { |
460 | char addstr[20]; | |
461 | ||
462 | /* FIXME-32x64: need a print_address_numeric with field width */ | |
463 | /* print_address_numeric (address, 1, local_stream); */ | |
464 | strcpy (addstr, local_hex_string_custom ((unsigned long) address, "08l")); | |
465 | ||
466 | ui_out_field_string (uiout, fldname, addstr); | |
467 | } | |
468 | ||
469 | void | |
88379baf AC |
470 | ui_out_field_stream (struct ui_out *uiout, |
471 | const char *fldname, | |
472 | struct ui_stream *buf) | |
8b93c638 JM |
473 | { |
474 | long length; | |
475 | char *buffer = ui_file_xstrdup (buf->stream, &length); | |
b8c9b27d | 476 | struct cleanup *old_cleanup = make_cleanup (xfree, buffer); |
8b93c638 JM |
477 | if (length > 0) |
478 | ui_out_field_string (uiout, fldname, buffer); | |
479 | else | |
480 | ui_out_field_skip (uiout, fldname); | |
481 | ui_file_rewind (buf->stream); | |
482 | do_cleanups (old_cleanup); | |
483 | } | |
484 | ||
485 | /* used to ommit a field */ | |
486 | ||
487 | void | |
88379baf AC |
488 | ui_out_field_skip (struct ui_out *uiout, |
489 | const char *fldname) | |
8b93c638 JM |
490 | { |
491 | int fldno; | |
492 | int width; | |
493 | int align; | |
80f49b30 | 494 | struct ui_out_level *current = current_level (uiout); |
8b93c638 JM |
495 | |
496 | verify_field_proper_position (uiout); | |
497 | ||
80f49b30 AC |
498 | current->field_count += 1; |
499 | fldno = current->field_count; | |
8b93c638 JM |
500 | |
501 | verify_field_alignment (uiout, fldno, &width, &align); | |
502 | ||
503 | uo_field_skip (uiout, fldno, width, align, fldname); | |
504 | } | |
505 | ||
506 | void | |
507 | ui_out_field_string (struct ui_out *uiout, | |
88379baf | 508 | const char *fldname, |
8b93c638 JM |
509 | const char *string) |
510 | { | |
511 | int fldno; | |
512 | int width; | |
513 | int align; | |
80f49b30 | 514 | struct ui_out_level *current = current_level (uiout); |
8b93c638 JM |
515 | |
516 | verify_field_proper_position (uiout); | |
517 | ||
80f49b30 AC |
518 | current->field_count += 1; |
519 | fldno = current->field_count; | |
8b93c638 JM |
520 | |
521 | verify_field_alignment (uiout, fldno, &width, &align); | |
522 | ||
523 | uo_field_string (uiout, fldno, width, align, fldname, string); | |
524 | } | |
525 | ||
526 | /* VARARGS */ | |
527 | void | |
88379baf AC |
528 | ui_out_field_fmt (struct ui_out *uiout, |
529 | const char *fldname, | |
530 | const char *format, ...) | |
8b93c638 JM |
531 | { |
532 | va_list args; | |
533 | int fldno; | |
534 | int width; | |
535 | int align; | |
80f49b30 | 536 | struct ui_out_level *current = current_level (uiout); |
8b93c638 JM |
537 | |
538 | verify_field_proper_position (uiout); | |
539 | ||
80f49b30 AC |
540 | current->field_count += 1; |
541 | fldno = current->field_count; | |
8b93c638 JM |
542 | |
543 | /* will not align, but has to call anyway */ | |
544 | verify_field_alignment (uiout, fldno, &width, &align); | |
545 | ||
546 | va_start (args, format); | |
547 | ||
548 | uo_field_fmt (uiout, fldno, width, align, fldname, format, args); | |
549 | ||
550 | va_end (args); | |
551 | } | |
552 | ||
553 | void | |
fba45db2 | 554 | ui_out_spaces (struct ui_out *uiout, int numspaces) |
8b93c638 JM |
555 | { |
556 | uo_spaces (uiout, numspaces); | |
557 | } | |
558 | ||
559 | void | |
88379baf AC |
560 | ui_out_text (struct ui_out *uiout, |
561 | const char *string) | |
8b93c638 JM |
562 | { |
563 | uo_text (uiout, string); | |
564 | } | |
565 | ||
566 | void | |
88379baf AC |
567 | ui_out_message (struct ui_out *uiout, int verbosity, |
568 | const char *format,...) | |
8b93c638 JM |
569 | { |
570 | va_list args; | |
571 | ||
572 | va_start (args, format); | |
573 | ||
574 | uo_message (uiout, verbosity, format, args); | |
575 | ||
576 | va_end (args); | |
577 | } | |
578 | ||
579 | struct ui_stream * | |
fba45db2 | 580 | ui_out_stream_new (struct ui_out *uiout) |
8b93c638 JM |
581 | { |
582 | struct ui_stream *tempbuf; | |
583 | ||
584 | tempbuf = XMALLOC (struct ui_stream); | |
585 | tempbuf->uiout = uiout; | |
586 | tempbuf->stream = mem_fileopen (); | |
587 | return tempbuf; | |
588 | } | |
589 | ||
590 | void | |
fba45db2 | 591 | ui_out_stream_delete (struct ui_stream *buf) |
8b93c638 JM |
592 | { |
593 | ui_file_delete (buf->stream); | |
b8c9b27d | 594 | xfree (buf); |
8b93c638 JM |
595 | } |
596 | ||
597 | static void | |
598 | do_stream_delete (void *buf) | |
599 | { | |
600 | ui_out_stream_delete (buf); | |
601 | } | |
602 | ||
603 | struct cleanup * | |
604 | make_cleanup_ui_out_stream_delete (struct ui_stream *buf) | |
605 | { | |
606 | return make_cleanup (do_stream_delete, buf); | |
607 | } | |
608 | ||
609 | ||
610 | void | |
fba45db2 | 611 | ui_out_wrap_hint (struct ui_out *uiout, char *identstring) |
8b93c638 JM |
612 | { |
613 | uo_wrap_hint (uiout, identstring); | |
614 | } | |
615 | ||
616 | void | |
fba45db2 | 617 | ui_out_flush (struct ui_out *uiout) |
8b93c638 JM |
618 | { |
619 | uo_flush (uiout); | |
620 | } | |
621 | ||
622 | /* set the flags specified by the mask given */ | |
623 | int | |
fba45db2 | 624 | ui_out_set_flags (struct ui_out *uiout, int mask) |
8b93c638 | 625 | { |
5bfb05ca | 626 | int oldflags = uiout->flags; |
8b93c638 | 627 | |
b8d86de3 | 628 | uiout->flags |= mask; |
8b93c638 JM |
629 | |
630 | return oldflags; | |
631 | } | |
632 | ||
633 | /* clear the flags specified by the mask given */ | |
634 | int | |
fba45db2 | 635 | ui_out_clear_flags (struct ui_out *uiout, int mask) |
8b93c638 | 636 | { |
5bfb05ca | 637 | int oldflags = uiout->flags; |
8b93c638 JM |
638 | |
639 | uiout->flags &= ~mask; | |
640 | ||
641 | return oldflags; | |
642 | } | |
643 | ||
644 | /* test the flags against the mask given */ | |
645 | int | |
fba45db2 | 646 | ui_out_test_flags (struct ui_out *uiout, int mask) |
8b93c638 JM |
647 | { |
648 | return (uiout->flags & mask); | |
649 | } | |
650 | ||
651 | /* obtain the current verbosity level (as stablished by the | |
652 | 'set verbositylevel' command */ | |
653 | ||
654 | int | |
fba45db2 | 655 | ui_out_get_verblvl (struct ui_out *uiout) |
8b93c638 JM |
656 | { |
657 | /* FIXME: not implemented yet */ | |
658 | return 0; | |
659 | } | |
660 | ||
661 | #if 0 | |
662 | void | |
fba45db2 | 663 | ui_out_result_begin (struct ui_out *uiout, char *class) |
8b93c638 JM |
664 | { |
665 | } | |
666 | ||
667 | void | |
fba45db2 | 668 | ui_out_result_end (struct ui_out *uiout) |
8b93c638 JM |
669 | { |
670 | } | |
671 | ||
672 | void | |
fba45db2 | 673 | ui_out_info_begin (struct ui_out *uiout, char *class) |
8b93c638 JM |
674 | { |
675 | } | |
676 | ||
677 | void | |
fba45db2 | 678 | ui_out_info_end (struct ui_out *uiout) |
8b93c638 JM |
679 | { |
680 | } | |
681 | ||
682 | void | |
fba45db2 | 683 | ui_out_notify_begin (struct ui_out *uiout, char *class) |
8b93c638 JM |
684 | { |
685 | } | |
686 | ||
687 | void | |
fba45db2 | 688 | ui_out_notify_end (struct ui_out *uiout) |
8b93c638 JM |
689 | { |
690 | } | |
691 | ||
692 | void | |
fba45db2 | 693 | ui_out_error_begin (struct ui_out *uiout, char *class) |
8b93c638 JM |
694 | { |
695 | } | |
696 | ||
697 | void | |
fba45db2 | 698 | ui_out_error_end (struct ui_out *uiout) |
8b93c638 JM |
699 | { |
700 | } | |
701 | #endif | |
702 | ||
703 | #if 0 | |
704 | void | |
705 | gdb_error (ui_out * uiout, int severity, char *format,...) | |
706 | { | |
707 | va_list args; | |
708 | } | |
709 | ||
710 | void | |
10689f25 | 711 | gdb_query (struct ui_out *uiout, int qflags, char *qprompt) |
8b93c638 JM |
712 | { |
713 | } | |
714 | #endif | |
715 | ||
9dc5e2a9 AC |
716 | int |
717 | ui_out_is_mi_like_p (struct ui_out *uiout) | |
718 | { | |
719 | return uiout->impl->is_mi_like_p; | |
720 | } | |
721 | ||
8b93c638 JM |
722 | /* default gdb-out hook functions */ |
723 | ||
724 | static void | |
d63f1d40 AC |
725 | default_table_begin (struct ui_out *uiout, int nbrofcols, |
726 | int nr_rows, | |
727 | const char *tblid) | |
8b93c638 JM |
728 | { |
729 | } | |
730 | ||
731 | static void | |
fba45db2 | 732 | default_table_body (struct ui_out *uiout) |
8b93c638 JM |
733 | { |
734 | } | |
735 | ||
736 | static void | |
fba45db2 | 737 | default_table_end (struct ui_out *uiout) |
8b93c638 JM |
738 | { |
739 | } | |
740 | ||
741 | static void | |
fba45db2 | 742 | default_table_header (struct ui_out *uiout, int width, enum ui_align alignment, |
b25959ec | 743 | const char *col_name, |
e2e11a41 | 744 | const char *colhdr) |
8b93c638 JM |
745 | { |
746 | } | |
747 | ||
748 | static void | |
631ec795 AC |
749 | default_begin (struct ui_out *uiout, |
750 | enum ui_out_type type, | |
751 | int level, | |
752 | const char *id) | |
8b93c638 JM |
753 | { |
754 | } | |
755 | ||
756 | static void | |
631ec795 AC |
757 | default_end (struct ui_out *uiout, |
758 | enum ui_out_type type, | |
759 | int level) | |
8b93c638 JM |
760 | { |
761 | } | |
762 | ||
763 | static void | |
fba45db2 | 764 | default_field_int (struct ui_out *uiout, int fldno, int width, |
e2e11a41 AC |
765 | enum ui_align align, |
766 | const char *fldname, int value) | |
8b93c638 JM |
767 | { |
768 | } | |
769 | ||
770 | static void | |
fba45db2 | 771 | default_field_skip (struct ui_out *uiout, int fldno, int width, |
e2e11a41 | 772 | enum ui_align align, const char *fldname) |
8b93c638 JM |
773 | { |
774 | } | |
775 | ||
776 | static void | |
777 | default_field_string (struct ui_out *uiout, | |
778 | int fldno, | |
779 | int width, | |
780 | enum ui_align align, | |
e2e11a41 | 781 | const char *fldname, |
8b93c638 JM |
782 | const char *string) |
783 | { | |
784 | } | |
785 | ||
786 | static void | |
fba45db2 | 787 | default_field_fmt (struct ui_out *uiout, int fldno, int width, |
e2e11a41 AC |
788 | enum ui_align align, |
789 | const char *fldname, | |
790 | const char *format, | |
fba45db2 | 791 | va_list args) |
8b93c638 JM |
792 | { |
793 | } | |
794 | ||
795 | static void | |
fba45db2 | 796 | default_spaces (struct ui_out *uiout, int numspaces) |
8b93c638 JM |
797 | { |
798 | } | |
799 | ||
800 | static void | |
e2e11a41 | 801 | default_text (struct ui_out *uiout, const char *string) |
8b93c638 JM |
802 | { |
803 | } | |
804 | ||
805 | static void | |
e2e11a41 AC |
806 | default_message (struct ui_out *uiout, int verbosity, |
807 | const char *format, | |
fba45db2 | 808 | va_list args) |
8b93c638 JM |
809 | { |
810 | } | |
811 | ||
812 | static void | |
fba45db2 | 813 | default_wrap_hint (struct ui_out *uiout, char *identstring) |
8b93c638 JM |
814 | { |
815 | } | |
816 | ||
817 | static void | |
fba45db2 | 818 | default_flush (struct ui_out *uiout) |
8b93c638 JM |
819 | { |
820 | } | |
821 | ||
822 | /* Interface to the implementation functions */ | |
823 | ||
824 | void | |
88379baf | 825 | uo_table_begin (struct ui_out *uiout, int nbrofcols, |
d63f1d40 | 826 | int nr_rows, |
88379baf | 827 | const char *tblid) |
8b93c638 JM |
828 | { |
829 | if (!uiout->impl->table_begin) | |
830 | return; | |
d63f1d40 | 831 | uiout->impl->table_begin (uiout, nbrofcols, nr_rows, tblid); |
8b93c638 JM |
832 | } |
833 | ||
834 | void | |
835 | uo_table_body (struct ui_out *uiout) | |
836 | { | |
837 | if (!uiout->impl->table_body) | |
838 | return; | |
839 | uiout->impl->table_body (uiout); | |
840 | } | |
841 | ||
842 | void | |
843 | uo_table_end (struct ui_out *uiout) | |
844 | { | |
845 | if (!uiout->impl->table_end) | |
846 | return; | |
847 | uiout->impl->table_end (uiout); | |
848 | } | |
849 | ||
850 | void | |
88379baf | 851 | uo_table_header (struct ui_out *uiout, int width, enum ui_align align, |
b25959ec | 852 | const char *col_name, |
88379baf | 853 | const char *colhdr) |
8b93c638 JM |
854 | { |
855 | if (!uiout->impl->table_header) | |
856 | return; | |
b25959ec | 857 | uiout->impl->table_header (uiout, width, align, col_name, colhdr); |
8b93c638 JM |
858 | } |
859 | ||
860 | void | |
631ec795 AC |
861 | uo_begin (struct ui_out *uiout, |
862 | enum ui_out_type type, | |
863 | int level, | |
864 | const char *id) | |
8b93c638 | 865 | { |
631ec795 | 866 | if (uiout->impl->begin == NULL) |
8b93c638 | 867 | return; |
631ec795 | 868 | uiout->impl->begin (uiout, type, level, id); |
8b93c638 JM |
869 | } |
870 | ||
871 | void | |
631ec795 AC |
872 | uo_end (struct ui_out *uiout, |
873 | enum ui_out_type type, | |
874 | int level) | |
8b93c638 | 875 | { |
631ec795 | 876 | if (uiout->impl->end == NULL) |
8b93c638 | 877 | return; |
631ec795 | 878 | uiout->impl->end (uiout, type, level); |
8b93c638 JM |
879 | } |
880 | ||
881 | void | |
88379baf AC |
882 | uo_field_int (struct ui_out *uiout, int fldno, int width, enum ui_align align, |
883 | const char *fldname, | |
884 | int value) | |
8b93c638 JM |
885 | { |
886 | if (!uiout->impl->field_int) | |
887 | return; | |
888 | uiout->impl->field_int (uiout, fldno, width, align, fldname, value); | |
889 | } | |
890 | ||
891 | void | |
88379baf AC |
892 | uo_field_skip (struct ui_out *uiout, int fldno, int width, enum ui_align align, |
893 | const char *fldname) | |
8b93c638 JM |
894 | { |
895 | if (!uiout->impl->field_skip) | |
896 | return; | |
897 | uiout->impl->field_skip (uiout, fldno, width, align, fldname); | |
898 | } | |
899 | ||
900 | void | |
901 | uo_field_string (struct ui_out *uiout, int fldno, int width, | |
88379baf AC |
902 | enum ui_align align, |
903 | const char *fldname, | |
904 | const char *string) | |
8b93c638 JM |
905 | { |
906 | if (!uiout->impl->field_string) | |
907 | return; | |
908 | uiout->impl->field_string (uiout, fldno, width, align, fldname, string); | |
909 | } | |
910 | ||
911 | void | |
88379baf AC |
912 | uo_field_fmt (struct ui_out *uiout, int fldno, int width, enum ui_align align, |
913 | const char *fldname, | |
914 | const char *format, | |
915 | va_list args) | |
8b93c638 JM |
916 | { |
917 | if (!uiout->impl->field_fmt) | |
918 | return; | |
919 | uiout->impl->field_fmt (uiout, fldno, width, align, fldname, format, args); | |
920 | } | |
921 | ||
922 | void | |
923 | uo_spaces (struct ui_out *uiout, int numspaces) | |
924 | { | |
925 | if (!uiout->impl->spaces) | |
926 | return; | |
927 | uiout->impl->spaces (uiout, numspaces); | |
928 | } | |
929 | ||
930 | void | |
88379baf AC |
931 | uo_text (struct ui_out *uiout, |
932 | const char *string) | |
8b93c638 JM |
933 | { |
934 | if (!uiout->impl->text) | |
935 | return; | |
936 | uiout->impl->text (uiout, string); | |
937 | } | |
938 | ||
939 | void | |
88379baf AC |
940 | uo_message (struct ui_out *uiout, int verbosity, |
941 | const char *format, | |
942 | va_list args) | |
8b93c638 JM |
943 | { |
944 | if (!uiout->impl->message) | |
945 | return; | |
946 | uiout->impl->message (uiout, verbosity, format, args); | |
947 | } | |
948 | ||
949 | void | |
950 | uo_wrap_hint (struct ui_out *uiout, char *identstring) | |
951 | { | |
952 | if (!uiout->impl->wrap_hint) | |
953 | return; | |
954 | uiout->impl->wrap_hint (uiout, identstring); | |
955 | } | |
956 | ||
957 | void | |
958 | uo_flush (struct ui_out *uiout) | |
959 | { | |
960 | if (!uiout->impl->flush) | |
961 | return; | |
962 | uiout->impl->flush (uiout); | |
963 | } | |
964 | ||
965 | /* local functions */ | |
966 | ||
967 | /* list of column headers manipulation routines */ | |
968 | ||
969 | static void | |
fba45db2 | 970 | clear_header_list (struct ui_out *uiout) |
8b93c638 JM |
971 | { |
972 | while (uiout->headerfirst != NULL) | |
973 | { | |
974 | uiout->headercurr = uiout->headerfirst; | |
975 | uiout->headerfirst = uiout->headerfirst->next; | |
976 | if (uiout->headercurr->colhdr != NULL) | |
b8c9b27d KB |
977 | xfree (uiout->headercurr->colhdr); |
978 | xfree (uiout->headercurr); | |
8b93c638 JM |
979 | } |
980 | uiout->headerlast = NULL; | |
981 | uiout->headercurr = NULL; | |
982 | } | |
983 | ||
984 | static void | |
985 | append_header_to_list (struct ui_out *uiout, | |
986 | int width, | |
987 | int alignment, | |
b25959ec | 988 | const char *col_name, |
88379baf | 989 | const char *colhdr) |
8b93c638 JM |
990 | { |
991 | struct ui_out_hdr *temphdr; | |
992 | ||
993 | temphdr = XMALLOC (struct ui_out_hdr); | |
994 | temphdr->width = width; | |
995 | temphdr->alignment = alignment; | |
996 | /* we have to copy the column title as the original may be an automatic */ | |
997 | if (colhdr != NULL) | |
b25959ec AC |
998 | temphdr->colhdr = xstrdup (colhdr); |
999 | else | |
1000 | temphdr->colhdr = NULL; | |
1001 | if (col_name != NULL) | |
1002 | temphdr->col_name = xstrdup (colhdr); | |
1003 | else | |
1004 | temphdr->col_name = xstrdup (colhdr); | |
8b93c638 JM |
1005 | temphdr->next = NULL; |
1006 | if (uiout->headerfirst == NULL) | |
1007 | { | |
1008 | temphdr->colno = 1; | |
1009 | uiout->headerfirst = temphdr; | |
1010 | uiout->headerlast = temphdr; | |
1011 | } | |
1012 | else | |
1013 | { | |
1014 | temphdr->colno = uiout->headerlast->colno + 1; | |
1015 | uiout->headerlast->next = temphdr; | |
1016 | uiout->headerlast = temphdr; | |
1017 | } | |
1018 | uiout->headercurr = uiout->headerlast; | |
1019 | } | |
1020 | ||
1021 | /* returns 0 if there is no more headers */ | |
1022 | ||
1023 | static int | |
1024 | get_curr_header (struct ui_out *uiout, | |
1025 | int *colno, | |
1026 | int *width, | |
1027 | int *alignment, | |
1028 | char **colhdr) | |
1029 | { | |
1030 | /* There may be no headers at all or we may have used all columns */ | |
1031 | if (uiout->headercurr == NULL) | |
1032 | return 0; | |
1033 | *colno = uiout->headercurr->colno; | |
1034 | *width = uiout->headercurr->width; | |
1035 | *alignment = uiout->headercurr->alignment; | |
1036 | *colhdr = uiout->headercurr->colhdr; | |
1037 | uiout->headercurr = uiout->headercurr->next; | |
1038 | return 1; | |
1039 | } | |
1040 | ||
1041 | /* makes sure the field_* calls were properly placed */ | |
1042 | ||
1043 | static void | |
1044 | verify_field_proper_position (struct ui_out *uiout) | |
1045 | { | |
1046 | if (uiout->table_flag) | |
1047 | { | |
1048 | if (!uiout->body_flag) | |
8e65ff28 AC |
1049 | internal_error (__FILE__, __LINE__, |
1050 | "table_body missing; table fields must be \ | |
8b93c638 | 1051 | specified after table_body and inside a list."); |
80f49b30 | 1052 | if (uiout->level == 0) |
8e65ff28 AC |
1053 | internal_error (__FILE__, __LINE__, |
1054 | "list_begin missing; table fields must be \ | |
8b93c638 JM |
1055 | specified after table_body and inside a list."); |
1056 | } | |
1057 | } | |
1058 | ||
1059 | /* determines what is the alignment policy */ | |
1060 | ||
1061 | static void | |
1062 | verify_field_alignment (struct ui_out *uiout, | |
1063 | int fldno, | |
1064 | int *width, | |
1065 | int *align) | |
1066 | { | |
1067 | int colno; | |
1068 | char *text; | |
1069 | ||
1070 | if (uiout->table_flag | |
1071 | && get_curr_header (uiout, &colno, width, align, &text)) | |
1072 | { | |
1073 | if (fldno != colno) | |
8e65ff28 AC |
1074 | internal_error (__FILE__, __LINE__, |
1075 | "ui-out internal error in handling headers."); | |
8b93c638 JM |
1076 | } |
1077 | else | |
1078 | { | |
1079 | *width = 0; | |
1080 | *align = ui_noalign; | |
1081 | } | |
1082 | } | |
1083 | ||
1084 | /* access to ui_out format private members */ | |
1085 | ||
1086 | void | |
fba45db2 | 1087 | ui_out_get_field_separator (struct ui_out *uiout) |
8b93c638 JM |
1088 | { |
1089 | } | |
1090 | ||
1091 | /* Access to ui-out members data */ | |
1092 | ||
1093 | struct ui_out_data * | |
1094 | ui_out_data (struct ui_out *uiout) | |
1095 | { | |
1096 | return uiout->data; | |
1097 | } | |
1098 | ||
1099 | /* initalize private members at startup */ | |
1100 | ||
1101 | struct ui_out * | |
1102 | ui_out_new (struct ui_out_impl *impl, | |
1103 | struct ui_out_data *data, | |
1104 | int flags) | |
1105 | { | |
1106 | struct ui_out *uiout = XMALLOC (struct ui_out); | |
1107 | uiout->data = data; | |
1108 | uiout->impl = impl; | |
1109 | uiout->flags = flags; | |
1110 | uiout->table_flag = 0; | |
1111 | uiout->body_flag = 0; | |
80f49b30 AC |
1112 | uiout->level = 0; |
1113 | memset (uiout->levels, 0, sizeof (uiout->levels)); | |
8b93c638 JM |
1114 | uiout->headerfirst = NULL; |
1115 | uiout->headerlast = NULL; | |
1116 | uiout->headercurr = NULL; | |
1117 | return uiout; | |
1118 | } | |
1119 | ||
1120 | /* standard gdb initialization hook */ | |
1121 | ||
1122 | void | |
fba45db2 | 1123 | _initialize_ui_out (void) |
8b93c638 JM |
1124 | { |
1125 | /* nothing needs to be done */ | |
1126 | } |