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