OSDN Git Service

2001-02-04 Fernando Nasser <fnasser@redhat.com>
[pf3gnuchains/pf3gnuchains4x.git] / gdb / mac-xdep.c
1 /* Top level support for Mac interface to GDB, the GNU debugger.
2    Copyright 1994, 2001 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., 59 Temple Place - Suite 330,
20    Boston, MA 02111-1307, USA.  */
21
22 #include "defs.h"
23
24 #include <readline/readline.h>
25 #include <readline/history.h>
26
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 <Gestalt.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 =
105 {-32000, -32000, 32000, 32000};
106 Rect sizerect;
107
108 int sbarwid = 15;
109
110 /* Globals for the console window. */
111
112 WindowPtr console_window;
113
114 ControlHandle console_v_scrollbar;
115
116 Rect console_v_scroll_rect;
117
118 TEHandle console_text;
119
120 Rect console_text_rect;
121
122 /* This will go away eventually. */
123 gdb_has_a_terminal (void)
124 {
125   return 1;
126 }
127
128 mac_init (void)
129 {
130   SysEnvRec se;
131   int eventloopdone = 0;
132   char *str;
133   Boolean gotevent;
134   Point mouse;
135   EventRecord event;
136   WindowPtr win;
137   RgnHandle cursorRgn;
138   int i;
139   Handle menubar;
140   MenuHandle menu;
141   Handle siow_resource;
142
143   mac_app = 0;
144
145   str = getenv ("DEBUG_GDB");
146   if (str != NULL && str[0] != '\0')
147     {
148       if (strcmp (str, "openp") == 0)
149         debug_openp = 1;
150     }
151
152   /* Don't do anything if we`re running under MPW. */
153   if (!StandAlone)
154     return;
155
156   /* Don't do anything if we're using SIOW. */
157   /* This test requires that the siow 0 resource, as defined in
158      {RIncludes}siow.r, not be messed with.  If it is, then the
159      standard Mac setup below will step on SIOW's Mac setup and
160      most likely crash the machine. */
161   siow_resource = GetResource ('siow', 0);
162   if (siow_resource != nil)
163     return;
164
165   mac_app = 1;
166
167   /* Do the standard Mac environment setup. */
168   InitGraf (&QD (thePort));
169   InitFonts ();
170   FlushEvents (everyEvent, 0);
171   InitWindows ();
172   InitMenus ();
173   TEInit ();
174   InitDialogs (NULL);
175   InitCursor ();
176
177   /* Color Quickdraw is different from Classic QD. */
178   SysEnvirons (2, &se);
179   has_color_qd = se.hasColorQD;
180   /* Use it if we got it. */
181   use_color_qd = has_color_qd;
182
183   sizerect.top = 50;
184   sizerect.left = 50;
185   sizerect.bottom = 1000;
186   sizerect.right = 1000;
187 #if 0
188   sizerect.bottom = screenBits.bounds.bottom - screenBits.bounds.top;
189   sizerect.right = screenBits.bounds.right - screenBits.bounds.left;
190 #endif
191
192   /* Set up the menus. */
193   menubar = GetNewMBar (mbMain);
194   SetMenuBar (menubar);
195   /* Add the DAs etc as usual. */
196   menu = GetMHandle (mApple);
197   if (menu != nil)
198     {
199       AddResMenu (menu, 'DRVR');
200     }
201   DrawMenuBar ();
202
203   new_console_window ();
204 }
205
206 new_console_window (void)
207 {
208   /* Create the main window we're going to play in. */
209   if (has_color_qd)
210     console_window = GetNewCWindow (wConsole, NULL, (WindowPtr) - 1L);
211   else
212     console_window = GetNewWindow (wConsole, NULL, (WindowPtr) - 1L);
213
214   SetPort (console_window);
215   console_text_rect = console_window->portRect;
216   /* Leave 8 pixels of blank space, for aesthetic reasons and to
217      make it easier to select from the beginning of a line. */
218   console_text_rect.left += 8;
219   console_text_rect.bottom -= sbarwid - 1;
220   console_text_rect.right -= sbarwid - 1;
221   console_text = TENew (&console_text_rect, &console_text_rect);
222   TESetSelect (0, 40000, console_text);
223   TEDelete (console_text);
224   TEAutoView (1, console_text);
225
226   console_v_scroll_rect = console_window->portRect;
227   console_v_scroll_rect.bottom -= sbarwid - 1;
228   console_v_scroll_rect.left = console_v_scroll_rect.right - sbarwid;
229   console_v_scrollbar =
230     NewControl (console_window, &console_v_scroll_rect,
231                 "\p", 1, 0, 0, 0, scrollBarProc, 0L);
232
233   ShowWindow (console_window);
234   SelectWindow (console_window);
235 }
236
237 mac_command_loop (void)
238 {
239   SysEnvRec se;
240   int eventloopdone = 0;
241   Boolean gotevent;
242   Point mouse;
243   EventRecord event;
244   WindowPtr win;
245   RgnHandle cursorRgn;
246   int i, tm;
247   Handle menubar;
248   MenuHandle menu;
249
250   /* Figure out if the WaitNextEvent Trap is available.  */
251   use_wne =
252     (NGetTrapAddress (0x60, ToolTrap) != NGetTrapAddress (0x9f, ToolTrap));
253   /* Pass WaitNextEvent an empty region the first time through.  */
254   cursorRgn = NewRgn ();
255   /* Go into the main event-handling loop.  */
256   while (!eventloopdone)
257     {
258       /* Use WaitNextEvent if it is available, otherwise GetNextEvent.  */
259       if (use_wne)
260         {
261           get_global_mouse (&mouse);
262           adjust_cursor (mouse, cursorRgn);
263           tm = GetCaretTime ();
264           gotevent = WaitNextEvent (everyEvent, &event, tm, cursorRgn);
265         }
266       else
267         {
268           SystemTask ();
269           gotevent = GetNextEvent (everyEvent, &event);
270         }
271       /* First decide if the event is for a dialog or is just any old event. */
272       if (FrontWindow () != nil && IsDialogEvent (&event))
273         {
274           short itemhit;
275           DialogPtr dialog;
276
277           /* Handle all the modeless dialogs here. */
278           if (DialogSelect (&event, &dialog, &itemhit))
279             {
280             }
281         }
282       else if (gotevent)
283         {
284           /* Make sure we have the right cursor before handling the event. */
285           adjust_cursor (event.where, cursorRgn);
286           do_event (&event);
287         }
288       else
289         {
290           do_idle ();
291         }
292     }
293 }
294
295 /* Collect the global coordinates of the mouse pointer.  */
296
297 get_global_mouse (Point *mouse)
298 {
299   EventRecord evt;
300
301   OSEventAvail (0, &evt);
302   *mouse = evt.where;
303 }
304
305 /* Change the cursor's appearance to be appropriate for the given mouse
306    location.  */
307
308 adjust_cursor (Point mouse, RgnHandle region)
309 {
310 }
311
312 /* Decipher an event, maybe do something with it.  */
313
314 do_event (EventRecord *evt)
315 {
316   short part, err, rslt = 0;
317   WindowPtr win;
318   Boolean hit;
319   char key;
320   Point pnt;
321
322   switch (evt->what)
323     {
324     case mouseDown:
325       /* See if the click happened in a special part of the screen. */
326       part = FindWindow (evt->where, &win);
327       switch (part)
328         {
329         case inMenuBar:
330           adjust_menus ();
331           do_menu_command (MenuSelect (evt->where));
332           break;
333         case inSysWindow:
334           SystemClick (evt, win);
335           break;
336         case inContent:
337           if (win != FrontWindow ())
338             {
339               /* Bring the clicked-on window to the front. */
340               SelectWindow (win);
341               /* Fix the menu to match the new front window. */
342               adjust_menus ();
343               /* We always want to discard the event now, since clicks in a
344                  windows are often irreversible actions. */
345             }
346           else
347             /* Mouse clicks in the front window do something useful. */
348             do_mouse_down (win, evt);
349           break;
350         case inDrag:
351           /* Standard drag behavior, no tricks necessary. */
352           DragWindow (win, evt->where, &dragrect);
353           break;
354         case inGrow:
355           grow_window (win, evt->where);
356           break;
357         case inZoomIn:
358         case inZoomOut:
359           zoom_window (win, evt->where, part);
360           break;
361         case inGoAway:
362           close_window (win);
363           break;
364         }
365       break;
366     case keyDown:
367     case autoKey:
368       key = evt->message & charCodeMask;
369       /* Check for menukey equivalents. */
370       if (evt->modifiers & cmdKey)
371         {
372           if (evt->what == keyDown)
373             {
374               adjust_menus ();
375               do_menu_command (MenuKey (key));
376             }
377         }
378       else
379         {
380           if (evt->what == keyDown)
381             {
382               /* Random keypress, interpret it. */
383               do_keyboard_command (key);
384             }
385         }
386       break;
387     case activateEvt:
388       activate_window ((WindowPtr) evt->message, evt->modifiers & activeFlag);
389       break;
390     case updateEvt:
391       update_window ((WindowPtr) evt->message);
392       break;
393     case diskEvt:
394       /* Call DIBadMount in response to a diskEvt, so that the user can format
395          a floppy. (from DTS Sample) */
396       if (HiWord (evt->message) != noErr)
397         {
398           SetPt (&pnt, 50, 50);
399           err = DIBadMount (pnt, evt->message);
400         }
401       break;
402     case app4Evt:
403       /* Grab only a single byte. */
404       switch ((evt->message >> 24) & 0xFF)
405         {
406         case 0xfa:
407           break;
408         case 1:
409           inbackground = !(evt->message & 1);
410           activate_window (FrontWindow (), !inbackground);
411           break;
412         }
413       break;
414     case kHighLevelEvent:
415       AEProcessAppleEvent (evt);
416       break;
417     case nullEvent:
418       do_idle ();
419       rslt = 1;
420       break;
421     default:
422       break;
423     }
424   return rslt;
425 }
426
427 /* Do any idle-time activities. */
428
429 do_idle (void)
430 {
431   TEIdle (console_text);
432 }
433
434 grow_window (WindowPtr win, 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 (WindowPtr win, Point where, short part)
459 {
460   ZoomWindow (win, part, (win == FrontWindow ()));
461   if (win == console_window)
462     {
463       resize_console_window ();
464     }
465 }
466
467 resize_console_window (void)
468 {
469   adjust_console_sizes ();
470   adjust_console_scrollbars ();
471   adjust_console_text ();
472   InvalRect (&console_window->portRect);
473 }
474
475 close_window (WindowPtr win)
476 {
477 }
478
479 pascal void
480 v_scroll_proc (ControlHandle control, short part)
481 {
482   int oldval, amount = 0, newval;
483   int pagesize = ((*console_text)->viewRect.bottom - (*console_text)->viewRect.top) / (*console_text)->lineHeight;
484   if (part)
485     {
486       oldval = GetCtlValue (control);
487       switch (part)
488         {
489         case inUpButton:
490           amount = 1;
491           break;
492         case inDownButton:
493           amount = -1;
494           break;
495         case inPageUp:
496           amount = pagesize;
497           break;
498         case inPageDown:
499           amount = -pagesize;
500           break;
501         default:
502           /* (should freak out) */
503           break;
504         }
505       SetCtlValue (control, oldval - amount);
506       newval = GetCtlValue (control);
507       amount = oldval - newval;
508       if (amount)
509         TEScroll (0, amount * (*console_text)->lineHeight, console_text);
510     }
511 }
512
513 do_mouse_down (WindowPtr win, EventRecord * event)
514 {
515   short part, value;
516   Point mouse;
517   ControlHandle control;
518
519   if (1 /*is_app_window(win) */ )
520     {
521       SetPort (win);
522       mouse = event->where;
523       GlobalToLocal (&mouse);
524       part = FindControl (mouse, win, &control);
525       if (control == console_v_scrollbar)
526         {
527           switch (part)
528             {
529             case inThumb:
530               value = GetCtlValue (control);
531               part = TrackControl (control, mouse, nil);
532               if (part)
533                 {
534                   value -= GetCtlValue (control);
535                   if (value)
536                     TEScroll (0, value * (*console_text)->lineHeight,
537                               console_text);
538                 }
539               break;
540             default:
541 #if 0                           /* don't deal with right now */
542 #if 1                           /* universal headers */
543               value = TrackControl (control, mouse, (ControlActionUPP) v_scroll_proc);
544 #else
545               value = TrackControl (control, mouse, (ProcPtr) v_scroll_proc);
546 #endif
547 #endif
548               break;
549             }
550         }
551       else
552         {
553           TEClick (mouse, 0, console_text);
554         }
555     }
556 }
557
558 scroll_text (int hlines, int vlines)
559 {
560 }
561
562 activate_window (WindowPtr win, int activate)
563 {
564   Rect grow_rect;
565
566   if (win == nil)
567     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 (WindowPtr win)
594 {
595   int controls = 1, growbox = 0;
596   GrafPtr oldport;
597
598   /* Set the updating window to be the current grafport. */
599   GetPort (&oldport);
600   SetPort (win);
601 /*  recalc_depths();  */
602   BeginUpdate (win);
603   if (win == console_window)
604     {
605       draw_console ();
606       controls = 1;
607       growbox = 1;
608     }
609   if (controls)
610     UpdateControls (win, win->visRgn);
611   if (growbox)
612     DrawGrowIcon (win);
613   EndUpdate (win);
614   SetPort (oldport);
615 }
616
617 adjust_menus (void)
618 {
619 }
620
621 do_menu_command (long which)
622 {
623   short menuid, menuitem;
624   short itemHit;
625   Str255 daname;
626   short daRefNum;
627   Boolean handledbyda;
628   WindowPtr win;
629   short ditem;
630   int i;
631   char cmdbuf[300];
632
633   cmdbuf[0] = '\0';
634   menuid = HiWord (which);
635   menuitem = LoWord (which);
636   switch (menuid)
637     {
638     case mApple:
639       switch (menuitem)
640         {
641         case miAbout:
642           Alert (128, nil);
643           break;
644 #if 0
645         case miHelp:
646           /* (should pop up help info) */
647           break;
648 #endif
649         default:
650           GetItem (GetMHandle (mApple), menuitem, daname);
651           daRefNum = OpenDeskAcc (daname);
652         }
653       break;
654     case mFile:
655       switch (menuitem)
656         {
657         case miFileNew:
658           if (console_window == FrontWindow ())
659             {
660               close_window (console_window);
661             }
662           new_console_window ();
663           break;
664         case miFileOpen:
665           SysBeep (20);
666           break;
667         case miFileQuit:
668           ExitToShell ();
669           break;
670         }
671       break;
672     case mEdit:
673       /* handledbyda = SystemEdit(menuitem-1); */
674       switch (menuitem)
675         {
676         case miEditCut:
677           TECut (console_text);
678           break;
679         case miEditCopy:
680           TECopy (console_text);
681           break;
682         case miEditPaste:
683           TEPaste (console_text);
684           break;
685         case miEditClear:
686           TEDelete (console_text);
687           break;
688         }
689       /* All of these operations need the same postprocessing. */
690       adjust_console_sizes ();
691       adjust_console_scrollbars ();
692       adjust_console_text ();
693       break;
694     case mDebug:
695       switch (menuitem)
696         {
697         case miDebugTarget:
698           sprintf (cmdbuf, "target %s", "remote");
699           break;
700         case miDebugRun:
701           sprintf (cmdbuf, "run");
702           break;
703         case miDebugContinue:
704           sprintf (cmdbuf, "continue");
705           break;
706         case miDebugStep:
707           sprintf (cmdbuf, "step");
708           break;
709         case miDebugNext:
710           sprintf (cmdbuf, "next");
711           break;
712         }
713       break;
714     }
715   HiliteMenu (0);
716   /* Execute a command if one had been given.  Do here because a command
717      may longjmp before we get a chance to unhilite the menu. */
718   if (strlen (cmdbuf) > 0)
719     execute_command (cmdbuf, 0);
720 }
721
722 char commandbuf[1000];
723
724 do_keyboard_command (int key)
725 {
726   int startpos, endpos, i, len;
727   char *last_newline;
728   char buf[10], *text_str, *command, *cmd_start;
729   CharsHandle text;
730
731   if (key == '\015' || key == '\003')
732     {
733       text = TEGetText (console_text);
734       HLock ((Handle) text);
735       text_str = *text;
736       startpos = (*console_text)->selStart;
737       endpos = (*console_text)->selEnd;
738       if (startpos != endpos)
739         {
740           len = endpos - startpos;
741           cmd_start = text_str + startpos;
742         }
743       else
744         {
745           for (i = startpos - 1; i >= 0; --i)
746             if (text_str[i] == '\015')
747               break;
748           last_newline = text_str + i;
749           len = (text_str + startpos) - 1 - last_newline;
750           cmd_start = last_newline + 1;
751         }
752       if (len > 1000)
753         len = 999;
754       if (len < 0)
755         len = 0;
756       strncpy (commandbuf + 1, cmd_start, len);
757       commandbuf[1 + len] = 0;
758       command = commandbuf + 1;
759       HUnlock ((Handle) text);
760       commandbuf[0] = strlen (command);
761
762       /* Insert a newline and recalculate before doing any command. */
763       key = '\015';
764       TEKey (key, console_text);
765       TEInsert (buf, 1, console_text);
766       adjust_console_sizes ();
767       adjust_console_scrollbars ();
768       adjust_console_text ();
769
770       if (strlen (command) > 0)
771         {
772           execute_command (command, 0);
773           bpstat_do_actions (&stop_bpstat);
774         }
775     }
776   else
777     {
778       /* A self-inserting character.  This includes delete.  */
779       TEKey (key, console_text);
780     }
781 }
782
783 /* Draw all graphical stuff in the console window.  */
784
785 draw_console (void)
786 {
787   SetPort (console_window);
788   TEUpdate (&(console_window->portRect), console_text);
789 }
790
791 /* Cause an update of a given window's entire contents.  */
792
793 force_update (WindowPtr win)
794 {
795   GrafPtr oldport;
796
797   if (win == nil)
798     return;
799   GetPort (&oldport);
800   SetPort (win);
801   EraseRect (&win->portRect);
802   InvalRect (&win->portRect);
803   SetPort (oldport);
804 }
805
806 adjust_console_sizes (void)
807 {
808   Rect tmprect;
809
810   tmprect = console_window->portRect;
811   /* Move and size the scrollbar. */
812   MoveControl (console_v_scrollbar, tmprect.right - sbarwid, 0);
813   SizeControl (console_v_scrollbar, sbarwid + 1, tmprect.bottom - sbarwid + 1);
814   /* Move and size the text. */
815   tmprect.left += 7;
816   tmprect.right -= sbarwid;
817   tmprect.bottom -= sbarwid;
818   InsetRect (&tmprect, 1, 1);
819   (*console_text)->destRect = tmprect;
820   /* Fiddle bottom of viewrect to be even multiple of text lines. */
821   tmprect.bottom = tmprect.top
822     + ((tmprect.bottom - tmprect.top) / (*console_text)->lineHeight)
823     * (*console_text)->lineHeight;
824   (*console_text)->viewRect = tmprect;
825 }
826
827 adjust_console_scrollbars (void)
828 {
829   int lines, newmax, value;
830
831   (*console_v_scrollbar)->contrlVis = 0;
832   lines = (*console_text)->nLines;
833   newmax = lines - (((*console_text)->viewRect.bottom
834                      - (*console_text)->viewRect.top)
835                     / (*console_text)->lineHeight);
836   if (newmax < 0)
837     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 (void)
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 (void)
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 xstrdup (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 }