Coverity: Resource leak: CID 400022
[sxemacs] / src / emacs.c
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.
7
8 This file is part of SXEmacs
9
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.
14
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.
19
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/>. */
22
23
24 /* Synched up with: Mule 2.0, FSF 19.28. */
25
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.
31
32 -- A time line for Lucid Emacs/XEmacs is
33
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
57   November 30, 1997.
58 version 20.4 released February 28, 1998.
59
60 -- A time line for GNU Emacs version 19 is
61
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.
91
92 -- A time line for GNU Emacs version 20 is
93
94 version 20.1 released September 17, 1997.
95 version 20.2 released September 20, 1997.
96 version 20.3 released August 19, 1998.
97
98 -- A time line for GNU Emacs version 18 and older is
99
100 GNU Emacs version 13 (the first public release) was released on
101   March 20, 1985.
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
112   System V.
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.
156
157 */
158
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. */
163
164 #include <config.h>
165 #include "lisp.h"
166
167 #include "backtrace.h"          /* run-emacs-from-temacs needs this */
168 #include "buffer.h"
169 #include "commands.h"
170 #include "ui/console.h"
171 #include "process.h"
172 #include "ui/redisplay.h"
173 #include "ui/frame.h"
174 #include "sysdep.h"
175
176 #include "syssignal.h"          /* Always include before systty.h */
177 #include "ui/systty.h"
178 #include "sysfile.h"
179 #include "systime.h"
180
181 #if defined WITH_EMODULES && defined HAVE_EMODULES
182 # include "emodules-ng.h"
183 #endif
184
185 #ifdef PDUMP
186 #include "dumper.h"
187 #endif
188
189 #ifndef SEPCHAR
190 #define SEPCHAR ':'
191 #endif
192
193 #ifdef QUANTIFY
194 #include <quantify.h>
195 #endif
196
197 #if defined WITH_EMODULES && defined HAVE_EMODULES && 0
198 #include "sysdll.h"
199 #endif
200
201 #if defined (HAVE_LOCALE_H) && \
202    (defined (I18N2) || defined (I18N3) || defined (I18N4))
203 #include <locale.h>
204 #endif
205
206 /* For PATH_EXEC */
207 #include <sxe-paths.h>
208
209 /* for stack exploitation */
210 #if defined HAVE_SYS_RESOURCE_H
211 # include <sys/resource.h>
212 #endif
213
214 /* for the reinit funs */
215 #include "skiplist.h"
216 #include "dllist.h"
217 #include "elhash.h"
218
219 #if defined HAVE_BDWGC && defined EF_USE_BDWGC
220 # if defined HAVE_GC_GC_H
221 #  include "gc/gc.h"
222 # elif defined HAVE_GC_H
223 #  include "gc.h"
224 # elif 1
225 /* declare the 3 funs we need */
226 extern void *GC_init(void);
227 # else
228 #  error Go back to your planet!
229 # endif
230 #endif  /* HAVE_BDWGC */
231
232 #if defined (HEAP_IN_DATA) && !defined(PDUMP)
233 void report_sheap_usage(int die_if_pure_storage_exceeded);
234 #endif
235
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 */
241
242 /* Command line args from shell, as list of strings */
243 Lisp_Object Vcommand_line_args;
244
245 /* Set nonzero after SXEmacs has started up the first time.
246   Prevents reinitialization of the Lisp world and keymaps
247   on subsequent starts.  */
248 int initialized;
249
250 #ifdef DOUG_LEA_MALLOC
251 # include <malloc.h>
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 */
256
257 # ifdef REL_ALLOC
258 void r_alloc_reinit(void);
259 # endif
260
261 /* Variable whose value is symbol giving operating system type. */
262 Lisp_Object Vsystem_type;
263
264 /* Variable whose value is string giving configuration built for.  */
265 Lisp_Object Vsystem_configuration;
266
267 /* Variable whose value is string containing the configuration options
268    SXEmacs was built with.  */
269 Lisp_Object Vsystem_configuration_options;
270
271 /* Version numbers and strings */
272 Lisp_Object Vemacs_major_version;
273 Lisp_Object Vemacs_minor_version;
274 Lisp_Object Vemacs_patch_level;
275 Lisp_Object Vemacs_beta_version;
276 Lisp_Object Vsxemacs_git_version;
277 Lisp_Object Vsxemacs_codename;
278 #ifdef INFODOCK
279 Lisp_Object Vinfodock_major_version;
280 Lisp_Object Vinfodock_minor_version;
281 Lisp_Object Vinfodock_build_version;
282 #endif
283
284 /* The path under which SXEmacs was invoked. */
285 Lisp_Object Vinvocation_path;
286
287 /* The name under which SXEmacs was invoked, with any leading directory
288    names discarded.  */
289 Lisp_Object Vinvocation_name;
290
291 /* The directory name from which SXEmacs was invoked.  */
292 Lisp_Object Vinvocation_directory;
293
294 #if 0                           /* FSFmacs */
295 /* The directory name in which to find subdirs such as lisp and etc.
296    nil means get them only from PATH_LOADSEARCH.  */
297 Lisp_Object Vinstallation_directory;
298 #endif
299
300 Lisp_Object Vemacs_program_name, Vemacs_program_version;
301 Lisp_Object Vexec_path;
302 Lisp_Object Vexec_directory, Vconfigure_exec_directory;
303 Lisp_Object Vlisp_directory, Vconfigure_lisp_directory;
304 Lisp_Object Vmule_lisp_directory, Vconfigure_mule_lisp_directory;
305 Lisp_Object Vmodule_directory, Vconfigure_module_directory;
306 Lisp_Object Vsite_module_directory, Vconfigure_site_module_directory;
307 Lisp_Object Vconfigure_package_path;
308 Lisp_Object Vdata_directory, Vconfigure_data_directory;
309 Lisp_Object Vdoc_directory, Vconfigure_doc_directory;
310 Lisp_Object Vconfigure_lock_directory;
311 Lisp_Object Vdata_directory_list;
312 Lisp_Object Vconfigure_info_directory;
313 Lisp_Object Vconfigure_info_path;
314 Lisp_Object Vinternal_error_checking;
315 Lisp_Object Vmail_lock_methods, Vconfigure_mail_lock_method;
316 Lisp_Object Vpath_separator;
317
318 /* The default base directory SXEmacs is installed under. */
319 Lisp_Object Vconfigure_exec_prefix_directory, Vconfigure_prefix_directory;
320
321 /* If nonzero, set SXEmacs to run at this priority.  This is also used
322    in child_setup and sys_suspend to make sure subshells run at normal
323    priority. */
324 Fixnum emacs_priority;
325
326 /* Some FSF junk with running_asynch_code, to preserve the match
327    data.  Not necessary because we don't call process filters
328    asynchronously (i.e. from within QUIT). */
329 /* #### Delete this when merging the rest of my code */
330 int running_asynch_code;
331
332 /* If non-zero, a window-system was specified on the command line. */
333 int display_arg;
334
335 /* Type of display specified.  We cannot use a Lisp symbol here because
336    Lisp symbols may not initialized at the time that we set this
337    variable. */
338 const char *display_use;
339
340 /* If non-zero, then the early error handler will only print the error
341    message and exit. */
342 int suppress_early_error_handler_backtrace;
343
344 /* An address near the bottom of the stack.
345    Tells GC how to save a copy of the stack.  */
346 char *stack_bottom;
347 /* the stack size as imposed by the system */
348 size_t sys_stk_sz = 0;
349
350 #ifdef USG_SHARED_LIBRARIES
351 /* If nonzero, this is the place to put the end of the writable segment
352    at startup.  */
353
354 uintptr_t bss_end = 0;
355 #endif
356
357 /* Number of bytes of writable memory we can expect to be able to get */
358 #ifdef _RLIM_T_DECLARED
359 rlim_t lim_data;
360 #else
361 unsigned long lim_data;
362 #endif
363
364 /* WARNING!
365
366    Some LISP-visible command-line options are set by SXEmacs _before_ the
367    data is dumped in building a --pdump SXEmacs, but used _after_ it is
368    restored in normal operation.  Thus the dump-time values overwrite the
369    values SXEmacs is getting at runtime.  Such variables must be saved
370    before loading the dumpfile, and restored afterward.
371
372    Therefore these variables may not be initialized in vars_of_emacs().
373
374    The save/restore is done immediately before and after pdump_load() in
375    main_1().  See that function for the current list of protected variables.
376
377    Note that saving/restoring is only necessary for a few variables that are
378      o command line arguments effective at runtime (as opposed to dump-time),
379      o parsed before pdump_load, and
380      o exported to Lisp via a DEFVAR.
381 */
382
383 /* Nonzero means running SXEmacs without interactive terminal.  */
384
385 int noninteractive;
386
387 /* Value of Lisp variable `noninteractive'.
388    Normally same as C variable `noninteractive'
389    but nothing terrible happens if user sets this one.
390
391    Shadowed from the pdumper by `noninteractive'. */
392
393 int noninteractive1;
394
395 /* Nonzero means don't perform site-modules searches at startup */
396 int inhibit_site_modules;
397
398 /* Nonzero means don't respect early packages at startup */
399 int inhibit_early_packages;
400
401 /* Nonzero means we warn about early packages shadowing late packages at startup */
402 int warn_early_package_shadows;
403
404 /* Nonzero means don't load package autoloads at startup */
405 int inhibit_autoloads;
406
407 /* Nonzero means don't load the dump file (ignored if not PDUMP)  */
408 int nodumpfile;
409
410 /* Nonzero means we assume all ttys are 8 color ANSI terminals */
411 int assume_colorterm;
412
413 /* Nonzero means print debug information about path searching */
414 int debug_paths;
415
416 /* Save argv and argc.  */
417 static Extbyte **initial_argv;  /* #### currently unused */
418 static int initial_argc;        /* #### currently unused */
419
420 static void sort_args(int argc, char **argv);
421
422 Lisp_Object Qkill_emacs_hook;
423 Lisp_Object Qsave_buffers_kill_emacs;
424
425 extern Lisp_Object Vlisp_EXEC_SUFFIXES;
426 \f
427 /* Ben's capsule summary about expected and unexpected exits from SXEmacs.
428
429    Expected exits occur when the user directs SXEmacs to exit, for example
430    by pressing the close button on the only frame in SXEmacs, or by typing
431    C-x C-c.  This runs `save-buffers-kill-emacs', which saves any necessary
432    buffers, and then exits using the primitive `kill-emacs'.
433
434    However, unexpected exits occur in a few different ways:
435
436      -- a memory access violation or other hardware-generated exception
437         occurs.  This is the worst possible problem to deal with, because
438         the fault can occur while SXEmacs is in any state whatsoever, even
439         quite unstable ones.  As a result, we need to be *extremely* careful
440         what we do.
441      -- we are using one X display (or if we've used more, we've closed the
442         others already), and some hardware or other problem happens and
443         suddenly we've lost our connection to the display.  In this situation,
444         things are not so dire as in the last one; our code itself isn't
445         trashed, so we can continue execution as normal, after having set
446         things up so that we can exit at the appropriate time.  Our exit
447         still needs to be of the emergency nature; we have no displays, so
448         any attempts to use them will fail.  We simply want to auto-save
449         (the single most important thing to do during shut-down), do minimal
450         cleanup of stuff that has an independent existence outside of SXEmacs,
451         and exit.
452
453         Currently, both unexpected exit scenarios described above set
454         preparing_for_armageddon to indicate that nonessential and possibly
455         dangerous things should not be done, specifically:
456
457         -- no garbage collection.
458         -- no hooks are run.
459         -- no messages of any sort from autosaving.
460         -- autosaving tries harder, ignoring certain failures.
461         -- existing frames are not deleted.
462
463         (Also, all places that set preparing_for_armageddon also
464         set dont_check_for_quit.  This happens separately because it's
465         also necessary to set other variables to make absolutely sure
466         no quitting happens.)
467
468         In the first scenario above (the access violation), we also set
469         fatal_error_in_progress.  This causes more things to not happen:
470
471         -- assertion failures do not abort.
472         -- printing code does not do code conversion or gettext when
473            printing to stdout/stderr.
474 */
475
476 /* Nonzero if handling a fatal error already. */
477 int fatal_error_in_progress;
478
479 /* Non-nil means we're going down, so we better not run any hooks
480    or do other non-essential stuff. */
481 int preparing_for_armageddon;
482
483 /* Nonzero means we're in an unstable situation and need to skip
484    i18n conversions and such during printing. */
485 int inhibit_non_essential_printing_operations;
486
487 static JMP_BUF run_temacs_catch;
488
489 static int run_temacs_argc;
490 static char **run_temacs_argv;
491 static char *run_temacs_args;
492 static EMACS_INT run_temacs_argv_size;
493 static EMACS_INT run_temacs_args_size;
494
495 static void shut_down_emacs(int sig, Lisp_Object stuff, int no_auto_save);
496
497 /* ------------------------------- */
498 /*  low-level debugging functions  */
499 /* ------------------------------- */
500
501 #define debugging_breakpoint()
502
503 void
504 debug_break(void)
505 {
506         debugging_breakpoint();
507 }
508
509 /* #### There must be a better way!!!! */
510
511 static JMP_BUF memory_error_jump;
512
513 #if 1
514 static SIGTYPE
515 debug_memory_error(int signum)
516 {
517         EMACS_REESTABLISH_SIGNAL(signum, debug_memory_error);
518         EMACS_UNBLOCK_SIGNAL(signum);
519         LONGJMP(memory_error_jump, 1);
520 }
521 #endif
522
523 static char dummy_char;
524
525 /* Return whether all bytes in the specified memory block can be read. */
526 int
527 debug_can_access_memory(void *ptr, Bytecount len)
528 {
529         /* Use volatile to protect variables from being clobbered by longjmp. */
530         SIGTYPE(*volatile old_sigbus) (int);
531         SIGTYPE(*volatile old_sigsegv) (int);
532         volatile int old_errno = errno;
533         volatile int retval = 1;
534
535         if (!SETJMP(memory_error_jump)) {
536 #if 1
537                 old_sigbus =
538                         (SIGTYPE(*)(int))signal(SIGBUS, debug_memory_error);
539                 old_sigsegv =
540                         (SIGTYPE(*)(int))signal(SIGSEGV, debug_memory_error);
541 #endif
542                 /*
543                  * Examine memory pool at PTR, trying to cheat
544                  * compiler's optimisations.
545                  */
546                 while (len-- > 0) {
547                         dummy_char = ((char*)ptr)[len];
548                 }
549         } else {
550                 retval = 0;
551         }
552         signal(SIGBUS, old_sigbus);
553         signal(SIGSEGV, old_sigsegv);
554         errno = old_errno;
555
556         return retval;
557 }
558
559 #ifdef DEBUG_SXEMACS
560
561 DEFUN("force-debugging-signal", Fforce_debugging_signal, 0, 1, 0, /*
562 Cause SXEmacs to enter the debugger.
563 On some systems, there may be no way to do this gracefully; if so,
564 nothing happens unless ABORT is non-nil, in which case SXEmacs will
565 abort() -- a sure-fire way to immediately get back to the debugger,
566 but also a sure-fire way to kill SXEmacs (and dump core on Unix
567 systems)!
568 */
569       (abort_))
570 {
571         debugging_breakpoint();
572         if (!NILP(abort_))
573                 abort();
574         return Qnil;
575 }
576
577 #endif                          /* DEBUG_SXEMACS */
578
579 static void
580 ensure_no_quitting_from_now_on(void)
581 {
582         /* make sure no quitting from now on!! */
583         dont_check_for_quit = 1;
584         Vinhibit_quit = Qt;
585         Vquit_flag = Qnil;
586 }
587
588 #if 1
589 /* Handle bus errors, illegal instruction, etc. */
590 SIGTYPE
591 fatal_error_signal(int sig)
592 {
593         fatal_error_in_progress++;
594         inhibit_non_essential_printing_operations = 1;
595         preparing_for_armageddon = 1;
596
597         ensure_no_quitting_from_now_on();
598
599         /* Unblock the signal so that if the same signal gets sent in the
600            code below, we avoid a deadlock. */
601         EMACS_UNBLOCK_SIGNAL(sig);
602
603         /* Only try auto-saving first time through.  If we crash in auto-saving,
604            don't do it again. */
605         if (fatal_error_in_progress == 1) {
606                 Fdo_auto_save(Qt, Qnil);        /* do this before anything hazardous */
607                 /* Do this so that the variable has the same value of 2 regardless of
608                    whether we made it through auto-saving correctly. */
609                 fatal_error_in_progress++;
610         } else if (fatal_error_in_progress == 2)
611                 stderr_out("WARNING: Unable to auto-save your files properly.\n"
612                            "Some or all may in fact have been auto-saved.\n"
613                            "\n");
614
615         /* Now, reset our signal handler, so the next time, we just die.
616            Don't do this before auto-saving. */
617         signal(sig, SIG_DFL);
618
619         /* Keep in mind that there's more than one signal that we can crash
620            on. */
621         /* If fatal error occurs in code below, avoid infinite recursion.  */
622         if (fatal_error_in_progress <= 2) {
623                 shut_down_emacs(sig, Qnil, 1);
624                 stderr_out("\nLisp backtrace follows:\n\n");
625                 Fbacktrace(Qexternal_debugging_output, Qt);
626 # if 0                          /* This is evil, rarely useful, and causes grief in some cases. */
627                 /* Check for Sun-style stack printing via /proc */
628                 {
629                         const char *pstack = "/usr/proc/bin/pstack";
630                         if (access(pstack, X_OK) == 0) {
631                                 char buf[100];
632                                 int sz = snprintf(buf, sizeof(buf), "%s %d >&2", pstack,
633                                         (int)getpid());
634                                 stderr_out("\nC backtrace follows:\n"
635                                            "(A real debugger may provide better information)\n\n");
636                                 if ( sz >= 0 && sz < sizeof(buf)) {
637                                         sz = system(buf);
638                                         if ( sz != 0 )
639                                                 stderr_out("\nStacktrace utility execution error code: %d\n", sz);
640                                 } else {
641                                         stderr_out("\nCould not build command line for stacktrace utility.\n");
642                                 }
643                         }
644                 }
645 # endif
646         }
647         /* Signal the same code; this time it will really be fatal. */
648         kill(getpid(), sig);
649         SIGRETURN;
650 }
651 #endif
652
653 \f
654 #ifdef SIGDANGER
655
656 /* Handler for SIGDANGER.  */
657 SIGTYPE
658 memory_warning_signal(int sig)
659 {
660         /* #### bad bad bad; this function shouldn't do anything except
661            set a flag, or weird corruption could happen. */
662         signal(sig, memory_warning_signal);
663
664         malloc_warning
665             (GETTEXT
666              ("Operating system warns that virtual memory is running low.\n"));
667
668         /* It might be unsafe to call do_auto_save now.  */
669         force_auto_save_soon();
670 }
671 #endif                          /* SIGDANGER */
672 \f
673 /* Code for dealing with Lisp access to the Unix command line */
674
675 static Lisp_Object
676 make_arg_list_1(int argc, Extbyte ** argv, int skip_args)
677 {
678         Lisp_Object result = Qnil;
679         REGISTER int i;
680
681         for (i = argc - 1; i >= 0; i--) {
682                 if (i != 0 && i <= skip_args)
683                         continue;
684
685                 result = Fcons(build_ext_string(argv[i], Qcommand_argument_encoding), result);
686         }
687         return result;
688 }
689
690 Lisp_Object
691 make_arg_list(int argc, Extbyte ** argv)
692 {
693         return make_arg_list_1(argc, argv, 0);
694 }
695
696 /* Calling functions are also responsible for calling free_argc_argv
697    when they are done with the generated list. */
698 void
699 make_argc_argv(Lisp_Object argv_list, int *argc, Extbyte *** argv)
700 {
701         Lisp_Object next;
702         int n = XINT(Flength(argv_list));
703         REGISTER int i;
704         *argv = (Extbyte **) malloc((n + 1) * sizeof(Extbyte *));
705
706         for (i = 0, next = argv_list; i < n; i++, next = XCDR(next)) {
707                 const Extbyte *temp;
708                 CHECK_STRING(XCAR(next));
709
710                 LISP_STRING_TO_EXTERNAL(XCAR(next), temp,
711                                         Qcommand_argument_encoding);
712                 (*argv)[i] = strdup(temp);
713         }
714         (*argv)[n] = 0;
715         *argc = i;
716 }
717
718 void free_argc_argv(Extbyte ** argv)
719 {
720         int elt = 0;
721
722         while (argv[elt]) {
723                 free(argv[elt]);
724                 elt++;
725         }
726         free(argv);
727 }
728
729 static void init_cmdargs(int argc, Extbyte ** argv, int skip_args)
730 {
731         initial_argv = argv;
732         initial_argc = argc;
733
734         Vcommand_line_args = make_arg_list_1(argc, argv, skip_args);
735 }
736
737 DEFUN("invocation-name", Finvocation_name, 0, 0, 0, /*
738 Return the program name that was used to run SXEmacs.
739 Any directory names are omitted.
740 */
741       ())
742 {
743         return Fcopy_sequence(Vinvocation_name);
744 }
745
746 DEFUN("invocation-directory", Finvocation_directory, 0, 0, 0, /*
747 Return the directory name in which the Emacs executable was located.
748 */
749       ())
750 {
751         return Fcopy_sequence(Vinvocation_directory);
752 }
753 \f
754 #ifdef I18N4
755                                 /* #### - don't know why I18N4 on SunOS/JLE
756                                    can't deal with this.  It's a potential
757                                    bug that needs to be looked at. */
758 # undef RUN_TIME_REMAP
759 #endif
760
761 /* Test whether the next argument in ARGV matches SSTR or a prefix of
762    LSTR (at least MINLEN characters).  If so, then if VALPTR is non-null
763    (the argument is supposed to have a value) store in *VALPTR either
764    the next argument or the portion of this one after the equal sign.
765    ARGV is read starting at position *SKIPPTR; this index is advanced
766    by the number of arguments used.
767
768    Too bad we can't just use getopt for all of this, but we don't have
769    enough information to do it right.  */
770
771 static int
772 argmatch(char **argv, int argc, char *sstr, char *lstr,
773          int minlen, char **valptr, int *skipptr)
774 {
775         char *p = NULL;
776         int arglen;
777         char *arg;
778
779         /* Don't access argv[argc]; give up in advance.  */
780         if (argc <= *skipptr + 1)
781                 return 0;
782
783         arg = argv[*skipptr + 1];
784         if (arg == NULL)
785                 return 0;
786         if (strcmp(arg, sstr) == 0) {
787                 if (valptr != NULL) {
788                         *valptr = argv[*skipptr + 2];
789                         *skipptr += 2;
790                 } else
791                         *skipptr += 1;
792                 return 1;
793         }
794         arglen = (valptr != NULL && (p = strchr(arg, '=')) != NULL
795                   ? p - arg : (int)strlen(arg));
796         if (lstr == 0 || arglen < minlen || strncmp(arg, lstr, arglen) != 0)
797                 return 0;
798         else if (valptr == NULL) {
799                 *skipptr += 1;
800                 return 1;
801         } else if (p != NULL) {
802                 *valptr = p + 1;
803                 *skipptr += 1;
804                 return 1;
805         } else if (argv[*skipptr + 2] != NULL) {
806                 *valptr = argv[*skipptr + 2];
807                 *skipptr += 2;
808                 return 1;
809         } else {
810                 return 0;
811         }
812 }
813
814 static int
815 make_docfile(int c, char **v)
816 {
817 #define make_docfile_prog       "make-docfile\0"
818 #define make_docfile_opt        "--make-docfile"
819         /* C99 we need you */
820         size_t edlen = XSTRING_LENGTH(Vexec_directory);
821         char mdocfile[edlen+countof(make_docfile_prog)];
822         char **newargv = xnew_array_and_zero(char*, c), **p;
823         int  ret = -1;
824
825         /* set up the program call */
826         xstrncpy(mdocfile,
827                  (char*)XSTRING_DATA(Vexec_directory),
828                  XSTRING_LENGTH(Vexec_directory));
829         xstrncpy(mdocfile+XSTRING_LENGTH(Vexec_directory),
830                  make_docfile_prog, countof(make_docfile_prog));
831
832         /* find the --make-docfile option */
833         for (p = v; *p; p++) {
834                 if (strncmp(*p, make_docfile_opt,
835                             countof(make_docfile_opt)) == 0) {
836                         p++;
837                         break;
838                 }
839         }
840
841         /* fill the new argv array */
842         newargv[0] = make_docfile_prog;
843         for (char **o = p, **n = &newargv[1]; *o;) {
844                 *n++ = *o++;
845         }
846         ret = execv(mdocfile, newargv);
847         xfree(newargv);
848         return ret;
849 }
850
851 static inline void*
852 __get_sp(void)
853 {
854         void *sp = 0;
855
856 #if 0
857 /* we need some checks whether this is supported! */
858         __asm__ __volatile__ (
859                 "movl %%esp, %[stkptr]\n\t"
860                 : [stkptr] "=m" (sp));
861 #endif
862
863         return sp;
864 }
865
866 static size_t
867 __sys_stk_sz(void)
868 {
869 /* return the stack size limit */
870 #if defined HAVE_GETRLIMIT64
871         struct rlimit64 foo;
872         (void)getrlimit64(RLIMIT_STACK, &foo);
873 #elif defined HAVE_GETRLIMIT
874         struct rlimit foo;
875         (void)getrlimit(RLIMIT_STACK, &foo);
876 #else
877         /* bollocks, maybe just a small one? 64k? */
878         struct {size_t rlim_cur;} foo = {65536};
879 #endif
880         return foo.rlim_cur;
881 }
882
883
884 /* Make stack traces always identify version + configuration */
885 #define main_1 STACK_TRACE_EYE_CATCHER
886
887 /* This function is not static, so that the compiler is less likely to
888    inline it, which would make it not show up in stack traces.
889
890    The restart argument is a flag that indicates that main_1 is now
891    being called for the second time in this invocation of sxemacs; this can
892    only happen in an sxemacs that is not loaded with dumped data (temacs
893    with the conventional dumper or sxemacs -nd with the pdumper).   See
894    Frun_emacs_from_temacs().
895
896    restart interacts with initialized as follows (per Olivier Galibert):
897
898      It's perverted.
899
900      initialized==0 => temacs
901      initialized!=0 && restart!=0 => run-temacs
902      initialized!=0 && restart==0 => sxemacs/post pdump_load()
903 */
904 DECLARE_DOESNT_RETURN(main_1(int, char **, char **, int));
905 DOESNT_RETURN main_1(int argc, char **argv, char **envp, int restart)
906 {
907         char stack_bottom_variable;
908         int skip_args = 0;
909         Lisp_Object load_me;
910         int inhibit_window_system;
911 #ifdef NeXT
912         extern int malloc_cookie;
913 #endif
914
915 #if (!defined (SYSTEM_MALLOC) && !defined (HAVE_LIBMCHECK)      \
916      && !defined (DOUG_LEA_MALLOC))
917         /* Make sure that any libraries we link against haven't installed a
918            hook for a gmalloc of a potentially incompatible version. */
919         /* If we're using libmcheck, the hooks have already been initialized, */
920         /* don't touch them. -slb */
921         __malloc_hook = NULL;
922         __realloc_hook = NULL;
923         __free_hook = NULL;
924 #endif  /* not SYSTEM_MALLOC or HAVE_LIBMCHECK or DOUG_LEA_MALLOC */
925
926         noninteractive = 0;
927         inhibit_non_essential_printing_operations = 1;
928
929 #ifdef NeXT
930         /* 19-Jun-1995 -baw
931          * NeXT secret magic, ripped from Emacs-for-NS by Carl Edman
932          * <cedman@princeton.edu>.  Note that even Carl doesn't know what this
933          * does; it was provided by NeXT, and it presumable makes NS's mallocator
934          * work with dumping.  But malloc_jumpstart() and malloc_freezedry() in
935          * unexnext.c are both completely undocumented, even in NS header files!
936          * But hey, it solves all NS related memory problems, so who's
937          * complaining? */
938         if (initialized && malloc_jumpstart(malloc_cookie) != 0)
939                 stderr_out("malloc jumpstart failed!\n");
940 #endif                          /* NeXT */
941
942         /*
943            #if defined (GNU_MALLOC) && \
944            defined (ERROR_CHECK_MALLOC) && \
945            !defined (HAVE_LIBMCHECK)
946          */
947 #if defined(LOSING_GCC_DESTRUCTOR_FREE_BUG)
948         /* Prior to SXEmacs 21, this was `#if 0'ed out.  */
949         /* I'm enabling this because it is the only reliable way I've found to */
950         /* prevent a very annoying problem where GCC will attempt to free(3) */
951         /* memory at exit() and cause a coredump. */
952 #if 0
953         init_free_hook();
954 #endif
955 #endif
956
957         sort_args(argc, argv);
958
959 #if defined(_SCO_DS)
960         environ = envp;
961 #endif
962
963         /* Record (approximately) where the stack begins.  */
964         stack_bottom = &stack_bottom_variable;
965         /* and determine the system's stack limit */
966         sys_stk_sz = __sys_stk_sz();
967
968 #ifdef USG_SHARED_LIBRARIES
969         if (bss_end)
970                 brk((void *)bss_end);
971 #endif
972
973         clearerr(stdin);
974
975 #if defined (HAVE_MMAP) && defined (REL_ALLOC)
976         /* ralloc can only be used if using the GNU memory allocator. */
977         init_ralloc();
978 #elif defined (REL_ALLOC) && !defined(DOUG_LEA_MALLOC)
979         if (initialized)
980                 init_ralloc();
981 #endif
982
983 #ifdef HAVE_SOCKS
984         if (initialized)
985                 SOCKSinit(argv[0]);
986 #endif                          /* HAVE_SOCKS */
987
988 #if !defined SYSTEM_MALLOC && !(defined HAVE_BDWGC && defined EF_USE_BDWGC)
989         if (!initialized)
990                 /* Arrange to get warning messages as memory fills up.  */
991                 memory_warnings(0, malloc_warning);
992 #endif                          /* not SYSTEM_MALLOC */
993
994 #ifdef SET_EMACS_PRIORITY
995         if (emacs_priority != 0)
996                 nice(-emacs_priority);
997         setuid(getuid());
998 #endif                          /* SET_EMACS_PRIORITY */
999
1000 #ifdef EXTRA_INITIALIZE
1001         EXTRA_INITIALIZE;
1002 #endif
1003
1004 #ifdef HAVE_WINDOW_SYSTEM
1005         inhibit_window_system = 0;
1006 #else
1007         inhibit_window_system = 1;
1008 #endif
1009
1010         /* Handle the --make-docfile argument */
1011         if (argmatch(argv, argc,
1012                      "--make-docfile", 0, 9, NULL, &skip_args)) {
1013
1014                 /* we need load the dump file as the exec-directory is in
1015                    there */
1016                 if (UNLIKELY(!pdump_load(argv[0]))) {
1017                         exit(1);
1018                 }
1019
1020                 exit(make_docfile(argc, argv));
1021         }
1022
1023         /* Handle the -sd/--show-dump-id switch, which means show the hex
1024            dump_id and quit */
1025         if (argmatch(argv, argc,
1026                      "-sd", "--show-dump-id",
1027                      9, NULL, &skip_args)) {
1028 #ifdef PDUMP
1029                 printf("%08x\n", dump_id);
1030 #else
1031                 printf
1032                     ("Portable dumper not configured; -sd just forces exit.\n");
1033 #endif
1034                 exit(0);
1035         }
1036
1037         /* Handle the -t switch, which specifies filename to use as terminal */
1038         {
1039                 char *term;
1040                 if (argmatch
1041                     (argv, argc, "-t", "--terminal", 4, &term, &skip_args)) {
1042                         int tdesc = -1;
1043                         close(0);
1044                         close(1);
1045                         tdesc = open(term, O_RDWR | OPEN_BINARY, 2);
1046                         if (tdesc < 0)
1047                                 fatal("%s: %s", term, strerror(errno));
1048                         assert(tdesc==0);
1049                         tdesc = dup(0);
1050                         if ( tdesc < 0) {
1051                                 fatal("dup failed %s: %s", term, strerror(errno));
1052                         }
1053                         if (!isatty(0)) {
1054                                 fatal("%s: not a tty", term);
1055                         }
1056 #if 0
1057                         stderr_out("Using %s", ttyname(0));
1058 #endif
1059                         stderr_out("Using %s", term);
1060                         inhibit_window_system = 1;      /* -t => -nw */
1061                 }
1062         }
1063
1064         /* Handle the --no-dump-file/-nd switch, which means don't
1065          * load the dump file (ignored when not using pdump) */
1066         if (argmatch(argv, argc, "-nd", "--no-dump-file", 7,
1067                      NULL, &skip_args)) {
1068                 nodumpfile = 1;
1069         }
1070
1071         if (argmatch(argv, argc, "-ct", "--color-terminal", 5,
1072                      NULL, &skip_args)) {
1073                 assume_colorterm = 1;
1074         }
1075
1076         /* Handle -nw switch */
1077         if (argmatch(argv, argc, "-nw", "--no-windows", 6, NULL, &skip_args))
1078                 inhibit_window_system = 1;
1079
1080         /* Handle the -batch switch, which means don't do interactive display */
1081         if (argmatch(argv, argc, "-batch", "--batch", 5, NULL, &skip_args)) {
1082 #if 0                           /* I don't think this is correct. */
1083                 inhibit_autoloads = 1;
1084 #endif
1085                 noninteractive = 1;
1086         }
1087
1088         if (argmatch(argv, argc, "-debug-paths", "--debug-paths",
1089                      11, NULL, &skip_args))
1090                 debug_paths = 1;
1091
1092         /* Partially handle -no-autoloads, -no-early-packages and -vanilla.
1093            Packages */
1094         /* are searched prior to the rest of the command line being parsed in */
1095         /* startup.el */
1096         if (argmatch(argv, argc, "-no-early-packages", "--no-early-packages",
1097                      6, NULL, &skip_args)) {
1098                 inhibit_early_packages = 1;
1099                 skip_args--;
1100         }
1101 #if defined WITH_EMODULES && defined HAVE_EMODULES
1102         if (argmatch(argv, argc, "-no-site-modules", "--no-site-modules",
1103                      9, NULL, &skip_args)) {
1104                 inhibit_site_modules = 1;
1105                 skip_args--;
1106         }
1107 #else
1108         inhibit_site_modules = 1;
1109 #endif
1110         if (argmatch(argv, argc, "-vanilla", "--vanilla", 7, NULL, &skip_args)) {
1111                 inhibit_early_packages = 1;
1112                 skip_args--;
1113         }
1114
1115         if (argmatch(argv, argc, "-no-autoloads", "--no-autoloads",
1116                      7, NULL, &skip_args)) {
1117                 /* Inhibit everything */
1118                 inhibit_autoloads = 1;
1119                 skip_args--;
1120         }
1121
1122         if (argmatch(argv, argc, "-debug-paths", "--debug-paths",
1123                      6, NULL, &skip_args)) {
1124                 debug_paths = 1;
1125                 skip_args--;
1126         }
1127
1128         /* Partially handle the -version and -help switches: they imply -batch,
1129            but are not removed from the list. */
1130         if (argmatch(argv, argc, "-help", "--help", 3, NULL, &skip_args))
1131                 noninteractive = 1, skip_args--;
1132
1133         if (argmatch(argv, argc, "-version", "--version", 3, NULL, &skip_args)
1134             || argmatch(argv, argc, "-V", 0, 2, NULL, &skip_args))
1135                 noninteractive = 1, skip_args--;
1136
1137         /* Now, figure out which type of console is our first console. */
1138
1139         display_arg = 0;
1140
1141         if (noninteractive)
1142                 display_use = "stream";
1143         else
1144                 display_use = "tty";
1145
1146 #ifndef HAVE_TTY
1147         if (inhibit_window_system)
1148                 fatal("Sorry, this SXEmacs was not compiled with TTY support");
1149 #endif
1150
1151 #ifdef HAVE_WINDOW_SYSTEM
1152         /* Stupid kludge to catch command-line display spec.  We can't
1153            handle this argument entirely in window-system-dependent code
1154            because we don't even know which window-system-dependent code
1155            to run until we've recognized this argument.  */
1156         if (!inhibit_window_system && !noninteractive) {
1157 #ifdef HAVE_X_WINDOWS
1158                 char *dpy = 0;
1159                 int count_before = skip_args;
1160
1161                 if (argmatch(argv, argc, "-d", "--display", 3, &dpy, &skip_args)
1162                     || argmatch(argv, argc, "-display", 0, 3, &dpy,
1163                                 &skip_args)) {
1164                         display_arg = 1;
1165                         display_use = "x";
1166                 }
1167                 /* If we have the form --display=NAME,
1168                    convert it into  -d name.
1169                    This requires inserting a new element into argv.  */
1170                 if (dpy != 0 && skip_args - count_before == 1) {
1171                         char **new =
1172                             (char **)xmalloc(sizeof(char *) * (argc + 2));
1173                         int j;
1174
1175                         for (j = 0; j < count_before + 1; j++)
1176                                 new[j] = argv[j];
1177                         new[count_before + 1] = "-d";
1178                         new[count_before + 2] = dpy;
1179                         for (j = count_before + 2; j < argc; j++)
1180                                 new[j + 1] = argv[j];
1181                         argv = new;
1182                         argc++;
1183                 }
1184                 /* Change --display to -d, when its arg is separate.  */
1185                 else if (dpy != 0 && skip_args > count_before
1186                          && argv[count_before + 1][1] == '-')
1187                         argv[count_before + 1] = "-d";
1188
1189                 /* Don't actually discard this arg.  */
1190                 skip_args = count_before;
1191
1192                 /* If there is a non-empty environment var DISPLAY, set
1193                    `display_use', but not `display_arg', which is only to be set
1194                    if the display was specified on the command line. */
1195                 if ((dpy = getenv("DISPLAY")) && dpy[0])
1196                         display_use = "x";
1197
1198 #endif                          /* HAVE_X_WINDOWS */
1199         }
1200 #endif                          /* HAVE_WINDOW_SYSTEM */
1201
1202         noninteractive1 = noninteractive;
1203
1204         /****** Now initialize everything *******/
1205
1206         /* First, do really basic environment initialization -- catching signals
1207            and the like.  These functions have no dependence on any part of
1208            the Lisp engine and need to be done both at dump time and at run time. */
1209
1210         init_signals_very_early();
1211         init_data_very_early(); /* Catch math errors. */
1212 #ifdef HAVE_FPFLOAT
1213         init_floatfns_very_early();     /* Catch floating-point math errors. */
1214 #endif
1215         init_process_times_very_early();        /* Initialize our process timers.
1216                                                    As early as possible, of course,
1217                                                    so we can be fairly accurate. */
1218         init_intl_very_early(); /* set up the locale and domain for gettext and
1219                                    such. */
1220
1221         /* Now initialize the Lisp engine and the like.  Done only during
1222            dumping.  No dependence on anything that may be in the user's
1223            environment when the dumped SXEmacs is run.
1224
1225            We try to do things in an order that minimizes the non-obvious
1226            dependencies between functions. */
1227
1228         /* purify_flag 1 is correct even if CANNOT_DUMP.
1229          * loadup.el will set to nil at end. */
1230
1231         purify_flag = 0;
1232 #ifdef PDUMP
1233         if (restart) {
1234                 initialized = 1;
1235         } else if (nodumpfile) {
1236                 initialized = 0;
1237                 purify_flag = 1;
1238         } else {
1239
1240                 /* Keep command options from getting stomped.
1241
1242                    Some LISP-visible options are changed by SXEmacs _after_ the data is
1243                    dumped in building a --pdump SXEmacs, but _before_ it is restored in
1244                    normal operation.  Thus the restored values overwrite the values
1245                    SXEmacs is getting at run-time.  Such variables must be saved here,
1246                    and restored after loading the dumped data.
1247
1248                    Boy, this is ugly, but how else to do it?
1249                  */
1250
1251                 /* noninteractive1 is saved in noninteractive, which isn't
1252                    LISP-visible */
1253                 int inhibit_early_packages_save = inhibit_early_packages;
1254                 int inhibit_autoloads_save = inhibit_autoloads;
1255                 int debug_paths_save = debug_paths;
1256                 int inhibit_site_modules_save = inhibit_site_modules;
1257
1258                 initialized = pdump_load(argv[0]);
1259
1260                 /* Now unstomp everything */
1261                 noninteractive1 = noninteractive;
1262                 inhibit_early_packages = inhibit_early_packages_save;
1263                 inhibit_autoloads = inhibit_autoloads_save;
1264                 debug_paths = debug_paths_save;
1265                 inhibit_site_modules = inhibit_site_modules_save;
1266
1267                 if (initialized)
1268                         run_temacs_argc = -1;
1269                 else
1270                         purify_flag = 1;
1271         }
1272 #else
1273         if (!initialized)
1274                 purify_flag = 1;
1275 #endif
1276
1277         if (!initialized) {
1278                 /* Initialize things so that new Lisp objects
1279                    can be created and objects can be staticpro'd.
1280                    Must be basically the very first thing done
1281                    because pretty much all of the initialization
1282                    routines below create new objects. */
1283                 init_alloc_once_early();
1284
1285                 /* Initialize Qnil, Qt, Qunbound, and the
1286                    obarray.  After this, symbols can be
1287                    interned.  This depends on init_alloc_once_early(). */
1288                 init_symbols_once_early();
1289
1290                 /* Declare the basic symbols pertaining to errors,
1291                    So that DEFERROR*() can be called. */
1292                 init_errors_once_early();
1293
1294                 /* Make sure that opaque pointers can be created. */
1295                 init_opaque_once_early();
1296
1297                 /* Now declare all the symbols and define all the Lisp primitives.
1298
1299                    The *only* thing that the syms_of_*() functions are allowed to do
1300                    is call one of the following:
1301
1302                    INIT_LRECORD_IMPLEMENTATION()
1303                    defsymbol(), DEFSYMBOL(), or DEFSYMBOL_MULTIWORD_PREDICATE()
1304                    defsubr() (i.e. DEFSUBR)
1305                    deferror(), DEFERROR(), or DEFERROR_STANDARD()
1306                    defkeyword() or DEFKEYWORD()
1307
1308                    Order does not matter in these functions.
1309                  */
1310
1311                 syms_of_abbrev();
1312                 syms_of_alloc();
1313                 syms_of_buffer();
1314                 syms_of_bytecode();
1315                 syms_of_callint();
1316                 syms_of_callproc();
1317                 syms_of_casefiddle();
1318                 syms_of_casetab();
1319                 syms_of_chartab();
1320                 syms_of_cmdloop();
1321                 syms_of_cmds();
1322                 syms_of_console();
1323                 syms_of_data();
1324 #ifdef DEBUG_SXEMACS
1325                 syms_of_debug();
1326                 syms_of_tests();
1327 #endif                          /* DEBUG_SXEMACS */
1328                 syms_of_device();
1329 #ifdef HAVE_DIALOGS
1330                 syms_of_dialog();
1331 #endif
1332                 syms_of_dired();
1333                 syms_of_doc();
1334                 syms_of_editfns();
1335                 syms_of_elhash();
1336                 syms_of_emacs();
1337                 syms_of_eval();
1338 #ifdef HAVE_X_WINDOWS
1339                 syms_of_event_Xt();
1340 #endif
1341 #ifdef HAVE_DRAGNDROP
1342                 syms_of_dragdrop();
1343 #endif
1344 #ifdef EF_USE_ASYNEQ
1345                 syms_of_event_queue();
1346                 syms_of_workers();
1347                 syms_of_worker_asyneq();
1348 #endif
1349                 syms_of_event_stream();
1350                 syms_of_events();
1351                 syms_of_extents();
1352                 syms_of_faces();
1353                 syms_of_fileio();
1354 #ifdef CLASH_DETECTION
1355                 syms_of_filelock();
1356 #endif                          /* CLASH_DETECTION */
1357                 syms_of_floatfns();
1358                 syms_of_fns();
1359                 syms_of_font_lock();
1360                 syms_of_frame();
1361                 syms_of_general();
1362                 syms_of_glyphs();
1363                 syms_of_glyphs_eimage();
1364                 syms_of_glyphs_widget();
1365                 syms_of_gui();
1366                 syms_of_gutter();
1367                 syms_of_indent();
1368                 syms_of_intl();
1369                 syms_of_keymap();
1370                 syms_of_lread();
1371                 syms_of_macros();
1372                 syms_of_marker();
1373                 syms_of_md5();
1374 #ifdef HAVE_DATABASE
1375                 syms_of_database();
1376 #endif
1377 #ifdef HAVE_MENUBARS
1378                 syms_of_menubar();
1379 #endif
1380                 syms_of_media();
1381                 syms_of_minibuf();
1382                 syms_of_dynacat();
1383 #if defined WITH_EMODULES && defined HAVE_EMODULES && 0
1384                 syms_of_module();
1385 #elif defined WITH_EMODULES && defined HAVE_EMODULES
1386                 syms_of_emodng();
1387 #endif
1388                 syms_of_objects();
1389                 syms_of_print();
1390 #if !defined (NO_SUBPROCESSES)
1391                 syms_of_process();
1392 #endif
1393                 syms_of_profile();
1394 #if defined (HAVE_MMAP) && defined (REL_ALLOC) && !defined(DOUG_LEA_MALLOC)
1395                 syms_of_ralloc();
1396 #endif                          /* HAVE_MMAP && REL_ALLOC */
1397                 syms_of_rangetab();
1398                 syms_of_redisplay();
1399                 syms_of_search();
1400                 syms_of_select();
1401                 syms_of_signal();
1402                 syms_of_sound();
1403                 syms_of_specifier();
1404                 syms_of_symbols();
1405                 syms_of_syntax();
1406 #ifdef HAVE_SCROLLBARS
1407                 syms_of_scrollbar();
1408 #endif
1409 #ifdef HAVE_TOOLBARS
1410                 syms_of_toolbar();
1411 #endif
1412                 syms_of_undo();
1413                 syms_of_widget();
1414                 syms_of_window();
1415
1416 #ifdef HAVE_TTY
1417                 syms_of_console_tty();
1418                 syms_of_device_tty();
1419                 syms_of_objects_tty();
1420 #endif
1421
1422 #ifdef HAVE_X_WINDOWS
1423 #ifdef HAVE_BALLOON_HELP
1424                 syms_of_balloon_x();
1425 #endif
1426                 syms_of_device_x();
1427 #ifdef HAVE_DIALOGS
1428                 syms_of_dialog_x();
1429 #endif
1430                 syms_of_frame_x();
1431                 syms_of_glyphs_x();
1432                 syms_of_objects_x();
1433 #ifdef HAVE_MENUBARS
1434                 syms_of_menubar_x();
1435 #endif
1436                 syms_of_select_x();
1437 #if defined (HAVE_MENUBARS) || defined (HAVE_SCROLLBARS) || defined (HAVE_DIALOGS) || defined (HAVE_TOOLBARS)
1438                 syms_of_gui_x();
1439 #endif
1440 #ifdef HAVE_XIM
1441 #ifdef XIM_XLIB
1442                 syms_of_input_method_xlib();
1443 #endif
1444 #endif                          /* HAVE_XIM */
1445 #endif                          /* HAVE_X_WINDOWS */
1446
1447 #ifdef MULE
1448                 syms_of_mule();
1449                 syms_of_mule_ccl();
1450                 syms_of_mule_charset();
1451 #endif
1452 #ifdef FILE_CODING
1453                 syms_of_file_coding();
1454 #endif
1455 #ifdef MULE
1456 #ifdef HAVE_WNN
1457                 syms_of_mule_wnn();
1458 #endif
1459 #ifdef HAVE_CANNA
1460                 syms_of_mule_canna();
1461 #endif                          /* HAVE_CANNA */
1462 #endif                          /* MULE */
1463
1464 #ifdef SYMS_SYSTEM
1465                 SYMS_SYSTEM;
1466 #endif
1467
1468 #ifdef SYMS_MACHINE
1469                 SYMS_MACHINE;
1470 #endif
1471
1472                 /*
1473                    #if defined (GNU_MALLOC) && \
1474                    defined (ERROR_CHECK_MALLOC) && \
1475                    !defined (HAVE_LIBMCHECK)
1476                  */
1477                 /* Prior to SXEmacs 21, this was `#if 0'ed out. -slb */
1478 #if defined (LOSING_GCC_DESTRUCTOR_FREE_BUG)
1479                 syms_of_free_hook();
1480 #endif
1481
1482 #ifdef SUNPRO
1483                 syms_of_sunpro();
1484 #endif
1485
1486 #ifdef HAVE_LDAP
1487                 syms_of_eldap();
1488 #endif
1489
1490 #ifdef HAVE_GPM
1491                 syms_of_gpmevent();
1492 #endif
1493
1494 #ifdef HAVE_POSTGRESQL
1495                 syms_of_postgresql();
1496 #endif
1497
1498 #ifdef HAVE_OPENSSL
1499                 syms_of_openssl();
1500 #endif
1501
1502 #ifdef WITH_NUMBER_TYPES
1503                 syms_of_ent();
1504 #endif
1505
1506 #ifdef HAVE_LIBFFI
1507                 syms_of_ffi();
1508 #endif
1509
1510                 syms_of_dllist();
1511                 syms_of_skiplist();
1512                 syms_of_bloom();
1513
1514                 /* Now create the subtypes for the types that have them.
1515                    We do this before the vars_*() because more symbols
1516                    may get initialized here. */
1517
1518                 /* Now initialize the console types and associated symbols.
1519                    Other than the first function below, the functions may
1520                    make exactly the following function/macro calls:
1521
1522                    INITIALIZE_CONSOLE_TYPE()
1523                    CONSOLE_HAS_METHOD()
1524
1525                    For any given console type, the former macro must be called
1526                    before the any calls to the latter macro. */
1527
1528                 console_type_create();
1529
1530                 console_type_create_stream();
1531
1532 #ifdef HAVE_TTY
1533                 console_type_create_tty();
1534                 console_type_create_device_tty();
1535                 console_type_create_frame_tty();
1536                 console_type_create_objects_tty();
1537                 console_type_create_redisplay_tty();
1538 #endif
1539
1540 #ifdef HAVE_X_WINDOWS
1541                 console_type_create_x();
1542                 console_type_create_device_x();
1543                 console_type_create_frame_x();
1544                 console_type_create_glyphs_x();
1545                 console_type_create_select_x();
1546 #ifdef HAVE_MENUBARS
1547                 console_type_create_menubar_x();
1548 #endif
1549                 console_type_create_objects_x();
1550                 console_type_create_redisplay_x();
1551 #ifdef HAVE_SCROLLBARS
1552                 console_type_create_scrollbar_x();
1553 #endif
1554 #ifdef HAVE_TOOLBARS
1555                 console_type_create_toolbar_x();
1556 #endif
1557 #ifdef HAVE_DIALOGS
1558                 console_type_create_dialog_x();
1559 #endif
1560 #endif                          /* HAVE_X_WINDOWS */
1561
1562                 /* Now initialize the specifier types and associated symbols.
1563                    Other than the first function below, the functions may
1564                    make exactly the following function/macro calls:
1565
1566                    INITIALIZE_SPECIFIER_TYPE()
1567                    SPECIFIER_HAS_METHOD()
1568
1569                    For any given specifier type, the former macro must be called
1570                    before the any calls to the latter macro. */
1571
1572                 specifier_type_create();
1573
1574                 specifier_type_create_image();
1575                 specifier_type_create_gutter();
1576                 specifier_type_create_objects();
1577 #ifdef HAVE_TOOLBARS
1578                 specifier_type_create_toolbar();
1579 #endif
1580
1581                 /* Now initialize the structure types and associated symbols.
1582                    Other than the first function below, the functions may
1583                    make exactly the following function/macro calls:
1584
1585                    define_structure_type()
1586                    define_structure_type_keyword()
1587
1588                  */
1589
1590                 structure_type_create();
1591
1592                 structure_type_create_chartab();
1593                 structure_type_create_faces();
1594                 structure_type_create_rangetab();
1595                 structure_type_create_hash_table();
1596
1597                 /* Now initialize the image instantiator formats and associated symbols.
1598                    Other than the first function below, the functions may
1599                    make exactly the following function/macro calls:
1600
1601                    INITIALIZE_IMAGE_INSTANTIATOR_FORMAT()
1602                    IIFORMAT_HAS_METHOD()
1603                    IIFORMAT_VALID_KEYWORD()
1604
1605                    For any given image instantiator format, the first macro must be
1606                    called before the any calls to the other macros. */
1607
1608                 image_instantiator_format_create();
1609                 image_instantiator_format_create_glyphs_eimage();
1610                 image_instantiator_format_create_glyphs_widget();
1611 #ifdef HAVE_TTY
1612                 image_instantiator_format_create_glyphs_tty();
1613 #endif
1614 #ifdef HAVE_X_WINDOWS
1615                 image_instantiator_format_create_glyphs_x();
1616 #endif                          /* HAVE_X_WINDOWS */
1617
1618                 /* Now initialize the lstream types and associated symbols.
1619                    Other than the first function below, the functions may
1620                    make exactly the following function/macro calls:
1621
1622                    LSTREAM_HAS_METHOD()
1623
1624                  */
1625
1626                 lstream_type_create();
1627 #ifdef FILE_CODING
1628                 lstream_type_create_file_coding();
1629 #endif
1630
1631                 /* Initialize processes implementation.
1632                    The functions may make exactly the following function/macro calls:
1633
1634                    PROCESS_HAS_METHOD()
1635                  */
1636 #ifdef HAVE_UNIX_PROCESSES
1637                 process_type_create_unix();
1638 #endif
1639
1640                 /* Now initialize most variables.
1641
1642                    These functions may do exactly the following:
1643
1644                    DEFVAR_INT()
1645                    DEFVAR_LISP()
1646                    DEFVAR_BOOL()
1647                    DEFER_GETTEXT()
1648                    Dynarr_*()
1649                    Blocktype_*()
1650                    staticpro()
1651                    Fprovide(symbol)
1652                    intern()
1653                    Fput()
1654                    xmalloc()
1655                    defsymbol(), if it's absolutely necessary and you're sure that
1656                    the symbol isn't referenced anywhere else in the initialization
1657                    code
1658                    Fset() on a symbol that is unbound
1659                    assigning a symbol or constant value to a variable
1660                    using a global variable that has been initialized
1661                    earlier on in the same function
1662
1663                    Any of the object-creating functions in alloc.c: e.g.
1664
1665                    make_pure_*()
1666                    make_string()
1667                    build_string()
1668                    make_vector()
1669                    make_int()
1670                    make_extent()
1671                    alloc_lcrecord()
1672                    Fcons()
1673                    listN()
1674                    make_opaque_ptr()
1675
1676                    perhaps a few others.
1677
1678                    NB:  Initialization or assignment should not be done here to certain
1679                    variables settable from the command line.  See the comment above
1680                    the call to pdump_load() in main_1().  This caveat should only
1681                    apply to vars_of_emacs().
1682                  */
1683
1684                 /* Now allow Fprovide() statements to be made. */
1685                 init_provide_once();
1686
1687                 /* Do that before any specifier creation (esp. vars_of_glyphs()) */
1688                 vars_of_specifier();
1689
1690                 vars_of_abbrev();
1691                 vars_of_alloc();
1692                 vars_of_buffer();
1693                 vars_of_bytecode();
1694                 vars_of_callint();
1695                 vars_of_callproc();
1696                 vars_of_chartab();
1697                 vars_of_cmdloop();
1698                 vars_of_cmds();
1699                 vars_of_console();
1700                 vars_of_data();
1701 #ifdef DEBUG_SXEMACS
1702                 vars_of_debug();
1703                 vars_of_tests();
1704 #endif
1705                 vars_of_console_stream();
1706                 vars_of_device();
1707 #ifdef HAVE_DIALOGS
1708                 vars_of_dialog();
1709 #endif
1710                 vars_of_dired();
1711                 vars_of_doc();
1712 #ifdef HAVE_DRAGNDROP
1713                 vars_of_dragdrop();
1714 #endif
1715                 vars_of_editfns();
1716                 vars_of_elhash();
1717                 vars_of_emacs();
1718                 vars_of_eval();
1719
1720 #ifdef HAVE_X_WINDOWS
1721                 vars_of_event_Xt();
1722 #endif
1723 #if defined(HAVE_TTY) && (defined (DEBUG_TTY_EVENT_STREAM) || !defined (HAVE_X_WINDOWS))
1724                 vars_of_event_tty();
1725 #endif
1726                 vars_of_event_stream();
1727 #ifdef EF_USE_ASYNEQ
1728                 vars_of_workers();
1729                 vars_of_worker_asyneq();
1730 #endif
1731
1732                 vars_of_events();
1733                 vars_of_extents();
1734                 vars_of_faces();
1735                 vars_of_fileio();
1736 #ifdef CLASH_DETECTION
1737                 vars_of_filelock();
1738 #endif
1739                 vars_of_floatfns();
1740                 vars_of_font_lock();
1741                 vars_of_frame();
1742                 vars_of_glyphs();
1743                 vars_of_glyphs_eimage();
1744                 vars_of_glyphs_widget();
1745                 vars_of_gui();
1746                 vars_of_gutter();
1747                 vars_of_indent();
1748                 vars_of_insdel();
1749                 vars_of_intl();
1750 #ifdef HAVE_XIM
1751 #ifdef XIM_MOTIF
1752                 vars_of_input_method_motif();
1753 #else                           /* XIM_XLIB */
1754                 vars_of_input_method_xlib();
1755 #endif
1756 #endif                          /* HAVE_XIM */
1757                 vars_of_keymap();
1758                 vars_of_lread();
1759                 vars_of_lstream();
1760                 vars_of_macros();
1761                 vars_of_md5();
1762 #ifdef HAVE_DATABASE
1763                 vars_of_database();
1764 #endif
1765 #ifdef HAVE_MENUBARS
1766                 vars_of_menubar();
1767 #endif
1768                 vars_of_media();
1769                 vars_of_minibuf();
1770                 vars_of_dynacat();
1771 #if defined WITH_EMODULES && defined HAVE_EMODULES && 0
1772                 vars_of_module();
1773 #elif defined WITH_EMODULES && defined HAVE_EMODULES
1774                 vars_of_emodng();
1775 #endif
1776                 vars_of_objects();
1777                 vars_of_print();
1778
1779 #ifndef NO_SUBPROCESSES
1780                 vars_of_process();
1781 #ifdef HAVE_UNIX_PROCESSES
1782                 vars_of_process_unix();
1783 #endif
1784 #endif
1785
1786                 vars_of_profile();
1787 #if defined (HAVE_MMAP) && defined (REL_ALLOC) && !defined(DOUG_LEA_MALLOC)
1788                 vars_of_ralloc();
1789 #endif                          /* HAVE_MMAP && REL_ALLOC */
1790                 vars_of_redisplay();
1791 #ifdef HAVE_SCROLLBARS
1792                 vars_of_scrollbar();
1793 #endif
1794                 vars_of_search();
1795                 vars_of_select();
1796                 vars_of_sound();
1797                 vars_of_symbols();
1798                 vars_of_syntax();
1799 #ifdef HAVE_TOOLBARS
1800                 vars_of_toolbar();
1801 #endif
1802                 vars_of_undo();
1803                 vars_of_window();
1804
1805 #ifdef HAVE_TTY
1806                 vars_of_console_tty();
1807                 vars_of_frame_tty();
1808                 vars_of_objects_tty();
1809 #endif
1810
1811 #ifdef HAVE_X_WINDOWS
1812 #ifdef HAVE_BALLOON_HELP
1813                 vars_of_balloon_x();
1814 #endif
1815                 vars_of_device_x();
1816 #ifdef HAVE_DIALOGS
1817                 vars_of_dialog_x();
1818 #endif
1819                 vars_of_frame_x();
1820                 vars_of_glyphs_x();
1821 #ifdef HAVE_MENUBARS
1822                 vars_of_menubar_x();
1823 #endif
1824                 vars_of_objects_x();
1825                 vars_of_select_x();
1826 #ifdef HAVE_SCROLLBARS
1827                 vars_of_scrollbar_x();
1828 #endif
1829 #if defined (HAVE_MENUBARS) || defined (HAVE_SCROLLBARS) || defined (HAVE_DIALOGS) || defined (HAVE_TOOLBARS)
1830                 vars_of_gui_x();
1831 #endif
1832 #endif                          /* HAVE_X_WINDOWS */
1833
1834 #ifdef MULE
1835                 vars_of_mule();
1836                 vars_of_mule_ccl();
1837                 vars_of_mule_charset();
1838 #endif
1839 #ifdef FILE_CODING
1840                 vars_of_file_coding();
1841 #endif
1842 #ifdef MULE
1843 #ifdef HAVE_WNN
1844                 vars_of_mule_wnn();
1845 #endif
1846 #ifdef HAVE_CANNA
1847                 vars_of_mule_canna();
1848 #endif                          /* HAVE_CANNA */
1849 #endif                          /* MULE */
1850
1851 #ifdef SUNPRO
1852                 vars_of_sunpro();
1853 #endif
1854
1855 #ifdef HAVE_LDAP
1856                 vars_of_eldap();
1857 #endif
1858
1859 #ifdef HAVE_POSTGRESQL
1860                 vars_of_postgresql();
1861 #endif
1862
1863 #ifdef HAVE_OPENSSL
1864                 vars_of_openssl();
1865 #endif
1866
1867 #ifdef HAVE_GPM
1868                 vars_of_gpmevent();
1869 #endif
1870
1871 #ifdef WITH_NUMBER_TYPES
1872                 vars_of_ent();
1873 #endif
1874
1875 #ifdef HAVE_LIBFFI
1876                 vars_of_ffi();
1877 #endif
1878
1879                 vars_of_dllist();
1880                 vars_of_skiplist();
1881                 vars_of_bloom();
1882
1883                 /* Now initialize any specifier variables.  We do this later
1884                    because it has some dependence on the vars initialized
1885                    above.
1886
1887                    These functions should *only* initialize specifier variables,
1888                    and may make use of the following functions/macros in addition
1889                    to the ones listed above:
1890
1891                    DEFVAR_SPECIFIER()
1892                    Fmake_specifier()
1893                    set_specifier_fallback()
1894                    set_specifier_caching()
1895                  */
1896
1897                 specifier_vars_of_glyphs();
1898                 specifier_vars_of_glyphs_widget();
1899                 specifier_vars_of_gutter();
1900 #ifdef HAVE_MENUBARS
1901                 specifier_vars_of_menubar();
1902 #endif
1903                 specifier_vars_of_redisplay();
1904 #ifdef HAVE_SCROLLBARS
1905                 specifier_vars_of_scrollbar();
1906 #endif
1907 #ifdef HAVE_TOOLBARS
1908                 specifier_vars_of_toolbar();
1909 #endif
1910                 specifier_vars_of_window();
1911
1912                 /* Now comes all the rest of the variables that couldn't
1913                    be handled above.  There may be dependencies on variables
1914                    initialized above, and dependencies between one complex_vars_()
1915                    function and another. */
1916
1917                 /* Calls Fmake_range_table(). */
1918                 complex_vars_of_regex();
1919                 /* Calls Fmake_range_table(). */
1920                 complex_vars_of_search();
1921
1922                 /* Calls make_lisp_hash_table(). */
1923                 complex_vars_of_extents();
1924
1925                 /* Depends on hash tables and specifiers. */
1926                 complex_vars_of_faces();
1927
1928 #ifdef MULE
1929                 /* These two depend on hash tables and various variables declared
1930                    earlier.  The second may also depend on the first. */
1931                 complex_vars_of_mule_charset();
1932 #endif
1933 #ifdef FILE_CODING
1934                 complex_vars_of_file_coding();
1935 #endif
1936
1937                 /* This calls allocate_glyph(), which creates specifiers
1938                    and also relies on a variable (Vthe_nothing_vector) initialized
1939                    above.  It also calls make_ext_string(), which under Mule
1940                    could require that the charsets be initialized. */
1941                 complex_vars_of_glyphs();
1942
1943                 /* These rely on the glyphs just created in the previous function,
1944                    and call Fadd_spec_to_specifier(), which relies on various
1945                    variables initialized above. */
1946 #ifdef HAVE_X_WINDOWS
1947                 complex_vars_of_glyphs_x();
1948 #endif
1949
1950                 /* This calls Fmake_glyph_internal(). */
1951                 complex_vars_of_alloc();
1952
1953                 /* This calls Fmake_glyph_internal(). */
1954 #ifdef HAVE_MENUBARS
1955                 complex_vars_of_menubar();
1956 #endif
1957
1958                 /* This calls Fmake_glyph_internal(). */
1959 #ifdef HAVE_SCROLLBARS
1960                 complex_vars_of_scrollbar();
1961 #endif
1962
1963                 /* This calls allocate_glyph(). */
1964                 complex_vars_of_frame();
1965
1966                 /* This calls Fcopy_category_table() under Mule, which calls who
1967                    knows what. */
1968                 complex_vars_of_chartab();
1969
1970                 /* This calls set_string_char(), which (under Mule) depends on the
1971                    charsets being initialized. */
1972                 complex_vars_of_casetab();
1973
1974                 /* This calls Fcopy_syntax_table(), which relies on char tables. */
1975                 complex_vars_of_syntax();
1976
1977                 /* This initializes buffer-local variables, sets things up so
1978                    that buffers can be created, and creates a couple of basic
1979                    buffers.  This depends on Vstandard_syntax_table and
1980                    Vstandard_category_table (initialized in the previous
1981                    functions), as well as a whole horde of variables that may
1982                    have been initialized above. */
1983                 complex_vars_of_buffer();
1984
1985                 /* This initializes console-local variables. */
1986                 complex_vars_of_console();
1987
1988                 /* This creates a couple more buffers, and depends on the
1989                    previous function. */
1990                 complex_vars_of_minibuf();
1991
1992                 /* These two might call Ffile_name_as_directory(), which
1993                    might depend on all sorts of things; I'm not sure. */
1994                 complex_vars_of_emacs();
1995
1996                 /* This creates a couple of basic keymaps and depends on Lisp
1997                    hash tables and Ffset() (both of which depend on some variables
1998                    initialized in the vars_of_*() section) and possibly other
1999                    stuff. */
2000                 complex_vars_of_keymap();
2001
2002                 /* Calls make_lisp_hash_table() and creates a keymap */
2003                 complex_vars_of_event_stream();
2004
2005 #ifdef ERROR_CHECK_GC
2006                 {
2007                         extern int always_gc;
2008                         if (always_gc)  /* purification debugging hack */
2009                                 garbage_collect_1();
2010                 }
2011 #endif
2012 #ifdef PDUMP
2013         } else if (!restart) {  /* after successful pdump_load() */
2014                 reinit_alloc_once_early();
2015                 reinit_symbols_once_early();
2016                 reinit_opaque_once_early();
2017
2018                 reinit_console_type_create_stream();
2019 #ifdef HAVE_TTY
2020                 reinit_console_type_create_tty();
2021 #endif
2022 #ifdef HAVE_X_WINDOWS
2023                 reinit_console_type_create_x();
2024                 reinit_console_type_create_device_x();
2025 #endif
2026
2027                 reinit_specifier_type_create();
2028                 reinit_specifier_type_create_image();
2029                 reinit_specifier_type_create_gutter();
2030                 reinit_specifier_type_create_objects();
2031 #ifdef HAVE_TOOLBARS
2032                 reinit_specifier_type_create_toolbar();
2033 #endif
2034
2035                 structure_type_create();
2036
2037                 structure_type_create_chartab();
2038                 structure_type_create_faces();
2039                 structure_type_create_rangetab();
2040                 structure_type_create_hash_table();
2041
2042                 lstream_type_create();
2043 #ifdef FILE_CODING
2044                 lstream_type_create_file_coding();
2045 #endif
2046 #ifdef HAVE_UNIX_PROCESSES
2047                 process_type_create_unix();
2048 #endif
2049
2050                 reinit_vars_of_buffer();
2051                 reinit_vars_of_console();
2052 #ifdef DEBUG_SXEMACS
2053                 reinit_vars_of_debug();
2054 #endif
2055                 reinit_vars_of_device();
2056                 reinit_vars_of_eval();
2057 #ifdef HAVE_X_WINDOWS
2058                 reinit_vars_of_event_Xt();
2059 #endif
2060 #if defined(HAVE_TTY) && (defined (DEBUG_TTY_EVENT_STREAM) || !defined (HAVE_X_WINDOWS))
2061                 reinit_vars_of_event_tty();
2062 #endif
2063                 reinit_vars_of_event_stream();
2064 #ifdef EF_USE_ASYNEQ
2065                 reinit_vars_of_worker_asyneq();
2066 #endif
2067                 reinit_vars_of_events();
2068                 reinit_vars_of_extents();
2069                 reinit_vars_of_fileio();
2070                 reinit_vars_of_font_lock();
2071                 reinit_vars_of_glyphs();
2072                 reinit_vars_of_glyphs_widget();
2073                 reinit_vars_of_insdel();
2074                 reinit_vars_of_lread();
2075                 reinit_vars_of_lstream();
2076                 reinit_vars_of_minibuf();
2077                 reinit_vars_of_dynacat();
2078 #if defined WITH_EMODULES && defined HAVE_EMODULES && 0
2079                 reinit_vars_of_module();
2080 #elif defined WITH_EMODULES && defined HAVE_EMODULES
2081                 reinit_vars_of_emodng();
2082 #endif
2083                 reinit_vars_of_objects();
2084                 reinit_vars_of_print();
2085                 reinit_vars_of_search();
2086                 reinit_vars_of_undo();
2087                 reinit_vars_of_window();
2088
2089 #ifdef HAVE_X_WINDOWS
2090                 reinit_vars_of_device_x();
2091 #ifdef HAVE_SCROLLBARS
2092                 reinit_vars_of_scrollbar_x();
2093 #endif
2094 #ifdef HAVE_MENUBARS
2095                 reinit_vars_of_menubar_x();
2096 #endif
2097                 reinit_vars_of_select_x();
2098 #if defined (HAVE_MENUBARS) || defined (HAVE_SCROLLBARS) || defined (HAVE_DIALOGS) || defined (HAVE_TOOLBARS)
2099                 reinit_vars_of_gui_x();
2100 #endif
2101 #endif                          /* HAVE_X_WINDOWS */
2102
2103 #if defined(MULE) && defined(HAVE_WNN)
2104                 reinit_vars_of_mule_wnn();
2105 #endif
2106
2107                 reinit_complex_vars_of_buffer();
2108                 reinit_complex_vars_of_console();
2109                 reinit_complex_vars_of_minibuf();
2110
2111 #ifdef HAVE_LIBFFI
2112                 reinit_vars_of_ffi();
2113 #endif
2114
2115 #if defined USE_STATIC_ASE && USE_STATIC_ASE
2116                 reinit_vars_of_ase();
2117 #endif
2118
2119 #endif                          /* PDUMP */
2120         }
2121
2122         /* the category subsystem needs some inits */
2123         dllist_reinit();
2124         elhash_reinit();
2125         skiplist_reinit();
2126
2127         /* CONGRATULATIONS!!!  We have successfully initialized the Lisp
2128            engine. */
2129
2130         if (initialized) {
2131                 /* Stuff that should not be done at dump time, including stuff that
2132                    needs to be reset at run time.  Order below should not matter.
2133
2134                    Many initializations taken from the environment should go here. */
2135                 reinit_alloc();
2136                 reinit_eval();
2137 #ifdef MULE_REGEXP
2138                 reinit_mule_category();
2139 #endif
2140 #ifdef HAVE_POSTGRESQL
2141                 init_postgresql_from_environment();
2142 #endif
2143         }
2144
2145         /* Now do further initialization/setup of stuff that is not needed by the
2146            syms_of_() routines.  This involves stuff that only is enabled in
2147            an interactive run (redisplay, user input, etc.) and stuff that is
2148            not needed until we start loading Lisp code (the reader).  A lot
2149            of this stuff involves querying the current environment and needs
2150            to be done both at dump time and at run time. */
2151
2152         init_initial_directory();       /* get the directory to use for the
2153                                            "*scratch*" buffer, etc. */
2154
2155         init_callproc();        /* Set up the process environment (so that egetenv
2156                                    works), the basic directory variables
2157                                    (exec-directory and so on), and stuff
2158                                    related to subprocesses.  This should be
2159                                    first because many of the functions below
2160                                    call egetenv() to get environment variables. */
2161         init_lread();           /* Set up the Lisp reader. */
2162         init_cmdargs(argc, (Extbyte **) argv, skip_args);       /* Create list Vcommand_line_args */
2163         init_buffer();          /* Set default directory of *scratch* buffer */
2164
2165         init_redisplay();       /* Determine terminal type.
2166                                    init_sys_modes uses results */
2167         init_frame();
2168         init_event_stream();    /* Set up so we can get user input. */
2169         init_macros();          /* set up so we can run macros. */
2170         init_editfns();         /* Determine the name of the user we're running as */
2171         init_sxemacs_process(); /* set up for calling subprocesses */
2172
2173 #ifdef WITH_NUMBER_TYPES
2174         /* Set up bignums, ratios, bigfloats, complex numbers.
2175          * This must be done before the Lisp reader is set up.
2176          */
2177         init_ent ();
2178 #endif
2179
2180 #ifdef SUNPRO
2181         init_sunpro();          /* Set up Sunpro usage tracking */
2182 #endif
2183 #if defined (HAVE_NATIVE_SOUND) && defined (hp9000s800) && 0
2184         init_hpplay();
2185 #endif
2186 #ifdef HAVE_TTY
2187         init_device_tty();
2188 #endif
2189         init_console_stream(restart);   /* Create the first console */
2190
2191         /* try to get the actual pathname of the exec file we are running */
2192         if (!restart) {
2193                 Vinvocation_name = Fcar(Vcommand_line_args);
2194                 if (XSTRING_DATA(Vinvocation_name)[0] == '-') {
2195                         /* SXEmacs as a login shell, oh goody! */
2196                         Vinvocation_name = build_string(getenv("SHELL"));
2197                 }
2198                 Vinvocation_directory = Vinvocation_name;
2199
2200                 if (!NILP(Ffile_name_directory(Vinvocation_name))) {
2201                         /* invocation-name includes a directory component -- presumably it
2202                            is relative to cwd, not $PATH */
2203                         Vinvocation_directory =
2204                             Fexpand_file_name(Vinvocation_name, Qnil);
2205                         Vinvocation_path = Qnil;
2206                 } else {
2207                         Vinvocation_path = decode_env_path("PATH", NULL);
2208                         locate_file(Vinvocation_path, Vinvocation_name,
2209                                     Vlisp_EXEC_SUFFIXES,
2210                                     &Vinvocation_directory, X_OK);
2211                 }
2212
2213                 if (NILP(Vinvocation_directory))
2214                         Vinvocation_directory = Vinvocation_name;
2215
2216                 Vinvocation_name =
2217                     Ffile_name_nondirectory(Vinvocation_directory);
2218                 Vinvocation_directory =
2219                     Ffile_name_directory(Vinvocation_directory);
2220         }
2221
2222 #if defined (LOCALTIME_CACHE) && defined (HAVE_TZSET)
2223         /* sun's localtime() has a bug.  it caches the value of the time
2224            zone rather than looking it up every time.  Since localtime() is
2225            called to bolt the undumping time into the undumped emacs, this
2226            results in localtime() ignoring the TZ environment variable.
2227            This flushes the new TZ value into localtime(). */
2228         tzset();
2229 #endif                          /* LOCALTIME_CACHE and TZSET */
2230
2231         load_me = Qnil;
2232         if (!initialized) {
2233                 /* Handle -l loadup-and-dump, args passed by Makefile. */
2234                 if (argc > 2 + skip_args && !strcmp(argv[1 + skip_args], "-l"))
2235                         load_me = build_string(argv[2 + skip_args]);
2236 #if 0
2237                 /* CANNOT_DUMP - this can never be right in SXEmacs --andyp */
2238                 /* Unless next switch is -nl, load "loadup.el" first thing.  */
2239                 if (!
2240                     (argc > 1 + skip_args
2241                      && !strcmp(argv[1 + skip_args], "-nl")))
2242                         load_me = build_string("loadup.el");
2243 #endif                          /* CANNOT_DUMP */
2244         }
2245 #ifdef QUANTIFY
2246         if (initialized)
2247                 quantify_start_recording_data();
2248 #endif                          /* QUANTIFY */
2249
2250         initialized = 1;
2251         inhibit_non_essential_printing_operations = 0;
2252
2253         /* This never returns.  */
2254         initial_command_loop(load_me);
2255         /* NOTREACHED */
2256 }
2257 \f
2258 /* Sort the args so we can find the most important ones
2259    at the beginning of argv.  */
2260
2261 /* First, here's a table of all the standard options.  */
2262
2263 struct standard_args {
2264         const char *name;
2265         const char *longname;
2266         int priority;
2267         int nargs;
2268 };
2269
2270 static const struct standard_args standard_args[] = {
2271         /* Handled by main_1 above: */
2272         {"--make-docfile", 0, 105, 0},
2273         {"-sd", "--show-dump-id", 105, 0},
2274         {"-t", "--terminal", 100, 1},
2275         {"-nd", "--no-dump-file", 95, 0},
2276         {"-ct", "--color-terminal", 92, 0},
2277         {"-nw", "--no-windows", 90, 0},
2278         {"-batch", "--batch", 85, 0},
2279         {"-debug-paths", "--debug-paths", 82, 0},
2280         {"-help", "--help", 80, 0},
2281         {"-version", "--version", 75, 0},
2282         {"-V", 0, 75, 0},
2283         {"-d", "--display", 80, 1},
2284         {"-display", 0, 80, 1},
2285         {"-NXHost", 0, 79, 0},
2286         {"-MachLaunch", 0, 79, 0},
2287
2288         /* Handled by command-line-early in startup.el: */
2289         {"-q", "--no-init-file", 50, 0},
2290         {"-unmapped", 0, 50, 0},
2291         {"-no-init-file", 0, 50, 0},
2292         {"-vanilla", "--vanilla", 50, 0},
2293         {"-no-autoloads", "--no-autoloads", 50, 0},
2294         {"-no-site-file", "--no-site-file", 40, 0},
2295         {"-no-early-packages", "--no-early-packages", 35, 0},
2296         {"-u", "--user", 30, 1},
2297         {"-user", 0, 30, 1},
2298         {"-debug-init", "--debug-init", 20, 0},
2299         {"-debug-paths", "--debug-paths", 20, 0},
2300
2301         /* Xt options: */
2302         {"-i", "--icon-type", 15, 0},
2303         {"-itype", 0, 15, 0},
2304         {"-iconic", "--iconic", 15, 0},
2305         {"-bg", "--background-color", 10, 1},
2306         {"-background", 0, 10, 1},
2307         {"-fg", "--foreground-color", 10, 1},
2308         {"-foreground", 0, 10, 1},
2309         {"-bd", "--border-color", 10, 1},
2310         {"-bw", "--border-width", 10, 1},
2311         {"-ib", "--internal-border", 10, 1},
2312         {"-ms", "--mouse-color", 10, 1},
2313         {"-cr", "--cursor-color", 10, 1},
2314         {"-fn", "--font", 10, 1},
2315         {"-font", 0, 10, 1},
2316         {"-g", "--geometry", 10, 1},
2317         {"-geometry", 0, 10, 1},
2318         {"-T", "--title", 10, 1},
2319         {"-title", 0, 10, 1},
2320         {"-name", "--name", 10, 1},
2321         {"-xrm", "--xrm", 10, 1},
2322         {"-r", "--reverse-video", 5, 0},
2323         {"-rv", 0, 5, 0},
2324         {"-reverse", 0, 5, 0},
2325         {"-hb", "--horizontal-scroll-bars", 5, 0},
2326         {"-vb", "--vertical-scroll-bars", 5, 0},
2327
2328         /* These have the same priority as ordinary file name args,
2329            so they are not reordered with respect to those.  */
2330         {"-L", "--directory", 0, 1},
2331         {"-directory", 0, 0, 1},
2332         {"-l", "--load", 0, 1},
2333         {"-load", 0, 0, 1},
2334         {"-f", "--funcall", 0, 1},
2335         {"-funcall", 0, 0, 1},
2336         {"-eval", "--eval", 0, 1},
2337         {"-insert", "--insert", 0, 1},
2338         /* This should be processed after ordinary file name args and the like.  */
2339         {"-kill", "--kill", -10, 0},
2340 };
2341
2342 /* Reorder the elements of ARGV (assumed to have ARGC elements)
2343    so that the highest priority ones come first.
2344    Do not change the order of elements of equal priority.
2345    If an option takes an argument, keep it and its argument together.  */
2346
2347 static void sort_args(int argc, char **argv)
2348 {
2349         char **new_argv = (char**)malloc(sizeof(char*) * argc);
2350         /* For each element of argv,
2351            the corresponding element of options is:
2352            0 for an option that takes no arguments,
2353            1 for an option that takes one argument, etc.
2354            -1 for an ordinary non-option argument.  */
2355         int *options = (int*)malloc(sizeof(int) * argc);
2356         int *priority = (int*)malloc(sizeof(int) * argc);
2357         int to = 1;
2358         int from;
2359         int i;
2360         int end_of_options_p = 0;
2361
2362         /* Categorize all the options,
2363            and figure out which argv elts are option arguments.  */
2364         for (from = 1; from < argc; from++) {
2365                 options[from] = -1;
2366                 priority[from] = 0;
2367                 /* Pseudo options "--" and "run-temacs" indicate end of
2368                    options */
2369                 if (!strcmp(argv[from], "--") ||
2370                     !strcmp(argv[from], "run-temacs"))
2371                         end_of_options_p = 1;
2372                 if (!end_of_options_p && argv[from][0] == '-') {
2373                         int match, thislen;
2374                         char *equals;
2375
2376                         /* Look for a match with a known old-fashioned
2377                            option.  */
2378                         for (i = 0; i < countof(standard_args); i++) {
2379                                 if (!strcmp(argv[from],
2380                                             standard_args[i].name)) {
2381                                         options[from] = standard_args[i].nargs;
2382                                         priority[from] =
2383                                             standard_args[i].priority;
2384                                         if (from + standard_args[i].nargs >=
2385                                             argc) {
2386                                                 fatal("Option `%s' requires "
2387                                                       "an argument\n",
2388                                                       argv[from]);
2389                                         }
2390                                         from += standard_args[i].nargs;
2391                                         goto done;
2392                                 }
2393                         }
2394
2395                         /* Look for a match with a known long option.  MATCH is
2396                            -1 if no match so far, -2 if two or more matches so
2397                            far,
2398                            >= 0 (the table index of the match) if just one match
2399                            >so far.  */
2400                         if (argv[from][1] == '-') {
2401                                 match = -1;
2402                                 thislen = strlen(argv[from]);
2403                                 equals = strchr(argv[from], '=');
2404                                 if (equals != 0)
2405                                         thislen = equals - argv[from];
2406
2407                                 for (i = 0; i < countof(standard_args); i++)
2408                                         if (standard_args[i].longname
2409                                             && !strncmp(argv[from],
2410                                                         standard_args[i].
2411                                                         longname, thislen)) {
2412                                                 if (match == -1)
2413                                                         match = i;
2414                                                 else
2415                                                         match = -2;
2416                                         }
2417
2418                                 /* If we found exactly one match, use that.  */
2419                                 if (match >= 0) {
2420                                         options[from] =
2421                                                 standard_args[match].nargs;
2422                                         priority[from] =
2423                                                 standard_args[match].priority;
2424                                         /* If --OPTION=VALUE syntax is used,
2425                                            this option uses just one argv
2426                                            element.  */
2427                                         if (equals != 0)
2428                                                 options[from] = 0;
2429                                         if (from + options[from] >= argc) {
2430                                                 fatal("Option `%s' requires "
2431                                                       "an argument\n",
2432                                                       argv[from]);
2433                                         }
2434                                         from += options[from];
2435                                 }
2436                         }
2437                 done:
2438                         ;
2439                 }
2440         }
2441
2442         /* Copy the arguments, in order of decreasing priority, to NEW_ARGV.  */
2443         new_argv[0] = argv[0];
2444         while (to < argc) {
2445                 int best = -1;
2446                 int best_priority = -9999;
2447
2448                 /* Find the highest priority remaining option.
2449                    If several have equal priority, take the first of them.  */
2450                 for (from = 1; from < argc; from++) {
2451                         if (argv[from] != 0 && priority[from] > best_priority) {
2452                                 best_priority = priority[from];
2453                                 best = from;
2454                         }
2455                         /* Skip option arguments--they are tied to the options.  */
2456                         if (options[from] > 0) {
2457                                 from += options[from];
2458                         }
2459                 }
2460
2461                 if (best < 0) {
2462                         abort();
2463                 }
2464
2465                 /* Copy the highest priority remaining option, with its args, to
2466                    NEW_ARGV.  */
2467                 new_argv[to++] = argv[best];
2468                 for (i = 0; i < options[best]; i++) {
2469                         new_argv[to++] = argv[best + i + 1];
2470                 }
2471                 /* Clear out this option in ARGV.  */
2472                 argv[best] = 0;
2473                 for (i = 0; i < options[best]; i++) {
2474                         argv[best + i + 1] = 0;
2475                 }
2476         }
2477
2478         memcpy(argv, new_argv, sizeof(char *) * argc);
2479         free(new_argv);
2480         free(options);
2481         free(priority);
2482         return;
2483 }
2484
2485 DEFUN("running-temacs-p", Frunning_temacs_p, 0, 0, 0, /*
2486 True if running temacs.  This means we are in the dumping stage.
2487 This is false during normal execution of the `sxemacs' program, and
2488 becomes false once `run-emacs-from-temacs' is run.
2489 */
2490       ())
2491 {
2492         return run_temacs_argc >= 0 ? Qt : Qnil;
2493 }
2494
2495 DEFUN("run-emacs-from-temacs", Frun_emacs_from_temacs, 0, MANY, 0, /*
2496 Do not call this.  It will reinitialize your SXEmacs.  You'll be sorry.
2497 */
2498 /* If this function is called from startup.el, it will be possible to run
2499    temacs as an editor using 'temacs -batch -l loadup.el run-temacs', instead
2500    of having to dump an emacs and then run that (when debugging emacs itself,
2501    this can be much faster)). [Actually, the speed difference isn't that
2502    much as long as your filesystem is local, and you don't end up with
2503    a dumped version in case you want to rerun it.  This function is most
2504    useful when used as part of the `make all-elc' command. --ben]
2505    This will "restart" emacs with the specified command-line arguments.
2506
2507    Martin thinks this function is most useful when using debugging
2508    tools like Purify or tcov that get confused by SXEmacs' dumping.  */
2509       (int nargs, Lisp_Object * args))
2510 {
2511         int ac;
2512         const Extbyte *wampum = NULL;
2513         int namesize;
2514         int total_len;
2515         Lisp_Object orig_invoc_name = Fcar(Vcommand_line_args);
2516         const Extbyte **wampum_all = alloca_array(const Extbyte *, nargs);
2517         int *wampum_all_len = alloca_array(int, nargs);
2518
2519         assert(!gc_in_progress);
2520
2521         if (run_temacs_argc < 0)
2522                 error("I've lost my temacs-hood.");
2523
2524         /* Need to convert the orig_invoc_name and all of the arguments
2525            to external format. */
2526
2527         TO_EXTERNAL_FORMAT(LISP_STRING, orig_invoc_name,
2528                            ALLOCA, (wampum, namesize), Qnative);
2529         if ( wampum == NULL )
2530                 error("Could not transcode invocation name");
2531
2532         namesize++;
2533
2534         for (ac = 0, total_len = namesize; ac < nargs; ac++) {
2535                 CHECK_STRING(args[ac]);
2536                 wampum_all[ac]=NULL;
2537                 TO_EXTERNAL_FORMAT(LISP_STRING, args[ac],
2538                                    ALLOCA, (wampum_all[ac], wampum_all_len[ac]),
2539                                    Qnative);
2540                 if(wampum_all[ac]==NULL) {
2541                         error("Could not transcode arguments");
2542                 }
2543                 wampum_all_len[ac]++;
2544                 total_len += wampum_all_len[ac];
2545         }
2546         DO_REALLOC(run_temacs_args, run_temacs_args_size, total_len, char);
2547         DO_REALLOC(run_temacs_argv, run_temacs_argv_size, nargs + 2, char *);
2548
2549         memcpy(run_temacs_args, wampum, namesize);
2550         run_temacs_argv[0] = run_temacs_args;
2551         for (ac = 0; ac < nargs; ac++) {
2552                 memcpy(run_temacs_args + namesize,
2553                        wampum_all[ac], wampum_all_len[ac]);
2554                 run_temacs_argv[ac + 1] = run_temacs_args + namesize;
2555                 namesize += wampum_all_len[ac];
2556         }
2557         run_temacs_argv[nargs + 1] = 0;
2558         catchlist = NULL;       /* Important!  Otherwise free_cons() calls in
2559                                    condition_case_unwind() may lead to GC death. */
2560         unbind_to(0, Qnil);     /* this closes loadup.el */
2561         purify_flag = 0;
2562         run_temacs_argc = nargs + 1;
2563 #if defined (HEAP_IN_DATA) && !defined(PDUMP)
2564         report_sheap_usage(0);
2565 #endif
2566         LONGJMP(run_temacs_catch, 1);
2567         return Qnil;            /* not reached; warning suppression */
2568 }
2569
2570 /* defined in alloc.c */
2571 extern void init_bdwgc(void);
2572
2573 /* ARGSUSED */
2574 int
2575 main(int argc, char **argv, char **envp)
2576 {
2577         int volatile vol_argc = argc;
2578         char **volatile vol_argv = argv;
2579         char **volatile vol_envp = envp;
2580         /* This is hairy.  We need to compute where the SXEmacs binary
2581            was invoked from because temacs initialization requires it
2582            to find the lisp directories.  The code that recomputes the
2583            path is guarded by the restarted flag.  There are three
2584            possible paths I've found so far through this:
2585
2586            temacs -- When running temacs for basic build stuff, the
2587            first main_1 will be the only one invoked.  It must compute
2588            the path else there will be a very ugly bomb in startup.el
2589            (can't find obvious location for doc-directory
2590            data-directory, etc.).
2591
2592            temacs w/ run-temacs on the command line -- This is run to
2593            bytecompile all the out of date dumped lisp.  It will
2594            execute both of the main_1 calls and the second one must
2595            not touch the first computation because argc/argv are hosed
2596            the second time through.
2597
2598            sxemacs -- Only the second main_1 is executed.  The
2599            invocation path must computed but this only matters when
2600            running in place or when running as a login shell.
2601
2602            As a bonus for straightening this out, SXEmacs can now be
2603            run in place as a login shell.  This never used to work.
2604
2605            As another bonus, we can now guarantee that (concat
2606            invocation-directory invocation-name) contains the filename
2607            of the SXEmacs binary we are running.  This can now be used
2608            in a definite test for out of date dumped files.  -slb 
2609         */
2610
2611         int restarted = 0;
2612
2613         int arg;
2614         assert(vol_argv[0] != NULL || vol_argv[0][0] != '\0');
2615         assert(argc >= 1);
2616         for( arg=1; arg < argc; arg++ ) {
2617                 assert(vol_argv[arg] != NULL);
2618         }
2619         assert(vol_argv[argc] == NULL);
2620
2621 #ifdef QUANTIFY
2622         quantify_stop_recording_data();
2623         quantify_clear_data();
2624 #endif /* QUANTIFY */
2625
2626         inhibit_non_essential_printing_operations = 1;
2627         suppress_early_error_handler_backtrace = 0;
2628         lim_data = 0;   /* force reinitialization of this variable */
2629
2630         /* Lisp_Object must fit in a word; check VALBITS and GCTYPEBITS */
2631         assert(sizeof(Lisp_Object) == sizeof(void *));
2632
2633 #ifdef LINUX_SBRK_BUG
2634         sbrk(1);
2635 #endif
2636
2637         /* defined in alloc.c */
2638         init_bdwgc();
2639
2640         if (!initialized) {
2641 #ifdef DOUG_LEA_MALLOC
2642                 if (mallopt(M_MMAP_MAX, 0) != 1)
2643                         abort();
2644 #endif
2645                 run_temacs_argc = 0;
2646                 if (!SETJMP(run_temacs_catch)) {
2647                         main_1(vol_argc, vol_argv, vol_envp, 0);
2648                 }
2649                 /* run-emacs-from-temacs called */
2650                 restarted = 1;
2651                 vol_argc = run_temacs_argc;
2652                 vol_argv = run_temacs_argv;
2653 #ifdef _SCO_DS
2654                 /* This makes absolutely no sense to anyone involved.  There are
2655                    several people using this stuff.  We've compared versions on
2656                    everything we can think of.  We can find no difference.
2657                    However, on both my systems environ is a plain old global
2658                    variable initialized to zero.  _environ is the one that
2659                    contains pointers to the actual environment.
2660
2661                    Since we can't figure out the difference (and we're hours
2662                    away from a release), this takes a very cowardly approach and
2663                    is bracketed with both a system specific preprocessor test
2664                    and a runtime "do you have this problem" test
2665
2666                    06/20/96 robertl@dgii.com */
2667                 {
2668                         extern char **_environ;
2669                         if ((unsigned)environ == 0)
2670                                 environ = _environ;
2671                 }
2672 #endif                          /* _SCO_DS */
2673                 vol_envp = environ;
2674         }
2675 #if defined (RUN_TIME_REMAP) && ! defined (PDUMP)
2676         else
2677                 /* obviously no-one uses this because where it was before initialized was
2678                  *always* true */
2679                 run_time_remap(argv[0]);
2680 #endif
2681
2682 #ifdef DOUG_LEA_MALLOC
2683         if (initialized && (malloc_state_ptr != NULL)) {
2684                 int rc = malloc_set_state(malloc_state_ptr);
2685                 if (rc != 0) {
2686                         stderr_out("malloc_set_state failed, rc = %d\n",
2687                                    rc);
2688                         abort();
2689                 }
2690 #if 0
2691                 free(malloc_state_ptr);
2692 #endif
2693                 /* mmap works in glibc-2.1, glibc-2.0 (Non-Mule only)
2694                  * and Linux libc5 */
2695 #if (defined(__GLIBC__) && __GLIBC_MINOR__ >= 1) ||                     \
2696         defined(_NO_MALLOC_WARNING_) ||                                 \
2697         (defined(__GLIBC__) && __GLIBC_MINOR__ < 1 && !defined(MULE)) || \
2698         defined(DEBUG_DOUG_LEA_MALLOC)
2699                 if (mallopt(M_MMAP_MAX, 0) != 1)
2700                         abort();
2701 #endif
2702 #ifdef REL_ALLOC
2703                 r_alloc_reinit();
2704 #endif
2705         }
2706  #endif                         /* DOUG_LEA_MALLOC */
2707
2708         run_temacs_argc = -1;
2709
2710         main_1(vol_argc, vol_argv, vol_envp, restarted);
2711
2712         return 0;               /* unreached */
2713 }
2714
2715 \f
2716 /* Dumping apparently isn't supported by versions of GCC >= 2.8. */
2717 /* The following needs conditionalization on whether either SXEmacs or */
2718 /* various system shared libraries have been built and linked with */
2719 /* GCC >= 2.8.  -slb */
2720 #if defined(GNU_MALLOC)
2721 static void voodoo_free_hook(void *mem)
2722 {
2723         /* Disable all calls to free() when SXEmacs is exiting and it doesn't */
2724         /* matter. */
2725         __free_hook =
2726 #if defined __GNUC__ || defined __INTEL_COMPILER
2727 /* prototype of __free_hook varies with glibc version */
2728             (__typeof__(__free_hook))
2729 #endif
2730             voodoo_free_hook;
2731 }
2732 #endif                          /* GNU_MALLOC */
2733
2734 DEFUN("kill-emacs", Fkill_emacs, 0, 1, "P", /*
2735 Exit the SXEmacs job and kill it.  Ask for confirmation, without argument.
2736 If ARG is an integer, return ARG as the exit program code.
2737 If ARG is a string, stuff it as keyboard input.
2738
2739 The value of `kill-emacs-hook', if not void,
2740 is a list of functions (of no args),
2741 all of which are called before SXEmacs is actually killed.
2742 */
2743       (arg))
2744 {
2745         /* This function can GC */
2746         struct gcpro gcpro1;
2747
2748         GCPRO1(arg);
2749
2750         if (feof(stdin))
2751                 arg = Qt;
2752
2753         if (!preparing_for_armageddon && !noninteractive)
2754                 run_hook(Qkill_emacs_hook);
2755
2756         ensure_no_quitting_from_now_on();
2757
2758         if (!preparing_for_armageddon) {
2759                 Lisp_Object concons, nextcons;
2760
2761                 /* Normally, go ahead and delete all the consoles now.
2762                    Some unmentionably lame window systems (MS Wwwww...... eek,
2763                    I can't even say it) don't properly clean up after themselves,
2764                    and even for those that do, it might be cleaner this way.
2765                    If we're going down, however, we don't do this (might
2766                    be too dangerous), and if we get a crash somewhere within
2767                    this loop, we'll still autosave and won't try this again. */
2768
2769                 LIST_LOOP_DELETING(concons, nextcons, Vconsole_list) {
2770                         /* There is very little point in deleting the stream console.
2771                            It uses stdio, which should flush any buffered output and
2772                            something can only go wrong. -slb */
2773                         /* I changed my mind.  There's a stupid hack in close to add
2774                            a trailing newline. */
2775                         /*if (!CONSOLE_STREAM_P (XCONSOLE (XCAR (concons)))) */
2776                         delete_console_internal(XCONSOLE(XCAR(concons)), 1, 1,
2777                                                 0);
2778                 }
2779         }
2780
2781         UNGCPRO;
2782
2783         shut_down_emacs(0, STRINGP(arg) ? arg : Qnil, 0);
2784
2785 #if defined(GNU_MALLOC)
2786         __free_hook =
2787 #if defined __GNUC__ || defined __INTEL_COMPILER
2788 /* prototype of __free_hook varies with glibc version */
2789             (__typeof__(__free_hook))
2790 #endif
2791             voodoo_free_hook;
2792 #endif
2793
2794         exit(INTP(arg) ? XINT(arg) : 0);
2795         /* NOTREACHED */
2796         return Qnil;            /* I'm sick of the compiler warning */
2797 }
2798
2799 /* Perform an orderly shutdown of SXEmacs.  Autosave any modified
2800    buffers, kill any child processes, clean up the terminal modes (if
2801    we're in the foreground), and other stuff like that.  Don't perform
2802    any redisplay; this may be called when SXEmacs is shutting down in
2803    the background, or after its X connection has died.
2804
2805    If SIG is a signal number, print a message for it.
2806
2807    This is called by fatal signal handlers and Fkill_emacs.  It used to
2808    be called by X protocol error handlers, but instead they now call
2809    Fkill_emacs. */
2810 static void shut_down_emacs(int sig, Lisp_Object stuff, int no_auto_save)
2811 {
2812         /* This function can GC */
2813         /* Prevent running of hooks and other non-essential stuff
2814            from now on.  */
2815         preparing_for_armageddon = 1;
2816
2817         ensure_no_quitting_from_now_on();
2818
2819 #ifdef QUANTIFY
2820         quantify_stop_recording_data();
2821 #endif                          /* QUANTIFY */
2822
2823         /* This is absolutely the most important thing to do, so make sure
2824            we do it now, before anything else.  We might have crashed and
2825            be in a weird inconsistent state, and potentially anything could
2826            set off another protection fault and cause us to bail out
2827            immediately. */
2828         /* Steve writes the following:
2829
2830            [[I'm not removing the code entirely, yet.  We have run up against
2831            a spate of problems in diagnosing crashes due to crashes within
2832            crashes.  It has very definitely been determined that code called
2833            during auto-saving cannot work if SXEmacs crashed inside of GC.
2834            We already auto-save on an itimer so there cannot be too much
2835            unsaved stuff around, and if we get better crash reports we might
2836            be able to get more problems fixed so I'm disabling this.  -slb]]
2837
2838            and DISABLES AUTO-SAVING ENTIRELY during crashes!  Way way bad idea.
2839
2840            Instead let's just be more intelligent about avoiding crashing
2841            when possible, esp. nested crashes.
2842          */
2843         if (!no_auto_save)
2844                 Fdo_auto_save(Qt, Qnil);        /* do this before anything hazardous */
2845
2846         fflush(stdout);
2847         reset_all_consoles();
2848         if (sig && sig != SIGTERM) {
2849                 if (sig == -1)
2850                         stderr_out("\nFatal error.\n\n");
2851                 else
2852                         stderr_out("\nFatal error (%d).\n\n", sig);
2853                 stderr_out
2854                     ("Your files have been auto-saved.\n"
2855                      "Use `M-x recover-session' to recover them.\n"
2856                      "\n"
2857                      "Your version of SXEmacs was distributed with a PROBLEMS file that  may describe\n"
2858                      "your crash, and with luck a workaround.  Please check it first, but do report\n"
2859                      "the crash anyway.  "
2860 #ifdef INFODOCK
2861                      "\n\nPlease report this bug by selecting `Report-Bug' in the InfoDock menu.\n"
2862                      "*BE SURE* to include the SXEmacs configuration from M-x describe-installation,\n"
2863                      "or the file Installation in the top directory of the build tree.\n"
2864 #else
2865                      "Please report this bug by invoking M-x report-sxemacs-bug,\n"
2866                      "or by selecting `Send Bug Report' from the Help menu.  If necessary, send\n"
2867                      "ordinary email to `sxemacs-devel@sxemacs.org'.  *MAKE SURE* to include the SXEmacs\n"
2868                      "configuration from M-x describe-installation, or equivalently the file\n"
2869                      "Installation in the top of the build tree.\n"
2870 #endif
2871 #ifndef _MSC_VER
2872                      "\n"
2873                      "*Please* try *hard* to obtain a C stack backtrace; without it, we are unlikely\n"
2874                      "to be able to analyze the problem.  Locate the core file produced as a result\n"
2875                      "of this crash (often called `core' or `core.<process-id>', and located in\n"
2876                      "the directory in which you started SXEmacs or your home directory), and type\n"
2877                      "\n" "  gdb "
2878 #endif
2879                     );
2880                 {
2881                         const char *name;
2882                         char *dir = 0;
2883
2884                         /* Now try to determine the actual path to the executable,
2885                            to try to make the backtrace-determination process as foolproof
2886                            as possible. */
2887                         if (STRINGP(Vinvocation_name))
2888                                 name = (char *)XSTRING_DATA(Vinvocation_name);
2889                         else
2890                                 name = "sxemacs";
2891                         if (STRINGP(Vinvocation_directory))
2892                                 dir =
2893                                     (char *)XSTRING_DATA(Vinvocation_directory);
2894                         if (!dir || dir[0] != '/')
2895                                 stderr_out("`which %s`", name);
2896                         else if (dir[strlen(dir) - 1] != '/')
2897                                 stderr_out("%s/%s", dir, name);
2898                         else
2899                                 stderr_out("%s%s", dir, name);
2900                 }
2901                 stderr_out
2902                     (" core\n"
2903                      "\n"
2904                      "then type `where' at the debugger prompt.  "
2905                      "No GDB on your system?  You may\n"
2906                      "have DBX, or XDB, or SDB.  (Ask your system "
2907                      "administrator if you need help.)\n"
2908                      "If no core file was produced, enable them "
2909                      "(often with `ulimit -c unlimited'\n"
2910                      "in case of future recurrance of the crash.\n");
2911         }
2912
2913         stuff_buffered_input(stuff);
2914
2915         kill_buffer_processes(Qnil);
2916
2917 #ifdef CLASH_DETECTION
2918         unlock_all_files();
2919 #endif
2920
2921 }
2922 \f
2923 #ifndef CANNOT_DUMP
2924
2925 #if !defined(PDUMP) || !defined(SYSTEM_MALLOC)
2926 extern char my_edata[];
2927 #endif
2928
2929 extern void disable_free_hook(void);
2930
2931 DEFUN("dump-emacs", Fdump_emacs, 2, 2, 0, /*
2932 Dump current state of SXEmacs into executable file FILENAME.
2933 Take symbols from SYMFILE (presumably the file you executed to run SXEmacs).
2934 This is used in the file `loadup.el' when building SXEmacs.
2935
2936 Remember to set `command-line-processed' to nil before dumping
2937 if you want the dumped SXEmacs to process its command line
2938 and announce itself normally when it is run.
2939 */
2940       (symfile, filename))
2941 {
2942         /* This function can GC */
2943         struct gcpro gcpro1, gcpro2;
2944         int opurify;
2945
2946         GCPRO2(filename, symfile);
2947
2948 #if 0
2949         /* kick them */
2950         Vinvocation_directory = Vinvocation_name = Qnil;
2951         Vcommand_line_args = Qnil;
2952 #endif
2953
2954 #ifdef FREE_CHECKING
2955         Freally_free(Qnil);
2956
2957         /* When we're dumping, we can't use the debugging free() */
2958         disable_free_hook();
2959 #endif
2960
2961         CHECK_STRING(filename);
2962         filename = Fexpand_file_name(filename, Qnil);
2963         if (!NILP(symfile)) {
2964                 CHECK_STRING(symfile);
2965                 if (XSTRING_LENGTH(symfile) > 0) {
2966                         symfile = Fexpand_file_name(symfile, Qnil);
2967                 } else {
2968                         symfile = Qnil;
2969                 }
2970         }
2971
2972         opurify = purify_flag;
2973         purify_flag = 0;
2974
2975 #if defined (HEAP_IN_DATA) && !defined(PDUMP)
2976         report_sheap_usage(1);
2977 #endif
2978
2979         clear_message();
2980
2981         fflush(stderr);
2982         fflush(stdout);
2983
2984         disksave_object_finalization();
2985         release_breathing_space();
2986
2987         /* Tell malloc where start of impure now is */
2988         /* Also arrange for warnings when nearly out of space.  */
2989 #ifndef SYSTEM_MALLOC
2990         memory_warnings(my_edata, malloc_warning);
2991 #endif
2992
2993         UNGCPRO;
2994
2995         {
2996                 char *filename_ext;
2997                 char *symfile_ext;
2998
2999                 LISP_STRING_TO_EXTERNAL(filename, filename_ext, Qfile_name);
3000
3001                 if (STRINGP(symfile)) {
3002                         LISP_STRING_TO_EXTERNAL(symfile, symfile_ext,
3003                                                 Qfile_name);
3004                 } else {
3005                         symfile_ext = 0;
3006                 }
3007
3008                 garbage_collect_1();
3009
3010 #ifdef PDUMP
3011                 pdump(filename_ext);
3012 #else
3013
3014 #ifdef DOUG_LEA_MALLOC
3015                 malloc_state_ptr = malloc_get_state();
3016 #endif
3017                 /* here we break our rule that the filename conversion should
3018                    be performed at the actual time that the system call is made.
3019                    It's a whole lot easier to do the conversion here than to
3020                    modify all the unexec routines to ensure that filename
3021                    conversion is applied everywhere.  Don't worry about memory
3022                    leakage because this call only happens once. */
3023                 unexec(filename_ext, symfile_ext, (uintptr_t) my_edata, 0, 0);
3024 #ifdef DOUG_LEA_MALLOC
3025                 free(malloc_state_ptr);
3026 #endif
3027 #endif                          /* not PDUMP */
3028         }
3029
3030         purify_flag = opurify;
3031
3032         return Qnil;
3033 }
3034
3035 #endif                          /* not CANNOT_DUMP */
3036 \f
3037 /* Split STRING into a list of substrings.  The substrings are the
3038    parts of original STRING separated by SEPCHAR.  */
3039 static Lisp_Object
3040 split_string_by_emchar_1(const Bufbyte * string, Bytecount size, Emchar sepchar)
3041 {
3042         Lisp_Object result = Qnil;
3043         const Bufbyte *end = string + size;
3044
3045         while (1) {
3046                 const Bufbyte *p = string;
3047                 while (p < end) {
3048                         if (charptr_emchar(p) == sepchar)
3049                                 break;
3050                         INC_CHARPTR(p);
3051                 }
3052                 result = Fcons(make_string(string, p - string), result);
3053                 if (p < end) {
3054                         string = p;
3055                         INC_CHARPTR(string);    /* skip sepchar */
3056                 } else
3057                         break;
3058         }
3059         return Fnreverse(result);
3060 }
3061
3062 /* The same as the above, except PATH is an external C string (it is
3063    converted using Qfile_name), and sepchar is hardcoded to SEPCHAR
3064    (':' or whatever).  */
3065 Lisp_Object decode_path(/*const*/ char *path)
3066 {
3067         Bytecount newlen = 0;
3068         Bufbyte *newpath = NULL;
3069         if (!path)
3070                 return Qnil;
3071
3072         TO_INTERNAL_FORMAT(C_STRING, path, ALLOCA, (newpath, newlen),
3073                            Qfile_name);
3074
3075         /* #### Does this make sense?  It certainly does for
3076            decode_env_path(), but it looks dubious here.  Does any code
3077            depend on decode_path("") returning nil instead of an empty
3078            string?  */
3079         if (!newlen || !newpath)
3080                 return Qnil;
3081
3082         return split_string_by_emchar_1(newpath, newlen, SEPCHAR);
3083 }
3084
3085 Lisp_Object decode_env_path(const char *evarname, /*const*/ char *default_)
3086 {
3087         /*const*/ char *path = 0;
3088         if (evarname)
3089                 path = egetenv(evarname);
3090         if (!path)
3091                 path = default_;
3092         return decode_path(path);
3093 }
3094
3095 /* Ben thinks this function should not exist or be exported to Lisp.
3096    We use it to define split-path-string in subr.el (not!).  */
3097
3098 DEFUN("split-string-by-char", Fsplit_string_by_char, 2, 2, 0, /*
3099 Split STRING into a list of substrings originally separated by SEPCHAR.
3100 */
3101       (string, sepchar))
3102 {
3103         CHECK_STRING(string);
3104         CHECK_CHAR(sepchar);
3105         return split_string_by_emchar_1(XSTRING_DATA(string),
3106                                         XSTRING_LENGTH(string), XCHAR(sepchar));
3107 }
3108
3109 /* #### This was supposed to be in subr.el, but is used VERY early in
3110    the bootstrap process, so it goes here.  Damn.  */
3111
3112 DEFUN("split-path", Fsplit_path, 1, 1, 0, /*
3113 Explode a search path into a list of strings.
3114 The path components are separated with the characters specified
3115 with `path-separator'.
3116 */
3117       (path))
3118 {
3119         CHECK_STRING(path);
3120
3121         while (!STRINGP(Vpath_separator)
3122                || (XSTRING_CHAR_LENGTH(Vpath_separator) != 1))
3123                 Vpath_separator = signal_simple_continuable_error
3124                     ("`path-separator' should be set to a single-character string",
3125                      Vpath_separator);
3126
3127         return (split_string_by_emchar_1
3128                 (XSTRING_DATA(path), XSTRING_LENGTH(path),
3129                  charptr_emchar(XSTRING_DATA(Vpath_separator))));
3130 }
3131 \f
3132 DEFUN("noninteractive", Fnoninteractive, 0, 0, 0, /*
3133 Non-nil return value means SXEmacs is running without interactive terminal.
3134 */
3135       ())
3136 {
3137         return noninteractive ? Qt : Qnil;
3138 }
3139
3140 #ifdef USE_ASSERTIONS
3141 static int in_assert_failed = 0;
3142 static const char *assert_failed_file = NULL;
3143 static int assert_failed_line = 0;
3144 static const char *assert_failed_expr = NULL;
3145 /* This flag is useful to define if you're under a debugger; this way, you
3146    can put a breakpoint of assert_failed() and debug multiple problems
3147    in one session without having to recompile. */
3148 static int assertions_dont_abort = 0;
3149
3150 #ifdef fprintf
3151 #undef fprintf
3152 #endif
3153
3154 #ifdef abort
3155 #undef abort                    /* avoid infinite #define loop... */
3156 #endif
3157
3158 #define enter_debugger()
3159
3160 void
3161 assert_failed(const char *file, int line, const char *expr)
3162 {
3163         /* If we're already crashing, let's not crash again.  This might be
3164            critical to getting auto-saving working properly. */
3165         if (fatal_error_in_progress)
3166                 return;
3167
3168         /* We are extremely paranoid so we sensibly deal with recursive
3169            assertion failures. */
3170         in_assert_failed++;
3171         inhibit_non_essential_printing_operations = 1;
3172
3173         if (in_assert_failed >= 4)
3174                 _exit(-1);
3175         else if (in_assert_failed == 3) {
3176                 enter_debugger();
3177                 abort();
3178         } else if (in_assert_failed == 2) {
3179                 /* Not stderr_out(), which does additional things and may trigger
3180                    a recursive assertion failure.  fprintf was undeffed above, in
3181                    case it was encapsulated. */
3182                 fprintf(stderr,
3183                         "\n\nFatal error: recursive assertion failure, "
3184                         "file %s, line %d, %s\n", file, line, expr);
3185                 fprintf(stderr,
3186                         "Original assertion failure: file %s, line %d, %s\n",
3187                         assert_failed_file, assert_failed_line,
3188                         assert_failed_expr);
3189                 fflush(stderr);
3190                 enter_debugger();
3191                 debug_short_backtrace(0x7FFF);
3192         } else {
3193                 assert_failed_file = file;
3194                 assert_failed_line = line;
3195                 assert_failed_expr = expr;
3196
3197                 if (!initialized)
3198                         fprintf(stderr,
3199                                 "\nFatal error: assertion failed, file %s, line %d, %s\n",
3200                                 file, line, expr);
3201                 else
3202                         stderr_out
3203                             ("\nFatal error: assertion failed, file %s, line %d, %s\n",
3204                              file, line, expr);
3205                 fflush(stderr);
3206                 enter_debugger();
3207                 debug_backtrace();
3208         }
3209         if (! assertions_dont_abort) {
3210                 abort();
3211         }
3212         inhibit_non_essential_printing_operations = 0;
3213         in_assert_failed = 0;
3214 }
3215 #endif                          /* USE_ASSERTIONS */
3216
3217 #ifdef QUANTIFY
3218 DEFUN("quantify-start-recording-data", Fquantify_start_recording_data, 0, 0, "", /*
3219 Start recording Quantify data.
3220 */
3221       ())
3222 {
3223         quantify_start_recording_data();
3224         return Qnil;
3225 }
3226
3227 DEFUN("quantify-stop-recording-data", Fquantify_stop_recording_data, 0, 0, "", /*
3228 Stop recording Quantify data.
3229 */
3230       ())
3231 {
3232         quantify_stop_recording_data();
3233         return Qnil;
3234 }
3235
3236 DEFUN("quantify-clear-data", Fquantify_clear_data, 0, 0, "", /*
3237 Clear all Quantify data.
3238 */
3239       ())
3240 {
3241         quantify_clear_data();
3242         return Qnil;
3243 }
3244 #endif                          /* QUANTIFY */
3245
3246 void syms_of_emacs(void)
3247 {
3248 #ifndef CANNOT_DUMP
3249         DEFSUBR(Fdump_emacs);
3250 #endif                          /* !CANNOT_DUMP */
3251
3252         DEFSUBR(Frun_emacs_from_temacs);
3253         DEFSUBR(Frunning_temacs_p);
3254         DEFSUBR(Finvocation_name);
3255         DEFSUBR(Finvocation_directory);
3256         DEFSUBR(Fkill_emacs);
3257         DEFSUBR(Fnoninteractive);
3258
3259 #ifdef DEBUG_SXEMACS
3260         DEFSUBR(Fforce_debugging_signal);
3261 #endif
3262
3263 #ifdef QUANTIFY
3264         DEFSUBR(Fquantify_start_recording_data);
3265         DEFSUBR(Fquantify_stop_recording_data);
3266         DEFSUBR(Fquantify_clear_data);
3267 #endif                          /* QUANTIFY */
3268
3269         DEFSUBR(Fsplit_string_by_char);
3270         DEFSUBR(Fsplit_path);   /* #### */
3271
3272         defsymbol(&Qkill_emacs_hook, "kill-emacs-hook");
3273         defsymbol(&Qsave_buffers_kill_emacs, "save-buffers-kill-emacs");
3274 }
3275
3276 void vars_of_emacs(void)
3277 {
3278         DEFVAR_BOOL("suppress-early-error-handler-backtrace", &suppress_early_error_handler_backtrace /*
3279 Non-nil means early error handler shouldn't print a backtrace.
3280                                                                                                       */ );
3281
3282         DEFVAR_LISP("command-line-args", &Vcommand_line_args /*
3283 Args passed by shell to SXEmacs, as a list of strings.
3284                                                              */ );
3285
3286         DEFVAR_LISP("invocation-name", &Vinvocation_name /*
3287 The program name that was used to run SXEmacs.
3288 Any directory names are omitted.
3289                                                          */ );
3290
3291         DEFVAR_LISP("invocation-directory", &Vinvocation_directory /*
3292 The directory in which the SXEmacs executable was found, to run it.
3293 The value is simply the program name if that directory's name is not known.
3294                                                                    */ );
3295
3296         DEFVAR_LISP("invocation-path", &Vinvocation_path /*
3297 The path in which the SXEmacs executable was found, to run it.
3298 The value is simply the value of environment variable PATH on startup
3299 if SXEmacs was found there.
3300                                                          */ );
3301
3302 #if 0                           /* FSFmacs */
3303         xxDEFVAR_LISP("installation-directory", &Vinstallation_directory,
3304                       "A directory within which to look for the `lib-src' and `etc' directories.\n"
3305                       "This is non-nil when we can't find those directories in their standard\n"
3306                       "installed locations, but we can find them\n"
3307                       "near where the SXEmacs executable was found.");
3308 #endif
3309
3310         DEFVAR_LISP("system-type", &Vsystem_type /*
3311 Symbol indicating type of operating system you are using.
3312                                                  */ );
3313         Vsystem_type = intern(SYSTEM_TYPE);
3314         Fprovide(intern(SYSTEM_TYPE));
3315
3316 #ifndef EMACS_CONFIGURATION
3317 # define EMACS_CONFIGURATION "UNKNOWN"
3318 #endif
3319         DEFVAR_LISP("system-configuration", &Vsystem_configuration /*
3320 String naming the configuration SXEmacs was built for.
3321                                                                    */ );
3322         Vsystem_configuration = build_string(EMACS_CONFIGURATION);
3323
3324 #ifndef EMACS_CONFIG_OPTIONS
3325 # define EMACS_CONFIG_OPTIONS "UNKNOWN"
3326 #endif
3327         DEFVAR_LISP("system-configuration-options", &Vsystem_configuration_options /*
3328 String containing the configuration options SXEmacs was built with.
3329                                                                                    */ );
3330         Vsystem_configuration_options = build_string(EMACS_CONFIG_OPTIONS);
3331
3332         DEFVAR_LISP("emacs-major-version", &Vemacs_major_version /*
3333 Major version number of this version of Emacs, as an integer.
3334 Warning: this variable did not exist in Emacs versions earlier than:
3335   FSF Emacs:   19.23
3336   XEmacs:      19.10
3337                                                                  */ );
3338         Vemacs_major_version = make_int(EMACS_MAJOR_VERSION);
3339
3340         DEFVAR_LISP("emacs-minor-version", &Vemacs_minor_version /*
3341 Minor version number of this version of Emacs, as an integer.
3342 Warning: this variable did not exist in Emacs versions earlier than:
3343   FSF Emacs:   19.23
3344   XEmacs:      19.10
3345                                                                  */ );
3346         Vemacs_minor_version = make_int(EMACS_MINOR_VERSION);
3347
3348         DEFVAR_LISP("emacs-patch-level", &Vemacs_patch_level /*
3349 The patch level of this version of Emacs, as an integer.
3350 The value is non-nil if this version of SXEmacs is part of a series of
3351 stable SXEmacsen, but has bug fixes applied.
3352 Warning: this variable does not exist in FSF Emacs or in XEmacs versions
3353 earlier than 21.1.1
3354                                                              */ );
3355 #ifdef EMACS_PATCH_LEVEL
3356         Vemacs_patch_level = make_int(EMACS_PATCH_LEVEL);
3357 #else
3358         Vemacs_patch_level = Qnil;
3359 #endif
3360
3361         DEFVAR_LISP("emacs-beta-version", &Vemacs_beta_version /*
3362 Beta number of this version of Emacs, as an integer.
3363 The value is nil if this is an officially released version of SXEmacs.
3364 Warning: this variable does not exist in FSF Emacs or in XEmacs versions
3365 earlier than 20.3.
3366                                                                */ );
3367 #ifdef EMACS_BETA_VERSION
3368         Vemacs_beta_version = make_int(EMACS_BETA_VERSION);
3369 #else
3370         Vemacs_beta_version = Qnil;
3371 #endif
3372
3373         DEFVAR_LISP("sxemacs-git-version", &Vsxemacs_git_version /*
3374 This revision name of this SXEmacs.
3375 Warning: this variable does not exist in FSF Emacs or XEmacs.
3376                                                                    */ );
3377
3378         Vsxemacs_git_version = build_string(SXEMACS_GIT_VERSION);
3379
3380 #ifdef INFODOCK
3381         DEFVAR_LISP("infodock-major-version", &Vinfodock_major_version /*
3382 Major version number of this InfoDock release.
3383                                                                        */ );
3384         Vinfodock_major_version = make_int(INFODOCK_MAJOR_VERSION);
3385
3386         DEFVAR_LISP("infodock-minor-version", &Vinfodock_minor_version /*
3387 Minor version number of this InfoDock release.
3388                                                                        */ );
3389         Vinfodock_minor_version = make_int(INFODOCK_MINOR_VERSION);
3390
3391         DEFVAR_LISP("infodock-build-version", &Vinfodock_build_version /*
3392 Build version of this InfoDock release.
3393                                                                        */ );
3394         Vinfodock_build_version = make_int(INFODOCK_BUILD_VERSION);
3395 #endif
3396
3397         DEFVAR_LISP("sxemacs-codename", &Vsxemacs_codename /*
3398 Codename of this version of SXEmacs (a string).
3399                                                            */ );
3400 #ifndef SXEMACS_CODENAME
3401 #define SXEMACS_CODENAME "Noname"
3402 #endif
3403         Vsxemacs_codename = build_string(SXEMACS_CODENAME);
3404
3405         /* Lisp variables which contain command line flags.
3406
3407            The portable dumper stomps on these; they must be saved and restored
3408            if they are processed before the call to pdump_load() in main_1().
3409          */
3410         DEFVAR_BOOL("noninteractive", &noninteractive1 /*
3411 Non-nil means SXEmacs is running without interactive terminal.
3412                                                        */ );
3413
3414         DEFVAR_BOOL("inhibit-early-packages", &inhibit_early_packages /*
3415 Set to non-nil when the early packages should not be respected at startup.
3416                                                                       */ );
3417         DEFVAR_BOOL("warn-early-package-shadows", &warn_early_package_shadows /*
3418 Set to non-nil when the early packages should not shadow late packages. Issues
3419 warning at startup when that happens.
3420                                                                               */ );
3421         warn_early_package_shadows = 0;
3422
3423         DEFVAR_BOOL("inhibit-autoloads", &inhibit_autoloads /*
3424  Set to non-nil when autoloads should not be loaded at startup.
3425                                                             */ );
3426
3427         DEFVAR_BOOL("debug-paths", &debug_paths /*
3428 Set to non-nil when debug information about paths should be printed.
3429                                                  */ );
3430
3431         DEFVAR_BOOL("inhibit-site-modules", &inhibit_site_modules /*
3432 Set to non-nil when site-modules should not be searched at startup.
3433                                                                   */ );
3434 #ifdef INHIBIT_SITE_MODULES
3435         inhibit_site_modules = 1;
3436 #endif
3437
3438         DEFVAR_INT("emacs-priority", &emacs_priority /*
3439 Priority for SXEmacs to run at.
3440 This value is effective only if set before SXEmacs is dumped,
3441 and only if the SXEmacs executable is installed with setuid to permit
3442 it to change priority.  (SXEmacs sets its uid back to the real uid.)
3443 Currently, you need to define SET_EMACS_PRIORITY in `config.h'
3444 before you compile SXEmacs, to enable the code for this feature.
3445                                                      */ );
3446         emacs_priority = 0;
3447
3448         DEFVAR_CONST_LISP("internal-error-checking", &Vinternal_error_checking /*
3449 Internal error checking built-in into this instance of SXEmacs.
3450 This is a list of symbols, initialized at build-time.  Legal symbols
3451 are:
3452    extents     - check extents prior to each extent change;
3453    typecheck   - check types strictly, aborting in case of error;
3454    malloc      - check operation of malloc;
3455    gc          - check garbage collection;
3456    bufpos      - check buffer positions.
3457    quick-build - user has requested the "quick-build" configure option.
3458                                                                                */ );
3459         Vinternal_error_checking = Qnil;
3460 #ifdef ERROR_CHECK_EXTENTS
3461         Vinternal_error_checking = Fcons(intern("extents"),
3462                                          Vinternal_error_checking);
3463 #endif
3464 #ifdef ERROR_CHECK_TYPECHECK
3465         Vinternal_error_checking = Fcons(intern("typecheck"),
3466                                          Vinternal_error_checking);
3467 #endif
3468 #ifdef ERROR_CHECK_MALLOC
3469         Vinternal_error_checking = Fcons(intern("malloc"),
3470                                          Vinternal_error_checking);
3471 #endif
3472 #ifdef ERROR_CHECK_GC
3473         Vinternal_error_checking = Fcons(intern("gc"),
3474                                          Vinternal_error_checking);
3475 #endif
3476 #ifdef ERROR_CHECK_BUFPOS
3477         Vinternal_error_checking = Fcons(intern("bufpos"),
3478                                          Vinternal_error_checking);
3479 #endif
3480 #ifdef QUICK_BUILD
3481         Vinternal_error_checking = Fcons(intern("quick-build"),
3482                                          Vinternal_error_checking);
3483 #endif
3484
3485         DEFVAR_CONST_LISP("mail-lock-methods", &Vmail_lock_methods /*
3486 Mail spool locking methods supported by this instance of SXEmacs.
3487 This is a list of symbols.  Each of the symbols is one of the
3488 following: dot, lockf, flock, locking, mmdf.
3489                                                                    */ );
3490         {
3491                 Vmail_lock_methods = Qnil;
3492                 Vmail_lock_methods = Fcons(intern("dot"), Vmail_lock_methods);
3493 #ifdef HAVE_LOCKF
3494                 Vmail_lock_methods = Fcons(intern("lockf"), Vmail_lock_methods);
3495 #endif
3496 #ifdef HAVE_FLOCK
3497                 Vmail_lock_methods = Fcons(intern("flock"), Vmail_lock_methods);
3498 #endif
3499 #ifdef HAVE_MMDF
3500                 Vmail_lock_methods = Fcons(intern("mmdf"), Vmail_lock_methods);
3501 #endif
3502 #ifdef HAVE_LOCKING
3503                 Vmail_lock_methods =
3504                     Fcons(intern("locking"), Vmail_lock_methods);
3505 #endif
3506         }
3507
3508         DEFVAR_CONST_LISP("configure-mail-lock-method", &Vconfigure_mail_lock_method /*
3509 Mail spool locking method suggested by configure.  This is one
3510 of the symbols in MAIL-LOCK-METHODS.
3511                                                                                      */ );
3512         {
3513 #if defined(MAIL_LOCK_FLOCK) && defined(HAVE_FLOCK)
3514                 Vconfigure_mail_lock_method = intern("flock");
3515 #elif defined(MAIL_LOCK_LOCKF) && defined(HAVE_LOCKF)
3516                 Vconfigure_mail_lock_method = intern("lockf");
3517 #elif defined(MAIL_LOCK_MMDF) && defined(HAVE_MMDF)
3518                 Vconfigure_mail_lock_method = intern("mmdf");
3519 #elif defined(MAIL_LOCK_LOCKING) && defined(HAVE_LOCKING)
3520                 Vconfigure_mail_lock_method = intern("locking");
3521 #else
3522                 Vconfigure_mail_lock_method = intern("dot");
3523 #endif
3524         }
3525
3526         DEFVAR_LISP("path-separator", &Vpath_separator /*
3527 The directory separator in search paths, as a string.
3528                                                        */ );
3529         {
3530                 char c = SEPCHAR;
3531                 Vpath_separator = make_string((Bufbyte *) & c, 1);
3532         }
3533 }
3534
3535 void complex_vars_of_emacs(void)
3536 {
3537         /* This is all related to path searching. */
3538
3539         DEFVAR_LISP("emacs-program-name", &Vemacs_program_name /*
3540 *Name of the Emacs variant.
3541 For example, this may be \"sxemacs\" or \"infodock\".
3542 This is mainly meant for use in path searching.
3543                                                                */ );
3544         Vemacs_program_name = build_string((char *)PATH_PROGNAME);
3545
3546         DEFVAR_LISP("emacs-program-version", &Vemacs_program_version /*
3547 *Version of the Emacs variant.
3548 This typically has the form NN.NN-bNN.
3549 This is mainly meant for use in path searching.
3550                                                                      */ );
3551         Vemacs_program_version = build_string((char *)PATH_VERSION);
3552
3553         DEFVAR_LISP("exec-path", &Vexec_path /*
3554 *List of directories to search programs to run in subprocesses.
3555 Each element is a string (directory name) or nil (try default directory).
3556                                              */ );
3557         Vexec_path = Qnil;
3558
3559         DEFVAR_LISP("exec-directory", &Vexec_directory /*
3560 *Directory of architecture-dependent files that come with SXEmacs,
3561 especially executable programs intended for SXEmacs to invoke.
3562                                                        */ );
3563         Vexec_directory = Qnil;
3564
3565         DEFVAR_LISP("configure-exec-directory", &Vconfigure_exec_directory /*
3566 For internal use by the build procedure only.
3567 configure's idea of what `exec-directory' will be.
3568                                                                            */ );
3569 #ifdef PATH_EXEC
3570         Vconfigure_exec_directory = Ffile_name_as_directory
3571             (build_string((char *)PATH_EXEC));
3572 #else
3573         Vconfigure_exec_directory = Qnil;
3574 #endif
3575
3576         DEFVAR_LISP("lisp-directory", &Vlisp_directory /*
3577 *Directory of core Lisp files that come with SXEmacs.
3578 */ );
3579         Vlisp_directory = Qnil;
3580
3581         DEFVAR_LISP("configure-lisp-directory", &Vconfigure_lisp_directory /*
3582 For internal use by the build procedure only.
3583 configure's idea of what `lisp-directory' will be.
3584                                                                            */ );
3585 #ifdef PATH_LOADSEARCH
3586         Vconfigure_lisp_directory = Ffile_name_as_directory
3587             (build_string((char *)PATH_LOADSEARCH));
3588 #else
3589         Vconfigure_lisp_directory = Qnil;
3590 #endif
3591
3592         DEFVAR_LISP("mule-lisp-directory", &Vmule_lisp_directory /*
3593 *Directory of Mule Lisp files that come with SXEmacs.
3594 */ );
3595         Vmule_lisp_directory = Qnil;
3596
3597         DEFVAR_LISP("configure-mule-lisp-directory", &Vconfigure_mule_lisp_directory /*
3598 For internal use by the build procedure only.
3599 configure's idea of what `mule-lisp-directory' will be.
3600                                                                                      */ );
3601 #ifdef PATH_MULELOADSEARCH
3602         Vconfigure_mule_lisp_directory = Ffile_name_as_directory
3603             (build_string((char *)PATH_MULELOADSEARCH));
3604 #else
3605         Vconfigure_mule_lisp_directory = Qnil;
3606 #endif
3607
3608         DEFVAR_LISP("module-directory", &Vmodule_directory /*
3609 *Directory of core dynamic modules that come with SXEmacs.
3610 */ );
3611         Vmodule_directory = Qnil;
3612
3613         DEFVAR_LISP("configure-module-directory", &Vconfigure_module_directory /*
3614 For internal use by the build procedure only.
3615 configure's idea of what `module-directory' will be.
3616                                                                                */ );
3617 #ifdef PATH_MODULESEARCH
3618         Vconfigure_module_directory = Ffile_name_as_directory
3619             (build_string((char *)PATH_MODULESEARCH));
3620 #else
3621         Vconfigure_module_directory = Qnil;
3622 #endif
3623
3624         DEFVAR_LISP("configure-package-path", &Vconfigure_package_path /*
3625 For internal use by the build procedure only.
3626 configure's idea of what the package path will be.
3627                                                                        */ );
3628 #ifdef PATH_PACKAGEPATH
3629         Vconfigure_package_path = decode_path(PATH_PACKAGEPATH);
3630 #else
3631         Vconfigure_package_path = Qnil;
3632 #endif
3633
3634         DEFVAR_LISP("data-directory", &Vdata_directory /*
3635 *Directory of architecture-independent files that come with SXEmacs,
3636 intended for SXEmacs to use.
3637 Use of this variable in new code is almost never correct.  See the
3638 functions `locate-data-file' and `locate-data-directory' and the variable
3639 `data-directory-list'.
3640                                                        */ );
3641         Vdata_directory = Qnil;
3642
3643         DEFVAR_LISP("configure-data-directory", &Vconfigure_data_directory /*
3644 For internal use by the build procedure only.
3645 configure's idea of what `data-directory' will be.
3646                                                                            */ );
3647 #ifdef PATH_DATA
3648         Vconfigure_data_directory = Ffile_name_as_directory
3649             (build_string((char *)PATH_DATA));
3650 #else
3651         Vconfigure_data_directory = Qnil;
3652 #endif
3653
3654         DEFVAR_LISP("data-directory-list", &Vdata_directory_list /*
3655 *List of directories of architecture-independent files that come with SXEmacs
3656 or were installed as packages, and are intended for SXEmacs to use.
3657                                                                  */ );
3658         Vdata_directory_list = Qnil;
3659
3660         DEFVAR_LISP("site-module-directory", &Vsite_module_directory /*
3661 *Directory of site-specific loadable modules that come with SXEmacs.
3662 */ );
3663         Vsite_module_directory = Qnil;
3664
3665         DEFVAR_LISP("configure-site-module-directory", &Vconfigure_site_module_directory /*
3666 For internal use by the build procedure only.
3667 configure's idea of what `site-directory' will be.
3668                                                                                          */ );
3669 #ifdef PATH_SITE_MODULES
3670         Vconfigure_site_module_directory = Ffile_name_as_directory
3671             (build_string((char *)PATH_SITE_MODULES));
3672 #else
3673         Vconfigure_site_module_directory = Qnil;
3674 #endif
3675
3676         DEFVAR_LISP("doc-directory", &Vdoc_directory /*
3677 *Directory containing the DOC file that comes with SXEmacs.
3678 This is usually the same as `exec-directory'.
3679                                                      */ );
3680         Vdoc_directory = Qnil;
3681
3682         DEFVAR_LISP("configure-doc-directory", &Vconfigure_doc_directory /*
3683 For internal use by the build procedure only.
3684 configure's idea of what `doc-directory' will be.
3685                                                                          */ );
3686 #ifdef PATH_DOC
3687         Vconfigure_doc_directory = Ffile_name_as_directory
3688             (build_string((char *)PATH_DOC));
3689 #else
3690         Vconfigure_doc_directory = Qnil;
3691 #endif
3692
3693         DEFVAR_LISP("configure-exec-prefix-directory", &Vconfigure_exec_prefix_directory /*
3694 For internal use by the build procedure only.
3695 configure's idea of what `exec-prefix-directory' will be.
3696                                                                                          */ );
3697 #ifdef PATH_EXEC_PREFIX
3698         Vconfigure_exec_prefix_directory = Ffile_name_as_directory
3699             (build_string((char *)PATH_EXEC_PREFIX));
3700 #else
3701         Vconfigure_exec_prefix_directory = Qnil;
3702 #endif
3703
3704         DEFVAR_LISP("configure-prefix-directory", &Vconfigure_prefix_directory /*
3705 For internal use by the build procedure only.
3706 configure's idea of what `prefix-directory' will be.
3707                                                                                */ );
3708 #ifdef PATH_PREFIX
3709         Vconfigure_prefix_directory = Ffile_name_as_directory
3710             (build_string((char *)PATH_PREFIX));
3711 #else
3712         Vconfigure_prefix_directory = Qnil;
3713 #endif
3714
3715         DEFVAR_LISP("configure-info-directory", &Vconfigure_info_directory /*
3716 For internal use by the build procedure only.
3717 This is the name of the directory in which the build procedure installed
3718 Emacs's info files; the default value for Info-default-directory-list
3719 includes this.
3720                                                                            */ );
3721 #ifdef PATH_INFO
3722         Vconfigure_info_directory =
3723             Ffile_name_as_directory(build_string(PATH_INFO));
3724 #else
3725         Vconfigure_info_directory = Qnil;
3726 #endif
3727
3728         DEFVAR_LISP("configure-info-path", &Vconfigure_info_path /*
3729 The configured initial path for info documentation.
3730                                                                  */ );
3731 #ifdef PATH_INFOPATH
3732         Vconfigure_info_path = decode_path(PATH_INFOPATH);
3733 #else
3734         Vconfigure_info_path = Qnil;
3735 #endif
3736 }
3737
3738 #if defined(__sgi) && !defined(PDUMP)
3739 /* This is so tremendously ugly I'd puke. But then, it works.
3740  * The target is to override the static constructor from the
3741  * libiflPNG.so library which is masquerading as libz, and
3742  * cores on us when re-started from the dumped executable.
3743  * This will have to go for 21.1  -- OG.
3744  */
3745 void __sti__iflPNGFile_c___(void);
3746 void __sti__iflPNGFile_c___(void)
3747 {
3748 }
3749
3750 #endif