Print this page
3737 grep does not support -H option
*** 52,61 ****
--- 52,63 ----
#include <unistd.h>
#include <wctype.h>
#include <ftw.h>
#include <sys/param.h>
+ #define STDIN_FILENAME gettext("(standard input)")
+
#define BSIZE 512 /* Size of block for -b */
#define BUFSIZE 8192 /* Input buffer size */
#define MAX_DEPTH 1000 /* how deep to recurse */
#define M_CSETSIZE 256 /* singlebyte chars */
*** 78,87 ****
--- 80,90 ----
static uchar_t fgrep = 0; /* Invoked as fgrep */
static uchar_t egrep = 0; /* Invoked as egrep */
static uchar_t nvflag = 1; /* 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 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 */
*** 153,163 ****
if (*ap == 'f' || *ap == 'F') {
fgrep++;
}
}
! while ((c = getopt(argc, argv, "vwchilnrbse:f:qxEFIR")) != EOF) {
switch (c) {
case 'v': /* POSIX: negate matches */
nvflag = 0;
break;
--- 156,166 ----
if (*ap == 'f' || *ap == 'F') {
fgrep++;
}
}
! while ((c = getopt(argc, argv, "vwchHilnrbse:f:qxEFIR")) != EOF) {
switch (c) {
case 'v': /* POSIX: negate matches */
nvflag = 0;
break;
*** 214,225 ****
--- 217,236 ----
cmdname);
exit(2);
}
*(file_list + n_file - 1) = optarg;
break;
+
+ /* based on options order h or H is set as in GNU grep */
case 'h': /* Solaris: supress printing of file name */
hflag = 1;
+ Hflag = 0;
+ break;
+ /* Solaris: precede every matching with file name */
+ case 'H':
+ Hflag = 1;
+ hflag = 0;
break;
case 'q': /* POSIX: quiet: status only */
qflag++;
break;
*** 292,301 ****
--- 303,318 ----
*/
if (Eflag && Fflag)
usage();
/*
+ * -l overrides -H like in GNU grep
+ */
+ if (lflag)
+ Hflag = 0;
+
+ /*
* -c, -l and -q flags are mutually exclusive
* We have -c override -l like in Solaris.
* -q overrides -l & -c programmatically in grep() function.
*/
if (cflag && lflag)
*** 344,356 ****
*/
fixpatterns();
/* Process all files: stdin, or rest of arg list */
if (argc < 2) {
! matched = grep(0, gettext("(standard input)"));
} else {
! if (argc > 2 && hflag == 0)
outfn = 1; /* Print filename on match line */
for (argv++; *argv != NULL; argv++) {
process_path(*argv);
}
}
--- 361,373 ----
*/
fixpatterns();
/* Process all files: stdin, or rest of arg list */
if (argc < 2) {
! matched = grep(0, STDIN_FILENAME);
} else {
! if (Hflag || (argc > 2 && hflag == 0))
outfn = 1; /* Print filename on match line */
for (argv++; *argv != NULL; argv++) {
process_path(*argv);
}
}
*** 1110,1120 ****
if (lflag) {
(void) printf("%s\n", fn);
break;
}
if (!cflag) {
! if (outfn) {
(void) printf("%s:", fn);
}
if (bflag) {
(void) printf("%lld:", (offset_t)
(line_offset / BSIZE));
--- 1127,1137 ----
if (lflag) {
(void) printf("%s\n", fn);
break;
}
if (!cflag) {
! if (Hflag || outfn) {
(void) printf("%s:", fn);
}
if (bflag) {
(void) printf("%lld:", (offset_t)
(line_offset / BSIZE));
*** 1137,1147 ****
line_offset += line_len + 1;
ptr = ptrend + 1;
}
if (cflag) {
! if (outfn) {
(void) printf("%s:", fn);
}
if (!qflag) {
(void) printf("%lld\n", matches);
}
--- 1154,1164 ----
line_offset += line_len + 1;
ptr = ptrend + 1;
}
if (cflag) {
! if (Hflag || outfn) {
(void) printf("%s:", fn);
}
if (!qflag) {
(void) printf("%lld\n", matches);
}
*** 1156,1204 ****
usage(void)
{
if (egrep || fgrep) {
(void) fprintf(stderr, gettext("Usage:\t%s"), cmdname);
(void) fprintf(stderr,
! gettext(" [-c|-l|-q] [-r|-R] [-bhinsvx] "
"pattern_list [file ...]\n"));
(void) fprintf(stderr, "\t%s", cmdname);
(void) fprintf(stderr,
! gettext(" [-c|-l|-q] [-r|-R] [-bhinsvx] "
"[-e pattern_list]... "
"[-f pattern_file]... [file...]\n"));
} else {
(void) fprintf(stderr, gettext("Usage:\t%s"), cmdname);
(void) fprintf(stderr,
! gettext(" [-c|-l|-q] [-r|-R] [-bhinsvwx] "
"pattern_list [file ...]\n"));
(void) fprintf(stderr, "\t%s", cmdname);
(void) fprintf(stderr,
! gettext(" [-c|-l|-q] [-r|-R] [-bhinsvwx] "
"[-e pattern_list]... "
"[-f pattern_file]... [file...]\n"));
(void) fprintf(stderr, "\t%s", cmdname);
(void) fprintf(stderr,
! gettext(" -E [-c|-l|-q] [-r|-R] [-bhinsvx] "
"pattern_list [file ...]\n"));
(void) fprintf(stderr, "\t%s", cmdname);
(void) fprintf(stderr,
! gettext(" -E [-c|-l|-q] [-r|-R] [-bhinsvx] "
"[-e pattern_list]... "
"[-f pattern_file]... [file...]\n"));
(void) fprintf(stderr, "\t%s", cmdname);
(void) fprintf(stderr,
! gettext(" -F [-c|-l|-q] [-r|-R] [-bhinsvx] "
"pattern_list [file ...]\n"));
(void) fprintf(stderr, "\t%s", cmdname);
(void) fprintf(stderr,
! gettext(" -F [-c|-l|-q] [-bhinsvx] [-e pattern_list]... "
"[-f pattern_file]... [file...]\n"));
}
exit(2);
/* NOTREACHED */
}
--- 1173,1221 ----
usage(void)
{
if (egrep || fgrep) {
(void) fprintf(stderr, gettext("Usage:\t%s"), cmdname);
(void) fprintf(stderr,
! gettext(" [-c|-l|-q] [-r|-R] [-bhHinsvx] "
"pattern_list [file ...]\n"));
(void) fprintf(stderr, "\t%s", cmdname);
(void) fprintf(stderr,
! gettext(" [-c|-l|-q] [-r|-R] [-bhHinsvx] "
"[-e pattern_list]... "
"[-f pattern_file]... [file...]\n"));
} else {
(void) fprintf(stderr, gettext("Usage:\t%s"), cmdname);
(void) fprintf(stderr,
! gettext(" [-c|-l|-q] [-r|-R] [-bhHinsvwx] "
"pattern_list [file ...]\n"));
(void) fprintf(stderr, "\t%s", cmdname);
(void) fprintf(stderr,
! gettext(" [-c|-l|-q] [-r|-R] [-bhHinsvwx] "
"[-e pattern_list]... "
"[-f pattern_file]... [file...]\n"));
(void) fprintf(stderr, "\t%s", cmdname);
(void) fprintf(stderr,
! gettext(" -E [-c|-l|-q] [-r|-R] [-bhHinsvx] "
"pattern_list [file ...]\n"));
(void) fprintf(stderr, "\t%s", cmdname);
(void) fprintf(stderr,
! gettext(" -E [-c|-l|-q] [-r|-R] [-bhHinsvx] "
"[-e pattern_list]... "
"[-f pattern_file]... [file...]\n"));
(void) fprintf(stderr, "\t%s", cmdname);
(void) fprintf(stderr,
! gettext(" -F [-c|-l|-q] [-r|-R] [-bhHinsvx] "
"pattern_list [file ...]\n"));
(void) fprintf(stderr, "\t%s", cmdname);
(void) fprintf(stderr,
! gettext(" -F [-c|-l|-q] [-bhHinsvx] [-e pattern_list]... "
"[-f pattern_file]... [file...]\n"));
}
exit(2);
/* NOTREACHED */
}