Print this page
3737 grep does not support -H option
Reviewed by: Andy Stormont <andyjstormont@gmail.com>

*** 28,38 **** /* All Rights Reserved */ /* Copyright (c) 1987, 1988 Microsoft Corporation */ /* All Rights Reserved */ ! #pragma ident "%Z%%M% %I% %E% SMI" /* * fgrep -- print all lines containing any of a set of keywords * * status returns: --- 28,40 ---- /* All Rights Reserved */ /* Copyright (c) 1987, 1988 Microsoft Corporation */ /* All Rights Reserved */ ! /* ! * Copyright 2013 Damian Bogel. All rights reserved. ! */ /* * fgrep -- print all lines containing any of a set of keywords * * status returns:
*** 105,114 **** --- 107,117 ---- wchar_t letter(); #define same(a, b) \ (a == b || iflag && (!MULTI_BYTE || ISASCII(a)) && (a ^ b) == ' ' && \ letter(a) == letter(b)) + #define STDIN_FILENAME gettext("(standard input)") #define QSIZE 400 struct words { wchar_t inp; char out;
*** 117,128 **** struct words *fail; } *w = NULL, *smax, *q; FILE *fptr; long long lnum; ! int bflag, cflag, lflag, fflag, nflag, vflag, xflag, eflag, sflag; ! int hflag, iflag; int retcode = 0; int nfile; long long blkno; int nsucc; long long tln; --- 120,131 ---- struct words *fail; } *w = NULL, *smax, *q; FILE *fptr; long long lnum; ! int bflag, cflag, lflag, fflag, nflag, vflag, xflag, eflag, qflag; ! int Hflag, hflag, iflag; int retcode = 0; int nfile; long long blkno; int nsucc; long long tln;
*** 148,165 **** #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, "hybcie:f:lnvxs")) != EOF) switch (c) { ! case 's': ! sflag++; continue; case 'h': hflag++; continue; case 'b': bflag++; continue; --- 151,174 ---- #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, "Hhybcie:f:lnvxqs")) != EOF) switch (c) { ! case 'q': ! case 's': /* Solaris: legacy option */ ! qflag++; continue; + case 'H': + Hflag++; + hflag = 0; + continue; case 'h': hflag++; + Hflag = 0; continue; case 'b': bflag++; continue;
*** 219,229 **** errflg++; } argc -= optind; if (errflg || ((argc <= 0) && !fflag && !eflag)) { ! (void) printf(gettext("usage: fgrep [ -bchilnsvx ] " "[ -e exp ] [ -f file ] [ strings ] [ file ] ...\n")); exit(2); } if (!eflag && !fflag) { argptr = argv[optind]; --- 228,238 ---- errflg++; } argc -= optind; if (errflg || ((argc <= 0) && !fflag && !eflag)) { ! (void) printf(gettext("usage: fgrep [ -bcHhilnqsvx ] " "[ -e exp ] [ -f file ] [ strings ] [ file ] ...\n")); exit(2); } if (!eflag && !fflag) { argptr = argv[optind];
*** 311,322 **** gettext("fgrep: can't open %s\n"), file); retcode = 2; return; } } else { - file = "<stdin>"; fptr = stdin; } ccount = 0; failed = 0; lnum = 1; tln = 0; --- 320,331 ---- gettext("fgrep: can't open %s\n"), file); retcode = 2; return; } } else { fptr = stdin; + file = STDIN_FILENAME; } ccount = 0; failed = 0; lnum = 1; tln = 0;
*** 415,432 **** if ((vflag && (failed == 0 || xflag == 0)) || (vflag == 0 && xflag && failed)) goto nomatch; succeed: nsucc = 1; ! if (cflag) ! tln++; ! else if (lflag && !sflag) { (void) printf("%s\n", file); (void) fclose(fptr); return; ! } else if (!sflag) { ! if (nfile > 1 && !hflag) (void) printf("%s:", file); if (bflag) (void) printf("%lld:", (blkno - (long long)(ccount-1)) / BUFSIZ); --- 424,443 ---- if ((vflag && (failed == 0 || xflag == 0)) || (vflag == 0 && xflag && failed)) goto nomatch; succeed: nsucc = 1; ! if (lflag || qflag) { ! if (!qflag) (void) printf("%s\n", file); (void) fclose(fptr); return; ! } ! if (cflag) { ! tln++; ! } else { ! if (Hflag || (nfile > 1 && !hflag)) (void) printf("%s:", file); if (bflag) (void) printf("%lld:", (blkno - (long long)(ccount-1)) / BUFSIZ);
*** 456,467 **** c = w; failed = 0; } } (void) fclose(fptr); ! if (cflag) { ! if ((nfile > 1) && !hflag) (void) printf("%s:", file); (void) printf("%lld\n", tln); } } --- 467,478 ---- c = w; failed = 0; } } (void) fclose(fptr); ! if (cflag && !qflag) { ! if (Hflag || (nfile > 1 && !hflag)) (void) printf("%s:", file); (void) printf("%lld\n", tln); } }