From owner-p4-projects@FreeBSD.ORG Wed Jun 25 13:58:21 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id A8797106567F; Wed, 25 Jun 2008 13:58:21 +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 518271065674 for ; Wed, 25 Jun 2008 13:58:21 +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 46D3C8FC1D for ; Wed, 25 Jun 2008 13:58:21 +0000 (UTC) (envelope-from gabor@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.1/8.14.1) with ESMTP id m5PDwL8I002683 for ; Wed, 25 Jun 2008 13:58:21 GMT (envelope-from gabor@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.1/8.14.1/Submit) id m5PDwLac002681 for perforce@freebsd.org; Wed, 25 Jun 2008 13:58:21 GMT (envelope-from gabor@freebsd.org) Date: Wed, 25 Jun 2008 13:58:21 GMT Message-Id: <200806251358.m5PDwLac002681@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 144096 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: Wed, 25 Jun 2008 13:58:21 -0000 http://perforce.freebsd.org/chv.cgi?CH=144096 Change 144096 by gabor@gabor_server on 2008/06/25 13:57:53 - Change the procline() layout to count the matches and store the matching offsets. This will lead as a working --color support. The change is incomplete now, thus --color and -o won't work yet. Obtained from: NetBSD Project Affected files ... .. //depot/projects/soc2008/gabor_textproc/grep/grep.h#28 edit .. //depot/projects/soc2008/gabor_textproc/grep/util.c#42 edit Differences ... ==== //depot/projects/soc2008/gabor_textproc/grep/grep.h#28 (text+ko) ==== @@ -60,6 +60,8 @@ #define LINK_EXPLICIT 1 #define LINK_SKIP 2 +#define MAX_LINE_MATCHES 32 + struct file { int noseek; FILE *f; ==== //depot/projects/soc2008/gabor_textproc/grep/util.c#42 (text+ko) ==== @@ -202,55 +202,42 @@ procline(struct str *l, int nottext) { regmatch_t pmatch; - int c, i, r; + regmatch_t matches[MAX_LINE_MATCHES]; + regoff_t st = 0; + int c = 0, i, r, m = 0, t; if (!matchall) { - for (c = i = 0; i < patterns; i++) { - pmatch.rm_so = 0; + t = vflag ? REG_NOMATCH : 0; + + while (st <= l->len) { + pmatch.rm_so = st; pmatch.rm_eo = l->len; - r = regexec(&r_pattern[i], l->dat, 1, &pmatch, eflags); - if (r == 0 && xflag) { - if (pmatch.rm_so != 0 || pmatch.rm_eo != l->len) - r = REG_NOMATCH; - } - if ((r == 0) && (color != NULL) && !oflag && !nottext) { - char *tmp, *begin, *matched, *end; - begin = grep_malloc(strlen(l->dat) - pmatch.rm_so + 1); - matched = grep_malloc((pmatch.rm_eo - pmatch.rm_so + 1) * sizeof(char)); - end = grep_malloc(strlen(l->dat) - pmatch.rm_eo + 1); - - strlcpy(begin, l->dat, pmatch.rm_so + 1); - strlcpy(matched, &(l->dat[pmatch.rm_so]), pmatch.rm_eo - pmatch.rm_so + 1); - strlcpy(end, &(l->dat[pmatch.rm_eo]), strlen(l->dat) - pmatch.rm_eo + 1); - - asprintf(&tmp, "%s\33[%sm\33[K%s\33[m\33[K%s", begin, color, matched, end); - - free(begin); - free(matched); - free(end); - - l->len += strlen(color) + 12; - l->dat = tmp; + for (i = 0; i < patterns; i++) { + pmatch.rm_so = 0; + pmatch.rm_eo = l->len; + r = regexec(&r_pattern[i], l->dat, 1, &pmatch, eflags); + if (r == REG_NOMATCH && t == 0) + continue; + if (r == 0 && xflag) + if (pmatch.rm_so != 0 || pmatch.rm_eo != l->len) + r = REG_NOMATCH; + if (r == t) { + if (m == 0) + c++; + if (m < MAX_LINE_MATCHES) + matches[m] = pmatch; + m++; + } + st = pmatch.rm_eo; + break; } - if (r == 0 && oflag && !nottext) { - char *tmp, *matched; + /* One pass if we are not recording matches */ + if (!oflag && !color) + break; - matched = grep_malloc((pmatch.rm_eo - pmatch.rm_so + 2) * sizeof(char)); - strlcpy(matched, &(l->dat[pmatch.rm_so]), pmatch.rm_eo - pmatch.rm_so + 1); - - if (color != NULL) - asprintf(&tmp, "\33[%sm%s\33[m", color, matched); - else - tmp = matched; - - l->dat = tmp; - l->len = strlen(l->dat); - } - if (r == 0) { - c++; - break; - } + if (st == pmatch.rm_so) + break; /* No matches */ } } else c = !vflag;