Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/grep Remove matchall handling for now, it doesn't wo...



details:   https://anonhg.NetBSD.org/src/rev/f3a47674d084
branches:  trunk
changeset: 779150:f3a47674d084
user:      joerg <joerg%NetBSD.org@localhost>
date:      Sun May 06 22:27:00 2012 +0000

description:
Remove matchall handling for now, it doesn't work correctly and as such,
it is a premature optimisation.

diffstat:

 usr.bin/grep/grep.c |  14 ++++----------
 usr.bin/grep/grep.h |   4 ++--
 usr.bin/grep/util.c |  23 ++++-------------------
 3 files changed, 10 insertions(+), 31 deletions(-)

diffs (111 lines):

diff -r 50dac757e68b -r f3a47674d084 usr.bin/grep/grep.c
--- a/usr.bin/grep/grep.c       Sun May 06 21:56:08 2012 +0000
+++ b/usr.bin/grep/grep.c       Sun May 06 22:27:00 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: grep.c,v 1.10 2011/09/16 15:39:26 joerg Exp $  */
+/*     $NetBSD: grep.c,v 1.11 2012/05/06 22:27:00 joerg Exp $  */
 /*     $FreeBSD: head/usr.bin/grep/grep.c 211519 2010-08-19 22:55:17Z delphij $        */
 /*     $OpenBSD: grep.c,v 1.42 2010/07/02 22:18:03 tedu Exp $  */
 
@@ -34,7 +34,7 @@
 #endif
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: grep.c,v 1.10 2011/09/16 15:39:26 joerg Exp $");
+__RCSID("$NetBSD: grep.c,v 1.11 2012/05/06 22:27:00 joerg Exp $");
 
 #include <sys/stat.h>
 #include <sys/types.h>
@@ -80,9 +80,6 @@
 int             cflags = 0;
 int             eflags = REG_STARTEND;
 
-/* Shortcut for matching all cases like empty regex */
-bool            matchall;
-
 /* Searching patterns */
 unsigned int    patterns, pattern_sz;
 char           **pattern;
@@ -229,11 +226,8 @@
 add_pattern(char *pat, size_t len)
 {
 
-       /* Check if we can do a shortcut */
-       if (len == 0 || matchall) {
-               matchall = true;
-               return;
-       }
+       /* TODO: Check for empty patterns and shortcut */
+
        /* Increase size if necessary */
        if (patterns == pattern_sz) {
                pattern_sz *= 2;
diff -r 50dac757e68b -r f3a47674d084 usr.bin/grep/grep.h
--- a/usr.bin/grep/grep.h       Sun May 06 21:56:08 2012 +0000
+++ b/usr.bin/grep/grep.h       Sun May 06 22:27:00 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: grep.h,v 1.7 2011/04/18 22:46:48 joerg Exp $   */
+/*     $NetBSD: grep.h,v 1.8 2012/05/06 22:27:00 joerg Exp $   */
 /*     $OpenBSD: grep.h,v 1.15 2010/04/05 03:03:55 tedu Exp $  */
 /*     $FreeBSD: head/usr.bin/grep/grep.h 211496 2010-08-19 09:28:59Z des $    */
 
@@ -120,7 +120,7 @@
 extern const char *color;
 extern int      binbehave, devbehave, dirbehave, filebehave, grepbehave, linkbehave;
 
-extern bool     matchall, notfound;
+extern bool     notfound;
 extern int      tail;
 extern unsigned int dpatterns, fpatterns, patterns;
 extern char    **pattern;
diff -r 50dac757e68b -r f3a47674d084 usr.bin/grep/util.c
--- a/usr.bin/grep/util.c       Sun May 06 21:56:08 2012 +0000
+++ b/usr.bin/grep/util.c       Sun May 06 22:27:00 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: util.c,v 1.14 2012/05/06 21:56:08 joerg Exp $  */
+/*     $NetBSD: util.c,v 1.15 2012/05/06 22:27:01 joerg Exp $  */
 /*     $FreeBSD: head/usr.bin/grep/util.c 211496 2010-08-19 09:28:59Z des $    */
 /*     $OpenBSD: util.c,v 1.39 2010/07/02 22:18:03 tedu Exp $  */
 
@@ -34,7 +34,7 @@
 #endif
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: util.c,v 1.14 2012/05/06 21:56:08 joerg Exp $");
+__RCSID("$NetBSD: util.c,v 1.15 2012/05/06 22:27:01 joerg Exp $");
 
 #include <sys/stat.h>
 #include <sys/types.h>
@@ -227,12 +227,8 @@
 
        for (first = true, c = 0;  c == 0 || !(lflag || qflag); ) {
                ln.off += ln.len + 1;
-               if ((ln.dat = grep_fgetln(f, &ln.len)) == NULL || ln.len == 0) {
-                       if (ln.line_no == 0 && matchall)
-                               exit(0);
-                       else
-                               break;
-               }
+               if ((ln.dat = grep_fgetln(f, &ln.len)) == NULL || ln.len == 0)
+                       break;
                if (ln.len > 0 && ln.dat[ln.len - 1] == line_sep)
                        --ln.len;
                ln.line_no++;
@@ -295,17 +291,6 @@
        unsigned int i;
        int c = 0, m = 0, r = 0;
 
-       if (matchall) {
-               /* Short cut the case of (not) matching wild card pattern */
-               if (vflag)
-                       return (0);
-               if ((binbehave == BINFILE_BIN && nottext) || cflag || qflag ||
-                   lflag || Lflag)
-                       return (1);
-               printline(l, ':', matches, m);
-               return (1);
-       }
-
        /* Loop to process the whole line */
        while (st <= l->len) {
                pmatch.rm_so = st;



Home | Main Index | Thread Index | Old Index