* mdebugread.c (parse_symbol): Use new variable
[deliverable/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
19Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
20
21#include "defs.h"
22
a6b26c44
SS
23#include "readline.h"
24#include "history.h"
25
939baabe
SS
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))
e70a10c3 57#endif /* MPW */
939baabe
SS
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"
939baabe
SS
81
82#include "mac-defs.h"
83
e70a10c3
SS
84int debug_openp = 0;
85
b8ec8d4a
SS
86/* This is true if we are running as a standalone application. */
87
a6b26c44
SS
88int mac_app;
89
b8ec8d4a
SS
90/* This is true if we are using WaitNextEvent. */
91
92int use_wne;
93
94/* This is true if we have Color Quickdraw. */
95
96int has_color_qd;
939baabe 97
b8ec8d4a
SS
98/* This is true if we are using Color Quickdraw. */
99
100int use_color_qd;
939baabe
SS
101
102int inbackground;
103
104Rect dragrect = { -32000, -32000, 32000, 32000 };
105Rect sizerect;
106
107int sbarwid = 15;
108
109/* Globals for the console window. */
110
111WindowPtr console_window;
112
113ControlHandle console_v_scrollbar;
114
115Rect console_v_scroll_rect;
116
117TEHandle console_text;
118
119Rect console_text_rect;
120
a6b26c44
SS
121/* This will go away eventually. */
122gdb_has_a_terminal () { return 1; }
123
939baabe
SS
124mac_init ()
125{
126 SysEnvRec se;
127 int eventloopdone = 0;
e70a10c3 128 char *str;
939baabe
SS
129 Boolean gotevent;
130 Point mouse;
131 EventRecord event;
132 WindowPtr win;
133 RgnHandle cursorRgn;
134 int i;
135 Handle menubar;
136 MenuHandle menu;
b8ec8d4a
SS
137 Handle siow_resource;
138
139 mac_app = 0;
140
e70a10c3
SS
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
b8ec8d4a
SS
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;
939baabe
SS
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);
b8ec8d4a
SS
175 has_color_qd = se.hasColorQD;
176 /* Use it if we got it. */
177 use_color_qd = has_color_qd;
939baabe
SS
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
58c0b523 198 new_console_window ();
58c0b523
SS
199}
200
201new_console_window ()
202{
939baabe 203 /* Create the main window we're going to play in. */
b8ec8d4a 204 if (has_color_qd)
939baabe
SS
205 console_window = GetNewCWindow (wConsole, NULL, (WindowPtr) -1L);
206 else
207 console_window = GetNewWindow (wConsole, NULL, (WindowPtr) -1L);
208
939baabe
SS
209 SetPort (console_window);
210 console_text_rect = console_window->portRect;
58c0b523
SS
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;
939baabe
SS
214 console_text_rect.bottom -= sbarwid - 1;
215 console_text_rect.right -= sbarwid - 1;
216 console_text = TENew (&console_text_rect, &console_text_rect);
58c0b523 217 TESetSelect (0, 40000, console_text);
939baabe 218 TEDelete (console_text);
58c0b523 219 TEAutoView (1, console_text);
939baabe
SS
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);
939baabe
SS
230}
231
232mac_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;
b8ec8d4a 241 int i, tm;
939baabe
SS
242 Handle menubar;
243 MenuHandle menu;
244
b8ec8d4a
SS
245 /* Figure out if the WaitNextEvent Trap is available. */
246 use_wne =
939baabe 247 (NGetTrapAddress (0x60, ToolTrap) != NGetTrapAddress (0x9f, ToolTrap));
b8ec8d4a 248 /* Pass WaitNextEvent an empty region the first time through. */
939baabe 249 cursorRgn = NewRgn ();
b8ec8d4a 250 /* Go into the main event-handling loop. */
939baabe
SS
251 while (!eventloopdone)
252 {
b8ec8d4a
SS
253 /* Use WaitNextEvent if it is available, otherwise GetNextEvent. */
254 if (use_wne)
939baabe
SS
255 {
256 get_global_mouse (&mouse);
257 adjust_cursor (mouse, cursorRgn);
b8ec8d4a
SS
258 tm = GetCaretTime();
259 gotevent = WaitNextEvent (everyEvent, &event, tm, cursorRgn);
939baabe
SS
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 }
58c0b523
SS
283 else
284 {
285 do_idle ();
286 }
939baabe
SS
287 }
288}
289
b8ec8d4a
SS
290/* Collect the global coordinates of the mouse pointer. */
291
939baabe
SS
292get_global_mouse (mouse)
293Point *mouse;
294{
295 EventRecord evt;
296
297 OSEventAvail (0, &evt);
298 *mouse = evt.where;
299}
300
b8ec8d4a
SS
301/* Change the cursor's appearance to be appropriate for the given mouse
302 location. */
303
939baabe
SS
304adjust_cursor (mouse, region)
305Point mouse;
306RgnHandle region;
307{
308}
309
b8ec8d4a 310/* Decipher an event, maybe do something with it. */
939baabe
SS
311
312do_event (evt)
313EventRecord *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:
58c0b523 416 do_idle ();
939baabe
SS
417 rslt = 1;
418 break;
419 default:
420 break;
421 }
422 return rslt;
423}
424
58c0b523
SS
425/* Do any idle-time activities. */
426
427do_idle ()
428{
429 TEIdle (console_text);
430}
431
939baabe
SS
432grow_window (win, where)
433WindowPtr win;
434Point where;
435{
436 long winsize;
437 int h, v;
438 GrafPtr oldport;
439
440 winsize = GrowWindow (win, where, &sizerect);
b8ec8d4a 441 /* Only do anything if it actually changed size. */
939baabe
SS
442 if (winsize != 0)
443 {
444 GetPort (&oldport);
445 SetPort (win);
b8ec8d4a
SS
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 }
939baabe
SS
454 SetPort (oldport);
455 }
456}
457
458zoom_window (win, where, part)
459WindowPtr win;
460Point where;
461short part;
462{
58c0b523 463 ZoomWindow (win, part, (win == FrontWindow ()));
b8ec8d4a
SS
464 if (win == console_window)
465 {
466 resize_console_window ();
467 }
468}
469
470resize_console_window ()
471{
58c0b523
SS
472 adjust_console_sizes ();
473 adjust_console_scrollbars ();
474 adjust_console_text ();
b8ec8d4a 475 InvalRect (&console_window->portRect);
939baabe
SS
476}
477
478close_window (win)
479WindowPtr win;
480{
481}
482
58c0b523
SS
483pascal void
484v_scroll_proc (ControlHandle control, short part)
939baabe 485{
58c0b523
SS
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
517do_mouse_down (WindowPtr win, EventRecord *event)
518{
519 short part, value;
939baabe
SS
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 {
58c0b523
SS
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 }
939baabe
SS
548 }
549 else
550 {
551 TEClick (mouse, 0, console_text);
552 }
553 }
554}
555
b8ec8d4a
SS
556scroll_text (hlines, vlines)
557int hlines, vlines;
558{
559}
560
939baabe
SS
561activate_window (win, activate)
562WindowPtr win;
563int activate;
564{
58c0b523
SS
565 Rect grow_rect;
566
939baabe
SS
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)
58c0b523
SS
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 }
939baabe
SS
591}
592
593update_window (win)
594WindowPtr 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
618adjust_menus ()
619{
620}
621
622do_menu_command (which)
623long 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;
58c0b523 633 char cmdbuf[300];
939baabe 634
58c0b523 635 cmdbuf[0] = '\0';
939baabe
SS
636 menuid = HiWord (which);
637 menuitem = LoWord (which);
638 switch (menuid)
639 {
640 case mApple:
641 switch (menuitem)
642 {
643 case miAbout:
58c0b523
SS
644 Alert (128, nil);
645 break;
646#if 0
647 case miHelp:
648 /* (should pop up help info) */
939baabe 649 break;
58c0b523 650#endif
939baabe
SS
651 default:
652 GetItem (GetMHandle (mApple), menuitem, daname);
653 daRefNum = OpenDeskAcc (daname);
654 }
655 break;
656 case mFile:
657 switch (menuitem)
658 {
58c0b523
SS
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;
939baabe
SS
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:
58c0b523 679 TECut (console_text);
939baabe
SS
680 break;
681 case miEditCopy:
58c0b523 682 TECopy (console_text);
939baabe
SS
683 break;
684 case miEditPaste:
58c0b523 685 TEPaste (console_text);
939baabe
SS
686 break;
687 case miEditClear:
58c0b523
SS
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");
939baabe
SS
713 break;
714 }
715 break;
716 }
717 HiliteMenu (0);
58c0b523
SS
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);
939baabe
SS
722}
723
724char commandbuf[1000];
725
726do_keyboard_command (key)
58c0b523 727int key;
939baabe 728{
58c0b523 729 int startpos, endpos, i, len;
a6b26c44 730 char *last_newline;
58c0b523 731 char buf[10], *text_str, *command, *cmd_start;
939baabe
SS
732 CharsHandle text;
733
734 if (key == '\015' || key == '\003')
735 {
939baabe
SS
736 text = TEGetText (console_text);
737 HLock ((Handle) text);
58c0b523 738 text_str = *text;
939baabe
SS
739 startpos = (*console_text)->selStart;
740 endpos = (*console_text)->selEnd;
741 if (startpos != endpos)
742 {
58c0b523
SS
743 len = endpos - startpos;
744 cmd_start = text_str + startpos;
939baabe
SS
745 }
746 else
747 {
58c0b523
SS
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;
939baabe 754 }
58c0b523
SS
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;
939baabe
SS
760 HUnlock ((Handle) text);
761 commandbuf[0] = strlen(command);
939baabe 762
58c0b523
SS
763 /* Insert a newline and recalculate before doing any command. */
764 key = '\015';
765 TEKey (key, console_text);
939baabe 766 TEInsert (buf, 1, console_text);
58c0b523
SS
767 adjust_console_sizes ();
768 adjust_console_scrollbars ();
769 adjust_console_text ();
939baabe 770
58c0b523
SS
771 if (strlen (command) > 0)
772 {
773 execute_command (command, 0);
774 bpstat_do_actions (&stop_bpstat);
775 }
939baabe 776 }
939baabe
SS
777 else
778 {
b8ec8d4a 779 /* A self-inserting character. This includes delete. */
58c0b523 780 TEKey (key, console_text);
939baabe
SS
781 }
782}
783
b8ec8d4a
SS
784/* Draw all graphical stuff in the console window. */
785
939baabe
SS
786draw_console ()
787{
939baabe
SS
788 SetPort (console_window);
789 TEUpdate (&(console_window->portRect), console_text);
939baabe
SS
790}
791
b8ec8d4a 792/* Cause an update of a given window's entire contents. */
939baabe
SS
793
794force_update (win)
795WindowPtr 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
58c0b523
SS
807adjust_console_sizes ()
808{
809 Rect tmprect;
810
811 tmprect = console_window->portRect;
b8ec8d4a 812 /* Move and size the scrollbar. */
58c0b523
SS
813 MoveControl (console_v_scrollbar, tmprect.right - sbarwid, 0);
814 SizeControl (console_v_scrollbar, sbarwid + 1, tmprect.bottom - sbarwid + 1);
b8ec8d4a 815 /* Move and size the text. */
58c0b523
SS
816 tmprect.left += 7;
817 tmprect.right -= sbarwid;
818 tmprect.bottom -= sbarwid;
819 InsetRect(&tmprect, 1, 1);
58c0b523 820 (*console_text)->destRect = tmprect;
b8ec8d4a
SS
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;
58c0b523
SS
826}
827
939baabe
SS
828adjust_console_scrollbars ()
829{
830 int lines, newmax, value;
831
58c0b523 832 (*console_v_scrollbar)->contrlVis = 0;
939baabe 833 lines = (*console_text)->nLines;
58c0b523
SS
834 newmax = lines - (((*console_text)->viewRect.bottom
835 - (*console_text)->viewRect.top)
939baabe
SS
836 / (*console_text)->lineHeight);
837 if (newmax < 0) newmax = 0;
a6b26c44 838 SetCtlMax (console_v_scrollbar, newmax);
939baabe
SS
839 value = ((*console_text)->viewRect.top - (*console_text)->destRect.top)
840 / (*console_text)->lineHeight;
a6b26c44 841 SetCtlValue (console_v_scrollbar, value);
58c0b523
SS
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
848adjust_console_text ()
849{
850 TEScroll (((*console_text)->viewRect.left
851 - (*console_text)->destRect.left)
852 - 0 /* get h scroll value */,
b8ec8d4a
SS
853 ((((*console_text)->viewRect.top - (*console_text)->destRect.top)
854 / (*console_text)->lineHeight)
58c0b523
SS
855 - GetCtlValue (console_v_scrollbar))
856 * (*console_text)->lineHeight,
857 console_text);
939baabe 858}
a6b26c44
SS
859
860/* Readline substitute. */
861
862char *
863readline (char *prrompt)
864{
865 return gdb_readline (prrompt);
866}
867
868char *rl_completer_word_break_characters;
869
870char *rl_completer_quote_characters;
871
872int (*rl_completion_entry_function) ();
873
874int rl_point;
875
876char *rl_line_buffer;
877
878char *rl_readline_name;
879
880/* History substitute. */
881
882void
883add_history (char *buf)
884{
885}
886
887void
888stifle_history (int n)
889{
890}
891
892int
893unstifle_history ()
894{
895}
896
897int
898read_history (char *name)
899{
900}
901
902int
903write_history (char *name)
904{
905}
906
907int
908history_expand (char *x, char **y)
909{
910}
911
912extern HIST_ENTRY *
913history_get (int xxx)
914{
915 return NULL;
916}
917
918int history_base;
919
920char *
921filename_completion_function (char *text, char *name)
922{
923 return "?";
924}
925
926char *
927tilde_expand (char *str)
928{
929 return strsave (str);
930}
931
932/* Modified versions of standard I/O. */
933
934#include <stdarg.h>
935
936#undef fprintf
937
938int
939hacked_fprintf (FILE *fp, const char *fmt, ...)
940{
941 int ret;
942 va_list ap;
943
944 va_start (ap, fmt);
945 if (mac_app && (fp == stdout || fp == stderr))
946 {
947 char buf[1000];
948
949 ret = vsprintf(buf, fmt, ap);
950 TEInsert (buf, strlen(buf), console_text);
a6b26c44
SS
951 }
952 else
953 ret = vfprintf (fp, fmt, ap);
954 va_end (ap);
955 return ret;
956}
957
958#undef printf
959
960int
961hacked_printf (const char *fmt, ...)
962{
963 int ret;
964 va_list ap;
965
966 va_start (ap, fmt);
b8ec8d4a 967 ret = hacked_vfprintf(stdout, fmt, ap);
a6b26c44
SS
968 va_end (ap);
969 return ret;
970}
971
972#undef vfprintf
973
974int
975hacked_vfprintf (FILE *fp, const char *format, va_list args)
976{
977 if (mac_app && (fp == stdout || fp == stderr))
978 {
979 char buf[1000];
980 int ret;
981
982 ret = vsprintf(buf, format, args);
983 TEInsert (buf, strlen(buf), console_text);
b8ec8d4a
SS
984 if (strchr(buf, '\n'))
985 {
986 adjust_console_sizes ();
987 adjust_console_scrollbars ();
988 adjust_console_text ();
989 }
a6b26c44
SS
990 return ret;
991 }
992 else
993 return vfprintf (fp, format, args);
994}
995
996#undef fputs
997
998hacked_fputs (const char *s, FILE *fp)
999{
1000 if (mac_app && (fp == stdout || fp == stderr))
1001 {
1002 TEInsert (s, strlen(s), console_text);
b8ec8d4a
SS
1003 if (strchr(s, '\n'))
1004 {
1005 adjust_console_sizes ();
1006 adjust_console_scrollbars ();
1007 adjust_console_text ();
1008 }
a6b26c44
SS
1009 return 0;
1010 }
1011 else
1012 return fputs (s, fp);
1013}
1014
1015#undef fputc
1016
1017hacked_fputc (const char c, FILE *fp)
1018{
1019 if (mac_app && (fp == stdout || fp == stderr))
1020 {
b8ec8d4a 1021 char buf[1];
a6b26c44
SS
1022
1023 buf[0] = c;
1024 TEInsert (buf, 1, console_text);
b8ec8d4a
SS
1025 if (c == '\n')
1026 {
1027 adjust_console_sizes ();
1028 adjust_console_scrollbars ();
1029 adjust_console_text ();
1030 }
1031 return c;
a6b26c44
SS
1032 }
1033 else
1034 return fputc (c, fp);
1035}
1036
1037#undef putc
1038
1039hacked_putc (const char c, FILE *fp)
1040{
1041 if (mac_app && (fp == stdout || fp == stderr))
1042 {
b8ec8d4a 1043 char buf[1];
a6b26c44
SS
1044
1045 buf[0] = c;
1046 TEInsert (buf, 1, console_text);
b8ec8d4a
SS
1047 if (c == '\n')
1048 {
1049 adjust_console_sizes ();
1050 adjust_console_scrollbars ();
1051 adjust_console_text ();
1052 }
1053 return c;
a6b26c44
SS
1054 }
1055 else
1056 return fputc (c, fp);
1057}
1058
1059#undef fflush
1060
1061hacked_fflush (FILE *fp)
1062{
1063 if (mac_app && (fp == stdout || fp == stderr))
b8ec8d4a
SS
1064 {
1065 adjust_console_sizes ();
1066 adjust_console_scrollbars ();
1067 adjust_console_text ();
1068 return 0;
1069 }
a6b26c44
SS
1070 return fflush (fp);
1071}
b8ec8d4a
SS
1072
1073#undef fgetc
1074
1075hacked_fgetc (FILE *fp)
1076{
1077 if (mac_app && (fp == stdin))
1078 {
1079 /* Catch any attempts to use this. */
1080 DebugStr("\pShould not be reading from stdin!");
1081 return '\n';
1082 }
1083 return fgetc (fp);
1084}
This page took 0.131619 seconds and 4 git commands to generate.