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