git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 3/7] grep: --count over binary

From
Dmitry Potapov <dpotapov@gmail.com>
Date
May 14, 2010, 09:34 UTC
Message-ID
<20100514093424.GA6212@dpotapov.dyndns.org>
In-Reply-To
<4BEC62F6.9050602@lsrfire.ath.cx>
On Thu, May 13, 2010 at 10:37:10PM +0200, René Scharfe wrote:
Show 7 quoted lines
> The intent of showing the message "Binary file xyz matches" for
> binary files is to avoid annoying users by potentially messing up
> their terminals by printing control characters.  In --count mode,
> this precaution isn't necessary.
> 
> Display counts of matches if -c/--count was specified, even if -a
> was not given.  GNU grep does the same.

It is also not necessary with '-l' and '-L' options. (At least, if we follow GNU grep).

Show 9 quoted lines
> --- a/grep.c
> +++ b/grep.c
> @@ -802,7 +802,7 @@ static int grep_buffer_1(struct grep_opt *opt, const char *name,
>  
>  	switch (opt->binary) {
>  	case GREP_BINARY_DEFAULT:
> -		if (buffer_is_binary(buf, size))
> +		if (!opt->count && buffer_is_binary(buf, size))
>  			binary_match_only = 1;
So, I believe it should be:
		if (!opt->count && !opt->name_only && !opt->unmatch_name_only &&
				buffer_is_binary(buf, size))
Dmitry
Previous: René ScharfeNext: René Scharfe
Message 5 of 10 in “grep: better support for binary files”
  1. 0/7 grep: better support for binary filesRené Scharfe, May 13, 2010
  2. 1/7 grep: add test script for binary file handlingRené Scharfe, May 13, 2010
  3. 2/7 grep: refactor handling of binary mode optionsRené Scharfe, May 13, 2010
  4. 3/7 grep: --count over binaryRené Scharfe, May 13, 2010
  5. Dmitry PotapovMay 14, 2010
  6. René ScharfeMay 16, 2010
  7. 4/7 grep: use memmem() for fixed string searchRené Scharfe, May 13, 2010
  8. 5/7 grep: continue case insensitive fixed string search after NUL charsRené Scharfe, May 13, 2010
  9. 6/7 grep: add regmatch(), a wrapper for REG_STARTEND handlingRené Scharfe, May 13, 2010
  10. 7/7 grep: use regmatch() for line matchingRené Scharfe, May 13, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.