2003-10-24 Andrew Cagney <cagney@redhat.com>
[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 208 default_flush,
0fac0b41 209 NULL,
9dc5e2a9 210 0, /* Does not need MI hacks. */
8b93c638
JM
211};
212
213/* The default ui_out */
214
215struct ui_out def_uiout =
216{
217 0, /* flags */
218 &default_ui_out_impl, /* impl */
219};
220
221/* Pointer to current ui_out */
222/* FIXME: This should not be a global, but something passed down from main.c
223 or top.c */
224
225struct ui_out *uiout = &def_uiout;
226
227/* These are the interfaces to implementation functions */
228
88379baf 229static void uo_table_begin (struct ui_out *uiout, int nbrofcols,
d63f1d40 230 int nr_rows, const char *tblid);
8b93c638
JM
231static void uo_table_body (struct ui_out *uiout);
232static void uo_table_end (struct ui_out *uiout);
233static void uo_table_header (struct ui_out *uiout, int width,
b25959ec
AC
234 enum ui_align align, const char *col_name,
235 const char *colhdr);
631ec795
AC
236static void uo_begin (struct ui_out *uiout,
237 enum ui_out_type type,
238 int level, const char *id);
239static void uo_end (struct ui_out *uiout,
240 enum ui_out_type type,
241 int level);
8b93c638 242static void uo_field_int (struct ui_out *uiout, int fldno, int width,
88379baf 243 enum ui_align align, const char *fldname, int value);
8b93c638 244static void uo_field_skip (struct ui_out *uiout, int fldno, int width,
88379baf 245 enum ui_align align, const char *fldname);
8b93c638 246static void uo_field_string (struct ui_out *uiout, int fldno, int width,
88379baf
AC
247 enum ui_align align, const char *fldname,
248 const char *string);
8b93c638 249static void uo_field_fmt (struct ui_out *uiout, int fldno, int width,
88379baf
AC
250 enum ui_align align, const char *fldname,
251 const char *format, va_list args);
8b93c638 252static void uo_spaces (struct ui_out *uiout, int numspaces);
88379baf 253static void uo_text (struct ui_out *uiout, const char *string);
8b93c638 254static void uo_message (struct ui_out *uiout, int verbosity,
88379baf 255 const char *format, va_list args);
8b93c638
JM
256static void uo_wrap_hint (struct ui_out *uiout, char *identstring);
257static void uo_flush (struct ui_out *uiout);
0fac0b41 258static int uo_redirect (struct ui_out *uiout, struct ui_file *outstream);
8b93c638
JM
259
260/* Prototypes for local functions */
261
262extern void _initialize_ui_out (void);
88379baf 263static void append_header_to_list (struct ui_out *uiout, int width,
b25959ec
AC
264 int alignment, const char *col_name,
265 const char *colhdr);
bafdd3b3 266static int get_next_header (struct ui_out *uiout, int *colno, int *width,
8b93c638
JM
267 int *alignment, char **colhdr);
268static void clear_header_list (struct ui_out *uiout);
a6c47c14
AC
269static void verify_field (struct ui_out *uiout, int *fldno, int *width,
270 int *align);
8b93c638
JM
271
272static void init_ui_out_state (struct ui_out *uiout);
273
274/* exported functions (ui_out API) */
275
276/* Mark beginning of a table */
277
3b31d625 278static void
88379baf 279ui_out_table_begin (struct ui_out *uiout, int nbrofcols,
d63f1d40 280 int nr_rows,
88379baf 281 const char *tblid)
8b93c638 282{
bafdd3b3 283 if (uiout->table.flag)
8e65ff28
AC
284 internal_error (__FILE__, __LINE__,
285 "tables cannot be nested; table_begin found before \
8b93c638
JM
286previous table_end.");
287
bafdd3b3
AC
288 uiout->table.flag = 1;
289 uiout->table.body_flag = 0;
a6c47c14 290 uiout->table.entry_level = uiout->level + 1;
bafdd3b3 291 uiout->table.columns = nbrofcols;
8b93c638 292 if (tblid != NULL)
bafdd3b3 293 uiout->table.id = xstrdup (tblid);
8b93c638 294 else
bafdd3b3 295 uiout->table.id = NULL;
8b93c638
JM
296 clear_header_list (uiout);
297
bafdd3b3 298 uo_table_begin (uiout, nbrofcols, nr_rows, uiout->table.id);
8b93c638
JM
299}
300
301void
fba45db2 302ui_out_table_body (struct ui_out *uiout)
8b93c638 303{
bafdd3b3 304 if (!uiout->table.flag)
8e65ff28
AC
305 internal_error (__FILE__, __LINE__,
306 "table_body outside a table is not valid; it must be \
8b93c638 307after a table_begin and before a table_end.");
bafdd3b3 308 if (uiout->table.body_flag)
8e65ff28
AC
309 internal_error (__FILE__, __LINE__,
310 "extra table_body call not allowed; there must be \
8b93c638 311only one table_body after a table_begin and before a table_end.");
bafdd3b3 312 if (uiout->table.header_next->colno != uiout->table.columns)
8e65ff28
AC
313 internal_error (__FILE__, __LINE__,
314 "number of headers differ from number of table \
8b93c638
JM
315columns.");
316
bafdd3b3
AC
317 uiout->table.body_flag = 1;
318 uiout->table.header_next = uiout->table.header_first;
8b93c638
JM
319
320 uo_table_body (uiout);
321}
322
3b31d625 323static void
fba45db2 324ui_out_table_end (struct ui_out *uiout)
8b93c638 325{
bafdd3b3 326 if (!uiout->table.flag)
8e65ff28
AC
327 internal_error (__FILE__, __LINE__,
328 "misplaced table_end or missing table_begin.");
8b93c638 329
a6c47c14 330 uiout->table.entry_level = 0;
bafdd3b3
AC
331 uiout->table.body_flag = 0;
332 uiout->table.flag = 0;
8b93c638
JM
333
334 uo_table_end (uiout);
335
bafdd3b3
AC
336 if (uiout->table.id)
337 xfree (uiout->table.id);
8b93c638
JM
338 clear_header_list (uiout);
339}
340
341void
fba45db2 342ui_out_table_header (struct ui_out *uiout, int width, enum ui_align alignment,
b25959ec 343 const char *col_name,
88379baf 344 const char *colhdr)
8b93c638 345{
bafdd3b3 346 if (!uiout->table.flag || uiout->table.body_flag)
8e65ff28
AC
347 internal_error (__FILE__, __LINE__,
348 "table header must be specified after table_begin \
8b93c638
JM
349and before table_body.");
350
b25959ec 351 append_header_to_list (uiout, width, alignment, col_name, colhdr);
8b93c638 352
b25959ec 353 uo_table_header (uiout, width, alignment, col_name, colhdr);
8b93c638
JM
354}
355
3b31d625
EZ
356static void
357do_cleanup_table_end (void *data)
358{
359 struct ui_out *ui_out = data;
360
361 ui_out_table_end (ui_out);
362}
363
364struct cleanup *
365make_cleanup_ui_out_table_begin_end (struct ui_out *ui_out, int nr_cols,
366 int nr_rows, const char *tblid)
367{
368 ui_out_table_begin (ui_out, nr_cols, nr_rows, tblid);
369 return make_cleanup (do_cleanup_table_end, ui_out);
370}
371
8b93c638 372void
631ec795
AC
373ui_out_begin (struct ui_out *uiout,
374 enum ui_out_type type,
375 const char *id)
8b93c638 376{
80f49b30 377 int new_level;
bafdd3b3 378 if (uiout->table.flag && !uiout->table.body_flag)
8e65ff28
AC
379 internal_error (__FILE__, __LINE__,
380 "table header or table_body expected; lists must be \
8b93c638 381specified after table_body.");
a6c47c14
AC
382
383 /* Be careful to verify the ``field'' before the new tuple/list is
384 pushed onto the stack. That way the containing list/table/row is
385 verified and not the newly created tuple/list. This verification
386 is needed (at least) for the case where a table row entry
387 contains either a tuple/list. For that case bookkeeping such as
388 updating the column count or advancing to the next heading still
389 needs to be performed. */
390 {
391 int fldno;
392 int width;
393 int align;
394 verify_field (uiout, &fldno, &width, &align);
395 }
396
631ec795 397 new_level = push_level (uiout, type, id);
a6c47c14
AC
398
399 /* If the push puts us at the same level as a table row entry, we've
400 got a new table row. Put the header pointer back to the start. */
401 if (uiout->table.body_flag
402 && uiout->table.entry_level == new_level)
bafdd3b3 403 uiout->table.header_next = uiout->table.header_first;
a6c47c14 404
631ec795
AC
405 uo_begin (uiout, type, new_level, id);
406}
407
631ec795
AC
408void
409ui_out_end (struct ui_out *uiout,
410 enum ui_out_type type)
411{
412 int old_level = pop_level (uiout, type);
413 uo_end (uiout, type, old_level);
8b93c638
JM
414}
415
127431f9
AC
416struct ui_out_end_cleanup_data
417{
418 struct ui_out *uiout;
419 enum ui_out_type type;
420};
421
e6e0bfab 422static void
127431f9
AC
423do_cleanup_end (void *data)
424{
425 struct ui_out_end_cleanup_data *end_cleanup_data = data;
426 ui_out_end (end_cleanup_data->uiout, end_cleanup_data->type);
427 xfree (end_cleanup_data);
428}
429
430static struct cleanup *
431make_cleanup_ui_out_end (struct ui_out *uiout,
432 enum ui_out_type type)
433{
434 struct ui_out_end_cleanup_data *end_cleanup_data;
435 end_cleanup_data = XMALLOC (struct ui_out_end_cleanup_data);
436 end_cleanup_data->uiout = uiout;
437 end_cleanup_data->type = type;
438 return make_cleanup (do_cleanup_end, end_cleanup_data);
439}
440
e6e0bfab 441struct cleanup *
666547aa
AC
442make_cleanup_ui_out_tuple_begin_end (struct ui_out *uiout,
443 const char *id)
444{
3b31d625 445 ui_out_begin (uiout, ui_out_type_tuple, id);
666547aa
AC
446 return make_cleanup_ui_out_end (uiout, ui_out_type_tuple);
447}
448
449struct cleanup *
6b28c186
AC
450make_cleanup_ui_out_list_begin_end (struct ui_out *uiout,
451 const char *id)
e6e0bfab 452{
3b31d625 453 ui_out_begin (uiout, ui_out_type_list, id);
127431f9 454 return make_cleanup_ui_out_end (uiout, ui_out_type_list);
e6e0bfab
MK
455}
456
8b93c638 457void
88379baf
AC
458ui_out_field_int (struct ui_out *uiout,
459 const char *fldname,
460 int value)
8b93c638
JM
461{
462 int fldno;
463 int width;
464 int align;
80f49b30 465 struct ui_out_level *current = current_level (uiout);
8b93c638 466
a6c47c14 467 verify_field (uiout, &fldno, &width, &align);
8b93c638
JM
468
469 uo_field_int (uiout, fldno, width, align, fldname, value);
470}
471
52c6a6ac
JJ
472void
473ui_out_field_fmt_int (struct ui_out *uiout,
474 int input_width,
475 enum ui_align input_align,
476 const char *fldname,
477 int value)
478{
479 int fldno;
480 int width;
481 int align;
482 struct ui_out_level *current = current_level (uiout);
483
484 verify_field (uiout, &fldno, &width, &align);
485
486 uo_field_int (uiout, fldno, input_width, input_align, fldname, value);
487}
488
8b93c638 489void
88379baf
AC
490ui_out_field_core_addr (struct ui_out *uiout,
491 const char *fldname,
492 CORE_ADDR address)
8b93c638
JM
493{
494 char addstr[20];
495
535c96ce
AC
496 /* FIXME: cagney/2002-05-03: Need local_address_string() function
497 that returns the language localized string formatted to a width
498 based on TARGET_ADDR_BIT. */
8b93c638 499 /* print_address_numeric (address, 1, local_stream); */
535c96ce 500 if (TARGET_ADDR_BIT <= 32)
9647fa49 501 strcpy (addstr, local_hex_string_custom (address, "08l"));
535c96ce 502 else
9647fa49 503 strcpy (addstr, local_hex_string_custom (address, "016l"));
8b93c638
JM
504
505 ui_out_field_string (uiout, fldname, addstr);
506}
507
508void
88379baf
AC
509ui_out_field_stream (struct ui_out *uiout,
510 const char *fldname,
511 struct ui_stream *buf)
8b93c638
JM
512{
513 long length;
514 char *buffer = ui_file_xstrdup (buf->stream, &length);
b8c9b27d 515 struct cleanup *old_cleanup = make_cleanup (xfree, buffer);
8b93c638
JM
516 if (length > 0)
517 ui_out_field_string (uiout, fldname, buffer);
518 else
519 ui_out_field_skip (uiout, fldname);
520 ui_file_rewind (buf->stream);
521 do_cleanups (old_cleanup);
522}
523
524/* used to ommit a field */
525
526void
88379baf
AC
527ui_out_field_skip (struct ui_out *uiout,
528 const char *fldname)
8b93c638
JM
529{
530 int fldno;
531 int width;
532 int align;
8b93c638 533
a6c47c14 534 verify_field (uiout, &fldno, &width, &align);
8b93c638
JM
535
536 uo_field_skip (uiout, fldno, width, align, fldname);
537}
538
539void
540ui_out_field_string (struct ui_out *uiout,
88379baf 541 const char *fldname,
8b93c638
JM
542 const char *string)
543{
544 int fldno;
545 int width;
546 int align;
8b93c638 547
a6c47c14 548 verify_field (uiout, &fldno, &width, &align);
8b93c638
JM
549
550 uo_field_string (uiout, fldno, width, align, fldname, string);
551}
552
553/* VARARGS */
554void
88379baf
AC
555ui_out_field_fmt (struct ui_out *uiout,
556 const char *fldname,
557 const char *format, ...)
8b93c638
JM
558{
559 va_list args;
560 int fldno;
561 int width;
562 int align;
8b93c638
JM
563
564 /* will not align, but has to call anyway */
a6c47c14 565 verify_field (uiout, &fldno, &width, &align);
8b93c638
JM
566
567 va_start (args, format);
568
569 uo_field_fmt (uiout, fldno, width, align, fldname, format, args);
570
571 va_end (args);
572}
573
574void
fba45db2 575ui_out_spaces (struct ui_out *uiout, int numspaces)
8b93c638
JM
576{
577 uo_spaces (uiout, numspaces);
578}
579
580void
88379baf
AC
581ui_out_text (struct ui_out *uiout,
582 const char *string)
8b93c638
JM
583{
584 uo_text (uiout, string);
585}
586
587void
88379baf
AC
588ui_out_message (struct ui_out *uiout, int verbosity,
589 const char *format,...)
8b93c638
JM
590{
591 va_list args;
592
593 va_start (args, format);
594
595 uo_message (uiout, verbosity, format, args);
596
597 va_end (args);
598}
599
600struct ui_stream *
fba45db2 601ui_out_stream_new (struct ui_out *uiout)
8b93c638
JM
602{
603 struct ui_stream *tempbuf;
604
605 tempbuf = XMALLOC (struct ui_stream);
606 tempbuf->uiout = uiout;
607 tempbuf->stream = mem_fileopen ();
608 return tempbuf;
609}
610
611void
fba45db2 612ui_out_stream_delete (struct ui_stream *buf)
8b93c638
JM
613{
614 ui_file_delete (buf->stream);
b8c9b27d 615 xfree (buf);
8b93c638
JM
616}
617
618static void
619do_stream_delete (void *buf)
620{
621 ui_out_stream_delete (buf);
622}
623
624struct cleanup *
625make_cleanup_ui_out_stream_delete (struct ui_stream *buf)
626{
627 return make_cleanup (do_stream_delete, buf);
628}
629
630
631void
fba45db2 632ui_out_wrap_hint (struct ui_out *uiout, char *identstring)
8b93c638
JM
633{
634 uo_wrap_hint (uiout, identstring);
635}
636
637void
fba45db2 638ui_out_flush (struct ui_out *uiout)
8b93c638
JM
639{
640 uo_flush (uiout);
641}
642
0fac0b41
DJ
643int
644ui_out_redirect (struct ui_out *uiout, struct ui_file *outstream)
645{
646 return uo_redirect (uiout, outstream);
647}
648
8b93c638
JM
649/* set the flags specified by the mask given */
650int
fba45db2 651ui_out_set_flags (struct ui_out *uiout, int mask)
8b93c638 652{
5bfb05ca 653 int oldflags = uiout->flags;
8b93c638 654
b8d86de3 655 uiout->flags |= mask;
8b93c638
JM
656
657 return oldflags;
658}
659
660/* clear the flags specified by the mask given */
661int
fba45db2 662ui_out_clear_flags (struct ui_out *uiout, int mask)
8b93c638 663{
5bfb05ca 664 int oldflags = uiout->flags;
8b93c638
JM
665
666 uiout->flags &= ~mask;
667
668 return oldflags;
669}
670
671/* test the flags against the mask given */
672int
fba45db2 673ui_out_test_flags (struct ui_out *uiout, int mask)
8b93c638
JM
674{
675 return (uiout->flags & mask);
676}
677
678/* obtain the current verbosity level (as stablished by the
679 'set verbositylevel' command */
680
681int
fba45db2 682ui_out_get_verblvl (struct ui_out *uiout)
8b93c638
JM
683{
684 /* FIXME: not implemented yet */
685 return 0;
686}
687
688#if 0
689void
fba45db2 690ui_out_result_begin (struct ui_out *uiout, char *class)
8b93c638
JM
691{
692}
693
694void
fba45db2 695ui_out_result_end (struct ui_out *uiout)
8b93c638
JM
696{
697}
698
699void
fba45db2 700ui_out_info_begin (struct ui_out *uiout, char *class)
8b93c638
JM
701{
702}
703
704void
fba45db2 705ui_out_info_end (struct ui_out *uiout)
8b93c638
JM
706{
707}
708
709void
fba45db2 710ui_out_notify_begin (struct ui_out *uiout, char *class)
8b93c638
JM
711{
712}
713
714void
fba45db2 715ui_out_notify_end (struct ui_out *uiout)
8b93c638
JM
716{
717}
718
719void
fba45db2 720ui_out_error_begin (struct ui_out *uiout, char *class)
8b93c638
JM
721{
722}
723
724void
fba45db2 725ui_out_error_end (struct ui_out *uiout)
8b93c638
JM
726{
727}
728#endif
729
730#if 0
731void
732gdb_error (ui_out * uiout, int severity, char *format,...)
733{
734 va_list args;
735}
736
737void
10689f25 738gdb_query (struct ui_out *uiout, int qflags, char *qprompt)
8b93c638
JM
739{
740}
741#endif
742
9dc5e2a9
AC
743int
744ui_out_is_mi_like_p (struct ui_out *uiout)
745{
746 return uiout->impl->is_mi_like_p;
747}
748
8b93c638
JM
749/* default gdb-out hook functions */
750
751static void
d63f1d40
AC
752default_table_begin (struct ui_out *uiout, int nbrofcols,
753 int nr_rows,
754 const char *tblid)
8b93c638
JM
755{
756}
757
758static void
fba45db2 759default_table_body (struct ui_out *uiout)
8b93c638
JM
760{
761}
762
763static void
fba45db2 764default_table_end (struct ui_out *uiout)
8b93c638
JM
765{
766}
767
768static void
fba45db2 769default_table_header (struct ui_out *uiout, int width, enum ui_align alignment,
b25959ec 770 const char *col_name,
e2e11a41 771 const char *colhdr)
8b93c638
JM
772{
773}
774
775static void
631ec795
AC
776default_begin (struct ui_out *uiout,
777 enum ui_out_type type,
778 int level,
779 const char *id)
8b93c638
JM
780{
781}
782
783static void
631ec795
AC
784default_end (struct ui_out *uiout,
785 enum ui_out_type type,
786 int level)
8b93c638
JM
787{
788}
789
790static void
fba45db2 791default_field_int (struct ui_out *uiout, int fldno, int width,
e2e11a41
AC
792 enum ui_align align,
793 const char *fldname, int value)
8b93c638
JM
794{
795}
796
797static void
fba45db2 798default_field_skip (struct ui_out *uiout, int fldno, int width,
e2e11a41 799 enum ui_align align, const char *fldname)
8b93c638
JM
800{
801}
802
803static void
804default_field_string (struct ui_out *uiout,
805 int fldno,
806 int width,
807 enum ui_align align,
e2e11a41 808 const char *fldname,
8b93c638
JM
809 const char *string)
810{
811}
812
813static void
fba45db2 814default_field_fmt (struct ui_out *uiout, int fldno, int width,
e2e11a41
AC
815 enum ui_align align,
816 const char *fldname,
817 const char *format,
fba45db2 818 va_list args)
8b93c638
JM
819{
820}
821
822static void
fba45db2 823default_spaces (struct ui_out *uiout, int numspaces)
8b93c638
JM
824{
825}
826
827static void
e2e11a41 828default_text (struct ui_out *uiout, const char *string)
8b93c638
JM
829{
830}
831
832static void
e2e11a41
AC
833default_message (struct ui_out *uiout, int verbosity,
834 const char *format,
fba45db2 835 va_list args)
8b93c638
JM
836{
837}
838
839static void
fba45db2 840default_wrap_hint (struct ui_out *uiout, char *identstring)
8b93c638
JM
841{
842}
843
844static void
fba45db2 845default_flush (struct ui_out *uiout)
8b93c638
JM
846{
847}
848
849/* Interface to the implementation functions */
850
851void
88379baf 852uo_table_begin (struct ui_out *uiout, int nbrofcols,
d63f1d40 853 int nr_rows,
88379baf 854 const char *tblid)
8b93c638
JM
855{
856 if (!uiout->impl->table_begin)
857 return;
d63f1d40 858 uiout->impl->table_begin (uiout, nbrofcols, nr_rows, tblid);
8b93c638
JM
859}
860
861void
862uo_table_body (struct ui_out *uiout)
863{
864 if (!uiout->impl->table_body)
865 return;
866 uiout->impl->table_body (uiout);
867}
868
869void
870uo_table_end (struct ui_out *uiout)
871{
872 if (!uiout->impl->table_end)
873 return;
874 uiout->impl->table_end (uiout);
875}
876
877void
88379baf 878uo_table_header (struct ui_out *uiout, int width, enum ui_align align,
b25959ec 879 const char *col_name,
88379baf 880 const char *colhdr)
8b93c638
JM
881{
882 if (!uiout->impl->table_header)
883 return;
b25959ec 884 uiout->impl->table_header (uiout, width, align, col_name, colhdr);
8b93c638
JM
885}
886
887void
631ec795
AC
888uo_begin (struct ui_out *uiout,
889 enum ui_out_type type,
890 int level,
891 const char *id)
8b93c638 892{
631ec795 893 if (uiout->impl->begin == NULL)
8b93c638 894 return;
631ec795 895 uiout->impl->begin (uiout, type, level, id);
8b93c638
JM
896}
897
898void
631ec795
AC
899uo_end (struct ui_out *uiout,
900 enum ui_out_type type,
901 int level)
8b93c638 902{
631ec795 903 if (uiout->impl->end == NULL)
8b93c638 904 return;
631ec795 905 uiout->impl->end (uiout, type, level);
8b93c638
JM
906}
907
908void
88379baf
AC
909uo_field_int (struct ui_out *uiout, int fldno, int width, enum ui_align align,
910 const char *fldname,
911 int value)
8b93c638
JM
912{
913 if (!uiout->impl->field_int)
914 return;
915 uiout->impl->field_int (uiout, fldno, width, align, fldname, value);
916}
917
918void
88379baf
AC
919uo_field_skip (struct ui_out *uiout, int fldno, int width, enum ui_align align,
920 const char *fldname)
8b93c638
JM
921{
922 if (!uiout->impl->field_skip)
923 return;
924 uiout->impl->field_skip (uiout, fldno, width, align, fldname);
925}
926
927void
928uo_field_string (struct ui_out *uiout, int fldno, int width,
88379baf
AC
929 enum ui_align align,
930 const char *fldname,
931 const char *string)
8b93c638
JM
932{
933 if (!uiout->impl->field_string)
934 return;
935 uiout->impl->field_string (uiout, fldno, width, align, fldname, string);
936}
937
938void
88379baf
AC
939uo_field_fmt (struct ui_out *uiout, int fldno, int width, enum ui_align align,
940 const char *fldname,
941 const char *format,
942 va_list args)
8b93c638
JM
943{
944 if (!uiout->impl->field_fmt)
945 return;
946 uiout->impl->field_fmt (uiout, fldno, width, align, fldname, format, args);
947}
948
949void
950uo_spaces (struct ui_out *uiout, int numspaces)
951{
952 if (!uiout->impl->spaces)
953 return;
954 uiout->impl->spaces (uiout, numspaces);
955}
956
957void
88379baf
AC
958uo_text (struct ui_out *uiout,
959 const char *string)
8b93c638
JM
960{
961 if (!uiout->impl->text)
962 return;
963 uiout->impl->text (uiout, string);
964}
965
966void
88379baf
AC
967uo_message (struct ui_out *uiout, int verbosity,
968 const char *format,
969 va_list args)
8b93c638
JM
970{
971 if (!uiout->impl->message)
972 return;
973 uiout->impl->message (uiout, verbosity, format, args);
974}
975
976void
977uo_wrap_hint (struct ui_out *uiout, char *identstring)
978{
979 if (!uiout->impl->wrap_hint)
980 return;
981 uiout->impl->wrap_hint (uiout, identstring);
982}
983
984void
985uo_flush (struct ui_out *uiout)
986{
987 if (!uiout->impl->flush)
988 return;
989 uiout->impl->flush (uiout);
990}
991
0fac0b41
DJ
992int
993uo_redirect (struct ui_out *uiout, struct ui_file *outstream)
994{
995 if (!uiout->impl->redirect)
996 return -1;
997 uiout->impl->redirect (uiout, outstream);
998 return 0;
999}
1000
8b93c638
JM
1001/* local functions */
1002
1003/* list of column headers manipulation routines */
1004
1005static void
fba45db2 1006clear_header_list (struct ui_out *uiout)
8b93c638 1007{
bafdd3b3 1008 while (uiout->table.header_first != NULL)
8b93c638 1009 {
bafdd3b3
AC
1010 uiout->table.header_next = uiout->table.header_first;
1011 uiout->table.header_first = uiout->table.header_first->next;
1012 if (uiout->table.header_next->colhdr != NULL)
1013 xfree (uiout->table.header_next->colhdr);
1014 xfree (uiout->table.header_next);
8b93c638 1015 }
bafdd3b3
AC
1016 gdb_assert (uiout->table.header_first == NULL);
1017 uiout->table.header_last = NULL;
1018 uiout->table.header_next = NULL;
8b93c638
JM
1019}
1020
1021static void
1022append_header_to_list (struct ui_out *uiout,
1023 int width,
1024 int alignment,
b25959ec 1025 const char *col_name,
88379baf 1026 const char *colhdr)
8b93c638
JM
1027{
1028 struct ui_out_hdr *temphdr;
1029
1030 temphdr = XMALLOC (struct ui_out_hdr);
1031 temphdr->width = width;
1032 temphdr->alignment = alignment;
1033 /* we have to copy the column title as the original may be an automatic */
1034 if (colhdr != NULL)
b25959ec
AC
1035 temphdr->colhdr = xstrdup (colhdr);
1036 else
1037 temphdr->colhdr = NULL;
1038 if (col_name != NULL)
1039 temphdr->col_name = xstrdup (colhdr);
1040 else
1041 temphdr->col_name = xstrdup (colhdr);
8b93c638 1042 temphdr->next = NULL;
bafdd3b3 1043 if (uiout->table.header_first == NULL)
8b93c638
JM
1044 {
1045 temphdr->colno = 1;
bafdd3b3
AC
1046 uiout->table.header_first = temphdr;
1047 uiout->table.header_last = temphdr;
8b93c638
JM
1048 }
1049 else
1050 {
bafdd3b3
AC
1051 temphdr->colno = uiout->table.header_last->colno + 1;
1052 uiout->table.header_last->next = temphdr;
1053 uiout->table.header_last = temphdr;
8b93c638 1054 }
bafdd3b3 1055 uiout->table.header_next = uiout->table.header_last;
8b93c638
JM
1056}
1057
bafdd3b3
AC
1058/* Extract the format information for the NEXT header and and advance
1059 the header pointer. Return 0 if there was no next header. */
8b93c638
JM
1060
1061static int
bafdd3b3 1062get_next_header (struct ui_out *uiout,
8b93c638
JM
1063 int *colno,
1064 int *width,
1065 int *alignment,
1066 char **colhdr)
1067{
bafdd3b3
AC
1068 /* There may be no headers at all or we may have used all columns. */
1069 if (uiout->table.header_next == NULL)
8b93c638 1070 return 0;
bafdd3b3
AC
1071 *colno = uiout->table.header_next->colno;
1072 *width = uiout->table.header_next->width;
1073 *alignment = uiout->table.header_next->alignment;
1074 *colhdr = uiout->table.header_next->colhdr;
1075 /* Advance the header pointer to the next entry. */
1076 uiout->table.header_next = uiout->table.header_next->next;
8b93c638
JM
1077 return 1;
1078}
1079
a6c47c14
AC
1080
1081/* Verify that the field/tuple/list is correctly positioned. Return
1082 the field number and corresponding alignment (if
1083 available/applicable). */
8b93c638
JM
1084
1085static void
a6c47c14 1086verify_field (struct ui_out *uiout, int *fldno, int *width, int *align)
8b93c638 1087{
a6c47c14
AC
1088 struct ui_out_level *current = current_level (uiout);
1089 char *text;
1090
bafdd3b3 1091 if (uiout->table.flag)
8b93c638 1092 {
bafdd3b3 1093 if (!uiout->table.body_flag)
8e65ff28
AC
1094 internal_error (__FILE__, __LINE__,
1095 "table_body missing; table fields must be \
8b93c638 1096specified after table_body and inside a list.");
a6c47c14
AC
1097 /* NOTE: cagney/2001-12-08: There was a check here to ensure
1098 that this code was only executed when uiout->level was
1099 greater than zero. That no longer applies - this code is run
1100 before each table row tuple is started and at that point the
1101 level is zero. */
8b93c638 1102 }
8b93c638 1103
a6c47c14 1104 current->field_count += 1;
8b93c638 1105
a6c47c14
AC
1106 if (uiout->table.body_flag
1107 && uiout->table.entry_level == uiout->level
1108 && get_next_header (uiout, fldno, width, align, &text))
8b93c638 1109 {
a6c47c14 1110 if (*fldno != current->field_count)
8e65ff28
AC
1111 internal_error (__FILE__, __LINE__,
1112 "ui-out internal error in handling headers.");
8b93c638
JM
1113 }
1114 else
1115 {
1116 *width = 0;
1117 *align = ui_noalign;
a6c47c14 1118 *fldno = current->field_count;
8b93c638
JM
1119 }
1120}
1121
a6c47c14 1122
8b93c638
JM
1123/* access to ui_out format private members */
1124
1125void
fba45db2 1126ui_out_get_field_separator (struct ui_out *uiout)
8b93c638
JM
1127{
1128}
1129
1130/* Access to ui-out members data */
1131
1132struct ui_out_data *
1133ui_out_data (struct ui_out *uiout)
1134{
1135 return uiout->data;
1136}
1137
1138/* initalize private members at startup */
1139
1140struct ui_out *
1141ui_out_new (struct ui_out_impl *impl,
1142 struct ui_out_data *data,
1143 int flags)
1144{
1145 struct ui_out *uiout = XMALLOC (struct ui_out);
1146 uiout->data = data;
1147 uiout->impl = impl;
1148 uiout->flags = flags;
bafdd3b3
AC
1149 uiout->table.flag = 0;
1150 uiout->table.body_flag = 0;
80f49b30
AC
1151 uiout->level = 0;
1152 memset (uiout->levels, 0, sizeof (uiout->levels));
bafdd3b3
AC
1153 uiout->table.header_first = NULL;
1154 uiout->table.header_last = NULL;
1155 uiout->table.header_next = NULL;
8b93c638
JM
1156 return uiout;
1157}
1158
1159/* standard gdb initialization hook */
1160
1161void
fba45db2 1162_initialize_ui_out (void)
8b93c638
JM
1163{
1164 /* nothing needs to be done */
1165}
This page took 0.434861 seconds and 4 git commands to generate.