]> code.delx.au - gnu-emacs/blobdiff - src/regex.c
* test/lisp/help-fns-tests.el: Add several tests for 'describe-function'.
[gnu-emacs] / src / regex.c
index dd3f2b3cd67d3cf203f79cc7888cacd4e956cef5..f92bcb7923b3dbbb7440cd70d56fca85d39032c2 100644 (file)
@@ -215,7 +215,7 @@ xmalloc (size_t size)
   void *val = malloc (size);
   if (!val && size)
     {
-      write (2, "virtual memory exhausted\n", 25);
+      write (STDERR_FILENO, "virtual memory exhausted\n", 25);
       exit (1);
     }
   return val;
@@ -233,7 +233,7 @@ xrealloc (void *block, size_t size)
     val = realloc (block, size);
   if (!val && size)
     {
-      write (2, "virtual memory exhausted\n", 25);
+      write (STDERR_FILENO, "virtual memory exhausted\n", 25);
       exit (1);
     }
   return val;
@@ -1197,13 +1197,6 @@ print_double_string (re_char *where, re_char *string1, ssize_t size1,
 
 #endif /* not DEBUG */
 \f
-/* Use this to suppress gcc's `...may be used before initialized' warnings. */
-#ifdef lint
-# define IF_LINT(Code) Code
-#else
-# define IF_LINT(Code) /* empty */
-#endif
-\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
    syntax, so it can be changed between regex compilations.  */
@@ -2472,9 +2465,9 @@ regex_compile (const_re_char *pattern, size_t size, reg_syntax_t syntax,
 
   /* These hold the values of p, pattern, and pend from the main
      pattern when we have pushed into a subpattern.  */
-  re_char *main_p IF_LINT (= NULL);
-  re_char *main_pattern IF_LINT (= NULL);
-  re_char *main_pend IF_LINT (= NULL);
+  re_char *main_p;
+  re_char *main_pattern;
+  re_char *main_pend;
 
 #ifdef DEBUG
   debug++;
@@ -5140,8 +5133,6 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const_re_char *string1,
 
       if (p == pend)
        {
-         ptrdiff_t dcnt;
-
          /* End of pattern means we might have succeeded.  */
          DEBUG_PRINT ("end of pattern ... ");
 
@@ -5149,19 +5140,22 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const_re_char *string1,
             longest match, try backtracking.  */
          if (d != end_match_2)
            {
-             /* 1 if this match ends in the same string (string1 or string2)
-                as the best previous match.  */
-             boolean same_str_p = (FIRST_STRING_P (match_end)
-                                   == FIRST_STRING_P (d));
-             /* 1 if this match is the best seen so far.  */
-             boolean best_match_p;
-
-             /* AIX compiler got confused when this was combined
-                with the previous declaration.  */
-             if (same_str_p)
-               best_match_p = d > match_end;
-             else
-               best_match_p = !FIRST_STRING_P (d);
+             /* True if this match is the best seen so far.  */
+             bool best_match_p;
+
+             {
+               /* True if this match ends in the same string (string1
+                  or string2) as the best previous match.  */
+               bool same_str_p = (FIRST_STRING_P (match_end)
+                                  == FIRST_STRING_P (d));
+
+               /* AIX compiler got confused when this was combined
+                  with the previous declaration.  */
+               if (same_str_p)
+                 best_match_p = d > match_end;
+               else
+                 best_match_p = !FIRST_STRING_P (d);
+             }
 
              DEBUG_PRINT ("backtracking.\n");
 
@@ -5290,7 +5284,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const_re_char *string1,
                       nfailure_points_pushed - nfailure_points_popped);
          DEBUG_PRINT ("%u registers pushed.\n", num_regs_pushed);
 
-         dcnt = POINTER_TO_OFFSET (d) - pos;
+         ptrdiff_t dcnt = POINTER_TO_OFFSET (d) - pos;
 
          DEBUG_PRINT ("Returning %td from re_match_2.\n", dcnt);
 
@@ -5444,13 +5438,13 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const_re_char *string1,
        case charset:
        case charset_not:
          {
-           register unsigned int c;
+           register unsigned int c, corig;
            boolean not = (re_opcode_t) *(p - 1) == charset_not;
            int len;
 
            /* Start of actual range_table, or end of bitmap if there is no
               range table.  */
-           re_char *range_table IF_LINT (= NULL);
+           re_char *range_table UNINIT;
 
            /* Nonzero if there is a range table.  */
            int range_table_exists;
@@ -5473,7 +5467,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const_re_char *string1,
              }
 
            PREFETCH ();
-           c = RE_STRING_CHAR_AND_LENGTH (d, len, target_multibyte);
+           corig = c = RE_STRING_CHAR_AND_LENGTH (d, len, target_multibyte);
            if (target_multibyte)
              {
                int c1;
@@ -5517,11 +5511,17 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const_re_char *string1,
              {
                int class_bits = CHARSET_RANGE_TABLE_BITS (&p[-1]);
 
-               if (  (class_bits & BIT_LOWER && ISLOWER (c))
+               if (  (class_bits & BIT_LOWER
+                      && (ISLOWER (c)
+                          || (corig != c
+                              && c == upcase (corig) && ISUPPER(c))))
                    | (class_bits & BIT_MULTIBYTE)
                    | (class_bits & BIT_PUNCT && ISPUNCT (c))
                    | (class_bits & BIT_SPACE && ISSPACE (c))
-                   | (class_bits & BIT_UPPER && ISUPPER (c))
+                   | (class_bits & BIT_UPPER
+                      && (ISUPPER (c)
+                          || (corig != c
+                              && c == downcase (corig) && ISLOWER (c))))
                    | (class_bits & BIT_WORD  && ISWORD  (c))
                    | (class_bits & BIT_ALPHA && ISALPHA (c))
                    | (class_bits & BIT_ALNUM && ISALNUM (c))