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