* regex.c (re_match_2_internals): Fix one more "not".
[bpt/emacs.git] / src / regex.c
index b563d93..0187a10 100644 (file)
@@ -2,9 +2,7 @@
    0.12.  (Implements POSIX draft P1003.2/D11.2, except for some of the
    internationalization features.)
 
-   Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
-                 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
-                 Free Software Foundation, Inc.
+   Copyright (C) 1993-2011  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
    even if config.h says that we can.  */
 # undef REL_ALLOC
 
-# if defined STDC_HEADERS || defined _LIBC
-#  include <stdlib.h>
-# else
-char *malloc ();
-char *realloc ();
-# endif
+# include <unistd.h>
 
 /* When used in Emacs's lib-src, we need xmalloc and xrealloc. */
 
 void *
-xmalloc (size)
-     size_t size;
+xmalloc (size_t size)
 {
   register void *val;
   val = (void *) malloc (size);
@@ -220,9 +212,7 @@ xmalloc (size)
 }
 
 void *
-xrealloc (block, size)
-     void *block;
-     size_t size;
+xrealloc (void *block, size_t size)
 {
   register void *val;
   /* We must call malloc explicitly when BLOCK is 0, since some
@@ -435,7 +425,7 @@ extern char *re_syntax_table;
 static char re_syntax_table[CHAR_SET_SIZE];
 
 static void
-init_syntax_once ()
+init_syntax_once (void)
 {
    register int c;
    static int done = 0;
@@ -871,14 +861,14 @@ extract_number_and_incr (destination, source)
   do                                                                   \
     {                                                                  \
       re_wchar_t range_start, range_end;                               \
-      re_char *p;                                                      \
+      re_char *rtp;                                                    \
       re_char *range_table_end                                         \
        = CHARSET_RANGE_TABLE_END ((range_table), (count));             \
                                                                        \
-      for (p = (range_table); p < range_table_end; p += 2 * 3)         \
+      for (rtp = (range_table); rtp < range_table_end; rtp += 2 * 3)   \
        {                                                               \
-         EXTRACT_CHARACTER (range_start, p);                           \
-         EXTRACT_CHARACTER (range_end, p + 3);                         \
+         EXTRACT_CHARACTER (range_start, rtp);                         \
+         EXTRACT_CHARACTER (range_end, rtp + 3);                       \
                                                                        \
          if (range_start <= (c) && (c) <= range_end)                   \
            {                                                           \
@@ -1565,22 +1555,22 @@ do {                                                                    \
 /* Pop a saved register off the stack.  */
 #define POP_FAILURE_REG_OR_COUNT()                                     \
 do {                                                                   \
-  int reg = POP_FAILURE_INT ();                                                \
-  if (reg == -1)                                                       \
+  int pfreg = POP_FAILURE_INT ();                                      \
+  if (pfreg == -1)                                                     \
     {                                                                  \
       /* It's a counter.  */                                           \
       /* Here, we discard `const', making re_match non-reentrant.  */  \
       unsigned char *ptr = (unsigned char*) POP_FAILURE_POINTER ();    \
-      reg = POP_FAILURE_INT ();                                                \
-      STORE_NUMBER (ptr, reg);                                         \
-      DEBUG_PRINT3 ("     Pop counter %p = %d\n", ptr, reg);           \
+      pfreg = POP_FAILURE_INT ();                                      \
+      STORE_NUMBER (ptr, pfreg);                                       \
+      DEBUG_PRINT3 ("     Pop counter %p = %d\n", ptr, pfreg);         \
     }                                                                  \
   else                                                                 \
     {                                                                  \
-      regend[reg] = POP_FAILURE_POINTER ();                            \
-      regstart[reg] = POP_FAILURE_POINTER ();                          \
+      regend[pfreg] = POP_FAILURE_POINTER ();                          \
+      regstart[pfreg] = POP_FAILURE_POINTER ();                                \
       DEBUG_PRINT4 ("     Pop reg %d (spanning %p -> %p)\n",           \
-                   reg, regstart[reg], regend[reg]);                   \
+                   pfreg, regstart[pfreg], regend[pfreg]);             \
     }                                                                  \
 } while (0)
 
@@ -2128,7 +2118,7 @@ struct range_table_work_area
 re_wctype_t
 re_wctype (const re_char *str)
 {
-  const char *string = str;
+  const char *string = (const char *) str;
   if      (STREQ (string, "alnum"))    return RECC_ALNUM;
   else if (STREQ (string, "alpha"))    return RECC_ALPHA;
   else if (STREQ (string, "word"))     return RECC_WORD;
@@ -2534,9 +2524,6 @@ regex_compile (const re_char *pattern, size_t size, reg_syntax_t syntax, struct
   /* We fetch characters from PATTERN here.  */
   register re_wchar_t c, c1;
 
-  /* A random temporary spot in PATTERN.  */
-  re_char *p1;
-
   /* Points to the end of the buffer, where we should append.  */
   register unsigned char *b;
 
@@ -2584,9 +2571,6 @@ regex_compile (const re_char *pattern, size_t size, reg_syntax_t syntax, struct
   /* If the object matched can contain multibyte characters.  */
   const boolean multibyte = RE_MULTIBYTE_P (bufp);
 
-  /* If a target of matching can contain multibyte characters.  */
-  const boolean target_multibyte = RE_TARGET_MULTIBYTE_P (bufp);
-
   /* Nonzero if we have pushed down into a subpattern.  */
   int in_subpattern = 0;
 
@@ -2710,7 +2694,7 @@ regex_compile (const re_char *pattern, size_t size, reg_syntax_t syntax, struct
            main_pend = pend;
            main_pattern = pattern;
            p = pattern = whitespace_regexp;
-           pend = p + strlen (p);
+           pend = p + strlen ((const char *) p);
            break;
          }
 
@@ -2904,6 +2888,8 @@ regex_compile (const re_char *pattern, size_t size, reg_syntax_t syntax, struct
 
        case '[':
          {
+           re_char *p1;
+
            CLEAR_RANGE_TABLE_WORK_USED (range_table_work);
 
            if (p == pend) FREE_STACK_RETURN (REG_EBRACK);
@@ -2939,7 +2925,7 @@ regex_compile (const re_char *pattern, size_t size, reg_syntax_t syntax, struct
              {
                boolean escaped_char = false;
                const unsigned char *p2 = p;
-               re_wchar_t ch, c2;
+               re_wchar_t ch;
 
                if (p == pend) FREE_STACK_RETURN (REG_EBRACK);
 
@@ -3002,10 +2988,7 @@ regex_compile (const re_char *pattern, size_t size, reg_syntax_t syntax, struct
                       them).  */
                    if (c == ':' && *p == ']')
                      {
-                       re_wctype_t cc;
-                       int limit;
-
-                       cc = re_wctype (str);
+                       re_wctype_t cc = re_wctype (str);
 
                        if (cc == 0)
                          FREE_STACK_RETURN (REG_ECTYPE);
@@ -4005,7 +3988,6 @@ analyse_first (const re_char *p, const re_char *pend, char *fastmap, const int m
        {
        case succeed:
          return 1;
-         continue;
 
        case duplicate:
          /* If the first character has to match a backreference, that means
@@ -4089,7 +4071,7 @@ analyse_first (const re_char *p, const re_char *pend, char *fastmap, const int m
                   && match_any_multibyte_characters == false)
            {
              /* Set fastmap[I] to 1 where I is a leading code of each
-                multibyte characer in the range table. */
+                multibyte character in the range table. */
              int c, count;
              unsigned char lc1, lc2;
 
@@ -4570,7 +4552,6 @@ re_search_2 (struct re_pattern_buffer *bufp, const char *str1, int size1, const
          if (multibyte)
            {
              re_char *p = POS_ADDR_VSTRING (startpos);
-             re_char *pend = STOP_ADDR_VSTRING (startpos);
              int len = BYTES_BY_CHAR_HEAD (*p);
 
              range -= len;
@@ -4978,11 +4959,8 @@ mutually_exclusive_p (struct re_pattern_buffer *bufp, const re_char *p1, const r
 /* re_match is like re_match_2 except it takes only a single string.  */
 
 int
-re_match (bufp, string, size, pos, regs)
-     struct re_pattern_buffer *bufp;
-     const char *string;
-     int size, pos;
-     struct re_registers *regs;
+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,
                                    pos, regs, size);
@@ -5038,7 +5016,6 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1, int
   /* General temporaries.  */
   int mcnt;
   size_t reg;
-  boolean not;
 
   /* Just past the end of the corresponding string.  */
   re_char *end1, *end2;
@@ -5478,7 +5455,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1, int
          else
            do
              {
-               int pat_charlen, buf_charlen;
+               int pat_charlen;
                int pat_ch, buf_ch;
 
                PREFETCH ();
@@ -5636,8 +5613,8 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1, int
            if (!not) goto fail;
 
            d += len;
-           break;
          }
+         break;
 
 
        /* The beginning of a group is represented by start_memory.
@@ -6019,46 +5996,48 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1, int
 
        case wordbound:
        case notwordbound:
-         not = (re_opcode_t) *(p - 1) == notwordbound;
-         DEBUG_PRINT2 ("EXECUTING %swordbound.\n", not?"not":"");
+         {
+           boolean not = (re_opcode_t) *(p - 1) == notwordbound;
+           DEBUG_PRINT2 ("EXECUTING %swordbound.\n", not?"not":"");
 
-         /* We SUCCEED (or FAIL) in one of the following cases: */
+           /* We SUCCEED (or FAIL) in one of the following cases: */
 
-         /* Case 1: D is at the beginning or the end of string.  */
-         if (AT_STRINGS_BEG (d) || AT_STRINGS_END (d))
-           not = !not;
-         else
-           {
-             /* C1 is the character before D, S1 is the syntax of C1, C2
-                is the character at D, and S2 is the syntax of C2.  */
-             re_wchar_t c1, c2;
-             int s1, s2;
-             int dummy;
+           /* Case 1: D is at the beginning or the end of string.  */
+           if (AT_STRINGS_BEG (d) || AT_STRINGS_END (d))
+             not = !not;
+           else
+             {
+               /* C1 is the character before D, S1 is the syntax of C1, C2
+                  is the character at D, and S2 is the syntax of C2.  */
+               re_wchar_t c1, c2;
+               int s1, s2;
+               int dummy;
 #ifdef emacs
-             int offset = PTR_TO_OFFSET (d - 1);
-             int charpos = SYNTAX_TABLE_BYTE_TO_CHAR (offset);
-             UPDATE_SYNTAX_TABLE (charpos);
+               int offset = PTR_TO_OFFSET (d - 1);
+               int charpos = SYNTAX_TABLE_BYTE_TO_CHAR (offset);
+               UPDATE_SYNTAX_TABLE (charpos);
 #endif
-             GET_CHAR_BEFORE_2 (c1, d, string1, end1, string2, end2);
-             s1 = SYNTAX (c1);
+               GET_CHAR_BEFORE_2 (c1, d, string1, end1, string2, end2);
+               s1 = SYNTAX (c1);
 #ifdef emacs
-             UPDATE_SYNTAX_TABLE_FORWARD (charpos + 1);
+               UPDATE_SYNTAX_TABLE_FORWARD (charpos + 1);
 #endif
-             PREFETCH_NOLIMIT ();
-             GET_CHAR_AFTER (c2, d, dummy);
-             s2 = SYNTAX (c2);
-
-             if (/* Case 2: Only one of S1 and S2 is Sword.  */
-                 ((s1 == Sword) != (s2 == Sword))
-                 /* Case 3: Both of S1 and S2 are Sword, and macro
-                    WORD_BOUNDARY_P (C1, C2) returns nonzero.  */
-                 || ((s1 == Sword) && WORD_BOUNDARY_P (c1, c2)))
-               not = !not;
-           }
-         if (not)
-           break;
-         else
-           goto fail;
+               PREFETCH_NOLIMIT ();
+               GET_CHAR_AFTER (c2, d, dummy);
+               s2 = SYNTAX (c2);
+
+               if (/* Case 2: Only one of S1 and S2 is Sword.  */
+                   ((s1 == Sword) != (s2 == Sword))
+                   /* Case 3: Both of S1 and S2 are Sword, and macro
+                      WORD_BOUNDARY_P (C1, C2) returns nonzero.  */
+                   || ((s1 == Sword) && WORD_BOUNDARY_P (c1, c2)))
+                 not = !not;
+             }
+           if (not)
+             break;
+           else
+             goto fail;
+         }
 
        case wordbeg:
          DEBUG_PRINT1 ("EXECUTING wordbeg.\n");
@@ -6238,25 +6217,27 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1, int
 
        case syntaxspec:
        case notsyntaxspec:
-         not = (re_opcode_t) *(p - 1) == notsyntaxspec;
-         mcnt = *p++;
-         DEBUG_PRINT3 ("EXECUTING %ssyntaxspec %d.\n", not?"not":"", mcnt);
-         PREFETCH ();
-#ifdef emacs
          {
-           int offset = PTR_TO_OFFSET (d);
-           int pos1 = SYNTAX_TABLE_BYTE_TO_CHAR (offset);
-           UPDATE_SYNTAX_TABLE (pos1);
-         }
+           boolean not = (re_opcode_t) *(p - 1) == notsyntaxspec;
+           mcnt = *p++;
+           DEBUG_PRINT3 ("EXECUTING %ssyntaxspec %d.\n", not?"not":"", mcnt);
+           PREFETCH ();
+#ifdef emacs
+           {
+             int offset = PTR_TO_OFFSET (d);
+             int pos1 = SYNTAX_TABLE_BYTE_TO_CHAR (offset);
+             UPDATE_SYNTAX_TABLE (pos1);
+           }
 #endif
-         {
-           int len;
-           re_wchar_t c;
+           {
+             int len;
+             re_wchar_t c;
 
-           GET_CHAR_AFTER (c, d, len);
-           if ((SYNTAX (c) != (enum syntaxcode) mcnt) ^ not)
-             goto fail;
-           d += len;
+             GET_CHAR_AFTER (c, d, len);
+             if ((SYNTAX (c) != (enum syntaxcode) mcnt) ^ not)
+               goto fail;
+             d += len;
+           }
          }
          break;
 
@@ -6281,18 +6262,21 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1, int
 
        case categoryspec:
        case notcategoryspec:
-         not = (re_opcode_t) *(p - 1) == notcategoryspec;
-         mcnt = *p++;
-         DEBUG_PRINT3 ("EXECUTING %scategoryspec %d.\n", not?"not":"", mcnt);
-         PREFETCH ();
          {
-           int len;
-           re_wchar_t c;
+           boolean not = (re_opcode_t) *(p - 1) == notcategoryspec;
+           mcnt = *p++;
+           DEBUG_PRINT3 ("EXECUTING %scategoryspec %d.\n",
+                         not?"not":"", mcnt);
+           PREFETCH ();
 
-           GET_CHAR_AFTER (c, d, len);
-           if ((!CHAR_HAS_CATEGORY (c, mcnt)) ^ not)
-             goto fail;
-           d += len;
+           {
+             int len;
+             re_wchar_t c;
+             GET_CHAR_AFTER (c, d, len);
+             if ((!CHAR_HAS_CATEGORY (c, mcnt)) ^ not)
+               goto fail;
+             d += len;
+           }
          }
          break;
 
@@ -6534,10 +6518,8 @@ re_exec (s)
    the return codes and their meanings.)  */
 
 int
-regcomp (preg, pattern, cflags)
-    regex_t *__restrict preg;
-    const char *__restrict pattern;
-    int cflags;
+regcomp (regex_t *__restrict preg, const char *__restrict pattern,
+        int cflags)
 {
   reg_errcode_t ret;
   reg_syntax_t syntax
@@ -6619,12 +6601,8 @@ WEAK_ALIAS (__regcomp, regcomp)
    We return 0 if we find a match and REG_NOMATCH if not.  */
 
 int
-regexec (preg, string, nmatch, pmatch, eflags)
-    const regex_t *__restrict preg;
-    const char *__restrict string;
-    size_t nmatch;
-    regmatch_t pmatch[__restrict_arr];
-    int eflags;
+regexec (const regex_t *__restrict preg, const char *__restrict string,
+        size_t nmatch, regmatch_t pmatch[__restrict_arr], int eflags)
 {
   int ret;
   struct re_registers regs;
@@ -6696,11 +6674,7 @@ WEAK_ALIAS (__regexec, regexec)
    error with msvc8 compiler.  */
 
 size_t
-regerror (err_code, preg, errbuf, errbuf_size)
-    int err_code;
-    const regex_t *preg;
-    char *errbuf;
-    size_t errbuf_size;
+regerror (int err_code, const regex_t *preg, char *errbuf, size_t errbuf_size)
 {
   const char *msg;
   size_t msg_size;
@@ -6736,8 +6710,7 @@ WEAK_ALIAS (__regerror, regerror)
 /* Free dynamically allocated space used by PREG.  */
 
 void
-regfree (preg)
-    regex_t *preg;
+regfree (regex_t *preg)
 {
   free (preg->buffer);
   preg->buffer = NULL;
@@ -6755,6 +6728,3 @@ regfree (preg)
 WEAK_ALIAS (__regfree, regfree)
 
 #endif /* not emacs  */
-
-/* arch-tag: 4ffd68ba-2a9e-435b-a21a-018990f9eeb2
-   (do not change this comment) */