* tuiWin.c (_parseScrollingArgs): Fix uninitialized variable.
[deliverable/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 #include "tuiGeneralWin.h"
26
27 /****************************
28 ** GLOBAL DECLARATIONS
29 ****************************/
30 TuiWinInfoPtr 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 ****************************/
43 static char *_tuiNullStr = TUI_NULL_STR;
44 static char *_tuiBlankStr = " ";
45 static char *_tuiLocationStr = " >";
46 static char *_tuiBreakStr = " * ";
47 static char *_tuiBreakLocationStr = " *>";
48 static TuiLayoutType _currentLayout = UNDEFINED_LAYOUT;
49 static int _termHeight, _termWidth;
50 static int _historyLimit = DEFAULT_HISTORY_COUNT;
51 static TuiGenWinInfo _locator;
52 static TuiGenWinInfo _execInfo[2];
53 static TuiWinInfoPtr _srcWinList[2];
54 static TuiList _sourceWindows =
55 {(OpaqueList) _srcWinList, 0};
56 static int _defaultTabLen = DEFAULT_TAB_LEN;
57 static TuiWinInfoPtr _winWithFocus = (TuiWinInfoPtr) NULL;
58 static TuiLayoutDef _layoutDef =
59 {SRC_WIN, /* displayMode */
60 FALSE, /* split */
61 TUI_UNDEFINED_REGS, /* regsDisplayType */
62 TUI_SFLOAT_REGS}; /* floatRegsDisplayType */
63 static int _winResized = FALSE;
64
65
66 /*********************************
67 ** Static function forward decls
68 **********************************/
69 static void freeContent (TuiWinContent, int, TuiWinType);
70 static void freeContentElements (TuiWinContent, int, TuiWinType);
71
72
73
74 /*********************************
75 ** PUBLIC FUNCTIONS
76 **********************************/
77
78 /******************************************
79 ** ACCESSORS & MUTATORS FOR PRIVATE DATA
80 ******************************************/
81
82 /*
83 ** tuiWinResized().
84 ** Answer a whether the terminal window has been resized or not
85 */
86 int
87 tuiWinResized (void)
88 {
89 return _winResized;
90 } /* tuiWinResized */
91
92
93 /*
94 ** tuiSetWinResized().
95 ** Set a whether the terminal window has been resized or not
96 */
97 void
98 tuiSetWinResizedTo (int resized)
99 {
100 _winResized = resized;
101
102 return;
103 } /* tuiSetWinResizedTo */
104
105
106 /*
107 ** tuiLayoutDef().
108 ** Answer a pointer to the current layout definition
109 */
110 TuiLayoutDefPtr
111 tuiLayoutDef (void)
112 {
113 return &_layoutDef;
114 } /* tuiLayoutDef */
115
116
117 /*
118 ** tuiWinWithFocus().
119 ** Answer the window with the logical focus
120 */
121 TuiWinInfoPtr
122 tuiWinWithFocus (void)
123 {
124 return _winWithFocus;
125 } /* tuiWinWithFocus */
126
127
128 /*
129 ** tuiSetWinWithFocus().
130 ** Set the window that has the logical focus
131 */
132 void
133 tuiSetWinWithFocus (TuiWinInfoPtr winInfo)
134 {
135 _winWithFocus = winInfo;
136
137 return;
138 } /* tuiSetWinWithFocus */
139
140
141 /*
142 ** tuiDefaultTabLen().
143 ** Answer the length in chars, of tabs
144 */
145 int
146 tuiDefaultTabLen (void)
147 {
148 return _defaultTabLen;
149 } /* tuiDefaultTabLen */
150
151
152 /*
153 ** tuiSetDefaultTabLen().
154 ** Set the length in chars, of tabs
155 */
156 void
157 tuiSetDefaultTabLen (int len)
158 {
159 _defaultTabLen = len;
160
161 return;
162 } /* tuiSetDefaultTabLen */
163
164
165 /*
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 */
171 TuiListPtr
172 sourceWindows (void)
173 {
174 return &_sourceWindows;
175 } /* currentSourceWindows */
176
177
178 /*
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 */
184 void
185 clearSourceWindows (void)
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 /*
196 ** clearSourceWindowsDetail()
197 ** Clear the pertinant detail in the source windows.
198 */
199 void
200 clearSourceWindowsDetail (void)
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 /*
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 */
217 void
218 addToSourceWindows (TuiWinInfoPtr winInfo)
219 {
220 if (_sourceWindows.count < 2)
221 _sourceWindows.list[_sourceWindows.count++] = (Opaque) winInfo;
222
223 return;
224 } /* addToSourceWindows */
225
226
227 /*
228 ** clearWinDetail()
229 ** Clear the pertinant detail in the windows.
230 */
231 void
232 clearWinDetail (TuiWinInfoPtr winInfo)
233 {
234 if (m_winPtrNotNull (winInfo))
235 {
236 switch (winInfo->generic.type)
237 {
238 case SRC_WIN:
239 case DISASSEM_WIN:
240 winInfo->detail.sourceInfo.startLineOrAddr.addr = 0;
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 /*
269 ** blankStr()
270 ** Accessor for the blank string.
271 */
272 char *
273 blankStr (void)
274 {
275 return _tuiBlankStr;
276 } /* blankStr */
277
278
279 /*
280 ** locationStr()
281 ** Accessor for the location string.
282 */
283 char *
284 locationStr (void)
285 {
286 return _tuiLocationStr;
287 } /* locationStr */
288
289
290 /*
291 ** breakStr()
292 ** Accessor for the break string.
293 */
294 char *
295 breakStr (void)
296 {
297 return _tuiBreakStr;
298 } /* breakStr */
299
300
301 /*
302 ** breakLocationStr()
303 ** Accessor for the breakLocation string.
304 */
305 char *
306 breakLocationStr (void)
307 {
308 return _tuiBreakLocationStr;
309 } /* breakLocationStr */
310
311
312 /*
313 ** nullStr()
314 ** Accessor for the null string.
315 */
316 char *
317 nullStr (void)
318 {
319 return _tuiNullStr;
320 } /* nullStr */
321
322
323 /*
324 ** sourceExecInfoPtr().
325 ** Accessor for the source execution info ptr.
326 */
327 TuiGenWinInfoPtr
328 sourceExecInfoWinPtr (void)
329 {
330 return &_execInfo[0];
331 } /* sourceExecInfoWinPtr */
332
333
334 /*
335 ** disassemExecInfoPtr().
336 ** Accessor for the disassem execution info ptr.
337 */
338 TuiGenWinInfoPtr
339 disassemExecInfoWinPtr (void)
340 {
341 return &_execInfo[1];
342 } /* disassemExecInfoWinPtr */
343
344
345 /*
346 ** locatorWinInfoPtr().
347 ** Accessor for the locator win info. Answers a pointer to the
348 ** static locator win info struct.
349 */
350 TuiGenWinInfoPtr
351 locatorWinInfoPtr (void)
352 {
353 return &_locator;
354 } /* locatorWinInfoPtr */
355
356
357 /*
358 ** historyLimit().
359 ** Accessor for the history limit
360 */
361 int
362 historyLimit (void)
363 {
364 return _historyLimit;
365 } /* historyLimit */
366
367
368 /*
369 ** setHistoryLimitTo().
370 ** Mutator for the history limit
371 */
372 void
373 setHistoryLimitTo (int h)
374 {
375 _historyLimit = h;
376
377 return;
378 } /* setHistoryLimitTo */
379
380 /*
381 ** termHeight().
382 ** Accessor for the termHeight
383 */
384 int
385 termHeight (void)
386 {
387 return _termHeight;
388 } /* termHeight */
389
390
391 /*
392 ** setTermHeightTo().
393 ** Mutator for the term height
394 */
395 void
396 setTermHeightTo (int h)
397 {
398 _termHeight = h;
399
400 return;
401 } /* setTermHeightTo */
402
403
404 /*
405 ** termWidth().
406 ** Accessor for the termWidth
407 */
408 int
409 termWidth (void)
410 {
411 return _termWidth;
412 } /* termWidth */
413
414
415 /*
416 ** setTermWidth().
417 ** Mutator for the termWidth
418 */
419 void
420 setTermWidthTo (int w)
421 {
422 _termWidth = w;
423
424 return;
425 } /* setTermWidthTo */
426
427
428 /*
429 ** currentLayout().
430 ** Accessor for the current layout
431 */
432 TuiLayoutType
433 currentLayout (void)
434 {
435 return _currentLayout;
436 } /* currentLayout */
437
438
439 /*
440 ** setCurrentLayoutTo().
441 ** Mutator for the current layout
442 */
443 void
444 setCurrentLayoutTo (TuiLayoutType newLayout)
445 {
446 _currentLayout = newLayout;
447
448 return;
449 } /* setCurrentLayoutTo */
450
451
452 /*
453 ** setGenWinOrigin().
454 ** Set the origin of the window
455 */
456 void
457 setGenWinOrigin (TuiGenWinInfoPtr winInfo, int x, int y)
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 /*
472 ** tuiNextWin().
473 ** Answer the next window in the list, cycling back to the top
474 ** if necessary
475 */
476 TuiWinInfoPtr
477 tuiNextWin (TuiWinInfoPtr curWin)
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 {
488 if (winList[type] && winList[type]->generic.isVisible)
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 /*
504 ** tuiPrevWin().
505 ** Answer the prev window in the list, cycling back to the bottom
506 ** if necessary
507 */
508 TuiWinInfoPtr
509 tuiPrevWin (TuiWinInfoPtr curWin)
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 /*
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 */
541 char *
542 displayableWinContentOf (TuiGenWinInfoPtr winInfo, TuiWinElementPtr elementPtr)
543 {
544
545 char *string = nullStr ();
546
547 if (elementPtr != (TuiWinElementPtr) NULL || winInfo->type == LOCATOR_WIN)
548 {
549 /*
550 ** Now convert the line to a displayable string
551 */
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 /*
571 ** First determine the amount of file/proc name width
572 ** we have available
573 */
574 i = strSize - (PC_WIDTH + LINE_WIDTH
575 + 25 /* pc and line labels */
576 + strlen (FILE_PREFIX) + 1 /* file label */
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 &&
608 elementPtr->whichElement.locator.addr != 0)
609 sprintf (pc, "0x%lx",
610 (long) elementPtr->whichElement.locator.addr);
611 else
612 strcpy (pc, "??");
613 /*
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 */
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 /*
667 ** winContentAt().
668 ** Answer a the content at the location indicated by index
669 */
670 char *
671 displayableWinContentAt (TuiGenWinInfoPtr winInfo, int index)
672 {
673 return (displayableWinContentOf (winInfo, (TuiWinElementPtr) winInfo->content[index]));
674 } /* winContentAt */
675
676
677 /*
678 ** winElementHeight().
679 ** Answer the height of the element in lines
680 */
681 int
682 winElementHeight (TuiGenWinInfoPtr winInfo, TuiWinElementPtr element)
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 /*
697 ** winByName().
698 ** Answer the window represented by name
699 */
700 TuiWinInfoPtr
701 winByName (char *name)
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 /*
718 ** partialWinByName().
719 ** Answer the window represented by name
720 */
721 TuiWinInfoPtr
722 partialWinByName (char *name)
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 {
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 }
739 i++;
740 }
741 }
742
743 return winInfo;
744 } /* partialWinByName */
745
746
747 /*
748 ** winName().
749 ** Answer the name of the window
750 */
751 char *
752 winName (TuiGenWinInfoPtr winInfo)
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 /*
780 ** initializeStaticData
781 */
782 void
783 initializeStaticData (void)
784 {
785 initGenericPart (sourceExecInfoWinPtr ());
786 initGenericPart (disassemExecInfoWinPtr ());
787 initGenericPart (locatorWinInfoPtr ());
788
789 return;
790 } /* initializeStaticData */
791
792
793 /*
794 ** allocGenericWinInfo().
795 */
796 TuiGenWinInfoPtr
797 allocGenericWinInfo (void)
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 /*
810 ** initGenericPart().
811 */
812 void
813 initGenericPart (TuiGenWinInfoPtr win)
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 /*
832 ** initContentElement().
833 */
834 void
835 initContentElement (TuiWinElementPtr element, TuiWinType type)
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 /*
881 ** initWinInfo().
882 */
883 void
884 initWinInfo (TuiWinInfoPtr winInfo)
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;
896 winInfo->detail.sourceInfo.startLineOrAddr.addr = 0;
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 /*
922 ** allocWinInfo().
923 */
924 TuiWinInfoPtr
925 allocWinInfo (TuiWinType type)
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 /*
941 ** allocContent().
942 ** Allocates the content and elements in a block.
943 */
944 TuiWinContent
945 allocContent (int numElements, TuiWinType type)
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 { /*
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 */
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 /*
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 */
990 int
991 addContentElements (TuiGenWinInfoPtr winInfo, int numElements)
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 }
1014 else /* things must be really hosed now! We ran out of memory!? */
1015 return (-1);
1016 }
1017 }
1018
1019 return indexStart;
1020 } /* addContentElements */
1021
1022
1023 /*
1024 ** tuiDelWindow().
1025 ** Delete all curses windows associated with winInfo, leaving everything
1026 ** else in tact.
1027 */
1028 void
1029 tuiDelWindow (TuiWinInfoPtr winInfo)
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 /*
1083 ** freeWindow().
1084 */
1085 void
1086 freeWindow (TuiWinInfoPtr winInfo)
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 }
1144 xfree (winInfo);
1145
1146 return;
1147 } /* freeWindow */
1148
1149
1150 /*
1151 ** freeAllSourceWinsContent().
1152 */
1153 void
1154 freeAllSourceWinsContent (void)
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 /*
1174 ** freeWinContent().
1175 */
1176 void
1177 freeWinContent (TuiGenWinInfoPtr winInfo)
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 /*
1193 ** freeAllWindows().
1194 */
1195 void
1196 freeAllWindows (void)
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
1208 void
1209 tuiDelDataWindows (TuiWinContent content, int contentSize)
1210 {
1211 int i;
1212
1213 /*
1214 ** Remember that data window content elements are of type TuiGenWinInfoPtr,
1215 ** each of which whose single element is a data element.
1216 */
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
1233 void
1234 freeDataContent (TuiWinContent content, int contentSize)
1235 {
1236 int i;
1237
1238 /*
1239 ** Remember that data window content elements are of type TuiGenWinInfoPtr,
1240 ** each of which whose single element is a data element.
1241 */
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 /*
1267 ** freeContent().
1268 */
1269 static void
1270 freeContent (TuiWinContent content, int contentSize, TuiWinType winType)
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 /*
1283 ** freeContentElements().
1284 */
1285 static void
1286 freeContentElements (TuiWinContent content, int contentSize, TuiWinType type)
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 /*
1314 ** Note that data elements are not allocated
1315 ** in a single block, but individually, as needed.
1316 */
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.05681 seconds and 4 git commands to generate.