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