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