* dvp-opc.c (parse_vif_unpackloc,insert_vif_unpackloc): Delete.
[deliverable/binutils-gdb.git] / gdb / mac-xdep.c
index 8b1cb6e5fadabacac5205905b9c4bf47c01b923b..20a79a53c88a5e9f40c91d90310581214e9b4a8f 100644 (file)
@@ -16,14 +16,13 @@ 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.  */
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
 #include "defs.h"
 
 #include "readline.h"
 #include "history.h"
 
-#include <Values.h>
 #include <Types.h>
 #include <Resources.h>
 #include <QuickDraw.h>
@@ -45,7 +44,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>
@@ -54,7 +53,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)
@@ -81,11 +80,23 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 
 #include "mac-defs.h"
 
+int debug_openp = 0;
+
+/* This is true if we are running as a standalone application.  */
+
 int mac_app;
 
-int useWNE;
+/* This is true if we are using WaitNextEvent.  */
+
+int use_wne;
 
-int hasColorQD;
+/* This is true if we have Color Quickdraw.  */
+
+int has_color_qd;
+
+/* This is true if we are using Color Quickdraw. */
+
+int use_color_qd;
 
 int inbackground;
 
@@ -109,11 +120,11 @@ 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;
@@ -122,6 +133,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));
@@ -135,7 +171,9 @@ mac_init ()
 
   /* Color Quickdraw is different from Classic QD. */
   SysEnvirons(2, &se);
-  hasColorQD = se.hasColorQD;
+  has_color_qd = se.hasColorQD;
+  /* Use it if we got it. */
+  use_color_qd = has_color_qd;
 
   sizerect.top = 50;
   sizerect.left = 50;
@@ -157,14 +195,12 @@ mac_init ()
   DrawMenuBar ();
 
   new_console_window ();
-
-  return 1;
 }
 
 new_console_window ()
 {
   /* Create the main window we're going to play in. */
-  if (hasColorQD)
+  if (has_color_qd)
     console_window = GetNewCWindow (wConsole, NULL, (WindowPtr) -1L);
   else
     console_window = GetNewWindow (wConsole, NULL, (WindowPtr) -1L);
@@ -201,24 +237,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, GetCaretTime(), cursorRgn);
+         tm = GetCaretTime();
+         gotevent = WaitNextEvent (everyEvent, &event, tm, cursorRgn);
        }
       else
        {
@@ -249,6 +286,8 @@ mac_command_loop()
     }
 }
 
+/* Collect the global coordinates of the mouse pointer.  */
+
 get_global_mouse (mouse)
 Point *mouse;
 {
@@ -258,13 +297,16 @@ Point *mouse;
   *mouse = evt.where;
 }
 
+/* Change the cursor's appearance to be appropriate for the given mouse
+   location.  */
+
 adjust_cursor (mouse, 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;
@@ -395,18 +437,19 @@ Point where;
   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);
-      adjust_console_sizes ();
-      adjust_console_scrollbars ();
-      adjust_console_text ();
-      InvalRect (&win->portRect);
+      if (win == console_window)
+       {
+         EraseRect (&win->portRect);
+         h = LoWord (winsize);
+         v = HiWord (winsize);
+         SizeWindow (win, h, v, 1);
+         resize_console_window ();
+       }
       SetPort (oldport);
     }
 }
@@ -417,10 +460,18 @@ 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 (&(win->portRect));
+  InvalRect (&console_window->portRect);
 }
 
 close_window (win)
@@ -490,7 +541,13 @@ do_mouse_down (WindowPtr win, EventRecord *event)
                }
              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;
            }
        }
@@ -501,6 +558,11 @@ do_mouse_down (WindowPtr win, EventRecord *event)
     }
 }
 
+scroll_text (hlines, vlines)
+int hlines, vlines;
+{
+}
+
 activate_window (win, activate)
 WindowPtr win;
 int activate;
@@ -717,27 +779,22 @@ int key;
          bpstat_do_actions (&stop_bpstat);
        }
     }
-  else if (0 /* editing chars... */)
-    {
-    }
   else
     {
-      /* A self-inserting character. */
+      /* A self-inserting character.  This includes delete.  */
       TEKey (key, console_text);
     }
 }
 
+/* Draw all graphical stuff in the console window.  */
+
 draw_console ()
 {
   SetPort (console_window);
   TEUpdate (&(console_window->portRect), console_text);
-#if 0
-  FrameRect (&((*console_text)->viewRect));
-  FrameRect (&((*console_text)->destRect));
-#endif
 }
 
-/* Cause an update of a window's entire contents. */
+/* Cause an update of a given window's entire contents.  */
 
 force_update (win)
 WindowPtr win;
@@ -757,15 +814,20 @@ 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)->viewRect = tmprect;
   (*console_text)->destRect = tmprect;
-  /* (should fiddle bottom of viewrect to be even multiple of lines?) */
+  /* 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 ()
@@ -793,8 +855,8 @@ 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)->viewRect.top - (*console_text)->destRect.top)
+             / (*console_text)->lineHeight)
             - GetCtlValue (console_v_scrollbar))
            * (*console_text)->lineHeight,
            console_text);
@@ -874,8 +936,6 @@ tilde_expand (char *str)
 
 /* Modified versions of standard I/O. */
 
-#include <stdarg.h>
-
 #undef fprintf
 
 int
@@ -890,7 +950,6 @@ hacked_fprintf (FILE *fp, const char *fmt, ...)
       char buf[1000];
 
       ret = vsprintf(buf, fmt, ap);
-      TESetSelect (40000, 40000, console_text);
       TEInsert (buf, strlen(buf), console_text);
     }
   else
@@ -908,12 +967,7 @@ hacked_printf (const char *fmt, ...)
   va_list ap;
 
   va_start (ap, fmt);
-  if (mac_app)
-    {
-      ret = hacked_vfprintf(stdout, fmt, ap);
-    }
-  else
-    ret = vfprintf (stdout, fmt, ap);
+  ret = hacked_vfprintf(stdout, fmt, ap);
   va_end (ap);
   return ret;
 }
@@ -929,8 +983,13 @@ hacked_vfprintf (FILE *fp, const char *format, va_list args)
       int ret;
 
       ret = vsprintf(buf, format, args);
-      TESetSelect (40000, 40000, console_text);
       TEInsert (buf, strlen(buf), console_text);
+      if (strchr(buf, '\n'))
+       {
+         adjust_console_sizes ();
+         adjust_console_scrollbars ();
+         adjust_console_text ();
+       }
       return ret;
     }
   else
@@ -943,8 +1002,13 @@ hacked_fputs (const char *s, FILE *fp)
 {
   if (mac_app && (fp == stdout || fp == stderr))
     {
-      TESetSelect (40000, 40000, console_text);
       TEInsert (s, strlen(s), console_text);
+      if (strchr(s, '\n'))
+       {
+         adjust_console_sizes ();
+         adjust_console_scrollbars ();
+         adjust_console_text ();
+       }
       return 0;
     }
   else
@@ -957,12 +1021,17 @@ hacked_fputc (const char c, FILE *fp)
 {
   if (mac_app && (fp == stdout || fp == stderr))
     {
-      char buf[2];
+      char buf[1];
 
       buf[0] = c;
-      TESetSelect (40000, 40000, console_text);
       TEInsert (buf, 1, console_text);
-      return 0;
+      if (c == '\n')
+       {
+         adjust_console_sizes ();
+         adjust_console_scrollbars ();
+         adjust_console_text ();
+       }
+      return c;
     }
   else
     return fputc (c, fp);
@@ -974,11 +1043,17 @@ hacked_putc (const char c, FILE *fp)
 {
   if (mac_app && (fp == stdout || fp == stderr))
     {
-      char buf[2];
+      char buf[1];
 
       buf[0] = c;
-      TESetSelect (40000, 40000, console_text);
       TEInsert (buf, 1, console_text);
+      if (c == '\n')
+       {
+         adjust_console_sizes ();
+         adjust_console_scrollbars ();
+         adjust_console_text ();
+       }
+      return c;
     }
   else
     return fputc (c, fp);
@@ -989,6 +1064,24 @@ hacked_putc (const char c, FILE *fp)
 hacked_fflush (FILE *fp)
 {
   if (mac_app && (fp == stdout || fp == stderr))
-    return 0;
+    {
+      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.029078 seconds and 4 git commands to generate.