Fix PR gdb/18155
[deliverable/binutils-gdb.git] / gdb / tui / tui-data.c
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 int 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 int 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 && startswith (cur_name, name))
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 element->which_element.data_window.content =
494 tui_alloc_content (1, DATA_ITEM_WIN);
495 element->which_element.data_window.content_size = 1;
496 break;
497 case CMD_WIN:
498 element->which_element.command.line = (char *) NULL;
499 break;
500 case DATA_ITEM_WIN:
501 element->which_element.data.name = (char *) NULL;
502 element->which_element.data.type = TUI_REGISTER;
503 element->which_element.data.item_no = UNDEFINED_ITEM;
504 element->which_element.data.value = NULL;
505 element->which_element.data.highlight = FALSE;
506 element->which_element.data.content = (char*) NULL;
507 break;
508 case LOCATOR_WIN:
509 element->which_element.locator.full_name[0] =
510 element->which_element.locator.proc_name[0] = (char) 0;
511 element->which_element.locator.line_no = 0;
512 element->which_element.locator.addr = 0;
513 break;
514 case EXEC_INFO_WIN:
515 memset(element->which_element.simple_string, ' ',
516 sizeof(element->which_element.simple_string));
517 break;
518 default:
519 break;
520 }
521 }
522
523 static void
524 init_win_info (struct tui_win_info *win_info)
525 {
526 tui_init_generic_part (&win_info->generic);
527 win_info->can_highlight =
528 win_info->is_highlighted = FALSE;
529 switch (win_info->generic.type)
530 {
531 case SRC_WIN:
532 case DISASSEM_WIN:
533 win_info->detail.source_info.execution_info
534 = (struct tui_gen_win_info *) NULL;
535 win_info->detail.source_info.has_locator = FALSE;
536 win_info->detail.source_info.horizontal_offset = 0;
537 win_info->detail.source_info.gdbarch = NULL;
538 win_info->detail.source_info.start_line_or_addr.loa = LOA_ADDRESS;
539 win_info->detail.source_info.start_line_or_addr.u.addr = 0;
540 win_info->detail.source_info.fullname = NULL;
541 break;
542 case DATA_WIN:
543 win_info->detail.data_display_info.data_content = (tui_win_content) NULL;
544 win_info->detail.data_display_info.data_content_count = 0;
545 win_info->detail.data_display_info.regs_content = (tui_win_content) NULL;
546 win_info->detail.data_display_info.regs_content_count = 0;
547 win_info->detail.data_display_info.regs_display_type =
548 TUI_UNDEFINED_REGS;
549 win_info->detail.data_display_info.regs_column_count = 1;
550 win_info->detail.data_display_info.display_regs = FALSE;
551 win_info->detail.data_display_info.current_group = 0;
552 break;
553 case CMD_WIN:
554 win_info->detail.command_info.cur_line = 0;
555 win_info->detail.command_info.curch = 0;
556 break;
557 default:
558 win_info->detail.opaque = NULL;
559 break;
560 }
561 }
562
563
564 struct tui_win_info *
565 tui_alloc_win_info (enum tui_win_type type)
566 {
567 struct tui_win_info *win_info;
568
569 win_info = XNEW (struct tui_win_info);
570 if (win_info != NULL)
571 {
572 win_info->generic.type = type;
573 init_win_info (win_info);
574 }
575
576 return win_info;
577 }
578
579
580 /* Allocates the content and elements in a block. */
581 tui_win_content
582 tui_alloc_content (int num_elements, enum tui_win_type type)
583 {
584 tui_win_content content;
585 char *element_block_ptr;
586 int i;
587
588 content = xmalloc (sizeof (struct tui_win_element *) *num_elements);
589 if (content != NULL)
590 {
591 /*
592 * All windows, except the data window, can allocate the
593 * elements in a chunk. The data window cannot because items
594 * can be added/removed from the data display by the user at any
595 * time.
596 */
597 if (type != DATA_WIN)
598 {
599 element_block_ptr =
600 xmalloc (sizeof (struct tui_win_element) * num_elements);
601 if (element_block_ptr != NULL)
602 {
603 for (i = 0; i < num_elements; i++)
604 {
605 content[i] = (struct tui_win_element *) element_block_ptr;
606 init_content_element (content[i], type);
607 element_block_ptr += sizeof (struct tui_win_element);
608 }
609 }
610 else
611 {
612 xfree (content);
613 content = (tui_win_content) NULL;
614 }
615 }
616 }
617
618 return content;
619 }
620
621
622 /* Adds the input number of elements to the windows's content. If no
623 content has been allocated yet, alloc_content() is called to do
624 this. The index of the first element added is returned, unless
625 there is a memory allocation error, in which case, (-1) is
626 returned. */
627 int
628 tui_add_content_elements (struct tui_gen_win_info *win_info,
629 int num_elements)
630 {
631 struct tui_win_element *element_ptr;
632 int i, index_start;
633
634 if (win_info->content == NULL)
635 {
636 win_info->content = tui_alloc_content (num_elements, win_info->type);
637 index_start = 0;
638 }
639 else
640 index_start = win_info->content_size;
641 if (win_info->content != NULL)
642 {
643 for (i = index_start; (i < num_elements + index_start); i++)
644 {
645 if ((element_ptr = XNEW (struct tui_win_element)) != NULL)
646 {
647 win_info->content[i] = (void *) element_ptr;
648 init_content_element (element_ptr, win_info->type);
649 win_info->content_size++;
650 }
651 else /* Things must be really hosed now! We ran out of
652 memory!? */
653 return (-1);
654 }
655 }
656
657 return index_start;
658 }
659
660
661 /* Delete all curses windows associated with win_info, leaving
662 everything else intact. */
663 void
664 tui_del_window (struct tui_win_info *win_info)
665 {
666 struct tui_gen_win_info *generic_win;
667
668 switch (win_info->generic.type)
669 {
670 case SRC_WIN:
671 case DISASSEM_WIN:
672 generic_win = tui_locator_win_info_ptr ();
673 if (generic_win != (struct tui_gen_win_info *) NULL)
674 {
675 tui_delete_win (generic_win->handle);
676 generic_win->handle = (WINDOW *) NULL;
677 generic_win->is_visible = FALSE;
678 }
679 if (win_info->detail.source_info.fullname)
680 {
681 xfree (win_info->detail.source_info.fullname);
682 win_info->detail.source_info.fullname = NULL;
683 }
684 generic_win = win_info->detail.source_info.execution_info;
685 if (generic_win != (struct tui_gen_win_info *) NULL)
686 {
687 tui_delete_win (generic_win->handle);
688 generic_win->handle = (WINDOW *) NULL;
689 generic_win->is_visible = FALSE;
690 }
691 break;
692 case DATA_WIN:
693 if (win_info->generic.content != NULL)
694 {
695 tui_del_data_windows (win_info->detail.data_display_info.regs_content,
696 win_info->detail.data_display_info.regs_content_count);
697 tui_del_data_windows (win_info->detail.data_display_info.data_content,
698 win_info->detail.data_display_info.data_content_count);
699 }
700 break;
701 default:
702 break;
703 }
704 if (win_info->generic.handle != (WINDOW *) NULL)
705 {
706 tui_delete_win (win_info->generic.handle);
707 win_info->generic.handle = (WINDOW *) NULL;
708 win_info->generic.is_visible = FALSE;
709 }
710 }
711
712
713 void
714 tui_free_window (struct tui_win_info *win_info)
715 {
716 struct tui_gen_win_info *generic_win;
717
718 switch (win_info->generic.type)
719 {
720 case SRC_WIN:
721 case DISASSEM_WIN:
722 if (win_info->detail.source_info.fullname)
723 {
724 xfree (win_info->detail.source_info.fullname);
725 win_info->detail.source_info.fullname = NULL;
726 }
727 generic_win = win_info->detail.source_info.execution_info;
728 if (generic_win != (struct tui_gen_win_info *) NULL)
729 {
730 tui_delete_win (generic_win->handle);
731 generic_win->handle = (WINDOW *) NULL;
732 tui_free_win_content (generic_win);
733 }
734 break;
735 case DATA_WIN:
736 if (win_info->generic.content != NULL)
737 {
738 tui_free_data_content (win_info->detail.data_display_info.regs_content,
739 win_info->detail.data_display_info.regs_content_count);
740 win_info->detail.data_display_info.regs_content =
741 (tui_win_content) NULL;
742 win_info->detail.data_display_info.regs_content_count = 0;
743 tui_free_data_content (win_info->detail.data_display_info.data_content,
744 win_info->detail.data_display_info.data_content_count);
745 win_info->detail.data_display_info.data_content =
746 (tui_win_content) NULL;
747 win_info->detail.data_display_info.data_content_count = 0;
748 win_info->detail.data_display_info.regs_display_type =
749 TUI_UNDEFINED_REGS;
750 win_info->detail.data_display_info.regs_column_count = 1;
751 win_info->detail.data_display_info.display_regs = FALSE;
752 win_info->generic.content = NULL;
753 win_info->generic.content_size = 0;
754 }
755 break;
756 default:
757 break;
758 }
759 if (win_info->generic.handle != (WINDOW *) NULL)
760 {
761 tui_delete_win (win_info->generic.handle);
762 win_info->generic.handle = (WINDOW *) NULL;
763 tui_free_win_content (&win_info->generic);
764 }
765 if (win_info->generic.title)
766 xfree (win_info->generic.title);
767 xfree (win_info);
768 }
769
770
771 void
772 tui_free_all_source_wins_content (void)
773 {
774 int i;
775
776 for (i = 0; i < (tui_source_windows ())->count; i++)
777 {
778 struct tui_win_info *win_info = (tui_source_windows ())->list[i];
779
780 if (win_info != NULL)
781 {
782 tui_free_win_content (&(win_info->generic));
783 tui_free_win_content (win_info->detail.source_info.execution_info);
784 }
785 }
786 }
787
788
789 void
790 tui_free_win_content (struct tui_gen_win_info *win_info)
791 {
792 if (win_info->content != NULL)
793 {
794 free_content ((tui_win_content) win_info->content,
795 win_info->content_size,
796 win_info->type);
797 win_info->content = NULL;
798 }
799 win_info->content_size = 0;
800 }
801
802
803 void
804 tui_del_data_windows (tui_win_content content,
805 int content_size)
806 {
807 int i;
808
809 /* Remember that data window content elements are of type struct
810 tui_gen_win_info *, each of which whose single element is a data
811 element. */
812 for (i = 0; i < content_size; i++)
813 {
814 struct tui_gen_win_info *generic_win
815 = &content[i]->which_element.data_window;
816
817 if (generic_win != (struct tui_gen_win_info *) NULL)
818 {
819 tui_delete_win (generic_win->handle);
820 generic_win->handle = (WINDOW *) NULL;
821 generic_win->is_visible = FALSE;
822 }
823 }
824 }
825
826
827 void
828 tui_free_data_content (tui_win_content content,
829 int content_size)
830 {
831 int i;
832
833 /* Remember that data window content elements are of type struct
834 tui_gen_win_info *, each of which whose single element is a data
835 element. */
836 for (i = 0; i < content_size; i++)
837 {
838 struct tui_gen_win_info *generic_win
839 = &content[i]->which_element.data_window;
840
841 if (generic_win != (struct tui_gen_win_info *) NULL)
842 {
843 tui_delete_win (generic_win->handle);
844 generic_win->handle = (WINDOW *) NULL;
845 tui_free_win_content (generic_win);
846 }
847 }
848 free_content (content,
849 content_size,
850 DATA_WIN);
851 }
852
853
854 /**********************************
855 ** LOCAL STATIC FUNCTIONS **
856 **********************************/
857
858
859 static void
860 free_content (tui_win_content content,
861 int content_size,
862 enum tui_win_type win_type)
863 {
864 if (content != (tui_win_content) NULL)
865 {
866 free_content_elements (content, content_size, win_type);
867 xfree (content);
868 }
869 }
870
871
872 /* free_content_elements().
873 */
874 static void
875 free_content_elements (tui_win_content content,
876 int content_size,
877 enum tui_win_type type)
878 {
879 if (content != (tui_win_content) NULL)
880 {
881 int i;
882
883 if (type == SRC_WIN || type == DISASSEM_WIN)
884 {
885 /* Free whole source block. */
886 xfree (content[0]->which_element.source.line);
887 }
888 else
889 {
890 for (i = 0; i < content_size; i++)
891 {
892 struct tui_win_element *element;
893
894 element = content[i];
895 if (element != (struct tui_win_element *) NULL)
896 {
897 switch (type)
898 {
899 case DATA_WIN:
900 xfree (element);
901 break;
902 case DATA_ITEM_WIN:
903 /* Note that data elements are not allocated in
904 a single block, but individually, as
905 needed. */
906 if (element->which_element.data.type != TUI_REGISTER)
907 xfree ((void *)element->which_element.data.name);
908 xfree (element->which_element.data.value);
909 xfree (element->which_element.data.content);
910 xfree (element);
911 break;
912 case CMD_WIN:
913 xfree (element->which_element.command.line);
914 break;
915 default:
916 break;
917 }
918 }
919 }
920 }
921 if (type != DATA_WIN && type != DATA_ITEM_WIN)
922 xfree (content[0]); /* Free the element block. */
923 }
924 }
This page took 0.064198 seconds and 5 git commands to generate.