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