diff options
author | Jerry Jelinek <jerry.jelinek@joyent.com> | 2020-05-28 11:45:02 +0000 |
---|---|---|
committer | Jerry Jelinek <jerry.jelinek@joyent.com> | 2020-05-28 11:45:02 +0000 |
commit | ca12249c9d3a839d51477c843e135ba49408c537 (patch) | |
tree | 6f02afaa57b11f5f0225a4b9e9687342b4614b29 /usr/src/cmd/grep/grep.c | |
parent | 4bed2831a184edd4530dcb078dc9725887e8a0c7 (diff) | |
parent | 4adc6f153a42519cb03b97bf215e1d4823300ebe (diff) | |
download | illumos-joyent-ca12249c9d3a839d51477c843e135ba49408c537.tar.gz |
[illumos-gate merge]
commit 4adc6f153a42519cb03b97bf215e1d4823300ebe
12785 grep -h ignored with -r
commit c9ad389f76487048d6fde034960b0f5edfb778d7
12788 fix tst.include.ksh for ddi_ufm.h
commit 2aeafac3612e19716bf8164f89c3c9196342979c
12787 build needs native rpcgen
Diffstat (limited to 'usr/src/cmd/grep/grep.c')
-rw-r--r-- | usr/src/cmd/grep/grep.c | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/usr/src/cmd/grep/grep.c b/usr/src/cmd/grep/grep.c index 7054d1f602..ac51023678 100644 --- a/usr/src/cmd/grep/grep.c +++ b/usr/src/cmd/grep/grep.c @@ -35,6 +35,7 @@ */ /* + * Copyright 2020 Peter Tribble. * Copyright 2018 RackTop Systems. * Copyright 2018 Nexenta Systems, Inc. * Copyright 2013 Damian Bogel. All rights reserved. @@ -64,8 +65,8 @@ #define BUFSIZE 8192 /* Input buffer size */ #define MAX_DEPTH 1000 /* how deep to recurse */ -#define AFTER 1 /* 'After' Context */ -#define BEFORE 2 /* 'Before' Context */ +#define AFTER 1 /* 'After' Context */ +#define BEFORE 2 /* 'Before' Context */ #define CONTEXT (AFTER|BEFORE) /* Full Context */ #define M_CSETSIZE 256 /* singlebyte chars */ @@ -91,11 +92,11 @@ static boolean_t nvflag = B_TRUE; /* Print matching lines */ static uchar_t cflag; /* Count of matches */ static uchar_t iflag; /* Case insensitve matching */ static uchar_t Hflag; /* Precede lines by file name */ -static uchar_t hflag; /* Supress printing of filename */ +static uchar_t hflag; /* Suppress printing of filename */ static uchar_t lflag; /* Print file names of matches */ static uchar_t nflag; /* Precede lines by line number */ static uchar_t rflag; /* Search directories recursively */ -static uchar_t bflag; /* Preccede matches by block number */ +static uchar_t bflag; /* Precede matches by block number */ static uchar_t sflag; /* Suppress file error messages */ static uchar_t qflag; /* Suppress standard output */ static uchar_t wflag; /* Search for expression as a word */ @@ -110,7 +111,7 @@ static char *cmdname; static int use_wchar, use_bmg, mblocale; static size_t outbuflen, prntbuflen, conbuflen; -static unsigned long conalen, conblen, conmatches; +static unsigned long conalen, conblen, conmatches; static char *prntbuf, *conbuf; static wchar_t *outline; @@ -264,11 +265,11 @@ main(int argc, char **argv) break; /* based on options order h or H is set as in GNU grep */ - case 'h': /* Solaris: supress printing of file name */ + case 'h': /* Solaris: suppress printing of file name */ hflag = 1; Hflag = 0; break; - /* Solaris: precede every matching with file name */ + /* Solaris: precede every match with file name */ case 'H': Hflag = 1; hflag = 0; @@ -485,7 +486,8 @@ process_path(const char *path) if (rflag) { if (stat(path, &st) != -1 && (st.st_mode & S_IFMT) == S_IFDIR) { - outfn = 1; /* Print filename */ + if (!hflag) + outfn = 1; /* Print filename unless -h */ /* * Add trailing slash if arg @@ -898,7 +900,7 @@ grep(int fd, const char *fn) off_t blkoffset; /* line_offset but context-compatible */ long long lineno, linenum; long long matches = 0; /* Number of matching lines */ - long long conacnt = 0, conbcnt = 0; /* context line count */ + long long conacnt = 0, conbcnt = 0; /* context line count */ int newlinep; /* 0 if the last line of file has no newline */ char *ptr, *ptrend, *prntptr, *prntptrend; char *nextptr = NULL, *nextend = NULL; |