2001-07-17 Elena Zannoni <ezannoni@redhat.com>
[binutils-gdb.git] / gdb / tui / tuiData.c
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. */
21
22 #include "defs.h"
23 #include "tui.h"
24 #include "tuiData.h"
25
26 /****************************
27 ** GLOBAL DECLARATIONS
28 ****************************/
29 TuiWinInfoPtr 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 ****************************/
42 static char *_tuiNullStr = TUI_NULL_STR;
43 static char *_tuiBlankStr = " ";
44 static char *_tuiLocationStr = " >";
45 static char *_tuiBreakStr = " * ";
46 static char *_tuiBreakLocationStr = " *>";
47 static TuiLayoutType _currentLayout = UNDEFINED_LAYOUT;
48 static int _termHeight, _termWidth;
49 static int _historyLimit = DEFAULT_HISTORY_COUNT;
50 static TuiGenWinInfo _locator;
51 static TuiGenWinInfo _execInfo[2];
52 static TuiWinInfoPtr _srcWinList[2];
53 static TuiList _sourceWindows =
54 {(OpaqueList) _srcWinList, 0};
55 static int _defaultTabLen = DEFAULT_TAB_LEN;
56 static TuiWinInfoPtr _winWithFocus = (TuiWinInfoPtr) NULL;
57 static TuiLayoutDef _layoutDef =
58 {SRC_WIN, /* displayMode */
59 FALSE, /* split */
60 TUI_UNDEFINED_REGS, /* regsDisplayType */
61 TUI_SFLOAT_REGS}; /* floatRegsDisplayType */
62 static int _winResized = FALSE;
63
64
65 /*********************************
66 ** Static function forward decls
67 **********************************/
68 static void freeContent (TuiWinContent, int, TuiWinType);
69 static void freeContentElements (TuiWinContent, int, TuiWinType);
70
71
72
73 /*********************************
74 ** PUBLIC FUNCTIONS
75 **********************************/
76
77 /******************************************
78 ** ACCESSORS & MUTATORS FOR PRIVATE DATA
79 ******************************************/
80
81 /*
82 ** tuiWinResized().
83 ** Answer a whether the terminal window has been resized or not
84 */
85 int
86 tuiWinResized (void)
87 {
88 return _winResized;
89 } /* tuiWinResized */
90
91
92 /*
93 ** tuiSetWinResized().
94 ** Set a whether the terminal window has been resized or not
95 */
96 void
97 tuiSetWinResizedTo (int resized)
98 {
99 _winResized = resized;
100
101 return;
102 } /* tuiSetWinResizedTo */
103
104
105 /*
106 ** tuiLayoutDef().
107 ** Answer a pointer to the current layout definition
108 */
109 TuiLayoutDefPtr
110 tuiLayoutDef (void)
111 {
112 return &_layoutDef;
113 } /* tuiLayoutDef */
114
115
116 /*
117 ** tuiWinWithFocus().
118 ** Answer the window with the logical focus
119 */
120 TuiWinInfoPtr
121 tuiWinWithFocus (void)
122 {
123 return _winWithFocus;
124 } /* tuiWinWithFocus */
125
126
127 /*
128 ** tuiSetWinWithFocus().
129 ** Set the window that has the logical focus
130 */
131 void
132 tuiSetWinWithFocus (TuiWinInfoPtr winInfo)
133 {
134 _winWithFocus = winInfo;
135
136 return;
137 } /* tuiSetWinWithFocus */
138
139
140 /*
141 ** tuiDefaultTabLen().
142 ** Answer the length in chars, of tabs
143 */
144 int
145 tuiDefaultTabLen (void)
146 {
147 return _defaultTabLen;
148 } /* tuiDefaultTabLen */
149
150
151 /*
152 ** tuiSetDefaultTabLen().
153 ** Set the length in chars, of tabs
154 */
155 void
156 tuiSetDefaultTabLen (int len)
157 {
158 _defaultTabLen = len;
159
160 return;
161 } /* tuiSetDefaultTabLen */
162
163
164 /*
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 */
170 TuiListPtr
171 sourceWindows (void)
172 {
173 return &_sourceWindows;
174 } /* currentSourceWindows */
175
176
177 /*
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 */
183 void
184 clearSourceWindows (void)
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 /*
195 ** clearSourceWindowsDetail()
196 ** Clear the pertinant detail in the source windows.
197 */
198 void
199 clearSourceWindowsDetail (void)
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 /*
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 */
216 void
217 addToSourceWindows (TuiWinInfoPtr winInfo)
218 {
219 if (_sourceWindows.count < 2)
220 _sourceWindows.list[_sourceWindows.count++] = (Opaque) winInfo;
221
222 return;
223 } /* addToSourceWindows */
224
225
226 /*
227 ** clearWinDetail()
228 ** Clear the pertinant detail in the windows.
229 */
230 void
231 clearWinDetail (TuiWinInfoPtr winInfo)
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 /*
268 ** blankStr()
269 ** Accessor for the blank string.
270 */
271 char *
272 blankStr (void)
273 {
274 return _tuiBlankStr;
275 } /* blankStr */
276
277
278 /*
279 ** locationStr()
280 ** Accessor for the location string.
281 */
282 char *
283 locationStr (void)
284 {
285 return _tuiLocationStr;
286 } /* locationStr */
287
288
289 /*
290 ** breakStr()
291 ** Accessor for the break string.
292 */
293 char *
294 breakStr (void)
295 {
296 return _tuiBreakStr;
297 } /* breakStr */
298
299
300 /*
301 ** breakLocationStr()
302 ** Accessor for the breakLocation string.
303 */
304 char *
305 breakLocationStr (void)
306 {
307 return _tuiBreakLocationStr;
308 } /* breakLocationStr */
309
310
311 /*
312 ** nullStr()
313 ** Accessor for the null string.
314 */
315 char *
316 nullStr (void)
317 {
318 return _tuiNullStr;
319 } /* nullStr */
320
321
322 /*
323 ** sourceExecInfoPtr().
324 ** Accessor for the source execution info ptr.
325 */
326 TuiGenWinInfoPtr
327 sourceExecInfoWinPtr (void)
328 {
329 return &_execInfo[0];
330 } /* sourceExecInfoWinPtr */
331
332
333 /*
334 ** disassemExecInfoPtr().
335 ** Accessor for the disassem execution info ptr.
336 */
337 TuiGenWinInfoPtr
338 disassemExecInfoWinPtr (void)
339 {
340 return &_execInfo[1];
341 } /* disassemExecInfoWinPtr */
342
343
344 /*
345 ** locatorWinInfoPtr().
346 ** Accessor for the locator win info. Answers a pointer to the
347 ** static locator win info struct.
348 */
349 TuiGenWinInfoPtr
350 locatorWinInfoPtr (void)
351 {
352 return &_locator;
353 } /* locatorWinInfoPtr */
354
355
356 /*
357 ** historyLimit().
358 ** Accessor for the history limit
359 */
360 int
361 historyLimit (void)
362 {
363 return _historyLimit;
364 } /* historyLimit */
365
366
367 /*
368 ** setHistoryLimitTo().
369 ** Mutator for the history limit
370 */
371 void
372 setHistoryLimitTo (int h)
373 {
374 _historyLimit = h;
375
376 return;
377 } /* setHistoryLimitTo */
378
379 /*
380 ** termHeight().
381 ** Accessor for the termHeight
382 */
383 int
384 termHeight (void)
385 {
386 return _termHeight;
387 } /* termHeight */
388
389
390 /*
391 ** setTermHeightTo().
392 ** Mutator for the term height
393 */
394 void
395 setTermHeightTo (int h)
396 {
397 _termHeight = h;
398
399 return;
400 } /* setTermHeightTo */
401
402
403 /*
404 ** termWidth().
405 ** Accessor for the termWidth
406 */
407 int
408 termWidth (void)
409 {
410 return _termWidth;
411 } /* termWidth */
412
413
414 /*
415 ** setTermWidth().
416 ** Mutator for the termWidth
417 */
418 void
419 setTermWidthTo (int w)
420 {
421 _termWidth = w;
422
423 return;
424 } /* setTermWidthTo */
425
426
427 /*
428 ** currentLayout().
429 ** Accessor for the current layout
430 */
431 TuiLayoutType
432 currentLayout (void)
433 {
434 return _currentLayout;
435 } /* currentLayout */
436
437
438 /*
439 ** setCurrentLayoutTo().
440 ** Mutator for the current layout
441 */
442 void
443 setCurrentLayoutTo (TuiLayoutType newLayout)
444 {
445 _currentLayout = newLayout;
446
447 return;
448 } /* setCurrentLayoutTo */
449
450
451 /*
452 ** setGenWinOrigin().
453 ** Set the origin of the window
454 */
455 void
456 setGenWinOrigin (TuiGenWinInfoPtr winInfo, int x, int y)
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 /*
471 ** tuiNextWin().
472 ** Answer the next window in the list, cycling back to the top
473 ** if necessary
474 */
475 TuiWinInfoPtr
476 tuiNextWin (TuiWinInfoPtr curWin)
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 /*
503 ** tuiPrevWin().
504 ** Answer the prev window in the list, cycling back to the bottom
505 ** if necessary
506 */
507 TuiWinInfoPtr
508 tuiPrevWin (TuiWinInfoPtr curWin)
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 /*
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 */
540 char *
541 displayableWinContentOf (TuiGenWinInfoPtr winInfo, TuiWinElementPtr elementPtr)
542 {
543
544 char *string = nullStr ();
545
546 if (elementPtr != (TuiWinElementPtr) NULL || winInfo->type == LOCATOR_WIN)
547 {
548 /*
549 ** Now convert the line to a displayable string
550 */
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 /*
570 ** First determine the amount of file/proc name width
571 ** we have available
572 */
573 i = strSize - (PC_WIDTH + LINE_WIDTH
574 + 25 /* pc and line labels */
575 + strlen (FILE_PREFIX) + 1 /* file label */
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 /*
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 */
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 /*
666 ** winContentAt().
667 ** Answer a the content at the location indicated by index
668 */
669 char *
670 displayableWinContentAt (TuiGenWinInfoPtr winInfo, int index)
671 {
672 return (displayableWinContentOf (winInfo, (TuiWinElementPtr) winInfo->content[index]));
673 } /* winContentAt */
674
675
676 /*
677 ** winElementHeight().
678 ** Answer the height of the element in lines
679 */
680 int
681 winElementHeight (TuiGenWinInfoPtr winInfo, TuiWinElementPtr element)
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 /*
696 ** winByName().
697 ** Answer the window represented by name
698 */
699 TuiWinInfoPtr
700 winByName (char *name)
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 /*
717 ** partialWinByName().
718 ** Answer the window represented by name
719 */
720 TuiWinInfoPtr
721 partialWinByName (char *name)
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 /*
744 ** winName().
745 ** Answer the name of the window
746 */
747 char *
748 winName (TuiGenWinInfoPtr winInfo)
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 /*
776 ** initializeStaticData
777 */
778 void
779 initializeStaticData (void)
780 {
781 initGenericPart (sourceExecInfoWinPtr ());
782 initGenericPart (disassemExecInfoWinPtr ());
783 initGenericPart (locatorWinInfoPtr ());
784
785 return;
786 } /* initializeStaticData */
787
788
789 /*
790 ** allocGenericWinInfo().
791 */
792 TuiGenWinInfoPtr
793 allocGenericWinInfo (void)
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 /*
806 ** initGenericPart().
807 */
808 void
809 initGenericPart (TuiGenWinInfoPtr win)
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 /*
828 ** initContentElement().
829 */
830 void
831 initContentElement (TuiWinElementPtr element, TuiWinType type)
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 /*
877 ** initWinInfo().
878 */
879 void
880 initWinInfo (TuiWinInfoPtr winInfo)
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 /*
918 ** allocWinInfo().
919 */
920 TuiWinInfoPtr
921 allocWinInfo (TuiWinType type)
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 /*
937 ** allocContent().
938 ** Allocates the content and elements in a block.
939 */
940 TuiWinContent
941 allocContent (int numElements, TuiWinType type)
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 { /*
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 */
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 /*
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 */
986 int
987 addContentElements (TuiGenWinInfoPtr winInfo, int numElements)
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 }
1010 else /* things must be really hosed now! We ran out of memory!? */
1011 return (-1);
1012 }
1013 }
1014
1015 return indexStart;
1016 } /* addContentElements */
1017
1018
1019 /*
1020 ** tuiDelWindow().
1021 ** Delete all curses windows associated with winInfo, leaving everything
1022 ** else in tact.
1023 */
1024 void
1025 tuiDelWindow (TuiWinInfoPtr winInfo)
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 /*
1079 ** freeWindow().
1080 */
1081 void
1082 freeWindow (TuiWinInfoPtr winInfo)
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 }
1140 xfree (winInfo);
1141
1142 return;
1143 } /* freeWindow */
1144
1145
1146 /*
1147 ** freeAllSourceWinsContent().
1148 */
1149 void
1150 freeAllSourceWinsContent (void)
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 /*
1170 ** freeWinContent().
1171 */
1172 void
1173 freeWinContent (TuiGenWinInfoPtr winInfo)
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 /*
1189 ** freeAllWindows().
1190 */
1191 void
1192 freeAllWindows (void)
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
1204 void
1205 tuiDelDataWindows (TuiWinContent content, int contentSize)
1206 {
1207 int i;
1208
1209 /*
1210 ** Remember that data window content elements are of type TuiGenWinInfoPtr,
1211 ** each of which whose single element is a data element.
1212 */
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
1229 void
1230 freeDataContent (TuiWinContent content, int contentSize)
1231 {
1232 int i;
1233
1234 /*
1235 ** Remember that data window content elements are of type TuiGenWinInfoPtr,
1236 ** each of which whose single element is a data element.
1237 */
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 /*
1263 ** freeContent().
1264 */
1265 static void
1266 freeContent (TuiWinContent content, int contentSize, TuiWinType winType)
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 /*
1279 ** freeContentElements().
1280 */
1281 static void
1282 freeContentElements (TuiWinContent content, int contentSize, TuiWinType type)
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 /*
1310 ** Note that data elements are not allocated
1311 ** in a single block, but individually, as needed.
1312 */
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 */