#include "lisp.h"
+#ifdef HAVE_WINDOW_SYSTEM
+#include TERM_HEADER
+#endif /* HAVE_WINDOW_SYSTEM */
+
#ifdef WINDOWSNT
#include <fcntl.h>
#include <windows.h> /* just for w32.h */
#include "gnutls.h"
#endif
-#ifdef HAVE_NS
-#include "nsterm.h"
-#endif
-
#if (defined PROFILING \
&& (defined __FreeBSD__ || defined GNU_LINUX || defined __MINGW32__))
# include <sys/gmon.h>
extern void moncontrol (int mode);
#endif
-#ifdef HAVE_X_WINDOWS
-#include "xterm.h"
-#endif
-
#ifdef HAVE_SETLOCALE
#include <locale.h>
#endif
#define O_RDWR 2
#endif
-#ifdef HAVE_SETPGID
-#if !defined (USG)
-#undef setpgrp
-#define setpgrp setpgid
-#endif
-#endif
-
static const char emacs_version[] = VERSION;
static const char emacs_copyright[] = "Copyright (C) 2012 Free Software Foundation, Inc.";
-/* Make these values available in GDB, which doesn't see macros. */
-
-#if USE_LSB_TAG
-int gdb_use_lsb EXTERNALLY_VISIBLE = 1;
-#else
-int gdb_use_lsb EXTERNALLY_VISIBLE = 0;
-#endif
-#ifndef CHECK_LISP_OBJECT_TYPE
-int gdb_use_struct EXTERNALLY_VISIBLE = 0;
-#else
-int gdb_use_struct EXTERNALLY_VISIBLE = 1;
-#endif
-int gdb_valbits EXTERNALLY_VISIBLE = VALBITS;
-int gdb_gctypebits EXTERNALLY_VISIBLE = GCTYPEBITS;
-#if defined DATA_SEG_BITS && !USE_LSB_TAG
-uintptr_t gdb_data_seg_bits EXTERNALLY_VISIBLE = DATA_SEG_BITS;
-#else
-uintptr_t gdb_data_seg_bits EXTERNALLY_VISIBLE = 0;
-#endif
-ptrdiff_t PVEC_FLAG EXTERNALLY_VISIBLE = PSEUDOVECTOR_FLAG;
-ptrdiff_t gdb_array_mark_flag EXTERNALLY_VISIBLE = ARRAY_MARK_FLAG;
-/* GDB might say "No enum type named pvec_type" if we don't have at
- least one symbol with that type, and then xbacktrace could fail. */
-enum pvec_type gdb_pvec_type EXTERNALLY_VISIBLE = PVEC_TYPE_MASK;
-
/* Empty lisp strings. To avoid having to build any others. */
Lisp_Object empty_unibyte_string, empty_multibyte_string;
-/* Set nonzero after Emacs has started up the first time.
- Prevents reinitialization of the Lisp world and keymaps
- on subsequent starts. */
-int initialized;
+/* Set after Emacs has started up the first time.
+ Prevents reinitialization of the Lisp world and keymaps
+ on subsequent starts. */
+bool initialized;
#ifdef DARWIN_OS
extern void unexec_init_emacs_zone (void);
extern void *malloc_get_state (void);
/* From glibc, a routine that overwrites the malloc internal state. */
extern int malloc_set_state (void*);
-/* Non-zero if the MALLOC_CHECK_ environment variable was set while
+/* True if the MALLOC_CHECK_ environment variable was set while
dumping. Used to work around a bug in glibc's malloc. */
-static int malloc_using_checking;
+static bool malloc_using_checking;
#endif
Lisp_Object Qfile_name_handler_alist;
Lisp_Object Qkill_emacs;
-/* If non-zero, Emacs should not attempt to use a window-specific code,
+/* If true, Emacs should not attempt to use a window-specific code,
but instead should use the virtual terminal under which it was started. */
-int inhibit_window_system;
+bool inhibit_window_system;
-/* If non-zero, a filter or a sentinel is running. Tested to save the match
+/* If true, a filter or a sentinel is running. Tested to save the match
data on the first attempt to change it inside asynchronous code. */
-int running_asynch_code;
+bool running_asynch_code;
#if defined (HAVE_X_WINDOWS) || defined (HAVE_NS)
-/* If non-zero, -d was specified, meaning we're using some window system. */
-int display_arg;
+/* If true, -d was specified, meaning we're using some window system. */
+bool display_arg;
#endif
/* An address near the bottom of the stack.
static uprintmax_t heap_bss_diff;
#endif
-/* Nonzero means running Emacs without interactive terminal. */
-int noninteractive;
+/* True means running Emacs without interactive terminal. */
+bool noninteractive;
-/* Nonzero means remove site-lisp directories from load-path. */
-int no_site_lisp;
+/* True means remove site-lisp directories from load-path. */
+bool no_site_lisp;
/* Name for the server started by the daemon.*/
static char *daemon_name;
/* Signal code for the fatal signal that was received. */
static int fatal_error_code;
-/* Nonzero if handling a fatal error already. */
-int fatal_error_in_progress;
-
-/* If non-null, call this function from fatal_error_signal before
- committing suicide. */
-
-static void (*fatal_error_signal_hook) (void);
+/* True if handling a fatal error already. */
+bool fatal_error_in_progress;
#ifdef FORWARD_SIGNAL_TO_MAIN_THREAD
/* When compiled with GTK and running under Gnome,
if (sig == SIGTERM || sig == SIGHUP || sig == SIGINT)
Fkill_emacs (make_number (sig));
- shut_down_emacs (sig, 0, Qnil);
+ shut_down_emacs (sig, Qnil);
}
/* Signal the same code; this time it will really be fatal.
sigunblock (sigmask (fatal_error_code));
#endif
- if (fatal_error_signal_hook)
- fatal_error_signal_hook ();
-
kill (getpid (), fatal_error_code);
}
force_auto_save_soon ();
}
#endif
-
-/* We define abort, rather than using it from the library,
- so that GDB can return from a breakpoint here.
- MSDOS has its own definition in msdos.c. */
-
-#if ! defined (DOS_NT) && ! defined (NO_ABORT)
-
-void
-abort (void)
-{
- kill (getpid (), SIGABRT);
- /* This shouldn't be executed, but it prevents a warning. */
- exit (1);
-}
-#endif
-
\f
/* Code for dealing with Lisp access to the Unix command line. */
if (!NILP (Vinvocation_directory))
{
dir = Vinvocation_directory;
+#ifdef WINDOWSNT
+ /* If we are running from the build directory, set DIR to the
+ src subdirectory of the Emacs tree, like on Posix
+ platforms. */
+ if (SBYTES (dir) > sizeof ("/i386/") - 1
+ && 0 == strcmp (SSDATA (dir) + SBYTES (dir) - sizeof ("/i386/") + 1,
+ "/i386/"))
+ dir = Fexpand_file_name (build_string ("../.."), dir);
+#else /* !WINDOWSNT */
+#endif
name = Fexpand_file_name (Vinvocation_name, dir);
while (1)
{
/* Define a dummy function F. Declare F too, to pacify gcc
-Wmissing-prototypes. */
#define DEFINE_DUMMY_FUNCTION(f) \
- void f (void) EXTERNALLY_VISIBLE; void f (void) {}
+ void f (void) ATTRIBUTE_CONST EXTERNALLY_VISIBLE; void f (void) {}
#ifndef GCC_CTORS_IN_LIBC
DEFINE_DUMMY_FUNCTION (__do_global_ctors)
Too bad we can't just use getopt for all of this, but we don't have
enough information to do it right. */
-static int
+static bool
argmatch (char **argv, int argc, const char *sstr, const char *lstr,
int minlen, char **valptr, int *skipptr)
{
static void
malloc_initialize_hook (void)
{
-#ifndef USE_CRT_DLL
- extern char **environ;
-#endif
-
if (initialized)
{
if (!malloc_using_checking)
Lisp_Object dummy;
#endif
char stack_bottom_variable;
- int do_initial_setlocale;
+ bool do_initial_setlocale;
int skip_args = 0;
#ifdef HAVE_SETRLIMIT
struct rlimit rlim;
#endif
- int no_loadup = 0;
+ bool no_loadup = 0;
char *junk = 0;
char *dname_arg = 0;
#ifdef NS_IMPL_COCOA
init_alloc_once ();
init_obarray ();
init_eval_once ();
- init_character_once ();
init_charset_once ();
init_coding_once ();
init_syntax_once (); /* Create standard syntax table. */
init_eval ();
init_data ();
-#ifdef CLASH_DETECTION
- init_filelock ();
-#endif
init_atimer ();
running_asynch_code = 0;
+ init_random ();
no_loadup
= argmatch (argv, argc, "-nl", "--no-loadup", 6, NULL, &skip_args);
init_ntproc (); /* must precede init_editfns. */
#endif
-#ifdef HAVE_NS
-#ifndef CANNOT_DUMP
- if (initialized)
-#endif
- ns_init_paths ();
-#endif
-
/* Initialize and GC-protect Vinitial_environment and
Vprocess_environment before set_initial_environment fills them
in. */
init_callproc (); /* Must follow init_cmdargs but not init_sys_modes. */
init_lread ();
+#ifdef WINDOWSNT
+ /* Check to see if Emacs has been installed correctly. */
+ check_windows_init_file ();
+#endif
/* Intern the names of all standard functions and variables;
define standard keys. */
init_charset ();
- init_editfns (); /* init_process uses Voperating_system_release. */
- init_process (); /* init_display uses add_keyboard_wait_descriptor. */
+ init_editfns (); /* init_process_emacs uses Voperating_system_release. */
+ init_process_emacs (); /* init_display uses add_keyboard_wait_descriptor. */
init_keyboard (); /* This too must precede init_sys_modes. */
if (!noninteractive)
init_display (); /* Determine terminal type. Calls init_sys_modes. */
- init_fns ();
init_xdisp ();
#ifdef HAVE_WINDOW_SYSTEM
init_fringe ();
- init_image ();
#endif /* HAVE_WINDOW_SYSTEM */
init_macros ();
init_floatfns ();
-#ifdef HAVE_SOUND
- init_sound ();
-#endif
init_window ();
init_font ();
static void
sort_args (int argc, char **argv)
{
- char **new = (char **) xmalloc (sizeof (char *) * argc);
+ char **new = xmalloc (argc * sizeof *new);
/* For each element of argv,
the corresponding element of options is:
0 for an option that takes no arguments,
}
if (best < 0)
- abort ();
+ emacs_abort ();
/* Copy the highest priority remaining option, with its args, to NEW.
Unless it is a duplicate of the previous one. */
x_clipboard_manager_save_all ();
#endif
- shut_down_emacs (0, 0, STRINGP (arg) ? arg : Qnil);
+ shut_down_emacs (0, STRINGP (arg) ? arg : Qnil);
#ifdef HAVE_NS
ns_release_autorelease_pool (ns_pool);
and Fkill_emacs. */
void
-shut_down_emacs (int sig, int no_x, Lisp_Object stuff)
+shut_down_emacs (int sig, Lisp_Object stuff)
{
/* Prevent running of hooks from now on. */
Vrun_hooks = Qnil;
unlock_all_files ();
#endif
-#if 0 /* This triggers a bug in XCloseDisplay and is not needed. */
-#ifdef HAVE_X_WINDOWS
- /* It's not safe to call intern here. Maybe we are crashing. */
- if (!noninteractive && SYMBOLP (Vinitial_window_system)
- && SCHARS (SYMBOL_NAME (Vinitial_window_system)) == 1
- && SREF (SYMBOL_NAME (Vinitial_window_system), 0) == 'x'
- && ! no_x)
- Fx_close_current_connection ();
-#endif /* HAVE_X_WINDOWS */
-#endif
-
#ifdef SIGIO
/* There is a tendency for a SIGIO signal to arrive within exit,
and cause a SIGHUP because the input descriptor is already closed. */
}
#endif /* HAVE_SETLOCALE */
\f
-#ifndef SEPCHAR
-#define SEPCHAR ':'
-#endif
Lisp_Object
decode_env_path (const char *evarname, const char *defalt)
{
const char *path, *p;
Lisp_Object lpath, element, tem;
+#ifdef WINDOWSNT
+ bool defaulted = 0;
+ const char *emacs_dir = egetenv ("emacs_dir");
+ static const char *emacs_dir_env = "%emacs_dir%/";
+ const size_t emacs_dir_len = strlen (emacs_dir_env);
+#endif
/* It's okay to use getenv here, because this function is only used
to initialize variables when Emacs starts up, and isn't called
else
path = 0;
if (!path)
- path = defalt;
+ {
+ path = defalt;
+#ifdef WINDOWSNT
+ defaulted = 1;
+#endif
+ }
#ifdef DOS_NT
/* Ensure values from the environment use the proper directory separator. */
if (path)
p = path + strlen (path);
element = (p - path ? make_string (path, p - path)
: build_string ("."));
+#ifdef WINDOWSNT
+ /* Relative file names in the default path are interpreted as
+ being relative to $emacs_dir. */
+ if (emacs_dir && defaulted
+ && strncmp (path, emacs_dir_env, emacs_dir_len) == 0)
+ element = Fexpand_file_name (Fsubstring (element,
+ make_number (emacs_dir_len),
+ Qnil),
+ build_string (emacs_dir));
+#endif
/* Add /: to the front of the name
if it would otherwise be treated as magic. */
(void)
{
int nfd;
- int err = 0;
+ bool err = 0;
if (!IS_DAEMON)
error ("This function can only be called if emacs is run as a daemon");
Anything else (in Emacs 24.1, the possibilities are: aix, berkeley-unix,
hpux, irix, usg-unix-v) indicates some sort of Unix system. */);
Vsystem_type = intern_c_string (SYSTEM_TYPE);
- /* The above values are from SYSTEM_TYPE in include files under src/s. */
+ /* See configure.ac (and config.nt) for the possible SYSTEM_TYPEs. */
DEFVAR_LISP ("system-configuration", Vsystem_configuration,
doc: /* Value is string indicating configuration Emacs was built for.
doc: /* Non-nil means Emacs is running without interactive terminal. */);
DEFVAR_LISP ("kill-emacs-hook", Vkill_emacs_hook,
- doc: /* Hook to be run when `kill-emacs' is called.
+ doc: /* Hook run when `kill-emacs' is called.
Since `kill-emacs' may be invoked when the terminal is disconnected (or
in other similar situations), functions placed on this hook should not
expect to be able to interact with the user. To ask for confirmation,