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