Fix -Wwrite_strings in general and for Gtk+ specific code.
[bpt/emacs.git] / src / emacs.c
index 7e9373d..026a210 100644 (file)
@@ -1,7 +1,7 @@
 /* Fully extensible Emacs, running on Unix, intended for GNU.
    Copyright (C) 1985, 1986, 1987, 1993, 1994, 1995, 1997, 1998, 1999,
-                 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
-                 Free Software Foundation, Inc.
+                 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
+                 2010  Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -26,12 +26,13 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include <sys/types.h>
 #include <sys/file.h>
+#include <setjmp.h>
 
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #endif
 
-#ifdef BSD_SYSTEM
+#ifdef HAVE_SYS_IOCTL_H
 #include <sys/ioctl.h>
 #endif
 
@@ -62,6 +63,10 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #include "keyboard.h"
 #include "keymap.h"
 
+#ifdef HAVE_NS
+#include "nsterm.h"
+#endif
+
 #ifdef HAVE_SETLOCALE
 #include <locale.h>
 #endif
@@ -80,17 +85,14 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #endif
 
 #ifdef HAVE_SETPGID
-#if !defined (USG) || defined (BSD_PGRPS)
+#if !defined (USG)
 #undef setpgrp
 #define setpgrp setpgid
 #endif
 #endif
 
-extern void malloc_warning P_ ((char *));
-extern void set_time_zone_rule P_ ((char *));
-#ifdef HAVE_INDEX
-extern char *index P_ ((const char *, int));
-#endif
+static const char emacs_copyright[] = "Copyright (C) 2010 Free Software Foundation, Inc.";
+static const char emacs_version[] = "24.0.50";
 
 /* Make these values available in GDB, which doesn't see macros.  */
 
@@ -153,10 +155,10 @@ int initialized;
    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 ();
+extern void *malloc_get_state (void);
 /* From glibc, a routine that overwrites the malloc internal state.  */
-extern int malloc_set_state ();
-/* Non-zero if the MALLOC_CHECK_ enviroment variable was set while
+extern int malloc_set_state (void*);
+/* Non-zero if the MALLOC_CHECK_ environment variable was set while
    dumping.  Used to work around a bug in glibc's malloc.  */
 int malloc_using_checking;
 #endif
@@ -179,6 +181,10 @@ Lisp_Object Vprevious_system_messages_locale;
 Lisp_Object Vsystem_time_locale;
 Lisp_Object Vprevious_system_time_locale;
 
+/* Copyright and version info.  The version number may be updated by
+   Lisp code.  */
+Lisp_Object Vemacs_copyright, Vemacs_version;
+
 /* If non-zero, emacs should not attempt to use a window-specific code,
    but instead should use the virtual terminal under which it was started.  */
 int inhibit_window_system;
@@ -192,20 +198,11 @@ EMACS_INT emacs_priority;
    data on the first attempt to change it inside asynchronous code.  */
 int running_asynch_code;
 
-#ifdef BSD_PGRPS
-/* See sysdep.c.  */
-extern int inherited_pgroup;
-#endif
-
 #if defined(HAVE_X_WINDOWS) || defined(HAVE_NS)
 /* If non-zero, -d was specified, meaning we're using some window system.  */
 int display_arg;
 #endif
 
-#ifdef HAVE_NS
-extern char ns_no_defaults;
-#endif
-
 /* An address near the bottom of the stack.
    Tells GC how to save a copy of the stack.  */
 char *stack_bottom;
@@ -220,15 +217,6 @@ static unsigned long heap_bss_diff;
    output a warning in dump-emacs.  */
 #define MAX_HEAP_BSS_DIFF (1024*1024)
 
-
-#ifdef HAVE_WINDOW_SYSTEM
-extern Lisp_Object Vinitial_window_system;
-#endif /* HAVE_WINDOW_SYSTEM */
-
-extern Lisp_Object Vauto_save_list_file_name;
-
-extern Lisp_Object Vinhibit_redisplay;
-
 /* Nonzero means running Emacs without interactive terminal.  */
 
 int noninteractive;
@@ -239,6 +227,9 @@ int noninteractive;
 
 int noninteractive1;
 
+/* Nonzero means Emacs was run in --quick mode.  */
+int inhibit_x_resources;
+
 /* Name for the server started by the daemon.*/
 static char *daemon_name;
 
@@ -250,8 +241,8 @@ int daemon_pipe[2];
 char **initial_argv;
 int initial_argc;
 
-static void sort_args ();
-void syms_of_emacs ();
+static void sort_args (int argc, char **argv);
+void syms_of_emacs (void);
 
 /* MSVC needs each string be shorter than 2048 bytes, so the usage
    strings below are split to not overflow this limit.  */
@@ -268,10 +259,10 @@ read the main documentation for these command-line arguments.\n\
 Initialization options:\n\
 \n\
 --batch                     do not do interactive display; implies -q\n\
+--chdir DIR                 change to directory DIR\n\
 --daemon                    start a server in the background\n\
 --debug-init                enable Emacs Lisp debugger for init file\n\
 --display, -d DISPLAY       use X server DISPLAY\n\
---multibyte, --no-unibyte   inhibit the effect of EMACS_UNIBYTE\n\
 --no-desktop                do not load a saved desktop\n\
 --no-init-file, -q          load neither ~/.emacs nor default.el\n\
 --no-shared-memory, -nl     do not use shared memory\n\
@@ -281,7 +272,6 @@ Initialization options:\n\
 --quick, -Q                 equivalent to -q --no-site-file --no-splash\n\
 --script FILE               run FILE as an Emacs Lisp script\n\
 --terminal, -t DEVICE       use DEVICE for terminal I/O\n\
---unibyte, --no-multibyte   run Emacs in unibyte mode\n\
 --user, -u USER             load ~USER/.emacs instead of your own\n\
 \n%s"
 
@@ -347,7 +337,7 @@ abbreviation for a --option.\n\
 Various environment variables and window system resources also affect\n\
 Emacs' operation.  See the main documentation.\n\
 \n\
-Report bugs to %s.  First, please see the Bugs\n\
+Report bugs to bug-gnu-emacs@gnu.org.  First, please see the Bugs\n\
 section of the Emacs manual or the file BUGS.\n"
 
 \f
@@ -360,7 +350,7 @@ int fatal_error_in_progress;
 /* If non-null, call this function from fatal_error_signal before
    committing suicide.  */
 
-void (*fatal_error_signal_hook) P_ ((void));
+void (*fatal_error_signal_hook) (void);
 
 #ifdef FORWARD_SIGNAL_TO_MAIN_THREAD
 /* When compiled with GTK and running under Gnome,
@@ -373,8 +363,7 @@ pthread_t main_thread;
 
 /* Handle bus errors, invalid instruction, etc.  */
 SIGTYPE
-fatal_error_signal (sig)
-     int sig;
+fatal_error_signal (int sig)
 {
   SIGNAL_THREAD_CHECK (sig);
   fatal_error_code = sig;
@@ -387,6 +376,9 @@ fatal_error_signal (sig)
     {
       fatal_error_in_progress = 1;
 
+      if (sig == SIGTERM || sig == SIGHUP)
+        Fkill_emacs (make_number (sig));
+
       shut_down_emacs (sig, 0, Qnil);
     }
 
@@ -428,7 +420,7 @@ memory_warning_signal (sig)
 #if ! defined (DOS_NT) && ! defined (NO_ABORT)
 
 void
-abort ()
+abort (void)
 {
   kill (getpid (), SIGABRT);
   /* This shouldn't be executed, but it prevents a warning.  */
@@ -440,10 +432,7 @@ abort ()
 /* Code for dealing with Lisp access to the Unix command line.  */
 
 static void
-init_cmdargs (argc, argv, skip_args)
-     int argc;
-     char **argv;
-     int skip_args;
+init_cmdargs (int argc, char **argv, int skip_args)
 {
   register int i;
   Lisp_Object name, dir, tem;
@@ -585,7 +574,7 @@ init_cmdargs (argc, argv, skip_args)
 DEFUN ("invocation-name", Finvocation_name, Sinvocation_name, 0, 0, 0,
        doc: /* Return the program name that was used to run Emacs.
 Any directory names are omitted.  */)
-     ()
+  (void)
 {
   return Fcopy_sequence (Vinvocation_name);
 }
@@ -593,7 +582,7 @@ Any directory names are omitted.  */)
 DEFUN ("invocation-directory", Finvocation_directory, Sinvocation_directory,
        0, 0, 0,
        doc: /* Return the directory name in which the Emacs executable was located.  */)
-     ()
+  (void)
 {
   return Fcopy_sequence (Vinvocation_directory);
 }
@@ -612,11 +601,11 @@ static char dump_tz[] = "UtC0";
    (We don't have any real constructors or destructors.)  */
 #ifdef __GNUC__
 #ifndef GCC_CTORS_IN_LIBC
-void __do_global_ctors ()
+void __do_global_ctors (void)
 {}
-void __do_global_ctors_aux ()
+void __do_global_ctors_aux (void)
 {}
-void __do_global_dtors ()
+void __do_global_dtors (void)
 {}
 /* GNU/Linux has a bug in its library; avoid an error.  */
 #ifndef GNU_LINUX
@@ -624,7 +613,7 @@ char * __CTOR_LIST__[2] = { (char *) (-1), 0 };
 #endif
 char * __DTOR_LIST__[2] = { (char *) (-1), 0 };
 #endif /* GCC_CTORS_IN_LIBC */
-void __main ()
+void __main (void)
 {}
 #endif /* __GNUC__ */
 #endif /* ORDINARY_LINK */
@@ -640,14 +629,7 @@ void __main ()
    enough information to do it right.  */
 
 static int
-argmatch (argv, argc, sstr, lstr, minlen, valptr, skipptr)
-     char **argv;
-     int argc;
-     char *sstr;
-     char *lstr;
-     int minlen;
-     char **valptr;
-     int *skipptr;
+argmatch (char **argv, int argc, const char *sstr, const char *lstr, int minlen, char **valptr, int *skipptr)
 {
   char *p = NULL;
   int arglen;
@@ -671,7 +653,7 @@ argmatch (argv, argc, sstr, lstr, minlen, valptr, skipptr)
        *skipptr += 1;
       return 1;
     }
-  arglen = (valptr != NULL && (p = index (arg, '=')) != NULL
+  arglen = (valptr != NULL && (p = strchr (arg, '=')) != NULL
            ? p - arg : strlen (arg));
   if (lstr == 0 || arglen < minlen || strncmp (arg, lstr, arglen) != 0)
     return 0;
@@ -705,7 +687,7 @@ argmatch (argv, argc, sstr, lstr, minlen, valptr, skipptr)
    possible using this special hook.  */
 
 static void
-malloc_initialize_hook ()
+malloc_initialize_hook (void)
 {
 #ifndef USE_CRT_DLL
   extern char **environ;
@@ -743,46 +725,11 @@ malloc_initialize_hook ()
     }
 }
 
-void (*__malloc_initialize_hook) () = malloc_initialize_hook;
+void (*__malloc_initialize_hook) (void) = malloc_initialize_hook;
 
 #endif /* DOUG_LEA_MALLOC */
 
 
-#define REPORT_EMACS_BUG_ADDRESS "bug-gnu-emacs@gnu.org"
-#define REPORT_EMACS_BUG_PRETEST_ADDRESS "emacs-pretest-bug@gnu.org"
-
-/* This function is used to determine an address to which bug report should
-   be sent.  */
-
-char *
-bug_reporting_address ()
-{
-  int count = 0;
-  Lisp_Object temp;
-  char *string;
-
-  temp = Fsymbol_value (intern ("emacs-version"));
-
-  /* When `emacs-version' is invalid, use normal address.  */
-  if (!STRINGP(temp))
-    return REPORT_EMACS_BUG_ADDRESS;
-
-  string = SDATA (temp);
-
-  /* Count dots in `emacs-version'.  */
-  while (*string)
-    {
-      if (*string == '.')
-       count++;
-      string++;
-    }
-
-  /* When `emacs-version' has at least three dots, it is development or
-     pretest version of Emacs.  */
-  return count >= 3 ? REPORT_EMACS_BUG_PRETEST_ADDRESS : REPORT_EMACS_BUG_ADDRESS;
-}
-
-
 /* ARGSUSED */
 int
 main (int argc, char **argv)
@@ -793,9 +740,6 @@ main (int argc, char **argv)
   char stack_bottom_variable;
   int do_initial_setlocale;
   int skip_args = 0;
-#ifndef USE_CRT_DLL
-  extern int errno;
-#endif
 #ifdef HAVE_SETRLIMIT
   struct rlimit rlim;
 #endif
@@ -805,12 +749,17 @@ main (int argc, char **argv)
 #ifdef NS_IMPL_COCOA
   char dname_arg2[80];
 #endif
+  char *ch_to_dir;
 
 #if GC_MARK_STACK
-  extern Lisp_Object *stack_base;
   stack_base = &dummy;
 #endif
 
+#if defined (USE_GTK) && defined (G_SLICE_ALWAYS_MALLOC)
+  /* This is used by the Cygwin build.  */
+  setenv ("G_SLICE", "always-malloc", 1);
+#endif
+
   if (!initialized)
     {
       extern char my_endbss[];
@@ -822,11 +771,6 @@ main (int argc, char **argv)
       heap_bss_diff = (char *)my_heap_start - max (my_endbss, my_endbss_static);
     }
 
-#ifdef LINUX_SBRK_BUG
-  /* This is only used GNU/LINUX running on alpha when using libc5 */
-  __sbrk (1);
-#endif
-
 #ifdef RUN_TIME_REMAP
   if (initialized)
     run_time_remap (argv[0]);
@@ -842,36 +786,52 @@ main (int argc, char **argv)
   argc = 0;
   while (argv[argc]) argc++;
 
-  if (argmatch (argv, argc, "-version", "--version", 3, NULL, &skip_args)
-      /* We don't know the version number unless this is a dumped Emacs.
-         So ignore --version otherwise.  */
-      && initialized)
+  if (argmatch (argv, argc, "-version", "--version", 3, NULL, &skip_args))
     {
-      Lisp_Object tem, tem2;
-      tem = Fsymbol_value (intern ("emacs-version"));
-      tem2 = Fsymbol_value (intern ("emacs-copyright"));
-      if (!STRINGP (tem))
-       {
-         fprintf (stderr, "Invalid value of `emacs-version'\n");
-         exit (1);
-       }
-      if (!STRINGP (tem2))
+      const char *version, *copyright;
+      if (initialized)
        {
-         fprintf (stderr, "Invalid value of `emacs-copyright'\n");
-         exit (1);
+         Lisp_Object tem, tem2;
+         tem = Fsymbol_value (intern_c_string ("emacs-version"));
+         tem2 = Fsymbol_value (intern_c_string ("emacs-copyright"));
+         if (!STRINGP (tem))
+           {
+             fprintf (stderr, "Invalid value of `emacs-version'\n");
+             exit (1);
+           }
+         if (!STRINGP (tem2))
+           {
+             fprintf (stderr, "Invalid value of `emacs-copyright'\n");
+             exit (1);
+           }
+         else
+           {
+             version = SDATA (tem);
+             copyright = SDATA (tem2);
+           }
        }
       else
        {
-         printf ("GNU Emacs %s\n", SDATA (tem));
-         printf ("%s\n", SDATA(tem2));
-         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");
-         printf ("For more information about these matters, ");
-         printf ("see the file named COPYING.\n");
-         exit (0);
+         version = emacs_version;
+         copyright = emacs_copyright;
        }
+      printf ("GNU Emacs %s\n", version);
+      printf ("%s\n", copyright);
+      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");
+      printf ("For more information about these matters, ");
+      printf ("see the file named COPYING.\n");
+      exit (0);
     }
+  if (argmatch (argv, argc, "-chdir", "--chdir", 2, &ch_to_dir, &skip_args))
+      if (chdir (ch_to_dir) == -1)
+        {
+          fprintf (stderr, "%s: Can't chdir to %s: %s\n",
+                   argv[0], ch_to_dir, strerror (errno));
+          exit (1);
+        }
+
 
 #ifdef HAVE_PERSONALITY_LINUX32
   if (!initialized
@@ -879,8 +839,9 @@ main (int argc, char **argv)
           || strcmp (argv[argc-1], "bootstrap") == 0)
       && ! getenv ("EMACS_HEAP_EXEC"))
     {
+      static char heapexec[] = "EMACS_HEAP_EXEC=true";
       /* Set this so we only do this once.  */
-      putenv("EMACS_HEAP_EXEC=true");
+      putenv(heapexec);
 
       /* A flag to turn off address randomization which is introduced
          in linux kernel shipped with fedora core 4 */
@@ -895,23 +856,6 @@ main (int argc, char **argv)
     }
 #endif /* HAVE_PERSONALITY_LINUX32 */
 
-
-/* Map in shared memory, if we are using that.  */
-#ifdef HAVE_SHM
-  if (argmatch (argv, argc, "-nl", "--no-shared-memory", 6, NULL, &skip_args))
-    {
-      map_in_data (0);
-      /* The shared memory was just restored, which clobbered this.  */
-      skip_args = 1;
-    }
-  else
-    {
-      map_in_data (1);
-      /* The shared memory was just restored, which clobbered this.  */
-      skip_args = 0;
-    }
-#endif
-
 #if defined (HAVE_SETRLIMIT) && defined (RLIMIT_STACK)
   /* Extend the stack space available.
      Don't do that if dumping, since some systems (e.g. DJGPP)
@@ -982,7 +926,6 @@ main (int argc, char **argv)
 #endif /* MSDOS || WINDOWSNT */
 
 #ifdef MSDOS
-#if __DJGPP__ >= 2
   if (!isatty (fileno (stdin)))
     setmode (fileno (stdin), O_BINARY);
   if (!isatty (fileno (stdout)))
@@ -990,19 +933,8 @@ main (int argc, char **argv)
       fflush (stdout);
       setmode (fileno (stdout), O_BINARY);
     }
-#else  /* not __DJGPP__ >= 2 */
-  (stdin)->_flag &= ~_IOTEXT;
-  (stdout)->_flag &= ~_IOTEXT;
-  (stderr)->_flag &= ~_IOTEXT;
-#endif /* not __DJGPP__ >= 2 */
 #endif /* MSDOS */
 
-#ifdef SET_EMACS_PRIORITY
-  if (emacs_priority)
-    nice (emacs_priority);
-  setuid (getuid ());
-#endif /* SET_EMACS_PRIORITY */
-
   /* Skip initial setlocale if LC_ALL is "C", as it's not needed in that case.
      The build procedure uses this while dumping, to ensure that the
      dumped Emacs does not have its system locale tables initialized,
@@ -1079,7 +1011,7 @@ main (int argc, char **argv)
     {
       printf (USAGE1, argv[0], USAGE2);
       printf (USAGE3);
-      printf (USAGE4, bug_reporting_address ());
+      printf (USAGE4);
       exit (0);
     }
 
@@ -1183,7 +1115,7 @@ main (int argc, char **argv)
             argv[skip_args] = fdStr;
 
             execv (argv[0], argv);
-            fprintf (stderr, "emacs daemon: exec failed: %d\t%d\n", errno);
+            fprintf (stderr, "emacs daemon: exec failed: %d\n", errno);
             exit (1);
           }
 
@@ -1220,20 +1152,12 @@ main (int argc, char **argv)
 
   if (! noninteractive)
     {
-#ifdef BSD_PGRPS
-      if (initialized)
-       {
-         inherited_pgroup = EMACS_GETPGRP (0);
-         setpgrp (0, getpid ());
-       }
-#else
 #if defined (USG5) && defined (INTERRUPT_INPUT)
       setpgrp ();
 #endif
-#endif
 #if defined (HAVE_GTK_AND_PTHREAD) && !defined (SYSTEM_MALLOC) && !defined (DOUG_LEA_MALLOC)
       {
-       extern void malloc_enable_thread P_ ((void));
+        extern void malloc_enable_thread (void);
 
        malloc_enable_thread ();
       }
@@ -1330,9 +1254,7 @@ main (int argc, char **argv)
 #ifdef AIX
 /* 20 is SIGCHLD, 21 is SIGTTIN, 22 is SIGTTOU.  */
       signal (SIGXCPU, fatal_error_signal);
-#ifndef _I386
       signal (SIGIOINT, fatal_error_signal);
-#endif
       signal (SIGGRANT, fatal_error_signal);
       signal (SIGRETRACT, fatal_error_signal);
       signal (SIGSOUND, fatal_error_signal);
@@ -1386,7 +1308,6 @@ main (int argc, char **argv)
       syms_of_coding ();       /* This should be after syms_of_fileio.  */
 
       init_window_once ();     /* Init the window system.  */
-      init_fileio_once ();     /* Must precede any path manipulation.  */
 #ifdef HAVE_WINDOW_SYSTEM
       init_fringe_once ();     /* Swap bitmaps if necessary. */
 #endif /* HAVE_WINDOW_SYSTEM */
@@ -1439,8 +1360,8 @@ main (int argc, char **argv)
          Lisp_Object old_log_max;
          Lisp_Object symbol, tail;
 
-         symbol = intern ("default-enable-multibyte-characters");
-         Fset (symbol, Qnil);
+         symbol = intern_c_string ("enable-multibyte-characters");
+         Fset_default (symbol, Qnil);
 
          if (initialized)
            {
@@ -1467,6 +1388,7 @@ main (int argc, char **argv)
                  set_buffer_temp (current);
                }
            }
+         message ("Warning: unibyte sessions are obsolete and will disappear");
        }
     }
 
@@ -1477,18 +1399,6 @@ main (int argc, char **argv)
   ns_alloc_autorelease_pool();
   if (!noninteractive)
     {
-      char *tmp;
-      display_arg = 4;
-      if (argmatch (argv, argc, "-q", "--no-init-file", 6, NULL, &skip_args))
-        {
-          ns_no_defaults = 1;
-          skip_args--;
-        }
-      if (argmatch (argv, argc, "-Q", "--quick", 5, NULL, &skip_args))
-        {
-          ns_no_defaults = 1;
-          skip_args--;
-        }
 #ifdef NS_IMPL_COCOA
       if (skip_args < argc)
         {
@@ -1503,16 +1413,7 @@ main (int argc, char **argv)
               chdir (getenv ("HOME"));
             }
         }
-#endif
-      /* This used for remote operation.. not fully implemented yet. */
-      if (argmatch (argv, argc, "-_NSMachLaunch", 0, 3, &tmp, &skip_args))
-          display_arg = 4;
-      else if (argmatch (argv, argc, "-MachLaunch", 0, 3, &tmp, &skip_args))
-          display_arg = 4;
-      else if (argmatch (argv, argc, "-macosx", 0, 2, NULL, &skip_args))
-          display_arg = 4;
-      else if (argmatch (argv, argc, "-NSHost", 0, 3, &tmp, &skip_args))
-          display_arg = 4;
+#endif  /* COCOA */
     }
 #endif /* HAVE_NS */
 
@@ -1595,6 +1496,11 @@ main (int argc, char **argv)
     ns_init_paths ();
 #endif
 
+  /* Initialize and GC-protect Vinitial_environment and
+     Vprocess_environment before set_initial_environment fills them
+     in.  */
+  if (!initialized)
+    syms_of_callproc ();
   /* egetenv is a pretty low-level facility, which may get called in
      many circumstances; it seems flimsy to put off initializing it
      until calling init_callproc.  */
@@ -1630,10 +1536,8 @@ main (int argc, char **argv)
 
   if (!initialized)
     {
-      /* The basic levels of Lisp must come first.  */
-      /* And data must come first of all
-        for the sake of symbols like error-message.  */
-      syms_of_data ();
+      /* The basic levels of Lisp must come first.  Note that
+        syms_of_data and some others have already been called.  */
       syms_of_chartab ();
       syms_of_lread ();
       syms_of_print ();
@@ -1646,14 +1550,11 @@ main (int argc, char **argv)
       syms_of_callint ();
       syms_of_casefiddle ();
       syms_of_casetab ();
-      syms_of_callproc ();
       syms_of_category ();
       syms_of_ccl ();
       syms_of_character ();
       syms_of_cmds ();
-#ifndef NO_DIR_LIBRARY
       syms_of_dired ();
-#endif /* not NO_DIR_LIBRARY */
       syms_of_display ();
       syms_of_doc ();
       syms_of_editfns ();
@@ -1694,6 +1595,7 @@ main (int argc, char **argv)
       syms_of_xfns ();
       syms_of_xmenu ();
       syms_of_fontset ();
+      syms_of_xsettings ();
 #ifdef HAVE_X_SM
       syms_of_xsmfns ();
 #endif
@@ -1714,6 +1616,9 @@ main (int argc, char **argv)
 
 #ifdef MSDOS
       syms_of_xmenu ();
+      syms_of_dosfns();
+      syms_of_msdos();
+      syms_of_win16select();
 #endif /* MSDOS */
 
 #ifdef HAVE_NS
@@ -1728,13 +1633,9 @@ main (int argc, char **argv)
       syms_of_dbusbind ();
 #endif /* HAVE_DBUS */
 
-#ifdef SYMS_SYSTEM
-      SYMS_SYSTEM;
-#endif
-
-#ifdef SYMS_MACHINE
-      SYMS_MACHINE;
-#endif
+#ifdef WINDOWSNT
+      syms_of_ntterm ();
+#endif /* WINDOWSNT */
 
       keys_of_casefiddle ();
       keys_of_cmds ();
@@ -1780,11 +1681,11 @@ main (int argc, char **argv)
       char *file;
       /* Handle -l loadup, args passed by Makefile.  */
       if (argmatch (argv, argc, "-l", "--load", 3, &file, &skip_args))
-       Vtop_level = Fcons (intern ("load"),
+       Vtop_level = Fcons (intern_c_string ("load"),
                            Fcons (build_string (file), Qnil));
       /* Unless next switch is -nl, load "loadup.el" first thing.  */
       if (! no_loadup)
-       Vtop_level = Fcons (intern ("load"),
+       Vtop_level = Fcons (intern_c_string ("load"),
                            Fcons (build_string ("loadup.el"), Qnil));
     }
 
@@ -1811,9 +1712,7 @@ main (int argc, char **argv)
   /* Set up for profiling.  This is known to work on FreeBSD,
      GNU/Linux and MinGW.  It might work on some other systems too.
      Give it a try and tell us if it works on your system.  To compile
-     for profiling, add -pg to the switches your platform uses in
-     CFLAGS and LDFLAGS.  For example:
-       `make CFLAGS="-pg -g -O -DPROFILING=1" LDFLAGS="-pg -g"'.  */
+     for profiling, use the configure option --enable-profiling.  */
 #if defined (__FreeBSD__) || defined (GNU_LINUX) || defined(__MINGW32__)
 #ifdef PROFILING
   if (initialized)
@@ -1824,15 +1723,26 @@ main (int argc, char **argv)
 #else
       extern char etext;
 #endif
+#ifdef HAVE___EXECUTABLE_START
+      /* This symbol is defined by GNU ld to the start of the text
+        segment.  */
+      extern char __executable_start[];
+#else
       extern void safe_bcopy ();
-      extern void dump_opcode_frequencies ();
+#endif
 
       atexit (_mcleanup);
+#ifdef HAVE___EXECUTABLE_START
+      monstartup (__executable_start, &etext);
+#else
       /* This uses safe_bcopy 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.  */
+      /* FIXME: Does not work on architectures with function
+        descriptors.  */
       monstartup (safe_bcopy, &etext);
+#endif
     }
   else
     moncontrol (0);
@@ -1863,18 +1773,16 @@ main (int argc, char **argv)
 
 struct standard_args
 {
-  char *name;
-  char *longname;
+  const char *name;
+  const char *longname;
   int priority;
   int nargs;
 };
 
-struct standard_args standard_args[] =
+const struct standard_args standard_args[] =
 {
   { "-version", "--version", 150, 0 },
-#ifdef HAVE_SHM
-  { "-nl", "--no-shared-memory", 140, 0 },
-#endif
+  { "-chdir", "--chdir", 130, 1 },
   { "-t", "--terminal", 120, 1 },
   { "-nw", "--no-window-system", 110, 0 },
   { "-nw", "--no-windows", 110, 0 },
@@ -1890,7 +1798,7 @@ struct standard_args standard_args[] =
   /* -d must come last before the options handled in startup.el.  */
   { "-d", "--display", 60, 1 },
   { "-display", 0, 60, 1 },
-  /* Now for the options handled in startup.el.  */
+  /* Now for the options handled in `command-line' (startup.el).  */
   { "-Q", "--quick", 55, 0 },
   { "-quick", 0, 55, 0 },
   { "-q", "--no-init-file", 50, 0 },
@@ -1899,10 +1807,12 @@ struct standard_args standard_args[] =
   { "-u", "--user", 30, 1 },
   { "-user", 0, 30, 1 },
   { "-debug-init", "--debug-init", 20, 0 },
-  { "-nbi", "--no-bitmap-icon", 15, 0 },
   { "-iconic", "--iconic", 15, 0 },
   { "-D", "--basic-display", 12, 0},
   { "-basic-display", 0, 12, 0},
+  { "-nbc", "--no-blinking-cursor", 12, 0 },
+  /* Now for the options handled in `command-line-1' (startup.el).  */
+  { "-nbi", "--no-bitmap-icon", 10, 0 },
   { "-bg", "--background-color", 10, 1 },
   { "-background", 0, 10, 1 },
   { "-fg", "--foreground-color", 10, 1 },
@@ -1912,7 +1822,6 @@ struct standard_args standard_args[] =
   { "-ib", "--internal-border", 10, 1 },
   { "-ms", "--mouse-color", 10, 1 },
   { "-cr", "--cursor-color", 10, 1 },
-  { "-nbc", "--no-blinking-cursor", 10, 0 },
   { "-fn", "--font", 10, 1 },
   { "-font", 0, 10, 1 },
   { "-fs", "--fullscreen", 10, 0 },
@@ -1982,9 +1891,7 @@ struct standard_args standard_args[] =
    than once, eliminate all but one copy of it.  */
 
 static void
-sort_args (argc, argv)
-     int argc;
-     char **argv;
+sort_args (int argc, char **argv)
 {
   char **new = (char **) xmalloc (sizeof (char *) * argc);
   /* For each element of argv,
@@ -2042,7 +1949,7 @@ sort_args (argc, argv)
            {
              match = -1;
              thislen = strlen (argv[from]);
-             equals = index (argv[from], '=');
+             equals = strchr (argv[from], '=');
              if (equals != 0)
                thislen = equals - argv[from];
 
@@ -2125,7 +2032,7 @@ sort_args (argc, argv)
   while (to < argc)
     new[to++] = 0;
 
-  bcopy (new, argv, sizeof (char *) * argc);
+  memcpy (argv, new, sizeof (char *) * argc);
 
   xfree (options);
   xfree (new);
@@ -2140,8 +2047,7 @@ If ARG is a string, stuff it as keyboard input.
 The value of `kill-emacs-hook', if not void,
 is a list of functions (of no args),
 all of which are called before Emacs is actually killed.  */)
-     (arg)
-     Lisp_Object arg;
+  (Lisp_Object arg)
 {
   struct gcpro gcpro1;
 
@@ -2164,8 +2070,6 @@ all of which are called before Emacs is actually killed.  */)
     unlink (SDATA (Vauto_save_list_file_name));
 
   exit (INTEGERP (arg) ? XINT (arg) : EXIT_SUCCESS);
-  /* NOTREACHED */
-  return Qnil;
 }
 
 
@@ -2181,9 +2085,7 @@ all of which are called before Emacs is actually killed.  */)
    and Fkill_emacs.  */
 
 void
-shut_down_emacs (sig, no_x, stuff)
-     int sig, no_x;
-     Lisp_Object stuff;
+shut_down_emacs (int sig, int no_x, Lisp_Object stuff)
 {
   /* Prevent running of hooks from now on.  */
   Vrun_hooks = Qnil;
@@ -2212,9 +2114,7 @@ shut_down_emacs (sig, no_x, stuff)
 
   stuff_buffered_input (stuff);
 
-#ifdef subprocesses
   inhibit_sentinels = 1;
-#endif
   kill_buffer_processes (Qnil);
   Fdo_auto_save (Qt, Qnil);
 
@@ -2265,47 +2165,13 @@ shut_down_emacs (sig, no_x, stuff)
 \f
 #ifndef CANNOT_DUMP
 
-#ifdef HAVE_SHM
-
-DEFUN ("dump-emacs-data", Fdump_emacs_data, Sdump_emacs_data, 1, 1, 0,
-       doc: /* Dump current state of Emacs into data file FILENAME.
-This function exists on systems that use HAVE_SHM.  */)
-     (filename)
-     Lisp_Object filename;
-{
-  extern char my_edata[];
-  Lisp_Object tem;
-
-  check_pure_size ();
-  CHECK_STRING (filename);
-  filename = Fexpand_file_name (filename, Qnil);
-
-  tem = Vpurify_flag;
-  Vpurify_flag = Qnil;
-
-  fflush (stdout);
-  /* Tell malloc where start of impure now is.  */
-  /* Also arrange for warnings when nearly out of space.  */
-#ifndef SYSTEM_MALLOC
-  memory_warnings (my_edata, malloc_warning);
-#endif
-  map_out_data (SDATA (filename));
-
-  Vpurify_flag = tem;
-
-  return Qnil;
-}
-
-#else /* not HAVE_SHM */
-
 DEFUN ("dump-emacs", Fdump_emacs, Sdump_emacs, 2, 2, 0,
        doc: /* Dump current state of Emacs into executable file FILENAME.
 Take symbols from SYMFILE (presumably the file you executed to run Emacs).
 This is used in the file `loadup.el' when building Emacs.
 
 You must run Emacs in batch mode in order to dump it.  */)
-     (filename, symfile)
-     Lisp_Object filename, symfile;
+  (Lisp_Object filename, Lisp_Object symfile)
 {
   extern char my_edata[];
   Lisp_Object tem;
@@ -2394,14 +2260,12 @@ You must run Emacs in batch mode in order to dump it.  */)
   return unbind_to (count, Qnil);
 }
 
-#endif /* not HAVE_SHM */
-
 #endif /* not CANNOT_DUMP */
 \f
 #if HAVE_SETLOCALE
 /* Recover from setlocale (LC_ALL, "").  */
 void
-fixup_locale ()
+fixup_locale (void)
 {
   /* The Emacs Lisp reader needs LC_NUMERIC to be "C",
      so that numbers are read and printed properly for Emacs Lisp.  */
@@ -2411,10 +2275,7 @@ fixup_locale ()
 /* Set system locale CATEGORY, with previous locale *PLOCALE, to
    DESIRED_LOCALE.  */
 static void
-synchronize_locale (category, plocale, desired_locale)
-     int category;
-     Lisp_Object *plocale;
-     Lisp_Object desired_locale;
+synchronize_locale (int category, Lisp_Object *plocale, Lisp_Object desired_locale)
 {
   if (! EQ (*plocale, desired_locale))
     {
@@ -2427,7 +2288,7 @@ synchronize_locale (category, plocale, desired_locale)
 
 /* Set system time locale to match Vsystem_time_locale, if possible.  */
 void
-synchronize_system_time_locale ()
+synchronize_system_time_locale (void)
 {
   synchronize_locale (LC_TIME, &Vprevious_system_time_locale,
                      Vsystem_time_locale);
@@ -2436,7 +2297,7 @@ synchronize_system_time_locale ()
 /* Set system messages locale to match Vsystem_messages_locale, if
    possible.  */
 void
-synchronize_system_messages_locale ()
+synchronize_system_messages_locale (void)
 {
 #ifdef LC_MESSAGES
   synchronize_locale (LC_MESSAGES, &Vprevious_system_messages_locale,
@@ -2450,17 +2311,16 @@ synchronize_system_messages_locale ()
 #endif
 
 Lisp_Object
-decode_env_path (evarname, defalt)
-     char *evarname, *defalt;
+decode_env_path (const char *evarname, const char *defalt)
 {
-  register char *path, *p;
+  const char *path, *p;
   Lisp_Object lpath, element, tem;
 
   /* 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);
+    path = getenv (evarname);
   else
     path = 0;
   if (!path)
@@ -2469,21 +2329,18 @@ decode_env_path (evarname, defalt)
   /* 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);
+      char *path_copy = alloca (strlen (path) + 1);
+      strcpy (path_copy, path);
+      dostounix_filename (path_copy);
+      path = path_copy;
     }
 #endif
   lpath = Qnil;
   while (1)
     {
-      p = index (path, SEPCHAR);
-      if (!p) p = path + strlen (path);
+      p = strchr (path, SEPCHAR);
+      if (!p)
+       p = path + strlen (path);
       element = (p - path ? make_string (path, p - path)
                 : build_string ("."));
 
@@ -2516,7 +2373,7 @@ decode_env_path (evarname, defalt)
 DEFUN ("daemonp", Fdaemonp, Sdaemonp, 0, 0, 0,
        doc: /* Return non-nil if the current emacs process is a daemon.
 If the daemon was given a name argument, return that name. */)
-  ()
+  (void)
 {
   if (IS_DAEMON)
     if (daemon_name)
@@ -2531,7 +2388,7 @@ DEFUN ("daemon-initialized", Fdaemon_initialized, Sdaemon_initialized, 0, 0, 0,
        doc: /* Mark the Emacs daemon as being initialized.
 This finishes the daemonization process by doing the other half of detaching
 from the parent process and its tty file descriptors.  */)
-  ()
+  (void)
 {
   int nfd;
 
@@ -2566,17 +2423,13 @@ from the parent process and its tty file descriptors.  */)
 }
 
 void
-syms_of_emacs ()
+syms_of_emacs (void)
 {
-  Qfile_name_handler_alist = intern ("file-name-handler-alist");
+  Qfile_name_handler_alist = intern_c_string ("file-name-handler-alist");
   staticpro (&Qfile_name_handler_alist);
 
 #ifndef CANNOT_DUMP
-#ifdef HAVE_SHM
-  defsubr (&Sdump_emacs_data);
-#else
   defsubr (&Sdump_emacs);
-#endif
 #endif
 
   defsubr (&Skill_emacs);
@@ -2591,16 +2444,18 @@ syms_of_emacs ()
 Many arguments are deleted from the list as they are processed.  */);
 
   DEFVAR_LISP ("system-type", &Vsystem_type,
-              doc: /* Value is symbol indicating type of operating system you are using.
+              doc: /* The value is a symbol indicating the type of operating system you are using.
 Special values:
-  `gnu'         compiled for a GNU Hurd system.
-  `gnu/linux'   compiled for a GNU/Linux system.
-  `darwin'      compiled for Darwin (GNU-Darwin, Mac OS X, ...).
-  `ms-dos'      compiled as an MS-DOS application.
-  `windows-nt'  compiled as a native W32 application.
-  `cygwin'      compiled using the Cygwin library.
-Anything else indicates some sort of Unix system.  */);
-  Vsystem_type = intern (SYSTEM_TYPE);
+  `gnu'          compiled for a GNU Hurd system.
+  `gnu/linux'    compiled for a GNU/Linux system.
+  `gnu/kfreebsd' compiled for a GNU system with a FreeBSD kernel.
+  `darwin'       compiled for Darwin (GNU-Darwin, Mac OS X, ...).
+  `ms-dos'       compiled as an MS-DOS application.
+  `windows-nt'   compiled as a native W32 application.
+  `cygwin'       compiled using the Cygwin library.
+Anything else (in Emacs 23.1, the possibilities are: aix, berkeley-unix,
+hpux, irix, lynxos 3.0.1, usg-unix-v) indicates some sort of Unix system.  */);
+  Vsystem_type = intern_c_string (SYSTEM_TYPE);
 
   DEFVAR_LISP ("system-configuration", &Vsystem_configuration,
               doc: /* Value is string indicating configuration Emacs was built for.
@@ -2683,6 +2538,18 @@ was found.  */);
 This is nil during initialization.  */);
   Vafter_init_time = Qnil;
 
+  DEFVAR_BOOL ("inhibit-x-resources", &inhibit_x_resources,
+              doc: /* If non-nil, X resources, Windows Registry settings, and NS defaults are not used.  */);
+  inhibit_x_resources = 0;
+
+  DEFVAR_LISP ("emacs-copyright", &Vemacs_copyright,
+              doc: /* Short copyright string for this version of Emacs.  */);
+  Vemacs_copyright = build_string (emacs_copyright);
+
+  DEFVAR_LISP ("emacs-version", &Vemacs_version,
+              doc: /* Version numbers of this version of Emacs.  */);
+  Vemacs_version = build_string (emacs_version);
+
   /* Make sure IS_DAEMON starts up as false.  */
   daemon_pipe[1] = 0;
 }