Commit | Line | Data |
---|---|---|
f377b406 | 1 | /* TUI data manipulation routines. |
f33c6cbf AC |
2 | |
3 | Copyright 1998, 1999, 2000, 2001, 2002 Free Software Foundation, | |
4 | Inc. | |
5 | ||
f377b406 SC |
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. */ | |
c906108c | 24 | |
f33c6cbf AC |
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 | ||
4e8f7a8b DJ |
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 | ||
c906108c | 42 | #include "defs.h" |
cb50eddd | 43 | #include "symtab.h" |
c906108c SS |
44 | #include "tui.h" |
45 | #include "tuiData.h" | |
a4b99e53 | 46 | #include "tuiGeneralWin.h" |
c906108c SS |
47 | |
48 | /**************************** | |
49 | ** GLOBAL DECLARATIONS | |
50 | ****************************/ | |
51 | TuiWinInfoPtr winList[MAX_MAJOR_WINDOWS]; | |
52 | ||
c906108c SS |
53 | /*************************** |
54 | ** Private data | |
55 | ****************************/ | |
c906108c SS |
56 | static TuiLayoutType _currentLayout = UNDEFINED_LAYOUT; |
57 | static int _termHeight, _termWidth; | |
c906108c SS |
58 | static TuiGenWinInfo _locator; |
59 | static TuiGenWinInfo _execInfo[2]; | |
60 | static TuiWinInfoPtr _srcWinList[2]; | |
61 | static TuiList _sourceWindows = | |
62 | {(OpaqueList) _srcWinList, 0}; | |
63 | static int _defaultTabLen = DEFAULT_TAB_LEN; | |
64 | static TuiWinInfoPtr _winWithFocus = (TuiWinInfoPtr) NULL; | |
65 | static TuiLayoutDef _layoutDef = | |
66 | {SRC_WIN, /* displayMode */ | |
67 | FALSE, /* split */ | |
68 | TUI_UNDEFINED_REGS, /* regsDisplayType */ | |
69 | TUI_SFLOAT_REGS}; /* floatRegsDisplayType */ | |
70 | static int _winResized = FALSE; | |
71 | ||
72 | ||
73 | /********************************* | |
74 | ** Static function forward decls | |
75 | **********************************/ | |
a14ed312 KB |
76 | static void freeContent (TuiWinContent, int, TuiWinType); |
77 | static void freeContentElements (TuiWinContent, int, TuiWinType); | |
c906108c SS |
78 | |
79 | ||
80 | ||
81 | /********************************* | |
82 | ** PUBLIC FUNCTIONS | |
83 | **********************************/ | |
84 | ||
85 | /****************************************** | |
86 | ** ACCESSORS & MUTATORS FOR PRIVATE DATA | |
87 | ******************************************/ | |
88 | ||
89 | /* | |
c5aa993b JM |
90 | ** tuiWinResized(). |
91 | ** Answer a whether the terminal window has been resized or not | |
92 | */ | |
c906108c | 93 | int |
c906108c | 94 | tuiWinResized (void) |
c906108c SS |
95 | { |
96 | return _winResized; | |
97 | } /* tuiWinResized */ | |
98 | ||
99 | ||
100 | /* | |
c5aa993b JM |
101 | ** tuiSetWinResized(). |
102 | ** Set a whether the terminal window has been resized or not | |
103 | */ | |
c906108c | 104 | void |
eca6576c | 105 | tuiSetWinResizedTo (int resized) |
c906108c SS |
106 | { |
107 | _winResized = resized; | |
108 | ||
109 | return; | |
110 | } /* tuiSetWinResizedTo */ | |
111 | ||
112 | ||
113 | /* | |
c5aa993b JM |
114 | ** tuiLayoutDef(). |
115 | ** Answer a pointer to the current layout definition | |
116 | */ | |
c906108c | 117 | TuiLayoutDefPtr |
c906108c | 118 | tuiLayoutDef (void) |
c906108c SS |
119 | { |
120 | return &_layoutDef; | |
121 | } /* tuiLayoutDef */ | |
122 | ||
123 | ||
124 | /* | |
c5aa993b JM |
125 | ** tuiWinWithFocus(). |
126 | ** Answer the window with the logical focus | |
127 | */ | |
c906108c | 128 | TuiWinInfoPtr |
c906108c | 129 | tuiWinWithFocus (void) |
c906108c SS |
130 | { |
131 | return _winWithFocus; | |
132 | } /* tuiWinWithFocus */ | |
133 | ||
134 | ||
135 | /* | |
c5aa993b JM |
136 | ** tuiSetWinWithFocus(). |
137 | ** Set the window that has the logical focus | |
138 | */ | |
c906108c | 139 | void |
eca6576c | 140 | tuiSetWinWithFocus (TuiWinInfoPtr winInfo) |
c906108c SS |
141 | { |
142 | _winWithFocus = winInfo; | |
143 | ||
144 | return; | |
145 | } /* tuiSetWinWithFocus */ | |
146 | ||
147 | ||
148 | /* | |
c5aa993b JM |
149 | ** tuiDefaultTabLen(). |
150 | ** Answer the length in chars, of tabs | |
151 | */ | |
c906108c | 152 | int |
c906108c | 153 | tuiDefaultTabLen (void) |
c906108c SS |
154 | { |
155 | return _defaultTabLen; | |
156 | } /* tuiDefaultTabLen */ | |
157 | ||
158 | ||
159 | /* | |
c5aa993b JM |
160 | ** tuiSetDefaultTabLen(). |
161 | ** Set the length in chars, of tabs | |
162 | */ | |
c906108c | 163 | void |
eca6576c | 164 | tuiSetDefaultTabLen (int len) |
c906108c SS |
165 | { |
166 | _defaultTabLen = len; | |
167 | ||
168 | return; | |
169 | } /* tuiSetDefaultTabLen */ | |
170 | ||
171 | ||
172 | /* | |
c5aa993b JM |
173 | ** currentSourceWin() |
174 | ** Accessor for the current source window. Usually there is only | |
175 | ** one source window (either source or disassembly), but both can | |
176 | ** be displayed at the same time. | |
177 | */ | |
c906108c | 178 | TuiListPtr |
c906108c | 179 | sourceWindows (void) |
c906108c SS |
180 | { |
181 | return &_sourceWindows; | |
182 | } /* currentSourceWindows */ | |
183 | ||
184 | ||
185 | /* | |
c5aa993b JM |
186 | ** clearSourceWindows() |
187 | ** Clear the list of source windows. Usually there is only one | |
188 | ** source window (either source or disassembly), but both can be | |
189 | ** displayed at the same time. | |
190 | */ | |
c906108c | 191 | void |
c906108c | 192 | clearSourceWindows (void) |
c906108c SS |
193 | { |
194 | _sourceWindows.list[0] = (Opaque) NULL; | |
195 | _sourceWindows.list[1] = (Opaque) NULL; | |
196 | _sourceWindows.count = 0; | |
197 | ||
198 | return; | |
199 | } /* currentSourceWindows */ | |
200 | ||
201 | ||
202 | /* | |
c5aa993b JM |
203 | ** clearSourceWindowsDetail() |
204 | ** Clear the pertinant detail in the source windows. | |
205 | */ | |
c906108c | 206 | void |
c906108c | 207 | clearSourceWindowsDetail (void) |
c906108c SS |
208 | { |
209 | int i; | |
210 | ||
211 | for (i = 0; i < (sourceWindows ())->count; i++) | |
212 | clearWinDetail ((TuiWinInfoPtr) (sourceWindows ())->list[i]); | |
213 | ||
214 | return; | |
215 | } /* currentSourceWindows */ | |
216 | ||
217 | ||
218 | /* | |
c5aa993b JM |
219 | ** addSourceWindowToList(). |
220 | ** Add a window to the list of source windows. Usually there is | |
221 | ** only one source window (either source or disassembly), but | |
222 | ** both can be displayed at the same time. | |
223 | */ | |
c906108c | 224 | void |
eca6576c | 225 | addToSourceWindows (TuiWinInfoPtr winInfo) |
c906108c SS |
226 | { |
227 | if (_sourceWindows.count < 2) | |
228 | _sourceWindows.list[_sourceWindows.count++] = (Opaque) winInfo; | |
229 | ||
230 | return; | |
231 | } /* addToSourceWindows */ | |
232 | ||
233 | ||
234 | /* | |
c5aa993b JM |
235 | ** clearWinDetail() |
236 | ** Clear the pertinant detail in the windows. | |
237 | */ | |
c906108c | 238 | void |
eca6576c | 239 | clearWinDetail (TuiWinInfoPtr winInfo) |
c906108c SS |
240 | { |
241 | if (m_winPtrNotNull (winInfo)) | |
242 | { | |
243 | switch (winInfo->generic.type) | |
244 | { | |
245 | case SRC_WIN: | |
246 | case DISASSEM_WIN: | |
a4b99e53 | 247 | winInfo->detail.sourceInfo.startLineOrAddr.addr = 0; |
c906108c SS |
248 | winInfo->detail.sourceInfo.horizontalOffset = 0; |
249 | break; | |
250 | case CMD_WIN: | |
251 | winInfo->detail.commandInfo.curLine = | |
252 | winInfo->detail.commandInfo.curch = 0; | |
253 | break; | |
254 | case DATA_WIN: | |
255 | winInfo->detail.dataDisplayInfo.dataContent = | |
256 | (TuiWinContent) NULL; | |
257 | winInfo->detail.dataDisplayInfo.dataContentCount = 0; | |
258 | winInfo->detail.dataDisplayInfo.regsContent = | |
259 | (TuiWinContent) NULL; | |
260 | winInfo->detail.dataDisplayInfo.regsContentCount = 0; | |
261 | winInfo->detail.dataDisplayInfo.regsDisplayType = | |
262 | TUI_UNDEFINED_REGS; | |
263 | winInfo->detail.dataDisplayInfo.regsColumnCount = 1; | |
264 | winInfo->detail.dataDisplayInfo.displayRegs = FALSE; | |
265 | break; | |
266 | default: | |
267 | break; | |
268 | } | |
269 | } | |
270 | ||
271 | return; | |
272 | } /* clearWinDetail */ | |
273 | ||
274 | ||
c906108c | 275 | /* |
c5aa993b JM |
276 | ** sourceExecInfoPtr(). |
277 | ** Accessor for the source execution info ptr. | |
278 | */ | |
c906108c | 279 | TuiGenWinInfoPtr |
c906108c | 280 | sourceExecInfoWinPtr (void) |
c906108c SS |
281 | { |
282 | return &_execInfo[0]; | |
283 | } /* sourceExecInfoWinPtr */ | |
284 | ||
285 | ||
286 | /* | |
c5aa993b JM |
287 | ** disassemExecInfoPtr(). |
288 | ** Accessor for the disassem execution info ptr. | |
289 | */ | |
c906108c | 290 | TuiGenWinInfoPtr |
c906108c | 291 | disassemExecInfoWinPtr (void) |
c906108c SS |
292 | { |
293 | return &_execInfo[1]; | |
294 | } /* disassemExecInfoWinPtr */ | |
295 | ||
296 | ||
297 | /* | |
c5aa993b JM |
298 | ** locatorWinInfoPtr(). |
299 | ** Accessor for the locator win info. Answers a pointer to the | |
300 | ** static locator win info struct. | |
301 | */ | |
c906108c | 302 | TuiGenWinInfoPtr |
c906108c | 303 | locatorWinInfoPtr (void) |
c906108c SS |
304 | { |
305 | return &_locator; | |
306 | } /* locatorWinInfoPtr */ | |
307 | ||
308 | ||
c906108c | 309 | /* |
c5aa993b JM |
310 | ** termHeight(). |
311 | ** Accessor for the termHeight | |
312 | */ | |
c906108c | 313 | int |
c906108c | 314 | termHeight (void) |
c906108c SS |
315 | { |
316 | return _termHeight; | |
317 | } /* termHeight */ | |
318 | ||
319 | ||
320 | /* | |
c5aa993b JM |
321 | ** setTermHeightTo(). |
322 | ** Mutator for the term height | |
323 | */ | |
c906108c | 324 | void |
eca6576c | 325 | setTermHeightTo (int h) |
c906108c SS |
326 | { |
327 | _termHeight = h; | |
328 | ||
329 | return; | |
330 | } /* setTermHeightTo */ | |
331 | ||
332 | ||
333 | /* | |
c5aa993b JM |
334 | ** termWidth(). |
335 | ** Accessor for the termWidth | |
336 | */ | |
c906108c | 337 | int |
c906108c | 338 | termWidth (void) |
c906108c SS |
339 | { |
340 | return _termWidth; | |
341 | } /* termWidth */ | |
342 | ||
343 | ||
344 | /* | |
c5aa993b JM |
345 | ** setTermWidth(). |
346 | ** Mutator for the termWidth | |
347 | */ | |
c906108c | 348 | void |
eca6576c | 349 | setTermWidthTo (int w) |
c906108c SS |
350 | { |
351 | _termWidth = w; | |
352 | ||
353 | return; | |
354 | } /* setTermWidthTo */ | |
355 | ||
356 | ||
357 | /* | |
c5aa993b JM |
358 | ** currentLayout(). |
359 | ** Accessor for the current layout | |
360 | */ | |
c906108c | 361 | TuiLayoutType |
c906108c | 362 | currentLayout (void) |
c906108c SS |
363 | { |
364 | return _currentLayout; | |
365 | } /* currentLayout */ | |
366 | ||
367 | ||
368 | /* | |
c5aa993b JM |
369 | ** setCurrentLayoutTo(). |
370 | ** Mutator for the current layout | |
371 | */ | |
c906108c | 372 | void |
eca6576c | 373 | setCurrentLayoutTo (TuiLayoutType newLayout) |
c906108c SS |
374 | { |
375 | _currentLayout = newLayout; | |
376 | ||
377 | return; | |
378 | } /* setCurrentLayoutTo */ | |
379 | ||
380 | ||
381 | /* | |
c5aa993b JM |
382 | ** setGenWinOrigin(). |
383 | ** Set the origin of the window | |
384 | */ | |
c906108c | 385 | void |
eca6576c | 386 | setGenWinOrigin (TuiGenWinInfoPtr winInfo, int x, int y) |
c906108c SS |
387 | { |
388 | winInfo->origin.x = x; | |
389 | winInfo->origin.y = y; | |
390 | ||
391 | return; | |
392 | } /* setGenWinOrigin */ | |
393 | ||
394 | ||
395 | /***************************** | |
396 | ** OTHER PUBLIC FUNCTIONS | |
397 | *****************************/ | |
398 | ||
399 | ||
400 | /* | |
c5aa993b JM |
401 | ** tuiNextWin(). |
402 | ** Answer the next window in the list, cycling back to the top | |
403 | ** if necessary | |
404 | */ | |
c906108c | 405 | TuiWinInfoPtr |
eca6576c | 406 | tuiNextWin (TuiWinInfoPtr curWin) |
c906108c SS |
407 | { |
408 | TuiWinType type = curWin->generic.type; | |
409 | TuiWinInfoPtr nextWin = (TuiWinInfoPtr) NULL; | |
410 | ||
411 | if (curWin->generic.type == CMD_WIN) | |
412 | type = SRC_WIN; | |
413 | else | |
414 | type = curWin->generic.type + 1; | |
415 | while (type != curWin->generic.type && m_winPtrIsNull (nextWin)) | |
416 | { | |
a4b99e53 | 417 | if (winList[type] && winList[type]->generic.isVisible) |
c906108c SS |
418 | nextWin = winList[type]; |
419 | else | |
420 | { | |
421 | if (type == CMD_WIN) | |
422 | type = SRC_WIN; | |
423 | else | |
424 | type++; | |
425 | } | |
426 | } | |
427 | ||
428 | return nextWin; | |
429 | } /* tuiNextWin */ | |
430 | ||
431 | ||
432 | /* | |
c5aa993b JM |
433 | ** tuiPrevWin(). |
434 | ** Answer the prev window in the list, cycling back to the bottom | |
435 | ** if necessary | |
436 | */ | |
c906108c | 437 | TuiWinInfoPtr |
eca6576c | 438 | tuiPrevWin (TuiWinInfoPtr curWin) |
c906108c SS |
439 | { |
440 | TuiWinType type = curWin->generic.type; | |
441 | TuiWinInfoPtr prev = (TuiWinInfoPtr) NULL; | |
442 | ||
443 | if (curWin->generic.type == SRC_WIN) | |
444 | type = CMD_WIN; | |
445 | else | |
446 | type = curWin->generic.type - 1; | |
447 | while (type != curWin->generic.type && m_winPtrIsNull (prev)) | |
448 | { | |
449 | if (winList[type]->generic.isVisible) | |
450 | prev = winList[type]; | |
451 | else | |
452 | { | |
453 | if (type == SRC_WIN) | |
454 | type = CMD_WIN; | |
455 | else | |
456 | type--; | |
457 | } | |
458 | } | |
459 | ||
460 | return prev; | |
cb50eddd | 461 | } |
c906108c SS |
462 | |
463 | ||
464 | /* | |
c5aa993b JM |
465 | ** partialWinByName(). |
466 | ** Answer the window represented by name | |
467 | */ | |
c906108c | 468 | TuiWinInfoPtr |
eca6576c | 469 | partialWinByName (char *name) |
c906108c SS |
470 | { |
471 | TuiWinInfoPtr winInfo = (TuiWinInfoPtr) NULL; | |
472 | ||
473 | if (name != (char *) NULL) | |
474 | { | |
475 | int i = 0; | |
476 | ||
477 | while (i < MAX_MAJOR_WINDOWS && m_winPtrIsNull (winInfo)) | |
478 | { | |
a4b99e53 SC |
479 | if (winList[i] != 0) |
480 | { | |
481 | char *curName = winName (&winList[i]->generic); | |
482 | if (strlen (name) <= strlen (curName) && | |
483 | strncmp (name, curName, strlen (name)) == 0) | |
484 | winInfo = winList[i]; | |
485 | } | |
c906108c SS |
486 | i++; |
487 | } | |
488 | } | |
489 | ||
490 | return winInfo; | |
491 | } /* partialWinByName */ | |
492 | ||
493 | ||
494 | /* | |
c5aa993b JM |
495 | ** winName(). |
496 | ** Answer the name of the window | |
497 | */ | |
c906108c | 498 | char * |
eca6576c | 499 | winName (TuiGenWinInfoPtr winInfo) |
c906108c SS |
500 | { |
501 | char *name = (char *) NULL; | |
502 | ||
503 | switch (winInfo->type) | |
504 | { | |
505 | case SRC_WIN: | |
506 | name = SRC_NAME; | |
507 | break; | |
508 | case CMD_WIN: | |
509 | name = CMD_NAME; | |
510 | break; | |
511 | case DISASSEM_WIN: | |
512 | name = DISASSEM_NAME; | |
513 | break; | |
514 | case DATA_WIN: | |
515 | name = DATA_NAME; | |
516 | break; | |
517 | default: | |
518 | name = ""; | |
519 | break; | |
520 | } | |
521 | ||
522 | return name; | |
523 | } /* winName */ | |
524 | ||
525 | ||
526 | /* | |
c5aa993b JM |
527 | ** initializeStaticData |
528 | */ | |
c906108c | 529 | void |
c906108c | 530 | initializeStaticData (void) |
c906108c SS |
531 | { |
532 | initGenericPart (sourceExecInfoWinPtr ()); | |
533 | initGenericPart (disassemExecInfoWinPtr ()); | |
534 | initGenericPart (locatorWinInfoPtr ()); | |
535 | ||
536 | return; | |
537 | } /* initializeStaticData */ | |
538 | ||
539 | ||
540 | /* | |
c5aa993b JM |
541 | ** allocGenericWinInfo(). |
542 | */ | |
c906108c | 543 | TuiGenWinInfoPtr |
c906108c | 544 | allocGenericWinInfo (void) |
c906108c SS |
545 | { |
546 | TuiGenWinInfoPtr win; | |
547 | ||
548 | if ((win = (TuiGenWinInfoPtr) xmalloc ( | |
549 | sizeof (TuiGenWinInfoPtr))) != (TuiGenWinInfoPtr) NULL) | |
550 | initGenericPart (win); | |
551 | ||
552 | return win; | |
553 | } /* allocGenericWinInfo */ | |
554 | ||
555 | ||
556 | /* | |
c5aa993b JM |
557 | ** initGenericPart(). |
558 | */ | |
c906108c | 559 | void |
eca6576c | 560 | initGenericPart (TuiGenWinInfoPtr win) |
c906108c SS |
561 | { |
562 | win->width = | |
563 | win->height = | |
564 | win->origin.x = | |
565 | win->origin.y = | |
566 | win->viewportHeight = | |
567 | win->contentSize = | |
568 | win->lastVisibleLine = 0; | |
569 | win->handle = (WINDOW *) NULL; | |
570 | win->content = (OpaquePtr) NULL; | |
571 | win->contentInUse = | |
572 | win->isVisible = FALSE; | |
bc6b7f04 SC |
573 | win->title = 0; |
574 | } | |
c906108c SS |
575 | |
576 | ||
577 | /* | |
c5aa993b JM |
578 | ** initContentElement(). |
579 | */ | |
c906108c | 580 | void |
eca6576c | 581 | initContentElement (TuiWinElementPtr element, TuiWinType type) |
c906108c SS |
582 | { |
583 | element->highlight = FALSE; | |
584 | switch (type) | |
585 | { | |
586 | case SRC_WIN: | |
587 | case DISASSEM_WIN: | |
588 | element->whichElement.source.line = (char *) NULL; | |
589 | element->whichElement.source.lineOrAddr.lineNo = 0; | |
590 | element->whichElement.source.isExecPoint = FALSE; | |
591 | element->whichElement.source.hasBreak = FALSE; | |
592 | break; | |
593 | case DATA_WIN: | |
594 | initGenericPart (&element->whichElement.dataWindow); | |
595 | element->whichElement.dataWindow.type = DATA_ITEM_WIN; | |
596 | ((TuiGenWinInfoPtr) & element->whichElement.dataWindow)->content = | |
597 | (OpaquePtr) allocContent (1, DATA_ITEM_WIN); | |
598 | ((TuiGenWinInfoPtr) | |
599 | & element->whichElement.dataWindow)->contentSize = 1; | |
600 | break; | |
601 | case CMD_WIN: | |
602 | element->whichElement.command.line = (char *) NULL; | |
603 | break; | |
604 | case DATA_ITEM_WIN: | |
605 | element->whichElement.data.name = (char *) NULL; | |
606 | element->whichElement.data.type = TUI_REGISTER; | |
607 | element->whichElement.data.itemNo = UNDEFINED_ITEM; | |
608 | element->whichElement.data.value = (Opaque) NULL; | |
609 | element->whichElement.data.highlight = FALSE; | |
610 | break; | |
611 | case LOCATOR_WIN: | |
612 | element->whichElement.locator.fileName[0] = | |
613 | element->whichElement.locator.procName[0] = (char) 0; | |
614 | element->whichElement.locator.lineNo = 0; | |
615 | element->whichElement.locator.addr = 0; | |
616 | break; | |
617 | case EXEC_INFO_WIN: | |
00b2bad4 SC |
618 | memset(element->whichElement.simpleString, ' ', |
619 | sizeof(element->whichElement.simpleString)); | |
c906108c SS |
620 | break; |
621 | default: | |
622 | break; | |
623 | } | |
624 | return; | |
625 | } /* initContentElement */ | |
626 | ||
627 | /* | |
c5aa993b JM |
628 | ** initWinInfo(). |
629 | */ | |
c906108c | 630 | void |
eca6576c | 631 | initWinInfo (TuiWinInfoPtr winInfo) |
c906108c SS |
632 | { |
633 | initGenericPart (&winInfo->generic); | |
634 | winInfo->canHighlight = | |
635 | winInfo->isHighlighted = FALSE; | |
636 | switch (winInfo->generic.type) | |
637 | { | |
638 | case SRC_WIN: | |
639 | case DISASSEM_WIN: | |
640 | winInfo->detail.sourceInfo.executionInfo = (TuiGenWinInfoPtr) NULL; | |
641 | winInfo->detail.sourceInfo.hasLocator = FALSE; | |
642 | winInfo->detail.sourceInfo.horizontalOffset = 0; | |
a4b99e53 | 643 | winInfo->detail.sourceInfo.startLineOrAddr.addr = 0; |
bc6b7f04 | 644 | winInfo->detail.sourceInfo.filename = 0; |
c906108c SS |
645 | break; |
646 | case DATA_WIN: | |
647 | winInfo->detail.dataDisplayInfo.dataContent = (TuiWinContent) NULL; | |
648 | winInfo->detail.dataDisplayInfo.dataContentCount = 0; | |
649 | winInfo->detail.dataDisplayInfo.regsContent = (TuiWinContent) NULL; | |
650 | winInfo->detail.dataDisplayInfo.regsContentCount = 0; | |
651 | winInfo->detail.dataDisplayInfo.regsDisplayType = | |
652 | TUI_UNDEFINED_REGS; | |
653 | winInfo->detail.dataDisplayInfo.regsColumnCount = 1; | |
654 | winInfo->detail.dataDisplayInfo.displayRegs = FALSE; | |
655 | break; | |
656 | case CMD_WIN: | |
657 | winInfo->detail.commandInfo.curLine = 0; | |
658 | winInfo->detail.commandInfo.curch = 0; | |
659 | break; | |
660 | default: | |
661 | winInfo->detail.opaque = (Opaque) NULL; | |
662 | break; | |
663 | } | |
664 | ||
665 | return; | |
666 | } /* initWinInfo */ | |
667 | ||
668 | ||
669 | /* | |
c5aa993b JM |
670 | ** allocWinInfo(). |
671 | */ | |
c906108c | 672 | TuiWinInfoPtr |
eca6576c | 673 | allocWinInfo (TuiWinType type) |
c906108c SS |
674 | { |
675 | TuiWinInfoPtr winInfo = (TuiWinInfoPtr) NULL; | |
676 | ||
677 | winInfo = (TuiWinInfoPtr) xmalloc (sizeof (TuiWinInfo)); | |
678 | if (m_winPtrNotNull (winInfo)) | |
679 | { | |
680 | winInfo->generic.type = type; | |
681 | initWinInfo (winInfo); | |
682 | } | |
683 | ||
684 | return winInfo; | |
685 | } /* allocWinInfo */ | |
686 | ||
687 | ||
688 | /* | |
c5aa993b JM |
689 | ** allocContent(). |
690 | ** Allocates the content and elements in a block. | |
691 | */ | |
c906108c | 692 | TuiWinContent |
eca6576c | 693 | allocContent (int numElements, TuiWinType type) |
c906108c SS |
694 | { |
695 | TuiWinContent content = (TuiWinContent) NULL; | |
696 | char *elementBlockPtr = (char *) NULL; | |
697 | int i; | |
698 | ||
699 | if ((content = (TuiWinContent) | |
700 | xmalloc (sizeof (TuiWinElementPtr) * numElements)) != (TuiWinContent) NULL) | |
701 | { /* | |
c5aa993b JM |
702 | ** All windows, except the data window, can allocate the elements |
703 | ** in a chunk. The data window cannot because items can be | |
704 | ** added/removed from the data display by the user at any time. | |
705 | */ | |
c906108c SS |
706 | if (type != DATA_WIN) |
707 | { | |
708 | if ((elementBlockPtr = (char *) | |
709 | xmalloc (sizeof (TuiWinElement) * numElements)) != (char *) NULL) | |
710 | { | |
711 | for (i = 0; i < numElements; i++) | |
712 | { | |
713 | content[i] = (TuiWinElementPtr) elementBlockPtr; | |
714 | initContentElement (content[i], type); | |
715 | elementBlockPtr += sizeof (TuiWinElement); | |
716 | } | |
717 | } | |
718 | else | |
719 | { | |
720 | tuiFree ((char *) content); | |
721 | content = (TuiWinContent) NULL; | |
722 | } | |
723 | } | |
724 | } | |
725 | ||
726 | return content; | |
727 | } /* allocContent */ | |
728 | ||
729 | ||
730 | /* | |
c5aa993b JM |
731 | ** addContentElements(). |
732 | ** Adds the input number of elements to the windows's content. If | |
733 | ** no content has been allocated yet, allocContent() is called to | |
734 | ** do this. The index of the first element added is returned, | |
735 | ** unless there is a memory allocation error, in which case, (-1) | |
736 | ** is returned. | |
737 | */ | |
c906108c | 738 | int |
eca6576c | 739 | addContentElements (TuiGenWinInfoPtr winInfo, int numElements) |
c906108c SS |
740 | { |
741 | TuiWinElementPtr elementPtr; | |
742 | int i, indexStart; | |
743 | ||
744 | if (winInfo->content == (OpaquePtr) NULL) | |
745 | { | |
746 | winInfo->content = (OpaquePtr) allocContent (numElements, winInfo->type); | |
747 | indexStart = 0; | |
748 | } | |
749 | else | |
750 | indexStart = winInfo->contentSize; | |
751 | if (winInfo->content != (OpaquePtr) NULL) | |
752 | { | |
753 | for (i = indexStart; (i < numElements + indexStart); i++) | |
754 | { | |
755 | if ((elementPtr = (TuiWinElementPtr) | |
756 | xmalloc (sizeof (TuiWinElement))) != (TuiWinElementPtr) NULL) | |
757 | { | |
758 | winInfo->content[i] = (Opaque) elementPtr; | |
759 | initContentElement (elementPtr, winInfo->type); | |
760 | winInfo->contentSize++; | |
761 | } | |
c5aa993b | 762 | else /* things must be really hosed now! We ran out of memory!? */ |
c906108c SS |
763 | return (-1); |
764 | } | |
765 | } | |
766 | ||
767 | return indexStart; | |
768 | } /* addContentElements */ | |
769 | ||
770 | ||
bc6b7f04 SC |
771 | /* Delete all curses windows associated with winInfo, leaving everything |
772 | else intact. */ | |
c906108c | 773 | void |
eca6576c | 774 | tuiDelWindow (TuiWinInfoPtr winInfo) |
c906108c | 775 | { |
c906108c SS |
776 | TuiGenWinInfoPtr genericWin; |
777 | ||
c906108c SS |
778 | switch (winInfo->generic.type) |
779 | { | |
780 | case SRC_WIN: | |
781 | case DISASSEM_WIN: | |
782 | genericWin = locatorWinInfoPtr (); | |
783 | if (genericWin != (TuiGenWinInfoPtr) NULL) | |
784 | { | |
785 | tuiDelwin (genericWin->handle); | |
786 | genericWin->handle = (WINDOW *) NULL; | |
787 | genericWin->isVisible = FALSE; | |
788 | } | |
bc6b7f04 SC |
789 | if (winInfo->detail.sourceInfo.filename) |
790 | { | |
791 | xfree (winInfo->detail.sourceInfo.filename); | |
792 | winInfo->detail.sourceInfo.filename = 0; | |
793 | } | |
c906108c SS |
794 | genericWin = winInfo->detail.sourceInfo.executionInfo; |
795 | if (genericWin != (TuiGenWinInfoPtr) NULL) | |
796 | { | |
797 | tuiDelwin (genericWin->handle); | |
798 | genericWin->handle = (WINDOW *) NULL; | |
799 | genericWin->isVisible = FALSE; | |
800 | } | |
801 | break; | |
802 | case DATA_WIN: | |
803 | if (winInfo->generic.content != (OpaquePtr) NULL) | |
804 | { | |
bc6b7f04 SC |
805 | tuiDelDataWindows (winInfo->detail.dataDisplayInfo.regsContent, |
806 | winInfo->detail.dataDisplayInfo.regsContentCount); | |
807 | tuiDelDataWindows (winInfo->detail.dataDisplayInfo.dataContent, | |
808 | winInfo->detail.dataDisplayInfo.dataContentCount); | |
c906108c SS |
809 | } |
810 | break; | |
811 | default: | |
812 | break; | |
813 | } | |
814 | if (winInfo->generic.handle != (WINDOW *) NULL) | |
815 | { | |
816 | tuiDelwin (winInfo->generic.handle); | |
817 | winInfo->generic.handle = (WINDOW *) NULL; | |
818 | winInfo->generic.isVisible = FALSE; | |
819 | } | |
bc6b7f04 | 820 | } |
c906108c SS |
821 | |
822 | ||
823 | /* | |
c5aa993b JM |
824 | ** freeWindow(). |
825 | */ | |
c906108c | 826 | void |
eca6576c | 827 | freeWindow (TuiWinInfoPtr winInfo) |
c906108c | 828 | { |
c906108c SS |
829 | TuiGenWinInfoPtr genericWin; |
830 | ||
c906108c SS |
831 | switch (winInfo->generic.type) |
832 | { | |
833 | case SRC_WIN: | |
834 | case DISASSEM_WIN: | |
835 | genericWin = locatorWinInfoPtr (); | |
836 | if (genericWin != (TuiGenWinInfoPtr) NULL) | |
837 | { | |
838 | tuiDelwin (genericWin->handle); | |
839 | genericWin->handle = (WINDOW *) NULL; | |
840 | } | |
841 | freeWinContent (genericWin); | |
bc6b7f04 SC |
842 | if (winInfo->detail.sourceInfo.filename) |
843 | { | |
844 | xfree (winInfo->detail.sourceInfo.filename); | |
845 | winInfo->detail.sourceInfo.filename = 0; | |
846 | } | |
c906108c SS |
847 | genericWin = winInfo->detail.sourceInfo.executionInfo; |
848 | if (genericWin != (TuiGenWinInfoPtr) NULL) | |
849 | { | |
850 | tuiDelwin (genericWin->handle); | |
851 | genericWin->handle = (WINDOW *) NULL; | |
852 | freeWinContent (genericWin); | |
853 | } | |
854 | break; | |
855 | case DATA_WIN: | |
856 | if (winInfo->generic.content != (OpaquePtr) NULL) | |
857 | { | |
858 | freeDataContent ( | |
859 | winInfo->detail.dataDisplayInfo.regsContent, | |
860 | winInfo->detail.dataDisplayInfo.regsContentCount); | |
861 | winInfo->detail.dataDisplayInfo.regsContent = | |
862 | (TuiWinContent) NULL; | |
863 | winInfo->detail.dataDisplayInfo.regsContentCount = 0; | |
864 | freeDataContent ( | |
865 | winInfo->detail.dataDisplayInfo.dataContent, | |
866 | winInfo->detail.dataDisplayInfo.dataContentCount); | |
867 | winInfo->detail.dataDisplayInfo.dataContent = | |
868 | (TuiWinContent) NULL; | |
869 | winInfo->detail.dataDisplayInfo.dataContentCount = 0; | |
870 | winInfo->detail.dataDisplayInfo.regsDisplayType = | |
871 | TUI_UNDEFINED_REGS; | |
872 | winInfo->detail.dataDisplayInfo.regsColumnCount = 1; | |
873 | winInfo->detail.dataDisplayInfo.displayRegs = FALSE; | |
874 | winInfo->generic.content = (OpaquePtr) NULL; | |
875 | winInfo->generic.contentSize = 0; | |
876 | } | |
877 | break; | |
878 | default: | |
879 | break; | |
880 | } | |
881 | if (winInfo->generic.handle != (WINDOW *) NULL) | |
882 | { | |
883 | tuiDelwin (winInfo->generic.handle); | |
884 | winInfo->generic.handle = (WINDOW *) NULL; | |
885 | freeWinContent (&winInfo->generic); | |
886 | } | |
bc6b7f04 SC |
887 | if (winInfo->generic.title) |
888 | xfree (winInfo->generic.title); | |
b8c9b27d | 889 | xfree (winInfo); |
bc6b7f04 | 890 | } |
c906108c SS |
891 | |
892 | ||
893 | /* | |
c5aa993b JM |
894 | ** freeAllSourceWinsContent(). |
895 | */ | |
c906108c | 896 | void |
c906108c | 897 | freeAllSourceWinsContent (void) |
c906108c SS |
898 | { |
899 | int i; | |
900 | ||
901 | for (i = 0; i < (sourceWindows ())->count; i++) | |
902 | { | |
903 | TuiWinInfoPtr winInfo = (TuiWinInfoPtr) (sourceWindows ())->list[i]; | |
904 | ||
905 | if (m_winPtrNotNull (winInfo)) | |
906 | { | |
907 | freeWinContent (&(winInfo->generic)); | |
908 | freeWinContent (winInfo->detail.sourceInfo.executionInfo); | |
909 | } | |
910 | } | |
911 | ||
912 | return; | |
913 | } /* freeAllSourceWinsContent */ | |
914 | ||
915 | ||
916 | /* | |
c5aa993b JM |
917 | ** freeWinContent(). |
918 | */ | |
c906108c | 919 | void |
eca6576c | 920 | freeWinContent (TuiGenWinInfoPtr winInfo) |
c906108c SS |
921 | { |
922 | if (winInfo->content != (OpaquePtr) NULL) | |
923 | { | |
924 | freeContent ((TuiWinContent) winInfo->content, | |
925 | winInfo->contentSize, | |
926 | winInfo->type); | |
927 | winInfo->content = (OpaquePtr) NULL; | |
928 | } | |
929 | winInfo->contentSize = 0; | |
930 | ||
931 | return; | |
932 | } /* freeWinContent */ | |
933 | ||
934 | ||
c906108c | 935 | void |
eca6576c | 936 | tuiDelDataWindows (TuiWinContent content, int contentSize) |
c906108c SS |
937 | { |
938 | int i; | |
939 | ||
940 | /* | |
c5aa993b JM |
941 | ** Remember that data window content elements are of type TuiGenWinInfoPtr, |
942 | ** each of which whose single element is a data element. | |
943 | */ | |
c906108c SS |
944 | for (i = 0; i < contentSize; i++) |
945 | { | |
946 | TuiGenWinInfoPtr genericWin = &content[i]->whichElement.dataWindow; | |
947 | ||
948 | if (genericWin != (TuiGenWinInfoPtr) NULL) | |
949 | { | |
950 | tuiDelwin (genericWin->handle); | |
951 | genericWin->handle = (WINDOW *) NULL; | |
952 | genericWin->isVisible = FALSE; | |
953 | } | |
954 | } | |
955 | ||
956 | return; | |
957 | } /* tuiDelDataWindows */ | |
958 | ||
959 | ||
960 | void | |
eca6576c | 961 | freeDataContent (TuiWinContent content, int contentSize) |
c906108c SS |
962 | { |
963 | int i; | |
964 | ||
965 | /* | |
c5aa993b JM |
966 | ** Remember that data window content elements are of type TuiGenWinInfoPtr, |
967 | ** each of which whose single element is a data element. | |
968 | */ | |
c906108c SS |
969 | for (i = 0; i < contentSize; i++) |
970 | { | |
971 | TuiGenWinInfoPtr genericWin = &content[i]->whichElement.dataWindow; | |
972 | ||
973 | if (genericWin != (TuiGenWinInfoPtr) NULL) | |
974 | { | |
975 | tuiDelwin (genericWin->handle); | |
976 | genericWin->handle = (WINDOW *) NULL; | |
977 | freeWinContent (genericWin); | |
978 | } | |
979 | } | |
980 | freeContent (content, | |
981 | contentSize, | |
982 | DATA_WIN); | |
983 | ||
984 | return; | |
985 | } /* freeDataContent */ | |
986 | ||
987 | ||
988 | /********************************** | |
989 | ** LOCAL STATIC FUNCTIONS ** | |
990 | **********************************/ | |
991 | ||
992 | ||
993 | /* | |
c5aa993b JM |
994 | ** freeContent(). |
995 | */ | |
c906108c | 996 | static void |
eca6576c | 997 | freeContent (TuiWinContent content, int contentSize, TuiWinType winType) |
c906108c SS |
998 | { |
999 | if (content != (TuiWinContent) NULL) | |
1000 | { | |
1001 | freeContentElements (content, contentSize, winType); | |
1002 | tuiFree ((char *) content); | |
1003 | } | |
1004 | ||
1005 | return; | |
1006 | } /* freeContent */ | |
1007 | ||
1008 | ||
1009 | /* | |
c5aa993b JM |
1010 | ** freeContentElements(). |
1011 | */ | |
c906108c | 1012 | static void |
eca6576c | 1013 | freeContentElements (TuiWinContent content, int contentSize, TuiWinType type) |
c906108c SS |
1014 | { |
1015 | if (content != (TuiWinContent) NULL) | |
1016 | { | |
1017 | int i; | |
1018 | ||
1019 | if (type == SRC_WIN || type == DISASSEM_WIN) | |
1020 | { | |
1021 | /* free whole source block */ | |
1022 | if (content[0]->whichElement.source.line != (char *) NULL) | |
1023 | tuiFree (content[0]->whichElement.source.line); | |
1024 | } | |
1025 | else | |
1026 | { | |
1027 | for (i = 0; i < contentSize; i++) | |
1028 | { | |
1029 | TuiWinElementPtr element; | |
1030 | ||
1031 | element = content[i]; | |
1032 | if (element != (TuiWinElementPtr) NULL) | |
1033 | { | |
1034 | switch (type) | |
1035 | { | |
1036 | case DATA_WIN: | |
1037 | tuiFree ((char *) element); | |
1038 | break; | |
1039 | case DATA_ITEM_WIN: | |
1040 | /* | |
c5aa993b JM |
1041 | ** Note that data elements are not allocated |
1042 | ** in a single block, but individually, as needed. | |
1043 | */ | |
c906108c SS |
1044 | if (element->whichElement.data.type != TUI_REGISTER) |
1045 | tuiFree ((char *) | |
1046 | element->whichElement.data.name); | |
1047 | tuiFree ((char *) element->whichElement.data.value); | |
1048 | tuiFree ((char *) element); | |
1049 | break; | |
1050 | case CMD_WIN: | |
1051 | tuiFree ((char *) element->whichElement.command.line); | |
1052 | break; | |
1053 | default: | |
1054 | break; | |
1055 | } | |
1056 | } | |
1057 | } | |
1058 | } | |
1059 | if (type != DATA_WIN && type != DATA_ITEM_WIN) | |
1060 | tuiFree ((char *) content[0]); /* free the element block */ | |
1061 | } | |
1062 | ||
1063 | return; | |
1064 | } /* freeContentElements */ |