Sync to HEAD
[bpt/emacs.git] / src / emacs.c
CommitLineData
f927c5ae 1/* Fully extensible Emacs, running on Unix, intended for GNU.
6b61353c 2 Copyright (C) 1985,86,87,93,94,95,97,98,1999,2001,02,03,2004
6c145d35 3 Free Software Foundation, Inc.
f927c5ae
JB
4
5This file is part of GNU Emacs.
6
7GNU Emacs is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
40be253a 9the Free Software Foundation; either version 2, or (at your option)
f927c5ae
JB
10any later version.
11
12GNU Emacs is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GNU Emacs; see the file COPYING. If not, write to
5a7670bf
RS
19the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20Boston, MA 02111-1307, USA. */
f927c5ae
JB
21
22
68c45bf0 23#include <config.h>
f927c5ae
JB
24#include <signal.h>
25#include <errno.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
cda4a5fd
GM
35#ifdef HAVE_UNISTD_H
36#include <unistd.h>
37#endif
38
488b7cb3 39#ifdef BSD_SYSTEM
f927c5ae
JB
40#include <sys/ioctl.h>
41#endif
42
edd3ff1d
JR
43#ifdef WINDOWSNT
44#include <fcntl.h>
45#endif
46
f927c5ae
JB
47#include "lisp.h"
48#include "commands.h"
bef79ee4 49#include "intervals.h"
a08a816a 50#include "buffer.h"
3f6abfd7 51#include "window.h"
f927c5ae 52
edc8ae07 53#include "systty.h"
6c3a4e9d 54#include "blockinput.h"
8090eb09 55#include "syssignal.h"
6c362a8b 56#include "process.h"
5bda49c6 57#include "termhooks.h"
dfcf069d 58#include "keyboard.h"
e35f6ff7 59#include "keymap.h"
a41f8bed 60
68c45bf0
PE
61#ifdef HAVE_SETLOCALE
62#include <locale.h>
63#endif
64
53c58b5d
RS
65#ifdef HAVE_SETRLIMIT
66#include <sys/time.h>
67#include <sys/resource.h>
68#endif
69
f927c5ae
JB
70#ifndef O_RDWR
71#define O_RDWR 2
72#endif
73
f95c3f91 74#ifdef HAVE_SETPGID
2b7e8799 75#if !defined (USG) || defined (BSD_PGRPS)
90553aa3 76#undef setpgrp
f95c3f91
GM
77#define setpgrp setpgid
78#endif
2b7e8799 79#endif
f95c3f91 80
90553aa3
DL
81extern void malloc_warning P_ ((char *));
82extern void set_time_zone_rule P_ ((char *));
8892f40b
GM
83#ifdef HAVE_INDEX
84extern char *index P_ ((const char *, int));
85#endif
43165242 86
30aa3f19
GM
87/* Make these values available in GDB, which doesn't see macros. */
88
6b61353c
KH
89#ifdef USE_LSB_TAG
90int gdb_use_lsb = 1;
91#else
92int gdb_use_lsb = 0;
93#endif
94#ifdef NO_UNION_TYPE
95int gdb_use_union = 0;
96#else
97int gdb_use_union = 1;
98#endif
30aa3f19
GM
99EMACS_INT gdb_valbits = VALBITS;
100EMACS_INT gdb_gctypebits = GCTYPEBITS;
30aa3f19
GM
101#ifdef DATA_SEG_BITS
102EMACS_INT gdb_data_seg_bits = DATA_SEG_BITS;
103#else
df50cf6c 104EMACS_INT gdb_data_seg_bits = 0;
30aa3f19 105#endif
00da0e4a 106EMACS_INT PVEC_FLAG = PSEUDOVECTOR_FLAG;
30aa3f19 107
7db35a48 108/* Command line args from shell, as list of strings. */
f927c5ae
JB
109Lisp_Object Vcommand_line_args;
110
59653951
JB
111/* The name under which Emacs was invoked, with any leading directory
112 names discarded. */
113Lisp_Object Vinvocation_name;
114
ace40a69
RS
115/* The directory name from which Emacs was invoked. */
116Lisp_Object Vinvocation_directory;
117
07f4d123
RS
118/* The directory name in which to find subdirs such as lisp and etc.
119 nil means get them only from PATH_LOADSEARCH. */
120Lisp_Object Vinstallation_directory;
121
e5d77022
JB
122/* Hook run by `kill-emacs' before it does really anything. */
123Lisp_Object Vkill_emacs_hook;
124
f9a6326d
SM
125/* An empty lisp string. To avoid having to build any other. */
126Lisp_Object empty_string;
127
7317d9e8 128#ifdef SIGUSR1
7db35a48 129/* Hooks for signal USR1 and USR2 handling. */
7317d9e8
RS
130Lisp_Object Vsignal_USR1_hook;
131#ifdef SIGUSR2
132Lisp_Object Vsignal_USR2_hook;
7db35a48 133#endif
7317d9e8
RS
134#endif
135
074a066b
GV
136/* Search path separator. */
137Lisp_Object Vpath_separator;
138
f927c5ae
JB
139/* Set nonzero after Emacs has started up the first time.
140 Prevents reinitialization of the Lisp world and keymaps
141 on subsequent starts. */
142int initialized;
143
15aaf1b5
RS
144#ifdef DOUG_LEA_MALLOC
145/* Preserves a pointer to the memory allocated that copies that
146 static data inside glibc's malloc. */
147void *malloc_state_ptr;
148/* From glibc, a routine that returns a copy of the malloc internal state. */
149extern void *malloc_get_state ();
150/* From glibc, a routine that overwrites the malloc internal state. */
151extern void malloc_set_state ();
7c9cd446
AS
152/* Non-zero if the MALLOC_CHECK_ enviroment variable was set while
153 dumping. Used to work around a bug in glibc's malloc. */
154int malloc_using_checking;
15aaf1b5
RS
155#endif
156
271c7b7c 157/* Variable whose value is symbol giving operating system type. */
f927c5ae 158Lisp_Object Vsystem_type;
271c7b7c
RS
159
160/* Variable whose value is string giving configuration built for. */
161Lisp_Object Vsystem_configuration;
f0fc0b1a
KH
162
163/* Variable whose value is string giving configuration options,
164 for use when reporting bugs. */
165Lisp_Object Vsystem_configuration_options;
166
213d0b1f
RS
167Lisp_Object Qfile_name_handler_alist;
168
68c45bf0 169/* Current and previous system locales for messages and time. */
ca9c0567
PE
170Lisp_Object Vsystem_messages_locale;
171Lisp_Object Vprevious_system_messages_locale;
172Lisp_Object Vsystem_time_locale;
173Lisp_Object Vprevious_system_time_locale;
68c45bf0 174
7d0393cf 175/* If non-zero, emacs should not attempt to use a window-specific code,
7db35a48 176 but instead should use the virtual terminal under which it was started. */
f927c5ae
JB
177int inhibit_window_system;
178
5aa7f46a
JB
179/* If nonzero, set Emacs to run at this priority. This is also used
180 in child_setup and sys_suspend to make sure subshells run at normal
7db35a48 181 priority; those functions have their own extern declaration. */
31ade731 182EMACS_INT emacs_priority;
3005da00 183
7db35a48
PJ
184/* If non-zero, a filter or a sentinel is running. Tested to save the match
185 data on the first attempt to change it inside asynchronous code. */
7074fde6
FP
186int running_asynch_code;
187
647cec74 188#ifdef BSD_PGRPS
9ae8f997
JB
189/* See sysdep.c. */
190extern int inherited_pgroup;
191#endif
192
f927c5ae 193#ifdef HAVE_X_WINDOWS
7db35a48 194/* If non-zero, -d was specified, meaning we're using some window system. */
f927c5ae
JB
195int display_arg;
196#endif
197
198/* An address near the bottom of the stack.
199 Tells GC how to save a copy of the stack. */
200char *stack_bottom;
201
8ba50e1a 202#ifdef HAVE_WINDOW_SYSTEM
f927c5ae 203extern Lisp_Object Vwindow_system;
8ba50e1a 204#endif /* HAVE_WINDOW_SYSTEM */
f927c5ae 205
1090a161
RS
206extern Lisp_Object Vauto_save_list_file_name;
207
f927c5ae
JB
208#ifdef USG_SHARED_LIBRARIES
209/* If nonzero, this is the place to put the end of the writable segment
210 at startup. */
211
212unsigned int bss_end = 0;
213#endif
214
215/* Nonzero means running Emacs without interactive terminal. */
216
217int noninteractive;
218
219/* Value of Lisp variable `noninteractive'.
220 Normally same as C variable `noninteractive'
221 but nothing terrible happens if user sets this one. */
222
223int noninteractive1;
e29f86e4
RS
224
225/* Save argv and argc. */
226char **initial_argv;
227int initial_argc;
081bef73
RS
228
229static void sort_args ();
dfcf069d 230void syms_of_emacs ();
bd4590ba 231
6b61353c
KH
232/* MSVC needs each string be shorter than 2048 bytes, so the usage
233 strings below are split to not overflow this limit. */
73ebcd25 234#define USAGE1 "\
bd4590ba
GM
235Usage: %s [OPTION-OR-FILENAME]...\n\
236\n\
237Run Emacs, the extensible, customizable, self-documenting real-time\n\
238display editor. The recommended way to start Emacs for normal editing\n\
239is with no options at all.\n\
240\n\
241Run M-x info RET m emacs RET m command arguments RET inside Emacs to\n\
242read the main documentation for these command-line arguments.\n\
243\n\
244Initialization options:\n\
245\n\
6b61353c
KH
246--batch do not do interactive display; implies -q\n\
247--debug-init enable Emacs Lisp debugger for init file\n\
248--display, -d DISPLAY use X server DISPLAY\n\
249--multibyte, --no-unibyte inhibit the effect of EMACS_UNIBYTE\n\
250--no-desktop do not load a saved desktop\n\
251--no-init-file, -q load neither ~/.emacs nor default.el\n\
252--no-shared-memory, -nl do not use shared memory\n\
253--no-site-file do not load site-start.el\n\
254--no-splash do not display a splash screen on startup\n\
255--no-window-system, -nw don't communicate with X, ignoring $DISPLAY\n\
256--script FILE run FILE as an Emacs Lisp script\n\
257--terminal, -t DEVICE use DEVICE for terminal I/O\n\
bd4590ba 258--unibyte, --no-multibyte run Emacs in unibyte mode\n\
6b61353c
KH
259--user, -u USER load ~USER/.emacs instead of your own\n\
260\n%s"
261
262#define USAGE2 "\
bd4590ba
GM
263Action options:\n\
264\n\
6b61353c
KH
265FILE visit FILE using find-file\n\
266+LINE FILE visit FILE using find-file, then go to line LINE\n\
267+LINE:COLUMN FILE visit FILE using find-file, then go to line LINE,\n\
268 column COLUMN\n\
269--directory, -L DIR add DIR to variable load-path\n\
270--eval EXPR evaluate Emacs Lisp expression EXPR\n\
271--execute EXPR evaluate Emacs Lisp expression EXPR\n\
272--file FILE visit FILE using find-file\n\
273--find-file FILE visit FILE using find-file\n\
274--funcall, -f FUNC call Emacs Lisp function FUNC with no arguments\n\
275--insert FILE insert contents of FILE into current buffer\n\
276--kill exit without asking for confirmation\n\
277--load, -l FILE load Emacs Lisp FILE using the load function\n\
278--visit FILE visit FILE using find-file\n\
73ebcd25
AI
279\n"
280
6b61353c 281#define USAGE3 "\
5b2ca26b 282Display options:\n\
bd4590ba 283\n\
6b61353c
KH
284--background-color, -bg COLOR window background color\n\
285--border-color, -bd COLOR main border color\n\
286--border-width, -bw WIDTH width of main border\n\
287--color MODE color mode for character terminals;\n\
288 MODE defaults to `auto', and can also\n\
289 be `never', `auto', `always',\n\
290 or a mode name like `ansi8'\n\
291--cursor-color, -cr COLOR color of the Emacs cursor indicating point\n\
292--font, -fn FONT default font; must be fixed-width\n\
293--foreground-color, -fg COLOR window foreground color\n\
294--fullheight, -fh make the first frame high as the screen\n\
295--fullscreen, -fs make first frame fullscreen\n\
296--fullwidth, -fw make the first frame wide as the screen\n\
297--geometry, -g GEOMETRY window geometry\n\
298--horizontal-scroll-bars, -hb enable horizontal scroll bars\n\
299--icon-type, -i use picture of gnu for Emacs icon\n\
300--iconic start Emacs in iconified state\n\
301--internal-border, -ib WIDTH width between text and main border\n\
302--line-spacing, -lsp PIXELS additional space to put between lines\n\
303--mouse-color, -ms COLOR mouse cursor color in Emacs window\n\
304--name NAME title for initial Emacs frame\n\
305--reverse-video, -r, -rv switch foreground and background\n\
306--title, -T TITLE title for initial Emacs frame\n\
307--vertical-scroll-bars, -vb enable vertical scroll bars\n\
308--xrm XRESOURCES set additional X resources\n\
309--help display this help and exit\n\
310--version output version information and exit\n\
bd4590ba
GM
311\n\
312You can generally also specify long option names with a single -; for\n\
313example, -batch as well as --batch. You can use any unambiguous\n\
314abbreviation for a --option.\n\
315\n\
316Various environment variables and window system resources also affect\n\
317Emacs' operation. See the main documentation.\n\
d883731c
PJ
318\n"
319
6b61353c 320#define USAGE4 "\
d883731c 321Report bugs to %s. First, please see the Bugs\n\
bd4590ba
GM
322section of the Emacs manual or the file BUGS.\n"
323
f927c5ae 324\f
7db35a48 325/* Signal code for the fatal signal that was received. */
f927c5ae
JB
326int fatal_error_code;
327
7db35a48 328/* Nonzero if handling a fatal error already. */
f927c5ae
JB
329int fatal_error_in_progress;
330
7db35a48 331/* If non-null, call this function from fatal_error_signal before
4fab758d
GM
332 committing suicide. */
333
334void (*fatal_error_signal_hook) P_ ((void));
335
336
7317d9e8 337#ifdef SIGUSR1
7317d9e8
RS
338SIGTYPE
339handle_USR1_signal (sig)
340 int sig;
341{
5bda49c6
RS
342 struct input_event buf;
343
75816372 344 bzero (&buf, sizeof buf);
5b50dae1 345 buf.kind = USER_SIGNAL_EVENT;
74c2d1c6 346 buf.frame_or_window = selected_frame;
5bda49c6
RS
347
348 kbd_buffer_store_event (&buf);
7317d9e8 349}
5bda49c6 350#endif /* SIGUSR1 */
fcf01ad3 351
7317d9e8 352#ifdef SIGUSR2
7317d9e8
RS
353SIGTYPE
354handle_USR2_signal (sig)
355 int sig;
356{
5bda49c6
RS
357 struct input_event buf;
358
75816372 359 bzero (&buf, sizeof buf);
5b50dae1 360 buf.kind = USER_SIGNAL_EVENT;
e2fa15ff 361 buf.code = 1;
74c2d1c6 362 buf.frame_or_window = selected_frame;
5bda49c6
RS
363
364 kbd_buffer_store_event (&buf);
7317d9e8 365}
5bda49c6 366#endif /* SIGUSR2 */
7317d9e8 367
7db35a48 368/* Handle bus errors, invalid instruction, etc. */
2447c626 369SIGTYPE
f927c5ae
JB
370fatal_error_signal (sig)
371 int sig;
372{
f927c5ae
JB
373 fatal_error_code = sig;
374 signal (sig, SIG_DFL);
375
061b7f94
RS
376 TOTALLY_UNBLOCK_INPUT;
377
f927c5ae 378 /* If fatal error occurs in code below, avoid infinite recursion. */
8090eb09
JB
379 if (! fatal_error_in_progress)
380 {
381 fatal_error_in_progress = 1;
f927c5ae 382
f7ab4e3d 383 shut_down_emacs (sig, 0, Qnil);
8090eb09 384 }
f927c5ae
JB
385
386#ifdef VMS
f927c5ae
JB
387 LIB$STOP (SS$_ABORT);
388#else
8090eb09
JB
389 /* Signal the same code; this time it will really be fatal.
390 Remember that since we're in a signal handler, the signal we're
391 going to send is probably blocked, so we have to unblock it if we
392 want to really receive it. */
29b89fe0 393#ifndef MSDOS
a90538cb 394 sigunblock (sigmask (fatal_error_code));
29b89fe0 395#endif
4fab758d
GM
396
397 if (fatal_error_signal_hook)
398 fatal_error_signal_hook ();
7db35a48 399
f927c5ae
JB
400 kill (getpid (), fatal_error_code);
401#endif /* not VMS */
402}
271c7b7c
RS
403
404#ifdef SIGDANGER
405
16c323ee 406/* Handler for SIGDANGER. */
271c7b7c
RS
407SIGTYPE
408memory_warning_signal (sig)
409 int sig;
410{
411 signal (sig, memory_warning_signal);
412
413 malloc_warning ("Operating system warns that virtual memory is running low.\n");
55796183
RS
414
415 /* It might be unsafe to call do_auto_save now. */
416 force_auto_save_soon ();
271c7b7c
RS
417}
418#endif
fcf01ad3
RS
419
420/* We define abort, rather than using it from the library,
c9fe9cce 421 so that GDB can return from a breakpoint here.
7db35a48 422 MSDOS has its own definition in msdos.c. */
fcf01ad3 423
37e2fdd2 424#if ! defined (DOS_NT) && ! defined (NO_ABORT)
ca9c0567
PE
425
426#ifndef ABORT_RETURN_TYPE
427#define ABORT_RETURN_TYPE void
428#endif
429
430ABORT_RETURN_TYPE
fcf01ad3
RS
431abort ()
432{
433 kill (getpid (), SIGABRT);
37e2fdd2
RS
434 /* This shouldn't be executed, but it prevents a warning. */
435 exit (1);
fcf01ad3 436}
c9fe9cce 437#endif
fcf01ad3 438
f927c5ae 439\f
7db35a48 440/* Code for dealing with Lisp access to the Unix command line. */
f927c5ae 441
dfcf069d 442static void
f927c5ae
JB
443init_cmdargs (argc, argv, skip_args)
444 int argc;
445 char **argv;
446 int skip_args;
447{
448 register int i;
213d0b1f 449 Lisp_Object name, dir, tem;
aed13378 450 int count = SPECPDL_INDEX ();
213d0b1f 451 Lisp_Object raw_name;
f927c5ae 452
e29f86e4
RS
453 initial_argv = argv;
454 initial_argc = argc;
455
213d0b1f
RS
456 raw_name = build_string (argv[0]);
457
458 /* Add /: to the front of the name
459 if it would otherwise be treated as magic. */
460 tem = Ffind_file_name_handler (raw_name, Qt);
461 if (! NILP (tem))
462 raw_name = concat2 (build_string ("/:"), raw_name);
463
464 Vinvocation_name = Ffile_name_nondirectory (raw_name);
465 Vinvocation_directory = Ffile_name_directory (raw_name);
466
ace40a69
RS
467 /* If we got no directory in argv[0], search PATH to find where
468 Emacs actually came from. */
469 if (NILP (Vinvocation_directory))
470 {
471 Lisp_Object found;
472 int yes = openp (Vexec_path, Vinvocation_name,
10c0915e 473 Vexec_suffixes, &found, make_number (X_OK));
e443f843 474 if (yes == 1)
213d0b1f
RS
475 {
476 /* Add /: to the front of the name
477 if it would otherwise be treated as magic. */
478 tem = Ffind_file_name_handler (found, Qt);
479 if (! NILP (tem))
480 found = concat2 (build_string ("/:"), found);
481 Vinvocation_directory = Ffile_name_directory (found);
482 }
ace40a69 483 }
59653951 484
4133b300
RS
485 if (!NILP (Vinvocation_directory)
486 && NILP (Ffile_name_absolute_p (Vinvocation_directory)))
213d0b1f
RS
487 /* Emacs was started with relative path, like ./emacs.
488 Make it absolute. */
4133b300
RS
489 Vinvocation_directory = Fexpand_file_name (Vinvocation_directory, Qnil);
490
07f4d123
RS
491 Vinstallation_directory = Qnil;
492
493 if (!NILP (Vinvocation_directory))
494 {
495 dir = Vinvocation_directory;
496 name = Fexpand_file_name (Vinvocation_name, dir);
497 while (1)
498 {
f5ab9736 499 Lisp_Object tem, lib_src_exists;
07f4d123
RS
500 Lisp_Object etc_exists, info_exists;
501
f5ab9736
RS
502 /* See if dir contains subdirs for use by Emacs.
503 Check for the ones that would exist in a build directory,
504 not including lisp and info. */
505 tem = Fexpand_file_name (build_string ("lib-src"), dir);
506 lib_src_exists = Ffile_exists_p (tem);
de004cc6 507
70344b34 508#ifdef MSDOS
de004cc6
RS
509 /* MSDOS installations frequently remove lib-src, but we still
510 must set installation-directory, or else info won't find
511 its files (it uses the value of installation-directory). */
512 tem = Fexpand_file_name (build_string ("info"), dir);
513 info_exists = Ffile_exists_p (tem);
70344b34
EZ
514#else
515 info_exists = Qnil;
516#endif
de004cc6
RS
517
518 if (!NILP (lib_src_exists) || !NILP (info_exists))
07f4d123 519 {
f5ab9736
RS
520 tem = Fexpand_file_name (build_string ("etc"), dir);
521 etc_exists = Ffile_exists_p (tem);
522 if (!NILP (etc_exists))
07f4d123 523 {
f5ab9736
RS
524 Vinstallation_directory
525 = Ffile_name_as_directory (dir);
526 break;
07f4d123
RS
527 }
528 }
529
530 /* See if dir's parent contains those subdirs. */
f5ab9736
RS
531 tem = Fexpand_file_name (build_string ("../lib-src"), dir);
532 lib_src_exists = Ffile_exists_p (tem);
de004cc6 533
70344b34
EZ
534
535#ifdef MSDOS
536 /* See the MSDOS commentary above. */
de004cc6
RS
537 tem = Fexpand_file_name (build_string ("../info"), dir);
538 info_exists = Ffile_exists_p (tem);
70344b34
EZ
539#else
540 info_exists = Qnil;
541#endif
de004cc6
RS
542
543 if (!NILP (lib_src_exists) || !NILP (info_exists))
07f4d123 544 {
f5ab9736
RS
545 tem = Fexpand_file_name (build_string ("../etc"), dir);
546 etc_exists = Ffile_exists_p (tem);
547 if (!NILP (etc_exists))
07f4d123 548 {
f5ab9736
RS
549 tem = Fexpand_file_name (build_string (".."), dir);
550 Vinstallation_directory
551 = Ffile_name_as_directory (tem);
552 break;
07f4d123
RS
553 }
554 }
555
556 /* If the Emacs executable is actually a link,
557 next try the dir that the link points into. */
558 tem = Ffile_symlink_p (name);
559 if (!NILP (tem))
560 {
260ec24d 561 name = Fexpand_file_name (tem, dir);
07f4d123
RS
562 dir = Ffile_name_directory (name);
563 }
564 else
565 break;
566 }
567 }
568
f927c5ae
JB
569 Vcommand_line_args = Qnil;
570
571 for (i = argc - 1; i >= 0; i--)
572 {
573 if (i == 0 || i > skip_args)
574 Vcommand_line_args
575 = Fcons (build_string (argv[i]), Vcommand_line_args);
576 }
213d0b1f
RS
577
578 unbind_to (count, Qnil);
f927c5ae 579}
59653951
JB
580
581DEFUN ("invocation-name", Finvocation_name, Sinvocation_name, 0, 0, 0,
7db35a48
PJ
582 doc: /* Return the program name that was used to run Emacs.
583Any directory names are omitted. */)
584 ()
59653951
JB
585{
586 return Fcopy_sequence (Vinvocation_name);
587}
588
ace40a69 589DEFUN ("invocation-directory", Finvocation_directory, Sinvocation_directory,
7db35a48
PJ
590 0, 0, 0,
591 doc: /* Return the directory name in which the Emacs executable was located. */)
592 ()
ace40a69
RS
593{
594 return Fcopy_sequence (Vinvocation_directory);
595}
596
f927c5ae
JB
597\f
598#ifdef VMS
599#ifdef LINK_CRTL_SHARE
34035df3 600#ifdef SHARABLE_LIB_BUG
f927c5ae 601extern noshare char **environ;
34035df3 602#endif /* SHARABLE_LIB_BUG */
f927c5ae
JB
603#endif /* LINK_CRTL_SHARE */
604#endif /* VMS */
605
0269dedb
RS
606#ifdef HAVE_TZSET
607/* A valid but unlikely value for the TZ environment value.
608 It is OK (though a bit slower) if the user actually chooses this value. */
609static char dump_tz[] = "UtC0";
610#endif
611
a90538cb 612#ifndef ORDINARY_LINK
efd241cc
RS
613/* We don't include crtbegin.o and crtend.o in the link,
614 so these functions and variables might be missed.
615 Provide dummy definitions to avoid error.
616 (We don't have any real constructors or destructors.) */
617#ifdef __GNUC__
46e65b73 618#ifndef GCC_CTORS_IN_LIBC
dfcf069d 619void __do_global_ctors ()
efd241cc 620{}
dfcf069d 621void __do_global_ctors_aux ()
c83a7064 622{}
dfcf069d 623void __do_global_dtors ()
33143604 624{}
554061d8 625/* GNU/Linux has a bug in its library; avoid an error. */
8a2a6032 626#ifndef GNU_LINUX
c83a7064 627char * __CTOR_LIST__[2] = { (char *) (-1), 0 };
64c1864a 628#endif
c83a7064 629char * __DTOR_LIST__[2] = { (char *) (-1), 0 };
46e65b73 630#endif /* GCC_CTORS_IN_LIBC */
dfcf069d 631void __main ()
efd241cc 632{}
efd241cc 633#endif /* __GNUC__ */
a90538cb 634#endif /* ORDINARY_LINK */
efd241cc 635
e2925360
KH
636/* Test whether the next argument in ARGV matches SSTR or a prefix of
637 LSTR (at least MINLEN characters). If so, then if VALPTR is non-null
638 (the argument is supposed to have a value) store in *VALPTR either
639 the next argument or the portion of this one after the equal sign.
640 ARGV is read starting at position *SKIPPTR; this index is advanced
641 by the number of arguments used.
642
643 Too bad we can't just use getopt for all of this, but we don't have
644 enough information to do it right. */
081bef73 645
e2925360 646static int
df6530f8 647argmatch (argv, argc, sstr, lstr, minlen, valptr, skipptr)
e2925360 648 char **argv;
df6530f8 649 int argc;
e2925360
KH
650 char *sstr;
651 char *lstr;
652 int minlen;
653 char **valptr;
654 int *skipptr;
655{
6bbd7a29 656 char *p = NULL;
e2925360 657 int arglen;
df6530f8
RS
658 char *arg;
659
660 /* Don't access argv[argc]; give up in advance. */
661 if (argc <= *skipptr + 1)
662 return 0;
663
664 arg = argv[*skipptr+1];
e2925360
KH
665 if (arg == NULL)
666 return 0;
667 if (strcmp (arg, sstr) == 0)
668 {
669 if (valptr != NULL)
670 {
671 *valptr = argv[*skipptr+2];
672 *skipptr += 2;
673 }
674 else
675 *skipptr += 1;
676 return 1;
677 }
678 arglen = (valptr != NULL && (p = index (arg, '=')) != NULL
679 ? p - arg : strlen (arg));
c03e1113 680 if (lstr == 0 || arglen < minlen || strncmp (arg, lstr, arglen) != 0)
e2925360
KH
681 return 0;
682 else if (valptr == NULL)
683 {
684 *skipptr += 1;
685 return 1;
686 }
687 else if (p != NULL)
688 {
689 *valptr = p+1;
690 *skipptr += 1;
691 return 1;
692 }
693 else if (argv[*skipptr+2] != NULL)
694 {
695 *valptr = argv[*skipptr+2];
696 *skipptr += 2;
697 return 1;
698 }
699 else
700 {
701 return 0;
702 }
703}
704
b6779252 705#ifdef DOUG_LEA_MALLOC
f927c5ae 706
b6779252
KH
707/* malloc can be invoked even before main (e.g. by the dynamic
708 linker), so the dumped malloc state must be restored as early as
709 possible using this special hook. */
710
711static void
712malloc_initialize_hook ()
713{
1f9c3929 714#ifndef USE_CRT_DLL
b6779252 715 extern char **environ;
1f9c3929 716#endif
6000fe37 717
15aaf1b5
RS
718 if (initialized)
719 {
7c9cd446
AS
720 if (!malloc_using_checking)
721 /* Work around a bug in glibc's malloc. MALLOC_CHECK_ must be
722 ignored if the heap to be restored was constructed without
d942e12a
AS
723 malloc checking. Can't use unsetenv, since that calls malloc. */
724 {
725 char **p;
726
a57c4026 727 for (p = environ; p && *p; p++)
d942e12a
AS
728 if (strncmp (*p, "MALLOC_CHECK_=", 14) == 0)
729 {
730 do
731 *p = p[1];
732 while (*++p);
733 break;
734 }
735 }
b6779252 736
15aaf1b5
RS
737 malloc_set_state (malloc_state_ptr);
738 free (malloc_state_ptr);
739 }
7c9cd446
AS
740 else
741 malloc_using_checking = getenv ("MALLOC_CHECK_") != NULL;
b6779252
KH
742}
743
744void (*__malloc_initialize_hook) () = malloc_initialize_hook;
745
746#endif /* DOUG_LEA_MALLOC */
747
d883731c
PJ
748
749#define REPORT_EMACS_BUG_ADDRESS "bug-gnu-emacs@gnu.org"
750#define REPORT_EMACS_BUG_PRETEST_ADDRESS "emacs-pretest-bug@gnu.org"
751
752/* This function is used to determine an address to which bug report should
753 be sent. */
754
400d6fa9
PJ
755char *
756bug_reporting_address ()
d883731c 757{
400d6fa9 758 int count = 0;
d883731c
PJ
759 Lisp_Object temp;
760 char *string;
761
762 temp = Fsymbol_value (intern ("emacs-version"));
763
764 /* When `emacs-version' is invalid, use normal address. */
765 if (!STRINGP(temp))
766 return REPORT_EMACS_BUG_ADDRESS;
767
d5db4077 768 string = SDATA (temp);
d883731c 769
400d6fa9
PJ
770 /* Count dots in `emacs-version'. */
771 while (*string)
772 {
773 if (*string == '.')
774 count++;
775 string++;
776 }
d883731c
PJ
777
778 /* When `emacs-version' has at least three dots, it is development or
779 pretest version of Emacs. */
400d6fa9 780 return count >= 3 ? REPORT_EMACS_BUG_PRETEST_ADDRESS : REPORT_EMACS_BUG_ADDRESS;
d883731c
PJ
781}
782
783
b6779252
KH
784/* ARGSUSED */
785int
3861bdcd
DL
786main (argc, argv
787#ifdef VMS
788, envp
789#endif
790)
b6779252
KH
791 int argc;
792 char **argv;
3861bdcd 793#ifdef VMS
b6779252 794 char **envp;
3861bdcd 795#endif
b6779252 796{
2313132f 797#if GC_MARK_STACK
39ec21ea
GM
798 Lisp_Object dummy;
799#endif
b6779252 800 char stack_bottom_variable;
68c45bf0 801 int do_initial_setlocale;
b6779252 802 int skip_args = 0;
1f9c3929 803#ifndef USE_CRT_DLL
b6779252 804 extern int errno;
1f9c3929 805#endif
b6779252
KH
806#ifdef HAVE_SETRLIMIT
807 struct rlimit rlim;
808#endif
809 int no_loadup = 0;
6e910e07 810 char *junk = 0;
b6779252 811
2313132f 812#if GC_MARK_STACK
39ec21ea
GM
813 extern Lisp_Object *stack_base;
814 stack_base = &dummy;
815#endif
816
b6779252
KH
817#ifdef LINUX_SBRK_BUG
818 __sbrk (1);
15aaf1b5
RS
819#endif
820
d785cf9e
RS
821#ifdef RUN_TIME_REMAP
822 if (initialized)
823 run_time_remap (argv[0]);
824#endif
825
3fb79984 826#ifdef MAC_OSX
e0f712ba
AC
827 if (!initialized)
828 unexec_init_emacs_zone ();
829#endif
830
081bef73 831 sort_args (argc, argv);
956e3c7e
RS
832 argc = 0;
833 while (argv[argc]) argc++;
081bef73 834
3270ae6e
KH
835 if (argmatch (argv, argc, "-version", "--version", 3, NULL, &skip_args)
836 /* We don't know the version number unless this is a dumped Emacs.
837 So ignore --version otherwise. */
838 && initialized)
1702afef
RS
839 {
840 Lisp_Object tem;
841 tem = Fsymbol_value (intern ("emacs-version"));
842 if (!STRINGP (tem))
843 {
844 fprintf (stderr, "Invalid value of `emacs-version'\n");
845 exit (1);
846 }
847 else
848 {
d5db4077 849 printf ("GNU Emacs %s\n", SDATA (tem));
483812ae 850 printf ("Copyright (C) 2002 Free Software Foundation, Inc.\n");
b455c665
RS
851 printf ("GNU Emacs comes with ABSOLUTELY NO WARRANTY.\n");
852 printf ("You may redistribute copies of Emacs\n");
853 printf ("under the terms of the GNU General Public License.\n");
854 printf ("For more information about these matters, ");
94487c4e 855 printf ("see the file named COPYING.\n");
1702afef
RS
856 exit (0);
857 }
858 }
859
f927c5ae
JB
860/* Map in shared memory, if we are using that. */
861#ifdef HAVE_SHM
df6530f8 862 if (argmatch (argv, argc, "-nl", "--no-shared-memory", 6, NULL, &skip_args))
f927c5ae
JB
863 {
864 map_in_data (0);
865 /* The shared memory was just restored, which clobbered this. */
866 skip_args = 1;
867 }
868 else
869 {
870 map_in_data (1);
871 /* The shared memory was just restored, which clobbered this. */
872 skip_args = 0;
873 }
874#endif
875
19a36ec6 876#ifdef NeXT
b9df9faa
KH
877 {
878 extern int malloc_cookie;
879 /* This helps out unexnext.c. */
880 if (initialized)
881 if (malloc_jumpstart (malloc_cookie) != 0)
882 printf ("malloc jumpstart failed!\n");
883 }
19a36ec6
RS
884#endif /* NeXT */
885
e0f712ba
AC
886#ifdef MAC_OSX
887 /* Skip process serial number passed in the form -psn_x_y as
888 command-line argument. */
889 if (argc > skip_args + 1 && strncmp (argv[skip_args+1], "-psn_", 5) == 0)
890 skip_args++;
891#endif /* MAC_OSX */
892
f927c5ae 893#ifdef VMS
7db35a48 894 /* If -map specified, map the data file in. */
e2925360
KH
895 {
896 char *file;
df6530f8 897 if (argmatch (argv, argc, "-map", "--map-data", 3, &mapin_file, &skip_args))
e2925360
KH
898 mapin_data (file);
899 }
f927c5ae
JB
900
901#ifdef LINK_CRTL_SHARE
34035df3 902#ifdef SHARABLE_LIB_BUG
7db35a48 903 /* Bletcherous shared libraries! */
f927c5ae
JB
904 if (!stdin)
905 stdin = fdopen (0, "r");
906 if (!stdout)
907 stdout = fdopen (1, "w");
908 if (!stderr)
909 stderr = fdopen (2, "w");
910 if (!environ)
911 environ = envp;
34035df3 912#endif /* SHARABLE_LIB_BUG */
f927c5ae
JB
913#endif /* LINK_CRTL_SHARE */
914#endif /* VMS */
915
ea2acec5 916#if defined (HAVE_SETRLIMIT) && defined (RLIMIT_STACK)
6c2935e9
RS
917 /* Extend the stack space available.
918 Don't do that if dumping, since some systems (e.g. DJGPP)
919 might define a smaller stack limit at that time. */
920 if (1
921#ifndef CANNOT_DUMP
922 && (!noninteractive || initialized)
923#endif
924 && !getrlimit (RLIMIT_STACK, &rlim))
53c58b5d 925 {
509a8fcd 926 long newlim;
6c2935e9 927 extern int re_max_failures;
03effc23
KH
928 /* Approximate the amount regex.c needs per unit of re_max_failures. */
929 int ratio = 20 * sizeof (char *);
930 /* Then add 33% to cover the size of the smaller stacks that regex.c
931 successively allocates and discards, on its way to the maximum. */
932 ratio += ratio / 3;
933 /* Add in some extra to cover
934 what we're likely to use for other reasons. */
935 newlim = re_max_failures * ratio + 200000;
d0381a7f
RS
936#ifdef __NetBSD__
937 /* NetBSD (at least NetBSD 1.2G and former) has a bug in its
938 stack allocation routine for new process that the allocation
939 fails if stack limit is not on page boundary. So, round up the
940 new limit to page boundary. */
941 newlim = (newlim + getpagesize () - 1) / getpagesize () * getpagesize();
942#endif
509a8fcd 943 if (newlim > rlim.rlim_max)
6c2935e9
RS
944 {
945 newlim = rlim.rlim_max;
03effc23
KH
946 /* Don't let regex.c overflow the stack we have. */
947 re_max_failures = (newlim - 200000) / ratio;
6c2935e9 948 }
509a8fcd
RS
949 if (rlim.rlim_cur < newlim)
950 rlim.rlim_cur = newlim;
951
53c58b5d
RS
952 setrlimit (RLIMIT_STACK, &rlim);
953 }
ea2acec5 954#endif /* HAVE_SETRLIMIT and RLIMIT_STACK */
53c58b5d 955
f927c5ae
JB
956 /* Record (approximately) where the stack begins. */
957 stack_bottom = &stack_bottom_variable;
958
f927c5ae
JB
959#ifdef USG_SHARED_LIBRARIES
960 if (bss_end)
1d233b80 961 brk ((void *)bss_end);
f927c5ae
JB
962#endif
963
964 clearerr (stdin);
9ae8f997 965
f927c5ae 966#ifndef SYSTEM_MALLOC
bf7f4e90
RS
967 /* Arrange to get warning messages as memory fills up. */
968 memory_warnings (0, malloc_warning);
9ac0d9e0 969
f5a3c8c4
AI
970 /* Call malloc at least once, to run the initial __malloc_hook.
971 Also call realloc and free for consistency. */
972 free (realloc (malloc (4), 4));
bf7f4e90
RS
973
974 /* Arrange to disable interrupt input inside malloc etc. */
975 uninterrupt_malloc ();
f927c5ae
JB
976#endif /* not SYSTEM_MALLOC */
977
edd3ff1d 978#if defined (MSDOS) || defined (WINDOWSNT)
29b89fe0
RS
979 /* We do all file input/output as binary files. When we need to translate
980 newlines, we do that manually. */
981 _fmode = O_BINARY;
edd3ff1d 982#endif /* MSDOS || WINDOWSNT */
18198bb2 983
edd3ff1d 984#ifdef MSDOS
18198bb2
RS
985#if __DJGPP__ >= 2
986 if (!isatty (fileno (stdin)))
987 setmode (fileno (stdin), O_BINARY);
988 if (!isatty (fileno (stdout)))
989 {
990 fflush (stdout);
991 setmode (fileno (stdout), O_BINARY);
992 }
993#else /* not __DJGPP__ >= 2 */
29b89fe0
RS
994 (stdin)->_flag &= ~_IOTEXT;
995 (stdout)->_flag &= ~_IOTEXT;
996 (stderr)->_flag &= ~_IOTEXT;
18198bb2 997#endif /* not __DJGPP__ >= 2 */
29b89fe0
RS
998#endif /* MSDOS */
999
a422068f 1000#ifdef SET_EMACS_PRIORITY
3005da00 1001 if (emacs_priority)
5aa7f46a 1002 nice (emacs_priority);
f927c5ae 1003 setuid (getuid ());
a422068f 1004#endif /* SET_EMACS_PRIORITY */
f927c5ae 1005
68c45bf0
PE
1006 /* Skip initial setlocale if LC_ALL is "C", as it's not needed in that case.
1007 The build procedure uses this while dumping, to ensure that the
1008 dumped Emacs does not have its system locale tables initialized,
1009 as that might cause screwups when the dumped Emacs starts up. */
1010 {
1011 char *lc_all = getenv ("LC_ALL");
1012 do_initial_setlocale = ! lc_all || strcmp (lc_all, "C");
1013 }
1014
1015 /* Set locale now, so that initial error messages are localized properly.
1016 fixup_locale must wait until later, since it builds strings. */
1017 if (do_initial_setlocale)
1018 setlocale (LC_ALL, "");
1019
d8b3a65d 1020#ifdef EXTRA_INITIALIZE
a9260219 1021 EXTRA_INITIALIZE;
d8b3a65d
RS
1022#endif
1023
f927c5ae
JB
1024 inhibit_window_system = 0;
1025
7db35a48 1026 /* Handle the -t switch, which specifies filename to use as terminal. */
956e3c7e
RS
1027 while (1)
1028 {
1029 char *term;
1030 if (argmatch (argv, argc, "-t", "--terminal", 4, &term, &skip_args))
1031 {
1032 int result;
68c45bf0
PE
1033 emacs_close (0);
1034 emacs_close (1);
1035 result = emacs_open (term, O_RDWR, 0);
956e3c7e
RS
1036 if (result < 0)
1037 {
1038 char *errstring = strerror (errno);
186486eb 1039 fprintf (stderr, "%s: %s: %s\n", argv[0], term, errstring);
956e3c7e
RS
1040 exit (1);
1041 }
1042 dup (0);
1043 if (! isatty (0))
1044 {
186486eb 1045 fprintf (stderr, "%s: %s: not a tty\n", argv[0], term);
956e3c7e
RS
1046 exit (1);
1047 }
1048 fprintf (stderr, "Using %s\n", term);
8ba50e1a 1049#ifdef HAVE_WINDOW_SYSTEM
956e3c7e 1050 inhibit_window_system = 1; /* -t => -nw */
f927c5ae 1051#endif
956e3c7e
RS
1052 }
1053 else
1054 break;
1055 }
1056
400d6fa9
PJ
1057 /* Command line option --no-windows is deprecated and thus not mentioned
1058 in the manual and usage informations. */
1059 if (argmatch (argv, argc, "-nw", "--no-window-system", 6, NULL, &skip_args)
1060 || argmatch (argv, argc, "-nw", "--no-windows", 6, NULL, &skip_args))
e2925360 1061 inhibit_window_system = 1;
f927c5ae 1062
e2925360 1063 /* Handle the -batch switch, which means don't do interactive display. */
f927c5ae 1064 noninteractive = 0;
df6530f8 1065 if (argmatch (argv, argc, "-batch", "--batch", 5, NULL, &skip_args))
e2925360 1066 noninteractive = 1;
6e910e07
RS
1067 if (argmatch (argv, argc, "-script", "--script", 3, &junk, &skip_args))
1068 {
1069 noninteractive = 1; /* Set batch mode. */
1070 /* Convert --script to -l, un-skip it, and sort again so that -l will be
1071 handled in proper sequence. */
1072 argv[skip_args - 1] = "-l";
1073 skip_args -= 2;
1074 sort_args (argc, argv);
1075 }
e2925360 1076
7db35a48 1077 /* Handle the --help option, which gives a usage message. */
df6530f8 1078 if (argmatch (argv, argc, "-help", "--help", 3, NULL, &skip_args))
f927c5ae 1079 {
6b61353c
KH
1080 printf (USAGE1, argv[0], USAGE2);
1081 printf (USAGE3);
1082 printf (USAGE4, bug_reporting_address ());
e2925360 1083 exit (0);
f927c5ae
JB
1084 }
1085
edb85f59
RS
1086 if (! noninteractive)
1087 {
1088#ifdef BSD_PGRPS
1089 if (initialized)
1090 {
1091 inherited_pgroup = EMACS_GETPGRP (0);
1092 setpgrp (0, getpid ());
1093 }
1094#else
1095#if defined (USG5) && defined (INTERRUPT_INPUT)
1096 setpgrp ();
1097#endif
1098#endif
1099 }
1100
fb8e9847 1101 init_signals ();
fb8e9847 1102
1efa2983
KH
1103 /* Don't catch SIGHUP if dumping. */
1104 if (1
1105#ifndef CANNOT_DUMP
1106 && initialized
1107#endif
1108 )
1109 {
57e3d22a 1110 sigblock (sigmask (SIGHUP));
1efa2983
KH
1111 /* In --batch mode, don't catch SIGHUP if already ignored.
1112 That makes nohup work. */
1113 if (! noninteractive
1114 || signal (SIGHUP, SIG_IGN) != SIG_IGN)
1115 signal (SIGHUP, fatal_error_signal);
57e3d22a 1116 sigunblock (sigmask (SIGHUP));
1efa2983
KH
1117 }
1118
f927c5ae
JB
1119 if (
1120#ifndef CANNOT_DUMP
1121 ! noninteractive || initialized
1122#else
1123 1
1124#endif
1125 )
1126 {
1efa2983 1127 /* Don't catch these signals in batch mode if dumping.
f927c5ae
JB
1128 On some machines, this sets static data that would make
1129 signal fail to work right when the dumped Emacs is run. */
f927c5ae
JB
1130 signal (SIGQUIT, fatal_error_signal);
1131 signal (SIGILL, fatal_error_signal);
1132 signal (SIGTRAP, fatal_error_signal);
7317d9e8
RS
1133#ifdef SIGUSR1
1134 signal (SIGUSR1, handle_USR1_signal);
1135#ifdef SIGUSR2
1136 signal (SIGUSR2, handle_USR2_signal);
1137#endif
1138#endif
99e372cd
RS
1139#ifdef SIGABRT
1140 signal (SIGABRT, fatal_error_signal);
1141#endif
1142#ifdef SIGHWE
1143 signal (SIGHWE, fatal_error_signal);
1144#endif
1145#ifdef SIGPRE
1146 signal (SIGPRE, fatal_error_signal);
1147#endif
1148#ifdef SIGORE
1149 signal (SIGORE, fatal_error_signal);
1150#endif
1151#ifdef SIGUME
1152 signal (SIGUME, fatal_error_signal);
1153#endif
1154#ifdef SIGDLK
1155 signal (SIGDLK, fatal_error_signal);
1156#endif
1157#ifdef SIGCPULIM
1158 signal (SIGCPULIM, fatal_error_signal);
1159#endif
a90538cb
JB
1160#ifdef SIGIOT
1161 /* This is missing on some systems - OS/2, for example. */
f927c5ae 1162 signal (SIGIOT, fatal_error_signal);
a90538cb 1163#endif
f927c5ae
JB
1164#ifdef SIGEMT
1165 signal (SIGEMT, fatal_error_signal);
1166#endif
1167 signal (SIGFPE, fatal_error_signal);
00eaaa32 1168#ifdef SIGBUS
f927c5ae 1169 signal (SIGBUS, fatal_error_signal);
00eaaa32 1170#endif
f927c5ae 1171 signal (SIGSEGV, fatal_error_signal);
00eaaa32 1172#ifdef SIGSYS
f927c5ae 1173 signal (SIGSYS, fatal_error_signal);
00eaaa32 1174#endif
f927c5ae
JB
1175 signal (SIGTERM, fatal_error_signal);
1176#ifdef SIGXCPU
1177 signal (SIGXCPU, fatal_error_signal);
1178#endif
1179#ifdef SIGXFSZ
1180 signal (SIGXFSZ, fatal_error_signal);
1181#endif /* SIGXFSZ */
1182
271c7b7c
RS
1183#ifdef SIGDANGER
1184 /* This just means available memory is getting low. */
1185 signal (SIGDANGER, memory_warning_signal);
1186#endif
1187
f927c5ae 1188#ifdef AIX
56e034fa
RS
1189/* 20 is SIGCHLD, 21 is SIGTTIN, 22 is SIGTTOU. */
1190 signal (SIGXCPU, fatal_error_signal);
0aef8561 1191#ifndef _I386
f927c5ae 1192 signal (SIGIOINT, fatal_error_signal);
0aef8561 1193#endif
f927c5ae
JB
1194 signal (SIGGRANT, fatal_error_signal);
1195 signal (SIGRETRACT, fatal_error_signal);
1196 signal (SIGSOUND, fatal_error_signal);
1197 signal (SIGMSG, fatal_error_signal);
1198#endif /* AIX */
1199 }
1200
1201 noninteractive1 = noninteractive;
1202
7db35a48 1203/* Perform basic initializations (not merely interning symbols). */
f927c5ae
JB
1204
1205 if (!initialized)
1206 {
1207 init_alloc_once ();
1208 init_obarray ();
1209 init_eval_once ();
e37d7195 1210 init_character_once ();
270ce821
KH
1211 init_charset_once ();
1212 init_coding_once ();
f927c5ae 1213 init_syntax_once (); /* Create standard syntax table. */
270ce821 1214 init_category_once (); /* Create standard category table. */
7db35a48 1215 /* Must be done before init_buffer. */
f927c5ae 1216 init_casetab_once ();
7db35a48
PJ
1217 init_buffer_once (); /* Create buffer table and some buffers. */
1218 init_minibuf_once (); /* Create list of minibuffers. */
1219 /* Must precede init_window_once. */
1220
90d920b6
GM
1221 /* Call syms_of_xfaces before init_window_once because that
1222 function creates Vterminal_frame. Termcap frames now use
1223 faces, and the face implementation uses some symbols as
1224 face names. */
90d920b6 1225 syms_of_xfaces ();
7a18af49
KR
1226 /* Call syms_of_keyboard before init_window_once because
1227 keyboard sets up symbols that include some face names that
1228 the X support will want to use. This can happen when
1229 CANNOT_DUMP is defined. */
1230 syms_of_keyboard ();
90d920b6 1231
e0f712ba 1232#ifdef MAC_OS8
c1e279c2
AC
1233 /* init_window_once calls make_terminal_frame which on Mac OS
1234 creates a full-fledge output_mac type frame. This does not
1235 work correctly before syms_of_textprop, syms_of_macfns,
1236 syms_of_ccl, syms_of_fontset, syms_of_xterm, syms_of_search,
e0f712ba 1237 syms_of_frame, mac_initialize, and init_keyboard have already
c1e279c2 1238 been called. */
1a578e9b
AC
1239 syms_of_textprop ();
1240 syms_of_macfns ();
1241 syms_of_ccl ();
1242 syms_of_fontset ();
1243 syms_of_macterm ();
1244 syms_of_macmenu ();
1245 syms_of_data ();
1246 syms_of_search ();
c1e279c2 1247 syms_of_frame ();
7db35a48 1248
e0f712ba 1249 mac_initialize ();
1a578e9b
AC
1250 init_keyboard ();
1251#endif
1252
7db35a48 1253 init_window_once (); /* Init the window system. */
680256a8 1254 init_fileio_once (); /* Must precede any path manipulation. */
6b61353c
KH
1255#ifdef HAVE_WINDOW_SYSTEM
1256 init_fringe_once (); /* Swap bitmaps if necessary. */
1257#endif /* HAVE_WINDOW_SYSTEM */
f927c5ae
JB
1258 }
1259
1260 init_alloc ();
68c45bf0
PE
1261
1262 if (do_initial_setlocale)
1263 {
1264 fixup_locale ();
ca9c0567
PE
1265 Vsystem_messages_locale = Vprevious_system_messages_locale;
1266 Vsystem_time_locale = Vprevious_system_time_locale;
68c45bf0
PE
1267 }
1268
f927c5ae
JB
1269 init_eval ();
1270 init_data ();
ad067ea6 1271#ifdef CLASH_DETECTION
01f67d2c 1272 init_filelock ();
ad067ea6 1273#endif
ab5d0358 1274 init_atimer ();
7074fde6 1275 running_asynch_code = 0;
0e956009 1276
a08a816a
RS
1277 /* Handle --unibyte and the EMACS_UNIBYTE envvar,
1278 but not while dumping. */
e721aa94 1279 if (1)
a08a816a
RS
1280 {
1281 int inhibit_unibyte = 0;
1282
1283 /* --multibyte overrides EMACS_UNIBYTE. */
1284 if (argmatch (argv, argc, "-no-unibyte", "--no-unibyte", 4, NULL, &skip_args)
e721aa94
SM
1285 || argmatch (argv, argc, "-multibyte", "--multibyte", 4, NULL, &skip_args)
1286 /* Ignore EMACS_UNIBYTE before dumping. */
1287 || (!initialized && noninteractive))
a08a816a
RS
1288 inhibit_unibyte = 1;
1289
1290 /* --unibyte requests that we set up to do everything with single-byte
1291 buffers and strings. We need to handle this before calling
1292 init_lread, init_editfns and other places that generate Lisp strings
1293 from text in the environment. */
c0218e1b
DL
1294 /* Actually this shouldn't be needed as of 20.4 in a generally
1295 unibyte environment. As handa says, environment values
1296 aren't now decoded; also existing buffers are now made
1297 unibyte during startup if .emacs sets unibyte. Tested with
1298 8-bit data in environment variables and /etc/passwd, setting
7db35a48 1299 unibyte and Latin-1 in .emacs. -- Dave Love */
a08a816a
RS
1300 if (argmatch (argv, argc, "-unibyte", "--unibyte", 4, NULL, &skip_args)
1301 || argmatch (argv, argc, "-no-multibyte", "--no-multibyte", 4, NULL, &skip_args)
1302 || (getenv ("EMACS_UNIBYTE") && !inhibit_unibyte))
1303 {
1304 Lisp_Object old_log_max;
1305 Lisp_Object symbol, tail;
1306
1307 symbol = intern ("default-enable-multibyte-characters");
1308 Fset (symbol, Qnil);
1309
6524291c
KH
1310 if (initialized)
1311 {
1312 /* Erase pre-dump messages in *Messages* now so no abort. */
1313 old_log_max = Vmessage_log_max;
1314 XSETFASTINT (Vmessage_log_max, 0);
1315 message_dolog ("", 0, 1, 0);
1316 Vmessage_log_max = old_log_max;
1317 }
a08a816a 1318
3e75bb9e 1319 for (tail = Vbuffer_alist; CONSP (tail);
7539e11f 1320 tail = XCDR (tail))
a08a816a
RS
1321 {
1322 Lisp_Object buffer;
1323
7539e11f 1324 buffer = Fcdr (XCAR (tail));
8f924df7 1325 /* Make a multibyte buffer unibyte. */
f2b89e21
KH
1326 if (BUF_Z_BYTE (XBUFFER (buffer)) > BUF_Z (XBUFFER (buffer)))
1327 {
1328 struct buffer *current = current_buffer;
1329
1330 set_buffer_temp (XBUFFER (buffer));
8f924df7 1331 Fset_buffer_multibyte (Qnil);
f2b89e21
KH
1332 set_buffer_temp (current);
1333 }
a08a816a
RS
1334 }
1335 }
1336 }
1337
956e3c7e 1338 no_loadup
b96f9fb7 1339 = argmatch (argv, argc, "-nl", "--no-loadup", 6, NULL, &skip_args);
956e3c7e
RS
1340
1341
1342#ifdef HAVE_X_WINDOWS
1343 /* Stupid kludge to catch command-line display spec. We can't
1344 handle this argument entirely in window system dependent code
1345 because we don't even know which window system dependent code
1346 to run until we've recognized this argument. */
1347 {
1348 char *displayname = 0;
956e3c7e
RS
1349 int count_before = skip_args;
1350
1351 /* Skip any number of -d options, but only use the last one. */
1352 while (1)
1353 {
1354 int count_before_this = skip_args;
1355
1356 if (argmatch (argv, argc, "-d", "--display", 3, &displayname, &skip_args))
1357 display_arg = 1;
1358 else if (argmatch (argv, argc, "-display", 0, 3, &displayname, &skip_args))
1359 display_arg = 1;
1360 else
1361 break;
1362
1363 count_before = count_before_this;
1364 }
1365
1366 /* If we have the form --display=NAME,
1367 convert it into -d name.
1368 This requires inserting a new element into argv. */
1369 if (displayname != 0 && skip_args - count_before == 1)
1370 {
1371 char **new = (char **) xmalloc (sizeof (char *) * (argc + 2));
1372 int j;
1373
1374 for (j = 0; j < count_before + 1; j++)
1375 new[j] = argv[j];
1376 new[count_before + 1] = "-d";
1377 new[count_before + 2] = displayname;
1378 for (j = count_before + 2; j <argc; j++)
1379 new[j + 1] = argv[j];
1380 argv = new;
1381 argc++;
1382 }
1383 /* Change --display to -d, when its arg is separate. */
1384 else if (displayname != 0 && skip_args > count_before
1385 && argv[count_before + 1][1] == '-')
1386 argv[count_before + 1] = "-d";
1387
1388 /* Don't actually discard this arg. */
1389 skip_args = count_before;
1390 }
1391#endif
1392
1393 /* argmatch must not be used after here,
1394 except when bulding temacs
1395 because the -d argument has not been skipped in skip_args. */
1396
29b89fe0
RS
1397#ifdef MSDOS
1398 /* Call early 'cause init_environment needs it. */
1399 init_dosfns ();
1400 /* Set defaults for several environment variables. */
18198bb2
RS
1401 if (initialized)
1402 init_environment (argc, argv, skip_args);
1403 else
d1fc6752 1404 tzset ();
18198bb2 1405#endif /* MSDOS */
29b89fe0 1406
8ba50e1a 1407#ifdef WINDOWSNT
9785d95b 1408 globals_of_w32 ();
8ba50e1a 1409 /* Initialize environment from registry settings. */
a3a58294 1410 init_environment (argv);
7db35a48 1411 init_ntproc (); /* must precede init_editfns. */
8ba50e1a
GV
1412#endif
1413
f1c1cccd 1414#ifdef HAVE_CARBON
1000788b
AC
1415 if (initialized)
1416 init_mac_osx_environment ();
1417#endif
1418
0e956009
JB
1419 /* egetenv is a pretty low-level facility, which may get called in
1420 many circumstances; it seems flimsy to put off initializing it
1421 until calling init_callproc. */
1422 set_process_environment ();
93aed04d
RS
1423 /* AIX crashes are reported in system versions 3.2.3 and 3.2.4
1424 if this is not done. Do it after set_process_environment so that we
1425 don't pollute Vprocess_environment. */
fa09a82d
DL
1426 /* Setting LANG here will defeat the startup locale processing... */
1427#ifdef AIX3_2
93aed04d
RS
1428 putenv ("LANG=C");
1429#endif
0e956009 1430
7db35a48 1431 init_buffer (); /* Init default directory of main buffer. */
ace40a69 1432
7928f0b5 1433 init_callproc_1 (); /* Must precede init_cmdargs and init_sys_modes. */
ace40a69 1434 init_cmdargs (argc, argv, skip_args); /* Must precede init_lread. */
380e25b8
RS
1435
1436 if (initialized)
1437 {
7db35a48 1438 /* Erase any pre-dump messages in the message log, to avoid confusion. */
380e25b8
RS
1439 Lisp_Object old_log_max;
1440 old_log_max = Vmessage_log_max;
1441 XSETFASTINT (Vmessage_log_max, 0);
f6fe7bb5 1442 message_dolog ("", 0, 1, 0);
380e25b8
RS
1443 Vmessage_log_max = old_log_max;
1444 }
1445
7928f0b5 1446 init_callproc (); /* Must follow init_cmdargs but not init_sys_modes. */
fb8e9847 1447 init_lread ();
f927c5ae 1448
8bb697c0
RS
1449 /* Intern the names of all standard functions and variables;
1450 define standard keys. */
f927c5ae
JB
1451
1452 if (!initialized)
1453 {
7db35a48 1454 /* The basic levels of Lisp must come first. */
f927c5ae 1455 /* And data must come first of all
7db35a48 1456 for the sake of symbols like error-message. */
e0f712ba
AC
1457#ifndef MAC_OS8
1458 /* Called before init_window_once for Mac OS Classic. */
f927c5ae 1459 syms_of_data ();
1a578e9b 1460#endif
f927c5ae 1461 syms_of_alloc ();
e37d7195 1462 syms_of_chartab ();
fb8e9847 1463 syms_of_lread ();
f927c5ae
JB
1464 syms_of_print ();
1465 syms_of_eval ();
1466 syms_of_fns ();
f927c5ae 1467 syms_of_floatfns ();
f927c5ae
JB
1468
1469 syms_of_abbrev ();
1470 syms_of_buffer ();
1471 syms_of_bytecode ();
1472 syms_of_callint ();
1473 syms_of_casefiddle ();
1474 syms_of_casetab ();
1475 syms_of_callproc ();
270ce821 1476 syms_of_category ();
e0f712ba
AC
1477#ifndef MAC_OS8
1478 /* Called before init_window_once for Mac OS Classic. */
270ce821 1479 syms_of_ccl ();
1a578e9b 1480#endif
e37d7195 1481 syms_of_character ();
270ce821 1482 syms_of_charset ();
f927c5ae
JB
1483 syms_of_cmds ();
1484#ifndef NO_DIR_LIBRARY
1485 syms_of_dired ();
1486#endif /* not NO_DIR_LIBRARY */
1487 syms_of_display ();
1488 syms_of_doc ();
1489 syms_of_editfns ();
1490 syms_of_emacs ();
1491 syms_of_fileio ();
270ce821 1492 syms_of_coding (); /* This should be after syms_of_fileio. */
f927c5ae
JB
1493#ifdef CLASH_DETECTION
1494 syms_of_filelock ();
1495#endif /* CLASH_DETECTION */
1496 syms_of_indent ();
c2c5ed2c 1497 syms_of_insdel ();
f927c5ae
JB
1498 syms_of_keymap ();
1499 syms_of_macros ();
1500 syms_of_marker ();
1501 syms_of_minibuf ();
f927c5ae 1502 syms_of_process ();
e0f712ba
AC
1503#ifndef MAC_OS8
1504 /* Called before init_window_once for Mac OS Classic. */
f927c5ae 1505 syms_of_search ();
1cbd5d9d 1506 syms_of_frame ();
c1e279c2 1507#endif
f927c5ae 1508 syms_of_syntax ();
0d934e7b 1509 syms_of_term ();
f927c5ae 1510 syms_of_undo ();
90d920b6
GM
1511#ifdef HAVE_SOUND
1512 syms_of_sound ();
1513#endif
e0f712ba
AC
1514#ifndef MAC_OS8
1515 /* Called before init_window_once for Mac OS Classic. */
bef79ee4 1516 syms_of_textprop ();
1a578e9b 1517#endif
9d100795 1518 syms_of_composite ();
f927c5ae
JB
1519#ifdef VMS
1520 syms_of_vmsproc ();
1521#endif /* VMS */
05687c54
RS
1522#ifdef WINDOWSNT
1523 syms_of_ntproc ();
1524#endif /* WINDOWSNT */
f927c5ae
JB
1525 syms_of_window ();
1526 syms_of_xdisp ();
6b61353c
KH
1527#ifdef HAVE_WINDOW_SYSTEM
1528 syms_of_fringe ();
1529 syms_of_image ();
1530#endif /* HAVE_WINDOW_SYSTEM */
f927c5ae 1531#ifdef HAVE_X_WINDOWS
72412588 1532 syms_of_xterm ();
f927c5ae 1533 syms_of_xfns ();
270ce821 1534 syms_of_fontset ();
28b1b672
JD
1535#ifdef HAVE_X_SM
1536 syms_of_xsmfns ();
1537#endif
72412588
JB
1538#ifdef HAVE_X11
1539 syms_of_xselect ();
1540#endif
f927c5ae
JB
1541#endif /* HAVE_X_WINDOWS */
1542
6b61353c 1543#ifdef HAVE_MENUS
1e9c210b 1544#ifndef HAVE_NTGUI
e0f712ba
AC
1545#ifndef MAC_OS
1546 /* Called before init_window_once for Mac OS Classic. */
6c850f3c 1547 syms_of_xmenu ();
1e9c210b 1548#endif
1a578e9b 1549#endif
6b61353c 1550#endif
6c850f3c 1551
8ba50e1a 1552#ifdef HAVE_NTGUI
fbd6baed
GV
1553 syms_of_w32term ();
1554 syms_of_w32fns ();
fbd6baed
GV
1555 syms_of_w32select ();
1556 syms_of_w32menu ();
02062ac3 1557 syms_of_fontset ();
8ba50e1a
GV
1558#endif /* HAVE_NTGUI */
1559
e0f712ba
AC
1560#ifdef HAVE_CARBON
1561 syms_of_macterm ();
1562 syms_of_macfns ();
1563 syms_of_macmenu ();
1564 syms_of_fontset ();
1565#endif /* HAVE_CARBON */
1566
f927c5ae
JB
1567#ifdef SYMS_SYSTEM
1568 SYMS_SYSTEM;
1569#endif
1570
1571#ifdef SYMS_MACHINE
1572 SYMS_MACHINE;
1573#endif
1574
1575 keys_of_casefiddle ();
1576 keys_of_cmds ();
1577 keys_of_buffer ();
1578 keys_of_keyboard ();
1579 keys_of_keymap ();
f927c5ae
JB
1580 keys_of_minibuf ();
1581 keys_of_window ();
9785d95b
BK
1582 }
1583 else
1584 {
1585 /*
1586 Initialization that must be done even if the global variable
1587 initialized is non zero
1588 */
1589#ifdef HAVE_NTGUI
1590 globals_of_w32fns ();
1591 globals_of_w32menu ();
1592#endif /* end #ifdef HAVE_NTGUI */
f927c5ae
JB
1593 }
1594
cf411e8d
KH
1595 init_charset ();
1596
8bb697c0
RS
1597 if (!noninteractive)
1598 {
1599#ifdef VMS
7db35a48 1600 init_vms_input ();/* init_display calls get_frame_size, that needs this. */
8bb697c0 1601#endif /* VMS */
7db35a48 1602 init_display (); /* Determine terminal type. init_sys_modes uses results. */
8bb697c0 1603 }
e0f712ba
AC
1604#ifndef MAC_OS8
1605 /* Called before init_window_once for Mac OS Classic. */
7db35a48 1606 init_keyboard (); /* This too must precede init_sys_modes. */
1a578e9b 1607#endif
8bb697c0 1608#ifdef VMS
7db35a48 1609 init_vmsproc (); /* And this too. */
8bb697c0 1610#endif /* VMS */
7db35a48 1611 init_sys_modes (); /* Init system terminal modes (RAW or CBREAK, etc.). */
90d920b6 1612 init_fns ();
8bb697c0 1613 init_xdisp ();
6b61353c
KH
1614#ifdef HAVE_WINDOW_SYSTEM
1615 init_fringe ();
1616 init_image ();
1617#endif /* HAVE_WINDOW_SYSTEM */
8bb697c0
RS
1618 init_macros ();
1619 init_editfns ();
8bb697c0 1620 init_floatfns ();
8bb697c0
RS
1621#ifdef VMS
1622 init_vmsfns ();
1623#endif /* VMS */
1624 init_process ();
90d920b6
GM
1625#ifdef HAVE_SOUND
1626 init_sound ();
1627#endif
75816372 1628 init_window ();
8bb697c0 1629
f927c5ae
JB
1630 if (!initialized)
1631 {
e2925360 1632 char *file;
7db35a48 1633 /* Handle -l loadup, args passed by Makefile. */
df6530f8 1634 if (argmatch (argv, argc, "-l", "--load", 3, &file, &skip_args))
f927c5ae 1635 Vtop_level = Fcons (intern ("load"),
e2925360 1636 Fcons (build_string (file), Qnil));
f927c5ae 1637 /* Unless next switch is -nl, load "loadup.el" first thing. */
956e3c7e 1638 if (! no_loadup)
f927c5ae
JB
1639 Vtop_level = Fcons (intern ("load"),
1640 Fcons (build_string ("loadup.el"), Qnil));
f927c5ae
JB
1641 }
1642
93572b43
KH
1643 if (initialized)
1644 {
0269dedb
RS
1645#ifdef HAVE_TZSET
1646 {
1647 /* If the execution TZ happens to be the same as the dump TZ,
1648 change it to some other value and then change it back,
1649 to force the underlying implementation to reload the TZ info.
1650 This is needed on implementations that load TZ info from files,
1651 since the TZ file contents may differ between dump and execution. */
1652 char *tz = getenv ("TZ");
1653 if (tz && !strcmp (tz, dump_tz))
1654 {
1655 ++*tz;
1656 tzset ();
1657 --*tz;
1658 }
1659 }
1660#endif
93572b43
KH
1661 }
1662
37a0ae84
GM
1663 /* Set up for profiling. This is known to work on FreeBSD and
1664 GNU/Linux. It might work on some other systems too. Give it a
1665 try and tell us if it works on your system. To compile for
7db35a48 1666 profiling use something like `make CFLAGS="-pg -g -O -DPROFILING=1'. */
6a97197e 1667#if defined (__FreeBSD__) || defined (__linux)
e610ea43
RS
1668#ifdef PROFILING
1669 if (initialized)
1670 {
7db35a48 1671 extern void _mcleanup ();
e610ea43 1672 extern char etext;
90d920b6 1673 extern void safe_bcopy ();
67a5596f
GM
1674 extern void dump_opcode_frequencies ();
1675
e610ea43 1676 atexit (_mcleanup);
90d920b6
GM
1677 /* This uses safe_bcopy because that function comes first in the
1678 Emacs executable. It might be better to use something that
1679 gives the start of the text segment, but start_of_text is not
1680 defined on all systems now. */
1681 monstartup (safe_bcopy, &etext);
e610ea43
RS
1682 }
1683 else
1684 moncontrol (0);
1685#endif
1686#endif
1687
f927c5ae
JB
1688 initialized = 1;
1689
e7536cff
RS
1690#ifdef LOCALTIME_CACHE
1691 /* Some versions of localtime have a bug. They cache the value of the time
279cc2b8
JB
1692 zone rather than looking it up every time. Since localtime() is
1693 called to bolt the undumping time into the undumped emacs, this
afe9fae9 1694 results in localtime ignoring the TZ environment variable.
7db35a48 1695 This flushes the new TZ value into localtime. */
afe9fae9 1696 tzset ();
e7536cff 1697#endif /* defined (LOCALTIME_CACHE) */
279cc2b8 1698
f927c5ae
JB
1699 /* Enter editor command loop. This never returns. */
1700 Frecursive_edit ();
1701 /* NOTREACHED */
6bbd7a29 1702 return 0;
f927c5ae
JB
1703}
1704\f
081bef73
RS
1705/* Sort the args so we can find the most important ones
1706 at the beginning of argv. */
1707
1708/* First, here's a table of all the standard options. */
1709
1710struct standard_args
1711{
1712 char *name;
1713 char *longname;
1714 int priority;
1715 int nargs;
1716};
1717
1718struct standard_args standard_args[] =
1719{
05922407
RS
1720 { "-version", "--version", 150, 0 },
1721#ifdef HAVE_SHM
1722 { "-nl", "--no-shared-memory", 140, 0 },
1723#endif
2725719a 1724#ifdef VMS
05922407 1725 { "-map", "--map-data", 130, 0 },
2725719a 1726#endif
05922407 1727 { "-t", "--terminal", 120, 1 },
400d6fa9 1728 { "-nw", "--no-window-system", 110, 0 },
05922407
RS
1729 { "-nw", "--no-windows", 110, 0 },
1730 { "-batch", "--batch", 100, 0 },
6e910e07 1731 { "-script", "--script", 100, 1 },
05922407 1732 { "-help", "--help", 90, 0 },
956e3c7e
RS
1733 { "-no-unibyte", "--no-unibyte", 83, 0 },
1734 { "-multibyte", "--multibyte", 82, 0 },
1735 { "-unibyte", "--unibyte", 81, 0 },
1736 { "-no-multibyte", "--no-multibyte", 80, 0 },
956e3c7e 1737 { "-nl", "--no-loadup", 70, 0 },
956e3c7e
RS
1738 /* -d must come last before the options handled in startup.el. */
1739 { "-d", "--display", 60, 1 },
1740 { "-display", 0, 60, 1 },
05922407 1741 /* Now for the options handled in startup.el. */
081bef73
RS
1742 { "-q", "--no-init-file", 50, 0 },
1743 { "-no-init-file", 0, 50, 0 },
1744 { "-no-site-file", "--no-site-file", 40, 0 },
af2bf12f 1745 { "-no-splash", "--no-splash", 40, 0 },
081bef73
RS
1746 { "-u", "--user", 30, 1 },
1747 { "-user", 0, 30, 1 },
1748 { "-debug-init", "--debug-init", 20, 0 },
adab4483
KH
1749 { "-i", "--icon-type", 15, 0 },
1750 { "-itype", 0, 15, 0 },
f2bc3538 1751 { "-iconic", "--iconic", 15, 0 },
081bef73
RS
1752 { "-bg", "--background-color", 10, 1 },
1753 { "-background", 0, 10, 1 },
1754 { "-fg", "--foreground-color", 10, 1 },
1755 { "-foreground", 0, 10, 1 },
1756 { "-bd", "--border-color", 10, 1 },
1757 { "-bw", "--border-width", 10, 1 },
1758 { "-ib", "--internal-border", 10, 1 },
1759 { "-ms", "--mouse-color", 10, 1 },
1760 { "-cr", "--cursor-color", 10, 1 },
1761 { "-fn", "--font", 10, 1 },
1762 { "-font", 0, 10, 1 },
94452530
EZ
1763 { "-fs", "--fullscreen", 10, 0 },
1764 { "-fw", "--fullwidth", 10, 0 },
1765 { "-fh", "--fullheight", 10, 0 },
081bef73
RS
1766 { "-g", "--geometry", 10, 1 },
1767 { "-geometry", 0, 10, 1 },
1768 { "-T", "--title", 10, 1 },
ae63ae52 1769 { "-title", 0, 10, 1 },
081bef73
RS
1770 { "-name", "--name", 10, 1 },
1771 { "-xrm", "--xrm", 10, 1 },
fcdeb5d9
RS
1772 { "-r", "--reverse-video", 5, 0 },
1773 { "-rv", 0, 5, 0 },
1774 { "-reverse", 0, 5, 0 },
ae63ae52 1775 { "-hb", "--horizontal-scroll-bars", 5, 0 },
fcdeb5d9 1776 { "-vb", "--vertical-scroll-bars", 5, 0 },
d20e1b1e 1777 { "-color", "--color", 5, 0},
fcdeb5d9
RS
1778 /* These have the same priority as ordinary file name args,
1779 so they are not reordered with respect to those. */
4af9e0b3
RS
1780 { "-L", "--directory", 0, 1 },
1781 { "-directory", 0, 0, 1 },
fcdeb5d9
RS
1782 { "-l", "--load", 0, 1 },
1783 { "-load", 0, 0, 1 },
1784 { "-f", "--funcall", 0, 1 },
1785 { "-funcall", 0, 0, 1 },
575985b1 1786 { "-eval", "--eval", 0, 1 },
67a5596f 1787 { "-execute", "--execute", 0, 1 },
2e13f8e9
RS
1788 { "-find-file", "--find-file", 0, 1 },
1789 { "-visit", "--visit", 0, 1 },
67a5596f 1790 { "-file", "--file", 0, 1 },
fcdeb5d9 1791 { "-insert", "--insert", 0, 1 },
f2bc3538 1792 /* This should be processed after ordinary file name args and the like. */
fcdeb5d9 1793 { "-kill", "--kill", -10, 0 },
081bef73
RS
1794};
1795
1796/* Reorder the elements of ARGV (assumed to have ARGC elements)
1797 so that the highest priority ones come first.
1798 Do not change the order of elements of equal priority.
956e3c7e
RS
1799 If an option takes an argument, keep it and its argument together.
1800
1801 If an option that takes no argument appears more
1802 than once, eliminate all but one copy of it. */
081bef73
RS
1803
1804static void
1805sort_args (argc, argv)
1806 int argc;
1807 char **argv;
1808{
1809 char **new = (char **) xmalloc (sizeof (char *) * argc);
1810 /* For each element of argv,
1811 the corresponding element of options is:
1812 0 for an option that takes no arguments,
1813 1 for an option that takes one argument, etc.
1814 -1 for an ordinary non-option argument. */
6dad9359 1815 int *options = (int *) xmalloc (sizeof (int) * argc);
081bef73
RS
1816 int *priority = (int *) xmalloc (sizeof (int) * argc);
1817 int to = 1;
956e3c7e 1818 int incoming_used = 1;
081bef73
RS
1819 int from;
1820 int i;
1821
1822 /* Categorize all the options,
1823 and figure out which argv elts are option arguments. */
1824 for (from = 1; from < argc; from++)
1825 {
1826 options[from] = -1;
fcdeb5d9 1827 priority[from] = 0;
081bef73
RS
1828 if (argv[from][0] == '-')
1829 {
1830 int match, thislen;
1831 char *equals;
1832
c96f26f4
RS
1833 /* If we have found "--", don't consider
1834 any more arguments as options. */
249443b6 1835 if (argv[from][1] == '-' && argv[from][2] == 0)
c96f26f4
RS
1836 {
1837 /* Leave the "--", and everything following it, at the end. */
1838 for (; from < argc; from++)
1839 {
1840 priority[from] = -100;
1841 options[from] = -1;
1842 }
1843 break;
1844 }
1845
081bef73
RS
1846 /* Look for a match with a known old-fashioned option. */
1847 for (i = 0; i < sizeof (standard_args) / sizeof (standard_args[0]); i++)
1848 if (!strcmp (argv[from], standard_args[i].name))
1849 {
1850 options[from] = standard_args[i].nargs;
1851 priority[from] = standard_args[i].priority;
fd76ec52
RS
1852 if (from + standard_args[i].nargs >= argc)
1853 fatal ("Option `%s' requires an argument\n", argv[from]);
081bef73
RS
1854 from += standard_args[i].nargs;
1855 goto done;
1856 }
1857
1858 /* Look for a match with a known long option.
1859 MATCH is -1 if no match so far, -2 if two or more matches so far,
1860 >= 0 (the table index of the match) if just one match so far. */
1861 if (argv[from][1] == '-')
1862 {
1863 match = -1;
1864 thislen = strlen (argv[from]);
1865 equals = index (argv[from], '=');
1866 if (equals != 0)
1867 thislen = equals - argv[from];
1868
f609ef57
KH
1869 for (i = 0;
1870 i < sizeof (standard_args) / sizeof (standard_args[0]); i++)
1871 if (standard_args[i].longname
1872 && !strncmp (argv[from], standard_args[i].longname,
1873 thislen))
081bef73
RS
1874 {
1875 if (match == -1)
1876 match = i;
1877 else
1878 match = -2;
1879 }
1880
1881 /* If we found exactly one match, use that. */
1882 if (match >= 0)
1883 {
1884 options[from] = standard_args[match].nargs;
1885 priority[from] = standard_args[match].priority;
1886 /* If --OPTION=VALUE syntax is used,
1887 this option uses just one argv element. */
1888 if (equals != 0)
1889 options[from] = 0;
fd76ec52
RS
1890 if (from + options[from] >= argc)
1891 fatal ("Option `%s' requires an argument\n", argv[from]);
081bef73
RS
1892 from += options[from];
1893 }
1894 }
1895 done: ;
1896 }
1897 }
1898
1899 /* Copy the arguments, in order of decreasing priority, to NEW. */
1900 new[0] = argv[0];
956e3c7e 1901 while (incoming_used < argc)
081bef73
RS
1902 {
1903 int best = -1;
2c70c992 1904 int best_priority = -9999;
081bef73
RS
1905
1906 /* Find the highest priority remaining option.
1907 If several have equal priority, take the first of them. */
1908 for (from = 1; from < argc; from++)
1909 {
1910 if (argv[from] != 0 && priority[from] > best_priority)
1911 {
1912 best_priority = priority[from];
1913 best = from;
1914 }
1915 /* Skip option arguments--they are tied to the options. */
1916 if (options[from] > 0)
1917 from += options[from];
1918 }
7db35a48 1919
081bef73
RS
1920 if (best < 0)
1921 abort ();
1922
956e3c7e
RS
1923 /* Copy the highest priority remaining option, with its args, to NEW.
1924 Unless it is a duplicate of the previous one. */
1925 if (! (options[best] == 0
1926 && ! strcmp (new[to - 1], argv[best])))
1927 {
1928 new[to++] = argv[best];
1929 for (i = 0; i < options[best]; i++)
1930 new[to++] = argv[best + i + 1];
1931 }
1932
1933 incoming_used += 1 + (options[best] > 0 ? options[best] : 0);
081bef73
RS
1934
1935 /* Clear out this option in ARGV. */
1936 argv[best] = 0;
1937 for (i = 0; i < options[best]; i++)
1938 argv[best + i + 1] = 0;
1939 }
1940
81b7af72
RS
1941 /* If duplicate options were deleted, fill up extra space with null ptrs. */
1942 while (to < argc)
1943 new[to++] = 0;
1944
6dad9359 1945 bcopy (new, argv, sizeof (char *) * argc);
0bf591da
RS
1946
1947 free (options);
1948 free (new);
1949 free (priority);
081bef73
RS
1950}
1951\f
f927c5ae 1952DEFUN ("kill-emacs", Fkill_emacs, Skill_emacs, 0, 1, "P",
7db35a48
PJ
1953 doc: /* Exit the Emacs job and kill it.
1954If ARG is an integer, return ARG as the exit program code.
1955If ARG is a string, stuff it as keyboard input.
1956
1957The value of `kill-emacs-hook', if not void,
1958is a list of functions (of no args),
1959all of which are called before Emacs is actually killed. */)
1960 (arg)
f927c5ae
JB
1961 Lisp_Object arg;
1962{
f927c5ae
JB
1963 struct gcpro gcpro1;
1964
1965 GCPRO1 (arg);
1966
1967 if (feof (stdin))
1968 arg = Qt;
1969
2447c626 1970 if (!NILP (Vrun_hooks) && !noninteractive)
f927c5ae
JB
1971 call1 (Vrun_hooks, intern ("kill-emacs-hook"));
1972
f927c5ae
JB
1973 UNGCPRO;
1974
1975/* Is it really necessary to do this deassign
1976 when we are going to exit anyway? */
1977/* #ifdef VMS
1978 stop_vms_input ();
1979 #endif */
40be253a 1980
d0068e25 1981 shut_down_emacs (0, 0, STRINGP (arg) ? arg : Qnil);
40be253a 1982
58545838
KH
1983 /* If we have an auto-save list file,
1984 kill it because we are exiting Emacs deliberately (not crashing).
1985 Do it after shut_down_emacs, which does an auto-save. */
1986 if (STRINGP (Vauto_save_list_file_name))
d5db4077 1987 unlink (SDATA (Vauto_save_list_file_name));
58545838 1988
55ccc0b3 1989 exit (INTEGERP (arg) ? XINT (arg)
f927c5ae
JB
1990#ifdef VMS
1991 : 1
1992#else
1993 : 0
1994#endif
1995 );
1996 /* NOTREACHED */
1997}
40be253a
JB
1998
1999
2000/* Perform an orderly shutdown of Emacs. Autosave any modified
2001 buffers, kill any child processes, clean up the terminal modes (if
2002 we're in the foreground), and other stuff like that. Don't perform
2003 any redisplay; this may be called when Emacs is shutting down in
2004 the background, or after its X connection has died.
2005
2006 If SIG is a signal number, print a message for it.
2007
2008 This is called by fatal signal handlers, X protocol error handlers,
2009 and Fkill_emacs. */
f7ab4e3d 2010
40be253a 2011void
f7ab4e3d 2012shut_down_emacs (sig, no_x, stuff)
41423a80 2013 int sig, no_x;
f7ab4e3d 2014 Lisp_Object stuff;
40be253a 2015{
829d872b
RS
2016 /* Prevent running of hooks from now on. */
2017 Vrun_hooks = Qnil;
2018
7db35a48 2019 /* If we are controlling the terminal, reset terminal modes. */
40be253a
JB
2020#ifdef EMACS_HAVE_TTY_PGRP
2021 {
d04d81d2
RS
2022 int pgrp = EMACS_GETPGRP (0);
2023
40be253a
JB
2024 int tpgrp;
2025 if (EMACS_GET_TTY_PGRP (0, &tpgrp) != -1
5a570e37 2026 && tpgrp == pgrp)
40be253a
JB
2027 {
2028 fflush (stdout);
2029 reset_sys_modes ();
2030 if (sig && sig != SIGTERM)
6b61353c 2031 fprintf (stderr, "Fatal error (%d)", sig);
40be253a
JB
2032 }
2033 }
2034#else
2035 fflush (stdout);
2036 reset_sys_modes ();
2037#endif
2038
f7ab4e3d
RS
2039 stuff_buffered_input (stuff);
2040
40be253a
JB
2041 kill_buffer_processes (Qnil);
2042 Fdo_auto_save (Qt, Qnil);
2043
2044#ifdef CLASH_DETECTION
2045 unlock_all_files ();
2046#endif
2047
2048#ifdef VMS
2049 kill_vms_processes ();
2050#endif
2051
5e7f8733 2052#if 0 /* This triggers a bug in XCloseDisplay and is not needed. */
41423a80 2053#ifdef HAVE_X_WINDOWS
f7511647
RS
2054 /* It's not safe to call intern here. Maybe we are crashing. */
2055 if (!noninteractive && SYMBOLP (Vwindow_system)
d5db4077
KR
2056 && SCHARS (SYMBOL_NAME (Vwindow_system)) == 1
2057 && SREF (SYMBOL_NAME (Vwindow_system), 0) == 'x'
f7511647 2058 && ! no_x)
41423a80
RS
2059 Fx_close_current_connection ();
2060#endif /* HAVE_X_WINDOWS */
5e7f8733 2061#endif
41423a80 2062
40be253a
JB
2063#ifdef SIGIO
2064 /* There is a tendency for a SIGIO signal to arrive within exit,
2065 and cause a SIGHUP because the input descriptor is already closed. */
2066 unrequest_sigio ();
2067 signal (SIGIO, SIG_IGN);
2068#endif
41f339d4
RS
2069
2070#ifdef WINDOWSNT
2071 term_ntproc ();
2072#endif
d546e578 2073
cd8d4168
GM
2074 /* Do this only if terminating normally, we want glyph matrices
2075 etc. in a core dump. */
200f868e 2076 if (sig == 0 || sig == SIGTERM)
cd8d4168
GM
2077 {
2078 check_glyph_memory ();
2079 check_message_stack ();
2080 }
90d920b6 2081
d546e578
EZ
2082#ifdef MSDOS
2083 dos_cleanup ();
2084#endif
40be253a
JB
2085}
2086
2087
f927c5ae
JB
2088\f
2089#ifndef CANNOT_DUMP
f927c5ae
JB
2090
2091#ifdef HAVE_SHM
2092
2093DEFUN ("dump-emacs-data", Fdump_emacs_data, Sdump_emacs_data, 1, 1, 0,
7db35a48
PJ
2094 doc: /* Dump current state of Emacs into data file FILENAME.
2095This function exists on systems that use HAVE_SHM. */)
2096 (filename)
c9aae259 2097 Lisp_Object filename;
f927c5ae 2098{
55697f5b 2099 extern char my_edata[];
f927c5ae 2100 Lisp_Object tem;
f927c5ae 2101
4fab758d 2102 check_pure_size ();
b7826503 2103 CHECK_STRING (filename);
c9aae259 2104 filename = Fexpand_file_name (filename, Qnil);
f927c5ae
JB
2105
2106 tem = Vpurify_flag;
2107 Vpurify_flag = Qnil;
2108
2109 fflush (stdout);
7db35a48 2110 /* Tell malloc where start of impure now is. */
f927c5ae
JB
2111 /* Also arrange for warnings when nearly out of space. */
2112#ifndef SYSTEM_MALLOC
1090a161 2113 memory_warnings (my_edata, malloc_warning);
f927c5ae 2114#endif
d5db4077 2115 map_out_data (SDATA (filename));
f927c5ae
JB
2116
2117 Vpurify_flag = tem;
2118
2119 return Qnil;
2120}
2121
2122#else /* not HAVE_SHM */
2123
2124DEFUN ("dump-emacs", Fdump_emacs, Sdump_emacs, 2, 2, 0,
7db35a48
PJ
2125 doc: /* Dump current state of Emacs into executable file FILENAME.
2126Take symbols from SYMFILE (presumably the file you executed to run Emacs).
2127This is used in the file `loadup.el' when building Emacs.
2128
2129You must run Emacs in batch mode in order to dump it. */)
2130 (filename, symfile)
c9aae259 2131 Lisp_Object filename, symfile;
f927c5ae 2132{
55697f5b 2133 extern char my_edata[];
f927c5ae 2134 Lisp_Object tem;
1b7ddf4f 2135 Lisp_Object symbol;
331379bf 2136 int count = SPECPDL_INDEX ();
4fab758d
GM
2137
2138 check_pure_size ();
f927c5ae 2139
87a98b1a
RS
2140 if (! noninteractive)
2141 error ("Dumping Emacs works only in batch mode");
2142
1b7ddf4f
RS
2143 /* Bind `command-line-processed' to nil before dumping,
2144 so that the dumped Emacs will process its command line
2145 and set up to work with X windows if appropriate. */
4aaa3607 2146 symbol = intern ("command-line-processed");
1b7ddf4f
RS
2147 specbind (symbol, Qnil);
2148
b7826503 2149 CHECK_STRING (filename);
c9aae259
EN
2150 filename = Fexpand_file_name (filename, Qnil);
2151 if (!NILP (symfile))
f927c5ae 2152 {
b7826503 2153 CHECK_STRING (symfile);
d5db4077 2154 if (SCHARS (symfile))
c9aae259 2155 symfile = Fexpand_file_name (symfile, Qnil);
f927c5ae
JB
2156 }
2157
2158 tem = Vpurify_flag;
2159 Vpurify_flag = Qnil;
2160
0269dedb
RS
2161#ifdef HAVE_TZSET
2162 set_time_zone_rule (dump_tz);
2163#ifndef LOCALTIME_CACHE
2164 /* Force a tz reload, since set_time_zone_rule doesn't. */
2165 tzset ();
2166#endif
2167#endif
2168
f927c5ae
JB
2169 fflush (stdout);
2170#ifdef VMS
d5db4077 2171 mapout_data (SDATA (filename));
f927c5ae 2172#else
7db35a48 2173 /* Tell malloc where start of impure now is. */
f927c5ae
JB
2174 /* Also arrange for warnings when nearly out of space. */
2175#ifndef SYSTEM_MALLOC
cc5f52cb
RS
2176#ifndef WINDOWSNT
2177 /* On Windows, this was done before dumping, and that once suffices.
2178 Meanwhile, my_edata is not valid on Windows. */
cb37cf78 2179 memory_warnings (my_edata, malloc_warning);
cc5f52cb 2180#endif /* not WINDOWSNT */
15aaf1b5
RS
2181#endif
2182#ifdef DOUG_LEA_MALLOC
2183 malloc_state_ptr = malloc_get_state ();
f927c5ae 2184#endif
2b7377ca 2185
a74c5ec1 2186#ifdef USE_MMAP_FOR_BUFFERS
2b7377ca
GM
2187 mmap_set_vars (0);
2188#endif
d5db4077
KR
2189 unexec (SDATA (filename),
2190 !NILP (symfile) ? SDATA (symfile) : 0, my_edata, 0, 0);
a74c5ec1 2191#ifdef USE_MMAP_FOR_BUFFERS
2b7377ca
GM
2192 mmap_set_vars (1);
2193#endif
15aaf1b5
RS
2194#ifdef DOUG_LEA_MALLOC
2195 free (malloc_state_ptr);
2196#endif
f927c5ae
JB
2197#endif /* not VMS */
2198
2199 Vpurify_flag = tem;
2200
1b7ddf4f 2201 return unbind_to (count, Qnil);
f927c5ae
JB
2202}
2203
2204#endif /* not HAVE_SHM */
2205
2206#endif /* not CANNOT_DUMP */
2207\f
68c45bf0
PE
2208#if HAVE_SETLOCALE
2209/* Recover from setlocale (LC_ALL, ""). */
2210void
2211fixup_locale ()
2212{
68c45bf0
PE
2213 /* The Emacs Lisp reader needs LC_NUMERIC to be "C",
2214 so that numbers are read and printed properly for Emacs Lisp. */
2215 setlocale (LC_NUMERIC, "C");
68c45bf0
PE
2216}
2217
0c8559bb
PE
2218/* Set system locale CATEGORY, with previous locale *PLOCALE, to
2219 DESIRED_LOCALE. */
68c45bf0
PE
2220static void
2221synchronize_locale (category, plocale, desired_locale)
2222 int category;
2223 Lisp_Object *plocale;
2224 Lisp_Object desired_locale;
2225{
0c8559bb
PE
2226 if (! EQ (*plocale, desired_locale))
2227 {
2228 *plocale = desired_locale;
2229 setlocale (category, (STRINGP (desired_locale)
d5db4077 2230 ? (char *)(SDATA (desired_locale))
0c8559bb
PE
2231 : ""));
2232 }
68c45bf0
PE
2233}
2234
ca9c0567 2235/* Set system time locale to match Vsystem_time_locale, if possible. */
68c45bf0 2236void
ca9c0567 2237synchronize_system_time_locale ()
68c45bf0 2238{
ca9c0567
PE
2239 synchronize_locale (LC_TIME, &Vprevious_system_time_locale,
2240 Vsystem_time_locale);
68c45bf0
PE
2241}
2242
ca9c0567
PE
2243/* Set system messages locale to match Vsystem_messages_locale, if
2244 possible. */
68c45bf0 2245void
ca9c0567 2246synchronize_system_messages_locale ()
68c45bf0
PE
2247{
2248#ifdef LC_MESSAGES
ca9c0567
PE
2249 synchronize_locale (LC_MESSAGES, &Vprevious_system_messages_locale,
2250 Vsystem_messages_locale);
68c45bf0
PE
2251#endif
2252}
2253#endif /* HAVE_SETLOCALE */
2254\f
4b163808 2255#ifndef SEPCHAR
f927c5ae
JB
2256#define SEPCHAR ':'
2257#endif
2258
2259Lisp_Object
2260decode_env_path (evarname, defalt)
2261 char *evarname, *defalt;
2262{
2263 register char *path, *p;
213d0b1f 2264 Lisp_Object lpath, element, tem;
f927c5ae 2265
2447c626
JB
2266 /* It's okay to use getenv here, because this function is only used
2267 to initialize variables when Emacs starts up, and isn't called
2268 after that. */
e065a56e
JB
2269 if (evarname != 0)
2270 path = (char *) getenv (evarname);
2271 else
2272 path = 0;
f927c5ae
JB
2273 if (!path)
2274 path = defalt;
6a30e6d6
RS
2275#ifdef DOS_NT
2276 /* Ensure values from the environment use the proper directory separator. */
2277 if (path)
2278 {
2279 p = alloca (strlen (path) + 1);
2280 strcpy (p, path);
2281 path = p;
2282
2283 if ('/' == DIRECTORY_SEP)
2284 dostounix_filename (path);
2285 else
2286 unixtodos_filename (path);
2287 }
2288#endif
f927c5ae
JB
2289 lpath = Qnil;
2290 while (1)
2291 {
2292 p = index (path, SEPCHAR);
2293 if (!p) p = path + strlen (path);
213d0b1f
RS
2294 element = (p - path ? make_string (path, p - path)
2295 : build_string ("."));
2296
2297 /* Add /: to the front of the name
2298 if it would otherwise be treated as magic. */
2299 tem = Ffind_file_name_handler (element, Qt);
ca3df2d5
RS
2300
2301 /* However, if the handler says "I'm safe",
2302 don't bother adding /:. */
2303 if (SYMBOLP (tem))
2304 {
2305 Lisp_Object prop;
2306 prop = Fget (tem, intern ("safe-magic"));
2307 if (! NILP (prop))
2308 tem = Qnil;
2309 }
2310
213d0b1f
RS
2311 if (! NILP (tem))
2312 element = concat2 (build_string ("/:"), element);
2313
2314 lpath = Fcons (element, lpath);
f927c5ae
JB
2315 if (*p)
2316 path = p + 1;
2317 else
2318 break;
2319 }
2320 return Fnreverse (lpath);
2321}
2322
dfcf069d 2323void
f927c5ae
JB
2324syms_of_emacs ()
2325{
213d0b1f
RS
2326 Qfile_name_handler_alist = intern ("file-name-handler-alist");
2327 staticpro (&Qfile_name_handler_alist);
2328
83591e66 2329#ifndef CANNOT_DUMP
f927c5ae
JB
2330#ifdef HAVE_SHM
2331 defsubr (&Sdump_emacs_data);
2332#else
2333 defsubr (&Sdump_emacs);
83591e66 2334#endif
f927c5ae
JB
2335#endif
2336
2337 defsubr (&Skill_emacs);
2338
59653951 2339 defsubr (&Sinvocation_name);
ace40a69 2340 defsubr (&Sinvocation_directory);
59653951 2341
f927c5ae 2342 DEFVAR_LISP ("command-line-args", &Vcommand_line_args,
2a9d2ed6
RS
2343 doc: /* Args passed by shell to Emacs, as a list of strings.
2344Many arguments are deleted from the list as they are processed. */);
f927c5ae
JB
2345
2346 DEFVAR_LISP ("system-type", &Vsystem_type,
7db35a48 2347 doc: /* Value is symbol indicating type of operating system you are using. */);
f927c5ae
JB
2348 Vsystem_type = intern (SYSTEM_TYPE);
2349
271c7b7c 2350 DEFVAR_LISP ("system-configuration", &Vsystem_configuration,
7db35a48
PJ
2351 doc: /* Value is string indicating configuration Emacs was built for.
2352On MS-Windows, the value reflects the OS flavor and version on which
2353Emacs is running. */);
f7511647 2354 Vsystem_configuration = build_string (EMACS_CONFIGURATION);
271c7b7c 2355
f0fc0b1a 2356 DEFVAR_LISP ("system-configuration-options", &Vsystem_configuration_options,
7db35a48 2357 doc: /* String containing the configuration options Emacs was built with. */);
f0fc0b1a
KH
2358 Vsystem_configuration_options = build_string (EMACS_CONFIG_OPTIONS);
2359
f927c5ae 2360 DEFVAR_BOOL ("noninteractive", &noninteractive1,
7db35a48 2361 doc: /* Non-nil means Emacs is running without interactive terminal. */);
e5d77022 2362
e5d77022 2363 DEFVAR_LISP ("kill-emacs-hook", &Vkill_emacs_hook,
d77b70e5
MR
2364 doc: /* Hook to be run when kill-emacs is called.
2365Since `kill-emacs' may be invoked when the terminal is disconnected (or
7db35a48
PJ
2366in other similar situations), functions placed on this hook should not
2367expect to be able to interact with the user. To ask for confirmation,
d77b70e5
MR
2368see `kill-emacs-query-functions' instead.
2369
2370The hook is not run in batch mode, i.e., if `noninteractive' is non-nil. */);
edc8ae07 2371 Vkill_emacs_hook = Qnil;
3005da00 2372
f9a6326d
SM
2373 empty_string = build_string ("");
2374 staticpro (&empty_string);
2375
7317d9e8
RS
2376#ifdef SIGUSR1
2377 DEFVAR_LISP ("signal-USR1-hook", &Vsignal_USR1_hook,
7db35a48 2378 doc: /* Hook to be run whenever emacs receives a USR1 signal. */);
7317d9e8
RS
2379 Vsignal_USR1_hook = Qnil;
2380#ifdef SIGUSR2
2381 DEFVAR_LISP ("signal-USR2-hook", &Vsignal_USR2_hook,
7db35a48 2382 doc: /* Hook to be run whenever emacs receives a USR2 signal. */);
7317d9e8
RS
2383 Vsignal_USR2_hook = Qnil;
2384#endif
2385#endif
2386
2387
3005da00 2388 DEFVAR_INT ("emacs-priority", &emacs_priority,
7db35a48
PJ
2389 doc: /* Priority for Emacs to run at.
2390This value is effective only if set before Emacs is dumped,
2391and only if the Emacs executable is installed with setuid to permit
2392it to change priority. (Emacs sets its uid back to the real uid.)
2393Currently, you need to define SET_EMACS_PRIORITY in `config.h'
2394before you compile Emacs, to enable the code for this feature. */);
e7a9e1c3 2395 emacs_priority = 0;
074a066b
GV
2396
2397 DEFVAR_LISP ("path-separator", &Vpath_separator,
ddb67bdc 2398 doc: /* The directory separator in search paths, as a string. */);
074a066b
GV
2399 {
2400 char c = SEPCHAR;
2401 Vpath_separator = make_string (&c, 1);
2402 }
59653951 2403
f67de86f 2404 DEFVAR_LISP ("invocation-name", &Vinvocation_name,
7db35a48
PJ
2405 doc: /* The program name that was used to run Emacs.
2406Any directory names are omitted. */);
f67de86f
RS
2407
2408 DEFVAR_LISP ("invocation-directory", &Vinvocation_directory,
7db35a48
PJ
2409 doc: /* The directory in which the Emacs executable was found, to run it.
2410The value is nil if that directory's name is not known. */);
f67de86f
RS
2411
2412 DEFVAR_LISP ("installation-directory", &Vinstallation_directory,
7db35a48
PJ
2413 doc: /* A directory within which to look for the `lib-src' and `etc' directories.
2414This is non-nil when we can't find those directories in their standard
2415installed locations, but we can find them
2416near where the Emacs executable was found. */);
07f4d123 2417 Vinstallation_directory = Qnil;
68c45bf0 2418
ca9c0567 2419 DEFVAR_LISP ("system-messages-locale", &Vsystem_messages_locale,
7db35a48 2420 doc: /* System locale for messages. */);
ca9c0567 2421 Vsystem_messages_locale = Qnil;
68c45bf0 2422
ca9c0567 2423 DEFVAR_LISP ("previous-system-messages-locale",
7db35a48
PJ
2424 &Vprevious_system_messages_locale,
2425 doc: /* Most recently used system locale for messages. */);
ca9c0567 2426 Vprevious_system_messages_locale = Qnil;
68c45bf0 2427
ca9c0567 2428 DEFVAR_LISP ("system-time-locale", &Vsystem_time_locale,
7db35a48 2429 doc: /* System locale for time. */);
ca9c0567 2430 Vsystem_time_locale = Qnil;
68c45bf0 2431
ca9c0567 2432 DEFVAR_LISP ("previous-system-time-locale", &Vprevious_system_time_locale,
7db35a48 2433 doc: /* Most recently used system locale for time. */);
ca9c0567 2434 Vprevious_system_time_locale = Qnil;
f927c5ae 2435}
6b61353c
KH
2436
2437/* arch-tag: 7bfd356a-c720-4612-8ab6-aa4222931c2e
2438 (do not change this comment) */