GDB (API)
|
00001 /* TUI data manipulation routines. 00002 00003 Copyright (C) 1998-2013 Free Software Foundation, Inc. 00004 00005 Contributed by Hewlett-Packard Company. 00006 00007 This file is part of GDB. 00008 00009 This program is free software; you can redistribute it and/or modify 00010 it under the terms of the GNU General Public License as published by 00011 the Free Software Foundation; either version 3 of the License, or 00012 (at your option) any later version. 00013 00014 This program is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 GNU General Public License for more details. 00018 00019 You should have received a copy of the GNU General Public License 00020 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 00021 00022 #include "defs.h" 00023 #include "symtab.h" 00024 #include "tui/tui.h" 00025 #include "tui/tui-data.h" 00026 #include "tui/tui-wingeneral.h" 00027 00028 #include "gdb_string.h" 00029 #include "gdb_curses.h" 00030 00031 /**************************** 00032 ** GLOBAL DECLARATIONS 00033 ****************************/ 00034 struct tui_win_info *(tui_win_list[MAX_MAJOR_WINDOWS]); 00035 00036 /*************************** 00037 ** Private data 00038 ****************************/ 00039 static enum tui_layout_type current_layout = UNDEFINED_LAYOUT; 00040 static int term_height, term_width; 00041 static struct tui_gen_win_info _locator; 00042 static struct tui_gen_win_info exec_info[2]; 00043 static struct tui_win_info *src_win_list[2]; 00044 static struct tui_list source_windows = {src_win_list, 0}; 00045 static int default_tab_len = DEFAULT_TAB_LEN; 00046 static struct tui_win_info *win_with_focus = (struct tui_win_info *) NULL; 00047 static struct tui_layout_def layout_def = { 00048 SRC_WIN, /* DISPLAY_MODE */ 00049 FALSE, /* SPLIT */ 00050 TUI_UNDEFINED_REGS, /* REGS_DISPLAY_TYPE */ 00051 TUI_SFLOAT_REGS}; /* FLOAT_REGS_DISPLAY_TYPE */ 00052 00053 static int win_resized = FALSE; 00054 00055 00056 /********************************* 00057 ** Static function forward decls 00058 **********************************/ 00059 static void free_content (tui_win_content, 00060 int, 00061 enum tui_win_type); 00062 static void free_content_elements (tui_win_content, 00063 int, 00064 enum tui_win_type); 00065 00066 00067 00068 /********************************* 00069 ** PUBLIC FUNCTIONS 00070 **********************************/ 00071 00072 int 00073 tui_win_is_source_type (enum tui_win_type win_type) 00074 { 00075 return (win_type == SRC_WIN || win_type == DISASSEM_WIN); 00076 } 00077 00078 int 00079 tui_win_is_auxillary (enum tui_win_type win_type) 00080 { 00081 return (win_type > MAX_MAJOR_WINDOWS); 00082 } 00083 00084 int 00085 tui_win_has_locator (struct tui_win_info *win_info) 00086 { 00087 return (win_info != NULL 00088 && win_info->detail.source_info.has_locator); 00089 } 00090 00091 void 00092 tui_set_win_highlight (struct tui_win_info *win_info, 00093 int highlight) 00094 { 00095 if (win_info != NULL) 00096 win_info->is_highlighted = highlight; 00097 } 00098 00099 /****************************************** 00100 ** ACCESSORS & MUTATORS FOR PRIVATE DATA 00101 ******************************************/ 00102 00103 /* Answer a whether the terminal window has been resized or not. */ 00104 int 00105 tui_win_resized (void) 00106 { 00107 return win_resized; 00108 } 00109 00110 00111 /* Set a whether the terminal window has been resized or not. */ 00112 void 00113 tui_set_win_resized_to (int resized) 00114 { 00115 win_resized = resized; 00116 } 00117 00118 00119 /* Answer a pointer to the current layout definition. */ 00120 struct tui_layout_def * 00121 tui_layout_def (void) 00122 { 00123 return &layout_def; 00124 } 00125 00126 00127 /* Answer the window with the logical focus. */ 00128 struct tui_win_info * 00129 tui_win_with_focus (void) 00130 { 00131 return win_with_focus; 00132 } 00133 00134 00135 /* Set the window that has the logical focus. */ 00136 void 00137 tui_set_win_with_focus (struct tui_win_info *win_info) 00138 { 00139 win_with_focus = win_info; 00140 } 00141 00142 00143 /* Answer the length in chars, of tabs. */ 00144 int 00145 tui_default_tab_len (void) 00146 { 00147 return default_tab_len; 00148 } 00149 00150 00151 /* Set the length in chars, of tabs. */ 00152 void 00153 tui_set_default_tab_len (int len) 00154 { 00155 default_tab_len = len; 00156 } 00157 00158 00159 /* Accessor for the current source window. Usually there is only one 00160 source window (either source or disassembly), but both can be 00161 displayed at the same time. */ 00162 struct tui_list * 00163 tui_source_windows (void) 00164 { 00165 return &source_windows; 00166 } 00167 00168 00169 /* Clear the list of source windows. Usually there is only one source 00170 window (either source or disassembly), but both can be displayed at 00171 the same time. */ 00172 void 00173 tui_clear_source_windows (void) 00174 { 00175 source_windows.list[0] = NULL; 00176 source_windows.list[1] = NULL; 00177 source_windows.count = 0; 00178 } 00179 00180 00181 /* Clear the pertinant detail in the source windows. */ 00182 void 00183 tui_clear_source_windows_detail (void) 00184 { 00185 int i; 00186 00187 for (i = 0; i < (tui_source_windows ())->count; i++) 00188 tui_clear_win_detail ((tui_source_windows ())->list[i]); 00189 } 00190 00191 00192 /* Add a window to the list of source windows. Usually there is only 00193 one source window (either source or disassembly), but both can be 00194 displayed at the same time. */ 00195 void 00196 tui_add_to_source_windows (struct tui_win_info *win_info) 00197 { 00198 if (source_windows.count < 2) 00199 source_windows.list[source_windows.count++] = (void *) win_info; 00200 } 00201 00202 00203 /* Clear the pertinant detail in the windows. */ 00204 void 00205 tui_clear_win_detail (struct tui_win_info *win_info) 00206 { 00207 if (win_info != NULL) 00208 { 00209 switch (win_info->generic.type) 00210 { 00211 case SRC_WIN: 00212 case DISASSEM_WIN: 00213 win_info->detail.source_info.gdbarch = NULL; 00214 win_info->detail.source_info.start_line_or_addr.loa = LOA_ADDRESS; 00215 win_info->detail.source_info.start_line_or_addr.u.addr = 0; 00216 win_info->detail.source_info.horizontal_offset = 0; 00217 break; 00218 case CMD_WIN: 00219 win_info->detail.command_info.cur_line = 00220 win_info->detail.command_info.curch = 0; 00221 break; 00222 case DATA_WIN: 00223 win_info->detail.data_display_info.data_content = 00224 (tui_win_content) NULL; 00225 win_info->detail.data_display_info.data_content_count = 0; 00226 win_info->detail.data_display_info.regs_content = 00227 (tui_win_content) NULL; 00228 win_info->detail.data_display_info.regs_content_count = 0; 00229 win_info->detail.data_display_info.regs_display_type = 00230 TUI_UNDEFINED_REGS; 00231 win_info->detail.data_display_info.regs_column_count = 1; 00232 win_info->detail.data_display_info.display_regs = FALSE; 00233 break; 00234 default: 00235 break; 00236 } 00237 } 00238 } 00239 00240 00241 /* Accessor for the source execution info ptr. */ 00242 struct tui_gen_win_info * 00243 tui_source_exec_info_win_ptr (void) 00244 { 00245 return &exec_info[0]; 00246 } 00247 00248 00249 /* Accessor for the disassem execution info ptr. */ 00250 struct tui_gen_win_info * 00251 tui_disassem_exec_info_win_ptr (void) 00252 { 00253 return &exec_info[1]; 00254 } 00255 00256 00257 /* Accessor for the locator win info. Answers a pointer to the static 00258 locator win info struct. */ 00259 struct tui_gen_win_info * 00260 tui_locator_win_info_ptr (void) 00261 { 00262 return &_locator; 00263 } 00264 00265 00266 /* Accessor for the term_height. */ 00267 int 00268 tui_term_height (void) 00269 { 00270 return term_height; 00271 } 00272 00273 00274 /* Mutator for the term height. */ 00275 void 00276 tui_set_term_height_to (int h) 00277 { 00278 term_height = h; 00279 } 00280 00281 00282 /* Accessor for the term_width. */ 00283 int 00284 tui_term_width (void) 00285 { 00286 return term_width; 00287 } 00288 00289 00290 /* Mutator for the term_width. */ 00291 void 00292 tui_set_term_width_to (int w) 00293 { 00294 term_width = w; 00295 } 00296 00297 00298 /* Accessor for the current layout. */ 00299 enum tui_layout_type 00300 tui_current_layout (void) 00301 { 00302 return current_layout; 00303 } 00304 00305 00306 /* Mutator for the current layout. */ 00307 void 00308 tui_set_current_layout_to (enum tui_layout_type new_layout) 00309 { 00310 current_layout = new_layout; 00311 } 00312 00313 00314 /***************************** 00315 ** OTHER PUBLIC FUNCTIONS 00316 *****************************/ 00317 00318 00319 /* Answer the next window in the list, cycling back to the top if 00320 necessary. */ 00321 struct tui_win_info * 00322 tui_next_win (struct tui_win_info *cur_win) 00323 { 00324 enum tui_win_type type = cur_win->generic.type; 00325 struct tui_win_info *next_win = (struct tui_win_info *) NULL; 00326 00327 if (cur_win->generic.type == CMD_WIN) 00328 type = SRC_WIN; 00329 else 00330 type = cur_win->generic.type + 1; 00331 while (type != cur_win->generic.type && (next_win == NULL)) 00332 { 00333 if (tui_win_list[type] 00334 && tui_win_list[type]->generic.is_visible) 00335 next_win = tui_win_list[type]; 00336 else 00337 { 00338 if (type == CMD_WIN) 00339 type = SRC_WIN; 00340 else 00341 type++; 00342 } 00343 } 00344 00345 return next_win; 00346 } 00347 00348 00349 /* Answer the prev window in the list, cycling back to the bottom if 00350 necessary. */ 00351 struct tui_win_info * 00352 tui_prev_win (struct tui_win_info *cur_win) 00353 { 00354 enum tui_win_type type = cur_win->generic.type; 00355 struct tui_win_info *prev = (struct tui_win_info *) NULL; 00356 00357 if (cur_win->generic.type == SRC_WIN) 00358 type = CMD_WIN; 00359 else 00360 type = cur_win->generic.type - 1; 00361 while (type != cur_win->generic.type && (prev == NULL)) 00362 { 00363 if (tui_win_list[type] 00364 && tui_win_list[type]->generic.is_visible) 00365 prev = tui_win_list[type]; 00366 else 00367 { 00368 if (type == SRC_WIN) 00369 type = CMD_WIN; 00370 else 00371 type--; 00372 } 00373 } 00374 00375 return prev; 00376 } 00377 00378 00379 /* Answer the window represented by name. */ 00380 struct tui_win_info * 00381 tui_partial_win_by_name (char *name) 00382 { 00383 struct tui_win_info *win_info = (struct tui_win_info *) NULL; 00384 00385 if (name != (char *) NULL) 00386 { 00387 int i = 0; 00388 00389 while (i < MAX_MAJOR_WINDOWS && win_info == NULL) 00390 { 00391 if (tui_win_list[i] != 0) 00392 { 00393 char *cur_name = tui_win_name (&tui_win_list[i]->generic); 00394 00395 if (strlen (name) <= strlen (cur_name) 00396 && strncmp (name, cur_name, strlen (name)) == 0) 00397 win_info = tui_win_list[i]; 00398 } 00399 i++; 00400 } 00401 } 00402 00403 return win_info; 00404 } 00405 00406 00407 /* Answer the name of the window. */ 00408 char * 00409 tui_win_name (struct tui_gen_win_info *win_info) 00410 { 00411 char *name = (char *) NULL; 00412 00413 switch (win_info->type) 00414 { 00415 case SRC_WIN: 00416 name = SRC_NAME; 00417 break; 00418 case CMD_WIN: 00419 name = CMD_NAME; 00420 break; 00421 case DISASSEM_WIN: 00422 name = DISASSEM_NAME; 00423 break; 00424 case DATA_WIN: 00425 name = DATA_NAME; 00426 break; 00427 default: 00428 name = ""; 00429 break; 00430 } 00431 00432 return name; 00433 } 00434 00435 00436 void 00437 tui_initialize_static_data (void) 00438 { 00439 tui_init_generic_part (tui_source_exec_info_win_ptr ()); 00440 tui_init_generic_part (tui_disassem_exec_info_win_ptr ()); 00441 tui_init_generic_part (tui_locator_win_info_ptr ()); 00442 } 00443 00444 00445 struct tui_gen_win_info * 00446 tui_alloc_generic_win_info (void) 00447 { 00448 struct tui_gen_win_info *win; 00449 00450 if ((win = XMALLOC (struct tui_gen_win_info)) != NULL) 00451 tui_init_generic_part (win); 00452 00453 return win; 00454 } 00455 00456 00457 void 00458 tui_init_generic_part (struct tui_gen_win_info *win) 00459 { 00460 win->width = 00461 win->height = 00462 win->origin.x = 00463 win->origin.y = 00464 win->viewport_height = 00465 win->content_size = 00466 win->last_visible_line = 0; 00467 win->handle = (WINDOW *) NULL; 00468 win->content = NULL; 00469 win->content_in_use = 00470 win->is_visible = FALSE; 00471 win->title = 0; 00472 } 00473 00474 00475 /* init_content_element(). 00476 */ 00477 static void 00478 init_content_element (struct tui_win_element *element, 00479 enum tui_win_type type) 00480 { 00481 element->highlight = FALSE; 00482 switch (type) 00483 { 00484 case SRC_WIN: 00485 case DISASSEM_WIN: 00486 element->which_element.source.line = (char *) NULL; 00487 element->which_element.source.line_or_addr.loa = LOA_LINE; 00488 element->which_element.source.line_or_addr.u.line_no = 0; 00489 element->which_element.source.is_exec_point = FALSE; 00490 element->which_element.source.has_break = FALSE; 00491 break; 00492 case DATA_WIN: 00493 tui_init_generic_part (&element->which_element.data_window); 00494 element->which_element.data_window.type = DATA_ITEM_WIN; 00495 ((struct tui_gen_win_info *) 00496 &element->which_element.data_window)->content = 00497 (void **) tui_alloc_content (1, DATA_ITEM_WIN); 00498 ((struct tui_gen_win_info *) 00499 & element->which_element.data_window)->content_size = 1; 00500 break; 00501 case CMD_WIN: 00502 element->which_element.command.line = (char *) NULL; 00503 break; 00504 case DATA_ITEM_WIN: 00505 element->which_element.data.name = (char *) NULL; 00506 element->which_element.data.type = TUI_REGISTER; 00507 element->which_element.data.item_no = UNDEFINED_ITEM; 00508 element->which_element.data.value = NULL; 00509 element->which_element.data.highlight = FALSE; 00510 element->which_element.data.content = (char*) NULL; 00511 break; 00512 case LOCATOR_WIN: 00513 element->which_element.locator.full_name[0] = 00514 element->which_element.locator.proc_name[0] = (char) 0; 00515 element->which_element.locator.line_no = 0; 00516 element->which_element.locator.addr = 0; 00517 break; 00518 case EXEC_INFO_WIN: 00519 memset(element->which_element.simple_string, ' ', 00520 sizeof(element->which_element.simple_string)); 00521 break; 00522 default: 00523 break; 00524 } 00525 } 00526 00527 static void 00528 init_win_info (struct tui_win_info *win_info) 00529 { 00530 tui_init_generic_part (&win_info->generic); 00531 win_info->can_highlight = 00532 win_info->is_highlighted = FALSE; 00533 switch (win_info->generic.type) 00534 { 00535 case SRC_WIN: 00536 case DISASSEM_WIN: 00537 win_info->detail.source_info.execution_info 00538 = (struct tui_gen_win_info *) NULL; 00539 win_info->detail.source_info.has_locator = FALSE; 00540 win_info->detail.source_info.horizontal_offset = 0; 00541 win_info->detail.source_info.gdbarch = NULL; 00542 win_info->detail.source_info.start_line_or_addr.loa = LOA_ADDRESS; 00543 win_info->detail.source_info.start_line_or_addr.u.addr = 0; 00544 win_info->detail.source_info.fullname = NULL; 00545 break; 00546 case DATA_WIN: 00547 win_info->detail.data_display_info.data_content = (tui_win_content) NULL; 00548 win_info->detail.data_display_info.data_content_count = 0; 00549 win_info->detail.data_display_info.regs_content = (tui_win_content) NULL; 00550 win_info->detail.data_display_info.regs_content_count = 0; 00551 win_info->detail.data_display_info.regs_display_type = 00552 TUI_UNDEFINED_REGS; 00553 win_info->detail.data_display_info.regs_column_count = 1; 00554 win_info->detail.data_display_info.display_regs = FALSE; 00555 win_info->detail.data_display_info.current_group = 0; 00556 break; 00557 case CMD_WIN: 00558 win_info->detail.command_info.cur_line = 0; 00559 win_info->detail.command_info.curch = 0; 00560 break; 00561 default: 00562 win_info->detail.opaque = NULL; 00563 break; 00564 } 00565 } 00566 00567 00568 struct tui_win_info * 00569 tui_alloc_win_info (enum tui_win_type type) 00570 { 00571 struct tui_win_info *win_info; 00572 00573 win_info = XMALLOC (struct tui_win_info); 00574 if (win_info != NULL) 00575 { 00576 win_info->generic.type = type; 00577 init_win_info (win_info); 00578 } 00579 00580 return win_info; 00581 } 00582 00583 00584 /* Allocates the content and elements in a block. */ 00585 tui_win_content 00586 tui_alloc_content (int num_elements, enum tui_win_type type) 00587 { 00588 tui_win_content content; 00589 char *element_block_ptr; 00590 int i; 00591 00592 content = xmalloc (sizeof (struct tui_win_element *) *num_elements); 00593 if (content != NULL) 00594 { 00595 /* 00596 * All windows, except the data window, can allocate the 00597 * elements in a chunk. The data window cannot because items 00598 * can be added/removed from the data display by the user at any 00599 * time. 00600 */ 00601 if (type != DATA_WIN) 00602 { 00603 element_block_ptr = 00604 xmalloc (sizeof (struct tui_win_element) * num_elements); 00605 if (element_block_ptr != NULL) 00606 { 00607 for (i = 0; i < num_elements; i++) 00608 { 00609 content[i] = (struct tui_win_element *) element_block_ptr; 00610 init_content_element (content[i], type); 00611 element_block_ptr += sizeof (struct tui_win_element); 00612 } 00613 } 00614 else 00615 { 00616 xfree (content); 00617 content = (tui_win_content) NULL; 00618 } 00619 } 00620 } 00621 00622 return content; 00623 } 00624 00625 00626 /* Adds the input number of elements to the windows's content. If no 00627 content has been allocated yet, alloc_content() is called to do 00628 this. The index of the first element added is returned, unless 00629 there is a memory allocation error, in which case, (-1) is 00630 returned. */ 00631 int 00632 tui_add_content_elements (struct tui_gen_win_info *win_info, 00633 int num_elements) 00634 { 00635 struct tui_win_element *element_ptr; 00636 int i, index_start; 00637 00638 if (win_info->content == NULL) 00639 { 00640 win_info->content = (void **) tui_alloc_content (num_elements, 00641 win_info->type); 00642 index_start = 0; 00643 } 00644 else 00645 index_start = win_info->content_size; 00646 if (win_info->content != NULL) 00647 { 00648 for (i = index_start; (i < num_elements + index_start); i++) 00649 { 00650 if ((element_ptr = XMALLOC (struct tui_win_element)) != NULL) 00651 { 00652 win_info->content[i] = (void *) element_ptr; 00653 init_content_element (element_ptr, win_info->type); 00654 win_info->content_size++; 00655 } 00656 else /* Things must be really hosed now! We ran out of 00657 memory!? */ 00658 return (-1); 00659 } 00660 } 00661 00662 return index_start; 00663 } 00664 00665 00666 /* Delete all curses windows associated with win_info, leaving 00667 everything else intact. */ 00668 void 00669 tui_del_window (struct tui_win_info *win_info) 00670 { 00671 struct tui_gen_win_info *generic_win; 00672 00673 switch (win_info->generic.type) 00674 { 00675 case SRC_WIN: 00676 case DISASSEM_WIN: 00677 generic_win = tui_locator_win_info_ptr (); 00678 if (generic_win != (struct tui_gen_win_info *) NULL) 00679 { 00680 tui_delete_win (generic_win->handle); 00681 generic_win->handle = (WINDOW *) NULL; 00682 generic_win->is_visible = FALSE; 00683 } 00684 if (win_info->detail.source_info.fullname) 00685 { 00686 xfree (win_info->detail.source_info.fullname); 00687 win_info->detail.source_info.fullname = NULL; 00688 } 00689 generic_win = win_info->detail.source_info.execution_info; 00690 if (generic_win != (struct tui_gen_win_info *) NULL) 00691 { 00692 tui_delete_win (generic_win->handle); 00693 generic_win->handle = (WINDOW *) NULL; 00694 generic_win->is_visible = FALSE; 00695 } 00696 break; 00697 case DATA_WIN: 00698 if (win_info->generic.content != NULL) 00699 { 00700 tui_del_data_windows (win_info->detail.data_display_info.regs_content, 00701 win_info->detail.data_display_info.regs_content_count); 00702 tui_del_data_windows (win_info->detail.data_display_info.data_content, 00703 win_info->detail.data_display_info.data_content_count); 00704 } 00705 break; 00706 default: 00707 break; 00708 } 00709 if (win_info->generic.handle != (WINDOW *) NULL) 00710 { 00711 tui_delete_win (win_info->generic.handle); 00712 win_info->generic.handle = (WINDOW *) NULL; 00713 win_info->generic.is_visible = FALSE; 00714 } 00715 } 00716 00717 00718 void 00719 tui_free_window (struct tui_win_info *win_info) 00720 { 00721 struct tui_gen_win_info *generic_win; 00722 00723 switch (win_info->generic.type) 00724 { 00725 case SRC_WIN: 00726 case DISASSEM_WIN: 00727 generic_win = tui_locator_win_info_ptr (); 00728 if (generic_win != (struct tui_gen_win_info *) NULL) 00729 { 00730 tui_delete_win (generic_win->handle); 00731 generic_win->handle = (WINDOW *) NULL; 00732 } 00733 tui_free_win_content (generic_win); 00734 if (win_info->detail.source_info.fullname) 00735 { 00736 xfree (win_info->detail.source_info.fullname); 00737 win_info->detail.source_info.fullname = NULL; 00738 } 00739 generic_win = win_info->detail.source_info.execution_info; 00740 if (generic_win != (struct tui_gen_win_info *) NULL) 00741 { 00742 tui_delete_win (generic_win->handle); 00743 generic_win->handle = (WINDOW *) NULL; 00744 tui_free_win_content (generic_win); 00745 } 00746 break; 00747 case DATA_WIN: 00748 if (win_info->generic.content != NULL) 00749 { 00750 tui_free_data_content (win_info->detail.data_display_info.regs_content, 00751 win_info->detail.data_display_info.regs_content_count); 00752 win_info->detail.data_display_info.regs_content = 00753 (tui_win_content) NULL; 00754 win_info->detail.data_display_info.regs_content_count = 0; 00755 tui_free_data_content (win_info->detail.data_display_info.data_content, 00756 win_info->detail.data_display_info.data_content_count); 00757 win_info->detail.data_display_info.data_content = 00758 (tui_win_content) NULL; 00759 win_info->detail.data_display_info.data_content_count = 0; 00760 win_info->detail.data_display_info.regs_display_type = 00761 TUI_UNDEFINED_REGS; 00762 win_info->detail.data_display_info.regs_column_count = 1; 00763 win_info->detail.data_display_info.display_regs = FALSE; 00764 win_info->generic.content = NULL; 00765 win_info->generic.content_size = 0; 00766 } 00767 break; 00768 default: 00769 break; 00770 } 00771 if (win_info->generic.handle != (WINDOW *) NULL) 00772 { 00773 tui_delete_win (win_info->generic.handle); 00774 win_info->generic.handle = (WINDOW *) NULL; 00775 tui_free_win_content (&win_info->generic); 00776 } 00777 if (win_info->generic.title) 00778 xfree (win_info->generic.title); 00779 xfree (win_info); 00780 } 00781 00782 00783 void 00784 tui_free_all_source_wins_content (void) 00785 { 00786 int i; 00787 00788 for (i = 0; i < (tui_source_windows ())->count; i++) 00789 { 00790 struct tui_win_info *win_info = (tui_source_windows ())->list[i]; 00791 00792 if (win_info != NULL) 00793 { 00794 tui_free_win_content (&(win_info->generic)); 00795 tui_free_win_content (win_info->detail.source_info.execution_info); 00796 } 00797 } 00798 } 00799 00800 00801 void 00802 tui_free_win_content (struct tui_gen_win_info *win_info) 00803 { 00804 if (win_info->content != NULL) 00805 { 00806 free_content ((tui_win_content) win_info->content, 00807 win_info->content_size, 00808 win_info->type); 00809 win_info->content = NULL; 00810 } 00811 win_info->content_size = 0; 00812 } 00813 00814 00815 void 00816 tui_del_data_windows (tui_win_content content, 00817 int content_size) 00818 { 00819 int i; 00820 00821 /* Remember that data window content elements are of type struct 00822 tui_gen_win_info *, each of which whose single element is a data 00823 element. */ 00824 for (i = 0; i < content_size; i++) 00825 { 00826 struct tui_gen_win_info *generic_win 00827 = &content[i]->which_element.data_window; 00828 00829 if (generic_win != (struct tui_gen_win_info *) NULL) 00830 { 00831 tui_delete_win (generic_win->handle); 00832 generic_win->handle = (WINDOW *) NULL; 00833 generic_win->is_visible = FALSE; 00834 } 00835 } 00836 } 00837 00838 00839 void 00840 tui_free_data_content (tui_win_content content, 00841 int content_size) 00842 { 00843 int i; 00844 00845 /* Remember that data window content elements are of type struct 00846 tui_gen_win_info *, each of which whose single element is a data 00847 element. */ 00848 for (i = 0; i < content_size; i++) 00849 { 00850 struct tui_gen_win_info *generic_win 00851 = &content[i]->which_element.data_window; 00852 00853 if (generic_win != (struct tui_gen_win_info *) NULL) 00854 { 00855 tui_delete_win (generic_win->handle); 00856 generic_win->handle = (WINDOW *) NULL; 00857 tui_free_win_content (generic_win); 00858 } 00859 } 00860 free_content (content, 00861 content_size, 00862 DATA_WIN); 00863 } 00864 00865 00866 /********************************** 00867 ** LOCAL STATIC FUNCTIONS ** 00868 **********************************/ 00869 00870 00871 static void 00872 free_content (tui_win_content content, 00873 int content_size, 00874 enum tui_win_type win_type) 00875 { 00876 if (content != (tui_win_content) NULL) 00877 { 00878 free_content_elements (content, content_size, win_type); 00879 xfree (content); 00880 } 00881 } 00882 00883 00884 /* free_content_elements(). 00885 */ 00886 static void 00887 free_content_elements (tui_win_content content, 00888 int content_size, 00889 enum tui_win_type type) 00890 { 00891 if (content != (tui_win_content) NULL) 00892 { 00893 int i; 00894 00895 if (type == SRC_WIN || type == DISASSEM_WIN) 00896 { 00897 /* Free whole source block. */ 00898 xfree (content[0]->which_element.source.line); 00899 } 00900 else 00901 { 00902 for (i = 0; i < content_size; i++) 00903 { 00904 struct tui_win_element *element; 00905 00906 element = content[i]; 00907 if (element != (struct tui_win_element *) NULL) 00908 { 00909 switch (type) 00910 { 00911 case DATA_WIN: 00912 xfree (element); 00913 break; 00914 case DATA_ITEM_WIN: 00915 /* Note that data elements are not allocated in 00916 a single block, but individually, as 00917 needed. */ 00918 if (element->which_element.data.type != TUI_REGISTER) 00919 xfree ((void *)element->which_element.data.name); 00920 xfree (element->which_element.data.value); 00921 xfree (element->which_element.data.content); 00922 xfree (element); 00923 break; 00924 case CMD_WIN: 00925 xfree (element->which_element.command.line); 00926 break; 00927 default: 00928 break; 00929 } 00930 } 00931 } 00932 } 00933 if (type != DATA_WIN && type != DATA_ITEM_WIN) 00934 xfree (content[0]); /* Free the element block. */ 00935 } 00936 }