1 /* Fully extensible Emacs, running on Unix, intended for GNU.
2 Copyright (C) 1985,86,87,93,94,95,97,98,1999 Free Software Foundation, Inc.
4 This file is part of GNU Emacs.
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)
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.
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. */
27 #include <sys/types.h>
39 #include <sys/ioctl.h>
44 #include "intervals.h"
48 #include "blockinput.h"
49 #include "syssignal.h"
51 #include "termhooks.h"
60 #include <sys/resource.h>
67 extern void malloc_warning ();
68 extern void set_time_zone_rule ();
69 extern char *index ();
71 /* Make these values available in GDB, which doesn't see macros. */
73 EMACS_INT gdb_valbits
= VALBITS
;
74 EMACS_INT gdb_gctypebits
= GCTYPEBITS
;
75 EMACS_INT gdb_emacs_intbits
= sizeof (EMACS_INT
) * BITS_PER_CHAR
;
77 EMACS_INT gdb_data_seg_bits
= DATA_SEG_BITS
;
79 EMACS_INT gdb_data_seg_bits
= 0;
81 EMACS_INT PVEC_FLAG
= PSEUDOVECTOR_FLAG
;
83 /* Command line args from shell, as list of strings */
84 Lisp_Object Vcommand_line_args
;
86 /* The name under which Emacs was invoked, with any leading directory
88 Lisp_Object Vinvocation_name
;
90 /* The directory name from which Emacs was invoked. */
91 Lisp_Object Vinvocation_directory
;
93 /* The directory name in which to find subdirs such as lisp and etc.
94 nil means get them only from PATH_LOADSEARCH. */
95 Lisp_Object Vinstallation_directory
;
97 /* Hook run by `kill-emacs' before it does really anything. */
98 Lisp_Object Vkill_emacs_hook
;
101 /* Hooks for signal USR1 and USR2 handing */
102 Lisp_Object Vsignal_USR1_hook
;
104 Lisp_Object Vsignal_USR2_hook
;
108 /* Search path separator. */
109 Lisp_Object Vpath_separator
;
111 /* Set nonzero after Emacs has started up the first time.
112 Prevents reinitialization of the Lisp world and keymaps
113 on subsequent starts. */
116 #ifdef DOUG_LEA_MALLOC
117 /* Preserves a pointer to the memory allocated that copies that
118 static data inside glibc's malloc. */
119 void *malloc_state_ptr
;
120 /* From glibc, a routine that returns a copy of the malloc internal state. */
121 extern void *malloc_get_state ();
122 /* From glibc, a routine that overwrites the malloc internal state. */
123 extern void malloc_set_state ();
124 /* Non-zero if the MALLOC_CHECK_ enviroment variable was set while
125 dumping. Used to work around a bug in glibc's malloc. */
126 int malloc_using_checking
;
129 /* Variable whose value is symbol giving operating system type. */
130 Lisp_Object Vsystem_type
;
132 /* Variable whose value is string giving configuration built for. */
133 Lisp_Object Vsystem_configuration
;
135 /* Variable whose value is string giving configuration options,
136 for use when reporting bugs. */
137 Lisp_Object Vsystem_configuration_options
;
139 Lisp_Object Qfile_name_handler_alist
;
141 /* Current and previous system locales for messages and time. */
142 Lisp_Object Vsystem_messages_locale
;
143 Lisp_Object Vprevious_system_messages_locale
;
144 Lisp_Object Vsystem_time_locale
;
145 Lisp_Object Vprevious_system_time_locale
;
147 /* If non-zero, emacs should not attempt to use an window-specific code,
148 but instead should use the virtual terminal under which it was started */
149 int inhibit_window_system
;
151 /* If nonzero, set Emacs to run at this priority. This is also used
152 in child_setup and sys_suspend to make sure subshells run at normal
153 priority; Those functions have their own extern declaration. */
156 /* If non-zero a filter or a sentinel is running. Tested to save the match
157 data on the first attempt to change it inside asynchronous code. */
158 int running_asynch_code
;
162 extern int inherited_pgroup
;
165 #ifdef HAVE_X_WINDOWS
166 /* If non-zero, -d was specified, meaning we're using some window system. */
170 /* An address near the bottom of the stack.
171 Tells GC how to save a copy of the stack. */
174 #ifdef HAVE_WINDOW_SYSTEM
175 extern Lisp_Object Vwindow_system
;
176 #endif /* HAVE_WINDOW_SYSTEM */
178 extern Lisp_Object Vauto_save_list_file_name
;
180 #ifdef USG_SHARED_LIBRARIES
181 /* If nonzero, this is the place to put the end of the writable segment
184 unsigned int bss_end
= 0;
187 /* Nonzero means running Emacs without interactive terminal. */
191 /* Value of Lisp variable `noninteractive'.
192 Normally same as C variable `noninteractive'
193 but nothing terrible happens if user sets this one. */
197 /* Save argv and argc. */
201 static void sort_args ();
202 void syms_of_emacs ();
204 /* Signal code for the fatal signal that was received */
205 int fatal_error_code
;
207 /* Nonzero if handling a fatal error already */
208 int fatal_error_in_progress
;
212 handle_USR1_signal (sig
)
215 struct input_event buf
;
217 buf
.kind
= user_signal
;
219 buf
.frame_or_window
= selected_frame
;
223 kbd_buffer_store_event (&buf
);
229 handle_USR2_signal (sig
)
232 struct input_event buf
;
234 buf
.kind
= user_signal
;
236 buf
.frame_or_window
= selected_frame
;
240 kbd_buffer_store_event (&buf
);
244 /* Handle bus errors, illegal instruction, etc. */
246 fatal_error_signal (sig
)
249 fatal_error_code
= sig
;
250 signal (sig
, SIG_DFL
);
252 TOTALLY_UNBLOCK_INPUT
;
254 /* If fatal error occurs in code below, avoid infinite recursion. */
255 if (! fatal_error_in_progress
)
257 fatal_error_in_progress
= 1;
259 shut_down_emacs (sig
, 0, Qnil
);
263 LIB$
STOP (SS$_ABORT
);
265 /* Signal the same code; this time it will really be fatal.
266 Remember that since we're in a signal handler, the signal we're
267 going to send is probably blocked, so we have to unblock it if we
268 want to really receive it. */
270 sigunblock (sigmask (fatal_error_code
));
272 kill (getpid (), fatal_error_code
);
278 /* Handler for SIGDANGER. */
280 memory_warning_signal (sig
)
283 signal (sig
, memory_warning_signal
);
285 malloc_warning ("Operating system warns that virtual memory is running low.\n");
287 /* It might be unsafe to call do_auto_save now. */
288 force_auto_save_soon ();
292 /* We define abort, rather than using it from the library,
293 so that GDB can return from a breakpoint here.
294 MSDOS has its own definition on msdos.c */
296 #if ! defined (DOS_NT) && ! defined (NO_ABORT)
298 #ifndef ABORT_RETURN_TYPE
299 #define ABORT_RETURN_TYPE void
305 kill (getpid (), SIGABRT
);
306 /* This shouldn't be executed, but it prevents a warning. */
312 /* Code for dealing with Lisp access to the Unix command line */
315 init_cmdargs (argc
, argv
, skip_args
)
321 Lisp_Object name
, dir
, tem
;
322 int count
= specpdl_ptr
- specpdl
;
323 Lisp_Object raw_name
;
328 raw_name
= build_string (argv
[0]);
330 /* Add /: to the front of the name
331 if it would otherwise be treated as magic. */
332 tem
= Ffind_file_name_handler (raw_name
, Qt
);
334 raw_name
= concat2 (build_string ("/:"), raw_name
);
336 Vinvocation_name
= Ffile_name_nondirectory (raw_name
);
337 Vinvocation_directory
= Ffile_name_directory (raw_name
);
339 /* If we got no directory in argv[0], search PATH to find where
340 Emacs actually came from. */
341 if (NILP (Vinvocation_directory
))
344 int yes
= openp (Vexec_path
, Vinvocation_name
,
345 EXEC_SUFFIXES
, &found
, 1);
348 /* Add /: to the front of the name
349 if it would otherwise be treated as magic. */
350 tem
= Ffind_file_name_handler (found
, Qt
);
352 found
= concat2 (build_string ("/:"), found
);
353 Vinvocation_directory
= Ffile_name_directory (found
);
357 if (!NILP (Vinvocation_directory
)
358 && NILP (Ffile_name_absolute_p (Vinvocation_directory
)))
359 /* Emacs was started with relative path, like ./emacs.
361 Vinvocation_directory
= Fexpand_file_name (Vinvocation_directory
, Qnil
);
363 Vinstallation_directory
= Qnil
;
365 if (!NILP (Vinvocation_directory
))
367 dir
= Vinvocation_directory
;
368 name
= Fexpand_file_name (Vinvocation_name
, dir
);
371 Lisp_Object tem
, lib_src_exists
;
372 Lisp_Object etc_exists
, info_exists
;
374 /* See if dir contains subdirs for use by Emacs.
375 Check for the ones that would exist in a build directory,
376 not including lisp and info. */
377 tem
= Fexpand_file_name (build_string ("lib-src"), dir
);
378 lib_src_exists
= Ffile_exists_p (tem
);
381 /* MSDOS installations frequently remove lib-src, but we still
382 must set installation-directory, or else info won't find
383 its files (it uses the value of installation-directory). */
384 tem
= Fexpand_file_name (build_string ("info"), dir
);
385 info_exists
= Ffile_exists_p (tem
);
390 if (!NILP (lib_src_exists
) || !NILP (info_exists
))
392 tem
= Fexpand_file_name (build_string ("etc"), dir
);
393 etc_exists
= Ffile_exists_p (tem
);
394 if (!NILP (etc_exists
))
396 Vinstallation_directory
397 = Ffile_name_as_directory (dir
);
402 /* See if dir's parent contains those subdirs. */
403 tem
= Fexpand_file_name (build_string ("../lib-src"), dir
);
404 lib_src_exists
= Ffile_exists_p (tem
);
408 /* See the MSDOS commentary above. */
409 tem
= Fexpand_file_name (build_string ("../info"), dir
);
410 info_exists
= Ffile_exists_p (tem
);
415 if (!NILP (lib_src_exists
) || !NILP (info_exists
))
417 tem
= Fexpand_file_name (build_string ("../etc"), dir
);
418 etc_exists
= Ffile_exists_p (tem
);
419 if (!NILP (etc_exists
))
421 tem
= Fexpand_file_name (build_string (".."), dir
);
422 Vinstallation_directory
423 = Ffile_name_as_directory (tem
);
428 /* If the Emacs executable is actually a link,
429 next try the dir that the link points into. */
430 tem
= Ffile_symlink_p (name
);
433 name
= Fexpand_file_name (tem
, dir
);
434 dir
= Ffile_name_directory (name
);
441 Vcommand_line_args
= Qnil
;
443 for (i
= argc
- 1; i
>= 0; i
--)
445 if (i
== 0 || i
> skip_args
)
447 = Fcons (build_string (argv
[i
]), Vcommand_line_args
);
450 unbind_to (count
, Qnil
);
453 DEFUN ("invocation-name", Finvocation_name
, Sinvocation_name
, 0, 0, 0,
454 "Return the program name that was used to run Emacs.\n\
455 Any directory names are omitted.")
458 return Fcopy_sequence (Vinvocation_name
);
461 DEFUN ("invocation-directory", Finvocation_directory
, Sinvocation_directory
,
463 "Return the directory name in which the Emacs executable was located")
466 return Fcopy_sequence (Vinvocation_directory
);
471 #ifdef LINK_CRTL_SHARE
472 #ifdef SHARABLE_LIB_BUG
473 extern noshare
char **environ
;
474 #endif /* SHARABLE_LIB_BUG */
475 #endif /* LINK_CRTL_SHARE */
479 /* A valid but unlikely value for the TZ environment value.
480 It is OK (though a bit slower) if the user actually chooses this value. */
481 static char dump_tz
[] = "UtC0";
484 #ifndef ORDINARY_LINK
485 /* We don't include crtbegin.o and crtend.o in the link,
486 so these functions and variables might be missed.
487 Provide dummy definitions to avoid error.
488 (We don't have any real constructors or destructors.) */
490 #ifndef GCC_CTORS_IN_LIBC
491 void __do_global_ctors ()
493 void __do_global_ctors_aux ()
495 void __do_global_dtors ()
497 /* Linux has a bug in its library; avoid an error. */
499 char * __CTOR_LIST__
[2] = { (char *) (-1), 0 };
501 char * __DTOR_LIST__
[2] = { (char *) (-1), 0 };
502 #endif /* GCC_CTORS_IN_LIBC */
505 #endif /* __GNUC__ */
506 #endif /* ORDINARY_LINK */
508 /* Test whether the next argument in ARGV matches SSTR or a prefix of
509 LSTR (at least MINLEN characters). If so, then if VALPTR is non-null
510 (the argument is supposed to have a value) store in *VALPTR either
511 the next argument or the portion of this one after the equal sign.
512 ARGV is read starting at position *SKIPPTR; this index is advanced
513 by the number of arguments used.
515 Too bad we can't just use getopt for all of this, but we don't have
516 enough information to do it right. */
519 argmatch (argv
, argc
, sstr
, lstr
, minlen
, valptr
, skipptr
)
532 /* Don't access argv[argc]; give up in advance. */
533 if (argc
<= *skipptr
+ 1)
536 arg
= argv
[*skipptr
+1];
539 if (strcmp (arg
, sstr
) == 0)
543 *valptr
= argv
[*skipptr
+2];
550 arglen
= (valptr
!= NULL
&& (p
= index (arg
, '=')) != NULL
551 ? p
- arg
: strlen (arg
));
552 if (lstr
== 0 || arglen
< minlen
|| strncmp (arg
, lstr
, arglen
) != 0)
554 else if (valptr
== NULL
)
565 else if (argv
[*skipptr
+2] != NULL
)
567 *valptr
= argv
[*skipptr
+2];
577 #ifdef DOUG_LEA_MALLOC
579 /* malloc can be invoked even before main (e.g. by the dynamic
580 linker), so the dumped malloc state must be restored as early as
581 possible using this special hook. */
584 malloc_initialize_hook ()
586 extern char **environ
;
590 if (!malloc_using_checking
)
591 /* Work around a bug in glibc's malloc. MALLOC_CHECK_ must be
592 ignored if the heap to be restored was constructed without
593 malloc checking. Can't use unsetenv, since that calls malloc. */
597 for (p
= environ
; *p
; p
++)
598 if (strncmp (*p
, "MALLOC_CHECK_=", 14) == 0)
607 malloc_set_state (malloc_state_ptr
);
608 free (malloc_state_ptr
);
611 malloc_using_checking
= getenv ("MALLOC_CHECK_") != NULL
;
614 void (*__malloc_initialize_hook
) () = malloc_initialize_hook
;
616 #endif /* DOUG_LEA_MALLOC */
620 main (argc
, argv
, envp
)
625 char stack_bottom_variable
;
626 int do_initial_setlocale
;
630 #ifdef HAVE_SETRLIMIT
635 #ifdef LINUX_SBRK_BUG
639 #ifdef RUN_TIME_REMAP
641 run_time_remap (argv
[0]);
644 sort_args (argc
, argv
);
646 while (argv
[argc
]) argc
++;
648 if (argmatch (argv
, argc
, "-version", "--version", 3, NULL
, &skip_args
)
649 /* We don't know the version number unless this is a dumped Emacs.
650 So ignore --version otherwise. */
654 tem
= Fsymbol_value (intern ("emacs-version"));
657 fprintf (stderr
, "Invalid value of `emacs-version'\n");
662 printf ("GNU Emacs %s\n", XSTRING (tem
)->data
);
663 printf ("Copyright (C) 1999 Free Software Foundation, Inc.\n");
664 printf ("GNU Emacs comes with ABSOLUTELY NO WARRANTY.\n");
665 printf ("You may redistribute copies of Emacs\n");
666 printf ("under the terms of the GNU General Public License.\n");
667 printf ("For more information about these matters, ");
668 printf ("see the file named COPYING.\n");
673 /* Map in shared memory, if we are using that. */
675 if (argmatch (argv
, argc
, "-nl", "--no-shared-memory", 6, NULL
, &skip_args
))
678 /* The shared memory was just restored, which clobbered this. */
684 /* The shared memory was just restored, which clobbered this. */
691 extern int malloc_cookie
;
692 /* This helps out unexnext.c. */
694 if (malloc_jumpstart (malloc_cookie
) != 0)
695 printf ("malloc jumpstart failed!\n");
700 /* If -map specified, map the data file in */
703 if (argmatch (argv
, argc
, "-map", "--map-data", 3, &mapin_file
, &skip_args
))
707 #ifdef LINK_CRTL_SHARE
708 #ifdef SHARABLE_LIB_BUG
709 /* Bletcherous shared libraries! */
711 stdin
= fdopen (0, "r");
713 stdout
= fdopen (1, "w");
715 stderr
= fdopen (2, "w");
718 #endif /* SHARABLE_LIB_BUG */
719 #endif /* LINK_CRTL_SHARE */
722 #if defined (HAVE_SETRLIMIT) && defined (RLIMIT_STACK)
723 /* Extend the stack space available.
724 Don't do that if dumping, since some systems (e.g. DJGPP)
725 might define a smaller stack limit at that time. */
728 && (!noninteractive
|| initialized
)
730 && !getrlimit (RLIMIT_STACK
, &rlim
))
733 extern int re_max_failures
;
734 /* Approximate the amount regex.c needs per unit of re_max_failures. */
735 int ratio
= 20 * sizeof (char *);
736 /* Then add 33% to cover the size of the smaller stacks that regex.c
737 successively allocates and discards, on its way to the maximum. */
739 /* Add in some extra to cover
740 what we're likely to use for other reasons. */
741 newlim
= re_max_failures
* ratio
+ 200000;
743 /* NetBSD (at least NetBSD 1.2G and former) has a bug in its
744 stack allocation routine for new process that the allocation
745 fails if stack limit is not on page boundary. So, round up the
746 new limit to page boundary. */
747 newlim
= (newlim
+ getpagesize () - 1) / getpagesize () * getpagesize();
749 if (newlim
> rlim
.rlim_max
)
751 newlim
= rlim
.rlim_max
;
752 /* Don't let regex.c overflow the stack we have. */
753 re_max_failures
= (newlim
- 200000) / ratio
;
755 if (rlim
.rlim_cur
< newlim
)
756 rlim
.rlim_cur
= newlim
;
758 setrlimit (RLIMIT_STACK
, &rlim
);
760 #endif /* HAVE_SETRLIMIT and RLIMIT_STACK */
762 /* Record (approximately) where the stack begins. */
763 stack_bottom
= &stack_bottom_variable
;
765 #ifdef USG_SHARED_LIBRARIES
767 brk ((void *)bss_end
);
772 #ifndef SYSTEM_MALLOC
773 /* Arrange to get warning messages as memory fills up. */
774 memory_warnings (0, malloc_warning
);
776 /* Call malloc at least once, to run the initial __malloc_hook.
777 Also call realloc and free for consistency. */
778 free (realloc (malloc (4), 4));
780 /* Arrange to disable interrupt input inside malloc etc. */
781 uninterrupt_malloc ();
782 #endif /* not SYSTEM_MALLOC */
785 /* We do all file input/output as binary files. When we need to translate
786 newlines, we do that manually. */
790 if (!isatty (fileno (stdin
)))
791 setmode (fileno (stdin
), O_BINARY
);
792 if (!isatty (fileno (stdout
)))
795 setmode (fileno (stdout
), O_BINARY
);
797 #else /* not __DJGPP__ >= 2 */
798 (stdin
)->_flag
&= ~_IOTEXT
;
799 (stdout
)->_flag
&= ~_IOTEXT
;
800 (stderr
)->_flag
&= ~_IOTEXT
;
801 #endif /* not __DJGPP__ >= 2 */
804 #ifdef SET_EMACS_PRIORITY
806 nice (emacs_priority
);
808 #endif /* SET_EMACS_PRIORITY */
810 /* Skip initial setlocale if LC_ALL is "C", as it's not needed in that case.
811 The build procedure uses this while dumping, to ensure that the
812 dumped Emacs does not have its system locale tables initialized,
813 as that might cause screwups when the dumped Emacs starts up. */
815 char *lc_all
= getenv ("LC_ALL");
816 do_initial_setlocale
= ! lc_all
|| strcmp (lc_all
, "C");
819 /* Set locale now, so that initial error messages are localized properly.
820 fixup_locale must wait until later, since it builds strings. */
821 if (do_initial_setlocale
)
822 setlocale (LC_ALL
, "");
824 #ifdef EXTRA_INITIALIZE
828 inhibit_window_system
= 0;
830 /* Handle the -t switch, which specifies filename to use as terminal */
834 if (argmatch (argv
, argc
, "-t", "--terminal", 4, &term
, &skip_args
))
839 result
= emacs_open (term
, O_RDWR
, 0);
842 char *errstring
= strerror (errno
);
843 fprintf (stderr
, "emacs: %s: %s\n", term
, errstring
);
849 fprintf (stderr
, "emacs: %s: not a tty\n", term
);
852 fprintf (stderr
, "Using %s\n", term
);
853 #ifdef HAVE_WINDOW_SYSTEM
854 inhibit_window_system
= 1; /* -t => -nw */
861 if (argmatch (argv
, argc
, "-nw", "--no-windows", 6, NULL
, &skip_args
))
862 inhibit_window_system
= 1;
864 /* Handle the -batch switch, which means don't do interactive display. */
866 if (argmatch (argv
, argc
, "-batch", "--batch", 5, NULL
, &skip_args
))
869 /* Handle the --help option, which gives a usage message.. */
870 if (argmatch (argv
, argc
, "-help", "--help", 3, NULL
, &skip_args
))
873 Usage: %s [--batch] [-t term] [--terminal term]\n\
874 [-d display] [--display display] [-nw] [--no-windows]\n\
875 [-q] [--no-init-file] [-u user] [--user user] [--debug-init]\n\
876 [--unibyte] [--multibyte] [--version] [--no-site-file]\n\
877 [-f func] [--funcall func] [-l file] [--load file] [--eval expr]\n\
878 [--execute expr] [--visit file] [--file file] [--insert file]\n\
879 [+linenum] file-to-visit [--kill]\n\
880 Report bugs to bug-gnu-emacs@gnu.org. First, please see\n\
881 the Bugs section of the Emacs manual or the file BUGS.\n", argv
[0]);
885 if (! noninteractive
)
890 inherited_pgroup
= EMACS_GETPGRP (0);
891 setpgrp (0, getpid ());
894 #if defined (USG5) && defined (INTERRUPT_INPUT)
902 /* Don't catch SIGHUP if dumping. */
909 sigblock (sigmask (SIGHUP
));
910 /* In --batch mode, don't catch SIGHUP if already ignored.
911 That makes nohup work. */
913 || signal (SIGHUP
, SIG_IGN
) != SIG_IGN
)
914 signal (SIGHUP
, fatal_error_signal
);
915 sigunblock (sigmask (SIGHUP
));
920 ! noninteractive
|| initialized
926 /* Don't catch these signals in batch mode if dumping.
927 On some machines, this sets static data that would make
928 signal fail to work right when the dumped Emacs is run. */
929 signal (SIGQUIT
, fatal_error_signal
);
930 signal (SIGILL
, fatal_error_signal
);
931 signal (SIGTRAP
, fatal_error_signal
);
933 signal (SIGUSR1
, handle_USR1_signal
);
935 signal (SIGUSR2
, handle_USR2_signal
);
939 signal (SIGABRT
, fatal_error_signal
);
942 signal (SIGHWE
, fatal_error_signal
);
945 signal (SIGPRE
, fatal_error_signal
);
948 signal (SIGORE
, fatal_error_signal
);
951 signal (SIGUME
, fatal_error_signal
);
954 signal (SIGDLK
, fatal_error_signal
);
957 signal (SIGCPULIM
, fatal_error_signal
);
960 /* This is missing on some systems - OS/2, for example. */
961 signal (SIGIOT
, fatal_error_signal
);
964 signal (SIGEMT
, fatal_error_signal
);
966 signal (SIGFPE
, fatal_error_signal
);
968 signal (SIGBUS
, fatal_error_signal
);
970 signal (SIGSEGV
, fatal_error_signal
);
972 signal (SIGSYS
, fatal_error_signal
);
974 signal (SIGTERM
, fatal_error_signal
);
976 signal (SIGXCPU
, fatal_error_signal
);
979 signal (SIGXFSZ
, fatal_error_signal
);
983 /* This just means available memory is getting low. */
984 signal (SIGDANGER
, memory_warning_signal
);
988 /* 20 is SIGCHLD, 21 is SIGTTIN, 22 is SIGTTOU. */
989 signal (SIGXCPU
, fatal_error_signal
);
991 signal (SIGIOINT
, fatal_error_signal
);
993 signal (SIGGRANT
, fatal_error_signal
);
994 signal (SIGRETRACT
, fatal_error_signal
);
995 signal (SIGSOUND
, fatal_error_signal
);
996 signal (SIGMSG
, fatal_error_signal
);
1000 noninteractive1
= noninteractive
;
1002 /* Perform basic initializations (not merely interning symbols) */
1009 init_charset_once ();
1010 init_coding_once ();
1011 init_syntax_once (); /* Create standard syntax table. */
1012 init_category_once (); /* Create standard category table. */
1013 /* Must be done before init_buffer */
1014 init_casetab_once ();
1015 init_buffer_once (); /* Create buffer table and some buffers */
1016 init_minibuf_once (); /* Create list of minibuffers */
1017 /* Must precede init_window_once */
1019 /* Call syms_of_xfaces before init_window_once because that
1020 function creates Vterminal_frame. Termcap frames now use
1021 faces, and the face implementation uses some symbols as
1027 init_window_once (); /* Init the window system */
1028 init_fileio_once (); /* Must precede any path manipulation. */
1033 if (do_initial_setlocale
)
1036 Vsystem_messages_locale
= Vprevious_system_messages_locale
;
1037 Vsystem_time_locale
= Vprevious_system_time_locale
;
1043 #ifdef CLASH_DETECTION
1046 running_asynch_code
= 0;
1048 /* Handle --unibyte and the EMACS_UNIBYTE envvar,
1049 but not while dumping. */
1052 ! noninteractive
|| initialized
1058 int inhibit_unibyte
= 0;
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;
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 /* Actually this shouldn't be needed as of 20.4 in a generally
1070 unibyte environment. As handa says, environment values
1071 aren't now decoded; also existing buffers are now made
1072 unibyte during startup if .emacs sets unibyte. Tested with
1073 8-bit data in environment variables and /etc/passwd, setting
1074 unibyte and Latin-1 in .emacs. -- Dave Love */
1075 if (argmatch (argv
, argc
, "-unibyte", "--unibyte", 4, NULL
, &skip_args
)
1076 || argmatch (argv
, argc
, "-no-multibyte", "--no-multibyte", 4, NULL
, &skip_args
)
1077 || (getenv ("EMACS_UNIBYTE") && !inhibit_unibyte
))
1079 Lisp_Object old_log_max
;
1080 Lisp_Object symbol
, tail
;
1082 symbol
= intern ("default-enable-multibyte-characters");
1083 Fset (symbol
, Qnil
);
1087 /* Erase pre-dump messages in *Messages* now so no abort. */
1088 old_log_max
= Vmessage_log_max
;
1089 XSETFASTINT (Vmessage_log_max
, 0);
1090 message_dolog ("", 0, 1, 0);
1091 Vmessage_log_max
= old_log_max
;
1094 for (tail
= Vbuffer_alist
; CONSP (tail
);
1099 buffer
= Fcdr (XCAR (tail
));
1100 /* Verify that all buffers are empty now, as they
1102 if (BUF_Z (XBUFFER (buffer
)) > BUF_BEG (XBUFFER (buffer
)))
1104 /* It is safe to do this crudely in an empty buffer. */
1105 XBUFFER (buffer
)->enable_multibyte_characters
= Qnil
;
1111 = !argmatch (argv
, argc
, "-nl", "--no-loadup", 6, NULL
, &skip_args
);
1114 #ifdef HAVE_X_WINDOWS
1115 /* Stupid kludge to catch command-line display spec. We can't
1116 handle this argument entirely in window system dependent code
1117 because we don't even know which window system dependent code
1118 to run until we've recognized this argument. */
1120 char *displayname
= 0;
1121 int count_before
= skip_args
;
1123 /* Skip any number of -d options, but only use the last one. */
1126 int count_before_this
= skip_args
;
1128 if (argmatch (argv
, argc
, "-d", "--display", 3, &displayname
, &skip_args
))
1130 else if (argmatch (argv
, argc
, "-display", 0, 3, &displayname
, &skip_args
))
1135 count_before
= count_before_this
;
1138 /* If we have the form --display=NAME,
1139 convert it into -d name.
1140 This requires inserting a new element into argv. */
1141 if (displayname
!= 0 && skip_args
- count_before
== 1)
1143 char **new = (char **) xmalloc (sizeof (char *) * (argc
+ 2));
1146 for (j
= 0; j
< count_before
+ 1; j
++)
1148 new[count_before
+ 1] = "-d";
1149 new[count_before
+ 2] = displayname
;
1150 for (j
= count_before
+ 2; j
<argc
; j
++)
1151 new[j
+ 1] = argv
[j
];
1155 /* Change --display to -d, when its arg is separate. */
1156 else if (displayname
!= 0 && skip_args
> count_before
1157 && argv
[count_before
+ 1][1] == '-')
1158 argv
[count_before
+ 1] = "-d";
1160 /* Don't actually discard this arg. */
1161 skip_args
= count_before
;
1165 /* argmatch must not be used after here,
1166 except when bulding temacs
1167 because the -d argument has not been skipped in skip_args. */
1170 /* Call early 'cause init_environment needs it. */
1172 /* Set defaults for several environment variables. */
1174 init_environment (argc
, argv
, skip_args
);
1180 /* Initialize environment from registry settings. */
1181 init_environment (argv
);
1182 init_ntproc (); /* must precede init_editfns */
1185 /* egetenv is a pretty low-level facility, which may get called in
1186 many circumstances; it seems flimsy to put off initializing it
1187 until calling init_callproc. */
1188 set_process_environment ();
1189 /* AIX crashes are reported in system versions 3.2.3 and 3.2.4
1190 if this is not done. Do it after set_process_environment so that we
1191 don't pollute Vprocess_environment. */
1192 /* Setting LANG here will defeat the startup locale processing... */
1197 init_buffer (); /* Init default directory of main buffer */
1199 init_callproc_1 (); /* Must precede init_cmdargs and init_sys_modes. */
1200 init_cmdargs (argc
, argv
, skip_args
); /* Must precede init_lread. */
1204 /* Erase any pre-dump messages in the message log, to avoid confusion */
1205 Lisp_Object old_log_max
;
1206 old_log_max
= Vmessage_log_max
;
1207 XSETFASTINT (Vmessage_log_max
, 0);
1208 message_dolog ("", 0, 1, 0);
1209 Vmessage_log_max
= old_log_max
;
1212 init_callproc (); /* Must follow init_cmdargs but not init_sys_modes. */
1215 /* Intern the names of all standard functions and variables;
1216 define standard keys. */
1220 /* The basic levels of Lisp must come first */
1221 /* And data must come first of all
1222 for the sake of symbols like error-message */
1229 syms_of_floatfns ();
1233 syms_of_bytecode ();
1235 syms_of_casefiddle ();
1237 syms_of_callproc ();
1238 syms_of_category ();
1242 #ifndef NO_DIR_LIBRARY
1244 #endif /* not NO_DIR_LIBRARY */
1250 syms_of_coding (); /* This should be after syms_of_fileio. */
1251 #ifdef CLASH_DETECTION
1252 syms_of_filelock ();
1253 #endif /* CLASH_DETECTION */
1256 syms_of_keyboard ();
1261 syms_of_mocklisp ();
1272 syms_of_textprop ();
1278 #endif /* WINDOWSNT */
1281 #ifdef HAVE_X_WINDOWS
1288 #endif /* HAVE_X_WINDOWS */
1297 syms_of_w32faces ();
1298 syms_of_w32select ();
1301 #endif /* HAVE_NTGUI */
1311 keys_of_casefiddle ();
1314 keys_of_keyboard ();
1322 if (!noninteractive
)
1325 init_vms_input ();/* init_display calls get_frame_size, that needs this */
1327 init_display (); /* Determine terminal type. init_sys_modes uses results */
1329 init_keyboard (); /* This too must precede init_sys_modes */
1331 init_vmsproc (); /* And this too. */
1333 init_sys_modes (); /* Init system terminal modes (RAW or CBREAK, etc.) */
1334 #ifdef HAVE_X_WINDOWS
1336 #endif /* HAVE_X_WINDOWS */
1341 #ifdef LISP_FLOAT_TYPE
1355 /* Handle -l loadup, args passed by Makefile. */
1356 if (argmatch (argv
, argc
, "-l", "--load", 3, &file
, &skip_args
))
1357 Vtop_level
= Fcons (intern ("load"),
1358 Fcons (build_string (file
), Qnil
));
1360 /* Unless next switch is -nl, load "loadup.el" first thing. */
1362 Vtop_level
= Fcons (intern ("load"),
1363 Fcons (build_string ("loadup.el"), Qnil
));
1364 #endif /* CANNOT_DUMP */
1371 /* If the execution TZ happens to be the same as the dump TZ,
1372 change it to some other value and then change it back,
1373 to force the underlying implementation to reload the TZ info.
1374 This is needed on implementations that load TZ info from files,
1375 since the TZ file contents may differ between dump and execution. */
1376 char *tz
= getenv ("TZ");
1377 if (tz
&& !strcmp (tz
, dump_tz
))
1387 /* Gerd Moellmann <gerd@acm.org> says this makes profiling work on
1388 FreeBSD. It might work on some other systems too.
1389 Give it a try and tell me if it works on your system. */
1390 #if defined (__FreeBSD__) || defined (__linux)
1394 extern void _mcleanup ();
1396 extern void safe_bcopy ();
1397 extern void dump_opcode_frequencies ();
1400 // atexit (dump_opcode_frequencies);
1401 /* This uses safe_bcopy because that function comes first in the
1402 Emacs executable. It might be better to use something that
1403 gives the start of the text segment, but start_of_text is not
1404 defined on all systems now. */
1405 monstartup (safe_bcopy
, &etext
);
1414 #ifdef LOCALTIME_CACHE
1415 /* Some versions of localtime have a bug. They cache the value of the time
1416 zone rather than looking it up every time. Since localtime() is
1417 called to bolt the undumping time into the undumped emacs, this
1418 results in localtime ignoring the TZ environment variable.
1419 This flushes the new TZ value into localtime. */
1421 #endif /* defined (LOCALTIME_CACHE) */
1423 /* Enter editor command loop. This never returns. */
1428 /* Sort the args so we can find the most important ones
1429 at the beginning of argv. */
1431 /* First, here's a table of all the standard options. */
1433 struct standard_args
1441 struct standard_args standard_args
[] =
1443 { "-version", "--version", 150, 0 },
1445 { "-nl", "--no-shared-memory", 140, 0 },
1448 { "-map", "--map-data", 130, 0 },
1450 { "-t", "--terminal", 120, 1 },
1451 { "-nw", "--no-windows", 110, 0 },
1452 { "-batch", "--batch", 100, 0 },
1453 { "-help", "--help", 90, 0 },
1454 { "-no-unibyte", "--no-unibyte", 83, 0 },
1455 { "-multibyte", "--multibyte", 82, 0 },
1456 { "-unibyte", "--unibyte", 81, 0 },
1457 { "-no-multibyte", "--no-multibyte", 80, 0 },
1459 { "-nl", "--no-loadup", 70, 0 },
1461 /* -d must come last before the options handled in startup.el. */
1462 { "-d", "--display", 60, 1 },
1463 { "-display", 0, 60, 1 },
1464 /* Now for the options handled in startup.el. */
1465 { "-q", "--no-init-file", 50, 0 },
1466 { "-no-init-file", 0, 50, 0 },
1467 { "-no-site-file", "--no-site-file", 40, 0 },
1468 { "-u", "--user", 30, 1 },
1469 { "-user", 0, 30, 1 },
1470 { "-debug-init", "--debug-init", 20, 0 },
1471 { "-i", "--icon-type", 15, 0 },
1472 { "-itype", 0, 15, 0 },
1473 { "-iconic", "--iconic", 15, 0 },
1474 { "-bg", "--background-color", 10, 1 },
1475 { "-background", 0, 10, 1 },
1476 { "-fg", "--foreground-color", 10, 1 },
1477 { "-foreground", 0, 10, 1 },
1478 { "-bd", "--border-color", 10, 1 },
1479 { "-bw", "--border-width", 10, 1 },
1480 { "-ib", "--internal-border", 10, 1 },
1481 { "-ms", "--mouse-color", 10, 1 },
1482 { "-cr", "--cursor-color", 10, 1 },
1483 { "-fn", "--font", 10, 1 },
1484 { "-font", 0, 10, 1 },
1485 { "-g", "--geometry", 10, 1 },
1486 { "-geometry", 0, 10, 1 },
1487 { "-T", "--title", 10, 1 },
1488 { "-title", 0, 10, 1 },
1489 { "-name", "--name", 10, 1 },
1490 { "-xrm", "--xrm", 10, 1 },
1491 { "-r", "--reverse-video", 5, 0 },
1493 { "-reverse", 0, 5, 0 },
1494 { "-hb", "--horizontal-scroll-bars", 5, 0 },
1495 { "-vb", "--vertical-scroll-bars", 5, 0 },
1496 /* These have the same priority as ordinary file name args,
1497 so they are not reordered with respect to those. */
1498 { "-L", "--directory", 0, 1 },
1499 { "-directory", 0, 0, 1 },
1500 { "-l", "--load", 0, 1 },
1501 { "-load", 0, 0, 1 },
1502 { "-f", "--funcall", 0, 1 },
1503 { "-funcall", 0, 0, 1 },
1504 { "-eval", "--eval", 0, 1 },
1505 { "-execute", "--execute", 0, 1 },
1506 { "-find-file", "--find-file", 0, 1 },
1507 { "-visit", "--visit", 0, 1 },
1508 { "-file", "--file", 0, 1 },
1509 { "-insert", "--insert", 0, 1 },
1510 /* This should be processed after ordinary file name args and the like. */
1511 { "-kill", "--kill", -10, 0 },
1514 /* Reorder the elements of ARGV (assumed to have ARGC elements)
1515 so that the highest priority ones come first.
1516 Do not change the order of elements of equal priority.
1517 If an option takes an argument, keep it and its argument together.
1519 If an option that takes no argument appears more
1520 than once, eliminate all but one copy of it. */
1523 sort_args (argc
, argv
)
1527 char **new = (char **) xmalloc (sizeof (char *) * argc
);
1528 /* For each element of argv,
1529 the corresponding element of options is:
1530 0 for an option that takes no arguments,
1531 1 for an option that takes one argument, etc.
1532 -1 for an ordinary non-option argument. */
1533 int *options
= (int *) xmalloc (sizeof (int) * argc
);
1534 int *priority
= (int *) xmalloc (sizeof (int) * argc
);
1536 int incoming_used
= 1;
1540 /* Categorize all the options,
1541 and figure out which argv elts are option arguments. */
1542 for (from
= 1; from
< argc
; from
++)
1546 if (argv
[from
][0] == '-')
1551 /* If we have found "--", don't consider
1552 any more arguments as options. */
1553 if (argv
[from
][1] == '-' && argv
[from
][2] == 0)
1555 /* Leave the "--", and everything following it, at the end. */
1556 for (; from
< argc
; from
++)
1558 priority
[from
] = -100;
1564 /* Look for a match with a known old-fashioned option. */
1565 for (i
= 0; i
< sizeof (standard_args
) / sizeof (standard_args
[0]); i
++)
1566 if (!strcmp (argv
[from
], standard_args
[i
].name
))
1568 options
[from
] = standard_args
[i
].nargs
;
1569 priority
[from
] = standard_args
[i
].priority
;
1570 if (from
+ standard_args
[i
].nargs
>= argc
)
1571 fatal ("Option `%s' requires an argument\n", argv
[from
]);
1572 from
+= standard_args
[i
].nargs
;
1576 /* Look for a match with a known long option.
1577 MATCH is -1 if no match so far, -2 if two or more matches so far,
1578 >= 0 (the table index of the match) if just one match so far. */
1579 if (argv
[from
][1] == '-')
1582 thislen
= strlen (argv
[from
]);
1583 equals
= index (argv
[from
], '=');
1585 thislen
= equals
- argv
[from
];
1588 i
< sizeof (standard_args
) / sizeof (standard_args
[0]); i
++)
1589 if (standard_args
[i
].longname
1590 && !strncmp (argv
[from
], standard_args
[i
].longname
,
1599 /* If we found exactly one match, use that. */
1602 options
[from
] = standard_args
[match
].nargs
;
1603 priority
[from
] = standard_args
[match
].priority
;
1604 /* If --OPTION=VALUE syntax is used,
1605 this option uses just one argv element. */
1608 if (from
+ options
[from
] >= argc
)
1609 fatal ("Option `%s' requires an argument\n", argv
[from
]);
1610 from
+= options
[from
];
1617 /* Copy the arguments, in order of decreasing priority, to NEW. */
1619 while (incoming_used
< argc
)
1622 int best_priority
= -9999;
1624 /* Find the highest priority remaining option.
1625 If several have equal priority, take the first of them. */
1626 for (from
= 1; from
< argc
; from
++)
1628 if (argv
[from
] != 0 && priority
[from
] > best_priority
)
1630 best_priority
= priority
[from
];
1633 /* Skip option arguments--they are tied to the options. */
1634 if (options
[from
] > 0)
1635 from
+= options
[from
];
1641 /* Copy the highest priority remaining option, with its args, to NEW.
1642 Unless it is a duplicate of the previous one. */
1643 if (! (options
[best
] == 0
1644 && ! strcmp (new[to
- 1], argv
[best
])))
1646 new[to
++] = argv
[best
];
1647 for (i
= 0; i
< options
[best
]; i
++)
1648 new[to
++] = argv
[best
+ i
+ 1];
1651 incoming_used
+= 1 + (options
[best
] > 0 ? options
[best
] : 0);
1653 /* Clear out this option in ARGV. */
1655 for (i
= 0; i
< options
[best
]; i
++)
1656 argv
[best
+ i
+ 1] = 0;
1659 /* If duplicate options were deleted, fill up extra space with null ptrs. */
1663 bcopy (new, argv
, sizeof (char *) * argc
);
1670 DEFUN ("kill-emacs", Fkill_emacs
, Skill_emacs
, 0, 1, "P",
1671 "Exit the Emacs job and kill it.\n\
1672 If ARG is an integer, return ARG as the exit program code.\n\
1673 If ARG is a string, stuff it as keyboard input.\n\n\
1674 The value of `kill-emacs-hook', if not void,\n\
1675 is a list of functions (of no args),\n\
1676 all of which are called before Emacs is actually killed.")
1680 struct gcpro gcpro1
;
1687 if (!NILP (Vrun_hooks
) && !noninteractive
)
1688 call1 (Vrun_hooks
, intern ("kill-emacs-hook"));
1692 /* Is it really necessary to do this deassign
1693 when we are going to exit anyway? */
1698 shut_down_emacs (0, 0, STRINGP (arg
) ? arg
: Qnil
);
1700 /* If we have an auto-save list file,
1701 kill it because we are exiting Emacs deliberately (not crashing).
1702 Do it after shut_down_emacs, which does an auto-save. */
1703 if (STRINGP (Vauto_save_list_file_name
))
1704 unlink (XSTRING (Vauto_save_list_file_name
)->data
);
1706 exit (INTEGERP (arg
) ? XINT (arg
)
1717 /* Perform an orderly shutdown of Emacs. Autosave any modified
1718 buffers, kill any child processes, clean up the terminal modes (if
1719 we're in the foreground), and other stuff like that. Don't perform
1720 any redisplay; this may be called when Emacs is shutting down in
1721 the background, or after its X connection has died.
1723 If SIG is a signal number, print a message for it.
1725 This is called by fatal signal handlers, X protocol error handlers,
1729 shut_down_emacs (sig
, no_x
, stuff
)
1733 /* Prevent running of hooks from now on. */
1736 /* If we are controlling the terminal, reset terminal modes */
1737 #ifdef EMACS_HAVE_TTY_PGRP
1739 int pgrp
= EMACS_GETPGRP (0);
1742 if (EMACS_GET_TTY_PGRP (0, &tpgrp
) != -1
1747 if (sig
&& sig
!= SIGTERM
)
1748 fprintf (stderr
, "Fatal error (%d).", sig
);
1756 stuff_buffered_input (stuff
);
1758 kill_buffer_processes (Qnil
);
1759 Fdo_auto_save (Qt
, Qnil
);
1761 #ifdef CLASH_DETECTION
1762 unlock_all_files ();
1766 kill_vms_processes ();
1769 #if 0 /* This triggers a bug in XCloseDisplay and is not needed. */
1770 #ifdef HAVE_X_WINDOWS
1771 /* It's not safe to call intern here. Maybe we are crashing. */
1772 if (!noninteractive
&& SYMBOLP (Vwindow_system
)
1773 && XSYMBOL (Vwindow_system
)->name
->size
== 1
1774 && XSYMBOL (Vwindow_system
)->name
->data
[0] == 'x'
1776 Fx_close_current_connection ();
1777 #endif /* HAVE_X_WINDOWS */
1781 /* There is a tendency for a SIGIO signal to arrive within exit,
1782 and cause a SIGHUP because the input descriptor is already closed. */
1784 signal (SIGIO
, SIG_IGN
);
1791 check_glyph_memory ();
1792 check_message_stack ();
1805 DEFUN ("dump-emacs-data", Fdump_emacs_data
, Sdump_emacs_data
, 1, 1, 0,
1806 "Dump current state of Emacs into data file FILENAME.\n\
1807 This function exists on systems that use HAVE_SHM.")
1809 Lisp_Object filename
;
1811 extern char my_edata
[];
1814 CHECK_STRING (filename
, 0);
1815 filename
= Fexpand_file_name (filename
, Qnil
);
1818 Vpurify_flag
= Qnil
;
1821 /* Tell malloc where start of impure now is */
1822 /* Also arrange for warnings when nearly out of space. */
1823 #ifndef SYSTEM_MALLOC
1824 memory_warnings (my_edata
, malloc_warning
);
1826 map_out_data (XSTRING (filename
)->data
);
1833 #else /* not HAVE_SHM */
1835 DEFUN ("dump-emacs", Fdump_emacs
, Sdump_emacs
, 2, 2, 0,
1836 "Dump current state of Emacs into executable file FILENAME.\n\
1837 Take symbols from SYMFILE (presumably the file you executed to run Emacs).\n\
1838 This is used in the file `loadup.el' when building Emacs.\n\
1840 You must run Emacs in batch mode in order to dump it.")
1842 Lisp_Object filename
, symfile
;
1844 extern char my_edata
[];
1847 int count
= specpdl_ptr
- specpdl
;
1849 if (! noninteractive
)
1850 error ("Dumping Emacs works only in batch mode");
1852 /* Bind `command-line-processed' to nil before dumping,
1853 so that the dumped Emacs will process its command line
1854 and set up to work with X windows if appropriate. */
1855 symbol
= intern ("command-line-process");
1856 specbind (symbol
, Qnil
);
1858 CHECK_STRING (filename
, 0);
1859 filename
= Fexpand_file_name (filename
, Qnil
);
1860 if (!NILP (symfile
))
1862 CHECK_STRING (symfile
, 0);
1863 if (XSTRING (symfile
)->size
)
1864 symfile
= Fexpand_file_name (symfile
, Qnil
);
1868 Vpurify_flag
= Qnil
;
1871 set_time_zone_rule (dump_tz
);
1872 #ifndef LOCALTIME_CACHE
1873 /* Force a tz reload, since set_time_zone_rule doesn't. */
1880 mapout_data (XSTRING (filename
)->data
);
1882 /* Tell malloc where start of impure now is */
1883 /* Also arrange for warnings when nearly out of space. */
1884 #ifndef SYSTEM_MALLOC
1886 /* On Windows, this was done before dumping, and that once suffices.
1887 Meanwhile, my_edata is not valid on Windows. */
1888 memory_warnings (my_edata
, malloc_warning
);
1889 #endif /* not WINDOWSNT */
1891 #ifdef DOUG_LEA_MALLOC
1892 malloc_state_ptr
= malloc_get_state ();
1894 unexec (XSTRING (filename
)->data
,
1895 !NILP (symfile
) ? XSTRING (symfile
)->data
: 0, my_edata
, 0, 0);
1896 #ifdef DOUG_LEA_MALLOC
1897 free (malloc_state_ptr
);
1899 #endif /* not VMS */
1903 return unbind_to (count
, Qnil
);
1906 #endif /* not HAVE_SHM */
1908 #endif /* not CANNOT_DUMP */
1911 /* Recover from setlocale (LC_ALL, ""). */
1915 /* The Emacs Lisp reader needs LC_NUMERIC to be "C",
1916 so that numbers are read and printed properly for Emacs Lisp. */
1917 setlocale (LC_NUMERIC
, "C");
1920 /* Set system locale CATEGORY, with previous locale *PLOCALE, to
1923 synchronize_locale (category
, plocale
, desired_locale
)
1925 Lisp_Object
*plocale
;
1926 Lisp_Object desired_locale
;
1928 if (! EQ (*plocale
, desired_locale
))
1930 *plocale
= desired_locale
;
1931 setlocale (category
, (STRINGP (desired_locale
)
1932 ? (char *)(XSTRING (desired_locale
)->data
)
1937 /* Set system time locale to match Vsystem_time_locale, if possible. */
1939 synchronize_system_time_locale ()
1941 synchronize_locale (LC_TIME
, &Vprevious_system_time_locale
,
1942 Vsystem_time_locale
);
1945 /* Set system messages locale to match Vsystem_messages_locale, if
1948 synchronize_system_messages_locale ()
1951 synchronize_locale (LC_MESSAGES
, &Vprevious_system_messages_locale
,
1952 Vsystem_messages_locale
);
1955 #endif /* HAVE_SETLOCALE */
1962 decode_env_path (evarname
, defalt
)
1963 char *evarname
, *defalt
;
1965 register char *path
, *p
;
1966 Lisp_Object lpath
, element
, tem
;
1968 /* It's okay to use getenv here, because this function is only used
1969 to initialize variables when Emacs starts up, and isn't called
1972 path
= (char *) getenv (evarname
);
1978 /* Ensure values from the environment use the proper directory separator. */
1981 p
= alloca (strlen (path
) + 1);
1985 if ('/' == DIRECTORY_SEP
)
1986 dostounix_filename (path
);
1988 unixtodos_filename (path
);
1994 p
= index (path
, SEPCHAR
);
1995 if (!p
) p
= path
+ strlen (path
);
1996 element
= (p
- path
? make_string (path
, p
- path
)
1997 : build_string ("."));
1999 /* Add /: to the front of the name
2000 if it would otherwise be treated as magic. */
2001 tem
= Ffind_file_name_handler (element
, Qt
);
2003 element
= concat2 (build_string ("/:"), element
);
2005 lpath
= Fcons (element
, lpath
);
2011 return Fnreverse (lpath
);
2017 Qfile_name_handler_alist
= intern ("file-name-handler-alist");
2018 staticpro (&Qfile_name_handler_alist
);
2022 defsubr (&Sdump_emacs_data
);
2024 defsubr (&Sdump_emacs
);
2028 defsubr (&Skill_emacs
);
2030 defsubr (&Sinvocation_name
);
2031 defsubr (&Sinvocation_directory
);
2033 DEFVAR_LISP ("command-line-args", &Vcommand_line_args
,
2034 "Args passed by shell to Emacs, as a list of strings.");
2036 DEFVAR_LISP ("system-type", &Vsystem_type
,
2037 "Value is symbol indicating type of operating system you are using.");
2038 Vsystem_type
= intern (SYSTEM_TYPE
);
2040 DEFVAR_LISP ("system-configuration", &Vsystem_configuration
,
2041 "Value is string indicating configuration Emacs was built for.");
2042 Vsystem_configuration
= build_string (EMACS_CONFIGURATION
);
2044 DEFVAR_LISP ("system-configuration-options", &Vsystem_configuration_options
,
2045 "String containing the configuration options Emacs was built with.");
2046 Vsystem_configuration_options
= build_string (EMACS_CONFIG_OPTIONS
);
2048 DEFVAR_BOOL ("noninteractive", &noninteractive1
,
2049 "Non-nil means Emacs is running without interactive terminal.");
2051 DEFVAR_LISP ("kill-emacs-hook", &Vkill_emacs_hook
,
2052 "Hook to be run whenever kill-emacs is called.\n\
2053 Since kill-emacs may be invoked when the terminal is disconnected (or\n\
2054 in other similar situations), functions placed on this hook should not\n\
2055 expect to be able to interact with the user. To ask for confirmation,\n\
2056 see `kill-emacs-query-functions' instead.");
2057 Vkill_emacs_hook
= Qnil
;
2060 DEFVAR_LISP ("signal-USR1-hook", &Vsignal_USR1_hook
,
2061 "Hook to be run whenever emacs receives a USR1 signal");
2062 Vsignal_USR1_hook
= Qnil
;
2064 DEFVAR_LISP ("signal-USR2-hook", &Vsignal_USR2_hook
,
2065 "Hook to be run whenever emacs receives a USR2 signal");
2066 Vsignal_USR2_hook
= Qnil
;
2071 DEFVAR_INT ("emacs-priority", &emacs_priority
,
2072 "Priority for Emacs to run at.\n\
2073 This value is effective only if set before Emacs is dumped,\n\
2074 and only if the Emacs executable is installed with setuid to permit\n\
2075 it to change priority. (Emacs sets its uid back to the real uid.)\n\
2076 Currently, you need to define SET_EMACS_PRIORITY in `config.h'\n\
2077 before you compile Emacs, to enable the code for this feature.");
2080 DEFVAR_LISP ("path-separator", &Vpath_separator
,
2081 "The directory separator in search paths, as a string.");
2084 Vpath_separator
= make_string (&c
, 1);
2087 DEFVAR_LISP ("invocation-name", &Vinvocation_name
,
2088 "The program name that was used to run Emacs.\n\
2089 Any directory names are omitted.");
2091 DEFVAR_LISP ("invocation-directory", &Vinvocation_directory
,
2092 "The directory in which the Emacs executable was found, to run it.\n\
2093 The value is nil if that directory's name is not known.");
2095 DEFVAR_LISP ("installation-directory", &Vinstallation_directory
,
2096 "A directory within which to look for the `lib-src' and `etc' directories.\n\
2097 This is non-nil when we can't find those directories in their standard\n\
2098 installed locations, but we can find them\n\
2099 near where the Emacs executable was found.");
2100 Vinstallation_directory
= Qnil
;
2102 DEFVAR_LISP ("system-messages-locale", &Vsystem_messages_locale
,
2103 "System locale for messages.");
2104 Vsystem_messages_locale
= Qnil
;
2106 DEFVAR_LISP ("previous-system-messages-locale",
2107 &Vprevious_system_messages_locale
,
2108 "Most recently used system locale for messages.");
2109 Vprevious_system_messages_locale
= Qnil
;
2111 DEFVAR_LISP ("system-time-locale", &Vsystem_time_locale
,
2112 "System locale for time.");
2113 Vsystem_time_locale
= Qnil
;
2115 DEFVAR_LISP ("previous-system-time-locale", &Vprevious_system_time_locale
,
2116 "Most recently used system locale for time.");
2117 Vprevious_system_time_locale
= Qnil
;