1 /* TUI data manipulation routines.
3 Copyright 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation,
6 Contributed by Hewlett-Packard Company.
8 This file is part of GDB.
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.
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.
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. */
28 #include "tui/tui-data.h"
29 #include "tui/tui-wingeneral.h"
39 /****************************
40 ** GLOBAL DECLARATIONS
41 ****************************/
42 TuiWinInfoPtr winList
[MAX_MAJOR_WINDOWS
];
44 /***************************
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 */
59 TUI_UNDEFINED_REGS
, /* regsDisplayType */
60 TUI_SFLOAT_REGS
}; /* floatRegsDisplayType */
61 static int _winResized
= FALSE
;
64 /*********************************
65 ** Static function forward decls
66 **********************************/
67 static void freeContent (TuiWinContent
, int, TuiWinType
);
68 static void freeContentElements (TuiWinContent
, int, TuiWinType
);
72 /*********************************
74 **********************************/
76 /******************************************
77 ** ACCESSORS & MUTATORS FOR PRIVATE DATA
78 ******************************************/
82 ** Answer a whether the terminal window has been resized or not
92 ** tuiSetWinResized().
93 ** Set a whether the terminal window has been resized or not
96 tuiSetWinResizedTo (int resized
)
98 _winResized
= resized
;
101 } /* tuiSetWinResizedTo */
106 ** Answer a pointer to the current layout definition
116 ** tuiWinWithFocus().
117 ** Answer the window with the logical focus
120 tuiWinWithFocus (void)
122 return _winWithFocus
;
123 } /* tuiWinWithFocus */
127 ** tuiSetWinWithFocus().
128 ** Set the window that has the logical focus
131 tuiSetWinWithFocus (TuiWinInfoPtr winInfo
)
133 _winWithFocus
= winInfo
;
136 } /* tuiSetWinWithFocus */
140 ** tuiDefaultTabLen().
141 ** Answer the length in chars, of tabs
144 tuiDefaultTabLen (void)
146 return _defaultTabLen
;
147 } /* tuiDefaultTabLen */
151 ** tuiSetDefaultTabLen().
152 ** Set the length in chars, of tabs
155 tuiSetDefaultTabLen (int len
)
157 _defaultTabLen
= len
;
160 } /* tuiSetDefaultTabLen */
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.
172 return &_sourceWindows
;
173 } /* currentSourceWindows */
177 ** clearSourceWindows()
178 ** Clear the list of source windows. Usually there is only one
179 ** source window (either source or disassembly), but both can be
180 ** displayed at the same time.
183 clearSourceWindows (void)
185 _sourceWindows
.list
[0] = (Opaque
) NULL
;
186 _sourceWindows
.list
[1] = (Opaque
) NULL
;
187 _sourceWindows
.count
= 0;
190 } /* currentSourceWindows */
194 ** clearSourceWindowsDetail()
195 ** Clear the pertinant detail in the source windows.
198 clearSourceWindowsDetail (void)
202 for (i
= 0; i
< (sourceWindows ())->count
; i
++)
203 clearWinDetail ((TuiWinInfoPtr
) (sourceWindows ())->list
[i
]);
206 } /* currentSourceWindows */
210 ** addSourceWindowToList().
211 ** Add a window to the list of source windows. Usually there is
212 ** only one source window (either source or disassembly), but
213 ** both can be displayed at the same time.
216 addToSourceWindows (TuiWinInfoPtr winInfo
)
218 if (_sourceWindows
.count
< 2)
219 _sourceWindows
.list
[_sourceWindows
.count
++] = (Opaque
) winInfo
;
222 } /* addToSourceWindows */
227 ** Clear the pertinant detail in the windows.
230 clearWinDetail (TuiWinInfoPtr winInfo
)
232 if (m_winPtrNotNull (winInfo
))
234 switch (winInfo
->generic
.type
)
238 winInfo
->detail
.sourceInfo
.startLineOrAddr
.addr
= 0;
239 winInfo
->detail
.sourceInfo
.horizontalOffset
= 0;
242 winInfo
->detail
.commandInfo
.curLine
=
243 winInfo
->detail
.commandInfo
.curch
= 0;
246 winInfo
->detail
.dataDisplayInfo
.dataContent
=
247 (TuiWinContent
) NULL
;
248 winInfo
->detail
.dataDisplayInfo
.dataContentCount
= 0;
249 winInfo
->detail
.dataDisplayInfo
.regsContent
=
250 (TuiWinContent
) NULL
;
251 winInfo
->detail
.dataDisplayInfo
.regsContentCount
= 0;
252 winInfo
->detail
.dataDisplayInfo
.regsDisplayType
=
254 winInfo
->detail
.dataDisplayInfo
.regsColumnCount
= 1;
255 winInfo
->detail
.dataDisplayInfo
.displayRegs
= FALSE
;
263 } /* clearWinDetail */
267 ** sourceExecInfoPtr().
268 ** Accessor for the source execution info ptr.
271 sourceExecInfoWinPtr (void)
273 return &_execInfo
[0];
274 } /* sourceExecInfoWinPtr */
278 ** disassemExecInfoPtr().
279 ** Accessor for the disassem execution info ptr.
282 disassemExecInfoWinPtr (void)
284 return &_execInfo
[1];
285 } /* disassemExecInfoWinPtr */
289 ** locatorWinInfoPtr().
290 ** Accessor for the locator win info. Answers a pointer to the
291 ** static locator win info struct.
294 locatorWinInfoPtr (void)
297 } /* locatorWinInfoPtr */
302 ** Accessor for the termHeight
312 ** setTermHeightTo().
313 ** Mutator for the term height
316 setTermHeightTo (int h
)
321 } /* setTermHeightTo */
326 ** Accessor for the termWidth
337 ** Mutator for the termWidth
340 setTermWidthTo (int w
)
345 } /* setTermWidthTo */
350 ** Accessor for the current layout
355 return _currentLayout
;
356 } /* currentLayout */
360 ** setCurrentLayoutTo().
361 ** Mutator for the current layout
364 setCurrentLayoutTo (TuiLayoutType newLayout
)
366 _currentLayout
= newLayout
;
369 } /* setCurrentLayoutTo */
373 ** setGenWinOrigin().
374 ** Set the origin of the window
377 setGenWinOrigin (TuiGenWinInfoPtr winInfo
, int x
, int y
)
379 winInfo
->origin
.x
= x
;
380 winInfo
->origin
.y
= y
;
383 } /* setGenWinOrigin */
386 /*****************************
387 ** OTHER PUBLIC FUNCTIONS
388 *****************************/
393 ** Answer the next window in the list, cycling back to the top
397 tuiNextWin (TuiWinInfoPtr curWin
)
399 TuiWinType type
= curWin
->generic
.type
;
400 TuiWinInfoPtr nextWin
= (TuiWinInfoPtr
) NULL
;
402 if (curWin
->generic
.type
== CMD_WIN
)
405 type
= curWin
->generic
.type
+ 1;
406 while (type
!= curWin
->generic
.type
&& m_winPtrIsNull (nextWin
))
408 if (winList
[type
] && winList
[type
]->generic
.isVisible
)
409 nextWin
= winList
[type
];
425 ** Answer the prev window in the list, cycling back to the bottom
429 tuiPrevWin (TuiWinInfoPtr curWin
)
431 TuiWinType type
= curWin
->generic
.type
;
432 TuiWinInfoPtr prev
= (TuiWinInfoPtr
) NULL
;
434 if (curWin
->generic
.type
== SRC_WIN
)
437 type
= curWin
->generic
.type
- 1;
438 while (type
!= curWin
->generic
.type
&& m_winPtrIsNull (prev
))
440 if (winList
[type
]->generic
.isVisible
)
441 prev
= winList
[type
];
456 ** partialWinByName().
457 ** Answer the window represented by name
460 partialWinByName (char *name
)
462 TuiWinInfoPtr winInfo
= (TuiWinInfoPtr
) NULL
;
464 if (name
!= (char *) NULL
)
468 while (i
< MAX_MAJOR_WINDOWS
&& m_winPtrIsNull (winInfo
))
472 char *curName
= winName (&winList
[i
]->generic
);
473 if (strlen (name
) <= strlen (curName
) &&
474 strncmp (name
, curName
, strlen (name
)) == 0)
475 winInfo
= winList
[i
];
482 } /* partialWinByName */
487 ** Answer the name of the window
490 winName (TuiGenWinInfoPtr winInfo
)
492 char *name
= (char *) NULL
;
494 switch (winInfo
->type
)
503 name
= DISASSEM_NAME
;
518 ** initializeStaticData
521 initializeStaticData (void)
523 initGenericPart (sourceExecInfoWinPtr ());
524 initGenericPart (disassemExecInfoWinPtr ());
525 initGenericPart (locatorWinInfoPtr ());
528 } /* initializeStaticData */
532 ** allocGenericWinInfo().
535 allocGenericWinInfo (void)
537 TuiGenWinInfoPtr win
;
539 if ((win
= (TuiGenWinInfoPtr
) xmalloc (
540 sizeof (TuiGenWinInfoPtr
))) != (TuiGenWinInfoPtr
) NULL
)
541 initGenericPart (win
);
544 } /* allocGenericWinInfo */
548 ** initGenericPart().
551 initGenericPart (TuiGenWinInfoPtr win
)
557 win
->viewportHeight
=
559 win
->lastVisibleLine
= 0;
560 win
->handle
= (WINDOW
*) NULL
;
561 win
->content
= (OpaquePtr
) NULL
;
563 win
->isVisible
= FALSE
;
569 ** initContentElement().
572 initContentElement (TuiWinElementPtr element
, TuiWinType type
)
574 element
->highlight
= FALSE
;
579 element
->whichElement
.source
.line
= (char *) NULL
;
580 element
->whichElement
.source
.lineOrAddr
.lineNo
= 0;
581 element
->whichElement
.source
.isExecPoint
= FALSE
;
582 element
->whichElement
.source
.hasBreak
= FALSE
;
585 initGenericPart (&element
->whichElement
.dataWindow
);
586 element
->whichElement
.dataWindow
.type
= DATA_ITEM_WIN
;
587 ((TuiGenWinInfoPtr
) & element
->whichElement
.dataWindow
)->content
=
588 (OpaquePtr
) allocContent (1, DATA_ITEM_WIN
);
590 & element
->whichElement
.dataWindow
)->contentSize
= 1;
593 element
->whichElement
.command
.line
= (char *) NULL
;
596 element
->whichElement
.data
.name
= (char *) NULL
;
597 element
->whichElement
.data
.type
= TUI_REGISTER
;
598 element
->whichElement
.data
.itemNo
= UNDEFINED_ITEM
;
599 element
->whichElement
.data
.value
= (Opaque
) NULL
;
600 element
->whichElement
.data
.highlight
= FALSE
;
603 element
->whichElement
.locator
.fileName
[0] =
604 element
->whichElement
.locator
.procName
[0] = (char) 0;
605 element
->whichElement
.locator
.lineNo
= 0;
606 element
->whichElement
.locator
.addr
= 0;
609 memset(element
->whichElement
.simpleString
, ' ',
610 sizeof(element
->whichElement
.simpleString
));
616 } /* initContentElement */
622 initWinInfo (TuiWinInfoPtr winInfo
)
624 initGenericPart (&winInfo
->generic
);
625 winInfo
->canHighlight
=
626 winInfo
->isHighlighted
= FALSE
;
627 switch (winInfo
->generic
.type
)
631 winInfo
->detail
.sourceInfo
.executionInfo
= (TuiGenWinInfoPtr
) NULL
;
632 winInfo
->detail
.sourceInfo
.hasLocator
= FALSE
;
633 winInfo
->detail
.sourceInfo
.horizontalOffset
= 0;
634 winInfo
->detail
.sourceInfo
.startLineOrAddr
.addr
= 0;
635 winInfo
->detail
.sourceInfo
.filename
= 0;
638 winInfo
->detail
.dataDisplayInfo
.dataContent
= (TuiWinContent
) NULL
;
639 winInfo
->detail
.dataDisplayInfo
.dataContentCount
= 0;
640 winInfo
->detail
.dataDisplayInfo
.regsContent
= (TuiWinContent
) NULL
;
641 winInfo
->detail
.dataDisplayInfo
.regsContentCount
= 0;
642 winInfo
->detail
.dataDisplayInfo
.regsDisplayType
=
644 winInfo
->detail
.dataDisplayInfo
.regsColumnCount
= 1;
645 winInfo
->detail
.dataDisplayInfo
.displayRegs
= FALSE
;
648 winInfo
->detail
.commandInfo
.curLine
= 0;
649 winInfo
->detail
.commandInfo
.curch
= 0;
652 winInfo
->detail
.opaque
= (Opaque
) NULL
;
664 allocWinInfo (TuiWinType type
)
666 TuiWinInfoPtr winInfo
= (TuiWinInfoPtr
) NULL
;
668 winInfo
= (TuiWinInfoPtr
) xmalloc (sizeof (TuiWinInfo
));
669 if (m_winPtrNotNull (winInfo
))
671 winInfo
->generic
.type
= type
;
672 initWinInfo (winInfo
);
681 ** Allocates the content and elements in a block.
684 allocContent (int numElements
, TuiWinType type
)
686 TuiWinContent content
= (TuiWinContent
) NULL
;
687 char *elementBlockPtr
= (char *) NULL
;
690 if ((content
= (TuiWinContent
)
691 xmalloc (sizeof (TuiWinElementPtr
) * numElements
)) != (TuiWinContent
) NULL
)
693 ** All windows, except the data window, can allocate the elements
694 ** in a chunk. The data window cannot because items can be
695 ** added/removed from the data display by the user at any time.
697 if (type
!= DATA_WIN
)
699 if ((elementBlockPtr
= (char *)
700 xmalloc (sizeof (TuiWinElement
) * numElements
)) != (char *) NULL
)
702 for (i
= 0; i
< numElements
; i
++)
704 content
[i
] = (TuiWinElementPtr
) elementBlockPtr
;
705 initContentElement (content
[i
], type
);
706 elementBlockPtr
+= sizeof (TuiWinElement
);
711 tuiFree ((char *) content
);
712 content
= (TuiWinContent
) NULL
;
722 ** addContentElements().
723 ** Adds the input number of elements to the windows's content. If
724 ** no content has been allocated yet, allocContent() is called to
725 ** do this. The index of the first element added is returned,
726 ** unless there is a memory allocation error, in which case, (-1)
730 addContentElements (TuiGenWinInfoPtr winInfo
, int numElements
)
732 TuiWinElementPtr elementPtr
;
735 if (winInfo
->content
== (OpaquePtr
) NULL
)
737 winInfo
->content
= (OpaquePtr
) allocContent (numElements
, winInfo
->type
);
741 indexStart
= winInfo
->contentSize
;
742 if (winInfo
->content
!= (OpaquePtr
) NULL
)
744 for (i
= indexStart
; (i
< numElements
+ indexStart
); i
++)
746 if ((elementPtr
= (TuiWinElementPtr
)
747 xmalloc (sizeof (TuiWinElement
))) != (TuiWinElementPtr
) NULL
)
749 winInfo
->content
[i
] = (Opaque
) elementPtr
;
750 initContentElement (elementPtr
, winInfo
->type
);
751 winInfo
->contentSize
++;
753 else /* things must be really hosed now! We ran out of memory!? */
759 } /* addContentElements */
762 /* Delete all curses windows associated with winInfo, leaving everything
765 tuiDelWindow (TuiWinInfoPtr winInfo
)
767 TuiGenWinInfoPtr genericWin
;
769 switch (winInfo
->generic
.type
)
773 genericWin
= locatorWinInfoPtr ();
774 if (genericWin
!= (TuiGenWinInfoPtr
) NULL
)
776 tuiDelwin (genericWin
->handle
);
777 genericWin
->handle
= (WINDOW
*) NULL
;
778 genericWin
->isVisible
= FALSE
;
780 if (winInfo
->detail
.sourceInfo
.filename
)
782 xfree (winInfo
->detail
.sourceInfo
.filename
);
783 winInfo
->detail
.sourceInfo
.filename
= 0;
785 genericWin
= winInfo
->detail
.sourceInfo
.executionInfo
;
786 if (genericWin
!= (TuiGenWinInfoPtr
) NULL
)
788 tuiDelwin (genericWin
->handle
);
789 genericWin
->handle
= (WINDOW
*) NULL
;
790 genericWin
->isVisible
= FALSE
;
794 if (winInfo
->generic
.content
!= (OpaquePtr
) NULL
)
796 tuiDelDataWindows (winInfo
->detail
.dataDisplayInfo
.regsContent
,
797 winInfo
->detail
.dataDisplayInfo
.regsContentCount
);
798 tuiDelDataWindows (winInfo
->detail
.dataDisplayInfo
.dataContent
,
799 winInfo
->detail
.dataDisplayInfo
.dataContentCount
);
805 if (winInfo
->generic
.handle
!= (WINDOW
*) NULL
)
807 tuiDelwin (winInfo
->generic
.handle
);
808 winInfo
->generic
.handle
= (WINDOW
*) NULL
;
809 winInfo
->generic
.isVisible
= FALSE
;
818 freeWindow (TuiWinInfoPtr winInfo
)
820 TuiGenWinInfoPtr genericWin
;
822 switch (winInfo
->generic
.type
)
826 genericWin
= locatorWinInfoPtr ();
827 if (genericWin
!= (TuiGenWinInfoPtr
) NULL
)
829 tuiDelwin (genericWin
->handle
);
830 genericWin
->handle
= (WINDOW
*) NULL
;
832 freeWinContent (genericWin
);
833 if (winInfo
->detail
.sourceInfo
.filename
)
835 xfree (winInfo
->detail
.sourceInfo
.filename
);
836 winInfo
->detail
.sourceInfo
.filename
= 0;
838 genericWin
= winInfo
->detail
.sourceInfo
.executionInfo
;
839 if (genericWin
!= (TuiGenWinInfoPtr
) NULL
)
841 tuiDelwin (genericWin
->handle
);
842 genericWin
->handle
= (WINDOW
*) NULL
;
843 freeWinContent (genericWin
);
847 if (winInfo
->generic
.content
!= (OpaquePtr
) NULL
)
850 winInfo
->detail
.dataDisplayInfo
.regsContent
,
851 winInfo
->detail
.dataDisplayInfo
.regsContentCount
);
852 winInfo
->detail
.dataDisplayInfo
.regsContent
=
853 (TuiWinContent
) NULL
;
854 winInfo
->detail
.dataDisplayInfo
.regsContentCount
= 0;
856 winInfo
->detail
.dataDisplayInfo
.dataContent
,
857 winInfo
->detail
.dataDisplayInfo
.dataContentCount
);
858 winInfo
->detail
.dataDisplayInfo
.dataContent
=
859 (TuiWinContent
) NULL
;
860 winInfo
->detail
.dataDisplayInfo
.dataContentCount
= 0;
861 winInfo
->detail
.dataDisplayInfo
.regsDisplayType
=
863 winInfo
->detail
.dataDisplayInfo
.regsColumnCount
= 1;
864 winInfo
->detail
.dataDisplayInfo
.displayRegs
= FALSE
;
865 winInfo
->generic
.content
= (OpaquePtr
) NULL
;
866 winInfo
->generic
.contentSize
= 0;
872 if (winInfo
->generic
.handle
!= (WINDOW
*) NULL
)
874 tuiDelwin (winInfo
->generic
.handle
);
875 winInfo
->generic
.handle
= (WINDOW
*) NULL
;
876 freeWinContent (&winInfo
->generic
);
878 if (winInfo
->generic
.title
)
879 xfree (winInfo
->generic
.title
);
885 ** freeAllSourceWinsContent().
888 freeAllSourceWinsContent (void)
892 for (i
= 0; i
< (sourceWindows ())->count
; i
++)
894 TuiWinInfoPtr winInfo
= (TuiWinInfoPtr
) (sourceWindows ())->list
[i
];
896 if (m_winPtrNotNull (winInfo
))
898 freeWinContent (&(winInfo
->generic
));
899 freeWinContent (winInfo
->detail
.sourceInfo
.executionInfo
);
904 } /* freeAllSourceWinsContent */
911 freeWinContent (TuiGenWinInfoPtr winInfo
)
913 if (winInfo
->content
!= (OpaquePtr
) NULL
)
915 freeContent ((TuiWinContent
) winInfo
->content
,
916 winInfo
->contentSize
,
918 winInfo
->content
= (OpaquePtr
) NULL
;
920 winInfo
->contentSize
= 0;
923 } /* freeWinContent */
927 tuiDelDataWindows (TuiWinContent content
, int contentSize
)
932 ** Remember that data window content elements are of type TuiGenWinInfoPtr,
933 ** each of which whose single element is a data element.
935 for (i
= 0; i
< contentSize
; i
++)
937 TuiGenWinInfoPtr genericWin
= &content
[i
]->whichElement
.dataWindow
;
939 if (genericWin
!= (TuiGenWinInfoPtr
) NULL
)
941 tuiDelwin (genericWin
->handle
);
942 genericWin
->handle
= (WINDOW
*) NULL
;
943 genericWin
->isVisible
= FALSE
;
948 } /* tuiDelDataWindows */
952 freeDataContent (TuiWinContent content
, int contentSize
)
957 ** Remember that data window content elements are of type TuiGenWinInfoPtr,
958 ** each of which whose single element is a data element.
960 for (i
= 0; i
< contentSize
; i
++)
962 TuiGenWinInfoPtr genericWin
= &content
[i
]->whichElement
.dataWindow
;
964 if (genericWin
!= (TuiGenWinInfoPtr
) NULL
)
966 tuiDelwin (genericWin
->handle
);
967 genericWin
->handle
= (WINDOW
*) NULL
;
968 freeWinContent (genericWin
);
971 freeContent (content
,
976 } /* freeDataContent */
979 /**********************************
980 ** LOCAL STATIC FUNCTIONS **
981 **********************************/
988 freeContent (TuiWinContent content
, int contentSize
, TuiWinType winType
)
990 if (content
!= (TuiWinContent
) NULL
)
992 freeContentElements (content
, contentSize
, winType
);
993 tuiFree ((char *) content
);
1001 ** freeContentElements().
1004 freeContentElements (TuiWinContent content
, int contentSize
, TuiWinType type
)
1006 if (content
!= (TuiWinContent
) NULL
)
1010 if (type
== SRC_WIN
|| type
== DISASSEM_WIN
)
1012 /* free whole source block */
1013 if (content
[0]->whichElement
.source
.line
!= (char *) NULL
)
1014 tuiFree (content
[0]->whichElement
.source
.line
);
1018 for (i
= 0; i
< contentSize
; i
++)
1020 TuiWinElementPtr element
;
1022 element
= content
[i
];
1023 if (element
!= (TuiWinElementPtr
) NULL
)
1028 tuiFree ((char *) element
);
1032 ** Note that data elements are not allocated
1033 ** in a single block, but individually, as needed.
1035 if (element
->whichElement
.data
.type
!= TUI_REGISTER
)
1037 element
->whichElement
.data
.name
);
1038 tuiFree ((char *) element
->whichElement
.data
.value
);
1039 tuiFree ((char *) element
);
1042 tuiFree ((char *) element
->whichElement
.command
.line
);
1050 if (type
!= DATA_WIN
&& type
!= DATA_ITEM_WIN
)
1051 tuiFree ((char *) content
[0]); /* free the element block */
1055 } /* freeContentElements */