* remote.c (remote_write_bytes): Add default case to switch
[deliverable/binutils-gdb.git] / gdb / mac-xdep.c
index 8b1cb6e5fadabacac5205905b9c4bf47c01b923b..b2ed22b76e26e80b5c66bab01daf760006e59066 100644 (file)
@@ -2,28 +2,28 @@
    Copyright 1994 Free Software Foundation, Inc.
    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 "readline.h"
-#include "history.h"
+#include <readline/readline.h>
+#include <readline/history.h>
 
-#include <Values.h>
 #include <Types.h>
 #include <Resources.h>
 #include <QuickDraw.h>
@@ -45,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>
@@ -54,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)
@@ -81,15 +81,28 @@ 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;
+
+/* This is true if we have Color Quickdraw.  */
 
-int hasColorQD;
+int has_color_qd;
+
+/* 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;
@@ -107,13 +120,16 @@ TEHandle console_text;
 Rect console_text_rect;
 
 /* This will go away eventually. */
-gdb_has_a_terminal () { return 1; }
-
+gdb_has_a_terminal (void)
+{
+  return 1;
+}
 
-mac_init ()
+mac_init (void)
 {
   SysEnvRec se;
   int eventloopdone = 0;
+  char *str;
   Boolean gotevent;
   Point mouse;
   EventRecord event;
@@ -122,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));
@@ -134,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. */
@@ -151,23 +194,22 @@ 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 ();
-
-  return 1;
 }
 
-new_console_window ()
+new_console_window (void)
 {
   /* 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);
 
   SetPort (console_window);
   console_text_rect = console_window->portRect;
@@ -192,7 +234,7 @@ new_console_window ()
   SelectWindow (console_window);
 }
 
-mac_command_loop()
+mac_command_loop (void)
 {
   SysEnvRec se;
   int eventloopdone = 0;
@@ -201,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, GetCaretTime(), cursorRgn);
+         tm = GetCaretTime ();
+         gotevent = WaitNextEvent (everyEvent, &event, tm, cursorRgn);
        }
       else
        {
@@ -230,7 +273,7 @@ mac_command_loop()
        {
          short itemhit;
          DialogPtr dialog;
-      
+
          /* Handle all the modeless dialogs here. */
          if (DialogSelect (&event, &dialog, &itemhit))
            {
@@ -249,25 +292,26 @@ mac_command_loop()
     }
 }
 
-get_global_mouse (mouse)
-Point *mouse;
+/* Collect the global coordinates of the mouse pointer.  */
+
+get_global_mouse (Point *mouse)
 {
   EventRecord evt;
-       
+
   OSEventAvail (0, &evt);
   *mouse = evt.where;
 }
 
-adjust_cursor (mouse, region)
-Point mouse;
-RgnHandle region;
+/* Change the cursor's appearance to be appropriate for the given mouse
+   location.  */
+
+adjust_cursor (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;
+do_event (EventRecord *evt)
 {
   short part, err, rslt = 0;
   WindowPtr win;
@@ -297,10 +341,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. */
@@ -347,7 +392,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);
@@ -381,50 +426,53 @@ EventRecord *evt;
 
 /* Do any idle-time activities. */
 
-do_idle ()
+do_idle (void)
 {
   TEIdle (console_text);
 }
 
-grow_window (win, where)
-WindowPtr win;
-Point where;
+grow_window (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);
-      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);
     }
 }
 
-zoom_window (win, where, part)
-WindowPtr win;
-Point where;
-short part;
+zoom_window (WindowPtr win, Point where, short part)
 {
   ZoomWindow (win, part, (win == FrontWindow ()));
+  if (win == console_window)
+    {
+      resize_console_window ();
+    }
+}
+
+resize_console_window (void)
+{
   adjust_console_sizes ();
   adjust_console_scrollbars ();
   adjust_console_text ();
-  InvalRect (&(win->portRect));
+  InvalRect (&console_window->portRect);
 }
 
-close_window (win)
-WindowPtr win;
+close_window (WindowPtr win)
 {
 }
 
@@ -448,13 +496,13 @@ v_scroll_proc (ControlHandle control, short part)
          amount = pagesize;
          break;
        case inPageDown:
-         amount = - pagesize;
+         amount = -pagesize;
          break;
        default:
          /* (should freak out) */
          break;
        }
-      SetCtlValue(control, oldval - amount);
+      SetCtlValue (control, oldval - amount);
       newval = GetCtlValue (control);
       amount = oldval - newval;
       if (amount)
@@ -462,18 +510,18 @@ v_scroll_proc (ControlHandle control, short part)
     }
 }
 
-do_mouse_down (WindowPtr win, EventRecord *event)
+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)
        {
          switch (part)
@@ -485,12 +533,18 @@ do_mouse_down (WindowPtr win, EventRecord *event)
                {
                  value -= GetCtlValue (control);
                  if (value)
-                   TEScroll(0, value * (*console_text)->lineHeight,
-                            console_text);
+                   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;
            }
        }
@@ -501,17 +555,20 @@ do_mouse_down (WindowPtr win, EventRecord *event)
     }
 }
 
-activate_window (win, activate)
-WindowPtr win;
-int activate;
+scroll_text (int hlines, int vlines)
+{
+}
+
+activate_window (WindowPtr win, int activate)
 {
   Rect grow_rect;
 
-  if (win == nil) return;
+  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)
     {
@@ -533,8 +590,7 @@ int activate;
     }
 }
 
-update_window (win)
-WindowPtr win;
+update_window (WindowPtr win)
 {
   int controls = 1, growbox = 0;
   GrafPtr oldport;
@@ -558,12 +614,11 @@ WindowPtr win;
   SetPort (oldport);
 }
 
-adjust_menus ()
+adjust_menus (void)
 {
 }
 
-do_menu_command (which)
-long which;
+do_menu_command (long which)
 {
   short menuid, menuitem;
   short itemHit;
@@ -666,8 +721,7 @@ long which;
 
 char commandbuf[1000];
 
-do_keyboard_command (key)
-int key;
+do_keyboard_command (int key)
 {
   int startpos, endpos, i, len;
   char *last_newline;
@@ -695,13 +749,15 @@ int key;
          len = (text_str + startpos) - 1 - last_newline;
          cmd_start = last_newline + 1;
        }
-      if (len > 1000) len = 999;
-      if (len < 0) len = 0;
+      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);
+      commandbuf[0] = strlen (command);
 
       /* Insert a newline and recalculate before doing any command. */
       key = '\015';
@@ -717,34 +773,29 @@ 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_console ()
+/* Draw all graphical stuff in the console window.  */
+
+draw_console (void)
 {
   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;
+force_update (WindowPtr win)
 {
   GrafPtr oldport;
 
-  if (win == nil) return;
+  if (win == nil)
+    return;
   GetPort (&oldport);
   SetPort (win);
   EraseRect (&win->portRect);
@@ -752,23 +803,28 @@ WindowPtr win;
   SetPort (oldport);
 }
 
-adjust_console_sizes ()
+adjust_console_sizes (void)
 {
   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;
+  InsetRect (&tmprect, 1, 1);
   (*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 ()
+adjust_console_scrollbars (void)
 {
   int lines, newmax, value;
 
@@ -777,7 +833,8 @@ adjust_console_scrollbars ()
   newmax = lines - (((*console_text)->viewRect.bottom
                     - (*console_text)->viewRect.top)
                    / (*console_text)->lineHeight);
-  if (newmax < 0) newmax = 0;
+  if (newmax < 0)
+    newmax = 0;
   SetCtlMax (console_v_scrollbar, newmax);
   value = ((*console_text)->viewRect.top - (*console_text)->destRect.top)
     / (*console_text)->lineHeight;
@@ -788,13 +845,13 @@ adjust_console_scrollbars ()
 
 /* Scroll the TE record so that it is consistent with the scrollbar(s). */
 
-adjust_console_text ()
+adjust_console_text (void)
 {
   TEScroll (((*console_text)->viewRect.left
             - (*console_text)->destRect.left)
-           - 0 /* get h scroll value */,
-           (((*console_text)->viewRect.top
-             - (*console_text)->destRect.top)
+           - 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);
@@ -833,7 +890,7 @@ stifle_history (int n)
 }
 
 int
-unstifle_history ()
+unstifle_history (void)
 {
 }
 
@@ -874,12 +931,10 @@ tilde_expand (char *str)
 
 /* Modified versions of standard I/O. */
 
-#include <stdarg.h>
-
 #undef fprintf
 
 int
-hacked_fprintf (FILE *fp, const char *fmt, ...)
+hacked_fprintf (FILE * fp, const char *fmt,...)
 {
   int ret;
   va_list ap;
@@ -889,9 +944,8 @@ 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);
+      ret = vsprintf (buf, fmt, ap);
+      TEInsert (buf, strlen (buf), console_text);
     }
   else
     ret = vfprintf (fp, fmt, ap);
@@ -902,35 +956,35 @@ hacked_fprintf (FILE *fp, const char *fmt, ...)
 #undef printf
 
 int
-hacked_printf (const char *fmt, ...)
+hacked_printf (const char *fmt,...)
 {
   int ret;
   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;
 }
 
 #undef vfprintf
 
-int 
-hacked_vfprintf (FILE *fp, const char *format, va_list args)
+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);
-      TESetSelect (40000, 40000, console_text);
-      TEInsert (buf, strlen(buf), console_text);
+      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
@@ -939,12 +993,17 @@ hacked_vfprintf (FILE *fp, const char *format, va_list args)
 
 #undef fputs
 
-hacked_fputs (const char *s, FILE *fp)
+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);
+      TEInsert (s, strlen (s), console_text);
+      if (strchr (s, '\n'))
+       {
+         adjust_console_sizes ();
+         adjust_console_scrollbars ();
+         adjust_console_text ();
+       }
       return 0;
     }
   else
@@ -953,16 +1012,21 @@ hacked_fputs (const char *s, FILE *fp)
 
 #undef fputc
 
-hacked_fputc (const char c, FILE *fp)
+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);
@@ -970,15 +1034,21 @@ hacked_fputc (const char c, FILE *fp)
 
 #undef putc
 
-hacked_putc (const char c, FILE *fp)
+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);
@@ -986,9 +1056,27 @@ hacked_putc (const char c, FILE *fp)
 
 #undef fflush
 
-hacked_fflush (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.034305 seconds and 4 git commands to generate.