* elf32-ppc.h: New file.
[deliverable/binutils-gdb.git] / gdb / ui-out.c
CommitLineData
8b93c638 1/* Output generating routines for GDB.
349c5d5f
AC
2
3 Copyright 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
4
8b93c638
JM
5 Contributed by Cygnus Solutions.
6 Written by Fernando Nasser for Cygnus.
7
8 This file is part of GDB.
9
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA. */
24
25#include "defs.h"
26#include "gdb_string.h"
27#include "expression.h" /* For language.h */
28#include "language.h"
29#include "ui-out.h"
80f49b30 30#include "gdb_assert.h"
8b93c638 31
8b93c638
JM
32/* table header structures */
33
34struct ui_out_hdr
35 {
36 int colno;
37 int width;
38 int alignment;
b25959ec 39 char *col_name;
8b93c638
JM
40 char *colhdr;
41 struct ui_out_hdr *next;
42 };
43
80f49b30
AC
44/* Maintain a stack so that the info applicable to the inner most list
45 is always available. Stack/nested level 0 is reserved for the
46 top-level result. */
47
a3edc55b 48enum { MAX_UI_OUT_LEVELS = 6 };
80f49b30
AC
49
50struct ui_out_level
51 {
52 /* Count each field; the first element is for non-list fields */
53 int field_count;
631ec795
AC
54 /* The type of this level. */
55 enum ui_out_type type;
80f49b30
AC
56 };
57
bafdd3b3
AC
58/* Tables are special. Maintain a separate structure that tracks
59 their state. At present an output can only contain a single table
60 but that restriction might eventually be lifted. */
61
62struct ui_out_table
63{
64 /* If on, a table is being generated. */
65 int flag;
66
67 /* If on, the body of a table is being generated. If off, the table
68 header is being generated. */
69 int body_flag;
70
a6c47c14
AC
71 /* The level at which each entry of the table is to be found. A row
72 (a tuple) is made up of entries. Consequently ENTRY_LEVEL is one
73 above that of the table. */
74 int entry_level;
75
bafdd3b3
AC
76 /* Number of table columns (as specified in the table_begin call). */
77 int columns;
78
79 /* String identifying the table (as specified in the table_begin
80 call). */
81 char *id;
82
83 /* Points to the first table header (if any). */
84 struct ui_out_hdr *header_first;
85
86 /* Points to the last table header (if any). */
87 struct ui_out_hdr *header_last;
88
89 /* Points to header of NEXT column to format. */
90 struct ui_out_hdr *header_next;
91
92};
93
94
8b93c638
JM
95/* The ui_out structure */
96/* Any change here requires a corresponding one in the initialization
97 of the default uiout, which is statically initialized */
98
99struct ui_out
100 {
101 int flags;
102 /* specific implementation of ui-out */
103 struct ui_out_impl *impl;
104 struct ui_out_data *data;
105
bafdd3b3 106 /* Sub structure tracking the ui-out depth. */
80f49b30
AC
107 int level;
108 struct ui_out_level levels[MAX_UI_OUT_LEVELS];
8b93c638 109
bafdd3b3
AC
110 /* A table, if any. At present only a single table is supported. */
111 struct ui_out_table table;
8b93c638
JM
112 };
113
80f49b30
AC
114/* The current (inner most) level. */
115static struct ui_out_level *
116current_level (struct ui_out *uiout)
117{
118 return &uiout->levels[uiout->level];
119}
120
121/* Create a new level, of TYPE. Return the new level's index. */
122static int
123push_level (struct ui_out *uiout,
631ec795 124 enum ui_out_type type,
80f49b30
AC
125 const char *id)
126{
127 struct ui_out_level *current;
128 /* We had better not overflow the buffer. */
129 uiout->level++;
631ec795 130 gdb_assert (uiout->level >= 0 && uiout->level < MAX_UI_OUT_LEVELS);
80f49b30
AC
131 current = current_level (uiout);
132 current->field_count = 0;
631ec795 133 current->type = type;
80f49b30
AC
134 return uiout->level;
135}
136
137/* Discard the current level, return the discarded level's index.
138 TYPE is the type of the level being discarded. */
139static int
631ec795
AC
140pop_level (struct ui_out *uiout,
141 enum ui_out_type type)
80f49b30
AC
142{
143 /* We had better not underflow the buffer. */
144 gdb_assert (uiout->level > 0 && uiout->level < MAX_UI_OUT_LEVELS);
631ec795 145 gdb_assert (current_level (uiout)->type == type);
80f49b30
AC
146 uiout->level--;
147 return uiout->level + 1;
148}
149
150
8b93c638
JM
151/* These are the default implementation functions */
152
153static void default_table_begin (struct ui_out *uiout, int nbrofcols,
d63f1d40 154 int nr_rows, const char *tblid);
8b93c638
JM
155static void default_table_body (struct ui_out *uiout);
156static void default_table_end (struct ui_out *uiout);
157static void default_table_header (struct ui_out *uiout, int width,
b25959ec 158 enum ui_align alig, const char *col_name,
e2e11a41 159 const char *colhdr);
631ec795
AC
160static void default_begin (struct ui_out *uiout,
161 enum ui_out_type type,
162 int level, const char *id);
163static void default_end (struct ui_out *uiout,
164 enum ui_out_type type,
165 int level);
8b93c638 166static void default_field_int (struct ui_out *uiout, int fldno, int width,
e2e11a41
AC
167 enum ui_align alig,
168 const char *fldname,
169 int value);
8b93c638 170static void default_field_skip (struct ui_out *uiout, int fldno, int width,
e2e11a41
AC
171 enum ui_align alig,
172 const char *fldname);
8b93c638 173static void default_field_string (struct ui_out *uiout, int fldno, int width,
e2e11a41
AC
174 enum ui_align align,
175 const char *fldname,
8b93c638
JM
176 const char *string);
177static void default_field_fmt (struct ui_out *uiout, int fldno,
178 int width, enum ui_align align,
e2e11a41
AC
179 const char *fldname,
180 const char *format,
181 va_list args);
8b93c638 182static void default_spaces (struct ui_out *uiout, int numspaces);
e2e11a41
AC
183static void default_text (struct ui_out *uiout, const char *string);
184static void default_message (struct ui_out *uiout, int verbosity,
185 const char *format,
8b93c638
JM
186 va_list args);
187static void default_wrap_hint (struct ui_out *uiout, char *identstring);
188static void default_flush (struct ui_out *uiout);
189
190/* This is the default ui-out implementation functions vector */
191
192struct ui_out_impl default_ui_out_impl =
193{
194 default_table_begin,
195 default_table_body,
196 default_table_end,
197 default_table_header,
631ec795
AC
198 default_begin,
199 default_end,
8b93c638
JM
200 default_field_int,
201 default_field_skip,
202 default_field_string,
203 default_field_fmt,
204 default_spaces,
205 default_text,
206 default_message,
207 default_wrap_hint,
9dc5e2a9
AC
208 default_flush,
209 0, /* Does not need MI hacks. */
8b93c638
JM
210};
211
212/* The default ui_out */
213
214struct ui_out def_uiout =
215{
216 0, /* flags */
217 &default_ui_out_impl, /* impl */
218};
219
220/* Pointer to current ui_out */
221/* FIXME: This should not be a global, but something passed down from main.c
222 or top.c */
223
224struct ui_out *uiout = &def_uiout;
225
226/* These are the interfaces to implementation functions */
227
88379baf 228static void uo_table_begin (struct ui_out *uiout, int nbrofcols,
d63f1d40 229 int nr_rows, const char *tblid);
8b93c638
JM
230static void uo_table_body (struct ui_out *uiout);
231static void uo_table_end (struct ui_out *uiout);
232static void uo_table_header (struct ui_out *uiout, int width,
b25959ec
AC
233 enum ui_align align, const char *col_name,
234 const char *colhdr);
631ec795
AC
235static void uo_begin (struct ui_out *uiout,
236 enum ui_out_type type,
237 int level, const char *id);
238static void uo_end (struct ui_out *uiout,
239 enum ui_out_type type,
240 int level);
8b93c638 241static void uo_field_int (struct ui_out *uiout, int fldno, int width,
88379baf 242 enum ui_align align, const char *fldname, int value);
8b93c638 243static void uo_field_skip (struct ui_out *uiout, int fldno, int width,
88379baf 244 enum ui_align align, const char *fldname);
8b93c638 245static void uo_field_string (struct ui_out *uiout, int fldno, int width,
88379baf
AC
246 enum ui_align align, const char *fldname,
247 const char *string);
8b93c638 248static void uo_field_fmt (struct ui_out *uiout, int fldno, int width,
88379baf
AC
249 enum ui_align align, const char *fldname,
250 const char *format, va_list args);
8b93c638 251static void uo_spaces (struct ui_out *uiout, int numspaces);
88379baf 252static void uo_text (struct ui_out *uiout, const char *string);
8b93c638 253static void uo_message (struct ui_out *uiout, int verbosity,
88379baf 254 const char *format, va_list args);
8b93c638
JM
255static void uo_wrap_hint (struct ui_out *uiout, char *identstring);
256static void uo_flush (struct ui_out *uiout);
257
258/* Prototypes for local functions */
259
260extern void _initialize_ui_out (void);
88379baf 261static void append_header_to_list (struct ui_out *uiout, int width,
b25959ec
AC
262 int alignment, const char *col_name,
263 const char *colhdr);
bafdd3b3 264static int get_next_header (struct ui_out *uiout, int *colno, int *width,
8b93c638
JM
265 int *alignment, char **colhdr);
266static void clear_header_list (struct ui_out *uiout);
a6c47c14
AC
267static void verify_field (struct ui_out *uiout, int *fldno, int *width,
268 int *align);
8b93c638
JM
269
270static void init_ui_out_state (struct ui_out *uiout);
271
272/* exported functions (ui_out API) */
273
274/* Mark beginning of a table */
275
3b31d625 276static void
88379baf 277ui_out_table_begin (struct ui_out *uiout, int nbrofcols,
d63f1d40 278 int nr_rows,
88379baf 279 const char *tblid)
8b93c638 280{
bafdd3b3 281 if (uiout->table.flag)
8e65ff28
AC
282 internal_error (__FILE__, __LINE__,
283 "tables cannot be nested; table_begin found before \
8b93c638
JM
284previous table_end.");
285
bafdd3b3
AC
286 uiout->table.flag = 1;
287 uiout->table.body_flag = 0;
a6c47c14 288 uiout->table.entry_level = uiout->level + 1;
bafdd3b3 289 uiout->table.columns = nbrofcols;
8b93c638 290 if (tblid != NULL)
bafdd3b3 291 uiout->table.id = xstrdup (tblid);
8b93c638 292 else
bafdd3b3 293 uiout->table.id = NULL;
8b93c638
JM
294 clear_header_list (uiout);
295
bafdd3b3 296 uo_table_begin (uiout, nbrofcols, nr_rows, uiout->table.id);
8b93c638
JM
297}
298
299void
fba45db2 300ui_out_table_body (struct ui_out *uiout)
8b93c638 301{
bafdd3b3 302 if (!uiout->table.flag)
8e65ff28
AC
303 internal_error (__FILE__, __LINE__,
304 "table_body outside a table is not valid; it must be \
8b93c638 305after a table_begin and before a table_end.");
bafdd3b3 306 if (uiout->table.body_flag)
8e65ff28
AC
307 internal_error (__FILE__, __LINE__,
308 "extra table_body call not allowed; there must be \
8b93c638 309only one table_body after a table_begin and before a table_end.");
bafdd3b3 310 if (uiout->table.header_next->colno != uiout->table.columns)
8e65ff28
AC
311 internal_error (__FILE__, __LINE__,
312 "number of headers differ from number of table \
8b93c638
JM
313columns.");
314
bafdd3b3
AC
315 uiout->table.body_flag = 1;
316 uiout->table.header_next = uiout->table.header_first;
8b93c638
JM
317
318 uo_table_body (uiout);
319}
320
3b31d625 321static void
fba45db2 322ui_out_table_end (struct ui_out *uiout)
8b93c638 323{
bafdd3b3 324 if (!uiout->table.flag)
8e65ff28
AC
325 internal_error (__FILE__, __LINE__,
326 "misplaced table_end or missing table_begin.");
8b93c638 327
a6c47c14 328 uiout->table.entry_level = 0;
bafdd3b3
AC
329 uiout->table.body_flag = 0;
330 uiout->table.flag = 0;
8b93c638
JM
331
332 uo_table_end (uiout);
333
bafdd3b3
AC
334 if (uiout->table.id)
335 xfree (uiout->table.id);
8b93c638
JM
336 clear_header_list (uiout);
337}
338
339void
fba45db2 340ui_out_table_header (struct ui_out *uiout, int width, enum ui_align alignment,
b25959ec 341 const char *col_name,
88379baf 342 const char *colhdr)
8b93c638 343{
bafdd3b3 344 if (!uiout->table.flag || uiout->table.body_flag)
8e65ff28
AC
345 internal_error (__FILE__, __LINE__,
346 "table header must be specified after table_begin \
8b93c638
JM
347and before table_body.");
348
b25959ec 349 append_header_to_list (uiout, width, alignment, col_name, colhdr);
8b93c638 350
b25959ec 351 uo_table_header (uiout, width, alignment, col_name, colhdr);
8b93c638
JM
352}
353
3b31d625
EZ
354static void
355do_cleanup_table_end (void *data)
356{
357 struct ui_out *ui_out = data;
358
359 ui_out_table_end (ui_out);
360}
361
362struct cleanup *
363make_cleanup_ui_out_table_begin_end (struct ui_out *ui_out, int nr_cols,
364 int nr_rows, const char *tblid)
365{
366 ui_out_table_begin (ui_out, nr_cols, nr_rows, tblid);
367 return make_cleanup (do_cleanup_table_end, ui_out);
368}
369
8b93c638 370void
631ec795
AC
371ui_out_begin (struct ui_out *uiout,
372 enum ui_out_type type,
373 const char *id)
8b93c638 374{
80f49b30 375 int new_level;
bafdd3b3 376 if (uiout->table.flag && !uiout->table.body_flag)
8e65ff28
AC
377 internal_error (__FILE__, __LINE__,
378 "table header or table_body expected; lists must be \
8b93c638 379specified after table_body.");
a6c47c14
AC
380
381 /* Be careful to verify the ``field'' before the new tuple/list is
382 pushed onto the stack. That way the containing list/table/row is
383 verified and not the newly created tuple/list. This verification
384 is needed (at least) for the case where a table row entry
385 contains either a tuple/list. For that case bookkeeping such as
386 updating the column count or advancing to the next heading still
387 needs to be performed. */
388 {
389 int fldno;
390 int width;
391 int align;
392 verify_field (uiout, &fldno, &width, &align);
393 }
394
631ec795 395 new_level = push_level (uiout, type, id);
a6c47c14
AC
396
397 /* If the push puts us at the same level as a table row entry, we've
398 got a new table row. Put the header pointer back to the start. */
399 if (uiout->table.body_flag
400 && uiout->table.entry_level == new_level)
bafdd3b3 401 uiout->table.header_next = uiout->table.header_first;
a6c47c14 402
631ec795
AC
403 uo_begin (uiout, type, new_level, id);
404}
405
631ec795
AC
406void
407ui_out_end (struct ui_out *uiout,
408 enum ui_out_type type)
409{
410 int old_level = pop_level (uiout, type);
411 uo_end (uiout, type, old_level);
8b93c638
JM
412}
413
127431f9
AC
414struct ui_out_end_cleanup_data
415{
416 struct ui_out *uiout;
417 enum ui_out_type type;
418};
419
e6e0bfab 420static void
127431f9
AC
421do_cleanup_end (void *data)
422{
423 struct ui_out_end_cleanup_data *end_cleanup_data = data;
424 ui_out_end (end_cleanup_data->uiout, end_cleanup_data->type);
425 xfree (end_cleanup_data);
426}
427
428static struct cleanup *
429make_cleanup_ui_out_end (struct ui_out *uiout,
430 enum ui_out_type type)
431{
432 struct ui_out_end_cleanup_data *end_cleanup_data;
433 end_cleanup_data = XMALLOC (struct ui_out_end_cleanup_data);
434 end_cleanup_data->uiout = uiout;
435 end_cleanup_data->type = type;
436 return make_cleanup (do_cleanup_end, end_cleanup_data);
437}
438
439struct cleanup *
440make_cleanup_ui_out_begin_end (struct ui_out *uiout,
441 enum ui_out_type type,
442 const char *id)
e6e0bfab 443{
127431f9
AC
444 ui_out_begin (uiout, type, id);
445 return make_cleanup_ui_out_end (uiout, type);
e6e0bfab
MK
446}
447
448struct cleanup *
666547aa
AC
449make_cleanup_ui_out_tuple_begin_end (struct ui_out *uiout,
450 const char *id)
451{
3b31d625 452 ui_out_begin (uiout, ui_out_type_tuple, id);
666547aa
AC
453 return make_cleanup_ui_out_end (uiout, ui_out_type_tuple);
454}
455
456struct cleanup *
6b28c186
AC
457make_cleanup_ui_out_list_begin_end (struct ui_out *uiout,
458 const char *id)
e6e0bfab 459{
3b31d625 460 ui_out_begin (uiout, ui_out_type_list, id);
127431f9 461 return make_cleanup_ui_out_end (uiout, ui_out_type_list);
e6e0bfab
MK
462}
463
8b93c638 464void
88379baf
AC
465ui_out_field_int (struct ui_out *uiout,
466 const char *fldname,
467 int value)
8b93c638
JM
468{
469 int fldno;
470 int width;
471 int align;
80f49b30 472 struct ui_out_level *current = current_level (uiout);
8b93c638 473
a6c47c14 474 verify_field (uiout, &fldno, &width, &align);
8b93c638
JM
475
476 uo_field_int (uiout, fldno, width, align, fldname, value);
477}
478
52c6a6ac
JJ
479void
480ui_out_field_fmt_int (struct ui_out *uiout,
481 int input_width,
482 enum ui_align input_align,
483 const char *fldname,
484 int value)
485{
486 int fldno;
487 int width;
488 int align;
489 struct ui_out_level *current = current_level (uiout);
490
491 verify_field (uiout, &fldno, &width, &align);
492
493 uo_field_int (uiout, fldno, input_width, input_align, fldname, value);
494}
495
8b93c638 496void
88379baf
AC
497ui_out_field_core_addr (struct ui_out *uiout,
498 const char *fldname,
499 CORE_ADDR address)
8b93c638
JM
500{
501 char addstr[20];
502
535c96ce
AC
503 /* FIXME: cagney/2002-05-03: Need local_address_string() function
504 that returns the language localized string formatted to a width
505 based on TARGET_ADDR_BIT. */
8b93c638 506 /* print_address_numeric (address, 1, local_stream); */
535c96ce 507 if (TARGET_ADDR_BIT <= 32)
9647fa49 508 strcpy (addstr, local_hex_string_custom (address, "08l"));
535c96ce 509 else
9647fa49 510 strcpy (addstr, local_hex_string_custom (address, "016l"));
8b93c638
JM
511
512 ui_out_field_string (uiout, fldname, addstr);
513}
514
515void
88379baf
AC
516ui_out_field_stream (struct ui_out *uiout,
517 const char *fldname,
518 struct ui_stream *buf)
8b93c638
JM
519{
520 long length;
521 char *buffer = ui_file_xstrdup (buf->stream, &length);
b8c9b27d 522 struct cleanup *old_cleanup = make_cleanup (xfree, buffer);
8b93c638
JM
523 if (length > 0)
524 ui_out_field_string (uiout, fldname, buffer);
525 else
526 ui_out_field_skip (uiout, fldname);
527 ui_file_rewind (buf->stream);
528 do_cleanups (old_cleanup);
529}
530
531/* used to ommit a field */
532
533void
88379baf
AC
534ui_out_field_skip (struct ui_out *uiout,
535 const char *fldname)
8b93c638
JM
536{
537 int fldno;
538 int width;
539 int align;
8b93c638 540
a6c47c14 541 verify_field (uiout, &fldno, &width, &align);
8b93c638
JM
542
543 uo_field_skip (uiout, fldno, width, align, fldname);
544}
545
546void
547ui_out_field_string (struct ui_out *uiout,
88379baf 548 const char *fldname,
8b93c638
JM
549 const char *string)
550{
551 int fldno;
552 int width;
553 int align;
8b93c638 554
a6c47c14 555 verify_field (uiout, &fldno, &width, &align);
8b93c638
JM
556
557 uo_field_string (uiout, fldno, width, align, fldname, string);
558}
559
560/* VARARGS */
561void
88379baf
AC
562ui_out_field_fmt (struct ui_out *uiout,
563 const char *fldname,
564 const char *format, ...)
8b93c638
JM
565{
566 va_list args;
567 int fldno;
568 int width;
569 int align;
8b93c638
JM
570
571 /* will not align, but has to call anyway */
a6c47c14 572 verify_field (uiout, &fldno, &width, &align);
8b93c638
JM
573
574 va_start (args, format);
575
576 uo_field_fmt (uiout, fldno, width, align, fldname, format, args);
577
578 va_end (args);
579}
580
581void
fba45db2 582ui_out_spaces (struct ui_out *uiout, int numspaces)
8b93c638
JM
583{
584 uo_spaces (uiout, numspaces);
585}
586
587void
88379baf
AC
588ui_out_text (struct ui_out *uiout,
589 const char *string)
8b93c638
JM
590{
591 uo_text (uiout, string);
592}
593
594void
88379baf
AC
595ui_out_message (struct ui_out *uiout, int verbosity,
596 const char *format,...)
8b93c638
JM
597{
598 va_list args;
599
600 va_start (args, format);
601
602 uo_message (uiout, verbosity, format, args);
603
604 va_end (args);
605}
606
607struct ui_stream *
fba45db2 608ui_out_stream_new (struct ui_out *uiout)
8b93c638
JM
609{
610 struct ui_stream *tempbuf;
611
612 tempbuf = XMALLOC (struct ui_stream);
613 tempbuf->uiout = uiout;
614 tempbuf->stream = mem_fileopen ();
615 return tempbuf;
616}
617
618void
fba45db2 619ui_out_stream_delete (struct ui_stream *buf)
8b93c638
JM
620{
621 ui_file_delete (buf->stream);
b8c9b27d 622 xfree (buf);
8b93c638
JM
623}
624
625static void
626do_stream_delete (void *buf)
627{
628 ui_out_stream_delete (buf);
629}
630
631struct cleanup *
632make_cleanup_ui_out_stream_delete (struct ui_stream *buf)
633{
634 return make_cleanup (do_stream_delete, buf);
635}
636
637
638void
fba45db2 639ui_out_wrap_hint (struct ui_out *uiout, char *identstring)
8b93c638
JM
640{
641 uo_wrap_hint (uiout, identstring);
642}
643
644void
fba45db2 645ui_out_flush (struct ui_out *uiout)
8b93c638
JM
646{
647 uo_flush (uiout);
648}
649
650/* set the flags specified by the mask given */
651int
fba45db2 652ui_out_set_flags (struct ui_out *uiout, int mask)
8b93c638 653{
5bfb05ca 654 int oldflags = uiout->flags;
8b93c638 655
b8d86de3 656 uiout->flags |= mask;
8b93c638
JM
657
658 return oldflags;
659}
660
661/* clear the flags specified by the mask given */
662int
fba45db2 663ui_out_clear_flags (struct ui_out *uiout, int mask)
8b93c638 664{
5bfb05ca 665 int oldflags = uiout->flags;
8b93c638
JM
666
667 uiout->flags &= ~mask;
668
669 return oldflags;
670}
671
672/* test the flags against the mask given */
673int
fba45db2 674ui_out_test_flags (struct ui_out *uiout, int mask)
8b93c638
JM
675{
676 return (uiout->flags & mask);
677}
678
679/* obtain the current verbosity level (as stablished by the
680 'set verbositylevel' command */
681
682int
fba45db2 683ui_out_get_verblvl (struct ui_out *uiout)
8b93c638
JM
684{
685 /* FIXME: not implemented yet */
686 return 0;
687}
688
689#if 0
690void
fba45db2 691ui_out_result_begin (struct ui_out *uiout, char *class)
8b93c638
JM
692{
693}
694
695void
fba45db2 696ui_out_result_end (struct ui_out *uiout)
8b93c638
JM
697{
698}
699
700void
fba45db2 701ui_out_info_begin (struct ui_out *uiout, char *class)
8b93c638
JM
702{
703}
704
705void
fba45db2 706ui_out_info_end (struct ui_out *uiout)
8b93c638
JM
707{
708}
709
710void
fba45db2 711ui_out_notify_begin (struct ui_out *uiout, char *class)
8b93c638
JM
712{
713}
714
715void
fba45db2 716ui_out_notify_end (struct ui_out *uiout)
8b93c638
JM
717{
718}
719
720void
fba45db2 721ui_out_error_begin (struct ui_out *uiout, char *class)
8b93c638
JM
722{
723}
724
725void
fba45db2 726ui_out_error_end (struct ui_out *uiout)
8b93c638
JM
727{
728}
729#endif
730
731#if 0
732void
733gdb_error (ui_out * uiout, int severity, char *format,...)
734{
735 va_list args;
736}
737
738void
10689f25 739gdb_query (struct ui_out *uiout, int qflags, char *qprompt)
8b93c638
JM
740{
741}
742#endif
743
9dc5e2a9
AC
744int
745ui_out_is_mi_like_p (struct ui_out *uiout)
746{
747 return uiout->impl->is_mi_like_p;
748}
749
8b93c638
JM
750/* default gdb-out hook functions */
751
752static void
d63f1d40
AC
753default_table_begin (struct ui_out *uiout, int nbrofcols,
754 int nr_rows,
755 const char *tblid)
8b93c638
JM
756{
757}
758
759static void
fba45db2 760default_table_body (struct ui_out *uiout)
8b93c638
JM
761{
762}
763
764static void
fba45db2 765default_table_end (struct ui_out *uiout)
8b93c638
JM
766{
767}
768
769static void
fba45db2 770default_table_header (struct ui_out *uiout, int width, enum ui_align alignment,
b25959ec 771 const char *col_name,
e2e11a41 772 const char *colhdr)
8b93c638
JM
773{
774}
775
776static void
631ec795
AC
777default_begin (struct ui_out *uiout,
778 enum ui_out_type type,
779 int level,
780 const char *id)
8b93c638
JM
781{
782}
783
784static void
631ec795
AC
785default_end (struct ui_out *uiout,
786 enum ui_out_type type,
787 int level)
8b93c638
JM
788{
789}
790
791static void
fba45db2 792default_field_int (struct ui_out *uiout, int fldno, int width,
e2e11a41
AC
793 enum ui_align align,
794 const char *fldname, int value)
8b93c638
JM
795{
796}
797
798static void
fba45db2 799default_field_skip (struct ui_out *uiout, int fldno, int width,
e2e11a41 800 enum ui_align align, const char *fldname)
8b93c638
JM
801{
802}
803
804static void
805default_field_string (struct ui_out *uiout,
806 int fldno,
807 int width,
808 enum ui_align align,
e2e11a41 809 const char *fldname,
8b93c638
JM
810 const char *string)
811{
812}
813
814static void
fba45db2 815default_field_fmt (struct ui_out *uiout, int fldno, int width,
e2e11a41
AC
816 enum ui_align align,
817 const char *fldname,
818 const char *format,
fba45db2 819 va_list args)
8b93c638
JM
820{
821}
822
823static void
fba45db2 824default_spaces (struct ui_out *uiout, int numspaces)
8b93c638
JM
825{
826}
827
828static void
e2e11a41 829default_text (struct ui_out *uiout, const char *string)
8b93c638
JM
830{
831}
832
833static void
e2e11a41
AC
834default_message (struct ui_out *uiout, int verbosity,
835 const char *format,
fba45db2 836 va_list args)
8b93c638
JM
837{
838}
839
840static void
fba45db2 841default_wrap_hint (struct ui_out *uiout, char *identstring)
8b93c638
JM
842{
843}
844
845static void
fba45db2 846default_flush (struct ui_out *uiout)
8b93c638
JM
847{
848}
849
850/* Interface to the implementation functions */
851
852void
88379baf 853uo_table_begin (struct ui_out *uiout, int nbrofcols,
d63f1d40 854 int nr_rows,
88379baf 855 const char *tblid)
8b93c638
JM
856{
857 if (!uiout->impl->table_begin)
858 return;
d63f1d40 859 uiout->impl->table_begin (uiout, nbrofcols, nr_rows, tblid);
8b93c638
JM
860}
861
862void
863uo_table_body (struct ui_out *uiout)
864{
865 if (!uiout->impl->table_body)
866 return;
867 uiout->impl->table_body (uiout);
868}
869
870void
871uo_table_end (struct ui_out *uiout)
872{
873 if (!uiout->impl->table_end)
874 return;
875 uiout->impl->table_end (uiout);
876}
877
878void
88379baf 879uo_table_header (struct ui_out *uiout, int width, enum ui_align align,
b25959ec 880 const char *col_name,
88379baf 881 const char *colhdr)
8b93c638
JM
882{
883 if (!uiout->impl->table_header)
884 return;
b25959ec 885 uiout->impl->table_header (uiout, width, align, col_name, colhdr);
8b93c638
JM
886}
887
888void
631ec795
AC
889uo_begin (struct ui_out *uiout,
890 enum ui_out_type type,
891 int level,
892 const char *id)
8b93c638 893{
631ec795 894 if (uiout->impl->begin == NULL)
8b93c638 895 return;
631ec795 896 uiout->impl->begin (uiout, type, level, id);
8b93c638
JM
897}
898
899void
631ec795
AC
900uo_end (struct ui_out *uiout,
901 enum ui_out_type type,
902 int level)
8b93c638 903{
631ec795 904 if (uiout->impl->end == NULL)
8b93c638 905 return;
631ec795 906 uiout->impl->end (uiout, type, level);
8b93c638
JM
907}
908
909void
88379baf
AC
910uo_field_int (struct ui_out *uiout, int fldno, int width, enum ui_align align,
911 const char *fldname,
912 int value)
8b93c638
JM
913{
914 if (!uiout->impl->field_int)
915 return;
916 uiout->impl->field_int (uiout, fldno, width, align, fldname, value);
917}
918
919void
88379baf
AC
920uo_field_skip (struct ui_out *uiout, int fldno, int width, enum ui_align align,
921 const char *fldname)
8b93c638
JM
922{
923 if (!uiout->impl->field_skip)
924 return;
925 uiout->impl->field_skip (uiout, fldno, width, align, fldname);
926}
927
928void
929uo_field_string (struct ui_out *uiout, int fldno, int width,
88379baf
AC
930 enum ui_align align,
931 const char *fldname,
932 const char *string)
8b93c638
JM
933{
934 if (!uiout->impl->field_string)
935 return;
936 uiout->impl->field_string (uiout, fldno, width, align, fldname, string);
937}
938
939void
88379baf
AC
940uo_field_fmt (struct ui_out *uiout, int fldno, int width, enum ui_align align,
941 const char *fldname,
942 const char *format,
943 va_list args)
8b93c638
JM
944{
945 if (!uiout->impl->field_fmt)
946 return;
947 uiout->impl->field_fmt (uiout, fldno, width, align, fldname, format, args);
948}
949
950void
951uo_spaces (struct ui_out *uiout, int numspaces)
952{
953 if (!uiout->impl->spaces)
954 return;
955 uiout->impl->spaces (uiout, numspaces);
956}
957
958void
88379baf
AC
959uo_text (struct ui_out *uiout,
960 const char *string)
8b93c638
JM
961{
962 if (!uiout->impl->text)
963 return;
964 uiout->impl->text (uiout, string);
965}
966
967void
88379baf
AC
968uo_message (struct ui_out *uiout, int verbosity,
969 const char *format,
970 va_list args)
8b93c638
JM
971{
972 if (!uiout->impl->message)
973 return;
974 uiout->impl->message (uiout, verbosity, format, args);
975}
976
977void
978uo_wrap_hint (struct ui_out *uiout, char *identstring)
979{
980 if (!uiout->impl->wrap_hint)
981 return;
982 uiout->impl->wrap_hint (uiout, identstring);
983}
984
985void
986uo_flush (struct ui_out *uiout)
987{
988 if (!uiout->impl->flush)
989 return;
990 uiout->impl->flush (uiout);
991}
992
993/* local functions */
994
995/* list of column headers manipulation routines */
996
997static void
fba45db2 998clear_header_list (struct ui_out *uiout)
8b93c638 999{
bafdd3b3 1000 while (uiout->table.header_first != NULL)
8b93c638 1001 {
bafdd3b3
AC
1002 uiout->table.header_next = uiout->table.header_first;
1003 uiout->table.header_first = uiout->table.header_first->next;
1004 if (uiout->table.header_next->colhdr != NULL)
1005 xfree (uiout->table.header_next->colhdr);
1006 xfree (uiout->table.header_next);
8b93c638 1007 }
bafdd3b3
AC
1008 gdb_assert (uiout->table.header_first == NULL);
1009 uiout->table.header_last = NULL;
1010 uiout->table.header_next = NULL;
8b93c638
JM
1011}
1012
1013static void
1014append_header_to_list (struct ui_out *uiout,
1015 int width,
1016 int alignment,
b25959ec 1017 const char *col_name,
88379baf 1018 const char *colhdr)
8b93c638
JM
1019{
1020 struct ui_out_hdr *temphdr;
1021
1022 temphdr = XMALLOC (struct ui_out_hdr);
1023 temphdr->width = width;
1024 temphdr->alignment = alignment;
1025 /* we have to copy the column title as the original may be an automatic */
1026 if (colhdr != NULL)
b25959ec
AC
1027 temphdr->colhdr = xstrdup (colhdr);
1028 else
1029 temphdr->colhdr = NULL;
1030 if (col_name != NULL)
1031 temphdr->col_name = xstrdup (colhdr);
1032 else
1033 temphdr->col_name = xstrdup (colhdr);
8b93c638 1034 temphdr->next = NULL;
bafdd3b3 1035 if (uiout->table.header_first == NULL)
8b93c638
JM
1036 {
1037 temphdr->colno = 1;
bafdd3b3
AC
1038 uiout->table.header_first = temphdr;
1039 uiout->table.header_last = temphdr;
8b93c638
JM
1040 }
1041 else
1042 {
bafdd3b3
AC
1043 temphdr->colno = uiout->table.header_last->colno + 1;
1044 uiout->table.header_last->next = temphdr;
1045 uiout->table.header_last = temphdr;
8b93c638 1046 }
bafdd3b3 1047 uiout->table.header_next = uiout->table.header_last;
8b93c638
JM
1048}
1049
bafdd3b3
AC
1050/* Extract the format information for the NEXT header and and advance
1051 the header pointer. Return 0 if there was no next header. */
8b93c638
JM
1052
1053static int
bafdd3b3 1054get_next_header (struct ui_out *uiout,
8b93c638
JM
1055 int *colno,
1056 int *width,
1057 int *alignment,
1058 char **colhdr)
1059{
bafdd3b3
AC
1060 /* There may be no headers at all or we may have used all columns. */
1061 if (uiout->table.header_next == NULL)
8b93c638 1062 return 0;
bafdd3b3
AC
1063 *colno = uiout->table.header_next->colno;
1064 *width = uiout->table.header_next->width;
1065 *alignment = uiout->table.header_next->alignment;
1066 *colhdr = uiout->table.header_next->colhdr;
1067 /* Advance the header pointer to the next entry. */
1068 uiout->table.header_next = uiout->table.header_next->next;
8b93c638
JM
1069 return 1;
1070}
1071
a6c47c14
AC
1072
1073/* Verify that the field/tuple/list is correctly positioned. Return
1074 the field number and corresponding alignment (if
1075 available/applicable). */
8b93c638
JM
1076
1077static void
a6c47c14 1078verify_field (struct ui_out *uiout, int *fldno, int *width, int *align)
8b93c638 1079{
a6c47c14
AC
1080 struct ui_out_level *current = current_level (uiout);
1081 char *text;
1082
bafdd3b3 1083 if (uiout->table.flag)
8b93c638 1084 {
bafdd3b3 1085 if (!uiout->table.body_flag)
8e65ff28
AC
1086 internal_error (__FILE__, __LINE__,
1087 "table_body missing; table fields must be \
8b93c638 1088specified after table_body and inside a list.");
a6c47c14
AC
1089 /* NOTE: cagney/2001-12-08: There was a check here to ensure
1090 that this code was only executed when uiout->level was
1091 greater than zero. That no longer applies - this code is run
1092 before each table row tuple is started and at that point the
1093 level is zero. */
8b93c638 1094 }
8b93c638 1095
a6c47c14 1096 current->field_count += 1;
8b93c638 1097
a6c47c14
AC
1098 if (uiout->table.body_flag
1099 && uiout->table.entry_level == uiout->level
1100 && get_next_header (uiout, fldno, width, align, &text))
8b93c638 1101 {
a6c47c14 1102 if (*fldno != current->field_count)
8e65ff28
AC
1103 internal_error (__FILE__, __LINE__,
1104 "ui-out internal error in handling headers.");
8b93c638
JM
1105 }
1106 else
1107 {
1108 *width = 0;
1109 *align = ui_noalign;
a6c47c14 1110 *fldno = current->field_count;
8b93c638
JM
1111 }
1112}
1113
a6c47c14 1114
8b93c638
JM
1115/* access to ui_out format private members */
1116
1117void
fba45db2 1118ui_out_get_field_separator (struct ui_out *uiout)
8b93c638
JM
1119{
1120}
1121
1122/* Access to ui-out members data */
1123
1124struct ui_out_data *
1125ui_out_data (struct ui_out *uiout)
1126{
1127 return uiout->data;
1128}
1129
1130/* initalize private members at startup */
1131
1132struct ui_out *
1133ui_out_new (struct ui_out_impl *impl,
1134 struct ui_out_data *data,
1135 int flags)
1136{
1137 struct ui_out *uiout = XMALLOC (struct ui_out);
1138 uiout->data = data;
1139 uiout->impl = impl;
1140 uiout->flags = flags;
bafdd3b3
AC
1141 uiout->table.flag = 0;
1142 uiout->table.body_flag = 0;
80f49b30
AC
1143 uiout->level = 0;
1144 memset (uiout->levels, 0, sizeof (uiout->levels));
bafdd3b3
AC
1145 uiout->table.header_first = NULL;
1146 uiout->table.header_last = NULL;
1147 uiout->table.header_next = NULL;
8b93c638
JM
1148 return uiout;
1149}
1150
1151/* standard gdb initialization hook */
1152
1153void
fba45db2 1154_initialize_ui_out (void)
8b93c638
JM
1155{
1156 /* nothing needs to be done */
1157}
This page took 0.342252 seconds and 4 git commands to generate.