| 1 | /* Top level support for Mac interface to GDB, the GNU debugger. |
| 2 | Copyright 1994 Free Software Foundation, Inc. |
| 3 | Contributed by Cygnus Support. Written by Stan Shebs. |
| 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., 675 Mass Ave, Cambridge, MA 02139, USA. */ |
| 20 | |
| 21 | #include "defs.h" |
| 22 | |
| 23 | #include "readline.h" |
| 24 | #include "history.h" |
| 25 | |
| 26 | #include <Values.h> |
| 27 | #include <Types.h> |
| 28 | #include <Resources.h> |
| 29 | #include <QuickDraw.h> |
| 30 | #include <Fonts.h> |
| 31 | #include <Events.h> |
| 32 | #include <Windows.h> |
| 33 | #include <Menus.h> |
| 34 | #include <TextEdit.h> |
| 35 | #include <Dialogs.h> |
| 36 | #include <Desk.h> |
| 37 | #include <ToolUtils.h> |
| 38 | #include <Memory.h> |
| 39 | #include <SegLoad.h> |
| 40 | #include <Files.h> |
| 41 | #include <Folders.h> |
| 42 | #include <OSUtils.h> |
| 43 | #include <OSEvents.h> |
| 44 | #include <DiskInit.h> |
| 45 | #include <Packages.h> |
| 46 | #include <Traps.h> |
| 47 | #include <Lists.h> |
| 48 | #include <GestaltEqu.h> |
| 49 | #include <PPCToolbox.h> |
| 50 | #include <AppleEvents.h> |
| 51 | #include <StandardFile.h> |
| 52 | #include <Sound.h> |
| 53 | |
| 54 | #ifdef MPW |
| 55 | #define QD(whatever) (qd.##whatever) |
| 56 | #define QDPat(whatever) (&(qd.##whatever)) |
| 57 | #endif /* MPW */ |
| 58 | |
| 59 | #ifdef THINK_C |
| 60 | #define QD(whatever) (whatever) |
| 61 | #endif |
| 62 | |
| 63 | #define p2c(pstr,cbuf) \ |
| 64 | strncpy(cbuf, ((char *) (pstr) + 1), pstr[0]); \ |
| 65 | cbuf[pstr[0]] = '\0'; |
| 66 | |
| 67 | #define pascalify(STR) \ |
| 68 | sprintf(tmpbuf, " %s", STR); \ |
| 69 | tmpbuf[0] = strlen(STR); |
| 70 | |
| 71 | #include "gdbcmd.h" |
| 72 | #include "call-cmds.h" |
| 73 | #include "symtab.h" |
| 74 | #include "inferior.h" |
| 75 | #include "signals.h" |
| 76 | #include "target.h" |
| 77 | #include "breakpoint.h" |
| 78 | #include "gdbtypes.h" |
| 79 | #include "expression.h" |
| 80 | #include "language.h" |
| 81 | |
| 82 | #include "mac-defs.h" |
| 83 | |
| 84 | int debug_openp = 0; |
| 85 | |
| 86 | /* This is true if we are running as a standalone application. */ |
| 87 | |
| 88 | int mac_app; |
| 89 | |
| 90 | /* This is true if we are using WaitNextEvent. */ |
| 91 | |
| 92 | int use_wne; |
| 93 | |
| 94 | /* This is true if we have Color Quickdraw. */ |
| 95 | |
| 96 | int has_color_qd; |
| 97 | |
| 98 | /* This is true if we are using Color Quickdraw. */ |
| 99 | |
| 100 | int use_color_qd; |
| 101 | |
| 102 | int inbackground; |
| 103 | |
| 104 | Rect dragrect = { -32000, -32000, 32000, 32000 }; |
| 105 | Rect sizerect; |
| 106 | |
| 107 | int sbarwid = 15; |
| 108 | |
| 109 | /* Globals for the console window. */ |
| 110 | |
| 111 | WindowPtr console_window; |
| 112 | |
| 113 | ControlHandle console_v_scrollbar; |
| 114 | |
| 115 | Rect console_v_scroll_rect; |
| 116 | |
| 117 | TEHandle console_text; |
| 118 | |
| 119 | Rect console_text_rect; |
| 120 | |
| 121 | /* This will go away eventually. */ |
| 122 | gdb_has_a_terminal () { return 1; } |
| 123 | |
| 124 | mac_init () |
| 125 | { |
| 126 | SysEnvRec se; |
| 127 | int eventloopdone = 0; |
| 128 | char *str; |
| 129 | Boolean gotevent; |
| 130 | Point mouse; |
| 131 | EventRecord event; |
| 132 | WindowPtr win; |
| 133 | RgnHandle cursorRgn; |
| 134 | int i; |
| 135 | Handle menubar; |
| 136 | MenuHandle menu; |
| 137 | Handle siow_resource; |
| 138 | |
| 139 | mac_app = 0; |
| 140 | |
| 141 | str = getenv("DEBUG_GDB"); |
| 142 | if (str != NULL && str[0] != '\0') |
| 143 | { |
| 144 | if (strcmp(str, "openp") == 0) |
| 145 | debug_openp = 1; |
| 146 | } |
| 147 | |
| 148 | /* Don't do anything if we`re running under MPW. */ |
| 149 | if (!StandAlone) |
| 150 | return; |
| 151 | |
| 152 | /* Don't do anything if we're using SIOW. */ |
| 153 | /* This test requires that the siow 0 resource, as defined in |
| 154 | {RIncludes}siow.r, not be messed with. If it is, then the |
| 155 | standard Mac setup below will step on SIOW's Mac setup and |
| 156 | most likely crash the machine. */ |
| 157 | siow_resource = GetResource('siow', 0); |
| 158 | if (siow_resource != nil) |
| 159 | return; |
| 160 | |
| 161 | mac_app = 1; |
| 162 | |
| 163 | /* Do the standard Mac environment setup. */ |
| 164 | InitGraf (&QD (thePort)); |
| 165 | InitFonts (); |
| 166 | FlushEvents (everyEvent, 0); |
| 167 | InitWindows (); |
| 168 | InitMenus (); |
| 169 | TEInit (); |
| 170 | InitDialogs (NULL); |
| 171 | InitCursor (); |
| 172 | |
| 173 | /* Color Quickdraw is different from Classic QD. */ |
| 174 | SysEnvirons(2, &se); |
| 175 | has_color_qd = se.hasColorQD; |
| 176 | /* Use it if we got it. */ |
| 177 | use_color_qd = has_color_qd; |
| 178 | |
| 179 | sizerect.top = 50; |
| 180 | sizerect.left = 50; |
| 181 | sizerect.bottom = 1000; |
| 182 | sizerect.right = 1000; |
| 183 | #if 0 |
| 184 | sizerect.bottom = screenBits.bounds.bottom - screenBits.bounds.top; |
| 185 | sizerect.right = screenBits.bounds.right - screenBits.bounds.left; |
| 186 | #endif |
| 187 | |
| 188 | /* Set up the menus. */ |
| 189 | menubar = GetNewMBar (mbMain); |
| 190 | SetMenuBar (menubar); |
| 191 | /* Add the DAs etc as usual. */ |
| 192 | menu = GetMHandle (mApple); |
| 193 | if (menu != nil) { |
| 194 | AddResMenu (menu, 'DRVR'); |
| 195 | } |
| 196 | DrawMenuBar (); |
| 197 | |
| 198 | new_console_window (); |
| 199 | } |
| 200 | |
| 201 | new_console_window () |
| 202 | { |
| 203 | /* Create the main window we're going to play in. */ |
| 204 | if (has_color_qd) |
| 205 | console_window = GetNewCWindow (wConsole, NULL, (WindowPtr) -1L); |
| 206 | else |
| 207 | console_window = GetNewWindow (wConsole, NULL, (WindowPtr) -1L); |
| 208 | |
| 209 | SetPort (console_window); |
| 210 | console_text_rect = console_window->portRect; |
| 211 | /* Leave 8 pixels of blank space, for aesthetic reasons and to |
| 212 | make it easier to select from the beginning of a line. */ |
| 213 | console_text_rect.left += 8; |
| 214 | console_text_rect.bottom -= sbarwid - 1; |
| 215 | console_text_rect.right -= sbarwid - 1; |
| 216 | console_text = TENew (&console_text_rect, &console_text_rect); |
| 217 | TESetSelect (0, 40000, console_text); |
| 218 | TEDelete (console_text); |
| 219 | TEAutoView (1, console_text); |
| 220 | |
| 221 | console_v_scroll_rect = console_window->portRect; |
| 222 | console_v_scroll_rect.bottom -= sbarwid - 1; |
| 223 | console_v_scroll_rect.left = console_v_scroll_rect.right - sbarwid; |
| 224 | console_v_scrollbar = |
| 225 | NewControl (console_window, &console_v_scroll_rect, |
| 226 | "\p", 1, 0, 0, 0, scrollBarProc, 0L); |
| 227 | |
| 228 | ShowWindow (console_window); |
| 229 | SelectWindow (console_window); |
| 230 | } |
| 231 | |
| 232 | mac_command_loop() |
| 233 | { |
| 234 | SysEnvRec se; |
| 235 | int eventloopdone = 0; |
| 236 | Boolean gotevent; |
| 237 | Point mouse; |
| 238 | EventRecord event; |
| 239 | WindowPtr win; |
| 240 | RgnHandle cursorRgn; |
| 241 | int i, tm; |
| 242 | Handle menubar; |
| 243 | MenuHandle menu; |
| 244 | |
| 245 | /* Figure out if the WaitNextEvent Trap is available. */ |
| 246 | use_wne = |
| 247 | (NGetTrapAddress (0x60, ToolTrap) != NGetTrapAddress (0x9f, ToolTrap)); |
| 248 | /* Pass WaitNextEvent an empty region the first time through. */ |
| 249 | cursorRgn = NewRgn (); |
| 250 | /* Go into the main event-handling loop. */ |
| 251 | while (!eventloopdone) |
| 252 | { |
| 253 | /* Use WaitNextEvent if it is available, otherwise GetNextEvent. */ |
| 254 | if (use_wne) |
| 255 | { |
| 256 | get_global_mouse (&mouse); |
| 257 | adjust_cursor (mouse, cursorRgn); |
| 258 | tm = GetCaretTime(); |
| 259 | gotevent = WaitNextEvent (everyEvent, &event, tm, cursorRgn); |
| 260 | } |
| 261 | else |
| 262 | { |
| 263 | SystemTask (); |
| 264 | gotevent = GetNextEvent (everyEvent, &event); |
| 265 | } |
| 266 | /* First decide if the event is for a dialog or is just any old event. */ |
| 267 | if (FrontWindow () != nil && IsDialogEvent (&event)) |
| 268 | { |
| 269 | short itemhit; |
| 270 | DialogPtr dialog; |
| 271 | |
| 272 | /* Handle all the modeless dialogs here. */ |
| 273 | if (DialogSelect (&event, &dialog, &itemhit)) |
| 274 | { |
| 275 | } |
| 276 | } |
| 277 | else if (gotevent) |
| 278 | { |
| 279 | /* Make sure we have the right cursor before handling the event. */ |
| 280 | adjust_cursor (event.where, cursorRgn); |
| 281 | do_event (&event); |
| 282 | } |
| 283 | else |
| 284 | { |
| 285 | do_idle (); |
| 286 | } |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | /* Collect the global coordinates of the mouse pointer. */ |
| 291 | |
| 292 | get_global_mouse (mouse) |
| 293 | Point *mouse; |
| 294 | { |
| 295 | EventRecord evt; |
| 296 | |
| 297 | OSEventAvail (0, &evt); |
| 298 | *mouse = evt.where; |
| 299 | } |
| 300 | |
| 301 | /* Change the cursor's appearance to be appropriate for the given mouse |
| 302 | location. */ |
| 303 | |
| 304 | adjust_cursor (mouse, region) |
| 305 | Point mouse; |
| 306 | RgnHandle region; |
| 307 | { |
| 308 | } |
| 309 | |
| 310 | /* Decipher an event, maybe do something with it. */ |
| 311 | |
| 312 | do_event (evt) |
| 313 | EventRecord *evt; |
| 314 | { |
| 315 | short part, err, rslt = 0; |
| 316 | WindowPtr win; |
| 317 | Boolean hit; |
| 318 | char key; |
| 319 | Point pnt; |
| 320 | |
| 321 | switch (evt->what) |
| 322 | { |
| 323 | case mouseDown: |
| 324 | /* See if the click happened in a special part of the screen. */ |
| 325 | part = FindWindow (evt->where, &win); |
| 326 | switch (part) |
| 327 | { |
| 328 | case inMenuBar: |
| 329 | adjust_menus (); |
| 330 | do_menu_command (MenuSelect (evt->where)); |
| 331 | break; |
| 332 | case inSysWindow: |
| 333 | SystemClick (evt, win); |
| 334 | break; |
| 335 | case inContent: |
| 336 | if (win != FrontWindow ()) |
| 337 | { |
| 338 | /* Bring the clicked-on window to the front. */ |
| 339 | SelectWindow (win); |
| 340 | /* Fix the menu to match the new front window. */ |
| 341 | adjust_menus (); |
| 342 | /* We always want to discard the event now, since clicks in a |
| 343 | windows are often irreversible actions. */ |
| 344 | } else |
| 345 | /* Mouse clicks in the front window do something useful. */ |
| 346 | do_mouse_down (win, evt); |
| 347 | break; |
| 348 | case inDrag: |
| 349 | /* Standard drag behavior, no tricks necessary. */ |
| 350 | DragWindow (win, evt->where, &dragrect); |
| 351 | break; |
| 352 | case inGrow: |
| 353 | grow_window (win, evt->where); |
| 354 | break; |
| 355 | case inZoomIn: |
| 356 | case inZoomOut: |
| 357 | zoom_window (win, evt->where, part); |
| 358 | break; |
| 359 | case inGoAway: |
| 360 | close_window (win); |
| 361 | break; |
| 362 | } |
| 363 | break; |
| 364 | case keyDown: |
| 365 | case autoKey: |
| 366 | key = evt->message & charCodeMask; |
| 367 | /* Check for menukey equivalents. */ |
| 368 | if (evt->modifiers & cmdKey) |
| 369 | { |
| 370 | if (evt->what == keyDown) |
| 371 | { |
| 372 | adjust_menus (); |
| 373 | do_menu_command (MenuKey (key)); |
| 374 | } |
| 375 | } |
| 376 | else |
| 377 | { |
| 378 | if (evt->what == keyDown) |
| 379 | { |
| 380 | /* Random keypress, interpret it. */ |
| 381 | do_keyboard_command (key); |
| 382 | } |
| 383 | } |
| 384 | break; |
| 385 | case activateEvt: |
| 386 | activate_window ((WindowPtr) evt->message, evt->modifiers & activeFlag); |
| 387 | break; |
| 388 | case updateEvt: |
| 389 | update_window ((WindowPtr) evt->message); |
| 390 | break; |
| 391 | case diskEvt: |
| 392 | /* Call DIBadMount in response to a diskEvt, so that the user can format |
| 393 | a floppy. (from DTS Sample) */ |
| 394 | if (HiWord (evt->message) != noErr) |
| 395 | { |
| 396 | SetPt (&pnt, 50, 50); |
| 397 | err = DIBadMount (pnt, evt->message); |
| 398 | } |
| 399 | break; |
| 400 | case app4Evt: |
| 401 | /* Grab only a single byte. */ |
| 402 | switch ((evt->message >> 24) & 0xFF) |
| 403 | { |
| 404 | case 0xfa: |
| 405 | break; |
| 406 | case 1: |
| 407 | inbackground = !(evt->message & 1); |
| 408 | activate_window (FrontWindow (), !inbackground); |
| 409 | break; |
| 410 | } |
| 411 | break; |
| 412 | case kHighLevelEvent: |
| 413 | AEProcessAppleEvent (evt); |
| 414 | break; |
| 415 | case nullEvent: |
| 416 | do_idle (); |
| 417 | rslt = 1; |
| 418 | break; |
| 419 | default: |
| 420 | break; |
| 421 | } |
| 422 | return rslt; |
| 423 | } |
| 424 | |
| 425 | /* Do any idle-time activities. */ |
| 426 | |
| 427 | do_idle () |
| 428 | { |
| 429 | TEIdle (console_text); |
| 430 | } |
| 431 | |
| 432 | grow_window (win, where) |
| 433 | WindowPtr win; |
| 434 | Point where; |
| 435 | { |
| 436 | long winsize; |
| 437 | int h, v; |
| 438 | GrafPtr oldport; |
| 439 | |
| 440 | winsize = GrowWindow (win, where, &sizerect); |
| 441 | /* Only do anything if it actually changed size. */ |
| 442 | if (winsize != 0) |
| 443 | { |
| 444 | GetPort (&oldport); |
| 445 | SetPort (win); |
| 446 | if (win == console_window) |
| 447 | { |
| 448 | EraseRect (&win->portRect); |
| 449 | h = LoWord (winsize); |
| 450 | v = HiWord (winsize); |
| 451 | SizeWindow (win, h, v, 1); |
| 452 | resize_console_window (); |
| 453 | } |
| 454 | SetPort (oldport); |
| 455 | } |
| 456 | } |
| 457 | |
| 458 | zoom_window (win, where, part) |
| 459 | WindowPtr win; |
| 460 | Point where; |
| 461 | short part; |
| 462 | { |
| 463 | ZoomWindow (win, part, (win == FrontWindow ())); |
| 464 | if (win == console_window) |
| 465 | { |
| 466 | resize_console_window (); |
| 467 | } |
| 468 | } |
| 469 | |
| 470 | resize_console_window () |
| 471 | { |
| 472 | adjust_console_sizes (); |
| 473 | adjust_console_scrollbars (); |
| 474 | adjust_console_text (); |
| 475 | InvalRect (&console_window->portRect); |
| 476 | } |
| 477 | |
| 478 | close_window (win) |
| 479 | WindowPtr win; |
| 480 | { |
| 481 | } |
| 482 | |
| 483 | pascal void |
| 484 | v_scroll_proc (ControlHandle control, short part) |
| 485 | { |
| 486 | int oldval, amount = 0, newval; |
| 487 | int pagesize = ((*console_text)->viewRect.bottom - (*console_text)->viewRect.top) / (*console_text)->lineHeight; |
| 488 | if (part) |
| 489 | { |
| 490 | oldval = GetCtlValue (control); |
| 491 | switch (part) |
| 492 | { |
| 493 | case inUpButton: |
| 494 | amount = 1; |
| 495 | break; |
| 496 | case inDownButton: |
| 497 | amount = -1; |
| 498 | break; |
| 499 | case inPageUp: |
| 500 | amount = pagesize; |
| 501 | break; |
| 502 | case inPageDown: |
| 503 | amount = - pagesize; |
| 504 | break; |
| 505 | default: |
| 506 | /* (should freak out) */ |
| 507 | break; |
| 508 | } |
| 509 | SetCtlValue(control, oldval - amount); |
| 510 | newval = GetCtlValue (control); |
| 511 | amount = oldval - newval; |
| 512 | if (amount) |
| 513 | TEScroll (0, amount * (*console_text)->lineHeight, console_text); |
| 514 | } |
| 515 | } |
| 516 | |
| 517 | do_mouse_down (WindowPtr win, EventRecord *event) |
| 518 | { |
| 519 | short part, value; |
| 520 | Point mouse; |
| 521 | ControlHandle control; |
| 522 | |
| 523 | if (1 /*is_app_window(win)*/) |
| 524 | { |
| 525 | SetPort (win); |
| 526 | mouse = event->where; |
| 527 | GlobalToLocal (&mouse); |
| 528 | part = FindControl(mouse, win, &control); |
| 529 | if (control == console_v_scrollbar) |
| 530 | { |
| 531 | switch (part) |
| 532 | { |
| 533 | case inThumb: |
| 534 | value = GetCtlValue (control); |
| 535 | part = TrackControl (control, mouse, nil); |
| 536 | if (part) |
| 537 | { |
| 538 | value -= GetCtlValue (control); |
| 539 | if (value) |
| 540 | TEScroll(0, value * (*console_text)->lineHeight, |
| 541 | console_text); |
| 542 | } |
| 543 | break; |
| 544 | default: |
| 545 | value = TrackControl (control, mouse, (ProcPtr) v_scroll_proc); |
| 546 | break; |
| 547 | } |
| 548 | } |
| 549 | else |
| 550 | { |
| 551 | TEClick (mouse, 0, console_text); |
| 552 | } |
| 553 | } |
| 554 | } |
| 555 | |
| 556 | scroll_text (hlines, vlines) |
| 557 | int hlines, vlines; |
| 558 | { |
| 559 | } |
| 560 | |
| 561 | activate_window (win, activate) |
| 562 | WindowPtr win; |
| 563 | int activate; |
| 564 | { |
| 565 | Rect grow_rect; |
| 566 | |
| 567 | if (win == nil) return; |
| 568 | /* It's convenient to make the activated window also be the |
| 569 | current GrafPort. */ |
| 570 | if (activate) |
| 571 | SetPort(win); |
| 572 | /* Activate the console window's scrollbar. */ |
| 573 | if (win == console_window) |
| 574 | { |
| 575 | if (activate) |
| 576 | { |
| 577 | TEActivate (console_text); |
| 578 | /* Cause the grow icon to be redrawn at the next update. */ |
| 579 | grow_rect = console_window->portRect; |
| 580 | grow_rect.top = grow_rect.bottom - sbarwid; |
| 581 | grow_rect.left = grow_rect.right - sbarwid; |
| 582 | InvalRect (&grow_rect); |
| 583 | } |
| 584 | else |
| 585 | { |
| 586 | TEDeactivate (console_text); |
| 587 | DrawGrowIcon (console_window); |
| 588 | } |
| 589 | HiliteControl (console_v_scrollbar, (activate ? 0 : 255)); |
| 590 | } |
| 591 | } |
| 592 | |
| 593 | update_window (win) |
| 594 | WindowPtr win; |
| 595 | { |
| 596 | int controls = 1, growbox = 0; |
| 597 | GrafPtr oldport; |
| 598 | |
| 599 | /* Set the updating window to be the current grafport. */ |
| 600 | GetPort (&oldport); |
| 601 | SetPort (win); |
| 602 | /* recalc_depths(); */ |
| 603 | BeginUpdate (win); |
| 604 | if (win == console_window) |
| 605 | { |
| 606 | draw_console (); |
| 607 | controls = 1; |
| 608 | growbox = 1; |
| 609 | } |
| 610 | if (controls) |
| 611 | UpdateControls (win, win->visRgn); |
| 612 | if (growbox) |
| 613 | DrawGrowIcon (win); |
| 614 | EndUpdate (win); |
| 615 | SetPort (oldport); |
| 616 | } |
| 617 | |
| 618 | adjust_menus () |
| 619 | { |
| 620 | } |
| 621 | |
| 622 | do_menu_command (which) |
| 623 | long which; |
| 624 | { |
| 625 | short menuid, menuitem; |
| 626 | short itemHit; |
| 627 | Str255 daname; |
| 628 | short daRefNum; |
| 629 | Boolean handledbyda; |
| 630 | WindowPtr win; |
| 631 | short ditem; |
| 632 | int i; |
| 633 | char cmdbuf[300]; |
| 634 | |
| 635 | cmdbuf[0] = '\0'; |
| 636 | menuid = HiWord (which); |
| 637 | menuitem = LoWord (which); |
| 638 | switch (menuid) |
| 639 | { |
| 640 | case mApple: |
| 641 | switch (menuitem) |
| 642 | { |
| 643 | case miAbout: |
| 644 | Alert (128, nil); |
| 645 | break; |
| 646 | #if 0 |
| 647 | case miHelp: |
| 648 | /* (should pop up help info) */ |
| 649 | break; |
| 650 | #endif |
| 651 | default: |
| 652 | GetItem (GetMHandle (mApple), menuitem, daname); |
| 653 | daRefNum = OpenDeskAcc (daname); |
| 654 | } |
| 655 | break; |
| 656 | case mFile: |
| 657 | switch (menuitem) |
| 658 | { |
| 659 | case miFileNew: |
| 660 | if (console_window == FrontWindow ()) |
| 661 | { |
| 662 | close_window (console_window); |
| 663 | } |
| 664 | new_console_window (); |
| 665 | break; |
| 666 | case miFileOpen: |
| 667 | SysBeep (20); |
| 668 | break; |
| 669 | case miFileQuit: |
| 670 | ExitToShell (); |
| 671 | break; |
| 672 | } |
| 673 | break; |
| 674 | case mEdit: |
| 675 | /* handledbyda = SystemEdit(menuitem-1); */ |
| 676 | switch (menuitem) |
| 677 | { |
| 678 | case miEditCut: |
| 679 | TECut (console_text); |
| 680 | break; |
| 681 | case miEditCopy: |
| 682 | TECopy (console_text); |
| 683 | break; |
| 684 | case miEditPaste: |
| 685 | TEPaste (console_text); |
| 686 | break; |
| 687 | case miEditClear: |
| 688 | TEDelete (console_text); |
| 689 | break; |
| 690 | } |
| 691 | /* All of these operations need the same postprocessing. */ |
| 692 | adjust_console_sizes (); |
| 693 | adjust_console_scrollbars (); |
| 694 | adjust_console_text (); |
| 695 | break; |
| 696 | case mDebug: |
| 697 | switch (menuitem) |
| 698 | { |
| 699 | case miDebugTarget: |
| 700 | sprintf (cmdbuf, "target %s", "remote"); |
| 701 | break; |
| 702 | case miDebugRun: |
| 703 | sprintf (cmdbuf, "run"); |
| 704 | break; |
| 705 | case miDebugContinue: |
| 706 | sprintf (cmdbuf, "continue"); |
| 707 | break; |
| 708 | case miDebugStep: |
| 709 | sprintf (cmdbuf, "step"); |
| 710 | break; |
| 711 | case miDebugNext: |
| 712 | sprintf (cmdbuf, "next"); |
| 713 | break; |
| 714 | } |
| 715 | break; |
| 716 | } |
| 717 | HiliteMenu (0); |
| 718 | /* Execute a command if one had been given. Do here because a command |
| 719 | may longjmp before we get a chance to unhilite the menu. */ |
| 720 | if (strlen (cmdbuf) > 0) |
| 721 | execute_command (cmdbuf, 0); |
| 722 | } |
| 723 | |
| 724 | char commandbuf[1000]; |
| 725 | |
| 726 | do_keyboard_command (key) |
| 727 | int key; |
| 728 | { |
| 729 | int startpos, endpos, i, len; |
| 730 | char *last_newline; |
| 731 | char buf[10], *text_str, *command, *cmd_start; |
| 732 | CharsHandle text; |
| 733 | |
| 734 | if (key == '\015' || key == '\003') |
| 735 | { |
| 736 | text = TEGetText (console_text); |
| 737 | HLock ((Handle) text); |
| 738 | text_str = *text; |
| 739 | startpos = (*console_text)->selStart; |
| 740 | endpos = (*console_text)->selEnd; |
| 741 | if (startpos != endpos) |
| 742 | { |
| 743 | len = endpos - startpos; |
| 744 | cmd_start = text_str + startpos; |
| 745 | } |
| 746 | else |
| 747 | { |
| 748 | for (i = startpos - 1; i >= 0; --i) |
| 749 | if (text_str[i] == '\015') |
| 750 | break; |
| 751 | last_newline = text_str + i; |
| 752 | len = (text_str + startpos) - 1 - last_newline; |
| 753 | cmd_start = last_newline + 1; |
| 754 | } |
| 755 | if (len > 1000) len = 999; |
| 756 | if (len < 0) len = 0; |
| 757 | strncpy (commandbuf + 1, cmd_start, len); |
| 758 | commandbuf[1 + len] = 0; |
| 759 | command = commandbuf + 1; |
| 760 | HUnlock ((Handle) text); |
| 761 | commandbuf[0] = strlen(command); |
| 762 | |
| 763 | /* Insert a newline and recalculate before doing any command. */ |
| 764 | key = '\015'; |
| 765 | TEKey (key, console_text); |
| 766 | TEInsert (buf, 1, console_text); |
| 767 | adjust_console_sizes (); |
| 768 | adjust_console_scrollbars (); |
| 769 | adjust_console_text (); |
| 770 | |
| 771 | if (strlen (command) > 0) |
| 772 | { |
| 773 | execute_command (command, 0); |
| 774 | bpstat_do_actions (&stop_bpstat); |
| 775 | } |
| 776 | } |
| 777 | else |
| 778 | { |
| 779 | /* A self-inserting character. This includes delete. */ |
| 780 | TEKey (key, console_text); |
| 781 | } |
| 782 | } |
| 783 | |
| 784 | /* Draw all graphical stuff in the console window. */ |
| 785 | |
| 786 | draw_console () |
| 787 | { |
| 788 | SetPort (console_window); |
| 789 | TEUpdate (&(console_window->portRect), console_text); |
| 790 | } |
| 791 | |
| 792 | /* Cause an update of a given window's entire contents. */ |
| 793 | |
| 794 | force_update (win) |
| 795 | WindowPtr win; |
| 796 | { |
| 797 | GrafPtr oldport; |
| 798 | |
| 799 | if (win == nil) return; |
| 800 | GetPort (&oldport); |
| 801 | SetPort (win); |
| 802 | EraseRect (&win->portRect); |
| 803 | InvalRect (&win->portRect); |
| 804 | SetPort (oldport); |
| 805 | } |
| 806 | |
| 807 | adjust_console_sizes () |
| 808 | { |
| 809 | Rect tmprect; |
| 810 | |
| 811 | tmprect = console_window->portRect; |
| 812 | /* Move and size the scrollbar. */ |
| 813 | MoveControl (console_v_scrollbar, tmprect.right - sbarwid, 0); |
| 814 | SizeControl (console_v_scrollbar, sbarwid + 1, tmprect.bottom - sbarwid + 1); |
| 815 | /* Move and size the text. */ |
| 816 | tmprect.left += 7; |
| 817 | tmprect.right -= sbarwid; |
| 818 | tmprect.bottom -= sbarwid; |
| 819 | InsetRect(&tmprect, 1, 1); |
| 820 | (*console_text)->destRect = tmprect; |
| 821 | /* Fiddle bottom of viewrect to be even multiple of text lines. */ |
| 822 | tmprect.bottom = tmprect.top |
| 823 | + ((tmprect.bottom - tmprect.top) / (*console_text)->lineHeight) |
| 824 | * (*console_text)->lineHeight; |
| 825 | (*console_text)->viewRect = tmprect; |
| 826 | } |
| 827 | |
| 828 | adjust_console_scrollbars () |
| 829 | { |
| 830 | int lines, newmax, value; |
| 831 | |
| 832 | (*console_v_scrollbar)->contrlVis = 0; |
| 833 | lines = (*console_text)->nLines; |
| 834 | newmax = lines - (((*console_text)->viewRect.bottom |
| 835 | - (*console_text)->viewRect.top) |
| 836 | / (*console_text)->lineHeight); |
| 837 | if (newmax < 0) newmax = 0; |
| 838 | SetCtlMax (console_v_scrollbar, newmax); |
| 839 | value = ((*console_text)->viewRect.top - (*console_text)->destRect.top) |
| 840 | / (*console_text)->lineHeight; |
| 841 | SetCtlValue (console_v_scrollbar, value); |
| 842 | (*console_v_scrollbar)->contrlVis = 0xff; |
| 843 | ShowControl (console_v_scrollbar); |
| 844 | } |
| 845 | |
| 846 | /* Scroll the TE record so that it is consistent with the scrollbar(s). */ |
| 847 | |
| 848 | adjust_console_text () |
| 849 | { |
| 850 | TEScroll (((*console_text)->viewRect.left |
| 851 | - (*console_text)->destRect.left) |
| 852 | - 0 /* get h scroll value */, |
| 853 | ((((*console_text)->viewRect.top - (*console_text)->destRect.top) |
| 854 | / (*console_text)->lineHeight) |
| 855 | - GetCtlValue (console_v_scrollbar)) |
| 856 | * (*console_text)->lineHeight, |
| 857 | console_text); |
| 858 | } |
| 859 | |
| 860 | /* Readline substitute. */ |
| 861 | |
| 862 | char * |
| 863 | readline (char *prrompt) |
| 864 | { |
| 865 | return gdb_readline (prrompt); |
| 866 | } |
| 867 | |
| 868 | char *rl_completer_word_break_characters; |
| 869 | |
| 870 | char *rl_completer_quote_characters; |
| 871 | |
| 872 | int (*rl_completion_entry_function) (); |
| 873 | |
| 874 | int rl_point; |
| 875 | |
| 876 | char *rl_line_buffer; |
| 877 | |
| 878 | char *rl_readline_name; |
| 879 | |
| 880 | /* History substitute. */ |
| 881 | |
| 882 | void |
| 883 | add_history (char *buf) |
| 884 | { |
| 885 | } |
| 886 | |
| 887 | void |
| 888 | stifle_history (int n) |
| 889 | { |
| 890 | } |
| 891 | |
| 892 | int |
| 893 | unstifle_history () |
| 894 | { |
| 895 | } |
| 896 | |
| 897 | int |
| 898 | read_history (char *name) |
| 899 | { |
| 900 | } |
| 901 | |
| 902 | int |
| 903 | write_history (char *name) |
| 904 | { |
| 905 | } |
| 906 | |
| 907 | int |
| 908 | history_expand (char *x, char **y) |
| 909 | { |
| 910 | } |
| 911 | |
| 912 | extern HIST_ENTRY * |
| 913 | history_get (int xxx) |
| 914 | { |
| 915 | return NULL; |
| 916 | } |
| 917 | |
| 918 | int history_base; |
| 919 | |
| 920 | char * |
| 921 | filename_completion_function (char *text, char *name) |
| 922 | { |
| 923 | return "?"; |
| 924 | } |
| 925 | |
| 926 | char * |
| 927 | tilde_expand (char *str) |
| 928 | { |
| 929 | return strsave (str); |
| 930 | } |
| 931 | |
| 932 | /* Modified versions of standard I/O. */ |
| 933 | |
| 934 | #undef fprintf |
| 935 | |
| 936 | int |
| 937 | hacked_fprintf (FILE *fp, const char *fmt, ...) |
| 938 | { |
| 939 | int ret; |
| 940 | va_list ap; |
| 941 | |
| 942 | va_start (ap, fmt); |
| 943 | if (mac_app && (fp == stdout || fp == stderr)) |
| 944 | { |
| 945 | char buf[1000]; |
| 946 | |
| 947 | ret = vsprintf(buf, fmt, ap); |
| 948 | TEInsert (buf, strlen(buf), console_text); |
| 949 | } |
| 950 | else |
| 951 | ret = vfprintf (fp, fmt, ap); |
| 952 | va_end (ap); |
| 953 | return ret; |
| 954 | } |
| 955 | |
| 956 | #undef printf |
| 957 | |
| 958 | int |
| 959 | hacked_printf (const char *fmt, ...) |
| 960 | { |
| 961 | int ret; |
| 962 | va_list ap; |
| 963 | |
| 964 | va_start (ap, fmt); |
| 965 | ret = hacked_vfprintf(stdout, fmt, ap); |
| 966 | va_end (ap); |
| 967 | return ret; |
| 968 | } |
| 969 | |
| 970 | #undef vfprintf |
| 971 | |
| 972 | int |
| 973 | hacked_vfprintf (FILE *fp, const char *format, va_list args) |
| 974 | { |
| 975 | if (mac_app && (fp == stdout || fp == stderr)) |
| 976 | { |
| 977 | char buf[1000]; |
| 978 | int ret; |
| 979 | |
| 980 | ret = vsprintf(buf, format, args); |
| 981 | TEInsert (buf, strlen(buf), console_text); |
| 982 | if (strchr(buf, '\n')) |
| 983 | { |
| 984 | adjust_console_sizes (); |
| 985 | adjust_console_scrollbars (); |
| 986 | adjust_console_text (); |
| 987 | } |
| 988 | return ret; |
| 989 | } |
| 990 | else |
| 991 | return vfprintf (fp, format, args); |
| 992 | } |
| 993 | |
| 994 | #undef fputs |
| 995 | |
| 996 | hacked_fputs (const char *s, FILE *fp) |
| 997 | { |
| 998 | if (mac_app && (fp == stdout || fp == stderr)) |
| 999 | { |
| 1000 | TEInsert (s, strlen(s), console_text); |
| 1001 | if (strchr(s, '\n')) |
| 1002 | { |
| 1003 | adjust_console_sizes (); |
| 1004 | adjust_console_scrollbars (); |
| 1005 | adjust_console_text (); |
| 1006 | } |
| 1007 | return 0; |
| 1008 | } |
| 1009 | else |
| 1010 | return fputs (s, fp); |
| 1011 | } |
| 1012 | |
| 1013 | #undef fputc |
| 1014 | |
| 1015 | hacked_fputc (const char c, FILE *fp) |
| 1016 | { |
| 1017 | if (mac_app && (fp == stdout || fp == stderr)) |
| 1018 | { |
| 1019 | char buf[1]; |
| 1020 | |
| 1021 | buf[0] = c; |
| 1022 | TEInsert (buf, 1, console_text); |
| 1023 | if (c == '\n') |
| 1024 | { |
| 1025 | adjust_console_sizes (); |
| 1026 | adjust_console_scrollbars (); |
| 1027 | adjust_console_text (); |
| 1028 | } |
| 1029 | return c; |
| 1030 | } |
| 1031 | else |
| 1032 | return fputc (c, fp); |
| 1033 | } |
| 1034 | |
| 1035 | #undef putc |
| 1036 | |
| 1037 | hacked_putc (const char c, FILE *fp) |
| 1038 | { |
| 1039 | if (mac_app && (fp == stdout || fp == stderr)) |
| 1040 | { |
| 1041 | char buf[1]; |
| 1042 | |
| 1043 | buf[0] = c; |
| 1044 | TEInsert (buf, 1, console_text); |
| 1045 | if (c == '\n') |
| 1046 | { |
| 1047 | adjust_console_sizes (); |
| 1048 | adjust_console_scrollbars (); |
| 1049 | adjust_console_text (); |
| 1050 | } |
| 1051 | return c; |
| 1052 | } |
| 1053 | else |
| 1054 | return fputc (c, fp); |
| 1055 | } |
| 1056 | |
| 1057 | #undef fflush |
| 1058 | |
| 1059 | hacked_fflush (FILE *fp) |
| 1060 | { |
| 1061 | if (mac_app && (fp == stdout || fp == stderr)) |
| 1062 | { |
| 1063 | adjust_console_sizes (); |
| 1064 | adjust_console_scrollbars (); |
| 1065 | adjust_console_text (); |
| 1066 | return 0; |
| 1067 | } |
| 1068 | return fflush (fp); |
| 1069 | } |
| 1070 | |
| 1071 | #undef fgetc |
| 1072 | |
| 1073 | hacked_fgetc (FILE *fp) |
| 1074 | { |
| 1075 | if (mac_app && (fp == stdin)) |
| 1076 | { |
| 1077 | /* Catch any attempts to use this. */ |
| 1078 | DebugStr("\pShould not be reading from stdin!"); |
| 1079 | return '\n'; |
| 1080 | } |
| 1081 | return fgetc (fp); |
| 1082 | } |