OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [gdb/] [ui-out.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.