s/char */const char */
[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 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 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 const char *tblid)
260 {
261 if (uiout->table_flag)
262 internal_error (__FILE__, __LINE__,
263 "tables cannot be nested; table_begin found before \
264 previous 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
277 void
278 ui_out_table_body (struct ui_out *uiout)
279 {
280 if (!uiout->table_flag)
281 internal_error (__FILE__, __LINE__,
282 "table_body outside a table is not valid; it must be \
283 after a table_begin and before a table_end.");
284 if (uiout->body_flag)
285 internal_error (__FILE__, __LINE__,
286 "extra table_body call not allowed; there must be \
287 only one table_body after a table_begin and before a table_end.");
288 if (uiout->headercurr->colno != uiout->table_columns)
289 internal_error (__FILE__, __LINE__,
290 "number of headers differ from number of table \
291 columns.");
292
293 uiout->body_flag = 1;
294 uiout->headercurr = uiout->headerfirst;
295
296 uo_table_body (uiout);
297 }
298
299 void
300 ui_out_table_end (struct ui_out *uiout)
301 {
302 if (!uiout->table_flag)
303 internal_error (__FILE__, __LINE__,
304 "misplaced table_end or missing table_begin.");
305
306 uiout->body_flag = 0;
307 uiout->table_flag = 0;
308
309 uo_table_end (uiout);
310
311 if (uiout->table_id)
312 xfree (uiout->table_id);
313 clear_header_list (uiout);
314 }
315
316 void
317 ui_out_table_header (struct ui_out *uiout, int width, enum ui_align alignment,
318 const char *colhdr)
319 {
320 if (!uiout->table_flag || uiout->body_flag)
321 internal_error (__FILE__, __LINE__,
322 "table header must be specified after table_begin \
323 and before table_body.");
324
325 append_header_to_list (uiout, width, alignment, colhdr);
326
327 uo_table_header (uiout, width, alignment, colhdr);
328 }
329
330 void
331 ui_out_begin (struct ui_out *uiout,
332 enum ui_out_type type,
333 const char *id)
334 {
335 int new_level;
336 if (uiout->table_flag && !uiout->body_flag)
337 internal_error (__FILE__, __LINE__,
338 "table header or table_body expected; lists must be \
339 specified after table_body.");
340 new_level = push_level (uiout, type, id);
341 if (uiout->table_flag && (new_level == 1))
342 uiout->headercurr = uiout->headerfirst;
343 uo_begin (uiout, type, new_level, id);
344 }
345
346 void
347 ui_out_list_begin (struct ui_out *uiout)
348 {
349 ui_out_begin (uiout, ui_out_type_list, NULL);
350 }
351
352 void
353 ui_out_tuple_begin (struct ui_out *uiout, const char *id)
354 {
355 ui_out_begin (uiout, ui_out_type_tuple, id);
356 }
357
358 void
359 ui_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);
364 }
365
366 void
367 ui_out_list_end (struct ui_out *uiout)
368 {
369 ui_out_end (uiout, ui_out_type_list);
370 }
371
372 void
373 ui_out_tuple_end (struct ui_out *uiout)
374 {
375 ui_out_end (uiout, ui_out_type_tuple);
376 }
377
378 struct ui_out_end_cleanup_data
379 {
380 struct ui_out *uiout;
381 enum ui_out_type type;
382 };
383
384 static void
385 do_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
392 static struct cleanup *
393 make_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
403 struct cleanup *
404 make_cleanup_ui_out_begin_end (struct ui_out *uiout,
405 enum ui_out_type type,
406 const char *id)
407 {
408 ui_out_begin (uiout, type, id);
409 return make_cleanup_ui_out_end (uiout, type);
410 }
411
412 struct cleanup *
413 make_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
420 struct cleanup *
421 make_cleanup_ui_out_list_begin_end (struct ui_out *uiout)
422 {
423 return make_cleanup_ui_out_end (uiout, ui_out_type_list);
424 }
425
426 void
427 ui_out_field_int (struct ui_out *uiout,
428 const char *fldname,
429 int value)
430 {
431 int fldno;
432 int width;
433 int align;
434 struct ui_out_level *current = current_level (uiout);
435
436 verify_field_proper_position (uiout);
437
438 current->field_count += 1;
439 fldno = current->field_count;
440
441 verify_field_alignment (uiout, fldno, &width, &align);
442
443 uo_field_int (uiout, fldno, width, align, fldname, value);
444 }
445
446 void
447 ui_out_field_core_addr (struct ui_out *uiout,
448 const char *fldname,
449 CORE_ADDR address)
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
460 void
461 ui_out_field_stream (struct ui_out *uiout,
462 const char *fldname,
463 struct ui_stream *buf)
464 {
465 long length;
466 char *buffer = ui_file_xstrdup (buf->stream, &length);
467 struct cleanup *old_cleanup = make_cleanup (xfree, buffer);
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
478 void
479 ui_out_field_skip (struct ui_out *uiout,
480 const char *fldname)
481 {
482 int fldno;
483 int width;
484 int align;
485 struct ui_out_level *current = current_level (uiout);
486
487 verify_field_proper_position (uiout);
488
489 current->field_count += 1;
490 fldno = current->field_count;
491
492 verify_field_alignment (uiout, fldno, &width, &align);
493
494 uo_field_skip (uiout, fldno, width, align, fldname);
495 }
496
497 void
498 ui_out_field_string (struct ui_out *uiout,
499 const char *fldname,
500 const char *string)
501 {
502 int fldno;
503 int width;
504 int align;
505 struct ui_out_level *current = current_level (uiout);
506
507 verify_field_proper_position (uiout);
508
509 current->field_count += 1;
510 fldno = current->field_count;
511
512 verify_field_alignment (uiout, fldno, &width, &align);
513
514 uo_field_string (uiout, fldno, width, align, fldname, string);
515 }
516
517 /* VARARGS */
518 void
519 ui_out_field_fmt (struct ui_out *uiout,
520 const char *fldname,
521 const char *format, ...)
522 {
523 va_list args;
524 int fldno;
525 int width;
526 int align;
527 struct ui_out_level *current = current_level (uiout);
528
529 verify_field_proper_position (uiout);
530
531 current->field_count += 1;
532 fldno = current->field_count;
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
544 void
545 ui_out_spaces (struct ui_out *uiout, int numspaces)
546 {
547 uo_spaces (uiout, numspaces);
548 }
549
550 void
551 ui_out_text (struct ui_out *uiout,
552 const char *string)
553 {
554 uo_text (uiout, string);
555 }
556
557 void
558 ui_out_message (struct ui_out *uiout, int verbosity,
559 const char *format,...)
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
570 struct ui_stream *
571 ui_out_stream_new (struct ui_out *uiout)
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
581 void
582 ui_out_stream_delete (struct ui_stream *buf)
583 {
584 ui_file_delete (buf->stream);
585 xfree (buf);
586 }
587
588 static void
589 do_stream_delete (void *buf)
590 {
591 ui_out_stream_delete (buf);
592 }
593
594 struct cleanup *
595 make_cleanup_ui_out_stream_delete (struct ui_stream *buf)
596 {
597 return make_cleanup (do_stream_delete, buf);
598 }
599
600
601 void
602 ui_out_wrap_hint (struct ui_out *uiout, char *identstring)
603 {
604 uo_wrap_hint (uiout, identstring);
605 }
606
607 void
608 ui_out_flush (struct ui_out *uiout)
609 {
610 uo_flush (uiout);
611 }
612
613 /* set the flags specified by the mask given */
614 int
615 ui_out_set_flags (struct ui_out *uiout, int mask)
616 {
617 int oldflags = uiout->flags;
618
619 uiout->flags |= mask;
620
621 return oldflags;
622 }
623
624 /* clear the flags specified by the mask given */
625 int
626 ui_out_clear_flags (struct ui_out *uiout, int mask)
627 {
628 int oldflags = uiout->flags;
629
630 uiout->flags &= ~mask;
631
632 return oldflags;
633 }
634
635 /* test the flags against the mask given */
636 int
637 ui_out_test_flags (struct ui_out *uiout, int mask)
638 {
639 return (uiout->flags & mask);
640 }
641
642 /* obtain the current verbosity level (as stablished by the
643 'set verbositylevel' command */
644
645 int
646 ui_out_get_verblvl (struct ui_out *uiout)
647 {
648 /* FIXME: not implemented yet */
649 return 0;
650 }
651
652 #if 0
653 void
654 ui_out_result_begin (struct ui_out *uiout, char *class)
655 {
656 }
657
658 void
659 ui_out_result_end (struct ui_out *uiout)
660 {
661 }
662
663 void
664 ui_out_info_begin (struct ui_out *uiout, char *class)
665 {
666 }
667
668 void
669 ui_out_info_end (struct ui_out *uiout)
670 {
671 }
672
673 void
674 ui_out_notify_begin (struct ui_out *uiout, char *class)
675 {
676 }
677
678 void
679 ui_out_notify_end (struct ui_out *uiout)
680 {
681 }
682
683 void
684 ui_out_error_begin (struct ui_out *uiout, char *class)
685 {
686 }
687
688 void
689 ui_out_error_end (struct ui_out *uiout)
690 {
691 }
692 #endif
693
694 #if 0
695 void
696 gdb_error (ui_out * uiout, int severity, char *format,...)
697 {
698 va_list args;
699 }
700
701 void
702 gdb_query (struct ui_out *uiout, int qflags, char *qprompt)
703 {
704 }
705 #endif
706
707 /* default gdb-out hook functions */
708
709 static void
710 default_table_begin (struct ui_out *uiout, int nbrofcols, const char *tblid)
711 {
712 }
713
714 static void
715 default_table_body (struct ui_out *uiout)
716 {
717 }
718
719 static void
720 default_table_end (struct ui_out *uiout)
721 {
722 }
723
724 static void
725 default_table_header (struct ui_out *uiout, int width, enum ui_align alignment,
726 const char *colhdr)
727 {
728 }
729
730 static void
731 default_begin (struct ui_out *uiout,
732 enum ui_out_type type,
733 int level,
734 const char *id)
735 {
736 }
737
738 static void
739 default_end (struct ui_out *uiout,
740 enum ui_out_type type,
741 int level)
742 {
743 }
744
745 static void
746 default_field_int (struct ui_out *uiout, int fldno, int width,
747 enum ui_align align,
748 const char *fldname, int value)
749 {
750 }
751
752 static void
753 default_field_skip (struct ui_out *uiout, int fldno, int width,
754 enum ui_align align, const char *fldname)
755 {
756 }
757
758 static void
759 default_field_string (struct ui_out *uiout,
760 int fldno,
761 int width,
762 enum ui_align align,
763 const char *fldname,
764 const char *string)
765 {
766 }
767
768 static void
769 default_field_fmt (struct ui_out *uiout, int fldno, int width,
770 enum ui_align align,
771 const char *fldname,
772 const char *format,
773 va_list args)
774 {
775 }
776
777 static void
778 default_spaces (struct ui_out *uiout, int numspaces)
779 {
780 }
781
782 static void
783 default_text (struct ui_out *uiout, const char *string)
784 {
785 }
786
787 static void
788 default_message (struct ui_out *uiout, int verbosity,
789 const char *format,
790 va_list args)
791 {
792 }
793
794 static void
795 default_wrap_hint (struct ui_out *uiout, char *identstring)
796 {
797 }
798
799 static void
800 default_flush (struct ui_out *uiout)
801 {
802 }
803
804 /* Interface to the implementation functions */
805
806 void
807 uo_table_begin (struct ui_out *uiout, int nbrofcols,
808 const char *tblid)
809 {
810 if (!uiout->impl->table_begin)
811 return;
812 uiout->impl->table_begin (uiout, nbrofcols, tblid);
813 }
814
815 void
816 uo_table_body (struct ui_out *uiout)
817 {
818 if (!uiout->impl->table_body)
819 return;
820 uiout->impl->table_body (uiout);
821 }
822
823 void
824 uo_table_end (struct ui_out *uiout)
825 {
826 if (!uiout->impl->table_end)
827 return;
828 uiout->impl->table_end (uiout);
829 }
830
831 void
832 uo_table_header (struct ui_out *uiout, int width, enum ui_align align,
833 const char *colhdr)
834 {
835 if (!uiout->impl->table_header)
836 return;
837 uiout->impl->table_header (uiout, width, align, colhdr);
838 }
839
840 void
841 uo_begin (struct ui_out *uiout,
842 enum ui_out_type type,
843 int level,
844 const char *id)
845 {
846 if (uiout->impl->begin == NULL)
847 return;
848 uiout->impl->begin (uiout, type, level, id);
849 }
850
851 void
852 uo_end (struct ui_out *uiout,
853 enum ui_out_type type,
854 int level)
855 {
856 if (uiout->impl->end == NULL)
857 return;
858 uiout->impl->end (uiout, type, level);
859 }
860
861 void
862 uo_field_int (struct ui_out *uiout, int fldno, int width, enum ui_align align,
863 const char *fldname,
864 int value)
865 {
866 if (!uiout->impl->field_int)
867 return;
868 uiout->impl->field_int (uiout, fldno, width, align, fldname, value);
869 }
870
871 void
872 uo_field_skip (struct ui_out *uiout, int fldno, int width, enum ui_align align,
873 const char *fldname)
874 {
875 if (!uiout->impl->field_skip)
876 return;
877 uiout->impl->field_skip (uiout, fldno, width, align, fldname);
878 }
879
880 void
881 uo_field_string (struct ui_out *uiout, int fldno, int width,
882 enum ui_align align,
883 const char *fldname,
884 const char *string)
885 {
886 if (!uiout->impl->field_string)
887 return;
888 uiout->impl->field_string (uiout, fldno, width, align, fldname, string);
889 }
890
891 void
892 uo_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)
896 {
897 if (!uiout->impl->field_fmt)
898 return;
899 uiout->impl->field_fmt (uiout, fldno, width, align, fldname, format, args);
900 }
901
902 void
903 uo_spaces (struct ui_out *uiout, int numspaces)
904 {
905 if (!uiout->impl->spaces)
906 return;
907 uiout->impl->spaces (uiout, numspaces);
908 }
909
910 void
911 uo_text (struct ui_out *uiout,
912 const char *string)
913 {
914 if (!uiout->impl->text)
915 return;
916 uiout->impl->text (uiout, string);
917 }
918
919 void
920 uo_message (struct ui_out *uiout, int verbosity,
921 const char *format,
922 va_list args)
923 {
924 if (!uiout->impl->message)
925 return;
926 uiout->impl->message (uiout, verbosity, format, args);
927 }
928
929 void
930 uo_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
937 void
938 uo_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
949 static void
950 clear_header_list (struct ui_out *uiout)
951 {
952 while (uiout->headerfirst != NULL)
953 {
954 uiout->headercurr = uiout->headerfirst;
955 uiout->headerfirst = uiout->headerfirst->next;
956 if (uiout->headercurr->colhdr != NULL)
957 xfree (uiout->headercurr->colhdr);
958 xfree (uiout->headercurr);
959 }
960 uiout->headerlast = NULL;
961 uiout->headercurr = NULL;
962 }
963
964 static void
965 append_header_to_list (struct ui_out *uiout,
966 int width,
967 int alignment,
968 const char *colhdr)
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
999 static int
1000 get_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
1019 static void
1020 verify_field_proper_position (struct ui_out *uiout)
1021 {
1022 if (uiout->table_flag)
1023 {
1024 if (!uiout->body_flag)
1025 internal_error (__FILE__, __LINE__,
1026 "table_body missing; table fields must be \
1027 specified after table_body and inside a list.");
1028 if (uiout->level == 0)
1029 internal_error (__FILE__, __LINE__,
1030 "list_begin missing; table fields must be \
1031 specified after table_body and inside a list.");
1032 }
1033 }
1034
1035 /* determines what is the alignment policy */
1036
1037 static void
1038 verify_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)
1050 internal_error (__FILE__, __LINE__,
1051 "ui-out internal error in handling headers.");
1052 }
1053 else
1054 {
1055 *width = 0;
1056 *align = ui_noalign;
1057 }
1058 }
1059
1060 /* access to ui_out format private members */
1061
1062 void
1063 ui_out_get_field_separator (struct ui_out *uiout)
1064 {
1065 }
1066
1067 /* Access to ui-out members data */
1068
1069 struct ui_out_data *
1070 ui_out_data (struct ui_out *uiout)
1071 {
1072 return uiout->data;
1073 }
1074
1075 /* initalize private members at startup */
1076
1077 struct ui_out *
1078 ui_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;
1088 uiout->level = 0;
1089 memset (uiout->levels, 0, sizeof (uiout->levels));
1090 uiout->headerfirst = NULL;
1091 uiout->headerlast = NULL;
1092 uiout->headercurr = NULL;
1093 return uiout;
1094 }
1095
1096 /* standard gdb initialization hook */
1097
1098 void
1099 _initialize_ui_out (void)
1100 {
1101 /* nothing needs to be done */
1102 }