summaryrefslogtreecommitdiff
path: root/usr/src/cmd/egrep
diff options
context:
space:
mode:
authorDamian Bogel <damian.bogel@gmail.com>2013-05-14 15:08:53 +0200
committerRichard Lowe <richlowe@richlowe.net>2013-09-13 15:16:32 -0400
commit41599e9fdccb44cc5f17828ab04b3147cefcc4e0 (patch)
treed9436585e9226721f83c7877855092e2230e17ad /usr/src/cmd/egrep
parentea76c26cbb46a2abd6ae5d4bdfaa26e32a405633 (diff)
downloadillumos-joyent-41599e9fdccb44cc5f17828ab04b3147cefcc4e0.tar.gz
3737 grep does not support -H option
3759 egrep(1) and fgrep(1) -s flag does not hide -c output Reviewed by: Albert Lee <trisk@nexenta.com> Reviewed by: Andy Stormont <andyjstormont@gmail.com> Approved by: Richard Lowe <richlowe@richlowe.net>
Diffstat (limited to 'usr/src/cmd/egrep')
-rw-r--r--usr/src/cmd/egrep/egrep.y58
1 files changed, 35 insertions, 23 deletions
diff --git a/usr/src/cmd/egrep/egrep.y b/usr/src/cmd/egrep/egrep.y
index 95e071ebb9..8068dc447e 100644
--- a/usr/src/cmd/egrep/egrep.y
+++ b/usr/src/cmd/egrep/egrep.y
@@ -32,9 +32,9 @@
/* Copyright (c) 1987, 1988 Microsoft Corporation */
/* All Rights Reserved */
-%{
-#pragma ident "%Z%%M% %I% %E% SMI"
-%}
+/*
+ * Copyright 2013 Damian Bogel. All rights reserved.
+ */
/*
* egrep -- print lines containing (or not containing) a regular expression
@@ -61,6 +61,8 @@
#include <limits.h>
#include <locale.h>
+#define STDIN_FILENAME gettext("(standard input)")
+
#define BLKSIZE 512 /* size of reported disk blocks */
#define EBUFSIZ 8192
#define MAXLIN 350
@@ -110,11 +112,12 @@ int bflag;
int cflag;
int eflag;
int fflag;
+int Hflag;
int hflag;
int iflag;
int lflag;
int nflag;
-int sflag;
+int qflag;
int vflag;
int nfile;
long long blkno;
@@ -644,7 +647,7 @@ follow(int v)
}
}
-#define USAGE "[ -bchilnsv ] [ -e exp ] [ -f file ] [ strings ] [ file ] ..."
+#define USAGE "[ -bchHilnsqv ] [ -e exp ] [ -f file ] [ strings ] [ file ] ..."
int
main(int argc, char **argv)
@@ -660,7 +663,7 @@ main(int argc, char **argv)
#endif
(void) textdomain(TEXT_DOMAIN);
- while((c = getopt(argc, argv, "ybcie:f:hlnvs")) != -1)
+ while((c = getopt(argc, argv, "ybcie:f:Hhlnvsq")) != -1)
switch(c) {
case 'b':
@@ -686,8 +689,15 @@ main(int argc, char **argv)
}
continue;
+ case 'H':
+ if (!lflag) /* H is excluded by l as in GNU grep */
+ Hflag++;
+ hflag = 0; /* H excludes h */
+ continue;
+
case 'h':
hflag++;
+ Hflag = 0; /* h excludes H */
continue;
case 'y':
@@ -697,14 +707,16 @@ main(int argc, char **argv)
case 'l':
lflag++;
+ Hflag = 0; /* l excludes H */
continue;
case 'n':
nflag++;
continue;
- case 's':
- sflag++;
+ case 'q':
+ case 's': /* Solaris: legacy option */
+ qflag++;
continue;
case 'v':
@@ -799,16 +811,16 @@ execute(char *file)
return;
}
} else {
- file = "<stdin>";
f = stdin;
+ file = STDIN_FILENAME;
}
lnum = 1;
tln = 0;
if((count = read(fileno(f), buf, EBUFSIZ)) <= 0) {
fclose(f);
- if (cflag) {
- if (nfile>1 && !hflag)
+ if (cflag && !qflag) {
+ if (Hflag || (nfile > 1 && !hflag))
fprintf(stdout, "%s:", file);
fprintf(stdout, "%lld\n", tln);
}
@@ -902,19 +914,19 @@ execute(char *file)
break;
}
}
- if(succ) {
+ if (succ) {
nsucc = 1;
- if (cflag) tln++;
- else if (sflag)
- ; /* ugh */
- else if (lflag) {
- printf("%s\n", file);
+ if (lflag || qflag) {
+ if (!qflag)
+ (void) printf("%s\n", file);
fclose(f);
return;
}
- else {
- if (nfile > 1 && !hflag)
- printf(gettext("%s:"), file);
+ if (cflag) {
+ tln++;
+ } else {
+ if (Hflag || (nfile > 1 && !hflag))
+ printf("%s:", file);
if (bflag) {
nchars = blkno - (buf + count - ptrend) - 2;
if(nlflag)
@@ -944,9 +956,9 @@ execute(char *file)
clearg();
}
fclose(f);
- if (cflag) {
- if (nfile > 1 && !hflag)
- printf(gettext("%s:"), file);
+ if (cflag && !qflag) {
+ if (Hflag || (nfile > 1 && !hflag))
+ printf("%s:", file);
printf("%lld\n", tln);
}
}