]> code.delx.au - gnu-emacs/blobdiff - src/lread.c
Merge changes from emacs-23 branch.
[gnu-emacs] / src / lread.c
index b35d2be78eb023f40af9f22e803b2fa5d6bea5a4..66b1a8068c2e98f3402c9eab73eed9e7e1c62713 100644 (file)
@@ -54,12 +54,7 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #include <locale.h>
 #endif /* HAVE_SETLOCALE */
 
-#ifdef HAVE_FCNTL_H
 #include <fcntl.h>
-#endif
-#ifndef O_RDONLY
-#define O_RDONLY 0
-#endif
 
 #ifdef HAVE_FSEEKO
 #define file_offset off_t
@@ -75,7 +70,6 @@ Lisp_Object Qtest, Qsize;
 Lisp_Object Qweakness;
 Lisp_Object Qrehash_size;
 Lisp_Object Qrehash_threshold;
-extern Lisp_Object QCtest, QCsize, QCrehash_size, QCrehash_threshold, QCweakness;
 
 Lisp_Object Qread_char, Qget_file_char, Qstandard_input, Qcurrent_load_list;
 Lisp_Object Qvariable_documentation, Vvalues, Vstandard_input, Vafter_load_alist;
@@ -91,9 +85,6 @@ static Lisp_Object Qget_emacs_mule_file_char;
 
 static Lisp_Object Qload_force_doc_strings;
 
-extern Lisp_Object Qevent_symbol_element_mask;
-extern Lisp_Object Qfile_exists_p;
-
 /* non-zero if inside `load' */
 int load_in_progress;
 static Lisp_Object Qload_in_progress;
@@ -167,13 +158,13 @@ static FILE *instream;
 static int read_pure;
 
 /* For use within read-from-string (this reader is non-reentrant!!)  */
-static int read_from_string_index;
-static int read_from_string_index_byte;
-static int read_from_string_limit;
+static EMACS_INT read_from_string_index;
+static EMACS_INT read_from_string_index_byte;
+static EMACS_INT read_from_string_limit;
 
 /* Number of characters read in the current call to Fread or
    Fread_from_string. */
-static int readchar_count;
+static EMACS_INT readchar_count;
 
 /* This contains the last string skipped with #@.  */
 static char *saved_doc_string;
@@ -280,7 +271,7 @@ readchar (Lisp_Object readcharfun, int *multibyte)
     {
       register struct buffer *inbuffer = XBUFFER (readcharfun);
 
-      int pt_byte = BUF_PT_BYTE (inbuffer);
+      EMACS_INT pt_byte = BUF_PT_BYTE (inbuffer);
 
       if (pt_byte >= BUF_ZV_BYTE (inbuffer))
        return -1;
@@ -309,7 +300,7 @@ readchar (Lisp_Object readcharfun, int *multibyte)
     {
       register struct buffer *inbuffer = XMARKER (readcharfun)->buffer;
 
-      int bytepos = marker_byte_position (readcharfun);
+      EMACS_INT bytepos = marker_byte_position (readcharfun);
 
       if (bytepos >= BUF_ZV_BYTE (inbuffer))
        return -1;
@@ -443,7 +434,7 @@ unreadchar (Lisp_Object readcharfun, int c)
   else if (BUFFERP (readcharfun))
     {
       struct buffer *b = XBUFFER (readcharfun);
-      int bytepos = BUF_PT_BYTE (b);
+      EMACS_INT bytepos = BUF_PT_BYTE (b);
 
       BUF_PT (b)--;
       if (! NILP (b->enable_multibyte_characters))
@@ -456,7 +447,7 @@ unreadchar (Lisp_Object readcharfun, int c)
   else if (MARKERP (readcharfun))
     {
       struct buffer *b = XMARKER (readcharfun)->buffer;
-      int bytepos = XMARKER (readcharfun)->bytepos;
+      EMACS_INT bytepos = XMARKER (readcharfun)->bytepos;
 
       XMARKER (readcharfun)->charpos--;
       if (! NILP (b->enable_multibyte_characters))
@@ -661,10 +652,8 @@ static void substitute_in_interval (INTERVAL, Lisp_Object);
    return Qnil if no input arrives within that time.  */
 
 Lisp_Object
-read_filtered_event (no_switch_frame, ascii_required, error_nonascii,
-                    input_method, seconds)
-     int no_switch_frame, ascii_required, error_nonascii, input_method;
-     Lisp_Object seconds;
+read_filtered_event (int no_switch_frame, int ascii_required,
+                    int error_nonascii, int input_method, Lisp_Object seconds)
 {
   Lisp_Object val, delayed_switch_frame;
   EMACS_TIME end_time;
@@ -779,8 +768,7 @@ If the optional argument SECONDS is non-nil, it should be a number
 specifying the maximum number of seconds to wait for input.  If no
 input arrives in that time, return nil.  SECONDS may be a
 floating-point value.  */)
-     (prompt, inherit_input_method, seconds)
-     Lisp_Object prompt, inherit_input_method, seconds;
+  (Lisp_Object prompt, Lisp_Object inherit_input_method, Lisp_Object seconds)
 {
   Lisp_Object val;
 
@@ -802,8 +790,7 @@ If the optional argument SECONDS is non-nil, it should be a number
 specifying the maximum number of seconds to wait for input.  If no
 input arrives in that time, return nil.  SECONDS may be a
 floating-point value.  */)
-     (prompt, inherit_input_method, seconds)
-     Lisp_Object prompt, inherit_input_method, seconds;
+  (Lisp_Object prompt, Lisp_Object inherit_input_method, Lisp_Object seconds)
 {
   if (! NILP (prompt))
     message_with_string ("%s", prompt, 0);
@@ -824,8 +811,7 @@ If the optional argument SECONDS is non-nil, it should be a number
 specifying the maximum number of seconds to wait for input.  If no
 input arrives in that time, return nil.  SECONDS may be a
 floating-point value.  */)
-     (prompt, inherit_input_method, seconds)
-     Lisp_Object prompt, inherit_input_method, seconds;
+  (Lisp_Object prompt, Lisp_Object inherit_input_method, Lisp_Object seconds)
 {
   Lisp_Object val;
 
@@ -840,7 +826,7 @@ floating-point value.  */)
 
 DEFUN ("get-file-char", Fget_file_char, Sget_file_char, 0, 0, 0,
        doc: /* Don't use this yourself.  */)
-     ()
+  (void)
 {
   register Lisp_Object val;
   BLOCK_INPUT;
@@ -925,7 +911,7 @@ DEFUN ("get-load-suffixes", Fget_load_suffixes, Sget_load_suffixes, 0, 0, 0,
        doc: /* Return the suffixes that `load' should try if a suffix is \
 required.
 This uses the variables `load-suffixes' and `load-file-rep-suffixes'.  */)
-     ()
+  (void)
 {
   Lisp_Object lst = Qnil, suffixes = Vload_suffixes, suffix, ext;
   while (CONSP (suffixes))
@@ -980,8 +966,7 @@ Loading a file records its definitions, and its `provide' and
 car is the file name loaded.  See `load-history'.
 
 Return t if the file exists and loads successfully.  */)
-     (file, noerror, nomessage, nosuffix, must_suffix)
-     Lisp_Object file, noerror, nomessage, nosuffix, must_suffix;
+  (Lisp_Object file, Lisp_Object noerror, Lisp_Object nomessage, Lisp_Object nosuffix, Lisp_Object must_suffix)
 {
   register FILE *stream;
   register int fd = -1;
@@ -994,7 +979,7 @@ Return t if the file exists and loads successfully.  */)
   int compiled = 0;
   Lisp_Object handler;
   int safe_p = 1;
-  char *fmode = "r";
+  const char *fmode = "r";
   Lisp_Object tmp[2];
   int version;
 
@@ -1125,8 +1110,7 @@ Return t if the file exists and loads successfully.  */)
   specbind (Qold_style_backquotes, Qnil);
   record_unwind_protect (load_warn_old_style_backquotes, file);
 
-  if (!bcmp (SDATA (found) + SBYTES (found) - 4,
-            ".elc", 4)
+  if (!memcmp (SDATA (found) + SBYTES (found) - 4, ".elc", 4)
       || (fd >= 0 && (version = safe_to_load_p (fd)) > 0))
     /* Load .elc files directly, but not when they are
        remote and have no handler!  */
@@ -1283,7 +1267,6 @@ Return t if the file exists and loads successfully.  */)
 
 static Lisp_Object
 load_unwind (Lisp_Object arg)  /* used as unwind-protect function in load */
-                     
 {
   FILE *stream = (FILE *) XSAVE_VALUE (arg)->pointer;
   if (stream != NULL)
@@ -1332,8 +1315,7 @@ file name when searching.
 If non-nil, PREDICATE is used instead of `file-readable-p'.
 PREDICATE can also be an integer to pass to the access(2) function,
 in which case file-name-handlers are ignored.  */)
-     (filename, path, suffixes, predicate)
-     Lisp_Object filename, path, suffixes, predicate;
+  (Lisp_Object filename, Lisp_Object path, Lisp_Object suffixes, Lisp_Object predicate)
 {
   Lisp_Object file;
   int fd = openp (path, filename, suffixes, &file, predicate);
@@ -1575,9 +1557,8 @@ build_load_history (Lisp_Object filename, int entire)
                           Vload_history);
 }
 
-Lisp_Object
+static Lisp_Object
 unreadpure (Lisp_Object junk) /* Used as unwind-protect function in readevalloop */
-                      
 {
   read_pure = 0;
   return Qnil;
@@ -1786,8 +1767,7 @@ DO-ALLOW-PRINT, if non-nil, specifies that `print' and related
  functions should work normally even if PRINTFLAG is nil.
 
 This function preserves the position of point.  */)
-     (buffer, printflag, filename, unibyte, do_allow_print)
-     Lisp_Object buffer, printflag, filename, unibyte, do_allow_print;
+  (Lisp_Object buffer, Lisp_Object printflag, Lisp_Object filename, Lisp_Object unibyte, Lisp_Object do_allow_print)
 {
   int count = SPECPDL_INDEX ();
   Lisp_Object tem, buf;
@@ -1830,8 +1810,7 @@ instead of `read' to read each expression.  It gets one argument
 which is the input stream for reading characters.
 
 This function does not move point.  */)
-     (start, end, printflag, read_function)
-     Lisp_Object start, end, printflag, read_function;
+  (Lisp_Object start, Lisp_Object end, Lisp_Object printflag, Lisp_Object read_function)
 {
   int count = SPECPDL_INDEX ();
   Lisp_Object tem, cbuf;
@@ -1865,8 +1844,7 @@ STREAM or the value of `standard-input' may be:
  a string (takes text from string, starting at the beginning)
  t (read text line using minibuffer and use it, or read from
     standard input in batch mode).  */)
-     (stream)
-     Lisp_Object stream;
+  (Lisp_Object stream)
 {
   if (NILP (stream))
     stream = Vstandard_input;
@@ -1883,8 +1861,7 @@ DEFUN ("read-from-string", Fread_from_string, Sread_from_string, 1, 3, 0,
 Returns a cons: (OBJECT-READ . FINAL-STRING-INDEX).
 START and END optionally delimit a substring of STRING from which to read;
  they default to 0 and (length STRING) respectively.  */)
-     (string, start, end)
-     Lisp_Object string, start, end;
+  (Lisp_Object string, Lisp_Object start, Lisp_Object end)
 {
   Lisp_Object ret;
   CHECK_STRING (string);
@@ -1911,7 +1888,7 @@ read_internal_start (Lisp_Object stream, Lisp_Object start, Lisp_Object end)
   if (STRINGP (stream)
       || ((CONSP (stream) && STRINGP (XCAR (stream)))))
     {
-      int startval, endval;
+      EMACS_INT startval, endval;
       Lisp_Object string;
 
       if (STRINGP (stream))
@@ -2326,28 +2303,28 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
              /* This is repetitive but fast and simple. */
              params[param_count] = QCsize;
              params[param_count+1] = Fplist_get (tmp, Qsize);
-             if (!NILP (params[param_count+1]))
-               param_count+=2;
+             if (!NILP (params[param_count + 1]))
+               param_count += 2;
 
              params[param_count] = QCtest;
              params[param_count+1] = Fplist_get (tmp, Qtest);
-             if (!NILP (params[param_count+1]))
-               param_count+=2;
+             if (!NILP (params[param_count + 1]))
+               param_count += 2;
 
              params[param_count] = QCweakness;
              params[param_count+1] = Fplist_get (tmp, Qweakness);
-             if (!NILP (params[param_count+1]))
-               param_count+=2;
+             if (!NILP (params[param_count + 1]))
+               param_count += 2;
 
              params[param_count] = QCrehash_size;
              params[param_count+1] = Fplist_get (tmp, Qrehash_size);
-             if (!NILP (params[param_count+1]))
-               param_count+=2;
+             if (!NILP (params[param_count + 1]))
+               param_count += 2;
 
              params[param_count] = QCrehash_threshold;
              params[param_count+1] = Fplist_get (tmp, Qrehash_threshold);
-             if (!NILP (params[param_count+1]))
-               param_count+=2;
+             if (!NILP (params[param_count + 1]))
+               param_count += 2;
 
              /* This is the hashtable data. */
              data = Fplist_get (tmp, Qdata);
@@ -2368,6 +2345,8 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
 
              return ht;
            }
+         UNREAD (c);
+         invalid_syntax ("#", 1);
        }
       if (c == '^')
        {
@@ -2430,8 +2409,7 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
                invalid_syntax ("#&...", 5);
 
              val = Fmake_bool_vector (length, Qnil);
-             bcopy (SDATA (tmp), XBOOL_VECTOR (val)->data,
-                    size_in_chars);
+             memcpy (XBOOL_VECTOR (val)->data, SDATA (tmp), size_in_chars);
              /* Clear the extraneous bits in the last byte.  */
              if (XINT (length) != size_in_chars * BOOL_VECTOR_BITS_PER_CHAR)
                XBOOL_VECTOR (val)->data[size_in_chars - 1]
@@ -2734,7 +2712,7 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
 
            ok = (next_next_char <= 040
                  || (next_next_char < 0200
-                     && (index ("\"';([#?", next_next_char)
+                     && (strchr ("\"';([#?", next_next_char)
                          || (!first_in_list && next_next_char == '`')
                          || (new_backquote_flag && next_next_char == ','))));
          }
@@ -2742,7 +2720,7 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
          {
            ok = (next_char <= 040
                  || (next_char < 0200
-                     && (index ("\"';()[]#?", next_char)
+                     && (strchr ("\"';()[]#?", next_char)
                          || (!first_in_list && next_char == '`')
                          || (new_backquote_flag && next_char == ','))));
          }
@@ -2887,7 +2865,7 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
 
        if (next_char <= 040
            || (next_char < 0200
-               && (index ("\"';([#?", next_char)
+               && (strchr ("\"';([#?", next_char)
                    || (!first_in_list && next_char == '`')
                    || (new_backquote_flag && next_char == ','))))
          {
@@ -2914,7 +2892,7 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
          while (c > 040
                 && c != 0x8a0 /* NBSP */
                 && (c >= 0200
-                    || (!index ("\"';()[]#", c)
+                    || (!strchr ("\"';()[]#", c)
                         && !(!first_in_list && c == '`')
                         && !(new_backquote_flag && c == ','))))
            {
@@ -3199,11 +3177,10 @@ substitute_in_interval (INTERVAL interval, Lisp_Object arg)
 #define EXP_INT 16
 
 int
-isfloat_string (register char *cp, int ignore_trailing)
+isfloat_string (const char *cp, int ignore_trailing)
 {
-  register int state;
-
-  char *start = cp;
+  int state;
+  const char *start = cp;
 
   state = 0;
   if (*cp == '+' || *cp == '-')
@@ -3254,7 +3231,8 @@ isfloat_string (register char *cp, int ignore_trailing)
     }
 
   return ((ignore_trailing
-           || (*cp == 0) || (*cp == ' ') || (*cp == '\t') || (*cp == '\n') || (*cp == '\r') || (*cp == '\f'))
+          || *cp == 0 || *cp == ' ' || *cp == '\t' || *cp == '\n'
+          || *cp == '\r' || *cp == '\f')
          && (state == (LEAD_INT|DOT_CHAR|TRAIL_INT)
              || state == (DOT_CHAR|TRAIL_INT)
              || state == (LEAD_INT|E_CHAR|EXP_INT)
@@ -3597,13 +3575,13 @@ intern_c_string (const char *str)
 /* Create an uninterned symbol with name STR.  */
 
 Lisp_Object
-make_symbol (char *str)
+make_symbol (const char *str)
 {
   int len = strlen (str);
 
-  return Fmake_symbol ((!NILP (Vpurify_flag)
-                       ? make_pure_string (str, len, len, 0)
-                       : make_string (str, len)));
+  return Fmake_symbol (!NILP (Vpurify_flag)
+                      ? make_pure_string (str, len, len, 0)
+                      : make_string (str, len));
 }
 \f
 DEFUN ("intern", Fintern, Sintern, 1, 2, 0,
@@ -3611,8 +3589,7 @@ DEFUN ("intern", Fintern, Sintern, 1, 2, 0,
 If there is none, one is created by this function and returned.
 A second optional argument specifies the obarray to use;
 it defaults to the value of `obarray'.  */)
-     (string, obarray)
-     Lisp_Object string, obarray;
+  (Lisp_Object string, Lisp_Object obarray)
 {
   register Lisp_Object tem, sym, *ptr;
 
@@ -3659,8 +3636,7 @@ NAME may be a string or a symbol.  If it is a symbol, that exact
 symbol is searched for.
 A second optional argument specifies the obarray to use;
 it defaults to the value of `obarray'.  */)
-     (name, obarray)
-     Lisp_Object name, obarray;
+  (Lisp_Object name, Lisp_Object obarray)
 {
   register Lisp_Object tem, string;
 
@@ -3688,8 +3664,7 @@ The value is t if a symbol was found and deleted, nil otherwise.
 NAME may be a string or a symbol.  If it is a symbol, that symbol
 is deleted, if it belongs to OBARRAY--no other symbol is deleted.
 OBARRAY defaults to the value of the variable `obarray'.  */)
-     (name, obarray)
-     Lisp_Object name, obarray;
+  (Lisp_Object name, Lisp_Object obarray)
 {
   register Lisp_Object string, tem;
   int hash;
@@ -3759,7 +3734,7 @@ OBARRAY defaults to the value of the variable `obarray'.  */)
    Also store the bucket number in oblookup_last_bucket_number.  */
 
 Lisp_Object
-oblookup (Lisp_Object obarray, register const char *ptr, int size, int size_byte)
+oblookup (Lisp_Object obarray, register const char *ptr, EMACS_INT size, EMACS_INT size_byte)
 {
   int hash;
   int obsize;
@@ -3786,7 +3761,7 @@ oblookup (Lisp_Object obarray, register const char *ptr, int size, int size_byte
       {
        if (SBYTES (SYMBOL_NAME (tail)) == size_byte
            && SCHARS (SYMBOL_NAME (tail)) == size
-           && !bcmp (SDATA (SYMBOL_NAME (tail)), ptr, size_byte))
+           && !memcmp (SDATA (SYMBOL_NAME (tail)), ptr, size_byte))
          return tail;
        else if (XSYMBOL (tail)->next == 0)
          break;
@@ -3832,7 +3807,7 @@ map_obarray (Lisp_Object obarray, void (*fn) (Lisp_Object, Lisp_Object), Lisp_Ob
     }
 }
 
-void
+static void
 mapatoms_1 (Lisp_Object sym, Lisp_Object function)
 {
   call1 (function, sym);
@@ -3841,8 +3816,7 @@ mapatoms_1 (Lisp_Object sym, Lisp_Object function)
 DEFUN ("mapatoms", Fmapatoms, Smapatoms, 1, 2, 0,
        doc: /* Call FUNCTION on every symbol in OBARRAY.
 OBARRAY defaults to the value of `obarray'.  */)
-     (function, obarray)
-     Lisp_Object function, obarray;
+  (Lisp_Object function, Lisp_Object obarray)
 {
   if (NILP (obarray)) obarray = Vobarray;
   obarray = check_obarray (obarray);
@@ -3992,7 +3966,7 @@ static Lisp_Object dump_path;
 void
 init_lread (void)
 {
-  char *normal;
+  const char *normal;
   int turn_off_warning = 0;
 
   /* Compute the default load-path.  */
@@ -4183,7 +4157,7 @@ init_lread (void)
    does not exist.  Print it on stderr and put it in *Messages*.  */
 
 void
-dir_warning (char *format, Lisp_Object dirname)
+dir_warning (const char *format, Lisp_Object dirname)
 {
   char *buffer
     = (char *) alloca (SCHARS (dirname) + strlen (format) + 5);