From 3ed621bc8eb70ee11c69cd408fb8450eac33c281 Mon Sep 17 00:00:00 2001 From: Alexander Eremin Date: Fri, 30 Mar 2012 10:49:58 -0400 Subject: [PATCH] =?utf8?q?650=20grep=20support=20for=20-q=20would=20be=20u?= =?utf8?q?seful=20Reviewed=20by:=20David=20H=C3=B6ppner=20<0xffea@googlema?= =?utf8?q?il.com>=20Reviewed=20by:=20Dan=20McDonald=20?= =?utf8?q?=20Reviewed=20by:=20Andrew=20Stormont=20=20Reviewed=20by:=20Garrett=20D'Amore=20=20Reviewed=20by:=20Albert=20Lee=20=20Approv?= =?utf8?q?ed=20by:=20Albert=20Lee=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- usr/src/cmd/grep/grep.c | 19 ++++++++++++++----- usr/src/man/man1/grep.1 | 23 ++++++++++++----------- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/usr/src/cmd/grep/grep.c b/usr/src/cmd/grep/grep.c index 37ccd8c2be..62a4527529 100644 --- a/usr/src/cmd/grep/grep.c +++ b/usr/src/cmd/grep/grep.c @@ -30,7 +30,7 @@ /* Copyright (c) 1987, 1988 Microsoft Corporation */ /* All Rights Reserved */ -#pragma ident "%Z%%M% %I% %E% SMI" +/* Copyright 2012 Nexenta Systems, Inc. All rights reserved. */ /* * grep -- print lines matching (or not matching) a pattern @@ -88,6 +88,7 @@ static int sflag; static int iflag; static int wflag; static int hflag; +static int qflag; static int errflg; static int nfile; static long long tln; @@ -113,11 +114,14 @@ main(int argc, char **argv) #endif (void) textdomain(TEXT_DOMAIN); - while ((c = getopt(argc, argv, "hblcnsviyw")) != -1) + while ((c = getopt(argc, argv, "hqblcnsviyw")) != -1) switch (c) { case 'h': hflag++; break; + case 'q': /* POSIX: quiet: status only */ + qflag++; + break; case 'v': vflag++; break; @@ -148,7 +152,7 @@ main(int argc, char **argv) } if (errflg || (optind >= argc)) { - errmsg("Usage: grep -hblcnsviw pattern file . . .\n", + errmsg("Usage: grep [-c|-l|-q] -hbnsviw pattern file . . .\n", (char *)NULL); exit(2); } @@ -228,7 +232,7 @@ execute(char *file) if ((count = read(temp, prntbuf, GBUFSIZ)) <= 0) { (void) close(temp); - if (cflag) { + if (cflag && !qflag) { if (nfile > 1 && !hflag && file) (void) fprintf(stdout, "%s:", file); (void) fprintf(stdout, "%lld\n", tln); @@ -324,7 +328,7 @@ execute(char *file) } (void) close(temp); - if (cflag) { + if (cflag && !qflag) { if (nfile > 1 && !hflag && file) (void) fprintf(stdout, "%s:", file); (void) fprintf(stdout, "%lld\n", tln); @@ -340,6 +344,11 @@ succeed(char *f) if (f == NULL) f = ""; + if (qflag) { + /* no need to continue */ + return (1); + } + if (cflag) { tln++; return (0); diff --git a/usr/src/man/man1/grep.1 b/usr/src/man/man1/grep.1 index 879ba61485..e93f3a19ca 100644 --- a/usr/src/man/man1/grep.1 +++ b/usr/src/man/man1/grep.1 @@ -1,4 +1,5 @@ '\" te +.\" Copyright 2012 Nexenta Systems, Inc. All rights reserved. .\" Copyright 1989 AT&T .\" Copyright (c) 2008, Sun Microsystems, Inc. All Rights Reserved .\" Portions Copyright (c) 1992, X/Open Company Limited All Rights Reserved @@ -15,7 +16,7 @@ grep \- search a file for a pattern .SH SYNOPSIS .LP .nf -\fB/usr/bin/grep\fR [\fB-bchilnsvw\fR] \fIlimited-regular-expression\fR +\fB/usr/bin/grep\fR [\fB-c\fR | \fB-l\fR | \fB-q\fR] [\fB-bhinsvw\fR] \fIlimited-regular-expression\fR [\fIfilename\fR]... .fi @@ -134,6 +135,16 @@ Precedes each line by its line number in the file (first line is 1). .sp .ne 2 .na +\fB\fB-q\fR\fR +.ad +.RS 6n +Quiet. Does not write anything to the standard output, regardless of matching +lines. Exits with zero status if an input line is selected. +.RE + +.sp +.ne 2 +.na \fB\fB-s\fR\fR .ad .RS 6n @@ -246,16 +257,6 @@ line. See \fBfgrep\fR(1) for more information. .sp .ne 2 .na -\fB\fB-q\fR\fR -.ad -.RS 19n -Quiet. Does not write anything to the standard output, regardless of matching -lines. Exits with zero status if an input line is selected. -.RE - -.sp -.ne 2 -.na \fB\fB-x\fR\fR .ad .RS 19n -- 2.11.4.GIT