summaryrefslogtreecommitdiff
path: root/usr/src/cmd/grep/grep.c
diff options
context:
space:
mode:
authorJohn Sonnenschein <johns@joyent.com>2012-05-17 18:26:57 +0000
committerJohn Sonnenschein <johns@joyent.com>2012-05-17 18:26:57 +0000
commit04b244dd661c24b510ac22936decfc0972d202d3 (patch)
tree3ebfef98afc303fddf3415d6fba64e8682f495e8 /usr/src/cmd/grep/grep.c
parenteac250589e41f1b705e1b7427b02b3379aac9f9e (diff)
parenta69187741b83640a90dd8586195456dd50c016a8 (diff)
downloadillumos-joyent-20120517.tar.gz
Merge git.joyent.com:illumos-joyent20120517
Diffstat (limited to 'usr/src/cmd/grep/grep.c')
-rw-r--r--usr/src/cmd/grep/grep.c19
1 files changed, 14 insertions, 5 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 = "<stdin>";
+ if (qflag) {
+ /* no need to continue */
+ return (1);
+ }
+
if (cflag) {
tln++;
return (0);