Contents in 1999-06-04-13 of release-21-2.
[chise/xemacs-chise.git.1] / src / fns.c
index c1fa079..ea6fcfe 100644 (file)
--- a/src/fns.c
+++ b/src/fns.c
@@ -881,7 +881,7 @@ Relevant parts of the string-extent-data are copied in the new string.
        (string, from, to))
 {
   Charcount ccfr, ccto;
-  Bytecount bfr, bto;
+  Bytecount bfr, blen;
   Lisp_Object val;
 
   CHECK_STRING (string);
@@ -889,10 +889,10 @@ Relevant parts of the string-extent-data are copied in the new string.
   get_string_range_char (string, from, to, &ccfr, &ccto,
                         GB_HISTORICAL_STRING_BEHAVIOR);
   bfr = charcount_to_bytecount (XSTRING_DATA (string), ccfr);
-  bto = charcount_to_bytecount (XSTRING_DATA (string), ccto);
-  val = make_string (XSTRING_DATA (string) + bfr, bto - bfr);
+  blen = charcount_to_bytecount (XSTRING_DATA (string) + bfr, ccto - ccfr);
+  val = make_string (XSTRING_DATA (string) + bfr, blen);
   /* Copy any applicable extent information into the new string: */
-  copy_string_extents (val, string, 0, bfr, bto - bfr);
+  copy_string_extents (val, string, 0, bfr, blen);
   return val;
 }
 
@@ -2678,7 +2678,7 @@ See also `get', `remprop', and `object-plist'.
        (object, propname, value))
 {
   CHECK_SYMBOL (propname);
-  CHECK_IMPURE (object);
+  CHECK_LISP_WRITEABLE (object);
 
   if (SYMBOLP (object))
     symbol_putprop (object, propname, value);
@@ -2723,7 +2723,7 @@ was present in the property list).  See also `get', `put', and
   int retval = 0;
 
   CHECK_SYMBOL (propname);
-  CHECK_IMPURE (object);
+  CHECK_LISP_WRITEABLE (object);
 
   if (SYMBOLP (object))
     retval = symbol_remprop (object, propname);
@@ -2786,47 +2786,12 @@ internal_equal (Lisp_Object obj1, Lisp_Object obj2, int depth)
 {
   if (depth > 200)
     error ("Stack overflow in equal");
-#ifndef LRECORD_CONS
- do_cdr:
-#endif
   QUIT;
   if (EQ_WITH_EBOLA_NOTICE (obj1, obj2))
     return 1;
   /* Note that (equal 20 20.0) should be nil */
   if (XTYPE (obj1) != XTYPE (obj2))
     return 0;
-#ifndef LRECORD_CONS
-  if (CONSP (obj1))
-    {
-      if (!internal_equal (XCAR (obj1), XCAR (obj2), depth + 1))
-        return 0;
-      obj1 = XCDR (obj1);
-      obj2 = XCDR (obj2);
-      goto do_cdr;
-    }
-#endif
-#ifndef LRECORD_VECTOR
-  if (VECTORP (obj1))
-    {
-      Lisp_Object *v1 = XVECTOR_DATA (obj1);
-      Lisp_Object *v2 = XVECTOR_DATA (obj2);
-      int len = XVECTOR_LENGTH (obj1);
-      if (len != XVECTOR_LENGTH (obj2))
-       return 0;
-      while (len--)
-       if (!internal_equal (*v1++, *v2++, depth + 1))
-         return 0;
-      return 1;
-    }
-#endif
-#ifndef LRECORD_STRING
-  if (STRINGP (obj1))
-    {
-      Bytecount len;
-      return (((len = XSTRING_LENGTH (obj1)) == XSTRING_LENGTH (obj2)) &&
-             !memcmp (XSTRING_DATA (obj1), XSTRING_DATA (obj2), len));
-    }
-#endif
   if (LRECORDP (obj1))
     {
       CONST struct lrecord_implementation
@@ -2851,39 +2816,12 @@ internal_old_equal (Lisp_Object obj1, Lisp_Object obj2, int depth)
 {
   if (depth > 200)
     error ("Stack overflow in equal");
-#ifndef LRECORD_CONS
- do_cdr:
-#endif
   QUIT;
   if (HACKEQ_UNSAFE (obj1, obj2))
     return 1;
   /* Note that (equal 20 20.0) should be nil */
   if (XTYPE (obj1) != XTYPE (obj2))
     return 0;
-#ifndef LRECORD_CONS
-  if (CONSP (obj1))
-    {
-      if (!internal_old_equal (XCAR (obj1), XCAR (obj2), depth + 1))
-        return 0;
-      obj1 = XCDR (obj1);
-      obj2 = XCDR (obj2);
-      goto do_cdr;
-    }
-#endif
-#ifndef LRECORD_VECTOR
-  if (VECTORP (obj1))
-    {
-      Lisp_Object *v1 = XVECTOR_DATA (obj1);
-      Lisp_Object *v2 = XVECTOR_DATA (obj2);
-      int len = XVECTOR_LENGTH (obj1);
-      if (len != XVECTOR_LENGTH (obj2))
-       return 0;
-      while (len--)
-       if (!internal_old_equal (*v1++, *v2++, depth + 1))
-         return 0;
-      return 1;
-    }
-#endif
 
   return internal_equal (obj1, obj2, depth);
 }
@@ -2929,7 +2867,7 @@ ARRAY is a vector, bit vector, or string.
       Charcount len = string_char_length (s);
       Charcount i;
       CHECK_CHAR_COERCE_INT (item);
-      CHECK_IMPURE (array);
+      CHECK_LISP_WRITEABLE (array);
       charval = XCHAR (item);
       for (i = 0; i < len; i++)
        set_string_char (s, i, charval);
@@ -2939,7 +2877,7 @@ ARRAY is a vector, bit vector, or string.
     {
       Lisp_Object *p = XVECTOR_DATA (array);
       int len = XVECTOR_LENGTH (array);
-      CHECK_IMPURE (array);
+      CHECK_LISP_WRITEABLE (array);
       while (len--)
        *p++ = item;
     }
@@ -2949,7 +2887,7 @@ ARRAY is a vector, bit vector, or string.
       int len = bit_vector_length (v);
       int bit;
       CHECK_BIT (item);
-      CHECK_IMPURE (array);
+      CHECK_LISP_WRITEABLE (array);
       bit = XINT (item);
       while (len--)
        set_bit_vector_bit (v, len, bit);
@@ -3502,11 +3440,11 @@ static short base64_char_to_value[128] =
    base64 characters.  */
 
 #define ADVANCE_INPUT(c, stream)                               \
- (ec = Lstream_get_emchar (stream),                            \
-  ec == -1 ? 0 :                                               \
+ ((ec = Lstream_get_emchar (stream)) == -1 ? 0 :               \
   ((ec > 255) ?                                                        \
-   (error ("Non-ascii character detected in base64 input"), 0) \
-   : (c = (Bufbyte)ec, 1)))
+   (signal_simple_error ("Non-ascii character in base64 input",        \
+                        make_char (ec)), 0)                    \
+   : (c = (Bufbyte)ec), 1))
 
 static Bytind
 base64_encode_1 (Lstream *istream, Bufbyte *to, int line_break)
@@ -3566,14 +3504,23 @@ base64_encode_1 (Lstream *istream, Bufbyte *to, int line_break)
 }
 #undef ADVANCE_INPUT
 
+/* Semantically identical to ADVANCE_INPUT above, only no >255
+   checking is needed for decoding -- checking is covered by IS_BASE64
+   below.  */
 #define ADVANCE_INPUT(c, stream)               \
  (ec = Lstream_get_emchar (stream),            \
   ec == -1 ? 0 : (c = (Bufbyte)ec, 1))
 
-#define INPUT_EOF_P(stream)                            \
- (ADVANCE_INPUT (c2, stream)                           \
-  ? (Lstream_unget_emchar (stream, (Emchar)c2), 0)     \
-  : 1)
+/* Get next character from the stream, but ignore it if it's
+   whitespace.  ENDP is set to 1 if EOF is hit.  */
+#define ADVANCE_INPUT_IGNORE_WHITESPACE(c, endp, stream) do {          \
+  endp = 0;                                                            \
+  do {                                                                 \
+    if (!ADVANCE_INPUT (c, stream))                                    \
+      endp = 1;                                                                \
+  } while (!endp && (c == ' ' || c == '\t' || c == '\r' || c == '\n'   \
+                    || c == '\f' || c == '\v'));                       \
+} while (0)
 
 #define STORE_BYTE(pos, val) do {                                      \
   pos += set_charptr_emchar (pos, (Emchar)((unsigned char)(val)));     \
@@ -3583,43 +3530,28 @@ base64_encode_1 (Lstream *istream, Bufbyte *to, int line_break)
 static Bytind
 base64_decode_1 (Lstream *istream, Bufbyte *to, Charcount *ccptr)
 {
-  EMACS_INT counter = 0;
-  Emchar ec;
   Bufbyte *e = to;
   unsigned long value;
 
   *ccptr = 0;
   while (1)
     {
-      Bufbyte c, c2;
+      Bufbyte c;
+      Emchar ec;
+      int endp;
 
-      if (!ADVANCE_INPUT (c, istream))
+      ADVANCE_INPUT_IGNORE_WHITESPACE (c, endp, istream);
+      if (endp)
        break;
 
-      /* Accept wrapping lines, reversibly if at each 76 characters.  */
-      if (c == '\n')
-       {
-         if (!ADVANCE_INPUT (c, istream))
-           break;
-         if (INPUT_EOF_P (istream))
-           break;
-         /* FSF Emacs has this check, apparently inherited from
-             recode.  However, I see no reason to be this picky about
-             line length -- why reject base64 with say 72-byte lines?
-             (yes, there are programs that generate them.)  */
-         /*if (counter != MIME_LINE_LENGTH / 4) return -1;*/
-         counter = 1;
-       }
-      else
-       counter++;
-
       /* Process first byte of a quadruplet.  */
       if (!IS_BASE64 (c))
        return -1;
       value = base64_char_to_value[c] << 18;
 
       /* Process second byte of a quadruplet.  */
-      if (!ADVANCE_INPUT (c, istream))
+      ADVANCE_INPUT_IGNORE_WHITESPACE (c, endp, istream);
+      if (endp)
        return -1;
 
       if (!IS_BASE64 (c))
@@ -3629,12 +3561,14 @@ base64_decode_1 (Lstream *istream, Bufbyte *to, Charcount *ccptr)
       STORE_BYTE (e, value >> 16);
 
       /* Process third byte of a quadruplet.  */
-      if (!ADVANCE_INPUT (c, istream))
+      ADVANCE_INPUT_IGNORE_WHITESPACE (c, endp, istream);
+      if (endp)
        return -1;
 
       if (c == '=')
        {
-         if (!ADVANCE_INPUT (c, istream))
+         ADVANCE_INPUT_IGNORE_WHITESPACE (c, endp, istream);
+         if (endp)
            return -1;
          if (c != '=')
            return -1;
@@ -3648,7 +3582,8 @@ base64_decode_1 (Lstream *istream, Bufbyte *to, Charcount *ccptr)
       STORE_BYTE (e, 0xff & value >> 8);
 
       /* Process fourth byte of a quadruplet.  */
-      if (!ADVANCE_INPUT (c, istream))
+      ADVANCE_INPUT_IGNORE_WHITESPACE (c, endp, istream);
+      if (endp)
        return -1;
 
       if (c == '=')
@@ -3664,7 +3599,8 @@ base64_decode_1 (Lstream *istream, Bufbyte *to, Charcount *ccptr)
   return e - to;
 }
 #undef ADVANCE_INPUT
-#undef INPUT_EOF_P
+#undef ADVANCE_INPUT_IGNORE_WHITESPACE
+#undef STORE_BYTE
 
 static Lisp_Object
 free_malloced_ptr (Lisp_Object unwind_obj)
@@ -3968,4 +3904,6 @@ A list of symbols which are the features of the executing emacs.
 Used by `featurep' and `require', and altered by `provide'.
 */ );
   Vfeatures = Qnil;
+
+  Fprovide (intern ("base64"));
 }