* tuiSourceWin.h (tui_update_all_breakpoint_info): Declare.
[deliverable/binutils-gdb.git] / gdb / tui / tuiData.c
CommitLineData
f377b406 1/* TUI data manipulation routines.
f33c6cbf
AC
2
3 Copyright 1998, 1999, 2000, 2001, 2002 Free Software Foundation,
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
f33c6cbf
AC
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
4e8f7a8b
DJ
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
c906108c
SS
42#include "defs.h"
43#include "tui.h"
44#include "tuiData.h"
a4b99e53 45#include "tuiGeneralWin.h"
c906108c
SS
46
47/****************************
48** GLOBAL DECLARATIONS
49****************************/
50TuiWinInfoPtr winList[MAX_MAJOR_WINDOWS];
51
52/***************************
53** Private Definitions
54****************************/
55#define FILE_WIDTH 30
56#define PROC_WIDTH 40
57#define LINE_WIDTH 4
58#define PC_WIDTH 8
59
60/***************************
61** Private data
62****************************/
63static char *_tuiNullStr = TUI_NULL_STR;
64static char *_tuiBlankStr = " ";
65static char *_tuiLocationStr = " >";
66static char *_tuiBreakStr = " * ";
67static char *_tuiBreakLocationStr = " *>";
68static TuiLayoutType _currentLayout = UNDEFINED_LAYOUT;
69static int _termHeight, _termWidth;
70static int _historyLimit = DEFAULT_HISTORY_COUNT;
71static TuiGenWinInfo _locator;
72static TuiGenWinInfo _execInfo[2];
73static TuiWinInfoPtr _srcWinList[2];
74static TuiList _sourceWindows =
75{(OpaqueList) _srcWinList, 0};
76static int _defaultTabLen = DEFAULT_TAB_LEN;
77static TuiWinInfoPtr _winWithFocus = (TuiWinInfoPtr) NULL;
78static TuiLayoutDef _layoutDef =
79{SRC_WIN, /* displayMode */
80 FALSE, /* split */
81 TUI_UNDEFINED_REGS, /* regsDisplayType */
82 TUI_SFLOAT_REGS}; /* floatRegsDisplayType */
83static int _winResized = FALSE;
84
85
86/*********************************
87** Static function forward decls
88**********************************/
a14ed312
KB
89static void freeContent (TuiWinContent, int, TuiWinType);
90static void freeContentElements (TuiWinContent, int, TuiWinType);
c906108c
SS
91
92
93
94/*********************************
95** PUBLIC FUNCTIONS
96**********************************/
97
98/******************************************
99** ACCESSORS & MUTATORS FOR PRIVATE DATA
100******************************************/
101
102/*
c5aa993b
JM
103 ** tuiWinResized().
104 ** Answer a whether the terminal window has been resized or not
105 */
c906108c 106int
c906108c 107tuiWinResized (void)
c906108c
SS
108{
109 return _winResized;
110} /* tuiWinResized */
111
112
113/*
c5aa993b
JM
114 ** tuiSetWinResized().
115 ** Set a whether the terminal window has been resized or not
116 */
c906108c 117void
eca6576c 118tuiSetWinResizedTo (int resized)
c906108c
SS
119{
120 _winResized = resized;
121
122 return;
123} /* tuiSetWinResizedTo */
124
125
126/*
c5aa993b
JM
127 ** tuiLayoutDef().
128 ** Answer a pointer to the current layout definition
129 */
c906108c 130TuiLayoutDefPtr
c906108c 131tuiLayoutDef (void)
c906108c
SS
132{
133 return &_layoutDef;
134} /* tuiLayoutDef */
135
136
137/*
c5aa993b
JM
138 ** tuiWinWithFocus().
139 ** Answer the window with the logical focus
140 */
c906108c 141TuiWinInfoPtr
c906108c 142tuiWinWithFocus (void)
c906108c
SS
143{
144 return _winWithFocus;
145} /* tuiWinWithFocus */
146
147
148/*
c5aa993b
JM
149 ** tuiSetWinWithFocus().
150 ** Set the window that has the logical focus
151 */
c906108c 152void
eca6576c 153tuiSetWinWithFocus (TuiWinInfoPtr winInfo)
c906108c
SS
154{
155 _winWithFocus = winInfo;
156
157 return;
158} /* tuiSetWinWithFocus */
159
160
161/*
c5aa993b
JM
162 ** tuiDefaultTabLen().
163 ** Answer the length in chars, of tabs
164 */
c906108c 165int
c906108c 166tuiDefaultTabLen (void)
c906108c
SS
167{
168 return _defaultTabLen;
169} /* tuiDefaultTabLen */
170
171
172/*
c5aa993b
JM
173 ** tuiSetDefaultTabLen().
174 ** Set the length in chars, of tabs
175 */
c906108c 176void
eca6576c 177tuiSetDefaultTabLen (int len)
c906108c
SS
178{
179 _defaultTabLen = len;
180
181 return;
182} /* tuiSetDefaultTabLen */
183
184
185/*
c5aa993b
JM
186 ** currentSourceWin()
187 ** Accessor for the current source window. Usually there is only
188 ** one source window (either source or disassembly), but both can
189 ** be displayed at the same time.
190 */
c906108c 191TuiListPtr
c906108c 192sourceWindows (void)
c906108c
SS
193{
194 return &_sourceWindows;
195} /* currentSourceWindows */
196
197
198/*
c5aa993b
JM
199 ** clearSourceWindows()
200 ** Clear the list of source windows. Usually there is only one
201 ** source window (either source or disassembly), but both can be
202 ** displayed at the same time.
203 */
c906108c 204void
c906108c 205clearSourceWindows (void)
c906108c
SS
206{
207 _sourceWindows.list[0] = (Opaque) NULL;
208 _sourceWindows.list[1] = (Opaque) NULL;
209 _sourceWindows.count = 0;
210
211 return;
212} /* currentSourceWindows */
213
214
215/*
c5aa993b
JM
216 ** clearSourceWindowsDetail()
217 ** Clear the pertinant detail in the source windows.
218 */
c906108c 219void
c906108c 220clearSourceWindowsDetail (void)
c906108c
SS
221{
222 int i;
223
224 for (i = 0; i < (sourceWindows ())->count; i++)
225 clearWinDetail ((TuiWinInfoPtr) (sourceWindows ())->list[i]);
226
227 return;
228} /* currentSourceWindows */
229
230
231/*
c5aa993b
JM
232 ** addSourceWindowToList().
233 ** Add a window to the list of source windows. Usually there is
234 ** only one source window (either source or disassembly), but
235 ** both can be displayed at the same time.
236 */
c906108c 237void
eca6576c 238addToSourceWindows (TuiWinInfoPtr winInfo)
c906108c
SS
239{
240 if (_sourceWindows.count < 2)
241 _sourceWindows.list[_sourceWindows.count++] = (Opaque) winInfo;
242
243 return;
244} /* addToSourceWindows */
245
246
247/*
c5aa993b
JM
248 ** clearWinDetail()
249 ** Clear the pertinant detail in the windows.
250 */
c906108c 251void
eca6576c 252clearWinDetail (TuiWinInfoPtr winInfo)
c906108c
SS
253{
254 if (m_winPtrNotNull (winInfo))
255 {
256 switch (winInfo->generic.type)
257 {
258 case SRC_WIN:
259 case DISASSEM_WIN:
a4b99e53 260 winInfo->detail.sourceInfo.startLineOrAddr.addr = 0;
c906108c
SS
261 winInfo->detail.sourceInfo.horizontalOffset = 0;
262 break;
263 case CMD_WIN:
264 winInfo->detail.commandInfo.curLine =
265 winInfo->detail.commandInfo.curch = 0;
266 break;
267 case DATA_WIN:
268 winInfo->detail.dataDisplayInfo.dataContent =
269 (TuiWinContent) NULL;
270 winInfo->detail.dataDisplayInfo.dataContentCount = 0;
271 winInfo->detail.dataDisplayInfo.regsContent =
272 (TuiWinContent) NULL;
273 winInfo->detail.dataDisplayInfo.regsContentCount = 0;
274 winInfo->detail.dataDisplayInfo.regsDisplayType =
275 TUI_UNDEFINED_REGS;
276 winInfo->detail.dataDisplayInfo.regsColumnCount = 1;
277 winInfo->detail.dataDisplayInfo.displayRegs = FALSE;
278 break;
279 default:
280 break;
281 }
282 }
283
284 return;
285} /* clearWinDetail */
286
287
288/*
c5aa993b
JM
289 ** blankStr()
290 ** Accessor for the blank string.
291 */
c906108c 292char *
c906108c 293blankStr (void)
c906108c
SS
294{
295 return _tuiBlankStr;
296} /* blankStr */
297
298
299/*
c5aa993b
JM
300 ** locationStr()
301 ** Accessor for the location string.
302 */
c906108c 303char *
c906108c 304locationStr (void)
c906108c
SS
305{
306 return _tuiLocationStr;
307} /* locationStr */
308
309
310/*
c5aa993b
JM
311 ** breakStr()
312 ** Accessor for the break string.
313 */
c906108c 314char *
c906108c 315breakStr (void)
c906108c
SS
316{
317 return _tuiBreakStr;
318} /* breakStr */
319
320
321/*
c5aa993b
JM
322 ** breakLocationStr()
323 ** Accessor for the breakLocation string.
324 */
c906108c 325char *
c906108c 326breakLocationStr (void)
c906108c
SS
327{
328 return _tuiBreakLocationStr;
329} /* breakLocationStr */
330
331
332/*
c5aa993b
JM
333 ** nullStr()
334 ** Accessor for the null string.
335 */
c906108c 336char *
c906108c 337nullStr (void)
c906108c
SS
338{
339 return _tuiNullStr;
340} /* nullStr */
341
342
343/*
c5aa993b
JM
344 ** sourceExecInfoPtr().
345 ** Accessor for the source execution info ptr.
346 */
c906108c 347TuiGenWinInfoPtr
c906108c 348sourceExecInfoWinPtr (void)
c906108c
SS
349{
350 return &_execInfo[0];
351} /* sourceExecInfoWinPtr */
352
353
354/*
c5aa993b
JM
355 ** disassemExecInfoPtr().
356 ** Accessor for the disassem execution info ptr.
357 */
c906108c 358TuiGenWinInfoPtr
c906108c 359disassemExecInfoWinPtr (void)
c906108c
SS
360{
361 return &_execInfo[1];
362} /* disassemExecInfoWinPtr */
363
364
365/*
c5aa993b
JM
366 ** locatorWinInfoPtr().
367 ** Accessor for the locator win info. Answers a pointer to the
368 ** static locator win info struct.
369 */
c906108c 370TuiGenWinInfoPtr
c906108c 371locatorWinInfoPtr (void)
c906108c
SS
372{
373 return &_locator;
374} /* locatorWinInfoPtr */
375
376
377/*
c5aa993b
JM
378 ** historyLimit().
379 ** Accessor for the history limit
380 */
c906108c 381int
c906108c 382historyLimit (void)
c906108c
SS
383{
384 return _historyLimit;
385} /* historyLimit */
386
387
388/*
c5aa993b
JM
389 ** setHistoryLimitTo().
390 ** Mutator for the history limit
391 */
c906108c 392void
eca6576c 393setHistoryLimitTo (int h)
c906108c
SS
394{
395 _historyLimit = h;
396
397 return;
398} /* setHistoryLimitTo */
399
400/*
c5aa993b
JM
401 ** termHeight().
402 ** Accessor for the termHeight
403 */
c906108c 404int
c906108c 405termHeight (void)
c906108c
SS
406{
407 return _termHeight;
408} /* termHeight */
409
410
411/*
c5aa993b
JM
412 ** setTermHeightTo().
413 ** Mutator for the term height
414 */
c906108c 415void
eca6576c 416setTermHeightTo (int h)
c906108c
SS
417{
418 _termHeight = h;
419
420 return;
421} /* setTermHeightTo */
422
423
424/*
c5aa993b
JM
425 ** termWidth().
426 ** Accessor for the termWidth
427 */
c906108c 428int
c906108c 429termWidth (void)
c906108c
SS
430{
431 return _termWidth;
432} /* termWidth */
433
434
435/*
c5aa993b
JM
436 ** setTermWidth().
437 ** Mutator for the termWidth
438 */
c906108c 439void
eca6576c 440setTermWidthTo (int w)
c906108c
SS
441{
442 _termWidth = w;
443
444 return;
445} /* setTermWidthTo */
446
447
448/*
c5aa993b
JM
449 ** currentLayout().
450 ** Accessor for the current layout
451 */
c906108c 452TuiLayoutType
c906108c 453currentLayout (void)
c906108c
SS
454{
455 return _currentLayout;
456} /* currentLayout */
457
458
459/*
c5aa993b
JM
460 ** setCurrentLayoutTo().
461 ** Mutator for the current layout
462 */
c906108c 463void
eca6576c 464setCurrentLayoutTo (TuiLayoutType newLayout)
c906108c
SS
465{
466 _currentLayout = newLayout;
467
468 return;
469} /* setCurrentLayoutTo */
470
471
472/*
c5aa993b
JM
473 ** setGenWinOrigin().
474 ** Set the origin of the window
475 */
c906108c 476void
eca6576c 477setGenWinOrigin (TuiGenWinInfoPtr winInfo, int x, int y)
c906108c
SS
478{
479 winInfo->origin.x = x;
480 winInfo->origin.y = y;
481
482 return;
483} /* setGenWinOrigin */
484
485
486/*****************************
487** OTHER PUBLIC FUNCTIONS
488*****************************/
489
490
491/*
c5aa993b
JM
492 ** tuiNextWin().
493 ** Answer the next window in the list, cycling back to the top
494 ** if necessary
495 */
c906108c 496TuiWinInfoPtr
eca6576c 497tuiNextWin (TuiWinInfoPtr curWin)
c906108c
SS
498{
499 TuiWinType type = curWin->generic.type;
500 TuiWinInfoPtr nextWin = (TuiWinInfoPtr) NULL;
501
502 if (curWin->generic.type == CMD_WIN)
503 type = SRC_WIN;
504 else
505 type = curWin->generic.type + 1;
506 while (type != curWin->generic.type && m_winPtrIsNull (nextWin))
507 {
a4b99e53 508 if (winList[type] && winList[type]->generic.isVisible)
c906108c
SS
509 nextWin = winList[type];
510 else
511 {
512 if (type == CMD_WIN)
513 type = SRC_WIN;
514 else
515 type++;
516 }
517 }
518
519 return nextWin;
520} /* tuiNextWin */
521
522
523/*
c5aa993b
JM
524 ** tuiPrevWin().
525 ** Answer the prev window in the list, cycling back to the bottom
526 ** if necessary
527 */
c906108c 528TuiWinInfoPtr
eca6576c 529tuiPrevWin (TuiWinInfoPtr curWin)
c906108c
SS
530{
531 TuiWinType type = curWin->generic.type;
532 TuiWinInfoPtr prev = (TuiWinInfoPtr) NULL;
533
534 if (curWin->generic.type == SRC_WIN)
535 type = CMD_WIN;
536 else
537 type = curWin->generic.type - 1;
538 while (type != curWin->generic.type && m_winPtrIsNull (prev))
539 {
540 if (winList[type]->generic.isVisible)
541 prev = winList[type];
542 else
543 {
544 if (type == SRC_WIN)
545 type = CMD_WIN;
546 else
547 type--;
548 }
549 }
550
551 return prev;
552} /* tuiPrevWin */
553
554
555/*
c5aa993b
JM
556 ** displayableWinContentOf().
557 ** Answer a the content at the location indicated by index. Note
558 ** that if this is a locator window, the string returned should be
559 ** freed after use.
560 */
c906108c 561char *
eca6576c 562displayableWinContentOf (TuiGenWinInfoPtr winInfo, TuiWinElementPtr elementPtr)
c906108c
SS
563{
564
565 char *string = nullStr ();
566
567 if (elementPtr != (TuiWinElementPtr) NULL || winInfo->type == LOCATOR_WIN)
568 {
569 /*
c5aa993b
JM
570 ** Now convert the line to a displayable string
571 */
c906108c
SS
572 switch (winInfo->type)
573 {
574 case SRC_WIN:
575 case DISASSEM_WIN:
576 string = elementPtr->whichElement.source.line;
577 break;
578 case CMD_WIN:
579 string = elementPtr->whichElement.command.line;
580 break;
581 case LOCATOR_WIN:
582 if ((string = (char *) xmalloc (
583 (termWidth () + 1) * sizeof (char))) == (char *) NULL)
584 string = nullStr ();
585 else
586 {
587 char lineNo[50], pc[50], buf[50], *fname, *pname;
588 register int strSize = termWidth (), i, procWidth, fileWidth;
589
590 /*
c5aa993b
JM
591 ** First determine the amount of file/proc name width
592 ** we have available
593 */
c906108c
SS
594 i = strSize - (PC_WIDTH + LINE_WIDTH
595 + 25 /* pc and line labels */
c5aa993b 596 + strlen (FILE_PREFIX) + 1 /* file label */
c906108c
SS
597 + 15 /* procedure label */ );
598 if (i >= FILE_WIDTH + PROC_WIDTH)
599 {
600 fileWidth = FILE_WIDTH;
601 procWidth = PROC_WIDTH;
602 }
603 else
604 {
605 fileWidth = i / 2;
606 procWidth = i - fileWidth;
607 }
608
609 /* Now convert elements to string form */
610 if (elementPtr != (TuiWinElementPtr) NULL &&
611 *elementPtr->whichElement.locator.fileName != (char) 0 &&
612 srcWin->generic.isVisible)
613 fname = elementPtr->whichElement.locator.fileName;
614 else
615 fname = "??";
616 if (elementPtr != (TuiWinElementPtr) NULL &&
617 *elementPtr->whichElement.locator.procName != (char) 0)
618 pname = elementPtr->whichElement.locator.procName;
619 else
620 pname = "??";
621 if (elementPtr != (TuiWinElementPtr) NULL &&
622 elementPtr->whichElement.locator.lineNo > 0)
623 sprintf (lineNo, "%d",
624 elementPtr->whichElement.locator.lineNo);
625 else
626 strcpy (lineNo, "??");
627 if (elementPtr != (TuiWinElementPtr) NULL &&
a4b99e53
SC
628 elementPtr->whichElement.locator.addr != 0)
629 sprintf (pc, "0x%lx",
630 (long) elementPtr->whichElement.locator.addr);
c906108c
SS
631 else
632 strcpy (pc, "??");
633 /*
c5aa993b
JM
634 ** Now create the locator line from the string version
635 ** of the elements. We could use sprintf() here but
636 ** that wouldn't ensure that we don't overrun the size
637 ** of the allocated buffer. strcat_to_buf() will.
638 */
c906108c
SS
639 *string = (char) 0;
640 /* Filename */
641 strcat_to_buf (string, strSize, " ");
642 strcat_to_buf (string, strSize, FILE_PREFIX);
643 if (strlen (fname) > fileWidth)
644 {
645 strncpy (buf, fname, fileWidth - 1);
646 buf[fileWidth - 1] = '*';
647 buf[fileWidth] = (char) 0;
648 }
649 else
650 strcpy (buf, fname);
651 strcat_to_buf (string, strSize, buf);
652 /* procedure/class name */
653 sprintf (buf, "%15s", PROC_PREFIX);
654 strcat_to_buf (string, strSize, buf);
655 if (strlen (pname) > procWidth)
656 {
657 strncpy (buf, pname, procWidth - 1);
658 buf[procWidth - 1] = '*';
659 buf[procWidth] = (char) 0;
660 }
661 else
662 strcpy (buf, pname);
663 strcat_to_buf (string, strSize, buf);
664 sprintf (buf, "%10s", LINE_PREFIX);
665 strcat_to_buf (string, strSize, buf);
666 strcat_to_buf (string, strSize, lineNo);
667 sprintf (buf, "%10s", PC_PREFIX);
668 strcat_to_buf (string, strSize, buf);
669 strcat_to_buf (string, strSize, pc);
670 for (i = strlen (string); i < strSize; i++)
671 string[i] = ' ';
672 string[strSize] = (char) 0;
673 }
674 break;
675 case EXEC_INFO_WIN:
676 string = elementPtr->whichElement.simpleString;
677 break;
678 default:
679 break;
680 }
681 }
682 return string;
683} /* displayableWinContentOf */
684
685
686/*
c5aa993b
JM
687 ** winContentAt().
688 ** Answer a the content at the location indicated by index
689 */
c906108c 690char *
eca6576c 691displayableWinContentAt (TuiGenWinInfoPtr winInfo, int index)
c906108c
SS
692{
693 return (displayableWinContentOf (winInfo, (TuiWinElementPtr) winInfo->content[index]));
694} /* winContentAt */
695
696
697/*
c5aa993b
JM
698 ** winElementHeight().
699 ** Answer the height of the element in lines
700 */
c906108c 701int
eca6576c 702winElementHeight (TuiGenWinInfoPtr winInfo, TuiWinElementPtr element)
c906108c
SS
703{
704 int h;
705
706 if (winInfo->type == DATA_WIN)
707/* FOR NOW SAY IT IS ONLY ONE LINE HIGH */
708 h = 1;
709 else
710 h = 1;
711
712 return h;
713} /* winElementHeight */
714
715
716/*
c5aa993b
JM
717 ** winByName().
718 ** Answer the window represented by name
719 */
c906108c 720TuiWinInfoPtr
eca6576c 721winByName (char *name)
c906108c
SS
722{
723 TuiWinInfoPtr winInfo = (TuiWinInfoPtr) NULL;
724 int i = 0;
725
726 while (i < MAX_MAJOR_WINDOWS && m_winPtrIsNull (winInfo))
727 {
728 if (strcmp (name, winName (&(winList[i]->generic))) == 0)
729 winInfo = winList[i];
730 i++;
731 }
732
733 return winInfo;
734} /* winByName */
735
736
737/*
c5aa993b
JM
738 ** partialWinByName().
739 ** Answer the window represented by name
740 */
c906108c 741TuiWinInfoPtr
eca6576c 742partialWinByName (char *name)
c906108c
SS
743{
744 TuiWinInfoPtr winInfo = (TuiWinInfoPtr) NULL;
745
746 if (name != (char *) NULL)
747 {
748 int i = 0;
749
750 while (i < MAX_MAJOR_WINDOWS && m_winPtrIsNull (winInfo))
751 {
a4b99e53
SC
752 if (winList[i] != 0)
753 {
754 char *curName = winName (&winList[i]->generic);
755 if (strlen (name) <= strlen (curName) &&
756 strncmp (name, curName, strlen (name)) == 0)
757 winInfo = winList[i];
758 }
c906108c
SS
759 i++;
760 }
761 }
762
763 return winInfo;
764} /* partialWinByName */
765
766
767/*
c5aa993b
JM
768 ** winName().
769 ** Answer the name of the window
770 */
c906108c 771char *
eca6576c 772winName (TuiGenWinInfoPtr winInfo)
c906108c
SS
773{
774 char *name = (char *) NULL;
775
776 switch (winInfo->type)
777 {
778 case SRC_WIN:
779 name = SRC_NAME;
780 break;
781 case CMD_WIN:
782 name = CMD_NAME;
783 break;
784 case DISASSEM_WIN:
785 name = DISASSEM_NAME;
786 break;
787 case DATA_WIN:
788 name = DATA_NAME;
789 break;
790 default:
791 name = "";
792 break;
793 }
794
795 return name;
796} /* winName */
797
798
799/*
c5aa993b
JM
800 ** initializeStaticData
801 */
c906108c 802void
c906108c 803initializeStaticData (void)
c906108c
SS
804{
805 initGenericPart (sourceExecInfoWinPtr ());
806 initGenericPart (disassemExecInfoWinPtr ());
807 initGenericPart (locatorWinInfoPtr ());
808
809 return;
810} /* initializeStaticData */
811
812
813/*
c5aa993b
JM
814 ** allocGenericWinInfo().
815 */
c906108c 816TuiGenWinInfoPtr
c906108c 817allocGenericWinInfo (void)
c906108c
SS
818{
819 TuiGenWinInfoPtr win;
820
821 if ((win = (TuiGenWinInfoPtr) xmalloc (
822 sizeof (TuiGenWinInfoPtr))) != (TuiGenWinInfoPtr) NULL)
823 initGenericPart (win);
824
825 return win;
826} /* allocGenericWinInfo */
827
828
829/*
c5aa993b
JM
830 ** initGenericPart().
831 */
c906108c 832void
eca6576c 833initGenericPart (TuiGenWinInfoPtr win)
c906108c
SS
834{
835 win->width =
836 win->height =
837 win->origin.x =
838 win->origin.y =
839 win->viewportHeight =
840 win->contentSize =
841 win->lastVisibleLine = 0;
842 win->handle = (WINDOW *) NULL;
843 win->content = (OpaquePtr) NULL;
844 win->contentInUse =
845 win->isVisible = FALSE;
bc6b7f04
SC
846 win->title = 0;
847}
c906108c
SS
848
849
850/*
c5aa993b
JM
851 ** initContentElement().
852 */
c906108c 853void
eca6576c 854initContentElement (TuiWinElementPtr element, TuiWinType type)
c906108c
SS
855{
856 element->highlight = FALSE;
857 switch (type)
858 {
859 case SRC_WIN:
860 case DISASSEM_WIN:
861 element->whichElement.source.line = (char *) NULL;
862 element->whichElement.source.lineOrAddr.lineNo = 0;
863 element->whichElement.source.isExecPoint = FALSE;
864 element->whichElement.source.hasBreak = FALSE;
865 break;
866 case DATA_WIN:
867 initGenericPart (&element->whichElement.dataWindow);
868 element->whichElement.dataWindow.type = DATA_ITEM_WIN;
869 ((TuiGenWinInfoPtr) & element->whichElement.dataWindow)->content =
870 (OpaquePtr) allocContent (1, DATA_ITEM_WIN);
871 ((TuiGenWinInfoPtr)
872 & element->whichElement.dataWindow)->contentSize = 1;
873 break;
874 case CMD_WIN:
875 element->whichElement.command.line = (char *) NULL;
876 break;
877 case DATA_ITEM_WIN:
878 element->whichElement.data.name = (char *) NULL;
879 element->whichElement.data.type = TUI_REGISTER;
880 element->whichElement.data.itemNo = UNDEFINED_ITEM;
881 element->whichElement.data.value = (Opaque) NULL;
882 element->whichElement.data.highlight = FALSE;
883 break;
884 case LOCATOR_WIN:
885 element->whichElement.locator.fileName[0] =
886 element->whichElement.locator.procName[0] = (char) 0;
887 element->whichElement.locator.lineNo = 0;
888 element->whichElement.locator.addr = 0;
889 break;
890 case EXEC_INFO_WIN:
00b2bad4
SC
891 memset(element->whichElement.simpleString, ' ',
892 sizeof(element->whichElement.simpleString));
c906108c
SS
893 break;
894 default:
895 break;
896 }
897 return;
898} /* initContentElement */
899
900/*
c5aa993b
JM
901 ** initWinInfo().
902 */
c906108c 903void
eca6576c 904initWinInfo (TuiWinInfoPtr winInfo)
c906108c
SS
905{
906 initGenericPart (&winInfo->generic);
907 winInfo->canHighlight =
908 winInfo->isHighlighted = FALSE;
909 switch (winInfo->generic.type)
910 {
911 case SRC_WIN:
912 case DISASSEM_WIN:
913 winInfo->detail.sourceInfo.executionInfo = (TuiGenWinInfoPtr) NULL;
914 winInfo->detail.sourceInfo.hasLocator = FALSE;
915 winInfo->detail.sourceInfo.horizontalOffset = 0;
a4b99e53 916 winInfo->detail.sourceInfo.startLineOrAddr.addr = 0;
bc6b7f04 917 winInfo->detail.sourceInfo.filename = 0;
c906108c
SS
918 break;
919 case DATA_WIN:
920 winInfo->detail.dataDisplayInfo.dataContent = (TuiWinContent) NULL;
921 winInfo->detail.dataDisplayInfo.dataContentCount = 0;
922 winInfo->detail.dataDisplayInfo.regsContent = (TuiWinContent) NULL;
923 winInfo->detail.dataDisplayInfo.regsContentCount = 0;
924 winInfo->detail.dataDisplayInfo.regsDisplayType =
925 TUI_UNDEFINED_REGS;
926 winInfo->detail.dataDisplayInfo.regsColumnCount = 1;
927 winInfo->detail.dataDisplayInfo.displayRegs = FALSE;
928 break;
929 case CMD_WIN:
930 winInfo->detail.commandInfo.curLine = 0;
931 winInfo->detail.commandInfo.curch = 0;
932 break;
933 default:
934 winInfo->detail.opaque = (Opaque) NULL;
935 break;
936 }
937
938 return;
939} /* initWinInfo */
940
941
942/*
c5aa993b
JM
943 ** allocWinInfo().
944 */
c906108c 945TuiWinInfoPtr
eca6576c 946allocWinInfo (TuiWinType type)
c906108c
SS
947{
948 TuiWinInfoPtr winInfo = (TuiWinInfoPtr) NULL;
949
950 winInfo = (TuiWinInfoPtr) xmalloc (sizeof (TuiWinInfo));
951 if (m_winPtrNotNull (winInfo))
952 {
953 winInfo->generic.type = type;
954 initWinInfo (winInfo);
955 }
956
957 return winInfo;
958} /* allocWinInfo */
959
960
961/*
c5aa993b
JM
962 ** allocContent().
963 ** Allocates the content and elements in a block.
964 */
c906108c 965TuiWinContent
eca6576c 966allocContent (int numElements, TuiWinType type)
c906108c
SS
967{
968 TuiWinContent content = (TuiWinContent) NULL;
969 char *elementBlockPtr = (char *) NULL;
970 int i;
971
972 if ((content = (TuiWinContent)
973 xmalloc (sizeof (TuiWinElementPtr) * numElements)) != (TuiWinContent) NULL)
974 { /*
c5aa993b
JM
975 ** All windows, except the data window, can allocate the elements
976 ** in a chunk. The data window cannot because items can be
977 ** added/removed from the data display by the user at any time.
978 */
c906108c
SS
979 if (type != DATA_WIN)
980 {
981 if ((elementBlockPtr = (char *)
982 xmalloc (sizeof (TuiWinElement) * numElements)) != (char *) NULL)
983 {
984 for (i = 0; i < numElements; i++)
985 {
986 content[i] = (TuiWinElementPtr) elementBlockPtr;
987 initContentElement (content[i], type);
988 elementBlockPtr += sizeof (TuiWinElement);
989 }
990 }
991 else
992 {
993 tuiFree ((char *) content);
994 content = (TuiWinContent) NULL;
995 }
996 }
997 }
998
999 return content;
1000} /* allocContent */
1001
1002
1003/*
c5aa993b
JM
1004 ** addContentElements().
1005 ** Adds the input number of elements to the windows's content. If
1006 ** no content has been allocated yet, allocContent() is called to
1007 ** do this. The index of the first element added is returned,
1008 ** unless there is a memory allocation error, in which case, (-1)
1009 ** is returned.
1010 */
c906108c 1011int
eca6576c 1012addContentElements (TuiGenWinInfoPtr winInfo, int numElements)
c906108c
SS
1013{
1014 TuiWinElementPtr elementPtr;
1015 int i, indexStart;
1016
1017 if (winInfo->content == (OpaquePtr) NULL)
1018 {
1019 winInfo->content = (OpaquePtr) allocContent (numElements, winInfo->type);
1020 indexStart = 0;
1021 }
1022 else
1023 indexStart = winInfo->contentSize;
1024 if (winInfo->content != (OpaquePtr) NULL)
1025 {
1026 for (i = indexStart; (i < numElements + indexStart); i++)
1027 {
1028 if ((elementPtr = (TuiWinElementPtr)
1029 xmalloc (sizeof (TuiWinElement))) != (TuiWinElementPtr) NULL)
1030 {
1031 winInfo->content[i] = (Opaque) elementPtr;
1032 initContentElement (elementPtr, winInfo->type);
1033 winInfo->contentSize++;
1034 }
c5aa993b 1035 else /* things must be really hosed now! We ran out of memory!? */
c906108c
SS
1036 return (-1);
1037 }
1038 }
1039
1040 return indexStart;
1041} /* addContentElements */
1042
1043
bc6b7f04
SC
1044/* Delete all curses windows associated with winInfo, leaving everything
1045 else intact. */
c906108c 1046void
eca6576c 1047tuiDelWindow (TuiWinInfoPtr winInfo)
c906108c 1048{
c906108c
SS
1049 TuiGenWinInfoPtr genericWin;
1050
c906108c
SS
1051 switch (winInfo->generic.type)
1052 {
1053 case SRC_WIN:
1054 case DISASSEM_WIN:
1055 genericWin = locatorWinInfoPtr ();
1056 if (genericWin != (TuiGenWinInfoPtr) NULL)
1057 {
1058 tuiDelwin (genericWin->handle);
1059 genericWin->handle = (WINDOW *) NULL;
1060 genericWin->isVisible = FALSE;
1061 }
bc6b7f04
SC
1062 if (winInfo->detail.sourceInfo.filename)
1063 {
1064 xfree (winInfo->detail.sourceInfo.filename);
1065 winInfo->detail.sourceInfo.filename = 0;
1066 }
c906108c
SS
1067 genericWin = winInfo->detail.sourceInfo.executionInfo;
1068 if (genericWin != (TuiGenWinInfoPtr) NULL)
1069 {
1070 tuiDelwin (genericWin->handle);
1071 genericWin->handle = (WINDOW *) NULL;
1072 genericWin->isVisible = FALSE;
1073 }
1074 break;
1075 case DATA_WIN:
1076 if (winInfo->generic.content != (OpaquePtr) NULL)
1077 {
bc6b7f04
SC
1078 tuiDelDataWindows (winInfo->detail.dataDisplayInfo.regsContent,
1079 winInfo->detail.dataDisplayInfo.regsContentCount);
1080 tuiDelDataWindows (winInfo->detail.dataDisplayInfo.dataContent,
1081 winInfo->detail.dataDisplayInfo.dataContentCount);
c906108c
SS
1082 }
1083 break;
1084 default:
1085 break;
1086 }
1087 if (winInfo->generic.handle != (WINDOW *) NULL)
1088 {
1089 tuiDelwin (winInfo->generic.handle);
1090 winInfo->generic.handle = (WINDOW *) NULL;
1091 winInfo->generic.isVisible = FALSE;
1092 }
bc6b7f04 1093}
c906108c
SS
1094
1095
1096/*
c5aa993b
JM
1097 ** freeWindow().
1098 */
c906108c 1099void
eca6576c 1100freeWindow (TuiWinInfoPtr winInfo)
c906108c 1101{
c906108c
SS
1102 TuiGenWinInfoPtr genericWin;
1103
c906108c
SS
1104 switch (winInfo->generic.type)
1105 {
1106 case SRC_WIN:
1107 case DISASSEM_WIN:
1108 genericWin = locatorWinInfoPtr ();
1109 if (genericWin != (TuiGenWinInfoPtr) NULL)
1110 {
1111 tuiDelwin (genericWin->handle);
1112 genericWin->handle = (WINDOW *) NULL;
1113 }
1114 freeWinContent (genericWin);
bc6b7f04
SC
1115 if (winInfo->detail.sourceInfo.filename)
1116 {
1117 xfree (winInfo->detail.sourceInfo.filename);
1118 winInfo->detail.sourceInfo.filename = 0;
1119 }
c906108c
SS
1120 genericWin = winInfo->detail.sourceInfo.executionInfo;
1121 if (genericWin != (TuiGenWinInfoPtr) NULL)
1122 {
1123 tuiDelwin (genericWin->handle);
1124 genericWin->handle = (WINDOW *) NULL;
1125 freeWinContent (genericWin);
1126 }
1127 break;
1128 case DATA_WIN:
1129 if (winInfo->generic.content != (OpaquePtr) NULL)
1130 {
1131 freeDataContent (
1132 winInfo->detail.dataDisplayInfo.regsContent,
1133 winInfo->detail.dataDisplayInfo.regsContentCount);
1134 winInfo->detail.dataDisplayInfo.regsContent =
1135 (TuiWinContent) NULL;
1136 winInfo->detail.dataDisplayInfo.regsContentCount = 0;
1137 freeDataContent (
1138 winInfo->detail.dataDisplayInfo.dataContent,
1139 winInfo->detail.dataDisplayInfo.dataContentCount);
1140 winInfo->detail.dataDisplayInfo.dataContent =
1141 (TuiWinContent) NULL;
1142 winInfo->detail.dataDisplayInfo.dataContentCount = 0;
1143 winInfo->detail.dataDisplayInfo.regsDisplayType =
1144 TUI_UNDEFINED_REGS;
1145 winInfo->detail.dataDisplayInfo.regsColumnCount = 1;
1146 winInfo->detail.dataDisplayInfo.displayRegs = FALSE;
1147 winInfo->generic.content = (OpaquePtr) NULL;
1148 winInfo->generic.contentSize = 0;
1149 }
1150 break;
1151 default:
1152 break;
1153 }
1154 if (winInfo->generic.handle != (WINDOW *) NULL)
1155 {
1156 tuiDelwin (winInfo->generic.handle);
1157 winInfo->generic.handle = (WINDOW *) NULL;
1158 freeWinContent (&winInfo->generic);
1159 }
bc6b7f04
SC
1160 if (winInfo->generic.title)
1161 xfree (winInfo->generic.title);
b8c9b27d 1162 xfree (winInfo);
bc6b7f04 1163}
c906108c
SS
1164
1165
1166/*
c5aa993b
JM
1167 ** freeAllSourceWinsContent().
1168 */
c906108c 1169void
c906108c 1170freeAllSourceWinsContent (void)
c906108c
SS
1171{
1172 int i;
1173
1174 for (i = 0; i < (sourceWindows ())->count; i++)
1175 {
1176 TuiWinInfoPtr winInfo = (TuiWinInfoPtr) (sourceWindows ())->list[i];
1177
1178 if (m_winPtrNotNull (winInfo))
1179 {
1180 freeWinContent (&(winInfo->generic));
1181 freeWinContent (winInfo->detail.sourceInfo.executionInfo);
1182 }
1183 }
1184
1185 return;
1186} /* freeAllSourceWinsContent */
1187
1188
1189/*
c5aa993b
JM
1190 ** freeWinContent().
1191 */
c906108c 1192void
eca6576c 1193freeWinContent (TuiGenWinInfoPtr winInfo)
c906108c
SS
1194{
1195 if (winInfo->content != (OpaquePtr) NULL)
1196 {
1197 freeContent ((TuiWinContent) winInfo->content,
1198 winInfo->contentSize,
1199 winInfo->type);
1200 winInfo->content = (OpaquePtr) NULL;
1201 }
1202 winInfo->contentSize = 0;
1203
1204 return;
1205} /* freeWinContent */
1206
1207
1208/*
c5aa993b
JM
1209 ** freeAllWindows().
1210 */
c906108c 1211void
c906108c 1212freeAllWindows (void)
c906108c
SS
1213{
1214 TuiWinType type = SRC_WIN;
1215
1216 for (; type < MAX_MAJOR_WINDOWS; type++)
1217 if (m_winPtrNotNull (winList[type]) &&
1218 winList[type]->generic.type != UNDEFINED_WIN)
1219 freeWindow (winList[type]);
1220 return;
1221} /* freeAllWindows */
1222
1223
1224void
eca6576c 1225tuiDelDataWindows (TuiWinContent content, int contentSize)
c906108c
SS
1226{
1227 int i;
1228
1229 /*
c5aa993b
JM
1230 ** Remember that data window content elements are of type TuiGenWinInfoPtr,
1231 ** each of which whose single element is a data element.
1232 */
c906108c
SS
1233 for (i = 0; i < contentSize; i++)
1234 {
1235 TuiGenWinInfoPtr genericWin = &content[i]->whichElement.dataWindow;
1236
1237 if (genericWin != (TuiGenWinInfoPtr) NULL)
1238 {
1239 tuiDelwin (genericWin->handle);
1240 genericWin->handle = (WINDOW *) NULL;
1241 genericWin->isVisible = FALSE;
1242 }
1243 }
1244
1245 return;
1246} /* tuiDelDataWindows */
1247
1248
1249void
eca6576c 1250freeDataContent (TuiWinContent content, int contentSize)
c906108c
SS
1251{
1252 int i;
1253
1254 /*
c5aa993b
JM
1255 ** Remember that data window content elements are of type TuiGenWinInfoPtr,
1256 ** each of which whose single element is a data element.
1257 */
c906108c
SS
1258 for (i = 0; i < contentSize; i++)
1259 {
1260 TuiGenWinInfoPtr genericWin = &content[i]->whichElement.dataWindow;
1261
1262 if (genericWin != (TuiGenWinInfoPtr) NULL)
1263 {
1264 tuiDelwin (genericWin->handle);
1265 genericWin->handle = (WINDOW *) NULL;
1266 freeWinContent (genericWin);
1267 }
1268 }
1269 freeContent (content,
1270 contentSize,
1271 DATA_WIN);
1272
1273 return;
1274} /* freeDataContent */
1275
1276
1277/**********************************
1278** LOCAL STATIC FUNCTIONS **
1279**********************************/
1280
1281
1282/*
c5aa993b
JM
1283 ** freeContent().
1284 */
c906108c 1285static void
eca6576c 1286freeContent (TuiWinContent content, int contentSize, TuiWinType winType)
c906108c
SS
1287{
1288 if (content != (TuiWinContent) NULL)
1289 {
1290 freeContentElements (content, contentSize, winType);
1291 tuiFree ((char *) content);
1292 }
1293
1294 return;
1295} /* freeContent */
1296
1297
1298/*
c5aa993b
JM
1299 ** freeContentElements().
1300 */
c906108c 1301static void
eca6576c 1302freeContentElements (TuiWinContent content, int contentSize, TuiWinType type)
c906108c
SS
1303{
1304 if (content != (TuiWinContent) NULL)
1305 {
1306 int i;
1307
1308 if (type == SRC_WIN || type == DISASSEM_WIN)
1309 {
1310 /* free whole source block */
1311 if (content[0]->whichElement.source.line != (char *) NULL)
1312 tuiFree (content[0]->whichElement.source.line);
1313 }
1314 else
1315 {
1316 for (i = 0; i < contentSize; i++)
1317 {
1318 TuiWinElementPtr element;
1319
1320 element = content[i];
1321 if (element != (TuiWinElementPtr) NULL)
1322 {
1323 switch (type)
1324 {
1325 case DATA_WIN:
1326 tuiFree ((char *) element);
1327 break;
1328 case DATA_ITEM_WIN:
1329 /*
c5aa993b
JM
1330 ** Note that data elements are not allocated
1331 ** in a single block, but individually, as needed.
1332 */
c906108c
SS
1333 if (element->whichElement.data.type != TUI_REGISTER)
1334 tuiFree ((char *)
1335 element->whichElement.data.name);
1336 tuiFree ((char *) element->whichElement.data.value);
1337 tuiFree ((char *) element);
1338 break;
1339 case CMD_WIN:
1340 tuiFree ((char *) element->whichElement.command.line);
1341 break;
1342 default:
1343 break;
1344 }
1345 }
1346 }
1347 }
1348 if (type != DATA_WIN && type != DATA_ITEM_WIN)
1349 tuiFree ((char *) content[0]); /* free the element block */
1350 }
1351
1352 return;
1353} /* freeContentElements */
This page took 0.311123 seconds and 4 git commands to generate.