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