X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/9b33d5960f6dc5bd0e41d679841661096dbd7f30..9e2f5050bc4da8360c53e740445268f34fc26292:/src/emacs.c diff --git a/src/emacs.c b/src/emacs.c index fc158693e4..1377a3d6b3 100644 --- a/src/emacs.c +++ b/src/emacs.c @@ -1,6 +1,6 @@ /* Fully extensible Emacs, running on Unix, intended for GNU. - Copyright (C) 1985,86,87,93,94,95,97,98,1999,2001,02,03,2004 - Free Software Foundation, Inc. + Copyright (C) 1985, 1986, 1987, 1993, 1994, 1995, 1997, 1998, 1999, + 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. This file is part of GNU Emacs. @@ -16,8 +16,8 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Emacs; see the file COPYING. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, -Boston, MA 02111-1307, USA. */ +the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +Boston, MA 02110-1301, USA. */ #include @@ -42,6 +42,9 @@ Boston, MA 02111-1307, USA. */ #ifdef WINDOWSNT #include +#include /* just for w32.h */ +#include "w32.h" +#include "w32heap.h" /* for prototype of sbrk */ #endif #include "lisp.h" @@ -109,6 +112,9 @@ EMACS_INT gdb_data_seg_bits = 0; #endif EMACS_INT PVEC_FLAG = PSEUDOVECTOR_FLAG; EMACS_INT gdb_array_mark_flag = 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 = PVEC_TYPE_MASK; /* Command line args from shell, as list of strings. */ Lisp_Object Vcommand_line_args; @@ -145,7 +151,7 @@ void *malloc_state_ptr; /* From glibc, a routine that returns a copy of the malloc internal state. */ extern void *malloc_get_state (); /* From glibc, a routine that overwrites the malloc internal state. */ -extern void malloc_set_state (); +extern int malloc_set_state (); /* Non-zero if the MALLOC_CHECK_ enviroment variable was set while dumping. Used to work around a bug in glibc's malloc. */ int malloc_using_checking; @@ -248,7 +254,7 @@ Run Emacs, the extensible, customizable, self-documenting real-time\n\ display editor. The recommended way to start Emacs for normal editing\n\ is with no options at all.\n\ \n\ -Run M-x info RET m emacs RET m command arguments RET inside Emacs to\n\ +Run M-x info RET m emacs RET m emacs invocation RET inside Emacs to\n\ read the main documentation for these command-line arguments.\n\ \n\ Initialization options:\n\ @@ -262,7 +268,8 @@ Initialization options:\n\ --no-shared-memory, -nl do not use shared memory\n\ --no-site-file do not load site-start.el\n\ --no-splash do not display a splash screen on startup\n\ ---no-window-system, -nw don't communicate with X, ignoring $DISPLAY\n\ +--no-window-system, -nw do not communicate with X, ignoring $DISPLAY\n\ +--quick, -Q equivalent to -q --no-site-file --no-splash\n\ --script FILE run FILE as an Emacs Lisp script\n\ --terminal, -t DEVICE use DEVICE for terminal I/O\n\ --unibyte, --no-multibyte run Emacs in unibyte mode\n\ @@ -292,9 +299,11 @@ FILE visit FILE using find-file\n\ Display options:\n\ \n\ --background-color, -bg COLOR window background color\n\ +--basic-display, -D disable many display features;\n\ + used for debugging Emacs\n\ --border-color, -bd COLOR main border color\n\ --border-width, -bw WIDTH width of main border\n\ ---color MODE color mode for character terminals;\n\ +--color, --color=MODE color mode for character terminals;\n\ MODE defaults to `auto', and can also\n\ be `never', `auto', `always',\n\ or a mode name like `ansi8'\n\ @@ -305,28 +314,29 @@ Display options:\n\ --fullscreen, -fs make first frame fullscreen\n\ --fullwidth, -fw make the first frame wide as the screen\n\ --geometry, -g GEOMETRY window geometry\n\ ---icon-type, -i use picture of gnu for Emacs icon\n\ +--no-bitmap-icon, -nbi do not use picture of gnu for Emacs icon\n\ --iconic start Emacs in iconified state\n\ --internal-border, -ib WIDTH width between text and main border\n\ --line-spacing, -lsp PIXELS additional space to put between lines\n\ --mouse-color, -ms COLOR mouse cursor color in Emacs window\n\ --name NAME title for initial Emacs frame\n\ +--no-blinking-cursor, -nbc disable blinking cursor\n\ --reverse-video, -r, -rv switch foreground and background\n\ --title, -T TITLE title for initial Emacs frame\n\ --vertical-scroll-bars, -vb enable vertical scroll bars\n\ --xrm XRESOURCES set additional X resources\n\ --help display this help and exit\n\ --version output version information and exit\n\ -\n\ +\n" + +#define USAGE4 "\ You can generally also specify long option names with a single -; for\n\ example, -batch as well as --batch. You can use any unambiguous\n\ abbreviation for a --option.\n\ \n\ Various environment variables and window system resources also affect\n\ Emacs' operation. See the main documentation.\n\ -\n" - -#define USAGE4 "\ +\n\ Report bugs to %s. First, please see the Bugs\n\ section of the Emacs manual or the file BUGS.\n" @@ -342,6 +352,14 @@ int fatal_error_in_progress; void (*fatal_error_signal_hook) P_ ((void)); +#ifdef HAVE_GTK_AND_PTHREAD +/* When compiled with GTK and running under Gnome, multiple threads meay be + created. Keep track of our main thread to make sure signals are delivered + to it (see syssignal.h). */ + +pthread_t main_thread; +#endif + #ifdef SIGUSR1 SIGTYPE @@ -350,6 +368,7 @@ handle_USR1_signal (sig) { struct input_event buf; + SIGNAL_THREAD_CHECK (sig); bzero (&buf, sizeof buf); buf.kind = USER_SIGNAL_EVENT; buf.frame_or_window = selected_frame; @@ -365,6 +384,7 @@ handle_USR2_signal (sig) { struct input_event buf; + SIGNAL_THREAD_CHECK (sig); bzero (&buf, sizeof buf); buf.kind = USER_SIGNAL_EVENT; buf.code = 1; @@ -379,6 +399,7 @@ SIGTYPE fatal_error_signal (sig) int sig; { + SIGNAL_THREAD_CHECK (sig); fatal_error_code = sig; signal (sig, SIG_DFL); @@ -418,6 +439,7 @@ memory_warning_signal (sig) int sig; { signal (sig, memory_warning_signal); + SIGNAL_THREAD_CHECK (sig); malloc_warning ("Operating system warns that virtual memory is running low.\n"); @@ -580,8 +602,12 @@ init_cmdargs (argc, argv, skip_args) for (i = argc - 1; i >= 0; i--) { if (i == 0 || i > skip_args) + /* For the moment, we keep arguments as is in unibyte strings. + They are decoded in the function command-line after we know + locale-coding-system. */ Vcommand_line_args - = Fcons (build_string (argv[i]), Vcommand_line_args); + = Fcons (make_unibyte_string (argv[i], strlen (argv[i])), + Vcommand_line_args); } unbind_to (count, Qnil); @@ -744,7 +770,9 @@ malloc_initialize_hook () } malloc_set_state (malloc_state_ptr); +#ifndef XMALLOC_OVERRUN_CHECK free (malloc_state_ptr); +#endif } else { @@ -871,7 +899,7 @@ main (argc, argv else { printf ("GNU Emacs %s\n", SDATA (tem)); - printf ("Copyright (C) 2004 Free Software Foundation, Inc.\n"); + printf ("Copyright (C) 2006 Free Software Foundation, Inc.\n"); printf ("GNU Emacs comes with ABSOLUTELY NO WARRANTY.\n"); printf ("You may redistribute copies of Emacs\n"); printf ("under the terms of the GNU General Public License.\n"); @@ -893,7 +921,13 @@ main (argc, argv { /* Set this so we only do this once. */ putenv("EMACS_HEAP_EXEC=true"); - personality (PER_LINUX32); + + /* A flag to turn off address randomization which is introduced + in linux kernel shipped with fedora core 4 */ +#define ADD_NO_RANDOMIZE 0x0040000 + personality (PER_LINUX32 | ADD_NO_RANDOMIZE); +#undef ADD_NO_RANDOMIZE + execvp (argv[0], argv); /* If the exec fails, try to dump anyway. */ @@ -931,9 +965,15 @@ main (argc, argv #ifdef MAC_OSX /* Skip process serial number passed in the form -psn_x_y as - command-line argument. */ + command-line argument. The WindowServer adds this option when + Emacs is invoked from the Finder or by the `open' command. In + these cases, the working directory becomes `/', so we change it + to the user's home directory. */ if (argc > skip_args + 1 && strncmp (argv[skip_args+1], "-psn_", 5) == 0) - skip_args++; + { + chdir (getenv ("HOME")); + skip_args++; + } #endif /* MAC_OSX */ #ifdef VMS @@ -970,7 +1010,7 @@ main (argc, argv && !getrlimit (RLIMIT_STACK, &rlim)) { long newlim; - extern int re_max_failures; + extern size_t re_max_failures; /* Approximate the amount regex.c needs per unit of re_max_failures. */ int ratio = 20 * sizeof (char *); /* Then add 33% to cover the size of the smaller stacks that regex.c @@ -1017,10 +1057,16 @@ main (argc, argv Also call realloc and free for consistency. */ free (realloc (malloc (4), 4)); +# ifndef SYNC_INPUT /* Arrange to disable interrupt input inside malloc etc. */ uninterrupt_malloc (); +# endif /* not SYNC_INPUT */ #endif /* not SYSTEM_MALLOC */ +#ifdef HAVE_GTK_AND_PTHREAD + main_thread = pthread_self (); +#endif /* HAVE_GTK_AND_PTHREAD */ + #if defined (MSDOS) || defined (WINDOWSNT) /* We do all file input/output as binary files. When we need to translate newlines, we do that manually. */ @@ -1109,13 +1155,16 @@ main (argc, argv /* Handle the -batch switch, which means don't do interactive display. */ noninteractive = 0; if (argmatch (argv, argc, "-batch", "--batch", 5, NULL, &skip_args)) - noninteractive = 1; + { + noninteractive = 1; + Vundo_outer_limit = Qnil; + } if (argmatch (argv, argc, "-script", "--script", 3, &junk, &skip_args)) { noninteractive = 1; /* Set batch mode. */ - /* Convert --script to -l, un-skip it, and sort again so that -l will be - handled in proper sequence. */ - argv[skip_args - 1] = "-l"; + /* Convert --script to --scriptload, un-skip it, and sort again + so that it will be handled in proper sequence. */ + argv[skip_args - 1] = "-scriptload"; skip_args -= 2; sort_args (argc, argv); } @@ -1279,7 +1328,7 @@ main (argc, argv creates a full-fledge output_mac type frame. This does not work correctly before syms_of_textprop, syms_of_macfns, syms_of_ccl, syms_of_fontset, syms_of_xterm, syms_of_search, - syms_of_frame, mac_initialize, and init_keyboard have already + syms_of_frame, mac_term_init, and init_keyboard have already been called. */ syms_of_textprop (); syms_of_macfns (); @@ -1287,11 +1336,13 @@ main (argc, argv syms_of_fontset (); syms_of_macterm (); syms_of_macmenu (); + syms_of_macselect (); syms_of_data (); syms_of_search (); syms_of_frame (); - mac_initialize (); + init_atimer (); + mac_term_init (build_string ("Mac"), NULL, NULL); init_keyboard (); #endif @@ -1316,7 +1367,9 @@ main (argc, argv #ifdef CLASH_DETECTION init_filelock (); #endif +#ifndef MAC_OS8 init_atimer (); +#endif running_asynch_code = 0; /* Handle --unibyte and the EMACS_UNIBYTE envvar, @@ -1453,7 +1506,7 @@ main (argc, argv init_ntproc (); /* must precede init_editfns. */ #endif -#ifdef HAVE_CARBON +#if defined (MAC_OSX) && defined (HAVE_CARBON) if (initialized) init_mac_osx_environment (); #endif @@ -1580,14 +1633,12 @@ main (argc, argv #endif #endif /* HAVE_X_WINDOWS */ -#ifdef HAVE_MENUS #ifndef HAVE_NTGUI #ifndef MAC_OS /* Called before init_window_once for Mac OS Classic. */ syms_of_xmenu (); #endif #endif -#endif #ifdef HAVE_NTGUI syms_of_w32term (); @@ -1597,12 +1648,13 @@ main (argc, argv syms_of_fontset (); #endif /* HAVE_NTGUI */ -#ifdef HAVE_CARBON +#if defined (MAC_OSX) && defined (HAVE_CARBON) syms_of_macterm (); syms_of_macfns (); syms_of_macmenu (); + syms_of_macselect (); syms_of_fontset (); -#endif /* HAVE_CARBON */ +#endif /* MAC_OSX && HAVE_CARBON */ #ifdef SYMS_SYSTEM SYMS_SYSTEM; @@ -1627,6 +1679,7 @@ main (argc, argv #ifdef HAVE_NTGUI globals_of_w32fns (); globals_of_w32menu (); + globals_of_w32select (); #endif /* HAVE_NTGUI */ } @@ -1696,16 +1749,21 @@ main (argc, argv #endif } - /* Set up for profiling. This is known to work on FreeBSD and - GNU/Linux. It might work on some other systems too. Give it a - try and tell us if it works on your system. To compile for - profiling use something like `make CFLAGS="-pg -g -O -DPROFILING=1'. */ -#if defined (__FreeBSD__) || defined (__linux) + /* Set up for profiling. This is known to work on FreeBSD, + GNU/Linux and MinGW. It might work on some other systems too. + Give it a try and tell us if it works on your system. To compile + for profiling use something like: + `make CFLAGS="-pg -g -O -DPROFILING=1'. */ +#if defined (__FreeBSD__) || defined (GNU_LINUX) || defined(__MINGW32__) #ifdef PROFILING if (initialized) { extern void _mcleanup (); +#ifdef __MINGW32__ + extern unsigned char etext asm ("etext"); +#else extern char etext; +#endif extern void safe_bcopy (); extern void dump_opcode_frequencies (); @@ -1775,6 +1833,8 @@ struct standard_args standard_args[] = { "-d", "--display", 60, 1 }, { "-display", 0, 60, 1 }, /* Now for the options handled in startup.el. */ + { "-Q", "--quick", 55, 0 }, + { "-quick", 0, 55, 0 }, { "-q", "--no-init-file", 50, 0 }, { "-no-init-file", 0, 50, 0 }, { "-no-site-file", "--no-site-file", 40, 0 }, @@ -1782,9 +1842,10 @@ struct standard_args standard_args[] = { "-u", "--user", 30, 1 }, { "-user", 0, 30, 1 }, { "-debug-init", "--debug-init", 20, 0 }, - { "-i", "--icon-type", 15, 0 }, - { "-itype", 0, 15, 0 }, + { "-nbi", "--no-bitmap-icon", 15, 0 }, { "-iconic", "--iconic", 15, 0 }, + { "-D", "--basic-display", 12, 0}, + { "-basic-display", 0, 12, 0}, { "-bg", "--background-color", 10, 1 }, { "-background", 0, 10, 1 }, { "-fg", "--foreground-color", 10, 1 }, @@ -1794,6 +1855,7 @@ struct standard_args standard_args[] = { "-ib", "--internal-border", 10, 1 }, { "-ms", "--mouse-color", 10, 1 }, { "-cr", "--cursor-color", 10, 1 }, + { "-nbc", "--no-blinking-cursor", 10, 0 }, { "-fn", "--font", 10, 1 }, { "-font", 0, 10, 1 }, { "-fs", "--fullscreen", 10, 0 }, @@ -1817,6 +1879,7 @@ struct standard_args standard_args[] = { "-directory", 0, 0, 1 }, { "-l", "--load", 0, 1 }, { "-load", 0, 0, 1 }, + { "-scriptload", "--scriptload", 0, 1 }, { "-f", "--funcall", 0, 1 }, { "-funcall", 0, 0, 1 }, { "-eval", "--eval", 0, 1 }, @@ -1980,15 +2043,15 @@ sort_args (argc, argv) bcopy (new, argv, sizeof (char *) * argc); - free (options); - free (new); - free (priority); + xfree (options); + xfree (new); + xfree (priority); } DEFUN ("kill-emacs", Fkill_emacs, Skill_emacs, 0, 1, "P", doc: /* Exit the Emacs job and kill it. If ARG is an integer, return ARG as the exit program code. -If ARG is a string, stuff it as keyboard input. +If ARG is a string, stuff it as keyboard input. The value of `kill-emacs-hook', if not void, is a list of functions (of no args), @@ -2022,14 +2085,9 @@ all of which are called before Emacs is actually killed. */) if (STRINGP (Vauto_save_list_file_name)) unlink (SDATA (Vauto_save_list_file_name)); - exit (INTEGERP (arg) ? XINT (arg) -#ifdef VMS - : 1 -#else - : 0 -#endif - ); + exit (INTEGERP (arg) ? XINT (arg) : EXIT_SUCCESS); /* NOTREACHED */ + return Qnil; } @@ -2077,6 +2135,9 @@ shut_down_emacs (sig, no_x, stuff) stuff_buffered_input (stuff); +#ifdef subprocesses + inhibit_sentinels = 1; +#endif kill_buffer_processes (Qnil); Fdo_auto_save (Qt, Qnil); @@ -2179,7 +2240,7 @@ You must run Emacs in batch mode in order to dump it. */) if (! noninteractive) error ("Dumping Emacs works only in batch mode"); -#ifdef __linux__ +#ifdef GNU_LINUX if (heap_bss_diff > MAX_HEAP_BSS_DIFF) { fprintf (stderr, "**************************************************\n"); @@ -2191,7 +2252,7 @@ You must run Emacs in batch mode in order to dump it. */) fprintf (stderr, "exec-shield in etc/PROBLEMS for more information.\n"); fprintf (stderr, "**************************************************\n"); } -#endif /* __linux__ */ +#endif /* GNU_LINUX */ /* Bind `command-line-processed' to nil before dumping, so that the dumped Emacs will process its command line @@ -2232,6 +2293,12 @@ You must run Emacs in batch mode in order to dump it. */) memory_warnings (my_edata, malloc_warning); #endif /* not WINDOWSNT */ #endif +#if !defined (SYSTEM_MALLOC) && defined (HAVE_GTK_AND_PTHREAD) && !defined SYNC_INPUT + /* Pthread may call malloc before main, and then we will get an endless + loop, because pthread_self (see alloc.c) calls malloc the first time + it is called on some systems. */ + reset_malloc_hooks (); +#endif #ifdef DOUG_LEA_MALLOC malloc_state_ptr = malloc_get_state (); #endif @@ -2397,7 +2464,16 @@ syms_of_emacs () Many arguments are deleted from the list as they are processed. */); DEFVAR_LISP ("system-type", &Vsystem_type, - doc: /* Value is symbol indicating type of operating system you are using. */); + doc: /* Value is symbol indicating type of operating system you are using. +Special values: + `gnu/linux' compiled for a GNU/Linux system. + `darwin' compiled for Darwin (GNU-Darwin, Mac OS X, ...). + `macos' compiled for Mac OS 9. + `ms-dos' compiled as an MS-DOS application. + `windows-nt' compiled as a native W32 application. + `cygwin' compiled using the Cygwin library. + `vax-vms' or `axp-vms': compiled for a (Open)VMS system. +Anything else indicates some sort of Unix system. */); Vsystem_type = intern (SYSTEM_TYPE); DEFVAR_LISP ("system-configuration", &Vsystem_configuration,