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

*** 30,42 **** /* All Rights Reserved */ /* Copyright (c) 1987, 1988 Microsoft Corporation */ /* All Rights Reserved */ ! %{ ! #pragma ident "%Z%%M% %I% %E% SMI" ! %} /* * egrep -- print lines containing (or not containing) a regular expression * * status returns: --- 30,42 ---- /* All Rights Reserved */ /* Copyright (c) 1987, 1988 Microsoft Corporation */ /* All Rights Reserved */ ! /* ! * Copyright 2013 Damian Bogel. All rights reserved. ! */ /* * egrep -- print lines containing (or not containing) a regular expression * * status returns:
*** 59,68 **** --- 59,70 ---- #include <widec.h> #include <stdlib.h> #include <limits.h> #include <locale.h> + #define STDIN_FILENAME gettext("(standard input)") + #define BLKSIZE 512 /* size of reported disk blocks */ #define EBUFSIZ 8192 #define MAXLIN 350 #define NCHARS 256 #define MAXPOS 4000
*** 108,122 **** long long lnum; int bflag; int cflag; int eflag; int fflag; int hflag; int iflag; int lflag; int nflag; ! int sflag; int vflag; int nfile; long long blkno; long long tln; int nsucc; --- 110,125 ---- long long lnum; int bflag; int cflag; int eflag; int fflag; + int Hflag; int hflag; int iflag; int lflag; int nflag; ! int qflag; int vflag; int nfile; long long blkno; long long tln; int nsucc;
*** 658,668 **** #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, "ybcie:f:hlnvs")) != -1) switch(c) { case 'b': bflag++; continue; --- 661,671 ---- #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, "ybcie:f:Hhlnvs")) != -1) switch(c) { case 'b': bflag++; continue;
*** 684,712 **** gettext("egrep: can't open %s\n"), optarg); exit(2); } continue; case 'h': hflag++; continue; case 'y': case 'i': iflag++; continue; case 'l': lflag++; continue; case 'n': nflag++; continue; ! case 's': ! sflag++; continue; case 'v': vflag++; continue; --- 687,724 ---- gettext("egrep: can't open %s\n"), optarg); exit(2); } continue; + case 'H': + if (!lflag) /* H is excluded by l as in GNU grep */ + Hflag++; + hflag = 0; /* H excludes h */ + continue; + case 'h': hflag++; + Hflag = 0; /* h excludes H */ continue; case 'y': case 'i': iflag++; continue; case 'l': lflag++; + Hflag = 0; /* l excludes H */ continue; case 'n': nflag++; continue; ! case 'q': ! case 's': /* Solaris: legacy option */ ! qflag++; continue; case 'v': vflag++; continue;
*** 797,816 **** gettext("egrep: can't open %s\n"), file); badbotch=1; return; } } else { - file = "<stdin>"; f = stdin; } lnum = 1; tln = 0; if((count = read(fileno(f), buf, EBUFSIZ)) <= 0) { fclose(f); ! if (cflag) { ! if (nfile>1 && !hflag) fprintf(stdout, "%s:", file); fprintf(stdout, "%lld\n", tln); } return; } --- 809,828 ---- gettext("egrep: can't open %s\n"), file); badbotch=1; return; } } else { f = stdin; + file = STDIN_FILENAME; } lnum = 1; tln = 0; if((count = read(fileno(f), buf, EBUFSIZ)) <= 0) { fclose(f); ! if (cflag && !qflag) { ! if (Hflag || (nfile > 1 && !hflag)) fprintf(stdout, "%s:", file); fprintf(stdout, "%lld\n", tln); } return; }
*** 900,922 **** } succ = vflag; break; } } ! if(succ) { nsucc = 1; ! if (cflag) tln++; ! else if (sflag) ! ; /* ugh */ ! else if (lflag) { ! printf("%s\n", file); fclose(f); return; } ! else { ! if (nfile > 1 && !hflag) ! printf(gettext("%s:"), file); if (bflag) { nchars = blkno - (buf + count - ptrend) - 2; if(nlflag) nchars++; printf("%lld:", nchars/BLKSIZE); --- 912,934 ---- } succ = vflag; break; } } ! if (succ) { nsucc = 1; ! if (lflag || qflag) { ! if (!qflag) ! (void) printf("%s\n", file); fclose(f); return; } ! if (cflag) { ! tln++; ! } else { ! if (Hflag || (nfile > 1 && !hflag)) ! printf("%s:", file); if (bflag) { nchars = blkno - (buf + count - ptrend) - 2; if(nlflag) nchars++; printf("%lld:", nchars/BLKSIZE);
*** 942,954 **** lnum++; if (reinit == 1) clearg(); } fclose(f); ! if (cflag) { ! if (nfile > 1 && !hflag) ! printf(gettext("%s:"), file); printf("%lld\n", tln); } } void --- 954,966 ---- lnum++; if (reinit == 1) clearg(); } fclose(f); ! if (cflag && !qflag) { ! if (Hflag || (nfile > 1 && !hflag)) ! printf("%s:", file); printf("%lld\n", tln); } } void