comparison src/emacs.c @ 442:abe6d1db359e r21-2-36

Import from CVS: tag r21-2-36
author cvs
date Mon, 13 Aug 2007 11:35:02 +0200
parents 8de8e3f6228a
children 576fb035e263
comparison
equal deleted inserted replaced
441:72a7cfa4a488 442:abe6d1db359e
1 /* XEmacs -- Fully extensible Emacs, running on Unix and other platforms. 1 /* XEmacs -- Fully extensible Emacs, running on Unix and other platforms.
2 Copyright (C) 1985, 1986, 1987, 1992, 1993, 1994 2 Copyright (C) 1985, 1986, 1987, 1992, 1993, 1994
3 Free Software Foundation, Inc. 3 Free Software Foundation, Inc.
4 Copyright (C) 1995 Sun Microsystems, Inc. 4 Copyright (C) 1995 Sun Microsystems, Inc.
5 Copyright (C) 2000 Ben Wing.
5 6
6 This file is part of XEmacs. 7 This file is part of XEmacs.
7 8
8 XEmacs is free software; you can redistribute it and/or modify it 9 XEmacs is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by the 10 under the terms of the GNU General Public License as published by the
19 along with XEmacs; see the file COPYING. If not, write to 20 along with XEmacs; see the file COPYING. If not, write to
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 21 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */ 22 Boston, MA 02111-1307, USA. */
22 23
23 /* Synched up with: Mule 2.0, FSF 19.28. */ 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 */
24 160
25 /* Note: It is necessary to specify <config.h> and not "config.h" in 161 /* Note: It is necessary to specify <config.h> and not "config.h" in
26 order for the --srcdir type of compilation to work properly. 162 order for the --srcdir type of compilation to work properly.
27 Otherwise the config.h from the srcdir, rather than the one from 163 Otherwise the config.h from the srcdir, rather than the one from
28 the build dir, will be used. */ 164 the build dir, will be used. */
42 #include "syssignal.h" /* Always include before systty.h */ 178 #include "syssignal.h" /* Always include before systty.h */
43 #include "systty.h" 179 #include "systty.h"
44 #include "sysfile.h" 180 #include "sysfile.h"
45 #include "systime.h" 181 #include "systime.h"
46 182
183 #ifdef PDUMP
184 #include "dump-id.h"
185 #include "dumper.h"
186 #endif
187
188 #ifndef SEPCHAR
189 #define SEPCHAR ':'
190 #endif
191
47 #ifdef QUANTIFY 192 #ifdef QUANTIFY
48 #include <quantify.h> 193 #include <quantify.h>
49 #endif 194 #endif
50 195
51 #ifdef HAVE_SHLIB 196 #ifdef HAVE_SHLIB
56 (defined (I18N2) || defined (I18N3) || defined (I18N4)) 201 (defined (I18N2) || defined (I18N3) || defined (I18N4))
57 #include <locale.h> 202 #include <locale.h>
58 #endif 203 #endif
59 204
60 #ifdef TOOLTALK 205 #ifdef TOOLTALK
61 #include TT_C_H_PATH 206 #include TT_C_H_FILE
62 #endif 207 #endif
63 208
64 #if defined (WINDOWSNT) 209 #if defined (WIN32_NATIVE)
65 #include <windows.h> 210 #include "nt.h"
66 #endif 211 #endif
67 212
68 /* For PATH_EXEC */ 213 /* For PATH_EXEC */
69 #include <paths.h> 214 #include <paths.h>
70 215
71 #ifdef HEAP_IN_DATA 216 #if defined (HEAP_IN_DATA) && !defined(PDUMP)
72 void report_sheap_usage (int die_if_pure_storage_exceeded); 217 void report_sheap_usage (int die_if_pure_storage_exceeded);
73 #endif 218 #endif
74 219
75 #if !defined (SYSTEM_MALLOC) && !defined (DOUG_LEA_MALLOC) 220 #if !defined (SYSTEM_MALLOC) && !defined (DOUG_LEA_MALLOC)
76 extern void *(*__malloc_hook)(size_t); 221 extern void *(*__malloc_hook)(size_t);
159 /* If nonzero, set XEmacs to run at this priority. This is also used 304 /* If nonzero, set XEmacs to run at this priority. This is also used
160 in child_setup and sys_suspend to make sure subshells run at normal 305 in child_setup and sys_suspend to make sure subshells run at normal
161 priority. */ 306 priority. */
162 int emacs_priority; 307 int emacs_priority;
163 308
164 /* If non-zero a filter or a sentinel is running. Tested to save the match 309 /* Some FSF junk with running_asynch_code, to preserve the match
165 data on the first attempt to change it inside asynchronous code. */ 310 data. Not necessary because we don't call process filters
311 asynchronously (i.e. from within QUIT). */
312 /* #### Delete this when merging the rest of my code */
166 int running_asynch_code; 313 int running_asynch_code;
167 314
168 /* If non-zero, a window-system was specified on the command line. */ 315 /* If non-zero, a window-system was specified on the command line. */
169 int display_arg; 316 int display_arg;
170 317
171 /* Type of display specified. We cannot use a Lisp symbol here because 318 /* Type of display specified. We cannot use a Lisp symbol here because
172 Lisp symbols may not initialized at the time that we set this 319 Lisp symbols may not initialized at the time that we set this
173 variable. */ 320 variable. */
174 CONST char *display_use; 321 const char *display_use;
175 322
176 /* If non-zero, then the early error handler will only print the error 323 /* If non-zero, then the early error handler will only print the error
177 message and exit. */ 324 message and exit. */
178 int suppress_early_error_handler_backtrace; 325 int suppress_early_error_handler_backtrace;
179 326
189 #endif 336 #endif
190 337
191 /* Number of bytes of writable memory we can expect to be able to get */ 338 /* Number of bytes of writable memory we can expect to be able to get */
192 unsigned int lim_data; 339 unsigned int lim_data;
193 340
341 /* WARNING!
342
343 Some LISP-visible command-line options are set by XEmacs _before_ the
344 data is dumped in building a --pdump XEmacs, but used _after_ it is
345 restored in normal operation. Thus the restored values overwrite the
346 values XEmacs is getting at run-time. Such variables must be saved
347 before loading the dumpfile, and restored afterward.
348
349 This is done immediately before and after pdump_load() in main_1().
350 See that function for the current list of protected variables.
351
352 Note that if the variable is never DEFVAR'd, saving/restoring is not
353 needed.
354 */
355
194 /* Nonzero means running XEmacs without interactive terminal. */ 356 /* Nonzero means running XEmacs without interactive terminal. */
195 357
196 int noninteractive; 358 int noninteractive;
197 359
198 /* Value of Lisp variable `noninteractive'. 360 /* Value of Lisp variable `noninteractive'.
199 Normally same as C variable `noninteractive' 361 Normally same as C variable `noninteractive'
200 but nothing terrible happens if user sets this one. */ 362 but nothing terrible happens if user sets this one.
363
364 Shadowed from the pdumper by `noninteractive'. */
201 365
202 int noninteractive1; 366 int noninteractive1;
203 367
204 /* Nonzero means don't perform site-lisp searches at startup */ 368 /* Nonzero means don't perform site-lisp searches at startup */
205 int inhibit_site_lisp; 369 int inhibit_site_lisp;
211 int inhibit_early_packages; 375 int inhibit_early_packages;
212 376
213 /* Nonzero means don't load package autoloads at startup */ 377 /* Nonzero means don't load package autoloads at startup */
214 int inhibit_autoloads; 378 int inhibit_autoloads;
215 379
380 /* Nonzero means don't load the dump file (ignored if not PDUMP) */
381
382 int nodumpfile;
383
216 /* Nonzero means print debug information about path searching */ 384 /* Nonzero means print debug information about path searching */
217 int debug_paths; 385 int debug_paths;
218 386
219 /* Save argv and argc. */ 387 /* Save argv and argc. */
220 static char **initial_argv; 388 static Extbyte **initial_argv;
221 static int initial_argc; 389 static int initial_argc;
222 390
223 static void sort_args (int argc, char **argv); 391 static void sort_args (int argc, char **argv);
224 392
225 Lisp_Object Qkill_emacs_hook; 393 Lisp_Object Qkill_emacs_hook;
226 Lisp_Object Qsave_buffers_kill_emacs; 394 Lisp_Object Qsave_buffers_kill_emacs;
227 395
228 extern Lisp_Object Vlisp_EXEC_SUFFIXES; 396 extern Lisp_Object Vlisp_EXEC_SUFFIXES;
229 397
230 398
231 /* Signal code for the fatal signal that was received */ 399
232 static int fatal_error_code; 400 /* Ben's capsule summary about expected and unexpected exits from XEmacs.
233 401
234 /* Nonzero if handling a fatal error already */ 402 Expected exits occur when the user directs XEmacs to exit, for example
235 static int fatal_error_in_progress; 403 by pressing the close button on the only frame in XEmacs, or by typing
236 404 C-x C-c. This runs `save-buffers-kill-emacs', which saves any necessary
237 static void shut_down_emacs (int sig, Lisp_Object stuff); 405 buffers, and then exits using the primitive `kill-emacs'.
406
407 However, unexpected exits occur in a few different ways:
408
409 -- a memory access violation or other hardware-generated exception
410 occurs. This is the worst possible problem to deal with, because
411 the fault can occur while XEmacs is in any state whatsoever, even
412 quite unstable ones. As a result, we need to be *extremely* careful
413 what we do.
414 -- we are using one X display (or if we've used more, we've closed the
415 others already), and some hardware or other problem happens and
416 suddenly we've lost our connection to the display. In this situation,
417 things are not so dire as in the last one; our code itself isn't
418 trashed, so we can continue execution as normal, after having set
419 things up so that we can exit at the appropriate time. Our exit
420 still needs to be of the emergency nature; we have no displays, so
421 any attempts to use them will fail. We simply want to auto-save
422 (the single most important thing to do during shut-down), do minimal
423 cleanup of stuff that has an independent existence outside of XEmacs,
424 and exit.
425
426 Currently, both unexpected exit scenarios described above set
427 preparing_for_armageddon to indicate that nonessential and possibly
428 dangerous things should not be done, specifically:
429
430 -- no garbage collection.
431 -- no hooks are run.
432 -- no messages of any sort from autosaving.
433 -- autosaving tries harder, ignoring certain failures.
434 -- existing frames are not deleted.
435
436 (Also, all places that set preparing_for_armageddon also
437 set dont_check_for_quit. This happens separately because it's
438 also necessary to set other variables to make absolutely sure
439 no quitting happens.)
440
441 In the first scenario above (the access violation), we also set
442 fatal_error_in_progress. This causes more things to not happen:
443
444 -- assertion failures do not abort.
445 -- printing code does not do code conversion or gettext when
446 printing to stdout/stderr.
447 */
448
449 /* Nonzero if handling a fatal error already. */
450 int fatal_error_in_progress;
451
452 /* Non-nil means we're going down, so we better not run any hooks
453 or do other non-essential stuff. */
454 int preparing_for_armageddon;
455
456
457 static JMP_BUF run_temacs_catch;
458
459 static int run_temacs_argc;
460 static char **run_temacs_argv;
461 static char *run_temacs_args;
462 static size_t run_temacs_argv_size;
463 static size_t run_temacs_args_size;
464
465 static void shut_down_emacs (int sig, Lisp_Object stuff, int no_auto_save);
466
467 static void
468 ensure_no_quitting_from_now_on (void)
469 {
470 /* make sure no quitting from now on!! */
471 dont_check_for_quit = 1;
472 Vinhibit_quit = Qt;
473 Vquit_flag = Qnil;
474 }
238 475
239 /* Handle bus errors, illegal instruction, etc. */ 476 /* Handle bus errors, illegal instruction, etc. */
240 SIGTYPE 477 SIGTYPE
241 fatal_error_signal (int sig) 478 fatal_error_signal (int sig)
242 { 479 {
243 fatal_error_code = sig; 480 fatal_error_in_progress++;
244 signal (sig, SIG_DFL); 481 preparing_for_armageddon = 1;
482
483 ensure_no_quitting_from_now_on ();
484
245 /* Unblock the signal so that if the same signal gets sent in the 485 /* Unblock the signal so that if the same signal gets sent in the
246 code below, we avoid a deadlock. */ 486 code below, we avoid a deadlock. */
247 EMACS_UNBLOCK_SIGNAL (fatal_error_code); 487 EMACS_UNBLOCK_SIGNAL (sig);
248 488
489 /* Only try auto-saving first time through. If we crash in auto-saving,
490 don't do it again. */
491 if (fatal_error_in_progress == 1)
492 {
493 Fdo_auto_save (Qt, Qnil); /* do this before anything hazardous */
494 /* Do this so that the variable has the same value of 2 regardless of
495 whether we made it through auto-saving correctly. */
496 fatal_error_in_progress++;
497 }
498 else if (fatal_error_in_progress == 2)
499 stderr_out ("WARNING: Unable to auto-save your files properly.\n"
500 "Some or all may in fact have been auto-saved.\n"
501 "\n");
502
503 /* Now, reset our signal handler, so the next time, we just die.
504 Don't do this before auto-saving. */
505 signal (sig, SIG_DFL);
506
507 /* Keep in mind that there's more than one signal that we can crash
508 on. */
249 /* If fatal error occurs in code below, avoid infinite recursion. */ 509 /* If fatal error occurs in code below, avoid infinite recursion. */
250 if (! fatal_error_in_progress) 510 if (fatal_error_in_progress <= 2)
251 { 511 {
252 fatal_error_in_progress = dont_check_for_quit = 1; 512 shut_down_emacs (sig, Qnil, 1);
253 shut_down_emacs (sig, Qnil);
254 stderr_out ("\nLisp backtrace follows:\n\n"); 513 stderr_out ("\nLisp backtrace follows:\n\n");
255 Fbacktrace (Qexternal_debugging_output, Qt); 514 Fbacktrace (Qexternal_debugging_output, Qt);
256 # if 0 /* This is evil, rarely useful, and causes grief in some cases. */ 515 # if 0 /* This is evil, rarely useful, and causes grief in some cases. */
257 /* Check for Sun-style stack printing via /proc */ 516 /* Check for Sun-style stack printing via /proc */
258 { 517 {
259 CONST char *pstack = "/usr/proc/bin/pstack"; 518 const char *pstack = "/usr/proc/bin/pstack";
260 if (access (pstack, X_OK) == 0) 519 if (access (pstack, X_OK) == 0)
261 { 520 {
262 char buf[100]; 521 char buf[100];
263 stderr_out ("\nC backtrace follows:\n" 522 stderr_out ("\nC backtrace follows:\n"
264 "(A real debugger may provide better information)\n\n"); 523 "(A real debugger may provide better information)\n\n");
267 } 526 }
268 } 527 }
269 # endif 528 # endif
270 } 529 }
271 /* Signal the same code; this time it will really be fatal. */ 530 /* Signal the same code; this time it will really be fatal. */
272 kill (getpid (), fatal_error_code); 531 kill (getpid (), sig);
273 SIGRETURN; 532 SIGRETURN;
274 } 533 }
534
535 #ifdef _MSC_VER
536
537 static DWORD
538 mswindows_handle_hardware_exceptions (DWORD code)
539 {
540 if (code != STATUS_ACCESS_VIOLATION && code != STATUS_ILLEGAL_INSTRUCTION
541 && code != STATUS_PRIVILEGED_INSTRUCTION
542 && code != STATUS_DATATYPE_MISALIGNMENT)
543 return EXCEPTION_CONTINUE_SEARCH;
544
545 /* I don't know if this filter is still wrapped in the outer __try, but
546 it doesn't hurt to have another one. --ben
547 And it lets us control more exactly what we really want to do in such
548 a situation. */
549 __try
550 {
551 fatal_error_in_progress++;
552 preparing_for_armageddon = 1;
553
554 ensure_no_quitting_from_now_on ();
555
556 /* Only try auto-saving first time through. If we crash in auto-saving,
557 don't do it again. */
558 if (fatal_error_in_progress == 1)
559 {
560 Fdo_auto_save (Qt, Qnil); /* do this before anything hazardous */
561 /* Do this so that the variable has the same value of 2 regardless of
562 whether we made it through auto-saving correctly. */
563 fatal_error_in_progress++;
564 }
565 else if (fatal_error_in_progress == 2)
566 stderr_out ("WARNING: Unable to auto-save your files properly.\n"
567 "Some or all may in fact have been auto-saved.\n"
568 "\n");
569
570 /* If fatal error occurs in code below, avoid infinite recursion. */
571 if (fatal_error_in_progress <= 2)
572 {
573 shut_down_emacs (-1, Qnil, 1);
574 stderr_out ("\nLisp backtrace follows:\n\n");
575 Fbacktrace (Qexternal_debugging_output, Qt);
576 }
577 }
578 /* VC++ documentation says that
579 GetExceptionCode() cannot be called inside the filter itself. */
580
581 /* __except (mswindows_handle_hardware_exceptions (GetExceptionCode ())) {}
582
583 The line above is original. Unfortunately, when an error is tripped
584 inside of the handler (e.g. during Fbacktrace()), and the handler for
585 the handler is invoked, it correctly notices that something is amiss
586 and it should just return -- but it returns EXCEPTION_CONTINUE_SEARCH,
587 which causes the debugger to be invoked debugging the handler code in
588 this function -- and WITH THE STACK UNWOUND so that you see main()
589 calling mswindows_handle_hardware_exceptions(), calling Fbacktrace(),
590 and a crash a couple of frames in -- AND NO SIGN OF THE ORIGINAL CRASH!
591
592 There's some real weirdness going on in the stack handling -- unlike
593 in Unix, where further crashes just keep adding to the stack, it seems
594 that under the structured-exception-handling, the stack can actually
595 bounce back and forth between the full stack at the location of the
596 exception and the unwound stack at the place where the __try clause was
597 established. I don't completely understand it. What I do know is that
598 returning EXCEPTION_EXECUTE_HANDLER on nested crash has the effect of
599 aborting execution of the handler and going back to the outer filter
600 function, which returns EXCEPTION_CONTINUE_SEARCH and everything is
601 hunky-dorey -- your debugger sees a crash at the right location with
602 the right stack.
603
604 I'm leaving in the trickier Unix-like code in the handler; someone who
605 understands better than me how the stack works in these handlers could
606 fix it up more. As it is, it works pretty well, so I'm not likely to
607 touch it more. --ben
608 */
609
610 __except (EXCEPTION_EXECUTE_HANDLER) {}
611
612
613 /* pretend we didn't handle this, so that the debugger is invoked and/or
614 the normal GPF box appears. */
615 return EXCEPTION_CONTINUE_SEARCH;
616 }
617
618 #endif /* _MSC_VER */
619
275 620
276
277 DOESNT_RETURN
278 fatal (CONST char *fmt, ...)
279 {
280 va_list args;
281 va_start (args, fmt);
282
283 fprintf (stderr, "\nXEmacs: ");
284 vfprintf (stderr, GETTEXT (fmt), args);
285 fprintf (stderr, "\n");
286
287 va_end (args);
288 fflush (stderr);
289 exit (1);
290 }
291
292 /* #### The following two functions should be replaced with
293 calls to emacs_doprnt_*() functions, with STREAM set to send out
294 to stdout or stderr. This is the only way to ensure that
295 I18N3 works properly (many implementations of the *printf()
296 functions, including the ones included in glibc, do not implement
297 the %###$ argument-positioning syntax). */
298
299 /* exactly equivalent to fprintf (stderr, fmt, ...) except that it calls
300 GETTEXT on the format string. */
301
302 int
303 stderr_out (CONST char *fmt, ...)
304 {
305 int retval;
306 va_list args;
307 va_start (args, fmt);
308
309 retval = vfprintf (stderr, GETTEXT (fmt), args);
310
311 va_end (args);
312 /* fflush (stderr); */
313 return retval;
314 }
315
316 /* exactly equivalent to fprintf (stdout, fmt, ...) except that it calls
317 GETTEXT on the format string. */
318
319 int
320 stdout_out (CONST char *fmt, ...)
321 {
322 int retval;
323 va_list args;
324 va_start (args, fmt);
325
326 retval = vfprintf (stdout, GETTEXT (fmt), args);
327
328 va_end (args);
329 return retval;
330 }
331 621
332 #ifdef SIGDANGER 622 #ifdef SIGDANGER
333 623
334 /* Handler for SIGDANGER. */ 624 /* Handler for SIGDANGER. */
335 SIGTYPE 625 SIGTYPE
348 #endif /* SIGDANGER */ 638 #endif /* SIGDANGER */
349 639
350 /* Code for dealing with Lisp access to the Unix command line */ 640 /* Code for dealing with Lisp access to the Unix command line */
351 641
352 static Lisp_Object 642 static Lisp_Object
353 make_arg_list_1 (int argc, char **argv, int skip_args) 643 make_arg_list_1 (int argc, Extbyte **argv, int skip_args)
354 { 644 {
355 Lisp_Object result = Qnil; 645 Lisp_Object result = Qnil;
356 REGISTER int i; 646 REGISTER int i;
357 647
358 for (i = argc - 1; i >= 0; i--) 648 for (i = argc - 1; i >= 0; i--)
359 { 649 {
360 if (i == 0 || i > skip_args) 650 if (i == 0 || i > skip_args)
361 { 651 {
362 #ifdef WINDOWSNT 652 #ifdef WIN32_NATIVE
363 if (i == 0) 653 if (i == 0)
364 { 654 {
365 /* Do not trust to what crt0 has stuffed into argv[0] */ 655 /* Do not trust to what crt0 has stuffed into argv[0] */
366 char full_exe_path [MAX_PATH]; 656 char full_exe_path[MAX_PATH];
657 Lisp_Object fullpath;
658
367 GetModuleFileName (NULL, full_exe_path, MAX_PATH); 659 GetModuleFileName (NULL, full_exe_path, MAX_PATH);
368 result = Fcons (build_ext_string (full_exe_path, Qfile_name), 660 fullpath = build_ext_string (full_exe_path, Qmswindows_tstr);
369 result); 661 result = Fcons (fullpath, result);
370 #if defined(HAVE_SHLIB) 662 #if defined(HAVE_SHLIB)
371 (void)dll_init(full_exe_path); 663 {
664 Extbyte *fullpathext;
665
666 LISP_STRING_TO_EXTERNAL (fullpath, fullpathext,
667 Qdll_filename_encoding);
668 (void) dll_init (fullpathext);
669 }
372 #endif 670 #endif
373 } 671 }
374 else 672 else
375 #endif 673 #endif
376 result = Fcons (build_ext_string (argv [i], Qfile_name), 674 result = Fcons (build_ext_string (argv[i],
675 Qcommand_argument_encoding),
377 result); 676 result);
378 } 677 }
379 } 678 }
380 return result; 679 return result;
381 } 680 }
382 681
383 Lisp_Object 682 Lisp_Object
384 make_arg_list (int argc, char **argv) 683 make_arg_list (int argc, Extbyte **argv)
385 { 684 {
386 return make_arg_list_1 (argc, argv, 0); 685 return make_arg_list_1 (argc, argv, 0);
387 } 686 }
388 687
389 /* Calling functions are also responsible for calling free_argc_argv 688 /* Calling functions are also responsible for calling free_argc_argv
390 when they are done with the generated list. */ 689 when they are done with the generated list. */
391 void 690 void
392 make_argc_argv (Lisp_Object argv_list, int *argc, char ***argv) 691 make_argc_argv (Lisp_Object argv_list, int *argc, Extbyte ***argv)
393 { 692 {
394 Lisp_Object next; 693 Lisp_Object next;
395 int n = XINT (Flength (argv_list)); 694 int n = XINT (Flength (argv_list));
396 REGISTER int i; 695 REGISTER int i;
397 *argv = (char**) xmalloc ((n+1) * sizeof (char*)); 696 *argv = (Extbyte**) xmalloc ((n+1) * sizeof (Extbyte*));
398 697
399 for (i = 0, next = argv_list; i < n; i++, next = XCDR (next)) 698 for (i = 0, next = argv_list; i < n; i++, next = XCDR (next))
400 { 699 {
401 CONST char *temp; 700 const Extbyte *temp;
402 CHECK_STRING (XCAR (next)); 701 CHECK_STRING (XCAR (next));
403 702
404 TO_EXTERNAL_FORMAT (LISP_STRING, XCAR (next), 703 LISP_STRING_TO_EXTERNAL (XCAR (next), temp, Qcommand_argument_encoding);
405 C_STRING_ALLOCA, temp,
406 Qnative);
407 (*argv) [i] = xstrdup (temp); 704 (*argv) [i] = xstrdup (temp);
408 } 705 }
409 (*argv) [n] = 0; 706 (*argv) [n] = 0;
410 *argc = i; 707 *argc = i;
411 } 708 }
412 709
413 void 710 void
414 free_argc_argv (char **argv) 711 free_argc_argv (Extbyte **argv)
415 { 712 {
416 int elt = 0; 713 int elt = 0;
417 714
418 while (argv[elt]) 715 while (argv[elt])
419 { 716 {
422 } 719 }
423 xfree (argv); 720 xfree (argv);
424 } 721 }
425 722
426 static void 723 static void
427 init_cmdargs (int argc, char **argv, int skip_args) 724 init_cmdargs (int argc, Extbyte **argv, int skip_args)
428 { 725 {
429 initial_argv = argv; 726 initial_argv = argv;
430 initial_argc = argc; 727 initial_argc = argc;
431 728
432 Vcommand_line_args = make_arg_list_1 (argc, argv, skip_args); 729 Vcommand_line_args = make_arg_list_1 (argc, argv, skip_args);
453 #ifdef I18N4 750 #ifdef I18N4
454 /* #### - don't know why I18N4 on SunOS/JLE 751 /* #### - don't know why I18N4 on SunOS/JLE
455 can't deal with this. It's a potential 752 can't deal with this. It's a potential
456 bug that needs to be looked at. */ 753 bug that needs to be looked at. */
457 # undef RUN_TIME_REMAP 754 # undef RUN_TIME_REMAP
458 #endif
459
460 #if defined (MULE) && defined (MSDOS) && defined (EMX)
461 /* Setup all of files be input/output'ed with binary translation mode. */
462 asm (" .text");
463 asm ("L_setbinmode:");
464 asm (" movl $1, __fmode_bin");
465 asm (" ret");
466 asm (" .stabs \"___CTOR_LIST__\", 23, 0, 0, L_setbinmode");
467 #endif 755 #endif
468 756
469 /* Test whether the next argument in ARGV matches SSTR or a prefix of 757 /* Test whether the next argument in ARGV matches SSTR or a prefix of
470 LSTR (at least MINLEN characters). If so, then if VALPTR is non-null 758 LSTR (at least MINLEN characters). If so, then if VALPTR is non-null
471 (the argument is supposed to have a value) store in *VALPTR either 759 (the argument is supposed to have a value) store in *VALPTR either
567 * work with dumping. But malloc_jumpstart() and malloc_freezedry() in 855 * work with dumping. But malloc_jumpstart() and malloc_freezedry() in
568 * unexnext.c are both completely undocumented, even in NS header files! 856 * unexnext.c are both completely undocumented, even in NS header files!
569 * But hey, it solves all NS related memory problems, so who's 857 * But hey, it solves all NS related memory problems, so who's
570 * complaining? */ 858 * complaining? */
571 if (initialized && malloc_jumpstart (malloc_cookie) != 0) 859 if (initialized && malloc_jumpstart (malloc_cookie) != 0)
572 fprintf (stderr, "malloc jumpstart failed!\n"); 860 stderr_out ("malloc jumpstart failed!\n");
573 #endif /* NeXT */ 861 #endif /* NeXT */
574 862
575 /* 863 /*
576 #if defined (GNU_MALLOC) && \ 864 #if defined (GNU_MALLOC) && \
577 defined (ERROR_CHECK_MALLOC) && \ 865 defined (ERROR_CHECK_MALLOC) && \
585 init_free_hook (); 873 init_free_hook ();
586 #endif 874 #endif
587 875
588 sort_args (argc, argv); 876 sort_args (argc, argv);
589 877
590 /* Map in shared memory, if we are using that. */ 878 #if defined (WIN32_NATIVE) || defined (_SCO_DS)
591 #ifdef HAVE_SHM
592 if (argmatch (argv, argc, "-nl", "--no-shared-memory", 6, NULL, &skip_args))
593 {
594 map_in_data (0);
595 /* The shared memory was just restored, which clobbered this. */
596 skip_args = 1;
597 }
598 else
599 {
600 map_in_data (1);
601 /* The shared memory was just restored, which clobbered this. */
602 skip_args = 0;
603 }
604 #endif /* HAVE_SHM */
605
606 #if (defined (MSDOS) && defined (EMX)) || defined (WIN32) || defined (_SCO_DS)
607 environ = envp; 879 environ = envp;
608 #endif 880 #endif
609 881
610 /* Record (approximately) where the stack begins. */ 882 /* Record (approximately) where the stack begins. */
611 stack_bottom = &stack_bottom_variable; 883 stack_bottom = &stack_bottom_variable;
634 if (!initialized) 906 if (!initialized)
635 /* Arrange to get warning messages as memory fills up. */ 907 /* Arrange to get warning messages as memory fills up. */
636 memory_warnings (0, malloc_warning); 908 memory_warnings (0, malloc_warning);
637 #endif /* not SYSTEM_MALLOC */ 909 #endif /* not SYSTEM_MALLOC */
638 910
639 #ifdef MSDOS
640 /* We do all file input/output as binary files. When we need to translate
641 newlines, we do that manually. */
642 _fmode = O_BINARY;
643 (stdin) ->_flag &= ~_IOTEXT;
644 (stdout)->_flag &= ~_IOTEXT;
645 (stderr)->_flag &= ~_IOTEXT;
646 #endif /* MSDOS */
647
648 #ifdef SET_EMACS_PRIORITY 911 #ifdef SET_EMACS_PRIORITY
649 if (emacs_priority != 0) 912 if (emacs_priority != 0)
650 nice (-emacs_priority); 913 nice (-emacs_priority);
651 setuid (getuid ()); 914 setuid (getuid ());
652 #endif /* SET_EMACS_PRIORITY */ 915 #endif /* SET_EMACS_PRIORITY */
658 #ifdef HAVE_WINDOW_SYSTEM 921 #ifdef HAVE_WINDOW_SYSTEM
659 inhibit_window_system = 0; 922 inhibit_window_system = 0;
660 #else 923 #else
661 inhibit_window_system = 1; 924 inhibit_window_system = 1;
662 #endif 925 #endif
926
927 /* Handle the -sd/--show-dump-id switch, which means show the hex dump_id and quit */
928 if (argmatch (argv, argc, "-sd", "--show-dump-id", 9, NULL, &skip_args))
929 {
930 #ifdef PDUMP
931 printf ("%08x\n", dump_id);
932 #else
933 printf ("*ERROR**\n");
934 #endif
935 exit (0);
936 }
663 937
664 /* Handle the -t switch, which specifies filename to use as terminal */ 938 /* Handle the -t switch, which specifies filename to use as terminal */
665 { 939 {
666 char *term; 940 char *term;
667 if (argmatch (argv, argc, "-t", "--terminal", 4, &term, &skip_args)) 941 if (argmatch (argv, argc, "-t", "--terminal", 4, &term, &skip_args))
679 #endif 953 #endif
680 stderr_out ("Using %s", term); 954 stderr_out ("Using %s", term);
681 inhibit_window_system = 1; /* -t => -nw */ 955 inhibit_window_system = 1; /* -t => -nw */
682 } 956 }
683 } 957 }
958
959 /* Handle the --no-dump-file/-nd switch, which means don't load the dump file (ignored when not using pdump) */
960 if (argmatch (argv, argc, "-nd", "--no-dump-file", 7, NULL, &skip_args))
961 {
962 nodumpfile = 1;
963 }
684 964
685 /* Handle -nw switch */ 965 /* Handle -nw switch */
686 if (argmatch (argv, argc, "-nw", "--no-windows", 6, NULL, &skip_args)) 966 if (argmatch (argv, argc, "-nw", "--no-windows", 6, NULL, &skip_args))
687 inhibit_window_system = 1; 967 inhibit_window_system = 1;
688 968
851 1131
852 purify_flag = 0; 1132 purify_flag = 0;
853 #ifdef PDUMP 1133 #ifdef PDUMP
854 if (restart) 1134 if (restart)
855 initialized = 1; 1135 initialized = 1;
856 else { 1136 else if (nodumpfile) {
857 initialized = pdump_load (); 1137 initialized = 0;
858 purify_flag = !initialized; 1138 purify_flag = 1;
1139 } else {
1140
1141 /* Keep command options from getting stomped.
1142
1143 Some LISP-visible options are changed by XEmacs _after_ the data is
1144 dumped in building a --pdump XEmacs, but _before_ it is restored in
1145 normal operation. Thus the restored values overwrite the values
1146 XEmacs is getting at run-time. Such variables must be saved here,
1147 and restored after loading the dumped data.
1148
1149 Boy, this is ugly, but how else to do it?
1150 */
1151
1152 /* noninteractive1 is protected by noninteractive, which is not
1153 LISP-visible */
1154 int inhibit_early_packages_save = inhibit_early_packages;
1155 int inhibit_autoloads_save = inhibit_autoloads;
1156 int debug_paths_save = debug_paths;
1157 #ifdef INHIBIT_SITE_LISP
1158 int inhibit_site_lisp_save = inhibit_site_lisp;
1159 #endif
1160 #ifdef INHIBIT_SITE_MODULES
1161 int inhibit_site_modules_save = inhibit_site_modules;
1162 #endif
1163
1164 initialized = pdump_load (argv[0]);
1165
1166 /* Now unstomp everything */
1167 noninteractive1 = noninteractive;
1168 inhibit_early_packages = inhibit_early_packages_save;
1169 inhibit_autoloads = inhibit_autoloads_save;
1170 debug_paths = debug_paths_save;
1171 #ifdef INHIBIT_SITE_LISP
1172 inhibit_site_lisp = inhibit_site_lisp_save;
1173 #endif
1174 #ifdef INHIBIT_SITE_MODULES
1175 inhibit_site_modules = inhibit_site_modules_save;
1176 #endif
1177
1178 if (initialized)
1179 run_temacs_argc = -1;
1180 else
1181 purify_flag = 1;
859 } 1182 }
860 #else 1183 #else
861 if (!initialized) 1184 if (!initialized)
862 purify_flag = 1; 1185 purify_flag = 1;
863 #endif 1186 #endif
871 routines below create new objects. */ 1194 routines below create new objects. */
872 init_alloc_once_early (); 1195 init_alloc_once_early ();
873 1196
874 /* Initialize Qnil, Qt, Qunbound, and the 1197 /* Initialize Qnil, Qt, Qunbound, and the
875 obarray. After this, symbols can be 1198 obarray. After this, symbols can be
876 interned. This depends on init_alloc_once(). */ 1199 interned. This depends on init_alloc_once_early(). */
877 init_symbols_once_early (); 1200 init_symbols_once_early ();
878 1201
879 /* Declare the basic symbols pertaining to errors, 1202 /* Declare the basic symbols pertaining to errors,
880 So that deferror() can be called. */ 1203 So that DEFERROR*() can be called. */
881 init_errors_once_early (); 1204 init_errors_once_early ();
882 1205
883 /* Make sure that opaque pointers can be created. */ 1206 /* Make sure that opaque pointers can be created. */
884 init_opaque_once_early (); 1207 init_opaque_once_early ();
885 1208
886 /* Now declare all the symbols and define all the Lisp primitives. 1209 /* Now declare all the symbols and define all the Lisp primitives.
887 1210
888 The *only* thing that the syms_of_*() functions are allowed to do 1211 The *only* thing that the syms_of_*() functions are allowed to do
889 is call one of the following three functions: 1212 is call one of the following:
890 1213
891 defsymbol() 1214 INIT_LRECORD_IMPLEMENTATION()
1215 defsymbol(), DEFSYMBOL(), or DEFSYMBOL_MULTIWORD_PREDICATE()
892 defsubr() (i.e. DEFSUBR) 1216 defsubr() (i.e. DEFSUBR)
893 deferror() 1217 deferror(), DEFERROR(), or DEFERROR_STANDARD()
894 defkeyword() 1218 defkeyword() or DEFKEYWORD()
895 1219
896 Order does not matter in these functions. 1220 Order does not matter in these functions.
897 */ 1221 */
898 1222
899 syms_of_abbrev (); 1223 syms_of_abbrev ();
943 syms_of_frame (); 1267 syms_of_frame ();
944 syms_of_general (); 1268 syms_of_general ();
945 syms_of_glyphs (); 1269 syms_of_glyphs ();
946 syms_of_glyphs_eimage (); 1270 syms_of_glyphs_eimage ();
947 syms_of_glyphs_widget (); 1271 syms_of_glyphs_widget ();
948 #if defined (HAVE_MENUBARS) || defined (HAVE_SCROLLBARS) || defined (HAVE_DIALOGS) || defined (HAVE_TOOLBARS)
949 syms_of_gui (); 1272 syms_of_gui ();
950 #endif
951 syms_of_gutter (); 1273 syms_of_gutter ();
952 syms_of_indent (); 1274 syms_of_indent ();
953 syms_of_intl (); 1275 syms_of_intl ();
954 syms_of_keymap (); 1276 syms_of_keymap ();
955 syms_of_lread (); 1277 syms_of_lread ();
1002 syms_of_device_tty (); 1324 syms_of_device_tty ();
1003 syms_of_objects_tty (); 1325 syms_of_objects_tty ();
1004 #endif 1326 #endif
1005 1327
1006 #ifdef HAVE_X_WINDOWS 1328 #ifdef HAVE_X_WINDOWS
1329 #ifdef HAVE_BALLOON_HELP
1007 syms_of_balloon_x (); 1330 syms_of_balloon_x ();
1331 #endif
1008 syms_of_device_x (); 1332 syms_of_device_x ();
1009 #ifdef HAVE_DIALOGS 1333 #ifdef HAVE_DIALOGS
1010 syms_of_dialog_x (); 1334 syms_of_dialog_x ();
1011 #endif 1335 #endif
1012 syms_of_frame_x (); 1336 syms_of_frame_x ();
1027 #endif /* HAVE_X_WINDOWS */ 1351 #endif /* HAVE_X_WINDOWS */
1028 1352
1029 #ifdef HAVE_MS_WINDOWS 1353 #ifdef HAVE_MS_WINDOWS
1030 syms_of_console_mswindows (); 1354 syms_of_console_mswindows ();
1031 syms_of_device_mswindows (); 1355 syms_of_device_mswindows ();
1356 syms_of_dialog_mswindows ();
1032 syms_of_frame_mswindows (); 1357 syms_of_frame_mswindows ();
1033 syms_of_objects_mswindows (); 1358 syms_of_objects_mswindows ();
1034 syms_of_select_mswindows (); 1359 syms_of_select_mswindows ();
1035 syms_of_glyphs_mswindows (); 1360 syms_of_glyphs_mswindows ();
1036 syms_of_gui_mswindows (); 1361 syms_of_gui_mswindows ();
1038 syms_of_menubar_mswindows (); 1363 syms_of_menubar_mswindows ();
1039 #endif 1364 #endif
1040 #ifdef HAVE_SCROLLBARS 1365 #ifdef HAVE_SCROLLBARS
1041 syms_of_scrollbar_mswindows (); 1366 syms_of_scrollbar_mswindows ();
1042 #endif 1367 #endif
1368 #endif /* HAVE_MS_WINDOWS */
1043 #ifdef HAVE_MSW_C_DIRED 1369 #ifdef HAVE_MSW_C_DIRED
1044 syms_of_dired_mswindows (); 1370 syms_of_dired_mswindows ();
1045 #endif 1371 #endif
1046 #ifdef WINDOWSNT 1372 #ifdef WIN32_NATIVE
1047 syms_of_ntproc (); 1373 syms_of_ntproc ();
1048 #endif 1374 #endif
1049 #endif /* HAVE_MS_WINDOWS */ 1375 #if defined (WIN32_NATIVE) || defined (CYGWIN)
1376 syms_of_win32 ();
1377 #endif
1050 1378
1051 #ifdef MULE 1379 #ifdef MULE
1052 syms_of_mule (); 1380 syms_of_mule ();
1053 syms_of_mule_ccl (); 1381 syms_of_mule_ccl ();
1054 syms_of_mule_charset (); 1382 syms_of_mule_charset ();
1094 #ifdef HAVE_LDAP 1422 #ifdef HAVE_LDAP
1095 syms_of_eldap (); 1423 syms_of_eldap ();
1096 #endif 1424 #endif
1097 1425
1098 #ifdef HAVE_GPM 1426 #ifdef HAVE_GPM
1099 syms_of_gpmevent (); 1427 syms_of_gpmevent ();
1428 #endif
1429
1430 #ifdef HAVE_POSTGRESQL
1431 syms_of_postgresql ();
1100 #endif 1432 #endif
1101 1433
1102 /* Now create the subtypes for the types that have them. 1434 /* Now create the subtypes for the types that have them.
1103 We do this before the vars_*() because more symbols 1435 We do this before the vars_*() because more symbols
1104 may get initialized here. */ 1436 may get initialized here. */
1277 Fset() on a symbol that is unbound 1609 Fset() on a symbol that is unbound
1278 assigning a symbol or constant value to a variable 1610 assigning a symbol or constant value to a variable
1279 using a global variable that has been initialized 1611 using a global variable that has been initialized
1280 earlier on in the same function 1612 earlier on in the same function
1281 1613
1282 Any of the object-creating functions on alloc.c: e.g. 1614 Any of the object-creating functions in alloc.c: e.g.
1283 1615
1284 make_pure_*() 1616 make_pure_*()
1285 make_string() 1617 make_string()
1286 build_string() 1618 build_string()
1287 make_vector() 1619 make_vector()
1350 vars_of_font_lock (); 1682 vars_of_font_lock ();
1351 vars_of_frame (); 1683 vars_of_frame ();
1352 vars_of_glyphs (); 1684 vars_of_glyphs ();
1353 vars_of_glyphs_eimage (); 1685 vars_of_glyphs_eimage ();
1354 vars_of_glyphs_widget (); 1686 vars_of_glyphs_widget ();
1355 #if defined (HAVE_MENUBARS) || defined (HAVE_SCROLLBARS) || defined (HAVE_DIALOGS) || defined (HAVE_TOOLBARS)
1356 vars_of_gui (); 1687 vars_of_gui ();
1357 #endif
1358 vars_of_gutter (); 1688 vars_of_gutter ();
1359 vars_of_indent (); 1689 vars_of_indent ();
1360 vars_of_insdel (); 1690 vars_of_insdel ();
1361 vars_of_intl (); 1691 vars_of_intl ();
1362 #ifdef HAVE_XIM 1692 #ifdef HAVE_XIM
1379 #endif 1709 #endif
1380 vars_of_minibuf (); 1710 vars_of_minibuf ();
1381 #ifdef HAVE_SHLIB 1711 #ifdef HAVE_SHLIB
1382 vars_of_module (); 1712 vars_of_module ();
1383 #endif 1713 #endif
1384 #ifdef WINDOWSNT 1714 #ifdef WIN32_NATIVE
1385 vars_of_nt (); 1715 vars_of_nt ();
1386 vars_of_ntproc (); 1716 vars_of_ntproc ();
1387 #endif 1717 #endif
1388 vars_of_objects (); 1718 vars_of_objects ();
1389 vars_of_print (); 1719 vars_of_print ();
1422 vars_of_frame_tty (); 1752 vars_of_frame_tty ();
1423 vars_of_objects_tty (); 1753 vars_of_objects_tty ();
1424 #endif 1754 #endif
1425 1755
1426 #ifdef HAVE_X_WINDOWS 1756 #ifdef HAVE_X_WINDOWS
1757 #ifdef HAVE_BALLOON_HELP
1427 vars_of_balloon_x (); 1758 vars_of_balloon_x ();
1759 #endif
1428 vars_of_device_x (); 1760 vars_of_device_x ();
1429 #ifdef HAVE_DIALOGS 1761 #ifdef HAVE_DIALOGS
1430 vars_of_dialog_x (); 1762 vars_of_dialog_x ();
1431 #endif 1763 #endif
1432 vars_of_frame_x (); 1764 vars_of_frame_x ();
1492 1824
1493 #ifdef HAVE_LDAP 1825 #ifdef HAVE_LDAP
1494 vars_of_eldap (); 1826 vars_of_eldap ();
1495 #endif 1827 #endif
1496 1828
1829 #ifdef HAVE_POSTGRESQL
1830 vars_of_postgresql();
1831 #endif
1832
1497 #ifdef HAVE_GPM 1833 #ifdef HAVE_GPM
1498 vars_of_gpmevent (); 1834 vars_of_gpmevent ();
1499 #endif 1835 #endif
1500 1836
1501 /* Now initialize any specifier variables. We do this later 1837 /* Now initialize any specifier variables. We do this later
1502 because it has some dependence on the vars initialized 1838 because it has some dependence on the vars initialized
1503 above. 1839 above.
1693 reinit_vars_of_event_mswindows (); 2029 reinit_vars_of_event_mswindows ();
1694 #endif 2030 #endif
1695 reinit_vars_of_event_stream (); 2031 reinit_vars_of_event_stream ();
1696 reinit_vars_of_events (); 2032 reinit_vars_of_events ();
1697 reinit_vars_of_extents (); 2033 reinit_vars_of_extents ();
2034 reinit_vars_of_fileio ();
1698 reinit_vars_of_font_lock (); 2035 reinit_vars_of_font_lock ();
1699 reinit_vars_of_glyphs (); 2036 reinit_vars_of_glyphs ();
1700 reinit_vars_of_glyphs_widget (); 2037 reinit_vars_of_glyphs_widget ();
1701 reinit_vars_of_insdel (); 2038 reinit_vars_of_insdel ();
1702 reinit_vars_of_lread (); 2039 reinit_vars_of_lread ();
1705 #ifdef HAVE_SHLIB 2042 #ifdef HAVE_SHLIB
1706 reinit_vars_of_module (); 2043 reinit_vars_of_module ();
1707 #endif 2044 #endif
1708 reinit_vars_of_objects (); 2045 reinit_vars_of_objects ();
1709 reinit_vars_of_print (); 2046 reinit_vars_of_print ();
1710 reinit_vars_of_redisplay ();
1711 reinit_vars_of_search (); 2047 reinit_vars_of_search ();
1712 reinit_vars_of_undo (); 2048 reinit_vars_of_undo ();
1713 reinit_vars_of_window (); 2049 reinit_vars_of_window ();
1714 2050
1715 #ifdef HAVE_MS_WINDOWS 2051 #ifdef HAVE_MS_WINDOWS
1763 to be done both at dump time and at run time. */ 2099 to be done both at dump time and at run time. */
1764 2100
1765 init_initial_directory(); /* get the directory to use for the 2101 init_initial_directory(); /* get the directory to use for the
1766 "*scratch*" buffer, etc. */ 2102 "*scratch*" buffer, etc. */
1767 2103
1768 #ifdef WINDOWSNT 2104 #ifdef WIN32_NATIVE
1769 /* 2105 /*
1770 * For Win32, call init_environment() now, so that environment/registry 2106 * For Win32, call init_environment() now, so that environment/registry
1771 * variables will be properly entered into Vprocess_environment. 2107 * variables will be properly entered into Vprocess_environment.
1772 */ 2108 */
1773 init_environment(); 2109 init_environment();
1778 (exec-directory and so on), and stuff 2114 (exec-directory and so on), and stuff
1779 related to subprocesses. This should be 2115 related to subprocesses. This should be
1780 first because many of the functions below 2116 first because many of the functions below
1781 call egetenv() to get environment variables. */ 2117 call egetenv() to get environment variables. */
1782 init_lread (); /* Set up the Lisp reader. */ 2118 init_lread (); /* Set up the Lisp reader. */
1783 #ifdef MSDOS 2119 init_cmdargs (argc, (Extbyte **) argv,
1784 /* Call early 'cause init_environment needs it. */ 2120 skip_args); /* Create list Vcommand_line_args */
1785 init_dosfns ();
1786 /* Set defaults for several environment variables. */
1787 init_environment (argc, argv, skip_args);
1788 #endif
1789 init_cmdargs (argc, argv, skip_args); /* Create list Vcommand_line_args */
1790 init_buffer (); /* Set default directory of *scratch* buffer */ 2121 init_buffer (); /* Set default directory of *scratch* buffer */
1791 2122
1792 #ifdef WINDOWSNT 2123 #ifdef WIN32_NATIVE
1793 init_ntproc(); 2124 init_ntproc();
1794 #endif 2125 #endif
1795 2126
1796 init_redisplay (); /* Determine terminal type. 2127 init_redisplay (); /* Determine terminal type.
1797 init_sys_modes uses results */ 2128 init_sys_modes uses results */
1801 init_editfns (); /* Determine the name of the user we're running as */ 2132 init_editfns (); /* Determine the name of the user we're running as */
1802 init_xemacs_process (); /* set up for calling subprocesses */ 2133 init_xemacs_process (); /* set up for calling subprocesses */
1803 #ifdef SUNPRO 2134 #ifdef SUNPRO
1804 init_sunpro (); /* Set up Sunpro usage tracking */ 2135 init_sunpro (); /* Set up Sunpro usage tracking */
1805 #endif 2136 #endif
2137 #if defined (WIN32_NATIVE) || defined (CYGWIN)
2138 init_win32 ();
2139 #endif
1806 #if defined (HAVE_NATIVE_SOUND) && defined (hp9000s800) 2140 #if defined (HAVE_NATIVE_SOUND) && defined (hp9000s800)
1807 init_hpplay (); 2141 init_hpplay ();
1808 #endif 2142 #endif
1809 #ifdef HAVE_TTY 2143 #ifdef HAVE_TTY
1810 init_device_tty (); 2144 init_device_tty ();
1811 #endif 2145 #endif
1812 init_console_stream (); /* Create the first console */ 2146 init_console_stream (restart); /* Create the first console */
1813 2147
1814 /* try to get the actual pathname of the exec file we are running */ 2148 /* try to get the actual pathname of the exec file we are running */
1815 if (!restart) 2149 if (!restart)
1816 { 2150 {
1817 Vinvocation_name = Fcar (Vcommand_line_args); 2151 Vinvocation_name = Fcar (Vcommand_line_args);
1843 2177
1844 Vinvocation_name = Ffile_name_nondirectory (Vinvocation_directory); 2178 Vinvocation_name = Ffile_name_nondirectory (Vinvocation_directory);
1845 Vinvocation_directory = Ffile_name_directory (Vinvocation_directory); 2179 Vinvocation_directory = Ffile_name_directory (Vinvocation_directory);
1846 } 2180 }
1847 2181
1848 #if defined(HAVE_SHLIB) && !defined(WINDOWSNT) 2182 #if defined(HAVE_SHLIB) && !defined(WIN32_NATIVE)
1849 /* This is Unix only. MS Windows NT has a library call that does 2183 /* This is Unix only. MS Windows NT has a library call that does
1850 The Right Thing on that system. Rumor has it, this must be 2184 The Right Thing on that system. Rumor has it, this must be
1851 called for GNU dld in temacs and xemacs. */ 2185 called for GNU dld in temacs and xemacs. */
1852 { 2186 {
1853 char *buf = (char *)alloca (XSTRING_LENGTH (Vinvocation_directory) 2187 char *buf = (char *)alloca (XSTRING_LENGTH (Vinvocation_directory)
1901 2235
1902 /* First, here's a table of all the standard options. */ 2236 /* First, here's a table of all the standard options. */
1903 2237
1904 struct standard_args 2238 struct standard_args
1905 { 2239 {
1906 CONST char * CONST name; 2240 const char *name;
1907 CONST char * CONST longname; 2241 const char *longname;
1908 int priority; 2242 int priority;
1909 int nargs; 2243 int nargs;
1910 }; 2244 };
1911 2245
1912 static struct standard_args standard_args[] = 2246 static const struct standard_args standard_args[] =
1913 { 2247 {
1914 /* Handled by main_1 above: */ 2248 /* Handled by main_1 above: */
1915 { "-nl", "--no-shared-memory", 100, 0 }, 2249 { "-sd", "--show-dump-id", 105, 0 },
1916 { "-t", "--terminal", 95, 1 }, 2250 { "-t", "--terminal", 100, 1 },
2251 { "-nd", "--no-dump-file", 95, 0 },
1917 { "-nw", "--no-windows", 90, 0 }, 2252 { "-nw", "--no-windows", 90, 0 },
1918 { "-batch", "--batch", 85, 0 }, 2253 { "-batch", "--batch", 85, 0 },
1919 { "-debug-paths", "--debug-paths", 82, 0 }, 2254 { "-debug-paths", "--debug-paths", 82, 0 },
1920 { "-help", "--help", 80, 0 }, 2255 { "-help", "--help", 80, 0 },
1921 { "-version", "--version", 75, 0 }, 2256 { "-version", "--version", 75, 0 },
2106 xfree (new_argv); 2441 xfree (new_argv);
2107 xfree (options); 2442 xfree (options);
2108 xfree (priority); 2443 xfree (priority);
2109 } 2444 }
2110 2445
2111 static JMP_BUF run_temacs_catch;
2112
2113 static int run_temacs_argc;
2114 static char **run_temacs_argv;
2115 static char *run_temacs_args;
2116 static size_t run_temacs_argv_size;
2117 static size_t run_temacs_args_size;
2118
2119 DEFUN ("running-temacs-p", Frunning_temacs_p, 0, 0, 0, /* 2446 DEFUN ("running-temacs-p", Frunning_temacs_p, 0, 0, 0, /*
2120 True if running temacs. This means we are in the dumping stage. 2447 True if running temacs. This means we are in the dumping stage.
2121 This is false during normal execution of the `xemacs' program, and 2448 This is false during normal execution of the `xemacs' program, and
2122 becomes false once `run-emacs-from-temacs' is run. 2449 becomes false once `run-emacs-from-temacs' is run.
2123 */ 2450 */
2141 Martin thinks this function is most useful when using debugging 2468 Martin thinks this function is most useful when using debugging
2142 tools like Purify or tcov that get confused by XEmacs' dumping. */ 2469 tools like Purify or tcov that get confused by XEmacs' dumping. */
2143 (int nargs, Lisp_Object *args)) 2470 (int nargs, Lisp_Object *args))
2144 { 2471 {
2145 int ac; 2472 int ac;
2146 CONST Extbyte *wampum; 2473 const Extbyte *wampum;
2147 int namesize; 2474 int namesize;
2148 int total_len; 2475 int total_len;
2149 Lisp_Object orig_invoc_name = Fcar (Vcommand_line_args); 2476 Lisp_Object orig_invoc_name = Fcar (Vcommand_line_args);
2150 CONST Extbyte **wampum_all = alloca_array (CONST Extbyte *, nargs); 2477 const Extbyte **wampum_all = alloca_array (const Extbyte *, nargs);
2151 int *wampum_all_len = alloca_array (int, nargs); 2478 int *wampum_all_len = alloca_array (int, nargs);
2152 2479
2153 assert (!gc_in_progress); 2480 assert (!gc_in_progress);
2154 2481
2155 if (run_temacs_argc < 0) 2482 if (run_temacs_argc < 0)
2188 catchlist = NULL; /* Important! Otherwise free_cons() calls in 2515 catchlist = NULL; /* Important! Otherwise free_cons() calls in
2189 condition_case_unwind() may lead to GC death. */ 2516 condition_case_unwind() may lead to GC death. */
2190 unbind_to (0, Qnil); /* this closes loadup.el */ 2517 unbind_to (0, Qnil); /* this closes loadup.el */
2191 purify_flag = 0; 2518 purify_flag = 0;
2192 run_temacs_argc = nargs + 1; 2519 run_temacs_argc = nargs + 1;
2193 #ifdef HEAP_IN_DATA 2520 #if defined (HEAP_IN_DATA) && !defined(PDUMP)
2194 report_sheap_usage (0); 2521 report_sheap_usage (0);
2195 #endif 2522 #endif
2196 LONGJMP (run_temacs_catch, 1); 2523 LONGJMP (run_temacs_catch, 1);
2197 return Qnil; /* not reached; warning suppression */ 2524 return Qnil; /* not reached; warning suppression */
2198 } 2525 }
2199 2526
2200 /* ARGSUSED */ 2527 /* ARGSUSED */
2201 int 2528 int
2202 main (int argc, char **argv, char **envp) 2529 main (int argc, char **argv, char **envp)
2203 { 2530 {
2531
2532 #ifdef _MSC_VER
2533 /* Under VC++, access violations and the like are not sent through
2534 the standard signal() mechanism. Rather, they need to be handled
2535 using the Microsoft "structured exception handling" mechanism,
2536 which vaguely resembles the C++ mechanisms. */
2537 __try
2538 {
2539 #endif
2540
2204 int volatile vol_argc = argc; 2541 int volatile vol_argc = argc;
2205 char ** volatile vol_argv = argv; 2542 char ** volatile vol_argv = argv;
2206 char ** volatile vol_envp = envp; 2543 char ** volatile vol_envp = envp;
2207 /* This is hairy. We need to compute where the XEmacs binary was invoked 2544 /* This is hairy. We need to compute where the XEmacs binary was invoked
2208 from because temacs initialization requires it to find the lisp 2545 from because temacs initialization requires it to find the lisp
2274 is bracketed with both a system specific preprocessor test 2611 is bracketed with both a system specific preprocessor test
2275 and a runtime "do you have this problem" test 2612 and a runtime "do you have this problem" test
2276 2613
2277 06/20/96 robertl@dgii.com */ 2614 06/20/96 robertl@dgii.com */
2278 { 2615 {
2279 extern char *_environ; 2616 extern char **_environ;
2280 if ((unsigned) environ == 0) 2617 if ((unsigned) environ == 0)
2281 environ=_environ; 2618 environ=_environ;
2282 } 2619 }
2283 #endif /* _SCO_DS */ 2620 #endif /* _SCO_DS */
2284 vol_envp = environ; 2621 vol_envp = environ;
2294 if (initialized && (malloc_state_ptr != NULL)) 2631 if (initialized && (malloc_state_ptr != NULL))
2295 { 2632 {
2296 int rc = malloc_set_state (malloc_state_ptr); 2633 int rc = malloc_set_state (malloc_state_ptr);
2297 if (rc != 0) 2634 if (rc != 0)
2298 { 2635 {
2299 fprintf (stderr, "malloc_set_state failed, rc = %d\n", rc); 2636 stderr_out ("malloc_set_state failed, rc = %d\n", rc);
2300 abort (); 2637 abort ();
2301 } 2638 }
2302 #if 0 2639 #if 0
2303 free (malloc_state_ptr); 2640 free (malloc_state_ptr);
2304 #endif 2641 #endif
2316 #endif /* DOUG_LEA_MALLOC */ 2653 #endif /* DOUG_LEA_MALLOC */
2317 2654
2318 run_temacs_argc = -1; 2655 run_temacs_argc = -1;
2319 2656
2320 main_1 (vol_argc, vol_argv, vol_envp, restarted); 2657 main_1 (vol_argc, vol_argv, vol_envp, restarted);
2658
2659 #ifdef _MSC_VER
2660 }
2661 /* VC++ documentation says that
2662 GetExceptionCode() cannot be called inside the filter itself. */
2663 __except (mswindows_handle_hardware_exceptions (GetExceptionCode ())) {}
2664 #endif
2665
2321 return 0; /* unreached */ 2666 return 0; /* unreached */
2322 } 2667 }
2323 2668
2324 2669
2325 /* Dumping apparently isn't supported by versions of GCC >= 2.8. */ 2670 /* Dumping apparently isn't supported by versions of GCC >= 2.8. */
2360 arg = Qt; 2705 arg = Qt;
2361 2706
2362 if (!preparing_for_armageddon && !noninteractive) 2707 if (!preparing_for_armageddon && !noninteractive)
2363 run_hook (Qkill_emacs_hook); 2708 run_hook (Qkill_emacs_hook);
2364 2709
2365 /* make sure no quitting from now on!! */ 2710 ensure_no_quitting_from_now_on ();
2366 dont_check_for_quit = 1;
2367 Vinhibit_quit = Qt;
2368 2711
2369 if (!preparing_for_armageddon) 2712 if (!preparing_for_armageddon)
2370 { 2713 {
2371 Lisp_Object concons, nextcons; 2714 Lisp_Object concons, nextcons;
2372 2715
2376 and even for those that do, it might be cleaner this way. 2719 and even for those that do, it might be cleaner this way.
2377 If we're going down, however, we don't do this (might 2720 If we're going down, however, we don't do this (might
2378 be too dangerous), and if we get a crash somewhere within 2721 be too dangerous), and if we get a crash somewhere within
2379 this loop, we'll still autosave and won't try this again. */ 2722 this loop, we'll still autosave and won't try this again. */
2380 2723
2381 LIST_LOOP_DELETING(concons, nextcons, Vconsole_list) 2724 LIST_LOOP_DELETING (concons, nextcons, Vconsole_list)
2382 { 2725 {
2383 /* There is very little point in deleting the stream console. 2726 /* There is very little point in deleting the stream console.
2384 It uses stdio, which should flush any buffered output and 2727 It uses stdio, which should flush any buffered output and
2385 something can only go wrong. -slb */ 2728 something can only go wrong. -slb */
2386 /* I changed my mind. There's a stupid hack in close to add 2729 /* I changed my mind. There's a stupid hack in close to add
2390 } 2733 }
2391 } 2734 }
2392 2735
2393 UNGCPRO; 2736 UNGCPRO;
2394 2737
2395 shut_down_emacs (0, STRINGP (arg) ? arg : Qnil); 2738 #ifdef HAVE_MS_WINDOWS
2739 /* If we displayed a message on the console, then we must allow the
2740 user to see this message. This may be unnecessary, but can't hurt,
2741 and we can't necessarily check arg; e.g. xemacs --help kills with
2742 argument 0. */
2743 if (mswindows_message_outputted)
2744 Fmswindows_message_box (build_string ("Messages outputted. XEmacs is exiting."),
2745 Qnil, Qnil);
2746 #endif
2747
2748 shut_down_emacs (0, STRINGP (arg) ? arg : Qnil, 0);
2396 2749
2397 #if defined(GNU_MALLOC) 2750 #if defined(GNU_MALLOC)
2398 __free_hook = 2751 __free_hook =
2399 #ifdef __GNUC__ /* prototype of __free_hook varies with glibc version */ 2752 #ifdef __GNUC__ /* prototype of __free_hook varies with glibc version */
2400 (__typeof__ (__free_hook)) 2753 (__typeof__ (__free_hook))
2413 any redisplay; this may be called when XEmacs is shutting down in 2766 any redisplay; this may be called when XEmacs is shutting down in
2414 the background, or after its X connection has died. 2767 the background, or after its X connection has died.
2415 2768
2416 If SIG is a signal number, print a message for it. 2769 If SIG is a signal number, print a message for it.
2417 2770
2418 This is called by fatal signal handlers, X protocol error handlers, 2771 This is called by fatal signal handlers and Fkill_emacs. It used to
2419 and Fkill_emacs. */ 2772 be called by X protocol error handlers, but instead they now call
2773 Fkill_emacs. */
2420 static void 2774 static void
2421 shut_down_emacs (int sig, Lisp_Object stuff) 2775 shut_down_emacs (int sig, Lisp_Object stuff, int no_auto_save)
2422 { 2776 {
2423 /* This function can GC */ 2777 /* This function can GC */
2424 /* Prevent running of hooks and other non-essential stuff 2778 /* Prevent running of hooks and other non-essential stuff
2425 from now on. */ 2779 from now on. */
2426 preparing_for_armageddon = 1; 2780 preparing_for_armageddon = 1;
2427 2781
2428 /* In case frames or windows are screwed up, avoid assertion 2782 ensure_no_quitting_from_now_on ();
2429 failures here */
2430 Vinhibit_quit = Qt;
2431 2783
2432 #ifdef QUANTIFY 2784 #ifdef QUANTIFY
2433 quantify_stop_recording_data (); 2785 quantify_stop_recording_data ();
2434 #endif /* QUANTIFY */ 2786 #endif /* QUANTIFY */
2435 2787
2436 #if 0
2437 /* This is absolutely the most important thing to do, so make sure 2788 /* This is absolutely the most important thing to do, so make sure
2438 we do it now, before anything else. We might have crashed and 2789 we do it now, before anything else. We might have crashed and
2439 be in a weird inconsistent state, and potentially anything could 2790 be in a weird inconsistent state, and potentially anything could
2440 set off another protection fault and cause us to bail out 2791 set off another protection fault and cause us to bail out
2441 immediately. */ 2792 immediately. */
2442 /* I'm not removing the code entirely, yet. We have run up against 2793 /* Steve writes the following:
2794
2795 [[I'm not removing the code entirely, yet. We have run up against
2443 a spate of problems in diagnosing crashes due to crashes within 2796 a spate of problems in diagnosing crashes due to crashes within
2444 crashes. It has very definitely been determined that code called 2797 crashes. It has very definitely been determined that code called
2445 during auto-saving cannot work if XEmacs crashed inside of GC. 2798 during auto-saving cannot work if XEmacs crashed inside of GC.
2446 We already auto-save on an itimer so there cannot be too much 2799 We already auto-save on an itimer so there cannot be too much
2447 unsaved stuff around, and if we get better crash reports we might 2800 unsaved stuff around, and if we get better crash reports we might
2448 be able to get more problems fixed so I'm disabling this. -slb */ 2801 be able to get more problems fixed so I'm disabling this. -slb]]
2449 Fdo_auto_save (Qt, Qnil); /* do this before anything hazardous */ 2802
2450 #endif 2803 and DISABLES AUTO-SAVING ENTIRELY during crashes! Way way bad idea.
2804
2805 Instead let's just be more intelligent about avoiding crashing
2806 when possible, esp. nested crashes.
2807 */
2808 if (!no_auto_save)
2809 Fdo_auto_save (Qt, Qnil); /* do this before anything hazardous */
2451 2810
2452 fflush (stdout); 2811 fflush (stdout);
2453 reset_all_consoles (); 2812 reset_all_consoles ();
2454 if (sig && sig != SIGTERM) 2813 if (sig && sig != SIGTERM)
2455 { 2814 {
2456 stderr_out ("\nFatal error (%d).\n", sig); 2815 if (sig == -1)
2816 stderr_out ("\nFatal error.\n\n");
2817 else
2818 stderr_out ("\nFatal error (%d).\n\n", sig);
2457 stderr_out 2819 stderr_out
2458 ("Your files have been auto-saved.\n" 2820 ("Your files have been auto-saved.\n"
2459 "Use `M-x recover-session' to recover them.\n" 2821 "Use `M-x recover-session' to recover them.\n"
2460 "\n" 2822 "\n"
2461 "If you have access to the PROBLEMS file that came with your\n" 2823 "If you have access to the PROBLEMS file that came with your\n"
2470 "from the help menu.\n" 2832 "from the help menu.\n"
2471 "As a last resort send ordinary email to `crashes@xemacs.org'.\n" 2833 "As a last resort send ordinary email to `crashes@xemacs.org'.\n"
2472 #endif 2834 #endif
2473 "*MAKE SURE* to include the information in the command\n" 2835 "*MAKE SURE* to include the information in the command\n"
2474 "M-x describe-installation.\n" 2836 "M-x describe-installation.\n"
2837 #ifndef _MSC_VER
2475 "\n" 2838 "\n"
2476 "If at all possible, *please* try to obtain a C stack backtrace;\n" 2839 "If at all possible, *please* try to obtain a C stack backtrace;\n"
2477 "it will help us immensely in determining what went wrong.\n" 2840 "it will help us immensely in determining what went wrong.\n"
2478 "To do this, locate the core file that was produced as a result\n" 2841 "To do this, locate the core file that was produced as a result\n"
2479 "of this crash (it's usually called `core' and is located in the\n" 2842 "of this crash (it's usually called `core' and is located in the\n"
2480 "directory in which you started the editor, or maybe in your home\n" 2843 "directory in which you started the editor, or maybe in your home\n"
2481 "directory), and type\n" 2844 "directory), and type\n"
2482 "\n" 2845 "\n"
2483 " gdb "); 2846 " gdb "
2847 #endif
2848 );
2849 #ifndef _MSC_VER
2484 { 2850 {
2485 CONST char *name; 2851 const char *name;
2486 char *dir = 0; 2852 char *dir = 0;
2487 2853
2488 /* Now try to determine the actual path to the executable, 2854 /* Now try to determine the actual path to the executable,
2489 to try to make the backtrace-determination process as foolproof 2855 to try to make the backtrace-determination process as foolproof
2490 as possible. */ 2856 as possible. */
2505 (" core\n\n" 2871 (" core\n\n"
2506 "then type `where' when the debugger prompt comes up.\n" 2872 "then type `where' when the debugger prompt comes up.\n"
2507 "(If you don't have GDB on your system, you might have DBX,\n" 2873 "(If you don't have GDB on your system, you might have DBX,\n"
2508 "or XDB, or SDB. A similar procedure should work for all of\n" 2874 "or XDB, or SDB. A similar procedure should work for all of\n"
2509 "these. Ask your system administrator if you need more help.)\n"); 2875 "these. Ask your system administrator if you need more help.)\n");
2876 #endif /* _MSC_VER */
2510 } 2877 }
2511 2878
2512 stuff_buffered_input (stuff); 2879 stuff_buffered_input (stuff);
2513 2880
2514 kill_buffer_processes (Qnil); 2881 kill_buffer_processes (Qnil);
2532 2899
2533 #if !defined(PDUMP) || !defined(SYSTEM_MALLOC) 2900 #if !defined(PDUMP) || !defined(SYSTEM_MALLOC)
2534 extern char my_edata[]; 2901 extern char my_edata[];
2535 #endif 2902 #endif
2536 2903
2537 #ifdef HAVE_SHM
2538
2539 DEFUN ("dump-emacs-data", Fdump_emacs_data, 1, 1, 0, /*
2540 Dump current state of XEmacs into data file FILENAME.
2541 This function exists on systems that use HAVE_SHM.
2542 */
2543 (intoname))
2544 {
2545 /* This function can GC */
2546 int opurify;
2547 struct gcpro gcpro1;
2548 GCPRO1 (intoname);
2549
2550 CHECK_STRING (intoname);
2551 intoname = Fexpand_file_name (intoname, Qnil);
2552
2553 opurify = purify_flag;
2554 purify_flag = 0;
2555
2556 fflush (stderr);
2557 fflush (stdout);
2558
2559 disksave_object_finalization ();
2560 release_breathing_space ();
2561
2562 /* Tell malloc where start of impure now is */
2563 /* Also arrange for warnings when nearly out of space. */
2564 #ifndef SYSTEM_MALLOC
2565 memory_warnings (my_edata, malloc_warning);
2566 #endif
2567 UNGCPRO;
2568 map_out_data (XSTRING_DATA (intoname));
2569
2570 purify_flag = opurify;
2571
2572 return Qnil;
2573 }
2574
2575 #else /* not HAVE_SHM */
2576 extern void disable_free_hook (void); 2904 extern void disable_free_hook (void);
2577 2905
2578 DEFUN ("dump-emacs", Fdump_emacs, 2, 2, 0, /* 2906 DEFUN ("dump-emacs", Fdump_emacs, 2, 2, 0, /*
2579 Dump current state of XEmacs into executable file FILENAME. 2907 Dump current state of XEmacs into executable file FILENAME.
2580 Take symbols from SYMFILE (presumably the file you executed to run XEmacs). 2908 Take symbols from SYMFILE (presumably the file you executed to run XEmacs).
2611 } 2939 }
2612 2940
2613 opurify = purify_flag; 2941 opurify = purify_flag;
2614 purify_flag = 0; 2942 purify_flag = 0;
2615 2943
2616 #ifdef HEAP_IN_DATA 2944 #if defined (HEAP_IN_DATA) && !defined(PDUMP)
2617 report_sheap_usage (1); 2945 report_sheap_usage (1);
2618 #endif 2946 #endif
2619 2947
2620 clear_message (); 2948 clear_message ();
2621 2949
2631 memory_warnings (my_edata, malloc_warning); 2959 memory_warnings (my_edata, malloc_warning);
2632 #endif 2960 #endif
2633 2961
2634 UNGCPRO; 2962 UNGCPRO;
2635 2963
2636 #if defined (MSDOS) && defined (EMX)
2637 {
2638 int fd = open ((char *) XSTRING_DATA (intoname),
2639 O_WRONLY|O_CREAT|O_TRUNC, S_IREAD|S_IWRITE);
2640 if (!fd) {
2641 error ("Failure operating on %s", XSTRING_DATA (intoname));
2642 } else {
2643 _core (fd);
2644 close (fd);
2645 }
2646 }
2647 #else /* not MSDOS and EMX */
2648 { 2964 {
2649 char *intoname_ext; 2965 char *intoname_ext;
2650 char *symname_ext; 2966 char *symname_ext;
2651 2967
2652 TO_EXTERNAL_FORMAT (LISP_STRING, intoname, 2968 LISP_STRING_TO_EXTERNAL (intoname, intoname_ext, Qfile_name);
2653 C_STRING_ALLOCA, intoname_ext,
2654 Qfile_name);
2655 2969
2656 if (STRINGP (symname)) 2970 if (STRINGP (symname))
2657 TO_EXTERNAL_FORMAT (LISP_STRING, symname, 2971 LISP_STRING_TO_EXTERNAL (symname, symname_ext, Qfile_name);
2658 C_STRING_ALLOCA, symname_ext,
2659 Qfile_name);
2660 else 2972 else
2661 symname_ext = 0; 2973 symname_ext = 0;
2662 2974
2663 garbage_collect_1 (); 2975 garbage_collect_1 ();
2664 2976
2679 #ifdef DOUG_LEA_MALLOC 2991 #ifdef DOUG_LEA_MALLOC
2680 free (malloc_state_ptr); 2992 free (malloc_state_ptr);
2681 #endif 2993 #endif
2682 #endif /* not PDUMP */ 2994 #endif /* not PDUMP */
2683 } 2995 }
2684 #endif /* not MSDOS and EMX */
2685 2996
2686 purify_flag = opurify; 2997 purify_flag = opurify;
2687 2998
2688 return Qnil; 2999 return Qnil;
2689 } 3000 }
2690 3001
2691 #endif /* not HAVE_SHM */
2692
2693 #endif /* not CANNOT_DUMP */ 3002 #endif /* not CANNOT_DUMP */
2694 3003
2695 #ifndef SEPCHAR
2696 #define SEPCHAR ':'
2697 #endif
2698 3004
2699 /* Split STRING into a list of substrings. The substrings are the 3005 /* Split STRING into a list of substrings. The substrings are the
2700 parts of original STRING separated by SEPCHAR. */ 3006 parts of original STRING separated by SEPCHAR. */
2701 static Lisp_Object 3007 static Lisp_Object
2702 split_string_by_emchar_1 (CONST Bufbyte *string, Bytecount size, 3008 split_string_by_emchar_1 (const Bufbyte *string, Bytecount size,
2703 Emchar sepchar) 3009 Emchar sepchar)
2704 { 3010 {
2705 Lisp_Object result = Qnil; 3011 Lisp_Object result = Qnil;
2706 CONST Bufbyte *end = string + size; 3012 const Bufbyte *end = string + size;
2707 3013
2708 while (1) 3014 while (1)
2709 { 3015 {
2710 CONST Bufbyte *p = string; 3016 const Bufbyte *p = string;
2711 while (p < end) 3017 while (p < end)
2712 { 3018 {
2713 if (charptr_emchar (p) == sepchar) 3019 if (charptr_emchar (p) == sepchar)
2714 break; 3020 break;
2715 INC_CHARPTR (p); 3021 INC_CHARPTR (p);
2728 3034
2729 /* The same as the above, except PATH is an external C string (it is 3035 /* The same as the above, except PATH is an external C string (it is
2730 converted using Qfile_name), and sepchar is hardcoded to SEPCHAR 3036 converted using Qfile_name), and sepchar is hardcoded to SEPCHAR
2731 (':' or whatever). */ 3037 (':' or whatever). */
2732 Lisp_Object 3038 Lisp_Object
2733 decode_path (CONST char *path) 3039 decode_path (const char *path)
2734 { 3040 {
2735 Bytecount newlen; 3041 Bytecount newlen;
2736 Bufbyte *newpath; 3042 Bufbyte *newpath;
2737 if (!path) 3043 if (!path)
2738 return Qnil; 3044 return Qnil;
2748 3054
2749 return split_string_by_emchar_1 (newpath, newlen, SEPCHAR); 3055 return split_string_by_emchar_1 (newpath, newlen, SEPCHAR);
2750 } 3056 }
2751 3057
2752 Lisp_Object 3058 Lisp_Object
2753 decode_env_path (CONST char *evarname, CONST char *default_) 3059 decode_env_path (const char *evarname, const char *default_)
2754 { 3060 {
2755 CONST char *path = 0; 3061 const char *path = 0;
2756 if (evarname) 3062 if (evarname)
2757 path = egetenv (evarname); 3063 path = egetenv (evarname);
2758 if (!path) 3064 if (!path)
2759 path = default_; 3065 path = default_;
2760 return decode_path (path); 3066 return decode_path (path);
2812 /* #define ASSERTIONS_DONT_ABORT */ 3118 /* #define ASSERTIONS_DONT_ABORT */
2813 3119
2814 #ifdef USE_ASSERTIONS 3120 #ifdef USE_ASSERTIONS
2815 /* This highly dubious kludge ... shut up Jamie, I'm tired of your slagging. */ 3121 /* This highly dubious kludge ... shut up Jamie, I'm tired of your slagging. */
2816 3122
2817 DOESNT_RETURN 3123 static int in_assert_failed;
2818 assert_failed (CONST char *file, int line, CONST char *expr) 3124 static const char *assert_failed_file;
3125 static int assert_failed_line;
3126 static const char *assert_failed_expr;
3127
3128 #ifdef fprintf
3129 #undef fprintf
3130 #endif
3131
3132 #undef abort /* avoid infinite #define loop... */
3133
3134 #if defined (WIN32_NATIVE) && defined (DEBUG_XEMACS)
3135 #define enter_debugger() DebugBreak ()
3136 #else
3137 #define enter_debugger()
3138 #endif
3139
3140 void
3141 assert_failed (const char *file, int line, const char *expr)
2819 { 3142 {
2820 stderr_out ("Fatal error: assertion failed, file %s, line %d, %s\n", 3143 /* If we're already crashing, let's not crash again. This might be
2821 file, line, expr); 3144 critical to getting auto-saving working properly. */
2822 #undef abort /* avoid infinite #define loop... */ 3145 if (fatal_error_in_progress)
2823 #if defined (WINDOWSNT) && defined (DEBUG_XEMACS) 3146 return;
2824 DebugBreak (); 3147
2825 #elif !defined (ASSERTIONS_DONT_ABORT) 3148 /* We are extremely paranoid so we sensibly deal with recursive
3149 assertion failures. */
3150 in_assert_failed++;
3151
3152 if (in_assert_failed >= 4)
3153 _exit (-1);
3154 else if (in_assert_failed == 3)
3155 {
3156 enter_debugger ();
3157 _exit (-1);
3158 }
3159 else if (in_assert_failed == 2)
3160 {
3161 /* Not stderr_out(), which does additional things and may trigger
3162 a recursive assertion failure. fprintf was undeffed above, in
3163 case it was encapsulated. */
3164 fprintf (stderr,
3165 "Fatal error: recursive assertion failure, "
3166 "file %s, line %d, %s\n",
3167 file, line, expr);
3168 fprintf (stderr,
3169 "Original assertion failure: file %s, line %d, %s\n",
3170 assert_failed_file, assert_failed_line, assert_failed_expr);
3171 }
3172 else
3173 {
3174 assert_failed_file = file;
3175 assert_failed_line = line;
3176 assert_failed_expr = expr;
3177
3178 if (!initialized)
3179 fprintf (stderr,
3180 "Fatal error: assertion failed, file %s, line %d, %s\n",
3181 file, line, expr);
3182 else
3183 stderr_out ("Fatal error: assertion failed, file %s, line %d, %s\n",
3184 file, line, expr);
3185 }
3186
3187 enter_debugger ();
3188 #if !defined (ASSERTIONS_DONT_ABORT)
2826 abort (); 3189 abort ();
2827 #endif 3190 #endif
3191 in_assert_failed = 0;
2828 } 3192 }
2829 #endif /* USE_ASSERTIONS */ 3193 #endif /* USE_ASSERTIONS */
2830 3194
2831 #ifdef QUANTIFY 3195 #ifdef QUANTIFY
2832 DEFUN ("quantify-start-recording-data", Fquantify_start_recording_data, 3196 DEFUN ("quantify-start-recording-data", Fquantify_start_recording_data,
2861 3225
2862 void 3226 void
2863 syms_of_emacs (void) 3227 syms_of_emacs (void)
2864 { 3228 {
2865 #ifndef CANNOT_DUMP 3229 #ifndef CANNOT_DUMP
2866 #ifdef HAVE_SHM
2867 DEFSUBR (Fdump_emacs_data);
2868 #else
2869 DEFSUBR (Fdump_emacs); 3230 DEFSUBR (Fdump_emacs);
2870 #endif
2871 #endif /* !CANNOT_DUMP */ 3231 #endif /* !CANNOT_DUMP */
2872 3232
2873 DEFSUBR (Frun_emacs_from_temacs); 3233 DEFSUBR (Frun_emacs_from_temacs);
2874 DEFSUBR (Frunning_temacs_p); 3234 DEFSUBR (Frunning_temacs_p);
2875 DEFSUBR (Finvocation_name); 3235 DEFSUBR (Finvocation_name);
3012 #ifndef XEMACS_CODENAME 3372 #ifndef XEMACS_CODENAME
3013 #define XEMACS_CODENAME "Noname" 3373 #define XEMACS_CODENAME "Noname"
3014 #endif 3374 #endif
3015 Vxemacs_codename = build_string (XEMACS_CODENAME); 3375 Vxemacs_codename = build_string (XEMACS_CODENAME);
3016 3376
3377 /* Lisp variables which contain command line flags.
3378
3379 The portable dumper stomps on these; they must be saved and restored
3380 if they are processed before the call to pdump_load() in main_1().
3381 */
3017 DEFVAR_BOOL ("noninteractive", &noninteractive1 /* 3382 DEFVAR_BOOL ("noninteractive", &noninteractive1 /*
3018 Non-nil means XEmacs is running without interactive terminal. 3383 Non-nil means XEmacs is running without interactive terminal.
3019 */ ); 3384 */ );
3020 3385
3021 DEFVAR_BOOL ("inhibit-early-packages", &inhibit_early_packages /* 3386 DEFVAR_BOOL ("inhibit-early-packages", &inhibit_early_packages /*
3062 extents - check extents prior to each extent change; 3427 extents - check extents prior to each extent change;
3063 typecheck - check types strictly, aborting in case of error; 3428 typecheck - check types strictly, aborting in case of error;
3064 malloc - check operation of malloc; 3429 malloc - check operation of malloc;
3065 gc - check garbage collection; 3430 gc - check garbage collection;
3066 bufpos - check buffer positions. 3431 bufpos - check buffer positions.
3432
3433 quick-build - user has requested the "quick-build" configure option.
3067 */ ); 3434 */ );
3068 Vinternal_error_checking = Qnil; 3435 Vinternal_error_checking = Qnil;
3069 #ifdef ERROR_CHECK_EXTENTS 3436 #ifdef ERROR_CHECK_EXTENTS
3070 Vinternal_error_checking = Fcons (intern ("extents"), 3437 Vinternal_error_checking = Fcons (intern ("extents"),
3071 Vinternal_error_checking); 3438 Vinternal_error_checking);
3082 Vinternal_error_checking = Fcons (intern ("gc"), 3449 Vinternal_error_checking = Fcons (intern ("gc"),
3083 Vinternal_error_checking); 3450 Vinternal_error_checking);
3084 #endif 3451 #endif
3085 #ifdef ERROR_CHECK_BUFPOS 3452 #ifdef ERROR_CHECK_BUFPOS
3086 Vinternal_error_checking = Fcons (intern ("bufpos"), 3453 Vinternal_error_checking = Fcons (intern ("bufpos"),
3454 Vinternal_error_checking);
3455 #endif
3456 #ifdef QUICK_BUILD
3457 Vinternal_error_checking = Fcons (intern ("quick-build"),
3087 Vinternal_error_checking); 3458 Vinternal_error_checking);
3088 #endif 3459 #endif
3089 3460
3090 DEFVAR_CONST_LISP ("mail-lock-methods", &Vmail_lock_methods /* 3461 DEFVAR_CONST_LISP ("mail-lock-methods", &Vmail_lock_methods /*
3091 Mail spool locking methods supported by this instance of XEmacs. 3462 Mail spool locking methods supported by this instance of XEmacs.
3106 #endif 3477 #endif
3107 #ifdef HAVE_LOCKING 3478 #ifdef HAVE_LOCKING
3108 Vmail_lock_methods = Fcons (intern ("locking"), Vmail_lock_methods); 3479 Vmail_lock_methods = Fcons (intern ("locking"), Vmail_lock_methods);
3109 #endif 3480 #endif
3110 } 3481 }
3111 3482
3112 DEFVAR_CONST_LISP ("configure-mail-lock-method", &Vconfigure_mail_lock_method /* 3483 DEFVAR_CONST_LISP ("configure-mail-lock-method", &Vconfigure_mail_lock_method /*
3113 Mail spool locking method suggested by configure. This is one 3484 Mail spool locking method suggested by configure. This is one
3114 of the symbols in MAIL-LOCK-METHODS. 3485 of the symbols in MAIL-LOCK-METHODS.
3115 */ ); 3486 */ );
3116 { 3487 {
3222 3593
3223 DEFVAR_LISP ("data-directory", &Vdata_directory /* 3594 DEFVAR_LISP ("data-directory", &Vdata_directory /*
3224 *Directory of architecture-independent files that come with XEmacs, 3595 *Directory of architecture-independent files that come with XEmacs,
3225 intended for XEmacs to use. 3596 intended for XEmacs to use.
3226 Use of this variable in new code is almost never correct. See the 3597 Use of this variable in new code is almost never correct. See the
3227 function `locate-data-directory' and the variable `data-directory-list'. 3598 functions `locate-data-file' and `locate-data-directory' and the variable
3599 `data-directory-list'.
3228 */ ); 3600 */ );
3229 Vdata_directory = Qnil; 3601 Vdata_directory = Qnil;
3230 3602
3231 DEFVAR_LISP ("configure-data-directory", &Vconfigure_data_directory /* 3603 DEFVAR_LISP ("configure-data-directory", &Vconfigure_data_directory /*
3232 For internal use by the build procedure only. 3604 For internal use by the build procedure only.
3243 *List of directories of architecture-independent files that come with XEmacs 3615 *List of directories of architecture-independent files that come with XEmacs
3244 or were installed as packages, and are intended for XEmacs to use. 3616 or were installed as packages, and are intended for XEmacs to use.
3245 */ ); 3617 */ );
3246 Vdata_directory_list = Qnil; 3618 Vdata_directory_list = Qnil;
3247 3619
3248 #ifdef CLASH_DETECTION
3249 DEFVAR_LISP ("configure-lock-directory", &Vconfigure_lock_directory /*
3250 For internal use by the build procedure only.
3251 configure's idea of what LOCK-DIRECTORY will be.
3252 */ );
3253 #ifdef PATH_LOCK
3254 Vconfigure_lock_directory = Ffile_name_as_directory
3255 (build_string ((char *) PATH_LOCK));
3256 #else
3257 Vconfigure_lock_directory = Qnil;
3258 #endif
3259 #endif /* CLASH_DETECTION */
3260
3261 DEFVAR_LISP ("site-directory", &Vsite_directory /* 3620 DEFVAR_LISP ("site-directory", &Vsite_directory /*
3262 *Directory of site-specific Lisp files that come with XEmacs. 3621 *Directory of site-specific Lisp files that come with XEmacs.
3263 */ ); 3622 */ );
3264 Vsite_directory = Qnil; 3623 Vsite_directory = Qnil;
3265 3624
3353 } 3712 }
3354 3713
3355 #if defined(__sgi) && !defined(PDUMP) 3714 #if defined(__sgi) && !defined(PDUMP)
3356 /* This is so tremendously ugly I'd puke. But then, it works. 3715 /* This is so tremendously ugly I'd puke. But then, it works.
3357 * The target is to override the static constructor from the 3716 * The target is to override the static constructor from the
3358 * libiflPNG.so library which is maskerading as libz, and 3717 * libiflPNG.so library which is masquerading as libz, and
3359 * cores on us when re-started from the dumped executable. 3718 * cores on us when re-started from the dumped executable.
3360 * This will have to go for 21.1 -- OG. 3719 * This will have to go for 21.1 -- OG.
3361 */ 3720 */
3362 void __sti__iflPNGFile_c___(void); 3721 void __sti__iflPNGFile_c___(void);
3363 void __sti__iflPNGFile_c___() 3722 void __sti__iflPNGFile_c___()