New file. From J. David Anglin.
[gnulib.git] / regex.c
diff --git a/regex.c b/regex.c
index 2e06d0e..97cc409 100644 (file)
--- a/regex.c
+++ b/regex.c
@@ -3064,7 +3064,12 @@ regex_compile (pattern, size, syntax, bufp)
 
          GET_BUFFER_SPACE (MAX_MULTIBYTE_LENGTH);
          {
-           int len = CHAR_STRING (c, b);
+           int len;
+
+           if (multibyte)
+             len = CHAR_STRING (c, b);
+           else
+             *b = c, len = 1;
            b += len;
            (*pending_exact) += len;
          }
@@ -3375,7 +3380,15 @@ analyse_first (p, pend, fastmap, multibyte)
         with `break'.  */
 
        case exactn:
-         if (fastmap) fastmap[p[1]] = 1;
+         if (fastmap)
+           {
+             int c = RE_STRING_CHAR (p + 1, pend - p);
+
+             if (SINGLE_BYTE_CHAR_P (c))
+               fastmap[c] = 1;
+             else
+               fastmap[p[1]] = 1;
+           }
          break;
 
 
@@ -4291,7 +4304,9 @@ re_match (bufp, string, size, pos, regs)
 {
   int result = re_match_2_internal (bufp, NULL, 0, string, size,
                                    pos, regs, size);
+#if defined (C_ALLOCA) && !defined (REGEX_MALLOC)
   alloca (0);
+#endif
   return result;
 }
 #endif /* not emacs */
@@ -4335,7 +4350,9 @@ re_match_2 (bufp, string1, size1, string2, size2, pos, regs, stop)
 
   result = re_match_2_internal (bufp, string1, size1, string2, size2,
                                pos, regs, stop);
+#if defined (C_ALLOCA) && !defined (REGEX_MALLOC)
   alloca (0);
+#endif
   return result;
 }
 
@@ -5593,7 +5610,8 @@ re_comp (s)
   if (!s)
     {
       if (!re_comp_buf.buffer)
-       return gettext ("No previous regular expression");
+        /* Yes, we're discarding `const' here if !HAVE_LIBINTL.  */
+       return (char *) gettext ("No previous regular expression");
       return 0;
     }
 
@@ -5601,12 +5619,14 @@ re_comp (s)
     {
       re_comp_buf.buffer = (unsigned char *) malloc (200);
       if (re_comp_buf.buffer == NULL)
-        return gettext (re_error_msgid[(int) REG_ESPACE]);
+        /* Yes, we're discarding `const' here if !HAVE_LIBINTL.  */
+        return (char *) gettext (re_error_msgid[(int) REG_ESPACE]);
       re_comp_buf.allocated = 200;
 
       re_comp_buf.fastmap = (char *) malloc (1 << BYTEWIDTH);
       if (re_comp_buf.fastmap == NULL)
-       return gettext (re_error_msgid[(int) REG_ESPACE]);
+       /* Yes, we're discarding `const' here if !HAVE_LIBINTL.  */
+       return (char *) gettext (re_error_msgid[(int) REG_ESPACE]);
     }
 
   /* Since `re_exec' always passes NULL for the `regs' argument, we