summaryrefslogtreecommitdiffstats
path: root/gnu/usr.bin/grep
diff options
context:
space:
mode:
Diffstat (limited to 'gnu/usr.bin/grep')
-rw-r--r--gnu/usr.bin/grep/Makefile51
-rw-r--r--gnu/usr.bin/grep/PROJECTS15
-rw-r--r--gnu/usr.bin/grep/README68
-rw-r--r--gnu/usr.bin/grep/config.h188
-rw-r--r--gnu/usr.bin/grep/dfa.c44
-rw-r--r--gnu/usr.bin/grep/dfa.h2
-rw-r--r--gnu/usr.bin/grep/doc/Makefile6
-rw-r--r--gnu/usr.bin/grep/getopt.c2
-rw-r--r--gnu/usr.bin/grep/getopt.h2
-rw-r--r--gnu/usr.bin/grep/getpagesize.h2
-rw-r--r--gnu/usr.bin/grep/grep.120
-rw-r--r--gnu/usr.bin/grep/grep.c65
-rw-r--r--gnu/usr.bin/grep/grep.h2
-rw-r--r--gnu/usr.bin/grep/kwset.c2
-rw-r--r--gnu/usr.bin/grep/kwset.h2
-rw-r--r--gnu/usr.bin/grep/obstack.c2
-rw-r--r--gnu/usr.bin/grep/obstack.h2
-rw-r--r--gnu/usr.bin/grep/search.c6
18 files changed, 419 insertions, 62 deletions
diff --git a/gnu/usr.bin/grep/Makefile b/gnu/usr.bin/grep/Makefile
new file mode 100644
index 0000000..b1875fe
--- /dev/null
+++ b/gnu/usr.bin/grep/Makefile
@@ -0,0 +1,51 @@
+# $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
+
+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/PROJECTS b/gnu/usr.bin/grep/PROJECTS
new file mode 100644
index 0000000..67e9a2a
--- /dev/null
+++ b/gnu/usr.bin/grep/PROJECTS
@@ -0,0 +1,15 @@
+Write Texinfo documentation for grep. The manual page would be a good
+place to start, but Info documents are also supposed to contain a
+tutorial and examples.
+
+Fix the DFA matcher to never use exponential space. (Fortunately, these
+cases are rare.)
+
+Improve the performance of the regex backtracking matcher. This matcher
+is agonizingly slow, and is responsible for grep sometimes being slower
+than Unix grep when backreferences are used.
+
+Provide support for the Posix [= =] and [. .] constructs. This is
+difficult because it requires locale-dependent details of the character
+set and collating sequence, but Posix does not standardize any method
+for accessing this information!
diff --git a/gnu/usr.bin/grep/README b/gnu/usr.bin/grep/README
index 27f5bae..bc34a85 100644
--- a/gnu/usr.bin/grep/README
+++ b/gnu/usr.bin/grep/README
@@ -1,70 +1,28 @@
-This README documents GNU e?grep version 1.6. All bugs reported for
-previous versions have been fixed.
+This is GNU grep 2.0, the "fastest grep in the west" (we hope). All
+bugs reported in previous releases have been fixed. Many exciting new
+bugs have probably been introduced in this major revision.
-See the file INSTALL for compilation and installation instructions.
-
-Send bug reports to bug-gnu-utils@prep.ai.mit.edu.
-
-GNU e?grep is provided "as is" with no warranty. The exact terms
+GNU grep is provided "as is" with no warranty. The exact terms
under which you may use and (re)distribute this program are detailed
in the GNU General Public License, in the file COPYING.
-GNU e?grep is based on a fast lazy-state deterministic matcher (about
+GNU grep is based on a fast lazy-state deterministic matcher (about
twice as fast as stock Unix egrep) hybridized with a Boyer-Moore-Gosper
search for a fixed string that eliminates impossible text from being
considered by the full regexp matcher without necessarily having to
look at every character. The result is typically many times faster
than Unix grep or egrep. (Regular expressions containing backreferencing
-may run more slowly, however.)
-
-GNU e?grep is brought to you by the efforts of several people:
-
- Mike Haertel wrote the deterministic regexp code and the bulk
- of the program.
-
- James A. Woods is responsible for the hybridized search strategy
- of using Boyer-Moore-Gosper fixed-string search as a filter
- before calling the general regexp matcher.
+will run more slowly, however.)
- Arthur David Olson contributed code that finds fixed strings for
- the aforementioned BMG search for a large class of regexps.
+See the file AUTHORS for a list of authors and other contributors.
- Richard Stallman wrote the backtracking regexp matcher that is
- used for \<digit> backreferences, as well as the getopt that
- is provided for 4.2BSD sites. The backtracking matcher was
- originally written for GNU Emacs.
-
- D. A. Gwyn wrote the C alloca emulation that is provided so
- System V machines can run this program. (Alloca is used only
- by RMS' backtracking matcher, and then only rarely, so there
- is no loss if your machine doesn't have a "real" alloca.)
-
- Scott Anderson and Henry Spencer designed the regression tests
- used in the "regress" script.
-
- Paul Placeway wrote the manual page, based on this README.
-
-If you are interested in improving this program, you may wish to try
-any of the following:
+See the file INSTALL for compilation and installation instructions.
-1. Replace the fast search loop with a faster search loop.
- There are several things that could be improved, the most notable
- of which would be to calculate a minimal delta2 to use.
+See the file MANIFEST for a list of files in this distribution.
-2. Make backreferencing \<digit> faster. Right now, backreferencing is
- handled by calling the Emacs backtracking matcher to verify the partial
- match. This is slow; if the DFA routines could handle backreferencing
- themselves a speedup on the order of three to four times might occur
- in those cases where the backtracking matcher is called to verify nearly
- every line. Also, some portability problems due to the inclusion of the
- emacs matcher would be solved because it could then be eliminated.
- Note that expressions with backreferencing are not true regular
- expressions, and thus are not equivalent to any DFA. So this is hard.
+See the file NEWS for a description of major changes in this release.
-3. Handle POSIX style regexps. I'm not sure if this could be called an
- improvement; some of the things on regexps in the POSIX draft I have
- seen are pretty sickening. But it would be useful in the interests of
- conforming to the standard.
+See the file PROJECTS if you want to be mentioned in AUTHORS.
-4. Replace the main driver program grep.c with the much cleaner main driver
- program used in GNU fgrep.
+Send bug reports to bug-gnu-utils@prep.ai.mit.edu. Be sure to
+include the word "grep" in your Subject: header field.
diff --git a/gnu/usr.bin/grep/config.h b/gnu/usr.bin/grep/config.h
new file mode 100644
index 0000000..415df26
--- /dev/null
+++ b/gnu/usr.bin/grep/config.h
@@ -0,0 +1,188 @@
+/* $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.3"
+
+/* 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 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 <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 */
diff --git a/gnu/usr.bin/grep/dfa.c b/gnu/usr.bin/grep/dfa.c
index 64ff27d..9f20c37 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;
@@ -714,6 +739,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);
@@ -724,6 +767,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 95b5d89..1e12515 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 3b957a0..5dfff47 100644
--- a/gnu/usr.bin/grep/grep.1
+++ b/gnu/usr.bin/grep/grep.1
@@ -1,14 +1,15 @@
.\" grep man page
+.\" $FreeBSD$
.de Id
.ds Dt \\$4
..
.Id $Id: grep.1,v 1.1 1998/11/22 06:45:20 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
-[-[AB] NUM] [-CEFGVabchiLlnqrsvwxyUu] [-e PATTERN | -f FILE]
+[-[AB] NUM] [-CEFGVZabchiLlnqrsvwxyUu] [-e PATTERN | -f FILE]
[-d ACTION] [--directories=ACTION]
[--extended-regexp] [--fixed-strings] [--basic-regexp]
[--regexp=PATTERN] [--file=FILE] [--ignore-case] [--word-regexp]
@@ -18,6 +19,7 @@ grep, egrep, fgrep \- print lines matching a pattern
[--files-without-match] [--files-with-matcces] [--count]
[--before-context=NUM] [--after-context=NUM] [--context]
[--binary] [--unix-byte-offsets] [--recursive]
+[--decompress]
.I files...
.SH DESCRIPTION
.PP
@@ -60,14 +62,17 @@ In addition, two variant programs
and
.B fgrep
are available.
-.B Egrep
+.B egrep
is similar (but not identical) to
.BR "grep\ \-E" ,
and is compatible with the historical Unix
.BR egrep .
-.B Fgrep
+.B fgrep
is the same as
.BR "grep\ \-F" .
+.B zgrep
+is the same as
+.BR "grep\ \-Z" .
.PD
.LP
All variants of
@@ -269,6 +274,13 @@ on a Unix machine. This option has no effect unless
.B \-b
option is also used; it is only supported on MS-DOS and MS-Windows.
.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.
diff --git a/gnu/usr.bin/grep/grep.c b/gnu/usr.bin/grep/grep.c
index 3ed4720..cf03988 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>
@@ -90,6 +93,9 @@ static struct option long_options[] =
{"version", no_argument, NULL, 'V'},
{"with-filename", no_argument, NULL, 'H'},
{"word-regexp", no_argument, NULL, 'w'},
+#if HAVE_LIBZ > 0
+ {"decompress", no_argument, NULL, 'Z'},
+#endif
{0, 0, 0, 0}
};
@@ -226,6 +232,12 @@ static off_t bufoffset; /* What read() normally remembers. */
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) \
@@ -292,6 +304,13 @@ reset (fd, file, stats)
bufbeg = buffer;
buflim = buffer;
}
+#if HAVE_LIBZ > 0
+ if (Zflag) {
+ gzbufdesc = gzdopen(fd, "r");
+ if (gzbufdesc == NULL)
+ fatal(_("memory exhausted"), 0);
+ }
+#endif
bufdesc = fd;
if (
@@ -309,7 +328,11 @@ reset (fd, file, stats)
if (directories == SKIP_DIRECTORIES && S_ISDIR (stats->stat.st_mode))
return 0;
#if defined(HAVE_MMAP)
- if (!S_ISREG (stats->stat.st_mode))
+ if (
+#if HAVE_LIBZ > 0
+ Zflag ||
+#endif
+ !S_ISREG (stats->stat.st_mode))
bufmapped = 0;
else
{
@@ -398,9 +421,19 @@ fillbuf (save, stats)
if (bufoffset != initial_bufoffset)
lseek (bufdesc, bufoffset, 0);
}
+#if HAVE_LIBZ > 0
+ if (Zflag)
+ cc = gzread (gzbufdesc, buffer + bufsalloc, bufalloc - bufsalloc);
+ else
+#endif
cc = read (bufdesc, buffer + bufsalloc, bufalloc - bufsalloc);
}
#else
+#if HAVE_LIBZ > 0
+ if (Zflag)
+ cc = gzread (gzbufdesc, buffer + bufsalloc, bufalloc - bufsalloc);
+ else
+#endif
cc = read (bufdesc, buffer + bufsalloc, bufalloc - bufsalloc);
#endif /*HAVE_MMAP*/
#if O_BINARY
@@ -648,6 +681,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;
@@ -822,6 +860,11 @@ grepfile (file, stats)
printf ("%s\n", filename);
}
+#if HAVE_LIBZ > 0
+ if (Zflag)
+ gzclose(gzbufdesc);
+ else
+#endif
if (file && close (desc) != 0)
error (file, errno);
}
@@ -919,6 +962,7 @@ Miscellaneous:\n\
-s, --no-messages suppress error messages\n\
-v, --revert-match select non-matching lines\n\
-V, --version print version information and exit\n\
+ -Z, --decompress decompress input before searching (HAVE_LIBZ=1)\n\
--help display this help and exit\n"));
printf (_("\
\n\
@@ -1020,6 +1064,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. */
@@ -1070,8 +1121,10 @@ main (argc, argv)
while ((opt = getopt_long (argc, argv,
#if O_BINARY
"0123456789A:B:C::EFGHVX:abcd:e:f:hiLlnqrsvwxyUu",
+#elif HAVE_LIBZ > 0
+ "0123456789A:B:C::EFGHRVX:Zabcd:e:f:hiLlnqrsvwxy",
#else
- "0123456789A:B:C::EFGHVX:abcd:e:f:hiLlnqrsvwxy",
+ "0123456789A:B:C::EFGHRVX:abcd:e:f:hiLlnqrsvwxy",
#endif
long_options, NULL)) != EOF)
switch (opt)
@@ -1148,6 +1201,11 @@ main (argc, argv)
fatal (_("matcher already specified"), 0);
matcher = optarg;
break;
+#if HAVE_LIBZ > 0
+ case 'Z':
+ Zflag = 1;
+ break;
+#endif
case 'a':
always_text = 1;
break;
@@ -1222,6 +1280,7 @@ main (argc, argv)
done_on_match = 1;
out_quiet = 1;
break;
+ case 'R':
case 'r':
directories = RECURSE_DIRECTORIES;
break;
@@ -1285,7 +1344,7 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"))
usage (2);
if (! matcher)
- matcher = default_matcher;
+ matcher = prog;
if (!setmatcher (matcher) && !setmatcher ("default"))
abort ();
diff --git a/gnu/usr.bin/grep/grep.h b/gnu/usr.bin/grep/grep.h
index ebd0bbc..e12cff5 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 cf51e3b..a3ca56c 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"
OpenPOWER on IntegriCloud