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 ();
1273 syms_of_composite ();
1279 #endif /* WINDOWSNT */
1282 #ifdef HAVE_X_WINDOWS
1289 #endif /* HAVE_X_WINDOWS */
1298 syms_of_w32faces ();
1299 syms_of_w32select ();
1302 #endif /* HAVE_NTGUI */
1312 keys_of_casefiddle ();
1315 keys_of_keyboard ();
1323 if (!noninteractive
)
1326 init_vms_input ();/* init_display calls get_frame_size, that needs this */
1328 init_display (); /* Determine terminal type. init_sys_modes uses results */
1330 init_keyboard (); /* This too must precede init_sys_modes */
1332 init_vmsproc (); /* And this too. */
1334 init_sys_modes (); /* Init system terminal modes (RAW or CBREAK, etc.) */
1335 #ifdef HAVE_X_WINDOWS
1337 #endif /* HAVE_X_WINDOWS */
1342 #ifdef LISP_FLOAT_TYPE
1356 /* Handle -l loadup, args passed by Makefile. */
1357 if (argmatch (argv
, argc
, "-l", "--load", 3, &file
, &skip_args
))
1358 Vtop_level
= Fcons (intern ("load"),
1359 Fcons (build_string (file
), Qnil
));
1361 /* Unless next switch is -nl, load "loadup.el" first thing. */
1363 Vtop_level
= Fcons (intern ("load"),
1364 Fcons (build_string ("loadup.el"), Qnil
));
1365 #endif /* CANNOT_DUMP */
1372 /* If the execution TZ happens to be the same as the dump TZ,
1373 change it to some other value and then change it back,
1374 to force the underlying implementation to reload the TZ info.
1375 This is needed on implementations that load TZ info from files,
1376 since the TZ file contents may differ between dump and execution. */
1377 char *tz
= getenv ("TZ");
1378 if (tz
&& !strcmp (tz
, dump_tz
))
1388 /* Gerd Moellmann <gerd@acm.org> says this makes profiling work on
1389 FreeBSD. It might work on some other systems too.
1390 Give it a try and tell me if it works on your system. */
1391 #if defined (__FreeBSD__) || defined (__linux)
1395 extern void _mcleanup ();
1397 extern void safe_bcopy ();
1398 extern void dump_opcode_frequencies ();
1401 // atexit (dump_opcode_frequencies);
1402 /* This uses safe_bcopy because that function comes first in the
1403 Emacs executable. It might be better to use something that
1404 gives the start of the text segment, but start_of_text is not
1405 defined on all systems now. */
1406 monstartup (safe_bcopy
, &etext
);
1415 #ifdef LOCALTIME_CACHE
1416 /* Some versions of localtime have a bug. They cache the value of the time
1417 zone rather than looking it up every time. Since localtime() is
1418 called to bolt the undumping time into the undumped emacs, this
1419 results in localtime ignoring the TZ environment variable.
1420 This flushes the new TZ value into localtime. */
1422 #endif /* defined (LOCALTIME_CACHE) */
1424 /* Enter editor command loop. This never returns. */
1429 /* Sort the args so we can find the most important ones
1430 at the beginning of argv. */
1432 /* First, here's a table of all the standard options. */
1434 struct standard_args
1442 struct standard_args standard_args
[] =
1444 { "-version", "--version", 150, 0 },
1446 { "-nl", "--no-shared-memory", 140, 0 },
1449 { "-map", "--map-data", 130, 0 },
1451 { "-t", "--terminal", 120, 1 },
1452 { "-nw", "--no-windows", 110, 0 },
1453 { "-batch", "--batch", 100, 0 },
1454 { "-help", "--help", 90, 0 },
1455 { "-no-unibyte", "--no-unibyte", 83, 0 },
1456 { "-multibyte", "--multibyte", 82, 0 },
1457 { "-unibyte", "--unibyte", 81, 0 },
1458 { "-no-multibyte", "--no-multibyte", 80, 0 },
1460 { "-nl", "--no-loadup", 70, 0 },
1462 /* -d must come last before the options handled in startup.el. */
1463 { "-d", "--display", 60, 1 },
1464 { "-display", 0, 60, 1 },
1465 /* Now for the options handled in startup.el. */
1466 { "-q", "--no-init-file", 50, 0 },
1467 { "-no-init-file", 0, 50, 0 },
1468 { "-no-site-file", "--no-site-file", 40, 0 },
1469 { "-u", "--user", 30, 1 },
1470 { "-user", 0, 30, 1 },
1471 { "-debug-init", "--debug-init", 20, 0 },
1472 { "-i", "--icon-type", 15, 0 },
1473 { "-itype", 0, 15, 0 },
1474 { "-iconic", "--iconic", 15, 0 },
1475 { "-bg", "--background-color", 10, 1 },
1476 { "-background", 0, 10, 1 },
1477 { "-fg", "--foreground-color", 10, 1 },
1478 { "-foreground", 0, 10, 1 },
1479 { "-bd", "--border-color", 10, 1 },
1480 { "-bw", "--border-width", 10, 1 },
1481 { "-ib", "--internal-border", 10, 1 },
1482 { "-ms", "--mouse-color", 10, 1 },
1483 { "-cr", "--cursor-color", 10, 1 },
1484 { "-fn", "--font", 10, 1 },
1485 { "-font", 0, 10, 1 },
1486 { "-g", "--geometry", 10, 1 },
1487 { "-geometry", 0, 10, 1 },
1488 { "-T", "--title", 10, 1 },
1489 { "-title", 0, 10, 1 },
1490 { "-name", "--name", 10, 1 },
1491 { "-xrm", "--xrm", 10, 1 },
1492 { "-r", "--reverse-video", 5, 0 },
1494 { "-reverse", 0, 5, 0 },
1495 { "-hb", "--horizontal-scroll-bars", 5, 0 },
1496 { "-vb", "--vertical-scroll-bars", 5, 0 },
1497 /* These have the same priority as ordinary file name args,
1498 so they are not reordered with respect to those. */
1499 { "-L", "--directory", 0, 1 },
1500 { "-directory", 0, 0, 1 },
1501 { "-l", "--load", 0, 1 },
1502 { "-load", 0, 0, 1 },
1503 { "-f", "--funcall", 0, 1 },
1504 { "-funcall", 0, 0, 1 },
1505 { "-eval", "--eval", 0, 1 },
1506 { "-execute", "--execute", 0, 1 },
1507 { "-find-file", "--find-file", 0, 1 },
1508 { "-visit", "--visit", 0, 1 },
1509 { "-file", "--file", 0, 1 },
1510 { "-insert", "--insert", 0, 1 },
1511 /* This should be processed after ordinary file name args and the like. */
1512 { "-kill", "--kill", -10, 0 },
1515 /* Reorder the elements of ARGV (assumed to have ARGC elements)
1516 so that the highest priority ones come first.
1517 Do not change the order of elements of equal priority.
1518 If an option takes an argument, keep it and its argument together.
1520 If an option that takes no argument appears more
1521 than once, eliminate all but one copy of it. */
1524 sort_args (argc
, argv
)
1528 char **new = (char **) xmalloc (sizeof (char *) * argc
);
1529 /* For each element of argv,
1530 the corresponding element of options is:
1531 0 for an option that takes no arguments,
1532 1 for an option that takes one argument, etc.
1533 -1 for an ordinary non-option argument. */
1534 int *options
= (int *) xmalloc (sizeof (int) * argc
);
1535 int *priority
= (int *) xmalloc (sizeof (int) * argc
);
1537 int incoming_used
= 1;
1541 /* Categorize all the options,
1542 and figure out which argv elts are option arguments. */
1543 for (from
= 1; from
< argc
; from
++)
1547 if (argv
[from
][0] == '-')
1552 /* If we have found "--", don't consider
1553 any more arguments as options. */
1554 if (argv
[from
][1] == '-' && argv
[from
][2] == 0)
1556 /* Leave the "--", and everything following it, at the end. */
1557 for (; from
< argc
; from
++)
1559 priority
[from
] = -100;
1565 /* Look for a match with a known old-fashioned option. */
1566 for (i
= 0; i
< sizeof (standard_args
) / sizeof (standard_args
[0]); i
++)
1567 if (!strcmp (argv
[from
], standard_args
[i
].name
))
1569 options
[from
] = standard_args
[i
].nargs
;
1570 priority
[from
] = standard_args
[i
].priority
;
1571 if (from
+ standard_args
[i
].nargs
>= argc
)
1572 fatal ("Option `%s' requires an argument\n", argv
[from
]);
1573 from
+= standard_args
[i
].nargs
;
1577 /* Look for a match with a known long option.
1578 MATCH is -1 if no match so far, -2 if two or more matches so far,
1579 >= 0 (the table index of the match) if just one match so far. */
1580 if (argv
[from
][1] == '-')
1583 thislen
= strlen (argv
[from
]);
1584 equals
= index (argv
[from
], '=');
1586 thislen
= equals
- argv
[from
];
1589 i
< sizeof (standard_args
) / sizeof (standard_args
[0]); i
++)
1590 if (standard_args
[i
].longname
1591 && !strncmp (argv
[from
], standard_args
[i
].longname
,
1600 /* If we found exactly one match, use that. */
1603 options
[from
] = standard_args
[match
].nargs
;
1604 priority
[from
] = standard_args
[match
].priority
;
1605 /* If --OPTION=VALUE syntax is used,
1606 this option uses just one argv element. */
1609 if (from
+ options
[from
] >= argc
)
1610 fatal ("Option `%s' requires an argument\n", argv
[from
]);
1611 from
+= options
[from
];
1618 /* Copy the arguments, in order of decreasing priority, to NEW. */
1620 while (incoming_used
< argc
)
1623 int best_priority
= -9999;
1625 /* Find the highest priority remaining option.
1626 If several have equal priority, take the first of them. */
1627 for (from
= 1; from
< argc
; from
++)
1629 if (argv
[from
] != 0 && priority
[from
] > best_priority
)
1631 best_priority
= priority
[from
];
1634 /* Skip option arguments--they are tied to the options. */
1635 if (options
[from
] > 0)
1636 from
+= options
[from
];
1642 /* Copy the highest priority remaining option, with its args, to NEW.
1643 Unless it is a duplicate of the previous one. */
1644 if (! (options
[best
] == 0
1645 && ! strcmp (new[to
- 1], argv
[best
])))
1647 new[to
++] = argv
[best
];
1648 for (i
= 0; i
< options
[best
]; i
++)
1649 new[to
++] = argv
[best
+ i
+ 1];
1652 incoming_used
+= 1 + (options
[best
] > 0 ? options
[best
] : 0);
1654 /* Clear out this option in ARGV. */
1656 for (i
= 0; i
< options
[best
]; i
++)
1657 argv
[best
+ i
+ 1] = 0;
1660 /* If duplicate options were deleted, fill up extra space with null ptrs. */
1664 bcopy (new, argv
, sizeof (char *) * argc
);
1671 DEFUN ("kill-emacs", Fkill_emacs
, Skill_emacs
, 0, 1, "P",
1672 "Exit the Emacs job and kill it.\n\
1673 If ARG is an integer, return ARG as the exit program code.\n\
1674 If ARG is a string, stuff it as keyboard input.\n\n\
1675 The value of `kill-emacs-hook', if not void,\n\
1676 is a list of functions (of no args),\n\
1677 all of which are called before Emacs is actually killed.")
1681 struct gcpro gcpro1
;
1688 if (!NILP (Vrun_hooks
) && !noninteractive
)
1689 call1 (Vrun_hooks
, intern ("kill-emacs-hook"));
1693 /* Is it really necessary to do this deassign
1694 when we are going to exit anyway? */
1699 shut_down_emacs (0, 0, STRINGP (arg
) ? arg
: Qnil
);
1701 /* If we have an auto-save list file,
1702 kill it because we are exiting Emacs deliberately (not crashing).
1703 Do it after shut_down_emacs, which does an auto-save. */
1704 if (STRINGP (Vauto_save_list_file_name
))
1705 unlink (XSTRING (Vauto_save_list_file_name
)->data
);
1707 exit (INTEGERP (arg
) ? XINT (arg
)
1718 /* Perform an orderly shutdown of Emacs. Autosave any modified
1719 buffers, kill any child processes, clean up the terminal modes (if
1720 we're in the foreground), and other stuff like that. Don't perform
1721 any redisplay; this may be called when Emacs is shutting down in
1722 the background, or after its X connection has died.
1724 If SIG is a signal number, print a message for it.
1726 This is called by fatal signal handlers, X protocol error handlers,
1730 shut_down_emacs (sig
, no_x
, stuff
)
1734 /* Prevent running of hooks from now on. */
1737 /* If we are controlling the terminal, reset terminal modes */
1738 #ifdef EMACS_HAVE_TTY_PGRP
1740 int pgrp
= EMACS_GETPGRP (0);
1743 if (EMACS_GET_TTY_PGRP (0, &tpgrp
) != -1
1748 if (sig
&& sig
!= SIGTERM
)
1749 fprintf (stderr
, "Fatal error (%d).", sig
);
1757 stuff_buffered_input (stuff
);
1759 kill_buffer_processes (Qnil
);
1760 Fdo_auto_save (Qt
, Qnil
);
1762 #ifdef CLASH_DETECTION
1763 unlock_all_files ();
1767 kill_vms_processes ();
1770 #if 0 /* This triggers a bug in XCloseDisplay and is not needed. */
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
== 1
1775 && XSYMBOL (Vwindow_system
)->name
->data
[0] == 'x'
1777 Fx_close_current_connection ();
1778 #endif /* HAVE_X_WINDOWS */
1782 /* There is a tendency for a SIGIO signal to arrive within exit,
1783 and cause a SIGHUP because the input descriptor is already closed. */
1785 signal (SIGIO
, SIG_IGN
);
1792 check_glyph_memory ();
1793 check_message_stack ();
1806 DEFUN ("dump-emacs-data", Fdump_emacs_data
, Sdump_emacs_data
, 1, 1, 0,
1807 "Dump current state of Emacs into data file FILENAME.\n\
1808 This function exists on systems that use HAVE_SHM.")
1810 Lisp_Object filename
;
1812 extern char my_edata
[];
1815 CHECK_STRING (filename
, 0);
1816 filename
= Fexpand_file_name (filename
, Qnil
);
1819 Vpurify_flag
= Qnil
;
1822 /* Tell malloc where start of impure now is */
1823 /* Also arrange for warnings when nearly out of space. */
1824 #ifndef SYSTEM_MALLOC
1825 memory_warnings (my_edata
, malloc_warning
);
1827 map_out_data (XSTRING (filename
)->data
);
1834 #else /* not HAVE_SHM */
1836 DEFUN ("dump-emacs", Fdump_emacs
, Sdump_emacs
, 2, 2, 0,
1837 "Dump current state of Emacs into executable file FILENAME.\n\
1838 Take symbols from SYMFILE (presumably the file you executed to run Emacs).\n\
1839 This is used in the file `loadup.el' when building Emacs.\n\
1841 You must run Emacs in batch mode in order to dump it.")
1843 Lisp_Object filename
, symfile
;
1845 extern char my_edata
[];
1848 int count
= specpdl_ptr
- specpdl
;
1850 if (! noninteractive
)
1851 error ("Dumping Emacs works only in batch mode");
1853 /* Bind `command-line-processed' to nil before dumping,
1854 so that the dumped Emacs will process its command line
1855 and set up to work with X windows if appropriate. */
1856 symbol
= intern ("command-line-process");
1857 specbind (symbol
, Qnil
);
1859 CHECK_STRING (filename
, 0);
1860 filename
= Fexpand_file_name (filename
, Qnil
);
1861 if (!NILP (symfile
))
1863 CHECK_STRING (symfile
, 0);
1864 if (XSTRING (symfile
)->size
)
1865 symfile
= Fexpand_file_name (symfile
, Qnil
);
1869 Vpurify_flag
= Qnil
;
1872 set_time_zone_rule (dump_tz
);
1873 #ifndef LOCALTIME_CACHE
1874 /* Force a tz reload, since set_time_zone_rule doesn't. */
1881 mapout_data (XSTRING (filename
)->data
);
1883 /* Tell malloc where start of impure now is */
1884 /* Also arrange for warnings when nearly out of space. */
1885 #ifndef SYSTEM_MALLOC
1887 /* On Windows, this was done before dumping, and that once suffices.
1888 Meanwhile, my_edata is not valid on Windows. */
1889 memory_warnings (my_edata
, malloc_warning
);
1890 #endif /* not WINDOWSNT */
1892 #ifdef DOUG_LEA_MALLOC
1893 malloc_state_ptr
= malloc_get_state ();
1895 unexec (XSTRING (filename
)->data
,
1896 !NILP (symfile
) ? XSTRING (symfile
)->data
: 0, my_edata
, 0, 0);
1897 #ifdef DOUG_LEA_MALLOC
1898 free (malloc_state_ptr
);
1900 #endif /* not VMS */
1904 return unbind_to (count
, Qnil
);
1907 #endif /* not HAVE_SHM */
1909 #endif /* not CANNOT_DUMP */
1912 /* Recover from setlocale (LC_ALL, ""). */
1916 /* The Emacs Lisp reader needs LC_NUMERIC to be "C",
1917 so that numbers are read and printed properly for Emacs Lisp. */
1918 setlocale (LC_NUMERIC
, "C");
1921 /* Set system locale CATEGORY, with previous locale *PLOCALE, to
1924 synchronize_locale (category
, plocale
, desired_locale
)
1926 Lisp_Object
*plocale
;
1927 Lisp_Object desired_locale
;
1929 if (! EQ (*plocale
, desired_locale
))
1931 *plocale
= desired_locale
;
1932 setlocale (category
, (STRINGP (desired_locale
)
1933 ? (char *)(XSTRING (desired_locale
)->data
)
1938 /* Set system time locale to match Vsystem_time_locale, if possible. */
1940 synchronize_system_time_locale ()
1942 synchronize_locale (LC_TIME
, &Vprevious_system_time_locale
,
1943 Vsystem_time_locale
);
1946 /* Set system messages locale to match Vsystem_messages_locale, if
1949 synchronize_system_messages_locale ()
1952 synchronize_locale (LC_MESSAGES
, &Vprevious_system_messages_locale
,
1953 Vsystem_messages_locale
);
1956 #endif /* HAVE_SETLOCALE */
1963 decode_env_path (evarname
, defalt
)
1964 char *evarname
, *defalt
;
1966 register char *path
, *p
;
1967 Lisp_Object lpath
, element
, tem
;
1969 /* It's okay to use getenv here, because this function is only used
1970 to initialize variables when Emacs starts up, and isn't called
1973 path
= (char *) getenv (evarname
);
1979 /* Ensure values from the environment use the proper directory separator. */
1982 p
= alloca (strlen (path
) + 1);
1986 if ('/' == DIRECTORY_SEP
)
1987 dostounix_filename (path
);
1989 unixtodos_filename (path
);
1995 p
= index (path
, SEPCHAR
);
1996 if (!p
) p
= path
+ strlen (path
);
1997 element
= (p
- path
? make_string (path
, p
- path
)
1998 : build_string ("."));
2000 /* Add /: to the front of the name
2001 if it would otherwise be treated as magic. */
2002 tem
= Ffind_file_name_handler (element
, Qt
);
2004 element
= concat2 (build_string ("/:"), element
);
2006 lpath
= Fcons (element
, lpath
);
2012 return Fnreverse (lpath
);
2018 Qfile_name_handler_alist
= intern ("file-name-handler-alist");
2019 staticpro (&Qfile_name_handler_alist
);
2023 defsubr (&Sdump_emacs_data
);
2025 defsubr (&Sdump_emacs
);
2029 defsubr (&Skill_emacs
);
2031 defsubr (&Sinvocation_name
);
2032 defsubr (&Sinvocation_directory
);
2034 DEFVAR_LISP ("command-line-args", &Vcommand_line_args
,
2035 "Args passed by shell to Emacs, as a list of strings.");
2037 DEFVAR_LISP ("system-type", &Vsystem_type
,
2038 "Value is symbol indicating type of operating system you are using.");
2039 Vsystem_type
= intern (SYSTEM_TYPE
);
2041 DEFVAR_LISP ("system-configuration", &Vsystem_configuration
,
2042 "Value is string indicating configuration Emacs was built for.");
2043 Vsystem_configuration
= build_string (EMACS_CONFIGURATION
);
2045 DEFVAR_LISP ("system-configuration-options", &Vsystem_configuration_options
,
2046 "String containing the configuration options Emacs was built with.");
2047 Vsystem_configuration_options
= build_string (EMACS_CONFIG_OPTIONS
);
2049 DEFVAR_BOOL ("noninteractive", &noninteractive1
,
2050 "Non-nil means Emacs is running without interactive terminal.");
2052 DEFVAR_LISP ("kill-emacs-hook", &Vkill_emacs_hook
,
2053 "Hook to be run whenever kill-emacs is called.\n\
2054 Since kill-emacs may be invoked when the terminal is disconnected (or\n\
2055 in other similar situations), functions placed on this hook should not\n\
2056 expect to be able to interact with the user. To ask for confirmation,\n\
2057 see `kill-emacs-query-functions' instead.");
2058 Vkill_emacs_hook
= Qnil
;
2061 DEFVAR_LISP ("signal-USR1-hook", &Vsignal_USR1_hook
,
2062 "Hook to be run whenever emacs receives a USR1 signal");
2063 Vsignal_USR1_hook
= Qnil
;
2065 DEFVAR_LISP ("signal-USR2-hook", &Vsignal_USR2_hook
,
2066 "Hook to be run whenever emacs receives a USR2 signal");
2067 Vsignal_USR2_hook
= Qnil
;
2072 DEFVAR_INT ("emacs-priority", &emacs_priority
,
2073 "Priority for Emacs to run at.\n\
2074 This value is effective only if set before Emacs is dumped,\n\
2075 and only if the Emacs executable is installed with setuid to permit\n\
2076 it to change priority. (Emacs sets its uid back to the real uid.)\n\
2077 Currently, you need to define SET_EMACS_PRIORITY in `config.h'\n\
2078 before you compile Emacs, to enable the code for this feature.");
2081 DEFVAR_LISP ("path-separator", &Vpath_separator
,
2082 "The directory separator in search paths, as a string.");
2085 Vpath_separator
= make_string (&c
, 1);
2088 DEFVAR_LISP ("invocation-name", &Vinvocation_name
,
2089 "The program name that was used to run Emacs.\n\
2090 Any directory names are omitted.");
2092 DEFVAR_LISP ("invocation-directory", &Vinvocation_directory
,
2093 "The directory in which the Emacs executable was found, to run it.\n\
2094 The value is nil if that directory's name is not known.");
2096 DEFVAR_LISP ("installation-directory", &Vinstallation_directory
,
2097 "A directory within which to look for the `lib-src' and `etc' directories.\n\
2098 This is non-nil when we can't find those directories in their standard\n\
2099 installed locations, but we can find them\n\
2100 near where the Emacs executable was found.");
2101 Vinstallation_directory
= Qnil
;
2103 DEFVAR_LISP ("system-messages-locale", &Vsystem_messages_locale
,
2104 "System locale for messages.");
2105 Vsystem_messages_locale
= Qnil
;
2107 DEFVAR_LISP ("previous-system-messages-locale",
2108 &Vprevious_system_messages_locale
,
2109 "Most recently used system locale for messages.");
2110 Vprevious_system_messages_locale
= Qnil
;
2112 DEFVAR_LISP ("system-time-locale", &Vsystem_time_locale
,
2113 "System locale for time.");
2114 Vsystem_time_locale
= Qnil
;
2116 DEFVAR_LISP ("previous-system-time-locale", &Vprevious_system_time_locale
,
2117 "Most recently used system locale for time.");
2118 Vprevious_system_time_locale
= Qnil
;