]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/mac-xdep.c
import gdb-1999-07-07 post reformat
[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., 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 ()
124 {
125 return 1;
126 }
127
128 mac_init ()
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 ()
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 ()
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 (mouse)
298 Point *mouse;
299 {
300 EventRecord evt;
301
302 OSEventAvail (0, &evt);
303 *mouse = evt.where;
304 }
305
306 /* Change the cursor's appearance to be appropriate for the given mouse
307 location. */
308
309 adjust_cursor (mouse, region)
310 Point mouse;
311 RgnHandle region;
312 {
313 }
314
315 /* Decipher an event, maybe do something with it. */
316
317 do_event (evt)
318 EventRecord *evt;
319 {
320 short part, err, rslt = 0;
321 WindowPtr win;
322 Boolean hit;
323 char key;
324 Point pnt;
325
326 switch (evt->what)
327 {
328 case mouseDown:
329 /* See if the click happened in a special part of the screen. */
330 part = FindWindow (evt->where, &win);
331 switch (part)
332 {
333 case inMenuBar:
334 adjust_menus ();
335 do_menu_command (MenuSelect (evt->where));
336 break;
337 case inSysWindow:
338 SystemClick (evt, win);
339 break;
340 case inContent:
341 if (win != FrontWindow ())
342 {
343 /* Bring the clicked-on window to the front. */
344 SelectWindow (win);
345 /* Fix the menu to match the new front window. */
346 adjust_menus ();
347 /* We always want to discard the event now, since clicks in a
348 windows are often irreversible actions. */
349 }
350 else
351 /* Mouse clicks in the front window do something useful. */
352 do_mouse_down (win, evt);
353 break;
354 case inDrag:
355 /* Standard drag behavior, no tricks necessary. */
356 DragWindow (win, evt->where, &dragrect);
357 break;
358 case inGrow:
359 grow_window (win, evt->where);
360 break;
361 case inZoomIn:
362 case inZoomOut:
363 zoom_window (win, evt->where, part);
364 break;
365 case inGoAway:
366 close_window (win);
367 break;
368 }
369 break;
370 case keyDown:
371 case autoKey:
372 key = evt->message & charCodeMask;
373 /* Check for menukey equivalents. */
374 if (evt->modifiers & cmdKey)
375 {
376 if (evt->what == keyDown)
377 {
378 adjust_menus ();
379 do_menu_command (MenuKey (key));
380 }
381 }
382 else
383 {
384 if (evt->what == keyDown)
385 {
386 /* Random keypress, interpret it. */
387 do_keyboard_command (key);
388 }
389 }
390 break;
391 case activateEvt:
392 activate_window ((WindowPtr) evt->message, evt->modifiers & activeFlag);
393 break;
394 case updateEvt:
395 update_window ((WindowPtr) evt->message);
396 break;
397 case diskEvt:
398 /* Call DIBadMount in response to a diskEvt, so that the user can format
399 a floppy. (from DTS Sample) */
400 if (HiWord (evt->message) != noErr)
401 {
402 SetPt (&pnt, 50, 50);
403 err = DIBadMount (pnt, evt->message);
404 }
405 break;
406 case app4Evt:
407 /* Grab only a single byte. */
408 switch ((evt->message >> 24) & 0xFF)
409 {
410 case 0xfa:
411 break;
412 case 1:
413 inbackground = !(evt->message & 1);
414 activate_window (FrontWindow (), !inbackground);
415 break;
416 }
417 break;
418 case kHighLevelEvent:
419 AEProcessAppleEvent (evt);
420 break;
421 case nullEvent:
422 do_idle ();
423 rslt = 1;
424 break;
425 default:
426 break;
427 }
428 return rslt;
429 }
430
431 /* Do any idle-time activities. */
432
433 do_idle ()
434 {
435 TEIdle (console_text);
436 }
437
438 grow_window (win, where)
439 WindowPtr win;
440 Point where;
441 {
442 long winsize;
443 int h, v;
444 GrafPtr oldport;
445
446 winsize = GrowWindow (win, where, &sizerect);
447 /* Only do anything if it actually changed size. */
448 if (winsize != 0)
449 {
450 GetPort (&oldport);
451 SetPort (win);
452 if (win == console_window)
453 {
454 EraseRect (&win->portRect);
455 h = LoWord (winsize);
456 v = HiWord (winsize);
457 SizeWindow (win, h, v, 1);
458 resize_console_window ();
459 }
460 SetPort (oldport);
461 }
462 }
463
464 zoom_window (win, where, part)
465 WindowPtr win;
466 Point where;
467 short part;
468 {
469 ZoomWindow (win, part, (win == FrontWindow ()));
470 if (win == console_window)
471 {
472 resize_console_window ();
473 }
474 }
475
476 resize_console_window ()
477 {
478 adjust_console_sizes ();
479 adjust_console_scrollbars ();
480 adjust_console_text ();
481 InvalRect (&console_window->portRect);
482 }
483
484 close_window (win)
485 WindowPtr win;
486 {
487 }
488
489 pascal void
490 v_scroll_proc (ControlHandle control, short part)
491 {
492 int oldval, amount = 0, newval;
493 int pagesize = ((*console_text)->viewRect.bottom - (*console_text)->viewRect.top) / (*console_text)->lineHeight;
494 if (part)
495 {
496 oldval = GetCtlValue (control);
497 switch (part)
498 {
499 case inUpButton:
500 amount = 1;
501 break;
502 case inDownButton:
503 amount = -1;
504 break;
505 case inPageUp:
506 amount = pagesize;
507 break;
508 case inPageDown:
509 amount = -pagesize;
510 break;
511 default:
512 /* (should freak out) */
513 break;
514 }
515 SetCtlValue (control, oldval - amount);
516 newval = GetCtlValue (control);
517 amount = oldval - newval;
518 if (amount)
519 TEScroll (0, amount * (*console_text)->lineHeight, console_text);
520 }
521 }
522
523 do_mouse_down (WindowPtr win, EventRecord * event)
524 {
525 short part, value;
526 Point mouse;
527 ControlHandle control;
528
529 if (1 /*is_app_window(win) */ )
530 {
531 SetPort (win);
532 mouse = event->where;
533 GlobalToLocal (&mouse);
534 part = FindControl (mouse, win, &control);
535 if (control == console_v_scrollbar)
536 {
537 switch (part)
538 {
539 case inThumb:
540 value = GetCtlValue (control);
541 part = TrackControl (control, mouse, nil);
542 if (part)
543 {
544 value -= GetCtlValue (control);
545 if (value)
546 TEScroll (0, value * (*console_text)->lineHeight,
547 console_text);
548 }
549 break;
550 default:
551 #if 0 /* don't deal with right now */
552 #if 1 /* universal headers */
553 value = TrackControl (control, mouse, (ControlActionUPP) v_scroll_proc);
554 #else
555 value = TrackControl (control, mouse, (ProcPtr) v_scroll_proc);
556 #endif
557 #endif
558 break;
559 }
560 }
561 else
562 {
563 TEClick (mouse, 0, console_text);
564 }
565 }
566 }
567
568 scroll_text (hlines, vlines)
569 int hlines, vlines;
570 {
571 }
572
573 activate_window (win, activate)
574 WindowPtr win;
575 int activate;
576 {
577 Rect grow_rect;
578
579 if (win == nil)
580 return;
581 /* It's convenient to make the activated window also be the
582 current GrafPort. */
583 if (activate)
584 SetPort (win);
585 /* Activate the console window's scrollbar. */
586 if (win == console_window)
587 {
588 if (activate)
589 {
590 TEActivate (console_text);
591 /* Cause the grow icon to be redrawn at the next update. */
592 grow_rect = console_window->portRect;
593 grow_rect.top = grow_rect.bottom - sbarwid;
594 grow_rect.left = grow_rect.right - sbarwid;
595 InvalRect (&grow_rect);
596 }
597 else
598 {
599 TEDeactivate (console_text);
600 DrawGrowIcon (console_window);
601 }
602 HiliteControl (console_v_scrollbar, (activate ? 0 : 255));
603 }
604 }
605
606 update_window (win)
607 WindowPtr win;
608 {
609 int controls = 1, growbox = 0;
610 GrafPtr oldport;
611
612 /* Set the updating window to be the current grafport. */
613 GetPort (&oldport);
614 SetPort (win);
615 /* recalc_depths(); */
616 BeginUpdate (win);
617 if (win == console_window)
618 {
619 draw_console ();
620 controls = 1;
621 growbox = 1;
622 }
623 if (controls)
624 UpdateControls (win, win->visRgn);
625 if (growbox)
626 DrawGrowIcon (win);
627 EndUpdate (win);
628 SetPort (oldport);
629 }
630
631 adjust_menus ()
632 {
633 }
634
635 do_menu_command (which)
636 long which;
637 {
638 short menuid, menuitem;
639 short itemHit;
640 Str255 daname;
641 short daRefNum;
642 Boolean handledbyda;
643 WindowPtr win;
644 short ditem;
645 int i;
646 char cmdbuf[300];
647
648 cmdbuf[0] = '\0';
649 menuid = HiWord (which);
650 menuitem = LoWord (which);
651 switch (menuid)
652 {
653 case mApple:
654 switch (menuitem)
655 {
656 case miAbout:
657 Alert (128, nil);
658 break;
659 #if 0
660 case miHelp:
661 /* (should pop up help info) */
662 break;
663 #endif
664 default:
665 GetItem (GetMHandle (mApple), menuitem, daname);
666 daRefNum = OpenDeskAcc (daname);
667 }
668 break;
669 case mFile:
670 switch (menuitem)
671 {
672 case miFileNew:
673 if (console_window == FrontWindow ())
674 {
675 close_window (console_window);
676 }
677 new_console_window ();
678 break;
679 case miFileOpen:
680 SysBeep (20);
681 break;
682 case miFileQuit:
683 ExitToShell ();
684 break;
685 }
686 break;
687 case mEdit:
688 /* handledbyda = SystemEdit(menuitem-1); */
689 switch (menuitem)
690 {
691 case miEditCut:
692 TECut (console_text);
693 break;
694 case miEditCopy:
695 TECopy (console_text);
696 break;
697 case miEditPaste:
698 TEPaste (console_text);
699 break;
700 case miEditClear:
701 TEDelete (console_text);
702 break;
703 }
704 /* All of these operations need the same postprocessing. */
705 adjust_console_sizes ();
706 adjust_console_scrollbars ();
707 adjust_console_text ();
708 break;
709 case mDebug:
710 switch (menuitem)
711 {
712 case miDebugTarget:
713 sprintf (cmdbuf, "target %s", "remote");
714 break;
715 case miDebugRun:
716 sprintf (cmdbuf, "run");
717 break;
718 case miDebugContinue:
719 sprintf (cmdbuf, "continue");
720 break;
721 case miDebugStep:
722 sprintf (cmdbuf, "step");
723 break;
724 case miDebugNext:
725 sprintf (cmdbuf, "next");
726 break;
727 }
728 break;
729 }
730 HiliteMenu (0);
731 /* Execute a command if one had been given. Do here because a command
732 may longjmp before we get a chance to unhilite the menu. */
733 if (strlen (cmdbuf) > 0)
734 execute_command (cmdbuf, 0);
735 }
736
737 char commandbuf[1000];
738
739 do_keyboard_command (key)
740 int key;
741 {
742 int startpos, endpos, i, len;
743 char *last_newline;
744 char buf[10], *text_str, *command, *cmd_start;
745 CharsHandle text;
746
747 if (key == '\015' || key == '\003')
748 {
749 text = TEGetText (console_text);
750 HLock ((Handle) text);
751 text_str = *text;
752 startpos = (*console_text)->selStart;
753 endpos = (*console_text)->selEnd;
754 if (startpos != endpos)
755 {
756 len = endpos - startpos;
757 cmd_start = text_str + startpos;
758 }
759 else
760 {
761 for (i = startpos - 1; i >= 0; --i)
762 if (text_str[i] == '\015')
763 break;
764 last_newline = text_str + i;
765 len = (text_str + startpos) - 1 - last_newline;
766 cmd_start = last_newline + 1;
767 }
768 if (len > 1000)
769 len = 999;
770 if (len < 0)
771 len = 0;
772 strncpy (commandbuf + 1, cmd_start, len);
773 commandbuf[1 + len] = 0;
774 command = commandbuf + 1;
775 HUnlock ((Handle) text);
776 commandbuf[0] = strlen (command);
777
778 /* Insert a newline and recalculate before doing any command. */
779 key = '\015';
780 TEKey (key, console_text);
781 TEInsert (buf, 1, console_text);
782 adjust_console_sizes ();
783 adjust_console_scrollbars ();
784 adjust_console_text ();
785
786 if (strlen (command) > 0)
787 {
788 execute_command (command, 0);
789 bpstat_do_actions (&stop_bpstat);
790 }
791 }
792 else
793 {
794 /* A self-inserting character. This includes delete. */
795 TEKey (key, console_text);
796 }
797 }
798
799 /* Draw all graphical stuff in the console window. */
800
801 draw_console ()
802 {
803 SetPort (console_window);
804 TEUpdate (&(console_window->portRect), console_text);
805 }
806
807 /* Cause an update of a given window's entire contents. */
808
809 force_update (win)
810 WindowPtr win;
811 {
812 GrafPtr oldport;
813
814 if (win == nil)
815 return;
816 GetPort (&oldport);
817 SetPort (win);
818 EraseRect (&win->portRect);
819 InvalRect (&win->portRect);
820 SetPort (oldport);
821 }
822
823 adjust_console_sizes ()
824 {
825 Rect tmprect;
826
827 tmprect = console_window->portRect;
828 /* Move and size the scrollbar. */
829 MoveControl (console_v_scrollbar, tmprect.right - sbarwid, 0);
830 SizeControl (console_v_scrollbar, sbarwid + 1, tmprect.bottom - sbarwid + 1);
831 /* Move and size the text. */
832 tmprect.left += 7;
833 tmprect.right -= sbarwid;
834 tmprect.bottom -= sbarwid;
835 InsetRect (&tmprect, 1, 1);
836 (*console_text)->destRect = tmprect;
837 /* Fiddle bottom of viewrect to be even multiple of text lines. */
838 tmprect.bottom = tmprect.top
839 + ((tmprect.bottom - tmprect.top) / (*console_text)->lineHeight)
840 * (*console_text)->lineHeight;
841 (*console_text)->viewRect = tmprect;
842 }
843
844 adjust_console_scrollbars ()
845 {
846 int lines, newmax, value;
847
848 (*console_v_scrollbar)->contrlVis = 0;
849 lines = (*console_text)->nLines;
850 newmax = lines - (((*console_text)->viewRect.bottom
851 - (*console_text)->viewRect.top)
852 / (*console_text)->lineHeight);
853 if (newmax < 0)
854 newmax = 0;
855 SetCtlMax (console_v_scrollbar, newmax);
856 value = ((*console_text)->viewRect.top - (*console_text)->destRect.top)
857 / (*console_text)->lineHeight;
858 SetCtlValue (console_v_scrollbar, value);
859 (*console_v_scrollbar)->contrlVis = 0xff;
860 ShowControl (console_v_scrollbar);
861 }
862
863 /* Scroll the TE record so that it is consistent with the scrollbar(s). */
864
865 adjust_console_text ()
866 {
867 TEScroll (((*console_text)->viewRect.left
868 - (*console_text)->destRect.left)
869 - 0 /* get h scroll value */ ,
870 ((((*console_text)->viewRect.top - (*console_text)->destRect.top)
871 / (*console_text)->lineHeight)
872 - GetCtlValue (console_v_scrollbar))
873 * (*console_text)->lineHeight,
874 console_text);
875 }
876
877 /* Readline substitute. */
878
879 char *
880 readline (char *prrompt)
881 {
882 return gdb_readline (prrompt);
883 }
884
885 char *rl_completer_word_break_characters;
886
887 char *rl_completer_quote_characters;
888
889 int (*rl_completion_entry_function) ();
890
891 int rl_point;
892
893 char *rl_line_buffer;
894
895 char *rl_readline_name;
896
897 /* History substitute. */
898
899 void
900 add_history (char *buf)
901 {
902 }
903
904 void
905 stifle_history (int n)
906 {
907 }
908
909 int
910 unstifle_history ()
911 {
912 }
913
914 int
915 read_history (char *name)
916 {
917 }
918
919 int
920 write_history (char *name)
921 {
922 }
923
924 int
925 history_expand (char *x, char **y)
926 {
927 }
928
929 extern HIST_ENTRY *
930 history_get (int xxx)
931 {
932 return NULL;
933 }
934
935 int history_base;
936
937 char *
938 filename_completion_function (char *text, char *name)
939 {
940 return "?";
941 }
942
943 char *
944 tilde_expand (char *str)
945 {
946 return strsave (str);
947 }
948
949 /* Modified versions of standard I/O. */
950
951 #undef fprintf
952
953 int
954 hacked_fprintf (FILE * fp, const char *fmt,...)
955 {
956 int ret;
957 va_list ap;
958
959 va_start (ap, fmt);
960 if (mac_app && (fp == stdout || fp == stderr))
961 {
962 char buf[1000];
963
964 ret = vsprintf (buf, fmt, ap);
965 TEInsert (buf, strlen (buf), console_text);
966 }
967 else
968 ret = vfprintf (fp, fmt, ap);
969 va_end (ap);
970 return ret;
971 }
972
973 #undef printf
974
975 int
976 hacked_printf (const char *fmt,...)
977 {
978 int ret;
979 va_list ap;
980
981 va_start (ap, fmt);
982 ret = hacked_vfprintf (stdout, fmt, ap);
983 va_end (ap);
984 return ret;
985 }
986
987 #undef vfprintf
988
989 int
990 hacked_vfprintf (FILE * fp, const char *format, va_list args)
991 {
992 if (mac_app && (fp == stdout || fp == stderr))
993 {
994 char buf[1000];
995 int ret;
996
997 ret = vsprintf (buf, format, args);
998 TEInsert (buf, strlen (buf), console_text);
999 if (strchr (buf, '\n'))
1000 {
1001 adjust_console_sizes ();
1002 adjust_console_scrollbars ();
1003 adjust_console_text ();
1004 }
1005 return ret;
1006 }
1007 else
1008 return vfprintf (fp, format, args);
1009 }
1010
1011 #undef fputs
1012
1013 hacked_fputs (const char *s, FILE * fp)
1014 {
1015 if (mac_app && (fp == stdout || fp == stderr))
1016 {
1017 TEInsert (s, strlen (s), console_text);
1018 if (strchr (s, '\n'))
1019 {
1020 adjust_console_sizes ();
1021 adjust_console_scrollbars ();
1022 adjust_console_text ();
1023 }
1024 return 0;
1025 }
1026 else
1027 return fputs (s, fp);
1028 }
1029
1030 #undef fputc
1031
1032 hacked_fputc (const char c, FILE * fp)
1033 {
1034 if (mac_app && (fp == stdout || fp == stderr))
1035 {
1036 char buf[1];
1037
1038 buf[0] = c;
1039 TEInsert (buf, 1, console_text);
1040 if (c == '\n')
1041 {
1042 adjust_console_sizes ();
1043 adjust_console_scrollbars ();
1044 adjust_console_text ();
1045 }
1046 return c;
1047 }
1048 else
1049 return fputc (c, fp);
1050 }
1051
1052 #undef putc
1053
1054 hacked_putc (const char c, FILE * fp)
1055 {
1056 if (mac_app && (fp == stdout || fp == stderr))
1057 {
1058 char buf[1];
1059
1060 buf[0] = c;
1061 TEInsert (buf, 1, console_text);
1062 if (c == '\n')
1063 {
1064 adjust_console_sizes ();
1065 adjust_console_scrollbars ();
1066 adjust_console_text ();
1067 }
1068 return c;
1069 }
1070 else
1071 return fputc (c, fp);
1072 }
1073
1074 #undef fflush
1075
1076 hacked_fflush (FILE * fp)
1077 {
1078 if (mac_app && (fp == stdout || fp == stderr))
1079 {
1080 adjust_console_sizes ();
1081 adjust_console_scrollbars ();
1082 adjust_console_text ();
1083 return 0;
1084 }
1085 return fflush (fp);
1086 }
1087
1088 #undef fgetc
1089
1090 hacked_fgetc (FILE * fp)
1091 {
1092 if (mac_app && (fp == stdin))
1093 {
1094 /* Catch any attempts to use this. */
1095 DebugStr ("\pShould not be reading from stdin!");
1096 return '\n';
1097 }
1098 return fgetc (fp);
1099 }