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