This commit was generated by cvs2svn to compensate for changes in r5670,
[chise/xemacs-chise.git.1] / src / regex.c
index b2a7a64..1b68465 100644 (file)
 #define _GNU_SOURCE 1
 #endif
 
-#ifdef emacs
-/* Converts the pointer to the char to BEG-based offset from the start.         */
-#define PTR_TO_OFFSET(d) (MATCHING_IN_FIRST_STRING                     \
-                         ? (d) - string1 : (d) - (string2 - size1))
-#else
-#define PTR_TO_OFFSET(d) 0
-#endif
-
 /* We assume non-Mule if emacs isn't defined. */
 #ifndef emacs
 #undef MULE
@@ -112,10 +104,7 @@ complex_vars_of_regex (void)
 {
 }
 
-#endif /* MULE */
-
-#define RE_TRANSLATE(ch) TRT_TABLE_OF (translate, (Emchar) ch)
-#define TRANSLATE_P(tr) (!NILP (tr))
+#endif /* not MULE */
 
 #else  /* not emacs */
 
@@ -131,11 +120,14 @@ char *malloc ();
 char *realloc ();
 #endif
 
-/* Other types */
-#include <stddef.h> /* for ptrdiff_t */
-
 #define charptr_emchar(str)            ((Emchar) (str)[0])
 
+#if (LONGBITS > INTBITS)
+# define EMACS_INT long
+#else
+# define EMACS_INT int
+#endif
+
 typedef int Emchar;
 
 #define INC_CHARPTR(p) ((p)++)
@@ -169,7 +161,7 @@ init_syntax_once (void)
 
   if (!done)
     {
-      const char *word_syntax_chars =
+      CONST char *word_syntax_chars =
        "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_";
 
       memset (re_syntax_table, 0, sizeof (re_syntax_table));
@@ -181,16 +173,11 @@ init_syntax_once (void)
     }
 }
 
-#endif /* SYNTAX_TABLE */
+#endif /* not SYNTAX_TABLE */
 
 #define SYNTAX_UNSAFE(ignored, c) re_syntax_table[c]
-#undef SYNTAX_FROM_CACHE
-#define SYNTAX_FROM_CACHE SYNTAX_UNSAFE
 
-#define RE_TRANSLATE(c) translate[(unsigned char) (c)]
-#define TRANSLATE_P(tr) tr
-
-#endif /* emacs */
+#endif /* not emacs */
 
 /* Under XEmacs, this is needed because we don't define it elsewhere. */
 #ifdef SWITCH_ENUM_BUG
@@ -299,10 +286,10 @@ init_syntax_once (void)
 #include <alloca.h>
 #else /* not __GNUC__ or HAVE_ALLOCA_H */
 #ifndef _AIX /* Already did AIX, up at the top.  */
-void *alloca ();
+char *alloca ();
 #endif /* not _AIX */
-#endif /* HAVE_ALLOCA_H */
-#endif /* __GNUC__ */
+#endif /* not HAVE_ALLOCA_H */
+#endif /* not __GNUC__ */
 
 #endif /* not alloca */
 
@@ -317,7 +304,7 @@ void *alloca ();
 /* No need to do anything to free, after alloca.  */
 #define REGEX_FREE(arg) ((void)0) /* Do nothing!  But inhibit gcc warning.  */
 
-#endif /* REGEX_MALLOC */
+#endif /* not REGEX_MALLOC */
 
 /* Define how to allocate the failure stack.  */
 
@@ -346,8 +333,8 @@ void *alloca ();
 /* No need to explicitly free anything.  */
 #define REGEX_FREE_STACK(arg)
 
-#endif /* REGEX_MALLOC */
-#endif /* REL_ALLOC */
+#endif /* not REGEX_MALLOC */
+#endif /* not REL_ALLOC */
 
 
 /* True if `size1' is non-NULL and PTR is pointing anywhere inside
@@ -365,17 +352,14 @@ void *alloca ();
 
 #define BYTEWIDTH 8 /* In bits.  */
 
-#define STREQ(s1, s2) (strcmp (s1, s2) == 0)
+#define STREQ(s1, s2) ((strcmp (s1, s2) == 0))
 
 #undef MAX
 #undef MIN
 #define MAX(a, b) ((a) > (b) ? (a) : (b))
 #define MIN(a, b) ((a) < (b) ? (a) : (b))
 
-/* Type of source-pattern and string chars.  */
-typedef const unsigned char re_char;
-
-typedef char re_bool;
+typedef char boolean;
 #define false 0
 #define true 1
 
@@ -570,7 +554,7 @@ typedef enum
 
 #ifdef DEBUG
 static void
-extract_number (int *dest, re_char *source)
+extract_number (int *dest, unsigned char *source)
 {
   int temp = SIGN_EXTEND_CHAR (*(source + 1));
   *dest = *source & 0377;
@@ -673,11 +657,11 @@ print_fastmap (char *fastmap)
    the START pointer into it and ending just before the pointer END.  */
 
 static void
-print_partial_compiled_pattern (re_char *start, re_char *end)
+print_partial_compiled_pattern (unsigned char *start, unsigned char *end)
 {
   int mcnt, mcnt2;
-  unsigned char *p = (unsigned char *) start;
-  re_char *pend = end;
+  unsigned char *p = start;
+  unsigned char *pend = end;
 
   if (start == NULL)
     {
@@ -955,7 +939,7 @@ print_partial_compiled_pattern (re_char *start, re_char *end)
 static void
 print_compiled_pattern (struct re_pattern_buffer *bufp)
 {
-  re_char *buffer = bufp->buffer;
+  unsigned char *buffer = bufp->buffer;
 
   print_partial_compiled_pattern (buffer, buffer + bufp->used);
   printf ("%ld bytes used/%ld bytes allocated.\n", bufp->used,
@@ -981,14 +965,14 @@ print_compiled_pattern (struct re_pattern_buffer *bufp)
 
 
 static void
-print_double_string (re_char *where, re_char *string1, int size1,
-                    re_char *string2, int size2)
+print_double_string (CONST char *where, CONST char *string1, int size1,
+                    CONST char *string2, int size2)
 {
   if (where == NULL)
     printf ("(null)");
   else
     {
-      Element_count this_char;
+      unsigned int this_char;
 
       if (FIRST_STRING_P (where))
         {
@@ -1016,7 +1000,7 @@ print_double_string (re_char *where, re_char *string1, int size1,
 #define DEBUG_PRINT_COMPILED_PATTERN(p, s, e)
 #define DEBUG_PRINT_DOUBLE_STRING(w, s1, sz1, s2, sz2)
 
-#endif /* DEBUG */
+#endif /* not DEBUG */
 \f
 /* Set by `re_set_syntax' to the current regexp syntax to recognize.  Can
    also be assigned to arbitrarily: each pattern buffer stores its own
@@ -1047,7 +1031,7 @@ re_set_syntax (reg_syntax_t syntax)
    POSIX doesn't require that we do anything for REG_NOERROR,
    but why not be nice?  */
 
-static const char *re_error_msgid[] =
+static CONST char *re_error_msgid[] =
 {
   "Success",                                   /* REG_NOERROR */
   "No match",                                  /* REG_NOMATCH */
@@ -1139,7 +1123,7 @@ int re_max_failures = 2000;
 
 union fail_stack_elt
 {
-  re_char *pointer;
+  unsigned char *pointer;
   int integer;
 };
 
@@ -1148,8 +1132,8 @@ typedef union fail_stack_elt fail_stack_elt_t;
 typedef struct
 {
   fail_stack_elt_t *stack;
-  Element_count size;
-  Element_count avail;                 /* Offset of next open position.  */
+  unsigned size;
+  unsigned avail;                      /* Offset of next open position.  */
 } fail_stack_type;
 
 #define FAIL_STACK_EMPTY()     (fail_stack.avail == 0)
@@ -1192,7 +1176,7 @@ typedef struct
    REGEX_REALLOCATE_STACK requires `destination' be declared.   */
 
 #define DOUBLE_FAIL_STACK(fail_stack)                                  \
-  ((int) (fail_stack).size > re_max_failures * MAX_FAILURE_ITEMS       \
+  ((fail_stack).size > re_max_failures * MAX_FAILURE_ITEMS             \
    ? 0                                                                 \
    : ((fail_stack).stack = (fail_stack_elt_t *)                                \
         REGEX_REALLOCATE_STACK ((fail_stack).stack,                    \
@@ -1259,89 +1243,85 @@ typedef struct
    Does `return FAILURE_CODE' if runs out of memory.  */
 
 #if !defined (REGEX_MALLOC) && !defined (REL_ALLOC)
-#define DECLARE_DESTINATION char *destination
+#define DECLARE_DESTINATION char *destination;
 #else
-#define DECLARE_DESTINATION DECLARE_NOTHING
+#define DECLARE_DESTINATION
 #endif
 
 #define PUSH_FAILURE_POINT(pattern_place, string_place, failure_code)  \
-do {                                                                   \
-  DECLARE_DESTINATION;                                                 \
-  /* Must be int, so when we don't save any registers, the arithmetic  \
-     of 0 + -1 isn't done as unsigned.  */                             \
-  int this_reg;                                                                \
-                                                                       \
-  DEBUG_STATEMENT (failure_id++);                                      \
-  DEBUG_STATEMENT (nfailure_points_pushed++);                          \
-  DEBUG_PRINT2 ("\nPUSH_FAILURE_POINT #%u:\n", failure_id);            \
-  DEBUG_PRINT2 ("  Before push, next avail: %lu\n",                    \
-               (unsigned long) (fail_stack).avail);                    \
-  DEBUG_PRINT2 ("                     size: %lu\n",                    \
-               (unsigned long) (fail_stack).size);                     \
-                                                                       \
-  DEBUG_PRINT2 ("  slots needed: %d\n", NUM_FAILURE_ITEMS);            \
-  DEBUG_PRINT2 ("     available: %ld\n",                               \
-               (long) REMAINING_AVAIL_SLOTS);                          \
+  do {                                                                 \
+    DECLARE_DESTINATION                                                        \
+    /* Must be int, so when we don't save any registers, the arithmetic        \
+       of 0 + -1 isn't done as unsigned.  */                           \
+    int this_reg;                                                      \
+                                                                       \
+    DEBUG_STATEMENT (failure_id++);                                    \
+    DEBUG_STATEMENT (nfailure_points_pushed++);                                \
+    DEBUG_PRINT2 ("\nPUSH_FAILURE_POINT #%u:\n", failure_id);          \
+    DEBUG_PRINT2 ("  Before push, next avail: %d\n", (fail_stack).avail);\
+    DEBUG_PRINT2 ("                     size: %d\n", (fail_stack).size);\
                                                                        \
-  /* Ensure we have enough space allocated for what we will push.  */  \
-  while (REMAINING_AVAIL_SLOTS < NUM_FAILURE_ITEMS)                    \
-    {                                                                  \
-      if (!DOUBLE_FAIL_STACK (fail_stack))                             \
-       return failure_code;                                            \
+    DEBUG_PRINT2 ("  slots needed: %d\n", NUM_FAILURE_ITEMS);          \
+    DEBUG_PRINT2 ("     available: %d\n", REMAINING_AVAIL_SLOTS);      \
                                                                        \
-      DEBUG_PRINT2 ("\n  Doubled stack; size now: %lu\n",              \
-                   (unsigned long) (fail_stack).size);                 \
-      DEBUG_PRINT2 ("  slots available: %ld\n",                                \
-                   (long) REMAINING_AVAIL_SLOTS);                      \
-    }                                                                  \
+    /* Ensure we have enough space allocated for what we will push.  */        \
+    while (REMAINING_AVAIL_SLOTS < NUM_FAILURE_ITEMS)                  \
+      {                                                                        \
+        if (!DOUBLE_FAIL_STACK (fail_stack))                           \
+          return failure_code;                                         \
                                                                        \
-  /* Push the info, starting with the registers.  */                   \
-  DEBUG_PRINT1 ("\n");                                                 \
+        DEBUG_PRINT2 ("\n  Doubled stack; size now: %d\n",             \
+                      (fail_stack).size);                              \
+        DEBUG_PRINT2 ("  slots available: %d\n", REMAINING_AVAIL_SLOTS);\
+      }                                                                        \
                                                                        \
-  for (this_reg = lowest_active_reg; this_reg <= highest_active_reg;   \
-       this_reg++)                                                     \
-    {                                                                  \
-      DEBUG_PRINT2 ("  Pushing reg: %d\n", this_reg);                  \
-      DEBUG_STATEMENT (num_regs_pushed++);                             \
+    /* Push the info, starting with the registers.  */                 \
+    DEBUG_PRINT1 ("\n");                                               \
                                                                        \
-      DEBUG_PRINT2 ("    start: 0x%lx\n", (long) regstart[this_reg]);  \
-      PUSH_FAILURE_POINTER (regstart[this_reg]);                       \
+    for (this_reg = lowest_active_reg; this_reg <= highest_active_reg; \
+         this_reg++)                                                   \
+      {                                                                        \
+       DEBUG_PRINT2 ("  Pushing reg: %d\n", this_reg);                 \
+        DEBUG_STATEMENT (num_regs_pushed++);                           \
                                                                        \
-      DEBUG_PRINT2 ("    end: 0x%lx\n", (long) regend[this_reg]);      \
-      PUSH_FAILURE_POINTER (regend[this_reg]);                         \
+       DEBUG_PRINT2 ("    start: 0x%p\n", regstart[this_reg]);         \
+        PUSH_FAILURE_POINTER (regstart[this_reg]);                     \
+                                                                        \
+       DEBUG_PRINT2 ("    end: 0x%p\n", regend[this_reg]);             \
+        PUSH_FAILURE_POINTER (regend[this_reg]);                       \
                                                                        \
-      DEBUG_PRINT2 ("    info: 0x%lx\n      ",                         \
-                   * (long *) (&reg_info[this_reg]));                  \
-      DEBUG_PRINT2 (" match_null=%d",                                  \
-                   REG_MATCH_NULL_STRING_P (reg_info[this_reg]));      \
-      DEBUG_PRINT2 (" active=%d", IS_ACTIVE (reg_info[this_reg]));     \
-      DEBUG_PRINT2 (" matched_something=%d",                           \
-                   MATCHED_SOMETHING (reg_info[this_reg]));            \
-      DEBUG_PRINT2 (" ever_matched_something=%d",                      \
-                   EVER_MATCHED_SOMETHING (reg_info[this_reg]));       \
-      DEBUG_PRINT1 ("\n");                                             \
-      PUSH_FAILURE_ELT (reg_info[this_reg].word);                      \
-    }                                                                  \
+       DEBUG_PRINT2 ("    info: 0x%lx\n      ",                        \
+                     * (unsigned long *) (&reg_info[this_reg]));       \
+        DEBUG_PRINT2 (" match_null=%d",                                        \
+                      REG_MATCH_NULL_STRING_P (reg_info[this_reg]));   \
+        DEBUG_PRINT2 (" active=%d", IS_ACTIVE (reg_info[this_reg]));   \
+        DEBUG_PRINT2 (" matched_something=%d",                         \
+                      MATCHED_SOMETHING (reg_info[this_reg]));         \
+        DEBUG_PRINT2 (" ever_matched=%d",                              \
+                      EVER_MATCHED_SOMETHING (reg_info[this_reg]));    \
+       DEBUG_PRINT1 ("\n");                                            \
+        PUSH_FAILURE_ELT (reg_info[this_reg].word);                    \
+      }                                                                        \
                                                                        \
-  DEBUG_PRINT2 ("  Pushing  low active reg: %d\n", lowest_active_reg); \
-  PUSH_FAILURE_INT (lowest_active_reg);                                        \
+    DEBUG_PRINT2 ("  Pushing  low active reg: %d\n", lowest_active_reg);\
+    PUSH_FAILURE_INT (lowest_active_reg);                              \
                                                                        \
-  DEBUG_PRINT2 ("  Pushing high active reg: %d\n", highest_active_reg);        \
-  PUSH_FAILURE_INT (highest_active_reg);                               \
+    DEBUG_PRINT2 ("  Pushing high active reg: %d\n", highest_active_reg);\
+    PUSH_FAILURE_INT (highest_active_reg);                             \
                                                                        \
-  DEBUG_PRINT2 ("  Pushing pattern 0x%lx: \n", (long) pattern_place);  \
-  DEBUG_PRINT_COMPILED_PATTERN (bufp, pattern_place, pend);            \
-  PUSH_FAILURE_POINTER (pattern_place);                                        \
+    DEBUG_PRINT2 ("  Pushing pattern 0x%p: ", pattern_place);          \
+    DEBUG_PRINT_COMPILED_PATTERN (bufp, pattern_place, pend);          \
+    PUSH_FAILURE_POINTER (pattern_place);                              \
                                                                        \
-  DEBUG_PRINT2 ("  Pushing string 0x%lx: `", (long) string_place);     \
-  DEBUG_PRINT_DOUBLE_STRING (string_place, string1, size1, string2,    \
-                            size2);                                    \
-  DEBUG_PRINT1 ("'\n");                                                        \
-  PUSH_FAILURE_POINTER (string_place);                                 \
+    DEBUG_PRINT2 ("  Pushing string 0x%p: `", string_place);           \
+    DEBUG_PRINT_DOUBLE_STRING (string_place, string1, size1, string2,   \
+                                size2);                                \
+    DEBUG_PRINT1 ("'\n");                                              \
+    PUSH_FAILURE_POINTER (string_place);                               \
                                                                        \
-  DEBUG_PRINT2 ("  Pushing failure id: %u\n", failure_id);             \
-  DEBUG_PUSH (failure_id);                                             \
-} while (0)
+    DEBUG_PRINT2 ("  Pushing failure id: %u\n", failure_id);           \
+    DEBUG_PUSH (failure_id);                                           \
+  } while (0)
 
 /* This is the number of items that are pushed and popped on the stack
    for each register.  */
@@ -1366,7 +1346,7 @@ do {                                                                      \
     + NUM_NONREG_ITEMS)
 
 /* How many items can still be added to the stack without overflowing it.  */
-#define REMAINING_AVAIL_SLOTS ((int) ((fail_stack).size - (fail_stack).avail))
+#define REMAINING_AVAIL_SLOTS ((fail_stack).size - (fail_stack).avail)
 
 
 /* Pops what PUSH_FAIL_STACK pushes.
@@ -1381,21 +1361,18 @@ do {                                                                    \
    Also assumes the variables `fail_stack' and (if debugging), `bufp',
    `pend', `string1', `size1', `string2', and `size2'.  */
 
-#define POP_FAILURE_POINT(str, pat, low_reg, high_reg,                 \
-                          regstart, regend, reg_info)                  \
-do {                                                                   \
+#define POP_FAILURE_POINT(str, pat, low_reg, high_reg, regstart, regend, reg_info)\
+{                                                                      \
   DEBUG_STATEMENT (fail_stack_elt_t ffailure_id;)                      \
   int this_reg;                                                                \
-  const unsigned char *string_temp;                                    \
+  CONST unsigned char *string_temp;                                    \
                                                                        \
   assert (!FAIL_STACK_EMPTY ());                                       \
                                                                        \
   /* Remove failure points and point to how many regs pushed.  */      \
   DEBUG_PRINT1 ("POP_FAILURE_POINT:\n");                               \
-  DEBUG_PRINT2 ("  Before pop, next avail: %lu\n",                     \
-               (unsigned long) fail_stack.avail);                      \
-  DEBUG_PRINT2 ("                    size: %lu\n",                     \
-               (unsigned long) fail_stack.size);                       \
+  DEBUG_PRINT2 ("  Before pop, next avail: %d\n", fail_stack.avail);   \
+  DEBUG_PRINT2 ("                    size: %d\n", fail_stack.size);    \
                                                                        \
   assert (fail_stack.avail >= NUM_NONREG_ITEMS);                       \
                                                                        \
@@ -1408,14 +1385,14 @@ do {                                                                    \
      saved NULL, thus retaining our current position in the string.  */        \
   string_temp = POP_FAILURE_POINTER ();                                        \
   if (string_temp != NULL)                                             \
-    str = string_temp;                                                 \
+    str = (CONST char *) string_temp;                                  \
                                                                        \
-  DEBUG_PRINT2 ("  Popping string 0x%lx: `",  (long) str);             \
+  DEBUG_PRINT2 ("  Popping string 0x%p: `",  str);                     \
   DEBUG_PRINT_DOUBLE_STRING (str, string1, size1, string2, size2);     \
   DEBUG_PRINT1 ("'\n");                                                        \
                                                                        \
   pat = (unsigned char *) POP_FAILURE_POINTER ();                      \
-  DEBUG_PRINT2 ("  Popping pattern 0x%lx: ", (long) pat);              \
+  DEBUG_PRINT2 ("  Popping pattern 0x%p: ", pat);                      \
   DEBUG_PRINT_COMPILED_PATTERN (bufp, pat, pend);                      \
                                                                        \
   /* Restore register info.  */                                                \
@@ -1431,18 +1408,18 @@ do {                                                                    \
                                                                        \
       reg_info[this_reg].word = POP_FAILURE_ELT ();                    \
       DEBUG_PRINT2 ("      info: 0x%lx\n",                             \
-                   * (long *) &reg_info[this_reg]);                    \
+                   * (unsigned long *) &reg_info[this_reg]);           \
                                                                        \
-      regend[this_reg] = POP_FAILURE_POINTER ();                       \
-      DEBUG_PRINT2 ("      end: 0x%lx\n", (long) regend[this_reg]);    \
+      regend[this_reg] = (CONST char *) POP_FAILURE_POINTER ();                \
+      DEBUG_PRINT2 ("      end: 0x%p\n", regend[this_reg]);            \
                                                                        \
-      regstart[this_reg] = POP_FAILURE_POINTER ();                     \
-      DEBUG_PRINT2 ("      start: 0x%lx\n", (long) regstart[this_reg]);        \
+      regstart[this_reg] = (CONST char *) POP_FAILURE_POINTER ();      \
+      DEBUG_PRINT2 ("      start: 0x%p\n", regstart[this_reg]);                \
     }                                                                  \
                                                                        \
   set_regs_matched_done = 0;                                           \
   DEBUG_STATEMENT (nfailure_points_popped++);                          \
-} while (0) /* POP_FAILURE_POINT */
+} /* POP_FAILURE_POINT */
 
 
 \f
@@ -1486,7 +1463,7 @@ typedef union
     {                                                                  \
       if (!set_regs_matched_done)                                      \
        {                                                               \
-         Element_count r;                                              \
+         unsigned r;                                                   \
          set_regs_matched_done = 1;                                    \
          for (r = lowest_active_reg; r <= highest_active_reg; r++)     \
            {                                                           \
@@ -1499,7 +1476,7 @@ typedef union
   while (0)
 
 /* Registers are set to a sentinel when they haven't yet matched.  */
-static unsigned char reg_unset_dummy;
+static char reg_unset_dummy;
 #define REG_UNSET_VALUE (&reg_unset_dummy)
 #define REG_UNSET(e) ((e) == REG_UNSET_VALUE)
 \f
@@ -1510,9 +1487,10 @@ static unsigned char reg_unset_dummy;
    string passed to us by the user to an unsigned char that we can use
    as an array index (in, e.g., `translate').  */
 #define PATFETCH(c)                                                    \
-  do {                                                                 \
-    PATFETCH_RAW (c);                                                  \
-    c = TRANSLATE (c);                                                 \
+  do {if (p == pend) return REG_EEND;                                  \
+    assert (p < pend);                                                 \
+    c = (unsigned char) *p++;                                          \
+    if (translate) c = (unsigned char) translate[c];                   \
   } while (0)
 
 /* Fetch the next character in the uncompiled pattern, with no
@@ -1520,28 +1498,27 @@ static unsigned char reg_unset_dummy;
 #define PATFETCH_RAW(c)                                                        \
   do {if (p == pend) return REG_EEND;                                  \
     assert (p < pend);                                                 \
-    c = charptr_emchar (p);                                            \
-    INC_CHARPTR (p);                                                   \
+    c = (unsigned char) *p++;                                          \
   } while (0)
 
 /* Go backwards one character in the pattern.  */
-#define PATUNFETCH DEC_CHARPTR (p)
+#define PATUNFETCH p--
 
 #ifdef MULE
 
 #define PATFETCH_EXTENDED(emch)                                                \
   do {if (p == pend) return REG_EEND;                                  \
     assert (p < pend);                                                 \
-    emch = charptr_emchar ((const Bufbyte *) p);                       \
+    emch = charptr_emchar ((CONST Bufbyte *) p);                       \
     INC_CHARPTR (p);                                                   \
-    if (TRANSLATE_P (translate) && emch < 0x80)                                \
-      emch = (Emchar) (unsigned char) RE_TRANSLATE (emch);             \
+    if (translate && emch < 0x80)                                      \
+      emch = (Emchar) (unsigned char) translate[emch];                 \
   } while (0)
 
 #define PATFETCH_RAW_EXTENDED(emch)                                    \
   do {if (p == pend) return REG_EEND;                                  \
     assert (p < pend);                                                 \
-    emch = charptr_emchar ((const Bufbyte *) p);                       \
+    emch = charptr_emchar ((CONST Bufbyte *) p);                       \
     INC_CHARPTR (p);                                                   \
   } while (0)
 
@@ -1577,18 +1554,18 @@ static unsigned char reg_unset_dummy;
 #define PATFETCH_RAW_EITHER(emch) PATFETCH_RAW (emch)
 #define PATUNFETCH_EITHER PATUNFETCH
 
-#endif /* MULE */
+#endif /* not MULE */
 
 /* If `translate' is non-null, return translate[D], else just D.  We
    cast the subscript to translate because some data is declared as
    `char *', to avoid warnings when a string constant is passed.  But
    when we use a character as a subscript we must make it unsigned.  */
-#define TRANSLATE(d) (TRANSLATE_P (translate) ? RE_TRANSLATE (d) : (d))
+#define TRANSLATE(d) (translate ? translate[(unsigned char) (d)] : (d))
 
 #ifdef MULE
 
 #define TRANSLATE_EXTENDED_UNSAFE(emch) \
-  (TRANSLATE_P (translate) && emch < 0x80 ? RE_TRANSLATE (emch) : (emch))
+  (translate && emch < 0x80 ? translate[emch] : (emch))
 
 #endif
 
@@ -1599,14 +1576,14 @@ static unsigned char reg_unset_dummy;
 
 /* Make sure we have at least N more bytes of space in buffer.  */
 #define GET_BUFFER_SPACE(n)                                            \
-    while (buf_end - bufp->buffer + (n) > (ptrdiff_t) bufp->allocated) \
+    while (b - bufp->buffer + (n) > bufp->allocated)                   \
       EXTEND_BUFFER ()
 
 /* Make sure we have one more byte of buffer space and then add C to it.  */
 #define BUF_PUSH(c)                                                    \
   do {                                                                 \
     GET_BUFFER_SPACE (1);                                              \
-    *buf_end++ = (unsigned char) (c);                                  \
+    *b++ = (unsigned char) (c);                                                \
   } while (0)
 
 
@@ -1614,8 +1591,8 @@ static unsigned char reg_unset_dummy;
 #define BUF_PUSH_2(c1, c2)                                             \
   do {                                                                 \
     GET_BUFFER_SPACE (2);                                              \
-    *buf_end++ = (unsigned char) (c1);                                 \
-    *buf_end++ = (unsigned char) (c2);                                 \
+    *b++ = (unsigned char) (c1);                                       \
+    *b++ = (unsigned char) (c2);                                       \
   } while (0)
 
 
@@ -1623,9 +1600,9 @@ static unsigned char reg_unset_dummy;
 #define BUF_PUSH_3(c1, c2, c3)                                         \
   do {                                                                 \
     GET_BUFFER_SPACE (3);                                              \
-    *buf_end++ = (unsigned char) (c1);                                 \
-    *buf_end++ = (unsigned char) (c2);                                 \
-    *buf_end++ = (unsigned char) (c3);                                 \
+    *b++ = (unsigned char) (c1);                                       \
+    *b++ = (unsigned char) (c2);                                       \
+    *b++ = (unsigned char) (c3);                                       \
   } while (0)
 
 
@@ -1638,15 +1615,13 @@ static unsigned char reg_unset_dummy;
 #define STORE_JUMP2(op, loc, to, arg) \
   store_op2 (op, loc, (to) - (loc) - 3, arg)
 
-/* Like `STORE_JUMP', but for inserting.  Assume `buf_end' is the
-   buffer end.  */
+/* Like `STORE_JUMP', but for inserting.  Assume `b' is the buffer end.  */
 #define INSERT_JUMP(op, loc, to) \
-  insert_op1 (op, loc, (to) - (loc) - 3, buf_end)
+  insert_op1 (op, loc, (to) - (loc) - 3, b)
 
-/* Like `STORE_JUMP2', but for inserting.  Assume `buf_end' is the
-   buffer end.  */
+/* Like `STORE_JUMP2', but for inserting.  Assume `b' is the buffer end.  */
 #define INSERT_JUMP2(op, loc, to, arg) \
-  insert_op2 (op, loc, (to) - (loc) - 3, arg, buf_end)
+  insert_op2 (op, loc, (to) - (loc) - 3, arg, b)
 
 
 /* This is not an arbitrary limit: the arguments which represent offsets
@@ -1661,7 +1636,7 @@ static unsigned char reg_unset_dummy;
    being larger than MAX_BUF_SIZE, then flag memory exhausted.  */
 #define EXTEND_BUFFER()                                                        \
   do {                                                                         \
-    re_char *old_buffer = bufp->buffer;                                \
+    unsigned char *old_buffer = bufp->buffer;                          \
     if (bufp->allocated == MAX_BUF_SIZE)                               \
       return REG_ESIZE;                                                        \
     bufp->allocated <<= 1;                                             \
@@ -1673,7 +1648,7 @@ static unsigned char reg_unset_dummy;
     /* If the buffer moved, move all the pointers into it.  */         \
     if (old_buffer != bufp->buffer)                                    \
       {                                                                        \
-        buf_end = (buf_end - old_buffer) + bufp->buffer;               \
+        b = (b - old_buffer) + bufp->buffer;                           \
         begalt = (begalt - old_buffer) + bufp->buffer;                 \
         if (fixup_alt_jump)                                            \
           fixup_alt_jump = (fixup_alt_jump - old_buffer) + bufp->buffer;\
@@ -1730,7 +1705,7 @@ typedef struct
 
 /* Set the bit for character C in a bit vector.  */
 #define SET_LIST_BIT(c)                                \
-  (buf_end[((unsigned char) (c)) / BYTEWIDTH]  \
+  (b[((unsigned char) (c)) / BYTEWIDTH]                \
    |= 1 << (((unsigned char) c) % BYTEWIDTH))
 
 #ifdef MULE
@@ -1787,35 +1762,34 @@ static void insert_op1 (re_opcode_t op, unsigned char *loc, int arg,
                        unsigned char *end);
 static void insert_op2 (re_opcode_t op, unsigned char *loc, int arg1, int arg2,
                        unsigned char *end);
-static re_bool at_begline_loc_p (re_char *pattern, re_char *p,
+static boolean at_begline_loc_p (CONST char *pattern, CONST char *p,
                                 reg_syntax_t syntax);
-static re_bool at_endline_loc_p (re_char *p, re_char *pend, int syntax);
-static re_bool group_in_compile_stack (compile_stack_type compile_stack,
+static boolean at_endline_loc_p (CONST char *p, CONST char *pend, int syntax);
+static boolean group_in_compile_stack (compile_stack_type compile_stack,
                                       regnum_t regnum);
-static reg_errcode_t compile_range (re_char **p_ptr, re_char *pend,
-                                   RE_TRANSLATE_TYPE translate,
-                                   reg_syntax_t syntax,
+static reg_errcode_t compile_range (CONST char **p_ptr, CONST char *pend,
+                                   char *translate, reg_syntax_t syntax,
                                    unsigned char *b);
 #ifdef MULE
-static reg_errcode_t compile_extended_range (re_char **p_ptr,
-                                            re_char *pend,
-                                            RE_TRANSLATE_TYPE translate,
+static reg_errcode_t compile_extended_range (CONST char **p_ptr,
+                                            CONST char *pend,
+                                            char *translate,
                                             reg_syntax_t syntax,
                                             Lisp_Object rtab);
 #endif /* MULE */
-static re_bool group_match_null_string_p (unsigned char **p,
+static boolean group_match_null_string_p (unsigned char **p,
                                          unsigned char *end,
                                          register_info_type *reg_info);
-static re_bool alt_match_null_string_p (unsigned char *p, unsigned char *end,
+static boolean alt_match_null_string_p (unsigned char *p, unsigned char *end,
                                        register_info_type *reg_info);
-static re_bool common_op_match_null_string_p (unsigned char **p,
+static boolean common_op_match_null_string_p (unsigned char **p,
                                              unsigned char *end,
                                              register_info_type *reg_info);
-static int bcmp_translate (const unsigned char *s1, const unsigned char *s2,
-                          REGISTER int len, RE_TRANSLATE_TYPE translate);
+static int bcmp_translate (CONST unsigned char *s1, CONST unsigned char *s2,
+                          REGISTER int len, char *translate);
 static int re_match_2_internal (struct re_pattern_buffer *bufp,
-                               re_char *string1, int size1,
-                               re_char *string2, int size2, int pos,
+                               CONST char *string1, int size1,
+                               CONST char *string2, int size2, int pos,
                                struct re_registers *regs, int stop);
 \f
 #ifndef MATCH_MAY_ALLOCATE
@@ -1834,11 +1808,11 @@ static fail_stack_type fail_stack;
    but never make them smaller.  */
 static int regs_allocated_size;
 
-static re_char **     regstart, **     regend;
-static re_char ** old_regstart, ** old_regend;
-static re_char **best_regstart, **best_regend;
+static CONST char **     regstart, **     regend;
+static CONST char ** old_regstart, ** old_regend;
+static CONST char **best_regstart, **best_regend;
 static register_info_type *reg_info;
-static re_char **reg_dummy;
+static CONST char **reg_dummy;
 static register_info_type *reg_info_dummy;
 
 /* Make the register vectors big enough for NUM_REGS registers,
@@ -1849,14 +1823,14 @@ regex_grow_registers (int num_regs)
 {
   if (num_regs > regs_allocated_size)
     {
-      RETALLOC_IF (regstart,      num_regs, re_char *);
-      RETALLOC_IF (regend,        num_regs, re_char *);
-      RETALLOC_IF (old_regstart,   num_regs, re_char *);
-      RETALLOC_IF (old_regend,    num_regs, re_char *);
-      RETALLOC_IF (best_regstart,  num_regs, re_char *);
-      RETALLOC_IF (best_regend,           num_regs, re_char *);
+      RETALLOC_IF (regstart,      num_regs, CONST char *);
+      RETALLOC_IF (regend,        num_regs, CONST char *);
+      RETALLOC_IF (old_regstart,   num_regs, CONST char *);
+      RETALLOC_IF (old_regend,    num_regs, CONST char *);
+      RETALLOC_IF (best_regstart,  num_regs, CONST char *);
+      RETALLOC_IF (best_regend,           num_regs, CONST char *);
       RETALLOC_IF (reg_info,      num_regs, register_info_type);
-      RETALLOC_IF (reg_dummy,     num_regs, re_char *);
+      RETALLOC_IF (reg_dummy,     num_regs, CONST char *);
       RETALLOC_IF (reg_info_dummy, num_regs, register_info_type);
 
       regs_allocated_size = num_regs;
@@ -1888,7 +1862,7 @@ regex_grow_registers (int num_regs)
   return (free (compile_stack.stack), value)
 
 static reg_errcode_t
-regex_compile (re_char *pattern, int size, reg_syntax_t syntax,
+regex_compile (CONST char *pattern, int size, reg_syntax_t syntax,
               struct re_pattern_buffer *bufp)
 {
   /* We fetch characters from PATTERN here.  We declare these as int
@@ -1900,20 +1874,20 @@ regex_compile (re_char *pattern, int size, reg_syntax_t syntax,
   REGISTER EMACS_INT c, c1;
 
   /* A random temporary spot in PATTERN.  */
-  re_char *p1;
+  CONST char *p1;
 
   /* Points to the end of the buffer, where we should append.  */
-  REGISTER unsigned char *buf_end;
+  REGISTER unsigned char *b;
 
   /* Keeps track of unclosed groups.  */
   compile_stack_type compile_stack;
 
   /* Points to the current (ending) position in the pattern.  */
-  re_char *p = pattern;
-  re_char *pend = pattern + size;
+  CONST char *p = pattern;
+  CONST char *pend = pattern + size;
 
   /* How to translate the characters in the pattern.  */
-  RE_TRANSLATE_TYPE translate = bufp->translate;
+  char *translate = bufp->translate;
 
   /* Address of the count-byte of the most recently inserted `exactn'
      command.  This makes it possible to tell if a new exact-match
@@ -1931,7 +1905,7 @@ regex_compile (re_char *pattern, int size, reg_syntax_t syntax,
 
   /* Place in the uncompiled pattern (i.e., the {) to
      which to go back if the interval is invalid.  */
-  re_char *beg_interval;
+  CONST char *beg_interval;
 
   /* Address of the place where a forward jump should go to the end of
      the containing expression.  Each alternative of an `or' -- except the
@@ -1947,7 +1921,7 @@ regex_compile (re_char *pattern, int size, reg_syntax_t syntax,
   DEBUG_PRINT1 ("\nCompiling pattern: ");
   if (debug)
     {
-      int debug_count;
+      unsigned debug_count;
 
       for (debug_count = 0; debug_count < size; debug_count++)
         putchar (pattern[debug_count]);
@@ -1998,7 +1972,7 @@ regex_compile (re_char *pattern, int size, reg_syntax_t syntax,
       bufp->allocated = INIT_BUF_SIZE;
     }
 
-  begalt = buf_end = bufp->buffer;
+  begalt = b = bufp->buffer;
 
   /* Loop through the uncompiled pattern until we're at the end.  */
   while (p != pend)
@@ -2055,11 +2029,11 @@ regex_compile (re_char *pattern, int size, reg_syntax_t syntax,
 
           {
            /* true means zero/many matches are allowed. */
-           re_bool zero_times_ok = c != '+';
-            re_bool many_times_ok = c != '?';
+           boolean zero_times_ok = c != '+';
+            boolean many_times_ok = c != '?';
 
             /* true means match shortest string possible. */
-            re_bool minimal = false;
+            boolean minimal = false;
 
             /* If there is a sequence of repetition chars, collapse it
                down to just one (the right one).  We can't combine
@@ -2096,9 +2070,9 @@ regex_compile (re_char *pattern, int size, reg_syntax_t syntax,
                 /* If we get here, we found another repeat character.  */
                 if (!(syntax & RE_NO_MINIMAL_MATCHING))
                   {
-                    /* "*?" and "+?" and "??" are okay (and mean match
-                       minimally), but other sequences (such as "*??" and
-                       "+++") are rejected (reserved for future use). */
+                    /* `*?' and `+?' and `??' are okay (and mean match
+                       minimally), but other sequences (such as `*??' and
+                       `+++') are rejected (reserved for future use). */
                     if (minimal || c != '?')
                       FREE_STACK_RETURN (REG_BADRPT);
                     minimal = true;
@@ -2129,10 +2103,10 @@ regex_compile (re_char *pattern, int size, reg_syntax_t syntax,
                        9: end of pattern.
                      */
                     GET_BUFFER_SPACE (6);
-                    INSERT_JUMP (jump, laststart, buf_end + 3);
-                    buf_end += 3;
+                    INSERT_JUMP (jump, laststart, b + 3);
+                    b += 3;
                     INSERT_JUMP (on_failure_jump, laststart, laststart + 6);
-                    buf_end += 3;
+                    b += 3;
                   }
                 else if (zero_times_ok)
                   {
@@ -2143,10 +2117,10 @@ regex_compile (re_char *pattern, int size, reg_syntax_t syntax,
                        9: end of pattern.
                      */
                     GET_BUFFER_SPACE (6);
-                    INSERT_JUMP (jump, laststart, buf_end + 3);
-                    buf_end += 3;
-                    STORE_JUMP (on_failure_jump, buf_end, laststart + 3);
-                    buf_end += 3;
+                    INSERT_JUMP (jump, laststart, b + 3);
+                    b += 3;
+                    STORE_JUMP (on_failure_jump, b, laststart + 3);
+                    b += 3;
                   }
                 else
                   {
@@ -2156,21 +2130,20 @@ regex_compile (re_char *pattern, int size, reg_syntax_t syntax,
                        6: end of pattern.
                      */
                     GET_BUFFER_SPACE (3);
-                    STORE_JUMP (on_failure_jump, buf_end, laststart);
-                    buf_end += 3;
+                    STORE_JUMP (on_failure_jump, b, laststart);
+                    b += 3;
                   }
               }
             else
               {
                 /* Are we optimizing this jump?  */
-                re_bool keep_string_p = false;
+                boolean keep_string_p = false;
 
                 if (many_times_ok)
-                  { /* More than one repetition is allowed, so put in
-                       at the end a backward relative jump from
-                       `buf_end' to before the next jump we're going
-                       to put in below (which jumps from laststart to
-                       after this jump).
+                  { /* More than one repetition is allowed, so put in at the
+                       end a backward relative jump from `b' to before the next
+                       jump we're going to put in below (which jumps from
+                       laststart to after this jump).
 
                        But if we are at the `*' in the exact sequence `.*\n',
                        insert an unconditional jump backwards to the .,
@@ -2188,30 +2161,29 @@ regex_compile (re_char *pattern, int size, reg_syntax_t syntax,
                        character after the `*'.  Do we have to do something
                        analogous here for null bytes, because of
                        RE_DOT_NOT_NULL? */
-                    if (*(p - 2) == '.'
+                    if (TRANSLATE (*(p - 2)) == TRANSLATE ('.')
                         && zero_times_ok
-                        && p < pend && *p == '\n'
+                        && p < pend && TRANSLATE (*p) == TRANSLATE ('\n')
                         && !(syntax & RE_DOT_NEWLINE))
                       { /* We have .*\n.  */
-                        STORE_JUMP (jump, buf_end, laststart);
+                        STORE_JUMP (jump, b, laststart);
                         keep_string_p = true;
                       }
                     else
                       /* Anything else.  */
-                      STORE_JUMP (maybe_pop_jump, buf_end, laststart - 3);
+                      STORE_JUMP (maybe_pop_jump, b, laststart - 3);
 
                     /* We've added more stuff to the buffer.  */
-                    buf_end += 3;
+                    b += 3;
                   }
 
-                /* On failure, jump from laststart to buf_end + 3,
-                   which will be the end of the buffer after this jump
-                   is inserted.  */
+                /* On failure, jump from laststart to b + 3, which will be the
+                   end of the buffer after this jump is inserted.  */
                 GET_BUFFER_SPACE (3);
                 INSERT_JUMP (keep_string_p ? on_failure_keep_string_jump
                                           : on_failure_jump,
-                             laststart, buf_end + 3);
-                buf_end += 3;
+                             laststart, b + 3);
+                b += 3;
 
                 if (!zero_times_ok)
                   {
@@ -2222,7 +2194,7 @@ regex_compile (re_char *pattern, int size, reg_syntax_t syntax,
                        we hit that loop.  */
                     GET_BUFFER_SPACE (3);
                     INSERT_JUMP (dummy_failure_jump, laststart, laststart + 6);
-                    buf_end += 3;
+                    b += 3;
                   }
               }
             pending_exact = 0;
@@ -2231,7 +2203,7 @@ regex_compile (re_char *pattern, int size, reg_syntax_t syntax,
 
 
        case '.':
-          laststart = buf_end;
+          laststart = b;
           BUF_PUSH (anychar);
           break;
 
@@ -2239,9 +2211,9 @@ regex_compile (re_char *pattern, int size, reg_syntax_t syntax,
         case '[':
           {
            /* XEmacs change: this whole section */
-            re_bool had_char_class = false;
+            boolean had_char_class = false;
 #ifdef MULE
-           re_bool has_extended_chars = false;
+           boolean has_extended_chars = false;
            REGISTER Lisp_Object rtab = Qnil;
 #endif
 
@@ -2251,7 +2223,7 @@ regex_compile (re_char *pattern, int size, reg_syntax_t syntax,
                opcode, the length count, and the bitset; 34 bytes in all.  */
            GET_BUFFER_SPACE (34);
 
-            laststart = buf_end;
+            laststart = b;
 
             /* We test `*p == '^' twice, instead of using an if
                statement, so we only need one BUF_PUSH.  */
@@ -2266,10 +2238,10 @@ regex_compile (re_char *pattern, int size, reg_syntax_t syntax,
             BUF_PUSH ((1 << BYTEWIDTH) / BYTEWIDTH);
 
             /* Clear the whole map.  */
-            memset (buf_end, 0, (1 << BYTEWIDTH) / BYTEWIDTH);
+            memset (b, 0, (1 << BYTEWIDTH) / BYTEWIDTH);
 
             /* charset_not matches newline according to a syntax bit.  */
-            if ((re_opcode_t) buf_end[-2] == charset_not
+            if ((re_opcode_t) b[-2] == charset_not
                 && (syntax & RE_HAT_LISTS_NOT_NEWLINE))
               SET_LIST_BIT ('\n');
 
@@ -2279,18 +2251,18 @@ regex_compile (re_char *pattern, int size, reg_syntax_t syntax,
              {
                /* There are extended chars here, which means we need to start
                   over and shift to unified range-table format. */
-               if (buf_end[-2] == charset)
-                 buf_end[-2] = charset_mule;
+               if (b[-2] == charset)
+                 b[-2] = charset_mule;
                else
-                 buf_end[-2] = charset_mule_not;
-               buf_end--;
+                 b[-2] = charset_mule_not;
+               b--;
                p = p1; /* go back to the beginning of the charset, after
                           a possible ^. */
                rtab = Vthe_lisp_rangetab;
                Fclear_range_table (rtab);
 
                /* charset_not matches newline according to a syntax bit.  */
-               if ((re_opcode_t) buf_end[-1] == charset_mule_not
+               if ((re_opcode_t) b[-1] == charset_mule_not
                    && (syntax & RE_HAT_LISTS_NOT_NEWLINE))
                  SET_EITHER_BIT ('\n');
              }
@@ -2301,7 +2273,7 @@ regex_compile (re_char *pattern, int size, reg_syntax_t syntax,
               {
                 if (p == pend) FREE_STACK_RETURN (REG_EBRACK);
 
-                PATFETCH (c);
+                PATFETCH_EITHER (c);
 
 #ifdef MULE
                if (c >= 0x80 && !has_extended_chars)
@@ -2320,7 +2292,7 @@ regex_compile (re_char *pattern, int size, reg_syntax_t syntax,
                   {
                     if (p == pend) FREE_STACK_RETURN (REG_EESCAPE);
 
-                    PATFETCH (c1);
+                    PATFETCH_EITHER (c1);
 #ifdef MULE
                    if (c1 >= 0x80 && !has_extended_chars)
                      {
@@ -2349,7 +2321,7 @@ regex_compile (re_char *pattern, int size, reg_syntax_t syntax,
                    operator.  */
                 if (c == '-'
                     && !(p - 2 >= pattern && p[-2] == '[')
-                   && !(p - 3 >= pattern && p[-3] == '[' && p[-2] == '^')
+                    && !(p - 3 >= pattern && p[-3] == '[' && p[-2] == '^')
                     && *p != ']')
                   {
                     reg_errcode_t ret;
@@ -2365,7 +2337,7 @@ regex_compile (re_char *pattern, int size, reg_syntax_t syntax,
                                                    syntax, rtab);
                    else
 #endif /* MULE */
-                     ret = compile_range (&p, pend, translate, syntax, buf_end);
+                     ret = compile_range (&p, pend, translate, syntax, b);
                     if (ret != REG_NOERROR) FREE_STACK_RETURN (ret);
                   }
 
@@ -2387,7 +2359,7 @@ regex_compile (re_char *pattern, int size, reg_syntax_t syntax,
                                                    syntax, rtab);
                    else
 #endif /* MULE */
-                     ret = compile_range (&p, pend, translate, syntax, buf_end);
+                     ret = compile_range (&p, pend, translate, syntax, b);
                     if (ret != REG_NOERROR) FREE_STACK_RETURN (ret);
                   }
 
@@ -2406,35 +2378,38 @@ regex_compile (re_char *pattern, int size, reg_syntax_t syntax,
 
                     for (;;)
                       {
-                       /* #### This code is unused.
-                          Correctness is not checked after TRT
-                          table change.  */
+                       /* Do not do PATFETCH_EITHER() here.  We want
+                          to just see if the bytes match particular
+                          strings, and we put them all back if not.
+
+                          #### May need to be changed once trt tables
+                          are working. */
                         PATFETCH (c);
                         if (c == ':' || c == ']' || p == pend
                             || c1 == CHAR_CLASS_MAX_LENGTH)
                           break;
-                        str[c1++] = (char) c;
+                        str[c1++] = c;
                       }
                     str[c1] = '\0';
 
-                    /* If isn't a word bracketed by `[:' and `:]':
+                    /* If isn't a word bracketed by `[:' and:`]':
                        undo the ending character, the letters, and leave
                        the leading `:' and `[' (but set bits for them).  */
                     if (c == ':' && *p == ']')
                       {
                         int ch;
-                        re_bool is_alnum = STREQ (str, "alnum");
-                        re_bool is_alpha = STREQ (str, "alpha");
-                        re_bool is_blank = STREQ (str, "blank");
-                        re_bool is_cntrl = STREQ (str, "cntrl");
-                        re_bool is_digit = STREQ (str, "digit");
-                        re_bool is_graph = STREQ (str, "graph");
-                        re_bool is_lower = STREQ (str, "lower");
-                        re_bool is_print = STREQ (str, "print");
-                        re_bool is_punct = STREQ (str, "punct");
-                        re_bool is_space = STREQ (str, "space");
-                        re_bool is_upper = STREQ (str, "upper");
-                        re_bool is_xdigit = STREQ (str, "xdigit");
+                        boolean is_alnum = STREQ (str, "alnum");
+                        boolean is_alpha = STREQ (str, "alpha");
+                        boolean is_blank = STREQ (str, "blank");
+                        boolean is_cntrl = STREQ (str, "cntrl");
+                        boolean is_digit = STREQ (str, "digit");
+                        boolean is_graph = STREQ (str, "graph");
+                        boolean is_lower = STREQ (str, "lower");
+                        boolean is_print = STREQ (str, "print");
+                        boolean is_punct = STREQ (str, "punct");
+                        boolean is_space = STREQ (str, "space");
+                        boolean is_upper = STREQ (str, "upper");
+                        boolean is_xdigit = STREQ (str, "xdigit");
 
                         if (!IS_CHAR_CLASS (str))
                          FREE_STACK_RETURN (REG_ECTYPE);
@@ -2491,16 +2466,16 @@ regex_compile (re_char *pattern, int size, reg_syntax_t syntax,
                int bytes_needed =
                  unified_range_table_bytes_needed (rtab);
                GET_BUFFER_SPACE (bytes_needed);
-               unified_range_table_copy_data (rtab, buf_end);
-               buf_end += unified_range_table_bytes_used (buf_end);
+               unified_range_table_copy_data (rtab, b);
+               b += unified_range_table_bytes_used (b);
                break;
              }
 #endif /* MULE */
             /* Discard any (non)matching list bytes that are all 0 at the
                end of the map.  Decrease the map-length byte too.  */
-            while ((int) buf_end[-1] > 0 && buf_end[buf_end[-1] - 1] == 0)
-              buf_end[-1]--;
-            buf_end += buf_end[-1];
+            while ((int) b[-1] > 0 && b[b[-1] - 1] == 0)
+              b[-1]--;
+            b += b[-1];
          }
          break;
 
@@ -2560,10 +2535,10 @@ regex_compile (re_char *pattern, int size, reg_syntax_t syntax,
 
                 if (!(syntax & RE_NO_SHY_GROUPS)
                     && p != pend
-                    && *p == '?')
+                    && TRANSLATE(*p) == TRANSLATE('?'))
                   {
                     p++;
-                    PATFETCH (c);
+                    PATFETCH(c);
                     switch (c)
                       {
                       case ':': /* shy groups */
@@ -2597,7 +2572,7 @@ regex_compile (re_char *pattern, int size, reg_syntax_t syntax,
                 COMPILE_STACK_TOP.begalt_offset = begalt - bufp->buffer;
                 COMPILE_STACK_TOP.fixup_alt_jump
                   = fixup_alt_jump ? fixup_alt_jump - bufp->buffer + 1 : 0;
-                COMPILE_STACK_TOP.laststart_offset = buf_end - bufp->buffer;
+                COMPILE_STACK_TOP.laststart_offset = b - bufp->buffer;
                 COMPILE_STACK_TOP.regnum = r;
 
                 /* We will eventually replace the 0 with the number of
@@ -2607,7 +2582,7 @@ regex_compile (re_char *pattern, int size, reg_syntax_t syntax,
                 if (r <= MAX_REGNUM)
                   {
                     COMPILE_STACK_TOP.inner_group_offset
-                      = buf_end - bufp->buffer + 2;
+                      = b - bufp->buffer + 2;
                     BUF_PUSH_3 (start_memory, r, 0);
                   }
 
@@ -2615,7 +2590,7 @@ regex_compile (re_char *pattern, int size, reg_syntax_t syntax,
 
                 fixup_alt_jump = 0;
                 laststart = 0;
-                begalt = buf_end;
+                begalt = b;
                 /* If we've reached MAX_REGNUM groups, then this open
                    won't actually generate any code, so we'll have to
                    clear pending_exact explicitly.  */
@@ -2644,7 +2619,7 @@ regex_compile (re_char *pattern, int size, reg_syntax_t syntax,
 
                   /* We allocated space for this jump when we assigned
                      to `fixup_alt_jump', in the `handle_alt' case below.  */
-                  STORE_JUMP (jump_past_alt, fixup_alt_jump, buf_end - 1);
+                  STORE_JUMP (jump_past_alt, fixup_alt_jump, b - 1);
                 }
 
               /* See similar code for backslashed left paren above.  */
@@ -2702,9 +2677,9 @@ regex_compile (re_char *pattern, int size, reg_syntax_t syntax,
               /* Insert before the previous alternative a jump which
                  jumps to this alternative if the former fails.  */
               GET_BUFFER_SPACE (3);
-              INSERT_JUMP (on_failure_jump, begalt, buf_end + 6);
+              INSERT_JUMP (on_failure_jump, begalt, b + 6);
               pending_exact = 0;
-              buf_end += 3;
+              b += 3;
 
               /* The alternative before this one has a jump after it
                  which gets executed if it gets matched.  Adjust that
@@ -2723,17 +2698,17 @@ regex_compile (re_char *pattern, int size, reg_syntax_t syntax,
                  bytes which we'll fill in when we get to after `c'.  */
 
               if (fixup_alt_jump)
-                STORE_JUMP (jump_past_alt, fixup_alt_jump, buf_end);
+                STORE_JUMP (jump_past_alt, fixup_alt_jump, b);
 
               /* Mark and leave space for a jump after this alternative,
                  to be filled in later either by next alternative or
                  when know we're at the end of a series of alternatives.  */
-              fixup_alt_jump = buf_end;
+              fixup_alt_jump = b;
               GET_BUFFER_SPACE (3);
-              buf_end += 3;
+              b += 3;
 
               laststart = 0;
-              begalt = buf_end;
+              begalt = b;
               break;
 
 
@@ -2806,7 +2781,7 @@ regex_compile (re_char *pattern, int size, reg_syntax_t syntax,
                     if (syntax & RE_CONTEXT_INVALID_OPS)
                       FREE_STACK_RETURN (REG_BADRPT);
                     else if (syntax & RE_CONTEXT_INDEP_OPS)
-                      laststart = buf_end;
+                      laststart = b;
                     else
                       goto unfetch_interval;
                   }
@@ -2817,8 +2792,8 @@ regex_compile (re_char *pattern, int size, reg_syntax_t syntax,
                  if (upper_bound == 0)
                    {
                      GET_BUFFER_SPACE (3);
-                     INSERT_JUMP (jump, laststart, buf_end + 3);
-                     buf_end += 3;
+                     INSERT_JUMP (jump, laststart, b + 3);
+                     b += 3;
                    }
 
                  /* Otherwise, we have a nontrivial interval.  When
@@ -2833,7 +2808,7 @@ regex_compile (re_char *pattern, int size, reg_syntax_t syntax,
                  else
                    { /* If the upper bound is > 1, we need to insert
                         more at the end of the loop.  */
-                     Memory_count nbytes = 10 + (upper_bound > 1) * 10;
+                     unsigned nbytes = 10 + (upper_bound > 1) * 10;
 
                      GET_BUFFER_SPACE (nbytes);
 
@@ -2843,16 +2818,16 @@ regex_compile (re_char *pattern, int size, reg_syntax_t syntax,
                         because `re_compile_fastmap' needs to know.
                         Jump to the `jump_n' we might insert below.  */
                      INSERT_JUMP2 (succeed_n, laststart,
-                                   buf_end + 5 + (upper_bound > 1) * 5,
+                                   b + 5 + (upper_bound > 1) * 5,
                                    lower_bound);
-                     buf_end += 5;
+                     b += 5;
 
                      /* Code to initialize the lower bound.  Insert
                         before the `succeed_n'.  The `5' is the last two
                         bytes of this `set_number_at', plus 3 bytes of
                         the following `succeed_n'.  */
-                     insert_op2 (set_number_at, laststart, 5, lower_bound, buf_end);
-                     buf_end += 5;
+                     insert_op2 (set_number_at, laststart, 5, lower_bound, b);
+                     b += 5;
 
                      if (upper_bound > 1)
                        { /* More than one repetition is allowed, so
@@ -2862,9 +2837,9 @@ regex_compile (re_char *pattern, int size, reg_syntax_t syntax,
                             When we've reached this during matching,
                             we'll have matched the interval once, so
                             jump back only `upper_bound - 1' times.  */
-                         STORE_JUMP2 (jump_n, buf_end, laststart + 5,
+                         STORE_JUMP2 (jump_n, b, laststart + 5,
                                       upper_bound - 1);
-                         buf_end += 5;
+                         b += 5;
 
                          /* The location we want to set is the second
                             parameter of the `jump_n'; that is `b-2' as
@@ -2880,10 +2855,9 @@ regex_compile (re_char *pattern, int size, reg_syntax_t syntax,
                             We insert this at the beginning of the loop
                             so that if we fail during matching, we'll
                             reinitialize the bounds.  */
-                         insert_op2 (set_number_at, laststart,
-                                    buf_end - laststart,
-                                     upper_bound - 1, buf_end);
-                         buf_end += 5;
+                         insert_op2 (set_number_at, laststart, b - laststart,
+                                     upper_bound - 1, b);
+                         b += 5;
                        }
                    }
                 pending_exact = 0;
@@ -2915,7 +2889,7 @@ regex_compile (re_char *pattern, int size, reg_syntax_t syntax,
               break;
 
             case 's':
-              laststart = buf_end;
+              laststart = b;
               PATFETCH (c);
              /* XEmacs addition */
              if (c >= 0x80 || syntax_spec_code[c] == 0377)
@@ -2924,7 +2898,7 @@ regex_compile (re_char *pattern, int size, reg_syntax_t syntax,
               break;
 
             case 'S':
-              laststart = buf_end;
+              laststart = b;
               PATFETCH (c);
              /* XEmacs addition */
              if (c >= 0x80 || syntax_spec_code[c] == 0377)
@@ -2935,7 +2909,7 @@ regex_compile (re_char *pattern, int size, reg_syntax_t syntax,
 #ifdef MULE
 /* 97.2.17 jhod merged in to XEmacs from mule-2.3 */
            case 'c':
-             laststart = buf_end;
+             laststart = b;
              PATFETCH_RAW (c);
              if (c < 32 || c > 127)
                FREE_STACK_RETURN (REG_ECATEGORY);
@@ -2943,7 +2917,7 @@ regex_compile (re_char *pattern, int size, reg_syntax_t syntax,
              break;
 
            case 'C':
-             laststart = buf_end;
+             laststart = b;
              PATFETCH_RAW (c);
              if (c < 32 || c > 127)
                FREE_STACK_RETURN (REG_ECATEGORY);
@@ -2955,13 +2929,13 @@ regex_compile (re_char *pattern, int size, reg_syntax_t syntax,
 
 
             case 'w':
-              laststart = buf_end;
+              laststart = b;
               BUF_PUSH (wordchar);
               break;
 
 
             case 'W':
-              laststart = buf_end;
+              laststart = b;
               BUF_PUSH (notwordchar);
               break;
 
@@ -2992,23 +2966,20 @@ regex_compile (re_char *pattern, int size, reg_syntax_t syntax,
 
             case '1': case '2': case '3': case '4': case '5':
             case '6': case '7': case '8': case '9':
-             {
-               regnum_t reg;
-               if (syntax & RE_NO_BK_REFS)
-                 goto normal_char;
+              if (syntax & RE_NO_BK_REFS)
+                goto normal_char;
 
-               reg = c - '0';
+              c1 = c - '0';
 
-               if (reg > regnum)
-                 FREE_STACK_RETURN (REG_ESUBREG);
+              if (c1 > regnum)
+                FREE_STACK_RETURN (REG_ESUBREG);
 
-               /* Can't back reference to a subexpression if inside of it.  */
-               if (group_in_compile_stack (compile_stack, reg))
-                 goto normal_char;
+              /* Can't back reference to a subexpression if inside of it.  */
+              if (group_in_compile_stack (compile_stack, c1))
+                goto normal_char;
 
-               laststart = buf_end;
-               BUF_PUSH_2 (duplicate, reg);
-             }
+              laststart = b;
+              BUF_PUSH_2 (duplicate, c1);
               break;
 
 
@@ -3037,13 +3008,14 @@ regex_compile (re_char *pattern, int size, reg_syntax_t syntax,
          {
            /* XEmacs: modifications here for Mule. */
            /* `q' points to the beginning of the next char. */
-           re_char *q = p;
+           CONST char *q = p - 1;
+           INC_CHARPTR (q);
 
            /* If no exactn currently being built.  */
            if (!pending_exact
 
                /* If last exactn not at current position.  */
-               || pending_exact + *pending_exact + 1 != buf_end
+               || pending_exact + *pending_exact + 1 != b
 
                /* We have only one byte following the exactn for the count. */
                || ((unsigned int) (*pending_exact + (q - p)) >=
@@ -3061,30 +3033,21 @@ regex_compile (re_char *pattern, int size, reg_syntax_t syntax,
              {
                /* Start building a new exactn.  */
 
-               laststart = buf_end;
+               laststart = b;
 
                BUF_PUSH_2 (exactn, 0);
-               pending_exact = buf_end - 1;
+               pending_exact = b - 1;
              }
 
-#ifndef MULE
            BUF_PUSH (c);
            (*pending_exact)++;
-#else
-           {
-             Bytecount bt_count;
-             Bufbyte tmp_buf[MAX_EMCHAR_LEN];
-             int i;
-
-             bt_count = set_charptr_emchar (tmp_buf, c);
 
-             for (i = 0; i < bt_count; i++)
-               {
-                 BUF_PUSH (tmp_buf[i]);
-                 (*pending_exact)++;
-               }
-           }
-#endif
+           while (p < q)
+             {
+               PATFETCH (c);
+               BUF_PUSH (c);
+               (*pending_exact)++;
+             }
            break;
          }
         } /* switch (c) */
@@ -3094,7 +3057,7 @@ regex_compile (re_char *pattern, int size, reg_syntax_t syntax,
   /* Through the pattern now.  */
 
   if (fixup_alt_jump)
-    STORE_JUMP (jump_past_alt, fixup_alt_jump, buf_end);
+    STORE_JUMP (jump_past_alt, fixup_alt_jump, b);
 
   if (!COMPILE_STACK_EMPTY)
     FREE_STACK_RETURN (REG_EPAREN);
@@ -3107,7 +3070,7 @@ regex_compile (re_char *pattern, int size, reg_syntax_t syntax,
   free (compile_stack.stack);
 
   /* We have succeeded; set the length of the buffer.  */
-  bufp->used = buf_end - bufp->buffer;
+  bufp->used = b - bufp->buffer;
 
 #ifdef DEBUG
   if (debug)
@@ -3151,7 +3114,7 @@ regex_compile (re_char *pattern, int size, reg_syntax_t syntax,
            = (fail_stack_elt_t *) realloc (fail_stack.stack,
                                            (fail_stack.size
                                             * sizeof (fail_stack_elt_t)));
-#endif /* emacs */
+#endif /* not emacs */
       }
 
     regex_grow_registers (num_regs);
@@ -3220,11 +3183,11 @@ insert_op2 (re_opcode_t op, unsigned char *loc, int arg1, int arg2,
    after an alternative or a begin-subexpression.  We assume there is at
    least one character before the ^.  */
 
-static re_bool
-at_begline_loc_p (re_char *pattern, re_char *p, reg_syntax_t syntax)
+static boolean
+at_begline_loc_p (CONST char *pattern, CONST char *p, reg_syntax_t syntax)
 {
-  re_char *prev = p - 2;
-  re_bool prev_prev_backslash = prev > pattern && prev[-1] == '\\';
+  CONST char *prev = p - 2;
+  boolean prev_prev_backslash = prev > pattern && prev[-1] == '\\';
 
   return
        /* After a subexpression?  */
@@ -3237,12 +3200,12 @@ at_begline_loc_p (re_char *pattern, re_char *p, reg_syntax_t syntax)
 /* The dual of at_begline_loc_p.  This one is for $.  We assume there is
    at least one character after the $, i.e., `P < PEND'.  */
 
-static re_bool
-at_endline_loc_p (re_char *p, re_char *pend, int syntax)
+static boolean
+at_endline_loc_p (CONST char *p, CONST char *pend, int syntax)
 {
-  re_char *next = p;
-  re_bool next_backslash = *next == '\\';
-  re_char *next_next = p + 1 < pend ? p + 1 : 0;
+  CONST char *next = p;
+  boolean next_backslash = *next == '\\';
+  CONST char *next_next = p + 1 < pend ? p + 1 : 0;
 
   return
        /* Before a subexpression?  */
@@ -3257,7 +3220,7 @@ at_endline_loc_p (re_char *p, re_char *pend, int syntax)
 /* Returns true if REGNUM is in one of COMPILE_STACK's elements and
    false if it's not.  */
 
-static re_bool
+static boolean
 group_in_compile_stack (compile_stack_type compile_stack, regnum_t regnum)
 {
   int this_element;
@@ -3284,12 +3247,12 @@ group_in_compile_stack (compile_stack_type compile_stack, regnum_t regnum)
    `regex_compile' itself.  */
 
 static reg_errcode_t
-compile_range (re_char **p_ptr, re_char *pend, RE_TRANSLATE_TYPE translate,
-              reg_syntax_t syntax, unsigned char *buf_end)
+compile_range (CONST char **p_ptr, CONST char *pend, char *translate,
+              reg_syntax_t syntax, unsigned char *b)
 {
-  Element_count this_char;
+  unsigned this_char;
 
-  re_char *p = *p_ptr;
+  CONST char *p = *p_ptr;
   int range_start, range_end;
 
   if (p == pend)
@@ -3302,9 +3265,9 @@ compile_range (re_char **p_ptr, re_char *pend, RE_TRANSLATE_TYPE translate,
 
      We also want to fetch the endpoints without translating them; the
      appropriate translation is done in the bit-setting loop below.  */
-  /* The SVR4 compiler on the 3B2 had trouble with unsigned const char *.  */
-  range_start = ((const unsigned char *) p)[-2];
-  range_end   = ((const unsigned char *) p)[0];
+  /* The SVR4 compiler on the 3B2 had trouble with unsigned CONST char *.  */
+  range_start = ((CONST unsigned char *) p)[-2];
+  range_end   = ((CONST unsigned char *) p)[0];
 
   /* Have to increment the pointer into the pattern string, so the
      caller isn't still at the ending character.  */
@@ -3329,17 +3292,16 @@ compile_range (re_char **p_ptr, re_char *pend, RE_TRANSLATE_TYPE translate,
 #ifdef MULE
 
 static reg_errcode_t
-compile_extended_range (re_char **p_ptr, re_char *pend,
-                       RE_TRANSLATE_TYPE translate,
+compile_extended_range (CONST char **p_ptr, CONST char *pend, char *translate,
                        reg_syntax_t syntax, Lisp_Object rtab)
 {
   Emchar this_char, range_start, range_end;
-  const Bufbyte *p;
+  CONST Bufbyte *p;
 
   if (*p_ptr == pend)
     return REG_ERANGE;
 
-  p = (const Bufbyte *) *p_ptr;
+  p = (CONST Bufbyte *) *p_ptr;
   range_end = charptr_emchar (p);
   p--; /* back to '-' */
   DEC_CHARPTR (p); /* back to start of range */
@@ -3353,7 +3315,7 @@ compile_extended_range (re_char **p_ptr, re_char *pend,
     return syntax & RE_NO_EMPTY_RANGES ? REG_ERANGE : REG_NOERROR;
 
   /* Can't have ranges spanning different charsets, except maybe for
-     ranges entirely within the first 256 chars. */
+     ranges entirely witin the first 256 chars. */
 
   if ((range_start >= 0x100 || range_end >= 0x100)
       && CHAR_LEADING_BYTE (range_start) !=
@@ -3409,7 +3371,7 @@ re_compile_fastmap (struct re_pattern_buffer *bufp)
 #ifdef MATCH_MAY_ALLOCATE
   fail_stack_type fail_stack;
 #endif
-  DECLARE_DESTINATION;
+  DECLARE_DESTINATION
   /* We don't push any register information onto the failure stack.  */
 
   REGISTER char *fastmap = bufp->fastmap;
@@ -3428,10 +3390,10 @@ re_compile_fastmap (struct re_pattern_buffer *bufp)
      proven otherwise.  We set this false at the bottom of switch
      statement, to which we get only if a particular path doesn't
      match the empty string.  */
-  re_bool path_can_be_null = true;
+  boolean path_can_be_null = true;
 
   /* We aren't doing a `succeed_n' to begin with.  */
-  re_bool succeed_n_p = false;
+  boolean succeed_n_p = false;
 
   assert (fastmap != NULL && p != NULL);
 
@@ -3452,7 +3414,7 @@ re_compile_fastmap (struct re_pattern_buffer *bufp)
              /* Reset for next path.  */
              path_can_be_null = true;
 
-             p = (unsigned char *) fail_stack.stack[--fail_stack.avail].pointer;
+             p = fail_stack.stack[--fail_stack.avail].pointer;
 
              continue;
            }
@@ -3501,10 +3463,10 @@ re_compile_fastmap (struct re_pattern_buffer *bufp)
          /* And all extended characters must be allowed, too. */
          for (j = 0x80; j < 0xA0; j++)
            fastmap[j] = 1;
-#else /* not MULE */
+#else /* ! MULE */
          for (j = *p * BYTEWIDTH; j < (1 << BYTEWIDTH); j++)
             fastmap[j] = 1;
-#endif /* MULE */
+#endif /* ! MULE */
 
          for (j = *p++ * BYTEWIDTH - 1; j >= 0; j--)
            if (!(p[j / BYTEWIDTH] & (1 << (j % BYTEWIDTH))))
@@ -3631,22 +3593,8 @@ re_compile_fastmap (struct re_pattern_buffer *bufp)
          }
 
 #ifdef emacs
-       case wordbound:
-       case notwordbound:
-       case wordbeg:
-       case wordend:
-       case notsyntaxspec:
-       case syntaxspec:
-         /* This match depends on text properties.  These end with
-            aborting optimizations.  */
-         bufp->can_be_null = 1;
-         goto done;
-
-#ifdef emacs
-#if 0   /* Removed during syntax-table properties patch -- 2000/12/07 mct */
         case syntaxspec:
          k = *p++;
-#endif
          matchsyntax:
 #ifdef MULE
          for (j = 0; j < 0x80; j++)
@@ -3675,21 +3623,19 @@ re_compile_fastmap (struct re_pattern_buffer *bufp)
                    }
                }
            }
-#else /* not MULE */
+#else /* ! MULE */
          for (j = 0; j < (1 << BYTEWIDTH); j++)
            if (SYNTAX_UNSAFE
                (XCHAR_TABLE
                 (regex_emacs_buffer->mirror_syntax_table), j) ==
                (enum syntaxcode) k)
              fastmap[j] = 1;
-#endif /* MULE */
+#endif /* ! MULE */
          break;
 
 
-#if 0   /* Removed during syntax-table properties patch -- 2000/12/07 mct */
        case notsyntaxspec:
          k = *p++;
-#endif
          matchnotsyntax:
 #ifdef MULE
          for (j = 0; j < 0x80; j++)
@@ -3718,16 +3664,15 @@ re_compile_fastmap (struct re_pattern_buffer *bufp)
                    }
                }
            }
-#else /* not MULE */
+#else /* ! MULE */
          for (j = 0; j < (1 << BYTEWIDTH); j++)
            if (SYNTAX_UNSAFE
                (XCHAR_TABLE
                 (regex_emacs_buffer->mirror_syntax_table), j) !=
                (enum syntaxcode) k)
              fastmap[j] = 1;
-#endif /* MULE */
+#endif /* ! MULE */
          break;
-#endif /* emacs */
 
 #ifdef MULE
 /* 97/2/17 jhod category patch */
@@ -3754,12 +3699,10 @@ re_compile_fastmap (struct re_pattern_buffer *bufp)
         case endline:
        case begbuf:
        case endbuf:
-#ifndef emacs
        case wordbound:
        case notwordbound:
        case wordbeg:
        case wordend:
-#endif
         case push_dummy_failure:
           continue;
 
@@ -3915,7 +3858,7 @@ re_set_registers (struct re_pattern_buffer *bufp, struct re_registers *regs,
    doesn't let you say where to stop matching. */
 
 int
-re_search (struct re_pattern_buffer *bufp, const char *string, int size,
+re_search (struct re_pattern_buffer *bufp, CONST char *string, int size,
           int startpos, int range, struct re_registers *regs)
 {
   return re_search_2 (bufp, NULL, 0, string, size, startpos, range,
@@ -3958,21 +3901,19 @@ typedef int Charcount;
    stack overflow).  */
 
 int
-re_search_2 (struct re_pattern_buffer *bufp, const char *str1,
-            int size1, const char *str2, int size2, int startpos,
+re_search_2 (struct re_pattern_buffer *bufp, CONST char *string1,
+            int size1, CONST char *string2, int size2, int startpos,
             int range, struct re_registers *regs, int stop)
 {
   int val;
-  re_char *string1 = (re_char *) str1;
-  re_char *string2 = (re_char *) str2;
   REGISTER char *fastmap = bufp->fastmap;
-  REGISTER RE_TRANSLATE_TYPE translate = bufp->translate;
+  REGISTER char *translate = bufp->translate;
   int total_size = size1 + size2;
   int endpos = startpos + range;
 #ifdef REGEX_BEGLINE_CHECK
   int anchored_at_begline = 0;
 #endif
-  re_char *d;
+  CONST unsigned char *d;
   Charcount d_size;
 
   /* Check for out-of-range STARTPOS.  */
@@ -3994,24 +3935,12 @@ re_search_2 (struct re_pattern_buffer *bufp, const char *str1,
        return -1;
       else
        {
-         d = ((const unsigned char *)
+         d = ((CONST unsigned char *)
               (startpos >= size1 ? string2 - size1 : string1) + startpos);
            range = charcount_to_bytecount (d, 1);
        }
     }
 
-#ifdef emacs
-  /* In a forward search for something that starts with \=.
-     don't keep searching past point.  */
-  if (bufp->used > 0 && (re_opcode_t) bufp->buffer[0] == at_dot && range > 0)
-    {
-      range = BUF_PT (regex_emacs_buffer) - BUF_BEGV (regex_emacs_buffer)
-             - startpos;
-      if (range < 0)
-       return -1;
-    }
-#endif /* emacs */
-
   /* Update the fastmap now if not correct already.  */
   if (fastmap && !bufp->fastmap_accurate)
     if (re_compile_fastmap (bufp) == -2)
@@ -4019,7 +3948,7 @@ re_search_2 (struct re_pattern_buffer *bufp, const char *str1,
 
 #ifdef REGEX_BEGLINE_CHECK
   {
-    unsigned long i = 0;
+    int i = 0;
 
     while (i < bufp->used)
       {
@@ -4033,15 +3962,6 @@ re_search_2 (struct re_pattern_buffer *bufp, const char *str1,
   }
 #endif
 
-#ifdef emacs
-    SETUP_SYNTAX_CACHE_FOR_OBJECT (regex_match_object,
-                                  regex_emacs_buffer,
-                                  SYNTAX_CACHE_OBJECT_BYTE_TO_CHAR (regex_match_object,
-                                                                    regex_emacs_buffer,
-                                                                    startpos),
-                                  1);
-#endif
-
   /* Loop through the string, looking for a place to start matching.  */
   for (;;)
     {
@@ -4060,13 +3980,17 @@ re_search_2 (struct re_pattern_buffer *bufp, const char *str1,
          if (startpos < size1 && startpos + range >= size1)
            lim = range - (size1 - startpos);
 
-         d = ((const unsigned char *)
+         d = ((CONST unsigned char *)
               (startpos >= size1 ? string2 - size1 : string1) + startpos);
          DEC_CHARPTR(d);       /* Ok, since startpos != size1. */
          d_size = charcount_to_bytecount (d, 1);
 
-         if (TRANSLATE_P (translate))
-           while (range > lim && *d != '\n')
+         if (translate)
+#ifdef MULE
+           while (range > lim && (*d >= 0x80 || translate[*d] != '\n'))
+#else
+           while (range > lim && translate[*d] != '\n')
+#endif
              {
                d += d_size;    /* Speedier INC_CHARPTR(d) */
                d_size = charcount_to_bytecount (d, 1);
@@ -4098,25 +4022,18 @@ re_search_2 (struct re_pattern_buffer *bufp, const char *str1,
               if (startpos < size1 && startpos + range >= size1)
                 lim = range - (size1 - startpos);
 
-             d = ((const unsigned char *)
+             d = ((CONST unsigned char *)
                   (startpos >= size1 ? string2 - size1 : string1) + startpos);
 
               /* Written out as an if-else to avoid testing `translate'
                  inside the loop.  */
-             if (TRANSLATE_P (translate))
-                while (range > lim)
-                 {
+             if (translate)
+                while (range > lim &&
 #ifdef MULE
-                   Emchar buf_ch;
-
-                   buf_ch = charptr_emchar (d);
-                   buf_ch = RE_TRANSLATE (buf_ch);
-                   if (buf_ch >= 0200 || fastmap[(unsigned char) buf_ch])
-                     break;
-#else
-                   if (fastmap[(unsigned char)RE_TRANSLATE (*d)])
-                     break;
-#endif /* MULE */
+                      *d < 0x80 &&
+#endif
+                      !fastmap[(unsigned char)translate[*d]])
+                 {
                    d_size = charcount_to_bytecount (d, 1);
                    range -= d_size;
                    d += d_size; /* Speedier INC_CHARPTR(d) */
@@ -4133,17 +4050,15 @@ re_search_2 (struct re_pattern_buffer *bufp, const char *str1,
            }
          else                          /* Searching backwards.  */
            {
-             Emchar c = (size1 == 0 || startpos >= size1
-                         ? charptr_emchar (string2 + startpos - size1)
-                         : charptr_emchar (string1 + startpos));
-             c = TRANSLATE (c);
+             unsigned char c = (size1 == 0 || startpos >= size1
+                                ? string2[startpos - size1]
+                                : string1[startpos]);
 #ifdef MULE
-             if (!(c >= 0200 || fastmap[(unsigned char) c]))
-               goto advance;
+             if (c < 0x80 && !fastmap[(unsigned char) TRANSLATE (c)])
 #else
-             if (!fastmap[(unsigned char) c])
-               goto advance;
+             if (!fastmap[(unsigned char) TRANSLATE (c)])
 #endif
+               goto advance;
            }
        }
 
@@ -4175,7 +4090,7 @@ re_search_2 (struct re_pattern_buffer *bufp, const char *str1,
        break;
       else if (range > 0)
        {
-         d = ((const unsigned char *)
+         d = ((CONST unsigned char *)
               (startpos >= size1 ? string2 - size1 : string1) + startpos);
          d_size = charcount_to_bytecount (d, 1);
          range -= d_size;
@@ -4185,7 +4100,7 @@ re_search_2 (struct re_pattern_buffer *bufp, const char *str1,
        {
          /* Note startpos > size1 not >=.  If we are on the
             string1/string2 boundary, we want to backup into string1. */
-         d = ((const unsigned char *)
+         d = ((CONST unsigned char *)
               (startpos > size1 ? string2 - size1 : string1) + startpos);
          DEC_CHARPTR(d);
          d_size = charcount_to_bytecount (d, 1);
@@ -4211,7 +4126,7 @@ re_search_2 (struct re_pattern_buffer *bufp, const char *str1,
 
 /* Call before fetching a character with *d.  This switches over to
    string2 if necessary.  */
-#define REGEX_PREFETCH()                                                       \
+#define PREFETCH()                                                     \
   while (d == dend)                                                    \
     {                                                                  \
       /* End of string2 => fail.  */                                   \
@@ -4256,9 +4171,9 @@ re_search_2 (struct re_pattern_buffer *bufp, const char *str1,
     FREE_VAR (reg_dummy);                                              \
     FREE_VAR (reg_info_dummy);                                         \
   } while (0)
-#else /* not MATCH_MAY_ALLOCATE */
+#else
 #define FREE_VARIABLES() ((void)0) /* Do nothing!  But inhibit gcc warning.  */
-#endif /* MATCH_MAY_ALLOCATE */
+#endif /* not MATCH_MAY_ALLOCATE */
 
 /* These values must meet several constraints.  They must not be valid
    register values; since we have a limit of 255 registers (because
@@ -4276,10 +4191,10 @@ re_search_2 (struct re_pattern_buffer *bufp, const char *str1,
 /* re_match is like re_match_2 except it takes only a single string.  */
 
 int
-re_match (struct re_pattern_buffer *bufp, const char *string, int size,
+re_match (struct re_pattern_buffer *bufp, CONST char *string, int size,
          int pos, struct re_registers *regs)
 {
-  int result = re_match_2_internal (bufp, NULL, 0, (re_char *) string, size,
+  int result = re_match_2_internal (bufp, NULL, 0, string, size,
                                    pos, regs, size);
   alloca (0);
   return result;
@@ -4301,25 +4216,12 @@ re_match (struct re_pattern_buffer *bufp, const char *string, int size,
    matched substring.  */
 
 int
-re_match_2 (struct re_pattern_buffer *bufp, const char *string1,
-           int size1, const char *string2, int size2, int pos,
+re_match_2 (struct re_pattern_buffer *bufp, CONST char *string1,
+           int size1, CONST char *string2, int size2, int pos,
            struct re_registers *regs, int stop)
 {
-  int result;
-
-#ifdef emacs
-    SETUP_SYNTAX_CACHE_FOR_OBJECT (regex_match_object,
-                                  regex_emacs_buffer,
-                                  SYNTAX_CACHE_OBJECT_BYTE_TO_CHAR (regex_match_object,
-                                                                    regex_emacs_buffer,
-                                                                    pos),
-                                  1);
-#endif
-
-  result = re_match_2_internal (bufp, (re_char *) string1, size1,
-                               (re_char *) string2, size2,
-                               pos, regs, stop);
-
+  int result = re_match_2_internal (bufp, string1, size1, string2, size2,
+                                   pos, regs, stop);
   alloca (0);
   return result;
 }
@@ -4327,8 +4229,8 @@ re_match_2 (struct re_pattern_buffer *bufp, const char *string1,
 /* This is a separate function so that we can force an alloca cleanup
    afterwards.  */
 static int
-re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1,
-                    int size1, re_char *string2, int size2, int pos,
+re_match_2_internal (struct re_pattern_buffer *bufp, CONST char *string1,
+                    int size1, CONST char *string2, int size2, int pos,
                     struct re_registers *regs, int stop)
 {
   /* General temporaries.  */
@@ -4337,14 +4239,14 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1,
   int should_succeed; /* XEmacs change */
 
   /* Just past the end of the corresponding string.  */
-  re_char *end1, *end2;
+  CONST char *end1, *end2;
 
   /* Pointers into string1 and string2, just past the last characters in
      each to consider matching.  */
-  re_char *end_match_1, *end_match_2;
+  CONST char *end_match_1, *end_match_2;
 
   /* Where we are in the data, and the end of the current string.  */
-  re_char *d, *dend;
+  CONST char *d, *dend;
 
   /* Where we are in the pattern, and the end of the pattern.  */
   unsigned char *p = bufp->buffer;
@@ -4352,10 +4254,10 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1,
 
   /* Mark the opcode just after a start_memory, so we can test for an
      empty subpattern when we get to the stop_memory.  */
-  re_char *just_past_start_mem = 0;
+  unsigned char *just_past_start_mem = 0;
 
   /* We use this to map every character in the string.  */
-  RE_TRANSLATE_TYPE translate = bufp->translate;
+  char *translate = bufp->translate;
 
   /* Failure point stack.  Each place that can handle a failure further
      down the line pushes a failure point on this stack.  It consists of
@@ -4371,7 +4273,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1,
 #endif
 #ifdef DEBUG
   static unsigned failure_id;
-  int nfailure_points_pushed = 0, nfailure_points_popped = 0;
+  unsigned nfailure_points_pushed = 0, nfailure_points_popped = 0;
 #endif
 
 #ifdef REL_ALLOC
@@ -4383,11 +4285,11 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1,
   /* We fill all the registers internally, independent of what we
      return, for use in backreferences.  The number here includes
      an element for register zero.  */
-  int num_regs = bufp->re_nsub + 1;
+  unsigned num_regs = bufp->re_nsub + 1;
 
   /* The currently active registers.  */
-  int lowest_active_reg = NO_LOWEST_ACTIVE_REG;
-  int highest_active_reg = NO_HIGHEST_ACTIVE_REG;
+  unsigned lowest_active_reg = NO_LOWEST_ACTIVE_REG;
+  unsigned highest_active_reg = NO_HIGHEST_ACTIVE_REG;
 
   /* Information on the contents of registers. These are pointers into
      the input strings; they record just what was matched (on this
@@ -4397,7 +4299,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1,
      stopped matching the regnum-th subexpression.  (The zeroth register
      keeps track of what the whole pattern matches.)  */
 #ifdef MATCH_MAY_ALLOCATE /* otherwise, these are global.  */
-  re_char **regstart, **regend;
+  CONST char **regstart, **regend;
 #endif
 
   /* If a group that's operated upon by a repetition operator fails to
@@ -4406,7 +4308,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1,
      are when we last see its open-group operator.  Similarly for a
      register's end.  */
 #ifdef MATCH_MAY_ALLOCATE /* otherwise, these are global.  */
-  re_char **old_regstart, **old_regend;
+  CONST char **old_regstart, **old_regend;
 #endif
 
   /* The is_active field of reg_info helps us keep track of which (possibly
@@ -4425,7 +4327,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1,
      turn happens only if we have not yet matched the entire string. */
   unsigned best_regs_set = false;
 #ifdef MATCH_MAY_ALLOCATE /* otherwise, these are global.  */
-  re_char **best_regstart, **best_regend;
+  CONST char **best_regstart, **best_regend;
 #endif
 
   /* Logically, this is `best_regend[0]'.  But we don't want to have to
@@ -4436,14 +4338,14 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1,
      the end of the best match so far in a separate variable.  We
      initialize this to NULL so that when we backtrack the first time
      and need to test it, it's not garbage.  */
-  re_char *match_end = NULL;
+  CONST char *match_end = NULL;
 
   /* This helps SET_REGS_MATCHED avoid doing redundant work.  */
   int set_regs_matched_done = 0;
 
   /* Used when we pop values we don't care about.  */
 #ifdef MATCH_MAY_ALLOCATE /* otherwise, these are global.  */
-  re_char **reg_dummy;
+  CONST char **reg_dummy;
   register_info_type *reg_info_dummy;
 #endif
 
@@ -4454,10 +4356,10 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1,
 
   /* 1 if this match ends in the same string (string1 or string2)
      as the best previous match.  */
-  re_bool same_str_p;
+  boolean same_str_p;
 
   /* 1 if this match is the best seen so far.  */
-  re_bool best_match_p;
+  boolean best_match_p;
 
   DEBUG_PRINT1 ("\n\nEntering re_match_2.\n");
 
@@ -4471,14 +4373,14 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1,
      array indexing.  We should fix this.  */
   if (bufp->re_nsub)
     {
-      regstart       = REGEX_TALLOC (num_regs, re_char *);
-      regend         = REGEX_TALLOC (num_regs, re_char *);
-      old_regstart   = REGEX_TALLOC (num_regs, re_char *);
-      old_regend     = REGEX_TALLOC (num_regs, re_char *);
-      best_regstart  = REGEX_TALLOC (num_regs, re_char *);
-      best_regend    = REGEX_TALLOC (num_regs, re_char *);
+      regstart       = REGEX_TALLOC (num_regs, CONST char *);
+      regend         = REGEX_TALLOC (num_regs, CONST char *);
+      old_regstart   = REGEX_TALLOC (num_regs, CONST char *);
+      old_regend     = REGEX_TALLOC (num_regs, CONST char *);
+      best_regstart  = REGEX_TALLOC (num_regs, CONST char *);
+      best_regend    = REGEX_TALLOC (num_regs, CONST char *);
       reg_info       = REGEX_TALLOC (num_regs, register_info_type);
-      reg_dummy      = REGEX_TALLOC (num_regs, re_char *);
+      reg_dummy      = REGEX_TALLOC (num_regs, CONST char *);
       reg_info_dummy = REGEX_TALLOC (num_regs, register_info_type);
 
       if (!(regstart && regend && old_regstart && old_regend && reg_info
@@ -4518,6 +4420,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1,
       MATCHED_SOMETHING (reg_info[mcnt]) = 0;
       EVER_MATCHED_SOMETHING (reg_info[mcnt]) = 0;
     }
+
   /* We move `string1' into `string2' if the latter's empty -- but not if
      `string1' is null.  */
   if (size2 == 0 && string1 != NULL)
@@ -4559,7 +4462,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1,
       dend = end_match_2;
     }
 
-  DEBUG_PRINT1 ("The compiled pattern is: \n");
+  DEBUG_PRINT1 ("The compiled pattern is: ");
   DEBUG_PRINT_COMPILED_PATTERN (bufp, p, pend);
   DEBUG_PRINT1 ("The string to match is: `");
   DEBUG_PRINT_DOUBLE_STRING (d, string1, size1, string2, size2);
@@ -4570,7 +4473,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1,
      fails at this starting point in the input data.  */
   for (;;)
     {
-      DEBUG_PRINT2 ("\n0x%lx: ", (long) p);
+      DEBUG_PRINT2 ("\n0x%p: ", p);
 #ifdef emacs /* XEmacs added, w/removal of immediate_quit */
       if (!no_quit_in_re_search)
        QUIT;
@@ -4757,40 +4660,22 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1,
 
           /* This is written out as an if-else so we don't waste time
              testing `translate' inside the loop.  */
-          if (TRANSLATE_P (translate))
+          if (translate)
            {
              do
                {
-#ifdef MULE
-                 Emchar pat_ch, buf_ch;
-                 Bytecount pat_len;
-
-                 REGEX_PREFETCH ();
-                 pat_ch = charptr_emchar (p);
-                 buf_ch = charptr_emchar (d);
-                 if (RE_TRANSLATE (buf_ch) != pat_ch)
+                 PREFETCH ();
+                 if (translate[(unsigned char) *d++] != (char) *p++)
                     goto fail;
-
-                 pat_len = charcount_to_bytecount (p, 1);
-                 p += pat_len;
-                 INC_CHARPTR (d);
-                 
-                 mcnt -= pat_len;
-#else /* not MULE */
-                 REGEX_PREFETCH ();
-                 if ((unsigned char) RE_TRANSLATE (*d++) != *p++)
-                    goto fail;
-                 mcnt--;
-#endif
                }
-             while (mcnt > 0);
+             while (--mcnt);
            }
          else
            {
              do
                {
-                 REGEX_PREFETCH ();
-                 if (*d++ != *p++) goto fail;
+                 PREFETCH ();
+                 if (*d++ != (char) *p++) goto fail;
                }
              while (--mcnt);
            }
@@ -4802,7 +4687,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1,
        case anychar:
           DEBUG_PRINT1 ("EXECUTING anychar.\n");
 
-          REGEX_PREFETCH ();
+          PREFETCH ();
 
           if ((!(bufp->syntax & RE_DOT_NEWLINE) && TRANSLATE (*d) == '\n')
               || (bufp->syntax & RE_DOT_NOT_NULL && TRANSLATE (*d) == '\000'))
@@ -4818,22 +4703,22 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1,
        case charset_not:
          {
            REGISTER unsigned char c;
-           re_bool not_p = (re_opcode_t) *(p - 1) == charset_not;
+           boolean not = (re_opcode_t) *(p - 1) == charset_not;
 
-            DEBUG_PRINT2 ("EXECUTING charset%s.\n", not_p ? "_not" : "");
+            DEBUG_PRINT2 ("EXECUTING charset%s.\n", not ? "_not" : "");
 
-           REGEX_PREFETCH ();
+           PREFETCH ();
            c = TRANSLATE (*d); /* The character to match.  */
 
             /* Cast to `unsigned' instead of `unsigned char' in case the
                bit list is a full 32 bytes long.  */
            if (c < (unsigned) (*p * BYTEWIDTH)
                && p[1 + c / BYTEWIDTH] & (1 << (c % BYTEWIDTH)))
-             not_p = !not_p;
+             not = !not;
 
            p += 1 + *p;
 
-           if (!not_p) goto fail;
+           if (!not) goto fail;
 
            SET_REGS_MATCHED ();
             INC_CHARPTR (d); /* XEmacs change */
@@ -4845,20 +4730,20 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1,
        case charset_mule_not:
          {
            REGISTER Emchar c;
-           re_bool not_p = (re_opcode_t) *(p - 1) == charset_mule_not;
+           boolean not = (re_opcode_t) *(p - 1) == charset_mule_not;
 
-            DEBUG_PRINT2 ("EXECUTING charset_mule%s.\n", not_p ? "_not" : "");
+            DEBUG_PRINT2 ("EXECUTING charset_mule%s.\n", not ? "_not" : "");
 
-           REGEX_PREFETCH ();
-           c = charptr_emchar ((const Bufbyte *) d);
+           PREFETCH ();
+           c = charptr_emchar ((CONST Bufbyte *) d);
            c = TRANSLATE_EXTENDED_UNSAFE (c); /* The character to match.  */
 
            if (EQ (Qt, unified_range_table_lookup (p, c, Qnil)))
-             not_p = !not_p;
+             not = !not;
 
            p += unified_range_table_bytes_used (p);
 
-           if (!not_p) goto fail;
+           if (!not) goto fail;
 
            SET_REGS_MATCHED ();
            INC_CHARPTR (d);
@@ -4972,16 +4857,8 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1,
                   highest_active_reg = NO_HIGHEST_ACTIVE_REG;
                 }
               else
-               {
-                 highest_active_reg = r;
-
-                 /* 98/9/21 jhod:  We've also gotta set lowest_active_reg, don't we? */
-                 r = 1;
-                 while (r < highest_active_reg && !IS_ACTIVE(reg_info[r]))
-                   r++;
-                 lowest_active_reg = r;
-               }
-           }
+                highest_active_reg = r;
+            }
 
           /* If just failed to match something this time around with a
              group that's operated on by a repetition operator, try to
@@ -4992,7 +4869,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1,
                || just_past_start_mem == p - 1)
              && (p + 2) < pend)
             {
-              re_bool is_a_jump_n = false;
+              boolean is_a_jump_n = false;
 
               p1 = p + 2;
               mcnt = 0;
@@ -5034,7 +4911,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1,
 
                   if (EVER_MATCHED_SOMETHING (reg_info[*p]))
                    {
-                     int r;
+                     unsigned r;
 
                       EVER_MATCHED_SOMETHING (reg_info[*p]) = 0;
 
@@ -5065,7 +4942,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1,
            followed by the numeric value of <digit> as the register number.  */
         case duplicate:
          {
-           REGISTER re_char *d2, *dend2;
+           REGISTER CONST char *d2, *dend2;
            int regno = *p++;   /* Get which register to match against.  */
            DEBUG_PRINT2 ("EXECUTING duplicate %d.\n", regno);
 
@@ -5101,7 +4978,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1,
                if (d2 == dend2) break;
 
                /* If necessary, advance to next segment in data.  */
-               REGEX_PREFETCH ();
+               PREFETCH ();
 
                /* How many characters left in this segment to match.  */
                mcnt = dend - d;
@@ -5113,7 +4990,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1,
 
                /* Compare that many; failure if mismatch, else move
                    past them.  */
-               if (TRANSLATE_P (translate)
+               if (translate
                     ? bcmp_translate ((unsigned char *) d,
                                      (unsigned char *) d2, mcnt, translate)
                     : memcmp (d, d2, mcnt))
@@ -5199,9 +5076,9 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1,
           DEBUG_PRINT1 ("EXECUTING on_failure_keep_string_jump");
 
           EXTRACT_NUMBER_AND_INCR (mcnt, p);
-          DEBUG_PRINT3 (" %d (to 0x%lx):\n", mcnt, (long) (p + mcnt));
+          DEBUG_PRINT3 (" %d (to 0x%p):\n", mcnt, p + mcnt);
 
-          PUSH_FAILURE_POINT (p + mcnt, (unsigned char *) 0, -2);
+          PUSH_FAILURE_POINT (p + mcnt, (char *) 0, -2);
           break;
 
 
@@ -5222,7 +5099,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1,
           DEBUG_PRINT1 ("EXECUTING on_failure_jump");
 
           EXTRACT_NUMBER_AND_INCR (mcnt, p);
-          DEBUG_PRINT3 (" %d (to 0x%lx)", mcnt, (long) (p + mcnt));
+          DEBUG_PRINT3 (" %d (to 0x%p)", mcnt, p + mcnt);
 
           /* If this on_failure_jump comes right before a group (i.e.,
              the original * applied to a group), save the information
@@ -5328,15 +5205,15 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1,
                else if ((re_opcode_t) p1[3] == charset
                         || (re_opcode_t) p1[3] == charset_not)
                  {
-                   int not_p = (re_opcode_t) p1[3] == charset_not;
+                   int not = (re_opcode_t) p1[3] == charset_not;
 
                    if (c < (unsigned char) (p1[4] * BYTEWIDTH)
                        && p1[5 + c / BYTEWIDTH] & (1 << (c % BYTEWIDTH)))
-                     not_p = !not_p;
+                     not = !not;
 
-                    /* `not_p' is equal to 1 if c would match, which means
+                    /* `not' is equal to 1 if c would match, which means
                         that we can't change to pop_failure_jump.  */
-                   if (!not_p)
+                   if (!not)
                       {
                        p[-3] = (unsigned char) pop_failure_jump;
                         DEBUG_PRINT1 ("  No match => pop_failure_jump.\n");
@@ -5419,9 +5296,9 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1,
                actual values.  Otherwise, we will restore only one
                register from the stack, since lowest will == highest in
                `pop_failure_point'.  */
-            int dummy_low_reg, dummy_high_reg;
+            unsigned dummy_low_reg, dummy_high_reg;
             unsigned char *pdummy;
-            re_char *sdummy = NULL;
+            CONST char *sdummy = NULL;
 
             DEBUG_PRINT1 ("EXECUTING pop_failure_jump.\n");
             POP_FAILURE_POINT (sdummy, pdummy,
@@ -5437,7 +5314,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1,
          EXTRACT_NUMBER_AND_INCR (mcnt, p);    /* Get the amount to jump.  */
           DEBUG_PRINT2 ("EXECUTING jump %d ", mcnt);
          p += mcnt;                            /* Do the jump.  */
-          DEBUG_PRINT2 ("(to 0x%lx).\n", (long) p);
+          DEBUG_PRINT2 ("(to 0x%p).\n", p);
          break;
 
 
@@ -5457,7 +5334,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1,
           DEBUG_PRINT1 ("EXECUTING dummy_failure_jump.\n");
           /* It doesn't matter what we push for the string here.  What
              the code at `fail' tests is the value for the pattern.  */
-          PUSH_FAILURE_POINT ((unsigned char *) 0, (unsigned char *) 0, -2);
+          PUSH_FAILURE_POINT ((unsigned char *) 0, (char *) 0, -2);
           goto unconditional_jump;
 
 
@@ -5470,7 +5347,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1,
           DEBUG_PRINT1 ("EXECUTING push_dummy_failure.\n");
           /* See comments just above at `dummy_failure_jump' about the
              two zeroes.  */
-          PUSH_FAILURE_POINT ((unsigned char *) 0, (unsigned char *) 0, -2);
+          PUSH_FAILURE_POINT ((unsigned char *) 0, (char *) 0, -2);
           break;
 
         /* Have to succeed matching what follows at least n times.
@@ -5486,12 +5363,11 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1,
                mcnt--;
               p += 2;
                STORE_NUMBER_AND_INCR (p, mcnt);
-               DEBUG_PRINT3 ("  Setting 0x%lx to %d.\n", (long) p, mcnt);
+               DEBUG_PRINT3 ("  Setting 0x%p to %d.\n", p, mcnt);
             }
          else if (mcnt == 0)
             {
-              DEBUG_PRINT2 ("  Setting two bytes from 0x%lx to no_op.\n",
-                           (long) (p+2));
+              DEBUG_PRINT2 ("  Setting two bytes from 0x%p to no_op.\n", p+2);
              p[2] = (unsigned char) no_op;
               p[3] = (unsigned char) no_op;
               goto on_failure;
@@ -5521,7 +5397,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1,
             EXTRACT_NUMBER_AND_INCR (mcnt, p);
             p1 = p + mcnt;
             EXTRACT_NUMBER_AND_INCR (mcnt, p);
-            DEBUG_PRINT3 ("  Setting 0x%lx to %d.\n", (long) p1, mcnt);
+            DEBUG_PRINT3 ("  Setting 0x%p to %d.\n", p1, mcnt);
            STORE_NUMBER (p1, mcnt);
             break;
           }
@@ -5537,34 +5413,17 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1,
              result = 1;
            else
              {
-               re_char *d_before = POS_BEFORE_GAP_UNSAFE (d);
-               re_char *d_after = POS_AFTER_GAP_UNSAFE (d);
-
-               /* emch1 is the character before d, syn1 is the syntax of emch1,
-                  emch2 is the character at d, and syn2 is the syntax of emch2. */
+               CONST unsigned char *d_before =
+                 (CONST unsigned char *) POS_BEFORE_GAP_UNSAFE (d);
+               CONST unsigned char *d_after =
+                 (CONST unsigned char *) POS_AFTER_GAP_UNSAFE (d);
                Emchar emch1, emch2;
-               int syn1, syn2;
-#ifdef emacs
-               int pos_before;
-#endif
 
                DEC_CHARPTR (d_before);
                emch1 = charptr_emchar (d_before);
                emch2 = charptr_emchar (d_after);
-
-#ifdef emacs
-               pos_before = SYNTAX_CACHE_BYTE_TO_CHAR (PTR_TO_OFFSET (d)) - 1;
-               UPDATE_SYNTAX_CACHE (pos_before);
-#endif
-               syn1 = SYNTAX_FROM_CACHE (XCHAR_TABLE (regex_emacs_buffer->mirror_syntax_table),
-                                         emch1);
-#ifdef emacs
-               UPDATE_SYNTAX_CACHE_FORWARD (pos_before + 1);
-#endif
-               syn2 = SYNTAX_FROM_CACHE (XCHAR_TABLE (regex_emacs_buffer->mirror_syntax_table),
-                                         emch2);
-
-               result = ((syn1 == Sword) != (syn2 == Sword));
+               result = (WORDCHAR_P_UNSAFE (emch1) !=
+                         WORDCHAR_P_UNSAFE (emch2));
              }
            if (result == should_succeed)
              break;
@@ -5578,8 +5437,6 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1,
 
        case wordbeg:
           DEBUG_PRINT1 ("EXECUTING wordbeg.\n");
-         if (AT_STRINGS_END (d))
-           goto fail;
          {
            /* XEmacs: this originally read:
 
@@ -5587,33 +5444,23 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1,
              break;
 
              */
-           re_char *dtmp = POS_AFTER_GAP_UNSAFE (d);
+           CONST unsigned char *dtmp =
+             (CONST unsigned char *) POS_AFTER_GAP_UNSAFE (d);
            Emchar emch = charptr_emchar (dtmp);
-#ifdef emacs
-           int charpos = SYNTAX_CACHE_BYTE_TO_CHAR (PTR_TO_OFFSET (d));
-           UPDATE_SYNTAX_CACHE (charpos);
-#endif
-           if (SYNTAX_FROM_CACHE (XCHAR_TABLE (regex_emacs_buffer->mirror_syntax_table),
-                                  emch) != Sword)
+           if (!WORDCHAR_P_UNSAFE (emch))
              goto fail;
            if (AT_STRINGS_BEG (d))
              break;
-           dtmp = POS_BEFORE_GAP_UNSAFE (d);
+           dtmp = (CONST unsigned char *) POS_BEFORE_GAP_UNSAFE (d);
            DEC_CHARPTR (dtmp);
            emch = charptr_emchar (dtmp);
-#ifdef emacs
-           UPDATE_SYNTAX_CACHE_BACKWARD (charpos - 1);
-#endif
-           if (SYNTAX_FROM_CACHE (XCHAR_TABLE (regex_emacs_buffer->mirror_syntax_table),
-                                  emch) != Sword)
+           if (!WORDCHAR_P_UNSAFE (emch))
              break;
            goto fail;
          }
 
        case wordend:
           DEBUG_PRINT1 ("EXECUTING wordend.\n");
-         if (AT_STRINGS_BEG (d))
-           goto fail;
          {
            /* XEmacs: this originally read:
 
@@ -5623,27 +5470,20 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1,
 
              The or condition is incorrect (reversed).
              */
-           re_char *dtmp;
+           CONST unsigned char *dtmp;
            Emchar emch;
-#ifdef emacs
-           int charpos = SYNTAX_CACHE_BYTE_TO_CHAR (PTR_TO_OFFSET (d)) - 1;
-           UPDATE_SYNTAX_CACHE (charpos);
-#endif
-           dtmp = POS_BEFORE_GAP_UNSAFE (d);
+           if (AT_STRINGS_BEG (d))
+             goto fail;
+           dtmp = (CONST unsigned char *) POS_BEFORE_GAP_UNSAFE (d);
            DEC_CHARPTR (dtmp);
            emch = charptr_emchar (dtmp);
-           if (SYNTAX_FROM_CACHE (XCHAR_TABLE (regex_emacs_buffer->mirror_syntax_table),
-                                  emch) != Sword)
+           if (!WORDCHAR_P_UNSAFE (emch))
              goto fail;
            if (AT_STRINGS_END (d))
              break;
-           dtmp = POS_AFTER_GAP_UNSAFE (d);
+           dtmp = (CONST unsigned char *) POS_AFTER_GAP_UNSAFE (d);
            emch = charptr_emchar (dtmp);
-#ifdef emacs
-           UPDATE_SYNTAX_CACHE_FORWARD (charpos + 1);
-#endif
-           if (SYNTAX_FROM_CACHE (XCHAR_TABLE (regex_emacs_buffer->mirror_syntax_table),
-                                  emch) != Sword)
+           if (!WORDCHAR_P_UNSAFE (emch))
              break;
            goto fail;
          }
@@ -5651,25 +5491,22 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1,
 #ifdef emacs
        case before_dot:
           DEBUG_PRINT1 ("EXECUTING before_dot.\n");
-         if (! (NILP (regex_match_object) || BUFFERP (regex_match_object))
-             || (BUF_PTR_BYTE_POS (regex_emacs_buffer, (unsigned char *) d)
-                 >= BUF_PT (regex_emacs_buffer)))
+         if (BUF_PTR_BYTE_POS (regex_emacs_buffer, (unsigned char *) d) >=
+             BUF_PT (regex_emacs_buffer))
            goto fail;
          break;
 
        case at_dot:
           DEBUG_PRINT1 ("EXECUTING at_dot.\n");
-         if (! (NILP (regex_match_object) || BUFFERP (regex_match_object))
-             || (BUF_PTR_BYTE_POS (regex_emacs_buffer, (unsigned char *) d)
-                 != BUF_PT (regex_emacs_buffer)))
+         if (BUF_PTR_BYTE_POS (regex_emacs_buffer, (unsigned char *) d)
+             != BUF_PT (regex_emacs_buffer))
            goto fail;
          break;
 
        case after_dot:
           DEBUG_PRINT1 ("EXECUTING after_dot.\n");
-          if (! (NILP (regex_match_object) || BUFFERP (regex_match_object))
-             || (BUF_PTR_BYTE_POS (regex_emacs_buffer, (unsigned char *) d)
-                 <= BUF_PT (regex_emacs_buffer)))
+          if (BUF_PTR_BYTE_POS (regex_emacs_buffer, (unsigned char *) d)
+             <= BUF_PT (regex_emacs_buffer))
            goto fail;
          break;
 #if 0 /* not emacs19 */
@@ -5696,16 +5533,10 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1,
            int matches;
            Emchar emch;
 
-           REGEX_PREFETCH ();
-#ifdef emacs
-           {
-             int charpos = SYNTAX_CACHE_BYTE_TO_CHAR (PTR_TO_OFFSET (d));
-             UPDATE_SYNTAX_CACHE (charpos);
-           }
-#endif
-
-           emch = charptr_emchar ((const Bufbyte *) d);
-           matches = (SYNTAX_FROM_CACHE (regex_emacs_buffer->mirror_syntax_table,
+           PREFETCH ();
+           emch = charptr_emchar ((CONST Bufbyte *) d);
+           matches = (SYNTAX_UNSAFE
+                      (XCHAR_TABLE (regex_emacs_buffer->mirror_syntax_table),
                        emch) == (enum syntaxcode) mcnt);
            INC_CHARPTR (d);
            if (matches != should_succeed)
@@ -5735,8 +5566,8 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1,
            Emchar emch;
 
            mcnt = *p++;
-           REGEX_PREFETCH ();
-           emch = charptr_emchar ((const Bufbyte *) d);
+           PREFETCH ();
+           emch = charptr_emchar ((CONST Bufbyte *) d);
            INC_CHARPTR (d);
            if (check_category_char(emch, regex_emacs_buffer->category_table,
                                    mcnt, should_succeed))
@@ -5753,7 +5584,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1,
 #else /* not emacs */
        case wordchar:
           DEBUG_PRINT1 ("EXECUTING non-Emacs wordchar.\n");
-         REGEX_PREFETCH ();
+         PREFETCH ();
           if (!WORDCHAR_P_UNSAFE ((int) (*d)))
             goto fail;
          SET_REGS_MATCHED ();
@@ -5762,13 +5593,13 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1,
 
        case notwordchar:
           DEBUG_PRINT1 ("EXECUTING non-Emacs notwordchar.\n");
-         REGEX_PREFETCH ();
+         PREFETCH ();
           if (!WORDCHAR_P_UNSAFE ((int) (*d)))
             goto fail;
           SET_REGS_MATCHED ();
           d++;
          break;
-#endif /* emacs */
+#endif /* not emacs */
 
         default:
           abort ();
@@ -5793,7 +5624,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1,
          assert (p <= pend);
           if (p < pend)
             {
-              re_bool is_a_jump_n = false;
+              boolean is_a_jump_n = false;
 
               /* If failed to a backwards jump that's part of a repetition
                  loop, need to pop this failure point and use the next one.  */
@@ -5846,7 +5677,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1,
 
    We don't handle duplicates properly (yet).  */
 
-static re_bool
+static boolean
 group_match_null_string_p (unsigned char **p, unsigned char *end,
                           register_info_type *reg_info)
 {
@@ -5954,7 +5785,7 @@ group_match_null_string_p (unsigned char **p, unsigned char *end,
    It expects P to be the first byte of a single alternative and END one
    byte past the last. The alternative can contain groups.  */
 
-static re_bool
+static boolean
 alt_match_null_string_p (unsigned char *p, unsigned char *end,
                         register_info_type *reg_info)
 {
@@ -5990,12 +5821,12 @@ alt_match_null_string_p (unsigned char *p, unsigned char *end,
 
    Sets P to one after the op and its arguments, if any.  */
 
-static re_bool
+static boolean
 common_op_match_null_string_p (unsigned char **p, unsigned char *end,
                               register_info_type *reg_info)
 {
   int mcnt;
-  re_bool ret;
+  boolean ret;
   int reg_no;
   unsigned char *p1 = *p;
 
@@ -6078,34 +5909,15 @@ common_op_match_null_string_p (unsigned char **p, unsigned char *end,
    bytes; nonzero otherwise.  */
 
 static int
-bcmp_translate (re_char *s1, re_char *s2,
-               REGISTER int len, RE_TRANSLATE_TYPE translate)
+bcmp_translate (CONST unsigned char *s1, CONST unsigned char *s2,
+               REGISTER int len, char *translate)
 {
-  REGISTER const unsigned char *p1 = s1, *p2 = s2;
-#ifdef MULE
-  const unsigned char *p1_end = s1 + len;
-  const unsigned char *p2_end = s2 + len;
-
-  while (p1 != p1_end && p2 != p2_end)
-    {
-      Emchar p1_ch, p2_ch;
-
-      p1_ch = charptr_emchar (p1);
-      p2_ch = charptr_emchar (p2);
-
-      if (RE_TRANSLATE (p1_ch)
-         != RE_TRANSLATE (p2_ch))
-       return 1;
-      INC_CHARPTR (p1);
-      INC_CHARPTR (p2);
-    }
-#else /* not MULE */
+  REGISTER CONST unsigned char *p1 = s1, *p2 = s2;
   while (len)
     {
-      if (RE_TRANSLATE (*p1++) != RE_TRANSLATE (*p2++)) return 1;
+      if (translate[*p1++] != translate[*p2++]) return 1;
       len--;
     }
-#endif /* MULE */
   return 0;
 }
 \f
@@ -6120,8 +5932,8 @@ bcmp_translate (re_char *s1, re_char *s2,
 
    We call regex_compile to do the actual compilation.  */
 
-const char *
-re_compile_pattern (const char *pattern, int length,
+CONST char *
+re_compile_pattern (CONST char *pattern, int length,
                    struct re_pattern_buffer *bufp)
 {
   reg_errcode_t ret;
@@ -6138,7 +5950,7 @@ re_compile_pattern (const char *pattern, int length,
   /* Match anchors at newline.  */
   bufp->newline_anchor = 1;
 
-  ret = regex_compile ((unsigned char *) pattern, length, re_syntax_options, bufp);
+  ret = regex_compile (pattern, length, re_syntax_options, bufp);
 
   if (!ret)
     return NULL;
@@ -6154,7 +5966,7 @@ re_compile_pattern (const char *pattern, int length,
 static struct re_pattern_buffer re_comp_buf;
 
 char *
-re_comp (const char *s)
+re_comp (CONST char *s)
 {
   reg_errcode_t ret;
 
@@ -6183,20 +5995,20 @@ re_comp (const char *s)
   /* Match anchors at newlines.  */
   re_comp_buf.newline_anchor = 1;
 
-  ret = regex_compile ((unsigned char *)s, strlen (s), re_syntax_options, &re_comp_buf);
+  ret = regex_compile (s, strlen (s), re_syntax_options, &re_comp_buf);
 
   if (!ret)
     return NULL;
 
-  /* Yes, we're discarding `const' here if !HAVE_LIBINTL.  */
+  /* Yes, we're discarding `CONST' here if !HAVE_LIBINTL.  */
   return (char *) gettext (re_error_msgid[(int) ret]);
 }
 
 
 int
-re_exec (const char *s)
+re_exec (CONST char *s)
 {
-  const int len = strlen (s);
+  CONST int len = strlen (s);
   return
     0 <= re_search (&re_comp_buf, s, len, 0, len, (struct re_registers *) 0);
 }
@@ -6241,7 +6053,7 @@ re_exec (const char *s)
    the return codes and their meanings.)  */
 
 int
-regcomp (regex_t *preg, const char *pattern, int cflags)
+regcomp (regex_t *preg, CONST char *pattern, int cflags)
 {
   reg_errcode_t ret;
   unsigned syntax
@@ -6289,7 +6101,7 @@ regcomp (regex_t *preg, const char *pattern, int cflags)
 
   /* POSIX says a null character in the pattern terminates it, so we
      can use strlen here in compiling the pattern.  */
-  ret = regex_compile ((unsigned char *) pattern, strlen (pattern), syntax, preg);
+  ret = regex_compile (pattern, strlen (pattern), syntax, preg);
 
   /* POSIX doesn't distinguish between an unmatched open-group and an
      unmatched close-group: both are REG_EPAREN.  */
@@ -6314,14 +6126,14 @@ regcomp (regex_t *preg, const char *pattern, int cflags)
    We return 0 if we find a match and REG_NOMATCH if not.  */
 
 int
-regexec (const regex_t *preg, const char *string, Element_count nmatch,
+regexec (CONST regex_t *preg, CONST char *string, size_t nmatch,
         regmatch_t pmatch[], int eflags)
 {
   int ret;
   struct re_registers regs;
   regex_t private_preg;
   int len = strlen (string);
-  re_bool want_reg_info = !preg->no_sub && nmatch > 0;
+  boolean want_reg_info = !preg->no_sub && nmatch > 0;
 
   private_preg = *preg;
 
@@ -6352,7 +6164,7 @@ regexec (const regex_t *preg, const char *string, Element_count nmatch,
     {
       if (ret >= 0)
         {
-          Element_count r;
+          unsigned r;
 
           for (r = 0; r < nmatch; r++)
             {
@@ -6374,16 +6186,14 @@ regexec (const regex_t *preg, const char *string, Element_count nmatch,
 /* Returns a message corresponding to an error code, ERRCODE, returned
    from either regcomp or regexec.   We don't use PREG here.  */
 
-Memory_count
-regerror (int errcode, const regex_t *preg, char *errbuf,
-         Memory_count errbuf_size)
+size_t
+regerror (int errcode, CONST regex_t *preg, char *errbuf, size_t errbuf_size)
 {
-  const char *msg;
-  Memory_count msg_size;
+  CONST char *msg;
+  size_t msg_size;
 
   if (errcode < 0
-      || (size_t) errcode >= (sizeof (re_error_msgid)
-                             / sizeof (re_error_msgid[0])))
+      || errcode >= (sizeof (re_error_msgid) / sizeof (re_error_msgid[0])))
     /* Only error codes returned by the rest of the code should be passed
        to this routine.  If we are given anything else, or if other regex
        code generates an invalid error code, then the program has a bug.