From owner-p4-projects@FreeBSD.ORG Fri Jun 13 19:18:37 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 99AF01065670; Fri, 13 Jun 2008 19:18:37 +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 42AD2106567B for ; Fri, 13 Jun 2008 19:18:37 +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 2CE678FC17 for ; Fri, 13 Jun 2008 19:18:37 +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 m5DJIbI7004707 for ; Fri, 13 Jun 2008 19:18:37 GMT (envelope-from gabor@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.1/8.14.1/Submit) id m5DJIbok004704 for perforce@freebsd.org; Fri, 13 Jun 2008 19:18:37 GMT (envelope-from gabor@freebsd.org) Date: Fri, 13 Jun 2008 19:18:37 GMT Message-Id: <200806131918.m5DJIbok004704@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 143423 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: Fri, 13 Jun 2008 19:18:37 -0000 http://perforce.freebsd.org/chv.cgi?CH=143423 Change 143423 by gabor@gabor_server on 2008/06/13 19:18:29 - Implement -m / --max-count Affected files ... .. //depot/projects/soc2008/gabor_textproc/grep/grep.1#9 edit .. //depot/projects/soc2008/gabor_textproc/grep/grep.c#17 edit .. //depot/projects/soc2008/gabor_textproc/grep/grep.h#13 edit .. //depot/projects/soc2008/gabor_textproc/grep/util.c#14 edit Differences ... ==== //depot/projects/soc2008/gabor_textproc/grep/grep.1#9 (text+ko) ==== @@ -29,7 +29,7 @@ .\" .\" @(#)grep.1 8.3 (Berkeley) 4/18/94 .\" -.Dd 6 Jun, 2008 +.Dd 13 Jun, 2008 .Dt GREP 1 .Os .Sh NAME @@ -39,7 +39,7 @@ .Sh SYNOPSIS .Nm grep .Bk -words -.Op Fl abcdDEFGHhIiLlnOoPqRSsUVvwxZ +.Op Fl abcdDEFGHhIiLlmnOoPqRSsUVvwxZ .Op Fl A Ar num .Op Fl B Ar num .Op Fl C Ns Op Ar num @@ -251,6 +251,10 @@ .Xr read 2 to read input, which can result in better performance under some circumstances but can cause undefined behaiour. +.It Fl m Ar num, Fl Fl max-count Ns = Ns Ar num +Stop reading the file after +.Ar num +matches. .It Fl n , Fl Fl line-number Each output line is preceded by its relative line number in the file, starting at line 1. ==== //depot/projects/soc2008/gabor_textproc/grep/grep.c#17 (text+ko) ==== @@ -84,6 +84,7 @@ int hflag; /* -h: don't print filename headers */ int iflag; /* -i: ignore case */ int lflag; /* -l: only show names of files with matches */ +int mflag; /* -m x: stop reading the files after x matches */ int nflag; /* -n: show line numbers in front of matching lines */ int oflag; /* -o: print only matching part */ int qflag; /* -q: quiet mode (don't output anything) */ @@ -95,6 +96,7 @@ int nullflag; /* --null */ char *label; /* --label */ char *color; /* --color */ +long long mcount; /* count for -m */ int binbehave = BIN_FILE_BIN; @@ -124,7 +126,7 @@ usage(void) { fprintf(stderr, - "usage: %s [-abcDEFGHhIiJLlnOoPqRSsUVvwxZ] [-A num] [-B num] [-C[num]]\n" + "usage: %s [-abcDEFGHhIiJLlmnOoPqRSsUVvwxZ] [-A num] [-B num] [-C[num]]\n" "\t[-e pattern] [-f file] [--binary-files=value] [--color=when]\n" "\t[--context[=num]] [--directories=action] [--label] [--line-buffered]\n" "\t[--null] [pattern] [file ...]\n" @@ -132,7 +134,7 @@ exit(2); } -static char *optstr = "0123456789A:B:CD:EFGHIJLOPSRUVZabcd:e:f:hilnoqrsuvwxy"; +static char *optstr = "0123456789A:B:CD:EFGHIJLOPSRUVZabcd:e:f:hilm:noqrsuvwxy"; struct option long_options[] = { @@ -163,8 +165,7 @@ {"bz2decompress", no_argument, NULL, 'J'}, {"files-with-matches", no_argument, NULL, 'l'}, {"files-without-match", no_argument, NULL, 'L'}, -/* XXX: UNIMPLEMENTED - {"max-count", required_argument, NULL, 'm'}, */ + {"max-count", required_argument, NULL, 'm'}, {"line-number", no_argument, NULL, 'n'}, {"only-matching", no_argument, NULL, 'o'}, {"quiet", no_argument, NULL, 'q'}, @@ -389,6 +390,10 @@ Lflag = 0; lflag = qflag = 1; break; + case 'm': + mflag++; + mcount = strtoll(optarg, (char **)NULL, 10); + break; case 'n': nflag = 1; break; ==== //depot/projects/soc2008/gabor_textproc/grep/grep.h#13 (text+ko) ==== @@ -62,9 +62,10 @@ /* Command line flags */ extern int Aflag, Bflag, Dflag, Eflag, Fflag, Gflag, Hflag, Jflag, Lflag, Pflag, Sflag, Rflag, Zflag, - bflag, cflag, hflag, iflag, lflag, nflag, Oflag, oflag, qflag, sflag, + bflag, cflag, hflag, iflag, lflag, mflag, nflag, Oflag, oflag, qflag, sflag, vflag, wflag, xflag, nullflag; +extern long long mcount; extern char *color, *label; extern int binbehave; ==== //depot/projects/soc2008/gabor_textproc/grep/util.c#14 (text+ko) ==== @@ -122,6 +122,9 @@ struct file *f; int c, t, z, nottext; + if (mflag && (mcount <= 0)) + return (0); + if (fn == NULL) { if (label != NULL) fn = label; @@ -167,6 +170,12 @@ linesqueued++; } c += t; + + if (mflag) { + mcount -= t; + if (mcount <= 0) + break; + } } if (Bflag > 0) clearqueue();