From owner-p4-projects@FreeBSD.ORG Tue Jun 17 12:02:40 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 6ABA3106577A; Tue, 17 Jun 2008 12:02:39 +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 1005E1065763 for ; Tue, 17 Jun 2008 12:02:39 +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 D35D98FC1E for ; Tue, 17 Jun 2008 12:02:26 +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 m5HC2Qg9026411 for ; Tue, 17 Jun 2008 12:02:26 GMT (envelope-from gabor@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.1/8.14.1/Submit) id m5HC2Qv5026409 for perforce@freebsd.org; Tue, 17 Jun 2008 12:02:26 GMT (envelope-from gabor@freebsd.org) Date: Tue, 17 Jun 2008 12:02:26 GMT Message-Id: <200806171202.m5HC2Qv5026409@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 143638 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: Tue, 17 Jun 2008 12:02:41 -0000 http://perforce.freebsd.org/chv.cgi?CH=143638 Change 143638 by gabor@gabor_server on 2008/06/17 12:02:09 - Make -A compatible with GNU grep Affected files ... .. //depot/projects/soc2008/gabor_textproc/grep/grep.c#19 edit .. //depot/projects/soc2008/gabor_textproc/grep/grep.h#15 edit .. //depot/projects/soc2008/gabor_textproc/grep/util.c#20 edit Differences ... ==== //depot/projects/soc2008/gabor_textproc/grep/grep.c#19 (text+ko) ==== @@ -110,7 +110,8 @@ }; /* Housekeeping */ -int first; /* flag whether or not this is our first match */ +int first = 1; /* flag whether we are processing the first match */ +int prev; /* flag whether or not the previous line matched */ int tail; /* lines left to print */ struct patfile { ==== //depot/projects/soc2008/gabor_textproc/grep/grep.h#15 (text+ko) ==== @@ -68,7 +68,7 @@ extern char *color, *label; extern int binbehave; -extern int first, matchall, patterns, tail; +extern int first, prev, matchall, patterns, tail; extern char **pattern; extern struct fastgrep *fg_pattern; extern regex_t *r_pattern; ==== //depot/projects/soc2008/gabor_textproc/grep/util.c#20 (text+ko) ==== @@ -276,22 +276,27 @@ if (c && binbehave == BIN_FILE_BIN && nottext) return (c); /* Binary file */ - if ((tail > 0 || c) && !cflag && !qflag) { + if ((tail || c) && !cflag && !qflag) { if (c) { - if (first > 0 && tail == 0 && (Bflag < linesqueued) && - (Aflag || Bflag)) + if (!first && !prev && !tail && (Aflag || Bflag)) printf("--\n"); - first = 1; tail = Aflag; if (Bflag > 0) printqueue(); linesqueued = 0; printline(l, ':'); } else { + prev = 0; printline(l, '-'); tail--; } } + + if (c) { + prev++; + first = 0; + } + return (c); }