Commit | Line | Data |
---|---|---|
f927c5ae JB |
1 | /* Fully extensible Emacs, running on Unix, intended for GNU. |
2 | Copyright (C) 1985, 1986, 1987 Free Software Foundation, Inc. | |
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 | |
8 | the Free Software Foundation; either version 1, or (at your option) | |
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 | |
18 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
19 | ||
20 | ||
21 | #include <signal.h> | |
22 | #include <errno.h> | |
23 | ||
24 | #include "config.h" | |
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 | ||
34 | #ifdef USG5 | |
35 | #include <fcntl.h> | |
36 | #endif | |
37 | ||
38 | #ifdef BSD | |
39 | #include <sys/ioctl.h> | |
40 | #endif | |
41 | ||
2447c626 JB |
42 | #ifdef HAVE_TERMIOS |
43 | #include <termios.h> | |
44 | #endif | |
45 | ||
f927c5ae JB |
46 | #ifdef APOLLO |
47 | #ifndef APOLLO_SR10 | |
48 | #include <default_acl.h> | |
49 | #endif | |
50 | #endif | |
51 | ||
f927c5ae JB |
52 | #include "lisp.h" |
53 | #include "commands.h" | |
54 | ||
a41f8bed JB |
55 | #include "systerm.h" |
56 | ||
f927c5ae JB |
57 | #ifndef O_RDWR |
58 | #define O_RDWR 2 | |
59 | #endif | |
60 | ||
61 | #define PRIO_PROCESS 0 | |
62 | ||
63 | /* Command line args from shell, as list of strings */ | |
64 | Lisp_Object Vcommand_line_args; | |
65 | ||
66 | /* Set nonzero after Emacs has started up the first time. | |
67 | Prevents reinitialization of the Lisp world and keymaps | |
68 | on subsequent starts. */ | |
69 | int initialized; | |
70 | ||
71 | /* Variable whose value is symbol giving operating system type */ | |
72 | Lisp_Object Vsystem_type; | |
73 | ||
74 | /* If non-zero, emacs should not attempt to use an window-specific code, | |
75 | but instead should use the virtual terminal under which it was started */ | |
76 | int inhibit_window_system; | |
77 | ||
78 | #ifdef HAVE_X_WINDOWS | |
79 | /* If non-zero, -d was specified, meaning we're using some window system. */ | |
80 | int display_arg; | |
81 | #endif | |
82 | ||
83 | /* An address near the bottom of the stack. | |
84 | Tells GC how to save a copy of the stack. */ | |
85 | char *stack_bottom; | |
86 | ||
87 | #ifdef HAVE_X_WINDOWS | |
88 | extern Lisp_Object Vwindow_system; | |
89 | #endif /* HAVE_X_WINDOWS */ | |
90 | ||
91 | #ifdef USG_SHARED_LIBRARIES | |
92 | /* If nonzero, this is the place to put the end of the writable segment | |
93 | at startup. */ | |
94 | ||
95 | unsigned int bss_end = 0; | |
96 | #endif | |
97 | ||
98 | /* Nonzero means running Emacs without interactive terminal. */ | |
99 | ||
100 | int noninteractive; | |
101 | ||
102 | /* Value of Lisp variable `noninteractive'. | |
103 | Normally same as C variable `noninteractive' | |
104 | but nothing terrible happens if user sets this one. */ | |
105 | ||
106 | int noninteractive1; | |
107 | \f | |
108 | /* Signal code for the fatal signal that was received */ | |
109 | int fatal_error_code; | |
110 | ||
111 | /* Nonzero if handling a fatal error already */ | |
112 | int fatal_error_in_progress; | |
113 | ||
114 | /* Handle bus errors, illegal instruction, etc. */ | |
2447c626 | 115 | SIGTYPE |
f927c5ae JB |
116 | fatal_error_signal (sig) |
117 | int sig; | |
118 | { | |
f927c5ae JB |
119 | fatal_error_code = sig; |
120 | signal (sig, SIG_DFL); | |
121 | ||
122 | /* If fatal error occurs in code below, avoid infinite recursion. */ | |
123 | if (fatal_error_in_progress) | |
124 | kill (getpid (), fatal_error_code); | |
125 | ||
126 | fatal_error_in_progress = 1; | |
127 | ||
128 | /* If we are controlling the terminal, reset terminal modes */ | |
a41f8bed | 129 | #ifdef EMACS_HAVE_TTY_PGRP |
2447c626 JB |
130 | { |
131 | int tpgrp; | |
a41f8bed | 132 | if (EMACS_GET_TTY_PGRP (0, &tpgrp) != -1 |
2447c626 JB |
133 | && tpgrp == getpgrp (0)) |
134 | { | |
135 | reset_sys_modes (); | |
136 | if (sig != SIGTERM) | |
137 | fprintf (stderr, "Fatal error (%d).", sig); | |
138 | } | |
139 | } | |
140 | #endif /* uses pgrp */ | |
f927c5ae JB |
141 | |
142 | /* Clean up */ | |
143 | #ifdef subprocesses | |
144 | kill_buffer_processes (Qnil); | |
145 | #endif | |
146 | Fdo_auto_save (Qt, Qnil); | |
147 | ||
148 | #ifdef CLASH_DETECTION | |
149 | unlock_all_files (); | |
150 | #endif /* CLASH_DETECTION */ | |
151 | ||
152 | #ifdef VMS | |
153 | kill_vms_processes (); | |
154 | LIB$STOP (SS$_ABORT); | |
155 | #else | |
156 | /* Signal the same code; this time it will really be fatal. */ | |
157 | kill (getpid (), fatal_error_code); | |
158 | #endif /* not VMS */ | |
159 | } | |
160 | \f | |
161 | /* Code for dealing with Lisp access to the Unix command line */ | |
162 | ||
163 | static | |
164 | init_cmdargs (argc, argv, skip_args) | |
165 | int argc; | |
166 | char **argv; | |
167 | int skip_args; | |
168 | { | |
169 | register int i; | |
170 | ||
171 | Vcommand_line_args = Qnil; | |
172 | ||
173 | for (i = argc - 1; i >= 0; i--) | |
174 | { | |
175 | if (i == 0 || i > skip_args) | |
176 | Vcommand_line_args | |
177 | = Fcons (build_string (argv[i]), Vcommand_line_args); | |
178 | } | |
179 | } | |
180 | \f | |
181 | #ifdef VMS | |
182 | #ifdef LINK_CRTL_SHARE | |
183 | #ifdef SHAREABLE_LIB_BUG | |
184 | extern noshare char **environ; | |
185 | #endif /* SHAREABLE_LIB_BUG */ | |
186 | #endif /* LINK_CRTL_SHARE */ | |
187 | #endif /* VMS */ | |
188 | ||
189 | /* ARGSUSED */ | |
190 | main (argc, argv, envp) | |
191 | int argc; | |
192 | char **argv; | |
193 | char **envp; | |
194 | { | |
195 | char stack_bottom_variable; | |
196 | int skip_args = 0; | |
197 | extern int errno; | |
198 | extern sys_nerr; | |
199 | extern char *sys_errlist[]; | |
200 | extern void malloc_warning (); | |
201 | ||
202 | /* Map in shared memory, if we are using that. */ | |
203 | #ifdef HAVE_SHM | |
204 | if (argc > 1 && !strcmp (argv[1], "-nl")) | |
205 | { | |
206 | map_in_data (0); | |
207 | /* The shared memory was just restored, which clobbered this. */ | |
208 | skip_args = 1; | |
209 | } | |
210 | else | |
211 | { | |
212 | map_in_data (1); | |
213 | /* The shared memory was just restored, which clobbered this. */ | |
214 | skip_args = 0; | |
215 | } | |
216 | #endif | |
217 | ||
218 | #ifdef HAVE_X_WINDOWS | |
fb8e9847 JB |
219 | /* Stupid kludge to catch command-line display spec. We can't |
220 | handle this argument entirely in window system dependent code | |
221 | because we don't even know which window system dependent code | |
222 | to run until we've recognized this argument. */ | |
f927c5ae JB |
223 | { |
224 | int i; | |
225 | ||
226 | for (i = 1; (i < argc && ! display_arg); i++) | |
227 | if (!strcmp (argv[i], "-d")) | |
228 | display_arg = 1; | |
229 | } | |
230 | #endif | |
231 | ||
232 | #ifdef VMS | |
233 | /* If -map specified, map the data file in */ | |
234 | if (argc > 2 && ! strcmp (argv[1], "-map")) | |
235 | { | |
236 | skip_args = 2; | |
237 | mapin_data (argv[2]); | |
238 | } | |
239 | ||
240 | #ifdef LINK_CRTL_SHARE | |
241 | #ifdef SHAREABLE_LIB_BUG | |
242 | /* Bletcherous shared libraries! */ | |
243 | if (!stdin) | |
244 | stdin = fdopen (0, "r"); | |
245 | if (!stdout) | |
246 | stdout = fdopen (1, "w"); | |
247 | if (!stderr) | |
248 | stderr = fdopen (2, "w"); | |
249 | if (!environ) | |
250 | environ = envp; | |
251 | #endif /* SHAREABLE_LIB_BUG */ | |
252 | #endif /* LINK_CRTL_SHARE */ | |
253 | #endif /* VMS */ | |
254 | ||
255 | /* Record (approximately) where the stack begins. */ | |
256 | stack_bottom = &stack_bottom_variable; | |
257 | ||
258 | #ifdef RUN_TIME_REMAP | |
259 | if (initialized) | |
260 | run_time_remap (argv[0]); | |
261 | #endif | |
262 | ||
263 | #ifdef USG_SHARED_LIBRARIES | |
264 | if (bss_end) | |
265 | brk (bss_end); | |
266 | #endif | |
267 | ||
268 | clearerr (stdin); | |
269 | #ifdef BSD | |
270 | setpgrp (0, getpid ()); | |
271 | #endif | |
272 | ||
273 | #ifdef APOLLO | |
274 | #ifndef APOLLO_SR10 | |
275 | /* If USE_DOMAIN_ACLS environment variable exists, | |
276 | use ACLs rather than UNIX modes. */ | |
277 | if (egetenv ("USE_DOMAIN_ACLS")) | |
278 | default_acl (USE_DEFACL); | |
279 | #endif | |
280 | #endif /* APOLLO */ | |
281 | ||
282 | #ifndef SYSTEM_MALLOC | |
283 | if (! initialized) | |
284 | malloc_init (0, malloc_warning); | |
285 | #endif /* not SYSTEM_MALLOC */ | |
286 | ||
287 | #ifdef HIGHPRI | |
288 | setpriority (PRIO_PROCESS, getpid (), HIGHPRI); | |
289 | setuid (getuid ()); | |
290 | #endif /* HIGHPRI */ | |
291 | ||
292 | #ifdef BSD | |
293 | /* interrupt_input has trouble if we aren't in a separate process group. */ | |
294 | setpgrp (getpid (), getpid ()); | |
295 | #endif | |
296 | ||
297 | inhibit_window_system = 0; | |
298 | ||
4fc0b45b | 299 | /* Handle the -t switch, which specifies filename to use as terminal */ |
f927c5ae JB |
300 | if (skip_args + 2 < argc && !strcmp (argv[skip_args + 1], "-t")) |
301 | { | |
302 | int result; | |
303 | skip_args += 2; | |
304 | close (0); | |
305 | close (1); | |
306 | result = open (argv[skip_args], O_RDWR, 2 ); | |
307 | if (result < 0) | |
308 | { | |
309 | char *errstring; | |
310 | ||
311 | if (errno >= 0 && errno < sys_nerr) | |
312 | errstring = sys_errlist[errno]; | |
313 | else | |
314 | errstring = "undocumented error code"; | |
315 | fprintf (stderr, "emacs: %s: %s\n", argv[skip_args], errstring); | |
316 | exit (1); | |
317 | } | |
318 | dup (0); | |
319 | if (! isatty (0)) | |
320 | { | |
321 | fprintf (stderr, "emacs: %s: not a tty\n", argv[skip_args]); | |
322 | exit (1); | |
323 | } | |
324 | fprintf (stderr, "Using %s\n", argv[skip_args]); | |
325 | #ifdef HAVE_X_WINDOWS | |
326 | inhibit_window_system = 1; /* -t => -nw */ | |
327 | #endif | |
328 | } | |
329 | ||
330 | if (skip_args + 1 < argc | |
331 | && (!strcmp (argv[skip_args + 1], "-nw"))) | |
332 | { | |
333 | skip_args += 1; | |
334 | inhibit_window_system = 1; | |
335 | } | |
336 | ||
337 | /* Handle the -batch switch, which means don't do interactive display. */ | |
338 | noninteractive = 0; | |
339 | if (skip_args + 1 < argc && !strcmp (argv[skip_args + 1], "-batch")) | |
340 | { | |
341 | skip_args += 1; | |
342 | noninteractive = 1; | |
343 | } | |
344 | ||
fb8e9847 JB |
345 | #ifdef POSIX_SIGNALS |
346 | init_signals (); | |
347 | #endif | |
348 | ||
f927c5ae JB |
349 | if ( |
350 | #ifndef CANNOT_DUMP | |
351 | ! noninteractive || initialized | |
352 | #else | |
353 | 1 | |
354 | #endif | |
355 | ) | |
356 | { | |
357 | /* Don't catch these signals in batch mode if not initialized. | |
358 | On some machines, this sets static data that would make | |
359 | signal fail to work right when the dumped Emacs is run. */ | |
360 | signal (SIGHUP, fatal_error_signal); | |
361 | signal (SIGQUIT, fatal_error_signal); | |
362 | signal (SIGILL, fatal_error_signal); | |
363 | signal (SIGTRAP, fatal_error_signal); | |
364 | signal (SIGIOT, fatal_error_signal); | |
365 | #ifdef SIGEMT | |
366 | signal (SIGEMT, fatal_error_signal); | |
367 | #endif | |
368 | signal (SIGFPE, fatal_error_signal); | |
369 | signal (SIGBUS, fatal_error_signal); | |
370 | signal (SIGSEGV, fatal_error_signal); | |
371 | signal (SIGSYS, fatal_error_signal); | |
372 | signal (SIGTERM, fatal_error_signal); | |
373 | #ifdef SIGXCPU | |
374 | signal (SIGXCPU, fatal_error_signal); | |
375 | #endif | |
376 | #ifdef SIGXFSZ | |
377 | signal (SIGXFSZ, fatal_error_signal); | |
378 | #endif /* SIGXFSZ */ | |
379 | ||
380 | #ifdef AIX | |
381 | signal (SIGDANGER, fatal_error_signal); | |
382 | signal (20, fatal_error_signal); | |
383 | signal (21, fatal_error_signal); | |
384 | signal (22, fatal_error_signal); | |
385 | signal (23, fatal_error_signal); | |
386 | signal (24, fatal_error_signal); | |
bfb61299 | 387 | #ifdef SIGIO |
f927c5ae JB |
388 | signal (SIGAIO, fatal_error_signal); |
389 | signal (SIGPTY, fatal_error_signal); | |
bfb61299 | 390 | #endif |
f927c5ae JB |
391 | signal (SIGIOINT, fatal_error_signal); |
392 | signal (SIGGRANT, fatal_error_signal); | |
393 | signal (SIGRETRACT, fatal_error_signal); | |
394 | signal (SIGSOUND, fatal_error_signal); | |
395 | signal (SIGMSG, fatal_error_signal); | |
396 | #endif /* AIX */ | |
397 | } | |
398 | ||
399 | noninteractive1 = noninteractive; | |
400 | ||
401 | /* Perform basic initializations (not merely interning symbols) */ | |
402 | ||
403 | if (!initialized) | |
404 | { | |
405 | init_alloc_once (); | |
406 | init_obarray (); | |
407 | init_eval_once (); | |
408 | init_syntax_once (); /* Create standard syntax table. */ | |
409 | /* Must be done before init_buffer */ | |
410 | init_casetab_once (); | |
411 | init_buffer_once (); /* Create buffer table and some buffers */ | |
412 | init_minibuf_once (); /* Create list of minibuffers */ | |
413 | /* Must precede init_window_once */ | |
414 | init_window_once (); /* Init the window system */ | |
415 | } | |
416 | ||
417 | init_alloc (); | |
f927c5ae JB |
418 | init_eval (); |
419 | init_data (); | |
fb8e9847 | 420 | init_lread (); |
f927c5ae JB |
421 | |
422 | init_cmdargs (argc, argv, skip_args); /* Create list Vcommand_line_args */ | |
423 | init_buffer (); /* Init default directory of main buffer */ | |
424 | if (!noninteractive) | |
425 | { | |
426 | #ifdef VMS | |
427 | init_vms_input ();/* init_display calls get_screen_size, that needs this */ | |
428 | #endif /* VMS */ | |
429 | init_display (); /* Determine terminal type. init_sys_modes uses results */ | |
430 | } | |
431 | init_keyboard (); /* This too must precede init_sys_modes */ | |
432 | init_callproc (); /* And this too. */ | |
433 | #ifdef VMS | |
434 | init_vmsproc (); /* And this too. */ | |
435 | #endif /* VMS */ | |
436 | init_sys_modes (); /* Init system terminal modes (RAW or CBREAK, etc.) */ | |
437 | init_xdisp (); | |
438 | init_macros (); | |
439 | init_editfns (); | |
440 | #ifdef LISP_FLOAT_TYPE | |
441 | init_floatfns (); | |
442 | #endif | |
443 | #ifdef VMS | |
444 | init_vmsfns (); | |
445 | #endif /* VMS */ | |
446 | #ifdef subprocesses | |
447 | init_process (); | |
448 | #endif /* subprocesses */ | |
449 | ||
450 | /* Intern the names of all standard functions and variables; define standard keys */ | |
451 | ||
452 | if (!initialized) | |
453 | { | |
454 | /* The basic levels of Lisp must come first */ | |
455 | /* And data must come first of all | |
456 | for the sake of symbols like error-message */ | |
457 | syms_of_data (); | |
458 | syms_of_alloc (); | |
fb8e9847 | 459 | syms_of_lread (); |
f927c5ae JB |
460 | syms_of_print (); |
461 | syms_of_eval (); | |
462 | syms_of_fns (); | |
463 | #ifdef LISP_FLOAT_TYPE | |
464 | syms_of_floatfns (); | |
465 | #endif | |
466 | ||
467 | syms_of_abbrev (); | |
468 | syms_of_buffer (); | |
469 | syms_of_bytecode (); | |
470 | syms_of_callint (); | |
471 | syms_of_casefiddle (); | |
472 | syms_of_casetab (); | |
473 | syms_of_callproc (); | |
474 | syms_of_cmds (); | |
475 | #ifndef NO_DIR_LIBRARY | |
476 | syms_of_dired (); | |
477 | #endif /* not NO_DIR_LIBRARY */ | |
478 | syms_of_display (); | |
479 | syms_of_doc (); | |
480 | syms_of_editfns (); | |
481 | syms_of_emacs (); | |
482 | syms_of_fileio (); | |
483 | #ifdef CLASH_DETECTION | |
484 | syms_of_filelock (); | |
485 | #endif /* CLASH_DETECTION */ | |
486 | syms_of_indent (); | |
487 | syms_of_keyboard (); | |
488 | syms_of_keymap (); | |
489 | syms_of_macros (); | |
490 | syms_of_marker (); | |
491 | syms_of_minibuf (); | |
492 | syms_of_mocklisp (); | |
493 | #ifdef subprocesses | |
494 | syms_of_process (); | |
495 | #endif /* subprocesses */ | |
496 | syms_of_search (); | |
497 | #ifdef MULTI_SCREEN | |
498 | syms_of_screen (); | |
499 | #endif | |
500 | syms_of_syntax (); | |
501 | syms_of_undo (); | |
502 | #ifdef VMS | |
503 | syms_of_vmsproc (); | |
504 | #endif /* VMS */ | |
505 | syms_of_window (); | |
506 | syms_of_xdisp (); | |
507 | #ifdef HAVE_X_WINDOWS | |
72412588 | 508 | syms_of_xterm (); |
f927c5ae | 509 | syms_of_xfns (); |
72412588 JB |
510 | #ifdef HAVE_X11 |
511 | syms_of_xselect (); | |
512 | #endif | |
f927c5ae JB |
513 | #ifdef HAVE_X_MENU |
514 | syms_of_xmenu (); | |
515 | #endif /* HAVE_X_MENU */ | |
516 | #endif /* HAVE_X_WINDOWS */ | |
517 | ||
518 | #ifdef SYMS_SYSTEM | |
519 | SYMS_SYSTEM; | |
520 | #endif | |
521 | ||
522 | #ifdef SYMS_MACHINE | |
523 | SYMS_MACHINE; | |
524 | #endif | |
525 | ||
526 | keys_of_casefiddle (); | |
527 | keys_of_cmds (); | |
528 | keys_of_buffer (); | |
529 | keys_of_keyboard (); | |
530 | keys_of_keymap (); | |
531 | keys_of_macros (); | |
532 | keys_of_minibuf (); | |
533 | keys_of_window (); | |
534 | } | |
535 | ||
536 | if (!initialized) | |
537 | { | |
538 | /* Handle -l loadup-and-dump, args passed by Makefile. */ | |
539 | if (argc > 2 + skip_args && !strcmp (argv[1 + skip_args], "-l")) | |
540 | Vtop_level = Fcons (intern ("load"), | |
541 | Fcons (build_string (argv[2 + skip_args]), Qnil)); | |
542 | #ifdef CANNOT_DUMP | |
543 | /* Unless next switch is -nl, load "loadup.el" first thing. */ | |
544 | if (!(argc > 1 + skip_args && !strcmp (argv[1 + skip_args], "-nl"))) | |
545 | Vtop_level = Fcons (intern ("load"), | |
546 | Fcons (build_string ("loadup.el"), Qnil)); | |
547 | #endif /* CANNOT_DUMP */ | |
548 | } | |
549 | ||
550 | initialized = 1; | |
551 | ||
552 | /* Enter editor command loop. This never returns. */ | |
553 | Frecursive_edit (); | |
554 | /* NOTREACHED */ | |
555 | } | |
556 | \f | |
557 | DEFUN ("kill-emacs", Fkill_emacs, Skill_emacs, 0, 1, "P", | |
558 | "Exit the Emacs job and kill it. Ask for confirmation, without argument.\n\ | |
559 | If ARG is an integer, return ARG as the exit program code.\n\ | |
560 | If ARG is a string, stuff it as keyboard input.\n\n\ | |
561 | The value of `kill-emacs-hook', if not void,\n\ | |
562 | is a list of functions (of no args),\n\ | |
563 | all of which are called before Emacs is actually killed.") | |
564 | (arg) | |
565 | Lisp_Object arg; | |
566 | { | |
567 | Lisp_Object hook, hook1; | |
568 | int i; | |
569 | struct gcpro gcpro1; | |
570 | ||
571 | GCPRO1 (arg); | |
572 | ||
573 | if (feof (stdin)) | |
574 | arg = Qt; | |
575 | ||
2447c626 | 576 | if (!NILP (Vrun_hooks) && !noninteractive) |
f927c5ae JB |
577 | call1 (Vrun_hooks, intern ("kill-emacs-hook")); |
578 | ||
579 | #ifdef subprocesses | |
580 | kill_buffer_processes (Qnil); | |
581 | #endif /* subprocesses */ | |
582 | ||
583 | #ifdef VMS | |
584 | kill_vms_processes (); | |
585 | #endif /* VMS */ | |
586 | ||
587 | Fdo_auto_save (Qt, Qnil); | |
588 | ||
589 | #ifdef CLASH_DETECTION | |
590 | unlock_all_files (); | |
591 | #endif /* CLASH_DETECTION */ | |
592 | ||
593 | fflush (stdout); | |
594 | reset_sys_modes (); | |
595 | ||
596 | #ifdef HAVE_X_WINDOWS | |
597 | if (!noninteractive && EQ (Vwindow_system, intern ("x"))) | |
598 | Fx_close_current_connection (); | |
599 | #endif /* HAVE_X_WINDOWS */ | |
600 | ||
601 | UNGCPRO; | |
602 | ||
603 | /* Is it really necessary to do this deassign | |
604 | when we are going to exit anyway? */ | |
605 | /* #ifdef VMS | |
606 | stop_vms_input (); | |
607 | #endif */ | |
608 | stuff_buffered_input (arg); | |
609 | #ifdef SIGIO | |
610 | /* There is a tendency for a SIGIO signal to arrive within exit, | |
611 | and cause a SIGHUP because the input descriptor is already closed. */ | |
612 | unrequest_sigio (); | |
613 | signal (SIGIO, SIG_IGN); | |
614 | #endif | |
615 | exit ((XTYPE (arg) == Lisp_Int) ? XINT (arg) | |
616 | #ifdef VMS | |
617 | : 1 | |
618 | #else | |
619 | : 0 | |
620 | #endif | |
621 | ); | |
622 | /* NOTREACHED */ | |
623 | } | |
624 | \f | |
625 | #ifndef CANNOT_DUMP | |
626 | /* Nothing like this can be implemented on an Apollo. | |
627 | What a loss! */ | |
628 | ||
629 | #ifdef HAVE_SHM | |
630 | ||
631 | DEFUN ("dump-emacs-data", Fdump_emacs_data, Sdump_emacs_data, 1, 1, 0, | |
632 | "Dump current state of Emacs into data file FILENAME.\n\ | |
633 | This function exists on systems that use HAVE_SHM.") | |
634 | (intoname) | |
635 | Lisp_Object intoname; | |
636 | { | |
637 | extern int my_edata; | |
638 | Lisp_Object tem; | |
639 | extern void malloc_warning (); | |
640 | ||
641 | CHECK_STRING (intoname, 0); | |
642 | intoname = Fexpand_file_name (intoname, Qnil); | |
643 | ||
644 | tem = Vpurify_flag; | |
645 | Vpurify_flag = Qnil; | |
646 | ||
647 | fflush (stdout); | |
648 | /* Tell malloc where start of impure now is */ | |
649 | /* Also arrange for warnings when nearly out of space. */ | |
650 | #ifndef SYSTEM_MALLOC | |
651 | malloc_init (&my_edata, malloc_warning); | |
652 | #endif | |
653 | map_out_data (XSTRING (intoname)->data); | |
654 | ||
655 | Vpurify_flag = tem; | |
656 | ||
657 | return Qnil; | |
658 | } | |
659 | ||
660 | #else /* not HAVE_SHM */ | |
661 | ||
662 | DEFUN ("dump-emacs", Fdump_emacs, Sdump_emacs, 2, 2, 0, | |
663 | "Dump current state of Emacs into executable file FILENAME.\n\ | |
664 | Take symbols from SYMFILE (presumably the file you executed to run Emacs).\n\ | |
665 | This is used in the file `loadup.el' when building Emacs.\n\ | |
666 | \n\ | |
667 | Bind `command-line-processed' to nil before dumping,\n\ | |
668 | if you want the dumped Emacs to process its command line\n\ | |
669 | and announce itself normally when it is run.") | |
670 | (intoname, symname) | |
671 | Lisp_Object intoname, symname; | |
672 | { | |
673 | extern int my_edata; | |
674 | Lisp_Object tem; | |
675 | extern void malloc_warning (); | |
676 | ||
677 | CHECK_STRING (intoname, 0); | |
678 | intoname = Fexpand_file_name (intoname, Qnil); | |
2447c626 | 679 | if (!NILP (symname)) |
f927c5ae JB |
680 | { |
681 | CHECK_STRING (symname, 0); | |
682 | if (XSTRING (symname)->size) | |
683 | symname = Fexpand_file_name (symname, Qnil); | |
684 | } | |
685 | ||
686 | tem = Vpurify_flag; | |
687 | Vpurify_flag = Qnil; | |
688 | ||
689 | fflush (stdout); | |
690 | #ifdef VMS | |
691 | mapout_data (XSTRING (intoname)->data); | |
692 | #else | |
693 | /* Tell malloc where start of impure now is */ | |
694 | /* Also arrange for warnings when nearly out of space. */ | |
695 | #ifndef SYSTEM_MALLOC | |
696 | malloc_init (&my_edata, malloc_warning); | |
697 | #endif | |
698 | unexec (XSTRING (intoname)->data, | |
2447c626 | 699 | !NILP (symname) ? XSTRING (symname)->data : 0, &my_edata, 0, 0); |
f927c5ae JB |
700 | #endif /* not VMS */ |
701 | ||
702 | Vpurify_flag = tem; | |
703 | ||
704 | return Qnil; | |
705 | } | |
706 | ||
707 | #endif /* not HAVE_SHM */ | |
708 | ||
709 | #endif /* not CANNOT_DUMP */ | |
710 | \f | |
711 | #ifdef VMS | |
712 | #define SEPCHAR ',' | |
713 | #else | |
714 | #define SEPCHAR ':' | |
715 | #endif | |
716 | ||
717 | Lisp_Object | |
718 | decode_env_path (evarname, defalt) | |
719 | char *evarname, *defalt; | |
720 | { | |
721 | register char *path, *p; | |
722 | extern char *index (); | |
723 | ||
724 | Lisp_Object lpath; | |
725 | ||
2447c626 JB |
726 | /* It's okay to use getenv here, because this function is only used |
727 | to initialize variables when Emacs starts up, and isn't called | |
728 | after that. */ | |
729 | path = (char *) getenv (evarname); | |
f927c5ae JB |
730 | if (!path) |
731 | path = defalt; | |
732 | lpath = Qnil; | |
733 | while (1) | |
734 | { | |
735 | p = index (path, SEPCHAR); | |
736 | if (!p) p = path + strlen (path); | |
737 | lpath = Fcons (p - path ? make_string (path, p - path) : Qnil, | |
738 | lpath); | |
739 | if (*p) | |
740 | path = p + 1; | |
741 | else | |
742 | break; | |
743 | } | |
744 | return Fnreverse (lpath); | |
745 | } | |
746 | ||
747 | syms_of_emacs () | |
748 | { | |
749 | #ifdef HAVE_SHM | |
750 | defsubr (&Sdump_emacs_data); | |
751 | #else | |
752 | defsubr (&Sdump_emacs); | |
753 | #endif | |
754 | ||
755 | defsubr (&Skill_emacs); | |
756 | ||
757 | DEFVAR_LISP ("command-line-args", &Vcommand_line_args, | |
758 | "Args passed by shell to Emacs, as a list of strings."); | |
759 | ||
760 | DEFVAR_LISP ("system-type", &Vsystem_type, | |
761 | "Value is symbol indicating type of operating system you are using."); | |
762 | Vsystem_type = intern (SYSTEM_TYPE); | |
763 | ||
764 | DEFVAR_BOOL ("noninteractive", &noninteractive1, | |
765 | "Non-nil means Emacs is running without interactive terminal."); | |
766 | } |