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