Print this page
3737 grep does not support -H option
*** 71,80 ****
--- 71,82 ----
"Illegal byte sequence.",
"Unknown regexp error code!!",
NULL
};
+ #define STDIN_FILENAME gettext("(standard input)")
+
#define errmsg(msg, arg) (void) fprintf(stderr, gettext(msg), arg)
#define BLKSIZE 512
#define GBUFSIZ 8192
#define MAX_DEPTH 1000
*** 92,101 ****
--- 94,104 ----
static int vflag;
static int sflag;
static int iflag;
static int wflag;
static int hflag;
+ static int Hflag;
static int qflag;
static int errflg;
static int nfile;
static long long tln;
static int nsucc;
*** 121,134 ****
#if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
#define TEXT_DOMAIN "SYS_TEST" /* Use this only if it weren't */
#endif
(void) textdomain(TEXT_DOMAIN);
! while ((c = getopt(argc, argv, "hqblcnRrsviyw")) != -1)
switch (c) {
case 'h':
hflag++;
break;
case 'q': /* POSIX: quiet: status only */
qflag++;
break;
case 'v':
--- 124,144 ----
#if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
#define TEXT_DOMAIN "SYS_TEST" /* Use this only if it weren't */
#endif
(void) textdomain(TEXT_DOMAIN);
! while ((c = getopt(argc, argv, "hHqblcnRrsviyw")) != -1)
switch (c) {
+ /* based on options order h or H is set as in GNU grep */
case 'h':
hflag++;
+ Hflag = 0; /* h excludes H */
+ break;
+ case 'H':
+ if (!lflag) /* H is excluded by l */
+ Hflag++;
+ hflag = 0; /* H excludes h */
break;
case 'q': /* POSIX: quiet: status only */
qflag++;
break;
case 'v':
*** 152,161 ****
--- 162,172 ----
case 's':
sflag++;
break;
case 'l':
lflag++;
+ Hflag = 0; /* l excludes H */
break;
case 'y':
case 'i':
iflag++;
break;
*** 165,175 ****
case '?':
errflg++;
}
if (errflg || (optind >= argc)) {
! errmsg("Usage: grep [-c|-l|-q] [-r|-R] -hbnsviw "
"pattern file . . .\n",
(char *)NULL);
exit(2);
}
--- 176,186 ----
case '?':
errflg++;
}
if (errflg || (optind >= argc)) {
! errmsg("Usage: grep [-c|-l|-q] [-r|-R] -hHbnsviw "
"pattern file . . .\n",
(char *)NULL);
exit(2);
}
*** 297,309 ****
if ((linebuf = malloc(fw_lPrntBufLen)) == NULL) {
exit(2); /* out of memory - BAIL */
}
}
! if (file == NULL)
temp = 0;
! else if ((temp = open(file + base, O_RDONLY)) == -1) {
if (!sflag)
errmsg("grep: can't open %s\n", file);
nsucc = 2;
return;
}
--- 308,321 ----
if ((linebuf = malloc(fw_lPrntBufLen)) == NULL) {
exit(2); /* out of memory - BAIL */
}
}
! if (file == NULL) {
temp = 0;
! file = STDIN_FILENAME;
! } else if ((temp = open(file + base, O_RDONLY)) == -1) {
if (!sflag)
errmsg("grep: can't open %s\n", file);
nsucc = 2;
return;
}
*** 311,321 ****
/* read in first block of bytes */
if ((count = read(temp, prntbuf, GBUFSIZ)) <= 0) {
(void) close(temp);
if (cflag && !qflag) {
! if (nfile > 1 && !hflag && file)
(void) fprintf(stdout, "%s:", file);
if (!rflag)
(void) fprintf(stdout, "%lld\n", tln);
}
return;
--- 323,333 ----
/* read in first block of bytes */
if ((count = read(temp, prntbuf, GBUFSIZ)) <= 0) {
(void) close(temp);
if (cflag && !qflag) {
! if (Hflag || (nfile > 1 && !hflag))
(void) fprintf(stdout, "%s:", file);
if (!rflag)
(void) fprintf(stdout, "%lld\n", tln);
}
return;
*** 408,419 ****
offset = 0;
}
(void) close(temp);
if (cflag && !qflag) {
! if (!hflag && file && (nfile > 1 ||
! (rflag && outfn)))
(void) fprintf(stdout, "%s:", file);
(void) fprintf(stdout, "%lld\n", tln);
}
}
--- 420,431 ----
offset = 0;
}
(void) close(temp);
if (cflag && !qflag) {
! if (Hflag || (!hflag && ((nfile > 1) ||
! (rflag && outfn))))
(void) fprintf(stdout, "%s:", file);
(void) fprintf(stdout, "%lld\n", tln);
}
}
*** 421,433 ****
succeed(const char *f)
{
int nchars;
nsucc = (nsucc == 2) ? 2 : 1;
- if (f == NULL)
- f = "<stdin>";
-
if (qflag) {
/* no need to continue */
return (1);
}
--- 433,442 ----
*** 439,449 ****
if (lflag) {
(void) fprintf(stdout, "%s\n", f);
return (1);
}
! if (!hflag && (nfile > 1 || (rflag && outfn))) {
/* print filename */
(void) fprintf(stdout, "%s:", f);
}
if (bflag)
--- 448,458 ----
if (lflag) {
(void) fprintf(stdout, "%s\n", f);
return (1);
}
! if (Hflag || (!hflag && (nfile > 1 || (rflag && outfn)))) {
/* print filename */
(void) fprintf(stdout, "%s:", f);
}
if (bflag)