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