2004-02-07 Andrew Cagney <cagney@redhat.com>
[deliverable/binutils-gdb.git] / gdb / tui / tui-data.c
CommitLineData
f377b406 1/* TUI data manipulation routines.
f33c6cbf 2
96ec9981 3 Copyright 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation,
f33c6cbf
AC
4 Inc.
5
f377b406
SC
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. */
c906108c 24
96ec9981
DJ
25#include "defs.h"
26#include "symtab.h"
d7b2e967
AC
27#include "tui/tui.h"
28#include "tui/tui-data.h"
29#include "tui/tui-wingeneral.h"
f33c6cbf 30
4e8f7a8b
DJ
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
c906108c
SS
39/****************************
40** GLOBAL DECLARATIONS
41****************************/
2a8854a7 42struct tui_win_info *(winList[MAX_MAJOR_WINDOWS]);
c906108c 43
c906108c
SS
44/***************************
45** Private data
46****************************/
2a8854a7 47static enum tui_layout_type _currentLayout = UNDEFINED_LAYOUT;
c906108c 48static int _termHeight, _termWidth;
2a8854a7
AC
49static struct tui_gen_win_info _locator;
50static struct tui_gen_win_info _execInfo[2];
51static struct tui_win_info * _srcWinList[2];
52static struct tui_list _sourceWindows =
c906108c
SS
53{(OpaqueList) _srcWinList, 0};
54static int _defaultTabLen = DEFAULT_TAB_LEN;
2a8854a7
AC
55static struct tui_win_info * _winWithFocus = (struct tui_win_info *) NULL;
56static struct tui_layout_def _layoutDef =
c906108c
SS
57{SRC_WIN, /* displayMode */
58 FALSE, /* split */
59 TUI_UNDEFINED_REGS, /* regsDisplayType */
60 TUI_SFLOAT_REGS}; /* floatRegsDisplayType */
61static int _winResized = FALSE;
62
63
64/*********************************
65** Static function forward decls
66**********************************/
2a8854a7
AC
67static void freeContent (tui_win_content, int, TuiWinType);
68static void freeContentElements (tui_win_content, int, TuiWinType);
c906108c
SS
69
70
71
72/*********************************
73** PUBLIC FUNCTIONS
74**********************************/
75
76/******************************************
77** ACCESSORS & MUTATORS FOR PRIVATE DATA
78******************************************/
79
dd1abb8c 80/* Answer a whether the terminal window has been resized or not. */
c906108c 81int
dd1abb8c 82tui_win_resized (void)
c906108c
SS
83{
84 return _winResized;
dd1abb8c 85}
c906108c
SS
86
87
dd1abb8c 88/* Set a whether the terminal window has been resized or not. */
c906108c 89void
dd1abb8c 90tui_set_win_resized_to (int resized)
c906108c
SS
91{
92 _winResized = resized;
dd1abb8c 93}
c906108c
SS
94
95
dd1abb8c 96/* Answer a pointer to the current layout definition. */
2a8854a7 97struct tui_layout_def *
dd1abb8c 98tui_layout_def (void)
c906108c
SS
99{
100 return &_layoutDef;
dd1abb8c 101}
c906108c
SS
102
103
dd1abb8c 104/* Answer the window with the logical focus. */
2a8854a7 105struct tui_win_info *
dd1abb8c 106tui_win_with_focus (void)
c906108c
SS
107{
108 return _winWithFocus;
dd1abb8c 109}
c906108c
SS
110
111
dd1abb8c 112/* Set the window that has the logical focus. */
c906108c 113void
2a8854a7 114tui_set_win_with_focus (struct tui_win_info * winInfo)
c906108c
SS
115{
116 _winWithFocus = winInfo;
dd1abb8c 117}
c906108c
SS
118
119
dd1abb8c 120/* Answer the length in chars, of tabs. */
c906108c 121int
dd1abb8c 122tui_default_tab_len (void)
c906108c
SS
123{
124 return _defaultTabLen;
dd1abb8c 125}
c906108c
SS
126
127
dd1abb8c 128/* Set the length in chars, of tabs. */
c906108c 129void
dd1abb8c 130tui_set_default_tab_len (int len)
c906108c
SS
131{
132 _defaultTabLen = len;
dd1abb8c 133}
c906108c
SS
134
135
136/*
c5aa993b
JM
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 */
2a8854a7 142struct tui_list *
dd1abb8c 143tui_source_windows (void)
c906108c
SS
144{
145 return &_sourceWindows;
dd1abb8c 146}
c906108c
SS
147
148
dd1abb8c
AC
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. */
c906108c 152void
dd1abb8c 153tui_clear_source_windows (void)
c906108c
SS
154{
155 _sourceWindows.list[0] = (Opaque) NULL;
156 _sourceWindows.list[1] = (Opaque) NULL;
157 _sourceWindows.count = 0;
dd1abb8c 158}
c906108c
SS
159
160
dd1abb8c 161/* Clear the pertinant detail in the source windows. */
c906108c 162void
dd1abb8c 163tui_clear_source_windows_detail (void)
c906108c
SS
164{
165 int i;
166
dd1abb8c 167 for (i = 0; i < (tui_source_windows ())->count; i++)
2a8854a7 168 tui_clear_win_detail ((struct tui_win_info *) (tui_source_windows ())->list[i]);
dd1abb8c 169}
c906108c
SS
170
171
dd1abb8c
AC
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. */
c906108c 175void
2a8854a7 176tui_add_to_source_windows (struct tui_win_info * winInfo)
c906108c
SS
177{
178 if (_sourceWindows.count < 2)
179 _sourceWindows.list[_sourceWindows.count++] = (Opaque) winInfo;
dd1abb8c 180}
c906108c
SS
181
182
dd1abb8c 183/* Clear the pertinant detail in the windows. */
c906108c 184void
2a8854a7 185tui_clear_win_detail (struct tui_win_info * winInfo)
c906108c
SS
186{
187 if (m_winPtrNotNull (winInfo))
188 {
189 switch (winInfo->generic.type)
190 {
191 case SRC_WIN:
192 case DISASSEM_WIN:
a4b99e53 193 winInfo->detail.sourceInfo.startLineOrAddr.addr = 0;
c906108c
SS
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 =
2a8854a7 202 (tui_win_content) NULL;
c906108c
SS
203 winInfo->detail.dataDisplayInfo.dataContentCount = 0;
204 winInfo->detail.dataDisplayInfo.regsContent =
2a8854a7 205 (tui_win_content) NULL;
c906108c
SS
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
c906108c 221/*
c5aa993b
JM
222 ** sourceExecInfoPtr().
223 ** Accessor for the source execution info ptr.
224 */
2a8854a7 225struct tui_gen_win_info *
dd1abb8c 226tui_source_exec_info_win_ptr (void)
c906108c
SS
227{
228 return &_execInfo[0];
229} /* sourceExecInfoWinPtr */
230
231
232/*
c5aa993b
JM
233 ** disassemExecInfoPtr().
234 ** Accessor for the disassem execution info ptr.
235 */
2a8854a7 236struct tui_gen_win_info *
dd1abb8c 237tui_disassem_exec_info_win_ptr (void)
c906108c
SS
238{
239 return &_execInfo[1];
240} /* disassemExecInfoWinPtr */
241
242
dd1abb8c
AC
243/* Accessor for the locator win info. Answers a pointer to the static
244 locator win info struct. */
2a8854a7 245struct tui_gen_win_info *
dd1abb8c 246tui_locator_win_info_ptr (void)
c906108c
SS
247{
248 return &_locator;
2a8854a7 249}
c906108c
SS
250
251
dd1abb8c 252/* Accessor for the termHeight. */
c906108c 253int
dd1abb8c 254tui_term_height (void)
c906108c
SS
255{
256 return _termHeight;
dd1abb8c 257}
c906108c
SS
258
259
dd1abb8c 260/* Mutator for the term height. */
c906108c 261void
dd1abb8c 262tui_set_term_height_to (int h)
c906108c
SS
263{
264 _termHeight = h;
dd1abb8c 265}
c906108c
SS
266
267
dd1abb8c 268/* Accessor for the termWidth. */
c906108c 269int
dd1abb8c 270tui_term_width (void)
c906108c
SS
271{
272 return _termWidth;
dd1abb8c 273}
c906108c
SS
274
275
dd1abb8c 276/* Mutator for the termWidth. */
c906108c 277void
dd1abb8c 278tui_set_term_width_to (int w)
c906108c
SS
279{
280 _termWidth = w;
dd1abb8c 281}
c906108c
SS
282
283
dd1abb8c 284/* Accessor for the current layout. */
2a8854a7 285enum tui_layout_type
dd1abb8c 286tui_current_layout (void)
c906108c
SS
287{
288 return _currentLayout;
dd1abb8c 289}
c906108c
SS
290
291
dd1abb8c 292/* Mutator for the current layout. */
c906108c 293void
2a8854a7 294tui_set_current_layout_to (enum tui_layout_type newLayout)
c906108c
SS
295{
296 _currentLayout = newLayout;
dd1abb8c 297}
c906108c
SS
298
299
300/*
c5aa993b
JM
301 ** setGenWinOrigin().
302 ** Set the origin of the window
303 */
c906108c 304void
2a8854a7 305setGenWinOrigin (struct tui_gen_win_info * winInfo, int x, int y)
c906108c
SS
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
dd1abb8c
AC
319/* Answer the next window in the list, cycling back to the top if
320 necessary. */
2a8854a7
AC
321struct tui_win_info *
322tui_next_win (struct tui_win_info * curWin)
c906108c
SS
323{
324 TuiWinType type = curWin->generic.type;
2a8854a7 325 struct tui_win_info * nextWin = (struct tui_win_info *) NULL;
c906108c
SS
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 {
a4b99e53 333 if (winList[type] && winList[type]->generic.isVisible)
c906108c
SS
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
dd1abb8c
AC
348/* Answer the prev window in the list, cycling back to the bottom if
349 necessary. */
2a8854a7
AC
350struct tui_win_info *
351tui_prev_win (struct tui_win_info * curWin)
c906108c
SS
352{
353 TuiWinType type = curWin->generic.type;
2a8854a7 354 struct tui_win_info * prev = (struct tui_win_info *) NULL;
c906108c
SS
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;
cb50eddd 374}
c906108c
SS
375
376
dd1abb8c 377/* Answer the window represented by name. */
2a8854a7 378struct tui_win_info *
dd1abb8c 379tui_partial_win_by_name (char *name)
c906108c 380{
2a8854a7 381 struct tui_win_info * winInfo = (struct tui_win_info *) NULL;
c906108c
SS
382
383 if (name != (char *) NULL)
384 {
385 int i = 0;
386
387 while (i < MAX_MAJOR_WINDOWS && m_winPtrIsNull (winInfo))
388 {
a4b99e53
SC
389 if (winList[i] != 0)
390 {
dd1abb8c 391 char *curName = tui_win_name (&winList[i]->generic);
a4b99e53
SC
392 if (strlen (name) <= strlen (curName) &&
393 strncmp (name, curName, strlen (name)) == 0)
394 winInfo = winList[i];
395 }
c906108c
SS
396 i++;
397 }
398 }
399
400 return winInfo;
401} /* partialWinByName */
402
403
404/*
c5aa993b
JM
405 ** winName().
406 ** Answer the name of the window
407 */
c906108c 408char *
2a8854a7 409tui_win_name (struct tui_gen_win_info * winInfo)
c906108c
SS
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
c906108c 436void
dd1abb8c 437tui_initialize_static_data (void)
c906108c 438{
dd1abb8c
AC
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}
c906108c
SS
443
444
2a8854a7 445struct tui_gen_win_info *
dd1abb8c 446tui_alloc_generic_win_info (void)
c906108c 447{
2a8854a7 448 struct tui_gen_win_info * win;
c906108c 449
2a8854a7
AC
450 if ((win = (struct tui_gen_win_info *) xmalloc (
451 sizeof (struct tui_gen_win_info *))) != (struct tui_gen_win_info *) NULL)
dd1abb8c 452 tui_init_generic_part (win);
c906108c
SS
453
454 return win;
455} /* allocGenericWinInfo */
456
457
458/*
c5aa993b
JM
459 ** initGenericPart().
460 */
c906108c 461void
2a8854a7 462tui_init_generic_part (struct tui_gen_win_info * win)
c906108c
SS
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;
bc6b7f04
SC
475 win->title = 0;
476}
c906108c
SS
477
478
479/*
c5aa993b
JM
480 ** initContentElement().
481 */
c906108c 482void
2a8854a7 483initContentElement (struct tui_win_element * element, TuiWinType type)
c906108c
SS
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:
dd1abb8c 496 tui_init_generic_part (&element->whichElement.dataWindow);
c906108c 497 element->whichElement.dataWindow.type = DATA_ITEM_WIN;
2a8854a7 498 ((struct tui_gen_win_info *) & element->whichElement.dataWindow)->content =
dd1abb8c 499 (OpaquePtr) tui_alloc_content (1, DATA_ITEM_WIN);
2a8854a7 500 ((struct tui_gen_win_info *)
c906108c
SS
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:
00b2bad4
SC
520 memset(element->whichElement.simpleString, ' ',
521 sizeof(element->whichElement.simpleString));
c906108c
SS
522 break;
523 default:
524 break;
525 }
526 return;
527} /* initContentElement */
528
529/*
c5aa993b
JM
530 ** initWinInfo().
531 */
c906108c 532void
2a8854a7 533initWinInfo (struct tui_win_info * winInfo)
c906108c 534{
dd1abb8c 535 tui_init_generic_part (&winInfo->generic);
c906108c
SS
536 winInfo->canHighlight =
537 winInfo->isHighlighted = FALSE;
538 switch (winInfo->generic.type)
539 {
540 case SRC_WIN:
541 case DISASSEM_WIN:
2a8854a7 542 winInfo->detail.sourceInfo.executionInfo = (struct tui_gen_win_info *) NULL;
c906108c
SS
543 winInfo->detail.sourceInfo.hasLocator = FALSE;
544 winInfo->detail.sourceInfo.horizontalOffset = 0;
a4b99e53 545 winInfo->detail.sourceInfo.startLineOrAddr.addr = 0;
bc6b7f04 546 winInfo->detail.sourceInfo.filename = 0;
c906108c
SS
547 break;
548 case DATA_WIN:
2a8854a7 549 winInfo->detail.dataDisplayInfo.dataContent = (tui_win_content) NULL;
c906108c 550 winInfo->detail.dataDisplayInfo.dataContentCount = 0;
2a8854a7 551 winInfo->detail.dataDisplayInfo.regsContent = (tui_win_content) NULL;
c906108c
SS
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
2a8854a7 571struct tui_win_info *
dd1abb8c 572tui_alloc_win_info (TuiWinType type)
c906108c 573{
2a8854a7 574 struct tui_win_info * winInfo = (struct tui_win_info *) NULL;
c906108c 575
2a8854a7 576 winInfo = (struct tui_win_info *) xmalloc (sizeof (struct tui_win_info));
c906108c
SS
577 if (m_winPtrNotNull (winInfo))
578 {
579 winInfo->generic.type = type;
580 initWinInfo (winInfo);
581 }
582
583 return winInfo;
584} /* allocWinInfo */
585
586
587/*
c5aa993b
JM
588 ** allocContent().
589 ** Allocates the content and elements in a block.
590 */
2a8854a7 591tui_win_content
dd1abb8c 592tui_alloc_content (int numElements, TuiWinType type)
c906108c 593{
2a8854a7 594 tui_win_content content = (tui_win_content) NULL;
c906108c
SS
595 char *elementBlockPtr = (char *) NULL;
596 int i;
597
2a8854a7
AC
598 if ((content = (tui_win_content)
599 xmalloc (sizeof (struct tui_win_element *) * numElements)) != (tui_win_content) NULL)
c906108c 600 { /*
c5aa993b
JM
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 */
c906108c
SS
605 if (type != DATA_WIN)
606 {
607 if ((elementBlockPtr = (char *)
2a8854a7 608 xmalloc (sizeof (struct tui_win_element) * numElements)) != (char *) NULL)
c906108c
SS
609 {
610 for (i = 0; i < numElements; i++)
611 {
2a8854a7 612 content[i] = (struct tui_win_element *) elementBlockPtr;
c906108c 613 initContentElement (content[i], type);
2a8854a7 614 elementBlockPtr += sizeof (struct tui_win_element);
c906108c
SS
615 }
616 }
617 else
618 {
619 tuiFree ((char *) content);
2a8854a7 620 content = (tui_win_content) NULL;
c906108c
SS
621 }
622 }
623 }
624
625 return content;
626} /* allocContent */
627
628
dd1abb8c
AC
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. */
c906108c 634int
2a8854a7 635tui_add_content_elements (struct tui_gen_win_info * winInfo, int numElements)
c906108c 636{
2a8854a7 637 struct tui_win_element * elementPtr;
c906108c
SS
638 int i, indexStart;
639
640 if (winInfo->content == (OpaquePtr) NULL)
641 {
dd1abb8c 642 winInfo->content = (OpaquePtr) tui_alloc_content (numElements, winInfo->type);
c906108c
SS
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 {
2a8854a7
AC
651 if ((elementPtr = (struct tui_win_element *)
652 xmalloc (sizeof (struct tui_win_element))) != (struct tui_win_element *) NULL)
c906108c
SS
653 {
654 winInfo->content[i] = (Opaque) elementPtr;
655 initContentElement (elementPtr, winInfo->type);
656 winInfo->contentSize++;
657 }
c5aa993b 658 else /* things must be really hosed now! We ran out of memory!? */
c906108c
SS
659 return (-1);
660 }
661 }
662
663 return indexStart;
664} /* addContentElements */
665
666
bc6b7f04
SC
667/* Delete all curses windows associated with winInfo, leaving everything
668 else intact. */
c906108c 669void
2a8854a7 670tuiDelWindow (struct tui_win_info * winInfo)
c906108c 671{
2a8854a7 672 struct tui_gen_win_info * genericWin;
c906108c 673
c906108c
SS
674 switch (winInfo->generic.type)
675 {
676 case SRC_WIN:
677 case DISASSEM_WIN:
dd1abb8c 678 genericWin = tui_locator_win_info_ptr ();
2a8854a7 679 if (genericWin != (struct tui_gen_win_info *) NULL)
c906108c 680 {
ec7d9e56 681 tui_delete_win (genericWin->handle);
c906108c
SS
682 genericWin->handle = (WINDOW *) NULL;
683 genericWin->isVisible = FALSE;
684 }
bc6b7f04
SC
685 if (winInfo->detail.sourceInfo.filename)
686 {
687 xfree (winInfo->detail.sourceInfo.filename);
688 winInfo->detail.sourceInfo.filename = 0;
689 }
c906108c 690 genericWin = winInfo->detail.sourceInfo.executionInfo;
2a8854a7 691 if (genericWin != (struct tui_gen_win_info *) NULL)
c906108c 692 {
ec7d9e56 693 tui_delete_win (genericWin->handle);
c906108c
SS
694 genericWin->handle = (WINDOW *) NULL;
695 genericWin->isVisible = FALSE;
696 }
697 break;
698 case DATA_WIN:
699 if (winInfo->generic.content != (OpaquePtr) NULL)
700 {
dd1abb8c
AC
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);
c906108c
SS
705 }
706 break;
707 default:
708 break;
709 }
710 if (winInfo->generic.handle != (WINDOW *) NULL)
711 {
ec7d9e56 712 tui_delete_win (winInfo->generic.handle);
c906108c
SS
713 winInfo->generic.handle = (WINDOW *) NULL;
714 winInfo->generic.isVisible = FALSE;
715 }
bc6b7f04 716}
c906108c
SS
717
718
c906108c 719void
2a8854a7 720tui_free_window (struct tui_win_info * winInfo)
c906108c 721{
2a8854a7 722 struct tui_gen_win_info * genericWin;
c906108c 723
c906108c
SS
724 switch (winInfo->generic.type)
725 {
726 case SRC_WIN:
727 case DISASSEM_WIN:
dd1abb8c 728 genericWin = tui_locator_win_info_ptr ();
2a8854a7 729 if (genericWin != (struct tui_gen_win_info *) NULL)
c906108c 730 {
ec7d9e56 731 tui_delete_win (genericWin->handle);
c906108c
SS
732 genericWin->handle = (WINDOW *) NULL;
733 }
dd1abb8c 734 tui_free_win_content (genericWin);
bc6b7f04
SC
735 if (winInfo->detail.sourceInfo.filename)
736 {
737 xfree (winInfo->detail.sourceInfo.filename);
738 winInfo->detail.sourceInfo.filename = 0;
739 }
c906108c 740 genericWin = winInfo->detail.sourceInfo.executionInfo;
2a8854a7 741 if (genericWin != (struct tui_gen_win_info *) NULL)
c906108c 742 {
ec7d9e56 743 tui_delete_win (genericWin->handle);
c906108c 744 genericWin->handle = (WINDOW *) NULL;
dd1abb8c 745 tui_free_win_content (genericWin);
c906108c
SS
746 }
747 break;
748 case DATA_WIN:
749 if (winInfo->generic.content != (OpaquePtr) NULL)
750 {
dd1abb8c
AC
751 tui_free_data_content (winInfo->detail.dataDisplayInfo.regsContent,
752 winInfo->detail.dataDisplayInfo.regsContentCount);
c906108c 753 winInfo->detail.dataDisplayInfo.regsContent =
2a8854a7 754 (tui_win_content) NULL;
c906108c 755 winInfo->detail.dataDisplayInfo.regsContentCount = 0;
dd1abb8c
AC
756 tui_free_data_content (winInfo->detail.dataDisplayInfo.dataContent,
757 winInfo->detail.dataDisplayInfo.dataContentCount);
c906108c 758 winInfo->detail.dataDisplayInfo.dataContent =
2a8854a7 759 (tui_win_content) NULL;
c906108c
SS
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 {
ec7d9e56 774 tui_delete_win (winInfo->generic.handle);
c906108c 775 winInfo->generic.handle = (WINDOW *) NULL;
dd1abb8c 776 tui_free_win_content (&winInfo->generic);
c906108c 777 }
bc6b7f04
SC
778 if (winInfo->generic.title)
779 xfree (winInfo->generic.title);
b8c9b27d 780 xfree (winInfo);
bc6b7f04 781}
c906108c
SS
782
783
c906108c 784void
dd1abb8c 785tui_free_all_source_wins_content (void)
c906108c
SS
786{
787 int i;
788
dd1abb8c 789 for (i = 0; i < (tui_source_windows ())->count; i++)
c906108c 790 {
2a8854a7 791 struct tui_win_info * winInfo = (struct tui_win_info *) (tui_source_windows ())->list[i];
c906108c
SS
792
793 if (m_winPtrNotNull (winInfo))
794 {
dd1abb8c
AC
795 tui_free_win_content (&(winInfo->generic));
796 tui_free_win_content (winInfo->detail.sourceInfo.executionInfo);
c906108c
SS
797 }
798 }
dd1abb8c 799}
c906108c
SS
800
801
c906108c 802void
2a8854a7 803tui_free_win_content (struct tui_gen_win_info * winInfo)
c906108c
SS
804{
805 if (winInfo->content != (OpaquePtr) NULL)
806 {
2a8854a7 807 freeContent ((tui_win_content) winInfo->content,
c906108c
SS
808 winInfo->contentSize,
809 winInfo->type);
810 winInfo->content = (OpaquePtr) NULL;
811 }
812 winInfo->contentSize = 0;
813
814 return;
815} /* freeWinContent */
816
817
c906108c 818void
2a8854a7 819tui_del_data_windows (tui_win_content content, int contentSize)
c906108c
SS
820{
821 int i;
822
823 /*
2a8854a7 824 ** Remember that data window content elements are of type struct tui_gen_win_info *,
c5aa993b
JM
825 ** each of which whose single element is a data element.
826 */
c906108c
SS
827 for (i = 0; i < contentSize; i++)
828 {
2a8854a7 829 struct tui_gen_win_info * genericWin = &content[i]->whichElement.dataWindow;
c906108c 830
2a8854a7 831 if (genericWin != (struct tui_gen_win_info *) NULL)
c906108c 832 {
ec7d9e56 833 tui_delete_win (genericWin->handle);
c906108c
SS
834 genericWin->handle = (WINDOW *) NULL;
835 genericWin->isVisible = FALSE;
836 }
837 }
dd1abb8c 838}
c906108c
SS
839
840
841void
2a8854a7 842tui_free_data_content (tui_win_content content, int contentSize)
c906108c
SS
843{
844 int i;
845
846 /*
2a8854a7 847 ** Remember that data window content elements are of type struct tui_gen_win_info *,
c5aa993b
JM
848 ** each of which whose single element is a data element.
849 */
c906108c
SS
850 for (i = 0; i < contentSize; i++)
851 {
2a8854a7 852 struct tui_gen_win_info * genericWin = &content[i]->whichElement.dataWindow;
c906108c 853
2a8854a7 854 if (genericWin != (struct tui_gen_win_info *) NULL)
c906108c 855 {
ec7d9e56 856 tui_delete_win (genericWin->handle);
c906108c 857 genericWin->handle = (WINDOW *) NULL;
dd1abb8c 858 tui_free_win_content (genericWin);
c906108c
SS
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/*
c5aa993b
JM
875 ** freeContent().
876 */
c906108c 877static void
2a8854a7 878freeContent (tui_win_content content, int contentSize, TuiWinType winType)
c906108c 879{
2a8854a7 880 if (content != (tui_win_content) NULL)
c906108c
SS
881 {
882 freeContentElements (content, contentSize, winType);
883 tuiFree ((char *) content);
884 }
885
886 return;
887} /* freeContent */
888
889
890/*
c5aa993b
JM
891 ** freeContentElements().
892 */
c906108c 893static void
2a8854a7 894freeContentElements (tui_win_content content, int contentSize, TuiWinType type)
c906108c 895{
2a8854a7 896 if (content != (tui_win_content) NULL)
c906108c
SS
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 {
2a8854a7 910 struct tui_win_element * element;
c906108c
SS
911
912 element = content[i];
2a8854a7 913 if (element != (struct tui_win_element *) NULL)
c906108c
SS
914 {
915 switch (type)
916 {
917 case DATA_WIN:
918 tuiFree ((char *) element);
919 break;
920 case DATA_ITEM_WIN:
921 /*
c5aa993b
JM
922 ** Note that data elements are not allocated
923 ** in a single block, but individually, as needed.
924 */
c906108c
SS
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.458987 seconds and 4 git commands to generate.