(main): Use Vbuffer_alist instead of Fbuffer_list.
[bpt/emacs.git] / src / search.c
index c3081f9..9015580 100644 (file)
@@ -20,6 +20,9 @@ Boston, MA 02111-1307, USA.  */
 
 
 #include <config.h>
+#ifdef STDC_HEADERS
+#include <stdlib.h>
+#endif
 #include "lisp.h"
 #include "syntax.h"
 #include "category.h"
@@ -33,6 +36,9 @@ Boston, MA 02111-1307, USA.  */
 #include <sys/types.h>
 #include "regex.h"
 
+#define min(a, b) ((a) < (b) ? (a) : (b))
+#define max(a, b) ((a) > (b) ? (a) : (b))
+
 #define REGEXP_CACHE_SIZE 20
 
 /* If the regexp is non-nil, then the buffer contains the compiled form
@@ -135,7 +141,7 @@ compile_pattern_1 (cp, pattern, translate, regp, posix, multibyte)
   if (multibyte == STRING_MULTIBYTE (pattern))
     {
       raw_pattern = (char *) XSTRING (pattern)->data;
-      raw_pattern_size = XSTRING (pattern)->size_byte;
+      raw_pattern_size = STRING_BYTES (XSTRING (pattern));
     }
   else if (multibyte)
     {
@@ -156,11 +162,11 @@ compile_pattern_1 (cp, pattern, translate, regp, posix, multibyte)
       raw_pattern_size = XSTRING (pattern)->size;
       raw_pattern = (char *) alloca (raw_pattern_size + 1);
       copy_text (XSTRING (pattern)->data, raw_pattern,
-                XSTRING (pattern)->size_byte, 1, 0);
+                STRING_BYTES (XSTRING (pattern)), 1, 0);
     }
 
   cp->regexp = Qnil;
-  cp->buf.translate = (! NILP (translate) ? translate : 0);
+  cp->buf.translate = (! NILP (translate) ? translate : make_number (0));
   cp->posix = posix;
   cp->buf.multibyte = multibyte;
   BLOCK_INPUT;
@@ -200,7 +206,7 @@ compile_pattern (pattern, regp, translate, posix, multibyte)
       cp = *cpp;
       if (XSTRING (cp->regexp)->size == XSTRING (pattern)->size
          && !NILP (Fstring_equal (cp->regexp, pattern))
-         && cp->buf.translate == (! NILP (translate) ? translate : 0)
+         && EQ (cp->buf.translate, (! NILP (translate) ? translate : make_number (0)))
          && cp->posix == posix
          && cp->buf.multibyte == multibyte)
        break;
@@ -368,8 +374,8 @@ string_match_1 (regexp, string, start, posix)
   re_match_object = string;
   
   val = re_search (bufp, (char *) XSTRING (string)->data,
-                  XSTRING (string)->size_byte, pos_byte,
-                  XSTRING (string)->size_byte - pos_byte,
+                  STRING_BYTES (XSTRING (string)), pos_byte,
+                  STRING_BYTES (XSTRING (string)) - pos_byte,
                   &search_regs);
   immediate_quit = 0;
   last_thing_searched = Qt;
@@ -431,8 +437,8 @@ fast_string_match (regexp, string)
   re_match_object = string;
   
   val = re_search (bufp, (char *) XSTRING (string)->data,
-                  XSTRING (string)->size_byte, 0, XSTRING (string)->size_byte,
-                  0);
+                  STRING_BYTES (XSTRING (string)), 0,
+                  STRING_BYTES (XSTRING (string)), 0);
   immediate_quit = 0;
   return val;
 }
@@ -464,23 +470,6 @@ fast_c_string_match_ignore_case (regexp, string)
   return val;
 }
 \f
-/* max and min.  */
-
-static int
-max (a, b)
-     int a, b;
-{
-  return ((a > b) ? a : b);
-}
-
-static int
-min (a, b)
-     int a, b;
-{
-  return ((a < b) ? a : b);
-}
-
-\f
 /* The newline cache: remembering which sections of text have no newlines.  */
 
 /* If the user has requested newline caching, make sure it's on.
@@ -529,6 +518,7 @@ newline_cache_on_off (buf)
    If ALLOW_QUIT is non-zero, set immediate_quit.  That's good to do
    except when inside redisplay.  */
 
+int
 scan_buffer (target, start, end, count, shortage, allow_quit)
      register int target;
      int start, end;
@@ -568,6 +558,7 @@ scan_buffer (target, start, end, count, shortage, allow_quit)
            examine.  */
        int ceiling_byte = CHAR_TO_BYTE (end) - 1;
        int start_byte = CHAR_TO_BYTE (start);
+       int tem;
 
         /* If we're looking for a newline, consult the newline cache
            to see where we can avoid some scanning.  */
@@ -593,7 +584,8 @@ scan_buffer (target, start, end, count, shortage, allow_quit)
            bytes. BUFFER_CEILING_OF returns the last character
            position that is contiguous, so the ceiling is the
            position after that.  */
-        ceiling_byte = min (BUFFER_CEILING_OF (start_byte), ceiling_byte);
+       tem = BUFFER_CEILING_OF (start_byte);
+       ceiling_byte = min (tem, ceiling_byte);
 
         {
           /* The termination address of the dumb loop.  */ 
@@ -639,6 +631,7 @@ scan_buffer (target, start, end, count, shortage, allow_quit)
         /* The last character to check before the next obstacle.  */
        int ceiling_byte = CHAR_TO_BYTE (end);
        int start_byte = CHAR_TO_BYTE (start);
+       int tem;
 
         /* Consult the newline cache, if appropriate.  */
         if (target == '\n' && newline_cache)
@@ -660,7 +653,8 @@ scan_buffer (target, start, end, count, shortage, allow_quit)
           }
 
         /* Stop scanning before the gap.  */
-        ceiling_byte = max (BUFFER_FLOOR_OF (start_byte - 1), ceiling_byte);
+       tem = BUFFER_FLOOR_OF (start_byte - 1);
+       ceiling_byte = max (tem, ceiling_byte);
 
         {
           /* The termination address of the dumb loop.  */
@@ -786,7 +780,6 @@ scan_newline (start, start_byte, limit, limit_byte, count, allow_quit)
     }
   else
     {
-      int start_byte = CHAR_TO_BYTE (start);
       while (start_byte > limit_byte)
        {
          ceiling = BUFFER_FLOOR_OF (start_byte - 1);
@@ -880,22 +873,23 @@ search_command (string, bound, noerror, count, direction, RE, posix)
     {
       CHECK_NUMBER_COERCE_MARKER (bound, 1);
       lim = XINT (bound);
-      lim_byte = CHAR_TO_BYTE (lim);
       if (n > 0 ? lim < PT : lim > PT)
        error ("Invalid search bound (wrong side of point)");
       if (lim > ZV)
        lim = ZV, lim_byte = ZV_BYTE;
-      if (lim < BEGV)
+      else if (lim < BEGV)
        lim = BEGV, lim_byte = BEGV_BYTE;
+      else
+       lim_byte = CHAR_TO_BYTE (lim);
     }
 
   np = search_buffer (string, PT, PT_BYTE, lim, lim_byte, n, RE,
                      (!NILP (current_buffer->case_fold_search)
                       ? current_buffer->case_canon_table
-                      : make_number (0)),
+                      : Qnil),
                      (!NILP (current_buffer->case_fold_search)
                       ? current_buffer->case_eqv_table
-                      : make_number (0)),
+                      : Qnil),
                      posix);
   if (np <= 0)
     {
@@ -930,7 +924,7 @@ static int
 trivial_regexp_p (regexp)
      Lisp_Object regexp;
 {
-  int len = XSTRING (regexp)->size_byte;
+  int len = STRING_BYTES (XSTRING (regexp));
   unsigned char *s = XSTRING (regexp)->data;
   unsigned char c;
   while (--len >= 0)
@@ -972,8 +966,22 @@ trivial_regexp_p (regexp)
    POSIX is nonzero if we want full backtracking (POSIX style)
    for this pattern.  0 means backtrack only enough to get a valid match.  */
 
-#define TRANSLATE(trt, d) \
-   (! NILP (trt) ? XINT (Faref (trt, make_number (d))) : (d))
+#define TRANSLATE(out, trt, d)                 \
+do                                             \
+  {                                            \
+    if (! NILP (trt))                          \
+      {                                                \
+       Lisp_Object temp;                       \
+       temp = Faref (trt, make_number (d));    \
+       if (INTEGERP (temp))                    \
+         out = XINT (temp);                    \
+       else                                    \
+         out = d;                              \
+      }                                                \
+    else                                       \
+      out = d;                                 \
+  }                                            \
+while (0)
 
 static int
 search_buffer (string, pos, pos_byte, lim, lim_byte, n,
@@ -990,7 +998,7 @@ search_buffer (string, pos, pos_byte, lim, lim_byte, n,
      int posix;
 {
   int len = XSTRING (string)->size;
-  int len_byte = XSTRING (string)->size_byte;
+  int len_byte = STRING_BYTES (XSTRING (string));
   register int i;
 
   if (running_asynch_code)
@@ -1055,6 +1063,7 @@ search_buffer (string, pos, pos_byte, lim, lim_byte, n,
            }
          if (val >= 0)
            {
+             pos_byte = search_regs.start[0] + BEGV_BYTE;
              for (i = 0; i < search_regs.num_regs; i++)
                if (search_regs.start[i] >= 0)
                  {
@@ -1087,6 +1096,7 @@ search_buffer (string, pos, pos_byte, lim, lim_byte, n,
            }
          if (val >= 0)
            {
+             pos_byte = search_regs.end[0] + BEGV_BYTE;
              for (i = 0; i < search_regs.num_regs; i++)
                if (search_regs.start[i] >= 0)
                  {
@@ -1127,7 +1137,7 @@ search_buffer (string, pos, pos_byte, lim, lim_byte, n,
        {
          raw_pattern = (char *) XSTRING (string)->data;
          raw_pattern_size = XSTRING (string)->size;
-         raw_pattern_size_byte = XSTRING (string)->size_byte;
+         raw_pattern_size_byte = STRING_BYTES (XSTRING (string));
        }
       else if (multibyte)
        {
@@ -1151,7 +1161,7 @@ search_buffer (string, pos, pos_byte, lim, lim_byte, n,
          raw_pattern_size_byte = XSTRING (string)->size;
          raw_pattern = (char *) alloca (raw_pattern_size + 1);
          copy_text (XSTRING (string)->data, raw_pattern,
-                    XSTRING (string)->size_byte, 1, 0);
+                    STRING_BYTES (XSTRING (string)), 1, 0);
        }
 
       /* Copy and optionally translate the pattern.  */
@@ -1165,7 +1175,7 @@ search_buffer (string, pos, pos_byte, lim, lim_byte, n,
          while (--len >= 0)
            {
              unsigned char workbuf[4], *str;
-             int c, translated;
+             int c, translated, inverse;
              int in_charlen, charlen;
 
              /* If we got here and the RE flag is set, it's because we're
@@ -1180,7 +1190,7 @@ search_buffer (string, pos, pos_byte, lim, lim_byte, n,
 
              c = STRING_CHAR_AND_LENGTH (base_pat, len_byte, in_charlen);
              /* Translate the character, if requested.  */
-             translated = TRANSLATE (trt, c);
+             TRANSLATE (translated, trt, c);
              /* If translation changed the byte-length, go back
                 to the original character.  */
              charlen = CHAR_STRING (translated, workbuf, str);
@@ -1190,10 +1200,11 @@ search_buffer (string, pos, pos_byte, lim, lim_byte, n,
                  charlen = CHAR_STRING (c, workbuf, str);
                }
 
+             TRANSLATE (inverse, inverse_trt, c);
+
              /* Did this char actually get translated?
                 Would any other char get translated into it?  */
-             if (translated != c
-                 || TRANSLATE (inverse_trt, c) != c)
+             if (translated != c || inverse != c)
                {
                  /* Keep track of which character set row
                     contains the characters that need translation.  */
@@ -1206,7 +1217,7 @@ search_buffer (string, pos, pos_byte, lim, lim_byte, n,
                    simple = 0;
                    /* ??? Handa: this must do simple = 0
                       if c is a composite character.  */
-               }                   
+               }
 
              /* Store this character into the translated pattern.  */
              bcopy (str, pat, charlen);
@@ -1219,7 +1230,7 @@ search_buffer (string, pos, pos_byte, lim, lim_byte, n,
        {
          while (--len >= 0)
            {
-             int c, translated;
+             int c, translated, inverse;
 
              /* If we got here and the RE flag is set, it's because we're
                 dealing with a regexp known to be trivial, so the backslash
@@ -1230,12 +1241,12 @@ search_buffer (string, pos, pos_byte, lim, lim_byte, n,
                  base_pat++;
                }
              c = *base_pat++;
-             translated = TRANSLATE (trt, c);
+             TRANSLATE (translated, trt, c);
+             TRANSLATE (inverse, inverse_trt, c);
 
              /* Did this char actually get translated?
                 Would any other char get translated into it?  */
-             if (translated != c
-                 || TRANSLATE (inverse_trt, c) != c)
+             if (translated != c || inverse != c)
                {
                  /* Keep track of which character set row
                     contains the characters that need translation.  */
@@ -1246,7 +1257,7 @@ search_buffer (string, pos, pos_byte, lim, lim_byte, n,
                    /* If two different rows appear, needing translation,
                       then we cannot use boyer_moore search.  */
                    simple = 0;
-               }                   
+               }
              *pat++ = translated;
            }
        }
@@ -1257,7 +1268,8 @@ search_buffer (string, pos, pos_byte, lim, lim_byte, n,
 
       if (simple)
        return boyer_moore (n, pat, len, len_byte, trt, inverse_trt,
-                           pos, pos_byte, lim, lim_byte);
+                           pos, pos_byte, lim, lim_byte,
+                           charset_base);
       else
        return simple_search (n, pat, len, len_byte, trt,
                              pos, pos_byte, lim, lim_byte);
@@ -1286,6 +1298,7 @@ simple_search (n, pat, len, len_byte, trt, pos, pos_byte, lim, lim_byte)
      int lim, lim_byte;
 {
   int multibyte = ! NILP (current_buffer->enable_multibyte_characters);
+  int forward = n > 0;
 
   if (lim > pos && multibyte)
     while (n > 0)
@@ -1304,22 +1317,23 @@ simple_search (n, pat, len, len_byte, trt, pos, pos_byte, lim, lim_byte)
            while (this_len > 0)
              {
                int charlen, buf_charlen;
-               int pat_ch = STRING_CHAR_AND_LENGTH (p, this_len_byte, charlen);
-               int buf_ch;
-
-               this_len_byte -= charlen;
-               this_len--;
-               p += charlen;
+               int pat_ch, buf_ch;
 
+               pat_ch = STRING_CHAR_AND_LENGTH (p, this_len_byte, charlen);
                buf_ch = STRING_CHAR_AND_LENGTH (BYTE_POS_ADDR (this_pos_byte),
                                                 ZV_BYTE - this_pos_byte,
                                                 buf_charlen);
-               this_pos_byte += buf_charlen;
-               this_pos++;
-               buf_ch = TRANSLATE (trt, buf_ch);
+               TRANSLATE (buf_ch, trt, buf_ch);
 
                if (buf_ch != pat_ch)
                  break;
+
+               this_len_byte -= charlen;
+               this_len--;
+               p += charlen;
+
+               this_pos_byte += buf_charlen;
+               this_pos++;
              }
 
            if (this_len == 0)
@@ -1351,12 +1365,13 @@ simple_search (n, pat, len, len_byte, trt, pos, pos_byte, lim, lim_byte)
              {
                int pat_ch = *p++;
                int buf_ch = FETCH_BYTE (this_pos);
-               this_len--;
-               this_pos++;
-               buf_ch = TRANSLATE (trt, buf_ch);
+               TRANSLATE (buf_ch, trt, buf_ch);
 
                if (buf_ch != pat_ch)
                  break;
+
+               this_len--;
+               this_pos++;
              }
 
            if (this_len == 0)
@@ -1389,22 +1404,22 @@ simple_search (n, pat, len, len_byte, trt, pos, pos_byte, lim, lim_byte)
            while (this_len > 0)
              {
                int charlen, buf_charlen;
-               int pat_ch = STRING_CHAR_AND_LENGTH (p, this_len_byte, charlen);
-               int buf_ch;
-
-               this_len_byte -= charlen;
-               this_len--;
-               p += charlen;
+               int pat_ch, buf_ch;
 
+               pat_ch = STRING_CHAR_AND_LENGTH (p, this_len_byte, charlen);
                buf_ch = STRING_CHAR_AND_LENGTH (BYTE_POS_ADDR (this_pos_byte),
                                                 ZV_BYTE - this_pos_byte,
                                                 buf_charlen);
-               this_pos_byte += buf_charlen;
-               this_pos++;
-               buf_ch = TRANSLATE (trt, buf_ch);
+               TRANSLATE (buf_ch, trt, buf_ch);
 
                if (buf_ch != pat_ch)
                  break;
+
+               this_len_byte -= charlen;
+               this_len--;
+               p += charlen;
+               this_pos_byte += buf_charlen;
+               this_pos++;
              }
 
            if (this_len == 0)
@@ -1436,12 +1451,12 @@ simple_search (n, pat, len, len_byte, trt, pos, pos_byte, lim, lim_byte)
              {
                int pat_ch = *p++;
                int buf_ch = FETCH_BYTE (this_pos);
-               this_len--;
-               this_pos++;
-               buf_ch = TRANSLATE (trt, buf_ch);
+               TRANSLATE (buf_ch, trt, buf_ch);
 
                if (buf_ch != pat_ch)
                  break;
+               this_len--;
+               this_pos++;
              }
 
            if (this_len == 0)
@@ -1458,7 +1473,14 @@ simple_search (n, pat, len, len_byte, trt, pos, pos_byte, lim, lim_byte)
 
  stop:
   if (n == 0)
-    return pos;
+    {
+      if (forward)
+       set_search_regs ((multibyte ? pos_byte : pos) - len_byte, len_byte);
+      else
+       set_search_regs (multibyte ? pos_byte : pos, len_byte);
+
+      return pos;
+    }
   else if (n > 0)
     return -n;
   else
@@ -1480,7 +1502,7 @@ simple_search (n, pat, len, len_byte, trt, pos, pos_byte, lim, lim_byte)
 
 static int
 boyer_moore (n, base_pat, len, len_byte, trt, inverse_trt,
-            pos, pos_byte, lim, lim_byte)
+            pos, pos_byte, lim, lim_byte, charset_base)
      int n;
      unsigned char *base_pat;
      int len, len_byte;
@@ -1488,6 +1510,7 @@ boyer_moore (n, base_pat, len, len_byte, trt, inverse_trt,
      Lisp_Object inverse_trt;
      int pos, pos_byte;
      int lim, lim_byte;
+     int charset_base;
 {
   int direction = ((n > 0) ? 1 : -1);
   register int dirlen;
@@ -1572,6 +1595,7 @@ boyer_moore (n, base_pat, len, len_byte, trt, inverse_trt,
       if (! NILP (trt))
        {
          int ch;
+         int untranslated;
          int this_translated = 1;
 
          if (multibyte
@@ -1580,40 +1604,63 @@ boyer_moore (n, base_pat, len, len_byte, trt, inverse_trt,
              unsigned char *charstart = ptr;
              while (! CHAR_HEAD_P (*charstart))
                charstart--;
-             if (! CHAR_HEAD_P (*ptr))
+             untranslated = STRING_CHAR (charstart, ptr - charstart + 1);
+             if (charset_base == (untranslated & ~0xff))
+               {
+                 TRANSLATE (ch, trt, untranslated);
+                 if (! CHAR_HEAD_P (*ptr))
+                   {
+                     translate_prev_byte = ptr[-1];
+                     if (! CHAR_HEAD_P (translate_prev_byte))
+                       translate_anteprev_byte = ptr[-2];
+                   }
+               }
+             else
                {
-                 translate_prev_byte = ptr[-1];
-                 if (! CHAR_HEAD_P (translate_prev_byte))
-                   translate_anteprev_byte = ptr[-2];
+                 this_translated = 0;
+                 ch = *ptr;
                }
-             ch = STRING_CHAR (charstart, ptr - charstart + 1);
-             ch = TRANSLATE (trt, ch);
            }
          else if (!multibyte)
-           ch = TRANSLATE (trt, *ptr);
+           TRANSLATE (ch, trt, *ptr);
          else
            {
              ch = *ptr;
              this_translated = 0;
            }
 
-         k = j = (unsigned char) ch;
+         if (ch > 0400)
+           j = ((unsigned char) ch) | 0200;
+         else
+           j = (unsigned char) ch;
+
          if (i == infinity)
            stride_for_teases = BM_tab[j];
+
          BM_tab[j] = dirlen - i;
          /* A translation table is accompanied by its inverse -- see */
          /* comment following downcase_table for details */ 
          if (this_translated)
-           while (1)
-             {
-               ch = TRANSLATE (inverse_trt, ch);
-               /* For all the characters that map into K,
-                  set up simple_translate to map them into K.  */
-               simple_translate[(unsigned char) ch] = k;
-               if ((unsigned char) ch == k)
-                 break;
-               BM_tab[(unsigned char) ch] = dirlen - i;
-             }
+           {
+             int starting_ch = ch;
+             int starting_j = j;
+             while (1)
+               {
+                 TRANSLATE (ch, inverse_trt, ch);
+                 if (ch > 0400)
+                   j = ((unsigned char) ch) | 0200;
+                 else
+                   j = (unsigned char) ch;
+
+                 /* For all the characters that map into CH,
+                    set up simple_translate to map the last byte
+                    into STARTING_J.  */
+                 simple_translate[j] = starting_j;
+                 if (ch == starting_ch)
+                   break;
+                 BM_tab[j] = dirlen - i;
+               }
+           }
        }
       else
        {
@@ -1648,14 +1695,22 @@ boyer_moore (n, base_pat, len, len_byte, trt, inverse_trt,
       QUIT;
       pat = base_pat;
       limit = pos_byte - dirlen + direction;
-      limit = ((direction > 0)
-              ? BUFFER_CEILING_OF (limit)
-              : BUFFER_FLOOR_OF (limit));
-      /* LIMIT is now the last (not beyond-last!) value POS_BYTE
-        can take on without hitting edge of buffer or the gap.  */
-      limit = ((direction > 0)
-              ? min (lim_byte - 1, min (limit, pos_byte + 20000))
-              : max (lim_byte, max (limit, pos_byte - 20000)));
+      if (direction > 0)
+       {
+         limit = BUFFER_CEILING_OF (limit);
+         /* LIMIT is now the last (not beyond-last!) value POS_BYTE
+            can take on without hitting edge of buffer or the gap.  */
+         limit = min (limit, pos_byte + 20000);
+         limit = min (limit, lim_byte - 1);
+       }
+      else
+       {
+         limit = BUFFER_FLOOR_OF (limit);
+         /* LIMIT is now the last (not beyond-last!) value POS_BYTE
+            can take on without hitting edge of buffer or the gap.  */
+         limit = max (limit, pos_byte - 20000);
+         limit = max (limit, lim_byte);
+       }
       tail_end = BUFFER_CEILING_OF (pos_byte) + 1;
       tail_end_ptr = BYTE_POS_ADDR (tail_end);
 
@@ -1898,13 +1953,13 @@ wordify (string)
 
   adjust = - punct_count + 5 * (word_count - 1) + 4;
   val = make_uninit_multibyte_string (len + adjust,
-                                     XSTRING (string)->size_byte + adjust);
+                                     STRING_BYTES (XSTRING (string)) + adjust);
 
   o = XSTRING (val)->data;
   *o++ = '\\';
   *o++ = 'b';
 
-  for (i = 0; i < XSTRING (val)->size_byte; i++)
+  for (i = 0; i < STRING_BYTES (XSTRING (val)); i++)
     if (SYNTAX (p[i]) == Sword)
       *o++ = p[i];
     else if (i > 0 && SYNTAX (p[i-1]) == Sword && --word_count)
@@ -2230,7 +2285,7 @@ since only regular expressions have distinguished subexpressions.")
 
          accum = Qnil;
 
-         for (pos_byte = 0, pos = 0; pos_byte < XSTRING (newtext)->size_byte;)
+         for (pos_byte = 0, pos = 0; pos_byte < STRING_BYTES (XSTRING (newtext));)
            {
              int substart = -1;
              int subend;
@@ -2504,7 +2559,7 @@ to hold all the values, and if INTEGERS is non-nil, no consing is done.")
 }
 
 
-DEFUN ("store-match-data", Fstore_match_data, Sstore_match_data, 1, 1, 0,
+DEFUN ("set-match-data", Fset_match_data, Sset_match_data, 1, 1, 0,
   "Set internal data on last search match from elements of LIST.\n\
 LIST should have been created by calling `match-data' previously.")
   (list)
@@ -2640,12 +2695,12 @@ DEFUN ("regexp-quote", Fregexp_quote, Sregexp_quote, 1, 1, 0,
 
   CHECK_STRING (string, 0);
 
-  temp = (unsigned char *) alloca (XSTRING (string)->size_byte * 2);
+  temp = (unsigned char *) alloca (STRING_BYTES (XSTRING (string)) * 2);
 
   /* Now copy the data into the new string, inserting escapes. */
 
   in = XSTRING (string)->data;
-  end = in + XSTRING (string)->size_byte;
+  end = in + STRING_BYTES (XSTRING (string));
   out = temp; 
 
   for (; in != end; in++)
@@ -2658,11 +2713,13 @@ DEFUN ("regexp-quote", Fregexp_quote, Sregexp_quote, 1, 1, 0,
       *out++ = *in;
     }
 
-  return make_multibyte_string (temp,
+  return make_specified_string (temp,
                                XSTRING (string)->size + backslashes_added,
-                               out - temp);
+                               out - temp,
+                               STRING_MULTIBYTE (string));
 }
 \f  
+void
 syms_of_search ()
 {
   register int i;
@@ -2712,6 +2769,6 @@ syms_of_search ()
   defsubr (&Smatch_beginning);
   defsubr (&Smatch_end);
   defsubr (&Smatch_data);
-  defsubr (&Sstore_match_data);
+  defsubr (&Sset_match_data);
   defsubr (&Sregexp_quote);
 }