diff options
author | ru <ru@FreeBSD.org> | 2000-01-18 09:46:39 +0000 |
---|---|---|
committer | ru <ru@FreeBSD.org> | 2000-01-18 09:46:39 +0000 |
commit | 510efd0af660bb070b3efce4fbdf49bc30ddc555 (patch) | |
tree | e58e90f0f4c69d1876065260db5e197825240158 /gnu | |
parent | 36e4acc76686203ceb3d56bc37ea3afdcfc5c6cb (diff) | |
download | FreeBSD-src-510efd0af660bb070b3efce4fbdf49bc30ddc555.zip FreeBSD-src-510efd0af660bb070b3efce4fbdf49bc30ddc555.tar.gz |
Fix conflicts.
Diffstat (limited to 'gnu')
-rw-r--r-- | gnu/usr.bin/grep/grep.1 | 54 | ||||
-rw-r--r-- | gnu/usr.bin/grep/grep.c | 37 |
2 files changed, 74 insertions, 17 deletions
diff --git a/gnu/usr.bin/grep/grep.1 b/gnu/usr.bin/grep/grep.1 index 9a3b05e..995439f 100644 --- a/gnu/usr.bin/grep/grep.1 +++ b/gnu/usr.bin/grep/grep.1 @@ -13,7 +13,7 @@ .de Id .ds Dt \\$4 .. -.Id $Id: grep.1,v 1.7 1999/10/12 20:41:01 alainm Exp $ +.Id $Id: grep.1,v 1.8 2000/01/17 00:55:06 alainm Exp $ .TH GREP 1 \*(Dt "GNU Project" .SH NAME grep, egrep, fgrep, zgrep \- print lines matching a pattern @@ -29,6 +29,7 @@ grep, egrep, fgrep, zgrep \- print lines matching a pattern .IR FILE ] .RB [ \-d .IR ACTION ] +.RB [ \-\^\-binary-files=\fITYPE\fP ] .RB [ \-\^\-directories=\fIACTION\fP ] .RB [ \-\^\-extended-regexp ] .RB [ \-\^\-fixed-strings ] @@ -148,6 +149,41 @@ Print the version number of to standard error. This version number should be included in all bug reports (see below). .TP +.BI \-\^\-binary-files= TYPE +If the first few bytes of a file indicate that the file contains binary +data, assume that the file is of type +.IR TYPE . +By default, +.I TYPE +is +.BR binary , +and +.B grep +normally outputs either +a one-line message saying that a binary file matches, or no message if +there is no match. +If +.I TYPE +is +.BR without-match , +.B grep +assumes that a binary file does not match. +If +.I TYPE +is +.BR text , +.B grep +processes a binary file as if it were text; this is equivalent to the +.B \-a +or +.B \-\^\-text +option. +.I Warning: +.B "grep \-\^\-binary-files=text" +might output binary garbage, +which can have nasty side effects if the output is a terminal and if the +terminal driver interprets some of it as commands. +.TP .BR \-b ", " \-\^\-byte-offset Print the byte offset within the input file before each line of output. @@ -262,15 +298,9 @@ and and should redirect output to /dev/null instead. .TP .BR \-a ", " \-\^\-text -Do not suppress output lines that contain binary data. -Normally, if the first few bytes of a file indicate that -the file contains binary data, -.B grep -outputs only a message saying that the file matches the pattern. -This option causes -.B grep -to act as if the file is a text file, -even if it would otherwise be treated as binary. +Process a binary file as if it were text; this is equivalent to the +.B \-\^\-binary-files=text +option. .TP .BR \-v ", " \-\^\-invert-match Invert the sense of matching, to select non-matching lines. @@ -328,9 +358,9 @@ system call to read input, instead of the default .BR read (2) system call. In some situations, -.B -\^-mmap +.B \-\^\-mmap yields better performance. However, -.B -\^-mmap +.B \-\^\-mmap can cause undefined behavior (including core dumps) if an input file shrinks while .B grep diff --git a/gnu/usr.bin/grep/grep.c b/gnu/usr.bin/grep/grep.c index a45df88..551a08c 100644 --- a/gnu/usr.bin/grep/grep.c +++ b/gnu/usr.bin/grep/grep.c @@ -68,12 +68,19 @@ static int filename_mask; static char const short_options[] = "0123456789A:B:C::EFGHUVX:abcd:e:f:hiLlnqrsuvwxyZz"; +/* Non-boolean long options that have no corresponding short equivalents. */ +enum +{ + BINARY_FILES_OPTION = CHAR_MAX + 1 +}; + /* Long options equivalences. */ static struct option long_options[] = { {"after-context", required_argument, NULL, 'A'}, {"basic-regexp", no_argument, NULL, 'G'}, {"before-context", required_argument, NULL, 'B'}, + {"binary-files", required_argument, NULL, BINARY_FILES_OPTION}, {"byte-offset", no_argument, NULL, 'b'}, {"context", optional_argument, NULL, 'C'}, {"count", no_argument, NULL, 'c'}, @@ -511,7 +518,12 @@ fillbuf (save, stats) } /* Flags controlling the style of output. */ -static int always_text; /* Assume the input is always text. */ +static enum + { + BINARY_BINARY_FILES, + TEXT_BINARY_FILES, + WITHOUT_MATCH_BINARY_FILES + } binary_files; /* How to handle binary files. */ static int out_quiet; /* Suppress all normal output. */ static int out_invert; /* Print nonmatching stuff. */ static int out_file; /* Print filenames. */ @@ -768,11 +780,14 @@ grep (fd, file, stats) { if (! (is_EISDIR (errno, file) && suppress_errors)) error (filename, errno); - return nlines; + return 0; } - not_text = (! (always_text | out_quiet) + not_text = (((binary_files == BINARY_BINARY_FILES && !out_quiet) + || binary_files == WITHOUT_MATCH_BINARY_FILES) && memchr (bufbeg, eol ? '\0' : '\200', buflim - bufbeg)); + if (not_text && binary_files == WITHOUT_MATCH_BINARY_FILES) + return 0; done_on_match += not_text; out_quiet += not_text; @@ -1038,7 +1053,9 @@ Output control:\n\ -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\ + -a, --text equivalent to --binary-files=text\n\ + --binary-files=TYPE assume that binary files are TYPE\n\ + TYPE is 'binary', 'text', or 'without-match'.\n\ -d, --directories=ACTION how to handle directories\n\ ACTION is 'read', 'recurse', or 'skip'.\n\ -r, --recursive equivalent to --directories=recurse.\n\ @@ -1328,7 +1345,7 @@ main (argc, argv) setmatcher (optarg); break; case 'a': - always_text = 1; + binary_files = TEXT_BINARY_FILES; break; case 'b': out_byte = 1; @@ -1427,6 +1444,16 @@ main (argc, argv) case 'z': eolbyte = '\0'; break; + case BINARY_FILES_OPTION: + if (strcmp (optarg, "binary") == 0) + binary_files = BINARY_BINARY_FILES; + else if (strcmp (optarg, "text") == 0) + binary_files = TEXT_BINARY_FILES; + else if (strcmp (optarg, "without-match") == 0) + binary_files = WITHOUT_MATCH_BINARY_FILES; + else + fatal (_("unknown binary-files type"), 0); + break; case 0: /* long options */ break; |