*** empty log message ***
[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;
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
50enum { MAX_UI_OUT_LEVELS = 5 };
51
52struct 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
64struct 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. */
99static struct ui_out_level *
100current_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. */
106static int
107push_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. */
123static int
631ec795
AC
124pop_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
137static void default_table_begin (struct ui_out *uiout, int nbrofcols,
138 char *tblid);
139static void default_table_body (struct ui_out *uiout);
140static void default_table_end (struct ui_out *uiout);
141static void default_table_header (struct ui_out *uiout, int width,
142 enum ui_align alig, char *colhdr);
631ec795
AC
143static void default_begin (struct ui_out *uiout,
144 enum ui_out_type type,
145 int level, const char *id);
146static void default_end (struct ui_out *uiout,
147 enum ui_out_type type,
148 int level);
8b93c638
JM
149static void default_field_int (struct ui_out *uiout, int fldno, int width,
150 enum ui_align alig, char *fldname, int value);
151static void default_field_skip (struct ui_out *uiout, int fldno, int width,
152 enum ui_align alig, char *fldname);
153static void default_field_string (struct ui_out *uiout, int fldno, int width,
154 enum ui_align align, char *fldname,
155 const char *string);
156static 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);
159static void default_spaces (struct ui_out *uiout, int numspaces);
160static void default_text (struct ui_out *uiout, char *string);
161static void default_message (struct ui_out *uiout, int verbosity, char *format,
162 va_list args);
163static void default_wrap_hint (struct ui_out *uiout, char *identstring);
164static void default_flush (struct ui_out *uiout);
165
166/* This is the default ui-out implementation functions vector */
167
168struct 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
189struct 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
199struct ui_out *uiout = &def_uiout;
200
201/* These are the interfaces to implementation functions */
202
203static void uo_table_begin (struct ui_out *uiout, int nbrofcols, char *tblid);
204static void uo_table_body (struct ui_out *uiout);
205static void uo_table_end (struct ui_out *uiout);
206static void uo_table_header (struct ui_out *uiout, int width,
207 enum ui_align align, char *colhdr);
631ec795
AC
208static void uo_begin (struct ui_out *uiout,
209 enum ui_out_type type,
210 int level, const char *id);
211static void uo_end (struct ui_out *uiout,
212 enum ui_out_type type,
213 int level);
8b93c638
JM
214static void uo_field_int (struct ui_out *uiout, int fldno, int width,
215 enum ui_align align, char *fldname, int value);
216static void uo_field_skip (struct ui_out *uiout, int fldno, int width,
217 enum ui_align align, char *fldname);
218static void uo_field_string (struct ui_out *uiout, int fldno, int width,
219 enum ui_align align, char *fldname, const char *string);
220static 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);
223static void uo_spaces (struct ui_out *uiout, int numspaces);
224static void uo_text (struct ui_out *uiout, char *string);
225static void uo_message (struct ui_out *uiout, int verbosity,
226 char *format, va_list args);
227static void uo_wrap_hint (struct ui_out *uiout, char *identstring);
228static void uo_flush (struct ui_out *uiout);
229
230/* Prototypes for local functions */
231
232extern void _initialize_ui_out (void);
233static void append_header_to_list (struct ui_out *uiout, int width, int alignment, char *colhdr);
234static int get_curr_header (struct ui_out *uiout, int *colno, int *width,
235 int *alignment, char **colhdr);
236static void clear_header_list (struct ui_out *uiout);
237static void verify_field_proper_position (struct ui_out *uiout);
238static void verify_field_alignment (struct ui_out *uiout, int fldno, int *width, int *alignment);
239
240static void init_ui_out_state (struct ui_out *uiout);
241
242/* exported functions (ui_out API) */
243
244/* Mark beginning of a table */
245
246void
fba45db2 247ui_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
252previous 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
265void
fba45db2 266ui_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
271after 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
275only 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
279columns.");
280
281 uiout->body_flag = 1;
282 uiout->headercurr = uiout->headerfirst;
283
284 uo_table_body (uiout);
285}
286
287void
fba45db2 288ui_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
304void
fba45db2
KB
305ui_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
311and before table_body.");
312
313 append_header_to_list (uiout, width, alignment, colhdr);
314
315 uo_table_header (uiout, width, alignment, colhdr);
316}
317
318void
631ec795
AC
319ui_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 327specified 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
334void
666547aa 335ui_out_list_begin (struct ui_out *uiout)
631ec795 336{
666547aa
AC
337 ui_out_begin (uiout, ui_out_type_list, NULL);
338}
339
340void
341ui_out_tuple_begin (struct ui_out *uiout, const char *id)
342{
343 ui_out_begin (uiout, ui_out_type_tuple, id);
631ec795
AC
344}
345
346void
347ui_out_end (struct ui_out *uiout,
348 enum ui_out_type type)
349{
350 int old_level = pop_level (uiout, type);
351 uo_end (uiout, type, old_level);
8b93c638
JM
352}
353
354void
fba45db2 355ui_out_list_end (struct ui_out *uiout)
8b93c638 356{
631ec795 357 ui_out_end (uiout, ui_out_type_list);
8b93c638
JM
358}
359
666547aa
AC
360void
361ui_out_tuple_end (struct ui_out *uiout)
362{
363 ui_out_end (uiout, ui_out_type_tuple);
364}
365
127431f9
AC
366struct ui_out_end_cleanup_data
367{
368 struct ui_out *uiout;
369 enum ui_out_type type;
370};
371
e6e0bfab 372static void
127431f9
AC
373do_cleanup_end (void *data)
374{
375 struct ui_out_end_cleanup_data *end_cleanup_data = data;
376 ui_out_end (end_cleanup_data->uiout, end_cleanup_data->type);
377 xfree (end_cleanup_data);
378}
379
380static struct cleanup *
381make_cleanup_ui_out_end (struct ui_out *uiout,
382 enum ui_out_type type)
383{
384 struct ui_out_end_cleanup_data *end_cleanup_data;
385 end_cleanup_data = XMALLOC (struct ui_out_end_cleanup_data);
386 end_cleanup_data->uiout = uiout;
387 end_cleanup_data->type = type;
388 return make_cleanup (do_cleanup_end, end_cleanup_data);
389}
390
391struct cleanup *
392make_cleanup_ui_out_begin_end (struct ui_out *uiout,
393 enum ui_out_type type,
394 const char *id)
e6e0bfab 395{
127431f9
AC
396 ui_out_begin (uiout, type, id);
397 return make_cleanup_ui_out_end (uiout, type);
e6e0bfab
MK
398}
399
400struct cleanup *
666547aa
AC
401make_cleanup_ui_out_tuple_begin_end (struct ui_out *uiout,
402 const char *id)
403{
404 ui_out_tuple_begin (uiout, id);
405 return make_cleanup_ui_out_end (uiout, ui_out_type_tuple);
406}
407
408struct cleanup *
409make_cleanup_ui_out_list_begin_end (struct ui_out *uiout)
e6e0bfab 410{
127431f9 411 return make_cleanup_ui_out_end (uiout, ui_out_type_list);
e6e0bfab
MK
412}
413
8b93c638 414void
fba45db2 415ui_out_field_int (struct ui_out *uiout, char *fldname, int value)
8b93c638
JM
416{
417 int fldno;
418 int width;
419 int align;
80f49b30 420 struct ui_out_level *current = current_level (uiout);
8b93c638
JM
421
422 verify_field_proper_position (uiout);
423
80f49b30
AC
424 current->field_count += 1;
425 fldno = current->field_count;
8b93c638
JM
426
427 verify_field_alignment (uiout, fldno, &width, &align);
428
429 uo_field_int (uiout, fldno, width, align, fldname, value);
430}
431
432void
fba45db2 433ui_out_field_core_addr (struct ui_out *uiout, char *fldname, CORE_ADDR address)
8b93c638
JM
434{
435 char addstr[20];
436
437 /* FIXME-32x64: need a print_address_numeric with field width */
438 /* print_address_numeric (address, 1, local_stream); */
439 strcpy (addstr, local_hex_string_custom ((unsigned long) address, "08l"));
440
441 ui_out_field_string (uiout, fldname, addstr);
442}
443
444void
fba45db2 445ui_out_field_stream (struct ui_out *uiout, char *fldname, struct ui_stream *buf)
8b93c638
JM
446{
447 long length;
448 char *buffer = ui_file_xstrdup (buf->stream, &length);
b8c9b27d 449 struct cleanup *old_cleanup = make_cleanup (xfree, buffer);
8b93c638
JM
450 if (length > 0)
451 ui_out_field_string (uiout, fldname, buffer);
452 else
453 ui_out_field_skip (uiout, fldname);
454 ui_file_rewind (buf->stream);
455 do_cleanups (old_cleanup);
456}
457
458/* used to ommit a field */
459
460void
fba45db2 461ui_out_field_skip (struct ui_out *uiout, char *fldname)
8b93c638
JM
462{
463 int fldno;
464 int width;
465 int align;
80f49b30 466 struct ui_out_level *current = current_level (uiout);
8b93c638
JM
467
468 verify_field_proper_position (uiout);
469
80f49b30
AC
470 current->field_count += 1;
471 fldno = current->field_count;
8b93c638
JM
472
473 verify_field_alignment (uiout, fldno, &width, &align);
474
475 uo_field_skip (uiout, fldno, width, align, fldname);
476}
477
478void
479ui_out_field_string (struct ui_out *uiout,
480 char *fldname,
481 const char *string)
482{
483 int fldno;
484 int width;
485 int align;
80f49b30 486 struct ui_out_level *current = current_level (uiout);
8b93c638
JM
487
488 verify_field_proper_position (uiout);
489
80f49b30
AC
490 current->field_count += 1;
491 fldno = current->field_count;
8b93c638
JM
492
493 verify_field_alignment (uiout, fldno, &width, &align);
494
495 uo_field_string (uiout, fldno, width, align, fldname, string);
496}
497
498/* VARARGS */
499void
500ui_out_field_fmt (struct ui_out *uiout, char *fldname, char *format,...)
501{
502 va_list args;
503 int fldno;
504 int width;
505 int align;
80f49b30 506 struct ui_out_level *current = current_level (uiout);
8b93c638
JM
507
508 verify_field_proper_position (uiout);
509
80f49b30
AC
510 current->field_count += 1;
511 fldno = current->field_count;
8b93c638
JM
512
513 /* will not align, but has to call anyway */
514 verify_field_alignment (uiout, fldno, &width, &align);
515
516 va_start (args, format);
517
518 uo_field_fmt (uiout, fldno, width, align, fldname, format, args);
519
520 va_end (args);
521}
522
523void
fba45db2 524ui_out_spaces (struct ui_out *uiout, int numspaces)
8b93c638
JM
525{
526 uo_spaces (uiout, numspaces);
527}
528
529void
fba45db2 530ui_out_text (struct ui_out *uiout, char *string)
8b93c638
JM
531{
532 uo_text (uiout, string);
533}
534
535void
536ui_out_message (struct ui_out *uiout, int verbosity, char *format,...)
537{
538 va_list args;
539
540 va_start (args, format);
541
542 uo_message (uiout, verbosity, format, args);
543
544 va_end (args);
545}
546
547struct ui_stream *
fba45db2 548ui_out_stream_new (struct ui_out *uiout)
8b93c638
JM
549{
550 struct ui_stream *tempbuf;
551
552 tempbuf = XMALLOC (struct ui_stream);
553 tempbuf->uiout = uiout;
554 tempbuf->stream = mem_fileopen ();
555 return tempbuf;
556}
557
558void
fba45db2 559ui_out_stream_delete (struct ui_stream *buf)
8b93c638
JM
560{
561 ui_file_delete (buf->stream);
b8c9b27d 562 xfree (buf);
8b93c638
JM
563}
564
565static void
566do_stream_delete (void *buf)
567{
568 ui_out_stream_delete (buf);
569}
570
571struct cleanup *
572make_cleanup_ui_out_stream_delete (struct ui_stream *buf)
573{
574 return make_cleanup (do_stream_delete, buf);
575}
576
577
578void
fba45db2 579ui_out_wrap_hint (struct ui_out *uiout, char *identstring)
8b93c638
JM
580{
581 uo_wrap_hint (uiout, identstring);
582}
583
584void
fba45db2 585ui_out_flush (struct ui_out *uiout)
8b93c638
JM
586{
587 uo_flush (uiout);
588}
589
590/* set the flags specified by the mask given */
591int
fba45db2 592ui_out_set_flags (struct ui_out *uiout, int mask)
8b93c638 593{
5bfb05ca 594 int oldflags = uiout->flags;
8b93c638 595
b8d86de3 596 uiout->flags |= mask;
8b93c638
JM
597
598 return oldflags;
599}
600
601/* clear the flags specified by the mask given */
602int
fba45db2 603ui_out_clear_flags (struct ui_out *uiout, int mask)
8b93c638 604{
5bfb05ca 605 int oldflags = uiout->flags;
8b93c638
JM
606
607 uiout->flags &= ~mask;
608
609 return oldflags;
610}
611
612/* test the flags against the mask given */
613int
fba45db2 614ui_out_test_flags (struct ui_out *uiout, int mask)
8b93c638
JM
615{
616 return (uiout->flags & mask);
617}
618
619/* obtain the current verbosity level (as stablished by the
620 'set verbositylevel' command */
621
622int
fba45db2 623ui_out_get_verblvl (struct ui_out *uiout)
8b93c638
JM
624{
625 /* FIXME: not implemented yet */
626 return 0;
627}
628
629#if 0
630void
fba45db2 631ui_out_result_begin (struct ui_out *uiout, char *class)
8b93c638
JM
632{
633}
634
635void
fba45db2 636ui_out_result_end (struct ui_out *uiout)
8b93c638
JM
637{
638}
639
640void
fba45db2 641ui_out_info_begin (struct ui_out *uiout, char *class)
8b93c638
JM
642{
643}
644
645void
fba45db2 646ui_out_info_end (struct ui_out *uiout)
8b93c638
JM
647{
648}
649
650void
fba45db2 651ui_out_notify_begin (struct ui_out *uiout, char *class)
8b93c638
JM
652{
653}
654
655void
fba45db2 656ui_out_notify_end (struct ui_out *uiout)
8b93c638
JM
657{
658}
659
660void
fba45db2 661ui_out_error_begin (struct ui_out *uiout, char *class)
8b93c638
JM
662{
663}
664
665void
fba45db2 666ui_out_error_end (struct ui_out *uiout)
8b93c638
JM
667{
668}
669#endif
670
671#if 0
672void
673gdb_error (ui_out * uiout, int severity, char *format,...)
674{
675 va_list args;
676}
677
678void
10689f25 679gdb_query (struct ui_out *uiout, int qflags, char *qprompt)
8b93c638
JM
680{
681}
682#endif
683
684/* default gdb-out hook functions */
685
686static void
fba45db2 687default_table_begin (struct ui_out *uiout, int nbrofcols, char *tblid)
8b93c638
JM
688{
689}
690
691static void
fba45db2 692default_table_body (struct ui_out *uiout)
8b93c638
JM
693{
694}
695
696static void
fba45db2 697default_table_end (struct ui_out *uiout)
8b93c638
JM
698{
699}
700
701static void
fba45db2
KB
702default_table_header (struct ui_out *uiout, int width, enum ui_align alignment,
703 char *colhdr)
8b93c638
JM
704{
705}
706
707static void
631ec795
AC
708default_begin (struct ui_out *uiout,
709 enum ui_out_type type,
710 int level,
711 const char *id)
8b93c638
JM
712{
713}
714
715static void
631ec795
AC
716default_end (struct ui_out *uiout,
717 enum ui_out_type type,
718 int level)
8b93c638
JM
719{
720}
721
722static void
fba45db2
KB
723default_field_int (struct ui_out *uiout, int fldno, int width,
724 enum ui_align align, char *fldname, int value)
8b93c638
JM
725{
726}
727
728static void
fba45db2
KB
729default_field_skip (struct ui_out *uiout, int fldno, int width,
730 enum ui_align align, char *fldname)
8b93c638
JM
731{
732}
733
734static void
735default_field_string (struct ui_out *uiout,
736 int fldno,
737 int width,
738 enum ui_align align,
739 char *fldname,
740 const char *string)
741{
742}
743
744static void
fba45db2
KB
745default_field_fmt (struct ui_out *uiout, int fldno, int width,
746 enum ui_align align, char *fldname, char *format,
747 va_list args)
8b93c638
JM
748{
749}
750
751static void
fba45db2 752default_spaces (struct ui_out *uiout, int numspaces)
8b93c638
JM
753{
754}
755
756static void
fba45db2 757default_text (struct ui_out *uiout, char *string)
8b93c638
JM
758{
759}
760
761static void
fba45db2
KB
762default_message (struct ui_out *uiout, int verbosity, char *format,
763 va_list args)
8b93c638
JM
764{
765}
766
767static void
fba45db2 768default_wrap_hint (struct ui_out *uiout, char *identstring)
8b93c638
JM
769{
770}
771
772static void
fba45db2 773default_flush (struct ui_out *uiout)
8b93c638
JM
774{
775}
776
777/* Interface to the implementation functions */
778
779void
780uo_table_begin (struct ui_out *uiout, int nbrofcols, char *tblid)
781{
782 if (!uiout->impl->table_begin)
783 return;
784 uiout->impl->table_begin (uiout, nbrofcols, tblid);
785}
786
787void
788uo_table_body (struct ui_out *uiout)
789{
790 if (!uiout->impl->table_body)
791 return;
792 uiout->impl->table_body (uiout);
793}
794
795void
796uo_table_end (struct ui_out *uiout)
797{
798 if (!uiout->impl->table_end)
799 return;
800 uiout->impl->table_end (uiout);
801}
802
803void
804uo_table_header (struct ui_out *uiout, int width, enum ui_align align, char *colhdr)
805{
806 if (!uiout->impl->table_header)
807 return;
808 uiout->impl->table_header (uiout, width, align, colhdr);
809}
810
811void
631ec795
AC
812uo_begin (struct ui_out *uiout,
813 enum ui_out_type type,
814 int level,
815 const char *id)
8b93c638 816{
631ec795 817 if (uiout->impl->begin == NULL)
8b93c638 818 return;
631ec795 819 uiout->impl->begin (uiout, type, level, id);
8b93c638
JM
820}
821
822void
631ec795
AC
823uo_end (struct ui_out *uiout,
824 enum ui_out_type type,
825 int level)
8b93c638 826{
631ec795 827 if (uiout->impl->end == NULL)
8b93c638 828 return;
631ec795 829 uiout->impl->end (uiout, type, level);
8b93c638
JM
830}
831
832void
833uo_field_int (struct ui_out *uiout, int fldno, int width, enum ui_align align, char *fldname, int value)
834{
835 if (!uiout->impl->field_int)
836 return;
837 uiout->impl->field_int (uiout, fldno, width, align, fldname, value);
838}
839
840void
841uo_field_skip (struct ui_out *uiout, int fldno, int width, enum ui_align align, char *fldname)
842{
843 if (!uiout->impl->field_skip)
844 return;
845 uiout->impl->field_skip (uiout, fldno, width, align, fldname);
846}
847
848void
849uo_field_string (struct ui_out *uiout, int fldno, int width,
850 enum ui_align align, char *fldname, const char *string)
851{
852 if (!uiout->impl->field_string)
853 return;
854 uiout->impl->field_string (uiout, fldno, width, align, fldname, string);
855}
856
857void
858uo_field_fmt (struct ui_out *uiout, int fldno, int width, enum ui_align align, char *fldname, char *format, va_list args)
859{
860 if (!uiout->impl->field_fmt)
861 return;
862 uiout->impl->field_fmt (uiout, fldno, width, align, fldname, format, args);
863}
864
865void
866uo_spaces (struct ui_out *uiout, int numspaces)
867{
868 if (!uiout->impl->spaces)
869 return;
870 uiout->impl->spaces (uiout, numspaces);
871}
872
873void
874uo_text (struct ui_out *uiout, char *string)
875{
876 if (!uiout->impl->text)
877 return;
878 uiout->impl->text (uiout, string);
879}
880
881void
882uo_message (struct ui_out *uiout, int verbosity, char *format, va_list args)
883{
884 if (!uiout->impl->message)
885 return;
886 uiout->impl->message (uiout, verbosity, format, args);
887}
888
889void
890uo_wrap_hint (struct ui_out *uiout, char *identstring)
891{
892 if (!uiout->impl->wrap_hint)
893 return;
894 uiout->impl->wrap_hint (uiout, identstring);
895}
896
897void
898uo_flush (struct ui_out *uiout)
899{
900 if (!uiout->impl->flush)
901 return;
902 uiout->impl->flush (uiout);
903}
904
905/* local functions */
906
907/* list of column headers manipulation routines */
908
909static void
fba45db2 910clear_header_list (struct ui_out *uiout)
8b93c638
JM
911{
912 while (uiout->headerfirst != NULL)
913 {
914 uiout->headercurr = uiout->headerfirst;
915 uiout->headerfirst = uiout->headerfirst->next;
916 if (uiout->headercurr->colhdr != NULL)
b8c9b27d
KB
917 xfree (uiout->headercurr->colhdr);
918 xfree (uiout->headercurr);
8b93c638
JM
919 }
920 uiout->headerlast = NULL;
921 uiout->headercurr = NULL;
922}
923
924static void
925append_header_to_list (struct ui_out *uiout,
926 int width,
927 int alignment,
928 char *colhdr)
929{
930 struct ui_out_hdr *temphdr;
931
932 temphdr = XMALLOC (struct ui_out_hdr);
933 temphdr->width = width;
934 temphdr->alignment = alignment;
935 /* we have to copy the column title as the original may be an automatic */
936 if (colhdr != NULL)
937 {
938 temphdr->colhdr = xmalloc (strlen (colhdr) + 1);
939 strcpy (temphdr->colhdr, colhdr);
940 }
941 temphdr->next = NULL;
942 if (uiout->headerfirst == NULL)
943 {
944 temphdr->colno = 1;
945 uiout->headerfirst = temphdr;
946 uiout->headerlast = temphdr;
947 }
948 else
949 {
950 temphdr->colno = uiout->headerlast->colno + 1;
951 uiout->headerlast->next = temphdr;
952 uiout->headerlast = temphdr;
953 }
954 uiout->headercurr = uiout->headerlast;
955}
956
957/* returns 0 if there is no more headers */
958
959static int
960get_curr_header (struct ui_out *uiout,
961 int *colno,
962 int *width,
963 int *alignment,
964 char **colhdr)
965{
966 /* There may be no headers at all or we may have used all columns */
967 if (uiout->headercurr == NULL)
968 return 0;
969 *colno = uiout->headercurr->colno;
970 *width = uiout->headercurr->width;
971 *alignment = uiout->headercurr->alignment;
972 *colhdr = uiout->headercurr->colhdr;
973 uiout->headercurr = uiout->headercurr->next;
974 return 1;
975}
976
977/* makes sure the field_* calls were properly placed */
978
979static void
980verify_field_proper_position (struct ui_out *uiout)
981{
982 if (uiout->table_flag)
983 {
984 if (!uiout->body_flag)
8e65ff28
AC
985 internal_error (__FILE__, __LINE__,
986 "table_body missing; table fields must be \
8b93c638 987specified after table_body and inside a list.");
80f49b30 988 if (uiout->level == 0)
8e65ff28
AC
989 internal_error (__FILE__, __LINE__,
990 "list_begin missing; table fields must be \
8b93c638
JM
991specified after table_body and inside a list.");
992 }
993}
994
995/* determines what is the alignment policy */
996
997static void
998verify_field_alignment (struct ui_out *uiout,
999 int fldno,
1000 int *width,
1001 int *align)
1002{
1003 int colno;
1004 char *text;
1005
1006 if (uiout->table_flag
1007 && get_curr_header (uiout, &colno, width, align, &text))
1008 {
1009 if (fldno != colno)
8e65ff28
AC
1010 internal_error (__FILE__, __LINE__,
1011 "ui-out internal error in handling headers.");
8b93c638
JM
1012 }
1013 else
1014 {
1015 *width = 0;
1016 *align = ui_noalign;
1017 }
1018}
1019
1020/* access to ui_out format private members */
1021
1022void
fba45db2 1023ui_out_get_field_separator (struct ui_out *uiout)
8b93c638
JM
1024{
1025}
1026
1027/* Access to ui-out members data */
1028
1029struct ui_out_data *
1030ui_out_data (struct ui_out *uiout)
1031{
1032 return uiout->data;
1033}
1034
1035/* initalize private members at startup */
1036
1037struct ui_out *
1038ui_out_new (struct ui_out_impl *impl,
1039 struct ui_out_data *data,
1040 int flags)
1041{
1042 struct ui_out *uiout = XMALLOC (struct ui_out);
1043 uiout->data = data;
1044 uiout->impl = impl;
1045 uiout->flags = flags;
1046 uiout->table_flag = 0;
1047 uiout->body_flag = 0;
80f49b30
AC
1048 uiout->level = 0;
1049 memset (uiout->levels, 0, sizeof (uiout->levels));
8b93c638
JM
1050 uiout->headerfirst = NULL;
1051 uiout->headerlast = NULL;
1052 uiout->headercurr = NULL;
1053 return uiout;
1054}
1055
1056/* standard gdb initialization hook */
1057
1058void
fba45db2 1059_initialize_ui_out (void)
8b93c638
JM
1060{
1061 /* nothing needs to be done */
1062}
This page took 0.180387 seconds and 4 git commands to generate.