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