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