(displaying-byte-compile-warnings): Show
[bpt/emacs.git] / src / emacs.c
index 7349a21..bf3e46c 100644 (file)
@@ -81,6 +81,16 @@ Lisp_Object Vkill_emacs_hook;
   on subsequent starts.  */
 int initialized;
 
+#ifdef DOUG_LEA_MALLOC
+/* Preserves a pointer to the memory allocated that copies that
+   static data inside glibc's malloc.  */
+void *malloc_state_ptr;
+/* From glibc, a routine that returns a copy of the malloc internal state.  */
+extern void *malloc_get_state ();
+/* From glibc, a routine that overwrites the malloc internal state.  */
+extern void malloc_set_state ();
+#endif
+
 /* Variable whose value is symbol giving operating system type.  */
 Lisp_Object Vsystem_type;
 
@@ -271,11 +281,15 @@ init_cmdargs (argc, argv, skip_args)
          tem = Fexpand_file_name (build_string ("lib-src"), dir);
          lib_src_exists = Ffile_exists_p (tem);
 
+#ifdef MSDOS
          /* MSDOS installations frequently remove lib-src, but we still
             must set installation-directory, or else info won't find
             its files (it uses the value of installation-directory).  */
          tem = Fexpand_file_name (build_string ("info"), dir);
          info_exists = Ffile_exists_p (tem);
+#else
+         info_exists = Qnil;
+#endif
 
          if (!NILP (lib_src_exists) || !NILP (info_exists))
            {
@@ -293,8 +307,14 @@ init_cmdargs (argc, argv, skip_args)
          tem = Fexpand_file_name (build_string ("../lib-src"), dir);
          lib_src_exists = Ffile_exists_p (tem);
 
+
+#ifdef MSDOS
+         /* See the MSDOS commentary above.  */
          tem = Fexpand_file_name (build_string ("../info"), dir);
          info_exists = Ffile_exists_p (tem);
+#else
+         info_exists = Qnil;
+#endif
 
          if (!NILP (lib_src_exists) || !NILP (info_exists))
            {
@@ -476,6 +496,20 @@ main (argc, argv, envp)
   __sbrk (1);
 #endif
 
+#ifdef DOUG_LEA_MALLOC
+  if (initialized)
+    {
+      malloc_set_state (malloc_state_ptr);
+      free (malloc_state_ptr);
+      r_alloc_reinit ();
+    }
+#endif
+
+#ifdef RUN_TIME_REMAP
+  if (initialized)
+    run_time_remap (argv[0]);
+#endif
+
   sort_args (argc, argv);
 
   if (argmatch (argv, argc, "-version", "--version", 3, NULL, &skip_args))
@@ -490,7 +524,7 @@ main (argc, argv, envp)
       else
        {
          printf ("GNU Emacs %s\n", XSTRING (tem)->data);
-         printf ("Copyright (C) 1996 Free Software Foundation, Inc.\n");
+         printf ("Copyright (C) 1997 Free Software Foundation, Inc.\n");
          printf ("GNU Emacs comes with ABSOLUTELY NO WARRANTY.\n");
          printf ("You may redistribute copies of Emacs\n");
          printf ("under the terms of the GNU General Public License.\n");
@@ -549,23 +583,43 @@ main (argc, argv, envp)
 #endif /* LINK_CRTL_SHARE */
 #endif /* VMS */
 
-#ifdef HAVE_SETRLIMIT
-  /* Extend the stack space available.  */
-  if (!getrlimit (RLIMIT_STACK, &rlim))
+#if defined (HAVE_SETRLIMIT) && defined (RLIMIT_STACK)
+  /* Extend the stack space available.
+     Don't do that if dumping, since some systems (e.g. DJGPP)
+     might define a smaller stack limit at that time.  */
+  if (1
+#ifndef CANNOT_DUMP
+      && (!noninteractive || initialized)
+#endif
+      && !getrlimit (RLIMIT_STACK, &rlim))
     {
-      rlim.rlim_cur = rlim.rlim_max;
+      long newlim;
+      extern int re_max_failures;
+      /* Approximate the amount regex.c needs, plus some more.  */
+      newlim = re_max_failures * 2 * 20 * sizeof (char *);
+#ifdef __NetBSD__
+      /* NetBSD (at least NetBSD 1.2G and former) has a bug in its
+       stack allocation routine for new process that the allocation
+       fails if stack limit is not on page boundary.  So, round up the
+       new limit to page boundary.  */
+      newlim = (newlim + getpagesize () - 1) / getpagesize () * getpagesize();
+#endif
+      if (newlim > rlim.rlim_max)
+       {
+         newlim = rlim.rlim_max;
+         /* Don't let regex.c overflow the stack.  */
+         re_max_failures = newlim / (2 * 20 * sizeof (char *));
+       }
+      if (rlim.rlim_cur < newlim)
+       rlim.rlim_cur = newlim;
+
       setrlimit (RLIMIT_STACK, &rlim);
     }
-#endif
+#endif /* HAVE_SETRLIMIT and RLIMIT_STACK */
 
   /* Record (approximately) where the stack begins.  */
   stack_bottom = &stack_bottom_variable;
 
-#ifdef RUN_TIME_REMAP
-  if (initialized)
-    run_time_remap (argv[0]);
-#endif
-
 #ifdef USG_SHARED_LIBRARIES
   if (bss_end)
     brk ((void *)bss_end);
@@ -662,7 +716,7 @@ Usage: %s [-t term] [--terminal term]  [-nw] [--no-windows]  [--batch]\n\
       [-f func] [--funcall func]  [-l file] [--load file]  [--insert file]\n\
       [+linenum] file-to-visit  [--kill]\n\
 Report bugs to bug-gnu-emacs@prep.ai.mit.edu.  First, please see\n\
-the Bugs section of the Emacs manual or the file BUGS.", argv[0]);
+the Bugs section of the Emacs manual or the file BUGS.\n", argv[0]);
       exit (0);
     }
 
@@ -828,7 +882,10 @@ the Bugs section of the Emacs manual or the file BUGS.", argv[0]);
       init_alloc_once ();
       init_obarray ();
       init_eval_once ();
+      init_charset_once ();
+      init_coding_once ();
       init_syntax_once ();     /* Create standard syntax table.  */
+      init_category_once ();   /* Create standard category table.  */
                      /* Must be done before init_buffer */
       init_casetab_once ();
       init_buffer_once ();     /* Create buffer table and some buffers */
@@ -909,9 +966,6 @@ the Bugs section of the Emacs manual or the file BUGS.", argv[0]);
   init_vmsfns ();
 #endif /* VMS */
   init_process ();
-#ifdef CLASH_DETECTION
-  init_filelock ();
-#endif /* CLASH_DETECTION */
 
 /* Intern the names of all standard functions and variables; define standard keys */
 
@@ -935,6 +989,9 @@ the Bugs section of the Emacs manual or the file BUGS.", argv[0]);
       syms_of_casefiddle ();
       syms_of_casetab ();
       syms_of_callproc ();
+      syms_of_category ();
+      syms_of_ccl ();
+      syms_of_charset ();
       syms_of_cmds ();
 #ifndef NO_DIR_LIBRARY
       syms_of_dired ();
@@ -944,6 +1001,7 @@ the Bugs section of the Emacs manual or the file BUGS.", argv[0]);
       syms_of_editfns ();
       syms_of_emacs ();
       syms_of_fileio ();
+      syms_of_coding ();       /* This should be after syms_of_fileio.  */
 #ifdef CLASH_DETECTION
       syms_of_filelock ();
 #endif /* CLASH_DETECTION */
@@ -975,17 +1033,14 @@ the Bugs section of the Emacs manual or the file BUGS.", argv[0]);
 #ifdef HAVE_X_WINDOWS
       syms_of_xterm ();
       syms_of_xfns ();
-      syms_of_xfaces ();
+      syms_of_fontset ();
 #ifdef HAVE_X11
       syms_of_xselect ();
 #endif
 #endif /* HAVE_X_WINDOWS */
 
-#if defined (MSDOS) && !defined (HAVE_X_WINDOWS)
-      syms_of_xfaces ();
-#endif
-
 #ifndef HAVE_NTGUI
+      syms_of_xfaces ();
       syms_of_xmenu ();
 #endif
 
@@ -1051,6 +1106,29 @@ the Bugs section of the Emacs manual or the file BUGS.", argv[0]);
 #endif
     }
 
+  /* Gerd Moellmann <gerd@acm.org> says this makes profiling work on
+     FreeBSD.  It might work on some other systems too.
+     Give it a try and tell me if it works on your system.  */
+#ifdef __FreeBSD__
+#ifdef PROFILING
+  if (initialized)
+    {
+      extern void _mcleanup ();       
+      extern char etext;
+      extern Lisp_Object Fredraw_frame ();
+      atexit (_mcleanup);
+      /* This uses Fredraw_frame because that function
+        comes first in the Emacs executable.
+        It might be better to use something that gives
+        the start of the text segment, but start_of_text
+        is not defined on all systems now.  */
+      monstartup (Fredraw_frame, &etext);
+    }
+  else
+    moncontrol (0);
+#endif
+#endif
+
   initialized = 1;
 
 #ifdef LOCALTIME_CACHE
@@ -1176,7 +1254,7 @@ sort_args (argc, argv)
 
          /* If we have found "--", don't consider
             any more arguments as options.  */
-         if (argv[from][1] == '-')
+         if (argv[from][1] == '-' && argv[from][2] == 0)
            {
              /* Leave the "--", and everything following it, at the end.  */
              for (; from < argc; from++)
@@ -1276,6 +1354,10 @@ sort_args (argc, argv)
     }
 
   bcopy (new, argv, sizeof (char *) * argc);
+
+  free (options);
+  free (new);
+  free (priority);
 }
 \f
 DEFUN ("kill-emacs", Fkill_emacs, Skill_emacs, 0, 1, "P",
@@ -1443,14 +1525,23 @@ DEFUN ("dump-emacs", Fdump_emacs, Sdump_emacs, 2, 2, 0,
 Take symbols from SYMFILE (presumably the file you executed to run Emacs).\n\
 This is used in the file `loadup.el' when building Emacs.\n\
 \n\
-Bind `command-line-processed' to nil before dumping,\n\
-if you want the dumped Emacs to process its command line\n\
-and announce itself normally when it is run.")
+You must run Emacs in batch mode in order to dump it.")
   (filename, symfile)
      Lisp_Object filename, symfile;
 {
   extern char my_edata[];
   Lisp_Object tem;
+  Lisp_Object symbol;
+  int count = specpdl_ptr - specpdl;
+
+  if (! noninteractive)
+    error ("Dumping Emacs works only in batch mode");
+
+  /* Bind `command-line-processed' to nil before dumping,
+     so that the dumped Emacs will process its command line
+     and set up to work with X windows if appropriate.  */
+  symbol = intern ("command-line-process");
+  specbind (symbol, Qnil);
 
   CHECK_STRING (filename, 0);
   filename = Fexpand_file_name (filename, Qnil);
@@ -1484,14 +1575,20 @@ and announce itself normally when it is run.")
      Meanwhile, my_edata is not valid on Windows.  */
   memory_warnings (my_edata, malloc_warning);
 #endif /* not WINDOWSNT */
+#endif
+#ifdef DOUG_LEA_MALLOC
+  malloc_state_ptr = malloc_get_state ();
 #endif
   unexec (XSTRING (filename)->data,
          !NILP (symfile) ? XSTRING (symfile)->data : 0, my_edata, 0, 0);
+#ifdef DOUG_LEA_MALLOC
+  free (malloc_state_ptr);
+#endif
 #endif /* not VMS */
 
   Vpurify_flag = tem;
 
-  return Qnil;
+  return unbind_to (count, Qnil);
 }
 
 #endif /* not HAVE_SHM */
@@ -1518,6 +1615,20 @@ decode_env_path (evarname, defalt)
     path = 0;
   if (!path)
     path = defalt;
+#ifdef DOS_NT
+  /* Ensure values from the environment use the proper directory separator.  */
+  if (path)
+    {
+      p = alloca (strlen (path) + 1);
+      strcpy (p, path);
+      path = p;
+
+      if ('/' == DIRECTORY_SEP)
+       dostounix_filename (path);
+      else
+       unixtodos_filename (path);
+    }
+#endif
   lpath = Qnil;
   while (1)
     {