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