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