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

Re: [PATCH/RFC] SunOS grep does not understand -C<n>

From
BCBrandon Casey <brandon.casey.ctr@nrlssc.navy.mil>
Date
Jul 24, 2009, 15:43 UTC
Message-ID
<bkmAA5IX0ZzfCv66mQCX1GFfM5XwTCDPMQk5LjxMd37QH7PwYK29XA@cipher.nrlssc.navy.mil>
In-Reply-To
<7vr5w6tzq8.fsf@alter.siamese.dyndns.org>
Junio C Hamano wrote:
Show 8 quoted lines
> I noticed that the first "grep -C1" test in t7002 does not pass on my 
> SunOS-5.11-i86pc, and that is not because our way to spawn external
> grep is broken, but because the native grep does not understand -C<n>.
> 
> Is it just me and my installation (i.e. I might have failed to install
> saner grep from the distribution that everybody uses), or everybody on
> SunOS is using this option himself because our Makefile doesn't do that
> automatically for them?

Hmm. I have _not_ been setting NO_EXTERNAL_GREP and the tests have _not_ been failing.

The system grep does not seem to have the -C option:
   # /usr/xpg4/bin/grep -C1 include ws.c
   /usr/xpg4/bin/grep: illegal option -- C
   Usage:  grep [-E|-F] [-c|-l|-q] [-bhinsvwx] [file ...]
   grep [-E|-F] [-c|-l|-q] [-bhinsvwx] -e pattern... [-f pattern_file]...[file...]
   grep [-E|-F] [-c|-l|-q] [-bhinsvwx] [-e pattern]... -f pattern_file [file...]
but git grep -C1 works fine
   # git grep -C1 include ws.c
   ws.c-
   ws.c:#include "cache.h"
   ws.c:#include "attr.h"
   ws.c-

I have been compiling with the SUNWspro compiler suite though, and I see these statements in builtin-grep.c:

   #ifndef NO_EXTERNAL_GREP
   #ifdef __unix__
   #define NO_EXTERNAL_GREP 0
   #else
   #define NO_EXTERNAL_GREP 1
   #endif
   #endif

So possibly, the SUNWspro compiler does not set the __unix__ macro. A quick compile of a test program confirms it.

   #include <stdio.h>
   int main (int argc, char* argv[])
   {
   #ifdef __unix__
   	puts("__unix__ is set");
   #else
   	puts("__unix__ is not set");
   #endif
   	return 0;
   }
   # /opt/SUNWspro/bin/cc -o test.out test.c
   ./test.out
   __unix__ is not set
   # gcc -o test.out test.c
   __unix__ is set
So, I have been getting NO_EXTERNAL_GREP all along without knowing it.
-brandon
Previous: Junio C HamanoNext: Junio C Hamano
Message 7 of 8 in “SunOS grep does not understand -C<n>”
  1. SunOS grep does not understand -C<n>Junio C Hamano, Jul 24, 2009
  2. Jeff KingJul 24, 2009
  3. Junio C HamanoJul 24, 2009
  4. Jeff KingJul 24, 2009
  5. FreeBSD iconv function signature is "old"Junio C Hamano, Jul 24, 2009
  6. FreeBSD iconv function signature is "old"Junio C Hamano, Dec 26, 2009
  7. Brandon CaseyJul 24, 2009
  8. Junio C HamanoJul 24, 2009

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.