(print_partial_compiled_pattern): Output to stderr.
[emacs.git] / src / emacs.c
blob7b5830c06a0515684ed19049fda77bd9cdcb9ef4
1 /* Fully extensible Emacs, running on Unix, intended for GNU.
2 Copyright (C) 1985,86,87,93,94,95,97,98,1999,2001,2002
3 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
23 #include <config.h>
24 #include <signal.h>
25 #include <errno.h>
26 #include <stdio.h>
28 #include <sys/types.h>
29 #include <sys/file.h>
31 #ifdef VMS
32 #include <ssdef.h>
33 #endif
35 #ifdef HAVE_UNISTD_H
36 #include <unistd.h>
37 #endif
39 #ifdef BSD_SYSTEM
40 #include <sys/ioctl.h>
41 #endif
43 #include "lisp.h"
44 #include "commands.h"
45 #include "intervals.h"
46 #include "buffer.h"
48 #include "systty.h"
49 #include "blockinput.h"
50 #include "syssignal.h"
51 #include "process.h"
52 #include "termhooks.h"
53 #include "keyboard.h"
54 #include "keymap.h"
56 #ifdef HAVE_SETLOCALE
57 #include <locale.h>
58 #endif
60 #ifdef HAVE_SETRLIMIT
61 #include <sys/time.h>
62 #include <sys/resource.h>
63 #endif
65 #ifndef O_RDWR
66 #define O_RDWR 2
67 #endif
69 #ifdef HAVE_SETPGID
70 #if !defined (USG) || defined (BSD_PGRPS)
71 #undef setpgrp
72 #define setpgrp setpgid
73 #endif
74 #endif
76 extern void malloc_warning P_ ((char *));
77 extern void set_time_zone_rule P_ ((char *));
78 #ifdef HAVE_INDEX
79 extern char *index P_ ((const char *, int));
80 #endif
82 /* Make these values available in GDB, which doesn't see macros. */
84 EMACS_INT gdb_valbits = VALBITS;
85 EMACS_INT gdb_gctypebits = GCTYPEBITS;
86 EMACS_INT gdb_emacs_intbits = sizeof (EMACS_INT) * BITS_PER_CHAR;
87 #ifdef DATA_SEG_BITS
88 EMACS_INT gdb_data_seg_bits = DATA_SEG_BITS;
89 #else
90 EMACS_INT gdb_data_seg_bits = 0;
91 #endif
92 EMACS_INT PVEC_FLAG = PSEUDOVECTOR_FLAG;
94 /* Command line args from shell, as list of strings. */
95 Lisp_Object Vcommand_line_args;
97 /* The name under which Emacs was invoked, with any leading directory
98 names discarded. */
99 Lisp_Object Vinvocation_name;
101 /* The directory name from which Emacs was invoked. */
102 Lisp_Object Vinvocation_directory;
104 /* The directory name in which to find subdirs such as lisp and etc.
105 nil means get them only from PATH_LOADSEARCH. */
106 Lisp_Object Vinstallation_directory;
108 /* Hook run by `kill-emacs' before it does really anything. */
109 Lisp_Object Vkill_emacs_hook;
111 /* An empty lisp string. To avoid having to build any other. */
112 Lisp_Object empty_string;
114 #ifdef SIGUSR1
115 /* Hooks for signal USR1 and USR2 handling. */
116 Lisp_Object Vsignal_USR1_hook;
117 #ifdef SIGUSR2
118 Lisp_Object Vsignal_USR2_hook;
119 #endif
120 #endif
122 /* Search path separator. */
123 Lisp_Object Vpath_separator;
125 /* Set nonzero after Emacs has started up the first time.
126 Prevents reinitialization of the Lisp world and keymaps
127 on subsequent starts. */
128 int initialized;
130 #ifdef DOUG_LEA_MALLOC
131 /* Preserves a pointer to the memory allocated that copies that
132 static data inside glibc's malloc. */
133 void *malloc_state_ptr;
134 /* From glibc, a routine that returns a copy of the malloc internal state. */
135 extern void *malloc_get_state ();
136 /* From glibc, a routine that overwrites the malloc internal state. */
137 extern void malloc_set_state ();
138 /* Non-zero if the MALLOC_CHECK_ enviroment variable was set while
139 dumping. Used to work around a bug in glibc's malloc. */
140 int malloc_using_checking;
141 #endif
143 /* Variable whose value is symbol giving operating system type. */
144 Lisp_Object Vsystem_type;
146 /* Variable whose value is string giving configuration built for. */
147 Lisp_Object Vsystem_configuration;
149 /* Variable whose value is string giving configuration options,
150 for use when reporting bugs. */
151 Lisp_Object Vsystem_configuration_options;
153 Lisp_Object Qfile_name_handler_alist;
155 /* Current and previous system locales for messages and time. */
156 Lisp_Object Vsystem_messages_locale;
157 Lisp_Object Vprevious_system_messages_locale;
158 Lisp_Object Vsystem_time_locale;
159 Lisp_Object Vprevious_system_time_locale;
161 /* If non-zero, emacs should not attempt to use a window-specific code,
162 but instead should use the virtual terminal under which it was started. */
163 int inhibit_window_system;
165 /* If nonzero, set Emacs to run at this priority. This is also used
166 in child_setup and sys_suspend to make sure subshells run at normal
167 priority; those functions have their own extern declaration. */
168 EMACS_INT emacs_priority;
170 /* If non-zero, a filter or a sentinel is running. Tested to save the match
171 data on the first attempt to change it inside asynchronous code. */
172 int running_asynch_code;
174 #ifdef BSD_PGRPS
175 /* See sysdep.c. */
176 extern int inherited_pgroup;
177 #endif
179 #ifdef HAVE_X_WINDOWS
180 /* If non-zero, -d was specified, meaning we're using some window system. */
181 int display_arg;
182 #endif
184 /* An address near the bottom of the stack.
185 Tells GC how to save a copy of the stack. */
186 char *stack_bottom;
188 #ifdef HAVE_WINDOW_SYSTEM
189 extern Lisp_Object Vwindow_system;
190 #endif /* HAVE_WINDOW_SYSTEM */
192 extern Lisp_Object Vauto_save_list_file_name;
194 #ifdef USG_SHARED_LIBRARIES
195 /* If nonzero, this is the place to put the end of the writable segment
196 at startup. */
198 unsigned int bss_end = 0;
199 #endif
201 /* Nonzero means running Emacs without interactive terminal. */
203 int noninteractive;
205 /* Value of Lisp variable `noninteractive'.
206 Normally same as C variable `noninteractive'
207 but nothing terrible happens if user sets this one. */
209 int noninteractive1;
211 /* Save argv and argc. */
212 char **initial_argv;
213 int initial_argc;
215 static void sort_args ();
216 void syms_of_emacs ();
218 #define USAGE1 "\
219 Usage: %s [OPTION-OR-FILENAME]...\n\
221 Run Emacs, the extensible, customizable, self-documenting real-time\n\
222 display editor. The recommended way to start Emacs for normal editing\n\
223 is with no options at all.\n\
225 Run M-x info RET m emacs RET m command arguments RET inside Emacs to\n\
226 read the main documentation for these command-line arguments.\n\
228 Initialization options:\n\
230 --batch do not do interactive display; implies -q\n\
231 --script FILE run FILE as an Emacs Lisp script.\n\
232 --debug-init enable Emacs Lisp debugger during init file\n\
233 --help display this help message and exit\n\
234 --multibyte, --no-unibyte run Emacs in multibyte mode\n\
235 --no-init-file, -q load neither ~/.emacs nor default.el\n\
236 --no-shared-memory, -nl do not use shared memory\n\
237 --no-site-file do not load site-start.el\n\
238 --no-splash do not display a splash screen on startup\n\
239 --no-window-system, -nw don't communicate with X, ignoring $DISPLAY\n\
240 --terminal, -t DEVICE use DEVICE for terminal I/O\n\
241 --unibyte, --no-multibyte run Emacs in unibyte mode\n\
242 --user, -u USER load ~USER/.emacs instead of your own\n\
243 --version display version information and exit\n\
245 Action options:\n\
247 FILE visit FILE using find-file\n\
248 +LINE FILE visit FILE using find-file, then go to line LINE\n\
249 +LINE:COLUMN FILE visit FILE using find-file, then go to line LINE,\n\
250 column COLUMN\n\
251 --directory, -L DIR add DIR to variable load-path\n\
252 --eval EXPR evaluate Emacs Lisp expression EXPR\n\
253 --execute EXPR evaluate Emacs Lisp expression EXPR\n\
254 --find-file FILE visit FILE\n\
255 --funcall, -f FUNC call Emacs function FUNC with no arguments\n\
256 --insert FILE insert contents of FILE into current buffer\n\
257 --kill exit without asking for confirmation\n\
258 --load, -l FILE load FILE of Emacs Lisp code using the load function\n\
259 --visit FILE visit FILE\n\
262 #define USAGE2 "\
263 Display options:\n\
265 --background-color, -bg COLOR window background color\n\
266 --border-color, -bd COLOR main border color\n\
267 --border-width, -bw WIDTH width of main border\n\
268 --color=MODE color mode for character terminals;\n\
269 MODE defaults to `auto', and can also\n\
270 be `never', `auto', `always',\n\
271 or a mode name like `ansi8'\n\
272 --cursor-color, -cr COLOR color of the Emacs cursor indicating point\n\
273 --display, -d DISPLAY use X server DISPLAY\n\
274 --font, -fn FONT default font; must be fixed-width\n\
275 --foreground-color, -fg COLOR window foreground color\n\
276 --fullscreen, -fs make first frame fullscreen\n\
277 --fullwidth, -fw make the first frame wide as the screen\n\
278 --fullheight, -fh make the first frame high as the screen\n\
279 --geometry, -g GEOMETRY window geometry\n\
280 --iconic start Emacs in iconified state\n\
281 --icon-type, -i use picture of gnu for Emacs icon\n\
282 --internal-border, -ib WIDTH width between text and main border\n\
283 --line-spacing, -lsp PIXELS additional space to put between lines\n\
284 --mouse-color, -ms COLOR mouse cursor color in Emacs window\n\
285 --name NAME title of main Emacs window\n\
286 --reverse-video, -r, -rv switch foreground and background\n\
287 --title, -T, -wn TITLE title for Emacs windows\n\
288 --vertical-scroll-bars, -vb enable vertical scroll bars\n\
289 --xrm XRESOURCES set additional X resources\n\
291 You can generally also specify long option names with a single -; for\n\
292 example, -batch as well as --batch. You can use any unambiguous\n\
293 abbreviation for a --option.\n\
295 Various environment variables and window system resources also affect\n\
296 Emacs' operation. See the main documentation.\n\
299 #define USAGE3 "\
300 Report bugs to %s. First, please see the Bugs\n\
301 section of the Emacs manual or the file BUGS.\n"
304 /* Signal code for the fatal signal that was received. */
305 int fatal_error_code;
307 /* Nonzero if handling a fatal error already. */
308 int fatal_error_in_progress;
310 /* If non-null, call this function from fatal_error_signal before
311 committing suicide. */
313 void (*fatal_error_signal_hook) P_ ((void));
316 #ifdef SIGUSR1
317 SIGTYPE
318 handle_USR1_signal (sig)
319 int sig;
321 struct input_event buf;
323 bzero (&buf, sizeof buf);
324 buf.kind = USER_SIGNAL_EVENT;
325 buf.frame_or_window = selected_frame;
327 kbd_buffer_store_event (&buf);
329 #endif /* SIGUSR1 */
331 #ifdef SIGUSR2
332 SIGTYPE
333 handle_USR2_signal (sig)
334 int sig;
336 struct input_event buf;
338 bzero (&buf, sizeof buf);
339 buf.kind = USER_SIGNAL_EVENT;
340 buf.code = 1;
341 buf.frame_or_window = selected_frame;
343 kbd_buffer_store_event (&buf);
345 #endif /* SIGUSR2 */
347 /* Handle bus errors, invalid instruction, etc. */
348 SIGTYPE
349 fatal_error_signal (sig)
350 int sig;
352 fatal_error_code = sig;
353 signal (sig, SIG_DFL);
355 TOTALLY_UNBLOCK_INPUT;
357 /* If fatal error occurs in code below, avoid infinite recursion. */
358 if (! fatal_error_in_progress)
360 fatal_error_in_progress = 1;
362 shut_down_emacs (sig, 0, Qnil);
365 #ifdef VMS
366 LIB$STOP (SS$_ABORT);
367 #else
368 /* Signal the same code; this time it will really be fatal.
369 Remember that since we're in a signal handler, the signal we're
370 going to send is probably blocked, so we have to unblock it if we
371 want to really receive it. */
372 #ifndef MSDOS
373 sigunblock (sigmask (fatal_error_code));
374 #endif
376 if (fatal_error_signal_hook)
377 fatal_error_signal_hook ();
379 kill (getpid (), fatal_error_code);
380 #endif /* not VMS */
383 #ifdef SIGDANGER
385 /* Handler for SIGDANGER. */
386 SIGTYPE
387 memory_warning_signal (sig)
388 int sig;
390 signal (sig, memory_warning_signal);
392 malloc_warning ("Operating system warns that virtual memory is running low.\n");
394 /* It might be unsafe to call do_auto_save now. */
395 force_auto_save_soon ();
397 #endif
399 /* We define abort, rather than using it from the library,
400 so that GDB can return from a breakpoint here.
401 MSDOS has its own definition in msdos.c. */
403 #if ! defined (DOS_NT) && ! defined (NO_ABORT)
405 #ifndef ABORT_RETURN_TYPE
406 #define ABORT_RETURN_TYPE void
407 #endif
409 ABORT_RETURN_TYPE
410 abort ()
412 kill (getpid (), SIGABRT);
413 /* This shouldn't be executed, but it prevents a warning. */
414 exit (1);
416 #endif
419 /* Code for dealing with Lisp access to the Unix command line. */
421 static void
422 init_cmdargs (argc, argv, skip_args)
423 int argc;
424 char **argv;
425 int skip_args;
427 register int i;
428 Lisp_Object name, dir, tem;
429 int count = SPECPDL_INDEX ();
430 Lisp_Object raw_name;
432 initial_argv = argv;
433 initial_argc = argc;
435 raw_name = build_string (argv[0]);
437 /* Add /: to the front of the name
438 if it would otherwise be treated as magic. */
439 tem = Ffind_file_name_handler (raw_name, Qt);
440 if (! NILP (tem))
441 raw_name = concat2 (build_string ("/:"), raw_name);
443 Vinvocation_name = Ffile_name_nondirectory (raw_name);
444 Vinvocation_directory = Ffile_name_directory (raw_name);
446 /* If we got no directory in argv[0], search PATH to find where
447 Emacs actually came from. */
448 if (NILP (Vinvocation_directory))
450 Lisp_Object found;
451 int yes = openp (Vexec_path, Vinvocation_name,
452 Vexec_suffixes, &found, make_number (X_OK));
453 if (yes == 1)
455 /* Add /: to the front of the name
456 if it would otherwise be treated as magic. */
457 tem = Ffind_file_name_handler (found, Qt);
458 if (! NILP (tem))
459 found = concat2 (build_string ("/:"), found);
460 Vinvocation_directory = Ffile_name_directory (found);
464 if (!NILP (Vinvocation_directory)
465 && NILP (Ffile_name_absolute_p (Vinvocation_directory)))
466 /* Emacs was started with relative path, like ./emacs.
467 Make it absolute. */
468 Vinvocation_directory = Fexpand_file_name (Vinvocation_directory, Qnil);
470 Vinstallation_directory = Qnil;
472 if (!NILP (Vinvocation_directory))
474 dir = Vinvocation_directory;
475 name = Fexpand_file_name (Vinvocation_name, dir);
476 while (1)
478 Lisp_Object tem, lib_src_exists;
479 Lisp_Object etc_exists, info_exists;
481 /* See if dir contains subdirs for use by Emacs.
482 Check for the ones that would exist in a build directory,
483 not including lisp and info. */
484 tem = Fexpand_file_name (build_string ("lib-src"), dir);
485 lib_src_exists = Ffile_exists_p (tem);
487 #ifdef MSDOS
488 /* MSDOS installations frequently remove lib-src, but we still
489 must set installation-directory, or else info won't find
490 its files (it uses the value of installation-directory). */
491 tem = Fexpand_file_name (build_string ("info"), dir);
492 info_exists = Ffile_exists_p (tem);
493 #else
494 info_exists = Qnil;
495 #endif
497 if (!NILP (lib_src_exists) || !NILP (info_exists))
499 tem = Fexpand_file_name (build_string ("etc"), dir);
500 etc_exists = Ffile_exists_p (tem);
501 if (!NILP (etc_exists))
503 Vinstallation_directory
504 = Ffile_name_as_directory (dir);
505 break;
509 /* See if dir's parent contains those subdirs. */
510 tem = Fexpand_file_name (build_string ("../lib-src"), dir);
511 lib_src_exists = Ffile_exists_p (tem);
514 #ifdef MSDOS
515 /* See the MSDOS commentary above. */
516 tem = Fexpand_file_name (build_string ("../info"), dir);
517 info_exists = Ffile_exists_p (tem);
518 #else
519 info_exists = Qnil;
520 #endif
522 if (!NILP (lib_src_exists) || !NILP (info_exists))
524 tem = Fexpand_file_name (build_string ("../etc"), dir);
525 etc_exists = Ffile_exists_p (tem);
526 if (!NILP (etc_exists))
528 tem = Fexpand_file_name (build_string (".."), dir);
529 Vinstallation_directory
530 = Ffile_name_as_directory (tem);
531 break;
535 /* If the Emacs executable is actually a link,
536 next try the dir that the link points into. */
537 tem = Ffile_symlink_p (name);
538 if (!NILP (tem))
540 name = Fexpand_file_name (tem, dir);
541 dir = Ffile_name_directory (name);
543 else
544 break;
548 Vcommand_line_args = Qnil;
550 for (i = argc - 1; i >= 0; i--)
552 if (i == 0 || i > skip_args)
553 Vcommand_line_args
554 = Fcons (build_string (argv[i]), Vcommand_line_args);
557 unbind_to (count, Qnil);
560 DEFUN ("invocation-name", Finvocation_name, Sinvocation_name, 0, 0, 0,
561 doc: /* Return the program name that was used to run Emacs.
562 Any directory names are omitted. */)
565 return Fcopy_sequence (Vinvocation_name);
568 DEFUN ("invocation-directory", Finvocation_directory, Sinvocation_directory,
569 0, 0, 0,
570 doc: /* Return the directory name in which the Emacs executable was located. */)
573 return Fcopy_sequence (Vinvocation_directory);
577 #ifdef VMS
578 #ifdef LINK_CRTL_SHARE
579 #ifdef SHARABLE_LIB_BUG
580 extern noshare char **environ;
581 #endif /* SHARABLE_LIB_BUG */
582 #endif /* LINK_CRTL_SHARE */
583 #endif /* VMS */
585 #ifdef HAVE_TZSET
586 /* A valid but unlikely value for the TZ environment value.
587 It is OK (though a bit slower) if the user actually chooses this value. */
588 static char dump_tz[] = "UtC0";
589 #endif
591 #ifndef ORDINARY_LINK
592 /* We don't include crtbegin.o and crtend.o in the link,
593 so these functions and variables might be missed.
594 Provide dummy definitions to avoid error.
595 (We don't have any real constructors or destructors.) */
596 #ifdef __GNUC__
597 #ifndef GCC_CTORS_IN_LIBC
598 void __do_global_ctors ()
600 void __do_global_ctors_aux ()
602 void __do_global_dtors ()
604 /* Linux has a bug in its library; avoid an error. */
605 #ifndef GNU_LINUX
606 char * __CTOR_LIST__[2] = { (char *) (-1), 0 };
607 #endif
608 char * __DTOR_LIST__[2] = { (char *) (-1), 0 };
609 #endif /* GCC_CTORS_IN_LIBC */
610 void __main ()
612 #endif /* __GNUC__ */
613 #endif /* ORDINARY_LINK */
615 /* Test whether the next argument in ARGV matches SSTR or a prefix of
616 LSTR (at least MINLEN characters). If so, then if VALPTR is non-null
617 (the argument is supposed to have a value) store in *VALPTR either
618 the next argument or the portion of this one after the equal sign.
619 ARGV is read starting at position *SKIPPTR; this index is advanced
620 by the number of arguments used.
622 Too bad we can't just use getopt for all of this, but we don't have
623 enough information to do it right. */
625 static int
626 argmatch (argv, argc, sstr, lstr, minlen, valptr, skipptr)
627 char **argv;
628 int argc;
629 char *sstr;
630 char *lstr;
631 int minlen;
632 char **valptr;
633 int *skipptr;
635 char *p = NULL;
636 int arglen;
637 char *arg;
639 /* Don't access argv[argc]; give up in advance. */
640 if (argc <= *skipptr + 1)
641 return 0;
643 arg = argv[*skipptr+1];
644 if (arg == NULL)
645 return 0;
646 if (strcmp (arg, sstr) == 0)
648 if (valptr != NULL)
650 *valptr = argv[*skipptr+2];
651 *skipptr += 2;
653 else
654 *skipptr += 1;
655 return 1;
657 arglen = (valptr != NULL && (p = index (arg, '=')) != NULL
658 ? p - arg : strlen (arg));
659 if (lstr == 0 || arglen < minlen || strncmp (arg, lstr, arglen) != 0)
660 return 0;
661 else if (valptr == NULL)
663 *skipptr += 1;
664 return 1;
666 else if (p != NULL)
668 *valptr = p+1;
669 *skipptr += 1;
670 return 1;
672 else if (argv[*skipptr+2] != NULL)
674 *valptr = argv[*skipptr+2];
675 *skipptr += 2;
676 return 1;
678 else
680 return 0;
684 #ifdef DOUG_LEA_MALLOC
686 /* malloc can be invoked even before main (e.g. by the dynamic
687 linker), so the dumped malloc state must be restored as early as
688 possible using this special hook. */
690 static void
691 malloc_initialize_hook ()
693 #ifndef USE_CRT_DLL
694 extern char **environ;
695 #endif
697 if (initialized)
699 if (!malloc_using_checking)
700 /* Work around a bug in glibc's malloc. MALLOC_CHECK_ must be
701 ignored if the heap to be restored was constructed without
702 malloc checking. Can't use unsetenv, since that calls malloc. */
704 char **p;
706 for (p = environ; p && *p; p++)
707 if (strncmp (*p, "MALLOC_CHECK_=", 14) == 0)
710 *p = p[1];
711 while (*++p);
712 break;
716 malloc_set_state (malloc_state_ptr);
717 free (malloc_state_ptr);
719 else
720 malloc_using_checking = getenv ("MALLOC_CHECK_") != NULL;
723 void (*__malloc_initialize_hook) () = malloc_initialize_hook;
725 #endif /* DOUG_LEA_MALLOC */
728 #define REPORT_EMACS_BUG_ADDRESS "bug-gnu-emacs@gnu.org"
729 #define REPORT_EMACS_BUG_PRETEST_ADDRESS "emacs-pretest-bug@gnu.org"
731 /* This function is used to determine an address to which bug report should
732 be sent. */
734 char *
735 bug_reporting_address ()
737 int count = 0;
738 Lisp_Object temp;
739 char *string;
741 temp = Fsymbol_value (intern ("emacs-version"));
743 /* When `emacs-version' is invalid, use normal address. */
744 if (!STRINGP(temp))
745 return REPORT_EMACS_BUG_ADDRESS;
747 string = SDATA (temp);
749 /* Count dots in `emacs-version'. */
750 while (*string)
752 if (*string == '.')
753 count++;
754 string++;
757 /* When `emacs-version' has at least three dots, it is development or
758 pretest version of Emacs. */
759 return count >= 3 ? REPORT_EMACS_BUG_PRETEST_ADDRESS : REPORT_EMACS_BUG_ADDRESS;
763 /* ARGSUSED */
765 main (argc, argv
766 #ifdef VMS
767 , envp
768 #endif
770 int argc;
771 char **argv;
772 #ifdef VMS
773 char **envp;
774 #endif
776 #if GC_MARK_STACK
777 Lisp_Object dummy;
778 #endif
779 char stack_bottom_variable;
780 int do_initial_setlocale;
781 int skip_args = 0;
782 #ifndef USE_CRT_DLL
783 extern int errno;
784 #endif
785 #ifdef HAVE_SETRLIMIT
786 struct rlimit rlim;
787 #endif
788 int no_loadup = 0;
789 char *junk = 0;
791 #if GC_MARK_STACK
792 extern Lisp_Object *stack_base;
793 stack_base = &dummy;
794 #endif
796 #ifdef LINUX_SBRK_BUG
797 __sbrk (1);
798 #endif
800 #ifdef RUN_TIME_REMAP
801 if (initialized)
802 run_time_remap (argv[0]);
803 #endif
805 #ifdef MAC_OSX
806 if (!initialized)
807 unexec_init_emacs_zone ();
808 #endif
810 sort_args (argc, argv);
811 argc = 0;
812 while (argv[argc]) argc++;
814 if (argmatch (argv, argc, "-version", "--version", 3, NULL, &skip_args)
815 /* We don't know the version number unless this is a dumped Emacs.
816 So ignore --version otherwise. */
817 && initialized)
819 Lisp_Object tem;
820 tem = Fsymbol_value (intern ("emacs-version"));
821 if (!STRINGP (tem))
823 fprintf (stderr, "Invalid value of `emacs-version'\n");
824 exit (1);
826 else
828 printf ("GNU Emacs %s\n", SDATA (tem));
829 printf ("Copyright (C) 2002 Free Software Foundation, Inc.\n");
830 printf ("GNU Emacs comes with ABSOLUTELY NO WARRANTY.\n");
831 printf ("You may redistribute copies of Emacs\n");
832 printf ("under the terms of the GNU General Public License.\n");
833 printf ("For more information about these matters, ");
834 printf ("see the file named COPYING.\n");
835 exit (0);
839 /* Map in shared memory, if we are using that. */
840 #ifdef HAVE_SHM
841 if (argmatch (argv, argc, "-nl", "--no-shared-memory", 6, NULL, &skip_args))
843 map_in_data (0);
844 /* The shared memory was just restored, which clobbered this. */
845 skip_args = 1;
847 else
849 map_in_data (1);
850 /* The shared memory was just restored, which clobbered this. */
851 skip_args = 0;
853 #endif
855 #ifdef NeXT
857 extern int malloc_cookie;
858 /* This helps out unexnext.c. */
859 if (initialized)
860 if (malloc_jumpstart (malloc_cookie) != 0)
861 printf ("malloc jumpstart failed!\n");
863 #endif /* NeXT */
865 #ifdef MAC_OSX
866 /* Skip process serial number passed in the form -psn_x_y as
867 command-line argument. */
868 if (argc > skip_args + 1 && strncmp (argv[skip_args+1], "-psn_", 5) == 0)
869 skip_args++;
870 #endif /* MAC_OSX */
872 #ifdef VMS
873 /* If -map specified, map the data file in. */
875 char *file;
876 if (argmatch (argv, argc, "-map", "--map-data", 3, &mapin_file, &skip_args))
877 mapin_data (file);
880 #ifdef LINK_CRTL_SHARE
881 #ifdef SHARABLE_LIB_BUG
882 /* Bletcherous shared libraries! */
883 if (!stdin)
884 stdin = fdopen (0, "r");
885 if (!stdout)
886 stdout = fdopen (1, "w");
887 if (!stderr)
888 stderr = fdopen (2, "w");
889 if (!environ)
890 environ = envp;
891 #endif /* SHARABLE_LIB_BUG */
892 #endif /* LINK_CRTL_SHARE */
893 #endif /* VMS */
895 #if defined (HAVE_SETRLIMIT) && defined (RLIMIT_STACK)
896 /* Extend the stack space available.
897 Don't do that if dumping, since some systems (e.g. DJGPP)
898 might define a smaller stack limit at that time. */
899 if (1
900 #ifndef CANNOT_DUMP
901 && (!noninteractive || initialized)
902 #endif
903 && !getrlimit (RLIMIT_STACK, &rlim))
905 long newlim;
906 extern int re_max_failures;
907 /* Approximate the amount regex.c needs per unit of re_max_failures. */
908 int ratio = 20 * sizeof (char *);
909 /* Then add 33% to cover the size of the smaller stacks that regex.c
910 successively allocates and discards, on its way to the maximum. */
911 ratio += ratio / 3;
912 /* Add in some extra to cover
913 what we're likely to use for other reasons. */
914 newlim = re_max_failures * ratio + 200000;
915 #ifdef __NetBSD__
916 /* NetBSD (at least NetBSD 1.2G and former) has a bug in its
917 stack allocation routine for new process that the allocation
918 fails if stack limit is not on page boundary. So, round up the
919 new limit to page boundary. */
920 newlim = (newlim + getpagesize () - 1) / getpagesize () * getpagesize();
921 #endif
922 if (newlim > rlim.rlim_max)
924 newlim = rlim.rlim_max;
925 /* Don't let regex.c overflow the stack we have. */
926 re_max_failures = (newlim - 200000) / ratio;
928 if (rlim.rlim_cur < newlim)
929 rlim.rlim_cur = newlim;
931 setrlimit (RLIMIT_STACK, &rlim);
933 #endif /* HAVE_SETRLIMIT and RLIMIT_STACK */
935 /* Record (approximately) where the stack begins. */
936 stack_bottom = &stack_bottom_variable;
938 #ifdef USG_SHARED_LIBRARIES
939 if (bss_end)
940 brk ((void *)bss_end);
941 #endif
943 clearerr (stdin);
945 #ifndef SYSTEM_MALLOC
946 /* Arrange to get warning messages as memory fills up. */
947 memory_warnings (0, malloc_warning);
949 /* Call malloc at least once, to run the initial __malloc_hook.
950 Also call realloc and free for consistency. */
951 free (realloc (malloc (4), 4));
953 /* Arrange to disable interrupt input inside malloc etc. */
954 uninterrupt_malloc ();
955 #endif /* not SYSTEM_MALLOC */
957 #ifdef MSDOS
958 /* We do all file input/output as binary files. When we need to translate
959 newlines, we do that manually. */
960 _fmode = O_BINARY;
962 #if __DJGPP__ >= 2
963 if (!isatty (fileno (stdin)))
964 setmode (fileno (stdin), O_BINARY);
965 if (!isatty (fileno (stdout)))
967 fflush (stdout);
968 setmode (fileno (stdout), O_BINARY);
970 #else /* not __DJGPP__ >= 2 */
971 (stdin)->_flag &= ~_IOTEXT;
972 (stdout)->_flag &= ~_IOTEXT;
973 (stderr)->_flag &= ~_IOTEXT;
974 #endif /* not __DJGPP__ >= 2 */
975 #endif /* MSDOS */
977 #ifdef SET_EMACS_PRIORITY
978 if (emacs_priority)
979 nice (emacs_priority);
980 setuid (getuid ());
981 #endif /* SET_EMACS_PRIORITY */
983 /* Skip initial setlocale if LC_ALL is "C", as it's not needed in that case.
984 The build procedure uses this while dumping, to ensure that the
985 dumped Emacs does not have its system locale tables initialized,
986 as that might cause screwups when the dumped Emacs starts up. */
988 char *lc_all = getenv ("LC_ALL");
989 do_initial_setlocale = ! lc_all || strcmp (lc_all, "C");
992 /* Set locale now, so that initial error messages are localized properly.
993 fixup_locale must wait until later, since it builds strings. */
994 if (do_initial_setlocale)
995 setlocale (LC_ALL, "");
997 #ifdef EXTRA_INITIALIZE
998 EXTRA_INITIALIZE;
999 #endif
1001 inhibit_window_system = 0;
1003 /* Handle the -t switch, which specifies filename to use as terminal. */
1004 while (1)
1006 char *term;
1007 if (argmatch (argv, argc, "-t", "--terminal", 4, &term, &skip_args))
1009 int result;
1010 emacs_close (0);
1011 emacs_close (1);
1012 result = emacs_open (term, O_RDWR, 0);
1013 if (result < 0)
1015 char *errstring = strerror (errno);
1016 fprintf (stderr, "%s: %s: %s\n", argv[0], term, errstring);
1017 exit (1);
1019 dup (0);
1020 if (! isatty (0))
1022 fprintf (stderr, "%s: %s: not a tty\n", argv[0], term);
1023 exit (1);
1025 fprintf (stderr, "Using %s\n", term);
1026 #ifdef HAVE_WINDOW_SYSTEM
1027 inhibit_window_system = 1; /* -t => -nw */
1028 #endif
1030 else
1031 break;
1034 /* Command line option --no-windows is deprecated and thus not mentioned
1035 in the manual and usage informations. */
1036 if (argmatch (argv, argc, "-nw", "--no-window-system", 6, NULL, &skip_args)
1037 || argmatch (argv, argc, "-nw", "--no-windows", 6, NULL, &skip_args))
1038 inhibit_window_system = 1;
1040 /* Handle the -batch switch, which means don't do interactive display. */
1041 noninteractive = 0;
1042 if (argmatch (argv, argc, "-batch", "--batch", 5, NULL, &skip_args))
1043 noninteractive = 1;
1044 if (argmatch (argv, argc, "-script", "--script", 3, &junk, &skip_args))
1046 noninteractive = 1; /* Set batch mode. */
1047 /* Convert --script to -l, un-skip it, and sort again so that -l will be
1048 handled in proper sequence. */
1049 argv[skip_args - 1] = "-l";
1050 skip_args -= 2;
1051 sort_args (argc, argv);
1054 /* Handle the --help option, which gives a usage message. */
1055 if (argmatch (argv, argc, "-help", "--help", 3, NULL, &skip_args))
1057 printf (USAGE1, argv[0]);
1058 printf (USAGE2);
1059 printf (USAGE3, bug_reporting_address ());
1060 exit (0);
1063 if (! noninteractive)
1065 #ifdef BSD_PGRPS
1066 if (initialized)
1068 inherited_pgroup = EMACS_GETPGRP (0);
1069 setpgrp (0, getpid ());
1071 #else
1072 #if defined (USG5) && defined (INTERRUPT_INPUT)
1073 setpgrp ();
1074 #endif
1075 #endif
1078 init_signals ();
1080 /* Don't catch SIGHUP if dumping. */
1081 if (1
1082 #ifndef CANNOT_DUMP
1083 && initialized
1084 #endif
1087 sigblock (sigmask (SIGHUP));
1088 /* In --batch mode, don't catch SIGHUP if already ignored.
1089 That makes nohup work. */
1090 if (! noninteractive
1091 || signal (SIGHUP, SIG_IGN) != SIG_IGN)
1092 signal (SIGHUP, fatal_error_signal);
1093 sigunblock (sigmask (SIGHUP));
1096 if (
1097 #ifndef CANNOT_DUMP
1098 ! noninteractive || initialized
1099 #else
1101 #endif
1104 /* Don't catch these signals in batch mode if dumping.
1105 On some machines, this sets static data that would make
1106 signal fail to work right when the dumped Emacs is run. */
1107 signal (SIGQUIT, fatal_error_signal);
1108 signal (SIGILL, fatal_error_signal);
1109 signal (SIGTRAP, fatal_error_signal);
1110 #ifdef SIGUSR1
1111 signal (SIGUSR1, handle_USR1_signal);
1112 #ifdef SIGUSR2
1113 signal (SIGUSR2, handle_USR2_signal);
1114 #endif
1115 #endif
1116 #ifdef SIGABRT
1117 signal (SIGABRT, fatal_error_signal);
1118 #endif
1119 #ifdef SIGHWE
1120 signal (SIGHWE, fatal_error_signal);
1121 #endif
1122 #ifdef SIGPRE
1123 signal (SIGPRE, fatal_error_signal);
1124 #endif
1125 #ifdef SIGORE
1126 signal (SIGORE, fatal_error_signal);
1127 #endif
1128 #ifdef SIGUME
1129 signal (SIGUME, fatal_error_signal);
1130 #endif
1131 #ifdef SIGDLK
1132 signal (SIGDLK, fatal_error_signal);
1133 #endif
1134 #ifdef SIGCPULIM
1135 signal (SIGCPULIM, fatal_error_signal);
1136 #endif
1137 #ifdef SIGIOT
1138 /* This is missing on some systems - OS/2, for example. */
1139 signal (SIGIOT, fatal_error_signal);
1140 #endif
1141 #ifdef SIGEMT
1142 signal (SIGEMT, fatal_error_signal);
1143 #endif
1144 signal (SIGFPE, fatal_error_signal);
1145 #ifdef SIGBUS
1146 signal (SIGBUS, fatal_error_signal);
1147 #endif
1148 signal (SIGSEGV, fatal_error_signal);
1149 #ifdef SIGSYS
1150 signal (SIGSYS, fatal_error_signal);
1151 #endif
1152 signal (SIGTERM, fatal_error_signal);
1153 #ifdef SIGXCPU
1154 signal (SIGXCPU, fatal_error_signal);
1155 #endif
1156 #ifdef SIGXFSZ
1157 signal (SIGXFSZ, fatal_error_signal);
1158 #endif /* SIGXFSZ */
1160 #ifdef SIGDANGER
1161 /* This just means available memory is getting low. */
1162 signal (SIGDANGER, memory_warning_signal);
1163 #endif
1165 #ifdef AIX
1166 /* 20 is SIGCHLD, 21 is SIGTTIN, 22 is SIGTTOU. */
1167 signal (SIGXCPU, fatal_error_signal);
1168 #ifndef _I386
1169 signal (SIGIOINT, fatal_error_signal);
1170 #endif
1171 signal (SIGGRANT, fatal_error_signal);
1172 signal (SIGRETRACT, fatal_error_signal);
1173 signal (SIGSOUND, fatal_error_signal);
1174 signal (SIGMSG, fatal_error_signal);
1175 #endif /* AIX */
1178 noninteractive1 = noninteractive;
1180 /* Perform basic initializations (not merely interning symbols). */
1182 if (!initialized)
1184 init_alloc_once ();
1185 init_obarray ();
1186 init_eval_once ();
1187 init_charset_once ();
1188 init_coding_once ();
1189 init_syntax_once (); /* Create standard syntax table. */
1190 init_category_once (); /* Create standard category table. */
1191 /* Must be done before init_buffer. */
1192 init_casetab_once ();
1193 init_buffer_once (); /* Create buffer table and some buffers. */
1194 init_minibuf_once (); /* Create list of minibuffers. */
1195 /* Must precede init_window_once. */
1197 /* Call syms_of_xfaces before init_window_once because that
1198 function creates Vterminal_frame. Termcap frames now use
1199 faces, and the face implementation uses some symbols as
1200 face names. */
1201 syms_of_xfaces ();
1202 /* Call syms_of_keyboard before init_window_once because
1203 keyboard sets up symbols that include some face names that
1204 the X support will want to use. This can happen when
1205 CANNOT_DUMP is defined. */
1206 syms_of_keyboard ();
1208 #ifdef MAC_OS8
1209 /* init_window_once calls make_terminal_frame which on Mac OS
1210 creates a full-fledge output_mac type frame. This does not
1211 work correctly before syms_of_textprop, syms_of_macfns,
1212 syms_of_ccl, syms_of_fontset, syms_of_xterm, syms_of_search,
1213 syms_of_frame, mac_initialize, and init_keyboard have already
1214 been called. */
1215 syms_of_textprop ();
1216 syms_of_macfns ();
1217 syms_of_ccl ();
1218 syms_of_fontset ();
1219 syms_of_macterm ();
1220 syms_of_macmenu ();
1221 syms_of_data ();
1222 syms_of_search ();
1223 syms_of_frame ();
1225 mac_initialize ();
1226 init_keyboard ();
1227 #endif
1229 init_window_once (); /* Init the window system. */
1230 init_fileio_once (); /* Must precede any path manipulation. */
1233 init_alloc ();
1235 if (do_initial_setlocale)
1237 fixup_locale ();
1238 Vsystem_messages_locale = Vprevious_system_messages_locale;
1239 Vsystem_time_locale = Vprevious_system_time_locale;
1242 init_eval ();
1243 init_data ();
1244 #ifdef CLASH_DETECTION
1245 init_filelock ();
1246 #endif
1247 init_atimer ();
1248 running_asynch_code = 0;
1250 /* Handle --unibyte and the EMACS_UNIBYTE envvar,
1251 but not while dumping. */
1252 if (1)
1254 int inhibit_unibyte = 0;
1256 /* --multibyte overrides EMACS_UNIBYTE. */
1257 if (argmatch (argv, argc, "-no-unibyte", "--no-unibyte", 4, NULL, &skip_args)
1258 || argmatch (argv, argc, "-multibyte", "--multibyte", 4, NULL, &skip_args)
1259 /* Ignore EMACS_UNIBYTE before dumping. */
1260 || (!initialized && noninteractive))
1261 inhibit_unibyte = 1;
1263 /* --unibyte requests that we set up to do everything with single-byte
1264 buffers and strings. We need to handle this before calling
1265 init_lread, init_editfns and other places that generate Lisp strings
1266 from text in the environment. */
1267 /* Actually this shouldn't be needed as of 20.4 in a generally
1268 unibyte environment. As handa says, environment values
1269 aren't now decoded; also existing buffers are now made
1270 unibyte during startup if .emacs sets unibyte. Tested with
1271 8-bit data in environment variables and /etc/passwd, setting
1272 unibyte and Latin-1 in .emacs. -- Dave Love */
1273 if (argmatch (argv, argc, "-unibyte", "--unibyte", 4, NULL, &skip_args)
1274 || argmatch (argv, argc, "-no-multibyte", "--no-multibyte", 4, NULL, &skip_args)
1275 || (getenv ("EMACS_UNIBYTE") && !inhibit_unibyte))
1277 Lisp_Object old_log_max;
1278 Lisp_Object symbol, tail;
1280 symbol = intern ("default-enable-multibyte-characters");
1281 Fset (symbol, Qnil);
1283 if (initialized)
1285 /* Erase pre-dump messages in *Messages* now so no abort. */
1286 old_log_max = Vmessage_log_max;
1287 XSETFASTINT (Vmessage_log_max, 0);
1288 message_dolog ("", 0, 1, 0);
1289 Vmessage_log_max = old_log_max;
1292 for (tail = Vbuffer_alist; CONSP (tail);
1293 tail = XCDR (tail))
1295 Lisp_Object buffer;
1297 buffer = Fcdr (XCAR (tail));
1298 /* Verify that all buffers are empty now, as they
1299 ought to be. */
1300 if (BUF_Z (XBUFFER (buffer)) > BUF_BEG (XBUFFER (buffer)))
1301 abort ();
1302 /* It is safe to do this crudely in an empty buffer. */
1303 XBUFFER (buffer)->enable_multibyte_characters = Qnil;
1308 no_loadup
1309 = argmatch (argv, argc, "-nl", "--no-loadup", 6, NULL, &skip_args);
1312 #ifdef HAVE_X_WINDOWS
1313 /* Stupid kludge to catch command-line display spec. We can't
1314 handle this argument entirely in window system dependent code
1315 because we don't even know which window system dependent code
1316 to run until we've recognized this argument. */
1318 char *displayname = 0;
1319 int count_before = skip_args;
1321 /* Skip any number of -d options, but only use the last one. */
1322 while (1)
1324 int count_before_this = skip_args;
1326 if (argmatch (argv, argc, "-d", "--display", 3, &displayname, &skip_args))
1327 display_arg = 1;
1328 else if (argmatch (argv, argc, "-display", 0, 3, &displayname, &skip_args))
1329 display_arg = 1;
1330 else
1331 break;
1333 count_before = count_before_this;
1336 /* If we have the form --display=NAME,
1337 convert it into -d name.
1338 This requires inserting a new element into argv. */
1339 if (displayname != 0 && skip_args - count_before == 1)
1341 char **new = (char **) xmalloc (sizeof (char *) * (argc + 2));
1342 int j;
1344 for (j = 0; j < count_before + 1; j++)
1345 new[j] = argv[j];
1346 new[count_before + 1] = "-d";
1347 new[count_before + 2] = displayname;
1348 for (j = count_before + 2; j <argc; j++)
1349 new[j + 1] = argv[j];
1350 argv = new;
1351 argc++;
1353 /* Change --display to -d, when its arg is separate. */
1354 else if (displayname != 0 && skip_args > count_before
1355 && argv[count_before + 1][1] == '-')
1356 argv[count_before + 1] = "-d";
1358 /* Don't actually discard this arg. */
1359 skip_args = count_before;
1361 #endif
1363 /* argmatch must not be used after here,
1364 except when bulding temacs
1365 because the -d argument has not been skipped in skip_args. */
1367 #ifdef MSDOS
1368 /* Call early 'cause init_environment needs it. */
1369 init_dosfns ();
1370 /* Set defaults for several environment variables. */
1371 if (initialized)
1372 init_environment (argc, argv, skip_args);
1373 else
1374 tzset ();
1375 #endif /* MSDOS */
1377 #ifdef WINDOWSNT
1378 globals_of_w32 ();
1379 /* Initialize environment from registry settings. */
1380 init_environment (argv);
1381 init_ntproc (); /* must precede init_editfns. */
1382 #endif
1384 #ifdef HAVE_CARBON
1385 if (initialized)
1386 init_mac_osx_environment ();
1387 #endif
1389 /* egetenv is a pretty low-level facility, which may get called in
1390 many circumstances; it seems flimsy to put off initializing it
1391 until calling init_callproc. */
1392 set_process_environment ();
1393 /* AIX crashes are reported in system versions 3.2.3 and 3.2.4
1394 if this is not done. Do it after set_process_environment so that we
1395 don't pollute Vprocess_environment. */
1396 /* Setting LANG here will defeat the startup locale processing... */
1397 #ifdef AIX3_2
1398 putenv ("LANG=C");
1399 #endif
1401 init_buffer (); /* Init default directory of main buffer. */
1403 init_callproc_1 (); /* Must precede init_cmdargs and init_sys_modes. */
1404 init_cmdargs (argc, argv, skip_args); /* Must precede init_lread. */
1406 if (initialized)
1408 /* Erase any pre-dump messages in the message log, to avoid confusion. */
1409 Lisp_Object old_log_max;
1410 old_log_max = Vmessage_log_max;
1411 XSETFASTINT (Vmessage_log_max, 0);
1412 message_dolog ("", 0, 1, 0);
1413 Vmessage_log_max = old_log_max;
1416 init_callproc (); /* Must follow init_cmdargs but not init_sys_modes. */
1417 init_lread ();
1419 /* Intern the names of all standard functions and variables;
1420 define standard keys. */
1422 if (!initialized)
1424 /* The basic levels of Lisp must come first. */
1425 /* And data must come first of all
1426 for the sake of symbols like error-message. */
1427 #ifndef MAC_OS8
1428 /* Called before init_window_once for Mac OS Classic. */
1429 syms_of_data ();
1430 #endif
1431 syms_of_alloc ();
1432 syms_of_lread ();
1433 syms_of_print ();
1434 syms_of_eval ();
1435 syms_of_fns ();
1436 syms_of_floatfns ();
1438 syms_of_abbrev ();
1439 syms_of_buffer ();
1440 syms_of_bytecode ();
1441 syms_of_callint ();
1442 syms_of_casefiddle ();
1443 syms_of_casetab ();
1444 syms_of_callproc ();
1445 syms_of_category ();
1446 #ifndef MAC_OS8
1447 /* Called before init_window_once for Mac OS Classic. */
1448 syms_of_ccl ();
1449 #endif
1450 syms_of_charset ();
1451 syms_of_cmds ();
1452 #ifndef NO_DIR_LIBRARY
1453 syms_of_dired ();
1454 #endif /* not NO_DIR_LIBRARY */
1455 syms_of_display ();
1456 syms_of_doc ();
1457 syms_of_editfns ();
1458 syms_of_emacs ();
1459 syms_of_fileio ();
1460 syms_of_coding (); /* This should be after syms_of_fileio. */
1461 #ifdef CLASH_DETECTION
1462 syms_of_filelock ();
1463 #endif /* CLASH_DETECTION */
1464 syms_of_indent ();
1465 syms_of_insdel ();
1466 syms_of_keymap ();
1467 syms_of_macros ();
1468 syms_of_marker ();
1469 syms_of_minibuf ();
1470 syms_of_process ();
1471 #ifndef MAC_OS8
1472 /* Called before init_window_once for Mac OS Classic. */
1473 syms_of_search ();
1474 syms_of_frame ();
1475 #endif
1476 syms_of_syntax ();
1477 syms_of_term ();
1478 syms_of_undo ();
1479 #ifdef HAVE_SOUND
1480 syms_of_sound ();
1481 #endif
1482 #ifndef MAC_OS8
1483 /* Called before init_window_once for Mac OS Classic. */
1484 syms_of_textprop ();
1485 #endif
1486 syms_of_composite ();
1487 #ifdef VMS
1488 syms_of_vmsproc ();
1489 #endif /* VMS */
1490 #ifdef WINDOWSNT
1491 syms_of_ntproc ();
1492 #endif /* WINDOWSNT */
1493 syms_of_window ();
1494 syms_of_xdisp ();
1495 #ifdef HAVE_X_WINDOWS
1496 syms_of_xterm ();
1497 syms_of_xfns ();
1498 syms_of_fontset ();
1499 #ifdef HAVE_X_SM
1500 syms_of_xsmfns ();
1501 #endif
1502 #ifdef HAVE_X11
1503 syms_of_xselect ();
1504 #endif
1505 #endif /* HAVE_X_WINDOWS */
1507 #ifndef HAVE_NTGUI
1508 #ifndef MAC_OS
1509 /* Called before init_window_once for Mac OS Classic. */
1510 syms_of_xmenu ();
1511 #endif
1512 #endif
1514 #ifdef HAVE_NTGUI
1515 syms_of_w32term ();
1516 syms_of_w32fns ();
1517 syms_of_w32select ();
1518 syms_of_w32menu ();
1519 syms_of_fontset ();
1520 #endif /* HAVE_NTGUI */
1522 #ifdef HAVE_CARBON
1523 syms_of_macterm ();
1524 syms_of_macfns ();
1525 syms_of_macmenu ();
1526 syms_of_fontset ();
1527 #endif /* HAVE_CARBON */
1529 #ifdef SYMS_SYSTEM
1530 SYMS_SYSTEM;
1531 #endif
1533 #ifdef SYMS_MACHINE
1534 SYMS_MACHINE;
1535 #endif
1537 keys_of_casefiddle ();
1538 keys_of_cmds ();
1539 keys_of_buffer ();
1540 keys_of_keyboard ();
1541 keys_of_keymap ();
1542 keys_of_minibuf ();
1543 keys_of_window ();
1545 else
1548 Initialization that must be done even if the global variable
1549 initialized is non zero
1551 #ifdef HAVE_NTGUI
1552 globals_of_w32fns ();
1553 globals_of_w32menu ();
1554 #endif /* end #ifdef HAVE_NTGUI */
1557 if (!noninteractive)
1559 #ifdef VMS
1560 init_vms_input ();/* init_display calls get_frame_size, that needs this. */
1561 #endif /* VMS */
1562 init_display (); /* Determine terminal type. init_sys_modes uses results. */
1564 #ifndef MAC_OS8
1565 /* Called before init_window_once for Mac OS Classic. */
1566 init_keyboard (); /* This too must precede init_sys_modes. */
1567 #endif
1568 #ifdef VMS
1569 init_vmsproc (); /* And this too. */
1570 #endif /* VMS */
1571 init_sys_modes (); /* Init system terminal modes (RAW or CBREAK, etc.). */
1572 #if defined (HAVE_X_WINDOWS) || defined (WINDOWSNT)
1573 init_xfns ();
1574 #endif /* HAVE_X_WINDOWS */
1575 init_fns ();
1576 init_xdisp ();
1577 init_macros ();
1578 init_editfns ();
1579 init_floatfns ();
1580 #ifdef VMS
1581 init_vmsfns ();
1582 #endif /* VMS */
1583 init_process ();
1584 #ifdef HAVE_SOUND
1585 init_sound ();
1586 #endif
1587 init_window ();
1589 if (!initialized)
1591 char *file;
1592 /* Handle -l loadup, args passed by Makefile. */
1593 if (argmatch (argv, argc, "-l", "--load", 3, &file, &skip_args))
1594 Vtop_level = Fcons (intern ("load"),
1595 Fcons (build_string (file), Qnil));
1596 /* Unless next switch is -nl, load "loadup.el" first thing. */
1597 if (! no_loadup)
1598 Vtop_level = Fcons (intern ("load"),
1599 Fcons (build_string ("loadup.el"), Qnil));
1602 if (initialized)
1604 #ifdef HAVE_TZSET
1606 /* If the execution TZ happens to be the same as the dump TZ,
1607 change it to some other value and then change it back,
1608 to force the underlying implementation to reload the TZ info.
1609 This is needed on implementations that load TZ info from files,
1610 since the TZ file contents may differ between dump and execution. */
1611 char *tz = getenv ("TZ");
1612 if (tz && !strcmp (tz, dump_tz))
1614 ++*tz;
1615 tzset ();
1616 --*tz;
1619 #endif
1622 /* Set up for profiling. This is known to work on FreeBSD and
1623 GNU/Linux. It might work on some other systems too. Give it a
1624 try and tell us if it works on your system. To compile for
1625 profiling use something like `make CFLAGS="-pg -g -O -DPROFILING=1'. */
1626 #if defined (__FreeBSD__) || defined (__linux)
1627 #ifdef PROFILING
1628 if (initialized)
1630 extern void _mcleanup ();
1631 extern char etext;
1632 extern void safe_bcopy ();
1633 extern void dump_opcode_frequencies ();
1635 atexit (_mcleanup);
1636 /* This uses safe_bcopy because that function comes first in the
1637 Emacs executable. It might be better to use something that
1638 gives the start of the text segment, but start_of_text is not
1639 defined on all systems now. */
1640 monstartup (safe_bcopy, &etext);
1642 else
1643 moncontrol (0);
1644 #endif
1645 #endif
1647 initialized = 1;
1649 #ifdef LOCALTIME_CACHE
1650 /* Some versions of localtime have a bug. They cache the value of the time
1651 zone rather than looking it up every time. Since localtime() is
1652 called to bolt the undumping time into the undumped emacs, this
1653 results in localtime ignoring the TZ environment variable.
1654 This flushes the new TZ value into localtime. */
1655 tzset ();
1656 #endif /* defined (LOCALTIME_CACHE) */
1658 /* Enter editor command loop. This never returns. */
1659 Frecursive_edit ();
1660 /* NOTREACHED */
1661 return 0;
1664 /* Sort the args so we can find the most important ones
1665 at the beginning of argv. */
1667 /* First, here's a table of all the standard options. */
1669 struct standard_args
1671 char *name;
1672 char *longname;
1673 int priority;
1674 int nargs;
1677 struct standard_args standard_args[] =
1679 { "-version", "--version", 150, 0 },
1680 #ifdef HAVE_SHM
1681 { "-nl", "--no-shared-memory", 140, 0 },
1682 #endif
1683 #ifdef VMS
1684 { "-map", "--map-data", 130, 0 },
1685 #endif
1686 { "-t", "--terminal", 120, 1 },
1687 { "-nw", "--no-window-system", 110, 0 },
1688 { "-nw", "--no-windows", 110, 0 },
1689 { "-batch", "--batch", 100, 0 },
1690 { "-script", "--script", 100, 1 },
1691 { "-help", "--help", 90, 0 },
1692 { "-no-unibyte", "--no-unibyte", 83, 0 },
1693 { "-multibyte", "--multibyte", 82, 0 },
1694 { "-unibyte", "--unibyte", 81, 0 },
1695 { "-no-multibyte", "--no-multibyte", 80, 0 },
1696 { "-nl", "--no-loadup", 70, 0 },
1697 /* -d must come last before the options handled in startup.el. */
1698 { "-d", "--display", 60, 1 },
1699 { "-display", 0, 60, 1 },
1700 /* Now for the options handled in startup.el. */
1701 { "-q", "--no-init-file", 50, 0 },
1702 { "-no-init-file", 0, 50, 0 },
1703 { "-no-site-file", "--no-site-file", 40, 0 },
1704 { "-no-splash", "--no-splash", 40, 0 },
1705 { "-u", "--user", 30, 1 },
1706 { "-user", 0, 30, 1 },
1707 { "-debug-init", "--debug-init", 20, 0 },
1708 { "-i", "--icon-type", 15, 0 },
1709 { "-itype", 0, 15, 0 },
1710 { "-iconic", "--iconic", 15, 0 },
1711 { "-bg", "--background-color", 10, 1 },
1712 { "-background", 0, 10, 1 },
1713 { "-fg", "--foreground-color", 10, 1 },
1714 { "-foreground", 0, 10, 1 },
1715 { "-bd", "--border-color", 10, 1 },
1716 { "-bw", "--border-width", 10, 1 },
1717 { "-ib", "--internal-border", 10, 1 },
1718 { "-ms", "--mouse-color", 10, 1 },
1719 { "-cr", "--cursor-color", 10, 1 },
1720 { "-fn", "--font", 10, 1 },
1721 { "-font", 0, 10, 1 },
1722 { "-fs", "--fullscreen", 10, 0 },
1723 { "-fw", "--fullwidth", 10, 0 },
1724 { "-fh", "--fullheight", 10, 0 },
1725 { "-g", "--geometry", 10, 1 },
1726 { "-geometry", 0, 10, 1 },
1727 { "-T", "--title", 10, 1 },
1728 { "-title", 0, 10, 1 },
1729 { "-name", "--name", 10, 1 },
1730 { "-xrm", "--xrm", 10, 1 },
1731 { "-r", "--reverse-video", 5, 0 },
1732 { "-rv", 0, 5, 0 },
1733 { "-reverse", 0, 5, 0 },
1734 { "-hb", "--horizontal-scroll-bars", 5, 0 },
1735 { "-vb", "--vertical-scroll-bars", 5, 0 },
1736 { "-color", "--color", 5, 0},
1737 /* These have the same priority as ordinary file name args,
1738 so they are not reordered with respect to those. */
1739 { "-L", "--directory", 0, 1 },
1740 { "-directory", 0, 0, 1 },
1741 { "-l", "--load", 0, 1 },
1742 { "-load", 0, 0, 1 },
1743 { "-f", "--funcall", 0, 1 },
1744 { "-funcall", 0, 0, 1 },
1745 { "-eval", "--eval", 0, 1 },
1746 { "-execute", "--execute", 0, 1 },
1747 { "-find-file", "--find-file", 0, 1 },
1748 { "-visit", "--visit", 0, 1 },
1749 { "-file", "--file", 0, 1 },
1750 { "-insert", "--insert", 0, 1 },
1751 /* This should be processed after ordinary file name args and the like. */
1752 { "-kill", "--kill", -10, 0 },
1755 /* Reorder the elements of ARGV (assumed to have ARGC elements)
1756 so that the highest priority ones come first.
1757 Do not change the order of elements of equal priority.
1758 If an option takes an argument, keep it and its argument together.
1760 If an option that takes no argument appears more
1761 than once, eliminate all but one copy of it. */
1763 static void
1764 sort_args (argc, argv)
1765 int argc;
1766 char **argv;
1768 char **new = (char **) xmalloc (sizeof (char *) * argc);
1769 /* For each element of argv,
1770 the corresponding element of options is:
1771 0 for an option that takes no arguments,
1772 1 for an option that takes one argument, etc.
1773 -1 for an ordinary non-option argument. */
1774 int *options = (int *) xmalloc (sizeof (int) * argc);
1775 int *priority = (int *) xmalloc (sizeof (int) * argc);
1776 int to = 1;
1777 int incoming_used = 1;
1778 int from;
1779 int i;
1781 /* Categorize all the options,
1782 and figure out which argv elts are option arguments. */
1783 for (from = 1; from < argc; from++)
1785 options[from] = -1;
1786 priority[from] = 0;
1787 if (argv[from][0] == '-')
1789 int match, thislen;
1790 char *equals;
1792 /* If we have found "--", don't consider
1793 any more arguments as options. */
1794 if (argv[from][1] == '-' && argv[from][2] == 0)
1796 /* Leave the "--", and everything following it, at the end. */
1797 for (; from < argc; from++)
1799 priority[from] = -100;
1800 options[from] = -1;
1802 break;
1805 /* Look for a match with a known old-fashioned option. */
1806 for (i = 0; i < sizeof (standard_args) / sizeof (standard_args[0]); i++)
1807 if (!strcmp (argv[from], standard_args[i].name))
1809 options[from] = standard_args[i].nargs;
1810 priority[from] = standard_args[i].priority;
1811 if (from + standard_args[i].nargs >= argc)
1812 fatal ("Option `%s' requires an argument\n", argv[from]);
1813 from += standard_args[i].nargs;
1814 goto done;
1817 /* Look for a match with a known long option.
1818 MATCH is -1 if no match so far, -2 if two or more matches so far,
1819 >= 0 (the table index of the match) if just one match so far. */
1820 if (argv[from][1] == '-')
1822 match = -1;
1823 thislen = strlen (argv[from]);
1824 equals = index (argv[from], '=');
1825 if (equals != 0)
1826 thislen = equals - argv[from];
1828 for (i = 0;
1829 i < sizeof (standard_args) / sizeof (standard_args[0]); i++)
1830 if (standard_args[i].longname
1831 && !strncmp (argv[from], standard_args[i].longname,
1832 thislen))
1834 if (match == -1)
1835 match = i;
1836 else
1837 match = -2;
1840 /* If we found exactly one match, use that. */
1841 if (match >= 0)
1843 options[from] = standard_args[match].nargs;
1844 priority[from] = standard_args[match].priority;
1845 /* If --OPTION=VALUE syntax is used,
1846 this option uses just one argv element. */
1847 if (equals != 0)
1848 options[from] = 0;
1849 if (from + options[from] >= argc)
1850 fatal ("Option `%s' requires an argument\n", argv[from]);
1851 from += options[from];
1854 done: ;
1858 /* Copy the arguments, in order of decreasing priority, to NEW. */
1859 new[0] = argv[0];
1860 while (incoming_used < argc)
1862 int best = -1;
1863 int best_priority = -9999;
1865 /* Find the highest priority remaining option.
1866 If several have equal priority, take the first of them. */
1867 for (from = 1; from < argc; from++)
1869 if (argv[from] != 0 && priority[from] > best_priority)
1871 best_priority = priority[from];
1872 best = from;
1874 /* Skip option arguments--they are tied to the options. */
1875 if (options[from] > 0)
1876 from += options[from];
1879 if (best < 0)
1880 abort ();
1882 /* Copy the highest priority remaining option, with its args, to NEW.
1883 Unless it is a duplicate of the previous one. */
1884 if (! (options[best] == 0
1885 && ! strcmp (new[to - 1], argv[best])))
1887 new[to++] = argv[best];
1888 for (i = 0; i < options[best]; i++)
1889 new[to++] = argv[best + i + 1];
1892 incoming_used += 1 + (options[best] > 0 ? options[best] : 0);
1894 /* Clear out this option in ARGV. */
1895 argv[best] = 0;
1896 for (i = 0; i < options[best]; i++)
1897 argv[best + i + 1] = 0;
1900 /* If duplicate options were deleted, fill up extra space with null ptrs. */
1901 while (to < argc)
1902 new[to++] = 0;
1904 bcopy (new, argv, sizeof (char *) * argc);
1906 free (options);
1907 free (new);
1908 free (priority);
1911 DEFUN ("kill-emacs", Fkill_emacs, Skill_emacs, 0, 1, "P",
1912 doc: /* Exit the Emacs job and kill it.
1913 If ARG is an integer, return ARG as the exit program code.
1914 If ARG is a string, stuff it as keyboard input.
1916 The value of `kill-emacs-hook', if not void,
1917 is a list of functions (of no args),
1918 all of which are called before Emacs is actually killed. */)
1919 (arg)
1920 Lisp_Object arg;
1922 struct gcpro gcpro1;
1924 GCPRO1 (arg);
1926 if (feof (stdin))
1927 arg = Qt;
1929 if (!NILP (Vrun_hooks) && !noninteractive)
1930 call1 (Vrun_hooks, intern ("kill-emacs-hook"));
1932 UNGCPRO;
1934 /* Is it really necessary to do this deassign
1935 when we are going to exit anyway? */
1936 /* #ifdef VMS
1937 stop_vms_input ();
1938 #endif */
1940 shut_down_emacs (0, 0, STRINGP (arg) ? arg : Qnil);
1942 /* If we have an auto-save list file,
1943 kill it because we are exiting Emacs deliberately (not crashing).
1944 Do it after shut_down_emacs, which does an auto-save. */
1945 if (STRINGP (Vauto_save_list_file_name))
1946 unlink (SDATA (Vauto_save_list_file_name));
1948 exit (INTEGERP (arg) ? XINT (arg)
1949 #ifdef VMS
1951 #else
1953 #endif
1955 /* NOTREACHED */
1959 /* Perform an orderly shutdown of Emacs. Autosave any modified
1960 buffers, kill any child processes, clean up the terminal modes (if
1961 we're in the foreground), and other stuff like that. Don't perform
1962 any redisplay; this may be called when Emacs is shutting down in
1963 the background, or after its X connection has died.
1965 If SIG is a signal number, print a message for it.
1967 This is called by fatal signal handlers, X protocol error handlers,
1968 and Fkill_emacs. */
1970 void
1971 shut_down_emacs (sig, no_x, stuff)
1972 int sig, no_x;
1973 Lisp_Object stuff;
1975 /* Prevent running of hooks from now on. */
1976 Vrun_hooks = Qnil;
1978 /* If we are controlling the terminal, reset terminal modes. */
1979 #ifdef EMACS_HAVE_TTY_PGRP
1981 int pgrp = EMACS_GETPGRP (0);
1983 int tpgrp;
1984 if (EMACS_GET_TTY_PGRP (0, &tpgrp) != -1
1985 && tpgrp == pgrp)
1987 fflush (stdout);
1988 reset_sys_modes ();
1989 if (sig && sig != SIGTERM)
1990 fprintf (stderr, "Fatal error (%d).", sig);
1993 #else
1994 fflush (stdout);
1995 reset_sys_modes ();
1996 #endif
1998 stuff_buffered_input (stuff);
2000 kill_buffer_processes (Qnil);
2001 Fdo_auto_save (Qt, Qnil);
2003 #ifdef CLASH_DETECTION
2004 unlock_all_files ();
2005 #endif
2007 #ifdef VMS
2008 kill_vms_processes ();
2009 #endif
2011 #if 0 /* This triggers a bug in XCloseDisplay and is not needed. */
2012 #ifdef HAVE_X_WINDOWS
2013 /* It's not safe to call intern here. Maybe we are crashing. */
2014 if (!noninteractive && SYMBOLP (Vwindow_system)
2015 && SCHARS (SYMBOL_NAME (Vwindow_system)) == 1
2016 && SREF (SYMBOL_NAME (Vwindow_system), 0) == 'x'
2017 && ! no_x)
2018 Fx_close_current_connection ();
2019 #endif /* HAVE_X_WINDOWS */
2020 #endif
2022 #ifdef SIGIO
2023 /* There is a tendency for a SIGIO signal to arrive within exit,
2024 and cause a SIGHUP because the input descriptor is already closed. */
2025 unrequest_sigio ();
2026 signal (SIGIO, SIG_IGN);
2027 #endif
2029 #ifdef WINDOWSNT
2030 term_ntproc ();
2031 #endif
2033 /* Do this only if terminating normally, we want glyph matrices
2034 etc. in a core dump. */
2035 if (sig == 0 || sig == SIGTERM)
2037 check_glyph_memory ();
2038 check_message_stack ();
2041 #ifdef MSDOS
2042 dos_cleanup ();
2043 #endif
2048 #ifndef CANNOT_DUMP
2050 #ifdef HAVE_SHM
2052 DEFUN ("dump-emacs-data", Fdump_emacs_data, Sdump_emacs_data, 1, 1, 0,
2053 doc: /* Dump current state of Emacs into data file FILENAME.
2054 This function exists on systems that use HAVE_SHM. */)
2055 (filename)
2056 Lisp_Object filename;
2058 extern char my_edata[];
2059 Lisp_Object tem;
2061 check_pure_size ();
2062 CHECK_STRING (filename);
2063 filename = Fexpand_file_name (filename, Qnil);
2065 tem = Vpurify_flag;
2066 Vpurify_flag = Qnil;
2068 fflush (stdout);
2069 /* Tell malloc where start of impure now is. */
2070 /* Also arrange for warnings when nearly out of space. */
2071 #ifndef SYSTEM_MALLOC
2072 memory_warnings (my_edata, malloc_warning);
2073 #endif
2074 map_out_data (SDATA (filename));
2076 Vpurify_flag = tem;
2078 return Qnil;
2081 #else /* not HAVE_SHM */
2083 DEFUN ("dump-emacs", Fdump_emacs, Sdump_emacs, 2, 2, 0,
2084 doc: /* Dump current state of Emacs into executable file FILENAME.
2085 Take symbols from SYMFILE (presumably the file you executed to run Emacs).
2086 This is used in the file `loadup.el' when building Emacs.
2088 You must run Emacs in batch mode in order to dump it. */)
2089 (filename, symfile)
2090 Lisp_Object filename, symfile;
2092 extern char my_edata[];
2093 Lisp_Object tem;
2094 Lisp_Object symbol;
2095 int count = SPECPDL_INDEX ();
2097 check_pure_size ();
2099 if (! noninteractive)
2100 error ("Dumping Emacs works only in batch mode");
2102 /* Bind `command-line-processed' to nil before dumping,
2103 so that the dumped Emacs will process its command line
2104 and set up to work with X windows if appropriate. */
2105 symbol = intern ("command-line-processed");
2106 specbind (symbol, Qnil);
2108 CHECK_STRING (filename);
2109 filename = Fexpand_file_name (filename, Qnil);
2110 if (!NILP (symfile))
2112 CHECK_STRING (symfile);
2113 if (SCHARS (symfile))
2114 symfile = Fexpand_file_name (symfile, Qnil);
2117 tem = Vpurify_flag;
2118 Vpurify_flag = Qnil;
2120 #ifdef HAVE_TZSET
2121 set_time_zone_rule (dump_tz);
2122 #ifndef LOCALTIME_CACHE
2123 /* Force a tz reload, since set_time_zone_rule doesn't. */
2124 tzset ();
2125 #endif
2126 #endif
2128 fflush (stdout);
2129 #ifdef VMS
2130 mapout_data (SDATA (filename));
2131 #else
2132 /* Tell malloc where start of impure now is. */
2133 /* Also arrange for warnings when nearly out of space. */
2134 #ifndef SYSTEM_MALLOC
2135 #ifndef WINDOWSNT
2136 /* On Windows, this was done before dumping, and that once suffices.
2137 Meanwhile, my_edata is not valid on Windows. */
2138 memory_warnings (my_edata, malloc_warning);
2139 #endif /* not WINDOWSNT */
2140 #endif
2141 #ifdef DOUG_LEA_MALLOC
2142 malloc_state_ptr = malloc_get_state ();
2143 #endif
2145 #ifdef USE_MMAP_FOR_BUFFERS
2146 mmap_set_vars (0);
2147 #endif
2148 unexec (SDATA (filename),
2149 !NILP (symfile) ? SDATA (symfile) : 0, my_edata, 0, 0);
2150 #ifdef USE_MMAP_FOR_BUFFERS
2151 mmap_set_vars (1);
2152 #endif
2153 #ifdef DOUG_LEA_MALLOC
2154 free (malloc_state_ptr);
2155 #endif
2156 #endif /* not VMS */
2158 Vpurify_flag = tem;
2160 return unbind_to (count, Qnil);
2163 #endif /* not HAVE_SHM */
2165 #endif /* not CANNOT_DUMP */
2167 #if HAVE_SETLOCALE
2168 /* Recover from setlocale (LC_ALL, ""). */
2169 void
2170 fixup_locale ()
2172 /* The Emacs Lisp reader needs LC_NUMERIC to be "C",
2173 so that numbers are read and printed properly for Emacs Lisp. */
2174 setlocale (LC_NUMERIC, "C");
2177 /* Set system locale CATEGORY, with previous locale *PLOCALE, to
2178 DESIRED_LOCALE. */
2179 static void
2180 synchronize_locale (category, plocale, desired_locale)
2181 int category;
2182 Lisp_Object *plocale;
2183 Lisp_Object desired_locale;
2185 if (! EQ (*plocale, desired_locale))
2187 *plocale = desired_locale;
2188 setlocale (category, (STRINGP (desired_locale)
2189 ? (char *)(SDATA (desired_locale))
2190 : ""));
2194 /* Set system time locale to match Vsystem_time_locale, if possible. */
2195 void
2196 synchronize_system_time_locale ()
2198 synchronize_locale (LC_TIME, &Vprevious_system_time_locale,
2199 Vsystem_time_locale);
2202 /* Set system messages locale to match Vsystem_messages_locale, if
2203 possible. */
2204 void
2205 synchronize_system_messages_locale ()
2207 #ifdef LC_MESSAGES
2208 synchronize_locale (LC_MESSAGES, &Vprevious_system_messages_locale,
2209 Vsystem_messages_locale);
2210 #endif
2212 #endif /* HAVE_SETLOCALE */
2214 #ifndef SEPCHAR
2215 #define SEPCHAR ':'
2216 #endif
2218 Lisp_Object
2219 decode_env_path (evarname, defalt)
2220 char *evarname, *defalt;
2222 register char *path, *p;
2223 Lisp_Object lpath, element, tem;
2225 /* It's okay to use getenv here, because this function is only used
2226 to initialize variables when Emacs starts up, and isn't called
2227 after that. */
2228 if (evarname != 0)
2229 path = (char *) getenv (evarname);
2230 else
2231 path = 0;
2232 if (!path)
2233 path = defalt;
2234 #ifdef DOS_NT
2235 /* Ensure values from the environment use the proper directory separator. */
2236 if (path)
2238 p = alloca (strlen (path) + 1);
2239 strcpy (p, path);
2240 path = p;
2242 if ('/' == DIRECTORY_SEP)
2243 dostounix_filename (path);
2244 else
2245 unixtodos_filename (path);
2247 #endif
2248 lpath = Qnil;
2249 while (1)
2251 p = index (path, SEPCHAR);
2252 if (!p) p = path + strlen (path);
2253 element = (p - path ? make_string (path, p - path)
2254 : build_string ("."));
2256 /* Add /: to the front of the name
2257 if it would otherwise be treated as magic. */
2258 tem = Ffind_file_name_handler (element, Qt);
2260 /* However, if the handler says "I'm safe",
2261 don't bother adding /:. */
2262 if (SYMBOLP (tem))
2264 Lisp_Object prop;
2265 prop = Fget (tem, intern ("safe-magic"));
2266 if (! NILP (prop))
2267 tem = Qnil;
2270 if (! NILP (tem))
2271 element = concat2 (build_string ("/:"), element);
2273 lpath = Fcons (element, lpath);
2274 if (*p)
2275 path = p + 1;
2276 else
2277 break;
2279 return Fnreverse (lpath);
2282 void
2283 syms_of_emacs ()
2285 Qfile_name_handler_alist = intern ("file-name-handler-alist");
2286 staticpro (&Qfile_name_handler_alist);
2288 #ifndef CANNOT_DUMP
2289 #ifdef HAVE_SHM
2290 defsubr (&Sdump_emacs_data);
2291 #else
2292 defsubr (&Sdump_emacs);
2293 #endif
2294 #endif
2296 defsubr (&Skill_emacs);
2298 defsubr (&Sinvocation_name);
2299 defsubr (&Sinvocation_directory);
2301 DEFVAR_LISP ("command-line-args", &Vcommand_line_args,
2302 doc: /* Args passed by shell to Emacs, as a list of strings.
2303 Many arguments are deleted from the list as they are processed. */);
2305 DEFVAR_LISP ("system-type", &Vsystem_type,
2306 doc: /* Value is symbol indicating type of operating system you are using. */);
2307 Vsystem_type = intern (SYSTEM_TYPE);
2309 DEFVAR_LISP ("system-configuration", &Vsystem_configuration,
2310 doc: /* Value is string indicating configuration Emacs was built for.
2311 On MS-Windows, the value reflects the OS flavor and version on which
2312 Emacs is running. */);
2313 Vsystem_configuration = build_string (EMACS_CONFIGURATION);
2315 DEFVAR_LISP ("system-configuration-options", &Vsystem_configuration_options,
2316 doc: /* String containing the configuration options Emacs was built with. */);
2317 Vsystem_configuration_options = build_string (EMACS_CONFIG_OPTIONS);
2319 DEFVAR_BOOL ("noninteractive", &noninteractive1,
2320 doc: /* Non-nil means Emacs is running without interactive terminal. */);
2322 DEFVAR_LISP ("kill-emacs-hook", &Vkill_emacs_hook,
2323 doc: /* Hook to be run when kill-emacs is called.
2324 Since `kill-emacs' may be invoked when the terminal is disconnected (or
2325 in other similar situations), functions placed on this hook should not
2326 expect to be able to interact with the user. To ask for confirmation,
2327 see `kill-emacs-query-functions' instead.
2329 The hook is not run in batch mode, i.e., if `noninteractive' is non-nil. */);
2330 Vkill_emacs_hook = Qnil;
2332 empty_string = build_string ("");
2333 staticpro (&empty_string);
2335 #ifdef SIGUSR1
2336 DEFVAR_LISP ("signal-USR1-hook", &Vsignal_USR1_hook,
2337 doc: /* Hook to be run whenever emacs receives a USR1 signal. */);
2338 Vsignal_USR1_hook = Qnil;
2339 #ifdef SIGUSR2
2340 DEFVAR_LISP ("signal-USR2-hook", &Vsignal_USR2_hook,
2341 doc: /* Hook to be run whenever emacs receives a USR2 signal. */);
2342 Vsignal_USR2_hook = Qnil;
2343 #endif
2344 #endif
2347 DEFVAR_INT ("emacs-priority", &emacs_priority,
2348 doc: /* Priority for Emacs to run at.
2349 This value is effective only if set before Emacs is dumped,
2350 and only if the Emacs executable is installed with setuid to permit
2351 it to change priority. (Emacs sets its uid back to the real uid.)
2352 Currently, you need to define SET_EMACS_PRIORITY in `config.h'
2353 before you compile Emacs, to enable the code for this feature. */);
2354 emacs_priority = 0;
2356 DEFVAR_LISP ("path-separator", &Vpath_separator,
2357 doc: /* The directory separator in search paths, as a string. */);
2359 char c = SEPCHAR;
2360 Vpath_separator = make_string (&c, 1);
2363 DEFVAR_LISP ("invocation-name", &Vinvocation_name,
2364 doc: /* The program name that was used to run Emacs.
2365 Any directory names are omitted. */);
2367 DEFVAR_LISP ("invocation-directory", &Vinvocation_directory,
2368 doc: /* The directory in which the Emacs executable was found, to run it.
2369 The value is nil if that directory's name is not known. */);
2371 DEFVAR_LISP ("installation-directory", &Vinstallation_directory,
2372 doc: /* A directory within which to look for the `lib-src' and `etc' directories.
2373 This is non-nil when we can't find those directories in their standard
2374 installed locations, but we can find them
2375 near where the Emacs executable was found. */);
2376 Vinstallation_directory = Qnil;
2378 DEFVAR_LISP ("system-messages-locale", &Vsystem_messages_locale,
2379 doc: /* System locale for messages. */);
2380 Vsystem_messages_locale = Qnil;
2382 DEFVAR_LISP ("previous-system-messages-locale",
2383 &Vprevious_system_messages_locale,
2384 doc: /* Most recently used system locale for messages. */);
2385 Vprevious_system_messages_locale = Qnil;
2387 DEFVAR_LISP ("system-time-locale", &Vsystem_time_locale,
2388 doc: /* System locale for time. */);
2389 Vsystem_time_locale = Qnil;
2391 DEFVAR_LISP ("previous-system-time-locale", &Vprevious_system_time_locale,
2392 doc: /* Most recently used system locale for time. */);
2393 Vprevious_system_time_locale = Qnil;