1 /* TUI data manipulation routines. 2 3 Copyright (C) 1998-2013 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 /***************************** 315 ** OTHER PUBLIC FUNCTIONS 316 *****************************/ 317 318 319 /* Answer the next window in the list, cycling back to the top if 320 necessary. */ 321 struct tui_win_info * 322 tui_next_win (struct tui_win_info *cur_win) 323 { 324 enum tui_win_type type = cur_win->generic.type; 325 struct tui_win_info *next_win = (struct tui_win_info *) NULL; 326 327 if (cur_win->generic.type == CMD_WIN) 328 type = SRC_WIN; 329 else 330 type = cur_win->generic.type + 1; 331 while (type != cur_win->generic.type && (next_win == NULL)) 332 { 333 if (tui_win_list[type] 334 && tui_win_list[type]->generic.is_visible) 335 next_win = tui_win_list[type]; 336 else 337 { 338 if (type == CMD_WIN) 339 type = SRC_WIN; 340 else 341 type++; 342 } 343 } 344 345 return next_win; 346 } 347 348 349 /* Answer the prev window in the list, cycling back to the bottom if 350 necessary. */ 351 struct tui_win_info * 352 tui_prev_win (struct tui_win_info *cur_win) 353 { 354 enum tui_win_type type = cur_win->generic.type; 355 struct tui_win_info *prev = (struct tui_win_info *) NULL; 356 357 if (cur_win->generic.type == SRC_WIN) 358 type = CMD_WIN; 359 else 360 type = cur_win->generic.type - 1; 361 while (type != cur_win->generic.type && (prev == NULL)) 362 { 363 if (tui_win_list[type] 364 && tui_win_list[type]->generic.is_visible) 365 prev = tui_win_list[type]; 366 else 367 { 368 if (type == SRC_WIN) 369 type = CMD_WIN; 370 else 371 type--; 372 } 373 } 374 375 return prev; 376 } 377 378 379 /* Answer the window represented by name. */ 380 struct tui_win_info * 381 tui_partial_win_by_name (char *name) 382 { 383 struct tui_win_info *win_info = (struct tui_win_info *) NULL; 384 385 if (name != (char *) NULL) 386 { 387 int i = 0; 388 389 while (i < MAX_MAJOR_WINDOWS && win_info == NULL) 390 { 391 if (tui_win_list[i] != 0) 392 { 393 char *cur_name = tui_win_name (&tui_win_list[i]->generic); 394 395 if (strlen (name) <= strlen (cur_name) 396 && strncmp (name, cur_name, strlen (name)) == 0) 397 win_info = tui_win_list[i]; 398 } 399 i++; 400 } 401 } 402 403 return win_info; 404 } 405 406 407 /* Answer the name of the window. */ 408 char * 409 tui_win_name (struct tui_gen_win_info *win_info) 410 { 411 char *name = (char *) NULL; 412 413 switch (win_info->type) 414 { 415 case SRC_WIN: 416 name = SRC_NAME; 417 break; 418 case CMD_WIN: 419 name = CMD_NAME; 420 break; 421 case DISASSEM_WIN: 422 name = DISASSEM_NAME; 423 break; 424 case DATA_WIN: 425 name = DATA_NAME; 426 break; 427 default: 428 name = ""; 429 break; 430 } 431 432 return name; 433 } 434 435 436 void 437 tui_initialize_static_data (void) 438 { 439 tui_init_generic_part (tui_source_exec_info_win_ptr ()); 440 tui_init_generic_part (tui_disassem_exec_info_win_ptr ()); 441 tui_init_generic_part (tui_locator_win_info_ptr ()); 442 } 443 444 445 struct tui_gen_win_info * 446 tui_alloc_generic_win_info (void) 447 { 448 struct tui_gen_win_info *win; 449 450 if ((win = XMALLOC (struct tui_gen_win_info)) != NULL) 451 tui_init_generic_part (win); 452 453 return win; 454 } 455 456 457 void 458 tui_init_generic_part (struct tui_gen_win_info *win) 459 { 460 win->width = 461 win->height = 462 win->origin.x = 463 win->origin.y = 464 win->viewport_height = 465 win->content_size = 466 win->last_visible_line = 0; 467 win->handle = (WINDOW *) NULL; 468 win->content = NULL; 469 win->content_in_use = 470 win->is_visible = FALSE; 471 win->title = 0; 472 } 473 474 475 /* init_content_element(). 476 */ 477 static void 478 init_content_element (struct tui_win_element *element, 479 enum tui_win_type type) 480 { 481 element->highlight = FALSE; 482 switch (type) 483 { 484 case SRC_WIN: 485 case DISASSEM_WIN: 486 element->which_element.source.line = (char *) NULL; 487 element->which_element.source.line_or_addr.loa = LOA_LINE; 488 element->which_element.source.line_or_addr.u.line_no = 0; 489 element->which_element.source.is_exec_point = FALSE; 490 element->which_element.source.has_break = FALSE; 491 break; 492 case DATA_WIN: 493 tui_init_generic_part (&element->which_element.data_window); 494 element->which_element.data_window.type = DATA_ITEM_WIN; 495 ((struct tui_gen_win_info *) 496 &element->which_element.data_window)->content = 497 (void **) tui_alloc_content (1, DATA_ITEM_WIN); 498 ((struct tui_gen_win_info *) 499 & element->which_element.data_window)->content_size = 1; 500 break; 501 case CMD_WIN: 502 element->which_element.command.line = (char *) NULL; 503 break; 504 case DATA_ITEM_WIN: 505 element->which_element.data.name = (char *) NULL; 506 element->which_element.data.type = TUI_REGISTER; 507 element->which_element.data.item_no = UNDEFINED_ITEM; 508 element->which_element.data.value = NULL; 509 element->which_element.data.highlight = FALSE; 510 element->which_element.data.content = (char*) NULL; 511 break; 512 case LOCATOR_WIN: 513 element->which_element.locator.full_name[0] = 514 element->which_element.locator.proc_name[0] = (char) 0; 515 element->which_element.locator.line_no = 0; 516 element->which_element.locator.addr = 0; 517 break; 518 case EXEC_INFO_WIN: 519 memset(element->which_element.simple_string, ' ', 520 sizeof(element->which_element.simple_string)); 521 break; 522 default: 523 break; 524 } 525 } 526 527 static void 528 init_win_info (struct tui_win_info *win_info) 529 { 530 tui_init_generic_part (&win_info->generic); 531 win_info->can_highlight = 532 win_info->is_highlighted = FALSE; 533 switch (win_info->generic.type) 534 { 535 case SRC_WIN: 536 case DISASSEM_WIN: 537 win_info->detail.source_info.execution_info 538 = (struct tui_gen_win_info *) NULL; 539 win_info->detail.source_info.has_locator = FALSE; 540 win_info->detail.source_info.horizontal_offset = 0; 541 win_info->detail.source_info.gdbarch = NULL; 542 win_info->detail.source_info.start_line_or_addr.loa = LOA_ADDRESS; 543 win_info->detail.source_info.start_line_or_addr.u.addr = 0; 544 win_info->detail.source_info.fullname = NULL; 545 break; 546 case DATA_WIN: 547 win_info->detail.data_display_info.data_content = (tui_win_content) NULL; 548 win_info->detail.data_display_info.data_content_count = 0; 549 win_info->detail.data_display_info.regs_content = (tui_win_content) NULL; 550 win_info->detail.data_display_info.regs_content_count = 0; 551 win_info->detail.data_display_info.regs_display_type = 552 TUI_UNDEFINED_REGS; 553 win_info->detail.data_display_info.regs_column_count = 1; 554 win_info->detail.data_display_info.display_regs = FALSE; 555 win_info->detail.data_display_info.current_group = 0; 556 break; 557 case CMD_WIN: 558 win_info->detail.command_info.cur_line = 0; 559 win_info->detail.command_info.curch = 0; 560 break; 561 default: 562 win_info->detail.opaque = NULL; 563 break; 564 } 565 } 566 567 568 struct tui_win_info * 569 tui_alloc_win_info (enum tui_win_type type) 570 { 571 struct tui_win_info *win_info; 572 573 win_info = XMALLOC (struct tui_win_info); 574 if (win_info != NULL) 575 { 576 win_info->generic.type = type; 577 init_win_info (win_info); 578 } 579 580 return win_info; 581 } 582 583 584 /* Allocates the content and elements in a block. */ 585 tui_win_content 586 tui_alloc_content (int num_elements, enum tui_win_type type) 587 { 588 tui_win_content content; 589 char *element_block_ptr; 590 int i; 591 592 content = xmalloc (sizeof (struct tui_win_element *) *num_elements); 593 if (content != NULL) 594 { 595 /* 596 * All windows, except the data window, can allocate the 597 * elements in a chunk. The data window cannot because items 598 * can be added/removed from the data display by the user at any 599 * time. 600 */ 601 if (type != DATA_WIN) 602 { 603 element_block_ptr = 604 xmalloc (sizeof (struct tui_win_element) * num_elements); 605 if (element_block_ptr != NULL) 606 { 607 for (i = 0; i < num_elements; i++) 608 { 609 content[i] = (struct tui_win_element *) element_block_ptr; 610 init_content_element (content[i], type); 611 element_block_ptr += sizeof (struct tui_win_element); 612 } 613 } 614 else 615 { 616 xfree (content); 617 content = (tui_win_content) NULL; 618 } 619 } 620 } 621 622 return content; 623 } 624 625 626 /* Adds the input number of elements to the windows's content. If no 627 content has been allocated yet, alloc_content() is called to do 628 this. The index of the first element added is returned, unless 629 there is a memory allocation error, in which case, (-1) is 630 returned. */ 631 int 632 tui_add_content_elements (struct tui_gen_win_info *win_info, 633 int num_elements) 634 { 635 struct tui_win_element *element_ptr; 636 int i, index_start; 637 638 if (win_info->content == NULL) 639 { 640 win_info->content = (void **) tui_alloc_content (num_elements, 641 win_info->type); 642 index_start = 0; 643 } 644 else 645 index_start = win_info->content_size; 646 if (win_info->content != NULL) 647 { 648 for (i = index_start; (i < num_elements + index_start); i++) 649 { 650 if ((element_ptr = XMALLOC (struct tui_win_element)) != NULL) 651 { 652 win_info->content[i] = (void *) element_ptr; 653 init_content_element (element_ptr, win_info->type); 654 win_info->content_size++; 655 } 656 else /* Things must be really hosed now! We ran out of 657 memory!? */ 658 return (-1); 659 } 660 } 661 662 return index_start; 663 } 664 665 666 /* Delete all curses windows associated with win_info, leaving 667 everything else intact. */ 668 void 669 tui_del_window (struct tui_win_info *win_info) 670 { 671 struct tui_gen_win_info *generic_win; 672 673 switch (win_info->generic.type) 674 { 675 case SRC_WIN: 676 case DISASSEM_WIN: 677 generic_win = tui_locator_win_info_ptr (); 678 if (generic_win != (struct tui_gen_win_info *) NULL) 679 { 680 tui_delete_win (generic_win->handle); 681 generic_win->handle = (WINDOW *) NULL; 682 generic_win->is_visible = FALSE; 683 } 684 if (win_info->detail.source_info.fullname) 685 { 686 xfree (win_info->detail.source_info.fullname); 687 win_info->detail.source_info.fullname = NULL; 688 } 689 generic_win = win_info->detail.source_info.execution_info; 690 if (generic_win != (struct tui_gen_win_info *) NULL) 691 { 692 tui_delete_win (generic_win->handle); 693 generic_win->handle = (WINDOW *) NULL; 694 generic_win->is_visible = FALSE; 695 } 696 break; 697 case DATA_WIN: 698 if (win_info->generic.content != NULL) 699 { 700 tui_del_data_windows (win_info->detail.data_display_info.regs_content, 701 win_info->detail.data_display_info.regs_content_count); 702 tui_del_data_windows (win_info->detail.data_display_info.data_content, 703 win_info->detail.data_display_info.data_content_count); 704 } 705 break; 706 default: 707 break; 708 } 709 if (win_info->generic.handle != (WINDOW *) NULL) 710 { 711 tui_delete_win (win_info->generic.handle); 712 win_info->generic.handle = (WINDOW *) NULL; 713 win_info->generic.is_visible = FALSE; 714 } 715 } 716 717 718 void 719 tui_free_window (struct tui_win_info *win_info) 720 { 721 struct tui_gen_win_info *generic_win; 722 723 switch (win_info->generic.type) 724 { 725 case SRC_WIN: 726 case DISASSEM_WIN: 727 generic_win = tui_locator_win_info_ptr (); 728 if (generic_win != (struct tui_gen_win_info *) NULL) 729 { 730 tui_delete_win (generic_win->handle); 731 generic_win->handle = (WINDOW *) NULL; 732 } 733 tui_free_win_content (generic_win); 734 if (win_info->detail.source_info.fullname) 735 { 736 xfree (win_info->detail.source_info.fullname); 737 win_info->detail.source_info.fullname = NULL; 738 } 739 generic_win = win_info->detail.source_info.execution_info; 740 if (generic_win != (struct tui_gen_win_info *) NULL) 741 { 742 tui_delete_win (generic_win->handle); 743 generic_win->handle = (WINDOW *) NULL; 744 tui_free_win_content (generic_win); 745 } 746 break; 747 case DATA_WIN: 748 if (win_info->generic.content != NULL) 749 { 750 tui_free_data_content (win_info->detail.data_display_info.regs_content, 751 win_info->detail.data_display_info.regs_content_count); 752 win_info->detail.data_display_info.regs_content = 753 (tui_win_content) NULL; 754 win_info->detail.data_display_info.regs_content_count = 0; 755 tui_free_data_content (win_info->detail.data_display_info.data_content, 756 win_info->detail.data_display_info.data_content_count); 757 win_info->detail.data_display_info.data_content = 758 (tui_win_content) NULL; 759 win_info->detail.data_display_info.data_content_count = 0; 760 win_info->detail.data_display_info.regs_display_type = 761 TUI_UNDEFINED_REGS; 762 win_info->detail.data_display_info.regs_column_count = 1; 763 win_info->detail.data_display_info.display_regs = FALSE; 764 win_info->generic.content = NULL; 765 win_info->generic.content_size = 0; 766 } 767 break; 768 default: 769 break; 770 } 771 if (win_info->generic.handle != (WINDOW *) NULL) 772 { 773 tui_delete_win (win_info->generic.handle); 774 win_info->generic.handle = (WINDOW *) NULL; 775 tui_free_win_content (&win_info->generic); 776 } 777 if (win_info->generic.title) 778 xfree (win_info->generic.title); 779 xfree (win_info); 780 } 781 782 783 void 784 tui_free_all_source_wins_content (void) 785 { 786 int i; 787 788 for (i = 0; i < (tui_source_windows ())->count; i++) 789 { 790 struct tui_win_info *win_info = (tui_source_windows ())->list[i]; 791 792 if (win_info != NULL) 793 { 794 tui_free_win_content (&(win_info->generic)); 795 tui_free_win_content (win_info->detail.source_info.execution_info); 796 } 797 } 798 } 799 800 801 void 802 tui_free_win_content (struct tui_gen_win_info *win_info) 803 { 804 if (win_info->content != NULL) 805 { 806 free_content ((tui_win_content) win_info->content, 807 win_info->content_size, 808 win_info->type); 809 win_info->content = NULL; 810 } 811 win_info->content_size = 0; 812 } 813 814 815 void 816 tui_del_data_windows (tui_win_content content, 817 int content_size) 818 { 819 int i; 820 821 /* Remember that data window content elements are of type struct 822 tui_gen_win_info *, each of which whose single element is a data 823 element. */ 824 for (i = 0; i < content_size; i++) 825 { 826 struct tui_gen_win_info *generic_win 827 = &content[i]->which_element.data_window; 828 829 if (generic_win != (struct tui_gen_win_info *) NULL) 830 { 831 tui_delete_win (generic_win->handle); 832 generic_win->handle = (WINDOW *) NULL; 833 generic_win->is_visible = FALSE; 834 } 835 } 836 } 837 838 839 void 840 tui_free_data_content (tui_win_content content, 841 int content_size) 842 { 843 int i; 844 845 /* Remember that data window content elements are of type struct 846 tui_gen_win_info *, each of which whose single element is a data 847 element. */ 848 for (i = 0; i < content_size; i++) 849 { 850 struct tui_gen_win_info *generic_win 851 = &content[i]->which_element.data_window; 852 853 if (generic_win != (struct tui_gen_win_info *) NULL) 854 { 855 tui_delete_win (generic_win->handle); 856 generic_win->handle = (WINDOW *) NULL; 857 tui_free_win_content (generic_win); 858 } 859 } 860 free_content (content, 861 content_size, 862 DATA_WIN); 863 } 864 865 866 /********************************** 867 ** LOCAL STATIC FUNCTIONS ** 868 **********************************/ 869 870 871 static void 872 free_content (tui_win_content content, 873 int content_size, 874 enum tui_win_type win_type) 875 { 876 if (content != (tui_win_content) NULL) 877 { 878 free_content_elements (content, content_size, win_type); 879 xfree (content); 880 } 881 } 882 883 884 /* free_content_elements(). 885 */ 886 static void 887 free_content_elements (tui_win_content content, 888 int content_size, 889 enum tui_win_type type) 890 { 891 if (content != (tui_win_content) NULL) 892 { 893 int i; 894 895 if (type == SRC_WIN || type == DISASSEM_WIN) 896 { 897 /* Free whole source block. */ 898 xfree (content[0]->which_element.source.line); 899 } 900 else 901 { 902 for (i = 0; i < content_size; i++) 903 { 904 struct tui_win_element *element; 905 906 element = content[i]; 907 if (element != (struct tui_win_element *) NULL) 908 { 909 switch (type) 910 { 911 case DATA_WIN: 912 xfree (element); 913 break; 914 case DATA_ITEM_WIN: 915 /* Note that data elements are not allocated in 916 a single block, but individually, as 917 needed. */ 918 if (element->which_element.data.type != TUI_REGISTER) 919 xfree ((void *)element->which_element.data.name); 920 xfree (element->which_element.data.value); 921 xfree (element->which_element.data.content); 922 xfree (element); 923 break; 924 case CMD_WIN: 925 xfree (element->which_element.command.line); 926 break; 927 default: 928 break; 929 } 930 } 931 } 932 } 933 if (type != DATA_WIN && type != DATA_ITEM_WIN) 934 xfree (content[0]); /* Free the element block. */ 935 } 936 } 937