diff options
Diffstat (limited to 'gnu/usr.bin/grep')
-rw-r--r-- | gnu/usr.bin/grep/Makefile | 53 | ||||
-rw-r--r-- | gnu/usr.bin/grep/config.h | 209 | ||||
-rw-r--r-- | gnu/usr.bin/grep/dfa.c | 44 | ||||
-rw-r--r-- | gnu/usr.bin/grep/dfa.h | 2 | ||||
-rw-r--r-- | gnu/usr.bin/grep/doc/Makefile | 6 | ||||
-rw-r--r-- | gnu/usr.bin/grep/getopt.c | 2 | ||||
-rw-r--r-- | gnu/usr.bin/grep/getopt.h | 2 | ||||
-rw-r--r-- | gnu/usr.bin/grep/getpagesize.h | 2 | ||||
-rw-r--r-- | gnu/usr.bin/grep/grep.1 | 84 | ||||
-rw-r--r-- | gnu/usr.bin/grep/grep.c | 108 | ||||
-rw-r--r-- | gnu/usr.bin/grep/grep.h | 2 | ||||
-rw-r--r-- | gnu/usr.bin/grep/kwset.c | 2 | ||||
-rw-r--r-- | gnu/usr.bin/grep/kwset.h | 2 | ||||
-rw-r--r-- | gnu/usr.bin/grep/obstack.c | 2 | ||||
-rw-r--r-- | gnu/usr.bin/grep/obstack.h | 2 | ||||
-rw-r--r-- | gnu/usr.bin/grep/search.c | 6 |
16 files changed, 442 insertions, 86 deletions
diff --git a/gnu/usr.bin/grep/Makefile b/gnu/usr.bin/grep/Makefile new file mode 100644 index 0000000..60dddfe --- /dev/null +++ b/gnu/usr.bin/grep/Makefile @@ -0,0 +1,53 @@ +# $FreeBSD$ + +GREP_LIBZ=YES + +PROG= grep +SRCS= dfa.c getopt.c getopt1.c grep.c kwset.c obstack.c savedir.c search.c \ + stpcpy.c + +CFLAGS+=-I${.CURDIR} -DHAVE_CONFIG_H + +LINKS+= ${BINDIR}/grep ${BINDIR}/egrep \ + ${BINDIR}/grep ${BINDIR}/fgrep +MLINKS= grep.1 egrep.1 grep.1 fgrep.1 + +DPADD+= ${LIBGNUREGEX} +LDADD+= -lgnuregex + +.if defined(GREP_LIBZ) && !empty(GREP_LIBZ) +LDADD+= -lz +DPADD+= ${LIBZ} +CFLAGS+=-DHAVE_LIBZ=1 +LINKS+= ${BINDIR}/grep ${BINDIR}/zgrep \ + ${BINDIR}/grep ${BINDIR}/zegrep \ + ${BINDIR}/grep ${BINDIR}/zfgrep +MLINKS+=grep.1 zgrep.1 grep.1 zegrep.1 grep.1 zfgrep.1 +.endif + +# XXX: cannot build docs until our texinfo system is updated to understand +# "command{foo}". +# SUBDIR+=doc + +check: all + @failed=0; total=0; \ + for tst in ${TESTS}; do \ + total=$$(($$total+1)); \ + if GREP=${.OBJDIR}/${PROG} srcdir=${.CURDIR}/tests \ + ${.CURDIR}/tests/$$tst; then \ + echo "PASS: $$tst"; \ + else \ + failed=$$(($$failed+1)); \ + echo "FAIL: $$tst"; \ + fi; \ + done; \ + if [ "$$failed" -eq 0 ]; then \ + echo "All $$total tests passed"; \ + else \ + echo "$$failed of $$total tests failed"; \ + fi + +TESTS= warning.sh khadafy.sh spencer1.sh bre.sh ere.sh status.sh empty.sh \ + options.sh + +.include <bsd.prog.mk> diff --git a/gnu/usr.bin/grep/config.h b/gnu/usr.bin/grep/config.h new file mode 100644 index 0000000..a20456c --- /dev/null +++ b/gnu/usr.bin/grep/config.h @@ -0,0 +1,209 @@ +/* $FreeBSD$ */ + +/* config.h. Generated automatically by configure. */ +/* config.hin. Generated automatically from configure.in by autoheader. */ + +/* Define if using alloca.c. */ +/* #undef C_ALLOCA */ + +/* Define if the closedir function returns void instead of int. */ +/* #undef CLOSEDIR_VOID */ + +/* Define to empty if the keyword does not work. */ +/* #undef const */ + +/* Define to one of _getb67, GETB67, getb67 for Cray-2 and Cray-YMP systems. + This function is required for alloca.c support on those systems. */ +/* #undef CRAY_STACKSEG_END */ + +/* Define if you have alloca, as a function or macro. */ +#define HAVE_ALLOCA 1 + +/* Define if you have <alloca.h> and it should be used (not on Ultrix). */ +/* #undef HAVE_ALLOCA_H */ + +/* Define if you have a working `mmap' system call. */ +#define HAVE_MMAP 1 + +/* Define as __inline if that's what the C compiler calls it. */ +/* #undef inline */ + +/* Define to `long' if <sys/types.h> doesn't define. */ +/* #undef off_t */ + +/* Define to `unsigned' if <sys/types.h> doesn't define. */ +/* #undef size_t */ + +/* If using the C implementation of alloca, define if you know the + direction of stack growth for your system; otherwise it will be + automatically deduced at run-time. + STACK_DIRECTION > 0 => grows toward higher addresses + STACK_DIRECTION < 0 => grows toward lower addresses + STACK_DIRECTION = 0 => direction of growth unknown + */ +/* #undef STACK_DIRECTION */ + +/* Define if the `S_IS*' macros in <sys/stat.h> do not work properly. */ +/* #undef STAT_MACROS_BROKEN */ + +/* Define if you have the ANSI C header files. */ +#define STDC_HEADERS 1 + +/* Define to use grep's error-checking malloc in the kwset routines. */ +#define GREP 1 + +/* Package name. */ +#define PACKAGE "grep" + +/* Version number. */ +#define VERSION "2.4" + +/* Define to `int' if <sys/types.h> doesn't define. */ +/* #undef ssize_t */ + +/* Hack for Visual C++ suggested by irox. */ +/* #undef alloca */ + +/* #undef HAVE_STPCPY */ + +/* #undef ENABLE_NLS */ + +/* #undef HAVE_CATGETS */ + +/* #undef HAVE_GETTEXT */ + +#define HAVE_LC_MESSAGES 1 + +/* + * DOS specific + */ +/* #undef HAVE_DOS_FILE_NAMES */ + +/* Define if you have the __argz_count function. */ +/* #undef HAVE___ARGZ_COUNT */ + +/* Define if you have the __argz_next function. */ +/* #undef HAVE___ARGZ_NEXT */ + +/* Define if you have the __argz_stringify function. */ +/* #undef HAVE___ARGZ_STRINGIFY */ + +/* Define if you have the btowc function. */ +/* #undef HAVE_BTOWC */ + +/* Define if you have the dcgettext function. */ +/* #undef HAVE_DCGETTEXT */ + +/* Define if you have the getcwd function. */ +#define HAVE_GETCWD 1 + +/* Define if you have the getpagesize function. */ +#define HAVE_GETPAGESIZE 1 + +/* Define if you have the isascii function. */ +#define HAVE_ISASCII 1 + +/* Define if you have the memchr function. */ +#define HAVE_MEMCHR 1 + +/* Define if you have the memmove function. */ +#define HAVE_MEMMOVE 1 + +/* Define if you have the munmap function. */ +#define HAVE_MUNMAP 1 + +/* Define if you have the putenv function. */ +#define HAVE_PUTENV 1 + +/* Define if you have the setenv function. */ +#define HAVE_SETENV 1 + +/* Define if you have the setlocale function. */ +#define HAVE_SETLOCALE 1 + +/* Define if you have the setmode function. */ +#define HAVE_SETMODE 1 + +/* Define if you have the stpcpy function. */ +/* #undef HAVE_STPCPY */ + +/* Define if you have the strcasecmp function. */ +#define HAVE_STRCASECMP 1 + +/* Define if you have the strchr function. */ +#define HAVE_STRCHR 1 + +/* Define if you have the strdup function. */ +#define HAVE_STRDUP 1 + +/* Define if you have the strerror function. */ +#define HAVE_STRERROR 1 + +/* Define if you have the wctype function. */ +/* #undef HAVE_WCTYPE */ + +/* Define if you have the <argz.h> header file. */ +/* #undef HAVE_ARGZ_H */ + +/* Define if you have the <dirent.h> header file. */ +#define HAVE_DIRENT_H 1 + +/* Define if you have the <libintl.h> header file. */ +/* #undef HAVE_LIBINTL_H */ + +/* Define if you have the <limits.h> header file. */ +#define HAVE_LIMITS_H 1 + +/* Define if you have the <locale.h> header file. */ +#define HAVE_LOCALE_H 1 + +/* Define if you have the <malloc.h> header file. */ +/* #undef HAVE_MALLOC_H */ + +/* Define if you have the <memory.h> header file. */ +#define HAVE_MEMORY_H 1 + +/* Define if you have the <ndir.h> header file. */ +/* #undef HAVE_NDIR_H */ + +/* Define if you have the <nl_types.h> header file. */ +#define HAVE_NL_TYPES_H 1 + +/* Define if you have the <stdlib.h> header file. */ +#define HAVE_STDLIB_H 1 + +/* Define if you have the <string.h> header file. */ +#define HAVE_STRING_H 1 + +/* Define if you have the <sys/dir.h> header file. */ +/* #undef HAVE_SYS_DIR_H */ + +/* Define if you have the <sys/ndir.h> header file. */ +/* #undef HAVE_SYS_NDIR_H */ + +/* Define if you have the <sys/param.h> header file. */ +#define HAVE_SYS_PARAM_H 1 + +/* Define if you have the <unistd.h> header file. */ +#define HAVE_UNISTD_H 1 + +/* Define if you have the <wchar.h> header file. */ +/* #undef HAVE_WCHAR_H */ + +/* Define if you have the <wctype.h> header file. */ +/* #undef HAVE_WCTYPE_H */ + +/* Define if you have the i library (-li). */ +/* #undef HAVE_LIBI */ + +/* Number of bits in a file offset, on hosts where this is settable. */ +/* #undef _FILE_OFFSET_BITS */ + +/* Define to make fseeko etc. visible, on some hosts. */ +/* #undef _LARGEFILE_SOURCE */ + +/* Define for large files, on AIX-style hosts. */ +/* #undef _LARGE_FILES */ + +/* Define if compiler has function prototypes */ +#define PROTOTYPES 1 diff --git a/gnu/usr.bin/grep/dfa.c b/gnu/usr.bin/grep/dfa.c index 40a926b..1fcf549 100644 --- a/gnu/usr.bin/grep/dfa.c +++ b/gnu/usr.bin/grep/dfa.c @@ -18,6 +18,8 @@ /* Written June, 1988 by Mike Haertel Modified July, 1988 by Arthur David Olson to assist BMG speedups */ +/* $FreeBSD$ */ + #ifdef HAVE_CONFIG_H #include <config.h> #endif @@ -90,7 +92,11 @@ extern void free(); # endif #endif +#ifdef __FreeBSD__ +#include <gnuregex.h> +#else #include "regex.h" +#endif #include "dfa.h" /* HPUX, define those as macros in sys/param.h */ @@ -144,6 +150,25 @@ static char **comsubs PARAMS ((char *left, char *right)); static char **addlists PARAMS ((char **old, char **new)); static char **inboth PARAMS ((char **left, char **right)); +#ifdef __FreeBSD__ +static int +collate_range_cmp(c1, c2) + int c1, c2; +{ + static char s1[2], s2[2]; + int r; + + if (c1 == c2) + return 0; + s1[0] = c1; + s2[0] = c2; + if ((r = strcoll(s1, s2)) == 0) + r = c1 - c2; + + return r; +} +#endif + static ptr_t xcalloc(n, s) size_t n; @@ -751,6 +776,24 @@ lex() } else c2 = c; +#ifdef __FreeBSD__ + if (collate_range_cmp(c, c2) <= 0) + { + token c3; + + for (c3 = 0; c3 < NOTCHAR; ++c3) { + if (collate_range_cmp(c, c3) <= 0 && + collate_range_cmp(c3, c2) <= 0) { + setbit(c3, ccl); + if (case_fold) + if (ISUPPER(c3)) + setbit(tolower(c3), ccl); + else if (ISLOWER(c)) + setbit(toupper(c3), ccl); + } + } + } +#else while (c <= c2) { setbit(c, ccl); @@ -761,6 +804,7 @@ lex() setbit(toupper(c), ccl); ++c; } +#endif skip: ; } diff --git a/gnu/usr.bin/grep/dfa.h b/gnu/usr.bin/grep/dfa.h index f2fef4b..2a7fed2 100644 --- a/gnu/usr.bin/grep/dfa.h +++ b/gnu/usr.bin/grep/dfa.h @@ -17,6 +17,8 @@ /* Written June, 1988 by Mike Haertel */ +/* $FreeBSD$ */ + /* FIXME: 2. We should not export so much of the DFA internals. In addition to clobbering modularity, we eat up valuable diff --git a/gnu/usr.bin/grep/doc/Makefile b/gnu/usr.bin/grep/doc/Makefile new file mode 100644 index 0000000..82620f9 --- /dev/null +++ b/gnu/usr.bin/grep/doc/Makefile @@ -0,0 +1,6 @@ +# $FreeBSD$ + +INFO= grep +INFOSECTION= "System Utilities" + +.include <bsd.info.mk> diff --git a/gnu/usr.bin/grep/getopt.c b/gnu/usr.bin/grep/getopt.c index eac576b..f919ed7 100644 --- a/gnu/usr.bin/grep/getopt.c +++ b/gnu/usr.bin/grep/getopt.c @@ -23,6 +23,8 @@ License along with the GNU C Library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + +/* $FreeBSD$ */ /* This tells Alpha OSF/1 not to define a getopt prototype in <stdio.h>. Ditto for AIX 3.2 and <stdlib.h>. */ diff --git a/gnu/usr.bin/grep/getopt.h b/gnu/usr.bin/grep/getopt.h index 2d8c8f9..4209871 100644 --- a/gnu/usr.bin/grep/getopt.h +++ b/gnu/usr.bin/grep/getopt.h @@ -19,6 +19,8 @@ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +/* $FreeBSD$ */ + #ifndef _GETOPT_H #define _GETOPT_H 1 diff --git a/gnu/usr.bin/grep/getpagesize.h b/gnu/usr.bin/grep/getpagesize.h index a064973..4d562216 100644 --- a/gnu/usr.bin/grep/getpagesize.h +++ b/gnu/usr.bin/grep/getpagesize.h @@ -1,5 +1,7 @@ /* Emulate getpagesize on systems that lack it. */ +/* $FreeBSD$ */ + #ifndef HAVE_GETPAGESIZE # ifdef VMS diff --git a/gnu/usr.bin/grep/grep.1 b/gnu/usr.bin/grep/grep.1 index f6f5485..9a3b05e 100644 --- a/gnu/usr.bin/grep/grep.1 +++ b/gnu/usr.bin/grep/grep.1 @@ -1,4 +1,5 @@ .\" grep man page +.\" $FreeBSD$ .if !\n(.g \{\ . if !\w|\*(lq| \{\ . ds lq `` @@ -12,10 +13,10 @@ .de Id .ds Dt \\$4 .. -.Id $Id: grep.1,v 1.8 2000/01/17 00:55:06 alainm Exp $ +.Id $Id: grep.1,v 1.7 1999/10/12 20:41:01 alainm Exp $ .TH GREP 1 \*(Dt "GNU Project" .SH NAME -grep, egrep, fgrep \- print lines matching a pattern +grep, egrep, fgrep, zgrep \- print lines matching a pattern .SH SYNOPSIS .B grep .RB [ \- [ ABC ] @@ -28,7 +29,6 @@ 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 ] @@ -61,10 +61,11 @@ grep, egrep, fgrep \- print lines matching a pattern .RB [ \-\^\-mmap ] .RB [ \-\^\-null ] .RB [ \-\^\-recursive ] +.RB [ \-\^\-decompress ] .RI [ file .\|.\|.] .SH DESCRIPTION .PP -.B Grep +.B grep searches the named input .I files (or standard input if no files are named, or @@ -103,12 +104,15 @@ In addition, two variant programs and .B fgrep are available. -.B Egrep +.B egrep is the same as .BR "grep\ \-E" . -.B Fgrep +.B fgrep is the same as .BR "grep\ \-F" . +.B zgrep +is the same as +.BR "grep\ \-Z" . .PD .PP All variants of @@ -144,41 +148,6 @@ 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. @@ -293,9 +262,15 @@ and and should redirect output to /dev/null instead. .TP .BR \-a ", " \-\^\-text -Process a binary file as if it were text; this is equivalent to the -.B \-\^\-binary-files=text -option. +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. .TP .BR \-v ", " \-\^\-invert-match Invert the sense of matching, to select non-matching lines. @@ -353,9 +328,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 @@ -379,13 +354,20 @@ and to process arbitrary file names, even those that contain newline characters. .PD +.LP +Following option is only available if compiled with zlib(3) library: +.PD 0 +.TP +.B \-Z, --decompress +Decompress the input data before searching. +.PD .SH "REGULAR EXPRESSIONS" .PP A regular expression is a pattern that describes a set of strings. Regular expressions are constructed analogously to arithmetic expressions, by using various operators to combine smaller expressions. .PP -.B Grep +.B grep understands two different versions of regular expression syntax: \*(lqbasic\*(rq and \*(lqextended.\*(rq In .RB "\s-1GNU\s0\ " grep , @@ -578,6 +560,14 @@ searches for the two-character string instead of reporting a syntax error in the regular expression. \s-1POSIX.2\s0 allows this behavior as an extension, but portable scripts should avoid it. +.SH ENVIRONMENT +The environment variable +.B GREP_OPTIONS +can hold a set of default +options for +.I grep. +These options are interpreted first and can be overwritten by explicit command +line parameters. .SH DIAGNOSTICS .PP Normally, exit status is 0 if matches were found, diff --git a/gnu/usr.bin/grep/grep.c b/gnu/usr.bin/grep/grep.c index 80f7470..a45df88 100644 --- a/gnu/usr.bin/grep/grep.c +++ b/gnu/usr.bin/grep/grep.c @@ -17,6 +17,9 @@ 02111-1307, USA. */ /* Written July 1992 by Mike Haertel. */ +/* Builtin decompression 1997 by Wolfram Schneider <wosch@FreeBSD.org>. */ + +/* $FreeBSD$ */ #ifdef HAVE_CONFIG_H # include <config.h> @@ -58,23 +61,19 @@ static int show_version; /* If nonzero, use mmap if possible. */ static int mmap_option; +/* If zero, output nulls after filenames. */ +static int filename_mask; + /* Short options. */ 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'}, @@ -92,7 +91,12 @@ static struct option long_options[] = {"mmap", no_argument, &mmap_option, 1}, {"no-filename", no_argument, NULL, 'h'}, {"no-messages", no_argument, NULL, 's'}, +#if HAVE_LIBZ > 0 + {"decompress", no_argument, NULL, 'Z'}, + {"null", no_argument, &filename_mask, 0}, +#else {"null", no_argument, NULL, 'Z'}, +#endif {"null-data", no_argument, NULL, 'z'}, {"quiet", no_argument, NULL, 'q'}, {"recursive", no_argument, NULL, 'r'}, @@ -109,6 +113,7 @@ static struct option long_options[] = }; /* Define flags declared in grep.h. */ +char const *matcher; int match_icase; int match_words; int match_lines; @@ -245,6 +250,12 @@ static int bufmapped; /* True if buffer is memory-mapped. */ static off_t initial_bufoffset; /* Initial value of bufoffset. */ #endif +#if HAVE_LIBZ > 0 +#include <zlib.h> +static gzFile gzbufdesc; /* zlib file descriptor. */ +static int Zflag; /* uncompress before searching. */ +#endif + /* Return VAL aligned to the next multiple of ALIGNMENT. VAL can be an integer or a pointer. Both args must be free of side effects. */ #define ALIGN_TO(val, alignment) \ @@ -306,6 +317,14 @@ reset (fd, file, stats) || ! (buffer = page_alloc (bufalloc + 1, &ubuffer))) fatal (_("memory exhausted"), 0); } +#if HAVE_LIBZ > 0 + if (Zflag) + { + gzbufdesc = gzdopen(fd, "r"); + if (gzbufdesc == NULL) + fatal(_("memory exhausted"), 0); + } +#endif buflim = buffer; bufdesc = fd; @@ -317,7 +336,11 @@ reset (fd, file, stats) } if (directories == SKIP_DIRECTORIES && S_ISDIR (stats->stat.st_mode)) return 0; - if (S_ISREG (stats->stat.st_mode)) + if ( +#if HAVE_LIBZ > 0 + Zflag || +#endif + S_ISREG (stats->stat.st_mode)) { if (file) bufoffset = 0; @@ -464,9 +487,14 @@ fillbuf (save, stats) if (! fillsize) { ssize_t bytesread; - while ((bytesread = read (bufdesc, buffer + bufsalloc, readsize)) < 0 - && errno == EINTR) - continue; + do +#if HAVE_LIBZ > 0 + if (Zflag) + bytesread = gzread (gzbufdesc, buffer + bufsalloc, readsize); + else +#endif + bytesread = read (bufdesc, buffer + bufsalloc, readsize); + while (bytesread < 0 && errno == EINTR); if (bytesread < 0) cc = 0; else @@ -483,13 +511,7 @@ fillbuf (save, stats) } /* Flags controlling the style of output. */ -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 always_text; /* Assume the input is always text. */ static int out_quiet; /* Suppress all normal output. */ static int out_invert; /* Print nonmatching stuff. */ static int out_file; /* Print filenames. */ @@ -723,6 +745,11 @@ grep (fd, file, stats) { /* Close fd now, so that we don't open a lot of file descriptors when we recurse deeply. */ +#if HAVE_LIBZ > 0 + if (Zflag) + gzclose(gzbufdesc); + else +#endif if (close (fd) != 0) error (file, errno); return grepdir (file, stats) - 2; @@ -741,14 +768,11 @@ grep (fd, file, stats) { if (! (is_EISDIR (errno, file) && suppress_errors)) error (filename, errno); - return 0; + return nlines; } - not_text = (((binary_files == BINARY_BINARY_FILES && !out_quiet) - || binary_files == WITHOUT_MATCH_BINARY_FILES) + not_text = (! (always_text | out_quiet) && 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; @@ -892,6 +916,11 @@ grepfile (file, stats) if (list_files == 1 - 2 * status) printf ("%s%c", filename, '\n' & filename_mask); +#if HAVE_LIBZ > 0 + if (Zflag) + gzclose(gzbufdesc); + else +#endif if (file) while (close (desc) != 0) if (errno != EINTR) @@ -999,6 +1028,7 @@ Miscellaneous:\n\ -v, --invert-match select non-matching lines\n\ -V, --version print version information and exit\n\ --help display this help and exit\n\ + -Z, --decompress decompress input before searching (HAVE_LIBZ=1)\n\ --mmap use memory-mapped input if possible\n")); printf (_("\ \n\ @@ -1008,16 +1038,14 @@ 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 equivalent to --binary-files=text\n\ - --binary-files=TYPE assume that binary files are TYPE\n\ - TYPE is 'binary', 'text', or 'without-match'.\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\ -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\ - -Z, --null print 0 byte after FILE name\n")); + --null print 0 byte after FILE name\n")); printf (_("\ \n\ Context control:\n\ @@ -1172,6 +1200,13 @@ main (argc, argv) if (prog && strrchr (prog, '/')) prog = strrchr (prog, '/') + 1; +#if HAVE_LIBZ > 0 + if (prog[0] == 'z') { + Zflag = 1; + ++prog; + } +#endif + #if defined(__MSDOS__) || defined(_WIN32) /* DOS and MS-Windows use backslashes as directory separators, and usually have an .exe suffix. They also have case-insensitive filesystems. */ @@ -1293,7 +1328,7 @@ main (argc, argv) setmatcher (optarg); break; case 'a': - binary_files = TEXT_BINARY_FILES; + always_text = 1; break; case 'b': out_byte = 1; @@ -1366,6 +1401,7 @@ main (argc, argv) done_on_match = 1; out_quiet = 1; break; + case 'R': case 'r': directories = RECURSE_DIRECTORIES; break; @@ -1382,21 +1418,15 @@ main (argc, argv) match_lines = 1; break; case 'Z': +#if HAVE_LIBZ > 0 + Zflag = 1; +#else filename_mask = 0; +#endif break; 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; @@ -1411,7 +1441,7 @@ main (argc, argv) out_before = default_context; if (! matcher) - matcher = "grep"; + matcher = prog; if (show_version) { diff --git a/gnu/usr.bin/grep/grep.h b/gnu/usr.bin/grep/grep.h index 13f55a2..264ad20 100644 --- a/gnu/usr.bin/grep/grep.h +++ b/gnu/usr.bin/grep/grep.h @@ -16,6 +16,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +/* $FreeBSD$ */ + #if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 6) || __STRICT_ANSI__ # define __attribute__(x) #endif diff --git a/gnu/usr.bin/grep/kwset.c b/gnu/usr.bin/grep/kwset.c index c7b088b..adde8a7 100644 --- a/gnu/usr.bin/grep/kwset.c +++ b/gnu/usr.bin/grep/kwset.c @@ -20,6 +20,8 @@ The author may be reached (Email) at the address mike@ai.mit.edu, or (US mail) as Mike Haertel c/o Free Software Foundation. */ +/* $FreeBSD$ */ + /* The algorithm implemented by these routines bears a startling resemblence to one discovered by Beate Commentz-Walter, although it is not identical. See "A String Matching Algorithm Fast on the Average," Technical Report, diff --git a/gnu/usr.bin/grep/kwset.h b/gnu/usr.bin/grep/kwset.h index e699258..f812b2e 100644 --- a/gnu/usr.bin/grep/kwset.h +++ b/gnu/usr.bin/grep/kwset.h @@ -20,6 +20,8 @@ The author may be reached (Email) at the address mike@ai.mit.edu, or (US mail) as Mike Haertel c/o Free Software Foundation. */ +/* $FreeBSD$ */ + struct kwsmatch { int index; /* Index number of matching keyword. */ diff --git a/gnu/usr.bin/grep/obstack.c b/gnu/usr.bin/grep/obstack.c index 4258c12..c77fdd4 100644 --- a/gnu/usr.bin/grep/obstack.c +++ b/gnu/usr.bin/grep/obstack.c @@ -20,6 +20,8 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +/* $FreeBSD$ */ + #ifdef HAVE_CONFIG_H #include <config.h> #endif diff --git a/gnu/usr.bin/grep/obstack.h b/gnu/usr.bin/grep/obstack.h index 5c03f68..df785c3 100644 --- a/gnu/usr.bin/grep/obstack.h +++ b/gnu/usr.bin/grep/obstack.h @@ -20,6 +20,8 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +/* $FreeBSD$ */ + /* Summary: All the apparent functions defined here are macros. The idea diff --git a/gnu/usr.bin/grep/search.c b/gnu/usr.bin/grep/search.c index 8fb3af0..4e3244a 100644 --- a/gnu/usr.bin/grep/search.c +++ b/gnu/usr.bin/grep/search.c @@ -18,13 +18,19 @@ /* Written August 1992 by Mike Haertel. */ +/* $FreeBSD$ */ + #ifdef HAVE_CONFIG_H # include <config.h> #endif #include <sys/types.h> #include "system.h" #include "grep.h" +#ifdef __FreeBSD__ +#include <gnuregex.h> +#else #include "regex.h" +#endif #include "dfa.h" #include "kwset.h" |