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