1 /* TUI data manipulation routines. 2 3 Copyright (C) 1998-2004, 2006-2012 Free Software Foundation, Inc. 4 5 Contributed by Hewlett-Packard Company. 6 7 This file is part of GDB. 8 9 This program is free software; you can redistribute it and/or modify 10 it under the terms of the GNU General Public License as published by 11 the Free Software Foundation; either version 3 of the License, or 12 (at your option) any later version. 13 14 This program is distributed in the hope that it will be useful, 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 GNU General Public License for more details. 18 19 You should have received a copy of the GNU General Public License 20 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 21 22 #include "defs.h" 23 #include "symtab.h" 24 #include "tui/tui.h" 25 #include "tui/tui-data.h" 26 #include "tui/tui-wingeneral.h" 27 28 #include "gdb_string.h" 29 #include "gdb_curses.h" 30 31 /**************************** 32 ** GLOBAL DECLARATIONS 33 ****************************/ 34 struct tui_win_info *(tui_win_list[MAX_MAJOR_WINDOWS]); 35 36 /*************************** 37 ** Private data 38 ****************************/ 39 static enum tui_layout_type current_layout = UNDEFINED_LAYOUT; 40 static int term_height, term_width; 41 static struct tui_gen_win_info _locator; 42 static struct tui_gen_win_info exec_info[2]; 43 static struct tui_win_info *src_win_list[2]; 44 static struct tui_list source_windows = {src_win_list, 0}; 45 static int default_tab_len = DEFAULT_TAB_LEN; 46 static struct tui_win_info *win_with_focus = (struct tui_win_info *) NULL; 47 static struct tui_layout_def layout_def = { 48 SRC_WIN, /* DISPLAY_MODE */ 49 FALSE, /* SPLIT */ 50 TUI_UNDEFINED_REGS, /* REGS_DISPLAY_TYPE */ 51 TUI_SFLOAT_REGS}; /* FLOAT_REGS_DISPLAY_TYPE */ 52 53 static int win_resized = FALSE; 54 55 56 /********************************* 57 ** Static function forward decls 58 **********************************/ 59 static void free_content (tui_win_content, 60 int, 61 enum tui_win_type); 62 static void free_content_elements (tui_win_content, 63 int, 64 enum tui_win_type); 65 66 67 68 /********************************* 69 ** PUBLIC FUNCTIONS 70 **********************************/ 71 72 int 73 tui_win_is_source_type (enum tui_win_type win_type) 74 { 75 return (win_type == SRC_WIN || win_type == DISASSEM_WIN); 76 } 77 78 int 79 tui_win_is_auxillary (enum tui_win_type win_type) 80 { 81 return (win_type > MAX_MAJOR_WINDOWS); 82 } 83 84 int 85 tui_win_has_locator (struct tui_win_info *win_info) 86 { 87 return (win_info != NULL 88 && win_info->detail.source_info.has_locator); 89 } 90 91 void 92 tui_set_win_highlight (struct tui_win_info *win_info, 93 int highlight) 94 { 95 if (win_info != NULL) 96 win_info->is_highlighted = highlight; 97 } 98 99 /****************************************** 100 ** ACCESSORS & MUTATORS FOR PRIVATE DATA 101 ******************************************/ 102 103 /* Answer a whether the terminal window has been resized or not. */ 104 int 105 tui_win_resized (void) 106 { 107 return win_resized; 108 } 109 110 111 /* Set a whether the terminal window has been resized or not. */ 112 void 113 tui_set_win_resized_to (int resized) 114 { 115 win_resized = resized; 116 } 117 118 119 /* Answer a pointer to the current layout definition. */ 120 struct tui_layout_def * 121 tui_layout_def (void) 122 { 123 return &layout_def; 124 } 125 126 127 /* Answer the window with the logical focus. */ 128 struct tui_win_info * 129 tui_win_with_focus (void) 130 { 131 return win_with_focus; 132 } 133 134 135 /* Set the window that has the logical focus. */ 136 void 137 tui_set_win_with_focus (struct tui_win_info *win_info) 138 { 139 win_with_focus = win_info; 140 } 141 142 143 /* Answer the length in chars, of tabs. */ 144 int 145 tui_default_tab_len (void) 146 { 147 return default_tab_len; 148 } 149 150 151 /* Set the length in chars, of tabs. */ 152 void 153 tui_set_default_tab_len (int len) 154 { 155 default_tab_len = len; 156 } 157 158 159 /* Accessor for the current source window. Usually there is only one 160 source window (either source or disassembly), but both can be 161 displayed at the same time. */ 162 struct tui_list * 163 tui_source_windows (void) 164 { 165 return &source_windows; 166 } 167 168 169 /* Clear the list of source windows. Usually there is only one source 170 window (either source or disassembly), but both can be displayed at 171 the same time. */ 172 void 173 tui_clear_source_windows (void) 174 { 175 source_windows.list[0] = NULL; 176 source_windows.list[1] = NULL; 177 source_windows.count = 0; 178 } 179 180 181 /* Clear the pertinant detail in the source windows. */ 182 void 183 tui_clear_source_windows_detail (void) 184 { 185 int i; 186 187 for (i = 0; i < (tui_source_windows ())->count; i++) 188 tui_clear_win_detail ((tui_source_windows ())->list[i]); 189 } 190 191 192 /* Add a window to the list of source windows. Usually there is only 193 one source window (either source or disassembly), but both can be 194 displayed at the same time. */ 195 void 196 tui_add_to_source_windows (struct tui_win_info *win_info) 197 { 198 if (source_windows.count < 2) 199 source_windows.list[source_windows.count++] = (void *) win_info; 200 } 201 202 203 /* Clear the pertinant detail in the windows. */ 204 void 205 tui_clear_win_detail (struct tui_win_info *win_info) 206 { 207 if (win_info != NULL) 208 { 209 switch (win_info->generic.type) 210 { 211 case SRC_WIN: 212 case DISASSEM_WIN: 213 win_info->detail.source_info.gdbarch = NULL; 214 win_info->detail.source_info.start_line_or_addr.loa = LOA_ADDRESS; 215 win_info->detail.source_info.start_line_or_addr.u.addr = 0; 216 win_info->detail.source_info.horizontal_offset = 0; 217 break; 218 case CMD_WIN: 219 win_info->detail.command_info.cur_line = 220 win_info->detail.command_info.curch = 0; 221 break; 222 case DATA_WIN: 223 win_info->detail.data_display_info.data_content = 224 (tui_win_content) NULL; 225 win_info->detail.data_display_info.data_content_count = 0; 226 win_info->detail.data_display_info.regs_content = 227 (tui_win_content) NULL; 228 win_info->detail.data_display_info.regs_content_count = 0; 229 win_info->detail.data_display_info.regs_display_type = 230 TUI_UNDEFINED_REGS; 231 win_info->detail.data_display_info.regs_column_count = 1; 232 win_info->detail.data_display_info.display_regs = FALSE; 233 break; 234 default: 235 break; 236 } 237 } 238 } 239 240 241 /* Accessor for the source execution info ptr. */ 242 struct tui_gen_win_info * 243 tui_source_exec_info_win_ptr (void) 244 { 245 return &exec_info[0]; 246 } 247 248 249 /* Accessor for the disassem execution info ptr. */ 250 struct tui_gen_win_info * 251 tui_disassem_exec_info_win_ptr (void) 252 { 253 return &exec_info[1]; 254 } 255 256 257 /* Accessor for the locator win info. Answers a pointer to the static 258 locator win info struct. */ 259 struct tui_gen_win_info * 260 tui_locator_win_info_ptr (void) 261 { 262 return &_locator; 263 } 264 265 266 /* Accessor for the term_height. */ 267 int 268 tui_term_height (void) 269 { 270 return term_height; 271 } 272 273 274 /* Mutator for the term height. */ 275 void 276 tui_set_term_height_to (int h) 277 { 278 term_height = h; 279 } 280 281 282 /* Accessor for the term_width. */ 283 int 284 tui_term_width (void) 285 { 286 return term_width; 287 } 288 289 290 /* Mutator for the term_width. */ 291 void 292 tui_set_term_width_to (int w) 293 { 294 term_width = w; 295 } 296 297 298 /* Accessor for the current layout. */ 299 enum tui_layout_type 300 tui_current_layout (void) 301 { 302 return current_layout; 303 } 304 305 306 /* Mutator for the current layout. */ 307 void 308 tui_set_current_layout_to (enum tui_layout_type new_layout) 309 { 310 current_layout = new_layout; 311 } 312 313 314 /* Set the origin of the window. */ 315 void 316 set_gen_win_origin (struct tui_gen_win_info *win_info, 317 int x, int y) 318 { 319 win_info->origin.x = x; 320 win_info->origin.y = y; 321 } 322 323 324 /***************************** 325 ** OTHER PUBLIC FUNCTIONS 326 *****************************/ 327 328 329 /* Answer the next window in the list, cycling back to the top if 330 necessary. */ 331 struct tui_win_info * 332 tui_next_win (struct tui_win_info *cur_win) 333 { 334 enum tui_win_type type = cur_win->generic.type; 335 struct tui_win_info *next_win = (struct tui_win_info *) NULL; 336 337 if (cur_win->generic.type == CMD_WIN) 338 type = SRC_WIN; 339 else 340 type = cur_win->generic.type + 1; 341 while (type != cur_win->generic.type && (next_win == NULL)) 342 { 343 if (tui_win_list[type] 344 && tui_win_list[type]->generic.is_visible) 345 next_win = tui_win_list[type]; 346 else 347 { 348 if (type == CMD_WIN) 349 type = SRC_WIN; 350 else 351 type++; 352 } 353 } 354 355 return next_win; 356 } 357 358 359 /* Answer the prev window in the list, cycling back to the bottom if 360 necessary. */ 361 struct tui_win_info * 362 tui_prev_win (struct tui_win_info *cur_win) 363 { 364 enum tui_win_type type = cur_win->generic.type; 365 struct tui_win_info *prev = (struct tui_win_info *) NULL; 366 367 if (cur_win->generic.type == SRC_WIN) 368 type = CMD_WIN; 369 else 370 type = cur_win->generic.type - 1; 371 while (type != cur_win->generic.type && (prev == NULL)) 372 { 373 if (tui_win_list[type] 374 && tui_win_list[type]->generic.is_visible) 375 prev = tui_win_list[type]; 376 else 377 { 378 if (type == SRC_WIN) 379 type = CMD_WIN; 380 else 381 type--; 382 } 383 } 384 385 return prev; 386 } 387 388 389 /* Answer the window represented by name. */ 390 struct tui_win_info * 391 tui_partial_win_by_name (char *name) 392 { 393 struct tui_win_info *win_info = (struct tui_win_info *) NULL; 394 395 if (name != (char *) NULL) 396 { 397 int i = 0; 398 399 while (i < MAX_MAJOR_WINDOWS && win_info == NULL) 400 { 401 if (tui_win_list[i] != 0) 402 { 403 char *cur_name = tui_win_name (&tui_win_list[i]->generic); 404 405 if (strlen (name) <= strlen (cur_name) 406 && strncmp (name, cur_name, strlen (name)) == 0) 407 win_info = tui_win_list[i]; 408 } 409 i++; 410 } 411 } 412 413 return win_info; 414 } 415 416 417 /* Answer the name of the window. */ 418 char * 419 tui_win_name (struct tui_gen_win_info *win_info) 420 { 421 char *name = (char *) NULL; 422 423 switch (win_info->type) 424 { 425 case SRC_WIN: 426 name = SRC_NAME; 427 break; 428 case CMD_WIN: 429 name = CMD_NAME; 430 break; 431 case DISASSEM_WIN: 432 name = DISASSEM_NAME; 433 break; 434 case DATA_WIN: 435 name = DATA_NAME; 436 break; 437 default: 438 name = ""; 439 break; 440 } 441 442 return name; 443 } 444 445 446 void 447 tui_initialize_static_data (void) 448 { 449 tui_init_generic_part (tui_source_exec_info_win_ptr ()); 450 tui_init_generic_part (tui_disassem_exec_info_win_ptr ()); 451 tui_init_generic_part (tui_locator_win_info_ptr ()); 452 } 453 454 455 struct tui_gen_win_info * 456 tui_alloc_generic_win_info (void) 457 { 458 struct tui_gen_win_info *win; 459 460 if ((win = XMALLOC (struct tui_gen_win_info)) != NULL) 461 tui_init_generic_part (win); 462 463 return win; 464 } 465 466 467 void 468 tui_init_generic_part (struct tui_gen_win_info *win) 469 { 470 win->width = 471 win->height = 472 win->origin.x = 473 win->origin.y = 474 win->viewport_height = 475 win->content_size = 476 win->last_visible_line = 0; 477 win->handle = (WINDOW *) NULL; 478 win->content = NULL; 479 win->content_in_use = 480 win->is_visible = FALSE; 481 win->title = 0; 482 } 483 484 485 /* init_content_element(). 486 */ 487 static void 488 init_content_element (struct tui_win_element *element, 489 enum tui_win_type type) 490 { 491 element->highlight = FALSE; 492 switch (type) 493 { 494 case SRC_WIN: 495 case DISASSEM_WIN: 496 element->which_element.source.line = (char *) NULL; 497 element->which_element.source.line_or_addr.loa = LOA_LINE; 498 element->which_element.source.line_or_addr.u.line_no = 0; 499 element->which_element.source.is_exec_point = FALSE; 500 element->which_element.source.has_break = FALSE; 501 break; 502 case DATA_WIN: 503 tui_init_generic_part (&element->which_element.data_window); 504 element->which_element.data_window.type = DATA_ITEM_WIN; 505 ((struct tui_gen_win_info *) 506 &element->which_element.data_window)->content = 507 (void **) tui_alloc_content (1, DATA_ITEM_WIN); 508 ((struct tui_gen_win_info *) 509 & element->which_element.data_window)->content_size = 1; 510 break; 511 case CMD_WIN: 512 element->which_element.command.line = (char *) NULL; 513 break; 514 case DATA_ITEM_WIN: 515 element->which_element.data.name = (char *) NULL; 516 element->which_element.data.type = TUI_REGISTER; 517 element->which_element.data.item_no = UNDEFINED_ITEM; 518 element->which_element.data.value = NULL; 519 element->which_element.data.highlight = FALSE; 520 element->which_element.data.content = (char*) NULL; 521 break; 522 case LOCATOR_WIN: 523 element->which_element.locator.file_name[0] = 524 element->which_element.locator.proc_name[0] = (char) 0; 525 element->which_element.locator.line_no = 0; 526 element->which_element.locator.addr = 0; 527 break; 528 case EXEC_INFO_WIN: 529 memset(element->which_element.simple_string, ' ', 530 sizeof(element->which_element.simple_string)); 531 break; 532 default: 533 break; 534 } 535 } 536 537 static void 538 init_win_info (struct tui_win_info *win_info) 539 { 540 tui_init_generic_part (&win_info->generic); 541 win_info->can_highlight = 542 win_info->is_highlighted = FALSE; 543 switch (win_info->generic.type) 544 { 545 case SRC_WIN: 546 case DISASSEM_WIN: 547 win_info->detail.source_info.execution_info 548 = (struct tui_gen_win_info *) NULL; 549 win_info->detail.source_info.has_locator = FALSE; 550 win_info->detail.source_info.horizontal_offset = 0; 551 win_info->detail.source_info.gdbarch = NULL; 552 win_info->detail.source_info.start_line_or_addr.loa = LOA_ADDRESS; 553 win_info->detail.source_info.start_line_or_addr.u.addr = 0; 554 win_info->detail.source_info.filename = 0; 555 break; 556 case DATA_WIN: 557 win_info->detail.data_display_info.data_content = (tui_win_content) NULL; 558 win_info->detail.data_display_info.data_content_count = 0; 559 win_info->detail.data_display_info.regs_content = (tui_win_content) NULL; 560 win_info->detail.data_display_info.regs_content_count = 0; 561 win_info->detail.data_display_info.regs_display_type = 562 TUI_UNDEFINED_REGS; 563 win_info->detail.data_display_info.regs_column_count = 1; 564 win_info->detail.data_display_info.display_regs = FALSE; 565 win_info->detail.data_display_info.current_group = 0; 566 break; 567 case CMD_WIN: 568 win_info->detail.command_info.cur_line = 0; 569 win_info->detail.command_info.curch = 0; 570 break; 571 default: 572 win_info->detail.opaque = NULL; 573 break; 574 } 575 } 576 577 578 struct tui_win_info * 579 tui_alloc_win_info (enum tui_win_type type) 580 { 581 struct tui_win_info *win_info; 582 583 win_info = XMALLOC (struct tui_win_info); 584 if (win_info != NULL) 585 { 586 win_info->generic.type = type; 587 init_win_info (win_info); 588 } 589 590 return win_info; 591 } 592 593 594 /* Allocates the content and elements in a block. */ 595 tui_win_content 596 tui_alloc_content (int num_elements, enum tui_win_type type) 597 { 598 tui_win_content content; 599 char *element_block_ptr; 600 int i; 601 602 content = xmalloc (sizeof (struct tui_win_element *) *num_elements); 603 if (content != NULL) 604 { 605 /* 606 * All windows, except the data window, can allocate the 607 * elements in a chunk. The data window cannot because items 608 * can be added/removed from the data display by the user at any 609 * time. 610 */ 611 if (type != DATA_WIN) 612 { 613 element_block_ptr = 614 xmalloc (sizeof (struct tui_win_element) * num_elements); 615 if (element_block_ptr != NULL) 616 { 617 for (i = 0; i < num_elements; i++) 618 { 619 content[i] = (struct tui_win_element *) element_block_ptr; 620 init_content_element (content[i], type); 621 element_block_ptr += sizeof (struct tui_win_element); 622 } 623 } 624 else 625 { 626 xfree (content); 627 content = (tui_win_content) NULL; 628 } 629 } 630 } 631 632 return content; 633 } 634 635 636 /* Adds the input number of elements to the windows's content. If no 637 content has been allocated yet, alloc_content() is called to do 638 this. The index of the first element added is returned, unless 639 there is a memory allocation error, in which case, (-1) is 640 returned. */ 641 int 642 tui_add_content_elements (struct tui_gen_win_info *win_info, 643 int num_elements) 644 { 645 struct tui_win_element *element_ptr; 646 int i, index_start; 647 648 if (win_info->content == NULL) 649 { 650 win_info->content = (void **) tui_alloc_content (num_elements, 651 win_info->type); 652 index_start = 0; 653 } 654 else 655 index_start = win_info->content_size; 656 if (win_info->content != NULL) 657 { 658 for (i = index_start; (i < num_elements + index_start); i++) 659 { 660 if ((element_ptr = XMALLOC (struct tui_win_element)) != NULL) 661 { 662 win_info->content[i] = (void *) element_ptr; 663 init_content_element (element_ptr, win_info->type); 664 win_info->content_size++; 665 } 666 else /* Things must be really hosed now! We ran out of 667 memory!? */ 668 return (-1); 669 } 670 } 671 672 return index_start; 673 } 674 675 676 /* Delete all curses windows associated with win_info, leaving 677 everything else intact. */ 678 void 679 tui_del_window (struct tui_win_info *win_info) 680 { 681 struct tui_gen_win_info *generic_win; 682 683 switch (win_info->generic.type) 684 { 685 case SRC_WIN: 686 case DISASSEM_WIN: 687 generic_win = tui_locator_win_info_ptr (); 688 if (generic_win != (struct tui_gen_win_info *) NULL) 689 { 690 tui_delete_win (generic_win->handle); 691 generic_win->handle = (WINDOW *) NULL; 692 generic_win->is_visible = FALSE; 693 } 694 if (win_info->detail.source_info.filename) 695 { 696 xfree (win_info->detail.source_info.filename); 697 win_info->detail.source_info.filename = 0; 698 } 699 generic_win = win_info->detail.source_info.execution_info; 700 if (generic_win != (struct tui_gen_win_info *) NULL) 701 { 702 tui_delete_win (generic_win->handle); 703 generic_win->handle = (WINDOW *) NULL; 704 generic_win->is_visible = FALSE; 705 } 706 break; 707 case DATA_WIN: 708 if (win_info->generic.content != NULL) 709 { 710 tui_del_data_windows (win_info->detail.data_display_info.regs_content, 711 win_info->detail.data_display_info.regs_content_count); 712 tui_del_data_windows (win_info->detail.data_display_info.data_content, 713 win_info->detail.data_display_info.data_content_count); 714 } 715 break; 716 default: 717 break; 718 } 719 if (win_info->generic.handle != (WINDOW *) NULL) 720 { 721 tui_delete_win (win_info->generic.handle); 722 win_info->generic.handle = (WINDOW *) NULL; 723 win_info->generic.is_visible = FALSE; 724 } 725 } 726 727 728 void 729 tui_free_window (struct tui_win_info *win_info) 730 { 731 struct tui_gen_win_info *generic_win; 732 733 switch (win_info->generic.type) 734 { 735 case SRC_WIN: 736 case DISASSEM_WIN: 737 generic_win = tui_locator_win_info_ptr (); 738 if (generic_win != (struct tui_gen_win_info *) NULL) 739 { 740 tui_delete_win (generic_win->handle); 741 generic_win->handle = (WINDOW *) NULL; 742 } 743 tui_free_win_content (generic_win); 744 if (win_info->detail.source_info.filename) 745 { 746 xfree (win_info->detail.source_info.filename); 747 win_info->detail.source_info.filename = 0; 748 } 749 generic_win = win_info->detail.source_info.execution_info; 750 if (generic_win != (struct tui_gen_win_info *) NULL) 751 { 752 tui_delete_win (generic_win->handle); 753 generic_win->handle = (WINDOW *) NULL; 754 tui_free_win_content (generic_win); 755 } 756 break; 757 case DATA_WIN: 758 if (win_info->generic.content != NULL) 759 { 760 tui_free_data_content (win_info->detail.data_display_info.regs_content, 761 win_info->detail.data_display_info.regs_content_count); 762 win_info->detail.data_display_info.regs_content = 763 (tui_win_content) NULL; 764 win_info->detail.data_display_info.regs_content_count = 0; 765 tui_free_data_content (win_info->detail.data_display_info.data_content, 766 win_info->detail.data_display_info.data_content_count); 767 win_info->detail.data_display_info.data_content = 768 (tui_win_content) NULL; 769 win_info->detail.data_display_info.data_content_count = 0; 770 win_info->detail.data_display_info.regs_display_type = 771 TUI_UNDEFINED_REGS; 772 win_info->detail.data_display_info.regs_column_count = 1; 773 win_info->detail.data_display_info.display_regs = FALSE; 774 win_info->generic.content = NULL; 775 win_info->generic.content_size = 0; 776 } 777 break; 778 default: 779 break; 780 } 781 if (win_info->generic.handle != (WINDOW *) NULL) 782 { 783 tui_delete_win (win_info->generic.handle); 784 win_info->generic.handle = (WINDOW *) NULL; 785 tui_free_win_content (&win_info->generic); 786 } 787 if (win_info->generic.title) 788 xfree (win_info->generic.title); 789 xfree (win_info); 790 } 791 792 793 void 794 tui_free_all_source_wins_content (void) 795 { 796 int i; 797 798 for (i = 0; i < (tui_source_windows ())->count; i++) 799 { 800 struct tui_win_info *win_info = (tui_source_windows ())->list[i]; 801 802 if (win_info != NULL) 803 { 804 tui_free_win_content (&(win_info->generic)); 805 tui_free_win_content (win_info->detail.source_info.execution_info); 806 } 807 } 808 } 809 810 811 void 812 tui_free_win_content (struct tui_gen_win_info *win_info) 813 { 814 if (win_info->content != NULL) 815 { 816 free_content ((tui_win_content) win_info->content, 817 win_info->content_size, 818 win_info->type); 819 win_info->content = NULL; 820 } 821 win_info->content_size = 0; 822 } 823 824 825 void 826 tui_del_data_windows (tui_win_content content, 827 int content_size) 828 { 829 int i; 830 831 /* Remember that data window content elements are of type struct 832 tui_gen_win_info *, each of which whose single element is a data 833 element. */ 834 for (i = 0; i < content_size; i++) 835 { 836 struct tui_gen_win_info *generic_win 837 = &content[i]->which_element.data_window; 838 839 if (generic_win != (struct tui_gen_win_info *) NULL) 840 { 841 tui_delete_win (generic_win->handle); 842 generic_win->handle = (WINDOW *) NULL; 843 generic_win->is_visible = FALSE; 844 } 845 } 846 } 847 848 849 void 850 tui_free_data_content (tui_win_content content, 851 int content_size) 852 { 853 int i; 854 855 /* Remember that data window content elements are of type struct 856 tui_gen_win_info *, each of which whose single element is a data 857 element. */ 858 for (i = 0; i < content_size; i++) 859 { 860 struct tui_gen_win_info *generic_win 861 = &content[i]->which_element.data_window; 862 863 if (generic_win != (struct tui_gen_win_info *) NULL) 864 { 865 tui_delete_win (generic_win->handle); 866 generic_win->handle = (WINDOW *) NULL; 867 tui_free_win_content (generic_win); 868 } 869 } 870 free_content (content, 871 content_size, 872 DATA_WIN); 873 } 874 875 876 /********************************** 877 ** LOCAL STATIC FUNCTIONS ** 878 **********************************/ 879 880 881 static void 882 free_content (tui_win_content content, 883 int content_size, 884 enum tui_win_type win_type) 885 { 886 if (content != (tui_win_content) NULL) 887 { 888 free_content_elements (content, content_size, win_type); 889 xfree (content); 890 } 891 } 892 893 894 /* free_content_elements(). 895 */ 896 static void 897 free_content_elements (tui_win_content content, 898 int content_size, 899 enum tui_win_type type) 900 { 901 if (content != (tui_win_content) NULL) 902 { 903 int i; 904 905 if (type == SRC_WIN || type == DISASSEM_WIN) 906 { 907 /* Free whole source block. */ 908 xfree (content[0]->which_element.source.line); 909 } 910 else 911 { 912 for (i = 0; i < content_size; i++) 913 { 914 struct tui_win_element *element; 915 916 element = content[i]; 917 if (element != (struct tui_win_element *) NULL) 918 { 919 switch (type) 920 { 921 case DATA_WIN: 922 xfree (element); 923 break; 924 case DATA_ITEM_WIN: 925 /* Note that data elements are not allocated in 926 a single block, but individually, as 927 needed. */ 928 if (element->which_element.data.type != TUI_REGISTER) 929 xfree ((void *)element->which_element.data.name); 930 xfree (element->which_element.data.value); 931 xfree (element->which_element.data.content); 932 xfree (element); 933 break; 934 case CMD_WIN: 935 xfree (element->which_element.command.line); 936 break; 937 default: 938 break; 939 } 940 } 941 } 942 } 943 if (type != DATA_WIN && type != DATA_ITEM_WIN) 944 xfree (content[0]); /* Free the element block. */ 945 } 946 } 947