Fix typo: __LIBC -> _LIBC.
[gnulib.git] / lib / regcomp.c
index 26a55b2..28e677b 100644 (file)
@@ -90,7 +90,7 @@ static reg_errcode_t build_equiv_class (re_bitset_ptr_t sbcset,
                                        re_charset_t *mbcset,
                                        int *equiv_class_alloc,
                                        const unsigned char *name);
-static reg_errcode_t build_charclass (unsigned RE_TRANSLATE_TYPE trans,
+static reg_errcode_t build_charclass (unsigned REG_TRANSLATE_TYPE trans,
                                      re_bitset_ptr_t sbcset,
                                      re_charset_t *mbcset,
                                      int *char_class_alloc,
@@ -99,13 +99,13 @@ static reg_errcode_t build_charclass (unsigned RE_TRANSLATE_TYPE trans,
 #else  /* not RE_ENABLE_I18N */
 static reg_errcode_t build_equiv_class (re_bitset_ptr_t sbcset,
                                        const unsigned char *name);
-static reg_errcode_t build_charclass (unsigned RE_TRANSLATE_TYPE trans,
+static reg_errcode_t build_charclass (unsigned REG_TRANSLATE_TYPE trans,
                                      re_bitset_ptr_t sbcset,
                                      const unsigned char *class_name,
                                      reg_syntax_t syntax);
 #endif /* not RE_ENABLE_I18N */
 static bin_tree_t *build_charclass_op (re_dfa_t *dfa,
-                                      unsigned RE_TRANSLATE_TYPE trans,
+                                      unsigned REG_TRANSLATE_TYPE trans,
                                       const unsigned char *class_name,
                                       const unsigned char *extra,
                                       int non_match, reg_errcode_t *err);
@@ -206,7 +206,7 @@ const size_t __re_error_msgid_idx[] attribute_hidden =
    compiles PATTERN (of length LENGTH) and puts the result in BUFP.
    Returns 0 if the pattern was valid, otherwise an error string.
 
-   Assumes the `allocated' (and perhaps `buffer') and `translate' fields
+   Assumes the `re_allocated' (and perhaps `re_buffer') and `translate' fields
    are set in BUFP on entry.  */
 
 const char *
@@ -217,11 +217,11 @@ re_compile_pattern (const char *pattern, size_t length,
 
   /* And GNU code determines whether or not to get register information
      by passing null for the REGS argument to re_match, etc., not by
-     setting no_sub, unless RE_NO_SUB is set.  */
-  bufp->no_sub = !!(re_syntax_options & RE_NO_SUB);
+     setting re_no_sub, unless REG_NO_SUB is set.  */
+  bufp->re_no_sub = !!(re_syntax_options & REG_NO_SUB);
 
   /* Match anchors at newline.  */
-  bufp->newline_anchor = 1;
+  bufp->re_newline_anchor = 1;
 
   ret = re_compile_internal (bufp, pattern, length, re_syntax_options);
 
@@ -263,8 +263,8 @@ weak_alias (__re_set_syntax, re_set_syntax)
 int
 re_compile_fastmap (struct re_pattern_buffer *bufp)
 {
-  re_dfa_t *dfa = (re_dfa_t *) bufp->buffer;
-  char *fastmap = bufp->fastmap;
+  re_dfa_t *dfa = (re_dfa_t *) bufp->re_buffer;
+  char *fastmap = bufp->re_fastmap;
 
   memset (fastmap, '\0', sizeof (char) * SBC_MAX);
   re_compile_fastmap_iter (bufp, dfa->init_state, fastmap);
@@ -274,7 +274,7 @@ re_compile_fastmap (struct re_pattern_buffer *bufp)
     re_compile_fastmap_iter (bufp, dfa->init_state_nl, fastmap);
   if (dfa->init_state != dfa->init_state_begbuf)
     re_compile_fastmap_iter (bufp, dfa->init_state_begbuf, fastmap);
-  bufp->fastmap_accurate = 1;
+  bufp->re_fastmap_accurate = 1;
   return 0;
 }
 #ifdef _LIBC
@@ -297,9 +297,9 @@ static void
 re_compile_fastmap_iter (regex_t *bufp, const re_dfastate_t *init_state,
                         char *fastmap)
 {
-  re_dfa_t *dfa = (re_dfa_t *) bufp->buffer;
+  re_dfa_t *dfa = (re_dfa_t *) bufp->re_buffer;
   int node_cnt;
-  int icase = (dfa->mb_cur_max == 1 && (bufp->syntax & RE_ICASE));
+  int icase = (dfa->mb_cur_max == 1 && (bufp->re_syntax & REG_IGNORE_CASE));
   for (node_cnt = 0; node_cnt < init_state->nodes.nelem; ++node_cnt)
     {
       int node = init_state->nodes.elems[node_cnt];
@@ -309,9 +309,10 @@ re_compile_fastmap_iter (regex_t *bufp, const re_dfastate_t *init_state,
        {
          re_set_fastmap (fastmap, icase, dfa->nodes[node].opr.c);
 #ifdef RE_ENABLE_I18N
-         if ((bufp->syntax & RE_ICASE) && dfa->mb_cur_max > 1)
+         if ((bufp->re_syntax & REG_IGNORE_CASE) && dfa->mb_cur_max > 1)
            {
-             unsigned char *buf = alloca (dfa->mb_cur_max), *p;
+             unsigned char buf[MB_LEN_MAX];
+             unsigned char *p;
              wchar_t wc;
              mbstate_t state;
 
@@ -377,7 +378,7 @@ re_compile_fastmap_iter (regex_t *bufp, const re_dfastate_t *init_state,
              memset (&state, '\0', sizeof (state));
              if (__wcrtomb (buf, cset->mbchars[i], &state) != (size_t) -1)
                re_set_fastmap (fastmap, icase, *(unsigned char *) buf);
-             if ((bufp->syntax & RE_ICASE) && dfa->mb_cur_max > 1)
+             if ((bufp->re_syntax & REG_IGNORE_CASE) && dfa->mb_cur_max > 1)
                {
                  if (__wcrtomb (buf, towlower (cset->mbchars[i]), &state)
                      != (size_t) -1)
@@ -394,7 +395,7 @@ re_compile_fastmap_iter (regex_t *bufp, const re_dfastate_t *init_state,
        {
          memset (fastmap, '\1', sizeof (char) * SBC_MAX);
          if (type == END_OF_RE)
-           bufp->can_be_null = 1;
+           bufp->re_can_be_null = 1;
          return;
        }
     }
@@ -406,14 +407,14 @@ re_compile_fastmap_iter (regex_t *bufp, const re_dfastate_t *init_state,
    PREG is a regex_t *.  We do not expect any fields to be initialized,
    since POSIX says we shouldn't.  Thus, we set
 
-     `buffer' to the compiled pattern;
-     `used' to the length of the compiled pattern;
-     `syntax' to RE_SYNTAX_POSIX_EXTENDED if the
+     `re_buffer' to the compiled pattern;
+     `re_used' to the length of the compiled pattern;
+     `re_syntax' to REG_SYNTAX_POSIX_EXTENDED if the
        REG_EXTENDED bit in CFLAGS is set; otherwise, to
-       RE_SYNTAX_POSIX_BASIC;
-     `newline_anchor' to REG_NEWLINE being set in CFLAGS;
-     `fastmap' to an allocated space for the fastmap;
-     `fastmap_accurate' to zero;
+       REG_SYNTAX_POSIX_BASIC;
+     `re_newline_anchor' to REG_NEWLINE being set in CFLAGS;
+     `re_fastmap' to an allocated space for the fastmap;
+     `re_fastmap_accurate' to zero;
      `re_nsub' to the number of subexpressions in PATTERN.
 
    PATTERN is the address of the pattern string.
@@ -440,32 +441,32 @@ int
 regcomp (regex_t *__restrict preg, const char *__restrict pattern, int cflags)
 {
   reg_errcode_t ret;
-  reg_syntax_t syntax = ((cflags & REG_EXTENDED) ? RE_SYNTAX_POSIX_EXTENDED
-                        : RE_SYNTAX_POSIX_BASIC);
+  reg_syntax_t syntax = ((cflags & REG_EXTENDED) ? REG_SYNTAX_POSIX_EXTENDED
+                       : REG_SYNTAX_POSIX_BASIC);
 
-  preg->buffer = NULL;
-  preg->allocated = 0;
-  preg->used = 0;
+  preg->re_buffer = NULL;
+  preg->re_allocated = 0;
+  preg->re_used = 0;
 
   /* Try to allocate space for the fastmap.  */
-  preg->fastmap = re_malloc (char, SBC_MAX);
-  if (BE (preg->fastmap == NULL, 0))
+  preg->re_fastmap = re_malloc (char, SBC_MAX);
+  if (BE (preg->re_fastmap == NULL, 0))
     return REG_ESPACE;
 
-  syntax |= (cflags & REG_ICASE) ? RE_ICASE : 0;
+  syntax |= (cflags & REG_ICASE) ? REG_IGNORE_CASE : 0;
 
   /* If REG_NEWLINE is set, newlines are treated differently.  */
   if (cflags & REG_NEWLINE)
     { /* REG_NEWLINE implies neither . nor [^...] match newline.  */
-      syntax &= ~RE_DOT_NEWLINE;
-      syntax |= RE_HAT_LISTS_NOT_NEWLINE;
+      syntax &= ~REG_DOT_NEWLINE;
+      syntax |= REG_HAT_LISTS_NOT_NEWLINE;
       /* It also changes the matching behavior.  */
-      preg->newline_anchor = 1;
+      preg->re_newline_anchor = 1;
     }
   else
-    preg->newline_anchor = 0;
-  preg->no_sub = !!(cflags & REG_NOSUB);
-  preg->translate = NULL;
+    preg->re_newline_anchor = 0;
+  preg->re_no_sub = !!(cflags & REG_NOSUB);
+  preg->re_translate = NULL;
 
   ret = re_compile_internal (preg, pattern, strlen (pattern), syntax);
 
@@ -474,7 +475,7 @@ regcomp (regex_t *__restrict preg, const char *__restrict pattern, int cflags)
   if (ret == REG_ERPAREN)
     ret = REG_EPAREN;
 
-  /* We have already checked preg->fastmap != NULL.  */
+  /* We have already checked preg->re_fastmap != NULL.  */
   if (BE (ret == REG_NOERROR, 1))
     /* Compute the fastmap now, since regexec cannot modify the pattern
        buffer.  This function never fails in this implementation.  */
@@ -482,8 +483,8 @@ regcomp (regex_t *__restrict preg, const char *__restrict pattern, int cflags)
   else
     {
       /* Some error occurred while compiling the expression.  */
-      re_free (preg->fastmap);
-      preg->fastmap = NULL;
+      re_free (preg->re_fastmap);
+      preg->re_fastmap = NULL;
     }
 
   return (int) ret;
@@ -496,7 +497,8 @@ weak_alias (__regcomp, regcomp)
    from either regcomp or regexec.   We don't use PREG here.  */
 
 size_t
-regerror (int errcode, const regex_t *preg, char *errbuf, size_t errbuf_size)
+regerror (int errcode, const regex_t *__restrict preg,
+         char *__restrict errbuf, size_t errbuf_size)
 {
   const char *msg;
   size_t msg_size;
@@ -606,17 +608,17 @@ free_dfa_content (re_dfa_t *dfa)
 void
 regfree (regex_t *preg)
 {
-  re_dfa_t *dfa = (re_dfa_t *) preg->buffer;
+  re_dfa_t *dfa = (re_dfa_t *) preg->re_buffer;
   if (BE (dfa != NULL, 1))
     free_dfa_content (dfa);
-  preg->buffer = NULL;
-  preg->allocated = 0;
+  preg->re_buffer = NULL;
+  preg->re_allocated = 0;
 
-  re_free (preg->fastmap);
-  preg->fastmap = NULL;
+  re_free (preg->re_fastmap);
+  preg->re_fastmap = NULL;
 
-  re_free (preg->translate);
-  preg->translate = NULL;
+  re_free (preg->re_translate);
+  preg->re_translate = NULL;
 }
 #ifdef _LIBC
 weak_alias (__regfree, regfree)
@@ -645,24 +647,24 @@ re_comp (s)
 
   if (!s)
     {
-      if (!re_comp_buf.buffer)
+      if (!re_comp_buf.re_buffer)
        return gettext ("No previous regular expression");
       return 0;
     }
 
-  if (re_comp_buf.buffer)
+  if (re_comp_buf.re_buffer)
     {
-      fastmap = re_comp_buf.fastmap;
-      re_comp_buf.fastmap = NULL;
+      fastmap = re_comp_buf.re_fastmap;
+      re_comp_buf.re_fastmap = NULL;
       __regfree (&re_comp_buf);
       memset (&re_comp_buf, '\0', sizeof (re_comp_buf));
-      re_comp_buf.fastmap = fastmap;
+      re_comp_buf.re_fastmap = fastmap;
     }
 
-  if (re_comp_buf.fastmap == NULL)
+  if (re_comp_buf.re_fastmap == NULL)
     {
-      re_comp_buf.fastmap = (char *) malloc (SBC_MAX);
-      if (re_comp_buf.fastmap == NULL)
+      re_comp_buf.re_fastmap = (char *) malloc (SBC_MAX);
+      if (re_comp_buf.re_fastmap == NULL)
        return (char *) gettext (__re_error_msgid
                                 + __re_error_msgid_idx[(int) REG_ESPACE]);
     }
@@ -671,7 +673,7 @@ re_comp (s)
      don't need to initialize the pattern buffer fields which affect it.  */
 
   /* Match anchors at newlines.  */
-  re_comp_buf.newline_anchor = 1;
+  re_comp_buf.re_newline_anchor = 1;
 
   ret = re_compile_internal (&re_comp_buf, s, strlen (s), re_syntax_options);
 
@@ -704,29 +706,29 @@ re_compile_internal (regex_t *preg, const char * pattern, int length,
   re_string_t regexp;
 
   /* Initialize the pattern buffer.  */
-  preg->fastmap_accurate = 0;
-  preg->syntax = syntax;
-  preg->not_bol = preg->not_eol = 0;
-  preg->used = 0;
+  preg->re_fastmap_accurate = 0;
+  preg->re_syntax = syntax;
+  preg->re_not_bol = preg->re_not_eol = 0;
+  preg->re_used = 0;
   preg->re_nsub = 0;
-  preg->can_be_null = 0;
-  preg->regs_allocated = REGS_UNALLOCATED;
+  preg->re_can_be_null = 0;
+  preg->re_regs_allocated = REG_UNALLOCATED;
 
   /* Initialize the dfa.  */
-  dfa = (re_dfa_t *) preg->buffer;
-  if (BE (preg->allocated < sizeof (re_dfa_t), 0))
+  dfa = (re_dfa_t *) preg->re_buffer;
+  if (BE (preg->re_allocated < sizeof (re_dfa_t), 0))
     {
       /* If zero allocated, but buffer is non-null, try to realloc
         enough space.  This loses if buffer's address is bogus, but
-        that is the user's responsibility.  If ->buffer is NULL this
+        that is the user's responsibility.  If buffer is null this
         is a simple allocation.  */
-      dfa = re_realloc (preg->buffer, re_dfa_t, 1);
+      dfa = re_realloc (preg->re_buffer, re_dfa_t, 1);
       if (dfa == NULL)
        return REG_ESPACE;
-      preg->allocated = sizeof (re_dfa_t);
-      preg->buffer = (unsigned char *) dfa;
+      preg->re_allocated = sizeof (re_dfa_t);
+      preg->re_buffer = (unsigned char *) dfa;
     }
-  preg->used = sizeof (re_dfa_t);
+  preg->re_used = sizeof (re_dfa_t);
 
   __libc_lock_init (dfa->lock);
 
@@ -734,8 +736,8 @@ re_compile_internal (regex_t *preg, const char * pattern, int length,
   if (BE (err != REG_NOERROR, 0))
     {
       free_dfa_content (dfa);
-      preg->buffer = NULL;
-      preg->allocated = 0;
+      preg->re_buffer = NULL;
+      preg->re_allocated = 0;
       return err;
     }
 #ifdef DEBUG
@@ -743,16 +745,16 @@ re_compile_internal (regex_t *preg, const char * pattern, int length,
   strncpy (dfa->re_str, pattern, length + 1);
 #endif
 
-  err = re_string_construct (&regexp, pattern, length, preg->translate,
-                            syntax & RE_ICASE, dfa);
+  err = re_string_construct (&regexp, pattern, length, preg->re_translate,
+                            syntax & REG_IGNORE_CASE, dfa);
   if (BE (err != REG_NOERROR, 0))
     {
     re_compile_internal_free_return:
       free_workarea_compile (preg);
       re_string_destruct (&regexp);
       free_dfa_content (dfa);
-      preg->buffer = NULL;
-      preg->allocated = 0;
+      preg->re_buffer = NULL;
+      preg->re_allocated = 0;
       return err;
     }
 
@@ -769,7 +771,7 @@ re_compile_internal (regex_t *preg, const char * pattern, int length,
 
 #ifdef RE_ENABLE_I18N
   /* If possible, do searching in single byte encoding to speed things up.  */
-  if (dfa->is_utf8 && !(syntax & RE_ICASE) && preg->translate == NULL)
+  if (dfa->is_utf8 && !(syntax & REG_IGNORE_CASE) && preg->re_translate == NULL)
     optimize_utf8 (dfa);
 #endif
 
@@ -783,8 +785,8 @@ re_compile_internal (regex_t *preg, const char * pattern, int length,
   if (BE (err != REG_NOERROR, 0))
     {
       free_dfa_content (dfa);
-      preg->buffer = NULL;
-      preg->allocated = 0;
+      preg->re_buffer = NULL;
+      preg->re_allocated = 0;
     }
 
   return err;
@@ -816,7 +818,7 @@ init_dfa (re_dfa_t *dfa, int pat_len)
     if (table_size > pat_len)
       break;
 
-  dfa->state_table = calloc (sizeof (struct re_state_table_entry), table_size);
+  dfa->state_table = re_calloc (struct re_state_table_entry, table_size);
   dfa->state_hash_mask = table_size - 1;
 
   dfa->mb_cur_max = MB_CUR_MAX;
@@ -859,7 +861,7 @@ init_dfa (re_dfa_t *dfa, int pat_len)
        {
          int i, j, ch;
 
-         dfa->sb_char = (re_bitset_ptr_t) calloc (sizeof (bitset), 1);
+         dfa->sb_char = re_calloc (unsigned int, BITSET_UINTS);
          if (BE (dfa->sb_char == NULL, 0))
            return REG_ESPACE;
 
@@ -907,7 +909,7 @@ init_word_char (re_dfa_t *dfa)
 static void
 free_workarea_compile (regex_t *preg)
 {
-  re_dfa_t *dfa = (re_dfa_t *) preg->buffer;
+  re_dfa_t *dfa = (re_dfa_t *) preg->re_buffer;
   bin_tree_storage_t *storage, *next;
   for (storage = dfa->str_tree_storage; storage; storage = next)
     {
@@ -1075,7 +1077,7 @@ optimize_utf8 (re_dfa_t *dfa)
 static reg_errcode_t
 analyze (regex_t *preg)
 {
-  re_dfa_t *dfa = (re_dfa_t *) preg->buffer;
+  re_dfa_t *dfa = (re_dfa_t *) preg->re_buffer;
   reg_errcode_t ret;
 
   /* Allocate arrays.  */
@@ -1120,7 +1122,7 @@ analyze (regex_t *preg)
 
   /* We only need this during the prune_impossible_nodes pass in regexec.c;
      skip it if p_i_n will not run, as calc_inveclosure can be quadratic.  */
-  if ((!preg->no_sub && preg->re_nsub > 0 && dfa->has_plural_match)
+  if ((!preg->re_no_sub && preg->re_nsub > 0 && dfa->has_plural_match)
       || dfa->nbackref)
     {
       dfa->inveclosures = re_malloc (re_node_set, dfa->nodes_len);
@@ -1256,11 +1258,11 @@ lower_subexps (void *extra, bin_tree_t *node)
 static bin_tree_t *
 lower_subexp (reg_errcode_t *err, regex_t *preg, bin_tree_t *node)
 {
-  re_dfa_t *dfa = (re_dfa_t *) preg->buffer;
+  re_dfa_t *dfa = (re_dfa_t *) preg->re_buffer;
   bin_tree_t *body = node->left;
   bin_tree_t *op, *cls, *tree1, *tree;
 
-  if (preg->no_sub
+  if (preg->re_no_sub
       /* We do not optimize empty subexpressions, because otherwise we may
         have bad CONCAT nodes with NULL children.  This is obviously not
         very common, so we do not lose much.  An example that triggers
@@ -1744,97 +1746,97 @@ peek_token (re_token_t *token, re_string_t *input, reg_syntax_t syntax)
       switch (c2)
        {
        case '|':
-         if (!(syntax & RE_LIMITED_OPS) && !(syntax & RE_NO_BK_VBAR))
+         if (!(syntax & REG_LIMITED_OPS) && !(syntax & REG_NO_BK_VBAR))
            token->type = OP_ALT;
          break;
        case '1': case '2': case '3': case '4': case '5':
        case '6': case '7': case '8': case '9':
-         if (!(syntax & RE_NO_BK_REFS))
+         if (!(syntax & REG_NO_BK_REFS))
            {
              token->type = OP_BACK_REF;
              token->opr.idx = c2 - '1';
            }
          break;
        case '<':
-         if (!(syntax & RE_NO_GNU_OPS))
+         if (!(syntax & REG_NO_GNU_OPS))
            {
              token->type = ANCHOR;
              token->opr.ctx_type = WORD_FIRST;
            }
          break;
        case '>':
-         if (!(syntax & RE_NO_GNU_OPS))
+         if (!(syntax & REG_NO_GNU_OPS))
            {
              token->type = ANCHOR;
              token->opr.ctx_type = WORD_LAST;
            }
          break;
        case 'b':
-         if (!(syntax & RE_NO_GNU_OPS))
+         if (!(syntax & REG_NO_GNU_OPS))
            {
              token->type = ANCHOR;
              token->opr.ctx_type = WORD_DELIM;
            }
          break;
        case 'B':
-         if (!(syntax & RE_NO_GNU_OPS))
+         if (!(syntax & REG_NO_GNU_OPS))
            {
              token->type = ANCHOR;
              token->opr.ctx_type = NOT_WORD_DELIM;
            }
          break;
        case 'w':
-         if (!(syntax & RE_NO_GNU_OPS))
+         if (!(syntax & REG_NO_GNU_OPS))
            token->type = OP_WORD;
          break;
        case 'W':
-         if (!(syntax & RE_NO_GNU_OPS))
+         if (!(syntax & REG_NO_GNU_OPS))
            token->type = OP_NOTWORD;
          break;
        case 's':
-         if (!(syntax & RE_NO_GNU_OPS))
+         if (!(syntax & REG_NO_GNU_OPS))
            token->type = OP_SPACE;
          break;
        case 'S':
-         if (!(syntax & RE_NO_GNU_OPS))
+         if (!(syntax & REG_NO_GNU_OPS))
            token->type = OP_NOTSPACE;
          break;
        case '`':
-         if (!(syntax & RE_NO_GNU_OPS))
+         if (!(syntax & REG_NO_GNU_OPS))
            {
              token->type = ANCHOR;
              token->opr.ctx_type = BUF_FIRST;
            }
          break;
        case '\'':
-         if (!(syntax & RE_NO_GNU_OPS))
+         if (!(syntax & REG_NO_GNU_OPS))
            {
              token->type = ANCHOR;
              token->opr.ctx_type = BUF_LAST;
            }
          break;
        case '(':
-         if (!(syntax & RE_NO_BK_PARENS))
+         if (!(syntax & REG_NO_BK_PARENS))
            token->type = OP_OPEN_SUBEXP;
          break;
        case ')':
-         if (!(syntax & RE_NO_BK_PARENS))
+         if (!(syntax & REG_NO_BK_PARENS))
            token->type = OP_CLOSE_SUBEXP;
          break;
        case '+':
-         if (!(syntax & RE_LIMITED_OPS) && (syntax & RE_BK_PLUS_QM))
+         if (!(syntax & REG_LIMITED_OPS) && (syntax & REG_BK_PLUS_QM))
            token->type = OP_DUP_PLUS;
          break;
        case '?':
-         if (!(syntax & RE_LIMITED_OPS) && (syntax & RE_BK_PLUS_QM))
+         if (!(syntax & REG_LIMITED_OPS) && (syntax & REG_BK_PLUS_QM))
            token->type = OP_DUP_QUESTION;
          break;
        case '{':
-         if ((syntax & RE_INTERVALS) && (!(syntax & RE_NO_BK_BRACES)))
+         if ((syntax & REG_INTERVALS) && (!(syntax & REG_NO_BK_BRACES)))
            token->type = OP_OPEN_DUP_NUM;
          break;
        case '}':
-         if ((syntax & RE_INTERVALS) && (!(syntax & RE_NO_BK_BRACES)))
+         if ((syntax & REG_INTERVALS) && (!(syntax & REG_NO_BK_BRACES)))
            token->type = OP_CLOSE_DUP_NUM;
          break;
        default:
@@ -1857,38 +1859,38 @@ peek_token (re_token_t *token, re_string_t *input, reg_syntax_t syntax)
   switch (c)
     {
     case '\n':
-      if (syntax & RE_NEWLINE_ALT)
+      if (syntax & REG_NEWLINE_ALT)
        token->type = OP_ALT;
       break;
     case '|':
-      if (!(syntax & RE_LIMITED_OPS) && (syntax & RE_NO_BK_VBAR))
+      if (!(syntax & REG_LIMITED_OPS) && (syntax & REG_NO_BK_VBAR))
        token->type = OP_ALT;
       break;
     case '*':
       token->type = OP_DUP_ASTERISK;
       break;
     case '+':
-      if (!(syntax & RE_LIMITED_OPS) && !(syntax & RE_BK_PLUS_QM))
+      if (!(syntax & REG_LIMITED_OPS) && !(syntax & REG_BK_PLUS_QM))
        token->type = OP_DUP_PLUS;
       break;
     case '?':
-      if (!(syntax & RE_LIMITED_OPS) && !(syntax & RE_BK_PLUS_QM))
+      if (!(syntax & REG_LIMITED_OPS) && !(syntax & REG_BK_PLUS_QM))
        token->type = OP_DUP_QUESTION;
       break;
     case '{':
-      if ((syntax & RE_INTERVALS) && (syntax & RE_NO_BK_BRACES))
+      if ((syntax & REG_INTERVALS) && (syntax & REG_NO_BK_BRACES))
        token->type = OP_OPEN_DUP_NUM;
       break;
     case '}':
-      if ((syntax & RE_INTERVALS) && (syntax & RE_NO_BK_BRACES))
+      if ((syntax & REG_INTERVALS) && (syntax & REG_NO_BK_BRACES))
        token->type = OP_CLOSE_DUP_NUM;
       break;
     case '(':
-      if (syntax & RE_NO_BK_PARENS)
+      if (syntax & REG_NO_BK_PARENS)
        token->type = OP_OPEN_SUBEXP;
       break;
     case ')':
-      if (syntax & RE_NO_BK_PARENS)
+      if (syntax & REG_NO_BK_PARENS)
        token->type = OP_CLOSE_SUBEXP;
       break;
     case '[':
@@ -1898,18 +1900,18 @@ peek_token (re_token_t *token, re_string_t *input, reg_syntax_t syntax)
       token->type = OP_PERIOD;
       break;
     case '^':
-      if (!(syntax & (RE_CONTEXT_INDEP_ANCHORS | RE_CARET_ANCHORS_HERE)) &&
+      if (!(syntax & (REG_CONTEXT_INDEP_ANCHORS | REG_CARET_ANCHORS_HERE)) &&
          re_string_cur_idx (input) != 0)
        {
          char prev = re_string_peek_byte (input, -1);
-         if (!(syntax & RE_NEWLINE_ALT) || prev != '\n')
+         if (!(syntax & REG_NEWLINE_ALT) || prev != '\n')
            break;
        }
       token->type = ANCHOR;
       token->opr.ctx_type = LINE_FIRST;
       break;
     case '$':
-      if (!(syntax & RE_CONTEXT_INDEP_ANCHORS) &&
+      if (!(syntax & REG_CONTEXT_INDEP_ANCHORS) &&
          re_string_cur_idx (input) + 1 != re_string_length (input))
        {
          re_token_t next;
@@ -1952,7 +1954,7 @@ peek_token_bracket (re_token_t *token, re_string_t *input, reg_syntax_t syntax)
     }
 #endif /* RE_ENABLE_I18N */
 
-  if (c == '\\' && (syntax & RE_BACKSLASH_ESCAPE_IN_LISTS)
+  if (c == '\\' && (syntax & REG_BACKSLASH_ESCAPE_IN_LISTS)
       && re_string_cur_idx (input) + 1 < re_string_length (input))
     {
       /* In this case, '\' escape a character.  */
@@ -1982,7 +1984,7 @@ peek_token_bracket (re_token_t *token, re_string_t *input, reg_syntax_t syntax)
          token->type = OP_OPEN_EQUIV_CLASS;
          break;
        case ':':
-         if (syntax & RE_CHAR_CLASSES)
+         if (syntax & REG_CHAR_CLASSES)
            {
              token->type = OP_OPEN_CHAR_CLASS;
              break;
@@ -2031,11 +2033,11 @@ static bin_tree_t *
 parse (re_string_t *regexp, regex_t *preg, reg_syntax_t syntax,
        reg_errcode_t *err)
 {
-  re_dfa_t *dfa = (re_dfa_t *) preg->buffer;
+  re_dfa_t *dfa = (re_dfa_t *) preg->re_buffer;
   bin_tree_t *tree, *eor, *root;
   re_token_t current_token;
   dfa->syntax = syntax;
-  fetch_token (&current_token, regexp, syntax | RE_CARET_ANCHORS_HERE);
+  fetch_token (&current_token, regexp, syntax | REG_CARET_ANCHORS_HERE);
   tree = parse_reg_exp (regexp, preg, &current_token, syntax, 0, err);
   if (BE (*err != REG_NOERROR && tree == NULL, 0))
     return NULL;
@@ -2065,7 +2067,7 @@ static bin_tree_t *
 parse_reg_exp (re_string_t *regexp, regex_t *preg, re_token_t *token,
               reg_syntax_t syntax, int nest, reg_errcode_t *err)
 {
-  re_dfa_t *dfa = (re_dfa_t *) preg->buffer;
+  re_dfa_t *dfa = (re_dfa_t *) preg->re_buffer;
   bin_tree_t *tree, *branch = NULL;
   tree = parse_branch (regexp, preg, token, syntax, nest, err);
   if (BE (*err != REG_NOERROR && tree == NULL, 0))
@@ -2073,7 +2075,7 @@ parse_reg_exp (re_string_t *regexp, regex_t *preg, re_token_t *token,
 
   while (token->type == OP_ALT)
     {
-      fetch_token (token, regexp, syntax | RE_CARET_ANCHORS_HERE);
+      fetch_token (token, regexp, syntax | REG_CARET_ANCHORS_HERE);
       if (token->type != OP_ALT && token->type != END_OF_RE
          && (nest == 0 || token->type != OP_CLOSE_SUBEXP))
        {
@@ -2107,7 +2109,7 @@ parse_branch (re_string_t *regexp, regex_t *preg, re_token_t *token,
              reg_syntax_t syntax, int nest, reg_errcode_t *err)
 {
   bin_tree_t *tree, *exp;
-  re_dfa_t *dfa = (re_dfa_t *) preg->buffer;
+  re_dfa_t *dfa = (re_dfa_t *) preg->re_buffer;
   tree = parse_expression (regexp, preg, token, syntax, nest, err);
   if (BE (*err != REG_NOERROR && tree == NULL, 0))
     return NULL;
@@ -2146,7 +2148,7 @@ static bin_tree_t *
 parse_expression (re_string_t *regexp, regex_t *preg, re_token_t *token,
                  reg_syntax_t syntax, int nest, reg_errcode_t *err)
 {
-  re_dfa_t *dfa = (re_dfa_t *) preg->buffer;
+  re_dfa_t *dfa = (re_dfa_t *) preg->re_buffer;
   bin_tree_t *tree;
   switch (token->type)
     {
@@ -2203,7 +2205,7 @@ parse_expression (re_string_t *regexp, regex_t *preg, re_token_t *token,
       dfa->has_mb_node = 1;
       break;
     case OP_OPEN_DUP_NUM:
-      if (syntax & RE_CONTEXT_INVALID_DUP)
+      if (syntax & REG_CONTEXT_INVALID_DUP)
        {
          *err = REG_BADRPT;
          return NULL;
@@ -2212,12 +2214,12 @@ parse_expression (re_string_t *regexp, regex_t *preg, re_token_t *token,
     case OP_DUP_ASTERISK:
     case OP_DUP_PLUS:
     case OP_DUP_QUESTION:
-      if (syntax & RE_CONTEXT_INVALID_OPS)
+      if (syntax & REG_CONTEXT_INVALID_OPS)
        {
          *err = REG_BADRPT;
          return NULL;
        }
-      else if (syntax & RE_CONTEXT_INDEP_OPS)
+      else if (syntax & REG_CONTEXT_INDEP_OPS)
        {
          fetch_token (token, regexp, syntax);
          return parse_expression (regexp, preg, token, syntax, nest, err);
@@ -2225,7 +2227,7 @@ parse_expression (re_string_t *regexp, regex_t *preg, re_token_t *token,
       /* else fall through  */
     case OP_CLOSE_SUBEXP:
       if ((token->type == OP_CLOSE_SUBEXP) &&
-         !(syntax & RE_UNMATCHED_RIGHT_PAREN_ORD))
+         !(syntax & REG_UNMATCHED_RIGHT_PAREN_ORD))
        {
          *err = REG_ERPAREN;
          return NULL;
@@ -2339,7 +2341,7 @@ parse_expression (re_string_t *regexp, regex_t *preg, re_token_t *token,
       if (BE (*err != REG_NOERROR && tree == NULL, 0))
        return NULL;
       /* In BRE consecutive duplications are not allowed.  */
-      if ((syntax & RE_CONTEXT_INVALID_DUP)
+      if ((syntax & REG_CONTEXT_INVALID_DUP)
          && (token->type == OP_DUP_ASTERISK
              || token->type == OP_OPEN_DUP_NUM))
        {
@@ -2362,12 +2364,12 @@ static bin_tree_t *
 parse_sub_exp (re_string_t *regexp, regex_t *preg, re_token_t *token,
               reg_syntax_t syntax, int nest, reg_errcode_t *err)
 {
-  re_dfa_t *dfa = (re_dfa_t *) preg->buffer;
+  re_dfa_t *dfa = (re_dfa_t *) preg->re_buffer;
   bin_tree_t *tree;
   size_t cur_nsub;
   cur_nsub = preg->re_nsub++;
 
-  fetch_token (token, regexp, syntax | RE_CARET_ANCHORS_HERE);
+  fetch_token (token, regexp, syntax | REG_CARET_ANCHORS_HERE);
 
   /* The subexpression may be a null string.  */
   if (token->type == OP_CLOSE_SUBEXP)
@@ -2426,7 +2428,7 @@ parse_dup_op (bin_tree_t *elem, re_string_t *regexp, re_dfa_t *dfa,
       if (BE (start == -2 || end == -2, 0))
        {
          /* Invalid sequence.  */
-         if (BE (!(syntax & RE_INVALID_INTERVAL_ORD), 0))
+         if (BE (!(syntax & REG_INVALID_INTERVAL_ORD), 0))
            {
              if (token->type == END_OF_RE)
                *err = REG_EBRACE;
@@ -2813,7 +2815,7 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
       /* Check start/end collation sequence values.  */
       if (BE (start_collseq == UINT_MAX || end_collseq == UINT_MAX, 0))
        return REG_ECOLLATE;
-      if (BE ((syntax & RE_NO_EMPTY_RANGES) && start_collseq > end_collseq, 0))
+      if (BE ((syntax & REG_NO_EMPTY_RANGES) && start_collseq > end_collseq, 0))
        return REG_ERANGE;
 
       /* Got valid collation sequence values, add them as a new entry.
@@ -2962,9 +2964,9 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
                                                   _NL_COLLATE_SYMB_EXTRAMB);
     }
 #endif
-  sbcset = (re_bitset_ptr_t) calloc (sizeof (unsigned int), BITSET_UINTS);
+  sbcset = re_calloc (unsigned int, BITSET_UINTS);
 #ifdef RE_ENABLE_I18N
-  mbcset = (re_charset_t *) calloc (sizeof (re_charset_t), 1);
+  mbcset = re_calloc (re_charset_t, 1);
 #endif /* RE_ENABLE_I18N */
 #ifdef RE_ENABLE_I18N
   if (BE (sbcset == NULL || mbcset == NULL, 0))
@@ -2988,7 +2990,7 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
       mbcset->non_match = 1;
 #endif /* not RE_ENABLE_I18N */
       non_match = 1;
-      if (syntax & RE_HAT_LISTS_NOT_NEWLINE)
+      if (syntax & REG_HAT_LISTS_NOT_NEWLINE)
        bitset_set (sbcset, '\0');
       re_string_skip_bytes (regexp, token_len); /* Skip a token.  */
       token_len = peek_token_bracket (token, regexp, syntax);
@@ -3403,7 +3405,7 @@ build_equiv_class (re_bitset_ptr_t sbcset,
      is a pointer argument sinse we may update it.  */
 
 static reg_errcode_t
-build_charclass (unsigned RE_TRANSLATE_TYPE trans, re_bitset_ptr_t sbcset,
+build_charclass (unsigned REG_TRANSLATE_TYPE trans, re_bitset_ptr_t sbcset,
 #ifdef RE_ENABLE_I18N
                 re_charset_t *mbcset, int *char_class_alloc,
 #endif
@@ -3414,7 +3416,7 @@ build_charclass (unsigned RE_TRANSLATE_TYPE trans, re_bitset_ptr_t sbcset,
 
   /* In case of REG_ICASE "upper" and "lower" match the both of
      upper and lower cases.  */
-  if ((syntax & RE_ICASE)
+  if ((syntax & REG_IGNORE_CASE)
       && (strcmp (name, "upper") == 0 || strcmp (name, "lower") == 0))
     name = "alpha";
 
@@ -3477,7 +3479,7 @@ build_charclass (unsigned RE_TRANSLATE_TYPE trans, re_bitset_ptr_t sbcset,
 }
 
 static bin_tree_t *
-build_charclass_op (re_dfa_t *dfa, unsigned RE_TRANSLATE_TYPE trans,
+build_charclass_op (re_dfa_t *dfa, unsigned REG_TRANSLATE_TYPE trans,
                    const unsigned char *class_name,
                    const unsigned char *extra,
                    int non_match, reg_errcode_t *err)
@@ -3491,9 +3493,9 @@ build_charclass_op (re_dfa_t *dfa, unsigned RE_TRANSLATE_TYPE trans,
   re_token_t br_token;
   bin_tree_t *tree;
 
-  sbcset = (re_bitset_ptr_t) calloc (sizeof (unsigned int), BITSET_UINTS);
+  sbcset = re_calloc (unsigned int, BITSET_UINTS);
 #ifdef RE_ENABLE_I18N
-  mbcset = (re_charset_t *) calloc (sizeof (re_charset_t), 1);
+  mbcset = re_calloc (re_charset_t, 1);
 #endif /* RE_ENABLE_I18N */
 
 #ifdef RE_ENABLE_I18N
@@ -3510,7 +3512,7 @@ build_charclass_op (re_dfa_t *dfa, unsigned RE_TRANSLATE_TYPE trans,
     {
 #ifdef RE_ENABLE_I18N
       /*
-      if (syntax & RE_HAT_LISTS_NOT_NEWLINE)
+      if (syntax & REG_HAT_LISTS_NOT_NEWLINE)
        bitset_set(cset->sbcset, '\0');
       */
       mbcset->non_match = 1;
@@ -3608,7 +3610,7 @@ fetch_number (re_string_t *input, re_token_t *token, reg_syntax_t syntax)
        break;
       num = ((token->type != CHARACTER || c < '0' || '9' < c || num == -2)
             ? -2 : ((num == -1) ? c - '0' : num * 10 + c - '0'));
-      num = (num > RE_DUP_MAX) ? -2 : num;
+      num = (num > REG_DUP_MAX) ? -2 : num;
     }
   return num;
 }