| 1 | /* Output generating routines for GDB. |
| 2 | Copyright 1999, 2000 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 | |
| 29 | /* Convenience macro for allocting typesafe memory. */ |
| 30 | |
| 31 | #undef XMALLOC |
| 32 | #define XMALLOC(TYPE) (TYPE*) xmalloc (sizeof (TYPE)) |
| 33 | |
| 34 | /* table header structures */ |
| 35 | |
| 36 | struct ui_out_hdr |
| 37 | { |
| 38 | int colno; |
| 39 | int width; |
| 40 | int alignment; |
| 41 | char *colhdr; |
| 42 | struct ui_out_hdr *next; |
| 43 | }; |
| 44 | |
| 45 | /* The ui_out structure */ |
| 46 | /* Any change here requires a corresponding one in the initialization |
| 47 | of the default uiout, which is statically initialized */ |
| 48 | |
| 49 | struct ui_out |
| 50 | { |
| 51 | int flags; |
| 52 | /* specific implementation of ui-out */ |
| 53 | struct ui_out_impl *impl; |
| 54 | struct ui_out_data *data; |
| 55 | |
| 56 | /* if on, a table is being generated */ |
| 57 | int table_flag; |
| 58 | |
| 59 | /* if on, the body of a table is being generated */ |
| 60 | int body_flag; |
| 61 | |
| 62 | /* number of table columns (as specified in the table_begin call) */ |
| 63 | int table_columns; |
| 64 | |
| 65 | /* strinf identifying the table (as specified in the table_begin call) */ |
| 66 | char *table_id; |
| 67 | |
| 68 | /* if on, a list is being generated. The value is the level of nesting */ |
| 69 | int list_flag; |
| 70 | |
| 71 | /* we count each field; the first element is for non-list fields */ |
| 72 | int field_count[5]; |
| 73 | |
| 74 | /* points to the first header (if any) */ |
| 75 | struct ui_out_hdr *headerfirst; |
| 76 | |
| 77 | /* points to the last header (if any) */ |
| 78 | struct ui_out_hdr *headerlast; |
| 79 | |
| 80 | /* points to header of next column to format */ |
| 81 | struct ui_out_hdr *headercurr; |
| 82 | |
| 83 | }; |
| 84 | |
| 85 | /* These are the default implementation functions */ |
| 86 | |
| 87 | static void default_table_begin (struct ui_out *uiout, int nbrofcols, |
| 88 | char *tblid); |
| 89 | static void default_table_body (struct ui_out *uiout); |
| 90 | static void default_table_end (struct ui_out *uiout); |
| 91 | static void default_table_header (struct ui_out *uiout, int width, |
| 92 | enum ui_align alig, char *colhdr); |
| 93 | static void default_list_begin (struct ui_out *uiout, int list_flag, |
| 94 | char *lstid); |
| 95 | static void default_list_end (struct ui_out *uiout, int list_flag); |
| 96 | static void default_field_int (struct ui_out *uiout, int fldno, int width, |
| 97 | enum ui_align alig, char *fldname, int value); |
| 98 | static void default_field_skip (struct ui_out *uiout, int fldno, int width, |
| 99 | enum ui_align alig, char *fldname); |
| 100 | static void default_field_string (struct ui_out *uiout, int fldno, int width, |
| 101 | enum ui_align align, char *fldname, |
| 102 | const char *string); |
| 103 | static void default_field_fmt (struct ui_out *uiout, int fldno, |
| 104 | int width, enum ui_align align, |
| 105 | char *fldname, char *format, va_list args); |
| 106 | static void default_spaces (struct ui_out *uiout, int numspaces); |
| 107 | static void default_text (struct ui_out *uiout, char *string); |
| 108 | static void default_message (struct ui_out *uiout, int verbosity, char *format, |
| 109 | va_list args); |
| 110 | static void default_wrap_hint (struct ui_out *uiout, char *identstring); |
| 111 | static void default_flush (struct ui_out *uiout); |
| 112 | |
| 113 | /* This is the default ui-out implementation functions vector */ |
| 114 | |
| 115 | struct ui_out_impl default_ui_out_impl = |
| 116 | { |
| 117 | default_table_begin, |
| 118 | default_table_body, |
| 119 | default_table_end, |
| 120 | default_table_header, |
| 121 | default_list_begin, |
| 122 | default_list_end, |
| 123 | default_field_int, |
| 124 | default_field_skip, |
| 125 | default_field_string, |
| 126 | default_field_fmt, |
| 127 | default_spaces, |
| 128 | default_text, |
| 129 | default_message, |
| 130 | default_wrap_hint, |
| 131 | default_flush |
| 132 | }; |
| 133 | |
| 134 | /* The default ui_out */ |
| 135 | |
| 136 | struct ui_out def_uiout = |
| 137 | { |
| 138 | 0, /* flags */ |
| 139 | &default_ui_out_impl, /* impl */ |
| 140 | }; |
| 141 | |
| 142 | /* Pointer to current ui_out */ |
| 143 | /* FIXME: This should not be a global, but something passed down from main.c |
| 144 | or top.c */ |
| 145 | |
| 146 | struct ui_out *uiout = &def_uiout; |
| 147 | |
| 148 | /* These are the interfaces to implementation functions */ |
| 149 | |
| 150 | static void uo_table_begin (struct ui_out *uiout, int nbrofcols, char *tblid); |
| 151 | static void uo_table_body (struct ui_out *uiout); |
| 152 | static void uo_table_end (struct ui_out *uiout); |
| 153 | static void uo_table_header (struct ui_out *uiout, int width, |
| 154 | enum ui_align align, char *colhdr); |
| 155 | static void uo_list_begin (struct ui_out *uiout, int list_flag, char *lstid); |
| 156 | static void uo_list_end (struct ui_out *uiout, int list_flag); |
| 157 | static void uo_field_int (struct ui_out *uiout, int fldno, int width, |
| 158 | enum ui_align align, char *fldname, int value); |
| 159 | static void uo_field_skip (struct ui_out *uiout, int fldno, int width, |
| 160 | enum ui_align align, char *fldname); |
| 161 | static void uo_field_string (struct ui_out *uiout, int fldno, int width, |
| 162 | enum ui_align align, char *fldname, const char *string); |
| 163 | static void uo_field_fmt (struct ui_out *uiout, int fldno, int width, |
| 164 | enum ui_align align, char *fldname, |
| 165 | char *format, va_list args); |
| 166 | static void uo_spaces (struct ui_out *uiout, int numspaces); |
| 167 | static void uo_text (struct ui_out *uiout, char *string); |
| 168 | static void uo_message (struct ui_out *uiout, int verbosity, |
| 169 | char *format, va_list args); |
| 170 | static void uo_wrap_hint (struct ui_out *uiout, char *identstring); |
| 171 | static void uo_flush (struct ui_out *uiout); |
| 172 | |
| 173 | /* Prototypes for local functions */ |
| 174 | |
| 175 | extern void _initialize_ui_out (void); |
| 176 | static void append_header_to_list (struct ui_out *uiout, int width, int alignment, char *colhdr); |
| 177 | static int get_curr_header (struct ui_out *uiout, int *colno, int *width, |
| 178 | int *alignment, char **colhdr); |
| 179 | static void clear_header_list (struct ui_out *uiout); |
| 180 | static void verify_field_proper_position (struct ui_out *uiout); |
| 181 | static void verify_field_alignment (struct ui_out *uiout, int fldno, int *width, int *alignment); |
| 182 | |
| 183 | static void init_ui_out_state (struct ui_out *uiout); |
| 184 | |
| 185 | /* exported functions (ui_out API) */ |
| 186 | |
| 187 | /* Mark beginning of a table */ |
| 188 | |
| 189 | void |
| 190 | ui_out_table_begin (struct ui_out *uiout, int nbrofcols, char *tblid) |
| 191 | { |
| 192 | if (uiout->table_flag) |
| 193 | internal_error ("gdb/ui_out.c: tables cannot be nested; table_begin found before \ |
| 194 | previous table_end."); |
| 195 | |
| 196 | uiout->table_flag = 1; |
| 197 | uiout->table_columns = nbrofcols; |
| 198 | if (tblid != NULL) |
| 199 | uiout->table_id = xstrdup (tblid); |
| 200 | else |
| 201 | uiout->table_id = NULL; |
| 202 | clear_header_list (uiout); |
| 203 | |
| 204 | uo_table_begin (uiout, nbrofcols, uiout->table_id); |
| 205 | } |
| 206 | |
| 207 | void |
| 208 | ui_out_table_body (struct ui_out *uiout) |
| 209 | { |
| 210 | if (!uiout->table_flag) |
| 211 | internal_error ("gdb/ui_out.c: table_body outside a table is not valid; it must be \ |
| 212 | after a table_begin and before a table_end."); |
| 213 | if (uiout->body_flag) |
| 214 | internal_error ("gdb/ui_out.c: extra table_body call not allowed; there must be \ |
| 215 | only one table_body after a table_begin and before a table_end."); |
| 216 | if (uiout->headercurr->colno != uiout->table_columns) |
| 217 | internal_error ("gdb/ui_out.c: number of headers differ from number of table \ |
| 218 | columns."); |
| 219 | |
| 220 | uiout->body_flag = 1; |
| 221 | uiout->headercurr = uiout->headerfirst; |
| 222 | |
| 223 | uo_table_body (uiout); |
| 224 | } |
| 225 | |
| 226 | void |
| 227 | ui_out_table_end (struct ui_out *uiout) |
| 228 | { |
| 229 | if (!uiout->table_flag) |
| 230 | internal_error ("gdb/ui_out.c: misplaced table_end or missing table_begin."); |
| 231 | |
| 232 | uiout->body_flag = 0; |
| 233 | uiout->table_flag = 0; |
| 234 | |
| 235 | uo_table_end (uiout); |
| 236 | |
| 237 | if (uiout->table_id) |
| 238 | free (uiout->table_id); |
| 239 | clear_header_list (uiout); |
| 240 | } |
| 241 | |
| 242 | void |
| 243 | ui_out_table_header (struct ui_out *uiout, int width, enum ui_align alignment, |
| 244 | char *colhdr) |
| 245 | { |
| 246 | if (!uiout->table_flag || uiout->body_flag) |
| 247 | internal_error ("ui_out: table header must be specified after table_begin \ |
| 248 | and before table_body."); |
| 249 | |
| 250 | append_header_to_list (uiout, width, alignment, colhdr); |
| 251 | |
| 252 | uo_table_header (uiout, width, alignment, colhdr); |
| 253 | } |
| 254 | |
| 255 | void |
| 256 | ui_out_list_begin (struct ui_out *uiout, char *lstid) |
| 257 | { |
| 258 | if (uiout->table_flag && !uiout->body_flag) |
| 259 | internal_error ("ui_out: table header or table_body expected; lists must be \ |
| 260 | specified after table_body."); |
| 261 | if (uiout->list_flag >= 4) |
| 262 | internal_error ("ui_out: list depth exceeded; only 4 levels of lists can be \ |
| 263 | nested."); |
| 264 | |
| 265 | uiout->list_flag++; |
| 266 | uiout->field_count[uiout->list_flag] = 0; |
| 267 | if (uiout->table_flag && (uiout->list_flag == 1)) |
| 268 | uiout->headercurr = uiout->headerfirst; |
| 269 | |
| 270 | uo_list_begin (uiout, uiout->list_flag, lstid); |
| 271 | } |
| 272 | |
| 273 | void |
| 274 | ui_out_list_end (struct ui_out *uiout) |
| 275 | { |
| 276 | if (!uiout->list_flag) |
| 277 | internal_error ("ui_out: misplaced list_end; there is no list to be closed."); |
| 278 | |
| 279 | uo_list_end (uiout, uiout->list_flag); |
| 280 | |
| 281 | uiout->list_flag--; |
| 282 | } |
| 283 | |
| 284 | void |
| 285 | ui_out_field_int (struct ui_out *uiout, char *fldname, int value) |
| 286 | { |
| 287 | int fldno; |
| 288 | int width; |
| 289 | int align; |
| 290 | |
| 291 | verify_field_proper_position (uiout); |
| 292 | |
| 293 | uiout->field_count[uiout->list_flag] += 1; |
| 294 | fldno = uiout->field_count[uiout->list_flag]; |
| 295 | |
| 296 | verify_field_alignment (uiout, fldno, &width, &align); |
| 297 | |
| 298 | uo_field_int (uiout, fldno, width, align, fldname, value); |
| 299 | } |
| 300 | |
| 301 | void |
| 302 | ui_out_field_core_addr (struct ui_out *uiout, char *fldname, CORE_ADDR address) |
| 303 | { |
| 304 | char addstr[20]; |
| 305 | |
| 306 | /* FIXME-32x64: need a print_address_numeric with field width */ |
| 307 | /* print_address_numeric (address, 1, local_stream); */ |
| 308 | strcpy (addstr, local_hex_string_custom ((unsigned long) address, "08l")); |
| 309 | |
| 310 | ui_out_field_string (uiout, fldname, addstr); |
| 311 | } |
| 312 | |
| 313 | void |
| 314 | ui_out_field_stream (struct ui_out *uiout, char *fldname, struct ui_stream *buf) |
| 315 | { |
| 316 | long length; |
| 317 | char *buffer = ui_file_xstrdup (buf->stream, &length); |
| 318 | struct cleanup *old_cleanup = make_cleanup (free, buffer); |
| 319 | if (length > 0) |
| 320 | ui_out_field_string (uiout, fldname, buffer); |
| 321 | else |
| 322 | ui_out_field_skip (uiout, fldname); |
| 323 | ui_file_rewind (buf->stream); |
| 324 | do_cleanups (old_cleanup); |
| 325 | } |
| 326 | |
| 327 | /* used to ommit a field */ |
| 328 | |
| 329 | void |
| 330 | ui_out_field_skip (struct ui_out *uiout, char *fldname) |
| 331 | { |
| 332 | int fldno; |
| 333 | int width; |
| 334 | int align; |
| 335 | |
| 336 | verify_field_proper_position (uiout); |
| 337 | |
| 338 | uiout->field_count[uiout->list_flag] += 1; |
| 339 | fldno = uiout->field_count[uiout->list_flag]; |
| 340 | |
| 341 | verify_field_alignment (uiout, fldno, &width, &align); |
| 342 | |
| 343 | uo_field_skip (uiout, fldno, width, align, fldname); |
| 344 | } |
| 345 | |
| 346 | void |
| 347 | ui_out_field_string (struct ui_out *uiout, |
| 348 | char *fldname, |
| 349 | const char *string) |
| 350 | { |
| 351 | int fldno; |
| 352 | int width; |
| 353 | int align; |
| 354 | |
| 355 | verify_field_proper_position (uiout); |
| 356 | |
| 357 | uiout->field_count[uiout->list_flag] += 1; |
| 358 | fldno = uiout->field_count[uiout->list_flag]; |
| 359 | |
| 360 | verify_field_alignment (uiout, fldno, &width, &align); |
| 361 | |
| 362 | uo_field_string (uiout, fldno, width, align, fldname, string); |
| 363 | } |
| 364 | |
| 365 | /* VARARGS */ |
| 366 | void |
| 367 | ui_out_field_fmt (struct ui_out *uiout, char *fldname, char *format,...) |
| 368 | { |
| 369 | va_list args; |
| 370 | int fldno; |
| 371 | int width; |
| 372 | int align; |
| 373 | |
| 374 | verify_field_proper_position (uiout); |
| 375 | |
| 376 | uiout->field_count[uiout->list_flag] += 1; |
| 377 | fldno = uiout->field_count[uiout->list_flag]; |
| 378 | |
| 379 | /* will not align, but has to call anyway */ |
| 380 | verify_field_alignment (uiout, fldno, &width, &align); |
| 381 | |
| 382 | va_start (args, format); |
| 383 | |
| 384 | uo_field_fmt (uiout, fldno, width, align, fldname, format, args); |
| 385 | |
| 386 | va_end (args); |
| 387 | } |
| 388 | |
| 389 | void |
| 390 | ui_out_spaces (struct ui_out *uiout, int numspaces) |
| 391 | { |
| 392 | uo_spaces (uiout, numspaces); |
| 393 | } |
| 394 | |
| 395 | void |
| 396 | ui_out_text (struct ui_out *uiout, char *string) |
| 397 | { |
| 398 | uo_text (uiout, string); |
| 399 | } |
| 400 | |
| 401 | void |
| 402 | ui_out_message (struct ui_out *uiout, int verbosity, char *format,...) |
| 403 | { |
| 404 | va_list args; |
| 405 | |
| 406 | va_start (args, format); |
| 407 | |
| 408 | uo_message (uiout, verbosity, format, args); |
| 409 | |
| 410 | va_end (args); |
| 411 | } |
| 412 | |
| 413 | struct ui_stream * |
| 414 | ui_out_stream_new (struct ui_out *uiout) |
| 415 | { |
| 416 | struct ui_stream *tempbuf; |
| 417 | |
| 418 | tempbuf = XMALLOC (struct ui_stream); |
| 419 | tempbuf->uiout = uiout; |
| 420 | tempbuf->stream = mem_fileopen (); |
| 421 | return tempbuf; |
| 422 | } |
| 423 | |
| 424 | void |
| 425 | ui_out_stream_delete (struct ui_stream *buf) |
| 426 | { |
| 427 | ui_file_delete (buf->stream); |
| 428 | free (buf); |
| 429 | } |
| 430 | |
| 431 | static void |
| 432 | do_stream_delete (void *buf) |
| 433 | { |
| 434 | ui_out_stream_delete (buf); |
| 435 | } |
| 436 | |
| 437 | struct cleanup * |
| 438 | make_cleanup_ui_out_stream_delete (struct ui_stream *buf) |
| 439 | { |
| 440 | return make_cleanup (do_stream_delete, buf); |
| 441 | } |
| 442 | |
| 443 | |
| 444 | void |
| 445 | ui_out_wrap_hint (struct ui_out *uiout, char *identstring) |
| 446 | { |
| 447 | uo_wrap_hint (uiout, identstring); |
| 448 | } |
| 449 | |
| 450 | void |
| 451 | ui_out_flush (struct ui_out *uiout) |
| 452 | { |
| 453 | uo_flush (uiout); |
| 454 | } |
| 455 | |
| 456 | /* set the flags specified by the mask given */ |
| 457 | int |
| 458 | ui_out_set_flags (struct ui_out *uiout, int mask) |
| 459 | { |
| 460 | int oldflags = uiout->flags; |
| 461 | |
| 462 | uiout->flags |= mask; |
| 463 | |
| 464 | return oldflags; |
| 465 | } |
| 466 | |
| 467 | /* clear the flags specified by the mask given */ |
| 468 | int |
| 469 | ui_out_clear_flags (struct ui_out *uiout, int mask) |
| 470 | { |
| 471 | int oldflags = uiout->flags; |
| 472 | |
| 473 | uiout->flags &= ~mask; |
| 474 | |
| 475 | return oldflags; |
| 476 | } |
| 477 | |
| 478 | /* test the flags against the mask given */ |
| 479 | int |
| 480 | ui_out_test_flags (struct ui_out *uiout, int mask) |
| 481 | { |
| 482 | return (uiout->flags & mask); |
| 483 | } |
| 484 | |
| 485 | /* obtain the current verbosity level (as stablished by the |
| 486 | 'set verbositylevel' command */ |
| 487 | |
| 488 | int |
| 489 | ui_out_get_verblvl (struct ui_out *uiout) |
| 490 | { |
| 491 | /* FIXME: not implemented yet */ |
| 492 | return 0; |
| 493 | } |
| 494 | |
| 495 | #if 0 |
| 496 | void |
| 497 | ui_out_result_begin (struct ui_out *uiout, char *class) |
| 498 | { |
| 499 | } |
| 500 | |
| 501 | void |
| 502 | ui_out_result_end (struct ui_out *uiout) |
| 503 | { |
| 504 | } |
| 505 | |
| 506 | void |
| 507 | ui_out_info_begin (struct ui_out *uiout, char *class) |
| 508 | { |
| 509 | } |
| 510 | |
| 511 | void |
| 512 | ui_out_info_end (struct ui_out *uiout) |
| 513 | { |
| 514 | } |
| 515 | |
| 516 | void |
| 517 | ui_out_notify_begin (struct ui_out *uiout, char *class) |
| 518 | { |
| 519 | } |
| 520 | |
| 521 | void |
| 522 | ui_out_notify_end (struct ui_out *uiout) |
| 523 | { |
| 524 | } |
| 525 | |
| 526 | void |
| 527 | ui_out_error_begin (struct ui_out *uiout, char *class) |
| 528 | { |
| 529 | } |
| 530 | |
| 531 | void |
| 532 | ui_out_error_end (struct ui_out *uiout) |
| 533 | { |
| 534 | } |
| 535 | #endif |
| 536 | |
| 537 | #if 0 |
| 538 | void |
| 539 | gdb_error (ui_out * uiout, int severity, char *format,...) |
| 540 | { |
| 541 | va_list args; |
| 542 | } |
| 543 | |
| 544 | void |
| 545 | gdb_query (struct ui_out *uiout, int qflags, char *qprompt) |
| 546 | { |
| 547 | } |
| 548 | #endif |
| 549 | |
| 550 | /* default gdb-out hook functions */ |
| 551 | |
| 552 | static void |
| 553 | default_table_begin (struct ui_out *uiout, int nbrofcols, char *tblid) |
| 554 | { |
| 555 | } |
| 556 | |
| 557 | static void |
| 558 | default_table_body (struct ui_out *uiout) |
| 559 | { |
| 560 | } |
| 561 | |
| 562 | static void |
| 563 | default_table_end (struct ui_out *uiout) |
| 564 | { |
| 565 | } |
| 566 | |
| 567 | static void |
| 568 | default_table_header (struct ui_out *uiout, int width, enum ui_align alignment, |
| 569 | char *colhdr) |
| 570 | { |
| 571 | } |
| 572 | |
| 573 | static void |
| 574 | default_list_begin (struct ui_out *uiout, int list_flag, char *lstid) |
| 575 | { |
| 576 | } |
| 577 | |
| 578 | static void |
| 579 | default_list_end (struct ui_out *uiout, int list_flag) |
| 580 | { |
| 581 | } |
| 582 | |
| 583 | static void |
| 584 | default_field_int (struct ui_out *uiout, int fldno, int width, |
| 585 | enum ui_align align, char *fldname, int value) |
| 586 | { |
| 587 | } |
| 588 | |
| 589 | static void |
| 590 | default_field_skip (struct ui_out *uiout, int fldno, int width, |
| 591 | enum ui_align align, char *fldname) |
| 592 | { |
| 593 | } |
| 594 | |
| 595 | static void |
| 596 | default_field_string (struct ui_out *uiout, |
| 597 | int fldno, |
| 598 | int width, |
| 599 | enum ui_align align, |
| 600 | char *fldname, |
| 601 | const char *string) |
| 602 | { |
| 603 | } |
| 604 | |
| 605 | static void |
| 606 | default_field_fmt (struct ui_out *uiout, int fldno, int width, |
| 607 | enum ui_align align, char *fldname, char *format, |
| 608 | va_list args) |
| 609 | { |
| 610 | } |
| 611 | |
| 612 | static void |
| 613 | default_spaces (struct ui_out *uiout, int numspaces) |
| 614 | { |
| 615 | } |
| 616 | |
| 617 | static void |
| 618 | default_text (struct ui_out *uiout, char *string) |
| 619 | { |
| 620 | } |
| 621 | |
| 622 | static void |
| 623 | default_message (struct ui_out *uiout, int verbosity, char *format, |
| 624 | va_list args) |
| 625 | { |
| 626 | } |
| 627 | |
| 628 | static void |
| 629 | default_wrap_hint (struct ui_out *uiout, char *identstring) |
| 630 | { |
| 631 | } |
| 632 | |
| 633 | static void |
| 634 | default_flush (struct ui_out *uiout) |
| 635 | { |
| 636 | } |
| 637 | |
| 638 | /* Interface to the implementation functions */ |
| 639 | |
| 640 | void |
| 641 | uo_table_begin (struct ui_out *uiout, int nbrofcols, char *tblid) |
| 642 | { |
| 643 | if (!uiout->impl->table_begin) |
| 644 | return; |
| 645 | uiout->impl->table_begin (uiout, nbrofcols, tblid); |
| 646 | } |
| 647 | |
| 648 | void |
| 649 | uo_table_body (struct ui_out *uiout) |
| 650 | { |
| 651 | if (!uiout->impl->table_body) |
| 652 | return; |
| 653 | uiout->impl->table_body (uiout); |
| 654 | } |
| 655 | |
| 656 | void |
| 657 | uo_table_end (struct ui_out *uiout) |
| 658 | { |
| 659 | if (!uiout->impl->table_end) |
| 660 | return; |
| 661 | uiout->impl->table_end (uiout); |
| 662 | } |
| 663 | |
| 664 | void |
| 665 | uo_table_header (struct ui_out *uiout, int width, enum ui_align align, char *colhdr) |
| 666 | { |
| 667 | if (!uiout->impl->table_header) |
| 668 | return; |
| 669 | uiout->impl->table_header (uiout, width, align, colhdr); |
| 670 | } |
| 671 | |
| 672 | void |
| 673 | uo_list_begin (struct ui_out *uiout, int list_flag, char *lstid) |
| 674 | { |
| 675 | if (!uiout->impl->list_begin) |
| 676 | return; |
| 677 | uiout->impl->list_begin (uiout, list_flag, lstid); |
| 678 | } |
| 679 | |
| 680 | void |
| 681 | uo_list_end (struct ui_out *uiout, int list_flag) |
| 682 | { |
| 683 | if (!uiout->impl->list_end) |
| 684 | return; |
| 685 | uiout->impl->list_end (uiout, list_flag); |
| 686 | } |
| 687 | |
| 688 | void |
| 689 | uo_field_int (struct ui_out *uiout, int fldno, int width, enum ui_align align, char *fldname, int value) |
| 690 | { |
| 691 | if (!uiout->impl->field_int) |
| 692 | return; |
| 693 | uiout->impl->field_int (uiout, fldno, width, align, fldname, value); |
| 694 | } |
| 695 | |
| 696 | void |
| 697 | uo_field_skip (struct ui_out *uiout, int fldno, int width, enum ui_align align, char *fldname) |
| 698 | { |
| 699 | if (!uiout->impl->field_skip) |
| 700 | return; |
| 701 | uiout->impl->field_skip (uiout, fldno, width, align, fldname); |
| 702 | } |
| 703 | |
| 704 | void |
| 705 | uo_field_string (struct ui_out *uiout, int fldno, int width, |
| 706 | enum ui_align align, char *fldname, const char *string) |
| 707 | { |
| 708 | if (!uiout->impl->field_string) |
| 709 | return; |
| 710 | uiout->impl->field_string (uiout, fldno, width, align, fldname, string); |
| 711 | } |
| 712 | |
| 713 | void |
| 714 | uo_field_fmt (struct ui_out *uiout, int fldno, int width, enum ui_align align, char *fldname, char *format, va_list args) |
| 715 | { |
| 716 | if (!uiout->impl->field_fmt) |
| 717 | return; |
| 718 | uiout->impl->field_fmt (uiout, fldno, width, align, fldname, format, args); |
| 719 | } |
| 720 | |
| 721 | void |
| 722 | uo_spaces (struct ui_out *uiout, int numspaces) |
| 723 | { |
| 724 | if (!uiout->impl->spaces) |
| 725 | return; |
| 726 | uiout->impl->spaces (uiout, numspaces); |
| 727 | } |
| 728 | |
| 729 | void |
| 730 | uo_text (struct ui_out *uiout, char *string) |
| 731 | { |
| 732 | if (!uiout->impl->text) |
| 733 | return; |
| 734 | uiout->impl->text (uiout, string); |
| 735 | } |
| 736 | |
| 737 | void |
| 738 | uo_message (struct ui_out *uiout, int verbosity, char *format, va_list args) |
| 739 | { |
| 740 | if (!uiout->impl->message) |
| 741 | return; |
| 742 | uiout->impl->message (uiout, verbosity, format, args); |
| 743 | } |
| 744 | |
| 745 | void |
| 746 | uo_wrap_hint (struct ui_out *uiout, char *identstring) |
| 747 | { |
| 748 | if (!uiout->impl->wrap_hint) |
| 749 | return; |
| 750 | uiout->impl->wrap_hint (uiout, identstring); |
| 751 | } |
| 752 | |
| 753 | void |
| 754 | uo_flush (struct ui_out *uiout) |
| 755 | { |
| 756 | if (!uiout->impl->flush) |
| 757 | return; |
| 758 | uiout->impl->flush (uiout); |
| 759 | } |
| 760 | |
| 761 | /* local functions */ |
| 762 | |
| 763 | /* list of column headers manipulation routines */ |
| 764 | |
| 765 | static void |
| 766 | clear_header_list (struct ui_out *uiout) |
| 767 | { |
| 768 | while (uiout->headerfirst != NULL) |
| 769 | { |
| 770 | uiout->headercurr = uiout->headerfirst; |
| 771 | uiout->headerfirst = uiout->headerfirst->next; |
| 772 | if (uiout->headercurr->colhdr != NULL) |
| 773 | free (uiout->headercurr->colhdr); |
| 774 | free (uiout->headercurr); |
| 775 | } |
| 776 | uiout->headerlast = NULL; |
| 777 | uiout->headercurr = NULL; |
| 778 | } |
| 779 | |
| 780 | static void |
| 781 | append_header_to_list (struct ui_out *uiout, |
| 782 | int width, |
| 783 | int alignment, |
| 784 | char *colhdr) |
| 785 | { |
| 786 | struct ui_out_hdr *temphdr; |
| 787 | |
| 788 | temphdr = XMALLOC (struct ui_out_hdr); |
| 789 | temphdr->width = width; |
| 790 | temphdr->alignment = alignment; |
| 791 | /* we have to copy the column title as the original may be an automatic */ |
| 792 | if (colhdr != NULL) |
| 793 | { |
| 794 | temphdr->colhdr = xmalloc (strlen (colhdr) + 1); |
| 795 | strcpy (temphdr->colhdr, colhdr); |
| 796 | } |
| 797 | temphdr->next = NULL; |
| 798 | if (uiout->headerfirst == NULL) |
| 799 | { |
| 800 | temphdr->colno = 1; |
| 801 | uiout->headerfirst = temphdr; |
| 802 | uiout->headerlast = temphdr; |
| 803 | } |
| 804 | else |
| 805 | { |
| 806 | temphdr->colno = uiout->headerlast->colno + 1; |
| 807 | uiout->headerlast->next = temphdr; |
| 808 | uiout->headerlast = temphdr; |
| 809 | } |
| 810 | uiout->headercurr = uiout->headerlast; |
| 811 | } |
| 812 | |
| 813 | /* returns 0 if there is no more headers */ |
| 814 | |
| 815 | static int |
| 816 | get_curr_header (struct ui_out *uiout, |
| 817 | int *colno, |
| 818 | int *width, |
| 819 | int *alignment, |
| 820 | char **colhdr) |
| 821 | { |
| 822 | /* There may be no headers at all or we may have used all columns */ |
| 823 | if (uiout->headercurr == NULL) |
| 824 | return 0; |
| 825 | *colno = uiout->headercurr->colno; |
| 826 | *width = uiout->headercurr->width; |
| 827 | *alignment = uiout->headercurr->alignment; |
| 828 | *colhdr = uiout->headercurr->colhdr; |
| 829 | uiout->headercurr = uiout->headercurr->next; |
| 830 | return 1; |
| 831 | } |
| 832 | |
| 833 | /* makes sure the field_* calls were properly placed */ |
| 834 | |
| 835 | static void |
| 836 | verify_field_proper_position (struct ui_out *uiout) |
| 837 | { |
| 838 | if (uiout->table_flag) |
| 839 | { |
| 840 | if (!uiout->body_flag) |
| 841 | internal_error ("ui_out: table_body missing; table fields must be \ |
| 842 | specified after table_body and inside a list."); |
| 843 | if (!uiout->list_flag) |
| 844 | internal_error ("ui_out: list_begin missing; table fields must be \ |
| 845 | specified after table_body and inside a list."); |
| 846 | } |
| 847 | } |
| 848 | |
| 849 | /* determines what is the alignment policy */ |
| 850 | |
| 851 | static void |
| 852 | verify_field_alignment (struct ui_out *uiout, |
| 853 | int fldno, |
| 854 | int *width, |
| 855 | int *align) |
| 856 | { |
| 857 | int colno; |
| 858 | char *text; |
| 859 | |
| 860 | if (uiout->table_flag |
| 861 | && get_curr_header (uiout, &colno, width, align, &text)) |
| 862 | { |
| 863 | if (fldno != colno) |
| 864 | internal_error ("gdb/ui-out.c: ui-out internal error in handling headers."); |
| 865 | } |
| 866 | else |
| 867 | { |
| 868 | *width = 0; |
| 869 | *align = ui_noalign; |
| 870 | } |
| 871 | } |
| 872 | |
| 873 | /* access to ui_out format private members */ |
| 874 | |
| 875 | void |
| 876 | ui_out_get_field_separator (struct ui_out *uiout) |
| 877 | { |
| 878 | } |
| 879 | |
| 880 | /* Access to ui-out members data */ |
| 881 | |
| 882 | struct ui_out_data * |
| 883 | ui_out_data (struct ui_out *uiout) |
| 884 | { |
| 885 | return uiout->data; |
| 886 | } |
| 887 | |
| 888 | /* initalize private members at startup */ |
| 889 | |
| 890 | struct ui_out * |
| 891 | ui_out_new (struct ui_out_impl *impl, |
| 892 | struct ui_out_data *data, |
| 893 | int flags) |
| 894 | { |
| 895 | struct ui_out *uiout = XMALLOC (struct ui_out); |
| 896 | uiout->data = data; |
| 897 | uiout->impl = impl; |
| 898 | uiout->flags = flags; |
| 899 | uiout->table_flag = 0; |
| 900 | uiout->body_flag = 0; |
| 901 | uiout->list_flag = 0; |
| 902 | uiout->field_count[0] = 0; |
| 903 | uiout->headerfirst = NULL; |
| 904 | uiout->headerlast = NULL; |
| 905 | uiout->headercurr = NULL; |
| 906 | return uiout; |
| 907 | } |
| 908 | |
| 909 | /* standard gdb initialization hook */ |
| 910 | |
| 911 | void |
| 912 | _initialize_ui_out (void) |
| 913 | { |
| 914 | /* nothing needs to be done */ |
| 915 | } |