]> code.delx.au - gnu-emacs/blobdiff - src/regex.c
* editfns.c, systime.h (mktime_z) [!HAVE_TZALLOC]: Now static.
[gnu-emacs] / src / regex.c
index 9e9018bff88eb457537f06f013e4ae11f1012345..1afc5037594096ad0b1b8cdcda7158fb1dc48afe 100644 (file)
@@ -2,7 +2,7 @@
    0.12.  (Implements POSIX draft P1003.2/D11.2, except for some of the
    internationalization features.)
 
-   Copyright (C) 1993-2014 Free Software Foundation, Inc.
+   Copyright (C) 1993-2015 Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -324,12 +324,12 @@ enum syntaxcode { Swhitespace = 0, Sword = 1, Ssymbol = 2 };
                    ? (((c) >= 'a' && (c) <= 'z')       \
                       || ((c) >= 'A' && (c) <= 'Z')    \
                       || ((c) >= '0' && (c) <= '9'))   \
-                   : SYNTAX (c) == Sword)
+                   : (alphabeticp (c) || decimalnump (c)))
 
 # define ISALPHA(c) (IS_REAL_ASCII (c)                 \
                    ? (((c) >= 'a' && (c) <= 'z')       \
                       || ((c) >= 'A' && (c) <= 'Z'))   \
-                   : SYNTAX (c) == Sword)
+                   : alphabeticp (c))
 
 # define ISLOWER(c) lowercasep (c)
 
@@ -515,10 +515,12 @@ init_syntax_once (void)
 
 #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))
+#ifndef emacs
+# undef max
+# undef min
+# define max(a, b) ((a) > (b) ? (a) : (b))
+# define min(a, b) ((a) < (b) ? (a) : (b))
+#endif
 
 /* Type of source-pattern and string chars.  */
 #ifdef _MSC_VER
@@ -1394,14 +1396,14 @@ typedef struct
    : ((fail_stack).stack                                               \
       = REGEX_REALLOCATE_STACK ((fail_stack).stack,                    \
          (fail_stack).size * sizeof (fail_stack_elt_t),                \
-         MIN (re_max_failures * TYPICAL_FAILURE_SIZE,                  \
+         min (re_max_failures * TYPICAL_FAILURE_SIZE,                  \
               ((fail_stack).size * sizeof (fail_stack_elt_t)           \
                * FAIL_STACK_GROWTH_FACTOR))),                          \
                                                                        \
       (fail_stack).stack == NULL                                       \
       ? 0                                                              \
       : ((fail_stack).size                                             \
-        = (MIN (re_max_failures * TYPICAL_FAILURE_SIZE,                \
+        = (min (re_max_failures * TYPICAL_FAILURE_SIZE,                \
                 ((fail_stack).size * sizeof (fail_stack_elt_t)         \
                  * FAIL_STACK_GROWTH_FACTOR))                          \
            / sizeof (fail_stack_elt_t)),                               \
@@ -1630,7 +1632,7 @@ static boolean at_begline_loc_p (re_char *pattern, re_char *p,
 static boolean at_endline_loc_p (re_char *p, re_char *pend,
                                 reg_syntax_t syntax);
 static re_char *skip_one_char (re_char *p);
-static int analyse_first (re_char *p, re_char *pend,
+static int analyze_first (re_char *p, re_char *pend,
                          char *fastmap, const int multibyte);
 
 /* Fetch the next character in the uncompiled pattern, with no
@@ -1870,6 +1872,8 @@ struct range_table_work_area
 #define BIT_SPACE      0x8
 #define BIT_UPPER      0x10
 #define BIT_MULTIBYTE  0x20
+#define BIT_ALPHA      0x40
+#define BIT_ALNUM      0x80
 \f
 
 /* Set the bit for character C in a list.  */
@@ -2070,7 +2074,9 @@ re_wctype_to_bit (re_wctype_t cc)
     {
     case RECC_NONASCII: case RECC_PRINT: case RECC_GRAPH:
     case RECC_MULTIBYTE: return BIT_MULTIBYTE;
-    case RECC_ALPHA: case RECC_ALNUM: case RECC_WORD: return BIT_WORD;
+    case RECC_ALPHA: return BIT_ALPHA;
+    case RECC_ALNUM: return BIT_ALNUM;
+    case RECC_WORD: return BIT_WORD;
     case RECC_LOWER: return BIT_LOWER;
     case RECC_UPPER: return BIT_UPPER;
     case RECC_PUNCT: return BIT_PUNCT;
@@ -2309,8 +2315,8 @@ set_image_of_range (struct range_table_work_area *work_area,
                cmin = c, cmax = c;
              else
                {
-                 cmin = MIN (cmin, c);
-                 cmax = MAX (cmax, c);
+                 cmin = min (cmin, c);
+                 cmax = max (cmax, c);
                }
            }
        }
@@ -2686,7 +2692,7 @@ regex_compile (const_re_char *pattern, size_t size, reg_syntax_t syntax,
                    size_t startoffset = 0;
                    re_opcode_t ofj =
                      /* Check if the loop can match the empty string.  */
-                     (simple || !analyse_first (laststart, b, NULL, 0))
+                     (simple || !analyze_first (laststart, b, NULL, 0))
                      ? on_failure_jump : on_failure_jump_loop;
                    assert (skip_one_char (laststart) <= b);
 
@@ -2733,7 +2739,7 @@ regex_compile (const_re_char *pattern, size_t size, reg_syntax_t syntax,
                GET_BUFFER_SPACE (7); /* We might use less.  */
                if (many_times_ok)
                  {
-                   boolean emptyp = analyse_first (laststart, b, NULL, 0);
+                   boolean emptyp = analyze_first (laststart, b, NULL, 0);
 
                    /* The non-greedy multiple match looks like
                       a repeat..until: we only need a conditional jump
@@ -2928,7 +2934,7 @@ regex_compile (const_re_char *pattern, size_t size, reg_syntax_t syntax,
 #endif /* emacs */
                        /* In most cases the matching rule for char classes
                           only uses the syntax table for multibyte chars,
-                          so that the content of the syntax-table it is not
+                          so that the content of the syntax-table is not
                           hardcoded in the range_table.  SPACE and WORD are
                           the two exceptions.  */
                        if ((1 << cc) & ((1 << RECC_SPACE) | (1 << RECC_WORD)))
@@ -2943,7 +2949,7 @@ regex_compile (const_re_char *pattern, size_t size, reg_syntax_t syntax,
                        p = class_beg;
                        SET_LIST_BIT ('[');
 
-                       /* Because the `:' may starts the range, we
+                       /* Because the `:' may start the range, we
                           can't simply set bit and repeat the loop.
                           Instead, just set it to C and handle below.  */
                        c = ':';
@@ -2989,7 +2995,7 @@ regex_compile (const_re_char *pattern, size_t size, reg_syntax_t syntax,
 #else  /* emacs */
                    if (c < 128)
                      {
-                       ch = MIN (127, c1);
+                       ch = min (127, c1);
                        SETUP_ASCII_RANGE (range_table_work, c, ch);
                        c = ch + 1;
                        if (CHAR_BYTE8_P (c1))
@@ -3834,7 +3840,7 @@ group_in_compile_stack (compile_stack_type compile_stack, regnum_t regnum)
   return false;
 }
 \f
-/* analyse_first.
+/* analyze_first.
    If fastmap is non-NULL, go through the pattern and fill fastmap
    with all the possible leading chars.  If fastmap is NULL, don't
    bother filling it up (obviously) and only return whether the
@@ -3845,7 +3851,7 @@ group_in_compile_stack (compile_stack_type compile_stack, regnum_t regnum)
    Return -1 if fastmap was not updated accurately.  */
 
 static int
-analyse_first (const_re_char *p, const_re_char *pend, char *fastmap,
+analyze_first (const_re_char *p, const_re_char *pend, char *fastmap,
               const int multibyte)
 {
   int j, k;
@@ -4087,7 +4093,7 @@ analyse_first (const_re_char *p, const_re_char *pend, char *fastmap,
            { /* We have to look down both arms.
                 We first go down the "straight" path so as to minimize
                 stack usage when going through alternatives.  */
-             int r = analyse_first (p, pend, fastmap, multibyte);
+             int r = analyze_first (p, pend, fastmap, multibyte);
              if (r) return r;
              p += j;
            }
@@ -4137,7 +4143,7 @@ analyse_first (const_re_char *p, const_re_char *pend, char *fastmap,
   /* We reached the end without matching anything.  */
   return 1;
 
-} /* analyse_first */
+} /* analyze_first */
 \f
 /* re_compile_fastmap computes a ``fastmap'' for the compiled pattern in
    BUFP.  A fastmap records which of the (1 << BYTEWIDTH) possible
@@ -4167,7 +4173,7 @@ re_compile_fastmap (struct re_pattern_buffer *bufp)
   memset (fastmap, 0, 1 << BYTEWIDTH);  /* Assume nothing's valid.  */
   bufp->fastmap_accurate = 1;      /* It will be when we're done.  */
 
-  analysis = analyse_first (bufp->buffer, bufp->buffer + bufp->used,
+  analysis = analyze_first (bufp->buffer, bufp->buffer + bufp->used,
                            fastmap, RE_MULTIBYTE_P (bufp));
   bufp->can_be_null = (analysis != 0);
   return 0;
@@ -5210,7 +5216,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const_re_char *string1,
                { /* No.  So allocate them with malloc.  We need one
                     extra element beyond `num_regs' for the `-1' marker
                     GNU code uses.  */
-                 regs->num_regs = MAX (RE_NREGS, num_regs + 1);
+                 regs->num_regs = max (RE_NREGS, num_regs + 1);
                  regs->start = TALLOC (regs->num_regs, regoff_t);
                  regs->end = TALLOC (regs->num_regs, regoff_t);
                  if (regs->start == NULL || regs->end == NULL)
@@ -5254,7 +5260,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const_re_char *string1,
 
              /* Go through the first `min (num_regs, regs->num_regs)'
                 registers, since that is all we initialized.  */
-             for (reg = 1; reg < MIN (num_regs, regs->num_regs); reg++)
+             for (reg = 1; reg < min (num_regs, regs->num_regs); reg++)
                {
                  if (REG_UNSET (regstart[reg]) || REG_UNSET (regend[reg]))
                    regs->start[reg] = regs->end[reg] = -1;
@@ -5511,7 +5517,9 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const_re_char *string1,
                    | (class_bits & BIT_PUNCT && ISPUNCT (c))
                    | (class_bits & BIT_SPACE && ISSPACE (c))
                    | (class_bits & BIT_UPPER && ISUPPER (c))
-                   | (class_bits & BIT_WORD  && ISWORD (c)))
+                   | (class_bits & BIT_WORD  && ISWORD  (c))
+                   | (class_bits & BIT_ALPHA && ISALPHA (c))
+                   | (class_bits & BIT_ALNUM && ISALNUM (c)))
                  not = !not;
                else
                  CHARSET_LOOKUP_RANGE_TABLE_RAW (not, c, range_table, count);