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 struct tui_win_info
*(winList
[MAX_MAJOR_WINDOWS
]);
44 /***************************
46 ****************************/
47 static enum tui_layout_type _currentLayout
= UNDEFINED_LAYOUT
;
48 static int _termHeight
, _termWidth
;
49 static struct tui_gen_win_info _locator
;
50 static struct tui_gen_win_info _execInfo
[2];
51 static struct tui_win_info
* _srcWinList
[2];
52 static struct tui_list _sourceWindows
=
53 {(OpaqueList
) _srcWinList
, 0};
54 static int _defaultTabLen
= DEFAULT_TAB_LEN
;
55 static struct tui_win_info
* _winWithFocus
= (struct tui_win_info
*) NULL
;
56 static struct tui_layout_def _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 (tui_win_content
, int, TuiWinType
);
68 static void freeContentElements (tui_win_content
, int, TuiWinType
);
72 /*********************************
74 **********************************/
76 /******************************************
77 ** ACCESSORS & MUTATORS FOR PRIVATE DATA
78 ******************************************/
80 /* Answer a whether the terminal window has been resized or not. */
82 tui_win_resized (void)
88 /* Set a whether the terminal window has been resized or not. */
90 tui_set_win_resized_to (int resized
)
92 _winResized
= resized
;
96 /* Answer a pointer to the current layout definition. */
97 struct tui_layout_def
*
104 /* Answer the window with the logical focus. */
105 struct tui_win_info
*
106 tui_win_with_focus (void)
108 return _winWithFocus
;
112 /* Set the window that has the logical focus. */
114 tui_set_win_with_focus (struct tui_win_info
* winInfo
)
116 _winWithFocus
= winInfo
;
120 /* Answer the length in chars, of tabs. */
122 tui_default_tab_len (void)
124 return _defaultTabLen
;
128 /* Set the length in chars, of tabs. */
130 tui_set_default_tab_len (int len
)
132 _defaultTabLen
= len
;
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.
143 tui_source_windows (void)
145 return &_sourceWindows
;
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
153 tui_clear_source_windows (void)
155 _sourceWindows
.list
[0] = (Opaque
) NULL
;
156 _sourceWindows
.list
[1] = (Opaque
) NULL
;
157 _sourceWindows
.count
= 0;
161 /* Clear the pertinant detail in the source windows. */
163 tui_clear_source_windows_detail (void)
167 for (i
= 0; i
< (tui_source_windows ())->count
; i
++)
168 tui_clear_win_detail ((struct tui_win_info
*) (tui_source_windows ())->list
[i
]);
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. */
176 tui_add_to_source_windows (struct tui_win_info
* winInfo
)
178 if (_sourceWindows
.count
< 2)
179 _sourceWindows
.list
[_sourceWindows
.count
++] = (Opaque
) winInfo
;
183 /* Clear the pertinant detail in the windows. */
185 tui_clear_win_detail (struct tui_win_info
* winInfo
)
187 if (m_winPtrNotNull (winInfo
))
189 switch (winInfo
->generic
.type
)
193 winInfo
->detail
.sourceInfo
.startLineOrAddr
.addr
= 0;
194 winInfo
->detail
.sourceInfo
.horizontalOffset
= 0;
197 winInfo
->detail
.commandInfo
.curLine
=
198 winInfo
->detail
.commandInfo
.curch
= 0;
201 winInfo
->detail
.dataDisplayInfo
.dataContent
=
202 (tui_win_content
) NULL
;
203 winInfo
->detail
.dataDisplayInfo
.dataContentCount
= 0;
204 winInfo
->detail
.dataDisplayInfo
.regsContent
=
205 (tui_win_content
) NULL
;
206 winInfo
->detail
.dataDisplayInfo
.regsContentCount
= 0;
207 winInfo
->detail
.dataDisplayInfo
.regsDisplayType
=
209 winInfo
->detail
.dataDisplayInfo
.regsColumnCount
= 1;
210 winInfo
->detail
.dataDisplayInfo
.displayRegs
= FALSE
;
218 } /* clearWinDetail */
222 ** sourceExecInfoPtr().
223 ** Accessor for the source execution info ptr.
225 struct tui_gen_win_info
*
226 tui_source_exec_info_win_ptr (void)
228 return &_execInfo
[0];
229 } /* sourceExecInfoWinPtr */
233 ** disassemExecInfoPtr().
234 ** Accessor for the disassem execution info ptr.
236 struct tui_gen_win_info
*
237 tui_disassem_exec_info_win_ptr (void)
239 return &_execInfo
[1];
240 } /* disassemExecInfoWinPtr */
243 /* Accessor for the locator win info. Answers a pointer to the static
244 locator win info struct. */
245 struct tui_gen_win_info
*
246 tui_locator_win_info_ptr (void)
252 /* Accessor for the termHeight. */
254 tui_term_height (void)
260 /* Mutator for the term height. */
262 tui_set_term_height_to (int h
)
268 /* Accessor for the termWidth. */
270 tui_term_width (void)
276 /* Mutator for the termWidth. */
278 tui_set_term_width_to (int w
)
284 /* Accessor for the current layout. */
286 tui_current_layout (void)
288 return _currentLayout
;
292 /* Mutator for the current layout. */
294 tui_set_current_layout_to (enum tui_layout_type newLayout
)
296 _currentLayout
= newLayout
;
301 ** setGenWinOrigin().
302 ** Set the origin of the window
305 setGenWinOrigin (struct tui_gen_win_info
* winInfo
, int x
, int y
)
307 winInfo
->origin
.x
= x
;
308 winInfo
->origin
.y
= y
;
311 } /* setGenWinOrigin */
314 /*****************************
315 ** OTHER PUBLIC FUNCTIONS
316 *****************************/
319 /* Answer the next window in the list, cycling back to the top if
321 struct tui_win_info
*
322 tui_next_win (struct tui_win_info
* curWin
)
324 TuiWinType type
= curWin
->generic
.type
;
325 struct tui_win_info
* nextWin
= (struct tui_win_info
*) NULL
;
327 if (curWin
->generic
.type
== CMD_WIN
)
330 type
= curWin
->generic
.type
+ 1;
331 while (type
!= curWin
->generic
.type
&& m_winPtrIsNull (nextWin
))
333 if (winList
[type
] && winList
[type
]->generic
.isVisible
)
334 nextWin
= winList
[type
];
348 /* Answer the prev window in the list, cycling back to the bottom if
350 struct tui_win_info
*
351 tui_prev_win (struct tui_win_info
* curWin
)
353 TuiWinType type
= curWin
->generic
.type
;
354 struct tui_win_info
* prev
= (struct tui_win_info
*) NULL
;
356 if (curWin
->generic
.type
== SRC_WIN
)
359 type
= curWin
->generic
.type
- 1;
360 while (type
!= curWin
->generic
.type
&& m_winPtrIsNull (prev
))
362 if (winList
[type
]->generic
.isVisible
)
363 prev
= winList
[type
];
377 /* Answer the window represented by name. */
378 struct tui_win_info
*
379 tui_partial_win_by_name (char *name
)
381 struct tui_win_info
* winInfo
= (struct tui_win_info
*) NULL
;
383 if (name
!= (char *) NULL
)
387 while (i
< MAX_MAJOR_WINDOWS
&& m_winPtrIsNull (winInfo
))
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
];
401 } /* partialWinByName */
406 ** Answer the name of the window
409 tui_win_name (struct tui_gen_win_info
* winInfo
)
411 char *name
= (char *) NULL
;
413 switch (winInfo
->type
)
422 name
= DISASSEM_NAME
;
437 tui_initialize_static_data (void)
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 ());
445 struct tui_gen_win_info
*
446 tui_alloc_generic_win_info (void)
448 struct tui_gen_win_info
* win
;
450 if ((win
= (struct tui_gen_win_info
*) xmalloc (
451 sizeof (struct tui_gen_win_info
*))) != (struct tui_gen_win_info
*) NULL
)
452 tui_init_generic_part (win
);
455 } /* allocGenericWinInfo */
459 ** initGenericPart().
462 tui_init_generic_part (struct tui_gen_win_info
* win
)
468 win
->viewportHeight
=
470 win
->lastVisibleLine
= 0;
471 win
->handle
= (WINDOW
*) NULL
;
472 win
->content
= (OpaquePtr
) NULL
;
474 win
->isVisible
= FALSE
;
480 ** initContentElement().
483 initContentElement (struct tui_win_element
* element
, TuiWinType type
)
485 element
->highlight
= FALSE
;
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
;
496 tui_init_generic_part (&element
->whichElement
.dataWindow
);
497 element
->whichElement
.dataWindow
.type
= DATA_ITEM_WIN
;
498 ((struct tui_gen_win_info
*) & element
->whichElement
.dataWindow
)->content
=
499 (OpaquePtr
) tui_alloc_content (1, DATA_ITEM_WIN
);
500 ((struct tui_gen_win_info
*)
501 & element
->whichElement
.dataWindow
)->contentSize
= 1;
504 element
->whichElement
.command
.line
= (char *) NULL
;
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
;
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;
520 memset(element
->whichElement
.simpleString
, ' ',
521 sizeof(element
->whichElement
.simpleString
));
527 } /* initContentElement */
533 initWinInfo (struct tui_win_info
* winInfo
)
535 tui_init_generic_part (&winInfo
->generic
);
536 winInfo
->canHighlight
=
537 winInfo
->isHighlighted
= FALSE
;
538 switch (winInfo
->generic
.type
)
542 winInfo
->detail
.sourceInfo
.executionInfo
= (struct tui_gen_win_info
*) 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;
549 winInfo
->detail
.dataDisplayInfo
.dataContent
= (tui_win_content
) NULL
;
550 winInfo
->detail
.dataDisplayInfo
.dataContentCount
= 0;
551 winInfo
->detail
.dataDisplayInfo
.regsContent
= (tui_win_content
) NULL
;
552 winInfo
->detail
.dataDisplayInfo
.regsContentCount
= 0;
553 winInfo
->detail
.dataDisplayInfo
.regsDisplayType
=
555 winInfo
->detail
.dataDisplayInfo
.regsColumnCount
= 1;
556 winInfo
->detail
.dataDisplayInfo
.displayRegs
= FALSE
;
559 winInfo
->detail
.commandInfo
.curLine
= 0;
560 winInfo
->detail
.commandInfo
.curch
= 0;
563 winInfo
->detail
.opaque
= (Opaque
) NULL
;
571 struct tui_win_info
*
572 tui_alloc_win_info (TuiWinType type
)
574 struct tui_win_info
* winInfo
= (struct tui_win_info
*) NULL
;
576 winInfo
= (struct tui_win_info
*) xmalloc (sizeof (struct tui_win_info
));
577 if (m_winPtrNotNull (winInfo
))
579 winInfo
->generic
.type
= type
;
580 initWinInfo (winInfo
);
589 ** Allocates the content and elements in a block.
592 tui_alloc_content (int numElements
, TuiWinType type
)
594 tui_win_content content
= (tui_win_content
) NULL
;
595 char *elementBlockPtr
= (char *) NULL
;
598 if ((content
= (tui_win_content
)
599 xmalloc (sizeof (struct tui_win_element
*) * numElements
)) != (tui_win_content
) NULL
)
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.
605 if (type
!= DATA_WIN
)
607 if ((elementBlockPtr
= (char *)
608 xmalloc (sizeof (struct tui_win_element
) * numElements
)) != (char *) NULL
)
610 for (i
= 0; i
< numElements
; i
++)
612 content
[i
] = (struct tui_win_element
*) elementBlockPtr
;
613 initContentElement (content
[i
], type
);
614 elementBlockPtr
+= sizeof (struct tui_win_element
);
619 tuiFree ((char *) content
);
620 content
= (tui_win_content
) NULL
;
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
635 tui_add_content_elements (struct tui_gen_win_info
* winInfo
, int numElements
)
637 struct tui_win_element
* elementPtr
;
640 if (winInfo
->content
== (OpaquePtr
) NULL
)
642 winInfo
->content
= (OpaquePtr
) tui_alloc_content (numElements
, winInfo
->type
);
646 indexStart
= winInfo
->contentSize
;
647 if (winInfo
->content
!= (OpaquePtr
) NULL
)
649 for (i
= indexStart
; (i
< numElements
+ indexStart
); i
++)
651 if ((elementPtr
= (struct tui_win_element
*)
652 xmalloc (sizeof (struct tui_win_element
))) != (struct tui_win_element
*) NULL
)
654 winInfo
->content
[i
] = (Opaque
) elementPtr
;
655 initContentElement (elementPtr
, winInfo
->type
);
656 winInfo
->contentSize
++;
658 else /* things must be really hosed now! We ran out of memory!? */
664 } /* addContentElements */
667 /* Delete all curses windows associated with winInfo, leaving everything
670 tuiDelWindow (struct tui_win_info
* winInfo
)
672 struct tui_gen_win_info
* genericWin
;
674 switch (winInfo
->generic
.type
)
678 genericWin
= tui_locator_win_info_ptr ();
679 if (genericWin
!= (struct tui_gen_win_info
*) NULL
)
681 tui_delete_win (genericWin
->handle
);
682 genericWin
->handle
= (WINDOW
*) NULL
;
683 genericWin
->isVisible
= FALSE
;
685 if (winInfo
->detail
.sourceInfo
.filename
)
687 xfree (winInfo
->detail
.sourceInfo
.filename
);
688 winInfo
->detail
.sourceInfo
.filename
= 0;
690 genericWin
= winInfo
->detail
.sourceInfo
.executionInfo
;
691 if (genericWin
!= (struct tui_gen_win_info
*) NULL
)
693 tui_delete_win (genericWin
->handle
);
694 genericWin
->handle
= (WINDOW
*) NULL
;
695 genericWin
->isVisible
= FALSE
;
699 if (winInfo
->generic
.content
!= (OpaquePtr
) NULL
)
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
);
710 if (winInfo
->generic
.handle
!= (WINDOW
*) NULL
)
712 tui_delete_win (winInfo
->generic
.handle
);
713 winInfo
->generic
.handle
= (WINDOW
*) NULL
;
714 winInfo
->generic
.isVisible
= FALSE
;
720 tui_free_window (struct tui_win_info
* winInfo
)
722 struct tui_gen_win_info
* genericWin
;
724 switch (winInfo
->generic
.type
)
728 genericWin
= tui_locator_win_info_ptr ();
729 if (genericWin
!= (struct tui_gen_win_info
*) NULL
)
731 tui_delete_win (genericWin
->handle
);
732 genericWin
->handle
= (WINDOW
*) NULL
;
734 tui_free_win_content (genericWin
);
735 if (winInfo
->detail
.sourceInfo
.filename
)
737 xfree (winInfo
->detail
.sourceInfo
.filename
);
738 winInfo
->detail
.sourceInfo
.filename
= 0;
740 genericWin
= winInfo
->detail
.sourceInfo
.executionInfo
;
741 if (genericWin
!= (struct tui_gen_win_info
*) NULL
)
743 tui_delete_win (genericWin
->handle
);
744 genericWin
->handle
= (WINDOW
*) NULL
;
745 tui_free_win_content (genericWin
);
749 if (winInfo
->generic
.content
!= (OpaquePtr
) NULL
)
751 tui_free_data_content (winInfo
->detail
.dataDisplayInfo
.regsContent
,
752 winInfo
->detail
.dataDisplayInfo
.regsContentCount
);
753 winInfo
->detail
.dataDisplayInfo
.regsContent
=
754 (tui_win_content
) 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 (tui_win_content
) NULL
;
760 winInfo
->detail
.dataDisplayInfo
.dataContentCount
= 0;
761 winInfo
->detail
.dataDisplayInfo
.regsDisplayType
=
763 winInfo
->detail
.dataDisplayInfo
.regsColumnCount
= 1;
764 winInfo
->detail
.dataDisplayInfo
.displayRegs
= FALSE
;
765 winInfo
->generic
.content
= (OpaquePtr
) NULL
;
766 winInfo
->generic
.contentSize
= 0;
772 if (winInfo
->generic
.handle
!= (WINDOW
*) NULL
)
774 tui_delete_win (winInfo
->generic
.handle
);
775 winInfo
->generic
.handle
= (WINDOW
*) NULL
;
776 tui_free_win_content (&winInfo
->generic
);
778 if (winInfo
->generic
.title
)
779 xfree (winInfo
->generic
.title
);
785 tui_free_all_source_wins_content (void)
789 for (i
= 0; i
< (tui_source_windows ())->count
; i
++)
791 struct tui_win_info
* winInfo
= (struct tui_win_info
*) (tui_source_windows ())->list
[i
];
793 if (m_winPtrNotNull (winInfo
))
795 tui_free_win_content (&(winInfo
->generic
));
796 tui_free_win_content (winInfo
->detail
.sourceInfo
.executionInfo
);
803 tui_free_win_content (struct tui_gen_win_info
* winInfo
)
805 if (winInfo
->content
!= (OpaquePtr
) NULL
)
807 freeContent ((tui_win_content
) winInfo
->content
,
808 winInfo
->contentSize
,
810 winInfo
->content
= (OpaquePtr
) NULL
;
812 winInfo
->contentSize
= 0;
815 } /* freeWinContent */
819 tui_del_data_windows (tui_win_content content
, int contentSize
)
824 ** Remember that data window content elements are of type struct tui_gen_win_info *,
825 ** each of which whose single element is a data element.
827 for (i
= 0; i
< contentSize
; i
++)
829 struct tui_gen_win_info
* genericWin
= &content
[i
]->whichElement
.dataWindow
;
831 if (genericWin
!= (struct tui_gen_win_info
*) NULL
)
833 tui_delete_win (genericWin
->handle
);
834 genericWin
->handle
= (WINDOW
*) NULL
;
835 genericWin
->isVisible
= FALSE
;
842 tui_free_data_content (tui_win_content content
, int contentSize
)
847 ** Remember that data window content elements are of type struct tui_gen_win_info *,
848 ** each of which whose single element is a data element.
850 for (i
= 0; i
< contentSize
; i
++)
852 struct tui_gen_win_info
* genericWin
= &content
[i
]->whichElement
.dataWindow
;
854 if (genericWin
!= (struct tui_gen_win_info
*) NULL
)
856 tui_delete_win (genericWin
->handle
);
857 genericWin
->handle
= (WINDOW
*) NULL
;
858 tui_free_win_content (genericWin
);
861 freeContent (content
,
866 } /* freeDataContent */
869 /**********************************
870 ** LOCAL STATIC FUNCTIONS **
871 **********************************/
878 freeContent (tui_win_content content
, int contentSize
, TuiWinType winType
)
880 if (content
!= (tui_win_content
) NULL
)
882 freeContentElements (content
, contentSize
, winType
);
883 tuiFree ((char *) content
);
891 ** freeContentElements().
894 freeContentElements (tui_win_content content
, int contentSize
, TuiWinType type
)
896 if (content
!= (tui_win_content
) NULL
)
900 if (type
== SRC_WIN
|| type
== DISASSEM_WIN
)
902 /* free whole source block */
903 if (content
[0]->whichElement
.source
.line
!= (char *) NULL
)
904 tuiFree (content
[0]->whichElement
.source
.line
);
908 for (i
= 0; i
< contentSize
; i
++)
910 struct tui_win_element
* element
;
912 element
= content
[i
];
913 if (element
!= (struct tui_win_element
*) NULL
)
918 tuiFree ((char *) element
);
922 ** Note that data elements are not allocated
923 ** in a single block, but individually, as needed.
925 if (element
->whichElement
.data
.type
!= TUI_REGISTER
)
927 element
->whichElement
.data
.name
);
928 tuiFree ((char *) element
->whichElement
.data
.value
);
929 tuiFree ((char *) element
);
932 tuiFree ((char *) element
->whichElement
.command
.line
);
940 if (type
!= DATA_WIN
&& type
!= DATA_ITEM_WIN
)
941 tuiFree ((char *) content
[0]); /* free the element block */
945 } /* freeContentElements */