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