(set-buffer-file-coding-system): Set cdr
[bpt/emacs.git] / src / lread.c
index c1ee530..e4ba522 100644 (file)
@@ -1,14 +1,14 @@
 /* Lisp parsing and input streams.
    Copyright (C) 1985, 1986, 1987, 1988, 1989, 1993, 1994, 1995,
                  1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
-                 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+                 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
-GNU Emacs is free software; you can redistribute it and/or modify
+GNU Emacs is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 3, or (at your option)
-any later version.
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
 
 GNU Emacs is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -16,9 +16,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 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., 51 Franklin Street, Fifth Floor,
-Boston, MA 02110-1301, USA.  */
+along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 
 
 #include <config.h>
@@ -793,13 +791,13 @@ floating-point value.  */)
      Lisp_Object prompt, inherit_input_method, seconds;
 {
   Lisp_Object val;
-  int c;
 
   if (! NILP (prompt))
     message_with_string ("%s", prompt, 0);
   val = read_filtered_event (1, 1, 1, ! NILP (inherit_input_method), seconds);
-  c = XINT (val);
-  return make_number (char_resolve_modifier_mask (c));
+
+  return (NILP (val) ? Qnil
+         : make_number (char_resolve_modifier_mask (XINT (val))));
 }
 
 DEFUN ("read-event", Fread_event, Sread_event, 0, 3, 0,
@@ -838,13 +836,14 @@ floating-point value.  */)
      Lisp_Object prompt, inherit_input_method, seconds;
 {
   Lisp_Object val;
-  int c;
 
   if (! NILP (prompt))
     message_with_string ("%s", prompt, 0);
+
   val = read_filtered_event (1, 1, 0, ! NILP (inherit_input_method), seconds);
-  c = XINT (val);
-  return make_number (char_resolve_modifier_mask (c));
+
+  return (NILP (val) ? Qnil
+         : make_number (char_resolve_modifier_mask (XINT (val))));
 }
 
 DEFUN ("get-file-char", Fget_file_char, Sget_file_char, 0, 0, 0,
@@ -1105,7 +1104,7 @@ Return t if the file exists and loads successfully.  */)
      2000-09-21: It's not possible to just check for the file loaded
      being a member of Vloads_in_progress.  This fails because of the
      way the byte compiler currently works; `provide's are not
-     evaluted, see font-lock.el/jit-lock.el as an example.  This
+     evaluated, see font-lock.el/jit-lock.el as an example.  This
      leads to a certain amount of ``normal'' recursion.
 
      Also, just loading a file recursively is not always an error in
@@ -1114,14 +1113,12 @@ Return t if the file exists and loads successfully.  */)
     int count = 0;
     Lisp_Object tem;
     for (tem = Vloads_in_progress; CONSP (tem); tem = XCDR (tem))
-      if (!NILP (Fequal (found, XCAR (tem))))
-       count++;
-    if (count > 3)
-      {
-       if (fd >= 0)
-         emacs_close (fd);
-       signal_error ("Recursive load", Fcons (found, Vloads_in_progress));
-      }
+      if (!NILP (Fequal (found, XCAR (tem))) && (++count > 3))
+       {
+         if (fd >= 0)
+           emacs_close (fd);
+         signal_error ("Recursive load", Fcons (found, Vloads_in_progress));
+       }
     record_unwind_protect (record_load_unwind, Vloads_in_progress);
     Vloads_in_progress = Fcons (found, Vloads_in_progress);
   }
@@ -1271,13 +1268,11 @@ Return t if the file exists and loads successfully.  */)
 
   UNGCPRO;
 
-  if (saved_doc_string)
-    free (saved_doc_string);
+  xfree (saved_doc_string);
   saved_doc_string = 0;
   saved_doc_string_size = 0;
 
-  if (prev_saved_doc_string)
-    xfree (prev_saved_doc_string);
+  xfree (prev_saved_doc_string);
   prev_saved_doc_string = 0;
   prev_saved_doc_string_size = 0;
 
@@ -1346,11 +1341,7 @@ complete_filename_p (pathname)
   register const unsigned char *s = SDATA (pathname);
   return (IS_DIRECTORY_SEP (s[0])
          || (SCHARS (pathname) > 2
-             && IS_DEVICE_SEP (s[1]) && IS_DIRECTORY_SEP (s[2]))
-#ifdef VMS
-         || index (s, ':')
-#endif /* VMS */
-         );
+             && IS_DEVICE_SEP (s[1]) && IS_DIRECTORY_SEP (s[2])));
 }
 
 DEFUN ("locate-file-internal", Flocate_file_internal, Slocate_file_internal, 2, 4, 0,
@@ -1850,7 +1841,7 @@ This function preserves the position of point.  */)
   specbind (Qeval_buffer_list, Fcons (buf, Veval_buffer_list));
   specbind (Qstandard_output, tem);
   record_unwind_protect (save_excursion_restore, save_excursion_save ());
-  BUF_SET_PT (XBUFFER (buf), BUF_BEGV (XBUFFER (buf)));
+  BUF_TEMP_SET_PT (XBUFFER (buf), BUF_BEGV (XBUFFER (buf)));
   readevalloop (buf, 0, filename, Feval,
                !NILP (printflag), unibyte, Qnil, Qnil, Qnil);
   unbind_to (count, Qnil);
@@ -2038,7 +2029,7 @@ read_escape (readcharfun, stringp)
 {
   register int c = READCHAR;
   /* \u allows up to four hex digits, \U up to eight. Default to the
-     behaviour for \u, and change this value in the case that \U is seen. */
+     behavior for \u, and change this value in the case that \U is seen. */
   int unicode_hex_count = 4;
 
   switch (c)
@@ -2214,7 +2205,7 @@ read_escape (readcharfun, stringp)
       /* A Unicode escape. We only permit them in strings and characters,
         not arbitrarily in the source code, as in some other languages.  */
       {
-       int i = 0;
+       unsigned int i = 0;
        int count = 0;
 
        while (++count <= unicode_hex_count)
@@ -2231,7 +2222,8 @@ read_escape (readcharfun, stringp)
                break;
              }
          }
-
+       if (i > 0x10FFFF)
+         error ("Non-Unicode character: 0x%x", i);
        return i;
       }
 
@@ -3057,18 +3049,18 @@ substitute_object_in_subtree (object, placeholder)
 }
 
 /*  Feval doesn't get called from here, so no gc protection is needed. */
-#define SUBSTITUTE(get_val, set_val)                 \
-{                                                    \
-  Lisp_Object old_value = get_val;                   \
-  Lisp_Object true_value                             \
-    = substitute_object_recurse (object, placeholder,\
-                              old_value);           \
-                                                     \
-  if (!EQ (old_value, true_value))                   \
-    {                                                \
-       set_val;                                      \
-    }                                                \
-}
+#define SUBSTITUTE(get_val, set_val)                   \
+  do {                                                 \
+    Lisp_Object old_value = get_val;                   \
+    Lisp_Object true_value                             \
+      = substitute_object_recurse (object, placeholder,        \
+                                  old_value);          \
+                                                       \
+    if (!EQ (old_value, true_value))                   \
+      {                                                        \
+       set_val;                                        \
+      }                                                        \
+  } while (0)
 
 static Lisp_Object
 substitute_object_recurse (object, placeholder, subtree)
@@ -3097,23 +3089,33 @@ substitute_object_recurse (object, placeholder, subtree)
     {
     case Lisp_Vectorlike:
       {
-       int i;
-       int length = XINT (Flength(subtree));
+       int i, length = 0;
+       if (BOOL_VECTOR_P (subtree))
+         return subtree;               /* No sub-objects anyway.  */
+       else if (CHAR_TABLE_P (subtree) || SUB_CHAR_TABLE_P (subtree)
+                || COMPILEDP (subtree))
+         length = ASIZE (subtree) & PSEUDOVECTOR_SIZE_MASK;
+       else if (VECTORP (subtree))
+         length = ASIZE (subtree);
+       else
+         /* An unknown pseudovector may contain non-Lisp fields, so we
+            can't just blindly traverse all its fields.  We used to call
+            `Flength' which signaled `sequencep', so I just preserved this
+            behavior.  */
+         wrong_type_argument (Qsequencep, subtree);
+
        for (i = 0; i < length; i++)
-         {
-           Lisp_Object idx = make_number (i);
-           SUBSTITUTE (Faref (subtree, idx),
-                       Faset (subtree, idx, true_value));
-         }
+         SUBSTITUTE (AREF (subtree, i),
+                     ASET (subtree, i, true_value));
        return subtree;
       }
 
     case Lisp_Cons:
       {
-       SUBSTITUTE (Fcar_safe (subtree),
-                   Fsetcar (subtree, true_value));
-       SUBSTITUTE (Fcdr_safe (subtree),
-                   Fsetcdr (subtree, true_value));
+       SUBSTITUTE (XCAR (subtree),
+                   XSETCAR (subtree, true_value));
+       SUBSTITUTE (XCDR (subtree),
+                   XSETCDR (subtree, true_value));
        return subtree;
       }
 
@@ -3713,9 +3715,7 @@ oblookup (obarray, ptr, size, size_byte)
     }
   /* This is sometimes needed in the middle of GC.  */
   obsize &= ~ARRAY_MARK_FLAG;
-  /* Combining next two lines breaks VMS C 2.3.  */
-  hash = hash_string (ptr, size_byte);
-  hash %= obsize;
+  hash = hash_string (ptr, size_byte) % obsize;
   bucket = XVECTOR (obarray)->contents[hash];
   oblookup_last_bucket_number = hash;
   if (EQ (bucket, make_number (0)))
@@ -4089,15 +4089,11 @@ init_lread ()
     }
 #endif
 
-#if (!(defined(WINDOWSNT) || (defined(HAVE_CARBON))))
+#if (!(defined(WINDOWSNT) || (defined(HAVE_NS))))
   /* When Emacs is invoked over network shares on NT, PATH_LOADSEARCH is
      almost never correct, thereby causing a warning to be printed out that
      confuses users.  Since PATH_LOADSEARCH is always overridden by the
-     EMACSLOADPATH environment variable below, disable the warning on NT.
-     Also, when using the "self-contained" option for Carbon Emacs for MacOSX,
-     the "standard" paths may not exist and would be overridden by
-     EMACSLOADPATH as on NT.  Since this depends on how the executable
-     was build and packaged, turn off the warnings in general */
+     EMACSLOADPATH environment variable below, disable the warning on NT.  */
 
   /* Warn if dirs in the *standard* path don't exist.  */
   if (!turn_off_warning)
@@ -4119,7 +4115,7 @@ init_lread ()
            }
        }
     }
-#endif /* !(WINDOWSNT || HAVE_CARBON) */
+#endif /* !(WINDOWSNT || HAVE_NS) */
 
   /* If the EMACSLOADPATH environment variable is set, use its value.
      This doesn't apply if we're dumping.  */