PageRenderTime 41ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/src/freebsd/contrib/gdb/gdb/tui/tui-data.c

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