Date: Tue, 4 Jan 2000 14:33:20 +0200 From: Ruslan Ermilov <ru@freebsd.org> To: Paul Eggert <eggert@twinsun.com> Cc: obrien@NUXI.com, alainm@rcsm.ece.mcgill.ca, freebsd-current@freebsd.org, bug-gnu-utils@gnu.org Subject: Re: Bad 'grep' behaviour in -CURRENT, faulty binary detection? Message-ID: <20000104143320.D10970@relay.ucb.crimea.ua> In-Reply-To: <199911130445.UAA03345@green.twinsun.com>
next in thread | previous in thread | raw e-mail | index | archive | help
--n8g4imXOkfNTN/H1 Content-Type: text/plain; charset=us-ascii On Fri, Nov 12, 1999 at 20:45:10 -0800, Paul Eggert wrote: > > Date: Fri, 12 Nov 1999 17:23:21 -0800 > From: "David O'Brien" <obrien@NUXI.com> > > I assume "--ignore-binary" or "--ignore-binary-files" would be the GNU > longopt. > > Another possibility would be to follow the example of the existing > --directories=ACTION option, e.g. something like this: > > --binary-files=ACTION how to handle binary files > ACTION is 'read', 'skip', or 'summarize' (default) > -I equivalent to --binary-files=skip > -a, --text equivalent to --binary-files=read > Paul, could you please consider applying the following patch (it is against virgin grep-2.4 sources). Could you please also let me know when the Alpha with this feature will be made available, so I could import it into FreeBSD. Or maybe tell me an address of appropriate "announce" mailing list... Thanks, -- Ruslan Ermilov Sysadmin and DBA of the ru@ucb.crimea.ua United Commercial Bank, ru@FreeBSD.org FreeBSD committer, +380.652.247.647 Simferopol, Ukraine http://www.FreeBSD.org The Power To Serve http://www.oracle.com Enabling The Information Age --n8g4imXOkfNTN/H1 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="grep.c.patch" --- grep.c.orig Sat Nov 13 18:31:55 1999 +++ grep.c Tue Jan 4 14:11:09 2000 @@ -60,7 +60,7 @@ /* Short options. */ static char const short_options[] = -"0123456789A:B:C::EFGHUVX:abcd:e:f:hiLlnqrsuvwxyZz"; +"0123456789A:B:C::EFGHIUVX:Y:abcd:e:f:hiLlnqrsuvwxyZz"; /* Long options equivalences. */ static struct option long_options[] = @@ -68,6 +68,7 @@ {"after-context", required_argument, NULL, 'A'}, {"basic-regexp", no_argument, NULL, 'G'}, {"before-context", required_argument, NULL, 'B'}, + {"binary-files", required_argument, NULL, 'Y'}, {"byte-offset", no_argument, NULL, 'b'}, {"context", optional_argument, NULL, 'C'}, {"count", no_argument, NULL, 'c'}, @@ -120,6 +121,14 @@ SKIP_DIRECTORIES } directories; +/* How to handle binary files. */ +static enum + { + SUMMARIZE_BINARIES, + READ_BINARIES, + SKIP_BINARIES + } binaries; + static int ck_atoi PARAMS ((char const *, int *)); static void usage PARAMS ((int)) __attribute__((noreturn)); static void error PARAMS ((const char *, int)); @@ -476,7 +485,6 @@ } /* Flags controlling the style of output. */ -static int always_text; /* Assume the input is always text. */ static int filename_mask; /* If zero, output nulls after filenames. */ static int out_quiet; /* Suppress all normal output. */ static int out_invert; /* Print nonmatching stuff. */ @@ -732,11 +740,14 @@ return nlines; } - not_text = (! (always_text | out_quiet) + not_text = (binaries != READ_BINARIES && memchr (bufbeg, eol ? '\0' : '\200', buflim - bufbeg)); done_on_match += not_text; out_quiet += not_text; + if (not_text && binaries == SKIP_BINARIES) + goto finish_grep; + for (;;) { lastnl = bufbeg; @@ -993,10 +1004,13 @@ -H, --with-filename print the filename for each match\n\ -h, --no-filename suppress the prefixing filename on output\n\ -q, --quiet, --silent suppress all normal output\n\ - -a, --text do not suppress binary output\n\ -d, --directories=ACTION how to handle directories\n\ ACTION is 'read', 'recurse', or 'skip'.\n\ -r, --recursive equivalent to --directories=recurse.\n\ + -Y, --binary-files=ACTION how to handle binary files\n\ + ACTION is 'summarize' (default), 'read', or 'skip'. + -a, --text equivalent to --binary-files=read\n\ + -I equivalent to --binary-files=skip\n\ -L, --files-without-match only print FILE names containing no match\n\ -l, --files-with-matches only print FILE names containing matches\n\ -c, --count only print a count of matching lines per FILE\n\ @@ -1276,7 +1290,7 @@ setmatcher (optarg); break; case 'a': - always_text = 1; + binaries = READ_BINARIES; break; case 'b': out_byte = 1; @@ -1326,6 +1340,9 @@ case 'h': no_filenames = 1; break; + case 'I': + binaries = SKIP_BINARIES; + break; case 'i': case 'y': /* For old-timers . . . */ match_icase = 1; @@ -1363,6 +1380,16 @@ break; case 'x': match_lines = 1; + break; + case 'Y': + if (strcmp (optarg, "summarize") == 0) + binaries = SUMMARIZE_BINARIES; + else if (strcmp (optarg, "read") == 0) + binaries = READ_BINARIES; + else if (strcmp (optarg, "skip") == 0) + binaries = SKIP_BINARIES; + else + fatal (_("unknown binary-files method"), 0); break; case 'Z': filename_mask = 0; --n8g4imXOkfNTN/H1-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20000104143320.D10970>