Print this page
3737 grep does not support -H option

*** 34,43 **** --- 34,47 ---- * */ /* Copyright 2012 Nexenta Systems, Inc. All rights reserved. */ + /* + * Copyright 2013 Damian Bogel. All rights reserved. + */ + #include <string.h> #include <stdlib.h> #include <ctype.h> #include <stdarg.h> #include <regex.h>
*** 52,61 **** --- 56,67 ---- #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 **** --- 84,94 ---- 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; --- 160,170 ---- 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 **** --- 221,240 ---- 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 **** --- 307,322 ---- */ 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); } } --- 365,377 ---- */ 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)); --- 1131,1141 ---- 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); } --- 1158,1168 ---- 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 */ } --- 1177,1225 ---- 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 */ }