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