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