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