1 /* SXEmacs -- Fully extensible Emacs, running on Unix and other platforms.
2 Copyright (C) 1985, 1986, 1987, 1992, 1993, 1994
3 Free Software Foundation, Inc.
4 Copyright (C) 1995 Sun Microsystems, Inc.
5 Copyright (C) 2000, 2002 Ben Wing.
6 Copyright (C) 2004 Steve Youngs.
8 This file is part of SXEmacs
10 SXEmacs is free software: you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation, either version 3 of the License, or
13 (at your option) any later version.
15 SXEmacs is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 /* Synched up with: Mule 2.0, FSF 19.28. */
26 /* Capsule summary of the various releases of Lucid Emacs/SXEmacs and
27 FSF/GNU Emacs. Provided here for use in cross-referencing version
28 releases and dates in comments, esp. in the authorship comments at
29 the beginning of each file. More information about history can be
30 found in the beginning of the Internals Manual and in the About page.
32 -- A time line for Lucid Emacs/XEmacs is
34 version 19.0 shipped with Energize 1.0, April 1992.
35 version 19.1 released June 4, 1992.
36 version 19.2 released June 19, 1992.
37 version 19.3 released September 9, 1992.
38 version 19.4 released January 21, 1993.
39 version 19.5 was a repackaging of 19.4 with a few bug fixes and
40 shipped with Energize 2.0. Never released to the net.
41 version 19.6 released April 9, 1993.
42 version 19.7 was a repackaging of 19.6 with a few bug fixes and
43 shipped with Energize 2.1. Never released to the net.
44 version 19.8 released September 6, 1993.
45 version 19.9 released January 12, 1994.
46 version 19.10 released May 27, 1994.
47 version 19.11 (first XEmacs) released September 13, 1994.
48 version 19.12 released June 23, 1995.
49 version 19.13 released September 1, 1995.
50 version 19.14 released June 23, 1996.
51 version 20.0 released February 9, 1997.
52 version 19.15 released March 28, 1997.
53 version 20.1 (not released to the net) April 15, 1997.
54 version 20.2 released May 16, 1997.
55 version 19.16 released October 31, 1997.
56 version 20.3 (the first stable version of XEmacs 20.x) released
58 version 20.4 released February 28, 1998.
60 -- A time line for GNU Emacs version 19 is
62 version 19.7 (beta) (first beta release) released May 22, 1993.
63 version 19.8 (beta) released May 27, 1993.
64 version 19.9 (beta) released May 27, 1993.
65 version 19.10 (beta) released May 30, 1993.
66 version 19.11 (beta) released June 1, 1993.
67 version 19.12 (beta) released June 2, 1993.
68 version 19.13 (beta) released June 8, 1993.
69 version 19.14 (beta) released June 17, 1993.
70 version 19.15 (beta) released June 19, 1993.
71 version 19.16 (beta) released July 6, 1993.
72 version 19.17 (beta) released late July, 1993.
73 version 19.18 (beta) released August 9, 1993.
74 version 19.19 (beta) released August 15, 1993.
75 version 19.20 (beta) released November 17, 1993.
76 version 19.21 (beta) released November 17, 1993.
77 version 19.22 (beta) released November 28, 1993.
78 version 19.23 (beta) released May 17, 1994.
79 version 19.24 (beta) released May 16, 1994.
80 version 19.25 (beta) released June 3, 1994.
81 version 19.26 (beta) released September 11, 1994.
82 version 19.27 (beta) released September 14, 1994.
83 version 19.28 (first ``official'' release) released November 1, 1994.
84 version 19.29 released June 21, 1995.
85 version 19.30 released November 24, 1995.
86 version 19.31 released May 25, 1996.
87 version 19.32 released July 31, 1996.
88 version 19.33 released August 11, 1996.
89 version 19.34 released August 21, 1996.
90 version 19.34b released September 6, 1996.
92 -- A time line for GNU Emacs version 20 is
94 version 20.1 released September 17, 1997.
95 version 20.2 released September 20, 1997.
96 version 20.3 released August 19, 1998.
98 -- A time line for GNU Emacs version 18 and older is
100 GNU Emacs version 13 (the first public release) was released on
102 GNU Emacs version 15 (15.34) was released on May 7, 1985 and
103 shared some code with a version of Emacs written by James Gosling (the
104 same James Gosling who later created the Java language).
105 GNU Emacs version 16 (first released version was 16.56) was released on
106 July 15, 1985. All Gosling code was removed due to potential copyright
107 problems with the code.
108 version 16.57: released on September 16, 1985.
109 versions 16.58, 16.59: released on September 17, 1985.
110 version 16.60: released on September 19, 1985. These later version 16's
111 incorporated patches from the net, esp. for getting Emacs to work under
113 version 17.36 (first official v17 release) released on December 20, 1985.
114 Included a TeX-able user manual. First official unpatched version that
115 worked on vanilla System V machines.
116 version 17.43 (second official v17 release) released on January 25, 1986.
117 version 17.45 released on January 30, 1986.
118 version 17.46 released on February 4, 1986.
119 version 17.48 released on February 10, 1986.
120 version 17.49 released on February 12, 1986.
121 version 17.55 released on March 18, 1986.
122 version 17.57 released on March 27, 1986.
123 version 17.58 released on April 4, 1986.
124 version 17.61 released on April 12, 1986.
125 version 17.63 released on May 7, 1986.
126 version 17.64 released on May 12, 1986.
127 version 18.24 (a beta version) released on October 2, 1986.
128 version 18.30 (a beta version) released on November 15, 1986.
129 version 18.31 (a beta version) released on November 23, 1986.
130 version 18.32 (a beta version) released on December 7, 1986.
131 version 18.33 (a beta version) released on December 12, 1986.
132 version 18.35 (a beta version) released on January 5, 1987.
133 version 18.36 (a beta version) released on January 21, 1987.
134 January 27, 1987: The Great Usenet Renaming. net.emacs is now comp.emacs.
135 version 18.37 (a beta version) released on February 12, 1987.
136 version 18.38 (a beta version) released on March 3, 1987.
137 version 18.39 (a beta version) released on March 14, 1987.
138 version 18.40 (a beta version) released on March 18, 1987.
139 version 18.41 (the first ``official'' release) released on March 22, 1987.
140 version 18.45 released on June 2, 1987.
141 version 18.46 released on June 9, 1987.
142 version 18.47 released on June 18, 1987.
143 version 18.48 released on September 3, 1987.
144 version 18.49 released on September 18, 1987.
145 version 18.50 released on February 13, 1988.
146 version 18.51 released on May 7, 1988.
147 version 18.52 released on September 1, 1988.
148 version 18.53 released on February 24, 1989.
149 version 18.54 released on April 26, 1989.
150 version 18.55 released on August 23, 1989. This is the earliest version
151 that is still available by FTP.
152 version 18.56 released on January 17, 1991.
153 version 18.57 released late January, 1991.
154 version 18.58 released ?????.
155 version 18.59 released October 31, 1992.
159 /* Note: It is necessary to specify <config.h> and not "config.h" in
160 order for the --srcdir type of compilation to work properly.
161 Otherwise the config.h from the srcdir, rather than the one from
162 the build dir, will be used. */
167 #include "backtrace.h" /* run-emacs-from-temacs needs this */
169 #include "commands.h"
170 #include "ui/console.h"
172 #include "ui/redisplay.h"
173 #include "ui/frame.h"
176 #include "syssignal.h" /* Always include before systty.h */
177 #include "ui/systty.h"
181 #if defined WITH_EMODULES && defined HAVE_EMODULES
182 # include "emodules-ng.h"
194 #include <quantify.h>
197 #if defined WITH_EMODULES && defined HAVE_EMODULES && 0
201 #if defined (HAVE_LOCALE_H) && \
202 (defined (I18N2) || defined (I18N3) || defined (I18N4))
207 #include <sxe-paths.h>
209 /* for stack exploitation */
210 #if defined HAVE_SYS_RESOURCE_H
211 # include <sys/resource.h>
214 /* for the reinit funs */
215 #include "skiplist.h"
219 #if defined HAVE_BDWGC && defined EF_USE_BDWGC
220 # if defined HAVE_GC_GC_H
222 # elif defined HAVE_GC_H
225 /* declare the 3 funs we need */
226 extern void *GC_init(void);
228 # error Go back to your planet!
230 #endif /* HAVE_BDWGC */
232 #if defined (HEAP_IN_DATA) && !defined(PDUMP)
233 void report_sheap_usage(int die_if_pure_storage_exceeded);
236 #if !defined (SYSTEM_MALLOC) && !defined (DOUG_LEA_MALLOC)
237 extern void *(*__malloc_hook) (size_t);
238 extern void *(*__realloc_hook) (void *, size_t);
239 extern void (*__free_hook) (void *);
240 #endif /* not SYSTEM_MALLOC && not DOUG_LEA_MALLOC */
242 /* Command line args from shell, as list of strings */
243 Lisp_Object Vcommand_line_args;
245 /* Set nonzero after SXEmacs has started up the first time.
246 Prevents reinitialization of the Lisp world and keymaps
247 on subsequent starts. */
250 #ifdef DOUG_LEA_MALLOC
252 /* Preserves a pointer to the memory allocated that copies that
253 static data inside glibc's malloc. */
254 static void *malloc_state_ptr;
255 #endif /* DOUG_LEA_MALLOC */
258 void r_alloc_reinit(void);
262 void console_type_create_select_gtk(void);
265 /* Variable whose value is symbol giving operating system type. */
266 Lisp_Object Vsystem_type;
268 /* Variable whose value is string giving configuration built for. */
269 Lisp_Object Vsystem_configuration;
271 /* Variable whose value is string containing the configuration options
272 SXEmacs was built with. */
273 Lisp_Object Vsystem_configuration_options;
275 /* Version numbers and strings */
276 Lisp_Object Vemacs_major_version;
277 Lisp_Object Vemacs_minor_version;
278 Lisp_Object Vemacs_patch_level;
279 Lisp_Object Vemacs_beta_version;
280 Lisp_Object Vsxemacs_git_version;
281 Lisp_Object Vsxemacs_codename;
283 Lisp_Object Vinfodock_major_version;
284 Lisp_Object Vinfodock_minor_version;
285 Lisp_Object Vinfodock_build_version;
288 /* The path under which SXEmacs was invoked. */
289 Lisp_Object Vinvocation_path;
291 /* The name under which SXEmacs was invoked, with any leading directory
293 Lisp_Object Vinvocation_name;
295 /* The directory name from which SXEmacs was invoked. */
296 Lisp_Object Vinvocation_directory;
299 /* The directory name in which to find subdirs such as lisp and etc.
300 nil means get them only from PATH_LOADSEARCH. */
301 Lisp_Object Vinstallation_directory;
304 Lisp_Object Vemacs_program_name, Vemacs_program_version;
305 Lisp_Object Vexec_path;
306 Lisp_Object Vexec_directory, Vconfigure_exec_directory;
307 Lisp_Object Vlisp_directory, Vconfigure_lisp_directory;
308 Lisp_Object Vmule_lisp_directory, Vconfigure_mule_lisp_directory;
309 Lisp_Object Vmodule_directory, Vconfigure_module_directory;
310 Lisp_Object Vsite_module_directory, Vconfigure_site_module_directory;
311 Lisp_Object Vconfigure_package_path;
312 Lisp_Object Vdata_directory, Vconfigure_data_directory;
313 Lisp_Object Vdoc_directory, Vconfigure_doc_directory;
314 Lisp_Object Vconfigure_lock_directory;
315 Lisp_Object Vdata_directory_list;
316 Lisp_Object Vconfigure_info_directory;
317 Lisp_Object Vconfigure_info_path;
318 Lisp_Object Vinternal_error_checking;
319 Lisp_Object Vmail_lock_methods, Vconfigure_mail_lock_method;
320 Lisp_Object Vpath_separator;
322 /* The default base directory SXEmacs is installed under. */
323 Lisp_Object Vconfigure_exec_prefix_directory, Vconfigure_prefix_directory;
325 /* If nonzero, set SXEmacs to run at this priority. This is also used
326 in child_setup and sys_suspend to make sure subshells run at normal
328 Fixnum emacs_priority;
330 /* Some FSF junk with running_asynch_code, to preserve the match
331 data. Not necessary because we don't call process filters
332 asynchronously (i.e. from within QUIT). */
333 /* #### Delete this when merging the rest of my code */
334 int running_asynch_code;
336 /* If non-zero, a window-system was specified on the command line. */
339 /* Type of display specified. We cannot use a Lisp symbol here because
340 Lisp symbols may not initialized at the time that we set this
342 const char *display_use;
344 /* If non-zero, then the early error handler will only print the error
346 int suppress_early_error_handler_backtrace;
348 /* An address near the bottom of the stack.
349 Tells GC how to save a copy of the stack. */
351 /* the stack size as imposed by the system */
352 size_t sys_stk_sz = 0;
354 #ifdef USG_SHARED_LIBRARIES
355 /* If nonzero, this is the place to put the end of the writable segment
358 uintptr_t bss_end = 0;
361 /* Number of bytes of writable memory we can expect to be able to get */
362 #ifdef _RLIM_T_DECLARED
365 unsigned long lim_data;
370 Some LISP-visible command-line options are set by SXEmacs _before_ the
371 data is dumped in building a --pdump SXEmacs, but used _after_ it is
372 restored in normal operation. Thus the dump-time values overwrite the
373 values SXEmacs is getting at runtime. Such variables must be saved
374 before loading the dumpfile, and restored afterward.
376 Therefore these variables may not be initialized in vars_of_emacs().
378 The save/restore is done immediately before and after pdump_load() in
379 main_1(). See that function for the current list of protected variables.
381 Note that saving/restoring is only necessary for a few variables that are
382 o command line arguments effective at runtime (as opposed to dump-time),
383 o parsed before pdump_load, and
384 o exported to Lisp via a DEFVAR.
387 /* Nonzero means running SXEmacs without interactive terminal. */
391 /* Value of Lisp variable `noninteractive'.
392 Normally same as C variable `noninteractive'
393 but nothing terrible happens if user sets this one.
395 Shadowed from the pdumper by `noninteractive'. */
399 /* Nonzero means don't perform site-modules searches at startup */
400 int inhibit_site_modules;
402 /* Nonzero means don't respect early packages at startup */
403 int inhibit_early_packages;
405 /* Nonzero means we warn about early packages shadowing late packages at startup */
406 int warn_early_package_shadows;
408 /* Nonzero means don't load package autoloads at startup */
409 int inhibit_autoloads;
411 /* Nonzero means don't load the dump file (ignored if not PDUMP) */
414 /* Nonzero means we assume all ttys are 8 color ANSI terminals */
415 int assume_colorterm;
417 /* Nonzero means print debug information about path searching */
420 /* Save argv and argc. */
421 static Extbyte **initial_argv; /* #### currently unused */
422 static int initial_argc; /* #### currently unused */
424 static void sort_args(int argc, char **argv);
426 Lisp_Object Qkill_emacs_hook;
427 Lisp_Object Qsave_buffers_kill_emacs;
429 extern Lisp_Object Vlisp_EXEC_SUFFIXES;
431 /* Ben's capsule summary about expected and unexpected exits from SXEmacs.
433 Expected exits occur when the user directs SXEmacs to exit, for example
434 by pressing the close button on the only frame in SXEmacs, or by typing
435 C-x C-c. This runs `save-buffers-kill-emacs', which saves any necessary
436 buffers, and then exits using the primitive `kill-emacs'.
438 However, unexpected exits occur in a few different ways:
440 -- a memory access violation or other hardware-generated exception
441 occurs. This is the worst possible problem to deal with, because
442 the fault can occur while SXEmacs is in any state whatsoever, even
443 quite unstable ones. As a result, we need to be *extremely* careful
445 -- we are using one X display (or if we've used more, we've closed the
446 others already), and some hardware or other problem happens and
447 suddenly we've lost our connection to the display. In this situation,
448 things are not so dire as in the last one; our code itself isn't
449 trashed, so we can continue execution as normal, after having set
450 things up so that we can exit at the appropriate time. Our exit
451 still needs to be of the emergency nature; we have no displays, so
452 any attempts to use them will fail. We simply want to auto-save
453 (the single most important thing to do during shut-down), do minimal
454 cleanup of stuff that has an independent existence outside of SXEmacs,
457 Currently, both unexpected exit scenarios described above set
458 preparing_for_armageddon to indicate that nonessential and possibly
459 dangerous things should not be done, specifically:
461 -- no garbage collection.
463 -- no messages of any sort from autosaving.
464 -- autosaving tries harder, ignoring certain failures.
465 -- existing frames are not deleted.
467 (Also, all places that set preparing_for_armageddon also
468 set dont_check_for_quit. This happens separately because it's
469 also necessary to set other variables to make absolutely sure
470 no quitting happens.)
472 In the first scenario above (the access violation), we also set
473 fatal_error_in_progress. This causes more things to not happen:
475 -- assertion failures do not abort.
476 -- printing code does not do code conversion or gettext when
477 printing to stdout/stderr.
480 /* Nonzero if handling a fatal error already. */
481 int fatal_error_in_progress;
483 /* Non-nil means we're going down, so we better not run any hooks
484 or do other non-essential stuff. */
485 int preparing_for_armageddon;
487 /* Nonzero means we're in an unstable situation and need to skip
488 i18n conversions and such during printing. */
489 int inhibit_non_essential_printing_operations;
491 static JMP_BUF run_temacs_catch;
493 static int run_temacs_argc;
494 static char **run_temacs_argv;
495 static char *run_temacs_args;
496 static EMACS_INT run_temacs_argv_size;
497 static EMACS_INT run_temacs_args_size;
499 static void shut_down_emacs(int sig, Lisp_Object stuff, int no_auto_save);
501 /* ------------------------------- */
502 /* low-level debugging functions */
503 /* ------------------------------- */
505 #define debugging_breakpoint()
510 debugging_breakpoint();
513 /* #### There must be a better way!!!! */
515 static JMP_BUF memory_error_jump;
519 debug_memory_error(int signum)
521 EMACS_REESTABLISH_SIGNAL(signum, debug_memory_error);
522 EMACS_UNBLOCK_SIGNAL(signum);
523 LONGJMP(memory_error_jump, 1);
527 static char dummy_char;
529 /* Return whether all bytes in the specified memory block can be read. */
531 debug_can_access_memory(void *ptr, Bytecount len)
533 /* Use volatile to protect variables from being clobbered by longjmp. */
534 SIGTYPE(*volatile old_sigbus) (int);
535 SIGTYPE(*volatile old_sigsegv) (int);
536 volatile int old_errno = errno;
537 volatile int retval = 1;
539 if (!SETJMP(memory_error_jump)) {
542 (SIGTYPE(*)(int))signal(SIGBUS, debug_memory_error);
544 (SIGTYPE(*)(int))signal(SIGSEGV, debug_memory_error);
547 * Examine memory pool at PTR, trying to cheat
548 * compiler's optimisations.
551 dummy_char = ((char*)ptr)[len];
556 signal(SIGBUS, old_sigbus);
557 signal(SIGSEGV, old_sigsegv);
565 DEFUN("force-debugging-signal", Fforce_debugging_signal, 0, 1, 0, /*
566 Cause SXEmacs to enter the debugger.
567 On some systems, there may be no way to do this gracefully; if so,
568 nothing happens unless ABORT is non-nil, in which case SXEmacs will
569 abort() -- a sure-fire way to immediately get back to the debugger,
570 but also a sure-fire way to kill SXEmacs (and dump core on Unix
575 debugging_breakpoint();
581 #endif /* DEBUG_SXEMACS */
584 ensure_no_quitting_from_now_on(void)
586 /* make sure no quitting from now on!! */
587 dont_check_for_quit = 1;
593 /* Handle bus errors, illegal instruction, etc. */
595 fatal_error_signal(int sig)
597 fatal_error_in_progress++;
598 inhibit_non_essential_printing_operations = 1;
599 preparing_for_armageddon = 1;
601 ensure_no_quitting_from_now_on();
603 /* Unblock the signal so that if the same signal gets sent in the
604 code below, we avoid a deadlock. */
605 EMACS_UNBLOCK_SIGNAL(sig);
607 /* Only try auto-saving first time through. If we crash in auto-saving,
608 don't do it again. */
609 if (fatal_error_in_progress == 1) {
610 Fdo_auto_save(Qt, Qnil); /* do this before anything hazardous */
611 /* Do this so that the variable has the same value of 2 regardless of
612 whether we made it through auto-saving correctly. */
613 fatal_error_in_progress++;
614 } else if (fatal_error_in_progress == 2)
615 stderr_out("WARNING: Unable to auto-save your files properly.\n"
616 "Some or all may in fact have been auto-saved.\n"
619 /* Now, reset our signal handler, so the next time, we just die.
620 Don't do this before auto-saving. */
621 signal(sig, SIG_DFL);
623 /* Keep in mind that there's more than one signal that we can crash
625 /* If fatal error occurs in code below, avoid infinite recursion. */
626 if (fatal_error_in_progress <= 2) {
627 shut_down_emacs(sig, Qnil, 1);
628 stderr_out("\nLisp backtrace follows:\n\n");
629 Fbacktrace(Qexternal_debugging_output, Qt);
630 # if 0 /* This is evil, rarely useful, and causes grief in some cases. */
631 /* Check for Sun-style stack printing via /proc */
633 const char *pstack = "/usr/proc/bin/pstack";
634 if (access(pstack, X_OK) == 0) {
636 stderr_out("\nC backtrace follows:\n"
637 "(A real debugger may provide better information)\n\n");
638 sprintf(buf, "%s %d >&2", pstack,
645 /* Signal the same code; this time it will really be fatal. */
654 /* Handler for SIGDANGER. */
656 memory_warning_signal(int sig)
658 /* #### bad bad bad; this function shouldn't do anything except
659 set a flag, or weird corruption could happen. */
660 signal(sig, memory_warning_signal);
664 ("Operating system warns that virtual memory is running low.\n"));
666 /* It might be unsafe to call do_auto_save now. */
667 force_auto_save_soon();
669 #endif /* SIGDANGER */
671 /* Code for dealing with Lisp access to the Unix command line */
674 make_arg_list_1(int argc, Extbyte ** argv, int skip_args)
676 Lisp_Object result = Qnil;
679 for (i = argc - 1; i >= 0; i--) {
680 if (i != 0 && i <= skip_args)
683 result = Fcons(build_ext_string(argv[i], Qcommand_argument_encoding), result);
689 make_arg_list(int argc, Extbyte ** argv)
691 return make_arg_list_1(argc, argv, 0);
694 /* Calling functions are also responsible for calling free_argc_argv
695 when they are done with the generated list. */
697 make_argc_argv(Lisp_Object argv_list, int *argc, Extbyte *** argv)
700 int n = XINT(Flength(argv_list));
702 *argv = (Extbyte **) malloc((n + 1) * sizeof(Extbyte *));
704 for (i = 0, next = argv_list; i < n; i++, next = XCDR(next)) {
706 CHECK_STRING(XCAR(next));
708 LISP_STRING_TO_EXTERNAL(XCAR(next), temp,
709 Qcommand_argument_encoding);
710 (*argv)[i] = strdup(temp);
716 void free_argc_argv(Extbyte ** argv)
727 static void init_cmdargs(int argc, Extbyte ** argv, int skip_args)
732 Vcommand_line_args = make_arg_list_1(argc, argv, skip_args);
735 DEFUN("invocation-name", Finvocation_name, 0, 0, 0, /*
736 Return the program name that was used to run SXEmacs.
737 Any directory names are omitted.
741 return Fcopy_sequence(Vinvocation_name);
744 DEFUN("invocation-directory", Finvocation_directory, 0, 0, 0, /*
745 Return the directory name in which the Emacs executable was located.
749 return Fcopy_sequence(Vinvocation_directory);
753 /* #### - don't know why I18N4 on SunOS/JLE
754 can't deal with this. It's a potential
755 bug that needs to be looked at. */
756 # undef RUN_TIME_REMAP
759 /* Test whether the next argument in ARGV matches SSTR or a prefix of
760 LSTR (at least MINLEN characters). If so, then if VALPTR is non-null
761 (the argument is supposed to have a value) store in *VALPTR either
762 the next argument or the portion of this one after the equal sign.
763 ARGV is read starting at position *SKIPPTR; this index is advanced
764 by the number of arguments used.
766 Too bad we can't just use getopt for all of this, but we don't have
767 enough information to do it right. */
770 argmatch(char **argv, int argc, char *sstr, char *lstr,
771 int minlen, char **valptr, int *skipptr)
777 /* Don't access argv[argc]; give up in advance. */
778 if (argc <= *skipptr + 1)
781 arg = argv[*skipptr + 1];
784 if (strcmp(arg, sstr) == 0) {
785 if (valptr != NULL) {
786 *valptr = argv[*skipptr + 2];
792 arglen = (valptr != NULL && (p = strchr(arg, '=')) != NULL
793 ? p - arg : (int)strlen(arg));
794 if (lstr == 0 || arglen < minlen || strncmp(arg, lstr, arglen) != 0)
796 else if (valptr == NULL) {
799 } else if (p != NULL) {
803 } else if (argv[*skipptr + 2] != NULL) {
804 *valptr = argv[*skipptr + 2];
813 make_docfile(int c, char **v)
815 #define make_docfile_prog "make-docfile\0"
816 #define make_docfile_opt "--make-docfile"
817 /* C99 we need you */
818 size_t edlen = XSTRING_LENGTH(Vexec_directory);
819 char mdocfile[edlen+countof(make_docfile_prog)];
820 char **newargv = xnew_array_and_zero(char*, c), **p;
822 /* set up the program call */
824 (char*)XSTRING_DATA(Vexec_directory),
825 XSTRING_LENGTH(Vexec_directory));
826 xstrncpy(mdocfile+XSTRING_LENGTH(Vexec_directory),
827 make_docfile_prog, countof(make_docfile_prog));
829 /* find the --make-docfile option */
830 for (p = v; *p; p++) {
831 if (strncmp(*p, make_docfile_opt,
832 countof(make_docfile_opt)) == 0) {
838 /* fill the new argv array */
839 newargv[0] = make_docfile_prog;
840 for (char **o = p, **n = &newargv[1]; *o;) {
843 return execv(mdocfile, newargv);
852 /* we need some checks whether this is supported! */
853 __asm__ __volatile__ (
854 "movl %%esp, %[stkptr]\n\t"
855 : [stkptr] "=m" (sp));
864 /* return the stack size limit */
865 #if defined HAVE_GETRLIMIT64
867 (void)getrlimit64(RLIMIT_STACK, &foo);
868 #elif defined HAVE_GETRLIMIT
870 (void)getrlimit(RLIMIT_STACK, &foo);
872 /* bollocks, maybe just a small one? 64k? */
873 struct {size_t rlim_cur;} foo = {65536};
879 /* Make stack traces always identify version + configuration */
880 #define main_1 STACK_TRACE_EYE_CATCHER
882 /* This function is not static, so that the compiler is less likely to
883 inline it, which would make it not show up in stack traces.
885 The restart argument is a flag that indicates that main_1 is now
886 being called for the second time in this invocation of sxemacs; this can
887 only happen in an sxemacs that is not loaded with dumped data (temacs
888 with the conventional dumper or sxemacs -nd with the pdumper). See
889 Frun_emacs_from_temacs().
891 restart interacts with initialized as follows (per Olivier Galibert):
895 initialized==0 => temacs
896 initialized!=0 && restart!=0 => run-temacs
897 initialized!=0 && restart==0 => sxemacs/post pdump_load()
899 DECLARE_DOESNT_RETURN(main_1(int, char **, char **, int));
900 DOESNT_RETURN main_1(int argc, char **argv, char **envp, int restart)
902 char stack_bottom_variable;
905 int inhibit_window_system;
907 extern int malloc_cookie;
910 #if (!defined (SYSTEM_MALLOC) && !defined (HAVE_LIBMCHECK) \
911 && !defined (DOUG_LEA_MALLOC))
912 /* Make sure that any libraries we link against haven't installed a
913 hook for a gmalloc of a potentially incompatible version. */
914 /* If we're using libmcheck, the hooks have already been initialized, */
915 /* don't touch them. -slb */
916 __malloc_hook = NULL;
917 __realloc_hook = NULL;
919 #endif /* not SYSTEM_MALLOC or HAVE_LIBMCHECK or DOUG_LEA_MALLOC */
922 inhibit_non_essential_printing_operations = 1;
926 * NeXT secret magic, ripped from Emacs-for-NS by Carl Edman
927 * <cedman@princeton.edu>. Note that even Carl doesn't know what this
928 * does; it was provided by NeXT, and it presumable makes NS's mallocator
929 * work with dumping. But malloc_jumpstart() and malloc_freezedry() in
930 * unexnext.c are both completely undocumented, even in NS header files!
931 * But hey, it solves all NS related memory problems, so who's
933 if (initialized && malloc_jumpstart(malloc_cookie) != 0)
934 stderr_out("malloc jumpstart failed!\n");
938 #if defined (GNU_MALLOC) && \
939 defined (ERROR_CHECK_MALLOC) && \
940 !defined (HAVE_LIBMCHECK)
942 #if defined(LOSING_GCC_DESTRUCTOR_FREE_BUG)
943 /* Prior to SXEmacs 21, this was `#if 0'ed out. */
944 /* I'm enabling this because it is the only reliable way I've found to */
945 /* prevent a very annoying problem where GCC will attempt to free(3) */
946 /* memory at exit() and cause a coredump. */
952 sort_args(argc, argv);
958 /* Record (approximately) where the stack begins. */
959 stack_bottom = &stack_bottom_variable;
960 /* and determine the system's stack limit */
961 sys_stk_sz = __sys_stk_sz();
963 #ifdef USG_SHARED_LIBRARIES
965 brk((void *)bss_end);
970 #if defined (HAVE_MMAP) && defined (REL_ALLOC)
971 /* ralloc can only be used if using the GNU memory allocator. */
973 #elif defined (REL_ALLOC) && !defined(DOUG_LEA_MALLOC)
981 #endif /* HAVE_SOCKS */
983 #if !defined SYSTEM_MALLOC && !(defined HAVE_BDWGC && defined EF_USE_BDWGC)
985 /* Arrange to get warning messages as memory fills up. */
986 memory_warnings(0, malloc_warning);
987 #endif /* not SYSTEM_MALLOC */
989 #ifdef SET_EMACS_PRIORITY
990 if (emacs_priority != 0)
991 nice(-emacs_priority);
993 #endif /* SET_EMACS_PRIORITY */
995 #ifdef EXTRA_INITIALIZE
999 #ifdef HAVE_WINDOW_SYSTEM
1000 inhibit_window_system = 0;
1002 inhibit_window_system = 1;
1005 /* Handle the --make-docfile argument */
1006 if (argmatch(argv, argc,
1007 "--make-docfile", 0, 9, NULL, &skip_args)) {
1009 /* we need load the dump file as the exec-directory is in
1011 if (UNLIKELY(!pdump_load(argv[0]))) {
1015 exit(make_docfile(argc, argv));
1018 /* Handle the -sd/--show-dump-id switch, which means show the hex
1020 if (argmatch(argv, argc,
1021 "-sd", "--show-dump-id",
1022 9, NULL, &skip_args)) {
1024 printf("%08x\n", dump_id);
1027 ("Portable dumper not configured; -sd just forces exit.\n");
1032 /* Handle the -t switch, which specifies filename to use as terminal */
1036 (argv, argc, "-t", "--terminal", 4, &term, &skip_args)) {
1039 if (open(term, O_RDWR | OPEN_BINARY, 2) < 0)
1040 fatal("%s: %s", term, strerror(errno));
1043 fatal("%s: not a tty", term);
1046 stderr_out("Using %s", ttyname(0));
1048 stderr_out("Using %s", term);
1049 inhibit_window_system = 1; /* -t => -nw */
1053 /* Handle the --no-dump-file/-nd switch, which means don't
1054 * load the dump file (ignored when not using pdump) */
1055 if (argmatch(argv, argc, "-nd", "--no-dump-file", 7,
1056 NULL, &skip_args)) {
1060 if (argmatch(argv, argc, "-ct", "--color-terminal", 5,
1061 NULL, &skip_args)) {
1062 assume_colorterm = 1;
1065 /* Handle -nw switch */
1066 if (argmatch(argv, argc, "-nw", "--no-windows", 6, NULL, &skip_args))
1067 inhibit_window_system = 1;
1069 /* Handle the -batch switch, which means don't do interactive display */
1070 if (argmatch(argv, argc, "-batch", "--batch", 5, NULL, &skip_args)) {
1071 #if 0 /* I don't think this is correct. */
1072 inhibit_autoloads = 1;
1077 if (argmatch(argv, argc, "-debug-paths", "--debug-paths",
1078 11, NULL, &skip_args))
1081 /* Partially handle -no-autoloads, -no-early-packages and -vanilla.
1083 /* are searched prior to the rest of the command line being parsed in */
1085 if (argmatch(argv, argc, "-no-early-packages", "--no-early-packages",
1086 6, NULL, &skip_args)) {
1087 inhibit_early_packages = 1;
1090 #if defined WITH_EMODULES && defined HAVE_EMODULES
1091 if (argmatch(argv, argc, "-no-site-modules", "--no-site-modules",
1092 9, NULL, &skip_args)) {
1093 inhibit_site_modules = 1;
1097 inhibit_site_modules = 1;
1099 if (argmatch(argv, argc, "-vanilla", "--vanilla", 7, NULL, &skip_args)) {
1100 inhibit_early_packages = 1;
1104 if (argmatch(argv, argc, "-no-autoloads", "--no-autoloads",
1105 7, NULL, &skip_args)) {
1106 /* Inhibit everything */
1107 inhibit_autoloads = 1;
1111 if (argmatch(argv, argc, "-debug-paths", "--debug-paths",
1112 6, NULL, &skip_args)) {
1117 /* Partially handle the -version and -help switches: they imply -batch,
1118 but are not removed from the list. */
1119 if (argmatch(argv, argc, "-help", "--help", 3, NULL, &skip_args))
1120 noninteractive = 1, skip_args--;
1122 if (argmatch(argv, argc, "-version", "--version", 3, NULL, &skip_args)
1123 || argmatch(argv, argc, "-V", 0, 2, NULL, &skip_args))
1124 noninteractive = 1, skip_args--;
1126 /* Now, figure out which type of console is our first console. */
1131 display_use = "stream";
1133 display_use = "tty";
1136 if (inhibit_window_system)
1137 fatal("Sorry, this SXEmacs was not compiled with TTY support");
1140 #ifdef HAVE_WINDOW_SYSTEM
1141 /* Stupid kludge to catch command-line display spec. We can't
1142 handle this argument entirely in window-system-dependent code
1143 because we don't even know which window-system-dependent code
1144 to run until we've recognized this argument. */
1145 if (!inhibit_window_system && !noninteractive) {
1146 #ifdef HAVE_X_WINDOWS
1148 int count_before = skip_args;
1150 if (argmatch(argv, argc, "-d", "--display", 3, &dpy, &skip_args)
1151 || argmatch(argv, argc, "-display", 0, 3, &dpy,
1156 /* If we have the form --display=NAME,
1157 convert it into -d name.
1158 This requires inserting a new element into argv. */
1159 if (dpy != 0 && skip_args - count_before == 1) {
1161 (char **)xmalloc(sizeof(char *) * (argc + 2));
1164 for (j = 0; j < count_before + 1; j++)
1166 new[count_before + 1] = "-d";
1167 new[count_before + 2] = dpy;
1168 for (j = count_before + 2; j < argc; j++)
1169 new[j + 1] = argv[j];
1173 /* Change --display to -d, when its arg is separate. */
1174 else if (dpy != 0 && skip_args > count_before
1175 && argv[count_before + 1][1] == '-')
1176 argv[count_before + 1] = "-d";
1178 /* Don't actually discard this arg. */
1179 skip_args = count_before;
1181 /* If there is a non-empty environment var DISPLAY, set
1182 `display_use', but not `display_arg', which is only to be set
1183 if the display was specified on the command line. */
1184 if ((dpy = getenv("DISPLAY")) && dpy[0])
1187 #endif /* HAVE_X_WINDOWS */
1190 char *dpy = getenv("DISPLAY");
1192 display_use = "gtk";
1196 #endif /* HAVE_WINDOW_SYSTEM */
1198 noninteractive1 = noninteractive;
1200 /****** Now initialize everything *******/
1202 /* First, do really basic environment initialization -- catching signals
1203 and the like. These functions have no dependence on any part of
1204 the Lisp engine and need to be done both at dump time and at run time. */
1206 init_signals_very_early();
1207 init_data_very_early(); /* Catch math errors. */
1209 init_floatfns_very_early(); /* Catch floating-point math errors. */
1211 init_process_times_very_early(); /* Initialize our process timers.
1212 As early as possible, of course,
1213 so we can be fairly accurate. */
1214 init_intl_very_early(); /* set up the locale and domain for gettext and
1217 /* Now initialize the Lisp engine and the like. Done only during
1218 dumping. No dependence on anything that may be in the user's
1219 environment when the dumped SXEmacs is run.
1221 We try to do things in an order that minimizes the non-obvious
1222 dependencies between functions. */
1224 /* purify_flag 1 is correct even if CANNOT_DUMP.
1225 * loadup.el will set to nil at end. */
1231 } else if (nodumpfile) {
1236 /* Keep command options from getting stomped.
1238 Some LISP-visible options are changed by SXEmacs _after_ the data is
1239 dumped in building a --pdump SXEmacs, but _before_ it is restored in
1240 normal operation. Thus the restored values overwrite the values
1241 SXEmacs is getting at run-time. Such variables must be saved here,
1242 and restored after loading the dumped data.
1244 Boy, this is ugly, but how else to do it?
1247 /* noninteractive1 is saved in noninteractive, which isn't
1249 int inhibit_early_packages_save = inhibit_early_packages;
1250 int inhibit_autoloads_save = inhibit_autoloads;
1251 int debug_paths_save = debug_paths;
1252 int inhibit_site_modules_save = inhibit_site_modules;
1254 initialized = pdump_load(argv[0]);
1256 /* Now unstomp everything */
1257 noninteractive1 = noninteractive;
1258 inhibit_early_packages = inhibit_early_packages_save;
1259 inhibit_autoloads = inhibit_autoloads_save;
1260 debug_paths = debug_paths_save;
1261 inhibit_site_modules = inhibit_site_modules_save;
1264 run_temacs_argc = -1;
1274 /* Initialize things so that new Lisp objects
1275 can be created and objects can be staticpro'd.
1276 Must be basically the very first thing done
1277 because pretty much all of the initialization
1278 routines below create new objects. */
1279 init_alloc_once_early();
1281 /* Initialize Qnil, Qt, Qunbound, and the
1282 obarray. After this, symbols can be
1283 interned. This depends on init_alloc_once_early(). */
1284 init_symbols_once_early();
1286 /* Declare the basic symbols pertaining to errors,
1287 So that DEFERROR*() can be called. */
1288 init_errors_once_early();
1290 /* Make sure that opaque pointers can be created. */
1291 init_opaque_once_early();
1293 /* Now declare all the symbols and define all the Lisp primitives.
1295 The *only* thing that the syms_of_*() functions are allowed to do
1296 is call one of the following:
1298 INIT_LRECORD_IMPLEMENTATION()
1299 defsymbol(), DEFSYMBOL(), or DEFSYMBOL_MULTIWORD_PREDICATE()
1300 defsubr() (i.e. DEFSUBR)
1301 deferror(), DEFERROR(), or DEFERROR_STANDARD()
1302 defkeyword() or DEFKEYWORD()
1304 Order does not matter in these functions.
1313 syms_of_casefiddle();
1320 #ifdef DEBUG_SXEMACS
1323 #endif /* DEBUG_SXEMACS */
1334 #ifdef HAVE_X_WINDOWS
1338 syms_of_event_gtk();
1340 #ifdef HAVE_DRAGNDROP
1343 #ifdef EF_USE_ASYNEQ
1344 syms_of_event_queue();
1346 syms_of_worker_asyneq();
1348 syms_of_event_stream();
1353 #ifdef CLASH_DETECTION
1355 #endif /* CLASH_DETECTION */
1358 syms_of_font_lock();
1362 syms_of_glyphs_eimage();
1363 syms_of_glyphs_widget();
1373 #ifdef HAVE_DATABASE
1376 #ifdef HAVE_MENUBARS
1382 #if defined WITH_EMODULES && defined HAVE_EMODULES && 0
1384 #elif defined WITH_EMODULES && defined HAVE_EMODULES
1389 #if !defined (NO_SUBPROCESSES)
1393 #if defined (HAVE_MMAP) && defined (REL_ALLOC) && !defined(DOUG_LEA_MALLOC)
1395 #endif /* HAVE_MMAP && REL_ALLOC */
1397 syms_of_redisplay();
1402 syms_of_specifier();
1405 #ifdef HAVE_SCROLLBARS
1406 syms_of_scrollbar();
1408 #ifdef HAVE_TOOLBARS
1416 syms_of_console_tty();
1417 syms_of_device_tty();
1418 syms_of_objects_tty();
1422 syms_of_device_gtk();
1423 syms_of_frame_gtk();
1424 syms_of_glyphs_gtk();
1425 syms_of_objects_gtk();
1427 syms_of_select_gtk();
1429 syms_of_dialog_gtk();
1431 #ifdef HAVE_MENUBARS
1432 syms_of_menubar_gtk();
1434 syms_of_select_gtk();
1436 #if defined (HAVE_MENUBARS) || defined(HAVE_SCROLLBARS) || defined(HAVE_DIALOGS) || defined(HAVE_TOOLBARS)
1439 #endif /* HAVE_GTK */
1441 #ifdef HAVE_X_WINDOWS
1442 #ifdef HAVE_BALLOON_HELP
1443 syms_of_balloon_x();
1451 syms_of_objects_x();
1452 #ifdef HAVE_MENUBARS
1453 syms_of_menubar_x();
1456 #if defined (HAVE_MENUBARS) || defined (HAVE_SCROLLBARS) || defined (HAVE_DIALOGS) || defined (HAVE_TOOLBARS)
1461 syms_of_input_method_xlib();
1463 #endif /* HAVE_XIM */
1464 #endif /* HAVE_X_WINDOWS */
1469 syms_of_mule_charset();
1472 syms_of_file_coding();
1479 syms_of_mule_canna();
1480 #endif /* HAVE_CANNA */
1492 #if defined (GNU_MALLOC) && \
1493 defined (ERROR_CHECK_MALLOC) && \
1494 !defined (HAVE_LIBMCHECK)
1496 /* Prior to SXEmacs 21, this was `#if 0'ed out. -slb */
1497 #if defined (LOSING_GCC_DESTRUCTOR_FREE_BUG)
1498 syms_of_free_hook();
1513 #ifdef HAVE_POSTGRESQL
1514 syms_of_postgresql();
1521 #ifdef WITH_NUMBER_TYPES
1533 /* Now create the subtypes for the types that have them.
1534 We do this before the vars_*() because more symbols
1535 may get initialized here. */
1537 /* Now initialize the console types and associated symbols.
1538 Other than the first function below, the functions may
1539 make exactly the following function/macro calls:
1541 INITIALIZE_CONSOLE_TYPE()
1542 CONSOLE_HAS_METHOD()
1544 For any given console type, the former macro must be called
1545 before the any calls to the latter macro. */
1547 console_type_create();
1549 console_type_create_stream();
1552 console_type_create_tty();
1553 console_type_create_device_tty();
1554 console_type_create_frame_tty();
1555 console_type_create_objects_tty();
1556 console_type_create_redisplay_tty();
1560 console_type_create_gtk();
1561 console_type_create_select_gtk();
1562 console_type_create_device_gtk();
1563 console_type_create_frame_gtk();
1564 console_type_create_objects_gtk();
1565 console_type_create_glyphs_gtk();
1566 console_type_create_redisplay_gtk();
1567 #ifdef HAVE_MENUBARS
1568 console_type_create_menubar_gtk();
1570 #ifdef HAVE_SCROLLBARS
1571 console_type_create_scrollbar_gtk();
1573 #ifdef HAVE_TOOLBARS
1574 console_type_create_toolbar_gtk();
1577 console_type_create_dialog_gtk();
1579 #endif /* HAVE_GTK */
1581 #ifdef HAVE_X_WINDOWS
1582 console_type_create_x();
1583 console_type_create_device_x();
1584 console_type_create_frame_x();
1585 console_type_create_glyphs_x();
1586 console_type_create_select_x();
1587 #ifdef HAVE_MENUBARS
1588 console_type_create_menubar_x();
1590 console_type_create_objects_x();
1591 console_type_create_redisplay_x();
1592 #ifdef HAVE_SCROLLBARS
1593 console_type_create_scrollbar_x();
1595 #ifdef HAVE_TOOLBARS
1596 console_type_create_toolbar_x();
1599 console_type_create_dialog_x();
1601 #endif /* HAVE_X_WINDOWS */
1603 /* Now initialize the specifier types and associated symbols.
1604 Other than the first function below, the functions may
1605 make exactly the following function/macro calls:
1607 INITIALIZE_SPECIFIER_TYPE()
1608 SPECIFIER_HAS_METHOD()
1610 For any given specifier type, the former macro must be called
1611 before the any calls to the latter macro. */
1613 specifier_type_create();
1615 specifier_type_create_image();
1616 specifier_type_create_gutter();
1617 specifier_type_create_objects();
1618 #ifdef HAVE_TOOLBARS
1619 specifier_type_create_toolbar();
1622 /* Now initialize the structure types and associated symbols.
1623 Other than the first function below, the functions may
1624 make exactly the following function/macro calls:
1626 define_structure_type()
1627 define_structure_type_keyword()
1631 structure_type_create();
1633 structure_type_create_chartab();
1634 structure_type_create_faces();
1635 structure_type_create_rangetab();
1636 structure_type_create_hash_table();
1638 /* Now initialize the image instantiator formats and associated symbols.
1639 Other than the first function below, the functions may
1640 make exactly the following function/macro calls:
1642 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT()
1643 IIFORMAT_HAS_METHOD()
1644 IIFORMAT_VALID_KEYWORD()
1646 For any given image instantiator format, the first macro must be
1647 called before the any calls to the other macros. */
1649 image_instantiator_format_create();
1650 image_instantiator_format_create_glyphs_eimage();
1651 image_instantiator_format_create_glyphs_widget();
1653 image_instantiator_format_create_glyphs_tty();
1655 #ifdef HAVE_X_WINDOWS
1656 image_instantiator_format_create_glyphs_x();
1657 #endif /* HAVE_X_WINDOWS */
1659 image_instantiator_format_create_glyphs_gtk();
1662 /* Now initialize the lstream types and associated symbols.
1663 Other than the first function below, the functions may
1664 make exactly the following function/macro calls:
1666 LSTREAM_HAS_METHOD()
1670 lstream_type_create();
1672 lstream_type_create_file_coding();
1675 /* Initialize processes implementation.
1676 The functions may make exactly the following function/macro calls:
1678 PROCESS_HAS_METHOD()
1680 #ifdef HAVE_UNIX_PROCESSES
1681 process_type_create_unix();
1684 /* Now initialize most variables.
1686 These functions may do exactly the following:
1699 defsymbol(), if it's absolutely necessary and you're sure that
1700 the symbol isn't referenced anywhere else in the initialization
1702 Fset() on a symbol that is unbound
1703 assigning a symbol or constant value to a variable
1704 using a global variable that has been initialized
1705 earlier on in the same function
1707 Any of the object-creating functions in alloc.c: e.g.
1720 perhaps a few others.
1722 NB: Initialization or assignment should not be done here to certain
1723 variables settable from the command line. See the comment above
1724 the call to pdump_load() in main_1(). This caveat should only
1725 apply to vars_of_emacs().
1728 /* Now allow Fprovide() statements to be made. */
1729 init_provide_once();
1731 /* Do that before any specifier creation (esp. vars_of_glyphs()) */
1732 vars_of_specifier();
1745 #ifdef DEBUG_SXEMACS
1749 vars_of_console_stream();
1756 #ifdef HAVE_DRAGNDROP
1764 #ifdef HAVE_X_WINDOWS
1767 #if defined(HAVE_TTY) && (defined (DEBUG_TTY_EVENT_STREAM) || !defined (HAVE_X_WINDOWS))
1768 vars_of_event_tty();
1770 vars_of_event_stream();
1771 #ifdef EF_USE_ASYNEQ
1773 vars_of_worker_asyneq();
1780 #ifdef CLASH_DETECTION
1784 vars_of_font_lock();
1787 vars_of_glyphs_eimage();
1788 vars_of_glyphs_widget();
1796 vars_of_input_method_motif();
1797 #else /* XIM_XLIB */
1798 vars_of_input_method_xlib();
1800 #endif /* HAVE_XIM */
1806 #ifdef HAVE_DATABASE
1809 #ifdef HAVE_MENUBARS
1815 #if defined WITH_EMODULES && defined HAVE_EMODULES && 0
1817 #elif defined WITH_EMODULES && defined HAVE_EMODULES
1823 #ifndef NO_SUBPROCESSES
1825 #ifdef HAVE_UNIX_PROCESSES
1826 vars_of_process_unix();
1831 #if defined (HAVE_MMAP) && defined (REL_ALLOC) && !defined(DOUG_LEA_MALLOC)
1833 #endif /* HAVE_MMAP && REL_ALLOC */
1834 vars_of_redisplay();
1835 #ifdef HAVE_SCROLLBARS
1836 vars_of_scrollbar();
1843 #ifdef HAVE_TOOLBARS
1850 vars_of_console_tty();
1851 vars_of_frame_tty();
1852 vars_of_objects_tty();
1856 vars_of_device_gtk();
1858 vars_of_dialog_gtk();
1860 vars_of_event_gtk();
1861 vars_of_frame_gtk();
1862 vars_of_glyphs_gtk();
1864 #ifdef HAVE_MENUBARS
1865 vars_of_menubar_gtk();
1867 vars_of_objects_gtk();
1868 vars_of_select_gtk();
1869 #ifdef HAVE_SCROLLBARS
1870 vars_of_scrollbar_gtk();
1872 #if defined (HAVE_MENUBARS) || defined (HAVE_SCROLLBARS) || defined (HAVE_DIALOGS) || defined (HAVE_TOOLBARS)
1875 #endif /* HAVE_GTK */
1877 #ifdef HAVE_X_WINDOWS
1878 #ifdef HAVE_BALLOON_HELP
1879 vars_of_balloon_x();
1887 #ifdef HAVE_MENUBARS
1888 vars_of_menubar_x();
1890 vars_of_objects_x();
1892 #ifdef HAVE_SCROLLBARS
1893 vars_of_scrollbar_x();
1895 #if defined (HAVE_MENUBARS) || defined (HAVE_SCROLLBARS) || defined (HAVE_DIALOGS) || defined (HAVE_TOOLBARS)
1898 #endif /* HAVE_X_WINDOWS */
1903 vars_of_mule_charset();
1906 vars_of_file_coding();
1913 vars_of_mule_canna();
1914 #endif /* HAVE_CANNA */
1925 #ifdef HAVE_POSTGRESQL
1926 vars_of_postgresql();
1937 #ifdef WITH_NUMBER_TYPES
1949 /* Now initialize any specifier variables. We do this later
1950 because it has some dependence on the vars initialized
1953 These functions should *only* initialize specifier variables,
1954 and may make use of the following functions/macros in addition
1955 to the ones listed above:
1959 set_specifier_fallback()
1960 set_specifier_caching()
1963 specifier_vars_of_glyphs();
1964 specifier_vars_of_glyphs_widget();
1965 specifier_vars_of_gutter();
1966 #ifdef HAVE_MENUBARS
1967 specifier_vars_of_menubar();
1969 specifier_vars_of_redisplay();
1970 #ifdef HAVE_SCROLLBARS
1971 specifier_vars_of_scrollbar();
1973 #ifdef HAVE_TOOLBARS
1974 specifier_vars_of_toolbar();
1976 specifier_vars_of_window();
1978 /* Now comes all the rest of the variables that couldn't
1979 be handled above. There may be dependencies on variables
1980 initialized above, and dependencies between one complex_vars_()
1981 function and another. */
1983 /* Calls Fmake_range_table(). */
1984 complex_vars_of_regex();
1985 /* Calls Fmake_range_table(). */
1986 complex_vars_of_search();
1988 /* Calls make_lisp_hash_table(). */
1989 complex_vars_of_extents();
1991 /* Depends on hash tables and specifiers. */
1992 complex_vars_of_faces();
1995 /* These two depend on hash tables and various variables declared
1996 earlier. The second may also depend on the first. */
1997 complex_vars_of_mule_charset();
2000 complex_vars_of_file_coding();
2003 /* This calls allocate_glyph(), which creates specifiers
2004 and also relies on a variable (Vthe_nothing_vector) initialized
2005 above. It also calls make_ext_string(), which under Mule
2006 could require that the charsets be initialized. */
2007 complex_vars_of_glyphs();
2009 /* These rely on the glyphs just created in the previous function,
2010 and call Fadd_spec_to_specifier(), which relies on various
2011 variables initialized above. */
2013 complex_vars_of_glyphs_gtk();
2015 #ifdef HAVE_X_WINDOWS
2016 complex_vars_of_glyphs_x();
2019 /* This calls Fmake_glyph_internal(). */
2020 complex_vars_of_alloc();
2022 /* This calls Fmake_glyph_internal(). */
2023 #ifdef HAVE_MENUBARS
2024 complex_vars_of_menubar();
2027 /* This calls Fmake_glyph_internal(). */
2028 #ifdef HAVE_SCROLLBARS
2029 complex_vars_of_scrollbar();
2032 /* This calls allocate_glyph(). */
2033 complex_vars_of_frame();
2035 /* This calls Fcopy_category_table() under Mule, which calls who
2037 complex_vars_of_chartab();
2039 /* This calls set_string_char(), which (under Mule) depends on the
2040 charsets being initialized. */
2041 complex_vars_of_casetab();
2043 /* This calls Fcopy_syntax_table(), which relies on char tables. */
2044 complex_vars_of_syntax();
2046 /* This initializes buffer-local variables, sets things up so
2047 that buffers can be created, and creates a couple of basic
2048 buffers. This depends on Vstandard_syntax_table and
2049 Vstandard_category_table (initialized in the previous
2050 functions), as well as a whole horde of variables that may
2051 have been initialized above. */
2052 complex_vars_of_buffer();
2054 /* This initializes console-local variables. */
2055 complex_vars_of_console();
2057 /* This creates a couple more buffers, and depends on the
2058 previous function. */
2059 complex_vars_of_minibuf();
2061 /* These two might call Ffile_name_as_directory(), which
2062 might depend on all sorts of things; I'm not sure. */
2063 complex_vars_of_emacs();
2065 /* This creates a couple of basic keymaps and depends on Lisp
2066 hash tables and Ffset() (both of which depend on some variables
2067 initialized in the vars_of_*() section) and possibly other
2069 complex_vars_of_keymap();
2071 /* Calls make_lisp_hash_table() and creates a keymap */
2072 complex_vars_of_event_stream();
2074 #ifdef ERROR_CHECK_GC
2076 extern int always_gc;
2077 if (always_gc) /* purification debugging hack */
2078 garbage_collect_1();
2082 } else if (!restart) { /* after successful pdump_load() */
2083 reinit_alloc_once_early();
2084 reinit_symbols_once_early();
2085 reinit_opaque_once_early();
2087 reinit_console_type_create_stream();
2089 reinit_console_type_create_tty();
2091 #ifdef HAVE_X_WINDOWS
2092 reinit_console_type_create_x();
2093 reinit_console_type_create_device_x();
2096 reinit_console_type_create_gtk();
2099 reinit_specifier_type_create();
2100 reinit_specifier_type_create_image();
2101 reinit_specifier_type_create_gutter();
2102 reinit_specifier_type_create_objects();
2103 #ifdef HAVE_TOOLBARS
2104 reinit_specifier_type_create_toolbar();
2107 structure_type_create();
2109 structure_type_create_chartab();
2110 structure_type_create_faces();
2111 structure_type_create_rangetab();
2112 structure_type_create_hash_table();
2114 lstream_type_create();
2116 lstream_type_create_file_coding();
2118 #ifdef HAVE_UNIX_PROCESSES
2119 process_type_create_unix();
2122 reinit_vars_of_buffer();
2123 reinit_vars_of_console();
2124 #ifdef DEBUG_SXEMACS
2125 reinit_vars_of_debug();
2127 reinit_vars_of_device();
2128 reinit_vars_of_eval();
2129 #ifdef HAVE_X_WINDOWS
2130 reinit_vars_of_event_Xt();
2133 reinit_vars_of_event_gtk();
2135 #if defined(HAVE_TTY) && (defined (DEBUG_TTY_EVENT_STREAM) || !defined (HAVE_X_WINDOWS))
2136 reinit_vars_of_event_tty();
2138 reinit_vars_of_event_stream();
2139 #ifdef EF_USE_ASYNEQ
2140 reinit_vars_of_worker_asyneq();
2142 reinit_vars_of_events();
2143 reinit_vars_of_extents();
2144 reinit_vars_of_fileio();
2145 reinit_vars_of_font_lock();
2146 reinit_vars_of_glyphs();
2147 reinit_vars_of_glyphs_widget();
2148 reinit_vars_of_insdel();
2149 reinit_vars_of_lread();
2150 reinit_vars_of_lstream();
2151 reinit_vars_of_minibuf();
2152 reinit_vars_of_dynacat();
2153 #if defined WITH_EMODULES && defined HAVE_EMODULES && 0
2154 reinit_vars_of_module();
2155 #elif defined WITH_EMODULES && defined HAVE_EMODULES
2156 reinit_vars_of_emodng();
2158 reinit_vars_of_objects();
2159 reinit_vars_of_print();
2160 reinit_vars_of_search();
2161 reinit_vars_of_undo();
2162 reinit_vars_of_window();
2165 reinit_vars_of_menubar_gtk();
2168 #ifdef HAVE_X_WINDOWS
2169 reinit_vars_of_device_x();
2170 #ifdef HAVE_SCROLLBARS
2171 reinit_vars_of_scrollbar_x();
2173 #ifdef HAVE_MENUBARS
2174 reinit_vars_of_menubar_x();
2176 reinit_vars_of_select_x();
2177 #if defined (HAVE_MENUBARS) || defined (HAVE_SCROLLBARS) || defined (HAVE_DIALOGS) || defined (HAVE_TOOLBARS)
2178 reinit_vars_of_gui_x();
2180 #endif /* HAVE_X_WINDOWS */
2182 #if defined(MULE) && defined(HAVE_WNN)
2183 reinit_vars_of_mule_wnn();
2186 reinit_complex_vars_of_buffer();
2187 reinit_complex_vars_of_console();
2188 reinit_complex_vars_of_minibuf();
2191 reinit_vars_of_ffi();
2194 #if defined USE_STATIC_ASE && USE_STATIC_ASE
2195 reinit_vars_of_ase();
2201 /* the category subsystem needs some inits */
2206 /* CONGRATULATIONS!!! We have successfully initialized the Lisp
2210 /* Stuff that should not be done at dump time, including stuff that
2211 needs to be reset at run time. Order below should not matter.
2213 Many initializations taken from the environment should go here. */
2217 reinit_mule_category();
2219 #ifdef HAVE_POSTGRESQL
2220 init_postgresql_from_environment();
2224 /* Now do further initialization/setup of stuff that is not needed by the
2225 syms_of_() routines. This involves stuff that only is enabled in
2226 an interactive run (redisplay, user input, etc.) and stuff that is
2227 not needed until we start loading Lisp code (the reader). A lot
2228 of this stuff involves querying the current environment and needs
2229 to be done both at dump time and at run time. */
2231 init_initial_directory(); /* get the directory to use for the
2232 "*scratch*" buffer, etc. */
2234 init_callproc(); /* Set up the process environment (so that egetenv
2235 works), the basic directory variables
2236 (exec-directory and so on), and stuff
2237 related to subprocesses. This should be
2238 first because many of the functions below
2239 call egetenv() to get environment variables. */
2240 init_lread(); /* Set up the Lisp reader. */
2241 init_cmdargs(argc, (Extbyte **) argv, skip_args); /* Create list Vcommand_line_args */
2242 init_buffer(); /* Set default directory of *scratch* buffer */
2244 init_redisplay(); /* Determine terminal type.
2245 init_sys_modes uses results */
2247 init_event_stream(); /* Set up so we can get user input. */
2248 init_macros(); /* set up so we can run macros. */
2249 init_editfns(); /* Determine the name of the user we're running as */
2250 init_sxemacs_process(); /* set up for calling subprocesses */
2252 #ifdef WITH_NUMBER_TYPES
2253 /* Set up bignums, ratios, bigfloats, complex numbers.
2254 * This must be done before the Lisp reader is set up.
2260 init_sunpro(); /* Set up Sunpro usage tracking */
2262 #if defined (HAVE_NATIVE_SOUND) && defined (hp9000s800) && 0
2268 init_console_stream(restart); /* Create the first console */
2270 /* try to get the actual pathname of the exec file we are running */
2272 Vinvocation_name = Fcar(Vcommand_line_args);
2273 if (XSTRING_DATA(Vinvocation_name)[0] == '-') {
2274 /* SXEmacs as a login shell, oh goody! */
2275 Vinvocation_name = build_string(getenv("SHELL"));
2277 Vinvocation_directory = Vinvocation_name;
2279 if (!NILP(Ffile_name_directory(Vinvocation_name))) {
2280 /* invocation-name includes a directory component -- presumably it
2281 is relative to cwd, not $PATH */
2282 Vinvocation_directory =
2283 Fexpand_file_name(Vinvocation_name, Qnil);
2284 Vinvocation_path = Qnil;
2286 Vinvocation_path = decode_env_path("PATH", NULL);
2287 locate_file(Vinvocation_path, Vinvocation_name,
2288 Vlisp_EXEC_SUFFIXES,
2289 &Vinvocation_directory, X_OK);
2292 if (NILP(Vinvocation_directory))
2293 Vinvocation_directory = Vinvocation_name;
2296 Ffile_name_nondirectory(Vinvocation_directory);
2297 Vinvocation_directory =
2298 Ffile_name_directory(Vinvocation_directory);
2301 #if defined (LOCALTIME_CACHE) && defined (HAVE_TZSET)
2302 /* sun's localtime() has a bug. it caches the value of the time
2303 zone rather than looking it up every time. Since localtime() is
2304 called to bolt the undumping time into the undumped emacs, this
2305 results in localtime() ignoring the TZ environment variable.
2306 This flushes the new TZ value into localtime(). */
2308 #endif /* LOCALTIME_CACHE and TZSET */
2312 /* Handle -l loadup-and-dump, args passed by Makefile. */
2313 if (argc > 2 + skip_args && !strcmp(argv[1 + skip_args], "-l"))
2314 load_me = build_string(argv[2 + skip_args]);
2316 /* CANNOT_DUMP - this can never be right in SXEmacs --andyp */
2317 /* Unless next switch is -nl, load "loadup.el" first thing. */
2319 (argc > 1 + skip_args
2320 && !strcmp(argv[1 + skip_args], "-nl")))
2321 load_me = build_string("loadup.el");
2322 #endif /* CANNOT_DUMP */
2326 quantify_start_recording_data();
2327 #endif /* QUANTIFY */
2330 inhibit_non_essential_printing_operations = 0;
2332 /* This never returns. */
2333 initial_command_loop(load_me);
2337 /* Sort the args so we can find the most important ones
2338 at the beginning of argv. */
2340 /* First, here's a table of all the standard options. */
2342 struct standard_args {
2344 const char *longname;
2349 static const struct standard_args standard_args[] = {
2350 /* Handled by main_1 above: */
2351 {"--make-docfile", 0, 105, 0},
2352 {"-sd", "--show-dump-id", 105, 0},
2353 {"-t", "--terminal", 100, 1},
2354 {"-nd", "--no-dump-file", 95, 0},
2355 {"-ct", "--color-terminal", 92, 0},
2356 {"-nw", "--no-windows", 90, 0},
2357 {"-batch", "--batch", 85, 0},
2358 {"-debug-paths", "--debug-paths", 82, 0},
2359 {"-help", "--help", 80, 0},
2360 {"-version", "--version", 75, 0},
2362 {"-d", "--display", 80, 1},
2363 {"-display", 0, 80, 1},
2364 {"-NXHost", 0, 79, 0},
2365 {"-MachLaunch", 0, 79, 0},
2367 /* Handled by command-line-early in startup.el: */
2368 {"-q", "--no-init-file", 50, 0},
2369 {"-unmapped", 0, 50, 0},
2370 {"-no-init-file", 0, 50, 0},
2371 {"-vanilla", "--vanilla", 50, 0},
2372 {"-no-autoloads", "--no-autoloads", 50, 0},
2373 {"-no-site-file", "--no-site-file", 40, 0},
2374 {"-no-early-packages", "--no-early-packages", 35, 0},
2375 {"-u", "--user", 30, 1},
2376 {"-user", 0, 30, 1},
2377 {"-debug-init", "--debug-init", 20, 0},
2378 {"-debug-paths", "--debug-paths", 20, 0},
2381 {"-i", "--icon-type", 15, 0},
2382 {"-itype", 0, 15, 0},
2383 {"-iconic", "--iconic", 15, 0},
2384 {"-bg", "--background-color", 10, 1},
2385 {"-background", 0, 10, 1},
2386 {"-fg", "--foreground-color", 10, 1},
2387 {"-foreground", 0, 10, 1},
2388 {"-bd", "--border-color", 10, 1},
2389 {"-bw", "--border-width", 10, 1},
2390 {"-ib", "--internal-border", 10, 1},
2391 {"-ms", "--mouse-color", 10, 1},
2392 {"-cr", "--cursor-color", 10, 1},
2393 {"-fn", "--font", 10, 1},
2394 {"-font", 0, 10, 1},
2395 {"-g", "--geometry", 10, 1},
2396 {"-geometry", 0, 10, 1},
2397 {"-T", "--title", 10, 1},
2398 {"-title", 0, 10, 1},
2399 {"-name", "--name", 10, 1},
2400 {"-xrm", "--xrm", 10, 1},
2401 {"-r", "--reverse-video", 5, 0},
2403 {"-reverse", 0, 5, 0},
2404 {"-hb", "--horizontal-scroll-bars", 5, 0},
2405 {"-vb", "--vertical-scroll-bars", 5, 0},
2407 /* These have the same priority as ordinary file name args,
2408 so they are not reordered with respect to those. */
2409 {"-L", "--directory", 0, 1},
2410 {"-directory", 0, 0, 1},
2411 {"-l", "--load", 0, 1},
2413 {"-f", "--funcall", 0, 1},
2414 {"-funcall", 0, 0, 1},
2415 {"-eval", "--eval", 0, 1},
2416 {"-insert", "--insert", 0, 1},
2417 /* This should be processed after ordinary file name args and the like. */
2418 {"-kill", "--kill", -10, 0},
2421 /* Reorder the elements of ARGV (assumed to have ARGC elements)
2422 so that the highest priority ones come first.
2423 Do not change the order of elements of equal priority.
2424 If an option takes an argument, keep it and its argument together. */
2426 static void sort_args(int argc, char **argv)
2428 char **new_argv = (char**)malloc(sizeof(char*) * argc);
2429 /* For each element of argv,
2430 the corresponding element of options is:
2431 0 for an option that takes no arguments,
2432 1 for an option that takes one argument, etc.
2433 -1 for an ordinary non-option argument. */
2434 int *options = (int*)malloc(sizeof(int) * argc);
2435 int *priority = (int*)malloc(sizeof(int) * argc);
2439 int end_of_options_p = 0;
2441 /* Categorize all the options,
2442 and figure out which argv elts are option arguments. */
2443 for (from = 1; from < argc; from++) {
2446 /* Pseudo options "--" and "run-temacs" indicate end of
2448 if (!strcmp(argv[from], "--") ||
2449 !strcmp(argv[from], "run-temacs"))
2450 end_of_options_p = 1;
2451 if (!end_of_options_p && argv[from][0] == '-') {
2455 /* Look for a match with a known old-fashioned
2457 for (i = 0; i < countof(standard_args); i++) {
2458 if (!strcmp(argv[from],
2459 standard_args[i].name)) {
2460 options[from] = standard_args[i].nargs;
2462 standard_args[i].priority;
2463 if (from + standard_args[i].nargs >=
2465 fatal("Option `%s' requires "
2469 from += standard_args[i].nargs;
2474 /* Look for a match with a known long option. MATCH is
2475 -1 if no match so far, -2 if two or more matches so
2477 >= 0 (the table index of the match) if just one match
2479 if (argv[from][1] == '-') {
2481 thislen = strlen(argv[from]);
2482 equals = strchr(argv[from], '=');
2484 thislen = equals - argv[from];
2486 for (i = 0; i < countof(standard_args); i++)
2487 if (standard_args[i].longname
2488 && !strncmp(argv[from],
2490 longname, thislen)) {
2497 /* If we found exactly one match, use that. */
2500 standard_args[match].nargs;
2502 standard_args[match].priority;
2503 /* If --OPTION=VALUE syntax is used,
2504 this option uses just one argv
2508 if (from + options[from] >= argc) {
2509 fatal("Option `%s' requires "
2513 from += options[from];
2521 /* Copy the arguments, in order of decreasing priority, to NEW_ARGV. */
2522 new_argv[0] = argv[0];
2525 int best_priority = -9999;
2527 /* Find the highest priority remaining option.
2528 If several have equal priority, take the first of them. */
2529 for (from = 1; from < argc; from++) {
2530 if (argv[from] != 0 && priority[from] > best_priority) {
2531 best_priority = priority[from];
2534 /* Skip option arguments--they are tied to the options. */
2535 if (options[from] > 0) {
2536 from += options[from];
2544 /* Copy the highest priority remaining option, with its args, to
2546 new_argv[to++] = argv[best];
2547 for (i = 0; i < options[best]; i++) {
2548 new_argv[to++] = argv[best + i + 1];
2550 /* Clear out this option in ARGV. */
2552 for (i = 0; i < options[best]; i++) {
2553 argv[best + i + 1] = 0;
2557 memcpy(argv, new_argv, sizeof(char *) * argc);
2564 DEFUN("running-temacs-p", Frunning_temacs_p, 0, 0, 0, /*
2565 True if running temacs. This means we are in the dumping stage.
2566 This is false during normal execution of the `sxemacs' program, and
2567 becomes false once `run-emacs-from-temacs' is run.
2571 return run_temacs_argc >= 0 ? Qt : Qnil;
2574 DEFUN("run-emacs-from-temacs", Frun_emacs_from_temacs, 0, MANY, 0, /*
2575 Do not call this. It will reinitialize your SXEmacs. You'll be sorry.
2577 /* If this function is called from startup.el, it will be possible to run
2578 temacs as an editor using 'temacs -batch -l loadup.el run-temacs', instead
2579 of having to dump an emacs and then run that (when debugging emacs itself,
2580 this can be much faster)). [Actually, the speed difference isn't that
2581 much as long as your filesystem is local, and you don't end up with
2582 a dumped version in case you want to rerun it. This function is most
2583 useful when used as part of the `make all-elc' command. --ben]
2584 This will "restart" emacs with the specified command-line arguments.
2586 Martin thinks this function is most useful when using debugging
2587 tools like Purify or tcov that get confused by SXEmacs' dumping. */
2588 (int nargs, Lisp_Object * args))
2591 const Extbyte *wampum;
2594 Lisp_Object orig_invoc_name = Fcar(Vcommand_line_args);
2595 const Extbyte **wampum_all = alloca_array(const Extbyte *, nargs);
2596 int *wampum_all_len = alloca_array(int, nargs);
2598 assert(!gc_in_progress);
2600 if (run_temacs_argc < 0)
2601 error("I've lost my temacs-hood.");
2603 /* Need to convert the orig_invoc_name and all of the arguments
2604 to external format. */
2606 TO_EXTERNAL_FORMAT(LISP_STRING, orig_invoc_name,
2607 ALLOCA, (wampum, namesize), Qnative);
2610 for (ac = 0, total_len = namesize; ac < nargs; ac++) {
2611 CHECK_STRING(args[ac]);
2612 TO_EXTERNAL_FORMAT(LISP_STRING, args[ac],
2613 ALLOCA, (wampum_all[ac], wampum_all_len[ac]),
2615 wampum_all_len[ac]++;
2616 total_len += wampum_all_len[ac];
2618 DO_REALLOC(run_temacs_args, run_temacs_args_size, total_len, char);
2619 DO_REALLOC(run_temacs_argv, run_temacs_argv_size, nargs + 2, char *);
2621 memcpy(run_temacs_args, wampum, namesize);
2622 run_temacs_argv[0] = run_temacs_args;
2623 for (ac = 0; ac < nargs; ac++) {
2624 memcpy(run_temacs_args + namesize,
2625 wampum_all[ac], wampum_all_len[ac]);
2626 run_temacs_argv[ac + 1] = run_temacs_args + namesize;
2627 namesize += wampum_all_len[ac];
2629 run_temacs_argv[nargs + 1] = 0;
2630 catchlist = NULL; /* Important! Otherwise free_cons() calls in
2631 condition_case_unwind() may lead to GC death. */
2632 unbind_to(0, Qnil); /* this closes loadup.el */
2634 run_temacs_argc = nargs + 1;
2635 #if defined (HEAP_IN_DATA) && !defined(PDUMP)
2636 report_sheap_usage(0);
2638 LONGJMP(run_temacs_catch, 1);
2639 return Qnil; /* not reached; warning suppression */
2642 /* defined in alloc.c */
2643 extern void init_bdwgc(void);
2647 main(int argc, char **argv, char **envp)
2649 int volatile vol_argc = argc;
2650 char **volatile vol_argv = argv;
2651 char **volatile vol_envp = envp;
2652 /* This is hairy. We need to compute where the SXEmacs binary was invoked
2653 from because temacs initialization requires it to find the lisp
2654 directories. The code that recomputes the path is guarded by the
2655 restarted flag. There are three possible paths I've found so far
2658 temacs -- When running temacs for basic build stuff, the first main_1
2659 will be the only one invoked. It must compute the path else there
2660 will be a very ugly bomb in startup.el (can't find obvious location
2661 for doc-directory data-directory, etc.).
2663 temacs w/ run-temacs on the command line -- This is run to bytecompile
2664 all the out of date dumped lisp. It will execute both of the main_1
2665 calls and the second one must not touch the first computation because
2666 argc/argv are hosed the second time through.
2668 sxemacs -- Only the second main_1 is executed. The invocation path must
2669 computed but this only matters when running in place or when running
2672 As a bonus for straightening this out, SXEmacs can now be run in place
2673 as a login shell. This never used to work.
2675 As another bonus, we can now guarantee that
2676 (concat invocation-directory invocation-name) contains the filename
2677 of the SXEmacs binary we are running. This can now be used in a
2678 definite test for out of date dumped files. -slb */
2681 quantify_stop_recording_data();
2682 quantify_clear_data();
2683 #endif /* QUANTIFY */
2685 inhibit_non_essential_printing_operations = 1;
2686 suppress_early_error_handler_backtrace = 0;
2687 lim_data = 0; /* force reinitialization of this variable */
2689 /* Lisp_Object must fit in a word; check VALBITS and GCTYPEBITS */
2690 assert(sizeof(Lisp_Object) == sizeof(void *));
2692 #ifdef LINUX_SBRK_BUG
2696 /* defined in alloc.c */
2700 #ifdef DOUG_LEA_MALLOC
2701 if (mallopt(M_MMAP_MAX, 0) != 1)
2704 run_temacs_argc = 0;
2705 if (!SETJMP(run_temacs_catch)) {
2706 main_1(vol_argc, vol_argv, vol_envp, 0);
2708 /* run-emacs-from-temacs called */
2710 vol_argc = run_temacs_argc;
2711 vol_argv = run_temacs_argv;
2713 /* This makes absolutely no sense to anyone involved. There are
2714 several people using this stuff. We've compared versions on
2715 everything we can think of. We can find no difference.
2716 However, on both my systems environ is a plain old global
2717 variable initialized to zero. _environ is the one that
2718 contains pointers to the actual environment.
2720 Since we can't figure out the difference (and we're hours
2721 away from a release), this takes a very cowardly approach and
2722 is bracketed with both a system specific preprocessor test
2723 and a runtime "do you have this problem" test
2725 06/20/96 robertl@dgii.com */
2727 extern char **_environ;
2728 if ((unsigned)environ == 0)
2731 #endif /* _SCO_DS */
2734 #if defined (RUN_TIME_REMAP) && ! defined (PDUMP)
2736 /* obviously no-one uses this because where it was before initialized was
2738 run_time_remap(argv[0]);
2741 #ifdef DOUG_LEA_MALLOC
2742 if (initialized && (malloc_state_ptr != NULL)) {
2743 int rc = malloc_set_state(malloc_state_ptr);
2745 stderr_out("malloc_set_state failed, rc = %d\n",
2750 free(malloc_state_ptr);
2752 /* mmap works in glibc-2.1, glibc-2.0 (Non-Mule only)
2753 * and Linux libc5 */
2754 #if (defined(__GLIBC__) && __GLIBC_MINOR__ >= 1) || \
2755 defined(_NO_MALLOC_WARNING_) || \
2756 (defined(__GLIBC__) && __GLIBC_MINOR__ < 1 && !defined(MULE)) || \
2757 defined(DEBUG_DOUG_LEA_MALLOC)
2758 if (mallopt(M_MMAP_MAX, 0) != 1)
2765 #endif /* DOUG_LEA_MALLOC */
2767 run_temacs_argc = -1;
2769 main_1(vol_argc, vol_argv, vol_envp, restarted);
2771 return 0; /* unreached */
2775 /* Dumping apparently isn't supported by versions of GCC >= 2.8. */
2776 /* The following needs conditionalization on whether either SXEmacs or */
2777 /* various system shared libraries have been built and linked with */
2778 /* GCC >= 2.8. -slb */
2779 #if defined(GNU_MALLOC)
2780 static void voodoo_free_hook(void *mem)
2782 /* Disable all calls to free() when SXEmacs is exiting and it doesn't */
2785 #if defined __GNUC__ || defined __INTEL_COMPILER
2786 /* prototype of __free_hook varies with glibc version */
2787 (__typeof__(__free_hook))
2791 #endif /* GNU_MALLOC */
2793 DEFUN("kill-emacs", Fkill_emacs, 0, 1, "P", /*
2794 Exit the SXEmacs job and kill it. Ask for confirmation, without argument.
2795 If ARG is an integer, return ARG as the exit program code.
2796 If ARG is a string, stuff it as keyboard input.
2798 The value of `kill-emacs-hook', if not void,
2799 is a list of functions (of no args),
2800 all of which are called before SXEmacs is actually killed.
2804 /* This function can GC */
2805 struct gcpro gcpro1;
2812 if (!preparing_for_armageddon && !noninteractive)
2813 run_hook(Qkill_emacs_hook);
2815 ensure_no_quitting_from_now_on();
2817 if (!preparing_for_armageddon) {
2818 Lisp_Object concons, nextcons;
2820 /* Normally, go ahead and delete all the consoles now.
2821 Some unmentionably lame window systems (MS Wwwww...... eek,
2822 I can't even say it) don't properly clean up after themselves,
2823 and even for those that do, it might be cleaner this way.
2824 If we're going down, however, we don't do this (might
2825 be too dangerous), and if we get a crash somewhere within
2826 this loop, we'll still autosave and won't try this again. */
2828 LIST_LOOP_DELETING(concons, nextcons, Vconsole_list) {
2829 /* There is very little point in deleting the stream console.
2830 It uses stdio, which should flush any buffered output and
2831 something can only go wrong. -slb */
2832 /* I changed my mind. There's a stupid hack in close to add
2833 a trailing newline. */
2834 /*if (!CONSOLE_STREAM_P (XCONSOLE (XCAR (concons)))) */
2835 delete_console_internal(XCONSOLE(XCAR(concons)), 1, 1,
2842 shut_down_emacs(0, STRINGP(arg) ? arg : Qnil, 0);
2844 #if defined(GNU_MALLOC)
2846 #if defined __GNUC__ || defined __INTEL_COMPILER
2847 /* prototype of __free_hook varies with glibc version */
2848 (__typeof__(__free_hook))
2853 exit(INTP(arg) ? XINT(arg) : 0);
2855 return Qnil; /* I'm sick of the compiler warning */
2858 /* Perform an orderly shutdown of SXEmacs. Autosave any modified
2859 buffers, kill any child processes, clean up the terminal modes (if
2860 we're in the foreground), and other stuff like that. Don't perform
2861 any redisplay; this may be called when SXEmacs is shutting down in
2862 the background, or after its X connection has died.
2864 If SIG is a signal number, print a message for it.
2866 This is called by fatal signal handlers and Fkill_emacs. It used to
2867 be called by X protocol error handlers, but instead they now call
2869 static void shut_down_emacs(int sig, Lisp_Object stuff, int no_auto_save)
2871 /* This function can GC */
2872 /* Prevent running of hooks and other non-essential stuff
2874 preparing_for_armageddon = 1;
2876 ensure_no_quitting_from_now_on();
2879 quantify_stop_recording_data();
2880 #endif /* QUANTIFY */
2882 /* This is absolutely the most important thing to do, so make sure
2883 we do it now, before anything else. We might have crashed and
2884 be in a weird inconsistent state, and potentially anything could
2885 set off another protection fault and cause us to bail out
2887 /* Steve writes the following:
2889 [[I'm not removing the code entirely, yet. We have run up against
2890 a spate of problems in diagnosing crashes due to crashes within
2891 crashes. It has very definitely been determined that code called
2892 during auto-saving cannot work if SXEmacs crashed inside of GC.
2893 We already auto-save on an itimer so there cannot be too much
2894 unsaved stuff around, and if we get better crash reports we might
2895 be able to get more problems fixed so I'm disabling this. -slb]]
2897 and DISABLES AUTO-SAVING ENTIRELY during crashes! Way way bad idea.
2899 Instead let's just be more intelligent about avoiding crashing
2900 when possible, esp. nested crashes.
2903 Fdo_auto_save(Qt, Qnil); /* do this before anything hazardous */
2906 reset_all_consoles();
2907 if (sig && sig != SIGTERM) {
2909 stderr_out("\nFatal error.\n\n");
2911 stderr_out("\nFatal error (%d).\n\n", sig);
2913 ("Your files have been auto-saved.\n"
2914 "Use `M-x recover-session' to recover them.\n"
2916 "Your version of SXEmacs was distributed with a PROBLEMS file that may describe\n"
2917 "your crash, and with luck a workaround. Please check it first, but do report\n"
2918 "the crash anyway. "
2920 "\n\nPlease report this bug by selecting `Report-Bug' in the InfoDock menu.\n"
2921 "*BE SURE* to include the SXEmacs configuration from M-x describe-installation,\n"
2922 "or the file Installation in the top directory of the build tree.\n"
2924 "Please report this bug by invoking M-x report-sxemacs-bug,\n"
2925 "or by selecting `Send Bug Report' from the Help menu. If necessary, send\n"
2926 "ordinary email to `sxemacs-devel@sxemacs.org'. *MAKE SURE* to include the SXEmacs\n"
2927 "configuration from M-x describe-installation, or equivalently the file\n"
2928 "Installation in the top of the build tree.\n"
2932 "*Please* try *hard* to obtain a C stack backtrace; without it, we are unlikely\n"
2933 "to be able to analyze the problem. Locate the core file produced as a result\n"
2934 "of this crash (often called `core' or `core.<process-id>', and located in\n"
2935 "the directory in which you started SXEmacs or your home directory), and type\n"
2943 /* Now try to determine the actual path to the executable,
2944 to try to make the backtrace-determination process as foolproof
2946 if (STRINGP(Vinvocation_name))
2947 name = (char *)XSTRING_DATA(Vinvocation_name);
2950 if (STRINGP(Vinvocation_directory))
2952 (char *)XSTRING_DATA(Vinvocation_directory);
2953 if (!dir || dir[0] != '/')
2954 stderr_out("`which %s`", name);
2955 else if (dir[strlen(dir) - 1] != '/')
2956 stderr_out("%s/%s", dir, name);
2958 stderr_out("%s%s", dir, name);
2963 "then type `where' at the debugger prompt. "
2964 "No GDB on your system? You may\n"
2965 "have DBX, or XDB, or SDB. (Ask your system "
2966 "administrator if you need help.)\n"
2967 "If no core file was produced, enable them "
2968 "(often with `ulimit -c unlimited'\n"
2969 "in case of future recurrance of the crash.\n");
2972 stuff_buffered_input(stuff);
2974 kill_buffer_processes(Qnil);
2976 #ifdef CLASH_DETECTION
2984 #if !defined(PDUMP) || !defined(SYSTEM_MALLOC)
2985 extern char my_edata[];
2988 extern void disable_free_hook(void);
2990 DEFUN("dump-emacs", Fdump_emacs, 2, 2, 0, /*
2991 Dump current state of SXEmacs into executable file FILENAME.
2992 Take symbols from SYMFILE (presumably the file you executed to run SXEmacs).
2993 This is used in the file `loadup.el' when building SXEmacs.
2995 Remember to set `command-line-processed' to nil before dumping
2996 if you want the dumped SXEmacs to process its command line
2997 and announce itself normally when it is run.
2999 (symfile, filename))
3001 /* This function can GC */
3002 struct gcpro gcpro1, gcpro2;
3005 GCPRO2(filename, symfile);
3009 Vinvocation_directory = Vinvocation_name = Qnil;
3010 Vcommand_line_args = Qnil;
3013 #ifdef FREE_CHECKING
3016 /* When we're dumping, we can't use the debugging free() */
3017 disable_free_hook();
3020 CHECK_STRING(filename);
3021 filename = Fexpand_file_name(filename, Qnil);
3022 if (!NILP(symfile)) {
3023 CHECK_STRING(symfile);
3024 if (XSTRING_LENGTH(symfile) > 0) {
3025 symfile = Fexpand_file_name(symfile, Qnil);
3031 opurify = purify_flag;
3034 #if defined (HEAP_IN_DATA) && !defined(PDUMP)
3035 report_sheap_usage(1);
3043 disksave_object_finalization();
3044 release_breathing_space();
3046 /* Tell malloc where start of impure now is */
3047 /* Also arrange for warnings when nearly out of space. */
3048 #ifndef SYSTEM_MALLOC
3049 memory_warnings(my_edata, malloc_warning);
3058 LISP_STRING_TO_EXTERNAL(filename, filename_ext, Qfile_name);
3060 if (STRINGP(symfile)) {
3061 LISP_STRING_TO_EXTERNAL(symfile, symfile_ext,