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