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