* Sanitization fixes to retain new files.
[binutils-gdb.git] / gdb / mac-xdep.c
blob20a79a53c88a5e9f40c91d90310581214e9b4a8f
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.
5 This file is part of GDB.
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.
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.
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, Boston, MA 02111-1307, USA. */
21 #include "defs.h"
23 #include "readline.h"
24 #include "history.h"
26 #include <Types.h>
27 #include <Resources.h>
28 #include <QuickDraw.h>
29 #include <Fonts.h>
30 #include <Events.h>
31 #include <Windows.h>
32 #include <Menus.h>
33 #include <TextEdit.h>
34 #include <Dialogs.h>
35 #include <Desk.h>
36 #include <ToolUtils.h>
37 #include <Memory.h>
38 #include <SegLoad.h>
39 #include <Files.h>
40 #include <Folders.h>
41 #include <OSUtils.h>
42 #include <OSEvents.h>
43 #include <DiskInit.h>
44 #include <Packages.h>
45 #include <Traps.h>
46 #include <Lists.h>
47 #include <Gestalt.h>
48 #include <PPCToolbox.h>
49 #include <AppleEvents.h>
50 #include <StandardFile.h>
51 #include <Sound.h>
53 #ifdef MPW
54 #define QD(whatever) (qd.##whatever)
55 #define QDPat(whatever) (&(qd.##whatever))
56 #endif /* MPW */
58 #ifdef THINK_C
59 #define QD(whatever) (whatever)
60 #endif
62 #define p2c(pstr,cbuf) \
63 strncpy(cbuf, ((char *) (pstr) + 1), pstr[0]); \
64 cbuf[pstr[0]] = '\0';
66 #define pascalify(STR) \
67 sprintf(tmpbuf, " %s", STR); \
68 tmpbuf[0] = strlen(STR);
70 #include "gdbcmd.h"
71 #include "call-cmds.h"
72 #include "symtab.h"
73 #include "inferior.h"
74 #include "signals.h"
75 #include "target.h"
76 #include "breakpoint.h"
77 #include "gdbtypes.h"
78 #include "expression.h"
79 #include "language.h"
81 #include "mac-defs.h"
83 int debug_openp = 0;
85 /* This is true if we are running as a standalone application. */
87 int mac_app;
89 /* This is true if we are using WaitNextEvent. */
91 int use_wne;
93 /* This is true if we have Color Quickdraw. */
95 int has_color_qd;
97 /* This is true if we are using Color Quickdraw. */
99 int use_color_qd;
101 int inbackground;
103 Rect dragrect = { -32000, -32000, 32000, 32000 };
104 Rect sizerect;
106 int sbarwid = 15;
108 /* Globals for the console window. */
110 WindowPtr console_window;
112 ControlHandle console_v_scrollbar;
114 Rect console_v_scroll_rect;
116 TEHandle console_text;
118 Rect console_text_rect;
120 /* This will go away eventually. */
121 gdb_has_a_terminal () { return 1; }
123 mac_init ()
125 SysEnvRec se;
126 int eventloopdone = 0;
127 char *str;
128 Boolean gotevent;
129 Point mouse;
130 EventRecord event;
131 WindowPtr win;
132 RgnHandle cursorRgn;
133 int i;
134 Handle menubar;
135 MenuHandle menu;
136 Handle siow_resource;
138 mac_app = 0;
140 str = getenv("DEBUG_GDB");
141 if (str != NULL && str[0] != '\0')
143 if (strcmp(str, "openp") == 0)
144 debug_openp = 1;
147 /* Don't do anything if we`re running under MPW. */
148 if (!StandAlone)
149 return;
151 /* Don't do anything if we're using SIOW. */
152 /* This test requires that the siow 0 resource, as defined in
153 {RIncludes}siow.r, not be messed with. If it is, then the
154 standard Mac setup below will step on SIOW's Mac setup and
155 most likely crash the machine. */
156 siow_resource = GetResource('siow', 0);
157 if (siow_resource != nil)
158 return;
160 mac_app = 1;
162 /* Do the standard Mac environment setup. */
163 InitGraf (&QD (thePort));
164 InitFonts ();
165 FlushEvents (everyEvent, 0);
166 InitWindows ();
167 InitMenus ();
168 TEInit ();
169 InitDialogs (NULL);
170 InitCursor ();
172 /* Color Quickdraw is different from Classic QD. */
173 SysEnvirons(2, &se);
174 has_color_qd = se.hasColorQD;
175 /* Use it if we got it. */
176 use_color_qd = has_color_qd;
178 sizerect.top = 50;
179 sizerect.left = 50;
180 sizerect.bottom = 1000;
181 sizerect.right = 1000;
182 #if 0
183 sizerect.bottom = screenBits.bounds.bottom - screenBits.bounds.top;
184 sizerect.right = screenBits.bounds.right - screenBits.bounds.left;
185 #endif
187 /* Set up the menus. */
188 menubar = GetNewMBar (mbMain);
189 SetMenuBar (menubar);
190 /* Add the DAs etc as usual. */
191 menu = GetMHandle (mApple);
192 if (menu != nil) {
193 AddResMenu (menu, 'DRVR');
195 DrawMenuBar ();
197 new_console_window ();
200 new_console_window ()
202 /* Create the main window we're going to play in. */
203 if (has_color_qd)
204 console_window = GetNewCWindow (wConsole, NULL, (WindowPtr) -1L);
205 else
206 console_window = GetNewWindow (wConsole, NULL, (WindowPtr) -1L);
208 SetPort (console_window);
209 console_text_rect = console_window->portRect;
210 /* Leave 8 pixels of blank space, for aesthetic reasons and to
211 make it easier to select from the beginning of a line. */
212 console_text_rect.left += 8;
213 console_text_rect.bottom -= sbarwid - 1;
214 console_text_rect.right -= sbarwid - 1;
215 console_text = TENew (&console_text_rect, &console_text_rect);
216 TESetSelect (0, 40000, console_text);
217 TEDelete (console_text);
218 TEAutoView (1, console_text);
220 console_v_scroll_rect = console_window->portRect;
221 console_v_scroll_rect.bottom -= sbarwid - 1;
222 console_v_scroll_rect.left = console_v_scroll_rect.right - sbarwid;
223 console_v_scrollbar =
224 NewControl (console_window, &console_v_scroll_rect,
225 "\p", 1, 0, 0, 0, scrollBarProc, 0L);
227 ShowWindow (console_window);
228 SelectWindow (console_window);
231 mac_command_loop()
233 SysEnvRec se;
234 int eventloopdone = 0;
235 Boolean gotevent;
236 Point mouse;
237 EventRecord event;
238 WindowPtr win;
239 RgnHandle cursorRgn;
240 int i, tm;
241 Handle menubar;
242 MenuHandle menu;
244 /* Figure out if the WaitNextEvent Trap is available. */
245 use_wne =
246 (NGetTrapAddress (0x60, ToolTrap) != NGetTrapAddress (0x9f, ToolTrap));
247 /* Pass WaitNextEvent an empty region the first time through. */
248 cursorRgn = NewRgn ();
249 /* Go into the main event-handling loop. */
250 while (!eventloopdone)
252 /* Use WaitNextEvent if it is available, otherwise GetNextEvent. */
253 if (use_wne)
255 get_global_mouse (&mouse);
256 adjust_cursor (mouse, cursorRgn);
257 tm = GetCaretTime();
258 gotevent = WaitNextEvent (everyEvent, &event, tm, cursorRgn);
260 else
262 SystemTask ();
263 gotevent = GetNextEvent (everyEvent, &event);
265 /* First decide if the event is for a dialog or is just any old event. */
266 if (FrontWindow () != nil && IsDialogEvent (&event))
268 short itemhit;
269 DialogPtr dialog;
271 /* Handle all the modeless dialogs here. */
272 if (DialogSelect (&event, &dialog, &itemhit))
276 else if (gotevent)
278 /* Make sure we have the right cursor before handling the event. */
279 adjust_cursor (event.where, cursorRgn);
280 do_event (&event);
282 else
284 do_idle ();
289 /* Collect the global coordinates of the mouse pointer. */
291 get_global_mouse (mouse)
292 Point *mouse;
294 EventRecord evt;
296 OSEventAvail (0, &evt);
297 *mouse = evt.where;
300 /* Change the cursor's appearance to be appropriate for the given mouse
301 location. */
303 adjust_cursor (mouse, region)
304 Point mouse;
305 RgnHandle region;
309 /* Decipher an event, maybe do something with it. */
311 do_event (evt)
312 EventRecord *evt;
314 short part, err, rslt = 0;
315 WindowPtr win;
316 Boolean hit;
317 char key;
318 Point pnt;
320 switch (evt->what)
322 case mouseDown:
323 /* See if the click happened in a special part of the screen. */
324 part = FindWindow (evt->where, &win);
325 switch (part)
327 case inMenuBar:
328 adjust_menus ();
329 do_menu_command (MenuSelect (evt->where));
330 break;
331 case inSysWindow:
332 SystemClick (evt, win);
333 break;
334 case inContent:
335 if (win != FrontWindow ())
337 /* Bring the clicked-on window to the front. */
338 SelectWindow (win);
339 /* Fix the menu to match the new front window. */
340 adjust_menus ();
341 /* We always want to discard the event now, since clicks in a
342 windows are often irreversible actions. */
343 } else
344 /* Mouse clicks in the front window do something useful. */
345 do_mouse_down (win, evt);
346 break;
347 case inDrag:
348 /* Standard drag behavior, no tricks necessary. */
349 DragWindow (win, evt->where, &dragrect);
350 break;
351 case inGrow:
352 grow_window (win, evt->where);
353 break;
354 case inZoomIn:
355 case inZoomOut:
356 zoom_window (win, evt->where, part);
357 break;
358 case inGoAway:
359 close_window (win);
360 break;
362 break;
363 case keyDown:
364 case autoKey:
365 key = evt->message & charCodeMask;
366 /* Check for menukey equivalents. */
367 if (evt->modifiers & cmdKey)
369 if (evt->what == keyDown)
371 adjust_menus ();
372 do_menu_command (MenuKey (key));
375 else
377 if (evt->what == keyDown)
379 /* Random keypress, interpret it. */
380 do_keyboard_command (key);
383 break;
384 case activateEvt:
385 activate_window ((WindowPtr) evt->message, evt->modifiers & activeFlag);
386 break;
387 case updateEvt:
388 update_window ((WindowPtr) evt->message);
389 break;
390 case diskEvt:
391 /* Call DIBadMount in response to a diskEvt, so that the user can format
392 a floppy. (from DTS Sample) */
393 if (HiWord (evt->message) != noErr)
395 SetPt (&pnt, 50, 50);
396 err = DIBadMount (pnt, evt->message);
398 break;
399 case app4Evt:
400 /* Grab only a single byte. */
401 switch ((evt->message >> 24) & 0xFF)
403 case 0xfa:
404 break;
405 case 1:
406 inbackground = !(evt->message & 1);
407 activate_window (FrontWindow (), !inbackground);
408 break;
410 break;
411 case kHighLevelEvent:
412 AEProcessAppleEvent (evt);
413 break;
414 case nullEvent:
415 do_idle ();
416 rslt = 1;
417 break;
418 default:
419 break;
421 return rslt;
424 /* Do any idle-time activities. */
426 do_idle ()
428 TEIdle (console_text);
431 grow_window (win, where)
432 WindowPtr win;
433 Point where;
435 long winsize;
436 int h, v;
437 GrafPtr oldport;
439 winsize = GrowWindow (win, where, &sizerect);
440 /* Only do anything if it actually changed size. */
441 if (winsize != 0)
443 GetPort (&oldport);
444 SetPort (win);
445 if (win == console_window)
447 EraseRect (&win->portRect);
448 h = LoWord (winsize);
449 v = HiWord (winsize);
450 SizeWindow (win, h, v, 1);
451 resize_console_window ();
453 SetPort (oldport);
457 zoom_window (win, where, part)
458 WindowPtr win;
459 Point where;
460 short part;
462 ZoomWindow (win, part, (win == FrontWindow ()));
463 if (win == console_window)
465 resize_console_window ();
469 resize_console_window ()
471 adjust_console_sizes ();
472 adjust_console_scrollbars ();
473 adjust_console_text ();
474 InvalRect (&console_window->portRect);
477 close_window (win)
478 WindowPtr win;
482 pascal void
483 v_scroll_proc (ControlHandle control, short part)
485 int oldval, amount = 0, newval;
486 int pagesize = ((*console_text)->viewRect.bottom - (*console_text)->viewRect.top) / (*console_text)->lineHeight;
487 if (part)
489 oldval = GetCtlValue (control);
490 switch (part)
492 case inUpButton:
493 amount = 1;
494 break;
495 case inDownButton:
496 amount = -1;
497 break;
498 case inPageUp:
499 amount = pagesize;
500 break;
501 case inPageDown:
502 amount = - pagesize;
503 break;
504 default:
505 /* (should freak out) */
506 break;
508 SetCtlValue(control, oldval - amount);
509 newval = GetCtlValue (control);
510 amount = oldval - newval;
511 if (amount)
512 TEScroll (0, amount * (*console_text)->lineHeight, console_text);
516 do_mouse_down (WindowPtr win, EventRecord *event)
518 short part, value;
519 Point mouse;
520 ControlHandle control;
522 if (1 /*is_app_window(win)*/)
524 SetPort (win);
525 mouse = event->where;
526 GlobalToLocal (&mouse);
527 part = FindControl(mouse, win, &control);
528 if (control == console_v_scrollbar)
530 switch (part)
532 case inThumb:
533 value = GetCtlValue (control);
534 part = TrackControl (control, mouse, nil);
535 if (part)
537 value -= GetCtlValue (control);
538 if (value)
539 TEScroll(0, value * (*console_text)->lineHeight,
540 console_text);
542 break;
543 default:
544 #if 0 /* don't deal with right now */
545 #if 1 /* universal headers */
546 value = TrackControl (control, mouse, (ControlActionUPP) v_scroll_proc);
547 #else
548 value = TrackControl (control, mouse, (ProcPtr) v_scroll_proc);
549 #endif
550 #endif
551 break;
554 else
556 TEClick (mouse, 0, console_text);
561 scroll_text (hlines, vlines)
562 int hlines, vlines;
566 activate_window (win, activate)
567 WindowPtr win;
568 int activate;
570 Rect grow_rect;
572 if (win == nil) return;
573 /* It's convenient to make the activated window also be the
574 current GrafPort. */
575 if (activate)
576 SetPort(win);
577 /* Activate the console window's scrollbar. */
578 if (win == console_window)
580 if (activate)
582 TEActivate (console_text);
583 /* Cause the grow icon to be redrawn at the next update. */
584 grow_rect = console_window->portRect;
585 grow_rect.top = grow_rect.bottom - sbarwid;
586 grow_rect.left = grow_rect.right - sbarwid;
587 InvalRect (&grow_rect);
589 else
591 TEDeactivate (console_text);
592 DrawGrowIcon (console_window);
594 HiliteControl (console_v_scrollbar, (activate ? 0 : 255));
598 update_window (win)
599 WindowPtr win;
601 int controls = 1, growbox = 0;
602 GrafPtr oldport;
604 /* Set the updating window to be the current grafport. */
605 GetPort (&oldport);
606 SetPort (win);
607 /* recalc_depths(); */
608 BeginUpdate (win);
609 if (win == console_window)
611 draw_console ();
612 controls = 1;
613 growbox = 1;
615 if (controls)
616 UpdateControls (win, win->visRgn);
617 if (growbox)
618 DrawGrowIcon (win);
619 EndUpdate (win);
620 SetPort (oldport);
623 adjust_menus ()
627 do_menu_command (which)
628 long which;
630 short menuid, menuitem;
631 short itemHit;
632 Str255 daname;
633 short daRefNum;
634 Boolean handledbyda;
635 WindowPtr win;
636 short ditem;
637 int i;
638 char cmdbuf[300];
640 cmdbuf[0] = '\0';
641 menuid = HiWord (which);
642 menuitem = LoWord (which);
643 switch (menuid)
645 case mApple:
646 switch (menuitem)
648 case miAbout:
649 Alert (128, nil);
650 break;
651 #if 0
652 case miHelp:
653 /* (should pop up help info) */
654 break;
655 #endif
656 default:
657 GetItem (GetMHandle (mApple), menuitem, daname);
658 daRefNum = OpenDeskAcc (daname);
660 break;
661 case mFile:
662 switch (menuitem)
664 case miFileNew:
665 if (console_window == FrontWindow ())
667 close_window (console_window);
669 new_console_window ();
670 break;
671 case miFileOpen:
672 SysBeep (20);
673 break;
674 case miFileQuit:
675 ExitToShell ();
676 break;
678 break;
679 case mEdit:
680 /* handledbyda = SystemEdit(menuitem-1); */
681 switch (menuitem)
683 case miEditCut:
684 TECut (console_text);
685 break;
686 case miEditCopy:
687 TECopy (console_text);
688 break;
689 case miEditPaste:
690 TEPaste (console_text);
691 break;
692 case miEditClear:
693 TEDelete (console_text);
694 break;
696 /* All of these operations need the same postprocessing. */
697 adjust_console_sizes ();
698 adjust_console_scrollbars ();
699 adjust_console_text ();
700 break;
701 case mDebug:
702 switch (menuitem)
704 case miDebugTarget:
705 sprintf (cmdbuf, "target %s", "remote");
706 break;
707 case miDebugRun:
708 sprintf (cmdbuf, "run");
709 break;
710 case miDebugContinue:
711 sprintf (cmdbuf, "continue");
712 break;
713 case miDebugStep:
714 sprintf (cmdbuf, "step");
715 break;
716 case miDebugNext:
717 sprintf (cmdbuf, "next");
718 break;
720 break;
722 HiliteMenu (0);
723 /* Execute a command if one had been given. Do here because a command
724 may longjmp before we get a chance to unhilite the menu. */
725 if (strlen (cmdbuf) > 0)
726 execute_command (cmdbuf, 0);
729 char commandbuf[1000];
731 do_keyboard_command (key)
732 int key;
734 int startpos, endpos, i, len;
735 char *last_newline;
736 char buf[10], *text_str, *command, *cmd_start;
737 CharsHandle text;
739 if (key == '\015' || key == '\003')
741 text = TEGetText (console_text);
742 HLock ((Handle) text);
743 text_str = *text;
744 startpos = (*console_text)->selStart;
745 endpos = (*console_text)->selEnd;
746 if (startpos != endpos)
748 len = endpos - startpos;
749 cmd_start = text_str + startpos;
751 else
753 for (i = startpos - 1; i >= 0; --i)
754 if (text_str[i] == '\015')
755 break;
756 last_newline = text_str + i;
757 len = (text_str + startpos) - 1 - last_newline;
758 cmd_start = last_newline + 1;
760 if (len > 1000) len = 999;
761 if (len < 0) len = 0;
762 strncpy (commandbuf + 1, cmd_start, len);
763 commandbuf[1 + len] = 0;
764 command = commandbuf + 1;
765 HUnlock ((Handle) text);
766 commandbuf[0] = strlen(command);
768 /* Insert a newline and recalculate before doing any command. */
769 key = '\015';
770 TEKey (key, console_text);
771 TEInsert (buf, 1, console_text);
772 adjust_console_sizes ();
773 adjust_console_scrollbars ();
774 adjust_console_text ();
776 if (strlen (command) > 0)
778 execute_command (command, 0);
779 bpstat_do_actions (&stop_bpstat);
782 else
784 /* A self-inserting character. This includes delete. */
785 TEKey (key, console_text);
789 /* Draw all graphical stuff in the console window. */
791 draw_console ()
793 SetPort (console_window);
794 TEUpdate (&(console_window->portRect), console_text);
797 /* Cause an update of a given window's entire contents. */
799 force_update (win)
800 WindowPtr win;
802 GrafPtr oldport;
804 if (win == nil) return;
805 GetPort (&oldport);
806 SetPort (win);
807 EraseRect (&win->portRect);
808 InvalRect (&win->portRect);
809 SetPort (oldport);
812 adjust_console_sizes ()
814 Rect tmprect;
816 tmprect = console_window->portRect;
817 /* Move and size the scrollbar. */
818 MoveControl (console_v_scrollbar, tmprect.right - sbarwid, 0);
819 SizeControl (console_v_scrollbar, sbarwid + 1, tmprect.bottom - sbarwid + 1);
820 /* Move and size the text. */
821 tmprect.left += 7;
822 tmprect.right -= sbarwid;
823 tmprect.bottom -= sbarwid;
824 InsetRect(&tmprect, 1, 1);
825 (*console_text)->destRect = tmprect;
826 /* Fiddle bottom of viewrect to be even multiple of text lines. */
827 tmprect.bottom = tmprect.top
828 + ((tmprect.bottom - tmprect.top) / (*console_text)->lineHeight)
829 * (*console_text)->lineHeight;
830 (*console_text)->viewRect = tmprect;
833 adjust_console_scrollbars ()
835 int lines, newmax, value;
837 (*console_v_scrollbar)->contrlVis = 0;
838 lines = (*console_text)->nLines;
839 newmax = lines - (((*console_text)->viewRect.bottom
840 - (*console_text)->viewRect.top)
841 / (*console_text)->lineHeight);
842 if (newmax < 0) newmax = 0;
843 SetCtlMax (console_v_scrollbar, newmax);
844 value = ((*console_text)->viewRect.top - (*console_text)->destRect.top)
845 / (*console_text)->lineHeight;
846 SetCtlValue (console_v_scrollbar, value);
847 (*console_v_scrollbar)->contrlVis = 0xff;
848 ShowControl (console_v_scrollbar);
851 /* Scroll the TE record so that it is consistent with the scrollbar(s). */
853 adjust_console_text ()
855 TEScroll (((*console_text)->viewRect.left
856 - (*console_text)->destRect.left)
857 - 0 /* get h scroll value */,
858 ((((*console_text)->viewRect.top - (*console_text)->destRect.top)
859 / (*console_text)->lineHeight)
860 - GetCtlValue (console_v_scrollbar))
861 * (*console_text)->lineHeight,
862 console_text);
865 /* Readline substitute. */
867 char *
868 readline (char *prrompt)
870 return gdb_readline (prrompt);
873 char *rl_completer_word_break_characters;
875 char *rl_completer_quote_characters;
877 int (*rl_completion_entry_function) ();
879 int rl_point;
881 char *rl_line_buffer;
883 char *rl_readline_name;
885 /* History substitute. */
887 void
888 add_history (char *buf)
892 void
893 stifle_history (int n)
898 unstifle_history ()
903 read_history (char *name)
908 write_history (char *name)
913 history_expand (char *x, char **y)
917 extern HIST_ENTRY *
918 history_get (int xxx)
920 return NULL;
923 int history_base;
925 char *
926 filename_completion_function (char *text, char *name)
928 return "?";
931 char *
932 tilde_expand (char *str)
934 return strsave (str);
937 /* Modified versions of standard I/O. */
939 #undef fprintf
942 hacked_fprintf (FILE *fp, const char *fmt, ...)
944 int ret;
945 va_list ap;
947 va_start (ap, fmt);
948 if (mac_app && (fp == stdout || fp == stderr))
950 char buf[1000];
952 ret = vsprintf(buf, fmt, ap);
953 TEInsert (buf, strlen(buf), console_text);
955 else
956 ret = vfprintf (fp, fmt, ap);
957 va_end (ap);
958 return ret;
961 #undef printf
964 hacked_printf (const char *fmt, ...)
966 int ret;
967 va_list ap;
969 va_start (ap, fmt);
970 ret = hacked_vfprintf(stdout, fmt, ap);
971 va_end (ap);
972 return ret;
975 #undef vfprintf
977 int
978 hacked_vfprintf (FILE *fp, const char *format, va_list args)
980 if (mac_app && (fp == stdout || fp == stderr))
982 char buf[1000];
983 int ret;
985 ret = vsprintf(buf, format, args);
986 TEInsert (buf, strlen(buf), console_text);
987 if (strchr(buf, '\n'))
989 adjust_console_sizes ();
990 adjust_console_scrollbars ();
991 adjust_console_text ();
993 return ret;
995 else
996 return vfprintf (fp, format, args);
999 #undef fputs
1001 hacked_fputs (const char *s, FILE *fp)
1003 if (mac_app && (fp == stdout || fp == stderr))
1005 TEInsert (s, strlen(s), console_text);
1006 if (strchr(s, '\n'))
1008 adjust_console_sizes ();
1009 adjust_console_scrollbars ();
1010 adjust_console_text ();
1012 return 0;
1014 else
1015 return fputs (s, fp);
1018 #undef fputc
1020 hacked_fputc (const char c, FILE *fp)
1022 if (mac_app && (fp == stdout || fp == stderr))
1024 char buf[1];
1026 buf[0] = c;
1027 TEInsert (buf, 1, console_text);
1028 if (c == '\n')
1030 adjust_console_sizes ();
1031 adjust_console_scrollbars ();
1032 adjust_console_text ();
1034 return c;
1036 else
1037 return fputc (c, fp);
1040 #undef putc
1042 hacked_putc (const char c, FILE *fp)
1044 if (mac_app && (fp == stdout || fp == stderr))
1046 char buf[1];
1048 buf[0] = c;
1049 TEInsert (buf, 1, console_text);
1050 if (c == '\n')
1052 adjust_console_sizes ();
1053 adjust_console_scrollbars ();
1054 adjust_console_text ();
1056 return c;
1058 else
1059 return fputc (c, fp);
1062 #undef fflush
1064 hacked_fflush (FILE *fp)
1066 if (mac_app && (fp == stdout || fp == stderr))
1068 adjust_console_sizes ();
1069 adjust_console_scrollbars ();
1070 adjust_console_text ();
1071 return 0;
1073 return fflush (fp);
1076 #undef fgetc
1078 hacked_fgetc (FILE *fp)
1080 if (mac_app && (fp == stdin))
1082 /* Catch any attempts to use this. */
1083 DebugStr("\pShould not be reading from stdin!");
1084 return '\n';
1086 return fgetc (fp);