home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / e20313sr.zip / emacs / 20.3.1 / src / emacs.c < prev    next >
C/C++ Source or Header  |  1999-07-31  |  58KB  |  2,065 lines

  1. /* Fully extensible Emacs, running on Unix, intended for GNU.
  2.    Copyright (C) 1985,86,87,93,94,95,97,1998 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU Emacs.
  5.  
  6. GNU Emacs is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10.  
  11. GNU Emacs is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU Emacs; see the file COPYING.  If not, write to
  18. the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  19. Boston, MA 02111-1307, USA.  */
  20.  
  21. /* Modified for emx by Jeremy Bowen, May 1999 based on patches
  22.    to v19.33 by Eberhard Mattes */
  23.  
  24. #include <signal.h>
  25. #include <errno.h>
  26.  
  27. #include <config.h>
  28. #include <stdio.h>
  29.  
  30. #include <sys/types.h>
  31. #include <sys/file.h>
  32.  
  33. #ifdef VMS
  34. #include <ssdef.h>
  35. #endif
  36.  
  37. #ifdef BSD_SYSTEM
  38. #include <sys/ioctl.h>
  39. #endif
  40.  
  41. #include "lisp.h"
  42. #include "commands.h"
  43. #include "intervals.h"
  44. #include "buffer.h"
  45.  
  46. #include "systty.h"
  47. #include "blockinput.h"
  48. #include "syssignal.h"
  49. #include "process.h"
  50. #include "keyboard.h"
  51.  
  52. #ifdef HAVE_SETRLIMIT
  53. #include <sys/time.h>
  54. #include <sys/resource.h>
  55. #endif
  56.  
  57. #ifndef O_RDWR
  58. #define O_RDWR 2
  59. #endif
  60.  
  61. extern void malloc_warning ();
  62. extern void set_time_zone_rule ();
  63. extern char *index ();
  64. extern char *strerror ();
  65.  
  66. /* Command line args from shell, as list of strings */
  67. Lisp_Object Vcommand_line_args;
  68.  
  69. /* The name under which Emacs was invoked, with any leading directory
  70.    names discarded.  */
  71. Lisp_Object Vinvocation_name;
  72.  
  73. /* The directory name from which Emacs was invoked.  */
  74. Lisp_Object Vinvocation_directory;
  75.  
  76. /* The directory name in which to find subdirs such as lisp and etc.
  77.    nil means get them only from PATH_LOADSEARCH.  */
  78. Lisp_Object Vinstallation_directory;
  79.  
  80. /* Hook run by `kill-emacs' before it does really anything.  */
  81. Lisp_Object Vkill_emacs_hook;
  82.  
  83. #ifdef SIGUSR1
  84. /* Hooks for signal USR1 and USR2 handing */
  85. Lisp_Object Vsignal_USR1_hook;
  86. #ifdef SIGUSR2
  87. Lisp_Object Vsignal_USR2_hook;
  88. #endif 
  89. #endif
  90.  
  91. /* Search path separator.  */
  92. Lisp_Object Vpath_separator;
  93.  
  94. /* Set nonzero after Emacs has started up the first time.
  95.   Prevents reinitialization of the Lisp world and keymaps
  96.   on subsequent starts.  */
  97. int initialized;
  98.  
  99. #ifdef DOUG_LEA_MALLOC
  100. /* Preserves a pointer to the memory allocated that copies that
  101.    static data inside glibc's malloc.  */
  102. void *malloc_state_ptr;
  103. /* From glibc, a routine that returns a copy of the malloc internal state.  */
  104. extern void *malloc_get_state ();
  105. /* From glibc, a routine that overwrites the malloc internal state.  */
  106. extern void malloc_set_state ();
  107. #endif
  108.  
  109. /* Variable whose value is symbol giving operating system type.  */
  110. Lisp_Object Vsystem_type;
  111.  
  112. /* Variable whose value is string giving configuration built for.  */
  113. Lisp_Object Vsystem_configuration;
  114.  
  115. /* Variable whose value is string giving configuration options,
  116.    for use when reporting bugs.  */
  117. Lisp_Object Vsystem_configuration_options;
  118.  
  119. Lisp_Object Qfile_name_handler_alist;
  120.  
  121. /* If non-zero, emacs should not attempt to use an window-specific code,
  122.    but instead should use the virtual terminal under which it was started */
  123. int inhibit_window_system;
  124.  
  125. /* If nonzero, set Emacs to run at this priority.  This is also used
  126.    in child_setup and sys_suspend to make sure subshells run at normal
  127.    priority; Those functions have their own extern declaration.  */
  128. int emacs_priority;
  129.  
  130. /* If non-zero a filter or a sentinel is running.  Tested to save the match
  131.    data on the first attempt to change it inside asynchronous code. */
  132. int running_asynch_code;
  133.  
  134. #ifdef BSD_PGRPS
  135. /* See sysdep.c.  */
  136. extern int inherited_pgroup;
  137. #endif
  138.  
  139. #ifdef HAVE_X_WINDOWS
  140. /* If non-zero, -d was specified, meaning we're using some window system. */
  141. int display_arg;
  142. #endif
  143.  
  144. /* An address near the bottom of the stack.
  145.    Tells GC how to save a copy of the stack.  */
  146. char *stack_bottom;
  147.  
  148. #ifdef HAVE_WINDOW_SYSTEM
  149. extern Lisp_Object Vwindow_system;
  150. #endif /* HAVE_WINDOW_SYSTEM */
  151.  
  152. extern Lisp_Object Vauto_save_list_file_name;
  153.  
  154. #ifdef USG_SHARED_LIBRARIES
  155. /* If nonzero, this is the place to put the end of the writable segment
  156.    at startup.  */
  157.  
  158. unsigned int bss_end = 0;
  159. #endif
  160.  
  161. /* Nonzero means running Emacs without interactive terminal.  */
  162.  
  163. int noninteractive;
  164.  
  165. /* Value of Lisp variable `noninteractive'.
  166.    Normally same as C variable `noninteractive'
  167.    but nothing terrible happens if user sets this one.  */
  168.  
  169. int noninteractive1;
  170.  
  171. /* Save argv and argc.  */
  172. char **initial_argv;
  173. int initial_argc;
  174.  
  175. static void sort_args ();
  176. void syms_of_emacs ();
  177.  
  178. /* Signal code for the fatal signal that was received */
  179. int fatal_error_code;
  180.  
  181. /* Nonzero if handling a fatal error already */
  182. int fatal_error_in_progress;
  183.  
  184. #ifdef SIGUSR1
  185. int SIGUSR1_in_progress=0;
  186. SIGTYPE
  187. handle_USR1_signal (sig)
  188.      int sig;
  189. {
  190.   if (! SIGUSR1_in_progress)
  191.     {
  192.       SIGUSR1_in_progress = 1;
  193.       
  194.       if (!NILP (Vrun_hooks) && !noninteractive)
  195.     call1 (Vrun_hooks, intern ("signal-USR1-hook"));
  196.       
  197.       SIGUSR1_in_progress = 0;
  198.     }
  199. }
  200.  
  201. #ifdef SIGUSR2
  202. int SIGUSR2_in_progress=0;
  203. SIGTYPE
  204. handle_USR2_signal (sig)
  205.      int sig;
  206. {
  207.   if (! SIGUSR2_in_progress)
  208.     {
  209.       SIGUSR2_in_progress = 1;
  210.       
  211.       if (!NILP (Vrun_hooks) && !noninteractive)
  212.     call1 (Vrun_hooks, intern ("signal-USR2-hook"));
  213.       
  214.       SIGUSR2_in_progress = 0;
  215.     }
  216. }
  217. #endif
  218. #endif 
  219.  
  220. /* Handle bus errors, illegal instruction, etc. */
  221. SIGTYPE
  222. fatal_error_signal (sig)
  223.      int sig;
  224. {
  225.   fatal_error_code = sig;
  226.   signal (sig, SIG_DFL);
  227.  
  228.   TOTALLY_UNBLOCK_INPUT;
  229.  
  230.   /* If fatal error occurs in code below, avoid infinite recursion.  */
  231.   if (! fatal_error_in_progress)
  232.     {
  233.       fatal_error_in_progress = 1;
  234.  
  235.       shut_down_emacs (sig, 0, Qnil);
  236.     }
  237.  
  238. #ifdef EMX
  239.   /* Simply returning will cause a core dump for fatal signals; that's
  240.      what we want.  If we called kill(), the core dump would not be
  241.      very helpful, because the stack backtrace would not work (we are
  242.      in a signal handler!).  On the other hand, SIGKILL is sent by
  243.      another process and we don't want to continue after delivery of
  244.      SIGKILL. */
  245. #ifndef POSIX_SIGNALS
  246.   signal (fatal_error_code, SIG_ACK);
  247. #endif
  248.   if (fatal_error_code != SIGKILL && fatal_error_code != SIGTERM)
  249.     return;
  250. #endif /* EMX */
  251. #ifdef VMS
  252.   LIB$STOP (SS$_ABORT);
  253. #else
  254.   /* Signal the same code; this time it will really be fatal.
  255.      Remember that since we're in a signal handler, the signal we're
  256.      going to send is probably blocked, so we have to unblock it if we
  257.      want to really receive it.  */
  258. #ifndef MSDOS
  259.   sigunblock (sigmask (fatal_error_code));
  260. #endif
  261.   kill (getpid (), fatal_error_code);
  262. #endif /* not VMS */
  263. }
  264.  
  265. #ifdef EMX
  266. SIGTYPE
  267. break_signal (sig)
  268.      int sig;
  269. {
  270. #ifndef POSIX_SIGNALS
  271.   signal (sig, SIG_ACK);
  272. #endif
  273.   Vquit_flag = Qt;
  274.   raise (SIGINT);
  275. }
  276. #endif /* EMX */
  277.  
  278. #ifdef SIGDANGER
  279.  
  280. /* Handler for SIGDANGER.  */
  281. SIGTYPE
  282. memory_warning_signal (sig)
  283.      int sig;
  284. {
  285.   signal (sig, memory_warning_signal);
  286.  
  287.   malloc_warning ("Operating system warns that virtual memory is running low.\n");
  288.  
  289.   /* It might be unsafe to call do_auto_save now.  */
  290.   force_auto_save_soon ();
  291. }
  292. #endif
  293.  
  294. /* We define abort, rather than using it from the library,
  295.    so that GDB can return from a breakpoint here.
  296.    MSDOS has its own definition on msdos.c  */
  297.  
  298. #if ! defined (DOS_NT) && ! defined (NO_ABORT)
  299. void
  300. abort ()
  301. {
  302.   kill (getpid (), SIGABRT);
  303.   /* This shouldn't be executed, but it prevents a warning.  */
  304.   exit (1);
  305. }
  306. #endif
  307.  
  308.  
  309. /* Code for dealing with Lisp access to the Unix command line */
  310.  
  311. static void
  312. init_cmdargs (argc, argv, skip_args)
  313.      int argc;
  314.      char **argv;
  315.      int skip_args;
  316. {
  317.   register int i;
  318.   Lisp_Object name, dir, tem;
  319.   int count = specpdl_ptr - specpdl;
  320.   Lisp_Object raw_name;
  321.  
  322.   initial_argv = argv;
  323.   initial_argc = argc;
  324.  
  325.   raw_name = build_string (argv[0]);
  326.  
  327.   /* Add /: to the front of the name
  328.      if it would otherwise be treated as magic.  */
  329.   tem = Ffind_file_name_handler (raw_name, Qt);
  330.   if (! NILP (tem))
  331.     raw_name = concat2 (build_string ("/:"), raw_name);
  332.  
  333.   Vinvocation_name = Ffile_name_nondirectory (raw_name);
  334.   Vinvocation_directory = Ffile_name_directory (raw_name);
  335.  
  336.   /* If we got no directory in argv[0], search PATH to find where
  337.      Emacs actually came from.  */
  338.   if (NILP (Vinvocation_directory))
  339.     {
  340.       Lisp_Object found;
  341.       int yes = openp (Vexec_path, Vinvocation_name,
  342.                EXEC_SUFFIXES, &found, 1);
  343.       if (yes == 1)
  344.     {
  345.       /* Add /: to the front of the name
  346.          if it would otherwise be treated as magic.  */
  347.       tem = Ffind_file_name_handler (found, Qt);
  348.       if (! NILP (tem))
  349.         found = concat2 (build_string ("/:"), found);
  350.       Vinvocation_directory = Ffile_name_directory (found);
  351.     }
  352.     }
  353.  
  354.   if (!NILP (Vinvocation_directory)
  355.       && NILP (Ffile_name_absolute_p (Vinvocation_directory)))
  356.     /* Emacs was started with relative path, like ./emacs.
  357.        Make it absolute.  */
  358.     Vinvocation_directory = Fexpand_file_name (Vinvocation_directory, Qnil);
  359.  
  360.   Vinstallation_directory = Qnil;
  361.  
  362.   if (!NILP (Vinvocation_directory))
  363.     {
  364.       dir = Vinvocation_directory;
  365.       name = Fexpand_file_name (Vinvocation_name, dir);
  366.       while (1)
  367.     {
  368.       Lisp_Object tem, lib_src_exists;
  369.       Lisp_Object etc_exists, info_exists;
  370.  
  371.       /* See if dir contains subdirs for use by Emacs.
  372.          Check for the ones that would exist in a build directory,
  373.          not including lisp and info.  */
  374.       tem = Fexpand_file_name (build_string ("lib-src"), dir);
  375.       lib_src_exists = Ffile_exists_p (tem);
  376.  
  377. #ifdef MSDOS
  378.       /* MSDOS installations frequently remove lib-src, but we still
  379.          must set installation-directory, or else info won't find
  380.          its files (it uses the value of installation-directory).  */
  381.       tem = Fexpand_file_name (build_string ("info"), dir);
  382.       info_exists = Ffile_exists_p (tem);
  383. #else
  384.       info_exists = Qnil;
  385. #endif
  386.  
  387.       if (!NILP (lib_src_exists) || !NILP (info_exists))
  388.         {
  389.           tem = Fexpand_file_name (build_string ("etc"), dir);
  390.           etc_exists = Ffile_exists_p (tem);
  391.           if (!NILP (etc_exists))
  392.         {
  393.           Vinstallation_directory
  394.             = Ffile_name_as_directory (dir);
  395.           break;
  396.         }
  397.         }
  398.  
  399.       /* See if dir's parent contains those subdirs.  */
  400.       tem = Fexpand_file_name (build_string ("../lib-src"), dir);
  401.       lib_src_exists = Ffile_exists_p (tem);
  402.  
  403.  
  404. #ifdef MSDOS
  405.       /* See the MSDOS commentary above.  */
  406.       tem = Fexpand_file_name (build_string ("../info"), dir);
  407.       info_exists = Ffile_exists_p (tem);
  408. #else
  409.       info_exists = Qnil;
  410. #endif
  411.  
  412.       if (!NILP (lib_src_exists) || !NILP (info_exists))
  413.         {
  414.           tem = Fexpand_file_name (build_string ("../etc"), dir);
  415.           etc_exists = Ffile_exists_p (tem);
  416.           if (!NILP (etc_exists))
  417.         {
  418.           tem = Fexpand_file_name (build_string (".."), dir);
  419.           Vinstallation_directory
  420.             = Ffile_name_as_directory (tem);
  421.           break;
  422.         }
  423.         }
  424.  
  425.       /* If the Emacs executable is actually a link,
  426.          next try the dir that the link points into.  */
  427.       tem = Ffile_symlink_p (name);
  428.       if (!NILP (tem))
  429.         {
  430.           name = Fexpand_file_name (tem, dir);
  431.           dir = Ffile_name_directory (name);
  432.         }
  433.       else
  434.         break;
  435.     }
  436.     }
  437.  
  438.   Vcommand_line_args = Qnil;
  439.  
  440.   for (i = argc - 1; i >= 0; i--)
  441.     {
  442.       if (i == 0 || i > skip_args)
  443.     Vcommand_line_args
  444.       = Fcons (build_string (argv[i]), Vcommand_line_args);
  445.     }
  446.  
  447.   unbind_to (count, Qnil);
  448. }
  449.  
  450. DEFUN ("invocation-name", Finvocation_name, Sinvocation_name, 0, 0, 0,
  451.   "Return the program name that was used to run Emacs.\n\
  452. Any directory names are omitted.")
  453.   ()
  454. {
  455.   return Fcopy_sequence (Vinvocation_name);
  456. }
  457.  
  458. DEFUN ("invocation-directory", Finvocation_directory, Sinvocation_directory,
  459.   0, 0, 0,
  460.   "Return the directory name in which the Emacs executable was located")
  461.   ()
  462. {
  463.   return Fcopy_sequence (Vinvocation_directory);
  464. }
  465.  
  466.  
  467. #ifdef VMS
  468. #ifdef LINK_CRTL_SHARE
  469. #ifdef SHARABLE_LIB_BUG
  470. extern noshare char **environ;
  471. #endif /* SHARABLE_LIB_BUG */
  472. #endif /* LINK_CRTL_SHARE */
  473. #endif /* VMS */
  474.  
  475. #ifdef HAVE_TZSET
  476. /* A valid but unlikely value for the TZ environment value.
  477.    It is OK (though a bit slower) if the user actually chooses this value.  */
  478. static char dump_tz[] = "UtC0";
  479. #endif
  480.  
  481. #ifndef ORDINARY_LINK
  482. /* We don't include crtbegin.o and crtend.o in the link,
  483.    so these functions and variables might be missed.
  484.    Provide dummy definitions to avoid error.
  485.    (We don't have any real constructors or destructors.)  */
  486. #ifdef __GNUC__
  487. #ifndef GCC_CTORS_IN_LIBC
  488. void __do_global_ctors ()
  489. {}
  490. void __do_global_ctors_aux ()
  491. {}
  492. void __do_global_dtors ()
  493. {}
  494. /* Linux has a bug in its library; avoid an error.  */
  495. #ifndef LINUX
  496. char * __CTOR_LIST__[2] = { (char *) (-1), 0 };
  497. #endif
  498. char * __DTOR_LIST__[2] = { (char *) (-1), 0 };
  499. #endif /* GCC_CTORS_IN_LIBC */
  500. void __main ()
  501. {}
  502. #endif /* __GNUC__ */
  503. #endif /* ORDINARY_LINK */
  504.  
  505. /* Test whether the next argument in ARGV matches SSTR or a prefix of
  506.    LSTR (at least MINLEN characters).  If so, then if VALPTR is non-null
  507.    (the argument is supposed to have a value) store in *VALPTR either
  508.    the next argument or the portion of this one after the equal sign.
  509.    ARGV is read starting at position *SKIPPTR; this index is advanced
  510.    by the number of arguments used.
  511.  
  512.    Too bad we can't just use getopt for all of this, but we don't have
  513.    enough information to do it right.  */
  514.  
  515. static int
  516. argmatch (argv, argc, sstr, lstr, minlen, valptr, skipptr)
  517.      char **argv;
  518.      int argc;
  519.      char *sstr;
  520.      char *lstr;
  521.      int minlen;
  522.      char **valptr;
  523.      int *skipptr;
  524. {
  525.   char *p;
  526.   int arglen;
  527.   char *arg;
  528.  
  529.   /* Don't access argv[argc]; give up in advance.  */
  530.   if (argc <= *skipptr + 1)
  531.     return 0;
  532.  
  533.   arg = argv[*skipptr+1];
  534.   if (arg == NULL)
  535.     return 0;
  536.   if (strcmp (arg, sstr) == 0)
  537.     {
  538.       if (valptr != NULL)
  539.     {
  540.       *valptr = argv[*skipptr+2];
  541.       *skipptr += 2;
  542.     }
  543.       else
  544.     *skipptr += 1;
  545.       return 1;
  546.     }
  547.   arglen = (valptr != NULL && (p = index (arg, '=')) != NULL
  548.         ? p - arg : strlen (arg));
  549.   if (lstr == 0 || arglen < minlen || strncmp (arg, lstr, arglen) != 0)
  550.     return 0;
  551.   else if (valptr == NULL)
  552.     {
  553.       *skipptr += 1;
  554.       return 1;
  555.     }
  556.   else if (p != NULL)
  557.     {
  558.       *valptr = p+1;
  559.       *skipptr += 1;
  560.       return 1;
  561.     }
  562.   else if (argv[*skipptr+2] != NULL)
  563.     {
  564.       *valptr = argv[*skipptr+2];
  565.       *skipptr += 2;
  566.       return 1;
  567.     }
  568.   else
  569.     {
  570.       return 0;
  571.     }
  572. }
  573.  
  574. /* ARGSUSED */
  575. int
  576. main (argc, argv, envp)
  577.      int argc;
  578.      char **argv;
  579.      char **envp;
  580. {
  581.   char stack_bottom_variable;
  582.   int skip_args = 0;
  583.   extern int errno;
  584.   extern int sys_nerr;
  585. #ifdef HAVE_SETRLIMIT
  586.   struct rlimit rlim;
  587. #endif
  588.   int no_loadup = 0;
  589.  
  590. #ifdef EMX
  591.     /* Expand wildcards on the command line. */
  592.     _wildcard (&argc, &argv);
  593. #endif /* EMX */
  594.  
  595. #ifdef LINUX_SBRK_BUG
  596.   __sbrk (1);
  597. #endif
  598.  
  599. #ifdef DOUG_LEA_MALLOC
  600.   if (initialized)
  601.     {
  602.       extern void r_alloc_reinit ();
  603.       malloc_set_state (malloc_state_ptr);
  604.       free (malloc_state_ptr);
  605.       r_alloc_reinit ();
  606.     }
  607. #endif
  608.  
  609. #ifdef RUN_TIME_REMAP
  610.   if (initialized)
  611.     run_time_remap (argv[0]);
  612. #endif
  613.  
  614.   sort_args (argc, argv);
  615.   argc = 0;
  616.   while (argv[argc]) argc++;
  617.  
  618.   if (argmatch (argv, argc, "-version", "--version", 3, NULL, &skip_args)
  619.       /* We don't know the version number unless this is a dumped Emacs.
  620.          So ignore --version otherwise.  */
  621.       && initialized)
  622.     {
  623.       Lisp_Object tem;
  624.       tem = Fsymbol_value (intern ("emacs-version"));
  625.       if (!STRINGP (tem))
  626.     {
  627.       fprintf (stderr, "Invalid value of `emacs-version'\n");
  628.       exit (1);
  629.     }
  630.       else
  631.     {
  632.       printf ("GNU Emacs %s\n", XSTRING (tem)->data);
  633.       printf ("Copyright (C) 1998 Free Software Foundation, Inc.\n");
  634.       printf ("GNU Emacs comes with ABSOLUTELY NO WARRANTY.\n");
  635.       printf ("You may redistribute copies of Emacs\n");
  636.       printf ("under the terms of the GNU General Public License.\n");
  637.       printf ("For more information about these matters, ");
  638.       printf ("see the file named COPYING.\n");
  639.       exit (0);
  640.     }
  641.     }
  642.  
  643. /* Map in shared memory, if we are using that.  */
  644. #ifdef HAVE_SHM
  645.   if (argmatch (argv, argc, "-nl", "--no-shared-memory", 6, NULL, &skip_args))
  646.     {
  647.       map_in_data (0);
  648.       /* The shared memory was just restored, which clobbered this.  */
  649.       skip_args = 1;
  650.     }
  651.   else
  652.     {
  653.       map_in_data (1);
  654.       /* The shared memory was just restored, which clobbered this.  */
  655.       skip_args = 0;
  656.     }
  657. #endif
  658.  
  659. #ifdef NeXT
  660.   {
  661.     extern int malloc_cookie;
  662.     /* This helps out unexnext.c.  */
  663.     if (initialized)
  664.       if (malloc_jumpstart (malloc_cookie) != 0)
  665.     printf ("malloc jumpstart failed!\n");
  666.   }
  667. #endif /* NeXT */
  668.     
  669. #ifdef EMX
  670.     emx_setup ();
  671.     _nls_init ();                 /* Call before emx_exec_name! */
  672.     emx_exec_name (&argv[0]);
  673. #endif /* EMX */
  674. #ifdef VMS
  675.   /* If -map specified, map the data file in */
  676.   {
  677.     char *file;
  678.     if (argmatch (argv, argc, "-map", "--map-data", 3, &mapin_file, &skip_args))
  679.       mapin_data (file);
  680.   }
  681.  
  682. #ifdef LINK_CRTL_SHARE
  683. #ifdef SHARABLE_LIB_BUG
  684.   /* Bletcherous shared libraries! */
  685.   if (!stdin)
  686.     stdin = fdopen (0, "r");
  687.   if (!stdout)
  688.     stdout = fdopen (1, "w");
  689.   if (!stderr)
  690.     stderr = fdopen (2, "w");
  691.   if (!environ)
  692.     environ = envp;
  693. #endif /* SHARABLE_LIB_BUG */
  694. #endif /* LINK_CRTL_SHARE */
  695. #endif /* VMS */
  696.  
  697. #if defined (HAVE_SETRLIMIT) && defined (RLIMIT_STACK)
  698.   /* Extend the stack space available.
  699.      Don't do that if dumping, since some systems (e.g. DJGPP)
  700.      might define a smaller stack limit at that time.  */
  701.   if (1
  702. #ifndef CANNOT_DUMP
  703.       && (!noninteractive || initialized)
  704. #endif
  705.       && !getrlimit (RLIMIT_STACK, &rlim))
  706.     {
  707.       long newlim;
  708.       extern int re_max_failures;
  709.       /* Approximate the amount regex.c needs per unit of re_max_failures.  */
  710.       int ratio = 20 * sizeof (char *);
  711.       /* Then add 33% to cover the size of the smaller stacks that regex.c
  712.      successively allocates and discards, on its way to the maximum.  */
  713.       ratio += ratio / 3;
  714.       /* Add in some extra to cover
  715.      what we're likely to use for other reasons.  */
  716.       newlim = re_max_failures * ratio + 200000;
  717. #ifdef __NetBSD__
  718.       /* NetBSD (at least NetBSD 1.2G and former) has a bug in its
  719.        stack allocation routine for new process that the allocation
  720.        fails if stack limit is not on page boundary.  So, round up the
  721.        new limit to page boundary.  */
  722.       newlim = (newlim + getpagesize () - 1) / getpagesize () * getpagesize();
  723. #endif
  724.       if (newlim > rlim.rlim_max)
  725.     {
  726.       newlim = rlim.rlim_max;
  727.       /* Don't let regex.c overflow the stack we have.  */
  728.       re_max_failures = (newlim - 200000) / ratio;
  729.     }
  730.       if (rlim.rlim_cur < newlim)
  731.     rlim.rlim_cur = newlim;
  732.  
  733.       setrlimit (RLIMIT_STACK, &rlim);
  734.     }
  735. #endif /* HAVE_SETRLIMIT and RLIMIT_STACK */
  736.  
  737.   /* Record (approximately) where the stack begins.  */
  738.   stack_bottom = &stack_bottom_variable;
  739.  
  740. #ifdef USG_SHARED_LIBRARIES
  741.   if (bss_end)
  742.     brk ((void *)bss_end);
  743. #endif
  744.  
  745.   clearerr (stdin);
  746.  
  747. #ifndef SYSTEM_MALLOC
  748.   if (! initialized)
  749.     {
  750.       /* Arrange to get warning messages as memory fills up.  */
  751.       memory_warnings (0, malloc_warning);
  752.  
  753.       /* Arrange to disable interrupt input while malloc and friends are
  754.      running.  */
  755.       uninterrupt_malloc ();
  756.     }
  757. #endif    /* not SYSTEM_MALLOC */
  758.  
  759. #ifdef MSDOS
  760.   /* We do all file input/output as binary files.  When we need to translate
  761.      newlines, we do that manually.  */
  762.   _fmode = O_BINARY;
  763.  
  764. #if __DJGPP__ >= 2
  765.   if (!isatty (fileno (stdin)))
  766.     setmode (fileno (stdin), O_BINARY);
  767.   if (!isatty (fileno (stdout)))
  768.     {
  769.       fflush (stdout);
  770.       setmode (fileno (stdout), O_BINARY);
  771.     }
  772. #else  /* not __DJGPP__ >= 2 */
  773.   (stdin)->_flag &= ~_IOTEXT;
  774.   (stdout)->_flag &= ~_IOTEXT;
  775.   (stderr)->_flag &= ~_IOTEXT;
  776. #endif /* not __DJGPP__ >= 2 */
  777. #endif /* MSDOS */
  778.  
  779. #ifdef SET_EMACS_PRIORITY
  780.   if (emacs_priority)
  781.     nice (emacs_priority);
  782.   setuid (getuid ());
  783. #endif /* SET_EMACS_PRIORITY */
  784.  
  785. #ifdef EXTRA_INITIALIZE
  786.   EXTRA_INITIALIZE;
  787. #endif
  788.  
  789.   inhibit_window_system = 0;
  790.  
  791.   /* Handle the -t switch, which specifies filename to use as terminal */
  792.   while (1)
  793.     {
  794.       char *term;
  795.       if (argmatch (argv, argc, "-t", "--terminal", 4, &term, &skip_args))
  796.     {
  797.       int result;
  798.       close (0);
  799.       close (1);
  800.       result = open (term, O_RDWR, 2 );
  801.       if (result < 0)
  802.         {
  803.           char *errstring = strerror (errno);
  804.           fprintf (stderr, "emacs: %s: %s\n", term, errstring);
  805.           exit (1);
  806.         }
  807.       dup (0);
  808.       if (! isatty (0))
  809.         {
  810.           fprintf (stderr, "emacs: %s: not a tty\n", term);
  811.           exit (1);
  812.         }
  813.       fprintf (stderr, "Using %s\n", term);
  814. #ifdef HAVE_WINDOW_SYSTEM
  815.       inhibit_window_system = 1; /* -t => -nw */
  816. #endif
  817.     }
  818.       else
  819.     break;
  820.     }
  821.  
  822.   if (argmatch (argv, argc, "-nw", "--no-windows", 6, NULL, &skip_args))
  823.     inhibit_window_system = 1;
  824.  
  825.   /* Handle the -batch switch, which means don't do interactive display.  */
  826.   noninteractive = 0;
  827.   if (argmatch (argv, argc, "-batch", "--batch", 5, NULL, &skip_args))
  828.     noninteractive = 1;
  829.  
  830.   /* Handle the --help option, which gives a usage message..  */
  831.   if (argmatch (argv, argc, "-help", "--help", 3, NULL, &skip_args))
  832.     {
  833.       printf ("\
  834. Usage: %s [-t term] [--terminal term]  [-nw] [--no-windows]  [--batch]\n\
  835.       [-q] [--no-init-file]  [-u user] [--user user]  [--debug-init]\n\
  836.       [--unibyte] [--multibyte] [--version] [--no-site-file]\n\
  837.       [-f func] [--funcall func]  [-l file] [--load file]  [--insert file]\n\
  838.       [+linenum] file-to-visit  [--kill]\n\
  839. Report bugs to bug-gnu-emacs@gnu.org.  First, please see\n\
  840. the Bugs section of the Emacs manual or the file BUGS.\n", argv[0]);
  841.       exit (0);
  842.     }
  843.  
  844. #ifdef HAVE_PM
  845.     if (argmatch (argv, argc, "-pm", "--pm", 4, NULL, &skip_args))
  846.         display_arg = 1;
  847. #endif /* HAVE_PM */
  848.  
  849. #ifdef HAVE_X_WINDOWS
  850.     /* Stupid kludge to catch command-line display spec.  We can't
  851.        handle this argument entirely in window system dependent code
  852.        because we don't even know which window system dependent code
  853.        to run until we've recognized this argument.  */
  854.     {
  855.         char *displayname = 0;
  856.         int i;
  857.         int count_before = skip_args;
  858.  
  859.         if (argmatch (argv, argc, "-d", "--display", 3, &displayname, &skip_args))
  860.             display_arg = 1;
  861.         else if (argmatch (argv, argc, "-display", 0, 3, &displayname, &skip_args))
  862.             display_arg = 1;
  863.  
  864.         /* If we have the form --display=NAME,
  865.            convert it into  -d name.
  866.            This requires inserting a new element into argv.  */
  867.         if (displayname != 0 && skip_args - count_before == 1)
  868.         {
  869.             char **new = (char **) xmalloc (sizeof (char *) * (argc + 2));
  870.             int j;
  871.  
  872.             for (j = 0; j < count_before + 1; j++)
  873.                 new[j] = argv[j];
  874.             new[count_before + 1] = "-d";
  875.             new[count_before + 2] = displayname;
  876.             for (j = count_before + 2; j <argc; j++)
  877.                 new[j + 1] = argv[j];
  878.             argv = new;
  879.             argc++;
  880.         }
  881.         /* Change --display to -d, when its arg is separate.  */
  882.         else if (displayname != 0 && skip_args > count_before
  883.                  && argv[count_before + 1][1] == '-')
  884.             argv[count_before + 1] = "-d";
  885.  
  886.         /* Don't actually discard this arg.  */
  887.         skip_args = count_before;
  888.     }
  889. #endif
  890.  
  891. #ifdef EMX
  892.  if (!display_arg || inhibit_window_system)
  893.  {
  894.      static char pid[40];
  895.  
  896.      sprintf (pid, "EMACS_PID=%d", getpid ());
  897.      putenv (pid);
  898.  }
  899. #endif /* EMX */
  900.  
  901.  if (! noninteractive)
  902.  {
  903. #ifdef BSD_PGRPS
  904.       if (initialized)
  905.     {
  906.       inherited_pgroup = EMACS_GETPGRP (0);
  907.       setpgrp (0, getpid ());
  908.     }
  909. #else
  910. #if defined (USG5) && defined (INTERRUPT_INPUT)
  911.       setpgrp ();
  912. #endif
  913. #endif
  914.     }
  915.  
  916. #ifdef POSIX_SIGNALS
  917.   init_signals ();
  918. #endif
  919.  
  920.   /* Don't catch SIGHUP if dumping.  */
  921.   if (1
  922. #ifndef CANNOT_DUMP
  923.       && initialized
  924. #endif
  925.       )
  926.     {
  927.       sigblock (sigmask (SIGHUP));
  928.       /* In --batch mode, don't catch SIGHUP if already ignored.
  929.      That makes nohup work.  */
  930.       if (! noninteractive
  931.       || signal (SIGHUP, SIG_IGN) != SIG_IGN)
  932.     signal (SIGHUP, fatal_error_signal);
  933.       sigunblock (sigmask (SIGHUP));
  934.     }
  935.  
  936.   if (
  937. #ifndef CANNOT_DUMP
  938.       ! noninteractive || initialized
  939. #else
  940.       1
  941. #endif
  942.       )
  943.     {
  944.       /* Don't catch these signals in batch mode if dumping.
  945.      On some machines, this sets static data that would make
  946.      signal fail to work right when the dumped Emacs is run.  */
  947.       signal (SIGQUIT, fatal_error_signal);
  948.       signal (SIGILL, fatal_error_signal);
  949.       signal (SIGTRAP, fatal_error_signal);
  950. #ifdef SIGUSR1
  951.       signal (SIGUSR1, handle_USR1_signal);
  952. #ifdef SIGUSR2
  953.       signal (SIGUSR2, handle_USR2_signal);
  954. #endif
  955. #endif
  956. #ifdef SIGABRT
  957.       signal (SIGABRT, fatal_error_signal);
  958. #endif
  959. #ifdef SIGHWE
  960.       signal (SIGHWE, fatal_error_signal);
  961. #endif
  962. #ifdef SIGPRE
  963.       signal (SIGPRE, fatal_error_signal);
  964. #endif
  965. #ifdef SIGORE
  966.       signal (SIGORE, fatal_error_signal);
  967. #endif
  968. #ifdef SIGUME
  969.       signal (SIGUME, fatal_error_signal);
  970. #endif
  971. #ifdef SIGDLK
  972.       signal (SIGDLK, fatal_error_signal);
  973. #endif
  974. #ifdef SIGCPULIM
  975.       signal (SIGCPULIM, fatal_error_signal);
  976. #endif
  977. #ifdef SIGIOT
  978.       /* This is missing on some systems - OS/2, for example.  */
  979.       signal (SIGIOT, fatal_error_signal);
  980. #endif
  981. #ifdef SIGEMT
  982.       signal (SIGEMT, fatal_error_signal);
  983. #endif
  984.       signal (SIGFPE, fatal_error_signal);
  985. #ifdef SIGBUS
  986.       signal (SIGBUS, fatal_error_signal);
  987. #endif
  988.       signal (SIGSEGV, fatal_error_signal);
  989. #ifdef SIGSYS
  990.       signal (SIGSYS, fatal_error_signal);
  991. #endif
  992.       signal (SIGTERM, fatal_error_signal);
  993. #ifdef SIGXCPU
  994.       signal (SIGXCPU, fatal_error_signal);
  995. #endif
  996. #ifdef SIGXFSZ
  997.       signal (SIGXFSZ, fatal_error_signal);
  998. #endif /* SIGXFSZ */
  999.  
  1000. #ifdef SIGDANGER
  1001.       /* This just means available memory is getting low.  */
  1002.       signal (SIGDANGER, memory_warning_signal);
  1003. #endif
  1004.  
  1005. #ifdef AIX
  1006. /* 20 is SIGCHLD, 21 is SIGTTIN, 22 is SIGTTOU.  */
  1007.       signal (SIGXCPU, fatal_error_signal);
  1008. #ifndef _I386
  1009.       signal (SIGIOINT, fatal_error_signal);
  1010. #endif
  1011.       signal (SIGGRANT, fatal_error_signal);
  1012.       signal (SIGRETRACT, fatal_error_signal);
  1013.       signal (SIGSOUND, fatal_error_signal);
  1014.       signal (SIGMSG, fatal_error_signal);
  1015. #endif /* AIX */
  1016. #ifdef EMX
  1017.       signal (SIGBREAK, break_signal);
  1018. #endif /* EMX */
  1019.     }
  1020.  
  1021.   noninteractive1 = noninteractive;
  1022.  
  1023. /* Perform basic initializations (not merely interning symbols) */
  1024.  
  1025.   if (!initialized)
  1026.     {
  1027.       init_alloc_once ();
  1028.       init_obarray ();
  1029.       init_eval_once ();
  1030.       init_charset_once ();
  1031.       init_coding_once ();
  1032.       init_syntax_once ();    /* Create standard syntax table.  */
  1033.       init_category_once ();    /* Create standard category table.  */
  1034.               /* Must be done before init_buffer */
  1035.       init_casetab_once ();
  1036.       init_buffer_once ();    /* Create buffer table and some buffers */
  1037.       init_minibuf_once ();    /* Create list of minibuffers */
  1038.                   /* Must precede init_window_once */
  1039.       init_window_once ();    /* Init the window system */
  1040.     }
  1041.  
  1042.   init_alloc ();
  1043.   init_eval ();
  1044.   init_coding ();
  1045.   init_data ();
  1046.   running_asynch_code = 0;
  1047.  
  1048.   /* Handle --unibyte and the EMACS_UNIBYTE envvar,
  1049.      but not while dumping.  */
  1050.   if (
  1051. #ifndef CANNOT_DUMP
  1052.       ! noninteractive || initialized
  1053. #else
  1054.       1
  1055. #endif
  1056.       )
  1057.     {
  1058.       int inhibit_unibyte = 0;
  1059.  
  1060.       /* --multibyte overrides EMACS_UNIBYTE.  */
  1061.       if (argmatch (argv, argc, "-no-unibyte", "--no-unibyte", 4, NULL, &skip_args)
  1062.       || argmatch (argv, argc, "-multibyte", "--multibyte", 4, NULL, &skip_args))
  1063.     inhibit_unibyte = 1;
  1064.  
  1065.       /* --unibyte requests that we set up to do everything with single-byte
  1066.      buffers and strings.  We need to handle this before calling
  1067.      init_lread, init_editfns and other places that generate Lisp strings
  1068.      from text in the environment.  */
  1069.       if (argmatch (argv, argc, "-unibyte", "--unibyte", 4, NULL, &skip_args)
  1070.       || argmatch (argv, argc, "-no-multibyte", "--no-multibyte", 4, NULL, &skip_args)
  1071.       || (getenv ("EMACS_UNIBYTE") && !inhibit_unibyte))
  1072.     {
  1073.       Lisp_Object old_log_max;
  1074.       Lisp_Object symbol, tail;
  1075.  
  1076.       symbol = intern ("default-enable-multibyte-characters");
  1077.       Fset (symbol, Qnil);
  1078.  
  1079.       if (initialized)
  1080.         {
  1081.           /* Erase pre-dump messages in *Messages* now so no abort.  */
  1082.           old_log_max = Vmessage_log_max;
  1083.           XSETFASTINT (Vmessage_log_max, 0);
  1084.           message_dolog ("", 0, 1, 0);
  1085.           Vmessage_log_max = old_log_max;
  1086.         }
  1087.  
  1088.       for (tail = Vbuffer_alist; CONSP (tail);
  1089.            tail = XCONS (tail)->cdr)
  1090.         {
  1091.           Lisp_Object buffer;
  1092.  
  1093.           buffer = Fcdr (XCONS (tail)->car);
  1094.           /* Verify that all buffers are empty now, as they
  1095.          ought to be.  */
  1096.           if (BUF_Z (XBUFFER (buffer)) > BUF_BEG (XBUFFER (buffer)))
  1097.         abort ();
  1098.           /* It is safe to do this crudely in an empty buffer.  */
  1099.           XBUFFER (buffer)->enable_multibyte_characters = Qnil;
  1100.         }
  1101.     }
  1102.     }
  1103.  
  1104.   no_loadup
  1105.     = !argmatch (argv, argc, "-nl", "--no-loadup", 6, NULL, &skip_args);
  1106.  
  1107.  
  1108. #ifdef HAVE_X_WINDOWS
  1109.   /* Stupid kludge to catch command-line display spec.  We can't
  1110.      handle this argument entirely in window system dependent code
  1111.      because we don't even know which window system dependent code
  1112.      to run until we've recognized this argument.  */
  1113.   {
  1114.     char *displayname = 0;
  1115.     int i;
  1116.     int count_before = skip_args;
  1117.  
  1118.     /* Skip any number of -d options, but only use the last one.  */
  1119.     while (1)
  1120.       {
  1121.     int count_before_this = skip_args;
  1122.  
  1123.     if (argmatch (argv, argc, "-d", "--display", 3, &displayname, &skip_args))
  1124.       display_arg = 1;
  1125.     else if (argmatch (argv, argc, "-display", 0, 3, &displayname, &skip_args))
  1126.       display_arg = 1;
  1127.     else
  1128.       break;
  1129.  
  1130.     count_before = count_before_this;
  1131.       }
  1132.  
  1133.     /* If we have the form --display=NAME,
  1134.        convert it into  -d name.
  1135.        This requires inserting a new element into argv.  */
  1136.     if (displayname != 0 && skip_args - count_before == 1)
  1137.       {
  1138.     char **new = (char **) xmalloc (sizeof (char *) * (argc + 2));
  1139.     int j;
  1140.  
  1141.     for (j = 0; j < count_before + 1; j++)
  1142.       new[j] = argv[j];
  1143.     new[count_before + 1] = "-d";
  1144.     new[count_before + 2] = displayname;
  1145.     for (j = count_before + 2; j <argc; j++)
  1146.       new[j + 1] = argv[j];
  1147.     argv = new;
  1148.     argc++;
  1149.       }
  1150.     /* Change --display to -d, when its arg is separate.  */
  1151.     else if (displayname != 0 && skip_args > count_before
  1152.          && argv[count_before + 1][1] == '-')
  1153.       argv[count_before + 1] = "-d";
  1154.  
  1155.     /* Don't actually discard this arg.  */
  1156.     skip_args = count_before;
  1157.   }
  1158. #endif
  1159.  
  1160.   /* argmatch must not be used after here,
  1161.      except when bulding temacs
  1162.      because the -d argument has not been skipped in skip_args.  */
  1163.  
  1164. #ifdef MSDOS
  1165.   /* Call early 'cause init_environment needs it.  */
  1166.   init_dosfns ();
  1167.   /* Set defaults for several environment variables.  */
  1168.   if (initialized)
  1169.     init_environment (argc, argv, skip_args);
  1170.   else
  1171.     tzset ();
  1172. #endif /* MSDOS */
  1173.  
  1174. #ifdef WINDOWSNT
  1175.   /* Initialize environment from registry settings.  */
  1176.   init_environment ();
  1177.   init_ntproc ();    /* must precede init_editfns */
  1178. #endif
  1179.  
  1180.   /* egetenv is a pretty low-level facility, which may get called in
  1181.      many circumstances; it seems flimsy to put off initializing it
  1182.      until calling init_callproc.  */
  1183.   set_process_environment ();
  1184.   /* AIX crashes are reported in system versions 3.2.3 and 3.2.4
  1185.      if this is not done.  Do it after set_process_environment so that we
  1186.      don't pollute Vprocess_environment.  */
  1187. #ifdef AIX
  1188.   putenv ("LANG=C");
  1189. #endif
  1190.  
  1191.   init_buffer ();    /* Init default directory of main buffer */
  1192.  
  1193.   init_callproc_1 ();    /* Must precede init_cmdargs and init_sys_modes.  */
  1194.   init_cmdargs (argc, argv, skip_args);    /* Must precede init_lread.  */
  1195.  
  1196.   if (initialized)
  1197.     {
  1198.       /* Erase any pre-dump messages in the message log, to avoid confusion */
  1199.       Lisp_Object old_log_max;
  1200.       old_log_max = Vmessage_log_max;
  1201.       XSETFASTINT (Vmessage_log_max, 0);
  1202.       message_dolog ("", 0, 1, 0);
  1203.       Vmessage_log_max = old_log_max;
  1204.     }
  1205.  
  1206.   init_callproc ();    /* Must follow init_cmdargs but not init_sys_modes.  */
  1207.   init_lread ();
  1208.  
  1209.   /* Intern the names of all standard functions and variables;
  1210.      define standard keys.  */
  1211.  
  1212.   if (!initialized)
  1213.     {
  1214.       /* The basic levels of Lisp must come first */
  1215.       /* And data must come first of all
  1216.      for the sake of symbols like error-message */
  1217.       syms_of_data ();
  1218.       syms_of_alloc ();
  1219.       syms_of_lread ();
  1220.       syms_of_print ();
  1221.       syms_of_eval ();
  1222.       syms_of_fns ();
  1223.       syms_of_floatfns ();
  1224.  
  1225.       syms_of_abbrev ();
  1226.       syms_of_buffer ();
  1227.       syms_of_bytecode ();
  1228.       syms_of_callint ();
  1229.       syms_of_casefiddle ();
  1230.       syms_of_casetab ();
  1231.       syms_of_callproc ();
  1232.       syms_of_category ();
  1233.       syms_of_ccl ();
  1234.       syms_of_charset ();
  1235.       syms_of_cmds ();
  1236. #ifndef NO_DIR_LIBRARY
  1237.       syms_of_dired ();
  1238. #endif /* not NO_DIR_LIBRARY */
  1239.       syms_of_display ();
  1240.       syms_of_doc ();
  1241.       syms_of_editfns ();
  1242.       syms_of_emacs ();
  1243.       syms_of_fileio ();
  1244.       syms_of_coding ();    /* This should be after syms_of_fileio.  */
  1245. #ifdef CLASH_DETECTION
  1246.       syms_of_filelock ();
  1247. #endif /* CLASH_DETECTION */
  1248.       syms_of_indent ();
  1249.       syms_of_insdel ();
  1250.       syms_of_keyboard ();
  1251.       syms_of_keymap ();
  1252.       syms_of_macros ();
  1253.       syms_of_marker ();
  1254.       syms_of_minibuf ();
  1255.       syms_of_mocklisp ();
  1256.       syms_of_process ();
  1257.       syms_of_search ();
  1258.       syms_of_frame ();
  1259.       syms_of_syntax ();
  1260.       syms_of_term ();
  1261.       syms_of_undo ();
  1262.  
  1263.       /* Only defined if Emacs is compiled with USE_TEXT_PROPERTIES */
  1264.       syms_of_textprop ();
  1265. #ifdef VMS
  1266.       syms_of_vmsproc ();
  1267. #endif /* VMS */
  1268. #ifdef WINDOWSNT
  1269.       syms_of_ntproc ();
  1270. #endif /* WINDOWSNT */
  1271.       syms_of_window ();
  1272.       syms_of_xdisp ();
  1273. #ifdef HAVE_X_WINDOWS
  1274.       syms_of_xterm ();
  1275.       syms_of_xfns ();
  1276. #ifdef HAVE_PM
  1277.       syms_of_xfaces ();
  1278. #else
  1279.       syms_of_fontset ();
  1280. #endif
  1281. #ifdef HAVE_X11
  1282.       syms_of_xselect ();
  1283. #endif
  1284. #endif /* HAVE_X_WINDOWS */
  1285.  
  1286. #ifndef HAVE_NTGUI
  1287.       syms_of_xfaces ();
  1288.       syms_of_xmenu ();
  1289. #endif
  1290.  
  1291. #ifdef HAVE_NTGUI
  1292.       syms_of_w32term ();
  1293.       syms_of_w32fns ();
  1294.       syms_of_w32faces ();
  1295.       syms_of_w32select ();
  1296.       syms_of_w32menu ();
  1297. #endif /* HAVE_NTGUI */
  1298.  
  1299. #ifdef SYMS_SYSTEM
  1300.       SYMS_SYSTEM;
  1301. #endif
  1302.  
  1303. #ifdef SYMS_MACHINE
  1304.       SYMS_MACHINE;
  1305. #endif
  1306.  
  1307.       keys_of_casefiddle ();
  1308.       keys_of_cmds ();
  1309.       keys_of_buffer ();
  1310.       keys_of_keyboard ();
  1311.       keys_of_keymap ();
  1312.       keys_of_macros ();
  1313.       keys_of_minibuf ();
  1314.       keys_of_window ();
  1315.       keys_of_frame ();
  1316.     }
  1317.   
  1318.   
  1319.   if (!noninteractive)
  1320.     {
  1321. #ifdef VMS
  1322.       init_vms_input ();/* init_display calls get_frame_size, that needs this */
  1323. #endif /* VMS */
  1324.       init_display ();    /* Determine terminal type.  init_sys_modes uses results */
  1325.     }
  1326.   init_keyboard ();    /* This too must precede init_sys_modes */
  1327. #ifdef VMS
  1328.   init_vmsproc ();    /* And this too. */
  1329. #endif /* VMS */
  1330.   init_sys_modes ();    /* Init system terminal modes (RAW or CBREAK, etc.) */
  1331.   init_xdisp ();
  1332.   init_macros ();
  1333.   init_editfns ();
  1334. #ifdef LISP_FLOAT_TYPE
  1335.   init_floatfns ();
  1336. #endif
  1337. #ifdef VMS
  1338.   init_vmsfns ();
  1339. #endif /* VMS */
  1340.   init_process ();
  1341.  
  1342.   if (!initialized)
  1343.     {
  1344.       char *file;
  1345.       /* Handle -l loadup, args passed by Makefile. */
  1346.       if (argmatch (argv, argc, "-l", "--load", 3, &file, &skip_args))
  1347.     Vtop_level = Fcons (intern ("load"),
  1348.                 Fcons (build_string (file), Qnil));
  1349. #ifdef CANNOT_DUMP
  1350.       /* Unless next switch is -nl, load "loadup.el" first thing.  */
  1351.       if (! no_loadup)
  1352.     Vtop_level = Fcons (intern ("load"),
  1353.                 Fcons (build_string ("loadup.el"), Qnil));
  1354. #endif /* CANNOT_DUMP */
  1355.     }
  1356.  
  1357.   if (initialized)
  1358.     {
  1359. #ifdef HAVE_TZSET
  1360.       {
  1361.     /* If the execution TZ happens to be the same as the dump TZ,
  1362.        change it to some other value and then change it back,
  1363.        to force the underlying implementation to reload the TZ info.
  1364.        This is needed on implementations that load TZ info from files,
  1365.        since the TZ file contents may differ between dump and execution.  */
  1366.     char *tz = getenv ("TZ");
  1367.     if (tz && !strcmp (tz, dump_tz))
  1368.       {
  1369.         ++*tz;
  1370.         tzset ();
  1371.         --*tz;
  1372.       }
  1373.       }
  1374. #endif
  1375.     }
  1376.  
  1377.   /* Gerd Moellmann <gerd@acm.org> says this makes profiling work on
  1378.      FreeBSD.  It might work on some other systems too.
  1379.      Give it a try and tell me if it works on your system.  */
  1380. #ifdef __FreeBSD__
  1381. #ifdef PROFILING
  1382.   if (initialized)
  1383.     {
  1384.       extern void _mcleanup ();       
  1385.       extern char etext;
  1386.       extern Lisp_Object Fredraw_frame ();
  1387.       atexit (_mcleanup);
  1388.       /* This uses Fredraw_frame because that function
  1389.      comes first in the Emacs executable.
  1390.      It might be better to use something that gives
  1391.      the start of the text segment, but start_of_text
  1392.      is not defined on all systems now.  */
  1393.       monstartup (Fredraw_frame, &etext);
  1394.     }
  1395.   else
  1396.     moncontrol (0);
  1397. #endif
  1398. #endif
  1399.  
  1400.   initialized = 1;
  1401.  
  1402. #ifdef LOCALTIME_CACHE
  1403.   /* Some versions of localtime have a bug.  They cache the value of the time
  1404.      zone rather than looking it up every time.  Since localtime() is
  1405.      called to bolt the undumping time into the undumped emacs, this
  1406.      results in localtime ignoring the TZ environment variable.
  1407.      This flushes the new TZ value into localtime. */
  1408.   tzset ();
  1409. #endif /* defined (LOCALTIME_CACHE) */
  1410.  
  1411.   /* Enter editor command loop.  This never returns.  */
  1412.   Frecursive_edit ();
  1413.   /* NOTREACHED */
  1414. }
  1415.  
  1416. /* Sort the args so we can find the most important ones
  1417.    at the beginning of argv.  */
  1418.  
  1419. /* First, here's a table of all the standard options.  */
  1420.  
  1421. struct standard_args
  1422. {
  1423.   char *name;
  1424.   char *longname;
  1425.   int priority;
  1426.   int nargs;
  1427. };
  1428.  
  1429. struct standard_args standard_args[] =
  1430. {
  1431.   { "-version", "--version", 150, 0 },
  1432. #ifdef HAVE_SHM
  1433.   { "-nl", "--no-shared-memory", 140, 0 },
  1434. #endif
  1435. #ifdef VMS
  1436.   { "-map", "--map-data", 130, 0 },
  1437. #endif
  1438.   { "-t", "--terminal", 120, 1 },
  1439.   { "-nw", "--no-windows", 110, 0 },
  1440.   { "-batch", "--batch", 100, 0 },
  1441.   { "-help", "--help", 90, 0 },
  1442.   { "-no-unibyte", "--no-unibyte", 83, 0 },
  1443.   { "-multibyte", "--multibyte", 82, 0 },
  1444.   { "-unibyte", "--unibyte", 81, 0 },
  1445.   { "-no-multibyte", "--no-multibyte", 80, 0 },
  1446. #ifdef CANNOT_DUMP
  1447.   { "-nl", "--no-loadup", 70, 0 },
  1448. #endif
  1449.   /* -d must come last before the options handled in startup.el.  */
  1450.   { "-d", "--display", 60, 1 },
  1451.   { "-display", 0, 60, 1 },
  1452. #ifdef HAVE_PM
  1453.   { "-pm", "--pm", 80, 0 },
  1454. #endif /* HAVE_PM */
  1455.   /* Now for the options handled in startup.el.  */
  1456.   { "-q", "--no-init-file", 50, 0 },
  1457.   { "-no-init-file", 0, 50, 0 },
  1458.   { "-no-site-file", "--no-site-file", 40, 0 },
  1459.   { "-u", "--user", 30, 1 },
  1460.   { "-user", 0, 30, 1 },
  1461.   { "-debug-init", "--debug-init", 20, 0 },
  1462.   { "-i", "--icon-type", 15, 0 },
  1463.   { "-itype", 0, 15, 0 },
  1464.   { "-iconic", "--iconic", 15, 0 },
  1465.   { "-bg", "--background-color", 10, 1 },
  1466.   { "-background", 0, 10, 1 },
  1467.   { "-fg", "--foreground-color", 10, 1 },
  1468.   { "-foreground", 0, 10, 1 },
  1469.   { "-bd", "--border-color", 10, 1 },
  1470.   { "-bw", "--border-width", 10, 1 },
  1471.   { "-ib", "--internal-border", 10, 1 },
  1472.   { "-ms", "--mouse-color", 10, 1 },
  1473.   { "-cr", "--cursor-color", 10, 1 },
  1474.   { "-fn", "--font", 10, 1 },
  1475.   { "-font", 0, 10, 1 },
  1476.   { "-g", "--geometry", 10, 1 },
  1477.   { "-geometry", 0, 10, 1 },
  1478.   { "-T", "--title", 10, 1 },
  1479.   { "-title", 0, 10, 1 },
  1480.   { "-name", "--name", 10, 1 },
  1481.   { "-xrm", "--xrm", 10, 1 },
  1482.   { "-r", "--reverse-video", 5, 0 },
  1483.   { "-rv", 0, 5, 0 },
  1484.   { "-reverse", 0, 5, 0 },
  1485.   { "-hb", "--horizontal-scroll-bars", 5, 0 },
  1486.   { "-vb", "--vertical-scroll-bars", 5, 0 },
  1487.   /* These have the same priority as ordinary file name args,
  1488.      so they are not reordered with respect to those.  */
  1489.   { "-L", "--directory", 0, 1 },
  1490.   { "-directory", 0, 0, 1 },
  1491.   { "-l", "--load", 0, 1 },
  1492.   { "-load", 0, 0, 1 },
  1493.   { "-f", "--funcall", 0, 1 },
  1494.   { "-funcall", 0, 0, 1 },
  1495.   { "-eval", "--eval", 0, 1 },
  1496.   { "-find-file", "--find-file", 0, 1 },
  1497.   { "-visit", "--visit", 0, 1 },
  1498.   { "-insert", "--insert", 0, 1 },
  1499.   /* This should be processed after ordinary file name args and the like.  */
  1500.   { "-kill", "--kill", -10, 0 },
  1501. };
  1502.  
  1503. /* Reorder the elements of ARGV (assumed to have ARGC elements)
  1504.    so that the highest priority ones come first.
  1505.    Do not change the order of elements of equal priority.
  1506.    If an option takes an argument, keep it and its argument together.
  1507.  
  1508.    If an option that takes no argument appears more
  1509.    than once, eliminate all but one copy of it.  */
  1510.  
  1511. static void
  1512. sort_args (argc, argv)
  1513.      int argc;
  1514.      char **argv;
  1515. {
  1516.   char **new = (char **) xmalloc (sizeof (char *) * argc);
  1517.   /* For each element of argv,
  1518.      the corresponding element of options is:
  1519.      0 for an option that takes no arguments,
  1520.      1 for an option that takes one argument, etc.
  1521.      -1 for an ordinary non-option argument.  */
  1522.   int *options = (int *) xmalloc (sizeof (int) * argc);
  1523.   int *priority = (int *) xmalloc (sizeof (int) * argc);
  1524.   int to = 1;
  1525.   int incoming_used = 1;
  1526.   int from;
  1527.   int i;
  1528.   int end_of_options = argc;
  1529.  
  1530.   /* Categorize all the options,
  1531.      and figure out which argv elts are option arguments.  */
  1532.   for (from = 1; from < argc; from++)
  1533.     {
  1534.       options[from] = -1;
  1535.       priority[from] = 0;
  1536.       if (argv[from][0] == '-')
  1537.     {
  1538.       int match, thislen;
  1539.       char *equals;
  1540.  
  1541.       /* If we have found "--", don't consider
  1542.          any more arguments as options.  */
  1543.       if (argv[from][1] == '-' && argv[from][2] == 0)
  1544.         {
  1545.           /* Leave the "--", and everything following it, at the end.  */
  1546.           for (; from < argc; from++)
  1547.         {
  1548.           priority[from] = -100;
  1549.           options[from] = -1;
  1550.         }
  1551.           break;
  1552.         }
  1553.  
  1554.       /* Look for a match with a known old-fashioned option.  */
  1555.       for (i = 0; i < sizeof (standard_args) / sizeof (standard_args[0]); i++)
  1556.         if (!strcmp (argv[from], standard_args[i].name))
  1557.           {
  1558.         options[from] = standard_args[i].nargs;
  1559.         priority[from] = standard_args[i].priority;
  1560.         if (from + standard_args[i].nargs >= argc)
  1561.           fatal ("Option `%s' requires an argument\n", argv[from]);
  1562.         from += standard_args[i].nargs;
  1563.         goto done;
  1564.           }
  1565.  
  1566.       /* Look for a match with a known long option.
  1567.          MATCH is -1 if no match so far, -2 if two or more matches so far,
  1568.          >= 0 (the table index of the match) if just one match so far.  */
  1569.       if (argv[from][1] == '-')
  1570.         {
  1571.           match = -1;
  1572.           thislen = strlen (argv[from]);
  1573.           equals = index (argv[from], '=');
  1574.           if (equals != 0)
  1575.         thislen = equals - argv[from];
  1576.  
  1577.           for (i = 0;
  1578.            i < sizeof (standard_args) / sizeof (standard_args[0]); i++)
  1579.         if (standard_args[i].longname
  1580.             && !strncmp (argv[from], standard_args[i].longname,
  1581.                  thislen))
  1582.           {
  1583.             if (match == -1)
  1584.               match = i;
  1585.             else
  1586.               match = -2;
  1587.           }
  1588.  
  1589.           /* If we found exactly one match, use that.  */
  1590.           if (match >= 0)
  1591.         {
  1592.           options[from] = standard_args[match].nargs;
  1593.           priority[from] = standard_args[match].priority;
  1594.           /* If --OPTION=VALUE syntax is used,
  1595.              this option uses just one argv element.  */
  1596.           if (equals != 0)
  1597.             options[from] = 0;
  1598.           if (from + options[from] >= argc)
  1599.             fatal ("Option `%s' requires an argument\n", argv[from]);
  1600.           from += options[from];
  1601.         }
  1602.         }
  1603.     done: ;
  1604.     }
  1605.     }
  1606.  
  1607.   /* Copy the arguments, in order of decreasing priority, to NEW.  */
  1608.   new[0] = argv[0];
  1609.   while (incoming_used < argc)
  1610.     {
  1611.       int best = -1;
  1612.       int best_priority = -9999;
  1613.  
  1614.       /* Find the highest priority remaining option.
  1615.      If several have equal priority, take the first of them.  */
  1616.       for (from = 1; from < argc; from++)
  1617.     {
  1618.       if (argv[from] != 0 && priority[from] > best_priority)
  1619.         {
  1620.           best_priority = priority[from];
  1621.           best = from;
  1622.         }
  1623.       /* Skip option arguments--they are tied to the options.  */
  1624.       if (options[from] > 0)
  1625.         from += options[from];
  1626.     }
  1627.         
  1628.       if (best < 0)
  1629.     abort ();
  1630.  
  1631.       /* Copy the highest priority remaining option, with its args, to NEW.
  1632.          Unless it is a duplicate of the previous one.  */
  1633.       if (! (options[best] == 0
  1634.          && ! strcmp (new[to - 1], argv[best])))
  1635.     {
  1636.       new[to++] = argv[best];
  1637.       for (i = 0; i < options[best]; i++)
  1638.         new[to++] = argv[best + i + 1];
  1639.     }
  1640.  
  1641.       incoming_used += 1 + (options[best] > 0 ? options[best] : 0);
  1642.  
  1643.       /* Clear out this option in ARGV.  */
  1644.       argv[best] = 0;
  1645.       for (i = 0; i < options[best]; i++)
  1646.     argv[best + i + 1] = 0;
  1647.     }
  1648.  
  1649.   bcopy (new, argv, sizeof (char *) * argc);
  1650.  
  1651.   free (options);
  1652.   free (new);
  1653.   free (priority);
  1654. }
  1655.  
  1656. DEFUN ("kill-emacs", Fkill_emacs, Skill_emacs, 0, 1, "P",
  1657.   "Exit the Emacs job and kill it.\n\
  1658. If ARG is an integer, return ARG as the exit program code.\n\
  1659. If ARG is a  string, stuff it as keyboard input.\n\n\
  1660. The value of `kill-emacs-hook', if not void,\n\
  1661. is a list of functions (of no args),\n\
  1662. all of which are called before Emacs is actually killed.")
  1663.   (arg)
  1664.      Lisp_Object arg;
  1665. {
  1666.   Lisp_Object hook, hook1;
  1667.   int i;
  1668.   struct gcpro gcpro1;
  1669.  
  1670.   GCPRO1 (arg);
  1671.  
  1672.   if (feof (stdin))
  1673.     arg = Qt;
  1674.  
  1675.   if (!NILP (Vrun_hooks) && !noninteractive)
  1676.     call1 (Vrun_hooks, intern ("kill-emacs-hook"));
  1677.  
  1678.   UNGCPRO;
  1679.  
  1680. /* Is it really necessary to do this deassign
  1681.    when we are going to exit anyway?  */
  1682. /* #ifdef VMS
  1683.   stop_vms_input ();
  1684.  #endif  */
  1685.  
  1686.   shut_down_emacs (0, 0, STRINGP (arg) ? arg : Qnil);
  1687.  
  1688.   /* If we have an auto-save list file,
  1689.      kill it because we are exiting Emacs deliberately (not crashing).
  1690.      Do it after shut_down_emacs, which does an auto-save.  */
  1691.   if (STRINGP (Vauto_save_list_file_name))
  1692.     unlink (XSTRING (Vauto_save_list_file_name)->data);
  1693.  
  1694.   exit (INTEGERP (arg) ? XINT (arg)
  1695. #ifdef VMS
  1696.     : 1
  1697. #else
  1698.     : 0
  1699. #endif
  1700.     );
  1701.   /* NOTREACHED */
  1702. }
  1703.  
  1704.  
  1705. /* Perform an orderly shutdown of Emacs.  Autosave any modified
  1706.    buffers, kill any child processes, clean up the terminal modes (if
  1707.    we're in the foreground), and other stuff like that.  Don't perform
  1708.    any redisplay; this may be called when Emacs is shutting down in
  1709.    the background, or after its X connection has died.
  1710.  
  1711.    If SIG is a signal number, print a message for it.
  1712.  
  1713.    This is called by fatal signal handlers, X protocol error handlers,
  1714.    and Fkill_emacs.  */
  1715.  
  1716. void
  1717. shut_down_emacs (sig, no_x, stuff)
  1718.      int sig, no_x;
  1719.      Lisp_Object stuff;
  1720. {
  1721.   /* Prevent running of hooks from now on.  */
  1722.   Vrun_hooks = Qnil;
  1723.  
  1724.   /* If we are controlling the terminal, reset terminal modes */
  1725. #ifdef EMACS_HAVE_TTY_PGRP
  1726.   {
  1727.     int pgrp = EMACS_GETPGRP (0);
  1728.  
  1729.     int tpgrp;
  1730.     if (EMACS_GET_TTY_PGRP (0, &tpgrp) != -1
  1731.     && tpgrp == pgrp)
  1732.       {
  1733.     fflush (stdout);
  1734.     reset_sys_modes ();
  1735.     if (sig && sig != SIGTERM)
  1736.       fprintf (stderr, "Fatal error (%d).", sig);
  1737.       }
  1738.   }
  1739. #else
  1740.   fflush (stdout);
  1741.   reset_sys_modes ();
  1742. #endif
  1743.  
  1744.   stuff_buffered_input (stuff);
  1745.  
  1746.   kill_buffer_processes (Qnil);
  1747.   Fdo_auto_save (Qt, Qnil);
  1748.  
  1749. #ifdef CLASH_DETECTION
  1750.   unlock_all_files ();
  1751. #endif
  1752.  
  1753. #ifdef VMS
  1754.   kill_vms_processes ();
  1755. #endif
  1756.  
  1757. #if 0 /* This triggers a bug in XCloseDisplay and is not needed.  */
  1758. #ifdef HAVE_X_WINDOWS
  1759.   /* It's not safe to call intern here.  Maybe we are crashing.  */
  1760.   if (!noninteractive && SYMBOLP (Vwindow_system)
  1761.       && XSYMBOL (Vwindow_system)->name->size == 1
  1762.       && XSYMBOL (Vwindow_system)->name->data[0] == 'x'
  1763.       && ! no_x)
  1764.     Fx_close_current_connection ();
  1765. #endif /* HAVE_X_WINDOWS */
  1766. #endif
  1767.  
  1768. #ifdef HAVE_PM
  1769. /* Under OS/2, however, pmemacs.exe is better than the Presentation
  1770.    Manager at closing multiple windows at once. */
  1771. #ifdef HAVE_X_WINDOWS
  1772.   /* It's not safe to call intern here.  Maybe we are crashing.  */
  1773.   if (!noninteractive && SYMBOLP (Vwindow_system)
  1774.       && XSYMBOL (Vwindow_system)->name->size == 2
  1775.       && XSYMBOL (Vwindow_system)->name->data[0] == 'p'
  1776.       && XSYMBOL (Vwindow_system)->name->data[1] == 'm'
  1777.       && ! no_x)
  1778.     pm_shutdown ();
  1779. #endif /* HAVE_X_WINDOWS */
  1780. #endif /* HAVE_PM */
  1781.  
  1782. #ifdef SIGIO
  1783.   /* There is a tendency for a SIGIO signal to arrive within exit,
  1784.      and cause a SIGHUP because the input descriptor is already closed.  */
  1785.   unrequest_sigio ();
  1786.   signal (SIGIO, SIG_IGN);
  1787. #endif
  1788.  
  1789. #ifdef WINDOWSNT
  1790.   term_ntproc ();
  1791. #endif
  1792.  
  1793. #ifdef MSDOS
  1794.   dos_cleanup ();
  1795. #endif
  1796. }
  1797.  
  1798.  
  1799.  
  1800. #ifndef CANNOT_DUMP
  1801.  
  1802. #ifdef HAVE_SHM
  1803.  
  1804. DEFUN ("dump-emacs-data", Fdump_emacs_data, Sdump_emacs_data, 1, 1, 0,
  1805.   "Dump current state of Emacs into data file FILENAME.\n\
  1806. This function exists on systems that use HAVE_SHM.")
  1807.   (filename)
  1808.      Lisp_Object filename;
  1809. {
  1810.   extern char my_edata[];
  1811.   Lisp_Object tem;
  1812.  
  1813.   CHECK_STRING (filename, 0);
  1814.   filename = Fexpand_file_name (filename, Qnil);
  1815.  
  1816.   tem = Vpurify_flag;
  1817.   Vpurify_flag = Qnil;
  1818.  
  1819.   fflush (stdout);
  1820.   /* Tell malloc where start of impure now is */
  1821.   /* Also arrange for warnings when nearly out of space.  */
  1822. #ifndef SYSTEM_MALLOC
  1823.   memory_warnings (my_edata, malloc_warning);
  1824. #endif
  1825.   map_out_data (XSTRING (filename)->data);
  1826.  
  1827.   Vpurify_flag = tem;
  1828.  
  1829.   return Qnil;
  1830. }
  1831.  
  1832. #else /* not HAVE_SHM */
  1833.  
  1834. DEFUN ("dump-emacs", Fdump_emacs, Sdump_emacs, 2, 2, 0,
  1835.   "Dump current state of Emacs into executable file FILENAME.\n\
  1836. Take symbols from SYMFILE (presumably the file you executed to run Emacs).\n\
  1837. This is used in the file `loadup.el' when building Emacs.\n\
  1838. \n\
  1839. You must run Emacs in batch mode in order to dump it.")
  1840.   (filename, symfile)
  1841.      Lisp_Object filename, symfile;
  1842. {
  1843.   extern char my_edata[];
  1844.   Lisp_Object tem;
  1845.   Lisp_Object symbol;
  1846.   int count = specpdl_ptr - specpdl;
  1847.  
  1848.   if (! noninteractive)
  1849.     error ("Dumping Emacs works only in batch mode");
  1850.  
  1851.   /* Bind `command-line-processed' to nil before dumping,
  1852.      so that the dumped Emacs will process its command line
  1853.      and set up to work with X windows if appropriate.  */
  1854.   symbol = intern ("command-line-process");
  1855.   specbind (symbol, Qnil);
  1856.  
  1857.   CHECK_STRING (filename, 0);
  1858.   filename = Fexpand_file_name (filename, Qnil);
  1859.   if (!NILP (symfile))
  1860.     {
  1861.       CHECK_STRING (symfile, 0);
  1862.       if (XSTRING (symfile)->size)
  1863.     symfile = Fexpand_file_name (symfile, Qnil);
  1864.     }
  1865.  
  1866.   tem = Vpurify_flag;
  1867.   Vpurify_flag = Qnil;
  1868.  
  1869. #ifdef HAVE_TZSET
  1870.   set_time_zone_rule (dump_tz);
  1871. #ifndef LOCALTIME_CACHE
  1872.   /* Force a tz reload, since set_time_zone_rule doesn't.  */
  1873.   tzset ();
  1874. #endif
  1875. #endif
  1876.  
  1877.   fflush (stdout);
  1878. #ifdef VMS
  1879.   mapout_data (XSTRING (filename)->data);
  1880. #else
  1881.   /* Tell malloc where start of impure now is */
  1882.   /* Also arrange for warnings when nearly out of space.  */
  1883. #ifndef SYSTEM_MALLOC
  1884. #ifndef WINDOWSNT
  1885.   /* On Windows, this was done before dumping, and that once suffices.
  1886.      Meanwhile, my_edata is not valid on Windows.  */
  1887.   memory_warnings (my_edata, malloc_warning);
  1888. #endif /* not WINDOWSNT */
  1889. #endif
  1890. #ifdef DOUG_LEA_MALLOC
  1891.   malloc_state_ptr = malloc_get_state ();
  1892. #endif
  1893.   unexec (XSTRING (filename)->data,
  1894.       !NILP (symfile) ? XSTRING (symfile)->data : 0, my_edata, 0, 0);
  1895. #ifdef DOUG_LEA_MALLOC
  1896.   free (malloc_state_ptr);
  1897. #endif
  1898. #endif /* not VMS */
  1899.  
  1900.   Vpurify_flag = tem;
  1901.  
  1902.   return unbind_to (count, Qnil);
  1903. }
  1904.  
  1905. #endif /* not HAVE_SHM */
  1906.  
  1907. #endif /* not CANNOT_DUMP */
  1908.  
  1909. #ifndef SEPCHAR
  1910. #define SEPCHAR ':'
  1911. #endif
  1912.  
  1913. Lisp_Object
  1914. decode_env_path (evarname, defalt)
  1915.      char *evarname, *defalt;
  1916. {
  1917.   register char *path, *p;
  1918.   Lisp_Object lpath, element, tem;
  1919.  
  1920.   /* It's okay to use getenv here, because this function is only used
  1921.      to initialize variables when Emacs starts up, and isn't called
  1922.      after that.  */
  1923.   if (evarname != 0)
  1924.     path = (char *) getenv (evarname);
  1925.   else
  1926.     path = 0;
  1927. #ifdef EMX
  1928.   if (path)
  1929.     {
  1930.       char *p = path;
  1931.       path = alloca (strlen (p) + 1);
  1932.       strcpy (path, p);
  1933.       for (p = path; *p != 0; ++p)
  1934.         if (*p == '\\')
  1935.           *p = '/';
  1936.     }
  1937. #endif /* EMX */
  1938.   if (!path)
  1939.     path = defalt;
  1940. #ifdef DOS_NT
  1941.   /* Ensure values from the environment use the proper directory separator.  */
  1942.   if (path)
  1943.     {
  1944.       p = alloca (strlen (path) + 1);
  1945.       strcpy (p, path);
  1946.       path = p;
  1947.  
  1948.       if ('/' == DIRECTORY_SEP)
  1949.     dostounix_filename (path);
  1950.       else
  1951.     unixtodos_filename (path);
  1952.     }
  1953. #endif
  1954.   lpath = Qnil;
  1955.   while (1)
  1956.     {
  1957.       p = index (path, SEPCHAR);
  1958.       if (!p) p = path + strlen (path);
  1959.       element = (p - path ? make_string (path, p - path)
  1960.          : build_string ("."));
  1961.  
  1962.       /* Add /: to the front of the name
  1963.      if it would otherwise be treated as magic.  */
  1964.       tem = Ffind_file_name_handler (element, Qt);
  1965.       if (! NILP (tem))
  1966.     element = concat2 (build_string ("/:"), element);
  1967.  
  1968.       lpath = Fcons (element, lpath);
  1969.       if (*p)
  1970.     path = p + 1;
  1971.       else
  1972.     break;
  1973.     }
  1974.   return Fnreverse (lpath);
  1975. }
  1976.  
  1977. void
  1978. syms_of_emacs ()
  1979. {
  1980.   Qfile_name_handler_alist = intern ("file-name-handler-alist");
  1981.   staticpro (&Qfile_name_handler_alist);
  1982.  
  1983. #ifndef CANNOT_DUMP
  1984. #ifdef HAVE_SHM
  1985.   defsubr (&Sdump_emacs_data);
  1986. #else
  1987.   defsubr (&Sdump_emacs);
  1988. #endif
  1989. #endif
  1990.  
  1991.   defsubr (&Skill_emacs);
  1992.  
  1993.   defsubr (&Sinvocation_name);
  1994.   defsubr (&Sinvocation_directory);
  1995.  
  1996.   DEFVAR_LISP ("command-line-args", &Vcommand_line_args,
  1997.     "Args passed by shell to Emacs, as a list of strings.");
  1998.  
  1999.   DEFVAR_LISP ("system-type", &Vsystem_type,
  2000.     "Value is symbol indicating type of operating system you are using.");
  2001.   Vsystem_type = intern (SYSTEM_TYPE);
  2002.  
  2003.   DEFVAR_LISP ("system-configuration", &Vsystem_configuration,
  2004.     "Value is string indicating configuration Emacs was built for.");
  2005.   Vsystem_configuration = build_string (EMACS_CONFIGURATION);
  2006.  
  2007.   DEFVAR_LISP ("system-configuration-options", &Vsystem_configuration_options,
  2008.     "String containing the configuration options Emacs was built with.");
  2009.   Vsystem_configuration_options = build_string (EMACS_CONFIG_OPTIONS);
  2010.  
  2011.   DEFVAR_BOOL ("noninteractive", &noninteractive1,
  2012.     "Non-nil means Emacs is running without interactive terminal.");
  2013.  
  2014.   DEFVAR_LISP ("kill-emacs-hook", &Vkill_emacs_hook,
  2015.     "Hook to be run whenever kill-emacs is called.\n\
  2016. Since kill-emacs may be invoked when the terminal is disconnected (or\n\
  2017. in other similar situations), functions placed on this hook should not\n\
  2018. expect to be able to interact with the user.  To ask for confirmation,\n\
  2019. see `kill-emacs-query-functions' instead.");
  2020.   Vkill_emacs_hook = Qnil;
  2021.  
  2022. #ifdef SIGUSR1
  2023.   DEFVAR_LISP ("signal-USR1-hook", &Vsignal_USR1_hook,
  2024.     "Hook to be run whenever emacs receives a USR1 signal");
  2025.   Vsignal_USR1_hook = Qnil;
  2026. #ifdef SIGUSR2
  2027.   DEFVAR_LISP ("signal-USR2-hook", &Vsignal_USR2_hook,
  2028.     "Hook to be run whenever emacs receives a USR2 signal");
  2029.   Vsignal_USR2_hook = Qnil;
  2030. #endif
  2031. #endif
  2032.  
  2033.  
  2034.   DEFVAR_INT ("emacs-priority", &emacs_priority,
  2035.     "Priority for Emacs to run at.\n\
  2036. This value is effective only if set before Emacs is dumped,\n\
  2037. and only if the Emacs executable is installed with setuid to permit\n\
  2038. it to change priority.  (Emacs sets its uid back to the real uid.)\n\
  2039. Currently, you need to define SET_EMACS_PRIORITY in `config.h'\n\
  2040. before you compile Emacs, to enable the code for this feature.");
  2041.   emacs_priority = 0;
  2042.  
  2043.   DEFVAR_LISP ("path-separator", &Vpath_separator,
  2044.     "The directory separator in search paths, as a string.");
  2045.   {
  2046.     char c = SEPCHAR;
  2047.     Vpath_separator = make_string (&c, 1);
  2048.   }
  2049.  
  2050.   DEFVAR_LISP ("invocation-name", &Vinvocation_name,
  2051.     "The program name that was used to run Emacs.\n\
  2052. Any directory names are omitted.");
  2053.  
  2054.   DEFVAR_LISP ("invocation-directory", &Vinvocation_directory,
  2055.     "The directory in which the Emacs executable was found, to run it.\n\
  2056. The value is nil if that directory's name is not known.");
  2057.  
  2058.   DEFVAR_LISP ("installation-directory", &Vinstallation_directory,
  2059.     "A directory within which to look for the `lib-src' and `etc' directories.\n\
  2060. This is non-nil when we can't find those directories in their standard\n\
  2061. installed locations, but we can find them\n\
  2062. near where the Emacs executable was found.");
  2063.   Vinstallation_directory = Qnil;
  2064. }
  2065.