Fri Sep 18 14:07:44 1998 Michael Snyder <msnyder@cleaver.cygnus.com>
[deliverable/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, Boston, MA 02111-1307, USA. */
20
21 #include "defs.h"
22
23 #include "readline.h"
24 #include "history.h"
25
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>
52
53 #ifdef MPW
54 #define QD(whatever) (qd.##whatever)
55 #define QDPat(whatever) (&(qd.##whatever))
56 #endif /* MPW */
57
58 #ifdef THINK_C
59 #define QD(whatever) (whatever)
60 #endif
61
62 #define p2c(pstr,cbuf) \
63 strncpy(cbuf, ((char *) (pstr) + 1), pstr[0]); \
64 cbuf[pstr[0]] = '\0';
65
66 #define pascalify(STR) \
67 sprintf(tmpbuf, " %s", STR); \
68 tmpbuf[0] = strlen(STR);
69
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"
80
81 #include "mac-defs.h"
82
83 int debug_openp = 0;
84
85 /* This is true if we are running as a standalone application. */
86
87 int mac_app;
88
89 /* This is true if we are using WaitNextEvent. */
90
91 int use_wne;
92
93 /* This is true if we have Color Quickdraw. */
94
95 int has_color_qd;
96
97 /* This is true if we are using Color Quickdraw. */
98
99 int use_color_qd;
100
101 int inbackground;
102
103 Rect dragrect = { -32000, -32000, 32000, 32000 };
104 Rect sizerect;
105
106 int sbarwid = 15;
107
108 /* Globals for the console window. */
109
110 WindowPtr console_window;
111
112 ControlHandle console_v_scrollbar;
113
114 Rect console_v_scroll_rect;
115
116 TEHandle console_text;
117
118 Rect console_text_rect;
119
120 /* This will go away eventually. */
121 gdb_has_a_terminal () { return 1; }
122
123 mac_init ()
124 {
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;
137
138 mac_app = 0;
139
140 str = getenv("DEBUG_GDB");
141 if (str != NULL && str[0] != '\0')
142 {
143 if (strcmp(str, "openp") == 0)
144 debug_openp = 1;
145 }
146
147 /* Don't do anything if we`re running under MPW. */
148 if (!StandAlone)
149 return;
150
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;
159
160 mac_app = 1;
161
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 ();
171
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;
177
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
186
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');
194 }
195 DrawMenuBar ();
196
197 new_console_window ();
198 }
199
200 new_console_window ()
201 {
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);
207
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);
219
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);
226
227 ShowWindow (console_window);
228 SelectWindow (console_window);
229 }
230
231 mac_command_loop()
232 {
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;
243
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)
251 {
252 /* Use WaitNextEvent if it is available, otherwise GetNextEvent. */
253 if (use_wne)
254 {
255 get_global_mouse (&mouse);
256 adjust_cursor (mouse, cursorRgn);
257 tm = GetCaretTime();
258 gotevent = WaitNextEvent (everyEvent, &event, tm, cursorRgn);
259 }
260 else
261 {
262 SystemTask ();
263 gotevent = GetNextEvent (everyEvent, &event);
264 }
265 /* First decide if the event is for a dialog or is just any old event. */
266 if (FrontWindow () != nil && IsDialogEvent (&event))
267 {
268 short itemhit;
269 DialogPtr dialog;
270
271 /* Handle all the modeless dialogs here. */
272 if (DialogSelect (&event, &dialog, &itemhit))
273 {
274 }
275 }
276 else if (gotevent)
277 {
278 /* Make sure we have the right cursor before handling the event. */
279 adjust_cursor (event.where, cursorRgn);
280 do_event (&event);
281 }
282 else
283 {
284 do_idle ();
285 }
286 }
287 }
288
289 /* Collect the global coordinates of the mouse pointer. */
290
291 get_global_mouse (mouse)
292 Point *mouse;
293 {
294 EventRecord evt;
295
296 OSEventAvail (0, &evt);
297 *mouse = evt.where;
298 }
299
300 /* Change the cursor's appearance to be appropriate for the given mouse
301 location. */
302
303 adjust_cursor (mouse, region)
304 Point mouse;
305 RgnHandle region;
306 {
307 }
308
309 /* Decipher an event, maybe do something with it. */
310
311 do_event (evt)
312 EventRecord *evt;
313 {
314 short part, err, rslt = 0;
315 WindowPtr win;
316 Boolean hit;
317 char key;
318 Point pnt;
319
320 switch (evt->what)
321 {
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)
326 {
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 ())
336 {
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;
361 }
362 break;
363 case keyDown:
364 case autoKey:
365 key = evt->message & charCodeMask;
366 /* Check for menukey equivalents. */
367 if (evt->modifiers & cmdKey)
368 {
369 if (evt->what == keyDown)
370 {
371 adjust_menus ();
372 do_menu_command (MenuKey (key));
373 }
374 }
375 else
376 {
377 if (evt->what == keyDown)
378 {
379 /* Random keypress, interpret it. */
380 do_keyboard_command (key);
381 }
382 }
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)
394 {
395 SetPt (&pnt, 50, 50);
396 err = DIBadMount (pnt, evt->message);
397 }
398 break;
399 case app4Evt:
400 /* Grab only a single byte. */
401 switch ((evt->message >> 24) & 0xFF)
402 {
403 case 0xfa:
404 break;
405 case 1:
406 inbackground = !(evt->message & 1);
407 activate_window (FrontWindow (), !inbackground);
408 break;
409 }
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;
420 }
421 return rslt;
422 }
423
424 /* Do any idle-time activities. */
425
426 do_idle ()
427 {
428 TEIdle (console_text);
429 }
430
431 grow_window (win, where)
432 WindowPtr win;
433 Point where;
434 {
435 long winsize;
436 int h, v;
437 GrafPtr oldport;
438
439 winsize = GrowWindow (win, where, &sizerect);
440 /* Only do anything if it actually changed size. */
441 if (winsize != 0)
442 {
443 GetPort (&oldport);
444 SetPort (win);
445 if (win == console_window)
446 {
447 EraseRect (&win->portRect);
448 h = LoWord (winsize);
449 v = HiWord (winsize);
450 SizeWindow (win, h, v, 1);
451 resize_console_window ();
452 }
453 SetPort (oldport);
454 }
455 }
456
457 zoom_window (win, where, part)
458 WindowPtr win;
459 Point where;
460 short part;
461 {
462 ZoomWindow (win, part, (win == FrontWindow ()));
463 if (win == console_window)
464 {
465 resize_console_window ();
466 }
467 }
468
469 resize_console_window ()
470 {
471 adjust_console_sizes ();
472 adjust_console_scrollbars ();
473 adjust_console_text ();
474 InvalRect (&console_window->portRect);
475 }
476
477 close_window (win)
478 WindowPtr win;
479 {
480 }
481
482 pascal void
483 v_scroll_proc (ControlHandle control, short part)
484 {
485 int oldval, amount = 0, newval;
486 int pagesize = ((*console_text)->viewRect.bottom - (*console_text)->viewRect.top) / (*console_text)->lineHeight;
487 if (part)
488 {
489 oldval = GetCtlValue (control);
490 switch (part)
491 {
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;
507 }
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);
513 }
514 }
515
516 do_mouse_down (WindowPtr win, EventRecord *event)
517 {
518 short part, value;
519 Point mouse;
520 ControlHandle control;
521
522 if (1 /*is_app_window(win)*/)
523 {
524 SetPort (win);
525 mouse = event->where;
526 GlobalToLocal (&mouse);
527 part = FindControl(mouse, win, &control);
528 if (control == console_v_scrollbar)
529 {
530 switch (part)
531 {
532 case inThumb:
533 value = GetCtlValue (control);
534 part = TrackControl (control, mouse, nil);
535 if (part)
536 {
537 value -= GetCtlValue (control);
538 if (value)
539 TEScroll(0, value * (*console_text)->lineHeight,
540 console_text);
541 }
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;
552 }
553 }
554 else
555 {
556 TEClick (mouse, 0, console_text);
557 }
558 }
559 }
560
561 scroll_text (hlines, vlines)
562 int hlines, vlines;
563 {
564 }
565
566 activate_window (win, activate)
567 WindowPtr win;
568 int activate;
569 {
570 Rect grow_rect;
571
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)
579 {
580 if (activate)
581 {
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);
588 }
589 else
590 {
591 TEDeactivate (console_text);
592 DrawGrowIcon (console_window);
593 }
594 HiliteControl (console_v_scrollbar, (activate ? 0 : 255));
595 }
596 }
597
598 update_window (win)
599 WindowPtr win;
600 {
601 int controls = 1, growbox = 0;
602 GrafPtr oldport;
603
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)
610 {
611 draw_console ();
612 controls = 1;
613 growbox = 1;
614 }
615 if (controls)
616 UpdateControls (win, win->visRgn);
617 if (growbox)
618 DrawGrowIcon (win);
619 EndUpdate (win);
620 SetPort (oldport);
621 }
622
623 adjust_menus ()
624 {
625 }
626
627 do_menu_command (which)
628 long which;
629 {
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];
639
640 cmdbuf[0] = '\0';
641 menuid = HiWord (which);
642 menuitem = LoWord (which);
643 switch (menuid)
644 {
645 case mApple:
646 switch (menuitem)
647 {
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);
659 }
660 break;
661 case mFile:
662 switch (menuitem)
663 {
664 case miFileNew:
665 if (console_window == FrontWindow ())
666 {
667 close_window (console_window);
668 }
669 new_console_window ();
670 break;
671 case miFileOpen:
672 SysBeep (20);
673 break;
674 case miFileQuit:
675 ExitToShell ();
676 break;
677 }
678 break;
679 case mEdit:
680 /* handledbyda = SystemEdit(menuitem-1); */
681 switch (menuitem)
682 {
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;
695 }
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)
703 {
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;
719 }
720 break;
721 }
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);
727 }
728
729 char commandbuf[1000];
730
731 do_keyboard_command (key)
732 int key;
733 {
734 int startpos, endpos, i, len;
735 char *last_newline;
736 char buf[10], *text_str, *command, *cmd_start;
737 CharsHandle text;
738
739 if (key == '\015' || key == '\003')
740 {
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)
747 {
748 len = endpos - startpos;
749 cmd_start = text_str + startpos;
750 }
751 else
752 {
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;
759 }
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);
767
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 ();
775
776 if (strlen (command) > 0)
777 {
778 execute_command (command, 0);
779 bpstat_do_actions (&stop_bpstat);
780 }
781 }
782 else
783 {
784 /* A self-inserting character. This includes delete. */
785 TEKey (key, console_text);
786 }
787 }
788
789 /* Draw all graphical stuff in the console window. */
790
791 draw_console ()
792 {
793 SetPort (console_window);
794 TEUpdate (&(console_window->portRect), console_text);
795 }
796
797 /* Cause an update of a given window's entire contents. */
798
799 force_update (win)
800 WindowPtr win;
801 {
802 GrafPtr oldport;
803
804 if (win == nil) return;
805 GetPort (&oldport);
806 SetPort (win);
807 EraseRect (&win->portRect);
808 InvalRect (&win->portRect);
809 SetPort (oldport);
810 }
811
812 adjust_console_sizes ()
813 {
814 Rect tmprect;
815
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;
831 }
832
833 adjust_console_scrollbars ()
834 {
835 int lines, newmax, value;
836
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);
849 }
850
851 /* Scroll the TE record so that it is consistent with the scrollbar(s). */
852
853 adjust_console_text ()
854 {
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);
863 }
864
865 /* Readline substitute. */
866
867 char *
868 readline (char *prrompt)
869 {
870 return gdb_readline (prrompt);
871 }
872
873 char *rl_completer_word_break_characters;
874
875 char *rl_completer_quote_characters;
876
877 int (*rl_completion_entry_function) ();
878
879 int rl_point;
880
881 char *rl_line_buffer;
882
883 char *rl_readline_name;
884
885 /* History substitute. */
886
887 void
888 add_history (char *buf)
889 {
890 }
891
892 void
893 stifle_history (int n)
894 {
895 }
896
897 int
898 unstifle_history ()
899 {
900 }
901
902 int
903 read_history (char *name)
904 {
905 }
906
907 int
908 write_history (char *name)
909 {
910 }
911
912 int
913 history_expand (char *x, char **y)
914 {
915 }
916
917 extern HIST_ENTRY *
918 history_get (int xxx)
919 {
920 return NULL;
921 }
922
923 int history_base;
924
925 char *
926 filename_completion_function (char *text, char *name)
927 {
928 return "?";
929 }
930
931 char *
932 tilde_expand (char *str)
933 {
934 return strsave (str);
935 }
936
937 /* Modified versions of standard I/O. */
938
939 #undef fprintf
940
941 int
942 hacked_fprintf (FILE *fp, const char *fmt, ...)
943 {
944 int ret;
945 va_list ap;
946
947 va_start (ap, fmt);
948 if (mac_app && (fp == stdout || fp == stderr))
949 {
950 char buf[1000];
951
952 ret = vsprintf(buf, fmt, ap);
953 TEInsert (buf, strlen(buf), console_text);
954 }
955 else
956 ret = vfprintf (fp, fmt, ap);
957 va_end (ap);
958 return ret;
959 }
960
961 #undef printf
962
963 int
964 hacked_printf (const char *fmt, ...)
965 {
966 int ret;
967 va_list ap;
968
969 va_start (ap, fmt);
970 ret = hacked_vfprintf(stdout, fmt, ap);
971 va_end (ap);
972 return ret;
973 }
974
975 #undef vfprintf
976
977 int
978 hacked_vfprintf (FILE *fp, const char *format, va_list args)
979 {
980 if (mac_app && (fp == stdout || fp == stderr))
981 {
982 char buf[1000];
983 int ret;
984
985 ret = vsprintf(buf, format, args);
986 TEInsert (buf, strlen(buf), console_text);
987 if (strchr(buf, '\n'))
988 {
989 adjust_console_sizes ();
990 adjust_console_scrollbars ();
991 adjust_console_text ();
992 }
993 return ret;
994 }
995 else
996 return vfprintf (fp, format, args);
997 }
998
999 #undef fputs
1000
1001 hacked_fputs (const char *s, FILE *fp)
1002 {
1003 if (mac_app && (fp == stdout || fp == stderr))
1004 {
1005 TEInsert (s, strlen(s), console_text);
1006 if (strchr(s, '\n'))
1007 {
1008 adjust_console_sizes ();
1009 adjust_console_scrollbars ();
1010 adjust_console_text ();
1011 }
1012 return 0;
1013 }
1014 else
1015 return fputs (s, fp);
1016 }
1017
1018 #undef fputc
1019
1020 hacked_fputc (const char c, FILE *fp)
1021 {
1022 if (mac_app && (fp == stdout || fp == stderr))
1023 {
1024 char buf[1];
1025
1026 buf[0] = c;
1027 TEInsert (buf, 1, console_text);
1028 if (c == '\n')
1029 {
1030 adjust_console_sizes ();
1031 adjust_console_scrollbars ();
1032 adjust_console_text ();
1033 }
1034 return c;
1035 }
1036 else
1037 return fputc (c, fp);
1038 }
1039
1040 #undef putc
1041
1042 hacked_putc (const char c, FILE *fp)
1043 {
1044 if (mac_app && (fp == stdout || fp == stderr))
1045 {
1046 char buf[1];
1047
1048 buf[0] = c;
1049 TEInsert (buf, 1, console_text);
1050 if (c == '\n')
1051 {
1052 adjust_console_sizes ();
1053 adjust_console_scrollbars ();
1054 adjust_console_text ();
1055 }
1056 return c;
1057 }
1058 else
1059 return fputc (c, fp);
1060 }
1061
1062 #undef fflush
1063
1064 hacked_fflush (FILE *fp)
1065 {
1066 if (mac_app && (fp == stdout || fp == stderr))
1067 {
1068 adjust_console_sizes ();
1069 adjust_console_scrollbars ();
1070 adjust_console_text ();
1071 return 0;
1072 }
1073 return fflush (fp);
1074 }
1075
1076 #undef fgetc
1077
1078 hacked_fgetc (FILE *fp)
1079 {
1080 if (mac_app && (fp == stdin))
1081 {
1082 /* Catch any attempts to use this. */
1083 DebugStr("\pShould not be reading from stdin!");
1084 return '\n';
1085 }
1086 return fgetc (fp);
1087 }
This page took 0.052419 seconds and 4 git commands to generate.