Bugfix festival.
[bpt/emacs.git] / src / emacs.c
index 5d4f24d..62b550a 100644 (file)
@@ -1,5 +1,5 @@
 /* Fully extensible Emacs, running on Unix, intended for GNU.
-   Copyright (C) 1985,86,87,93,94,95,97,98,1999,2001,2002
+   Copyright (C) 1985,86,87,93,94,95,97,98,1999,2001,02,2003
       Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
@@ -40,10 +40,15 @@ Boston, MA 02111-1307, USA.  */
 #include <sys/ioctl.h>
 #endif
 
+#ifdef WINDOWSNT
+#include <fcntl.h>
+#endif
+
 #include "lisp.h"
 #include "commands.h"
 #include "intervals.h"
 #include "buffer.h"
+#include "window.h"
 
 #include "systty.h"
 #include "blockinput.h"
@@ -87,7 +92,7 @@ EMACS_INT gdb_emacs_intbits = sizeof (EMACS_INT) * BITS_PER_CHAR;
 #ifdef DATA_SEG_BITS
 EMACS_INT gdb_data_seg_bits = DATA_SEG_BITS;
 #else
-EMACS_INT  gdb_data_seg_bits = 0;
+EMACS_INT gdb_data_seg_bits = 0;
 #endif
 EMACS_INT PVEC_FLAG = PSEUDOVECTOR_FLAG;
 
@@ -158,7 +163,7 @@ Lisp_Object Vprevious_system_messages_locale;
 Lisp_Object Vsystem_time_locale;
 Lisp_Object Vprevious_system_time_locale;
 
-/* If non-zero, emacs should not attempt to use an window-specific code,
+/* If non-zero, 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;
 
@@ -228,6 +233,7 @@ read the main documentation for these command-line arguments.\n\
 Initialization options:\n\
 \n\
 --batch                        do not do interactive display; implies -q\n\
+--script FILE           run FILE as an Emacs Lisp script.\n\
 --debug-init           enable Emacs Lisp debugger during init file\n\
 --help                 display this help message and exit\n\
 --multibyte, --no-unibyte   run Emacs in multibyte mode\n\
@@ -600,7 +606,7 @@ void __do_global_ctors_aux ()
 {}
 void __do_global_dtors ()
 {}
-/* Linux has a bug in its library; avoid an error.  */
+/* GNU/Linux has a bug in its library; avoid an error.  */
 #ifndef GNU_LINUX
 char * __CTOR_LIST__[2] = { (char *) (-1), 0 };
 #endif
@@ -761,10 +767,16 @@ bug_reporting_address ()
 
 /* ARGSUSED */
 int
-main (argc, argv, envp)
+main (argc, argv
+#ifdef VMS
+, envp
+#endif
+)
      int argc;
      char **argv;
+#ifdef VMS
      char **envp;
+#endif
 {
 #if GC_MARK_STACK
   Lisp_Object dummy;
@@ -779,6 +791,7 @@ main (argc, argv, envp)
   struct rlimit rlim;
 #endif
   int no_loadup = 0;
+  char *junk = 0;
 
 #if GC_MARK_STACK
   extern Lisp_Object *stack_base;
@@ -946,11 +959,13 @@ main (argc, argv, envp)
   uninterrupt_malloc ();
 #endif /* not SYSTEM_MALLOC */
 
-#ifdef MSDOS
+#if defined (MSDOS) || defined (WINDOWSNT)
   /* We do all file input/output as binary files.  When we need to translate
      newlines, we do that manually.  */
   _fmode = O_BINARY;
+#endif /* MSDOS || WINDOWSNT */
 
+#ifdef MSDOS
 #if __DJGPP__ >= 2
   if (!isatty (fileno (stdin)))
     setmode (fileno (stdin), O_BINARY);
@@ -1033,6 +1048,15 @@ main (argc, argv, envp)
   noninteractive = 0;
   if (argmatch (argv, argc, "-batch", "--batch", 5, NULL, &skip_args))
     noninteractive = 1;
+  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";
+      skip_args -= 2;
+      sort_args (argc, argv);
+    }
 
   /* Handle the --help option, which gives a usage message.  */
   if (argmatch (argv, argc, "-help", "--help", 3, NULL, &skip_args))
@@ -1358,12 +1382,13 @@ main (argc, argv, envp)
 #endif /* MSDOS */
 
 #ifdef WINDOWSNT
+  globals_of_w32 ();
   /* Initialize environment from registry settings.  */
   init_environment (argv);
   init_ntproc ();      /* must precede init_editfns.  */
 #endif
 
-#ifdef MAC_OSX
+#ifdef HAVE_CARBON
   if (initialized)
     init_mac_osx_environment ();
 #endif
@@ -1524,14 +1549,18 @@ main (argc, argv, envp)
       keys_of_minibuf ();
       keys_of_window ();
     }
-
-  if (!noninteractive)
+       else
     {
-#ifdef VMS
-      init_vms_input ();/* init_display calls get_frame_size, that needs this.  */
-#endif /* VMS */
-      init_display (); /* Determine terminal type.  init_sys_modes uses results.  */
+      /*
+        Initialization that must be done even if the global variable
+        initialized is non zero
+      */
+#ifdef HAVE_NTGUI
+      globals_of_w32fns ();
+      globals_of_w32menu ();
+#endif  /* end #ifdef HAVE_NTGUI */
     }
+
 #ifndef MAC_OS8
   /* Called before init_window_once for Mac OS Classic.  */
   init_keyboard ();    /* This too must precede init_sys_modes.  */
@@ -1539,7 +1568,13 @@ main (argc, argv, envp)
 #ifdef VMS
   init_vmsproc ();     /* And this too.  */
 #endif /* VMS */
-  init_sys_modes ();   /* Init system terminal modes (RAW or CBREAK, etc.).  */
+  if (!noninteractive)
+    {
+#ifdef VMS
+      init_vms_input ();/* init_display calls get_tty_size, that needs this.  */
+#endif /* VMS */
+      init_display (); /* Determine terminal type.  Calls init_sys_modes.  */
+    }
 #if defined (HAVE_X_WINDOWS) || defined (WINDOWSNT)
   init_xfns ();
 #endif /* HAVE_X_WINDOWS */
@@ -1658,6 +1693,7 @@ struct standard_args standard_args[] =
   { "-nw", "--no-window-system", 110, 0 },
   { "-nw", "--no-windows", 110, 0 },
   { "-batch", "--batch", 100, 0 },
+  { "-script", "--script", 100, 1 },
   { "-help", "--help", 90, 0 },
   { "-no-unibyte", "--no-unibyte", 83, 0 },
   { "-multibyte", "--multibyte", 82, 0 },
@@ -1873,9 +1909,9 @@ sort_args (argc, argv)
 
   bcopy (new, argv, sizeof (char *) * argc);
 
-  free (options);
-  free (new);
-  free (priority);
+  xfree (options);
+  xfree (new);
+  xfree (priority);
 }
 \f
 DEFUN ("kill-emacs", Fkill_emacs, Skill_emacs, 0, 1, "P",
@@ -1955,14 +1991,14 @@ shut_down_emacs (sig, no_x, stuff)
        && tpgrp == pgrp)
       {
        fflush (stdout);
-       reset_sys_modes ();
+       reset_all_sys_modes ();
        if (sig && sig != SIGTERM)
-         fprintf (stderr, "Fatal error (%d).", sig);
+         fprintf (stderr, "Fatal error (%d)", sig);
       }
   }
 #else
   fflush (stdout);
-  reset_sys_modes ();
+  reset_all_sys_modes ();
 #endif
 
   stuff_buffered_input (stuff);
@@ -2226,6 +2262,17 @@ decode_env_path (evarname, defalt)
       /* Add /: to the front of the name
         if it would otherwise be treated as magic.  */
       tem = Ffind_file_name_handler (element, Qt);
+
+      /* However, if the handler says "I'm safe",
+        don't bother adding /:.  */
+      if (SYMBOLP (tem))
+       {
+         Lisp_Object prop;
+         prop = Fget (tem, intern ("safe-magic"));
+         if (! NILP (prop))
+           tem = Qnil;
+       }
+
       if (! NILP (tem))
        element = concat2 (build_string ("/:"), element);
 
@@ -2258,7 +2305,8 @@ syms_of_emacs ()
   defsubr (&Sinvocation_directory);
 
   DEFVAR_LISP ("command-line-args", &Vcommand_line_args,
-              doc: /* Args passed by shell to Emacs, as a list of strings.  */);
+              doc: /* Args passed by shell to Emacs, as a list of strings.
+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.  */);
@@ -2278,11 +2326,13 @@ Emacs is running.  */);
               doc: /* Non-nil means Emacs is running without interactive terminal.  */);
 
   DEFVAR_LISP ("kill-emacs-hook", &Vkill_emacs_hook,
-              doc: /* Hook to be run whenever kill-emacs is called.
-Since kill-emacs may be invoked when the terminal is disconnected (or
+              doc: /* Hook to be 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,
-see `kill-emacs-query-functions' instead.  */);
+see `kill-emacs-query-functions' instead.
+
+The hook is not run in batch mode, i.e., if `noninteractive' is non-nil.  */);
   Vkill_emacs_hook = Qnil;
 
   empty_string = build_string ("");
@@ -2348,3 +2398,6 @@ near where the Emacs executable was found.  */);
               doc: /* Most recently used system locale for time.  */);
   Vprevious_system_time_locale = Qnil;
 }
+
+/* arch-tag: 7bfd356a-c720-4612-8ab6-aa4222931c2e
+   (do not change this comment) */