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