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