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