Changes for Irix 4.0, tested this time:
[bpt/emacs.git] / src / emacs.c
index c5b6953..96040e1 100644 (file)
@@ -1,5 +1,5 @@
 /* Fully extensible Emacs, running on Unix, intended for GNU.
-   Copyright (C) 1985, 1986, 1987, 1992, 1993 Free Software Foundation, Inc.
+   Copyright (C) 1985, 1986, 1987, 1993 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -35,10 +35,6 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #include <sys/ioctl.h>
 #endif
 
-#ifdef HAVE_TERMIOS
-#include <termios.h>
-#endif
-
 #ifdef APOLLO
 #ifndef APOLLO_SR10
 #include <default_acl.h>
@@ -85,6 +81,11 @@ int inhibit_window_system;
    priority; Those functions have their own extern declaration.  */
 int emacs_priority;
 
+#ifdef BSD
+/* See sysdep.c.  */
+extern int inherited_pgroup;
+#endif
+
 #ifdef HAVE_X_WINDOWS
 /* If non-zero, -d was specified, meaning we're using some window system. */
 int display_arg;
@@ -134,7 +135,7 @@ fatal_error_signal (sig)
     {
       fatal_error_in_progress = 1;
 
-      shut_down_emacs (sig);
+      shut_down_emacs (sig, 0, Qnil);
     }
 
 #ifdef VMS
@@ -159,7 +160,7 @@ init_cmdargs (argc, argv, skip_args)
 {
   register int i;
 
-  Vinvocation_name = Ffile_name_nondirectory (argv[0]);
+  Vinvocation_name = Ffile_name_nondirectory (build_string (argv[0]));
 
   Vcommand_line_args = Qnil;
 
@@ -237,7 +238,7 @@ main (argc, argv, envp)
 #endif
 
 #ifdef NeXT
-  static int malloc_cookie;
+  extern int malloc_cookie;
 
   /* This helps out unexnext.c.  */
   if (initialized)
@@ -254,7 +255,7 @@ main (argc, argv, envp)
     int i;
 
     for (i = 1; (i < argc && ! display_arg); i++)
-      if (!strcmp (argv[i], "-d"))
+      if (!strcmp (argv[i], "-d") || !strcmp (argv[i], "-display"))
        display_arg = 1;
   }
 #endif
@@ -296,10 +297,15 @@ main (argc, argv, envp)
 #endif
 
   clearerr (stdin);
+
 #ifdef BSD
-  setpgrp (0, getpid ());
+  {
+    inherited_pgroup = getpgrp (0);
+    setpgrp (0, getpid ());
+  }
 #endif
 
+
 #ifdef APOLLO
 #ifndef APOLLO_SR10
   /* If USE_DOMAIN_ACLS environment variable exists,
@@ -311,7 +317,14 @@ main (argc, argv, envp)
 
 #ifndef SYSTEM_MALLOC
   if (! initialized)
-    memory_warnings (0, malloc_warning);
+    {
+      /* Arrange to get warning messages as memory fills up.  */
+      memory_warnings (0, malloc_warning);
+
+      /* Arrange to disable interrupt input while malloc and friends are
+        running.  */
+      uninterrupt_malloc ();
+    }
 #endif /* not SYSTEM_MALLOC */
 
 #ifdef PRIO_PROCESS
@@ -320,11 +333,6 @@ main (argc, argv, envp)
   setuid (getuid ());
 #endif /* PRIO_PROCESS */
 
-#ifdef BSD
-  /* interrupt_input has trouble if we aren't in a separate process group.  */
-  setpgrp (getpid (), getpid ());
-#endif
-
   inhibit_window_system = 0;
 
   /* Handle the -t switch, which specifies filename to use as terminal */
@@ -400,9 +408,13 @@ main (argc, argv, envp)
       signal (SIGEMT, fatal_error_signal);
 #endif
       signal (SIGFPE, fatal_error_signal);
+#ifdef SIGBUS
       signal (SIGBUS, fatal_error_signal);
+#endif
       signal (SIGSEGV, fatal_error_signal);
+#ifdef SIGSYS
       signal (SIGSYS, fatal_error_signal);
+#endif
       signal (SIGTERM, fatal_error_signal);
 #ifdef SIGXCPU
       signal (SIGXCPU, fatal_error_signal);
@@ -422,7 +434,9 @@ main (argc, argv, envp)
       signal (SIGAIO, fatal_error_signal);
       signal (SIGPTY, fatal_error_signal);
 #endif
+#ifndef _I386
       signal (SIGIOINT, fatal_error_signal);
+#endif
       signal (SIGGRANT, fatal_error_signal);
       signal (SIGRETRACT, fatal_error_signal);
       signal (SIGSOUND, fatal_error_signal);
@@ -547,6 +561,7 @@ main (argc, argv, envp)
 #ifdef HAVE_X_WINDOWS
       syms_of_xterm ();
       syms_of_xfns ();
+      syms_of_xfaces ();
 #ifdef HAVE_X11
       syms_of_xselect ();
 #endif
@@ -626,11 +641,6 @@ all of which are called before Emacs is actually killed.")
   if (!NILP (Vrun_hooks) && !noninteractive)
     call1 (Vrun_hooks, intern ("kill-emacs-hook"));
 
-#ifdef HAVE_X_WINDOWS
-  if (!noninteractive && EQ (Vwindow_system, intern ("x")))
-    Fx_close_current_connection ();
-#endif /* HAVE_X_WINDOWS */
-
   UNGCPRO;
 
 /* Is it really necessary to do this deassign
@@ -638,9 +648,8 @@ all of which are called before Emacs is actually killed.")
 /* #ifdef VMS
   stop_vms_input ();
  #endif  */
-  stuff_buffered_input (arg);
 
-  shut_down_emacs (0);
+  shut_down_emacs (0, 0);
 
   exit ((XTYPE (arg) == Lisp_Int) ? XINT (arg)
 #ifdef VMS
@@ -663,16 +672,23 @@ all of which are called before Emacs is actually killed.")
 
    This is called by fatal signal handlers, X protocol error handlers,
    and Fkill_emacs.  */
+
 void
-shut_down_emacs (sig)
-     int sig;
+shut_down_emacs (sig, no_x, stuff)
+     int sig, no_x;
+     Lisp_Object stuff;
 {
   /* If we are controlling the terminal, reset terminal modes */
 #ifdef EMACS_HAVE_TTY_PGRP
   {
+#ifdef USG
+    int pgrp = getpgrp ();
+#else
+    int pgrp = getpgrp (0);
+#endif
     int tpgrp;
     if (EMACS_GET_TTY_PGRP (0, &tpgrp) != -1
-       && tpgrp == getpgrp (0))
+       && tpgrp == pgrp)
       {
        fflush (stdout);
        reset_sys_modes ();
@@ -685,6 +701,8 @@ shut_down_emacs (sig)
   reset_sys_modes ();
 #endif
 
+  stuff_buffered_input (stuff);
+
   kill_buffer_processes (Qnil);
   Fdo_auto_save (Qt, Qnil);
 
@@ -696,6 +714,11 @@ shut_down_emacs (sig)
   kill_vms_processes ();
 #endif
 
+#ifdef HAVE_X_WINDOWS
+  if (!noninteractive && EQ (Vwindow_system, intern ("x")) && ! no_x)
+    Fx_close_current_connection ();
+#endif /* HAVE_X_WINDOWS */
+
 #ifdef SIGIO
   /* There is a tendency for a SIGIO signal to arrive within exit,
      and cause a SIGHUP because the input descriptor is already closed.  */
@@ -792,9 +815,7 @@ and announce itself normally when it is run.")
 
 #endif /* not CANNOT_DUMP */
 \f
-#ifdef VMS
-#define SEPCHAR ','
-#else
+#ifndef SEPCHAR
 #define SEPCHAR ':'
 #endif
 
@@ -833,10 +854,12 @@ decode_env_path (evarname, defalt)
 
 syms_of_emacs ()
 {
+#ifndef CANNOT_DUMP
 #ifdef HAVE_SHM
   defsubr (&Sdump_emacs_data);
 #else
   defsubr (&Sdump_emacs);
+#endif
 #endif
 
   defsubr (&Skill_emacs);
@@ -857,7 +880,7 @@ syms_of_emacs ()
     "Hook to be run whenever kill-emacs is called.\n\
 Since kill-emacs may be invoked when the terminal is disconnected (or\n\
 in other similar situations), functions placed on this hook should not\n\
-not expect to be able to interact with the user.");
+expect to be able to interact with the user.");
   Vkill_emacs_hook = Qnil;
 
   DEFVAR_INT ("emacs-priority", &emacs_priority,