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