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