Coverity: Uninit: CID 400
[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                         close(0);
1043                         close(1);
1044                         if (open(term, O_RDWR | OPEN_BINARY, 2) < 0)
1045                                 fatal("%s: %s", term, strerror(errno));
1046                         if( dup(0) < 0)
1047                                 fatal("dup failed %s: %s", term, strerror(errno));
1048                         if (!isatty(0))
1049                                 fatal("%s: not a tty", term);
1050
1051 #if 0
1052                         stderr_out("Using %s", ttyname(0));
1053 #endif
1054                         stderr_out("Using %s", term);
1055                         inhibit_window_system = 1;      /* -t => -nw */
1056                 }
1057         }
1058
1059         /* Handle the --no-dump-file/-nd switch, which means don't
1060          * load the dump file (ignored when not using pdump) */
1061         if (argmatch(argv, argc, "-nd", "--no-dump-file", 7,
1062                      NULL, &skip_args)) {
1063                 nodumpfile = 1;
1064         }
1065
1066         if (argmatch(argv, argc, "-ct", "--color-terminal", 5,
1067                      NULL, &skip_args)) {
1068                 assume_colorterm = 1;
1069         }
1070
1071         /* Handle -nw switch */
1072         if (argmatch(argv, argc, "-nw", "--no-windows", 6, NULL, &skip_args))
1073                 inhibit_window_system = 1;
1074
1075         /* Handle the -batch switch, which means don't do interactive display */
1076         if (argmatch(argv, argc, "-batch", "--batch", 5, NULL, &skip_args)) {
1077 #if 0                           /* I don't think this is correct. */
1078                 inhibit_autoloads = 1;
1079 #endif
1080                 noninteractive = 1;
1081         }
1082
1083         if (argmatch(argv, argc, "-debug-paths", "--debug-paths",
1084                      11, NULL, &skip_args))
1085                 debug_paths = 1;
1086
1087         /* Partially handle -no-autoloads, -no-early-packages and -vanilla.
1088            Packages */
1089         /* are searched prior to the rest of the command line being parsed in */
1090         /* startup.el */
1091         if (argmatch(argv, argc, "-no-early-packages", "--no-early-packages",
1092                      6, NULL, &skip_args)) {
1093                 inhibit_early_packages = 1;
1094                 skip_args--;
1095         }
1096 #if defined WITH_EMODULES && defined HAVE_EMODULES
1097         if (argmatch(argv, argc, "-no-site-modules", "--no-site-modules",
1098                      9, NULL, &skip_args)) {
1099                 inhibit_site_modules = 1;
1100                 skip_args--;
1101         }
1102 #else
1103         inhibit_site_modules = 1;
1104 #endif
1105         if (argmatch(argv, argc, "-vanilla", "--vanilla", 7, NULL, &skip_args)) {
1106                 inhibit_early_packages = 1;
1107                 skip_args--;
1108         }
1109
1110         if (argmatch(argv, argc, "-no-autoloads", "--no-autoloads",
1111                      7, NULL, &skip_args)) {
1112                 /* Inhibit everything */
1113                 inhibit_autoloads = 1;
1114                 skip_args--;
1115         }
1116
1117         if (argmatch(argv, argc, "-debug-paths", "--debug-paths",
1118                      6, NULL, &skip_args)) {
1119                 debug_paths = 1;
1120                 skip_args--;
1121         }
1122
1123         /* Partially handle the -version and -help switches: they imply -batch,
1124            but are not removed from the list. */
1125         if (argmatch(argv, argc, "-help", "--help", 3, NULL, &skip_args))
1126                 noninteractive = 1, skip_args--;
1127
1128         if (argmatch(argv, argc, "-version", "--version", 3, NULL, &skip_args)
1129             || argmatch(argv, argc, "-V", 0, 2, NULL, &skip_args))
1130                 noninteractive = 1, skip_args--;
1131
1132         /* Now, figure out which type of console is our first console. */
1133
1134         display_arg = 0;
1135
1136         if (noninteractive)
1137                 display_use = "stream";
1138         else
1139                 display_use = "tty";
1140
1141 #ifndef HAVE_TTY
1142         if (inhibit_window_system)
1143                 fatal("Sorry, this SXEmacs was not compiled with TTY support");
1144 #endif
1145
1146 #ifdef HAVE_WINDOW_SYSTEM
1147         /* Stupid kludge to catch command-line display spec.  We can't
1148            handle this argument entirely in window-system-dependent code
1149            because we don't even know which window-system-dependent code
1150            to run until we've recognized this argument.  */
1151         if (!inhibit_window_system && !noninteractive) {
1152 #ifdef HAVE_X_WINDOWS
1153                 char *dpy = 0;
1154                 int count_before = skip_args;
1155
1156                 if (argmatch(argv, argc, "-d", "--display", 3, &dpy, &skip_args)
1157                     || argmatch(argv, argc, "-display", 0, 3, &dpy,
1158                                 &skip_args)) {
1159                         display_arg = 1;
1160                         display_use = "x";
1161                 }
1162                 /* If we have the form --display=NAME,
1163                    convert it into  -d name.
1164                    This requires inserting a new element into argv.  */
1165                 if (dpy != 0 && skip_args - count_before == 1) {
1166                         char **new =
1167                             (char **)xmalloc(sizeof(char *) * (argc + 2));
1168                         int j;
1169
1170                         for (j = 0; j < count_before + 1; j++)
1171                                 new[j] = argv[j];
1172                         new[count_before + 1] = "-d";
1173                         new[count_before + 2] = dpy;
1174                         for (j = count_before + 2; j < argc; j++)
1175                                 new[j + 1] = argv[j];
1176                         argv = new;
1177                         argc++;
1178                 }
1179                 /* Change --display to -d, when its arg is separate.  */
1180                 else if (dpy != 0 && skip_args > count_before
1181                          && argv[count_before + 1][1] == '-')
1182                         argv[count_before + 1] = "-d";
1183
1184                 /* Don't actually discard this arg.  */
1185                 skip_args = count_before;
1186
1187                 /* If there is a non-empty environment var DISPLAY, set
1188                    `display_use', but not `display_arg', which is only to be set
1189                    if the display was specified on the command line. */
1190                 if ((dpy = getenv("DISPLAY")) && dpy[0])
1191                         display_use = "x";
1192
1193 #endif                          /* HAVE_X_WINDOWS */
1194         }
1195 #endif                          /* HAVE_WINDOW_SYSTEM */
1196
1197         noninteractive1 = noninteractive;
1198
1199         /****** Now initialize everything *******/
1200
1201         /* First, do really basic environment initialization -- catching signals
1202            and the like.  These functions have no dependence on any part of
1203            the Lisp engine and need to be done both at dump time and at run time. */
1204
1205         init_signals_very_early();
1206         init_data_very_early(); /* Catch math errors. */
1207 #ifdef HAVE_FPFLOAT
1208         init_floatfns_very_early();     /* Catch floating-point math errors. */
1209 #endif
1210         init_process_times_very_early();        /* Initialize our process timers.
1211                                                    As early as possible, of course,
1212                                                    so we can be fairly accurate. */
1213         init_intl_very_early(); /* set up the locale and domain for gettext and
1214                                    such. */
1215
1216         /* Now initialize the Lisp engine and the like.  Done only during
1217            dumping.  No dependence on anything that may be in the user's
1218            environment when the dumped SXEmacs is run.
1219
1220            We try to do things in an order that minimizes the non-obvious
1221            dependencies between functions. */
1222
1223         /* purify_flag 1 is correct even if CANNOT_DUMP.
1224          * loadup.el will set to nil at end. */
1225
1226         purify_flag = 0;
1227 #ifdef PDUMP
1228         if (restart) {
1229                 initialized = 1;
1230         } else if (nodumpfile) {
1231                 initialized = 0;
1232                 purify_flag = 1;
1233         } else {
1234
1235                 /* Keep command options from getting stomped.
1236
1237                    Some LISP-visible options are changed by SXEmacs _after_ the data is
1238                    dumped in building a --pdump SXEmacs, but _before_ it is restored in
1239                    normal operation.  Thus the restored values overwrite the values
1240                    SXEmacs is getting at run-time.  Such variables must be saved here,
1241                    and restored after loading the dumped data.
1242
1243                    Boy, this is ugly, but how else to do it?
1244                  */
1245
1246                 /* noninteractive1 is saved in noninteractive, which isn't
1247                    LISP-visible */
1248                 int inhibit_early_packages_save = inhibit_early_packages;
1249                 int inhibit_autoloads_save = inhibit_autoloads;
1250                 int debug_paths_save = debug_paths;
1251                 int inhibit_site_modules_save = inhibit_site_modules;
1252
1253                 initialized = pdump_load(argv[0]);
1254
1255                 /* Now unstomp everything */
1256                 noninteractive1 = noninteractive;
1257                 inhibit_early_packages = inhibit_early_packages_save;
1258                 inhibit_autoloads = inhibit_autoloads_save;
1259                 debug_paths = debug_paths_save;
1260                 inhibit_site_modules = inhibit_site_modules_save;
1261
1262                 if (initialized)
1263                         run_temacs_argc = -1;
1264                 else
1265                         purify_flag = 1;
1266         }
1267 #else
1268         if (!initialized)
1269                 purify_flag = 1;
1270 #endif
1271
1272         if (!initialized) {
1273                 /* Initialize things so that new Lisp objects
1274                    can be created and objects can be staticpro'd.
1275                    Must be basically the very first thing done
1276                    because pretty much all of the initialization
1277                    routines below create new objects. */
1278                 init_alloc_once_early();
1279
1280                 /* Initialize Qnil, Qt, Qunbound, and the
1281                    obarray.  After this, symbols can be
1282                    interned.  This depends on init_alloc_once_early(). */
1283                 init_symbols_once_early();
1284
1285                 /* Declare the basic symbols pertaining to errors,
1286                    So that DEFERROR*() can be called. */
1287                 init_errors_once_early();
1288
1289                 /* Make sure that opaque pointers can be created. */
1290                 init_opaque_once_early();
1291
1292                 /* Now declare all the symbols and define all the Lisp primitives.
1293
1294                    The *only* thing that the syms_of_*() functions are allowed to do
1295                    is call one of the following:
1296
1297                    INIT_LRECORD_IMPLEMENTATION()
1298                    defsymbol(), DEFSYMBOL(), or DEFSYMBOL_MULTIWORD_PREDICATE()
1299                    defsubr() (i.e. DEFSUBR)
1300                    deferror(), DEFERROR(), or DEFERROR_STANDARD()
1301                    defkeyword() or DEFKEYWORD()
1302
1303                    Order does not matter in these functions.
1304                  */
1305
1306                 syms_of_abbrev();
1307                 syms_of_alloc();
1308                 syms_of_buffer();
1309                 syms_of_bytecode();
1310                 syms_of_callint();
1311                 syms_of_callproc();
1312                 syms_of_casefiddle();
1313                 syms_of_casetab();
1314                 syms_of_chartab();
1315                 syms_of_cmdloop();
1316                 syms_of_cmds();
1317                 syms_of_console();
1318                 syms_of_data();
1319 #ifdef DEBUG_SXEMACS
1320                 syms_of_debug();
1321                 syms_of_tests();
1322 #endif                          /* DEBUG_SXEMACS */
1323                 syms_of_device();
1324 #ifdef HAVE_DIALOGS
1325                 syms_of_dialog();
1326 #endif
1327                 syms_of_dired();
1328                 syms_of_doc();
1329                 syms_of_editfns();
1330                 syms_of_elhash();
1331                 syms_of_emacs();
1332                 syms_of_eval();
1333 #ifdef HAVE_X_WINDOWS
1334                 syms_of_event_Xt();
1335 #endif
1336 #ifdef HAVE_DRAGNDROP
1337                 syms_of_dragdrop();
1338 #endif
1339 #ifdef EF_USE_ASYNEQ
1340                 syms_of_event_queue();
1341                 syms_of_workers();
1342                 syms_of_worker_asyneq();
1343 #endif
1344                 syms_of_event_stream();
1345                 syms_of_events();
1346                 syms_of_extents();
1347                 syms_of_faces();
1348                 syms_of_fileio();
1349 #ifdef CLASH_DETECTION
1350                 syms_of_filelock();
1351 #endif                          /* CLASH_DETECTION */
1352                 syms_of_floatfns();
1353                 syms_of_fns();
1354                 syms_of_font_lock();
1355                 syms_of_frame();
1356                 syms_of_general();
1357                 syms_of_glyphs();
1358                 syms_of_glyphs_eimage();
1359                 syms_of_glyphs_widget();
1360                 syms_of_gui();
1361                 syms_of_gutter();
1362                 syms_of_indent();
1363                 syms_of_intl();
1364                 syms_of_keymap();
1365                 syms_of_lread();
1366                 syms_of_macros();
1367                 syms_of_marker();
1368                 syms_of_md5();
1369 #ifdef HAVE_DATABASE
1370                 syms_of_database();
1371 #endif
1372 #ifdef HAVE_MENUBARS
1373                 syms_of_menubar();
1374 #endif
1375                 syms_of_media();
1376                 syms_of_minibuf();
1377                 syms_of_dynacat();
1378 #if defined WITH_EMODULES && defined HAVE_EMODULES && 0
1379                 syms_of_module();
1380 #elif defined WITH_EMODULES && defined HAVE_EMODULES
1381                 syms_of_emodng();
1382 #endif
1383                 syms_of_objects();
1384                 syms_of_print();
1385 #if !defined (NO_SUBPROCESSES)
1386                 syms_of_process();
1387 #endif
1388                 syms_of_profile();
1389 #if defined (HAVE_MMAP) && defined (REL_ALLOC) && !defined(DOUG_LEA_MALLOC)
1390                 syms_of_ralloc();
1391 #endif                          /* HAVE_MMAP && REL_ALLOC */
1392                 syms_of_rangetab();
1393                 syms_of_redisplay();
1394                 syms_of_search();
1395                 syms_of_select();
1396                 syms_of_signal();
1397                 syms_of_sound();
1398                 syms_of_specifier();
1399                 syms_of_symbols();
1400                 syms_of_syntax();
1401 #ifdef HAVE_SCROLLBARS
1402                 syms_of_scrollbar();
1403 #endif
1404 #ifdef HAVE_TOOLBARS
1405                 syms_of_toolbar();
1406 #endif
1407                 syms_of_undo();
1408                 syms_of_widget();
1409                 syms_of_window();
1410
1411 #ifdef HAVE_TTY
1412                 syms_of_console_tty();
1413                 syms_of_device_tty();
1414                 syms_of_objects_tty();
1415 #endif
1416
1417 #ifdef HAVE_X_WINDOWS
1418 #ifdef HAVE_BALLOON_HELP
1419                 syms_of_balloon_x();
1420 #endif
1421                 syms_of_device_x();
1422 #ifdef HAVE_DIALOGS
1423                 syms_of_dialog_x();
1424 #endif
1425                 syms_of_frame_x();
1426                 syms_of_glyphs_x();
1427                 syms_of_objects_x();
1428 #ifdef HAVE_MENUBARS
1429                 syms_of_menubar_x();
1430 #endif
1431                 syms_of_select_x();
1432 #if defined (HAVE_MENUBARS) || defined (HAVE_SCROLLBARS) || defined (HAVE_DIALOGS) || defined (HAVE_TOOLBARS)
1433                 syms_of_gui_x();
1434 #endif
1435 #ifdef HAVE_XIM
1436 #ifdef XIM_XLIB
1437                 syms_of_input_method_xlib();
1438 #endif
1439 #endif                          /* HAVE_XIM */
1440 #endif                          /* HAVE_X_WINDOWS */
1441
1442 #ifdef MULE
1443                 syms_of_mule();
1444                 syms_of_mule_ccl();
1445                 syms_of_mule_charset();
1446 #endif
1447 #ifdef FILE_CODING
1448                 syms_of_file_coding();
1449 #endif
1450 #ifdef MULE
1451 #ifdef HAVE_WNN
1452                 syms_of_mule_wnn();
1453 #endif
1454 #ifdef HAVE_CANNA
1455                 syms_of_mule_canna();
1456 #endif                          /* HAVE_CANNA */
1457 #endif                          /* MULE */
1458
1459 #ifdef SYMS_SYSTEM
1460                 SYMS_SYSTEM;
1461 #endif
1462
1463 #ifdef SYMS_MACHINE
1464                 SYMS_MACHINE;
1465 #endif
1466
1467                 /*
1468                    #if defined (GNU_MALLOC) && \
1469                    defined (ERROR_CHECK_MALLOC) && \
1470                    !defined (HAVE_LIBMCHECK)
1471                  */
1472                 /* Prior to SXEmacs 21, this was `#if 0'ed out. -slb */
1473 #if defined (LOSING_GCC_DESTRUCTOR_FREE_BUG)
1474                 syms_of_free_hook();
1475 #endif
1476
1477 #ifdef SUNPRO
1478                 syms_of_sunpro();
1479 #endif
1480
1481 #ifdef HAVE_LDAP
1482                 syms_of_eldap();
1483 #endif
1484
1485 #ifdef HAVE_GPM
1486                 syms_of_gpmevent();
1487 #endif
1488
1489 #ifdef HAVE_POSTGRESQL
1490                 syms_of_postgresql();
1491 #endif
1492
1493 #ifdef HAVE_OPENSSL
1494                 syms_of_openssl();
1495 #endif
1496
1497 #ifdef WITH_NUMBER_TYPES
1498                 syms_of_ent();
1499 #endif
1500
1501 #ifdef HAVE_LIBFFI
1502                 syms_of_ffi();
1503 #endif
1504
1505                 syms_of_dllist();
1506                 syms_of_skiplist();
1507                 syms_of_bloom();
1508
1509                 /* Now create the subtypes for the types that have them.
1510                    We do this before the vars_*() because more symbols
1511                    may get initialized here. */
1512
1513                 /* Now initialize the console types and associated symbols.
1514                    Other than the first function below, the functions may
1515                    make exactly the following function/macro calls:
1516
1517                    INITIALIZE_CONSOLE_TYPE()
1518                    CONSOLE_HAS_METHOD()
1519
1520                    For any given console type, the former macro must be called
1521                    before the any calls to the latter macro. */
1522
1523                 console_type_create();
1524
1525                 console_type_create_stream();
1526
1527 #ifdef HAVE_TTY
1528                 console_type_create_tty();
1529                 console_type_create_device_tty();
1530                 console_type_create_frame_tty();
1531                 console_type_create_objects_tty();
1532                 console_type_create_redisplay_tty();
1533 #endif
1534
1535 #ifdef HAVE_X_WINDOWS
1536                 console_type_create_x();
1537                 console_type_create_device_x();
1538                 console_type_create_frame_x();
1539                 console_type_create_glyphs_x();
1540                 console_type_create_select_x();
1541 #ifdef HAVE_MENUBARS
1542                 console_type_create_menubar_x();
1543 #endif
1544                 console_type_create_objects_x();
1545                 console_type_create_redisplay_x();
1546 #ifdef HAVE_SCROLLBARS
1547                 console_type_create_scrollbar_x();
1548 #endif
1549 #ifdef HAVE_TOOLBARS
1550                 console_type_create_toolbar_x();
1551 #endif
1552 #ifdef HAVE_DIALOGS
1553                 console_type_create_dialog_x();
1554 #endif
1555 #endif                          /* HAVE_X_WINDOWS */
1556
1557                 /* Now initialize the specifier types and associated symbols.
1558                    Other than the first function below, the functions may
1559                    make exactly the following function/macro calls:
1560
1561                    INITIALIZE_SPECIFIER_TYPE()
1562                    SPECIFIER_HAS_METHOD()
1563
1564                    For any given specifier type, the former macro must be called
1565                    before the any calls to the latter macro. */
1566
1567                 specifier_type_create();
1568
1569                 specifier_type_create_image();
1570                 specifier_type_create_gutter();
1571                 specifier_type_create_objects();
1572 #ifdef HAVE_TOOLBARS
1573                 specifier_type_create_toolbar();
1574 #endif
1575
1576                 /* Now initialize the structure types and associated symbols.
1577                    Other than the first function below, the functions may
1578                    make exactly the following function/macro calls:
1579
1580                    define_structure_type()
1581                    define_structure_type_keyword()
1582
1583                  */
1584
1585                 structure_type_create();
1586
1587                 structure_type_create_chartab();
1588                 structure_type_create_faces();
1589                 structure_type_create_rangetab();
1590                 structure_type_create_hash_table();
1591
1592                 /* Now initialize the image instantiator formats and associated symbols.
1593                    Other than the first function below, the functions may
1594                    make exactly the following function/macro calls:
1595
1596                    INITIALIZE_IMAGE_INSTANTIATOR_FORMAT()
1597                    IIFORMAT_HAS_METHOD()
1598                    IIFORMAT_VALID_KEYWORD()
1599
1600                    For any given image instantiator format, the first macro must be
1601                    called before the any calls to the other macros. */
1602
1603                 image_instantiator_format_create();
1604                 image_instantiator_format_create_glyphs_eimage();
1605                 image_instantiator_format_create_glyphs_widget();
1606 #ifdef HAVE_TTY
1607                 image_instantiator_format_create_glyphs_tty();
1608 #endif
1609 #ifdef HAVE_X_WINDOWS
1610                 image_instantiator_format_create_glyphs_x();
1611 #endif                          /* HAVE_X_WINDOWS */
1612
1613                 /* Now initialize the lstream types and associated symbols.
1614                    Other than the first function below, the functions may
1615                    make exactly the following function/macro calls:
1616
1617                    LSTREAM_HAS_METHOD()
1618
1619                  */
1620
1621                 lstream_type_create();
1622 #ifdef FILE_CODING
1623                 lstream_type_create_file_coding();
1624 #endif
1625
1626                 /* Initialize processes implementation.
1627                    The functions may make exactly the following function/macro calls:
1628
1629                    PROCESS_HAS_METHOD()
1630                  */
1631 #ifdef HAVE_UNIX_PROCESSES
1632                 process_type_create_unix();
1633 #endif
1634
1635                 /* Now initialize most variables.
1636
1637                    These functions may do exactly the following:
1638
1639                    DEFVAR_INT()
1640                    DEFVAR_LISP()
1641                    DEFVAR_BOOL()
1642                    DEFER_GETTEXT()
1643                    Dynarr_*()
1644                    Blocktype_*()
1645                    staticpro()
1646                    Fprovide(symbol)
1647                    intern()
1648                    Fput()
1649                    xmalloc()
1650                    defsymbol(), if it's absolutely necessary and you're sure that
1651                    the symbol isn't referenced anywhere else in the initialization
1652                    code
1653                    Fset() on a symbol that is unbound
1654                    assigning a symbol or constant value to a variable
1655                    using a global variable that has been initialized
1656                    earlier on in the same function
1657
1658                    Any of the object-creating functions in alloc.c: e.g.
1659
1660                    make_pure_*()
1661                    make_string()
1662                    build_string()
1663                    make_vector()
1664                    make_int()
1665                    make_extent()
1666                    alloc_lcrecord()
1667                    Fcons()
1668                    listN()
1669                    make_opaque_ptr()
1670
1671                    perhaps a few others.
1672
1673                    NB:  Initialization or assignment should not be done here to certain
1674                    variables settable from the command line.  See the comment above
1675                    the call to pdump_load() in main_1().  This caveat should only
1676                    apply to vars_of_emacs().
1677                  */
1678
1679                 /* Now allow Fprovide() statements to be made. */
1680                 init_provide_once();
1681
1682                 /* Do that before any specifier creation (esp. vars_of_glyphs()) */
1683                 vars_of_specifier();
1684
1685                 vars_of_abbrev();
1686                 vars_of_alloc();
1687                 vars_of_buffer();
1688                 vars_of_bytecode();
1689                 vars_of_callint();
1690                 vars_of_callproc();
1691                 vars_of_chartab();
1692                 vars_of_cmdloop();
1693                 vars_of_cmds();
1694                 vars_of_console();
1695                 vars_of_data();
1696 #ifdef DEBUG_SXEMACS
1697                 vars_of_debug();
1698                 vars_of_tests();
1699 #endif
1700                 vars_of_console_stream();
1701                 vars_of_device();
1702 #ifdef HAVE_DIALOGS
1703                 vars_of_dialog();
1704 #endif
1705                 vars_of_dired();
1706                 vars_of_doc();
1707 #ifdef HAVE_DRAGNDROP
1708                 vars_of_dragdrop();
1709 #endif
1710                 vars_of_editfns();
1711                 vars_of_elhash();
1712                 vars_of_emacs();
1713                 vars_of_eval();
1714
1715 #ifdef HAVE_X_WINDOWS
1716                 vars_of_event_Xt();
1717 #endif
1718 #if defined(HAVE_TTY) && (defined (DEBUG_TTY_EVENT_STREAM) || !defined (HAVE_X_WINDOWS))
1719                 vars_of_event_tty();
1720 #endif
1721                 vars_of_event_stream();
1722 #ifdef EF_USE_ASYNEQ
1723                 vars_of_workers();
1724                 vars_of_worker_asyneq();
1725 #endif
1726
1727                 vars_of_events();
1728                 vars_of_extents();
1729                 vars_of_faces();
1730                 vars_of_fileio();
1731 #ifdef CLASH_DETECTION
1732                 vars_of_filelock();
1733 #endif
1734                 vars_of_floatfns();
1735                 vars_of_font_lock();
1736                 vars_of_frame();
1737                 vars_of_glyphs();
1738                 vars_of_glyphs_eimage();
1739                 vars_of_glyphs_widget();
1740                 vars_of_gui();
1741                 vars_of_gutter();
1742                 vars_of_indent();
1743                 vars_of_insdel();
1744                 vars_of_intl();
1745 #ifdef HAVE_XIM
1746 #ifdef XIM_MOTIF
1747                 vars_of_input_method_motif();
1748 #else                           /* XIM_XLIB */
1749                 vars_of_input_method_xlib();
1750 #endif
1751 #endif                          /* HAVE_XIM */
1752                 vars_of_keymap();
1753                 vars_of_lread();
1754                 vars_of_lstream();
1755                 vars_of_macros();
1756                 vars_of_md5();
1757 #ifdef HAVE_DATABASE
1758                 vars_of_database();
1759 #endif
1760 #ifdef HAVE_MENUBARS
1761                 vars_of_menubar();
1762 #endif
1763                 vars_of_media();
1764                 vars_of_minibuf();
1765                 vars_of_dynacat();
1766 #if defined WITH_EMODULES && defined HAVE_EMODULES && 0
1767                 vars_of_module();
1768 #elif defined WITH_EMODULES && defined HAVE_EMODULES
1769                 vars_of_emodng();
1770 #endif
1771                 vars_of_objects();
1772                 vars_of_print();
1773
1774 #ifndef NO_SUBPROCESSES
1775                 vars_of_process();
1776 #ifdef HAVE_UNIX_PROCESSES
1777                 vars_of_process_unix();
1778 #endif
1779 #endif
1780
1781                 vars_of_profile();
1782 #if defined (HAVE_MMAP) && defined (REL_ALLOC) && !defined(DOUG_LEA_MALLOC)
1783                 vars_of_ralloc();
1784 #endif                          /* HAVE_MMAP && REL_ALLOC */
1785                 vars_of_redisplay();
1786 #ifdef HAVE_SCROLLBARS
1787                 vars_of_scrollbar();
1788 #endif
1789                 vars_of_search();
1790                 vars_of_select();
1791                 vars_of_sound();
1792                 vars_of_symbols();
1793                 vars_of_syntax();
1794 #ifdef HAVE_TOOLBARS
1795                 vars_of_toolbar();
1796 #endif
1797                 vars_of_undo();
1798                 vars_of_window();
1799
1800 #ifdef HAVE_TTY
1801                 vars_of_console_tty();
1802                 vars_of_frame_tty();
1803                 vars_of_objects_tty();
1804 #endif
1805
1806 #ifdef HAVE_X_WINDOWS
1807 #ifdef HAVE_BALLOON_HELP
1808                 vars_of_balloon_x();
1809 #endif
1810                 vars_of_device_x();
1811 #ifdef HAVE_DIALOGS
1812                 vars_of_dialog_x();
1813 #endif
1814                 vars_of_frame_x();
1815                 vars_of_glyphs_x();
1816 #ifdef HAVE_MENUBARS
1817                 vars_of_menubar_x();
1818 #endif
1819                 vars_of_objects_x();
1820                 vars_of_select_x();
1821 #ifdef HAVE_SCROLLBARS
1822                 vars_of_scrollbar_x();
1823 #endif
1824 #if defined (HAVE_MENUBARS) || defined (HAVE_SCROLLBARS) || defined (HAVE_DIALOGS) || defined (HAVE_TOOLBARS)
1825                 vars_of_gui_x();
1826 #endif
1827 #endif                          /* HAVE_X_WINDOWS */
1828
1829 #ifdef MULE
1830                 vars_of_mule();
1831                 vars_of_mule_ccl();
1832                 vars_of_mule_charset();
1833 #endif
1834 #ifdef FILE_CODING
1835                 vars_of_file_coding();
1836 #endif
1837 #ifdef MULE
1838 #ifdef HAVE_WNN
1839                 vars_of_mule_wnn();
1840 #endif
1841 #ifdef HAVE_CANNA
1842                 vars_of_mule_canna();
1843 #endif                          /* HAVE_CANNA */
1844 #endif                          /* MULE */
1845
1846 #ifdef SUNPRO
1847                 vars_of_sunpro();
1848 #endif
1849
1850 #ifdef HAVE_LDAP
1851                 vars_of_eldap();
1852 #endif
1853
1854 #ifdef HAVE_POSTGRESQL
1855                 vars_of_postgresql();
1856 #endif
1857
1858 #ifdef HAVE_OPENSSL
1859                 vars_of_openssl();
1860 #endif
1861
1862 #ifdef HAVE_GPM
1863                 vars_of_gpmevent();
1864 #endif
1865
1866 #ifdef WITH_NUMBER_TYPES
1867                 vars_of_ent();
1868 #endif
1869
1870 #ifdef HAVE_LIBFFI
1871                 vars_of_ffi();
1872 #endif
1873
1874                 vars_of_dllist();
1875                 vars_of_skiplist();
1876                 vars_of_bloom();
1877
1878                 /* Now initialize any specifier variables.  We do this later
1879                    because it has some dependence on the vars initialized
1880                    above.
1881
1882                    These functions should *only* initialize specifier variables,
1883                    and may make use of the following functions/macros in addition
1884                    to the ones listed above:
1885
1886                    DEFVAR_SPECIFIER()
1887                    Fmake_specifier()
1888                    set_specifier_fallback()
1889                    set_specifier_caching()
1890                  */
1891
1892                 specifier_vars_of_glyphs();
1893                 specifier_vars_of_glyphs_widget();
1894                 specifier_vars_of_gutter();
1895 #ifdef HAVE_MENUBARS
1896                 specifier_vars_of_menubar();
1897 #endif
1898                 specifier_vars_of_redisplay();
1899 #ifdef HAVE_SCROLLBARS
1900                 specifier_vars_of_scrollbar();
1901 #endif
1902 #ifdef HAVE_TOOLBARS
1903                 specifier_vars_of_toolbar();
1904 #endif
1905                 specifier_vars_of_window();
1906
1907                 /* Now comes all the rest of the variables that couldn't
1908                    be handled above.  There may be dependencies on variables
1909                    initialized above, and dependencies between one complex_vars_()
1910                    function and another. */
1911
1912                 /* Calls Fmake_range_table(). */
1913                 complex_vars_of_regex();
1914                 /* Calls Fmake_range_table(). */
1915                 complex_vars_of_search();
1916
1917                 /* Calls make_lisp_hash_table(). */
1918                 complex_vars_of_extents();
1919
1920                 /* Depends on hash tables and specifiers. */
1921                 complex_vars_of_faces();
1922
1923 #ifdef MULE
1924                 /* These two depend on hash tables and various variables declared
1925                    earlier.  The second may also depend on the first. */
1926                 complex_vars_of_mule_charset();
1927 #endif
1928 #ifdef FILE_CODING
1929                 complex_vars_of_file_coding();
1930 #endif
1931
1932                 /* This calls allocate_glyph(), which creates specifiers
1933                    and also relies on a variable (Vthe_nothing_vector) initialized
1934                    above.  It also calls make_ext_string(), which under Mule
1935                    could require that the charsets be initialized. */
1936                 complex_vars_of_glyphs();
1937
1938                 /* These rely on the glyphs just created in the previous function,
1939                    and call Fadd_spec_to_specifier(), which relies on various
1940                    variables initialized above. */
1941 #ifdef HAVE_X_WINDOWS
1942                 complex_vars_of_glyphs_x();
1943 #endif
1944
1945                 /* This calls Fmake_glyph_internal(). */
1946                 complex_vars_of_alloc();
1947
1948                 /* This calls Fmake_glyph_internal(). */
1949 #ifdef HAVE_MENUBARS
1950                 complex_vars_of_menubar();
1951 #endif
1952
1953                 /* This calls Fmake_glyph_internal(). */
1954 #ifdef HAVE_SCROLLBARS
1955                 complex_vars_of_scrollbar();
1956 #endif
1957
1958                 /* This calls allocate_glyph(). */
1959                 complex_vars_of_frame();
1960
1961                 /* This calls Fcopy_category_table() under Mule, which calls who
1962                    knows what. */
1963                 complex_vars_of_chartab();
1964
1965                 /* This calls set_string_char(), which (under Mule) depends on the
1966                    charsets being initialized. */
1967                 complex_vars_of_casetab();
1968
1969                 /* This calls Fcopy_syntax_table(), which relies on char tables. */
1970                 complex_vars_of_syntax();
1971
1972                 /* This initializes buffer-local variables, sets things up so
1973                    that buffers can be created, and creates a couple of basic
1974                    buffers.  This depends on Vstandard_syntax_table and
1975                    Vstandard_category_table (initialized in the previous
1976                    functions), as well as a whole horde of variables that may
1977                    have been initialized above. */
1978                 complex_vars_of_buffer();
1979
1980                 /* This initializes console-local variables. */
1981                 complex_vars_of_console();
1982
1983                 /* This creates a couple more buffers, and depends on the
1984                    previous function. */
1985                 complex_vars_of_minibuf();
1986
1987                 /* These two might call Ffile_name_as_directory(), which
1988                    might depend on all sorts of things; I'm not sure. */
1989                 complex_vars_of_emacs();
1990
1991                 /* This creates a couple of basic keymaps and depends on Lisp
1992                    hash tables and Ffset() (both of which depend on some variables
1993                    initialized in the vars_of_*() section) and possibly other
1994                    stuff. */
1995                 complex_vars_of_keymap();
1996
1997                 /* Calls make_lisp_hash_table() and creates a keymap */
1998                 complex_vars_of_event_stream();
1999
2000 #ifdef ERROR_CHECK_GC
2001                 {
2002                         extern int always_gc;
2003                         if (always_gc)  /* purification debugging hack */
2004                                 garbage_collect_1();
2005                 }
2006 #endif
2007 #ifdef PDUMP
2008         } else if (!restart) {  /* after successful pdump_load() */
2009                 reinit_alloc_once_early();
2010                 reinit_symbols_once_early();
2011                 reinit_opaque_once_early();
2012
2013                 reinit_console_type_create_stream();
2014 #ifdef HAVE_TTY
2015                 reinit_console_type_create_tty();
2016 #endif
2017 #ifdef HAVE_X_WINDOWS
2018                 reinit_console_type_create_x();
2019                 reinit_console_type_create_device_x();
2020 #endif
2021
2022                 reinit_specifier_type_create();
2023                 reinit_specifier_type_create_image();
2024                 reinit_specifier_type_create_gutter();
2025                 reinit_specifier_type_create_objects();
2026 #ifdef HAVE_TOOLBARS
2027                 reinit_specifier_type_create_toolbar();
2028 #endif
2029
2030                 structure_type_create();
2031
2032                 structure_type_create_chartab();
2033                 structure_type_create_faces();
2034                 structure_type_create_rangetab();
2035                 structure_type_create_hash_table();
2036
2037                 lstream_type_create();
2038 #ifdef FILE_CODING
2039                 lstream_type_create_file_coding();
2040 #endif
2041 #ifdef HAVE_UNIX_PROCESSES
2042                 process_type_create_unix();
2043 #endif
2044
2045                 reinit_vars_of_buffer();
2046                 reinit_vars_of_console();
2047 #ifdef DEBUG_SXEMACS
2048                 reinit_vars_of_debug();
2049 #endif
2050                 reinit_vars_of_device();
2051                 reinit_vars_of_eval();
2052 #ifdef HAVE_X_WINDOWS
2053                 reinit_vars_of_event_Xt();
2054 #endif
2055 #if defined(HAVE_TTY) && (defined (DEBUG_TTY_EVENT_STREAM) || !defined (HAVE_X_WINDOWS))
2056                 reinit_vars_of_event_tty();
2057 #endif
2058                 reinit_vars_of_event_stream();
2059 #ifdef EF_USE_ASYNEQ
2060                 reinit_vars_of_worker_asyneq();
2061 #endif
2062                 reinit_vars_of_events();
2063                 reinit_vars_of_extents();
2064                 reinit_vars_of_fileio();
2065                 reinit_vars_of_font_lock();
2066                 reinit_vars_of_glyphs();
2067                 reinit_vars_of_glyphs_widget();
2068                 reinit_vars_of_insdel();
2069                 reinit_vars_of_lread();
2070                 reinit_vars_of_lstream();
2071                 reinit_vars_of_minibuf();
2072                 reinit_vars_of_dynacat();
2073 #if defined WITH_EMODULES && defined HAVE_EMODULES && 0
2074                 reinit_vars_of_module();
2075 #elif defined WITH_EMODULES && defined HAVE_EMODULES
2076                 reinit_vars_of_emodng();
2077 #endif
2078                 reinit_vars_of_objects();
2079                 reinit_vars_of_print();
2080                 reinit_vars_of_search();
2081                 reinit_vars_of_undo();
2082                 reinit_vars_of_window();
2083
2084 #ifdef HAVE_X_WINDOWS
2085                 reinit_vars_of_device_x();
2086 #ifdef HAVE_SCROLLBARS
2087                 reinit_vars_of_scrollbar_x();
2088 #endif
2089 #ifdef HAVE_MENUBARS
2090                 reinit_vars_of_menubar_x();
2091 #endif
2092                 reinit_vars_of_select_x();
2093 #if defined (HAVE_MENUBARS) || defined (HAVE_SCROLLBARS) || defined (HAVE_DIALOGS) || defined (HAVE_TOOLBARS)
2094                 reinit_vars_of_gui_x();
2095 #endif
2096 #endif                          /* HAVE_X_WINDOWS */
2097
2098 #if defined(MULE) && defined(HAVE_WNN)
2099                 reinit_vars_of_mule_wnn();
2100 #endif
2101
2102                 reinit_complex_vars_of_buffer();
2103                 reinit_complex_vars_of_console();
2104                 reinit_complex_vars_of_minibuf();
2105
2106 #ifdef HAVE_LIBFFI
2107                 reinit_vars_of_ffi();
2108 #endif
2109
2110 #if defined USE_STATIC_ASE && USE_STATIC_ASE
2111                 reinit_vars_of_ase();
2112 #endif
2113
2114 #endif                          /* PDUMP */
2115         }
2116
2117         /* the category subsystem needs some inits */
2118         dllist_reinit();
2119         elhash_reinit();
2120         skiplist_reinit();
2121
2122         /* CONGRATULATIONS!!!  We have successfully initialized the Lisp
2123            engine. */
2124
2125         if (initialized) {
2126                 /* Stuff that should not be done at dump time, including stuff that
2127                    needs to be reset at run time.  Order below should not matter.
2128
2129                    Many initializations taken from the environment should go here. */
2130                 reinit_alloc();
2131                 reinit_eval();
2132 #ifdef MULE_REGEXP
2133                 reinit_mule_category();
2134 #endif
2135 #ifdef HAVE_POSTGRESQL
2136                 init_postgresql_from_environment();
2137 #endif
2138         }
2139
2140         /* Now do further initialization/setup of stuff that is not needed by the
2141            syms_of_() routines.  This involves stuff that only is enabled in
2142            an interactive run (redisplay, user input, etc.) and stuff that is
2143            not needed until we start loading Lisp code (the reader).  A lot
2144            of this stuff involves querying the current environment and needs
2145            to be done both at dump time and at run time. */
2146
2147         init_initial_directory();       /* get the directory to use for the
2148                                            "*scratch*" buffer, etc. */
2149
2150         init_callproc();        /* Set up the process environment (so that egetenv
2151                                    works), the basic directory variables
2152                                    (exec-directory and so on), and stuff
2153                                    related to subprocesses.  This should be
2154                                    first because many of the functions below
2155                                    call egetenv() to get environment variables. */
2156         init_lread();           /* Set up the Lisp reader. */
2157         init_cmdargs(argc, (Extbyte **) argv, skip_args);       /* Create list Vcommand_line_args */
2158         init_buffer();          /* Set default directory of *scratch* buffer */
2159
2160         init_redisplay();       /* Determine terminal type.
2161                                    init_sys_modes uses results */
2162         init_frame();
2163         init_event_stream();    /* Set up so we can get user input. */
2164         init_macros();          /* set up so we can run macros. */
2165         init_editfns();         /* Determine the name of the user we're running as */
2166         init_sxemacs_process(); /* set up for calling subprocesses */
2167
2168 #ifdef WITH_NUMBER_TYPES
2169         /* Set up bignums, ratios, bigfloats, complex numbers.
2170          * This must be done before the Lisp reader is set up.
2171          */
2172         init_ent ();
2173 #endif
2174
2175 #ifdef SUNPRO
2176         init_sunpro();          /* Set up Sunpro usage tracking */
2177 #endif
2178 #if defined (HAVE_NATIVE_SOUND) && defined (hp9000s800) && 0
2179         init_hpplay();
2180 #endif
2181 #ifdef HAVE_TTY
2182         init_device_tty();
2183 #endif
2184         init_console_stream(restart);   /* Create the first console */
2185
2186         /* try to get the actual pathname of the exec file we are running */
2187         if (!restart) {
2188                 Vinvocation_name = Fcar(Vcommand_line_args);
2189                 if (XSTRING_DATA(Vinvocation_name)[0] == '-') {
2190                         /* SXEmacs as a login shell, oh goody! */
2191                         Vinvocation_name = build_string(getenv("SHELL"));
2192                 }
2193                 Vinvocation_directory = Vinvocation_name;
2194
2195                 if (!NILP(Ffile_name_directory(Vinvocation_name))) {
2196                         /* invocation-name includes a directory component -- presumably it
2197                            is relative to cwd, not $PATH */
2198                         Vinvocation_directory =
2199                             Fexpand_file_name(Vinvocation_name, Qnil);
2200                         Vinvocation_path = Qnil;
2201                 } else {
2202                         Vinvocation_path = decode_env_path("PATH", NULL);
2203                         locate_file(Vinvocation_path, Vinvocation_name,
2204                                     Vlisp_EXEC_SUFFIXES,
2205                                     &Vinvocation_directory, X_OK);
2206                 }
2207
2208                 if (NILP(Vinvocation_directory))
2209                         Vinvocation_directory = Vinvocation_name;
2210
2211                 Vinvocation_name =
2212                     Ffile_name_nondirectory(Vinvocation_directory);
2213                 Vinvocation_directory =
2214                     Ffile_name_directory(Vinvocation_directory);
2215         }
2216
2217 #if defined (LOCALTIME_CACHE) && defined (HAVE_TZSET)
2218         /* sun's localtime() has a bug.  it caches the value of the time
2219            zone rather than looking it up every time.  Since localtime() is
2220            called to bolt the undumping time into the undumped emacs, this
2221            results in localtime() ignoring the TZ environment variable.
2222            This flushes the new TZ value into localtime(). */
2223         tzset();
2224 #endif                          /* LOCALTIME_CACHE and TZSET */
2225
2226         load_me = Qnil;
2227         if (!initialized) {
2228                 /* Handle -l loadup-and-dump, args passed by Makefile. */
2229                 if (argc > 2 + skip_args && !strcmp(argv[1 + skip_args], "-l"))
2230                         load_me = build_string(argv[2 + skip_args]);
2231 #if 0
2232                 /* CANNOT_DUMP - this can never be right in SXEmacs --andyp */
2233                 /* Unless next switch is -nl, load "loadup.el" first thing.  */
2234                 if (!
2235                     (argc > 1 + skip_args
2236                      && !strcmp(argv[1 + skip_args], "-nl")))
2237                         load_me = build_string("loadup.el");
2238 #endif                          /* CANNOT_DUMP */
2239         }
2240 #ifdef QUANTIFY
2241         if (initialized)
2242                 quantify_start_recording_data();
2243 #endif                          /* QUANTIFY */
2244
2245         initialized = 1;
2246         inhibit_non_essential_printing_operations = 0;
2247
2248         /* This never returns.  */
2249         initial_command_loop(load_me);
2250         /* NOTREACHED */
2251 }
2252 \f
2253 /* Sort the args so we can find the most important ones
2254    at the beginning of argv.  */
2255
2256 /* First, here's a table of all the standard options.  */
2257
2258 struct standard_args {
2259         const char *name;
2260         const char *longname;
2261         int priority;
2262         int nargs;
2263 };
2264
2265 static const struct standard_args standard_args[] = {
2266         /* Handled by main_1 above: */
2267         {"--make-docfile", 0, 105, 0},
2268         {"-sd", "--show-dump-id", 105, 0},
2269         {"-t", "--terminal", 100, 1},
2270         {"-nd", "--no-dump-file", 95, 0},
2271         {"-ct", "--color-terminal", 92, 0},
2272         {"-nw", "--no-windows", 90, 0},
2273         {"-batch", "--batch", 85, 0},
2274         {"-debug-paths", "--debug-paths", 82, 0},
2275         {"-help", "--help", 80, 0},
2276         {"-version", "--version", 75, 0},
2277         {"-V", 0, 75, 0},
2278         {"-d", "--display", 80, 1},
2279         {"-display", 0, 80, 1},
2280         {"-NXHost", 0, 79, 0},
2281         {"-MachLaunch", 0, 79, 0},
2282
2283         /* Handled by command-line-early in startup.el: */
2284         {"-q", "--no-init-file", 50, 0},
2285         {"-unmapped", 0, 50, 0},
2286         {"-no-init-file", 0, 50, 0},
2287         {"-vanilla", "--vanilla", 50, 0},
2288         {"-no-autoloads", "--no-autoloads", 50, 0},
2289         {"-no-site-file", "--no-site-file", 40, 0},
2290         {"-no-early-packages", "--no-early-packages", 35, 0},
2291         {"-u", "--user", 30, 1},
2292         {"-user", 0, 30, 1},
2293         {"-debug-init", "--debug-init", 20, 0},
2294         {"-debug-paths", "--debug-paths", 20, 0},
2295
2296         /* Xt options: */
2297         {"-i", "--icon-type", 15, 0},
2298         {"-itype", 0, 15, 0},
2299         {"-iconic", "--iconic", 15, 0},
2300         {"-bg", "--background-color", 10, 1},
2301         {"-background", 0, 10, 1},
2302         {"-fg", "--foreground-color", 10, 1},
2303         {"-foreground", 0, 10, 1},
2304         {"-bd", "--border-color", 10, 1},
2305         {"-bw", "--border-width", 10, 1},
2306         {"-ib", "--internal-border", 10, 1},
2307         {"-ms", "--mouse-color", 10, 1},
2308         {"-cr", "--cursor-color", 10, 1},
2309         {"-fn", "--font", 10, 1},
2310         {"-font", 0, 10, 1},
2311         {"-g", "--geometry", 10, 1},
2312         {"-geometry", 0, 10, 1},
2313         {"-T", "--title", 10, 1},
2314         {"-title", 0, 10, 1},
2315         {"-name", "--name", 10, 1},
2316         {"-xrm", "--xrm", 10, 1},
2317         {"-r", "--reverse-video", 5, 0},
2318         {"-rv", 0, 5, 0},
2319         {"-reverse", 0, 5, 0},
2320         {"-hb", "--horizontal-scroll-bars", 5, 0},
2321         {"-vb", "--vertical-scroll-bars", 5, 0},
2322
2323         /* These have the same priority as ordinary file name args,
2324            so they are not reordered with respect to those.  */
2325         {"-L", "--directory", 0, 1},
2326         {"-directory", 0, 0, 1},
2327         {"-l", "--load", 0, 1},
2328         {"-load", 0, 0, 1},
2329         {"-f", "--funcall", 0, 1},
2330         {"-funcall", 0, 0, 1},
2331         {"-eval", "--eval", 0, 1},
2332         {"-insert", "--insert", 0, 1},
2333         /* This should be processed after ordinary file name args and the like.  */
2334         {"-kill", "--kill", -10, 0},
2335 };
2336
2337 /* Reorder the elements of ARGV (assumed to have ARGC elements)
2338    so that the highest priority ones come first.
2339    Do not change the order of elements of equal priority.
2340    If an option takes an argument, keep it and its argument together.  */
2341
2342 static void sort_args(int argc, char **argv)
2343 {
2344         char **new_argv = (char**)malloc(sizeof(char*) * argc);
2345         /* For each element of argv,
2346            the corresponding element of options is:
2347            0 for an option that takes no arguments,
2348            1 for an option that takes one argument, etc.
2349            -1 for an ordinary non-option argument.  */
2350         int *options = (int*)malloc(sizeof(int) * argc);
2351         int *priority = (int*)malloc(sizeof(int) * argc);
2352         int to = 1;
2353         int from;
2354         int i;
2355         int end_of_options_p = 0;
2356
2357         /* Categorize all the options,
2358            and figure out which argv elts are option arguments.  */
2359         for (from = 1; from < argc; from++) {
2360                 options[from] = -1;
2361                 priority[from] = 0;
2362                 /* Pseudo options "--" and "run-temacs" indicate end of
2363                    options */
2364                 if (!strcmp(argv[from], "--") ||
2365                     !strcmp(argv[from], "run-temacs"))
2366                         end_of_options_p = 1;
2367                 if (!end_of_options_p && argv[from][0] == '-') {
2368                         int match, thislen;
2369                         char *equals;
2370
2371                         /* Look for a match with a known old-fashioned
2372                            option.  */
2373                         for (i = 0; i < countof(standard_args); i++) {
2374                                 if (!strcmp(argv[from],
2375                                             standard_args[i].name)) {
2376                                         options[from] = standard_args[i].nargs;
2377                                         priority[from] =
2378                                             standard_args[i].priority;
2379                                         if (from + standard_args[i].nargs >=
2380                                             argc) {
2381                                                 fatal("Option `%s' requires "
2382                                                       "an argument\n",
2383                                                       argv[from]);
2384                                         }
2385                                         from += standard_args[i].nargs;
2386                                         goto done;
2387                                 }
2388                         }
2389
2390                         /* Look for a match with a known long option.  MATCH is
2391                            -1 if no match so far, -2 if two or more matches so
2392                            far,
2393                            >= 0 (the table index of the match) if just one match
2394                            >so far.  */
2395                         if (argv[from][1] == '-') {
2396                                 match = -1;
2397                                 thislen = strlen(argv[from]);
2398                                 equals = strchr(argv[from], '=');
2399                                 if (equals != 0)
2400                                         thislen = equals - argv[from];
2401
2402                                 for (i = 0; i < countof(standard_args); i++)
2403                                         if (standard_args[i].longname
2404                                             && !strncmp(argv[from],
2405                                                         standard_args[i].
2406                                                         longname, thislen)) {
2407                                                 if (match == -1)
2408                                                         match = i;
2409                                                 else
2410                                                         match = -2;
2411                                         }
2412
2413                                 /* If we found exactly one match, use that.  */
2414                                 if (match >= 0) {
2415                                         options[from] =
2416                                                 standard_args[match].nargs;
2417                                         priority[from] =
2418                                                 standard_args[match].priority;
2419                                         /* If --OPTION=VALUE syntax is used,
2420                                            this option uses just one argv
2421                                            element.  */
2422                                         if (equals != 0)
2423                                                 options[from] = 0;
2424                                         if (from + options[from] >= argc) {
2425                                                 fatal("Option `%s' requires "
2426                                                       "an argument\n",
2427                                                       argv[from]);
2428                                         }
2429                                         from += options[from];
2430                                 }
2431                         }
2432                 done:
2433                         ;
2434                 }
2435         }
2436
2437         /* Copy the arguments, in order of decreasing priority, to NEW_ARGV.  */
2438         new_argv[0] = argv[0];
2439         while (to < argc) {
2440                 int best = -1;
2441                 int best_priority = -9999;
2442
2443                 /* Find the highest priority remaining option.
2444                    If several have equal priority, take the first of them.  */
2445                 for (from = 1; from < argc; from++) {
2446                         if (argv[from] != 0 && priority[from] > best_priority) {
2447                                 best_priority = priority[from];
2448                                 best = from;
2449                         }
2450                         /* Skip option arguments--they are tied to the options.  */
2451                         if (options[from] > 0) {
2452                                 from += options[from];
2453                         }
2454                 }
2455
2456                 if (best < 0) {
2457                         abort();
2458                 }
2459
2460                 /* Copy the highest priority remaining option, with its args, to
2461                    NEW_ARGV.  */
2462                 new_argv[to++] = argv[best];
2463                 for (i = 0; i < options[best]; i++) {
2464                         new_argv[to++] = argv[best + i + 1];
2465                 }
2466                 /* Clear out this option in ARGV.  */
2467                 argv[best] = 0;
2468                 for (i = 0; i < options[best]; i++) {
2469                         argv[best + i + 1] = 0;
2470                 }
2471         }
2472
2473         memcpy(argv, new_argv, sizeof(char *) * argc);
2474         free(new_argv);
2475         free(options);
2476         free(priority);
2477         return;
2478 }
2479
2480 DEFUN("running-temacs-p", Frunning_temacs_p, 0, 0, 0, /*
2481 True if running temacs.  This means we are in the dumping stage.
2482 This is false during normal execution of the `sxemacs' program, and
2483 becomes false once `run-emacs-from-temacs' is run.
2484 */
2485       ())
2486 {
2487         return run_temacs_argc >= 0 ? Qt : Qnil;
2488 }
2489
2490 DEFUN("run-emacs-from-temacs", Frun_emacs_from_temacs, 0, MANY, 0, /*
2491 Do not call this.  It will reinitialize your SXEmacs.  You'll be sorry.
2492 */
2493 /* If this function is called from startup.el, it will be possible to run
2494    temacs as an editor using 'temacs -batch -l loadup.el run-temacs', instead
2495    of having to dump an emacs and then run that (when debugging emacs itself,
2496    this can be much faster)). [Actually, the speed difference isn't that
2497    much as long as your filesystem is local, and you don't end up with
2498    a dumped version in case you want to rerun it.  This function is most
2499    useful when used as part of the `make all-elc' command. --ben]
2500    This will "restart" emacs with the specified command-line arguments.
2501
2502    Martin thinks this function is most useful when using debugging
2503    tools like Purify or tcov that get confused by SXEmacs' dumping.  */
2504       (int nargs, Lisp_Object * args))
2505 {
2506         int ac;
2507         const Extbyte *wampum = NULL;
2508         int namesize;
2509         int total_len;
2510         Lisp_Object orig_invoc_name = Fcar(Vcommand_line_args);
2511         const Extbyte **wampum_all = alloca_array(const Extbyte *, nargs);
2512         int *wampum_all_len = alloca_array(int, nargs);
2513
2514         assert(!gc_in_progress);
2515
2516         if (run_temacs_argc < 0)
2517                 error("I've lost my temacs-hood.");
2518
2519         /* Need to convert the orig_invoc_name and all of the arguments
2520            to external format. */
2521
2522         TO_EXTERNAL_FORMAT(LISP_STRING, orig_invoc_name,
2523                            ALLOCA, (wampum, namesize), Qnative);
2524         if ( wampum == NULL )
2525                 error("Could not transcode invocation name");
2526
2527         namesize++;
2528
2529         for (ac = 0, total_len = namesize; ac < nargs; ac++) {
2530                 CHECK_STRING(args[ac]);
2531                 wampum_all[ac]=NULL;
2532                 TO_EXTERNAL_FORMAT(LISP_STRING, args[ac],
2533                                    ALLOCA, (wampum_all[ac], wampum_all_len[ac]),
2534                                    Qnative);
2535                 if(wampum_all[ac]==NULL) {
2536                         error("Could not transcode arguments");
2537                 }
2538                 wampum_all_len[ac]++;
2539                 total_len += wampum_all_len[ac];
2540         }
2541         DO_REALLOC(run_temacs_args, run_temacs_args_size, total_len, char);
2542         DO_REALLOC(run_temacs_argv, run_temacs_argv_size, nargs + 2, char *);
2543
2544         memcpy(run_temacs_args, wampum, namesize);
2545         run_temacs_argv[0] = run_temacs_args;
2546         for (ac = 0; ac < nargs; ac++) {
2547                 memcpy(run_temacs_args + namesize,
2548                        wampum_all[ac], wampum_all_len[ac]);
2549                 run_temacs_argv[ac + 1] = run_temacs_args + namesize;
2550                 namesize += wampum_all_len[ac];
2551         }
2552         run_temacs_argv[nargs + 1] = 0;
2553         catchlist = NULL;       /* Important!  Otherwise free_cons() calls in
2554                                    condition_case_unwind() may lead to GC death. */
2555         unbind_to(0, Qnil);     /* this closes loadup.el */
2556         purify_flag = 0;
2557         run_temacs_argc = nargs + 1;
2558 #if defined (HEAP_IN_DATA) && !defined(PDUMP)
2559         report_sheap_usage(0);
2560 #endif
2561         LONGJMP(run_temacs_catch, 1);
2562         return Qnil;            /* not reached; warning suppression */
2563 }
2564
2565 /* defined in alloc.c */
2566 extern void init_bdwgc(void);
2567
2568 /* ARGSUSED */
2569 int
2570 main(int argc, char **argv, char **envp)
2571 {
2572         int volatile vol_argc = argc;
2573         char **volatile vol_argv = argv;
2574         char **volatile vol_envp = envp;
2575         /* This is hairy.  We need to compute where the SXEmacs binary was invoked
2576            from because temacs initialization requires it to find the lisp
2577            directories.  The code that recomputes the path is guarded by the
2578            restarted flag.  There are three possible paths I've found so far
2579            through this:
2580
2581            temacs -- When running temacs for basic build stuff, the first main_1
2582            will be the only one invoked.  It must compute the path else there
2583            will be a very ugly bomb in startup.el (can't find obvious location
2584            for doc-directory data-directory, etc.).
2585
2586            temacs w/ run-temacs on the command line -- This is run to bytecompile
2587            all the out of date dumped lisp.  It will execute both of the main_1
2588            calls and the second one must not touch the first computation because
2589            argc/argv are hosed the second time through.
2590
2591            sxemacs -- Only the second main_1 is executed.  The invocation path must
2592            computed but this only matters when running in place or when running
2593            as a login shell.
2594
2595            As a bonus for straightening this out, SXEmacs can now be run in place
2596            as a login shell.  This never used to work.
2597
2598            As another bonus, we can now guarantee that
2599            (concat invocation-directory invocation-name) contains the filename
2600            of the SXEmacs binary we are running.  This can now be used in a
2601            definite test for out of date dumped files.  -slb */
2602         int restarted = 0;
2603 #ifdef QUANTIFY
2604         quantify_stop_recording_data();
2605         quantify_clear_data();
2606 #endif /* QUANTIFY */
2607
2608         inhibit_non_essential_printing_operations = 1;
2609         suppress_early_error_handler_backtrace = 0;
2610         lim_data = 0;   /* force reinitialization of this variable */
2611
2612         /* Lisp_Object must fit in a word; check VALBITS and GCTYPEBITS */
2613         assert(sizeof(Lisp_Object) == sizeof(void *));
2614
2615 #ifdef LINUX_SBRK_BUG
2616         sbrk(1);
2617 #endif
2618
2619         /* defined in alloc.c */
2620         init_bdwgc();
2621
2622         if (!initialized) {
2623 #ifdef DOUG_LEA_MALLOC
2624                 if (mallopt(M_MMAP_MAX, 0) != 1)
2625                         abort();
2626 #endif
2627                 run_temacs_argc = 0;
2628                 if (!SETJMP(run_temacs_catch)) {
2629                         main_1(vol_argc, vol_argv, vol_envp, 0);
2630                 }
2631                 /* run-emacs-from-temacs called */
2632                 restarted = 1;
2633                 vol_argc = run_temacs_argc;
2634                 vol_argv = run_temacs_argv;
2635 #ifdef _SCO_DS
2636                 /* This makes absolutely no sense to anyone involved.  There are
2637                    several people using this stuff.  We've compared versions on
2638                    everything we can think of.  We can find no difference.
2639                    However, on both my systems environ is a plain old global
2640                    variable initialized to zero.  _environ is the one that
2641                    contains pointers to the actual environment.
2642
2643                    Since we can't figure out the difference (and we're hours
2644                    away from a release), this takes a very cowardly approach and
2645                    is bracketed with both a system specific preprocessor test
2646                    and a runtime "do you have this problem" test
2647
2648                    06/20/96 robertl@dgii.com */
2649                 {
2650                         extern char **_environ;
2651                         if ((unsigned)environ == 0)
2652                                 environ = _environ;
2653                 }
2654 #endif                          /* _SCO_DS */
2655                 vol_envp = environ;
2656         }
2657 #if defined (RUN_TIME_REMAP) && ! defined (PDUMP)
2658         else
2659                 /* obviously no-one uses this because where it was before initialized was
2660                  *always* true */
2661                 run_time_remap(argv[0]);
2662 #endif
2663
2664 #ifdef DOUG_LEA_MALLOC
2665         if (initialized && (malloc_state_ptr != NULL)) {
2666                 int rc = malloc_set_state(malloc_state_ptr);
2667                 if (rc != 0) {
2668                         stderr_out("malloc_set_state failed, rc = %d\n",
2669                                    rc);
2670                         abort();
2671                 }
2672 #if 0
2673                 free(malloc_state_ptr);
2674 #endif
2675                 /* mmap works in glibc-2.1, glibc-2.0 (Non-Mule only)
2676                  * and Linux libc5 */
2677 #if (defined(__GLIBC__) && __GLIBC_MINOR__ >= 1) ||                     \
2678         defined(_NO_MALLOC_WARNING_) ||                                 \
2679         (defined(__GLIBC__) && __GLIBC_MINOR__ < 1 && !defined(MULE)) || \
2680         defined(DEBUG_DOUG_LEA_MALLOC)
2681                 if (mallopt(M_MMAP_MAX, 0) != 1)
2682                         abort();
2683 #endif
2684 #ifdef REL_ALLOC
2685                 r_alloc_reinit();
2686 #endif
2687         }
2688  #endif                         /* DOUG_LEA_MALLOC */
2689
2690         run_temacs_argc = -1;
2691
2692         main_1(vol_argc, vol_argv, vol_envp, restarted);
2693
2694         return 0;               /* unreached */
2695 }
2696
2697 \f
2698 /* Dumping apparently isn't supported by versions of GCC >= 2.8. */
2699 /* The following needs conditionalization on whether either SXEmacs or */
2700 /* various system shared libraries have been built and linked with */
2701 /* GCC >= 2.8.  -slb */
2702 #if defined(GNU_MALLOC)
2703 static void voodoo_free_hook(void *mem)
2704 {
2705         /* Disable all calls to free() when SXEmacs is exiting and it doesn't */
2706         /* matter. */
2707         __free_hook =
2708 #if defined __GNUC__ || defined __INTEL_COMPILER
2709 /* prototype of __free_hook varies with glibc version */
2710             (__typeof__(__free_hook))
2711 #endif
2712             voodoo_free_hook;
2713 }
2714 #endif                          /* GNU_MALLOC */
2715
2716 DEFUN("kill-emacs", Fkill_emacs, 0, 1, "P", /*
2717 Exit the SXEmacs job and kill it.  Ask for confirmation, without argument.
2718 If ARG is an integer, return ARG as the exit program code.
2719 If ARG is a string, stuff it as keyboard input.
2720
2721 The value of `kill-emacs-hook', if not void,
2722 is a list of functions (of no args),
2723 all of which are called before SXEmacs is actually killed.
2724 */
2725       (arg))
2726 {
2727         /* This function can GC */
2728         struct gcpro gcpro1;
2729
2730         GCPRO1(arg);
2731
2732         if (feof(stdin))
2733                 arg = Qt;
2734
2735         if (!preparing_for_armageddon && !noninteractive)
2736                 run_hook(Qkill_emacs_hook);
2737
2738         ensure_no_quitting_from_now_on();
2739
2740         if (!preparing_for_armageddon) {
2741                 Lisp_Object concons, nextcons;
2742
2743                 /* Normally, go ahead and delete all the consoles now.
2744                    Some unmentionably lame window systems (MS Wwwww...... eek,
2745                    I can't even say it) don't properly clean up after themselves,
2746                    and even for those that do, it might be cleaner this way.
2747                    If we're going down, however, we don't do this (might
2748                    be too dangerous), and if we get a crash somewhere within
2749                    this loop, we'll still autosave and won't try this again. */
2750
2751                 LIST_LOOP_DELETING(concons, nextcons, Vconsole_list) {
2752                         /* There is very little point in deleting the stream console.
2753                            It uses stdio, which should flush any buffered output and
2754                            something can only go wrong. -slb */
2755                         /* I changed my mind.  There's a stupid hack in close to add
2756                            a trailing newline. */
2757                         /*if (!CONSOLE_STREAM_P (XCONSOLE (XCAR (concons)))) */
2758                         delete_console_internal(XCONSOLE(XCAR(concons)), 1, 1,
2759                                                 0);
2760                 }
2761         }
2762
2763         UNGCPRO;
2764
2765         shut_down_emacs(0, STRINGP(arg) ? arg : Qnil, 0);
2766
2767 #if defined(GNU_MALLOC)
2768         __free_hook =
2769 #if defined __GNUC__ || defined __INTEL_COMPILER
2770 /* prototype of __free_hook varies with glibc version */
2771             (__typeof__(__free_hook))
2772 #endif
2773             voodoo_free_hook;
2774 #endif
2775
2776         exit(INTP(arg) ? XINT(arg) : 0);
2777         /* NOTREACHED */
2778         return Qnil;            /* I'm sick of the compiler warning */
2779 }
2780
2781 /* Perform an orderly shutdown of SXEmacs.  Autosave any modified
2782    buffers, kill any child processes, clean up the terminal modes (if
2783    we're in the foreground), and other stuff like that.  Don't perform
2784    any redisplay; this may be called when SXEmacs is shutting down in
2785    the background, or after its X connection has died.
2786
2787    If SIG is a signal number, print a message for it.
2788
2789    This is called by fatal signal handlers and Fkill_emacs.  It used to
2790    be called by X protocol error handlers, but instead they now call
2791    Fkill_emacs. */
2792 static void shut_down_emacs(int sig, Lisp_Object stuff, int no_auto_save)
2793 {
2794         /* This function can GC */
2795         /* Prevent running of hooks and other non-essential stuff
2796            from now on.  */
2797         preparing_for_armageddon = 1;
2798
2799         ensure_no_quitting_from_now_on();
2800
2801 #ifdef QUANTIFY
2802         quantify_stop_recording_data();
2803 #endif                          /* QUANTIFY */
2804
2805         /* This is absolutely the most important thing to do, so make sure
2806            we do it now, before anything else.  We might have crashed and
2807            be in a weird inconsistent state, and potentially anything could
2808            set off another protection fault and cause us to bail out
2809            immediately. */
2810         /* Steve writes the following:
2811
2812            [[I'm not removing the code entirely, yet.  We have run up against
2813            a spate of problems in diagnosing crashes due to crashes within
2814            crashes.  It has very definitely been determined that code called
2815            during auto-saving cannot work if SXEmacs crashed inside of GC.
2816            We already auto-save on an itimer so there cannot be too much
2817            unsaved stuff around, and if we get better crash reports we might
2818            be able to get more problems fixed so I'm disabling this.  -slb]]
2819
2820            and DISABLES AUTO-SAVING ENTIRELY during crashes!  Way way bad idea.
2821
2822            Instead let's just be more intelligent about avoiding crashing
2823            when possible, esp. nested crashes.
2824          */
2825         if (!no_auto_save)
2826                 Fdo_auto_save(Qt, Qnil);        /* do this before anything hazardous */
2827
2828         fflush(stdout);
2829         reset_all_consoles();
2830         if (sig && sig != SIGTERM) {
2831                 if (sig == -1)
2832                         stderr_out("\nFatal error.\n\n");
2833                 else
2834                         stderr_out("\nFatal error (%d).\n\n", sig);
2835                 stderr_out
2836                     ("Your files have been auto-saved.\n"
2837                      "Use `M-x recover-session' to recover them.\n"
2838                      "\n"
2839                      "Your version of SXEmacs was distributed with a PROBLEMS file that  may describe\n"
2840                      "your crash, and with luck a workaround.  Please check it first, but do report\n"
2841                      "the crash anyway.  "
2842 #ifdef INFODOCK
2843                      "\n\nPlease report this bug by selecting `Report-Bug' in the InfoDock menu.\n"
2844                      "*BE SURE* to include the SXEmacs configuration from M-x describe-installation,\n"
2845                      "or the file Installation in the top directory of the build tree.\n"
2846 #else
2847                      "Please report this bug by invoking M-x report-sxemacs-bug,\n"
2848                      "or by selecting `Send Bug Report' from the Help menu.  If necessary, send\n"
2849                      "ordinary email to `sxemacs-devel@sxemacs.org'.  *MAKE SURE* to include the SXEmacs\n"
2850                      "configuration from M-x describe-installation, or equivalently the file\n"
2851                      "Installation in the top of the build tree.\n"
2852 #endif
2853 #ifndef _MSC_VER
2854                      "\n"
2855                      "*Please* try *hard* to obtain a C stack backtrace; without it, we are unlikely\n"
2856                      "to be able to analyze the problem.  Locate the core file produced as a result\n"
2857                      "of this crash (often called `core' or `core.<process-id>', and located in\n"
2858                      "the directory in which you started SXEmacs or your home directory), and type\n"
2859                      "\n" "  gdb "
2860 #endif
2861                     );
2862                 {
2863                         const char *name;
2864                         char *dir = 0;
2865
2866                         /* Now try to determine the actual path to the executable,
2867                            to try to make the backtrace-determination process as foolproof
2868                            as possible. */
2869                         if (STRINGP(Vinvocation_name))
2870                                 name = (char *)XSTRING_DATA(Vinvocation_name);
2871                         else
2872                                 name = "sxemacs";
2873                         if (STRINGP(Vinvocation_directory))
2874                                 dir =
2875                                     (char *)XSTRING_DATA(Vinvocation_directory);
2876                         if (!dir || dir[0] != '/')
2877                                 stderr_out("`which %s`", name);
2878                         else if (dir[strlen(dir) - 1] != '/')
2879                                 stderr_out("%s/%s", dir, name);
2880                         else
2881                                 stderr_out("%s%s", dir, name);
2882                 }
2883                 stderr_out
2884                     (" core\n"
2885                      "\n"
2886                      "then type `where' at the debugger prompt.  "
2887                      "No GDB on your system?  You may\n"
2888                      "have DBX, or XDB, or SDB.  (Ask your system "
2889                      "administrator if you need help.)\n"
2890                      "If no core file was produced, enable them "
2891                      "(often with `ulimit -c unlimited'\n"
2892                      "in case of future recurrance of the crash.\n");
2893         }
2894
2895         stuff_buffered_input(stuff);
2896
2897         kill_buffer_processes(Qnil);
2898
2899 #ifdef CLASH_DETECTION
2900         unlock_all_files();
2901 #endif
2902
2903 }
2904 \f
2905 #ifndef CANNOT_DUMP
2906
2907 #if !defined(PDUMP) || !defined(SYSTEM_MALLOC)
2908 extern char my_edata[];
2909 #endif
2910
2911 extern void disable_free_hook(void);
2912
2913 DEFUN("dump-emacs", Fdump_emacs, 2, 2, 0, /*
2914 Dump current state of SXEmacs into executable file FILENAME.
2915 Take symbols from SYMFILE (presumably the file you executed to run SXEmacs).
2916 This is used in the file `loadup.el' when building SXEmacs.
2917
2918 Remember to set `command-line-processed' to nil before dumping
2919 if you want the dumped SXEmacs to process its command line
2920 and announce itself normally when it is run.
2921 */
2922       (symfile, filename))
2923 {
2924         /* This function can GC */
2925         struct gcpro gcpro1, gcpro2;
2926         int opurify;
2927
2928         GCPRO2(filename, symfile);
2929
2930 #if 0
2931         /* kick them */
2932         Vinvocation_directory = Vinvocation_name = Qnil;
2933         Vcommand_line_args = Qnil;
2934 #endif
2935
2936 #ifdef FREE_CHECKING
2937         Freally_free(Qnil);
2938
2939         /* When we're dumping, we can't use the debugging free() */
2940         disable_free_hook();
2941 #endif
2942
2943         CHECK_STRING(filename);
2944         filename = Fexpand_file_name(filename, Qnil);
2945         if (!NILP(symfile)) {
2946                 CHECK_STRING(symfile);
2947                 if (XSTRING_LENGTH(symfile) > 0) {
2948                         symfile = Fexpand_file_name(symfile, Qnil);
2949                 } else {
2950                         symfile = Qnil;
2951                 }
2952         }
2953
2954         opurify = purify_flag;
2955         purify_flag = 0;
2956
2957 #if defined (HEAP_IN_DATA) && !defined(PDUMP)
2958         report_sheap_usage(1);
2959 #endif
2960
2961         clear_message();
2962
2963         fflush(stderr);
2964         fflush(stdout);
2965
2966         disksave_object_finalization();
2967         release_breathing_space();
2968
2969         /* Tell malloc where start of impure now is */
2970         /* Also arrange for warnings when nearly out of space.  */
2971 #ifndef SYSTEM_MALLOC
2972         memory_warnings(my_edata, malloc_warning);
2973 #endif
2974
2975         UNGCPRO;
2976
2977         {
2978                 char *filename_ext;
2979                 char *symfile_ext;
2980
2981                 LISP_STRING_TO_EXTERNAL(filename, filename_ext, Qfile_name);
2982
2983                 if (STRINGP(symfile)) {
2984                         LISP_STRING_TO_EXTERNAL(symfile, symfile_ext,
2985                                                 Qfile_name);
2986                 } else {
2987                         symfile_ext = 0;
2988                 }
2989
2990                 garbage_collect_1();
2991
2992 #ifdef PDUMP
2993                 pdump(filename_ext);
2994 #else
2995
2996 #ifdef DOUG_LEA_MALLOC
2997                 malloc_state_ptr = malloc_get_state();
2998 #endif
2999                 /* here we break our rule that the filename conversion should
3000                    be performed at the actual time that the system call is made.
3001                    It's a whole lot easier to do the conversion here than to
3002                    modify all the unexec routines to ensure that filename
3003                    conversion is applied everywhere.  Don't worry about memory
3004                    leakage because this call only happens once. */
3005                 unexec(filename_ext, symfile_ext, (uintptr_t) my_edata, 0, 0);
3006 #ifdef DOUG_LEA_MALLOC
3007                 free(malloc_state_ptr);
3008 #endif
3009 #endif                          /* not PDUMP */
3010         }
3011
3012         purify_flag = opurify;
3013
3014         return Qnil;
3015 }
3016
3017 #endif                          /* not CANNOT_DUMP */
3018 \f
3019 /* Split STRING into a list of substrings.  The substrings are the
3020    parts of original STRING separated by SEPCHAR.  */
3021 static Lisp_Object
3022 split_string_by_emchar_1(const Bufbyte * string, Bytecount size, Emchar sepchar)
3023 {
3024         Lisp_Object result = Qnil;
3025         const Bufbyte *end = string + size;
3026
3027         while (1) {
3028                 const Bufbyte *p = string;
3029                 while (p < end) {
3030                         if (charptr_emchar(p) == sepchar)
3031                                 break;
3032                         INC_CHARPTR(p);
3033                 }
3034                 result = Fcons(make_string(string, p - string), result);
3035                 if (p < end) {
3036                         string = p;
3037                         INC_CHARPTR(string);    /* skip sepchar */
3038                 } else
3039                         break;
3040         }
3041         return Fnreverse(result);
3042 }
3043
3044 /* The same as the above, except PATH is an external C string (it is
3045    converted using Qfile_name), and sepchar is hardcoded to SEPCHAR
3046    (':' or whatever).  */
3047 Lisp_Object decode_path(/*const*/ char *path)
3048 {
3049         Bytecount newlen = 0;
3050         Bufbyte *newpath = NULL;
3051         if (!path)
3052                 return Qnil;
3053
3054         TO_INTERNAL_FORMAT(C_STRING, path, ALLOCA, (newpath, newlen),
3055                            Qfile_name);
3056
3057         /* #### Does this make sense?  It certainly does for
3058            decode_env_path(), but it looks dubious here.  Does any code
3059            depend on decode_path("") returning nil instead of an empty
3060            string?  */
3061         if (!newlen || !newpath)
3062                 return Qnil;
3063
3064         return split_string_by_emchar_1(newpath, newlen, SEPCHAR);
3065 }
3066
3067 Lisp_Object decode_env_path(const char *evarname, /*const*/ char *default_)
3068 {
3069         /*const*/ char *path = 0;
3070         if (evarname)
3071                 path = egetenv(evarname);
3072         if (!path)
3073                 path = default_;
3074         return decode_path(path);
3075 }
3076
3077 /* Ben thinks this function should not exist or be exported to Lisp.
3078    We use it to define split-path-string in subr.el (not!).  */
3079
3080 DEFUN("split-string-by-char", Fsplit_string_by_char, 2, 2, 0, /*
3081 Split STRING into a list of substrings originally separated by SEPCHAR.
3082 */
3083       (string, sepchar))
3084 {
3085         CHECK_STRING(string);
3086         CHECK_CHAR(sepchar);
3087         return split_string_by_emchar_1(XSTRING_DATA(string),
3088                                         XSTRING_LENGTH(string), XCHAR(sepchar));
3089 }
3090
3091 /* #### This was supposed to be in subr.el, but is used VERY early in
3092    the bootstrap process, so it goes here.  Damn.  */
3093
3094 DEFUN("split-path", Fsplit_path, 1, 1, 0, /*
3095 Explode a search path into a list of strings.
3096 The path components are separated with the characters specified
3097 with `path-separator'.
3098 */
3099       (path))
3100 {
3101         CHECK_STRING(path);
3102
3103         while (!STRINGP(Vpath_separator)
3104                || (XSTRING_CHAR_LENGTH(Vpath_separator) != 1))
3105                 Vpath_separator = signal_simple_continuable_error
3106                     ("`path-separator' should be set to a single-character string",
3107                      Vpath_separator);
3108
3109         return (split_string_by_emchar_1
3110                 (XSTRING_DATA(path), XSTRING_LENGTH(path),
3111                  charptr_emchar(XSTRING_DATA(Vpath_separator))));
3112 }
3113 \f
3114 DEFUN("noninteractive", Fnoninteractive, 0, 0, 0, /*
3115 Non-nil return value means SXEmacs is running without interactive terminal.
3116 */
3117       ())
3118 {
3119         return noninteractive ? Qt : Qnil;
3120 }
3121
3122 #ifdef USE_ASSERTIONS
3123 static int in_assert_failed = 0;
3124 static const char *assert_failed_file = NULL;
3125 static int assert_failed_line = 0;
3126 static const char *assert_failed_expr = NULL;
3127 /* This flag is useful to define if you're under a debugger; this way, you
3128    can put a breakpoint of assert_failed() and debug multiple problems
3129    in one session without having to recompile. */
3130 static int assertions_dont_abort = 0;
3131
3132 #ifdef fprintf
3133 #undef fprintf
3134 #endif
3135
3136 #ifdef abort
3137 #undef abort                    /* avoid infinite #define loop... */
3138 #endif
3139
3140 #define enter_debugger()
3141
3142 void
3143 assert_failed(const char *file, int line, const char *expr)
3144 {
3145         /* If we're already crashing, let's not crash again.  This might be
3146            critical to getting auto-saving working properly. */
3147         if (fatal_error_in_progress)
3148                 return;
3149
3150         /* We are extremely paranoid so we sensibly deal with recursive
3151            assertion failures. */
3152         in_assert_failed++;
3153         inhibit_non_essential_printing_operations = 1;
3154
3155         if (in_assert_failed >= 4)
3156                 _exit(-1);
3157         else if (in_assert_failed == 3) {
3158                 enter_debugger();
3159                 abort();
3160         } else if (in_assert_failed == 2) {
3161                 /* Not stderr_out(), which does additional things and may trigger
3162                    a recursive assertion failure.  fprintf was undeffed above, in
3163                    case it was encapsulated. */
3164                 fprintf(stderr,
3165                         "\n\nFatal error: recursive assertion failure, "
3166                         "file %s, line %d, %s\n", file, line, expr);
3167                 fprintf(stderr,
3168                         "Original assertion failure: file %s, line %d, %s\n",
3169                         assert_failed_file, assert_failed_line,
3170                         assert_failed_expr);
3171                 fflush(stderr);
3172                 enter_debugger();
3173                 debug_short_backtrace(0x7FFF);
3174         } else {
3175                 assert_failed_file = file;
3176                 assert_failed_line = line;
3177                 assert_failed_expr = expr;
3178
3179                 if (!initialized)
3180                         fprintf(stderr,
3181                                 "\nFatal error: assertion failed, file %s, line %d, %s\n",
3182                                 file, line, expr);
3183                 else
3184                         stderr_out
3185                             ("\nFatal error: assertion failed, file %s, line %d, %s\n",
3186                              file, line, expr);
3187                 fflush(stderr);
3188                 enter_debugger();
3189                 debug_backtrace();
3190         }
3191         if (! assertions_dont_abort) {
3192                 abort();
3193         }
3194         inhibit_non_essential_printing_operations = 0;
3195         in_assert_failed = 0;
3196 }
3197 #endif                          /* USE_ASSERTIONS */
3198
3199 #ifdef QUANTIFY
3200 DEFUN("quantify-start-recording-data", Fquantify_start_recording_data, 0, 0, "", /*
3201 Start recording Quantify data.
3202 */
3203       ())
3204 {
3205         quantify_start_recording_data();
3206         return Qnil;
3207 }
3208
3209 DEFUN("quantify-stop-recording-data", Fquantify_stop_recording_data, 0, 0, "", /*
3210 Stop recording Quantify data.
3211 */
3212       ())
3213 {
3214         quantify_stop_recording_data();
3215         return Qnil;
3216 }
3217
3218 DEFUN("quantify-clear-data", Fquantify_clear_data, 0, 0, "", /*
3219 Clear all Quantify data.
3220 */
3221       ())
3222 {
3223         quantify_clear_data();
3224         return Qnil;
3225 }
3226 #endif                          /* QUANTIFY */
3227
3228 void syms_of_emacs(void)
3229 {
3230 #ifndef CANNOT_DUMP
3231         DEFSUBR(Fdump_emacs);
3232 #endif                          /* !CANNOT_DUMP */
3233
3234         DEFSUBR(Frun_emacs_from_temacs);
3235         DEFSUBR(Frunning_temacs_p);
3236         DEFSUBR(Finvocation_name);
3237         DEFSUBR(Finvocation_directory);
3238         DEFSUBR(Fkill_emacs);
3239         DEFSUBR(Fnoninteractive);
3240
3241 #ifdef DEBUG_SXEMACS
3242         DEFSUBR(Fforce_debugging_signal);
3243 #endif
3244
3245 #ifdef QUANTIFY
3246         DEFSUBR(Fquantify_start_recording_data);
3247         DEFSUBR(Fquantify_stop_recording_data);
3248         DEFSUBR(Fquantify_clear_data);
3249 #endif                          /* QUANTIFY */
3250
3251         DEFSUBR(Fsplit_string_by_char);
3252         DEFSUBR(Fsplit_path);   /* #### */
3253
3254         defsymbol(&Qkill_emacs_hook, "kill-emacs-hook");
3255         defsymbol(&Qsave_buffers_kill_emacs, "save-buffers-kill-emacs");
3256 }
3257
3258 void vars_of_emacs(void)
3259 {
3260         DEFVAR_BOOL("suppress-early-error-handler-backtrace", &suppress_early_error_handler_backtrace /*
3261 Non-nil means early error handler shouldn't print a backtrace.
3262                                                                                                       */ );
3263
3264         DEFVAR_LISP("command-line-args", &Vcommand_line_args /*
3265 Args passed by shell to SXEmacs, as a list of strings.
3266                                                              */ );
3267
3268         DEFVAR_LISP("invocation-name", &Vinvocation_name /*
3269 The program name that was used to run SXEmacs.
3270 Any directory names are omitted.
3271                                                          */ );
3272
3273         DEFVAR_LISP("invocation-directory", &Vinvocation_directory /*
3274 The directory in which the SXEmacs executable was found, to run it.
3275 The value is simply the program name if that directory's name is not known.
3276                                                                    */ );
3277
3278         DEFVAR_LISP("invocation-path", &Vinvocation_path /*
3279 The path in which the SXEmacs executable was found, to run it.
3280 The value is simply the value of environment variable PATH on startup
3281 if SXEmacs was found there.
3282                                                          */ );
3283
3284 #if 0                           /* FSFmacs */
3285         xxDEFVAR_LISP("installation-directory", &Vinstallation_directory,
3286                       "A directory within which to look for the `lib-src' and `etc' directories.\n"
3287                       "This is non-nil when we can't find those directories in their standard\n"
3288                       "installed locations, but we can find them\n"
3289                       "near where the SXEmacs executable was found.");
3290 #endif
3291
3292         DEFVAR_LISP("system-type", &Vsystem_type /*
3293 Symbol indicating type of operating system you are using.
3294                                                  */ );
3295         Vsystem_type = intern(SYSTEM_TYPE);
3296         Fprovide(intern(SYSTEM_TYPE));
3297
3298 #ifndef EMACS_CONFIGURATION
3299 # define EMACS_CONFIGURATION "UNKNOWN"
3300 #endif
3301         DEFVAR_LISP("system-configuration", &Vsystem_configuration /*
3302 String naming the configuration SXEmacs was built for.
3303                                                                    */ );
3304         Vsystem_configuration = build_string(EMACS_CONFIGURATION);
3305
3306 #ifndef EMACS_CONFIG_OPTIONS
3307 # define EMACS_CONFIG_OPTIONS "UNKNOWN"
3308 #endif
3309         DEFVAR_LISP("system-configuration-options", &Vsystem_configuration_options /*
3310 String containing the configuration options SXEmacs was built with.
3311                                                                                    */ );
3312         Vsystem_configuration_options = build_string(EMACS_CONFIG_OPTIONS);
3313
3314         DEFVAR_LISP("emacs-major-version", &Vemacs_major_version /*
3315 Major version number of this version of Emacs, as an integer.
3316 Warning: this variable did not exist in Emacs versions earlier than:
3317   FSF Emacs:   19.23
3318   XEmacs:      19.10
3319                                                                  */ );
3320         Vemacs_major_version = make_int(EMACS_MAJOR_VERSION);
3321
3322         DEFVAR_LISP("emacs-minor-version", &Vemacs_minor_version /*
3323 Minor version number of this version of Emacs, as an integer.
3324 Warning: this variable did not exist in Emacs versions earlier than:
3325   FSF Emacs:   19.23
3326   XEmacs:      19.10
3327                                                                  */ );
3328         Vemacs_minor_version = make_int(EMACS_MINOR_VERSION);
3329
3330         DEFVAR_LISP("emacs-patch-level", &Vemacs_patch_level /*
3331 The patch level of this version of Emacs, as an integer.
3332 The value is non-nil if this version of SXEmacs is part of a series of
3333 stable SXEmacsen, but has bug fixes applied.
3334 Warning: this variable does not exist in FSF Emacs or in XEmacs versions
3335 earlier than 21.1.1
3336                                                              */ );
3337 #ifdef EMACS_PATCH_LEVEL
3338         Vemacs_patch_level = make_int(EMACS_PATCH_LEVEL);
3339 #else
3340         Vemacs_patch_level = Qnil;
3341 #endif
3342
3343         DEFVAR_LISP("emacs-beta-version", &Vemacs_beta_version /*
3344 Beta number of this version of Emacs, as an integer.
3345 The value is nil if this is an officially released version of SXEmacs.
3346 Warning: this variable does not exist in FSF Emacs or in XEmacs versions
3347 earlier than 20.3.
3348                                                                */ );
3349 #ifdef EMACS_BETA_VERSION
3350         Vemacs_beta_version = make_int(EMACS_BETA_VERSION);
3351 #else
3352         Vemacs_beta_version = Qnil;
3353 #endif
3354
3355         DEFVAR_LISP("sxemacs-git-version", &Vsxemacs_git_version /*
3356 This revision name of this SXEmacs.
3357 Warning: this variable does not exist in FSF Emacs or XEmacs.
3358                                                                    */ );
3359
3360         Vsxemacs_git_version = build_string(SXEMACS_GIT_VERSION);
3361
3362 #ifdef INFODOCK
3363         DEFVAR_LISP("infodock-major-version", &Vinfodock_major_version /*
3364 Major version number of this InfoDock release.
3365                                                                        */ );
3366         Vinfodock_major_version = make_int(INFODOCK_MAJOR_VERSION);
3367
3368         DEFVAR_LISP("infodock-minor-version", &Vinfodock_minor_version /*
3369 Minor version number of this InfoDock release.
3370                                                                        */ );
3371         Vinfodock_minor_version = make_int(INFODOCK_MINOR_VERSION);
3372
3373         DEFVAR_LISP("infodock-build-version", &Vinfodock_build_version /*
3374 Build version of this InfoDock release.
3375                                                                        */ );
3376         Vinfodock_build_version = make_int(INFODOCK_BUILD_VERSION);
3377 #endif
3378
3379         DEFVAR_LISP("sxemacs-codename", &Vsxemacs_codename /*
3380 Codename of this version of SXEmacs (a string).
3381                                                            */ );
3382 #ifndef SXEMACS_CODENAME
3383 #define SXEMACS_CODENAME "Noname"
3384 #endif
3385         Vsxemacs_codename = build_string(SXEMACS_CODENAME);
3386
3387         /* Lisp variables which contain command line flags.
3388
3389            The portable dumper stomps on these; they must be saved and restored
3390            if they are processed before the call to pdump_load() in main_1().
3391          */
3392         DEFVAR_BOOL("noninteractive", &noninteractive1 /*
3393 Non-nil means SXEmacs is running without interactive terminal.
3394                                                        */ );
3395
3396         DEFVAR_BOOL("inhibit-early-packages", &inhibit_early_packages /*
3397 Set to non-nil when the early packages should not be respected at startup.
3398                                                                       */ );
3399         DEFVAR_BOOL("warn-early-package-shadows", &warn_early_package_shadows /*
3400 Set to non-nil when the early packages should not shadow late packages. Issues
3401 warning at startup when that happens.
3402                                                                               */ );
3403         warn_early_package_shadows = 0;
3404
3405         DEFVAR_BOOL("inhibit-autoloads", &inhibit_autoloads /*
3406  Set to non-nil when autoloads should not be loaded at startup.
3407                                                             */ );
3408
3409         DEFVAR_BOOL("debug-paths", &debug_paths /*
3410 Set to non-nil when debug information about paths should be printed.
3411                                                  */ );
3412
3413         DEFVAR_BOOL("inhibit-site-modules", &inhibit_site_modules /*
3414 Set to non-nil when site-modules should not be searched at startup.
3415                                                                   */ );
3416 #ifdef INHIBIT_SITE_MODULES
3417         inhibit_site_modules = 1;
3418 #endif
3419
3420         DEFVAR_INT("emacs-priority", &emacs_priority /*
3421 Priority for SXEmacs to run at.
3422 This value is effective only if set before SXEmacs is dumped,
3423 and only if the SXEmacs executable is installed with setuid to permit
3424 it to change priority.  (SXEmacs sets its uid back to the real uid.)
3425 Currently, you need to define SET_EMACS_PRIORITY in `config.h'
3426 before you compile SXEmacs, to enable the code for this feature.
3427                                                      */ );
3428         emacs_priority = 0;
3429
3430         DEFVAR_CONST_LISP("internal-error-checking", &Vinternal_error_checking /*
3431 Internal error checking built-in into this instance of SXEmacs.
3432 This is a list of symbols, initialized at build-time.  Legal symbols
3433 are:
3434    extents     - check extents prior to each extent change;
3435    typecheck   - check types strictly, aborting in case of error;
3436    malloc      - check operation of malloc;
3437    gc          - check garbage collection;
3438    bufpos      - check buffer positions.
3439    quick-build - user has requested the "quick-build" configure option.
3440                                                                                */ );
3441         Vinternal_error_checking = Qnil;
3442 #ifdef ERROR_CHECK_EXTENTS
3443         Vinternal_error_checking = Fcons(intern("extents"),
3444                                          Vinternal_error_checking);
3445 #endif
3446 #ifdef ERROR_CHECK_TYPECHECK
3447         Vinternal_error_checking = Fcons(intern("typecheck"),
3448                                          Vinternal_error_checking);
3449 #endif
3450 #ifdef ERROR_CHECK_MALLOC
3451         Vinternal_error_checking = Fcons(intern("malloc"),
3452                                          Vinternal_error_checking);
3453 #endif
3454 #ifdef ERROR_CHECK_GC
3455         Vinternal_error_checking = Fcons(intern("gc"),
3456                                          Vinternal_error_checking);
3457 #endif
3458 #ifdef ERROR_CHECK_BUFPOS
3459         Vinternal_error_checking = Fcons(intern("bufpos"),
3460                                          Vinternal_error_checking);
3461 #endif
3462 #ifdef QUICK_BUILD
3463         Vinternal_error_checking = Fcons(intern("quick-build"),
3464                                          Vinternal_error_checking);
3465 #endif
3466
3467         DEFVAR_CONST_LISP("mail-lock-methods", &Vmail_lock_methods /*
3468 Mail spool locking methods supported by this instance of SXEmacs.
3469 This is a list of symbols.  Each of the symbols is one of the
3470 following: dot, lockf, flock, locking, mmdf.
3471                                                                    */ );
3472         {
3473                 Vmail_lock_methods = Qnil;
3474                 Vmail_lock_methods = Fcons(intern("dot"), Vmail_lock_methods);
3475 #ifdef HAVE_LOCKF
3476                 Vmail_lock_methods = Fcons(intern("lockf"), Vmail_lock_methods);
3477 #endif
3478 #ifdef HAVE_FLOCK
3479                 Vmail_lock_methods = Fcons(intern("flock"), Vmail_lock_methods);
3480 #endif
3481 #ifdef HAVE_MMDF
3482                 Vmail_lock_methods = Fcons(intern("mmdf"), Vmail_lock_methods);
3483 #endif
3484 #ifdef HAVE_LOCKING
3485                 Vmail_lock_methods =
3486                     Fcons(intern("locking"), Vmail_lock_methods);
3487 #endif
3488         }
3489
3490         DEFVAR_CONST_LISP("configure-mail-lock-method", &Vconfigure_mail_lock_method /*
3491 Mail spool locking method suggested by configure.  This is one
3492 of the symbols in MAIL-LOCK-METHODS.
3493                                                                                      */ );
3494         {
3495 #if defined(MAIL_LOCK_FLOCK) && defined(HAVE_FLOCK)
3496                 Vconfigure_mail_lock_method = intern("flock");
3497 #elif defined(MAIL_LOCK_LOCKF) && defined(HAVE_LOCKF)
3498                 Vconfigure_mail_lock_method = intern("lockf");
3499 #elif defined(MAIL_LOCK_MMDF) && defined(HAVE_MMDF)
3500                 Vconfigure_mail_lock_method = intern("mmdf");
3501 #elif defined(MAIL_LOCK_LOCKING) && defined(HAVE_LOCKING)
3502                 Vconfigure_mail_lock_method = intern("locking");
3503 #else
3504                 Vconfigure_mail_lock_method = intern("dot");
3505 #endif
3506         }
3507
3508         DEFVAR_LISP("path-separator", &Vpath_separator /*
3509 The directory separator in search paths, as a string.
3510                                                        */ );
3511         {
3512                 char c = SEPCHAR;
3513                 Vpath_separator = make_string((Bufbyte *) & c, 1);
3514         }
3515 }
3516
3517 void complex_vars_of_emacs(void)
3518 {
3519         /* This is all related to path searching. */
3520
3521         DEFVAR_LISP("emacs-program-name", &Vemacs_program_name /*
3522 *Name of the Emacs variant.
3523 For example, this may be \"sxemacs\" or \"infodock\".
3524 This is mainly meant for use in path searching.
3525                                                                */ );
3526         Vemacs_program_name = build_string((char *)PATH_PROGNAME);
3527
3528         DEFVAR_LISP("emacs-program-version", &Vemacs_program_version /*
3529 *Version of the Emacs variant.
3530 This typically has the form NN.NN-bNN.
3531 This is mainly meant for use in path searching.
3532                                                                      */ );
3533         Vemacs_program_version = build_string((char *)PATH_VERSION);
3534
3535         DEFVAR_LISP("exec-path", &Vexec_path /*
3536 *List of directories to search programs to run in subprocesses.
3537 Each element is a string (directory name) or nil (try default directory).
3538                                              */ );
3539         Vexec_path = Qnil;
3540
3541         DEFVAR_LISP("exec-directory", &Vexec_directory /*
3542 *Directory of architecture-dependent files that come with SXEmacs,
3543 especially executable programs intended for SXEmacs to invoke.
3544                                                        */ );
3545         Vexec_directory = Qnil;
3546
3547         DEFVAR_LISP("configure-exec-directory", &Vconfigure_exec_directory /*
3548 For internal use by the build procedure only.
3549 configure's idea of what `exec-directory' will be.
3550                                                                            */ );
3551 #ifdef PATH_EXEC
3552         Vconfigure_exec_directory = Ffile_name_as_directory
3553             (build_string((char *)PATH_EXEC));
3554 #else
3555         Vconfigure_exec_directory = Qnil;
3556 #endif
3557
3558         DEFVAR_LISP("lisp-directory", &Vlisp_directory /*
3559 *Directory of core Lisp files that come with SXEmacs.
3560 */ );
3561         Vlisp_directory = Qnil;
3562
3563         DEFVAR_LISP("configure-lisp-directory", &Vconfigure_lisp_directory /*
3564 For internal use by the build procedure only.
3565 configure's idea of what `lisp-directory' will be.
3566                                                                            */ );
3567 #ifdef PATH_LOADSEARCH
3568         Vconfigure_lisp_directory = Ffile_name_as_directory
3569             (build_string((char *)PATH_LOADSEARCH));
3570 #else
3571         Vconfigure_lisp_directory = Qnil;
3572 #endif
3573
3574         DEFVAR_LISP("mule-lisp-directory", &Vmule_lisp_directory /*
3575 *Directory of Mule Lisp files that come with SXEmacs.
3576 */ );
3577         Vmule_lisp_directory = Qnil;
3578
3579         DEFVAR_LISP("configure-mule-lisp-directory", &Vconfigure_mule_lisp_directory /*
3580 For internal use by the build procedure only.
3581 configure's idea of what `mule-lisp-directory' will be.
3582                                                                                      */ );
3583 #ifdef PATH_MULELOADSEARCH
3584         Vconfigure_mule_lisp_directory = Ffile_name_as_directory
3585             (build_string((char *)PATH_MULELOADSEARCH));
3586 #else
3587         Vconfigure_mule_lisp_directory = Qnil;
3588 #endif
3589
3590         DEFVAR_LISP("module-directory", &Vmodule_directory /*
3591 *Directory of core dynamic modules that come with SXEmacs.
3592 */ );
3593         Vmodule_directory = Qnil;
3594
3595         DEFVAR_LISP("configure-module-directory", &Vconfigure_module_directory /*
3596 For internal use by the build procedure only.
3597 configure's idea of what `module-directory' will be.
3598                                                                                */ );
3599 #ifdef PATH_MODULESEARCH
3600         Vconfigure_module_directory = Ffile_name_as_directory
3601             (build_string((char *)PATH_MODULESEARCH));
3602 #else
3603         Vconfigure_module_directory = Qnil;
3604 #endif
3605
3606         DEFVAR_LISP("configure-package-path", &Vconfigure_package_path /*
3607 For internal use by the build procedure only.
3608 configure's idea of what the package path will be.
3609                                                                        */ );
3610 #ifdef PATH_PACKAGEPATH
3611         Vconfigure_package_path = decode_path(PATH_PACKAGEPATH);
3612 #else
3613         Vconfigure_package_path = Qnil;
3614 #endif
3615
3616         DEFVAR_LISP("data-directory", &Vdata_directory /*
3617 *Directory of architecture-independent files that come with SXEmacs,
3618 intended for SXEmacs to use.
3619 Use of this variable in new code is almost never correct.  See the
3620 functions `locate-data-file' and `locate-data-directory' and the variable
3621 `data-directory-list'.
3622                                                        */ );
3623         Vdata_directory = Qnil;
3624
3625         DEFVAR_LISP("configure-data-directory", &Vconfigure_data_directory /*
3626 For internal use by the build procedure only.
3627 configure's idea of what `data-directory' will be.
3628                                                                            */ );
3629 #ifdef PATH_DATA
3630         Vconfigure_data_directory = Ffile_name_as_directory
3631             (build_string((char *)PATH_DATA));
3632 #else
3633         Vconfigure_data_directory = Qnil;
3634 #endif
3635
3636         DEFVAR_LISP("data-directory-list", &Vdata_directory_list /*
3637 *List of directories of architecture-independent files that come with SXEmacs
3638 or were installed as packages, and are intended for SXEmacs to use.
3639                                                                  */ );
3640         Vdata_directory_list = Qnil;
3641
3642         DEFVAR_LISP("site-module-directory", &Vsite_module_directory /*
3643 *Directory of site-specific loadable modules that come with SXEmacs.
3644 */ );
3645         Vsite_module_directory = Qnil;
3646
3647         DEFVAR_LISP("configure-site-module-directory", &Vconfigure_site_module_directory /*
3648 For internal use by the build procedure only.
3649 configure's idea of what `site-directory' will be.
3650                                                                                          */ );
3651 #ifdef PATH_SITE_MODULES
3652         Vconfigure_site_module_directory = Ffile_name_as_directory
3653             (build_string((char *)PATH_SITE_MODULES));
3654 #else
3655         Vconfigure_site_module_directory = Qnil;
3656 #endif
3657
3658         DEFVAR_LISP("doc-directory", &Vdoc_directory /*
3659 *Directory containing the DOC file that comes with SXEmacs.
3660 This is usually the same as `exec-directory'.
3661                                                      */ );
3662         Vdoc_directory = Qnil;
3663
3664         DEFVAR_LISP("configure-doc-directory", &Vconfigure_doc_directory /*
3665 For internal use by the build procedure only.
3666 configure's idea of what `doc-directory' will be.
3667                                                                          */ );
3668 #ifdef PATH_DOC
3669         Vconfigure_doc_directory = Ffile_name_as_directory
3670             (build_string((char *)PATH_DOC));
3671 #else
3672         Vconfigure_doc_directory = Qnil;
3673 #endif
3674
3675         DEFVAR_LISP("configure-exec-prefix-directory", &Vconfigure_exec_prefix_directory /*
3676 For internal use by the build procedure only.
3677 configure's idea of what `exec-prefix-directory' will be.
3678                                                                                          */ );
3679 #ifdef PATH_EXEC_PREFIX
3680         Vconfigure_exec_prefix_directory = Ffile_name_as_directory
3681             (build_string((char *)PATH_EXEC_PREFIX));
3682 #else
3683         Vconfigure_exec_prefix_directory = Qnil;
3684 #endif
3685
3686         DEFVAR_LISP("configure-prefix-directory", &Vconfigure_prefix_directory /*
3687 For internal use by the build procedure only.
3688 configure's idea of what `prefix-directory' will be.
3689                                                                                */ );
3690 #ifdef PATH_PREFIX
3691         Vconfigure_prefix_directory = Ffile_name_as_directory
3692             (build_string((char *)PATH_PREFIX));
3693 #else
3694         Vconfigure_prefix_directory = Qnil;
3695 #endif
3696
3697         DEFVAR_LISP("configure-info-directory", &Vconfigure_info_directory /*
3698 For internal use by the build procedure only.
3699 This is the name of the directory in which the build procedure installed
3700 Emacs's info files; the default value for Info-default-directory-list
3701 includes this.
3702                                                                            */ );
3703 #ifdef PATH_INFO
3704         Vconfigure_info_directory =
3705             Ffile_name_as_directory(build_string(PATH_INFO));
3706 #else
3707         Vconfigure_info_directory = Qnil;
3708 #endif
3709
3710         DEFVAR_LISP("configure-info-path", &Vconfigure_info_path /*
3711 The configured initial path for info documentation.
3712                                                                  */ );
3713 #ifdef PATH_INFOPATH
3714         Vconfigure_info_path = decode_path(PATH_INFOPATH);
3715 #else
3716         Vconfigure_info_path = Qnil;
3717 #endif
3718 }
3719
3720 #if defined(__sgi) && !defined(PDUMP)
3721 /* This is so tremendously ugly I'd puke. But then, it works.
3722  * The target is to override the static constructor from the
3723  * libiflPNG.so library which is masquerading as libz, and
3724  * cores on us when re-started from the dumped executable.
3725  * This will have to go for 21.1  -- OG.
3726  */
3727 void __sti__iflPNGFile_c___(void);
3728 void __sti__iflPNGFile_c___(void)
3729 {
3730 }
3731
3732 #endif