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