Comment change.
[bpt/emacs.git] / src / emacs.c
index bd5e175..f76d224 100644 (file)
@@ -53,6 +53,10 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #define O_RDWR 2
 #endif
 
+extern void malloc_warning ();
+extern char *index ();
+extern char *strerror ();
+
 /* Command line args from shell, as list of strings */
 Lisp_Object Vcommand_line_args;
 
@@ -63,6 +67,10 @@ Lisp_Object Vinvocation_name;
 /* The directory name from which Emacs was invoked.  */
 Lisp_Object Vinvocation_directory;
 
+/* The directory name in which to find subdirs such as lisp and etc.
+   nil means get them only from PATH_LOADSEARCH.  */
+Lisp_Object Vinstallation_directory;
+
 /* Hook run by `kill-emacs' before it does really anything.  */
 Lisp_Object Vkill_emacs_hook;
 
@@ -159,7 +167,7 @@ fatal_error_signal (sig)
 
 #ifdef SIGDANGER
 
-/* Handle bus errors, illegal instruction, etc. */
+/* Handler for SIGDANGER.  */
 SIGTYPE
 memory_warning_signal (sig)
      int sig;
@@ -179,6 +187,7 @@ init_cmdargs (argc, argv, skip_args)
      int skip_args;
 {
   register int i;
+  Lisp_Object name, dir;
 
   Vinvocation_name = Ffile_name_nondirectory (build_string (argv[0]));
   Vinvocation_directory = Ffile_name_directory (build_string (argv[0]));
@@ -193,6 +202,81 @@ init_cmdargs (argc, argv, skip_args)
        Vinvocation_directory = Ffile_name_directory (found);
     }
 
+  Vinstallation_directory = Qnil;
+
+  if (!NILP (Vinvocation_directory))
+    {
+      dir = Vinvocation_directory;
+      name = Fexpand_file_name (Vinvocation_name, dir);
+      while (1)
+       {
+         Lisp_Object tem, lisp_exists, lib_src_exists;
+         Lisp_Object etc_exists, info_exists;
+
+         /* See if dir contains subdirs for use by Emacs.  */
+         tem = Fexpand_file_name (build_string ("lisp"), dir);
+         lisp_exists = Ffile_exists_p (tem);
+         if (!NILP (lisp_exists))
+           {
+             tem = Fexpand_file_name (build_string ("lib-src"), dir);
+             lib_src_exists = Ffile_exists_p (tem);
+             if (!NILP (lib_src_exists))
+               {
+                 tem = Fexpand_file_name (build_string ("etc"), dir);
+                 etc_exists = Ffile_exists_p (tem);
+                 if (!NILP (etc_exists))
+                   {
+                     tem = Fexpand_file_name (build_string ("info"), dir);
+                     info_exists = Ffile_exists_p (tem);
+                     if (!NILP (info_exists))
+                       {
+                         Vinstallation_directory
+                           = Ffile_name_as_directory (dir);
+                         break;
+                       }
+                   }
+               }
+           }
+
+         /* See if dir's parent contains those subdirs.  */
+         tem = Fexpand_file_name (build_string ("../lisp"), dir);
+         lisp_exists = Ffile_exists_p (tem);
+         if (!NILP (lisp_exists))
+           {
+             tem = Fexpand_file_name (build_string ("../lib-src"), dir);
+             lib_src_exists = Ffile_exists_p (tem);
+             if (!NILP (lib_src_exists))
+               {
+                 tem = Fexpand_file_name (build_string ("../etc"), dir);
+                 etc_exists = Ffile_exists_p (tem);
+                 if (!NILP (etc_exists))
+                   {
+                     tem = Fexpand_file_name (build_string ("../info"), dir);
+                     info_exists = Ffile_exists_p (tem);
+                     if (!NILP (info_exists))
+                       {
+                         tem = Fexpand_file_name (build_string (".."), dir);
+                         Vinstallation_directory
+                           = Ffile_name_as_directory (tem);
+                         break;
+                       }
+                   }
+               }
+           }
+
+         /* If the Emacs executable is actually a link,
+            next try the dir that the link points into.  */
+         tem = Ffile_symlink_p (name);
+         if (!NILP (tem))
+           {
+             name = tem;
+             dir = Ffile_name_directory (name);
+           }
+         else
+           break;
+       }
+    }
+
   Vcommand_line_args = Qnil;
 
   for (i = argc - 1; i >= 0; i--)
@@ -260,8 +344,6 @@ main (argc, argv, envp)
   int skip_args = 0;
   extern int errno;
   extern sys_nerr;
-  extern char *strerror ();
-  extern void malloc_warning ();
 
 /* Map in shared memory, if we are using that.  */
 #ifdef HAVE_SHM
@@ -340,7 +422,7 @@ main (argc, argv, envp)
 
   clearerr (stdin);
 
-#ifdef BSD
+#ifdef BSD_PGRPS
   if (initialized)
     {
       inherited_pgroup = EMACS_GETPGRP (0);
@@ -480,17 +562,8 @@ main (argc, argv, envp)
 #endif
 
 #ifdef AIX
-      signal (20, fatal_error_signal);
-      signal (21, fatal_error_signal);
-      signal (22, fatal_error_signal);
-      signal (24, fatal_error_signal);
-#if 0 /* mvn@library.ucla.edu says these are SIGIO on AIX 3.2.4.  */
-      signal (23, fatal_error_signal);
-#ifdef SIGIO
-      signal (SIGAIO, fatal_error_signal);
-      signal (SIGPTY, fatal_error_signal);
-#endif
-#endif
+/* 20 is SIGCHLD, 21 is SIGTTIN, 22 is SIGTTOU.  */
+      signal (SIGXCPU, fatal_error_signal);
 #ifndef _I386
       signal (SIGIOINT, fatal_error_signal);
 #endif
@@ -810,7 +883,6 @@ This function exists on systems that use HAVE_SHM.")
 {
   extern int my_edata;
   Lisp_Object tem;
-  extern void malloc_warning ();
 
   CHECK_STRING (intoname, 0);
   intoname = Fexpand_file_name (intoname, Qnil);
@@ -846,7 +918,6 @@ and announce itself normally when it is run.")
 {
   extern int my_edata;
   Lisp_Object tem;
-  extern void malloc_warning ();
 
   CHECK_STRING (intoname, 0);
   intoname = Fexpand_file_name (intoname, Qnil);
@@ -891,7 +962,6 @@ decode_env_path (evarname, defalt)
      char *evarname, *defalt;
 {
   register char *path, *p;
-  extern char *index ();
 
   Lisp_Object lpath;
 
@@ -962,6 +1032,8 @@ and only if the Emacs executable is installed with setuid to permit\n\
 it to change priority.  (Emacs sets its uid back to the real uid.)");
   emacs_priority = 0;
 
+  staticpro (&Vinstallation_directory);
+  Vinstallation_directory = Qnil;
   staticpro (&Vinvocation_name);
   Vinvocation_name = Qnil;
   staticpro (&Vinvocation_directory);