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