]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Code cleanup.
authorBruno Haible <bruno@clisp.org>
Mon, 24 May 2010 09:17:32 +0000 (11:17 +0200)
committerBruno Haible <bruno@clisp.org>
Thu, 3 Jun 2010 13:03:48 +0000 (15:03 +0200)
gettext-tools/libgrep/ChangeLog
gettext-tools/libgrep/m-regex.c

index 0e3951701887b9a37e999cb11fc31e802fd72e6f..7e30fc36d1c149582a3590fb6f98fd9be0e56c2b 100644 (file)
@@ -1,3 +1,9 @@
+2010-05-24  Bruno Haible  <bruno@clisp.org>
+
+       Code cleanup.
+       * m-regex.c (EGexecute): Write logic in a similar way as
+       m-fgrep.c:Fexecute.
+
 2010-05-24  Bruno Haible  <bruno@clisp.org>
 
        Fix bug: Avoid out-of-bounds access.
index e3582bcb42b6af6e4e1fd25238819f42620f467c..d5d3dd14e212e7abeab1f5798e9952790bb3848d 100644 (file)
@@ -179,52 +179,58 @@ EGexecute (const void *compiled_pattern,
                   *match_size = len;
                   return start;
                 }
-              if ((!cregex->match_lines && !cregex->match_words)
-                  || (cregex->match_lines && len == end - beg))
+              if (cregex->match_lines)
+                {
+                  if (len == end - beg) /* implies start == 0 */
+                    goto success;
+                }
+              else if (cregex->match_words)
+                {
+                  /* If -w, check if the match aligns with word boundaries.
+                     We do this iteratively because:
+                     (a) the line may contain more than one occurence of the
+                         pattern, and
+                     (b) Several alternatives in the pattern might be valid at
+                         a given point, and we may need to consider a shorter
+                         one to find a word boundary.  */
+                  while (start >= 0)
+                    {
+                      if ((start == 0 || !IS_WORD_CONSTITUENT ((unsigned char) beg[start - 1]))
+                          && (start + len == end - beg
+                              || !IS_WORD_CONSTITUENT ((unsigned char) beg[start + len])))
+                        goto success;
+                      if (len > 0)
+                        {
+                          /* Try a shorter length anchored at the same place. */
+                          --len;
+                          cregex->patterns[i].regexbuf.not_eol = 1;
+                          len = re_match (&cregex->patterns[i].regexbuf, beg,
+                                          start + len, start,
+                                          &cregex->patterns[i].regs);
+                        }
+                      if (len <= 0)
+                        {
+                          /* Try looking further on. */
+                          if (start == end - beg)
+                            break;
+                          ++start;
+                          cregex->patterns[i].regexbuf.not_eol = 0;
+                          start = re_search (&cregex->patterns[i].regexbuf, beg,
+                                             end - beg,
+                                             start, end - beg - start,
+                                             &cregex->patterns[i].regs);
+                          len = cregex->patterns[i].regs.end[0] - start;
+                        }
+                    }
+                }
+              else
                 goto success;
-              /* If -w, check if the match aligns with word boundaries.
-                 We do this iteratively because:
-                 (a) the line may contain more than one occurence of the
-                 pattern, and
-                 (b) Several alternatives in the pattern might be valid at a
-                 given point, and we may need to consider a shorter one to
-                 find a word boundary.  */
-              if (cregex->match_words)
-                while (start >= 0)
-                  {
-                    if ((start == 0 || !IS_WORD_CONSTITUENT ((unsigned char) beg[start - 1]))
-                        && (start + len == end - beg
-                            || !IS_WORD_CONSTITUENT ((unsigned char) beg[start + len])))
-                      goto success;
-                    if (len > 0)
-                      {
-                        /* Try a shorter length anchored at the same place. */
-                        --len;
-                        cregex->patterns[i].regexbuf.not_eol = 1;
-                        len = re_match (&cregex->patterns[i].regexbuf, beg,
-                                        start + len, start,
-                                        &cregex->patterns[i].regs);
-                      }
-                    if (len <= 0)
-                      {
-                        /* Try looking further on. */
-                        if (start == end - beg)
-                          break;
-                        ++start;
-                        cregex->patterns[i].regexbuf.not_eol = 0;
-                        start = re_search (&cregex->patterns[i].regexbuf, beg,
-                                           end - beg,
-                                           start, end - beg - start,
-                                           &cregex->patterns[i].regs);
-                        len = cregex->patterns[i].regs.end[0] - start;
-                      }
-                  }
             }
-        } /* for Regex patterns.  */
+        }
 
       if (end < buflim)
         end++;
-    } /* for (beg = end ..) */
+    }
   return (size_t) -1;
 
  success: