*** empty log message ***
[bpt/emacs.git] / src / emacs.c
index cbdc2a2..df698ee 100644 (file)
@@ -1,5 +1,5 @@
 /* Fully extensible Emacs, running on Unix, intended for GNU.
-   Copyright (C) 1985, 1986, 1987 Free Software Foundation, Inc.
+   Copyright (C) 1985, 1986, 1987, 1992 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -39,16 +39,21 @@ 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>
 #endif
 #endif
 
-#undef NULL
 #include "lisp.h"
 #include "commands.h"
 
+#include "systerm.h"
+
 #ifndef O_RDWR
 #define O_RDWR 2
 #endif
@@ -58,6 +63,9 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 /* Command line args from shell, as list of strings */
 Lisp_Object Vcommand_line_args;
 
+/* Hook run by `kill-emacs' before it does really anything.  */
+Lisp_Object Vkill_emacs_hook;
+
 /* Set nonzero after Emacs has started up the first time.
   Prevents reinitialization of the Lisp world and keymaps
   on subsequent starts.  */
@@ -107,13 +115,10 @@ int fatal_error_code;
 int fatal_error_in_progress;
 
 /* Handle bus errors, illegal instruction, etc. */
+SIGTYPE
 fatal_error_signal (sig)
      int sig;
 {
-#ifdef BSD
-  int tpgrp;
-#endif /* BSD */
-
   fatal_error_code = sig;
   signal (sig, SIG_DFL);
 
@@ -124,20 +129,21 @@ fatal_error_signal (sig)
   fatal_error_in_progress = 1;
 
   /* If we are controlling the terminal, reset terminal modes */
-#ifdef BSD
-  if (ioctl(0, TIOCGPGRP, &tpgrp) == 0
-      && tpgrp == getpgrp (0))
-#endif /* BSD */
-    {
-      reset_sys_modes ();
-      if (sig != SIGTERM)
-       fprintf (stderr, "Fatal error (%d).", sig);
-    }
+#ifdef EMACS_HAVE_TTY_PGRP
+  {
+    int tpgrp;
+    if (EMACS_GET_TTY_PGRP (0, &tpgrp) != -1
+       && tpgrp == getpgrp (0))
+      {
+       reset_sys_modes ();
+       if (sig != SIGTERM)
+         fprintf (stderr, "Fatal error (%d).", sig);
+      }
+  }
+#endif /* uses pgrp */
 
   /* Clean up */
-#ifdef subprocesses
   kill_buffer_processes (Qnil);
-#endif
   Fdo_auto_save (Qt, Qnil);
 
 #ifdef CLASH_DETECTION
@@ -291,7 +297,7 @@ main (argc, argv, envp)
 
   inhibit_window_system = 0;
 
-/* Handle the -t switch, which specifies filename to use as terminal */
+  /* Handle the -t switch, which specifies filename to use as terminal */
   if (skip_args + 2 < argc && !strcmp (argv[skip_args + 1], "-t"))
     {
       int result;
@@ -410,9 +416,6 @@ main (argc, argv, envp)
     }
 
   init_alloc ();
-#ifdef MAINTAIN_ENVIRONMENT
-  init_environ ();
-#endif
   init_eval ();
   init_data ();
   init_lread ();
@@ -441,9 +444,10 @@ main (argc, argv, envp)
 #ifdef VMS
   init_vmsfns ();
 #endif /* VMS */
-#ifdef subprocesses
   init_process ();
-#endif /* subprocesses */
+#ifdef CLASH_DETECTION
+  init_filelock ();
+#endif /* CLASH_DETECTION */
 
 /* Intern the names of all standard functions and variables; define standard keys */
 
@@ -454,9 +458,6 @@ main (argc, argv, envp)
         for the sake of symbols like error-message */
       syms_of_data ();
       syms_of_alloc ();
-#ifdef MAINTAIN_ENVIRONMENT
-      syms_of_environ ();
-#endif /* MAINTAIN_ENVIRONMENT */
       syms_of_lread ();
       syms_of_print ();
       syms_of_eval ();
@@ -491,9 +492,7 @@ main (argc, argv, envp)
       syms_of_marker ();
       syms_of_minibuf ();
       syms_of_mocklisp ();
-#ifdef subprocesses
       syms_of_process ();
-#endif /* subprocesses */
       syms_of_search ();
 #ifdef MULTI_SCREEN
       syms_of_screen ();
@@ -506,7 +505,11 @@ main (argc, argv, envp)
       syms_of_window ();
       syms_of_xdisp ();
 #ifdef HAVE_X_WINDOWS
+      syms_of_xterm ();
       syms_of_xfns ();
+#ifdef HAVE_X11
+      syms_of_xselect ();
+#endif
 #ifdef HAVE_X_MENU
       syms_of_xmenu ();
 #endif /* HAVE_X_MENU */
@@ -570,12 +573,10 @@ all of which are called before Emacs is actually killed.")
   if (feof (stdin))
     arg = Qt;
 
-  if (!NULL (Vrun_hooks) && !noninteractive)
+  if (!NILP (Vrun_hooks) && !noninteractive)
     call1 (Vrun_hooks, intern ("kill-emacs-hook"));
 
-#ifdef subprocesses
   kill_buffer_processes (Qnil);
-#endif /* subprocesses */
 
 #ifdef VMS
   kill_vms_processes ();
@@ -673,7 +674,7 @@ and announce itself normally when it is run.")
 
   CHECK_STRING (intoname, 0);
   intoname = Fexpand_file_name (intoname, Qnil);
-  if (!NULL (symname))
+  if (!NILP (symname))
     {
       CHECK_STRING (symname, 0);
       if (XSTRING (symname)->size)
@@ -693,7 +694,7 @@ and announce itself normally when it is run.")
   malloc_init (&my_edata, malloc_warning);
 #endif
   unexec (XSTRING (intoname)->data,
-         !NULL (symname) ? XSTRING (symname)->data : 0, &my_edata, 0, 0);
+         !NILP (symname) ? XSTRING (symname)->data : 0, &my_edata, 0, 0);
 #endif /* not VMS */
 
   Vpurify_flag = tem;
@@ -720,7 +721,13 @@ decode_env_path (evarname, defalt)
 
   Lisp_Object lpath;
 
-  path = (char *) egetenv (evarname);
+  /* It's okay to use getenv here, because this function is only used
+     to initialize variables when Emacs starts up, and isn't called
+     after that.  */
+  if (evarname != 0)
+    path = (char *) getenv (evarname);
+  else
+    path = 0;
   if (!path)
     path = defalt;
   lpath = Qnil;
@@ -757,4 +764,9 @@ syms_of_emacs ()
 
   DEFVAR_BOOL ("noninteractive", &noninteractive1,
     "Non-nil means Emacs is running without interactive terminal.");
+
+  Vkill_emacs_hook = Qnil;
+
+  DEFVAR_LISP ("kill-emacs-hook", &Vkill_emacs_hook,
+    "Hook to be run whenever kill-emacs is called.");
 }