summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorru <ru@FreeBSD.org>2000-01-18 09:45:11 +0000
committerru <ru@FreeBSD.org>2000-01-18 09:45:11 +0000
commit5b9b49c3cdaddcc4b57202e7fdf055ca9a17cf4b (patch)
tree6a3e9fbebdb4098a110fc0e558643fb8b4db2e24
parentd8d7d228e475566fe145acde42c3569c522cd98c (diff)
downloadFreeBSD-src-5b9b49c3cdaddcc4b57202e7fdf055ca9a17cf4b.zip
FreeBSD-src-5b9b49c3cdaddcc4b57202e7fdf055ca9a17cf4b.tar.gz
Virgin import of a trimmed down GNU Grep 2.4a.
-rw-r--r--gnu/usr.bin/grep/ChangeLog31
-rw-r--r--gnu/usr.bin/grep/NEWS7
-rw-r--r--gnu/usr.bin/grep/THANKS1
-rw-r--r--gnu/usr.bin/grep/doc/grep.texi27
-rw-r--r--gnu/usr.bin/grep/doc/version.texi6
-rw-r--r--gnu/usr.bin/grep/grep.154
-rw-r--r--gnu/usr.bin/grep/grep.c37
-rw-r--r--gnu/usr.bin/grep/savedir.c6
-rw-r--r--gnu/usr.bin/grep/system.h13
9 files changed, 143 insertions, 39 deletions
diff --git a/gnu/usr.bin/grep/ChangeLog b/gnu/usr.bin/grep/ChangeLog
index 3855810..8106528 100644
--- a/gnu/usr.bin/grep/ChangeLog
+++ b/gnu/usr.bin/grep/ChangeLog
@@ -1,3 +1,22 @@
+2000-01-04 Paul Eggert
+
+ Inititial patch from David O'Brien.
+
+ Add --binary-files option.
+ * NEWS, doc/grep.1, doc/grep.texi: Document it.
+ * src/grep.c (BINARY_FILES_OPTION): New constant.
+ (long_options, grep, usage, main): New --binary-files option.
+ (binary_files): New var.
+ * src/system.h (TYPE_SIGNED, TYPE_MINIMUM, TYPE_MAXIMUM, CHAR_MAX):
+ New macros.
+ (INT_MAX, UCHAR_MAX): Define in terms of TYPE_MAXIMUM.
+
+2000-01-04 Paul Eggert
+
+ * savedir.c (savedir): Don't store past the end of an array if
+ name_size is zero and the directory is empty.
+ Reported by Dima Barsky <dima@pwd.hp.com>.
+
1999-11-18 Paul Eggert
* m4/largefile.m4 (AC_SYS_LARGEFILE_FLAGS): Work around a
@@ -46,8 +65,8 @@
* configure.in: drop support for --without-included-regex.
This was generating bogus bug reports, since many GNU/Linux
users have different version of glibc. And glibc maintainers
- decided to drop k&r support.
-
+ decided to drop k&r support.
+
1999-11-01 Arnold D. Robbins
* regex.c (init_syntax_once): move below definition of
@@ -302,7 +321,7 @@ axes.)
1999-06-15 Alain Magloire
- * src/grep.c, doc/grep{1,texi} :
+ * src/grep.c, doc/grep{1,texi} :
--revert-match should be --invert-match.
Correction proposed by Karl Berry.
@@ -337,7 +356,7 @@ axes.)
1999-03-05 Eli Zaretskii
* src/grep.c (main): Print the name of the default matcher instead
- of just "grep".
+ of just "grep".
1999-02-06 Alain Magloire
@@ -349,7 +368,7 @@ axes.)
the input is drained, like this:
status=`echo 'check' | { ${GREP} -E -e pattern >/dev/null 2>&1;
echo $?; cat >/dev/null; }`; if test $status -ne $errnu then ... fi
- Excerpt email from Andreas Schwab.
+ Excerpt email from Andreas Schwab.
1999-02-23 Alain Magloire
@@ -470,7 +489,7 @@ axes.)
* PATCHES-AM: New file. A small patch for automake-1.4, use $(sep)
as the path separator base on @SEP@.
* PATCHES-AC configure.in : updated for autoconf-13.
-
+
1999-01-27 Volker Borchert
* grep.c: fgrep -NUM not working correctly.
diff --git a/gnu/usr.bin/grep/NEWS b/gnu/usr.bin/grep/NEWS
index efeaf41..88701af 100644
--- a/gnu/usr.bin/grep/NEWS
+++ b/gnu/usr.bin/grep/NEWS
@@ -1,3 +1,10 @@
+ - The new option --binary-files=TYPE makes grep assume that a binary input
+ file is of type TYPE.
+ --binary-files='binary' (the default) outputs a 1-line summary of matches.
+ --binary-files='without-match' assumes binary files do not match.
+ --binary-files='text' treats binary files as text
+ (equivalent to -a or --text).
+
Version 2.4:
- egrep is now equivalent to `grep -E' as required by POSIX,
diff --git a/gnu/usr.bin/grep/THANKS b/gnu/usr.bin/grep/THANKS
index 924b6cf..75ecc46 100644
--- a/gnu/usr.bin/grep/THANKS
+++ b/gnu/usr.bin/grep/THANKS
@@ -4,6 +4,7 @@ Andreas Schwab <schwab@suse.de>
Andreas Ley <andy@rz.uni-karlsruhe.de>
Ben Elliston <bje@cygnus.com>
David J MacKenzie <djm@catapult.va.pubnix.com>
+David O'Brien <obrien@freebsd.org>
Eli Zaretskii <eliz@is.elta.co.il>
Florian La Roche <florian@knorke.saar.de>
Franc,ois Pinard <pinard@IRO.UMontreal.CA>
diff --git a/gnu/usr.bin/grep/doc/grep.texi b/gnu/usr.bin/grep/doc/grep.texi
index 50a6938..d71f2c1 100644
--- a/gnu/usr.bin/grep/doc/grep.texi
+++ b/gnu/usr.bin/grep/doc/grep.texi
@@ -275,6 +275,21 @@ This version number should be included in all bug reports.
Print a usage message briefly summarizing these command-line options
and the bug-reporting address, then exit.
+@itemx --binary-files=@var{type}
+@opindex --binary-files
+@cindex binary files
+If the first few bytes of a file indicate that the file contains binary
+data, assume that the file is of type @var{type}. By default,
+@var{type} is @samp{binary}, and @command{grep} normally outputs either
+a one-line message saying that a binary file matches, or no message if
+there is no match. If @var{type} is @samp{without-match},
+@command{grep} assumes that a binary file does not match. If @var{type}
+is @samp{text}, @command{grep} processes a binary file as if it were
+text; this is equivalent to the @samp{-a} or @samp{--text} option.
+@emph{Warning:} @samp{--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.
+
@item -b
@itemx --byte-offset
@opindex -b
@@ -329,16 +344,8 @@ The scanning of every file will stop on the first match.
@opindex --text
@cindex suppress binary data
@cindex binary files
-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, grep outputs only a
-message saying that the file matches the pattern. This
-option causes grep to act as if the file is a text
-file, even if it would otherwise be treated as binary.
-@emph{Warning:} the result might be binary garbage
-printed to the terminal, which can have nasty
-side-effects if the terminal driver interprets some of
-it as commands.
+Process a binary file as if it were text; this is equivalent to the
+@samp{--binary-files=text} option.
@item -w
@itemx --word-regexp
diff --git a/gnu/usr.bin/grep/doc/version.texi b/gnu/usr.bin/grep/doc/version.texi
index 2c6880e..2deace2 100644
--- a/gnu/usr.bin/grep/doc/version.texi
+++ b/gnu/usr.bin/grep/doc/version.texi
@@ -1,3 +1,3 @@
-@set UPDATED 13 November 1999
-@set EDITION 2.4
-@set VERSION 2.4
+@set UPDATED 16 January 2000
+@set EDITION 2.4a
+@set VERSION 2.4a
diff --git a/gnu/usr.bin/grep/grep.1 b/gnu/usr.bin/grep/grep.1
index 0cee267..f6f5485 100644
--- a/gnu/usr.bin/grep/grep.1
+++ b/gnu/usr.bin/grep/grep.1
@@ -12,7 +12,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 \- print lines matching a pattern
@@ -28,6 +28,7 @@ grep, egrep, fgrep \- 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 ]
@@ -143,6 +144,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.
@@ -257,15 +293,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.
@@ -323,9 +353,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 445eeca..80f7470 100644
--- a/gnu/usr.bin/grep/grep.c
+++ b/gnu/usr.bin/grep/grep.c
@@ -62,12 +62,19 @@ static int mmap_option;
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'},
@@ -476,7 +483,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 filename_mask; /* If zero, output nulls after filenames. */
static int out_quiet; /* Suppress all normal output. */
static int out_invert; /* Print nonmatching stuff. */
@@ -729,11 +741,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;
@@ -993,7 +1008,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\
@@ -1276,7 +1293,7 @@ main (argc, argv)
setmatcher (optarg);
break;
case 'a':
- always_text = 1;
+ binary_files = TEXT_BINARY_FILES;
break;
case 'b':
out_byte = 1;
@@ -1370,6 +1387,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;
diff --git a/gnu/usr.bin/grep/savedir.c b/gnu/usr.bin/grep/savedir.c
index 5a9c339..e329717 100644
--- a/gnu/usr.bin/grep/savedir.c
+++ b/gnu/usr.bin/grep/savedir.c
@@ -1,5 +1,5 @@
/* savedir.c -- save the list of files in a directory in a string
- Copyright (C) 1990, 1997, 1998 Free Software Foundation, Inc.
+ Copyright (C) 1990, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -89,6 +89,10 @@ savedir (dir, name_size)
if (dirp == NULL)
return NULL;
+ /* Be sure name_size is at least `1' so there's room for
+ the final NUL byte. */
+ name_size += !name_size;
+
name_space = (char *) malloc (name_size);
if (name_space == NULL)
{
diff --git a/gnu/usr.bin/grep/system.h b/gnu/usr.bin/grep/system.h
index a6966e4..3cd9b56 100644
--- a/gnu/usr.bin/grep/system.h
+++ b/gnu/usr.bin/grep/system.h
@@ -127,11 +127,20 @@ void free();
#ifndef CHAR_BIT
# define CHAR_BIT 8
#endif
+/* The extra casts work around common compiler bugs. */
+#define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
+#define TYPE_MINIMUM(t) ((t) (TYPE_SIGNED (t) \
+ ? ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1) \
+ : (t) 0))
+#define TYPE_MAXIMUM(t) ((t) (~ (t) 0 - TYPE_MINIMUM (t)))
+#ifndef CHAR_MAX
+# define CHAR_MAX TYPE_MAXIMUM (char)
+#endif
#ifndef INT_MAX
-# define INT_MAX 2147483647
+# define INT_MAX TYPE_MAXIMUM (int)
#endif
#ifndef UCHAR_MAX
-# define UCHAR_MAX 255
+# define UCHAR_MAX TYPE_MAXIMUM (unsigned char)
#endif
#if !defined(STDC_HEADERS) && defined(HAVE_STRING_H) && defined(HAVE_MEMORY_H)
OpenPOWER on IntegriCloud