From owner-p4-projects@FreeBSD.ORG Sun Aug 10 09:48:12 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 0EE1F1065671; Sun, 10 Aug 2008 09:48:12 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id AEFE1106564A for ; Sun, 10 Aug 2008 09:48:11 +0000 (UTC) (envelope-from gabor@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id A27918FC18 for ; Sun, 10 Aug 2008 09:48:11 +0000 (UTC) (envelope-from gabor@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.2/8.14.2) with ESMTP id m7A9mB20072695 for ; Sun, 10 Aug 2008 09:48:11 GMT (envelope-from gabor@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.2/8.14.1/Submit) id m7A9mBJl072693 for perforce@freebsd.org; Sun, 10 Aug 2008 09:48:11 GMT (envelope-from gabor@freebsd.org) Date: Sun, 10 Aug 2008 09:48:11 GMT Message-Id: <200808100948.m7A9mBJl072693@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to gabor@freebsd.org using -f From: Gabor Kovesdan To: Perforce Change Reviews Cc: Subject: PERFORCE change 147064 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 10 Aug 2008 09:48:12 -0000 http://perforce.freebsd.org/chv.cgi?CH=147064 Change 147064 by gabor@gabor_server on 2008/08/10 09:48:11 - Cut out fixed string -w in a working way Affected files ... .. //depot/projects/soc2008/gabor_textproc/grep/fastgrep.c#4 edit Differences ... ==== //depot/projects/soc2008/gabor_textproc/grep/fastgrep.c#4 (text+ko) ==== @@ -52,7 +52,6 @@ fg->patternLen = strlen(pattern); fg->bol = 0; fg->eol = 0; - fg->wmatch = wflag; fg->reversedSearch = 0; /* @@ -101,7 +100,6 @@ fg->patternLen = strlen(pattern); fg->bol = 0; fg->eol = 0; - fg->wmatch = 0; fg->reversedSearch = 0; /* Remove end-of-line character ('$'). */ @@ -118,17 +116,11 @@ fg->patternLen--; } - /* Remove enclosing [[:<:]] and [[:>:]] (word match). */ - if (wflag) { - /* basic re's use \( \), extended re's ( ) */ - int extra = (grepbehave == GREP_EXTENDED) ? 1 : 2; - fg->patternLen -= 14 + 2 * extra; - fg->wmatch = 7 + extra; - } else if (fg->patternLen >= 14 && + if (fg->patternLen >= 14 && strncmp(pattern + fg->bol, "[[:<:]]", 7) == 0 && strncmp(pattern + fg->bol + fg->patternLen - 7, "[[:>:]]", 7) == 0) { fg->patternLen -= 14; - fg->wmatch = 7; + wflag = 1; } /* @@ -137,7 +129,7 @@ * string respectively. */ fg->pattern = grep_malloc(fg->patternLen + 1); - memcpy(fg->pattern, pattern + bol + fg->wmatch, fg->patternLen); + memcpy(fg->pattern, pattern + bol + wflag, fg->patternLen); fg->pattern[fg->patternLen] = '\0'; /* Look for ways to cheat...er...avoid the full regex engine. */ @@ -230,18 +222,6 @@ return (0); } -/* - * Word boundaries using regular expressions are defined as the point - * of transition from a non-word char to a word char, or vice versa. - * This means that grep -w +a and grep -w a+ never match anything, - * because they lack a starting or ending transition, but grep -w a+b - * does match a line containing a+b. - */ -#define isword(x) (isalnum(x) || (x) == '_') -#define wmatch(d, l, s, e) \ - ((s == 0 || !isword(d[s-1])) && (e == l || !isword(d[e])) && \ - e > s && isword(d[s]) && isword(d[e-1])) - int grep_search(fastgrep_t *fg, unsigned char *data, size_t dataLen, regmatch_t *pmatch) { @@ -270,8 +250,6 @@ fg->patternLen) == -1) { pmatch->rm_so = j; pmatch->rm_eo = j + fg->patternLen; - if (!fg->wmatch || wmatch(data, dataLen, - pmatch->rm_so, pmatch->rm_eo)) rtrnVal = 0; } } @@ -283,11 +261,8 @@ fg->patternLen) == -1) { pmatch->rm_so = j - fg->patternLen; pmatch->rm_eo = j; - if (!fg->wmatch || wmatch(data, dataLen, - pmatch->rm_so, pmatch->rm_eo)) { - rtrnVal = 0; - break; - } + rtrnVal = 0; + break; } /* Shift if within bounds, otherwise, we are done. */ if (j == fg->patternLen) @@ -301,12 +276,8 @@ if (grep_cmp(fg->pattern, data + j, fg->patternLen) == -1) { pmatch->rm_so = j; pmatch->rm_eo = j + fg->patternLen; - if (fg->patternLen == 0 || !fg->wmatch || - wmatch(data, dataLen, pmatch->rm_so, - pmatch->rm_eo)) { - rtrnVal = 0; - break; - } + rtrnVal = 0; + break; } /* Shift if within bounds, otherwise, we are done. */