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

Subversion Repositories or1k

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
/* MI Command Set - output generating routines.
2
   Copyright 2000 Free Software Foundation, Inc.
3
   Contributed by Cygnus Solutions (a Red Hat company).
4
 
5
   This file is part of GDB.
6
 
7
   This program is free software; you can redistribute it and/or modify
8
   it under the terms of the GNU General Public License as published by
9
   the Free Software Foundation; either version 2 of the License, or
10
   (at your option) any later version.
11
 
12
   This program is distributed in the hope that it will be useful,
13
   but WITHOUT ANY WARRANTY; without even the implied warranty of
14
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
   GNU General Public License for more details.
16
 
17
   You should have received a copy of the GNU General Public License
18
   along with this program; if not, write to the Free Software
19
   Foundation, Inc., 59 Temple Place - Suite 330,
20
   Boston, MA 02111-1307, USA.  */
21
 
22
#include "defs.h"
23
#include "ui-out.h"
24
#include "mi-out.h"
25
 
26
/* Convenience macro for allocting typesafe memory. */
27
 
28
#ifndef XMALLOC
29
#define XMALLOC(TYPE) (TYPE*) xmalloc (sizeof (TYPE))
30
#endif
31
 
32
struct ui_out_data
33
  {
34
    int suppress_field_separator;
35
    int suppress_output;
36
    int mi_version;
37
    struct ui_file *buffer;
38
  };
39
 
40
/* These are the MI output functions */
41
 
42
static void mi_table_begin (struct ui_out *uiout, int nbrofcols,
43
                            int nr_rows, const char *tblid);
44
static void mi_table_body (struct ui_out *uiout);
45
static void mi_table_end (struct ui_out *uiout);
46
static void mi_table_header (struct ui_out *uiout, int width,
47
                             enum ui_align alig, const char *col_name,
48
                             const char *colhdr);
49
static void mi_begin (struct ui_out *uiout, enum ui_out_type type,
50
                      int level, const char *id);
51
static void mi_end (struct ui_out *uiout, enum ui_out_type type, int level);
52
static void mi_field_int (struct ui_out *uiout, int fldno, int width,
53
                          enum ui_align alig, const char *fldname, int value);
54
static void mi_field_skip (struct ui_out *uiout, int fldno, int width,
55
                           enum ui_align alig, const char *fldname);
56
static void mi_field_string (struct ui_out *uiout, int fldno, int width,
57
                             enum ui_align alig, const char *fldname,
58
                             const char *string);
59
static void mi_field_fmt (struct ui_out *uiout, int fldno,
60
                          int width, enum ui_align align,
61
                          const char *fldname, const char *format,
62
                          va_list args);
63
static void mi_spaces (struct ui_out *uiout, int numspaces);
64
static void mi_text (struct ui_out *uiout, const char *string);
65
static void mi_message (struct ui_out *uiout, int verbosity,
66
                        const char *format, va_list args);
67
static void mi_wrap_hint (struct ui_out *uiout, char *identstring);
68
static void mi_flush (struct ui_out *uiout);
69
 
70
/* This is the MI ui-out implementation functions vector */
71
 
72
/* FIXME: This can be initialized dynamically after default is set to
73
   handle initial output in main.c */
74
 
75
struct ui_out_impl mi_ui_out_impl =
76
{
77
  mi_table_begin,
78
  mi_table_body,
79
  mi_table_end,
80
  mi_table_header,
81
  mi_begin,
82
  mi_end,
83
  mi_field_int,
84
  mi_field_skip,
85
  mi_field_string,
86
  mi_field_fmt,
87
  mi_spaces,
88
  mi_text,
89
  mi_message,
90
  mi_wrap_hint,
91
  mi_flush,
92
  1, /* Needs MI hacks.  */
93
};
94
 
95
/* Prototypes for local functions */
96
 
97
extern void _initialize_mi_out (void);
98
static void field_separator (struct ui_out *uiout);
99
static void mi_open (struct ui_out *uiout, const char *name,
100
                     enum ui_out_type type);
101
static void mi_close (struct ui_out *uiout, enum ui_out_type type);
102
 
103
static void out_field_fmt (struct ui_out *uiout, int fldno, char *fldname,
104
                           char *format,...);
105
 
106
/* Mark beginning of a table */
107
 
108
void
109
mi_table_begin (struct ui_out *uiout,
110
                int nr_cols,
111
                int nr_rows,
112
                const char *tblid)
113
{
114
  struct ui_out_data *data = ui_out_data (uiout);
115
  mi_open (uiout, tblid, ui_out_type_tuple);
116
  if (data->mi_version == 0)
117
    {
118
      if (nr_rows == 0)
119
        data->suppress_output = 1;
120
      else
121
        mi_open (uiout, "hdr", ui_out_type_list);
122
      return;
123
    }
124
  mi_field_int (uiout, -1/*fldno*/, -1/*width*/, -1/*alin*/,
125
                "nr_rows", nr_rows);
126
  mi_field_int (uiout, -1/*fldno*/, -1/*width*/, -1/*alin*/,
127
                "nr_cols", nr_cols);
128
  mi_open (uiout, "hdr", ui_out_type_list);
129
}
130
 
131
/* Mark beginning of a table body */
132
 
133
void
134
mi_table_body (struct ui_out *uiout)
135
{
136
  struct ui_out_data *data = ui_out_data (uiout);
137
  if (data->suppress_output)
138
    return;
139
  /* close the table header line if there were any headers */
140
  mi_close (uiout, ui_out_type_list);
141
  if (data->mi_version == 0)
142
    return;
143
  mi_open (uiout, "body", ui_out_type_list);
144
}
145
 
146
/* Mark end of a table */
147
 
148
void
149
mi_table_end (struct ui_out *uiout)
150
{
151
  struct ui_out_data *data = ui_out_data (uiout);
152
  data->suppress_output = 0;
153
  if (data->mi_version == 0)
154
    {
155
      mi_close (uiout, ui_out_type_tuple);
156
      return;
157
    }
158
  mi_close (uiout, ui_out_type_list); /* body */
159
  mi_close (uiout, ui_out_type_tuple);
160
}
161
 
162
/* Specify table header */
163
 
164
void
165
mi_table_header (struct ui_out *uiout, int width, int alignment,
166
                 const char *col_name,
167
                 const char *colhdr)
168
{
169
  struct ui_out_data *data = ui_out_data (uiout);
170
  if (data->suppress_output)
171
    return;
172
  if (data->mi_version == 0)
173
    {
174
      mi_field_string (uiout, 0, width, alignment, 0, colhdr);
175
      return;
176
    }
177
  mi_open (uiout, NULL, ui_out_type_tuple);
178
  mi_field_int (uiout, 0, 0, 0, "width", width);
179
  mi_field_int (uiout, 0, 0, 0, "alignment", alignment);
180
  mi_field_string (uiout, 0, 0, 0, "col_name", col_name);
181
  mi_field_string (uiout, 0, width, alignment, "colhdr", colhdr);
182
  mi_close (uiout, ui_out_type_tuple);
183
}
184
 
185
/* Mark beginning of a list */
186
 
187
void
188
mi_begin (struct ui_out *uiout,
189
          enum ui_out_type type,
190
          int level,
191
          const char *id)
192
{
193
  struct ui_out_data *data = ui_out_data (uiout);
194
  if (data->suppress_output)
195
    return;
196
  mi_open (uiout, id, type);
197
}
198
 
199
/* Mark end of a list */
200
 
201
void
202
mi_end (struct ui_out *uiout,
203
        enum ui_out_type type,
204
        int level)
205
{
206
  struct ui_out_data *data = ui_out_data (uiout);
207
  if (data->suppress_output)
208
    return;
209
  mi_close (uiout, type);
210
}
211
 
212
/* output an int field */
213
 
214
void
215
mi_field_int (struct ui_out *uiout, int fldno, int width, int alignment,
216
              const char *fldname, int value)
217
{
218
  char buffer[20];              /* FIXME: how many chars long a %d can become? */
219
  struct ui_out_data *data = ui_out_data (uiout);
220
  if (data->suppress_output)
221
    return;
222
 
223
  sprintf (buffer, "%d", value);
224
  mi_field_string (uiout, fldno, width, alignment, fldname, buffer);
225
}
226
 
227
/* used to ommit a field */
228
 
229
void
230
mi_field_skip (struct ui_out *uiout, int fldno, int width, int alignment,
231
               const char *fldname)
232
{
233
  struct ui_out_data *data = ui_out_data (uiout);
234
  if (data->suppress_output)
235
    return;
236
  mi_field_string (uiout, fldno, width, alignment, fldname, "");
237
}
238
 
239
/* other specific mi_field_* end up here so alignment and field
240
   separators are both handled by mi_field_string */
241
 
242
void
243
mi_field_string (struct ui_out *uiout,
244
                 int fldno,
245
                 int width,
246
                 int align,
247
                 const char *fldname,
248
                 const char *string)
249
{
250
  struct ui_out_data *data = ui_out_data (uiout);
251
  if (data->suppress_output)
252
    return;
253
  field_separator (uiout);
254
  if (fldname)
255
    fprintf_unfiltered (data->buffer, "%s=", fldname);
256
  fprintf_unfiltered (data->buffer, "\"");
257
  if (string)
258
    fputstr_unfiltered (string, '"', data->buffer);
259
  fprintf_unfiltered (data->buffer, "\"");
260
}
261
 
262
/* This is the only field function that does not align */
263
 
264
void
265
mi_field_fmt (struct ui_out *uiout, int fldno,
266
              int width, enum ui_align align,
267
              const char *fldname,
268
              const char *format,
269
              va_list args)
270
{
271
  struct ui_out_data *data = ui_out_data (uiout);
272
  if (data->suppress_output)
273
    return;
274
  field_separator (uiout);
275
  if (fldname)
276
    fprintf_unfiltered (data->buffer, "%s=\"", fldname);
277
  else
278
    fputs_unfiltered ("\"", data->buffer);
279
  vfprintf_unfiltered (data->buffer, format, args);
280
  fputs_unfiltered ("\"", data->buffer);
281
}
282
 
283
void
284
mi_spaces (struct ui_out *uiout, int numspaces)
285
{
286
}
287
 
288
void
289
mi_text (struct ui_out *uiout, const char *string)
290
{
291
}
292
 
293
void
294
mi_message (struct ui_out *uiout, int verbosity,
295
            const char *format,
296
            va_list args)
297
{
298
}
299
 
300
void
301
mi_wrap_hint (struct ui_out *uiout, char *identstring)
302
{
303
  wrap_here (identstring);
304
}
305
 
306
void
307
mi_flush (struct ui_out *uiout)
308
{
309
  struct ui_out_data *data = ui_out_data (uiout);
310
  gdb_flush (data->buffer);
311
}
312
 
313
/* local functions */
314
 
315
/* Like mi_field_fmt, but takes a variable number of args
316
   and makes a va_list and does not insert a separator */
317
 
318
/* VARARGS */
319
static void
320
out_field_fmt (struct ui_out *uiout, int fldno, char *fldname,
321
               char *format,...)
322
{
323
  struct ui_out_data *data = ui_out_data (uiout);
324
  va_list args;
325
 
326
  field_separator (uiout);
327
  if (fldname)
328
    fprintf_unfiltered (data->buffer, "%s=\"", fldname);
329
  else
330
    fputs_unfiltered ("\"", data->buffer);
331
 
332
  va_start (args, format);
333
  vfprintf_unfiltered (data->buffer, format, args);
334
 
335
  fputs_unfiltered ("\"", data->buffer);
336
 
337
  va_end (args);
338
}
339
 
340
/* access to ui_out format private members */
341
 
342
static void
343
field_separator (struct ui_out *uiout)
344
{
345
  struct ui_out_data *data = ui_out_data (uiout);
346
  if (data->suppress_field_separator)
347
    data->suppress_field_separator = 0;
348
  else
349
    fputc_unfiltered (',', data->buffer);
350
}
351
 
352
static void
353
mi_open (struct ui_out *uiout,
354
         const char *name,
355
         enum ui_out_type type)
356
{
357
  struct ui_out_data *data = ui_out_data (uiout);
358
  field_separator (uiout);
359
  data->suppress_field_separator = 1;
360
  if (name)
361
    fprintf_unfiltered (data->buffer, "%s=", name);
362
  switch (type)
363
    {
364
    case ui_out_type_tuple:
365
      fputc_unfiltered ('{', data->buffer);
366
      break;
367
    case ui_out_type_list:
368
      if (data->mi_version == 0)
369
        fputc_unfiltered ('{', data->buffer);
370
      else
371
        fputc_unfiltered ('[', data->buffer);
372
      break;
373
    default:
374
      internal_error (__FILE__, __LINE__, "bad switch");
375
    }
376
}
377
 
378
static void
379
mi_close (struct ui_out *uiout,
380
          enum ui_out_type type)
381
{
382
  struct ui_out_data *data = ui_out_data (uiout);
383
  switch (type)
384
    {
385
    case ui_out_type_tuple:
386
      fputc_unfiltered ('}', data->buffer);
387
      break;
388
    case ui_out_type_list:
389
      if (data->mi_version == 0)
390
        fputc_unfiltered ('}', data->buffer);
391
      else
392
        fputc_unfiltered (']', data->buffer);
393
      break;
394
    default:
395
      internal_error (__FILE__, __LINE__, "bad switch");
396
    }
397
  data->suppress_field_separator = 0;
398
}
399
 
400
/* add a string to the buffer */
401
 
402
void
403
mi_out_buffered (struct ui_out *uiout, char *string)
404
{
405
  struct ui_out_data *data = ui_out_data (uiout);
406
  fprintf_unfiltered (data->buffer, "%s", string);
407
}
408
 
409
/* clear the buffer */
410
 
411
void
412
mi_out_rewind (struct ui_out *uiout)
413
{
414
  struct ui_out_data *data = ui_out_data (uiout);
415
  ui_file_rewind (data->buffer);
416
}
417
 
418
/* dump the buffer onto the specified stream */
419
 
420
static void
421
do_write (void *data, const char *buffer, long length_buffer)
422
{
423
  ui_file_write (data, buffer, length_buffer);
424
}
425
 
426
void
427
mi_out_put (struct ui_out *uiout,
428
            struct ui_file *stream)
429
{
430
  struct ui_out_data *data = ui_out_data (uiout);
431
  ui_file_put (data->buffer, do_write, stream);
432
  ui_file_rewind (data->buffer);
433
}
434
 
435
/* initalize private members at startup */
436
 
437
struct ui_out *
438
mi_out_new (int mi_version)
439
{
440
  int flags = 0;
441
  struct ui_out_data *data = XMALLOC (struct ui_out_data);
442
  data->suppress_field_separator = 0;
443
  data->mi_version = mi_version;
444
  /* FIXME: This code should be using a ``string_file'' and not the
445
     TUI buffer hack. */
446
  data->buffer = mem_fileopen ();
447
  return ui_out_new (&mi_ui_out_impl, data, flags);
448
}
449
 
450
/* standard gdb initialization hook */
451
void
452
_initialize_mi_out (void)
453
{
454
  /* nothing happens here */
455
}

powered by: WebSVN 2.1.0

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