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;
82 /* Command line args from shell, as list of strings */
83 Lisp_Object Vcommand_line_args
;
85 /* The name under which Emacs was invoked, with any leading directory
87 Lisp_Object Vinvocation_name
;
89 /* The directory name from which Emacs was invoked. */
90 Lisp_Object Vinvocation_directory
;
92 /* The directory name in which to find subdirs such as lisp and etc.
93 nil means get them only from PATH_LOADSEARCH. */
94 Lisp_Object Vinstallation_directory
;
96 /* Hook run by `kill-emacs' before it does really anything. */
97 Lisp_Object Vkill_emacs_hook
;
100 /* Hooks for signal USR1 and USR2 handing */
101 Lisp_Object Vsignal_USR1_hook
;
103 Lisp_Object Vsignal_USR2_hook
;
107 /* Search path separator. */
108 Lisp_Object Vpath_separator
;
110 /* Set nonzero after Emacs has started up the first time.
111 Prevents reinitialization of the Lisp world and keymaps
112 on subsequent starts. */
115 #ifdef DOUG_LEA_MALLOC
116 /* Preserves a pointer to the memory allocated that copies that
117 static data inside glibc's malloc. */
118 void *malloc_state_ptr
;
119 /* From glibc, a routine that returns a copy of the malloc internal state. */
120 extern void *malloc_get_state ();
121 /* From glibc, a routine that overwrites the malloc internal state. */
122 extern void malloc_set_state ();
123 /* Non-zero if the MALLOC_CHECK_ enviroment variable was set while
124 dumping. Used to work around a bug in glibc's malloc. */
125 int malloc_using_checking
;
128 /* Variable whose value is symbol giving operating system type. */
129 Lisp_Object Vsystem_type
;
131 /* Variable whose value is string giving configuration built for. */
132 Lisp_Object Vsystem_configuration
;
134 /* Variable whose value is string giving configuration options,
135 for use when reporting bugs. */
136 Lisp_Object Vsystem_configuration_options
;
138 Lisp_Object Qfile_name_handler_alist
;
140 /* Current and previous system locales for messages and time. */
141 Lisp_Object Vsystem_messages_locale
;
142 Lisp_Object Vprevious_system_messages_locale
;
143 Lisp_Object Vsystem_time_locale
;
144 Lisp_Object Vprevious_system_time_locale
;
146 /* If non-zero, emacs should not attempt to use an window-specific code,
147 but instead should use the virtual terminal under which it was started */
148 int inhibit_window_system
;
150 /* If nonzero, set Emacs to run at this priority. This is also used
151 in child_setup and sys_suspend to make sure subshells run at normal
152 priority; Those functions have their own extern declaration. */
155 /* If non-zero a filter or a sentinel is running. Tested to save the match
156 data on the first attempt to change it inside asynchronous code. */
157 int running_asynch_code
;
161 extern int inherited_pgroup
;
164 #ifdef HAVE_X_WINDOWS
165 /* If non-zero, -d was specified, meaning we're using some window system. */
169 /* An address near the bottom of the stack.
170 Tells GC how to save a copy of the stack. */
173 #ifdef HAVE_WINDOW_SYSTEM
174 extern Lisp_Object Vwindow_system
;
175 #endif /* HAVE_WINDOW_SYSTEM */
177 extern Lisp_Object Vauto_save_list_file_name
;
179 #ifdef USG_SHARED_LIBRARIES
180 /* If nonzero, this is the place to put the end of the writable segment
183 unsigned int bss_end
= 0;
186 /* Nonzero means running Emacs without interactive terminal. */
190 /* Value of Lisp variable `noninteractive'.
191 Normally same as C variable `noninteractive'
192 but nothing terrible happens if user sets this one. */
196 /* Save argv and argc. */
200 static void sort_args ();
201 void syms_of_emacs ();
203 /* Signal code for the fatal signal that was received */
204 int fatal_error_code
;
206 /* Nonzero if handling a fatal error already */
207 int fatal_error_in_progress
;
211 handle_USR1_signal (sig
)
214 struct input_event buf
;
216 buf
.kind
= user_signal
;
218 buf
.frame_or_window
= selected_frame
;
222 kbd_buffer_store_event (&buf
);
228 handle_USR2_signal (sig
)
231 struct input_event buf
;
233 buf
.kind
= user_signal
;
235 buf
.frame_or_window
= selected_frame
;
239 kbd_buffer_store_event (&buf
);
243 /* Handle bus errors, illegal instruction, etc. */
245 fatal_error_signal (sig
)
248 fatal_error_code
= sig
;
249 signal (sig
, SIG_DFL
);
251 TOTALLY_UNBLOCK_INPUT
;
253 /* If fatal error occurs in code below, avoid infinite recursion. */
254 if (! fatal_error_in_progress
)
256 fatal_error_in_progress
= 1;
258 shut_down_emacs (sig
, 0, Qnil
);
262 LIB$
STOP (SS$_ABORT
);
264 /* Signal the same code; this time it will really be fatal.
265 Remember that since we're in a signal handler, the signal we're
266 going to send is probably blocked, so we have to unblock it if we
267 want to really receive it. */
269 sigunblock (sigmask (fatal_error_code
));
271 kill (getpid (), fatal_error_code
);
277 /* Handler for SIGDANGER. */
279 memory_warning_signal (sig
)
282 signal (sig
, memory_warning_signal
);
284 malloc_warning ("Operating system warns that virtual memory is running low.\n");
286 /* It might be unsafe to call do_auto_save now. */
287 force_auto_save_soon ();
291 /* We define abort, rather than using it from the library,
292 so that GDB can return from a breakpoint here.
293 MSDOS has its own definition on msdos.c */
295 #if ! defined (DOS_NT) && ! defined (NO_ABORT)
297 #ifndef ABORT_RETURN_TYPE
298 #define ABORT_RETURN_TYPE void
304 kill (getpid (), SIGABRT
);
305 /* This shouldn't be executed, but it prevents a warning. */
311 /* Code for dealing with Lisp access to the Unix command line */
314 init_cmdargs (argc
, argv
, skip_args
)
320 Lisp_Object name
, dir
, tem
;
321 int count
= specpdl_ptr
- specpdl
;
322 Lisp_Object raw_name
;
327 raw_name
= build_string (argv
[0]);
329 /* Add /: to the front of the name
330 if it would otherwise be treated as magic. */
331 tem
= Ffind_file_name_handler (raw_name
, Qt
);
333 raw_name
= concat2 (build_string ("/:"), raw_name
);
335 Vinvocation_name
= Ffile_name_nondirectory (raw_name
);
336 Vinvocation_directory
= Ffile_name_directory (raw_name
);
338 /* If we got no directory in argv[0], search PATH to find where
339 Emacs actually came from. */
340 if (NILP (Vinvocation_directory
))
343 int yes
= openp (Vexec_path
, Vinvocation_name
,
344 EXEC_SUFFIXES
, &found
, 1);
347 /* Add /: to the front of the name
348 if it would otherwise be treated as magic. */
349 tem
= Ffind_file_name_handler (found
, Qt
);
351 found
= concat2 (build_string ("/:"), found
);
352 Vinvocation_directory
= Ffile_name_directory (found
);
356 if (!NILP (Vinvocation_directory
)
357 && NILP (Ffile_name_absolute_p (Vinvocation_directory
)))
358 /* Emacs was started with relative path, like ./emacs.
360 Vinvocation_directory
= Fexpand_file_name (Vinvocation_directory
, Qnil
);
362 Vinstallation_directory
= Qnil
;
364 if (!NILP (Vinvocation_directory
))
366 dir
= Vinvocation_directory
;
367 name
= Fexpand_file_name (Vinvocation_name
, dir
);
370 Lisp_Object tem
, lib_src_exists
;
371 Lisp_Object etc_exists
, info_exists
;
373 /* See if dir contains subdirs for use by Emacs.
374 Check for the ones that would exist in a build directory,
375 not including lisp and info. */
376 tem
= Fexpand_file_name (build_string ("lib-src"), dir
);
377 lib_src_exists
= Ffile_exists_p (tem
);
380 /* MSDOS installations frequently remove lib-src, but we still
381 must set installation-directory, or else info won't find
382 its files (it uses the value of installation-directory). */
383 tem
= Fexpand_file_name (build_string ("info"), dir
);
384 info_exists
= Ffile_exists_p (tem
);
389 if (!NILP (lib_src_exists
) || !NILP (info_exists
))
391 tem
= Fexpand_file_name (build_string ("etc"), dir
);
392 etc_exists
= Ffile_exists_p (tem
);
393 if (!NILP (etc_exists
))
395 Vinstallation_directory
396 = Ffile_name_as_directory (dir
);
401 /* See if dir's parent contains those subdirs. */
402 tem
= Fexpand_file_name (build_string ("../lib-src"), dir
);
403 lib_src_exists
= Ffile_exists_p (tem
);
407 /* See the MSDOS commentary above. */
408 tem
= Fexpand_file_name (build_string ("../info"), dir
);
409 info_exists
= Ffile_exists_p (tem
);
414 if (!NILP (lib_src_exists
) || !NILP (info_exists
))
416 tem
= Fexpand_file_name (build_string ("../etc"), dir
);
417 etc_exists
= Ffile_exists_p (tem
);
418 if (!NILP (etc_exists
))
420 tem
= Fexpand_file_name (build_string (".."), dir
);
421 Vinstallation_directory
422 = Ffile_name_as_directory (tem
);
427 /* If the Emacs executable is actually a link,
428 next try the dir that the link points into. */
429 tem
= Ffile_symlink_p (name
);
432 name
= Fexpand_file_name (tem
, dir
);
433 dir
= Ffile_name_directory (name
);
440 Vcommand_line_args
= Qnil
;
442 for (i
= argc
- 1; i
>= 0; i
--)
444 if (i
== 0 || i
> skip_args
)
446 = Fcons (build_string (argv
[i
]), Vcommand_line_args
);
449 unbind_to (count
, Qnil
);
452 DEFUN ("invocation-name", Finvocation_name
, Sinvocation_name
, 0, 0, 0,
453 "Return the program name that was used to run Emacs.\n\
454 Any directory names are omitted.")
457 return Fcopy_sequence (Vinvocation_name
);
460 DEFUN ("invocation-directory", Finvocation_directory
, Sinvocation_directory
,
462 "Return the directory name in which the Emacs executable was located")
465 return Fcopy_sequence (Vinvocation_directory
);
470 #ifdef LINK_CRTL_SHARE
471 #ifdef SHARABLE_LIB_BUG
472 extern noshare
char **environ
;
473 #endif /* SHARABLE_LIB_BUG */
474 #endif /* LINK_CRTL_SHARE */
478 /* A valid but unlikely value for the TZ environment value.
479 It is OK (though a bit slower) if the user actually chooses this value. */
480 static char dump_tz
[] = "UtC0";
483 #ifndef ORDINARY_LINK
484 /* We don't include crtbegin.o and crtend.o in the link,
485 so these functions and variables might be missed.
486 Provide dummy definitions to avoid error.
487 (We don't have any real constructors or destructors.) */
489 #ifndef GCC_CTORS_IN_LIBC
490 void __do_global_ctors ()
492 void __do_global_ctors_aux ()
494 void __do_global_dtors ()
496 /* Linux has a bug in its library; avoid an error. */
498 char * __CTOR_LIST__
[2] = { (char *) (-1), 0 };
500 char * __DTOR_LIST__
[2] = { (char *) (-1), 0 };
501 #endif /* GCC_CTORS_IN_LIBC */
504 #endif /* __GNUC__ */
505 #endif /* ORDINARY_LINK */
507 /* Test whether the next argument in ARGV matches SSTR or a prefix of
508 LSTR (at least MINLEN characters). If so, then if VALPTR is non-null
509 (the argument is supposed to have a value) store in *VALPTR either
510 the next argument or the portion of this one after the equal sign.
511 ARGV is read starting at position *SKIPPTR; this index is advanced
512 by the number of arguments used.
514 Too bad we can't just use getopt for all of this, but we don't have
515 enough information to do it right. */
518 argmatch (argv
, argc
, sstr
, lstr
, minlen
, valptr
, skipptr
)
531 /* Don't access argv[argc]; give up in advance. */
532 if (argc
<= *skipptr
+ 1)
535 arg
= argv
[*skipptr
+1];
538 if (strcmp (arg
, sstr
) == 0)
542 *valptr
= argv
[*skipptr
+2];
549 arglen
= (valptr
!= NULL
&& (p
= index (arg
, '=')) != NULL
550 ? p
- arg
: strlen (arg
));
551 if (lstr
== 0 || arglen
< minlen
|| strncmp (arg
, lstr
, arglen
) != 0)
553 else if (valptr
== NULL
)
564 else if (argv
[*skipptr
+2] != NULL
)
566 *valptr
= argv
[*skipptr
+2];
576 #ifdef DOUG_LEA_MALLOC
578 /* malloc can be invoked even before main (e.g. by the dynamic
579 linker), so the dumped malloc state must be restored as early as
580 possible using this special hook. */
583 malloc_initialize_hook ()
585 extern char **environ
;
589 if (!malloc_using_checking
)
590 /* Work around a bug in glibc's malloc. MALLOC_CHECK_ must be
591 ignored if the heap to be restored was constructed without
592 malloc checking. Can't use unsetenv, since that calls malloc. */
596 for (p
= environ
; *p
; p
++)
597 if (strncmp (*p
, "MALLOC_CHECK_=", 14) == 0)
606 malloc_set_state (malloc_state_ptr
);
607 free (malloc_state_ptr
);
610 malloc_using_checking
= getenv ("MALLOC_CHECK_") != NULL
;
613 void (*__malloc_initialize_hook
) () = malloc_initialize_hook
;
615 #endif /* DOUG_LEA_MALLOC */
619 main (argc
, argv
, envp
)
624 char stack_bottom_variable
;
625 int do_initial_setlocale
;
629 #ifdef HAVE_SETRLIMIT
634 #ifdef LINUX_SBRK_BUG
638 #ifdef RUN_TIME_REMAP
640 run_time_remap (argv
[0]);
643 sort_args (argc
, argv
);
645 while (argv
[argc
]) argc
++;
647 if (argmatch (argv
, argc
, "-version", "--version", 3, NULL
, &skip_args
)
648 /* We don't know the version number unless this is a dumped Emacs.
649 So ignore --version otherwise. */
653 tem
= Fsymbol_value (intern ("emacs-version"));
656 fprintf (stderr
, "Invalid value of `emacs-version'\n");
661 printf ("GNU Emacs %s\n", XSTRING (tem
)->data
);
662 printf ("Copyright (C) 1999 Free Software Foundation, Inc.\n");
663 printf ("GNU Emacs comes with ABSOLUTELY NO WARRANTY.\n");
664 printf ("You may redistribute copies of Emacs\n");
665 printf ("under the terms of the GNU General Public License.\n");
666 printf ("For more information about these matters, ");
667 printf ("see the file named COPYING.\n");
672 /* Map in shared memory, if we are using that. */
674 if (argmatch (argv
, argc
, "-nl", "--no-shared-memory", 6, NULL
, &skip_args
))
677 /* The shared memory was just restored, which clobbered this. */
683 /* The shared memory was just restored, which clobbered this. */
690 extern int malloc_cookie
;
691 /* This helps out unexnext.c. */
693 if (malloc_jumpstart (malloc_cookie
) != 0)
694 printf ("malloc jumpstart failed!\n");
699 /* If -map specified, map the data file in */
702 if (argmatch (argv
, argc
, "-map", "--map-data", 3, &mapin_file
, &skip_args
))
706 #ifdef LINK_CRTL_SHARE
707 #ifdef SHARABLE_LIB_BUG
708 /* Bletcherous shared libraries! */
710 stdin
= fdopen (0, "r");
712 stdout
= fdopen (1, "w");
714 stderr
= fdopen (2, "w");
717 #endif /* SHARABLE_LIB_BUG */
718 #endif /* LINK_CRTL_SHARE */
721 #if defined (HAVE_SETRLIMIT) && defined (RLIMIT_STACK)
722 /* Extend the stack space available.
723 Don't do that if dumping, since some systems (e.g. DJGPP)
724 might define a smaller stack limit at that time. */
727 && (!noninteractive
|| initialized
)
729 && !getrlimit (RLIMIT_STACK
, &rlim
))
732 extern int re_max_failures
;
733 /* Approximate the amount regex.c needs per unit of re_max_failures. */
734 int ratio
= 20 * sizeof (char *);
735 /* Then add 33% to cover the size of the smaller stacks that regex.c
736 successively allocates and discards, on its way to the maximum. */
738 /* Add in some extra to cover
739 what we're likely to use for other reasons. */
740 newlim
= re_max_failures
* ratio
+ 200000;
742 /* NetBSD (at least NetBSD 1.2G and former) has a bug in its
743 stack allocation routine for new process that the allocation
744 fails if stack limit is not on page boundary. So, round up the
745 new limit to page boundary. */
746 newlim
= (newlim
+ getpagesize () - 1) / getpagesize () * getpagesize();
748 if (newlim
> rlim
.rlim_max
)
750 newlim
= rlim
.rlim_max
;
751 /* Don't let regex.c overflow the stack we have. */
752 re_max_failures
= (newlim
- 200000) / ratio
;
754 if (rlim
.rlim_cur
< newlim
)
755 rlim
.rlim_cur
= newlim
;
757 setrlimit (RLIMIT_STACK
, &rlim
);
759 #endif /* HAVE_SETRLIMIT and RLIMIT_STACK */
761 /* Record (approximately) where the stack begins. */
762 stack_bottom
= &stack_bottom_variable
;
764 #ifdef USG_SHARED_LIBRARIES
766 brk ((void *)bss_end
);
771 #ifndef SYSTEM_MALLOC
772 /* Arrange to get warning messages as memory fills up. */
773 memory_warnings (0, malloc_warning
);
775 /* Call malloc at least once, to run the initial __malloc_hook.
776 Also call realloc and free for consistency. */
777 free (realloc (malloc (4), 4));
779 /* Arrange to disable interrupt input inside malloc etc. */
780 uninterrupt_malloc ();
781 #endif /* not SYSTEM_MALLOC */
784 /* We do all file input/output as binary files. When we need to translate
785 newlines, we do that manually. */
789 if (!isatty (fileno (stdin
)))
790 setmode (fileno (stdin
), O_BINARY
);
791 if (!isatty (fileno (stdout
)))
794 setmode (fileno (stdout
), O_BINARY
);
796 #else /* not __DJGPP__ >= 2 */
797 (stdin
)->_flag
&= ~_IOTEXT
;
798 (stdout
)->_flag
&= ~_IOTEXT
;
799 (stderr
)->_flag
&= ~_IOTEXT
;
800 #endif /* not __DJGPP__ >= 2 */
803 #ifdef SET_EMACS_PRIORITY
805 nice (emacs_priority
);
807 #endif /* SET_EMACS_PRIORITY */
809 /* Skip initial setlocale if LC_ALL is "C", as it's not needed in that case.
810 The build procedure uses this while dumping, to ensure that the
811 dumped Emacs does not have its system locale tables initialized,
812 as that might cause screwups when the dumped Emacs starts up. */
814 char *lc_all
= getenv ("LC_ALL");
815 do_initial_setlocale
= ! lc_all
|| strcmp (lc_all
, "C");
818 /* Set locale now, so that initial error messages are localized properly.
819 fixup_locale must wait until later, since it builds strings. */
820 if (do_initial_setlocale
)
821 setlocale (LC_ALL
, "");
823 #ifdef EXTRA_INITIALIZE
827 inhibit_window_system
= 0;
829 /* Handle the -t switch, which specifies filename to use as terminal */
833 if (argmatch (argv
, argc
, "-t", "--terminal", 4, &term
, &skip_args
))
838 result
= emacs_open (term
, O_RDWR
, 0);
841 char *errstring
= strerror (errno
);
842 fprintf (stderr
, "emacs: %s: %s\n", term
, errstring
);
848 fprintf (stderr
, "emacs: %s: not a tty\n", term
);
851 fprintf (stderr
, "Using %s\n", term
);
852 #ifdef HAVE_WINDOW_SYSTEM
853 inhibit_window_system
= 1; /* -t => -nw */
860 if (argmatch (argv
, argc
, "-nw", "--no-windows", 6, NULL
, &skip_args
))
861 inhibit_window_system
= 1;
863 /* Handle the -batch switch, which means don't do interactive display. */
865 if (argmatch (argv
, argc
, "-batch", "--batch", 5, NULL
, &skip_args
))
868 /* Handle the --help option, which gives a usage message.. */
869 if (argmatch (argv
, argc
, "-help", "--help", 3, NULL
, &skip_args
))
872 Usage: %s [--batch] [-t term] [--terminal term]\n\
873 [-d display] [--display display] [-nw] [--no-windows]\n\
874 [-q] [--no-init-file] [-u user] [--user user] [--debug-init]\n\
875 [--unibyte] [--multibyte] [--version] [--no-site-file]\n\
876 [-f func] [--funcall func] [-l file] [--load file] [--eval expr]\n\
877 [--execute expr] [--visit file] [--file file] [--insert file]\n\
878 [+linenum] file-to-visit [--kill]\n\
879 Report bugs to bug-gnu-emacs@gnu.org. First, please see\n\
880 the Bugs section of the Emacs manual or the file BUGS.\n", argv
[0]);
884 if (! noninteractive
)
889 inherited_pgroup
= EMACS_GETPGRP (0);
890 setpgrp (0, getpid ());
893 #if defined (USG5) && defined (INTERRUPT_INPUT)
901 /* Don't catch SIGHUP if dumping. */
908 sigblock (sigmask (SIGHUP
));
909 /* In --batch mode, don't catch SIGHUP if already ignored.
910 That makes nohup work. */
912 || signal (SIGHUP
, SIG_IGN
) != SIG_IGN
)
913 signal (SIGHUP
, fatal_error_signal
);
914 sigunblock (sigmask (SIGHUP
));
919 ! noninteractive
|| initialized
925 /* Don't catch these signals in batch mode if dumping.
926 On some machines, this sets static data that would make
927 signal fail to work right when the dumped Emacs is run. */
928 signal (SIGQUIT
, fatal_error_signal
);
929 signal (SIGILL
, fatal_error_signal
);
930 signal (SIGTRAP
, fatal_error_signal
);
932 signal (SIGUSR1
, handle_USR1_signal
);
934 signal (SIGUSR2
, handle_USR2_signal
);
938 signal (SIGABRT
, fatal_error_signal
);
941 signal (SIGHWE
, fatal_error_signal
);
944 signal (SIGPRE
, fatal_error_signal
);
947 signal (SIGORE
, fatal_error_signal
);
950 signal (SIGUME
, fatal_error_signal
);
953 signal (SIGDLK
, fatal_error_signal
);
956 signal (SIGCPULIM
, fatal_error_signal
);
959 /* This is missing on some systems - OS/2, for example. */
960 signal (SIGIOT
, fatal_error_signal
);
963 signal (SIGEMT
, fatal_error_signal
);
965 signal (SIGFPE
, fatal_error_signal
);
967 signal (SIGBUS
, fatal_error_signal
);
969 signal (SIGSEGV
, fatal_error_signal
);
971 signal (SIGSYS
, fatal_error_signal
);
973 signal (SIGTERM
, fatal_error_signal
);
975 signal (SIGXCPU
, fatal_error_signal
);
978 signal (SIGXFSZ
, fatal_error_signal
);
982 /* This just means available memory is getting low. */
983 signal (SIGDANGER
, memory_warning_signal
);
987 /* 20 is SIGCHLD, 21 is SIGTTIN, 22 is SIGTTOU. */
988 signal (SIGXCPU
, fatal_error_signal
);
990 signal (SIGIOINT
, fatal_error_signal
);
992 signal (SIGGRANT
, fatal_error_signal
);
993 signal (SIGRETRACT
, fatal_error_signal
);
994 signal (SIGSOUND
, fatal_error_signal
);
995 signal (SIGMSG
, fatal_error_signal
);
999 noninteractive1
= noninteractive
;
1001 /* Perform basic initializations (not merely interning symbols) */
1008 init_charset_once ();
1009 init_coding_once ();
1010 init_syntax_once (); /* Create standard syntax table. */
1011 init_category_once (); /* Create standard category table. */
1012 /* Must be done before init_buffer */
1013 init_casetab_once ();
1014 init_buffer_once (); /* Create buffer table and some buffers */
1015 init_minibuf_once (); /* Create list of minibuffers */
1016 /* Must precede init_window_once */
1018 /* Call syms_of_xfaces before init_window_once because that
1019 function creates Vterminal_frame. Termcap frames now use
1020 faces, and the face implementation uses some symbols as
1026 init_window_once (); /* Init the window system */
1027 init_fileio_once (); /* Must precede any path manipulation. */
1032 if (do_initial_setlocale
)
1035 Vsystem_messages_locale
= Vprevious_system_messages_locale
;
1036 Vsystem_time_locale
= Vprevious_system_time_locale
;
1042 #ifdef CLASH_DETECTION
1045 running_asynch_code
= 0;
1047 /* Handle --unibyte and the EMACS_UNIBYTE envvar,
1048 but not while dumping. */
1051 ! noninteractive
|| initialized
1057 int inhibit_unibyte
= 0;
1059 /* --multibyte overrides EMACS_UNIBYTE. */
1060 if (argmatch (argv
, argc
, "-no-unibyte", "--no-unibyte", 4, NULL
, &skip_args
)
1061 || argmatch (argv
, argc
, "-multibyte", "--multibyte", 4, NULL
, &skip_args
))
1062 inhibit_unibyte
= 1;
1064 /* --unibyte requests that we set up to do everything with single-byte
1065 buffers and strings. We need to handle this before calling
1066 init_lread, init_editfns and other places that generate Lisp strings
1067 from text in the environment. */
1068 /* Actually this shouldn't be needed as of 20.4 in a generally
1069 unibyte environment. As handa says, environment values
1070 aren't now decoded; also existing buffers are now made
1071 unibyte during startup if .emacs sets unibyte. Tested with
1072 8-bit data in environment variables and /etc/passwd, setting
1073 unibyte and Latin-1 in .emacs. -- Dave Love */
1074 if (argmatch (argv
, argc
, "-unibyte", "--unibyte", 4, NULL
, &skip_args
)
1075 || argmatch (argv
, argc
, "-no-multibyte", "--no-multibyte", 4, NULL
, &skip_args
)
1076 || (getenv ("EMACS_UNIBYTE") && !inhibit_unibyte
))
1078 Lisp_Object old_log_max
;
1079 Lisp_Object symbol
, tail
;
1081 symbol
= intern ("default-enable-multibyte-characters");
1082 Fset (symbol
, Qnil
);
1086 /* Erase pre-dump messages in *Messages* now so no abort. */
1087 old_log_max
= Vmessage_log_max
;
1088 XSETFASTINT (Vmessage_log_max
, 0);
1089 message_dolog ("", 0, 1, 0);
1090 Vmessage_log_max
= old_log_max
;
1093 for (tail
= Vbuffer_alist
; CONSP (tail
);
1098 buffer
= Fcdr (XCAR (tail
));
1099 /* Verify that all buffers are empty now, as they
1101 if (BUF_Z (XBUFFER (buffer
)) > BUF_BEG (XBUFFER (buffer
)))
1103 /* It is safe to do this crudely in an empty buffer. */
1104 XBUFFER (buffer
)->enable_multibyte_characters
= Qnil
;
1110 = !argmatch (argv
, argc
, "-nl", "--no-loadup", 6, NULL
, &skip_args
);
1113 #ifdef HAVE_X_WINDOWS
1114 /* Stupid kludge to catch command-line display spec. We can't
1115 handle this argument entirely in window system dependent code
1116 because we don't even know which window system dependent code
1117 to run until we've recognized this argument. */
1119 char *displayname
= 0;
1120 int count_before
= skip_args
;
1122 /* Skip any number of -d options, but only use the last one. */
1125 int count_before_this
= skip_args
;
1127 if (argmatch (argv
, argc
, "-d", "--display", 3, &displayname
, &skip_args
))
1129 else if (argmatch (argv
, argc
, "-display", 0, 3, &displayname
, &skip_args
))
1134 count_before
= count_before_this
;
1137 /* If we have the form --display=NAME,
1138 convert it into -d name.
1139 This requires inserting a new element into argv. */
1140 if (displayname
!= 0 && skip_args
- count_before
== 1)
1142 char **new = (char **) xmalloc (sizeof (char *) * (argc
+ 2));
1145 for (j
= 0; j
< count_before
+ 1; j
++)
1147 new[count_before
+ 1] = "-d";
1148 new[count_before
+ 2] = displayname
;
1149 for (j
= count_before
+ 2; j
<argc
; j
++)
1150 new[j
+ 1] = argv
[j
];
1154 /* Change --display to -d, when its arg is separate. */
1155 else if (displayname
!= 0 && skip_args
> count_before
1156 && argv
[count_before
+ 1][1] == '-')
1157 argv
[count_before
+ 1] = "-d";
1159 /* Don't actually discard this arg. */
1160 skip_args
= count_before
;
1164 /* argmatch must not be used after here,
1165 except when bulding temacs
1166 because the -d argument has not been skipped in skip_args. */
1169 /* Call early 'cause init_environment needs it. */
1171 /* Set defaults for several environment variables. */
1173 init_environment (argc
, argv
, skip_args
);
1179 /* Initialize environment from registry settings. */
1180 init_environment (argv
);
1181 init_ntproc (); /* must precede init_editfns */
1184 /* egetenv is a pretty low-level facility, which may get called in
1185 many circumstances; it seems flimsy to put off initializing it
1186 until calling init_callproc. */
1187 set_process_environment ();
1188 /* AIX crashes are reported in system versions 3.2.3 and 3.2.4
1189 if this is not done. Do it after set_process_environment so that we
1190 don't pollute Vprocess_environment. */
1195 init_buffer (); /* Init default directory of main buffer */
1197 init_callproc_1 (); /* Must precede init_cmdargs and init_sys_modes. */
1198 init_cmdargs (argc
, argv
, skip_args
); /* Must precede init_lread. */
1202 /* Erase any pre-dump messages in the message log, to avoid confusion */
1203 Lisp_Object old_log_max
;
1204 old_log_max
= Vmessage_log_max
;
1205 XSETFASTINT (Vmessage_log_max
, 0);
1206 message_dolog ("", 0, 1, 0);
1207 Vmessage_log_max
= old_log_max
;
1210 init_callproc (); /* Must follow init_cmdargs but not init_sys_modes. */
1213 /* Intern the names of all standard functions and variables;
1214 define standard keys. */
1218 /* The basic levels of Lisp must come first */
1219 /* And data must come first of all
1220 for the sake of symbols like error-message */
1227 syms_of_floatfns ();
1231 syms_of_bytecode ();
1233 syms_of_casefiddle ();
1235 syms_of_callproc ();
1236 syms_of_category ();
1240 #ifndef NO_DIR_LIBRARY
1242 #endif /* not NO_DIR_LIBRARY */
1248 syms_of_coding (); /* This should be after syms_of_fileio. */
1249 #ifdef CLASH_DETECTION
1250 syms_of_filelock ();
1251 #endif /* CLASH_DETECTION */
1254 syms_of_keyboard ();
1259 syms_of_mocklisp ();
1270 syms_of_textprop ();
1276 #endif /* WINDOWSNT */
1279 #ifdef HAVE_X_WINDOWS
1286 #endif /* HAVE_X_WINDOWS */
1295 syms_of_w32faces ();
1296 syms_of_w32select ();
1299 #endif /* HAVE_NTGUI */
1309 keys_of_casefiddle ();
1312 keys_of_keyboard ();
1320 if (!noninteractive
)
1323 init_vms_input ();/* init_display calls get_frame_size, that needs this */
1325 init_display (); /* Determine terminal type. init_sys_modes uses results */
1327 init_keyboard (); /* This too must precede init_sys_modes */
1329 init_vmsproc (); /* And this too. */
1331 init_sys_modes (); /* Init system terminal modes (RAW or CBREAK, etc.) */
1332 #ifdef HAVE_X_WINDOWS
1334 #endif /* HAVE_X_WINDOWS */
1339 #ifdef LISP_FLOAT_TYPE
1353 /* Handle -l loadup, args passed by Makefile. */
1354 if (argmatch (argv
, argc
, "-l", "--load", 3, &file
, &skip_args
))
1355 Vtop_level
= Fcons (intern ("load"),
1356 Fcons (build_string (file
), Qnil
));
1358 /* Unless next switch is -nl, load "loadup.el" first thing. */
1360 Vtop_level
= Fcons (intern ("load"),
1361 Fcons (build_string ("loadup.el"), Qnil
));
1362 #endif /* CANNOT_DUMP */
1369 /* If the execution TZ happens to be the same as the dump TZ,
1370 change it to some other value and then change it back,
1371 to force the underlying implementation to reload the TZ info.
1372 This is needed on implementations that load TZ info from files,
1373 since the TZ file contents may differ between dump and execution. */
1374 char *tz
= getenv ("TZ");
1375 if (tz
&& !strcmp (tz
, dump_tz
))
1385 /* Gerd Moellmann <gerd@acm.org> says this makes profiling work on
1386 FreeBSD. It might work on some other systems too.
1387 Give it a try and tell me if it works on your system. */
1388 #if defined (__FreeBSD__) || defined (__linux)
1392 extern void _mcleanup ();
1394 extern void safe_bcopy ();
1395 extern void dump_opcode_frequencies ();
1398 // atexit (dump_opcode_frequencies);
1399 /* This uses safe_bcopy because that function comes first in the
1400 Emacs executable. It might be better to use something that
1401 gives the start of the text segment, but start_of_text is not
1402 defined on all systems now. */
1403 monstartup (safe_bcopy
, &etext
);
1412 #ifdef LOCALTIME_CACHE
1413 /* Some versions of localtime have a bug. They cache the value of the time
1414 zone rather than looking it up every time. Since localtime() is
1415 called to bolt the undumping time into the undumped emacs, this
1416 results in localtime ignoring the TZ environment variable.
1417 This flushes the new TZ value into localtime. */
1419 #endif /* defined (LOCALTIME_CACHE) */
1421 /* Enter editor command loop. This never returns. */
1426 /* Sort the args so we can find the most important ones
1427 at the beginning of argv. */
1429 /* First, here's a table of all the standard options. */
1431 struct standard_args
1439 struct standard_args standard_args
[] =
1441 { "-version", "--version", 150, 0 },
1443 { "-nl", "--no-shared-memory", 140, 0 },
1446 { "-map", "--map-data", 130, 0 },
1448 { "-t", "--terminal", 120, 1 },
1449 { "-nw", "--no-windows", 110, 0 },
1450 { "-batch", "--batch", 100, 0 },
1451 { "-help", "--help", 90, 0 },
1452 { "-no-unibyte", "--no-unibyte", 83, 0 },
1453 { "-multibyte", "--multibyte", 82, 0 },
1454 { "-unibyte", "--unibyte", 81, 0 },
1455 { "-no-multibyte", "--no-multibyte", 80, 0 },
1457 { "-nl", "--no-loadup", 70, 0 },
1459 /* -d must come last before the options handled in startup.el. */
1460 { "-d", "--display", 60, 1 },
1461 { "-display", 0, 60, 1 },
1462 /* Now for the options handled in startup.el. */
1463 { "-q", "--no-init-file", 50, 0 },
1464 { "-no-init-file", 0, 50, 0 },
1465 { "-no-site-file", "--no-site-file", 40, 0 },
1466 { "-u", "--user", 30, 1 },
1467 { "-user", 0, 30, 1 },
1468 { "-debug-init", "--debug-init", 20, 0 },
1469 { "-i", "--icon-type", 15, 0 },
1470 { "-itype", 0, 15, 0 },
1471 { "-iconic", "--iconic", 15, 0 },
1472 { "-bg", "--background-color", 10, 1 },
1473 { "-background", 0, 10, 1 },
1474 { "-fg", "--foreground-color", 10, 1 },
1475 { "-foreground", 0, 10, 1 },
1476 { "-bd", "--border-color", 10, 1 },
1477 { "-bw", "--border-width", 10, 1 },
1478 { "-ib", "--internal-border", 10, 1 },
1479 { "-ms", "--mouse-color", 10, 1 },
1480 { "-cr", "--cursor-color", 10, 1 },
1481 { "-fn", "--font", 10, 1 },
1482 { "-font", 0, 10, 1 },
1483 { "-g", "--geometry", 10, 1 },
1484 { "-geometry", 0, 10, 1 },
1485 { "-T", "--title", 10, 1 },
1486 { "-title", 0, 10, 1 },
1487 { "-name", "--name", 10, 1 },
1488 { "-xrm", "--xrm", 10, 1 },
1489 { "-r", "--reverse-video", 5, 0 },
1491 { "-reverse", 0, 5, 0 },
1492 { "-hb", "--horizontal-scroll-bars", 5, 0 },
1493 { "-vb", "--vertical-scroll-bars", 5, 0 },
1494 /* These have the same priority as ordinary file name args,
1495 so they are not reordered with respect to those. */
1496 { "-L", "--directory", 0, 1 },
1497 { "-directory", 0, 0, 1 },
1498 { "-l", "--load", 0, 1 },
1499 { "-load", 0, 0, 1 },
1500 { "-f", "--funcall", 0, 1 },
1501 { "-funcall", 0, 0, 1 },
1502 { "-eval", "--eval", 0, 1 },
1503 { "-execute", "--execute", 0, 1 },
1504 { "-find-file", "--find-file", 0, 1 },
1505 { "-visit", "--visit", 0, 1 },
1506 { "-file", "--file", 0, 1 },
1507 { "-insert", "--insert", 0, 1 },
1508 /* This should be processed after ordinary file name args and the like. */
1509 { "-kill", "--kill", -10, 0 },
1512 /* Reorder the elements of ARGV (assumed to have ARGC elements)
1513 so that the highest priority ones come first.
1514 Do not change the order of elements of equal priority.
1515 If an option takes an argument, keep it and its argument together.
1517 If an option that takes no argument appears more
1518 than once, eliminate all but one copy of it. */
1521 sort_args (argc
, argv
)
1525 char **new = (char **) xmalloc (sizeof (char *) * argc
);
1526 /* For each element of argv,
1527 the corresponding element of options is:
1528 0 for an option that takes no arguments,
1529 1 for an option that takes one argument, etc.
1530 -1 for an ordinary non-option argument. */
1531 int *options
= (int *) xmalloc (sizeof (int) * argc
);
1532 int *priority
= (int *) xmalloc (sizeof (int) * argc
);
1534 int incoming_used
= 1;
1538 /* Categorize all the options,
1539 and figure out which argv elts are option arguments. */
1540 for (from
= 1; from
< argc
; from
++)
1544 if (argv
[from
][0] == '-')
1549 /* If we have found "--", don't consider
1550 any more arguments as options. */
1551 if (argv
[from
][1] == '-' && argv
[from
][2] == 0)
1553 /* Leave the "--", and everything following it, at the end. */
1554 for (; from
< argc
; from
++)
1556 priority
[from
] = -100;
1562 /* Look for a match with a known old-fashioned option. */
1563 for (i
= 0; i
< sizeof (standard_args
) / sizeof (standard_args
[0]); i
++)
1564 if (!strcmp (argv
[from
], standard_args
[i
].name
))
1566 options
[from
] = standard_args
[i
].nargs
;
1567 priority
[from
] = standard_args
[i
].priority
;
1568 if (from
+ standard_args
[i
].nargs
>= argc
)
1569 fatal ("Option `%s' requires an argument\n", argv
[from
]);
1570 from
+= standard_args
[i
].nargs
;
1574 /* Look for a match with a known long option.
1575 MATCH is -1 if no match so far, -2 if two or more matches so far,
1576 >= 0 (the table index of the match) if just one match so far. */
1577 if (argv
[from
][1] == '-')
1580 thislen
= strlen (argv
[from
]);
1581 equals
= index (argv
[from
], '=');
1583 thislen
= equals
- argv
[from
];
1586 i
< sizeof (standard_args
) / sizeof (standard_args
[0]); i
++)
1587 if (standard_args
[i
].longname
1588 && !strncmp (argv
[from
], standard_args
[i
].longname
,
1597 /* If we found exactly one match, use that. */
1600 options
[from
] = standard_args
[match
].nargs
;
1601 priority
[from
] = standard_args
[match
].priority
;
1602 /* If --OPTION=VALUE syntax is used,
1603 this option uses just one argv element. */
1606 if (from
+ options
[from
] >= argc
)
1607 fatal ("Option `%s' requires an argument\n", argv
[from
]);
1608 from
+= options
[from
];
1615 /* Copy the arguments, in order of decreasing priority, to NEW. */
1617 while (incoming_used
< argc
)
1620 int best_priority
= -9999;
1622 /* Find the highest priority remaining option.
1623 If several have equal priority, take the first of them. */
1624 for (from
= 1; from
< argc
; from
++)
1626 if (argv
[from
] != 0 && priority
[from
] > best_priority
)
1628 best_priority
= priority
[from
];
1631 /* Skip option arguments--they are tied to the options. */
1632 if (options
[from
] > 0)
1633 from
+= options
[from
];
1639 /* Copy the highest priority remaining option, with its args, to NEW.
1640 Unless it is a duplicate of the previous one. */
1641 if (! (options
[best
] == 0
1642 && ! strcmp (new[to
- 1], argv
[best
])))
1644 new[to
++] = argv
[best
];
1645 for (i
= 0; i
< options
[best
]; i
++)
1646 new[to
++] = argv
[best
+ i
+ 1];
1649 incoming_used
+= 1 + (options
[best
] > 0 ? options
[best
] : 0);
1651 /* Clear out this option in ARGV. */
1653 for (i
= 0; i
< options
[best
]; i
++)
1654 argv
[best
+ i
+ 1] = 0;
1657 /* If duplicate options were deleted, fill up extra space with null ptrs. */
1661 bcopy (new, argv
, sizeof (char *) * argc
);
1668 DEFUN ("kill-emacs", Fkill_emacs
, Skill_emacs
, 0, 1, "P",
1669 "Exit the Emacs job and kill it.\n\
1670 If ARG is an integer, return ARG as the exit program code.\n\
1671 If ARG is a string, stuff it as keyboard input.\n\n\
1672 The value of `kill-emacs-hook', if not void,\n\
1673 is a list of functions (of no args),\n\
1674 all of which are called before Emacs is actually killed.")
1678 struct gcpro gcpro1
;
1685 if (!NILP (Vrun_hooks
) && !noninteractive
)
1686 call1 (Vrun_hooks
, intern ("kill-emacs-hook"));
1690 /* Is it really necessary to do this deassign
1691 when we are going to exit anyway? */
1696 shut_down_emacs (0, 0, STRINGP (arg
) ? arg
: Qnil
);
1698 /* If we have an auto-save list file,
1699 kill it because we are exiting Emacs deliberately (not crashing).
1700 Do it after shut_down_emacs, which does an auto-save. */
1701 if (STRINGP (Vauto_save_list_file_name
))
1702 unlink (XSTRING (Vauto_save_list_file_name
)->data
);
1704 exit (INTEGERP (arg
) ? XINT (arg
)
1715 /* Perform an orderly shutdown of Emacs. Autosave any modified
1716 buffers, kill any child processes, clean up the terminal modes (if
1717 we're in the foreground), and other stuff like that. Don't perform
1718 any redisplay; this may be called when Emacs is shutting down in
1719 the background, or after its X connection has died.
1721 If SIG is a signal number, print a message for it.
1723 This is called by fatal signal handlers, X protocol error handlers,
1727 shut_down_emacs (sig
, no_x
, stuff
)
1731 /* Prevent running of hooks from now on. */
1734 /* If we are controlling the terminal, reset terminal modes */
1735 #ifdef EMACS_HAVE_TTY_PGRP
1737 int pgrp
= EMACS_GETPGRP (0);
1740 if (EMACS_GET_TTY_PGRP (0, &tpgrp
) != -1
1745 if (sig
&& sig
!= SIGTERM
)
1746 fprintf (stderr
, "Fatal error (%d).", sig
);
1754 stuff_buffered_input (stuff
);
1756 kill_buffer_processes (Qnil
);
1757 Fdo_auto_save (Qt
, Qnil
);
1759 #ifdef CLASH_DETECTION
1760 unlock_all_files ();
1764 kill_vms_processes ();
1767 #if 0 /* This triggers a bug in XCloseDisplay and is not needed. */
1768 #ifdef HAVE_X_WINDOWS
1769 /* It's not safe to call intern here. Maybe we are crashing. */
1770 if (!noninteractive
&& SYMBOLP (Vwindow_system
)
1771 && XSYMBOL (Vwindow_system
)->name
->size
== 1
1772 && XSYMBOL (Vwindow_system
)->name
->data
[0] == 'x'
1774 Fx_close_current_connection ();
1775 #endif /* HAVE_X_WINDOWS */
1779 /* There is a tendency for a SIGIO signal to arrive within exit,
1780 and cause a SIGHUP because the input descriptor is already closed. */
1782 signal (SIGIO
, SIG_IGN
);
1789 check_glyph_memory ();
1790 check_message_stack ();
1803 DEFUN ("dump-emacs-data", Fdump_emacs_data
, Sdump_emacs_data
, 1, 1, 0,
1804 "Dump current state of Emacs into data file FILENAME.\n\
1805 This function exists on systems that use HAVE_SHM.")
1807 Lisp_Object filename
;
1809 extern char my_edata
[];
1812 CHECK_STRING (filename
, 0);
1813 filename
= Fexpand_file_name (filename
, Qnil
);
1816 Vpurify_flag
= Qnil
;
1819 /* Tell malloc where start of impure now is */
1820 /* Also arrange for warnings when nearly out of space. */
1821 #ifndef SYSTEM_MALLOC
1822 memory_warnings (my_edata
, malloc_warning
);
1824 map_out_data (XSTRING (filename
)->data
);
1831 #else /* not HAVE_SHM */
1833 DEFUN ("dump-emacs", Fdump_emacs
, Sdump_emacs
, 2, 2, 0,
1834 "Dump current state of Emacs into executable file FILENAME.\n\
1835 Take symbols from SYMFILE (presumably the file you executed to run Emacs).\n\
1836 This is used in the file `loadup.el' when building Emacs.\n\
1838 You must run Emacs in batch mode in order to dump it.")
1840 Lisp_Object filename
, symfile
;
1842 extern char my_edata
[];
1845 int count
= specpdl_ptr
- specpdl
;
1847 if (! noninteractive
)
1848 error ("Dumping Emacs works only in batch mode");
1850 /* Bind `command-line-processed' to nil before dumping,
1851 so that the dumped Emacs will process its command line
1852 and set up to work with X windows if appropriate. */
1853 symbol
= intern ("command-line-process");
1854 specbind (symbol
, Qnil
);
1856 CHECK_STRING (filename
, 0);
1857 filename
= Fexpand_file_name (filename
, Qnil
);
1858 if (!NILP (symfile
))
1860 CHECK_STRING (symfile
, 0);
1861 if (XSTRING (symfile
)->size
)
1862 symfile
= Fexpand_file_name (symfile
, Qnil
);
1866 Vpurify_flag
= Qnil
;
1869 set_time_zone_rule (dump_tz
);
1870 #ifndef LOCALTIME_CACHE
1871 /* Force a tz reload, since set_time_zone_rule doesn't. */
1878 mapout_data (XSTRING (filename
)->data
);
1880 /* Tell malloc where start of impure now is */
1881 /* Also arrange for warnings when nearly out of space. */
1882 #ifndef SYSTEM_MALLOC
1884 /* On Windows, this was done before dumping, and that once suffices.
1885 Meanwhile, my_edata is not valid on Windows. */
1886 memory_warnings (my_edata
, malloc_warning
);
1887 #endif /* not WINDOWSNT */
1889 #ifdef DOUG_LEA_MALLOC
1890 malloc_state_ptr
= malloc_get_state ();
1892 unexec (XSTRING (filename
)->data
,
1893 !NILP (symfile
) ? XSTRING (symfile
)->data
: 0, my_edata
, 0, 0);
1894 #ifdef DOUG_LEA_MALLOC
1895 free (malloc_state_ptr
);
1897 #endif /* not VMS */
1901 return unbind_to (count
, Qnil
);
1904 #endif /* not HAVE_SHM */
1906 #endif /* not CANNOT_DUMP */
1909 /* 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 l
= setlocale (LC_MESSAGES
, (char *) 0);
1921 Vprevious_system_messages_locale
= l
? build_string (l
) : Qnil
;
1923 l
= setlocale (LC_TIME
, (char *) 0);
1924 Vprevious_system_time_locale
= l
? build_string (l
) : Qnil
;
1928 synchronize_locale (category
, plocale
, desired_locale
)
1930 Lisp_Object
*plocale
;
1931 Lisp_Object desired_locale
;
1933 if (STRINGP (desired_locale
)
1934 && (NILP (*plocale
) || NILP (Fstring_equal (*plocale
, desired_locale
)))
1935 && setlocale (category
, XSTRING (desired_locale
)->data
))
1936 *plocale
= desired_locale
;
1939 /* Set system time locale to match Vsystem_time_locale, if possible. */
1941 synchronize_system_time_locale ()
1943 synchronize_locale (LC_TIME
, &Vprevious_system_time_locale
,
1944 Vsystem_time_locale
);
1947 /* Set system messages locale to match Vsystem_messages_locale, if
1950 synchronize_system_messages_locale ()
1953 synchronize_locale (LC_MESSAGES
, &Vprevious_system_messages_locale
,
1954 Vsystem_messages_locale
);
1957 #endif /* HAVE_SETLOCALE */
1964 decode_env_path (evarname
, defalt
)
1965 char *evarname
, *defalt
;
1967 register char *path
, *p
;
1968 Lisp_Object lpath
, element
, tem
;
1970 /* It's okay to use getenv here, because this function is only used
1971 to initialize variables when Emacs starts up, and isn't called
1974 path
= (char *) getenv (evarname
);
1980 /* Ensure values from the environment use the proper directory separator. */
1983 p
= alloca (strlen (path
) + 1);
1987 if ('/' == DIRECTORY_SEP
)
1988 dostounix_filename (path
);
1990 unixtodos_filename (path
);
1996 p
= index (path
, SEPCHAR
);
1997 if (!p
) p
= path
+ strlen (path
);
1998 element
= (p
- path
? make_string (path
, p
- path
)
1999 : build_string ("."));
2001 /* Add /: to the front of the name
2002 if it would otherwise be treated as magic. */
2003 tem
= Ffind_file_name_handler (element
, Qt
);
2005 element
= concat2 (build_string ("/:"), element
);
2007 lpath
= Fcons (element
, lpath
);
2013 return Fnreverse (lpath
);
2019 Qfile_name_handler_alist
= intern ("file-name-handler-alist");
2020 staticpro (&Qfile_name_handler_alist
);
2024 defsubr (&Sdump_emacs_data
);
2026 defsubr (&Sdump_emacs
);
2030 defsubr (&Skill_emacs
);
2032 defsubr (&Sinvocation_name
);
2033 defsubr (&Sinvocation_directory
);
2035 DEFVAR_LISP ("command-line-args", &Vcommand_line_args
,
2036 "Args passed by shell to Emacs, as a list of strings.");
2038 DEFVAR_LISP ("system-type", &Vsystem_type
,
2039 "Value is symbol indicating type of operating system you are using.");
2040 Vsystem_type
= intern (SYSTEM_TYPE
);
2042 DEFVAR_LISP ("system-configuration", &Vsystem_configuration
,
2043 "Value is string indicating configuration Emacs was built for.");
2044 Vsystem_configuration
= build_string (EMACS_CONFIGURATION
);
2046 DEFVAR_LISP ("system-configuration-options", &Vsystem_configuration_options
,
2047 "String containing the configuration options Emacs was built with.");
2048 Vsystem_configuration_options
= build_string (EMACS_CONFIG_OPTIONS
);
2050 DEFVAR_BOOL ("noninteractive", &noninteractive1
,
2051 "Non-nil means Emacs is running without interactive terminal.");
2053 DEFVAR_LISP ("kill-emacs-hook", &Vkill_emacs_hook
,
2054 "Hook to be run whenever kill-emacs is called.\n\
2055 Since kill-emacs may be invoked when the terminal is disconnected (or\n\
2056 in other similar situations), functions placed on this hook should not\n\
2057 expect to be able to interact with the user. To ask for confirmation,\n\
2058 see `kill-emacs-query-functions' instead.");
2059 Vkill_emacs_hook
= Qnil
;
2062 DEFVAR_LISP ("signal-USR1-hook", &Vsignal_USR1_hook
,
2063 "Hook to be run whenever emacs receives a USR1 signal");
2064 Vsignal_USR1_hook
= Qnil
;
2066 DEFVAR_LISP ("signal-USR2-hook", &Vsignal_USR2_hook
,
2067 "Hook to be run whenever emacs receives a USR2 signal");
2068 Vsignal_USR2_hook
= Qnil
;
2073 DEFVAR_INT ("emacs-priority", &emacs_priority
,
2074 "Priority for Emacs to run at.\n\
2075 This value is effective only if set before Emacs is dumped,\n\
2076 and only if the Emacs executable is installed with setuid to permit\n\
2077 it to change priority. (Emacs sets its uid back to the real uid.)\n\
2078 Currently, you need to define SET_EMACS_PRIORITY in `config.h'\n\
2079 before you compile Emacs, to enable the code for this feature.");
2082 DEFVAR_LISP ("path-separator", &Vpath_separator
,
2083 "The directory separator in search paths, as a string.");
2086 Vpath_separator
= make_string (&c
, 1);
2089 DEFVAR_LISP ("invocation-name", &Vinvocation_name
,
2090 "The program name that was used to run Emacs.\n\
2091 Any directory names are omitted.");
2093 DEFVAR_LISP ("invocation-directory", &Vinvocation_directory
,
2094 "The directory in which the Emacs executable was found, to run it.\n\
2095 The value is nil if that directory's name is not known.");
2097 DEFVAR_LISP ("installation-directory", &Vinstallation_directory
,
2098 "A directory within which to look for the `lib-src' and `etc' directories.\n\
2099 This is non-nil when we can't find those directories in their standard\n\
2100 installed locations, but we can find them\n\
2101 near where the Emacs executable was found.");
2102 Vinstallation_directory
= Qnil
;
2104 DEFVAR_LISP ("system-messages-locale", &Vsystem_messages_locale
,
2105 "System locale for messages.");
2106 Vsystem_messages_locale
= Qnil
;
2108 DEFVAR_LISP ("previous-system-messages-locale",
2109 &Vprevious_system_messages_locale
,
2110 "Most recently used system locale for messages.");
2111 Vprevious_system_messages_locale
= Qnil
;
2113 DEFVAR_LISP ("system-time-locale", &Vsystem_time_locale
,
2114 "System locale for time.");
2115 Vsystem_time_locale
= Qnil
;
2117 DEFVAR_LISP ("previous-system-time-locale", &Vprevious_system_time_locale
,
2118 "Most recently used system locale for time.");
2119 Vprevious_system_time_locale
= Qnil
;