[INCLUDED_FCNTL]: Don't include fcntl.h again.
[bpt/emacs.git] / src / lread.c
index 6c2854a..d6fa228 100644 (file)
@@ -165,7 +165,11 @@ unreadchar (readcharfun, c)
      Lisp_Object readcharfun;
      int c;
 {
-  if (XTYPE (readcharfun) == Lisp_Buffer)
+  if (c == -1)
+    /* Don't back up the pointer if we're unreading the end-of-input mark,
+       since readchar didn't advance it when we read it.  */
+    ;
+  else if (XTYPE (readcharfun) == Lisp_Buffer)
     {
       if (XBUFFER (readcharfun) == current_buffer)
        SET_PT (point - 1);
@@ -209,13 +213,17 @@ read_filtered_event (no_switch_frame, ascii_required, error_nonascii)
 #ifdef standalone
   return make_number (getchar ());
 #else
-  register Lisp_Object val;
-  register Lisp_Object delayed_switch_frame = Qnil;
+  register Lisp_Object val, delayed_switch_frame;
+
+  delayed_switch_frame = Qnil;
 
   /* Read until we get an acceptable event.  */
  retry:
   val = read_char (0, 0, 0, Qnil, 0);
 
+  if (XTYPE (val) == Lisp_Buffer)
+    goto retry;
+
   /* switch-frame events are put off until after the next ASCII
      character.  This is better than signalling an error just because
      the last characters were typed to a separate minibuffer frame,
@@ -350,8 +358,10 @@ Return t if file exists.")
      since it would try to load a directory as a Lisp file */
   if (XSTRING (str)->size > 0)
     {
+      GCPRO1 (str);
       fd = openp (Vload_path, str, !NILP (nosuffix) ? "" : ".elc:.el:",
                  &found, 0);
+      UNGCPRO;
     }
 
   if (fd < 0)
@@ -373,9 +383,9 @@ Return t if file exists.")
 #ifdef MSDOS
       dosmode = "rb";
 #endif
-      stat (XSTRING (found)->data, &s1);
+      stat ((char *)XSTRING (found)->data, &s1);
       XSTRING (found)->data[XSTRING (found)->size - 1] = 0;
-      result = stat (XSTRING (found)->data, &s2);
+      result = stat ((char *)XSTRING (found)->data, &s2);
       if (result >= 0 && (unsigned) s1.st_mtime < (unsigned) s2.st_mtime)
        {
          message ("Source file `%s' newer than byte-compiled file",
@@ -502,7 +512,9 @@ openp (path, str, suffix, storeptr, exec_only)
   int want_size;
   register Lisp_Object filename;
   struct stat st;
+  struct gcpro gcpro1;
 
+  GCPRO1 (str);
   if (storeptr)
     *storeptr = Qnil;
 
@@ -560,7 +572,7 @@ openp (path, str, suffix, storeptr, exec_only)
                  /* We succeeded; return this descriptor and filename.  */
                  if (storeptr)
                    *storeptr = build_string (fn);
-                 return fd;
+                 RETURN_UNGCPRO (fd);
                }
            }
 
@@ -569,10 +581,11 @@ openp (path, str, suffix, storeptr, exec_only)
            break;
          nsuffix += lsuffix + 1;
        }
-      if (absolute) return -1;
+      if (absolute)
+       RETURN_UNGCPRO (-1);
     }
 
-  return -1;
+  RETURN_UNGCPRO (-1);
 }
 
 \f
@@ -1202,11 +1215,15 @@ read1 (readcharfun)
                if (p == read_buffer)
                  cancel = 1;
              }
-           else if (c & CHAR_META)
-             /* Move the meta bit to the right place for a string.  */
-             *p++ = (c & ~CHAR_META) | 0x80;
            else
-             *p++ = c;
+             {
+               if (c & CHAR_META)
+                 /* Move the meta bit to the right place for a string.  */
+                 c = (c & ~CHAR_META) | 0x80;
+               if (c & ~0xff)
+                 error ("Invalid modifier in string");
+               *p++ = c;
+             }
          }
        if (c < 0) return Fsignal (Qend_of_file, Qnil);
 
@@ -1504,8 +1521,9 @@ intern (str)
 {
   Lisp_Object tem;
   int len = strlen (str);
-  Lisp_Object obarray = Vobarray;
+  Lisp_Object obarray;
 
+  obarray = Vobarray;
   if (XTYPE (obarray) != Lisp_Vector || XVECTOR (obarray)->size == 0)
     obarray = check_obarray (obarray);
   tem = oblookup (obarray, str, len);
@@ -1849,15 +1867,14 @@ init_lread ()
       if (! NILP (Fequal (dump_path, Vload_path)))
        {
          Vload_path = decode_env_path (0, normal);
-         if (!NILP (Vinvocation_directory))
+         if (!NILP (Vinstallation_directory))
            {
-             /* Add to the path the ../lisp dir of the Emacs executable,
-                if that dir exists.  */
-             Lisp_Object tem, tem1;
-             tem = Fexpand_file_name (build_string ("../lisp"),
-                                      Vinvocation_directory);
-             tem1 = Ffile_exists_p (tem);
-             if (!NILP (tem1) && NILP (Fmember (tem, Vload_path)))
+             /* Add to the path the lisp subdir of the
+                installation dir.  */
+             Lisp_Object tem;
+             tem = Fexpand_file_name (build_string ("lisp"),
+                                      Vinstallation_directory);
+             if (NILP (Fmember (tem, Vload_path)))
                Vload_path = nconc2 (Vload_path, Fcons (tem, Qnil));
            }
        }
@@ -1880,8 +1897,8 @@ init_lread ()
          {
            dirfile = Fdirectory_file_name (dirfile);
            if (access (XSTRING (dirfile)->data, 0) < 0)
-             printf ("Warning: lisp library (%s) does not exist.\n",
-                     XSTRING (Fcar (path_tail))->data);
+             fprintf (stderr, "Warning: lisp library (%s) does not exist.\n",
+                      XSTRING (Fcar (path_tail))->data);
          }
       }
   }