Split the tui_win_info destructor
[deliverable/binutils-gdb.git] / gdb / tui / tui-data.c
CommitLineData
f377b406 1/* TUI data manipulation routines.
f33c6cbf 2
42a4f53d 3 Copyright (C) 1998-2019 Free Software Foundation, Inc.
f33c6cbf 4
f377b406
SC
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
a9762ec7 11 the Free Software Foundation; either version 3 of the License, or
f377b406
SC
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
a9762ec7 20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
c906108c 21
96ec9981
DJ
22#include "defs.h"
23#include "symtab.h"
d7b2e967
AC
24#include "tui/tui.h"
25#include "tui/tui-data.h"
26#include "tui/tui-wingeneral.h"
6a83354a 27#include "gdb_curses.h"
4e8f7a8b 28
c906108c
SS
29/****************************
30** GLOBAL DECLARATIONS
31****************************/
7fa29be9 32struct tui_win_info *tui_win_list[MAX_MAJOR_WINDOWS];
c906108c 33
c906108c
SS
34/***************************
35** Private data
36****************************/
6ba8e26f
AC
37static enum tui_layout_type current_layout = UNDEFINED_LAYOUT;
38static int term_height, term_width;
2a8854a7 39static struct tui_gen_win_info _locator;
6ba8e26f 40static struct tui_gen_win_info exec_info[2];
b4eb2452 41static std::vector<tui_win_info *> source_windows;
e65b5245 42static struct tui_win_info *win_with_focus = NULL;
08ef48c5
MS
43static struct tui_layout_def layout_def = {
44 SRC_WIN, /* DISPLAY_MODE */
7bd0be3a 45 FALSE}; /* SPLIT */
08ef48c5 46
6ba8e26f 47static int win_resized = FALSE;
c906108c
SS
48
49
50/*********************************
51** Static function forward decls
52**********************************/
08ef48c5
MS
53static void free_content (tui_win_content,
54 int,
55 enum tui_win_type);
56static void free_content_elements (tui_win_content,
57 int,
58 enum tui_win_type);
c906108c
SS
59
60
61
62/*********************************
63** PUBLIC FUNCTIONS
64**********************************/
65
6d012f14
AC
66int
67tui_win_is_source_type (enum tui_win_type win_type)
68{
69 return (win_type == SRC_WIN || win_type == DISASSEM_WIN);
70}
71
72int
73tui_win_is_auxillary (enum tui_win_type win_type)
74{
75 return (win_type > MAX_MAJOR_WINDOWS);
76}
77
78int
79tui_win_has_locator (struct tui_win_info *win_info)
80{
08ef48c5 81 return (win_info != NULL
6d012f14
AC
82 && win_info->detail.source_info.has_locator);
83}
84
85void
08ef48c5
MS
86tui_set_win_highlight (struct tui_win_info *win_info,
87 int highlight)
6d012f14
AC
88{
89 if (win_info != NULL)
90 win_info->is_highlighted = highlight;
91}
92
c906108c
SS
93/******************************************
94** ACCESSORS & MUTATORS FOR PRIVATE DATA
95******************************************/
96
1cc6d956 97/* Answer a whether the terminal window has been resized or not. */
c906108c 98int
dd1abb8c 99tui_win_resized (void)
c906108c 100{
6ba8e26f 101 return win_resized;
dd1abb8c 102}
c906108c
SS
103
104
1cc6d956 105/* Set a whether the terminal window has been resized or not. */
c906108c 106void
dd1abb8c 107tui_set_win_resized_to (int resized)
c906108c 108{
6ba8e26f 109 win_resized = resized;
dd1abb8c 110}
c906108c
SS
111
112
1cc6d956 113/* Answer a pointer to the current layout definition. */
2a8854a7 114struct tui_layout_def *
dd1abb8c 115tui_layout_def (void)
c906108c 116{
6ba8e26f 117 return &layout_def;
dd1abb8c 118}
c906108c
SS
119
120
1cc6d956 121/* Answer the window with the logical focus. */
2a8854a7 122struct tui_win_info *
dd1abb8c 123tui_win_with_focus (void)
c906108c 124{
6ba8e26f 125 return win_with_focus;
dd1abb8c 126}
c906108c
SS
127
128
1cc6d956 129/* Set the window that has the logical focus. */
c906108c 130void
5b6fe301 131tui_set_win_with_focus (struct tui_win_info *win_info)
c906108c 132{
6ba8e26f 133 win_with_focus = win_info;
dd1abb8c 134}
c906108c
SS
135
136
6ba8e26f
AC
137/* Accessor for the current source window. Usually there is only one
138 source window (either source or disassembly), but both can be
139 displayed at the same time. */
b4eb2452
TT
140std::vector<tui_win_info *> &
141tui_source_windows ()
c906108c 142{
b4eb2452 143 return source_windows;
dd1abb8c 144}
c906108c
SS
145
146
dd1abb8c
AC
147/* Clear the list of source windows. Usually there is only one source
148 window (either source or disassembly), but both can be displayed at
149 the same time. */
c906108c 150void
b4eb2452 151tui_clear_source_windows ()
c906108c 152{
b4eb2452 153 source_windows.clear ();
dd1abb8c 154}
c906108c
SS
155
156
1cc6d956 157/* Clear the pertinant detail in the source windows. */
c906108c 158void
b4eb2452 159tui_clear_source_windows_detail ()
c906108c 160{
b4eb2452
TT
161 for (tui_win_info *win : tui_source_windows ())
162 tui_clear_win_detail (win);
dd1abb8c 163}
c906108c
SS
164
165
dd1abb8c
AC
166/* Add a window to the list of source windows. Usually there is only
167 one source window (either source or disassembly), but both can be
168 displayed at the same time. */
c906108c 169void
5b6fe301 170tui_add_to_source_windows (struct tui_win_info *win_info)
c906108c 171{
b4eb2452
TT
172 if (source_windows.size () < 2)
173 source_windows.push_back (win_info);
dd1abb8c 174}
c906108c 175
8761a91b
TT
176/* See tui-data.h. */
177
178void
179tui_source_window::clear_detail ()
180{
181 detail.source_info.gdbarch = NULL;
182 detail.source_info.start_line_or_addr.loa = LOA_ADDRESS;
183 detail.source_info.start_line_or_addr.u.addr = 0;
184 detail.source_info.horizontal_offset = 0;
185}
186
187/* See tui-data.h. */
188
189void
190tui_cmd_window::clear_detail ()
191{
192 wmove (generic.handle, 0, 0);
193}
194
195/* See tui-data.h. */
196
197void
198tui_data_window::clear_detail ()
199{
200 detail.data_display_info.data_content = NULL;
201 detail.data_display_info.data_content_count = 0;
202 detail.data_display_info.regs_content = NULL;
203 detail.data_display_info.regs_content_count = 0;
204 detail.data_display_info.regs_column_count = 1;
205 detail.data_display_info.display_regs = FALSE;
206}
c906108c 207
1cc6d956 208/* Clear the pertinant detail in the windows. */
c906108c 209void
5b6fe301 210tui_clear_win_detail (struct tui_win_info *win_info)
c906108c 211{
6d012f14 212 if (win_info != NULL)
8761a91b 213 win_info->clear_detail ();
6ba8e26f 214}
c906108c
SS
215
216
6ba8e26f 217/* Accessor for the source execution info ptr. */
2a8854a7 218struct tui_gen_win_info *
dd1abb8c 219tui_source_exec_info_win_ptr (void)
c906108c 220{
6ba8e26f
AC
221 return &exec_info[0];
222}
c906108c
SS
223
224
6ba8e26f 225/* Accessor for the disassem execution info ptr. */
2a8854a7 226struct tui_gen_win_info *
dd1abb8c 227tui_disassem_exec_info_win_ptr (void)
c906108c 228{
6ba8e26f
AC
229 return &exec_info[1];
230}
c906108c
SS
231
232
dd1abb8c
AC
233/* Accessor for the locator win info. Answers a pointer to the static
234 locator win info struct. */
2a8854a7 235struct tui_gen_win_info *
dd1abb8c 236tui_locator_win_info_ptr (void)
c906108c
SS
237{
238 return &_locator;
2a8854a7 239}
c906108c
SS
240
241
6ba8e26f 242/* Accessor for the term_height. */
c906108c 243int
dd1abb8c 244tui_term_height (void)
c906108c 245{
6ba8e26f 246 return term_height;
dd1abb8c 247}
c906108c
SS
248
249
1cc6d956 250/* Mutator for the term height. */
c906108c 251void
dd1abb8c 252tui_set_term_height_to (int h)
c906108c 253{
6ba8e26f 254 term_height = h;
dd1abb8c 255}
c906108c
SS
256
257
1cc6d956 258/* Accessor for the term_width. */
c906108c 259int
dd1abb8c 260tui_term_width (void)
c906108c 261{
6ba8e26f 262 return term_width;
dd1abb8c 263}
c906108c
SS
264
265
6ba8e26f 266/* Mutator for the term_width. */
c906108c 267void
dd1abb8c 268tui_set_term_width_to (int w)
c906108c 269{
6ba8e26f 270 term_width = w;
dd1abb8c 271}
c906108c
SS
272
273
1cc6d956 274/* Accessor for the current layout. */
2a8854a7 275enum tui_layout_type
dd1abb8c 276tui_current_layout (void)
c906108c 277{
6ba8e26f 278 return current_layout;
dd1abb8c 279}
c906108c
SS
280
281
dd1abb8c 282/* Mutator for the current layout. */
c906108c 283void
6ba8e26f 284tui_set_current_layout_to (enum tui_layout_type new_layout)
c906108c 285{
6ba8e26f 286 current_layout = new_layout;
dd1abb8c 287}
c906108c
SS
288
289
c906108c
SS
290/*****************************
291** OTHER PUBLIC FUNCTIONS
292*****************************/
293
294
dd1abb8c
AC
295/* Answer the next window in the list, cycling back to the top if
296 necessary. */
2a8854a7 297struct tui_win_info *
5b6fe301 298tui_next_win (struct tui_win_info *cur_win)
c906108c 299{
570dc176 300 int type = cur_win->generic.type;
e65b5245 301 struct tui_win_info *next_win = NULL;
c906108c 302
6ba8e26f 303 if (cur_win->generic.type == CMD_WIN)
c906108c
SS
304 type = SRC_WIN;
305 else
6ba8e26f
AC
306 type = cur_win->generic.type + 1;
307 while (type != cur_win->generic.type && (next_win == NULL))
c906108c 308 {
e5908723
MS
309 if (tui_win_list[type]
310 && tui_win_list[type]->generic.is_visible)
6ba8e26f 311 next_win = tui_win_list[type];
c906108c
SS
312 else
313 {
314 if (type == CMD_WIN)
315 type = SRC_WIN;
316 else
317 type++;
318 }
319 }
320
6ba8e26f
AC
321 return next_win;
322}
c906108c
SS
323
324
dd1abb8c
AC
325/* Answer the prev window in the list, cycling back to the bottom if
326 necessary. */
2a8854a7 327struct tui_win_info *
5b6fe301 328tui_prev_win (struct tui_win_info *cur_win)
c906108c 329{
570dc176 330 int type = cur_win->generic.type;
e65b5245 331 struct tui_win_info *prev = NULL;
c906108c 332
6ba8e26f 333 if (cur_win->generic.type == SRC_WIN)
c906108c
SS
334 type = CMD_WIN;
335 else
6ba8e26f
AC
336 type = cur_win->generic.type - 1;
337 while (type != cur_win->generic.type && (prev == NULL))
c906108c 338 {
37715c4c
TJB
339 if (tui_win_list[type]
340 && tui_win_list[type]->generic.is_visible)
6d012f14 341 prev = tui_win_list[type];
c906108c
SS
342 else
343 {
344 if (type == SRC_WIN)
345 type = CMD_WIN;
346 else
347 type--;
348 }
349 }
350
351 return prev;
cb50eddd 352}
c906108c
SS
353
354
1cc6d956 355/* Answer the window represented by name. */
2a8854a7 356struct tui_win_info *
a121b7c1 357tui_partial_win_by_name (const char *name)
c906108c 358{
e65b5245 359 struct tui_win_info *win_info = NULL;
c906108c 360
63a33118 361 if (name != NULL)
c906108c
SS
362 {
363 int i = 0;
364
6d012f14 365 while (i < MAX_MAJOR_WINDOWS && win_info == NULL)
c906108c 366 {
6d012f14 367 if (tui_win_list[i] != 0)
a4b99e53 368 {
f41cbf58
AB
369 const char *cur_name =
370 tui_win_name (&tui_win_list[i]->generic);
1c5313c5 371
e5908723 372 if (strlen (name) <= strlen (cur_name)
61012eef 373 && startswith (cur_name, name))
6d012f14 374 win_info = tui_win_list[i];
a4b99e53 375 }
c906108c
SS
376 i++;
377 }
378 }
379
6d012f14 380 return win_info;
6ba8e26f 381}
c906108c
SS
382
383
6ba8e26f 384/* Answer the name of the window. */
f41cbf58
AB
385const char *
386tui_win_name (const struct tui_gen_win_info *win_info)
c906108c 387{
136765ea 388 const char *name = NULL;
c906108c 389
6d012f14 390 switch (win_info->type)
c906108c
SS
391 {
392 case SRC_WIN:
393 name = SRC_NAME;
394 break;
395 case CMD_WIN:
396 name = CMD_NAME;
397 break;
398 case DISASSEM_WIN:
399 name = DISASSEM_NAME;
400 break;
401 case DATA_WIN:
402 name = DATA_NAME;
403 break;
404 default:
405 name = "";
406 break;
407 }
408
409 return name;
6ba8e26f 410}
c906108c
SS
411
412
c906108c 413void
dd1abb8c 414tui_initialize_static_data (void)
c906108c 415{
dd1abb8c
AC
416 tui_init_generic_part (tui_source_exec_info_win_ptr ());
417 tui_init_generic_part (tui_disassem_exec_info_win_ptr ());
418 tui_init_generic_part (tui_locator_win_info_ptr ());
419}
c906108c
SS
420
421
2a8854a7 422struct tui_gen_win_info *
dd1abb8c 423tui_alloc_generic_win_info (void)
c906108c 424{
8d749320 425 struct tui_gen_win_info *win = XNEW (struct tui_gen_win_info);
c906108c 426
730ead81 427 tui_init_generic_part (win);
c906108c
SS
428
429 return win;
6ba8e26f 430}
c906108c
SS
431
432
c906108c 433void
5b6fe301 434tui_init_generic_part (struct tui_gen_win_info *win)
c906108c
SS
435{
436 win->width =
437 win->height =
438 win->origin.x =
439 win->origin.y =
6d012f14
AC
440 win->viewport_height =
441 win->content_size =
442 win->last_visible_line = 0;
e65b5245 443 win->handle = NULL;
22940a24 444 win->content = NULL;
6d012f14
AC
445 win->content_in_use =
446 win->is_visible = FALSE;
bc6b7f04
SC
447 win->title = 0;
448}
c906108c
SS
449
450
ef5eab5a 451/* init_content_element().
c5aa993b 452 */
2c0b251b 453static void
08ef48c5
MS
454init_content_element (struct tui_win_element *element,
455 enum tui_win_type type)
c906108c 456{
c906108c
SS
457 switch (type)
458 {
459 case SRC_WIN:
460 case DISASSEM_WIN:
e65b5245 461 element->which_element.source.line = NULL;
362c05fe
AS
462 element->which_element.source.line_or_addr.loa = LOA_LINE;
463 element->which_element.source.line_or_addr.u.line_no = 0;
6d012f14
AC
464 element->which_element.source.is_exec_point = FALSE;
465 element->which_element.source.has_break = FALSE;
c906108c
SS
466 break;
467 case DATA_WIN:
6d012f14
AC
468 tui_init_generic_part (&element->which_element.data_window);
469 element->which_element.data_window.type = DATA_ITEM_WIN;
63ed8182
PP
470 element->which_element.data_window.content =
471 tui_alloc_content (1, DATA_ITEM_WIN);
472 element->which_element.data_window.content_size = 1;
c906108c
SS
473 break;
474 case CMD_WIN:
e65b5245 475 element->which_element.command.line = NULL;
c906108c
SS
476 break;
477 case DATA_ITEM_WIN:
e65b5245 478 element->which_element.data.name = NULL;
6d012f14
AC
479 element->which_element.data.type = TUI_REGISTER;
480 element->which_element.data.item_no = UNDEFINED_ITEM;
481 element->which_element.data.value = NULL;
482 element->which_element.data.highlight = FALSE;
e65b5245 483 element->which_element.data.content = NULL;
c906108c
SS
484 break;
485 case LOCATOR_WIN:
56d397a3 486 element->which_element.locator.full_name[0] =
6d012f14
AC
487 element->which_element.locator.proc_name[0] = (char) 0;
488 element->which_element.locator.line_no = 0;
489 element->which_element.locator.addr = 0;
c906108c
SS
490 break;
491 case EXEC_INFO_WIN:
6d012f14
AC
492 memset(element->which_element.simple_string, ' ',
493 sizeof(element->which_element.simple_string));
c906108c
SS
494 break;
495 default:
496 break;
497 }
6ba8e26f 498}
c906108c 499
33b906ab 500tui_win_info::tui_win_info (enum tui_win_type type)
c906108c 501{
33b906ab
TT
502 generic.type = type;
503 tui_init_generic_part (&generic);
6ba8e26f 504}
c906108c 505
33b906ab
TT
506tui_source_window::tui_source_window (enum tui_win_type type)
507 : tui_win_info (type)
508{
509 gdb_assert (type == SRC_WIN || type == DISASSEM_WIN);
510 detail.source_info.execution_info = NULL;
511 detail.source_info.has_locator = FALSE;
512 detail.source_info.horizontal_offset = 0;
513 detail.source_info.gdbarch = NULL;
514 detail.source_info.start_line_or_addr.loa = LOA_ADDRESS;
515 detail.source_info.start_line_or_addr.u.addr = 0;
516 detail.source_info.fullname = NULL;
517}
518
519tui_data_window::tui_data_window ()
520 : tui_win_info (DATA_WIN)
521{
522 detail.data_display_info.data_content = (tui_win_content) NULL;
523 detail.data_display_info.data_content_count = 0;
524 detail.data_display_info.regs_content = (tui_win_content) NULL;
525 detail.data_display_info.regs_content_count = 0;
526 detail.data_display_info.regs_column_count = 1;
527 detail.data_display_info.display_regs = FALSE;
528 detail.data_display_info.current_group = 0;
529}
530
531tui_cmd_window::tui_cmd_window ()
532 : tui_win_info (CMD_WIN)
533{
534}
c906108c 535
2a8854a7 536struct tui_win_info *
22940a24 537tui_alloc_win_info (enum tui_win_type type)
c906108c 538{
33b906ab
TT
539 switch (type)
540 {
541 case SRC_WIN:
542 case DISASSEM_WIN:
543 return new tui_source_window (type);
c906108c 544
33b906ab
TT
545 case DATA_WIN:
546 return new tui_data_window ();
c906108c 547
33b906ab
TT
548 case CMD_WIN:
549 return new tui_cmd_window ();
550 }
551
552 gdb_assert_not_reached (_("Unhandled window type"));
6ba8e26f 553}
c906108c
SS
554
555
6ba8e26f 556/* Allocates the content and elements in a block. */
2a8854a7 557tui_win_content
6ba8e26f 558tui_alloc_content (int num_elements, enum tui_win_type type)
c906108c 559{
c0645fb5 560 tui_win_content content;
7acd011b 561 struct tui_win_element *element_block_ptr;
c906108c
SS
562 int i;
563
8d749320 564 content = XNEWVEC (struct tui_win_element *, num_elements);
7acd011b
SM
565
566 /*
567 * All windows, except the data window, can allocate the
568 * elements in a chunk. The data window cannot because items
569 * can be added/removed from the data display by the user at any
570 * time.
571 */
572 if (type != DATA_WIN)
c0645fb5 573 {
7acd011b
SM
574 element_block_ptr = XNEWVEC (struct tui_win_element, num_elements);
575 for (i = 0; i < num_elements; i++)
c906108c 576 {
7acd011b
SM
577 content[i] = element_block_ptr;
578 init_content_element (content[i], type);
579 element_block_ptr++;
c906108c
SS
580 }
581 }
582
583 return content;
6ba8e26f 584}
c906108c
SS
585
586
dd1abb8c 587/* Adds the input number of elements to the windows's content. If no
6ba8e26f 588 content has been allocated yet, alloc_content() is called to do
dd1abb8c
AC
589 this. The index of the first element added is returned, unless
590 there is a memory allocation error, in which case, (-1) is
591 returned. */
c906108c 592int
08ef48c5
MS
593tui_add_content_elements (struct tui_gen_win_info *win_info,
594 int num_elements)
c906108c 595{
5b6fe301 596 struct tui_win_element *element_ptr;
6ba8e26f 597 int i, index_start;
c906108c 598
6d012f14 599 if (win_info->content == NULL)
c906108c 600 {
63ed8182 601 win_info->content = tui_alloc_content (num_elements, win_info->type);
6ba8e26f 602 index_start = 0;
c906108c
SS
603 }
604 else
6ba8e26f 605 index_start = win_info->content_size;
6d012f14 606 if (win_info->content != NULL)
c906108c 607 {
6ba8e26f 608 for (i = index_start; (i < num_elements + index_start); i++)
c906108c 609 {
8d749320 610 element_ptr = XNEW (struct tui_win_element);
730ead81
TT
611 win_info->content[i] = element_ptr;
612 init_content_element (element_ptr, win_info->type);
613 win_info->content_size++;
c906108c
SS
614 }
615 }
616
6ba8e26f
AC
617 return index_start;
618}
c906108c 619
ee1d42d6 620tui_source_window::~tui_source_window ()
c906108c 621{
ee1d42d6
TT
622 if (detail.source_info.fullname)
623 {
624 xfree (detail.source_info.fullname);
625 detail.source_info.fullname = NULL;
626 }
627 struct tui_gen_win_info *generic_win = detail.source_info.execution_info;
628 if (generic_win != NULL)
629 {
630 tui_delete_win (generic_win->handle);
631 generic_win->handle = NULL;
632 tui_free_win_content (generic_win);
633 }
634}
c906108c 635
ee1d42d6
TT
636tui_data_window::~tui_data_window ()
637{
638 if (generic.content != NULL)
c906108c 639 {
ee1d42d6
TT
640 tui_free_data_content (detail.data_display_info.regs_content,
641 detail.data_display_info.regs_content_count);
642 detail.data_display_info.regs_content = NULL;
643 detail.data_display_info.regs_content_count = 0;
644 tui_free_data_content (detail.data_display_info.data_content,
645 detail.data_display_info.data_content_count);
646 detail.data_display_info.data_content = NULL;
647 detail.data_display_info.data_content_count = 0;
648 detail.data_display_info.regs_column_count = 1;
649 detail.data_display_info.display_regs = FALSE;
650 generic.content = NULL;
651 generic.content_size = 0;
c906108c 652 }
ee1d42d6
TT
653}
654
655tui_win_info::~tui_win_info ()
656{
e7e11af4 657 if (generic.handle != NULL)
c906108c 658 {
e7e11af4
TT
659 tui_delete_win (generic.handle);
660 generic.handle = NULL;
661 tui_free_win_content (&generic);
c906108c 662 }
e7e11af4
TT
663 if (generic.title)
664 xfree (generic.title);
bc6b7f04 665}
c906108c
SS
666
667
c906108c 668void
b4eb2452 669tui_free_all_source_wins_content ()
c906108c 670{
b4eb2452 671 for (tui_win_info *win_info : tui_source_windows ())
c906108c 672 {
b4eb2452
TT
673 tui_free_win_content (&(win_info->generic));
674 tui_free_win_content (win_info->detail.source_info.execution_info);
c906108c 675 }
dd1abb8c 676}
c906108c
SS
677
678
c906108c 679void
5b6fe301 680tui_free_win_content (struct tui_gen_win_info *win_info)
c906108c 681{
6d012f14 682 if (win_info->content != NULL)
c906108c 683 {
63a33118 684 free_content (win_info->content,
6d012f14
AC
685 win_info->content_size,
686 win_info->type);
687 win_info->content = NULL;
c906108c 688 }
6d012f14 689 win_info->content_size = 0;
6ba8e26f 690}
c906108c
SS
691
692
c906108c 693void
08ef48c5
MS
694tui_free_data_content (tui_win_content content,
695 int content_size)
c906108c
SS
696{
697 int i;
698
ef5eab5a
MS
699 /* Remember that data window content elements are of type struct
700 tui_gen_win_info *, each of which whose single element is a data
701 element. */
6ba8e26f 702 for (i = 0; i < content_size; i++)
c906108c 703 {
9a2b4c1b
MS
704 struct tui_gen_win_info *generic_win
705 = &content[i]->which_element.data_window;
c906108c 706
cafb3438 707 if (generic_win != NULL)
c906108c 708 {
6ba8e26f 709 tui_delete_win (generic_win->handle);
e65b5245 710 generic_win->handle = NULL;
6ba8e26f 711 tui_free_win_content (generic_win);
c906108c
SS
712 }
713 }
6ba8e26f 714 free_content (content,
08ef48c5
MS
715 content_size,
716 DATA_WIN);
6ba8e26f 717}
c906108c
SS
718
719
720/**********************************
721** LOCAL STATIC FUNCTIONS **
722**********************************/
723
724
c906108c 725static void
08ef48c5
MS
726free_content (tui_win_content content,
727 int content_size,
728 enum tui_win_type win_type)
c906108c 729{
d04b44a1 730 if (content != NULL)
c906108c 731 {
6ba8e26f 732 free_content_elements (content, content_size, win_type);
22940a24 733 xfree (content);
c906108c 734 }
6ba8e26f 735}
c906108c
SS
736
737
ef5eab5a 738/* free_content_elements().
c5aa993b 739 */
c906108c 740static void
08ef48c5
MS
741free_content_elements (tui_win_content content,
742 int content_size,
743 enum tui_win_type type)
c906108c 744{
d04b44a1 745 if (content != NULL)
c906108c
SS
746 {
747 int i;
748
62f29fda 749 if (type == DISASSEM_WIN)
c906108c 750 {
1cc6d956 751 /* Free whole source block. */
6d012f14 752 xfree (content[0]->which_element.source.line);
c906108c
SS
753 }
754 else
755 {
6ba8e26f 756 for (i = 0; i < content_size; i++)
c906108c 757 {
5b6fe301 758 struct tui_win_element *element;
c906108c
SS
759
760 element = content[i];
cafb3438 761 if (element != NULL)
c906108c
SS
762 {
763 switch (type)
764 {
62f29fda
TT
765 case SRC_WIN:
766 xfree (element->which_element.source.line);
767 break;
c906108c 768 case DATA_WIN:
22940a24 769 xfree (element);
c906108c
SS
770 break;
771 case DATA_ITEM_WIN:
ef5eab5a
MS
772 /* Note that data elements are not allocated in
773 a single block, but individually, as
774 needed. */
6d012f14
AC
775 if (element->which_element.data.type != TUI_REGISTER)
776 xfree ((void *)element->which_element.data.name);
777 xfree (element->which_element.data.value);
10f59415 778 xfree (element->which_element.data.content);
22940a24 779 xfree (element);
c906108c
SS
780 break;
781 case CMD_WIN:
6d012f14 782 xfree (element->which_element.command.line);
c906108c
SS
783 break;
784 default:
785 break;
786 }
787 }
788 }
789 }
790 if (type != DATA_WIN && type != DATA_ITEM_WIN)
1cc6d956 791 xfree (content[0]); /* Free the element block. */
c906108c 792 }
6ba8e26f 793}
This page took 2.404657 seconds and 4 git commands to generate.