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