]> code.delx.au - gnu-emacs/blobdiff - src/sysdep.c
* macfns.c (Fx_display_color_cells): Do not limit return value to 256.
[gnu-emacs] / src / sysdep.c
index 65cb02156b07e24c047d31ae13c315f34c0a2d28..5ede3d27208b11384f98cccd427584f5a38f4fac 100644 (file)
@@ -1,5 +1,5 @@
 /* Interfaces to system-dependent kernel and library entries.
 /* Interfaces to system-dependent kernel and library entries.
-   Copyright (C) 1985, 86,87,88,93,94,95, 1999, 2000
+   Copyright (C) 1985, 86,87,88,93,94,95,1999,2000,01,2003
    Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
    Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
@@ -19,19 +19,37 @@ along with GNU Emacs; see the file COPYING.  If not, write to
 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 Boston, MA 02111-1307, USA.  */
 
 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 Boston, MA 02111-1307, USA.  */
 
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
 
 
-#include "config.h"
 #include <signal.h>
 #include <signal.h>
+#include <stdio.h>
 #include <setjmp.h>
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #endif
 #include <setjmp.h>
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #endif
-
 #include "lisp.h"
 #include "lisp.h"
+/* Including stdlib.h isn't necessarily enough to get srandom
+   declared, e.g. without __USE_XOPEN_EXTENDED with glibc 2.  */
+#ifdef HAVE_RANDOM
+#if 0 /* It turns out that defining _OSF_SOURCE in osf5-0.h gets
+        random prototyped as returning `int'.  It looks to me as
+        though the best way to DTRT is to prefer the rand48 functions
+        (per libc.info).  -- fx */
+extern long int random P_ ((void));
+#endif
+#if 0 /* Don't prototype srandom; it takes an unsigned argument on
+        some systems, and an unsigned long on others, like FreeBSD
+        4.1.  */
+extern void srandom P_ ((unsigned int));
+#endif
+#endif
+
 #include "blockinput.h"
 #undef NULL
 
 #include "blockinput.h"
 #undef NULL
 
-#ifdef macintosh
+#ifdef MAC_OS8
 /* It is essential to include stdlib.h so that this file picks up
    the correct definitions of rand, srand, and RAND_MAX.
    Otherwise random numbers will not work correctly.  */
 /* It is essential to include stdlib.h so that this file picks up
    the correct definitions of rand, srand, and RAND_MAX.
    Otherwise random numbers will not work correctly.  */
@@ -41,9 +59,7 @@ Boston, MA 02111-1307, USA.  */
 /* Nonzero means delete a process right away if it exits (process.c).  */
 static int delete_exited_processes;
 #endif
 /* Nonzero means delete a process right away if it exits (process.c).  */
 static int delete_exited_processes;
 #endif
-#endif  /* macintosh */
-
-#define min(x,y) ((x) > (y) ? (y) : (x))
+#endif  /* MAC_OS8 */
 
 #ifdef WINDOWSNT
 #define read sys_read
 
 #ifdef WINDOWSNT
 #define read sys_read
@@ -54,6 +70,10 @@ static int delete_exited_processes;
 #endif
 #endif /* not WINDOWSNT */
 
 #endif
 #endif /* not WINDOWSNT */
 
+#ifdef HAVE_CARBON
+#define read sys_read
+#endif
+
 /* Does anyone other than VMS need this? */
 #ifndef fwrite
 #define sys_fwrite fwrite
 /* Does anyone other than VMS need this? */
 #ifndef fwrite
 #define sys_fwrite fwrite
@@ -61,20 +81,10 @@ static int delete_exited_processes;
 #undef fwrite
 #endif
 
 #undef fwrite
 #endif
 
-#include <stdio.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <errno.h>
 
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <errno.h>
 
-/* Get _POSIX_VDISABLE, if it is available.  */
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-
-#ifdef HAVE_STDLIB_H
-#include <stdlib.h>
-#endif
-
 #ifdef HAVE_SETPGID
 #if !defined (USG) || defined (BSD_PGRPS)
 #undef setpgrp
 #ifdef HAVE_SETPGID
 #if !defined (USG) || defined (BSD_PGRPS)
 #undef setpgrp
@@ -128,17 +138,13 @@ extern int errno;
 #define MAXIOSIZE (32 * PAGESIZE) /* Don't I/O more than 32 blocks at a time */
 #endif /* VMS */
 
 #define MAXIOSIZE (32 * PAGESIZE) /* Don't I/O more than 32 blocks at a time */
 #endif /* VMS */
 
-#ifndef BSD4_1
-#ifdef BSD_SYSTEM /* avoid writing defined (BSD_SYSTEM) || defined (USG)
-             because the vms compiler doesn't grok `defined' */
-#include <fcntl.h>
-#endif
-#ifdef USG
-#ifndef USG5
+#ifndef VMS
+#include <sys/file.h>
+#endif /* not VMS */
+
+#ifdef HAVE_FCNTL_H
 #include <fcntl.h>
 #endif
 #include <fcntl.h>
 #endif
-#endif
-#endif /* not 4.1 bsd */
 
 #ifndef MSDOS
 #include <sys/ioctl.h>
 
 #ifndef MSDOS
 #include <sys/ioctl.h>
@@ -232,7 +238,7 @@ static int baud_convert[] =
 #else
 #if defined (HAVE_LIBNCURSES) && ! defined (NCURSES_OSPEED_T)
 #else
 #else
 #if defined (HAVE_LIBNCURSES) && ! defined (NCURSES_OSPEED_T)
 #else
-#if defined (HAVE_TERMIOS_H) && defined (LINUX)
+#if defined (HAVE_TERMIOS_H) && defined (GNU_LINUX)
 #include <termios.h>
 #endif
 #endif
 #include <termios.h>
 #endif
 #endif
@@ -312,8 +318,12 @@ discard_tty_input ()
    the terminal.  */
 
 void
    the terminal.  */
 
 void
+#ifdef PROTOTYPES
+stuff_char (char c)
+#else
 stuff_char (c)
      char c;
 stuff_char (c)
      char c;
+#endif
 {
   if (read_socket_hook)
     return;
 {
   if (read_socket_hook)
     return;
@@ -372,7 +382,7 @@ init_baud_rate ()
       emacs_ospeed = sg.c_cflag & CBAUD;
 #else /* neither VMS nor TERMIOS nor TERMIO */
       struct sgttyb sg;
       emacs_ospeed = sg.c_cflag & CBAUD;
 #else /* neither VMS nor TERMIOS nor TERMIO */
       struct sgttyb sg;
-      
+
       sg.sg_ospeed = B9600;
       if (ioctl (input_fd, TIOCGETP, &sg) < 0)
        abort ();
       sg.sg_ospeed = B9600;
       if (ioctl (input_fd, TIOCGETP, &sg) < 0)
        abort ();
@@ -383,7 +393,7 @@ init_baud_rate ()
 #endif /* not DOS_NT */
 #endif /* not INIT_BAUD_RATE */
     }
 #endif /* not DOS_NT */
 #endif /* not INIT_BAUD_RATE */
     }
-   
+
   baud_rate = (emacs_ospeed < sizeof baud_convert / sizeof baud_convert[0]
               ? baud_convert[emacs_ospeed] : 9600);
   if (baud_rate == 0)
   baud_rate = (emacs_ospeed < sizeof baud_convert / sizeof baud_convert[0]
               ? baud_convert[emacs_ospeed] : 9600);
   if (baud_rate == 0)
@@ -463,14 +473,16 @@ wait_for_termination (pid)
        break;
       wait (0);
 #else /* neither BSD_SYSTEM nor UNIPLUS: random sysV */
        break;
       wait (0);
 #else /* neither BSD_SYSTEM nor UNIPLUS: random sysV */
-#ifdef POSIX_SIGNALS    /* would this work for LINUX as well? */
+#ifdef POSIX_SIGNALS    /* would this work for GNU/Linux as well? */
       sigblock (sigmask (SIGCHLD));
       sigblock (sigmask (SIGCHLD));
-      if (0 > kill (pid, 0))
+      errno = 0;
+      if (kill (pid, 0) == -1 && errno == ESRCH)
        {
          sigunblock (sigmask (SIGCHLD));
          break;
        }
        {
          sigunblock (sigmask (SIGCHLD));
          break;
        }
-      sigpause (SIGEMPTYMASK);
+
+      sigsuspend (&empty_mask);
 #else /* not POSIX_SIGNALS */
 #ifdef HAVE_SYSV_SIGPAUSE
       sighold (SIGCHLD);
 #else /* not POSIX_SIGNALS */
 #ifdef HAVE_SYSV_SIGPAUSE
       sighold (SIGCHLD);
@@ -522,7 +534,7 @@ wait_for_termination (pid)
  *     flush any pending output
  *      (may flush input as well; it does not matter the way we use it)
  */
  *     flush any pending output
  *      (may flush input as well; it does not matter the way we use it)
  */
+
 void
 flush_pending_output (channel)
      int channel;
 void
 flush_pending_output (channel)
      int channel;
@@ -569,6 +581,13 @@ child_setup_tty (out)
 #endif
   s.main.c_lflag &= ~ECHO;     /* Disable echo */
   s.main.c_lflag |= ISIG;      /* Enable signals */
 #endif
   s.main.c_lflag &= ~ECHO;     /* Disable echo */
   s.main.c_lflag |= ISIG;      /* Enable signals */
+#if 0  /* This causes bugs in (for instance) telnet to certain sites.  */
+  s.main.c_iflag &= ~ICRNL;    /* Disable map of CR to NL on input */
+#ifdef INLCR  /* Just being cautious, since I can't check how
+                widespread INLCR is--rms.  */
+  s.main.c_iflag &= ~INLCR;    /* Disable map of NL to CR on input */
+#endif
+#endif
 #ifdef IUCLC
   s.main.c_iflag &= ~IUCLC;    /* Disable downcasing on input.  */
 #endif
 #ifdef IUCLC
   s.main.c_iflag &= ~IUCLC;    /* Disable downcasing on input.  */
 #endif
@@ -735,7 +754,7 @@ sys_suspend ()
 
 /* Fork a subshell.  */
 
 
 /* Fork a subshell.  */
 
-#ifndef macintosh
+#ifndef MAC_OS8
 void
 sys_subshell ()
 {
 void
 sys_subshell ()
 {
@@ -771,9 +790,9 @@ sys_subshell ()
     goto xyzzy;
 
   dir = expand_and_dir_to_file (Funhandled_file_name_directory (dir), Qnil);
     goto xyzzy;
 
   dir = expand_and_dir_to_file (Funhandled_file_name_directory (dir), Qnil);
-  str = (unsigned char *) alloca (XSTRING (dir)->size + 2);
-  len = XSTRING (dir)->size;
-  bcopy (XSTRING (dir)->data, str, len);
+  str = (unsigned char *) alloca (SCHARS (dir) + 2);
+  len = SCHARS (dir);
+  bcopy (SDATA (dir), str, len);
   if (str[len - 1] != '/') str[len++] = '/';
   str[len] = 0;
  xyzzy:
   if (str[len - 1] != '/') str[len++] = '/';
   str[len] = 0;
  xyzzy:
@@ -784,7 +803,7 @@ sys_subshell ()
   save_signal_handlers (saved_handlers);
   synch_process_alive = 1;
 #endif /* __DJGPP__ > 1 */
   save_signal_handlers (saved_handlers);
   synch_process_alive = 1;
 #endif /* __DJGPP__ > 1 */
-#else  
+#else
   pid = vfork ();
   if (pid == -1)
     error ("Can't spawn subshell");
   pid = vfork ();
   if (pid == -1)
     error ("Can't spawn subshell");
@@ -814,7 +833,7 @@ sys_subshell ()
 
 #ifdef SET_EMACS_PRIORITY
       {
 
 #ifdef SET_EMACS_PRIORITY
       {
-       extern int emacs_priority;
+       extern EMACS_INT emacs_priority;
 
        if (emacs_priority < 0)
          nice (-emacs_priority);
 
        if (emacs_priority < 0)
          nice (-emacs_priority);
@@ -822,8 +841,23 @@ sys_subshell ()
 #endif
 
 #ifdef MSDOS    /* Demacs 1.1.2 91/10/20 Manabu Higashida */
 #endif
 
 #ifdef MSDOS    /* Demacs 1.1.2 91/10/20 Manabu Higashida */
-      st = system (sh);
-      chdir (oldwd);
+      {
+       char *epwd = getenv ("PWD");
+       char old_pwd[MAXPATHLEN+1+4];
+
+       /* If PWD is set, pass it with corrected value.  */
+       if (epwd)
+         {
+           strcpy (old_pwd, epwd);
+           if (str[len - 1] == '/')
+             str[len - 1] = '\0';
+           setenv ("PWD", str, 1);
+         }
+       st = system (sh);
+       chdir (oldwd);
+       if (epwd)
+         putenv (old_pwd);     /* restore previous value */
+      }
 #if 0  /* This is also reported if last command executed in subshell failed, KFS */
       if (st)
        report_file_error ("Can't execute subshell", Fcons (build_string (sh), Qnil));
 #if 0  /* This is also reported if last command executed in subshell failed, KFS */
       if (st)
        report_file_error ("Can't execute subshell", Fcons (build_string (sh), Qnil));
@@ -856,7 +890,7 @@ sys_subshell ()
   synch_process_alive = 0;
 #endif /* !VMS */
 }
   synch_process_alive = 0;
 #endif /* !VMS */
 }
-#endif /* !macintosh */
+#endif /* !MAC_OS8 */
 
 static void
 save_signal_handlers (saved_handlers)
 
 static void
 save_signal_handlers (saved_handlers)
@@ -959,7 +993,7 @@ unrequest_sigio ()
 }
 
 #else /* not FASYNC, not STRIDE */
 }
 
 #else /* not FASYNC, not STRIDE */
+
 #ifdef _CX_UX
 
 #include <termios.h>
 #ifdef _CX_UX
 
 #include <termios.h>
@@ -993,6 +1027,7 @@ unrequest_sigio ()
 }
 
 #else /* ! _CX_UX */
 }
 
 #else /* ! _CX_UX */
+#ifndef MSDOS
 
 void
 request_sigio ()
 
 void
 request_sigio ()
@@ -1002,7 +1037,7 @@ request_sigio ()
 
   croak ("request_sigio");
 }
 
   croak ("request_sigio");
 }
+
 void
 unrequest_sigio ()
 {
 void
 unrequest_sigio ()
 {
@@ -1011,7 +1046,8 @@ unrequest_sigio ()
 
   croak ("unrequest_sigio");
 }
 
   croak ("unrequest_sigio");
 }
+
+#endif /* MSDOS */
 #endif /* _CX_UX */
 #endif /* STRIDE */
 #endif /* FASYNC */
 #endif /* _CX_UX */
 #endif /* STRIDE */
 #endif /* FASYNC */
@@ -1213,7 +1249,7 @@ emacs_set_tty (fd, settings, flushp)
       || ioctl (fd, TIOCLSET, &settings->lmode) < 0)
     return -1;
 #endif
       || ioctl (fd, TIOCLSET, &settings->lmode) < 0)
     return -1;
 #endif
-  
+
   /* We have survived the tempest.  */
   return 0;
 }
   /* We have survived the tempest.  */
   return 0;
 }
@@ -1253,28 +1289,28 @@ unsigned char _sobuf[BUFSIZ+8];
 char _sobuf[BUFSIZ];
 #endif
 #endif
 char _sobuf[BUFSIZ];
 #endif
 #endif
+
 #ifdef HAVE_LTCHARS
 static struct ltchars new_ltchars = {-1,-1,-1,-1,-1,-1};
 #endif
 #ifdef HAVE_TCHARS
 static struct tchars new_tchars = {-1,-1,-1,-1,-1,-1};
 #ifdef HAVE_LTCHARS
 static struct ltchars new_ltchars = {-1,-1,-1,-1,-1,-1};
 #endif
 #ifdef HAVE_TCHARS
 static struct tchars new_tchars = {-1,-1,-1,-1,-1,-1};
-#endif 
+#endif
 
 void
 init_sys_modes ()
 {
   struct emacs_tty tty;
 
 
 void
 init_sys_modes ()
 {
   struct emacs_tty tty;
 
-#ifdef macintosh
+#ifdef MAC_OS8
 /* cus-start.el complains if delete-exited-processes is not defined */
 #ifndef subprocesses
   DEFVAR_BOOL ("delete-exited-processes", &delete_exited_processes,
 /* cus-start.el complains if delete-exited-processes is not defined */
 #ifndef subprocesses
   DEFVAR_BOOL ("delete-exited-processes", &delete_exited_processes,
-    "*Non-nil means delete processes immediately when they exit.\n\
-nil means don't delete them until `list-processes' is run.");
+              doc: /* *Non-nil means delete processes immediately when they exit.
+nil means don't delete them until `list-processes' is run.  */);
   delete_exited_processes = 0;
 #endif
   delete_exited_processes = 0;
 #endif
-#endif /* not macintosh */
+#endif /* MAC_OS8 */
 
 #ifdef VMS
 #if 0
 
 #ifdef VMS
 #if 0
@@ -1368,7 +1404,7 @@ nil means don't delete them until `list-processes' is run.");
        }
       else
        tty.main.c_iflag &= ~IXON;      /* Disable start/stop output control */
        }
       else
        tty.main.c_iflag &= ~IXON;      /* Disable start/stop output control */
-      tty.main.c_oflag &= ~ONLCR;      /* Disable map of NL to CR-NL 
+      tty.main.c_oflag &= ~ONLCR;      /* Disable map of NL to CR-NL
                                           on output */
       tty.main.c_oflag &= ~TAB3;       /* Disable tab expansion */
 #ifdef CS8
                                           on output */
       tty.main.c_oflag &= ~TAB3;       /* Disable tab expansion */
 #ifdef CS8
@@ -1509,7 +1545,7 @@ nil means don't delete them until `list-processes' is run.");
         anything, and leaving it in breaks the meta key.  Go figure.  */
       tty.lmode &= ~LLITOUT;
 #endif
         anything, and leaving it in breaks the meta key.  Go figure.  */
       tty.lmode &= ~LLITOUT;
 #endif
-      
+
 #ifdef BSD4_1
       lmode = tty.lmode;
 #endif
 #ifdef BSD4_1
       lmode = tty.lmode;
 #endif
@@ -1634,7 +1670,7 @@ nil means don't delete them until `list-processes' is run.");
 
 /* Return nonzero if safe to use tabs in output.
    At the time this is called, init_sys_modes has not been done yet.  */
 
 /* Return nonzero if safe to use tabs in output.
    At the time this is called, init_sys_modes has not been done yet.  */
-   
+
 int
 tabs_safe_p ()
 {
 int
 tabs_safe_p ()
 {
@@ -1670,7 +1706,7 @@ get_frame_size (widthp, heightp)
 #ifdef TIOCGSIZE
 
   /* SunOS - style.  */
 #ifdef TIOCGSIZE
 
   /* SunOS - style.  */
-  struct ttysize size;  
+  struct ttysize size;
 
   if (ioctl (input_fd, TIOCGSIZE, &size) == -1)
     *widthp = *heightp = 0;
 
   if (ioctl (input_fd, TIOCGSIZE, &size) == -1)
     *widthp = *heightp = 0;
@@ -1684,7 +1720,7 @@ get_frame_size (widthp, heightp)
 #ifdef VMS
 
   struct sensemode tty;
 #ifdef VMS
 
   struct sensemode tty;
-  
+
   SYS$QIOW (0, input_fd, IO$_SENSEMODE, &tty, 0, 0,
            &tty.class, 12, 0, 0, 0, 0);
   *widthp = tty.scr_wid;
   SYS$QIOW (0, input_fd, IO$_SENSEMODE, &tty, 0, 0,
            &tty.class, 12, 0, 0, 0, 0);
   *widthp = tty.scr_wid;
@@ -1727,7 +1763,7 @@ set_window_size (fd, height, width)
 #ifdef TIOCSSIZE
 
   /* SunOS - style.  */
 #ifdef TIOCSSIZE
 
   /* SunOS - style.  */
-  struct ttysize size;  
+  struct ttysize size;
   size.ts_lines = height;
   size.ts_cols = width;
 
   size.ts_lines = height;
   size.ts_cols = width;
 
@@ -1748,7 +1784,7 @@ void
 reset_sys_modes ()
 {
   struct frame *sf;
 reset_sys_modes ()
 {
   struct frame *sf;
-  
+
   if (noninteractive)
     {
       fflush (stdout);
   if (noninteractive)
     {
       fflush (stdout);
@@ -1769,13 +1805,13 @@ reset_sys_modes ()
     return;
 #endif
   sf = SELECTED_FRAME ();
     return;
 #endif
   sf = SELECTED_FRAME ();
-  cursor_to (FRAME_HEIGHT (sf) - 1, 0);
-  clear_end_of_line (FRAME_WIDTH (sf));
+  cursor_to (FRAME_LINES (sf) - 1, 0);
+  clear_end_of_line (FRAME_COLS (sf));
   /* clear_end_of_line may move the cursor */
   /* clear_end_of_line may move the cursor */
-  cursor_to (FRAME_HEIGHT (sf) - 1, 0);
+  cursor_to (FRAME_LINES (sf) - 1, 0);
 #if defined (IBMR2AIX) && defined (AIXHFT)
   {
 #if defined (IBMR2AIX) && defined (AIXHFT)
   {
-    /* HFT devices normally use ^J as a LF/CR.  We forced it to 
+    /* HFT devices normally use ^J as a LF/CR.  We forced it to
        do the LF only.  Now, we need to reset it. */
     struct termio tty;
 
        do the LF only.  Now, we need to reset it. */
     struct termio tty;
 
@@ -1858,13 +1894,13 @@ setup_pty (fd)
      does this.  Also it is known that telnet mode will hang
      in such a way that Emacs must be stopped (perhaps this
      is the same problem).
      does this.  Also it is known that telnet mode will hang
      in such a way that Emacs must be stopped (perhaps this
      is the same problem).
-     
+
      If TIOCREMOTE is turned off, then there is a bug in
      hp-ux which sometimes loses data.  Apparently the
      code which blocks the master process when the internal
      buffer fills up does not work.  Other than this,
      though, everything else seems to work fine.
      If TIOCREMOTE is turned off, then there is a bug in
      hp-ux which sometimes loses data.  Apparently the
      code which blocks the master process when the internal
      buffer fills up does not work.  Other than this,
      though, everything else seems to work fine.
-     
+
      Since the latter lossage is more benign, we may as well
      lose that way.  -- cph */
 #ifdef FIONBIO
      Since the latter lossage is more benign, we may as well
      lose that way.  -- cph */
 #ifdef FIONBIO
@@ -1896,7 +1932,7 @@ void
 init_vms_input ()
 {
   int status;
 init_vms_input ()
 {
   int status;
-  
+
   if (input_fd == 0)
     {
       status = SYS$ASSIGN (&input_dsc, &input_fd, 0, 0);
   if (input_fd == 0)
     {
       status = SYS$ASSIGN (&input_dsc, &input_fd, 0, 0);
@@ -1972,7 +2008,9 @@ kbd_input_ast ()
   if (c >= 0)
     {
       struct input_event e;
   if (c >= 0)
     {
       struct input_event e;
-      e.kind = ascii_keystroke;
+      EVENT_INIT (e);
+
+      e.kind = ASCII_KEYSTROKE_EVENT;
       XSETINT (e.code, c);
       e.frame_or_window = selected_frame;
       kbd_buffer_store_event (&e);
       XSETINT (e.code, c);
       e.frame_or_window = selected_frame;
       kbd_buffer_store_event (&e);
@@ -2003,7 +2041,7 @@ wait_for_kbd_input ()
       /* No timing error: wait for flag to be set.  */
       set_waiting_for_input (0);
       SYS$WFLOR (input_ef, input_eflist);
       /* No timing error: wait for flag to be set.  */
       set_waiting_for_input (0);
       SYS$WFLOR (input_ef, input_eflist);
-      clear_waiting_for_input (0);
+      clear_waiting_for_input ();
       if (!detect_input_pending ())
        /* Check for subprocess input availability */
        {
       if (!detect_input_pending ())
        /* Check for subprocess input availability */
        {
@@ -2018,7 +2056,7 @@ wait_for_kbd_input ()
            {
              update_mode_lines++;
              prepare_menu_bars ();
            {
              update_mode_lines++;
              prepare_menu_bars ();
-             redisplay_preserve_echo_area ();
+             redisplay_preserve_echo_area (18);
            }
        }
     }
            }
        }
     }
@@ -2097,7 +2135,7 @@ sys_sleep (timeval)
   int time [2];
   static int zero = 0;
   static int large = -10000000;
   int time [2];
   static int zero = 0;
   static int large = -10000000;
-  
+
   LIB$EMUL (&timeval, &large, &zero, time);      /* Convert to VMS format */
 
   SYS$CANTIM (1, 0);
   LIB$EMUL (&timeval, &large, &zero, time);      /* Convert to VMS format */
 
   SYS$CANTIM (1, 0);
@@ -2197,7 +2235,8 @@ start_of_text ()
  *     will be patched by unexec to the correct value.
  *
  */
  *     will be patched by unexec to the correct value.
  *
  */
+
+#ifndef start_of_data
 char *
 start_of_data ()
 {
 char *
 start_of_data ()
 {
@@ -2220,44 +2259,8 @@ start_of_data ()
 #endif /* ORDINARY_LINK */
 #endif /* DATA_START */
 }
 #endif /* ORDINARY_LINK */
 #endif /* DATA_START */
 }
+#endif /* start_of_data */
 #endif /* NEED_STARTS (not CANNOT_DUMP or not SYSTEM_MALLOC) */
 #endif /* NEED_STARTS (not CANNOT_DUMP or not SYSTEM_MALLOC) */
-
-#ifndef CANNOT_DUMP
-/* Some systems that cannot dump also cannot implement these.  */
-
-/*
- *     Return the address of the end of the text segment prior to
- *     doing an unexec.  After unexec the return value is undefined.
- */
-char *
-end_of_text ()
-{
-#ifdef TEXT_END
-  return ((char *) TEXT_END);
-#else
-  extern int etext;
-  return ((char *) &etext);
-#endif
-}
-/*
- *     Return the address of the end of the data segment prior to
- *     doing an unexec.  After unexec the return value is undefined.
- */
-
-char *
-end_of_data ()
-{
-#ifdef DATA_END
-  return ((char *) DATA_END);
-#else
-  extern int edata;
-  return ((char *) &edata);
-#endif
-}
-
-#endif /* not CANNOT_DUMP */
 \f
 /* init_system_name sets up the string for the Lisp function
    system-name to return. */
 \f
 /* init_system_name sets up the string for the Lisp function
    system-name to return. */
@@ -2350,7 +2353,9 @@ init_system_name ()
        if (hp)
          {
            char *fqdn = (char *) hp->h_name;
        if (hp)
          {
            char *fqdn = (char *) hp->h_name;
+#if 0
            char *p;
            char *p;
+#endif
 
            if (!index (fqdn, '.'))
              {
 
            if (!index (fqdn, '.'))
              {
@@ -2424,7 +2429,7 @@ init_system_name ()
 #endif /* BSD4_1 */
   {
     unsigned char *p;
 #endif /* BSD4_1 */
   {
     unsigned char *p;
-    for (p = XSTRING (Vsystem_name)->data; *p; p++)
+    for (p = SDATA (Vsystem_name); *p; p++)
       if (*p == ' ' || *p == '\t')
        *p = '-';
   }
       if (*p == ' ' || *p == '\t')
        *p = '-';
   }
@@ -2530,7 +2535,7 @@ sys_select (nfds, rfds, wfds, efds, timeout)
   /* Once a second, till the timer expires, check all the flagged read
    * descriptors to see if any input is available.  If there is some then
    * set the corresponding bit in the return copy of rfds.
   /* Once a second, till the timer expires, check all the flagged read
    * descriptors to see if any input is available.  If there is some then
    * set the corresponding bit in the return copy of rfds.
-   */ 
+   */
   while (1)
     {
       register int to_check, fd;
   while (1)
     {
       register int to_check, fd;
@@ -2577,7 +2582,7 @@ sys_select (nfds, rfds, wfds, efds, timeout)
       signal (SIGALRM, select_alarm);
       select_alarmed = 0;
       alarm (SELECT_PAUSE);
       signal (SIGALRM, select_alarm);
       select_alarmed = 0;
       alarm (SELECT_PAUSE);
-      
+
       /* Wait for a SIGALRM (or maybe a SIGTINT) */
       while (select_alarmed == 0 && *local_timeout != 0
             && process_tick == update_tick)
       /* Wait for a SIGALRM (or maybe a SIGTINT) */
       while (select_alarmed == 0 && *local_timeout != 0
             && process_tick == update_tick)
@@ -2595,10 +2600,10 @@ sys_select (nfds, rfds, wfds, efds, timeout)
            pause ();
        }
       (*local_timeout) -= SELECT_PAUSE;
            pause ();
        }
       (*local_timeout) -= SELECT_PAUSE;
-      
+
       /* Reset the old alarm if there was one.  */
       turn_on_atimers (1);
       /* Reset the old alarm if there was one.  */
       turn_on_atimers (1);
-      
+
       if (*local_timeout == 0)  /* Stop on timer being cleared */
        break;
     }
       if (*local_timeout == 0)  /* Stop on timer being cleared */
        break;
     }
@@ -2609,48 +2614,37 @@ sys_select (nfds, rfds, wfds, efds, timeout)
 /* Read keyboard input into the standard buffer,
    waiting for at least one character.  */
 
 /* Read keyboard input into the standard buffer,
    waiting for at least one character.  */
 
-/* Make all keyboard buffers much bigger when using a window system.  */
-#ifdef HAVE_WINDOW_SYSTEM
-#define BUFFER_SIZE_FACTOR 16
-#else
-#define BUFFER_SIZE_FACTOR 1
-#endif
-
 void
 read_input_waiting ()
 {
 void
 read_input_waiting ()
 {
-  struct input_event e;
   int nread, i;
   extern int quit_char;
 
   if (read_socket_hook)
     {
   int nread, i;
   extern int quit_char;
 
   if (read_socket_hook)
     {
-      struct input_event buf[256];
+      struct input_event hold_quit;
+
+      EVENT_INIT (hold_quit);
+      hold_quit.kind = NO_EVENT;
 
       read_alarm_should_throw = 0;
       if (! setjmp (read_alarm_throw))
 
       read_alarm_should_throw = 0;
       if (! setjmp (read_alarm_throw))
-       nread = (*read_socket_hook) (0, buf, 256, 1);
+       nread = (*read_socket_hook) (0, 1, &hold_quit);
       else
        nread = -1;
 
       else
        nread = -1;
 
-      /* Scan the chars for C-g and store them in kbd_buffer.  */
-      for (i = 0; i < nread; i++)
-       {
-         kbd_buffer_store_event (&buf[i]);
-         /* Don't look at input that follows a C-g too closely.
-            This reduces lossage due to autorepeat on C-g.  */
-         if (buf[i].kind == ascii_keystroke
-             && buf[i].code == quit_char)
-           break;
-       }
+      if (hold_quit.kind != NO_EVENT)
+       kbd_buffer_store_event (&hold_quit);
     }
   else
     {
     }
   else
     {
+      struct input_event e;
       char buf[3];
       nread = read (fileno (stdin), buf, 1);
       char buf[3];
       nread = read (fileno (stdin), buf, 1);
+      EVENT_INIT (e);
 
       /* Scan the chars for C-g and store them in kbd_buffer.  */
 
       /* Scan the chars for C-g and store them in kbd_buffer.  */
-      e.kind = ascii_keystroke;
+      e.kind = ASCII_KEYSTROKE_EVENT;
       e.frame_or_window = selected_frame;
       e.modifiers = 0;
       for (i = 0; i < nread; i++)
       e.frame_or_window = selected_frame;
       e.modifiers = 0;
       for (i = 0; i < nread; i++)
@@ -2775,10 +2769,12 @@ sys_signal (int signal_number, signal_handler_t action)
   struct sigaction new_action, old_action;
   sigemptyset (&new_action.sa_mask);
   new_action.sa_handler = action;
   struct sigaction new_action, old_action;
   sigemptyset (&new_action.sa_mask);
   new_action.sa_handler = action;
-#ifdef SA_RESTART
+#if defined (SA_RESTART) && ! defined (BROKEN_SA_RESTART)
   /* Emacs mostly works better with restartable system services. If this
   /* Emacs mostly works better with restartable system services. If this
-   * flag exists, we probably want to turn it on here.
-   */
+     flag exists, we probably want to turn it on here.
+     However, on some systems this resets the timeout of `select'
+     which means that `select' never finishes if it keeps getting signals.
+     BROKEN_SA_RESTART is defined on those systems.  */
   new_action.sa_flags = SA_RESTART;
 #else
   new_action.sa_flags = 0;
   new_action.sa_flags = SA_RESTART;
 #else
   new_action.sa_flags = 0;
@@ -2831,7 +2827,7 @@ sys_sigsetmask (sigset_t new_mask)
 
 #endif /* POSIX_SIGNALS */
 \f
 
 #endif /* POSIX_SIGNALS */
 \f
-#if !defined HAVE_STRSIGNAL && !defined SYS_SIGLIST_DECLARED
+#if !defined HAVE_STRSIGNAL && !HAVE_DECL_SYS_SIGLIST
 static char *my_sys_siglist[NSIG];
 # ifdef sys_siglist
 #  undef sys_siglist
 static char *my_sys_siglist[NSIG];
 # ifdef sys_siglist
 #  undef sys_siglist
@@ -2847,7 +2843,7 @@ init_signals ()
   sigfillset (&full_mask);
 #endif
 
   sigfillset (&full_mask);
 #endif
 
-#if !defined HAVE_STRSIGNAL && !defined SYS_SIGLIST_DECLARED
+#if !defined HAVE_STRSIGNAL && !HAVE_DECL_SYS_SIGLIST
   if (! initialized)
     {
 # ifdef SIGABRT
   if (! initialized)
     {
 # ifdef SIGABRT
@@ -3007,7 +3003,7 @@ init_signals ()
       sys_siglist[SIGXFSZ] = "File size limit exceeded";
 # endif
     }
       sys_siglist[SIGXFSZ] = "File size limit exceeded";
 # endif
     }
-#endif /* !defined HAVE_STRSIGNAL && !defined SYS_SIGLIST_DECLARED */
+#endif /* !defined HAVE_STRSIGNAL && !defined HAVE_DECL_SYS_SIGLIST */
 }
 \f
 #ifndef HAVE_RANDOM
 }
 \f
 #ifndef HAVE_RANDOM
@@ -3219,16 +3215,16 @@ strerror (errnum)
 \f
 int
 emacs_open (path, oflag, mode)
 \f
 int
 emacs_open (path, oflag, mode)
-     char *path;
+     const char *path;
      int oflag, mode;
 {
   register int rtnval;
 
 #ifdef BSD4_1
      int oflag, mode;
 {
   register int rtnval;
 
 #ifdef BSD4_1
-  if (oflag & O_CREAT) 
+  if (oflag & O_CREAT)
     return creat (path, mode);
 #endif
     return creat (path, mode);
 #endif
-  
+
   while ((rtnval = open (path, oflag, mode)) == -1
         && (errno == EINTR));
   return (rtnval);
   while ((rtnval = open (path, oflag, mode)) == -1
         && (errno == EINTR));
   return (rtnval);
@@ -3261,7 +3257,7 @@ emacs_read (fildes, buf, nbyte)
      unsigned int nbyte;
 {
   register int rtnval;
      unsigned int nbyte;
 {
   register int rtnval;
-  
+
   while ((rtnval = read (fildes, buf, nbyte)) == -1
         && (errno == EINTR));
   return (rtnval);
   while ((rtnval = read (fildes, buf, nbyte)) == -1
         && (errno == EINTR));
   return (rtnval);
@@ -3270,7 +3266,7 @@ emacs_read (fildes, buf, nbyte)
 int
 emacs_write (fildes, buf, nbyte)
      int fildes;
 int
 emacs_write (fildes, buf, nbyte)
      int fildes;
-     char *buf;
+     const char *buf;
      unsigned int nbyte;
 {
   register int rtnval, bytes_written;
      unsigned int nbyte;
 {
   register int rtnval, bytes_written;
@@ -3334,7 +3330,10 @@ getwd (pathname)
   BLOCK_INPUT;                 /* getcwd uses malloc */
   spath = npath = getcwd ((char *) 0, MAXPATHLEN);
   if (spath == 0)
   BLOCK_INPUT;                 /* getcwd uses malloc */
   spath = npath = getcwd ((char *) 0, MAXPATHLEN);
   if (spath == 0)
-    return spath;
+    {
+      UNBLOCK_INPUT;
+      return spath;
+    }
   /* On Altos 3068, getcwd can return @hostname/dir, so discard
      up to first slash.  Should be harmless on other systems.  */
   while (*npath && *npath != '/')
   /* On Altos 3068, getcwd can return @hostname/dir, so discard
      up to first slash.  Should be harmless on other systems.  */
   while (*npath && *npath != '/')
@@ -3398,7 +3397,7 @@ dup2 (oldd, newd)
      int newd;
 {
   register int fd, ret;
      int newd;
 {
   register int fd, ret;
-  
+
   emacs_close (newd);
 
 #ifdef F_DUPFD
   emacs_close (newd);
 
 #ifdef F_DUPFD
@@ -3427,7 +3426,7 @@ dup2 (oldd, newd)
 #ifndef VMS
 #ifndef HAVE_GETTIMEOFDAY
 #ifdef HAVE_TIMEVAL
 #ifndef VMS
 #ifndef HAVE_GETTIMEOFDAY
 #ifdef HAVE_TIMEVAL
+
 /* ARGSUSED */
 int
 gettimeofday (tp, tzp)
 /* ARGSUSED */
 int
 gettimeofday (tp, tzp)
@@ -3436,18 +3435,18 @@ gettimeofday (tp, tzp)
 {
   extern long time ();
 
 {
   extern long time ();
 
-  tp->tv_sec = time ((long *)0);    
+  tp->tv_sec = time ((long *)0);
   tp->tv_usec = 0;
   if (tzp != 0)
     tzp->tz_minuteswest = -1;
   return 0;
 }
   tp->tv_usec = 0;
   if (tzp != 0)
     tzp->tz_minuteswest = -1;
   return 0;
 }
+
 #endif
 #endif
 #endif
 #endif /* subprocess && !HAVE_GETTIMEOFDAY && HAVE_TIMEVAL && !VMS */
 #endif
 #endif
 #endif
 #endif /* subprocess && !HAVE_GETTIMEOFDAY && HAVE_TIMEVAL && !VMS */
-  
+
 /*
  *     This function will go away as soon as all the stubs fixed. (fnf)
  */
 /*
  *     This function will go away as soon as all the stubs fixed. (fnf)
  */
@@ -3639,7 +3638,7 @@ readdirver (dirp)
 \f
 int
 set_file_times (filename, atime, mtime)
 \f
 int
 set_file_times (filename, atime, mtime)
-     char *filename;
+     const char *filename;
      EMACS_TIME atime, mtime;
 {
 #ifdef HAVE_UTIMES
      EMACS_TIME atime, mtime;
 {
 #ifdef HAVE_UTIMES
@@ -3728,7 +3727,8 @@ mkdir (dpath, dmode)
       wait_for_termination (cpid);
     }
 
       wait_for_termination (cpid);
     }
 
-  if (synch_process_death != 0 || synch_process_retcode != 0)
+  if (synch_process_death != 0 || synch_process_retcode != 0
+      || synch_process_termsig != 0)
     {
       errno = EIO;             /* We don't know why, but */
       return -1;               /* /bin/mkdir failed */
     {
       errno = EIO;             /* We don't know why, but */
       return -1;               /* /bin/mkdir failed */
@@ -3774,7 +3774,8 @@ rmdir (dpath)
       wait_for_termination (cpid);
     }
 
       wait_for_termination (cpid);
     }
 
-  if (synch_process_death != 0 || synch_process_retcode != 0)
+  if (synch_process_death != 0 || synch_process_retcode != 0
+      || synch_process_termsig != 0)
     {
       errno = EIO;             /* We don't know why, but */
       return -1;               /* /bin/rmdir failed */
     {
       errno = EIO;             /* We don't know why, but */
       return -1;               /* /bin/rmdir failed */
@@ -3814,7 +3815,7 @@ vmserrstr (status)
 
 #ifdef access
 #undef access
 
 #ifdef access
 #undef access
-  
+
 /* The following is necessary because 'access' emulation by VMS C (2.0) does
  * not work correctly.  (It also doesn't work well in version 2.3.)
  */
 /* The following is necessary because 'access' emulation by VMS C (2.0) does
  * not work correctly.  (It also doesn't work well in version 2.3.)
  */
@@ -3855,7 +3856,7 @@ sys_access (path, mode)
    * access can treat the directory like a file.  */
   if (directory_file_name (path, dir_fn))
     path = dir_fn;
    * access can treat the directory like a file.  */
   if (directory_file_name (path, dir_fn))
     path = dir_fn;
-  
+
   if (mode == F_OK)
     return access (path, mode);
   if (user == NULL && (user = (char *) getenv ("USER")) == NULL)
   if (mode == F_OK)
     return access (path, mode);
   if (user == NULL && (user = (char *) getenv ("USER")) == NULL)
@@ -3869,7 +3870,7 @@ sys_access (path, mode)
     static int constant = ACL$C_FILE;
     DESCRIPTOR (path_desc, path);
     DESCRIPTOR (user_desc, user);
     static int constant = ACL$C_FILE;
     DESCRIPTOR (path_desc, path);
     DESCRIPTOR (user_desc, user);
+
     flags = 0;
     acces = 0;
     if ((mode & X_OK) && ((stat = access (path, mode)) < 0 || mode == X_OK))
     flags = 0;
     acces = 0;
     if ((mode & X_OK) && ((stat = access (path, mode)) < 0 || mode == X_OK))
@@ -3934,7 +3935,7 @@ sys_access (filename, type)
     return access (filename, type);
 
   /* Check write protection. */
     return access (filename, type);
 
   /* Check write protection. */
-    
+
 #define CHECKPRIV(bit)    (prvmask.bit)
 #define WRITABLE(field)  (! ((xab.xab$w_pro >> field) & XAB$M_NOWRITE))
 
 #define CHECKPRIV(bit)    (prvmask.bit)
 #define WRITABLE(field)  (! ((xab.xab$w_pro >> field) & XAB$M_NOWRITE))
 
@@ -3996,7 +3997,7 @@ sys_access (filename, type)
 }
 #endif /* not VMS4_4 */
 #endif /* access */
 }
 #endif /* not VMS4_4 */
 #endif /* access */
-  
+
 static char vtbuf[NAM$C_MAXRSS+1];
 
 /* translate a vms file spec to a unix path */
 static char vtbuf[NAM$C_MAXRSS+1];
 
 /* translate a vms file spec to a unix path */
@@ -4037,7 +4038,7 @@ sys_translate_vms (vfile)
            *targ++ = '.';
            *targ++ = '.';
            break;
            *targ++ = '.';
            *targ++ = '.';
            break;
-           
+
          default:
            *targ++ = *vfile;
            break;
          default:
            *targ++ = *vfile;
            break;
@@ -4130,7 +4131,7 @@ sys_translate_unix (ufile)
       ufile++;
     }
   *targ = '\0';
       ufile++;
     }
   *targ = '\0';
-  
+
   return utbuf;
 }
 
   return utbuf;
 }
 
@@ -4152,7 +4153,7 @@ getwd (pathname)
     }
   strcpy (pathname, ptr);
   xfree (ptr);
     }
   strcpy (pathname, ptr);
   xfree (ptr);
-  
+
  return pathname;
 }
 
  return pathname;
 }
 
@@ -4489,7 +4490,7 @@ sys_fwrite (ptr, size, num, fp)
  * when this is not the desired behavior, for instance, when writing an
  * auto save file (you only want one version), or when you don't have
  * write permission in the directory containing the file (but the file
  * when this is not the desired behavior, for instance, when writing an
  * auto save file (you only want one version), or when you don't have
  * write permission in the directory containing the file (but the file
- * itself is writable).  Hence this routine, which is equivalent to 
+ * itself is writable).  Hence this routine, which is equivalent to
  * "close (creat (fn, 0));" on Unix if fn already exists.
  */
 int
  * "close (creat (fn, 0));" on Unix if fn already exists.
  */
 int
@@ -4546,7 +4547,7 @@ get_uaf_name (uname)
   register status;
   struct FAB uaf_fab;
   struct RAB uaf_rab;
   register status;
   struct FAB uaf_fab;
   struct RAB uaf_rab;
-  
+
   uaf_fab = cc$rms_fab;
   uaf_rab = cc$rms_rab;
   /* initialize fab fields */
   uaf_fab = cc$rms_fab;
   uaf_rab = cc$rms_rab;
   /* initialize fab fields */
@@ -4610,7 +4611,7 @@ get_uaf_uic (uic)
   register status;
   struct FAB uaf_fab;
   struct RAB uaf_rab;
   register status;
   struct FAB uaf_fab;
   struct RAB uaf_rab;
-  
+
   uaf_fab = cc$rms_fab;
   uaf_rab = cc$rms_rab;
   /* initialize fab fields */
   uaf_fab = cc$rms_fab;
   uaf_rab = cc$rms_rab;
   /* initialize fab fields */
@@ -4903,7 +4904,7 @@ rename (from, to)
    bits).  To maintain portability, the VMS implementation of `chmod' wires
    the W and D bits together.  */
 
    bits).  To maintain portability, the VMS implementation of `chmod' wires
    the W and D bits together.  */
 
+
 static struct fibdef fib;      /* We need this initialized to zero */
 char vms_file_written[NAM$C_MAXRSS];
 
 static struct fibdef fib;      /* We need this initialized to zero */
 char vms_file_written[NAM$C_MAXRSS];
 
@@ -5071,7 +5072,7 @@ hft_init ()
 
   /* If we're not on an HFT we shouldn't do any of this.  We determine
      if we are on an HFT by trying to get an HFT error code.  If this
 
   /* If we're not on an HFT we shouldn't do any of this.  We determine
      if we are on an HFT by trying to get an HFT error code.  If this
-     call fails, we're not on an HFT. */ 
+     call fails, we're not on an HFT. */
 #ifdef IBMR2AIX
   if (ioctl (0, HFQERROR, &junk) < 0)
     return;
 #ifdef IBMR2AIX
   if (ioctl (0, HFQERROR, &junk) < 0)
     return;
@@ -5285,3 +5286,5 @@ strsignal (code)
 }
 #endif /* HAVE_STRSIGNAL */
 
 }
 #endif /* HAVE_STRSIGNAL */
 
+/* arch-tag: edb43589-4e09-4544-b325-978b5b121dcf
+   (do not change this comment) */