* hppa-dis.c (print_insn_hppa): Change condition args to use
[deliverable/binutils-gdb.git] / gdb / mac-xdep.c
index 93fd0548fb7ff2dda4d757e64389de9d68b3e9af..ae5c4fafe5206381e2e767c556acc4af213945cc 100644 (file)
@@ -1,26 +1,29 @@
 /* Top level support for Mac interface to GDB, the GNU debugger.
    Copyright 1994 Free Software Foundation, Inc.
-   Contributed by Cygnus Support.  Written by Stan Shebs for Cygnus.
+   Contributed by Cygnus Support.  Written by Stan Shebs.
 
-This file is part of GDB.
+   This file is part of GDB.
 
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
 
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
 
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
 
 #include "defs.h"
 
-#include <Values.h>
+#include <readline/readline.h>
+#include <readline/history.h>
+
 #include <Types.h>
 #include <Resources.h>
 #include <QuickDraw.h>
@@ -42,7 +45,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #include <Packages.h>
 #include <Traps.h>
 #include <Lists.h>
-#include <GestaltEqu.h>
+#include <Gestalt.h>
 #include <PPCToolbox.h>
 #include <AppleEvents.h>
 #include <StandardFile.h>
@@ -51,7 +54,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #ifdef MPW
 #define QD(whatever) (qd.##whatever)
 #define QDPat(whatever) (&(qd.##whatever))
-#endif
+#endif /* MPW */
 
 #ifdef THINK_C
 #define QD(whatever) (whatever)
@@ -75,17 +78,31 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #include "gdbtypes.h"
 #include "expression.h"
 #include "language.h"
-#include "terminal.h" /* For job_control.  */
 
 #include "mac-defs.h"
 
-int useWNE;
+int debug_openp = 0;
+
+/* This is true if we are running as a standalone application.  */
+
+int mac_app;
+
+/* This is true if we are using WaitNextEvent.  */
+
+int use_wne;
+
+/* This is true if we have Color Quickdraw.  */
+
+int has_color_qd;
 
-int hasColorQD;
+/* This is true if we are using Color Quickdraw. */
+
+int use_color_qd;
 
 int inbackground;
 
-Rect dragrect = { -32000, -32000, 32000, 32000 };
+Rect dragrect =
+{-32000, -32000, 32000, 32000};
 Rect sizerect;
 
 int sbarwid = 15;
@@ -102,10 +119,17 @@ TEHandle console_text;
 
 Rect console_text_rect;
 
+/* This will go away eventually. */
+gdb_has_a_terminal ()
+{
+  return 1;
+}
+
 mac_init ()
 {
   SysEnvRec se;
   int eventloopdone = 0;
+  char *str;
   Boolean gotevent;
   Point mouse;
   EventRecord event;
@@ -114,6 +138,31 @@ mac_init ()
   int i;
   Handle menubar;
   MenuHandle menu;
+  Handle siow_resource;
+
+  mac_app = 0;
+
+  str = getenv ("DEBUG_GDB");
+  if (str != NULL && str[0] != '\0')
+    {
+      if (strcmp (str, "openp") == 0)
+       debug_openp = 1;
+    }
+
+  /* Don't do anything if we`re running under MPW. */
+  if (!StandAlone)
+    return;
+
+  /* Don't do anything if we're using SIOW. */
+  /* This test requires that the siow 0 resource, as defined in
+     {RIncludes}siow.r, not be messed with.  If it is, then the
+     standard Mac setup below will step on SIOW's Mac setup and
+     most likely crash the machine. */
+  siow_resource = GetResource ('siow', 0);
+  if (siow_resource != nil)
+    return;
+
+  mac_app = 1;
 
   /* Do the standard Mac environment setup. */
   InitGraf (&QD (thePort));
@@ -126,16 +175,18 @@ mac_init ()
   InitCursor ();
 
   /* Color Quickdraw is different from Classic QD. */
-  SysEnvirons(2, &se);
-  hasColorQD = se.hasColorQD;
+  SysEnvirons (2, &se);
+  has_color_qd = se.hasColorQD;
+  /* Use it if we got it. */
+  use_color_qd = has_color_qd;
 
   sizerect.top = 50;
   sizerect.left = 50;
   sizerect.bottom = 1000;
-  sizerect.right  = 1000;
+  sizerect.right = 1000;
 #if 0
   sizerect.bottom = screenBits.bounds.bottom - screenBits.bounds.top;
-  sizerect.right  = screenBits.bounds.right  - screenBits.bounds.left;
+  sizerect.right = screenBits.bounds.right - screenBits.bounds.left;
 #endif
 
   /* Set up the menus. */
@@ -143,26 +194,34 @@ mac_init ()
   SetMenuBar (menubar);
   /* Add the DAs etc as usual. */
   menu = GetMHandle (mApple);
-  if (menu != nil) {
-    AddResMenu (menu, 'DRVR');
-  }
+  if (menu != nil)
+    {
+      AddResMenu (menu, 'DRVR');
+    }
   DrawMenuBar ();
 
+  new_console_window ();
+}
+
+new_console_window ()
+{
   /* Create the main window we're going to play in. */
-  if (hasColorQD)
-    console_window = GetNewCWindow (wConsole, NULL, (WindowPtr) -1L);
+  if (has_color_qd)
+    console_window = GetNewCWindow (wConsole, NULL, (WindowPtr) - 1L);
   else
-    console_window = GetNewWindow (wConsole, NULL, (WindowPtr) -1L);
+    console_window = GetNewWindow (wConsole, NULL, (WindowPtr) - 1L);
 
-  if (1) DebugStr("\pnear beginning");
   SetPort (console_window);
   console_text_rect = console_window->portRect;
+  /* Leave 8 pixels of blank space, for aesthetic reasons and to
+     make it easier to select from the beginning of a line. */
+  console_text_rect.left += 8;
   console_text_rect.bottom -= sbarwid - 1;
   console_text_rect.right -= sbarwid - 1;
   console_text = TENew (&console_text_rect, &console_text_rect);
-  TESetSelect (0, 32767, console_text);
+  TESetSelect (0, 40000, console_text);
   TEDelete (console_text);
-  TEInsert ("(gdb)", strlen("(gdb)"), console_text);
+  TEAutoView (1, console_text);
 
   console_v_scroll_rect = console_window->portRect;
   console_v_scroll_rect.bottom -= sbarwid - 1;
@@ -173,12 +232,9 @@ mac_init ()
 
   ShowWindow (console_window);
   SelectWindow (console_window);
-/*  force_update (console_window);  */
-
-  return 1;
 }
 
-mac_command_loop()
+mac_command_loop ()
 {
   SysEnvRec se;
   int eventloopdone = 0;
@@ -187,24 +243,25 @@ mac_command_loop()
   EventRecord event;
   WindowPtr win;
   RgnHandle cursorRgn;
-  int i;
+  int i, tm;
   Handle menubar;
   MenuHandle menu;
 
-  /* Figure out if the WaitNextEvent Trap is available. */
-  useWNE =
+  /* Figure out if the WaitNextEvent Trap is available.  */
+  use_wne =
     (NGetTrapAddress (0x60, ToolTrap) != NGetTrapAddress (0x9f, ToolTrap));
-  /* Pass WNE an empty region the 1st time thru. */
+  /* Pass WaitNextEvent an empty region the first time through.  */
   cursorRgn = NewRgn ();
-  /* Go into the main event-handling loop. */
+  /* Go into the main event-handling loop.  */
   while (!eventloopdone)
     {
-      /* Use WaitNextEvent if it is available, otherwise GetNextEvent. */
-      if (useWNE)
+      /* Use WaitNextEvent if it is available, otherwise GetNextEvent.  */
+      if (use_wne)
        {
          get_global_mouse (&mouse);
          adjust_cursor (mouse, cursorRgn);
-         gotevent = WaitNextEvent (everyEvent, &event, 0L, cursorRgn);
+         tm = GetCaretTime ();
+         gotevent = WaitNextEvent (everyEvent, &event, tm, cursorRgn);
        }
       else
        {
@@ -216,7 +273,7 @@ mac_command_loop()
        {
          short itemhit;
          DialogPtr dialog;
-      
+
          /* Handle all the modeless dialogs here. */
          if (DialogSelect (&event, &dialog, &itemhit))
            {
@@ -228,28 +285,37 @@ mac_command_loop()
          adjust_cursor (event.where, cursorRgn);
          do_event (&event);
        }
+      else
+       {
+         do_idle ();
+       }
     }
 }
 
+/* Collect the global coordinates of the mouse pointer.  */
+
 get_global_mouse (mouse)
-Point *mouse;
+     Point *mouse;
 {
   EventRecord evt;
-       
+
   OSEventAvail (0, &evt);
   *mouse = evt.where;
 }
 
+/* Change the cursor's appearance to be appropriate for the given mouse
+   location.  */
+
 adjust_cursor (mouse, region)
-Point mouse;
-RgnHandle region;
+     Point mouse;
+     RgnHandle region;
 {
 }
 
-/* Decipher an event, maybe do something with it. */
+/* Decipher an event, maybe do something with it.  */
 
 do_event (evt)
-EventRecord *evt;
+     EventRecord *evt;
 {
   short part, err, rslt = 0;
   WindowPtr win;
@@ -279,10 +345,11 @@ EventRecord *evt;
              /* Fix the menu to match the new front window. */
              adjust_menus ();
              /* We always want to discard the event now, since clicks in a
-                windows are often irreversible actions. */
-           } else
-             /* Mouse clicks in the front window do something useful. */
-             do_mouse_down (win, evt);
+                windows are often irreversible actions. */
+           }
+         else
+           /* Mouse clicks in the front window do something useful. */
+           do_mouse_down (win, evt);
          break;
        case inDrag:
          /* Standard drag behavior, no tricks necessary. */
@@ -329,7 +396,7 @@ EventRecord *evt;
       break;
     case diskEvt:
       /* Call DIBadMount in response to a diskEvt, so that the user can format
-        a floppy. (from DTS Sample) */
+         a floppy. (from DTS Sample) */
       if (HiWord (evt->message) != noErr)
        {
          SetPt (&pnt, 50, 50);
@@ -352,6 +419,7 @@ EventRecord *evt;
       AEProcessAppleEvent (evt);
       break;
     case nullEvent:
+      do_idle ();
       rslt = 1;
       break;
     default:
@@ -360,62 +428,135 @@ EventRecord *evt;
   return rslt;
 }
 
+/* Do any idle-time activities. */
+
+do_idle ()
+{
+  TEIdle (console_text);
+}
+
 grow_window (win, where)
-WindowPtr win;
-Point where;
+     WindowPtr win;
+     Point where;
 {
   long winsize;
   int h, v;
   GrafPtr oldport;
 
   winsize = GrowWindow (win, where, &sizerect);
+  /* Only do anything if it actually changed size. */
   if (winsize != 0)
     {
       GetPort (&oldport);
       SetPort (win);
-      EraseRect (&win->portRect);
-      h = LoWord (winsize);
-      v = HiWord (winsize);
-      SizeWindow (win, h, v, 1);
       if (win == console_window)
        {
-         MoveControl(console_v_scrollbar, h - sbarwid, 0);
-         SizeControl(console_v_scrollbar, sbarwid + 1, v - sbarwid + 1);
+         EraseRect (&win->portRect);
+         h = LoWord (winsize);
+         v = HiWord (winsize);
+         SizeWindow (win, h, v, 1);
+         resize_console_window ();
        }
-      InvalRect (&win->portRect);
       SetPort (oldport);
     }
 }
 
 zoom_window (win, where, part)
-WindowPtr win;
-Point where;
-short part;
+     WindowPtr win;
+     Point where;
+     short part;
+{
+  ZoomWindow (win, part, (win == FrontWindow ()));
+  if (win == console_window)
+    {
+      resize_console_window ();
+    }
+}
+
+resize_console_window ()
 {
+  adjust_console_sizes ();
+  adjust_console_scrollbars ();
+  adjust_console_text ();
+  InvalRect (&console_window->portRect);
 }
 
 close_window (win)
-WindowPtr win;
+     WindowPtr win;
 {
 }
 
-do_mouse_down (win, event)
-WindowPtr win;
-EventRecord *event;
+pascal void
+v_scroll_proc (ControlHandle control, short part)
 {
-  short part;
+  int oldval, amount = 0, newval;
+  int pagesize = ((*console_text)->viewRect.bottom - (*console_text)->viewRect.top) / (*console_text)->lineHeight;
+  if (part)
+    {
+      oldval = GetCtlValue (control);
+      switch (part)
+       {
+       case inUpButton:
+         amount = 1;
+         break;
+       case inDownButton:
+         amount = -1;
+         break;
+       case inPageUp:
+         amount = pagesize;
+         break;
+       case inPageDown:
+         amount = -pagesize;
+         break;
+       default:
+         /* (should freak out) */
+         break;
+       }
+      SetCtlValue (control, oldval - amount);
+      newval = GetCtlValue (control);
+      amount = oldval - newval;
+      if (amount)
+       TEScroll (0, amount * (*console_text)->lineHeight, console_text);
+    }
+}
+
+do_mouse_down (WindowPtr win, EventRecord * event)
+{
+  short part, value;
   Point mouse;
   ControlHandle control;
 
-  if (1 /*is_app_window(win)*/)
+  if (1 /*is_app_window(win) */ )
     {
       SetPort (win);
       mouse = event->where;
       GlobalToLocal (&mouse);
-      part = FindControl(mouse, win, &control);
+      part = FindControl (mouse, win, &control);
       if (control == console_v_scrollbar)
        {
-         SysBeep(20);
+         switch (part)
+           {
+           case inThumb:
+             value = GetCtlValue (control);
+             part = TrackControl (control, mouse, nil);
+             if (part)
+               {
+                 value -= GetCtlValue (control);
+                 if (value)
+                   TEScroll (0, value * (*console_text)->lineHeight,
+                             console_text);
+               }
+             break;
+           default:
+#if 0                          /* don't deal with right now */
+#if 1                          /* universal headers */
+             value = TrackControl (control, mouse, (ControlActionUPP) v_scroll_proc);
+#else
+             value = TrackControl (control, mouse, (ProcPtr) v_scroll_proc);
+#endif
+#endif
+             break;
+           }
        }
       else
        {
@@ -424,22 +565,46 @@ EventRecord *event;
     }
 }
 
+scroll_text (hlines, vlines)
+     int hlines, vlines;
+{
+}
+
 activate_window (win, activate)
-WindowPtr win;
-int activate;
+     WindowPtr win;
+     int activate;
 {
-  if (win == nil) return;
+  Rect grow_rect;
+
+  if (win == nil)
+    return;
   /* It's convenient to make the activated window also be the
      current GrafPort. */
   if (activate)
-    SetPort(win);
+    SetPort (win);
   /* Activate the console window's scrollbar. */
   if (win == console_window)
-    HiliteControl (console_v_scrollbar, (activate ? 0 : 255));
+    {
+      if (activate)
+       {
+         TEActivate (console_text);
+         /* Cause the grow icon to be redrawn at the next update. */
+         grow_rect = console_window->portRect;
+         grow_rect.top = grow_rect.bottom - sbarwid;
+         grow_rect.left = grow_rect.right - sbarwid;
+         InvalRect (&grow_rect);
+       }
+      else
+       {
+         TEDeactivate (console_text);
+         DrawGrowIcon (console_window);
+       }
+      HiliteControl (console_v_scrollbar, (activate ? 0 : 255));
+    }
 }
 
 update_window (win)
-WindowPtr win;
+     WindowPtr win;
 {
   int controls = 1, growbox = 0;
   GrafPtr oldport;
@@ -468,7 +633,7 @@ adjust_menus ()
 }
 
 do_menu_command (which)
-long which;
+     long which;
 {
   short menuid, menuitem;
   short itemHit;
@@ -478,7 +643,9 @@ long which;
   WindowPtr win;
   short ditem;
   int i;
+  char cmdbuf[300];
 
+  cmdbuf[0] = '\0';
   menuid = HiWord (which);
   menuitem = LoWord (which);
   switch (menuid)
@@ -487,8 +654,13 @@ long which;
       switch (menuitem)
        {
        case miAbout:
-/*       Alert(aAbout, nil); */
+         Alert (128, nil);
+         break;
+#if 0
+       case miHelp:
+         /* (should pop up help info) */
          break;
+#endif
        default:
          GetItem (GetMHandle (mApple), menuitem, daname);
          daRefNum = OpenDeskAcc (daname);
@@ -497,6 +669,16 @@ long which;
     case mFile:
       switch (menuitem)
        {
+       case miFileNew:
+         if (console_window == FrontWindow ())
+           {
+             close_window (console_window);
+           }
+         new_console_window ();
+         break;
+       case miFileOpen:
+         SysBeep (20);
+         break;
        case miFileQuit:
          ExitToShell ();
          break;
@@ -507,107 +689,130 @@ long which;
       switch (menuitem)
        {
        case miEditCut:
+         TECut (console_text);
          break;
        case miEditCopy:
+         TECopy (console_text);
          break;
        case miEditPaste:
+         TEPaste (console_text);
          break;
        case miEditClear:
+         TEDelete (console_text);
+         break;
+       }
+      /* All of these operations need the same postprocessing. */
+      adjust_console_sizes ();
+      adjust_console_scrollbars ();
+      adjust_console_text ();
+      break;
+    case mDebug:
+      switch (menuitem)
+       {
+       case miDebugTarget:
+         sprintf (cmdbuf, "target %s", "remote");
+         break;
+       case miDebugRun:
+         sprintf (cmdbuf, "run");
+         break;
+       case miDebugContinue:
+         sprintf (cmdbuf, "continue");
+         break;
+       case miDebugStep:
+         sprintf (cmdbuf, "step");
+         break;
+       case miDebugNext:
+         sprintf (cmdbuf, "next");
          break;
        }
       break;
     }
   HiliteMenu (0);
+  /* Execute a command if one had been given.  Do here because a command
+     may longjmp before we get a chance to unhilite the menu. */
+  if (strlen (cmdbuf) > 0)
+    execute_command (cmdbuf, 0);
 }
 
 char commandbuf[1000];
 
 do_keyboard_command (key)
-char key;
+     int key;
 {
-  int startpos, endpos, i;
-  char buf[10], *text_str, *command;
+  int startpos, endpos, i, len;
+  char *last_newline;
+  char buf[10], *text_str, *command, *cmd_start;
   CharsHandle text;
 
   if (key == '\015' || key == '\003')
     {
-      /* (should) Interpret the line as a command. */
       text = TEGetText (console_text);
       HLock ((Handle) text);
+      text_str = *text;
       startpos = (*console_text)->selStart;
       endpos = (*console_text)->selEnd;
       if (startpos != endpos)
        {
-         strncpy (commandbuf + 1, *text + startpos, endpos - startpos);
-         commandbuf[1 + endpos - startpos] = 0;
-         command = commandbuf + 1;
+         len = endpos - startpos;
+         cmd_start = text_str + startpos;
        }
       else
        {
-         for (i = startpos; i > 0; --i)
-           {
-             strncpy (buf, *text + i, 5);
-             buf[5] = 0;
-             if (strncmp (buf, "(gdb)") == 0)
-               break;
-           }
-         if (i > 0)
-           {
-             strncpy (commandbuf + 1, *text + i + 5, startpos - i);
-             commandbuf[1 + startpos - i] = '\0';
-           }
-         else
-           {
-             SysBeep (20);
-             commandbuf[1] = '\0';
-           }
-         command = commandbuf + 1;
+         for (i = startpos - 1; i >= 0; --i)
+           if (text_str[i] == '\015')
+             break;
+         last_newline = text_str + i;
+         len = (text_str + startpos) - 1 - last_newline;
+         cmd_start = last_newline + 1;
        }
+      if (len > 1000)
+       len = 999;
+      if (len < 0)
+       len = 0;
+      strncpy (commandbuf + 1, cmd_start, len);
+      commandbuf[1 + len] = 0;
+      command = commandbuf + 1;
       HUnlock ((Handle) text);
-      commandbuf[0] = strlen(command);
-      DebugStr(commandbuf);
+      commandbuf[0] = strlen (command);
 
-      /* Insert a newline and redraw before doing the command. */
-      buf[0] = '\015';
+      /* Insert a newline and recalculate before doing any command. */
+      key = '\015';
+      TEKey (key, console_text);
       TEInsert (buf, 1, console_text);
-      TESetSelect (100000, 100000, console_text);
-      draw_console ();
+      adjust_console_sizes ();
+      adjust_console_scrollbars ();
+      adjust_console_text ();
 
-      execute_command (commandbuf, 0);
-      bpstat_do_actions (&stop_bpstat);
-    }
-  else if (0 /* editing chars... */)
-    {
+      if (strlen (command) > 0)
+       {
+         execute_command (command, 0);
+         bpstat_do_actions (&stop_bpstat);
+       }
     }
   else
     {
-      /* A self-inserting character. */
-      buf[0] = key;
-      TEInsert (buf, 1, console_text);
-      TESetSelect (100000, 100000, console_text);
-      draw_console ();
+      /* A self-inserting character.  This includes delete.  */
+      TEKey (key, console_text);
     }
 }
 
+/* Draw all graphical stuff in the console window.  */
+
 draw_console ()
 {
-  GrafPtr oldport;
-
-  GetPort (&oldport);
   SetPort (console_window);
   TEUpdate (&(console_window->portRect), console_text);
-  SetPort (oldport);
-/*     adjust_help_scrollbar();  */
 }
 
-/* Cause an update of a window's entire contents. */
+/* Cause an update of a given window's entire contents.  */
 
 force_update (win)
-WindowPtr win;
+     WindowPtr win;
 {
   GrafPtr oldport;
 
-  if (win == nil) return;
+  if (win == nil)
+    return;
   GetPort (&oldport);
   SetPort (win);
   EraseRect (&win->portRect);
@@ -615,16 +820,280 @@ WindowPtr win;
   SetPort (oldport);
 }
 
+adjust_console_sizes ()
+{
+  Rect tmprect;
+
+  tmprect = console_window->portRect;
+  /* Move and size the scrollbar. */
+  MoveControl (console_v_scrollbar, tmprect.right - sbarwid, 0);
+  SizeControl (console_v_scrollbar, sbarwid + 1, tmprect.bottom - sbarwid + 1);
+  /* Move and size the text. */
+  tmprect.left += 7;
+  tmprect.right -= sbarwid;
+  tmprect.bottom -= sbarwid;
+  InsetRect (&tmprect, 1, 1);
+  (*console_text)->destRect = tmprect;
+  /* Fiddle bottom of viewrect to be even multiple of text lines. */
+  tmprect.bottom = tmprect.top
+    + ((tmprect.bottom - tmprect.top) / (*console_text)->lineHeight)
+    * (*console_text)->lineHeight;
+  (*console_text)->viewRect = tmprect;
+}
+
 adjust_console_scrollbars ()
 {
   int lines, newmax, value;
 
+  (*console_v_scrollbar)->contrlVis = 0;
   lines = (*console_text)->nLines;
-  newmax = lines - (((*console_text)->viewRect.bottom - (*console_text)->viewRect.top)
+  newmax = lines - (((*console_text)->viewRect.bottom
+                    - (*console_text)->viewRect.top)
                    / (*console_text)->lineHeight);
-  if (newmax < 0) newmax = 0;
-  SetCtlMax(console_v_scrollbar, newmax);
+  if (newmax < 0)
+    newmax = 0;
+  SetCtlMax (console_v_scrollbar, newmax);
   value = ((*console_text)->viewRect.top - (*console_text)->destRect.top)
     / (*console_text)->lineHeight;
-  SetCtlValue(console_v_scrollbar, value);
+  SetCtlValue (console_v_scrollbar, value);
+  (*console_v_scrollbar)->contrlVis = 0xff;
+  ShowControl (console_v_scrollbar);
+}
+
+/* Scroll the TE record so that it is consistent with the scrollbar(s). */
+
+adjust_console_text ()
+{
+  TEScroll (((*console_text)->viewRect.left
+            - (*console_text)->destRect.left)
+           - 0 /* get h scroll value */ ,
+           ((((*console_text)->viewRect.top - (*console_text)->destRect.top)
+             / (*console_text)->lineHeight)
+            - GetCtlValue (console_v_scrollbar))
+           * (*console_text)->lineHeight,
+           console_text);
+}
+
+/* Readline substitute. */
+
+char *
+readline (char *prrompt)
+{
+  return gdb_readline (prrompt);
+}
+
+char *rl_completer_word_break_characters;
+
+char *rl_completer_quote_characters;
+
+int (*rl_completion_entry_function) ();
+
+int rl_point;
+
+char *rl_line_buffer;
+
+char *rl_readline_name;
+
+/* History substitute. */
+
+void
+add_history (char *buf)
+{
+}
+
+void
+stifle_history (int n)
+{
+}
+
+int
+unstifle_history ()
+{
+}
+
+int
+read_history (char *name)
+{
+}
+
+int
+write_history (char *name)
+{
+}
+
+int
+history_expand (char *x, char **y)
+{
+}
+
+extern HIST_ENTRY *
+history_get (int xxx)
+{
+  return NULL;
+}
+
+int history_base;
+
+char *
+filename_completion_function (char *text, char *name)
+{
+  return "?";
+}
+
+char *
+tilde_expand (char *str)
+{
+  return strsave (str);
+}
+
+/* Modified versions of standard I/O. */
+
+#undef fprintf
+
+int
+hacked_fprintf (FILE * fp, const char *fmt,...)
+{
+  int ret;
+  va_list ap;
+
+  va_start (ap, fmt);
+  if (mac_app && (fp == stdout || fp == stderr))
+    {
+      char buf[1000];
+
+      ret = vsprintf (buf, fmt, ap);
+      TEInsert (buf, strlen (buf), console_text);
+    }
+  else
+    ret = vfprintf (fp, fmt, ap);
+  va_end (ap);
+  return ret;
+}
+
+#undef printf
+
+int
+hacked_printf (const char *fmt,...)
+{
+  int ret;
+  va_list ap;
+
+  va_start (ap, fmt);
+  ret = hacked_vfprintf (stdout, fmt, ap);
+  va_end (ap);
+  return ret;
+}
+
+#undef vfprintf
+
+int
+hacked_vfprintf (FILE * fp, const char *format, va_list args)
+{
+  if (mac_app && (fp == stdout || fp == stderr))
+    {
+      char buf[1000];
+      int ret;
+
+      ret = vsprintf (buf, format, args);
+      TEInsert (buf, strlen (buf), console_text);
+      if (strchr (buf, '\n'))
+       {
+         adjust_console_sizes ();
+         adjust_console_scrollbars ();
+         adjust_console_text ();
+       }
+      return ret;
+    }
+  else
+    return vfprintf (fp, format, args);
+}
+
+#undef fputs
+
+hacked_fputs (const char *s, FILE * fp)
+{
+  if (mac_app && (fp == stdout || fp == stderr))
+    {
+      TEInsert (s, strlen (s), console_text);
+      if (strchr (s, '\n'))
+       {
+         adjust_console_sizes ();
+         adjust_console_scrollbars ();
+         adjust_console_text ();
+       }
+      return 0;
+    }
+  else
+    return fputs (s, fp);
+}
+
+#undef fputc
+
+hacked_fputc (const char c, FILE * fp)
+{
+  if (mac_app && (fp == stdout || fp == stderr))
+    {
+      char buf[1];
+
+      buf[0] = c;
+      TEInsert (buf, 1, console_text);
+      if (c == '\n')
+       {
+         adjust_console_sizes ();
+         adjust_console_scrollbars ();
+         adjust_console_text ();
+       }
+      return c;
+    }
+  else
+    return fputc (c, fp);
+}
+
+#undef putc
+
+hacked_putc (const char c, FILE * fp)
+{
+  if (mac_app && (fp == stdout || fp == stderr))
+    {
+      char buf[1];
+
+      buf[0] = c;
+      TEInsert (buf, 1, console_text);
+      if (c == '\n')
+       {
+         adjust_console_sizes ();
+         adjust_console_scrollbars ();
+         adjust_console_text ();
+       }
+      return c;
+    }
+  else
+    return fputc (c, fp);
+}
+
+#undef fflush
+
+hacked_fflush (FILE * fp)
+{
+  if (mac_app && (fp == stdout || fp == stderr))
+    {
+      adjust_console_sizes ();
+      adjust_console_scrollbars ();
+      adjust_console_text ();
+      return 0;
+    }
+  return fflush (fp);
+}
+
+#undef fgetc
+
+hacked_fgetc (FILE * fp)
+{
+  if (mac_app && (fp == stdin))
+    {
+      /* Catch any attempts to use this.  */
+      DebugStr ("\pShould not be reading from stdin!");
+      return '\n';
+    }
+  return fgetc (fp);
 }
This page took 0.034559 seconds and 4 git commands to generate.