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