summaryrefslogtreecommitdiffstats
path: root/gnu
diff options
context:
space:
mode:
authortjr <tjr@FreeBSD.org>2004-07-04 09:52:08 +0000
committertjr <tjr@FreeBSD.org>2004-07-04 09:52:08 +0000
commit7bb57b0d67aa634a010e91a2f147ebc35d105f9b (patch)
tree71cb48dc556a8b4a5218b2b2e4e0cb2626d8327a /gnu
parenta819334bbc6f1b20536282eb0624b0793641b55c (diff)
parentd4c611919468bb0fb6a564c4b8cada55792c3fc4 (diff)
downloadFreeBSD-src-7bb57b0d67aa634a010e91a2f147ebc35d105f9b.zip
FreeBSD-src-7bb57b0d67aa634a010e91a2f147ebc35d105f9b.tar.gz
This commit was generated by cvs2svn to compensate for changes in r131554,
which included commits to RCS files with non-trunk default branches.
Diffstat (limited to 'gnu')
-rw-r--r--gnu/usr.bin/grep/AUTHORS5
-rw-r--r--gnu/usr.bin/grep/COPYING6
-rw-r--r--gnu/usr.bin/grep/ChangeLog984
-rw-r--r--gnu/usr.bin/grep/NEWS70
-rw-r--r--gnu/usr.bin/grep/THANKS122
-rw-r--r--gnu/usr.bin/grep/closeout.c121
-rw-r--r--gnu/usr.bin/grep/closeout.h17
-rw-r--r--gnu/usr.bin/grep/doc/grep.texi1387
-rw-r--r--gnu/usr.bin/grep/doc/version.texi7
-rw-r--r--gnu/usr.bin/grep/error.c276
-rw-r--r--gnu/usr.bin/grep/error.h78
-rw-r--r--gnu/usr.bin/grep/exclude.c128
-rw-r--r--gnu/usr.bin/grep/exclude.h35
-rw-r--r--gnu/usr.bin/grep/hard-locale.c85
-rw-r--r--gnu/usr.bin/grep/hard-locale.h18
-rw-r--r--gnu/usr.bin/grep/isdir.c42
-rw-r--r--gnu/usr.bin/grep/quotearg.c613
-rw-r--r--gnu/usr.bin/grep/quotearg.h110
-rw-r--r--gnu/usr.bin/grep/savedir.c47
-rw-r--r--gnu/usr.bin/grep/savedir.h7
-rw-r--r--gnu/usr.bin/grep/system.h19
-rwxr-xr-xgnu/usr.bin/grep/tests/backref.sh38
-rw-r--r--gnu/usr.bin/grep/tests/bre.awk3
-rwxr-xr-xgnu/usr.bin/grep/tests/bre.sh2
-rw-r--r--gnu/usr.bin/grep/tests/bre.tests2
-rwxr-xr-xgnu/usr.bin/grep/tests/empty.sh41
-rw-r--r--gnu/usr.bin/grep/tests/ere.awk3
-rwxr-xr-xgnu/usr.bin/grep/tests/ere.sh2
-rwxr-xr-xgnu/usr.bin/grep/tests/file.sh59
-rw-r--r--gnu/usr.bin/grep/tests/formatbre.awk55
-rw-r--r--gnu/usr.bin/grep/tests/formatere.awk60
-rwxr-xr-xgnu/usr.bin/grep/tests/khadafy.sh2
-rwxr-xr-xgnu/usr.bin/grep/tests/options.sh2
-rw-r--r--gnu/usr.bin/grep/tests/spencer1.awk3
-rwxr-xr-xgnu/usr.bin/grep/tests/spencer1.sh2
-rwxr-xr-xgnu/usr.bin/grep/tests/spencer2.sh13
-rw-r--r--gnu/usr.bin/grep/tests/spencer2.tests317
-rwxr-xr-xgnu/usr.bin/grep/tests/status.sh22
-rw-r--r--gnu/usr.bin/grep/tests/tests475
-rwxr-xr-xgnu/usr.bin/grep/tests/warning.sh2
-rw-r--r--gnu/usr.bin/grep/xalloc.h87
-rw-r--r--gnu/usr.bin/grep/xmalloc.c116
-rw-r--r--gnu/usr.bin/grep/xstrtol.c282
-rw-r--r--gnu/usr.bin/grep/xstrtol.h64
-rw-r--r--gnu/usr.bin/grep/xstrtoumax.c31
45 files changed, 5612 insertions, 248 deletions
diff --git a/gnu/usr.bin/grep/AUTHORS b/gnu/usr.bin/grep/AUTHORS
index 65ff8a1..e08a38cf 100644
--- a/gnu/usr.bin/grep/AUTHORS
+++ b/gnu/usr.bin/grep/AUTHORS
@@ -38,4 +38,7 @@ it came straight from gawk-3.0.3 with small editing and fixes.
Many folks contributed see THANKS, if I omited someone please
send me email.
-Alain Magloire is the current maintainer.
+Alain Magloire maintained GNU grep until version 2.5e.
+
+Bernhard "Bero" Rosenkränzer <bero@redhat.com> is the current maintainer.
+
diff --git a/gnu/usr.bin/grep/COPYING b/gnu/usr.bin/grep/COPYING
index d60c31a..60549be 100644
--- a/gnu/usr.bin/grep/COPYING
+++ b/gnu/usr.bin/grep/COPYING
@@ -2,7 +2,7 @@
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
- 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
@@ -291,7 +291,7 @@ convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
- Copyright (C) <year> <name of author>
+ Copyright (C) 19yy <name of author>
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
@@ -313,7 +313,7 @@ Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
- Gnomovision version 69, Copyright (C) year name of author
+ Gnomovision version 69, Copyright (C) 19yy name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
diff --git a/gnu/usr.bin/grep/ChangeLog b/gnu/usr.bin/grep/ChangeLog
index c98848a..aa50e78 100644
--- a/gnu/usr.bin/grep/ChangeLog
+++ b/gnu/usr.bin/grep/ChangeLog
@@ -1,3 +1,983 @@
+2002-03-26 Bernhard Rosenkraenzer <bero@redhat.com>
+ * src/grep.c: Don't fail if we don't have an stdout fd and -q
+ is used (happens e.g. on calls from hotplug scripts)
+ * src/grep.c: Don't hang forever if fed with an empty string to
+ grep for and --color enabled
+ * src/grep.c: Fix infinite loop on
+ echo "1 one" | grep -E "[0-9]*" -o
+ echo "1 one" | grep -E "[0-9]*" --color
+ * po/*: Sync wiith translation project
+ * src/grep.c, src/Makefile.am, configure.in: Add patch from
+ Paul Eggert <eggert@twinsun.com> to comply with ridiculous
+ guidelines (don't act differently if invoked as egrep or fgrep)
+ * configure.in: Bump version number, require a recent autoconf
+
+2002-03-14 Bernhard Rosenkraenzer <bero@redhat.com>
+ * src/Makefile.am, po/Makefile.in.in: Support DESTDIR properly
+ * tests/bre.tests: Add fix from
+ Peter Breitenlohner <peb@mppmu.mpg.de>
+
+2002-03-13 Bernhard Rosenkraenzer <bero@redhat.com>
+ * configure.in, m4/regex.m4, m4/malloc.m4, m4/realloc.m4:
+ Don't set LIBOBJS directly, autoconf 2.53 doesn't like it
+ * intl/*: Sync with gettext 0.11
+ * po/*: Sync with translation project
+ * configure.in, src/Makefile.am: Don't duplicate code - make
+ egrep and fgrep links to grep and set matcher based on
+ application name, suggestion from
+ Guillaume Cottenceau <gc@mandrakesoft.com>
+ * src/grep.c: (prline) Add fix for -i --color from
+ Jim Meyering <meyering@lucent.com>
+ * configure.in: Version 2.5; release
+
+2002-01-23 Bernhard Rosenkraenzer <bero@redhat.com>
+ * configure.in: Version 2.5g
+ * Makefile.cvs, grep.spec: Add packaging tools
+ Merge djgpp changes from Andrew Cottrell <anddjgpp@ihug.coml.au>:
+ * src/grep.c: Added conditional compilation for DJGPP
+ * djgpp: remove directory as it is no longer required with DJGPP 2.03
+ (or 2.04 when released)
+ * README.DOS: Moved djgpp/readme to readme.dos
+ * PATCHES.AC, PATCHES.AM: delete files - redundant
+ * configure.in, Makefile.am: remove djgpp directory from list
+
+2002-01-22 Bernhard Rosenkraenzer <bero@redhat.com>
+ * doc/grep.texi, doc/grep.1, NEWS: Document --label
+ * po/ru.po: Sync with translation project
+ * po/grep.pot: Sync with source
+
+2002-01-18 Bernhard Rosenkraenzer <bero@redhat.com>
+ * src/grep.c: Add --label, based on patch from Stepan Koltsov
+
+2001-11-20 Bernhard Rosenkraenzer <bero@redhat.com>
+ * autogen.sh: Don't hardcode aclocal dir
+
+2001-11-19 Bernhard Rosenkraenzer <bero@redhat.com>
+ * src/grep.c: Add --only-matching (-o) switch (see NEWS)
+ * doc/grep.texi, doc/grep.1, NEWS: Document changes
+ * configure.in, lib/Makefile.am: Don't use internal getopt if
+ we're on a system that provides a working getopt function
+
+2001-09-25 Bernhard Rosenkraenzer <bero@redhat.com>
+ * configure.in: Detect pcre correctly even when it's in
+ non-standard locations, using pcre-config
+ * src/grep.c: Add --color={always,never,tty} argument (like in ls)
+ * src/grep.c: Turn off blinking in the default colorization
+ * src/grep.c: Add --devices (-D) switch (analogous to --directories)
+ * src/dfa.c: Fix an i18n bug: echo "A" | grep '[A-Z0-9]' wouldn't work
+ in non-C-Locales on systems using current versions of glibc.
+ * AUTHORS: Change maintainer, credit Alain for his work until now
+ * configure.in, m4/decl.m4, m4/dosfile.m4, m4/gettext.m4,
+ m4/init.m4, m4/install.m4, m4/largefile.m4, m4/lcmessage.m4,
+ m4/header.m4, m4/isc-posix.m4, m4/missing.m4, m4/progtest.m4,
+ m4/sanity.m4:
+ Fix build with autoconf 2.5x, retain 2.1x compatibility for now
+ * autogen.sh: Add some crude hacks to make it possible to build with
+ both autoconf 2.5x and 2.1x
+ * acconfig.h: removed (no longer required)
+ * Makefile.am: add cvs-clean target
+ * doc/grep.texi, doc/grep.1, NEWS: Document changes
+ (--color, --devices, -D)
+ * src/dfa.c, src/grep.c: Add vim modelines
+
+2001-08-30 Alain Magloire
+
+ * configure.in: Add gl in ALL_LINGUAS.
+
+2001-08-30 Kurt D Schwehr
+
+ * doc/grep.1: Warn that grep insert a "--" between groups of matches,
+ when using the context options.
+ * doc/grep.texi: Likewised.
+
+2001-08-25 Heikki Korpela
+
+ * doc/grep.texi: Point out that some Platforms do not support
+ reading of directories and silently ignore them.
+
+2001-08-21 Alain Magloire
+
+ * lib/malloc.c: New file:
+ * lib/realloc.c: New file:
+ * lib/Makefile.am: Add malloc.c and realloc.c in EXTRA_DIST.
+
+2001-07-31 Alain Magloire
+
+ * po/*.po: New files from the translation team:
+ grep-2.5e.de.po grep-2.5e.el.po grep-2.5e.eo.po grep-2.5e.es.po
+ grep-2.5e.et.po grep-2.5e.fr.po grep-2.5e.gl.po grep-2.5e.it.po
+ grep-2.5e.pl.po grep-2.5e.sl.po
+
+2001-07-31 Andreas Schwab
+
+ * src/grep.c: Fix all uses of error to pass a proper format
+ string.
+
+2001-07-29 Alain Magloire
+
+ * grep/src/grep.c (usage): Typos corrected.
+ Patches from Santiago Vila.
+
+2001-07-29 Alain Magloire
+
+ David Clissold, wrote:
+ a small bug in the GNU grep 2.4.2, which may have gone unnoticed
+ because it only causes a failure if building on a system with large
+ files enabled (e.g. an "off_t" is a "long long" rather than a "long").
+ savedir() takes on off_t argument, but in grepdir() the parameter
+ is cast to an (unsigned). Well, if an off_t is larger than an int,
+ the value gets truncated. This would not normally have an effect on a
+ little-endian platform (unless the file is >2GB), but on a big-endian
+ system it will always fail. The external effect is that
+ "grep -r foo dir_name" fails with ENOMEM (from malloc() within
+ savedir()).
+
+ * grep/src/grep.c (grepdir): Remove the (unsigned) cast when calling
+ savedir().
+ Patch from David Clissold.
+
+2001-07-29 Alain Magloire
+
+ * grep/doc/grep.texi: In Bugs report use {n,m} for consistency.
+ * grep/doc/grep.1: Likewised.
+ Noted by Steven Lucy.
+
+2001-04-27 Isamu Hasegawa
+
+ * dfa.c (mblen_buf) : New variable contains the amount of remain
+ byte of corresponding multibyte character in the input string.
+ (SKIP_REMAIN_MB_IF_INITIAL_STATE) : Use mblen_buf.
+ (match_anychar) : Use mblen_buf.
+ (match_mb_charset) : Use mblen_buf.
+ (transit_state_consume_1char) : Use mblen_buf.
+ (transit_state) : Use inputwcs to get current (multibyte) character.
+ (dfaexec) : Add initialization of mblen_buf.
+
+2001-04-27 Isamu Hasegawa
+
+ * dfa.c (addtok) : Set appropriate value to multibyte_prop.
+ (dfastate) : Add the initialization of the variable.
+ (dfaexec) : Call transit_state if d->fail may transit by
+ multibyte characters.
+ (transit_state_singlebyte) : Clean up unnecessary code.
+ (transit_state_consume_1char) : Likewise.
+ (transit_state) : Add checking for word and newline.
+
+2001-04-19 Isamu Hasegawa
+
+ * search.c (check_multibyte_string) : Check the case when mbclen == 0.
+
+2001-04-11 Isamu Hasegawa
+
+ * search.c (check_multibyte_string) : Check the head of multibyte
+ characters, and optimize a bit.
+ (EGexecute) : Optimize a bit.
+ (Fexecute) : Fix the index.
+
+2001-04-02 Alain Magloire
+
+ * lib/regex.c: Update from GNU lib C, with the changes
+ provided by Paul Eggert.
+ * lib/posix/regex.h: Likewise.
+
+2001-02-17 Paul Eggert
+
+ Stop trying to support hosts that have nonstandard declarations for
+ mbrtowc and/or mbstate_t. It's not worth the portability hassle.
+
+ * lib/quotearg.c (mbrtowc, mbsinit): Remove workaround macros
+ for hosts that have mbrtowc but not mbstate_t, as we now
+ insist on proper declarations for both before using mbrtowc.
+
+2001-03-18 Alain Magloire
+
+ * configure.in: Call AC_MBSTATE_T.
+ * Makefile.am: Add mbstate_t.m4
+ * m4/Makefile.am: Add mbstate_t.m4
+ * m4/mbstate_t.m4: New m4 macro.
+ * lib/strtol.c: Define CHAR_BITS.
+ Uwe H. Steinfeld, Ruslan Ermilov, Volkert Bochert, noted
+ that mbstate_t was not define for certain platforms.
+
+2001-03-18 Paul Eggert
+
+ * src/grep.c (fillbuf): Fix storage allocation performance
+ bug: buffer was doubling in size in many cases where it didn't
+ have to.
+
+2001-03-17 Paul Eggert
+
+ * src/grep.c (fillbuf): Avoid unnecessary division by 2.
+ Don't check xrealloc return value; it's guaranteed to be nonzero.
+ (fillbuf, grepdir): Use xalloc_die rather than error; it's shorter.
+
+2001-03-17 Alain Magloire
+
+ * src/grep.c (context_length_arg): error () passing wrong format.
+ Spotted by Jim Meyering.
+
+2001-03-07 Alain Magloire
+
+ * README-alpha: Removed reference to GNU tar, add the location
+ of the CVSROOT.
+
+2001-03-06 Alain Magloire
+
+ Only the Regex patterns should be split in an array, patterns[].
+ The dfa and KWset compiled patterns should remain global and the
+ patterns compiled all at once.
+
+ * src/search.c: include "error.h" and "xalloc.h" to get prototyping
+ of x*alloc() and error().
+ (kwsinit): Reverse to previous behaviour and takes no argument.
+ (kwsmusts): Likewised.
+ (Gcompile): For the regex pattern, split them and each pattern
+ is put in different compiled structure patterns[]. The patterns
+ are given to dfacomp() and kwsmusts() as is.
+ (Ecompile): Likewised.
+ (Fcompile): Reverse to the old behaviour of compiling the enire
+ patterns in one shot.
+ (EGexecute): If falling to GNU regex for the matching, loop in the
+ array of compile patterns[] to find a match.
+ (error): Many error () were call with arguments in the wrong order.
+ * tests/file.sh: Simple test to check for pattern in files.
+
+ Reaction to bug report fired by Greg Louis <glouis@dynamicro.on.ca>
+
+2001-03-06 Isamu Hasegawa
+
+ In multibyte environments, handle multibyte characters as single
+ characters in bracket expressions.
+
+ * src/dfa.h (mb_char_classes) : new structure.
+ (mbcsets): new variable.
+ (nmbcsets): new variable.
+ (mbcsets_alloc) : new variable.
+ * src/dfa.c (prtok) : handle MBCSET.
+ (fetch_wc): new function to fetch a wide character.
+ (parse_bracket_exp_mb) : new function to handle multibyte character
+ in lex().
+ (lex): invoke parse_bracket_exp_mb() for multibyte bracket expression.
+ (atom): handle MBCSET.
+ (epsclosure): likewise.
+ (dfaanalyze): likewise.
+ (dfastate): likewise.
+ (match_mb_charset): new function to judge whether a bracket match
+ with a multibyte character.
+ (check_matching_with_multibyte_ops) : handle MBCSET.
+ (dfainit): initialize new variables.
+ (dfafree): free new variables.
+
+2001-03-04 Alain Magloire
+
+ To get more in sync with other GNU utilities like GNU tar and fetish
+ all the supporting functions are now under lib.
+ Thanks to Jim Meyering, Volkert Bochert and Paul Eggert for
+ the code and the reminders.
+
+ * src/grep.c (fatal): Function removed, using error () from
+ lib/error.c instead.
+ (usage): Copyright updated.
+ (error): Function removed, using error () from lib/error.c instead,
+ adjust prototypes.
+ (prog): Global variable rename to program_name, to work with new
+ lib/error.c.
+ (xrealloc): Removed using lib/xmalloc.c.
+ (xmalloc): Removed using lib/xmalloc.c
+ (main): Register with atexit() to check for error on stdout.
+ * configure.in: Check for atexit(), call jm_MALLOC, jm_RELLOC and
+ jm_PREREQ_ERROR.
+ * tests/bre.awk: Removed the hack to drain the buffer since we
+ always fclose(stdout) atexit.
+ * tests/ere.awk: Likewise.
+ * tests/spencer1.awk: Likewise.
+ * bootstrap/Makefile.try: Update the Makefile to reflect the changes
+ in the new hierarchy.
+
+ * README-alpha: New File.
+ * m4/realloc.m4: New File.
+ * m4/malloc.m4: New File.
+ * m4/error.m4: New File.
+ * m4/Makefile.am: Updated.
+ * lib: New directory.
+ * lib/Makefile.am: New file.
+ * lib/closeout.c: New file.
+ * lib/closeout.h: New file.
+ * lib/fnmatch.c: New file.
+ * lib/fnmatch.h: New file.
+ * lib/atexit.c: New file.
+ * lib/error.c: New file.
+ * lib/error.h: New file.
+ * lib/quotearg.h: New file.
+ * lib/quotearg.c: New file.
+ * lib/xmalloc.c: New file.
+ * lib/posix: New directory.
+ * lib/posix/Makefile.am: New file.
+ * src/getopt.c: Moved to lib.
+ * src/getopt1.c: Moved to lib.
+ * src/getopt.h: Moved to lib.
+ * src/alloca.c: Moved to lib.
+ * src/exclude.c: Moved to lib.
+ * src/exclude.h: Moved to lib.
+ * src/hard-locale.h: Moved to lib.
+ * src/hard-locale.c: Moved to lib.
+ * src/isdir.c: Moved to lib.
+ * src/mechr.c: Moved to lib.
+ * src/obstack.c: Moved to lib.
+ * src/obstack.h: Moved to lib.
+ * src/regex.c: Moved to lib.
+ * src/regex.h: Moved to lib.
+ * src/posix: Moved to lib.
+ * src/posix/regex.h: Moved to lib.
+ * src/savedir.h: Moved to lib.
+ * src/savedir.c: Moved to lib.
+ * src/stpcpy.c: Moved to lib.
+ * src/strtoul.c: Moved to lib.
+ * src/strtol.c: Moved to lib.
+ * src/strtoull.c: Moved to lib.
+ * src/strtoumax.c: Moved to lib.
+ * src/xstrtol.c: Moved to lib.
+ * src/xstrtol.h: Moved to lib.
+ * src/xstrtoumax.c: Moved to lib.
+
+2001-03-01 Isamu Hasegawa
+
+ Implement the mechanism to match with multibyte characters,
+ and use it for `period' in multibyte environments.
+
+ * dfa.h (mbps): new variable.
+ * dfa.c (prtok): handle ANYCHAR.
+ (lex): use ANYCHAR for `period' in multibyte environments.
+ (atom): handle ANYCHAR.
+ (state_index): initialize mbps in multibyte environments.
+ (epsclosure): handle ANYCHAR.
+ (dfaanalyze): handle ANYCHAR.
+ (dfastate): handle ANYCHAR.
+ (realloc_trans_if_necessary): new function.
+ (transit_state_singlebyte): new function.
+ (match_anychar): new function.
+ (check_matching_with_multibyte_ops): new function.
+ (transit_state_consume_1char): new function.
+ (transit_state): new function.
+ (dfaexec): invoke transit_state if expression can match with
+ a multibyte character in multibyte environments.
+ (dfamust): handle ANYCHAR.
+
+2001-03-01 Alain Magloire
+
+ * src/exclude.c: New file.
+ * src/exclude.h: New file.
+ * src/grep.c (main): Took the GNU tar code to handle
+ the option --include, --exclude, --exclude-from.
+ Files are check for a match, with exlude_filename ().
+ New option --exclude-from.
+ * src/savedir.c: Call exclude_filename() to check for
+ file pattern exclusion or inclusion.
+ * configure.in: --disable-pcre rename to --disable-perl-regexp.
+
+
+2001-02-25 Alain Magloire
+
+ * src/dfa.c: Typo corrected.
+ Noted by Isamu Hasegawa.
+ * src/savedir.c: Typos corrected.
+
+2001-02-22 Alain Magloire
+
+ * src/savedir.c (isdir1): New function, calling isdir with
+ the correct pathname.
+
+2001-02-19 Isamu Hasegawa
+
+ Avoid incorrect state transition in multibyte environments.
+
+ * dfa.h (nmultibyte_prop): new variable.
+ (multibyte_prop): new variable.
+ * dfa.c (addtok): set inputwcs.
+ (dfastate): avoid incorrect state transition in multibyte
+ environments.
+ (dfaexec): likewise.
+ (dfainit): init multibyte_prop.
+ (dfafree): free multibyte_prop.
+ (inputwcs): new variable.
+
+2001-02-19 Isamu Hasegawa
+
+ Handle a multibyte character followed by '*', '+', and '{n,m}'
+ correctly.
+
+ * dfa.c (update_mb_len_index): new function.
+ Support for multibyte string.
+ (FETCH): call update_mb_len_index.
+ (lex): check cur_mb_index not to misunderstand multibyte characters.
+ (atom): make a tree from a multibyte character.
+ (dfaparse): initialize new variables.
+ (mbs): new variable.
+ (cur_mb_len): new variable.
+ (cur_mb_index): new variable.
+
+2001-02-18 Jim Meyering
+
+ * m4/dosfile.m4 (AC_DOSFILE): Move AC_DEFINEs out of AC_CACHE_CHECK.
+
+2001-02-17 Alain Malgoire
+
+ * doc/grep.texi: Document the new options and the new behaviour
+ back-references are local. Use excerpt from Karl Berry regex
+ texinfo.
+
+ * bootstrap/Makefile.try: Added xstrtoumax.o xstrtoul.o hard-local.o
+
+2001-02-17 Alain Magloire
+
+ From Guglielmo 'bond' Bondioni :
+ The bug was that using a multi line file that contained REs (one per
+ line), backreferences in the REs were considered global (to the file)
+ and not local (to the line).
+ That is, \1 in line n refers to the first \(.\) in the whole file,
+ rather than in the line itself.
+
+ From Tapani Tarvainen :
+ # Re: grep -e '\(a\)\1' -e '\(b\)\1'
+ That's not the way it should work: multiple -e arguments
+ should be treated as independent patterns and back references
+ should not refer to previous ones.
+
+ From Paul Eggert :
+ GNU grep currently does not issue
+ diagnostics for the following two cases, both of which are erroneous:
+ grep -e '[' -e ']'
+ grep '[
+ ]'
+ POSIX requires a diagnostic in both cases because '[' is not a valid
+ regular expression.
+
+ To overcome those problems, grep no longer pass the concatenate
+ patterns to GNU regex but rather compile each patterns separately
+ and keep the result in an array.
+
+ * src/search.c (patterns): New global variable; a structure array
+ holding the compiled patterns.
+ Declare function prototypes to minimize error.
+ (dfa, kswset, regexbuf, regs): Removed, no longer static globals, but
+ rather fields in patterns[] structure per motif.
+ (Fcompile): Alloc an entry in patterns[] to hold the regex.
+ (Ecompile): Alloc an entry per motif in the patterns[] array.
+ (Gcompile): Likewise.
+ (EGexecute): Loop through of array of patterns[] for a match.
+
+2001-02-17 Alain Magloire
+
+ From Bernd Strieder :
+ # tail -f logfile | grep important | do_something_urgent
+ # tail -f logfile | grep important | do_something_taking_very_long
+ If grep does full buffering in these cases then the urgent operation
+ does not happen as it should in the first case, and in the second case
+ time is lost due to waiting for the buffer to be filled.
+ This is clearly spoken not grep's fault in the first place, but libc's.
+ There is a heuristic in libc that make a stream line-buffered only if a
+ terminal is on the other end. This doesn't take care of the cases where
+ this connection is somehow indirect.
+
+ * src/grep.c (line_buffered): new option variable.
+ (prline): if line_buffered is set fflush() is call.
+ (usage): line_buffered new option.
+ Input from Paul Eggert, doing setvbuf() may not be portable
+ and breaks grep -z.
+
+2001-02-16 Alain Magloire
+
+ Patch from Isamu Hasegawa, for multibyte support.
+ This patch prevent kwset_matcher from following problems.
+ For example, in SJIS encoding, one character has the codepoint 0x895c.
+ So the second byte of the character can match with '\' incorrectly.
+ And in eucJP encoding, there are the characters whose codepoints are
+ 0xa5b9, 0xa5c8. On the other hand, there is one character whose
+ codepoint is 0xb9a5. So 0xb9a5 can match with 2nd byte of 0xa5b9
+ and 1st byte of 0xa5c8.
+
+ * configure.in: Add check for mbrtowc.
+ * src/search.c (check_multibyte_string): new function.
+ Support for multibyte string.
+ (EGexecute): call check_multibyte_string when kwset is set.
+ (Fexecute): call to check_multibyte_string.
+ (MBS_SUPPORT): new macro.
+ (MB_CUR_MAX): new macro.
+
+2001-02-16 Alain Magloire
+
+ * djgpp/config.bat: Fix for 4dos.com.
+ * m4/dosfile.m4 (HAVE_DOS_FILE_CONTENTS): Was not set.
+ Bugs noted and patched by Juan Manuel Guerrero.
+
+2001-02-16 Alain Magloire
+
+ A much requested feature, the possibility to select
+ files when doing recurse :
+ # find . -name "*.c" | xargs grep main {}
+ # grep --include=*.c main .
+ # find . -not -name "*.c" | xargs grep main {}
+ # grep --exclude=*.c main .
+
+ * src/grep.c (short_options): -R equivalent to -r.
+ (#ifdef) : Fix some inconsistencies in the use of #ifdefs, prefer
+ #if defined() wen possible.
+ (long_options): Add --color, --include and exclude.
+ (Usage): Description of new options.
+ (color): Rename color variable to color_option.
+ Removed 'always|never|auto' arguments, not necessary for grep.
+ (exclude_pattern): new variable, holder for the file pattern.
+ (include_pattern): new variable, hoder for the file pattern.
+ * src/savedir.c: Signature change, take two new argmuments.
+ * doc/grep.texi: Document, new options.
+ * doc/grep.man: Document, new options.
+
+2001-02-09 Alain Magloire
+
+ * src/grep.c (long_options): Added equivalent to -r with -R.
+ * src/grep.c (usage): added --color and --colour.
+ Noted with patch from, H.Merijn Brand and Wichert Akkerman.
+
+2001-02-09 Alain Magloire
+
+ Patch from Ulrich Drepper to provide hilighting.
+
+ * src/grep.c: New option --color.
+ (color): New static var.
+ (COLOR_OPTION): new constant.
+ (grep_color): new static var.
+ (prline): Now when color is set prline() will call the current matcher
+ to find the offset of the matching string.
+ * src/savedir.c: Take advantage of _DIRENT_HAVE_TYPE if supported.
+ * src/search.c (EGexecute, Fexecute, Pexecute): Take a new argument
+ when doing exact match for the color hiligting.
+
+2000-09-01 Brian Youmans
+
+ * doc/grep.texi: Typo fixes.
+
+2000-08-30 Paul Eggert
+
+ * doc/grep.texi (Usage): Talk about what "grep -r hello *.c"
+ means.
+
+2000-08-20 Paul Eggert
+
+ Handle range expressions correctly even when they match
+ strings with two or more characters.
+
+ * src/dfa.h (CRANGE): New enum value. Comment fix.
+
+ * src/dfa.c: Include <locale.h> if HAVE_SETLOCALE.
+ Include "hard-locale.h".
+ (prtok): Print CRANGE.
+ (hard_LC_COLLATE): New static var.
+ (lex): Return CRANGE when parsing a character range in a hard locale.
+ Don't use strcoll; it's no longer needed and wasn't correct anyway.
+ Use unsigned rather than token to hold unsigned chars.
+ (addtok): Comment fix.
+ (atom): Treat a CRANGE as if it were (.\1), approximately.
+ (dfaparse): Initialize hard_LC_COLLATE.
+
+ * src/Makefile.am (base_sources): Add hard-locale.c, hard-locale.h.
+
+ * src/hard-locale.c, src/hard-locale.h: New files, taken from
+ textutils.
+
+2000-08-20 Paul Eggert
+
+ * tests/Makefile.am (TESTS_ENVIRONMENT): Add LC_ALL=C, since
+ some of the tests assume the C locale.
+
+2000-08-16 Paul Eggert
+
+ * src/search.c (Gcompile, Ecompile): -x overrides -w, for
+ consistency with fgrep. Don't assume that sizes fit in 'int'.
+ Fix comments to match code.
+
+2000-06-06 Paul Eggert
+
+ * src/grep.c (grepdir): Don't look at st_dev when testing for
+ Mingw32 bug.
+
+2000-06-05 Paul Eggert
+
+ Port to Mingw32, based on suggestions from Christian Groessler
+ <cpg@aladdin.de>.
+
+ * src/isdir.c: New file, taken from fileutils.
+
+ * src/Makefile.am (base_sources): Add isdir.c.
+
+ * src/grep.c (grepfile): Use isdir instead of doing it inline.
+ (grepdir): Suppress ancestor check if the directory's inode and device
+ are both zero, as that occurs only on Mingw32 which doesn't support
+ inode or device.
+
+ * src/system.h (isdir): New decl.
+ (is_EISDIR): Depend on HAVE_DIR_EACCES_BUG, not D_OK.
+ Use isdir, not access.
+
+2000-06-02 Paul Eggert
+
+ Problen noted by Gerald Stoller <gerald_stoller@hotmail.com>
+
+ * src/grep.c (main): POSIX.2 says that -q overrides -l, which
+ in turn overrides the other output options. Fix grep to
+ behave that way.
+
+2000-05-27 Paul Eggert
+
+ Simplify and tune the buffer allocation strategy. Do not reserve a
+ large save area: reserve only enough bytes to hold the residue, plus
+ page alignment. Put a newline sentinel before the buffer, for speed
+ when searching backwards for newline.
+
+ * src/grep.c (ubuffer, bufsalloc, PREFERRED_SAVE_FACTOR, page_alloc):
+ Remove. All uses changed.
+ (INITIAL_BUFSIZE): New macro.
+ (reset, fillbuf): Use simpler buffer allocation strategy.
+ (reset): Check for preposterously large pagesize that would cause
+ later calculations to overflow.
+ (fillbuf): Do not resize buffer if there's room at the end for
+ at least one more page. This greatly increases performance when
+ reading from non-regular files that contain no newlines.
+ When growing the buffer, double its size instead of using a
+ more complicated algorithm.
+ (prtext, grep): Speed up by relying on the newline sentinel before the
+ start of the buffer.
+ (grep): When looking backwards for the last newline in a buffer,
+ stop when we hit the residue, since it can't contain a newline.
+ This avoids an O(N**2) algorithm when reading binary data from
+ a pipe. Use a sentinel to speed up the backward search for newline.
+ (nlscan): Undo previous change; it wasn't needed and just complicates
+ and slows down the code a tad.
+
+2000-05-24 Paul Eggert
+
+ Handle very large input counts better. Bug noted by Jim Meyering.
+
+ * src/grep.c (totalcc, totalnl): Use uintmax_t, not off_t.
+ (add_count): New function.
+ (nlscan, prline, grep): Use it to check line and byte count overflows.
+ (nlscan, grep): Don't keep track of counts when not asked to; this
+ avoids unnecessary overflow diagnostics.
+ (print_offset_sep): Now takes args of type uintmax_t and char,
+ not off_t and int.
+
+2000-05-16 Paul Eggert
+
+ Problem reported by Bob Proulx <rwp@hprwp.fc.hp.com>, this patch
+ is base on his finding, with appropiate corrections.
+
+ * src/grep.c (main): Fix bug: -x and -w matched even when no
+ patterns were specified.
+ * tests/empty.sh: Test for -x and -w bug in grep 2.4.2.
+
+2000-04-24 Paul Eggert
+
+ POSIX.2 conformance fixes: grep -q now exits with status zero
+ if an input line is selected, even if an error also occurs.
+ grep -s no longer affects exit status.
+
+ * src/grep.c (suppress_errors): Move definition earlier so
+ that suppressible_error can use it.
+ (suppressible_error): New function.
+ (exit_on_match): New var.
+ (grepbuf): If exit_on_match is nonzero, exit with status zero
+ immediately.
+ (grep, grepfile, grepdir): Invoke suppressible_error.
+ (main): -q sets exit_on_match.
+
+ * doc/grep.1, doc/grep.texi, NEWS:
+ Document -q's behavior as required by POSIX.2.
+
+ * tests/status.sh:
+ Test for -q and -s behavior as conforming to POSIX.2.
+
+2000-04-20 Paul Eggert
+
+ * tests/Makefile.am (TESTS_ENVIRONMENT):
+ Set GREP_OPTIONS to the empty string.
+
+2000-04-20 Paul Eggert
+
+ * tests/status.sh: Fix typo: test -b -> test -r.
+
+2000-04-20 Paul Eggert
+
+ * src/dfa.c (lex):
+ Do not assume that [c] is equivalent to [c-c]; this isn't true
+ if LC_COLLATE specifies that some characters are equivalent.
+ (setbit_case_fold): New function.
+ (lex): Use it to simplify the code a bit.
+
+2000-04-17 Paul Eggert
+
+ Do CRLF munging only if HAVE_DOS_FILE_CONTENTS, instead of
+ having it depend on O_BINARY (which leads to incorrect results
+ on BeOS, VMS, and MacOS).
+
+ * bootstrap/Makefile.try (DEFS): Add -DHAVE_DOS_FILE_CONTENTS.
+ * src/system.h (SET_BINARY): Define only if HAVE_DOS_FILE_CONTENTS.
+ (O_BINARY): Do not define.
+
+ * m4/dosfile.m4: Define HAVE_DOS_FILE_CONTENTS if it appears we're
+ using DOS.
+
+ * src/grep.c (undossify_input, fillbuf, dosbuf.c, prline, main):
+ Depend on HAVE_DOS_FILE_CONTENTS, not O_BINARY, when handling CRLF
+ matters.
+ (grepfile, main): Depend on SET_BINARY, not O_BINARY, when
+ handling binary files on hosts that care about text versus binary.
+
+2000-04-17 Paul Eggert
+
+ * lib/getpagesize.h (getpagesize): Define to B_PAGE_SIZE if
+ __BEOS__ is defined. Based on a fix by Bruno Haible
+ <haible@clisp.cons.org>.
+
+2000-04-17 Bruno Haible
+
+ * src/system.h [BeOS]: Ignore O_BINARY.
+ * src/getpagesize.h [BeOS]: Define getpagesize() as B_PAGE_SIZE.
+
+2000-04-10 Paul Eggert
+
+ * doc/grep.1, doc/grep.texi, NEWS: -C now requires an operand.
+ * src/grep.c (short_options, long_options, main, usage): Likewise.
+ (context_length_arg): Renamed from ck_atoi. Now reports an error
+ and exits if the number is out of range for a context length.
+ (get_nondigit_option): New function, which checks for overflow
+ correctly, and which does not parse nonadjacent strings of digits
+ into a single number.
+ (main): Use get_nondigit_option instead of doing the code inline.
+ With -A, -B, and -C, optarg is now guaranteed to be nonzero.
+
+2000-04-08 Paul Eggert
+
+ Now that we know that the input is always terminated by a
+ newline before the matching algorithms see it, clean up the
+ matching algorithms so that they no longer need to modify the
+ input by inserting a sentinel newline, and no longer worry
+ about running off the end of the buffer due to a missing sentinel.
+
+ * src/grep.c (nlscan, prpending, prtext, grepbuf): Do not
+ worry about running off the end of the input buffer, since
+ it's now guaranteed to end in the sentinel newline.
+ * src/search.c (EGexecute, Pexecute): Likewise.
+
+ * src/dfa.c (prtok, dfasyntax, dfaparse, copy, merge, state_index,
+ epsclosure, dfaexec, dfacomp):
+ Change many instances of "T *" to "T const *", to catch
+ any inadvertent programming errors made during this conversion.
+ * src/dfa.h (dfacomp, dfaexec, dfaparse): Likewise.
+ * src/grep.c (struct stats.parent, long_options, grepdir,
+ compile, execute, fillbuf, lastnl, lastout, nlscan, prline,
+ prpending, prtext, grepbuf, grep, grepfile, grepdir): Likewise.
+ * src/grep.h (struct matcher.compile, struct matcher.execute):
+ Likewise.
+ * src/kwset.c (struct kwset.trans, kwsalloc, kwsincr, treefails,
+ treedelta, hasevery, treenext, bmexec, cwexec, kwsexec): Likewise.
+ * src/kwset.h (kwsalloc, kwsincr, kwsexec): Likewise.
+ * src/search.c (kwsmusts, Gcompile, Ecompile, EGexecute, Pcompile,
+ Pexecute): Likewise.
+
+ * src/dfa.c (dfaexec):
+ Use size_t, not char *, to avoid worrisome casts to convert
+ char const * to char *.
+ * src/dfa.h (dfaexec): Likewise.
+ * src/grep.c (execute): Likewise.
+ * src/grep.h (execute): Likewise.
+ * src/kwset.c (bmexec, cwexec, kwsexec): Likewise.
+ * src/kwset.h (struct kwsmatch.offset, kwsalloc, kwsincr,
+ kwsexec): Likewise.
+ * src/search.c (EGexecute, Fexecute, Pexecute): Likewise.
+
+ * src/dfa.h (_PTR_T): Depend on defined __STDC__, not __STDC__.
+ (PARAMS): Depend on PROTOTYPES, not __STDC__.
+
+ * src/dfa.c (dfasyntax): Last arg is unsigned char, not int.
+ * src/dfa.h (dfasyntax): Likewise.
+
+ * src/dfa.h (struct dfa): Remove member newlines; no longer needed.
+ * src/dfa.c (build_state, dfaexec, dfafree): Do not worry
+ about special newline state.
+
+ * src/search.c (matchers): Move definition to end of file, so
+ that we don't need forward decls.
+ (lastexact): Remove.
+ (kwset_exact_matches): New var; subsumes old lastexact var.
+ All uses changed.
+
+ * src/dfa.c (index): Remove macro.
+ (REALLOC_IF_NECESSARY): Skip unnecessary test.
+ (tstbit, setbit, clrbit): Declare arg to be unsigned, to help compiler.
+ (copyset, zeroset, equal): Use C builtin primitives, to help compiler.
+ (dfaexec): Do not modify input string.
+ Remove newline parameter; no longer needed.
+ (comsubs): Use strchr, not index.
+
+ * src/grep.h (matchers): Use fixed name size, not pointer (as
+ there's no need for the extra flexibility). All uses changed.
+
+ * src/kwset.h (struct kwsmatch.offset): Renamed from beg, with
+ change of type to size_t. All uses changed.
+
+ * src/grep.c (reset): No longer need kludge for dfaexec. Simplify.
+ (reset, grepbuf): Adjust to new interface for 'execute'.
+ (install_matcher): List is now terminated by null compile,
+ not null name.
+ Do not invoke setrlimit if that wouldn't change the limit.
+
+ * src/dfa.c (xcalloc, xmalloc, xrealloc, prtok, tstbit, setbit,
+ clrbit, copyset, zeroset, notset, equal, charclass_index,
+ looking_at, lex, addtok, atom, nsubtoks, copytoks, closure,
+ branch, regexp, copy, insert, merge, delete, state_index,
+ build_state, build_state_zero, icatalloc, icpyalloc, istrstr,
+ ifree, freelist, enlist, comsubs, addlists, inboth):
+ Remove forward decls; no longer needed.
+ * src/grep.c (ck_atoi, usage, error, setmatcher,
+ install_matcher, prepend_args, prepend_default_options,
+ page_alloc, reset, fillbuf, grepbuf, prtext, prpending, prline,
+ print_offset_sep, nlscan, grep, grepfile): Likewise.
+ * src/kwset.c (enqueue, treefails, treedelta, hasevery,
+ treenext, bmexec, cwexec): Likewise.
+ * src/search.c (Gcompile, Ecompile, EGexecute, Fcompile, Fexecute,
+ Pcompile, Pexecute, kwsinit): Likewise.
+
+ * src/search.c (Pcompile): Do not assume newly allocated
+ storage is zeroed.
+
+2000-04-06 Paul Eggert
+
+ * doc/grep.1, doc/grep.texi, NEWS: Improve the explanation of
+ locale-dependent behavior of range expressions. Mention
+ LC_COLLATE, since this affects range expressions.
+
+2000-03-26 Paul Eggert
+
+ * Makefile.am (ACINCLUDE_INPUTS): Add decl.m4, inttypes_h.m4,
+ uintmax_t.m4, ulonglong.m4, xstrtoumax.m4.
+ * m4/Makefile.am (EXTRA_DIST): Likewise.
+
+ * src/Makefile.am (base_sources):
+ Add xstrtol.c, xstrtol.h, xstrtoumax.c.
+ (EXTRA_DIST): Add strtol.c.
+
+ * configure.in (jm_AC_TYPE_UINTMAX_T, jm_AC_PREREQ_XSTRTOUMAX,
+ HAVE_DECL_STRTOUL, HAVE_DECL_STRTOULL): Add.
+ (AC_REPLACE_FUNCS): Add strtoul.
+
+ * src/grep.c: Include xstrtol.h.
+ (ck_atio): Use xstrtoumax and do proper overflow checking.
+ (max_count, outleft): Now off_t, not int.
+ (main): Likewise. Use xstrtoumax to convert max_count from string.
+
+ * acconfig.h (HAVE_DECL_STRTOUL, HAVE_DECL_STRTOULL): New #undefs.
+ (HAVE_STPCPY, ENABLE_NLS, HAVE_CATGETS, HAVE_GETTEXT,
+ HAVE_LC_MESSAGES): Remove.
+
+ * m4/decl.m4, m4/inttypes_h.m4, m4/uintmax_t.m4, m4/ulonglong.m4,
+ m4/xstrtoumax.m4, src/strtol.c, src/strtoul.c, src/strtoull.c,
+ src/strtoumax.c, src/xstrtol.c, src/xstrtol.h, src/xstrtoumax.c:
+ New files, taken unchanged from textutils, fileutils, sh-utils
+ and/or tar.
+
+2000-03-23 Paul Eggert
+
+ * src/search.c (Pcompile): Add support for NUL bytes in
+ Perl regular expressions.
+
+2000-03-23 Paul Eggert
+
+ * NEWS, doc/grep.1, doc/grep.texi: Change --pcre to --perl-regexp.
+ * src/grep.c (long_options, usage): Likewise.
+
+ * doc/grep.1, doc/grep.texi: Remove pgrep program.
+ * src/Makefile.am (bin_PROGRAMS): Likewise.
+ (pgrep_SOURCES): Remove.
+
+ * src/grep.c (main): Rename matcher from "pgrep" to "perl".
+ * src/search.c (matchers): Likewise.
+
+ * src/search.c: Do not include stdio.h; no longer needed.
+ (NILP): Remove.
+ (sub): No longer static.
+ (n_pcre): Remove.
+ (cre): No longer an array. Present only if HAVE_LIBPCRE.
+ (extra): New variable.
+ (Pcompile): Use fatal to report errors.
+ This also removes a possible core dump.
+ Add checks (marked FIXME) for restrictions in pcre.
+ Use pcre_maketables for proper localized behavior.
+ (Pcompile, Pexecute): Use GNU coding style.
+ The argument is a single pattern, not a list of patterns separated
+ by newlines; this is for consistency with grep and egrep.
+ Use pcre_study for speed.
+ (Pexecute): Abort if we lack pcre.
+ Abort if pcre_exec reports an impossible error.
+ Use code similar to the rest of search.c
+ to narrow down to the line we've found.
+
+2000-03-21 Alain Magloire
+
+ * configure.in: added AC_CHECK_LIB(pcre, pcre_exec)
+ * ChangeLog: Typos corrected.
+ * src/search.c: new MACRO HAVE_LIBPCRE
+
+2000-03-21 H.Merijn Brand
+
+ * src/Makefile.am(bin_PROGRAMS): added pgrep and new macro
+ pgrep_SOURCES.
+ * src/search.c: new functions Pcompile() and Pexecute()
+ to support PCRE. Update matcher[] array for pgrep.
+ * src/grep.c: new short and long option --pcre and -P.
+ usage() updated.
+
+2000-03-21 Bastiaan Stougie
+
+ Improvement of the -m or --max-count option. Now works for NUM > 1 and
+ prints trailing context for the last matching line.
+
+ * src/grep.c
+ (after_last_match): Is a new off_t variable that replaces inputhwm
+ to retain the correct input offset even after a call to fillbuf. Note
+ that after_last_match has a different meaning than inputhwm:
+ it always points to the offset in the input of the first byte after
+ the last matching line, and is 0 if no matching line has been found
+ yet.
+ (grep): Print trailing context after the NUMth match when the -m NUM
+ option is used.
+ (grep): Added comment. Should have been commented already.
+ (grepbuf): Now updates outleft correctly. This fixes the bug that the
+ -m NUM option did not stop after NUM lines for NUM greater than 1.
+ (grepbuf, prtext): Now update after_last_match instead of inputhwm.
+ (fillbuf): No longer updates inputhwm.
+ (prpending): When outputting trailing context of the max_count-th
+ matching line, stop at the first matching line.
+ (grepfile): Seek to after_last_match or eof, depending on the values
+ of outleft and bufmapped.
+ (usage): added the -m or --max-count option to the help message.
+ * doc/grep.texi, doc/grep.1: Document the change of the -m option.
+
+2000-03-17 Paul Eggert
+
+ Add new -m or --max-count option, based on a suggestion by
+ Bastiaan Stougie.
+
+ * doc/grep.texi, doc/grep.1: Document it.
+ * src/grep.c (short_options, long_options, main): Add it.
+ (inputhwm): New variable.
+ (fillbuf, prtext, grepbuf): Set it.
+ (bufmapped): Now a macro (defined to zero) if HAVE_MMAP is not defined.
+ (max_count, outleft): New variables.
+ (prtext, grepbuf, grep): Don't output more than outleft lines.
+ (grepfile): If grepping standard input, seek to the limit of what
+ we've read before exiting. This fixes a bug with mmapped input,
+ and is needed for proper -m support.
+ (main): Exit immediately if -m 0 is specified.
+
2000-03-08 Alain Magloire
* configure.in: version 2.4.2
@@ -45,7 +1025,7 @@
2000-01-30 Alain Magloire
* doc/grep.1: corrected typo.
- Noted by Ruslan Ermilob.
+ Noted by Ruslan Ermilov.
2000-01-30 Alain Magloire
@@ -171,7 +1151,7 @@
2000-01-04 Paul Eggert
- Inititial patch from David O'Brien.
+ Initial patch by Ruslan Ermilov.
Add --binary-files option.
* NEWS, doc/grep.1, doc/grep.texi: Document it.
diff --git a/gnu/usr.bin/grep/NEWS b/gnu/usr.bin/grep/NEWS
index 115952f..9bb8219 100644
--- a/gnu/usr.bin/grep/NEWS
+++ b/gnu/usr.bin/grep/NEWS
@@ -1,3 +1,73 @@
+Version 2.5.1
+ - This is a bugfix release. No new features.
+
+Version 2.5
+ - The new option --label allows to specify a different name for input
+ from stdin. See the man or info pages for details.
+
+ - The internal lib/getopt* files are no longer used on systems providing
+ getopt functionality in their libc (e.g. glibc 2.2.x).
+ If you need the old getopt files, use --with-included-getopt.
+
+ - The new option --only-matching (-o) will print only the part of matching
+ lines that matches the pattern. This is useful, for example, to extract
+ IP addresses from log files.
+
+ - i18n bug fixed ([A-Z0-9] wouldn't match A in locales other than C on
+ systems using recent glibc builds
+
+ - GNU grep can now be built with autoconf 2.52.
+
+ - The new option --devices controls how grep handles device files. Its usage
+ is analogous to --directories.
+
+ - The new option --line-buffered fflush on everyline. There is a noticeable
+ slow down when forcing line buffering.
+
+ - Back references are now local to the regex.
+ grep -e '\(a\)\1' -e '\(b\)\1'
+ The last backref \1 in the second expression refer to \(b\)
+
+ - The new option --include=PATTERN will only search matching files
+ when recursing in directories
+
+ - The new option --exclude=PATTERN will skip matching files when
+ recursing in directories.
+
+ - The new option --color will use the environment variable GREP_COLOR
+ (default is red) to highlight the matching string.
+ --color takes an optional argument specifying when to colorize a line:
+ --color=always, --color=tty, --color=never
+
+ - The following changes are for POSIX.2 conformance:
+
+ . The -q or --quiet or --silent option now causes grep to exit
+ with zero status when a input line is selected, even if an error
+ also occurs.
+
+ . The -s or --no-messages option no longer affects the exit status.
+
+ . Bracket regular expressions like [a-z] are now locale-dependent.
+ For example, many locales sort characters in dictionary order,
+ and in these locales the regular expression [a-d] is not
+ equivalent to [abcd]; it might be equivalent to [aBbCcDd], for
+ example. To obtain the traditional interpretation of bracket
+ expressions, you can use the C locale by setting the LC_ALL
+ environment variable to the value "C".
+
+ - The -C or --context option now requires an argument, partly for
+ consistency, and partly because POSIX.2 recommends against
+ optional arguments.
+
+ - The new -P or --perl-regexp option tells grep to interpert the pattern as
+ a Perl regular expression.
+
+ - The new option --max-count=num makes grep stop reading a file after num
+ matching lines.
+ New option -m; equivalent to --max-count.
+
+ - Translations for bg, ca, da, nb and tr have been added.
+
Version 2.4.2
- Added more check in configure to default the grep-${version}/src/regex.c
diff --git a/gnu/usr.bin/grep/THANKS b/gnu/usr.bin/grep/THANKS
index 40295fc..93dd31c 100644
--- a/gnu/usr.bin/grep/THANKS
+++ b/gnu/usr.bin/grep/THANKS
@@ -1,50 +1,72 @@
-Aharon Robbins <arnold@gnu.org>
-Akim Demaille <akim@epita.fr>
-Alain Magloire <alainm@gnu.org>
-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>
-Grant McDorman <grant@isgtec.com>
-Harald Hanche-Olsen <hanche@math.ntnu.no>
-Jeff Bailey <jbailey@nisa.net>
-Jim Hand <jhand@austx.tandem.com>
-Jim Meyering <meyering@asic.sc.ti.com>
-Jochen Hein <jochen.hein@delphi.central.de>
-Joel N. Weber II <devnull@gnu.org>
-John Hughes <john@nitelite.calvacom.fr>
-Jorge Stolfi <stolfi@dcc.unicamp.br>
-Karl Berry <karl@cs.umb.edu>
-Karl Heuer <kwzh@gnu.org>
-Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
-Kazuro Furukawa <furukawa@apricot.kek.jp>
-Keith Bostic <bostic@bsdi.com>
-Krishna Sethuraman <krishna@sgihub.corp.sgi.com>
-Mark Waite <markw@mddmew.fc.hp.com>
-Martin P.J. Zinser <zinser@decus.de>
-Martin Rex <martin.rex@sap-ag.de>
-Michael Aichlmayr <mikla@nx.com>
-Miles Bader <miles@ccs.mt.nec.co.jp>
-Olaf Kirch <okir@ns.lst.de>
-Paul Eggert <eggert@twinsun.com>
-Paul Kimoto <kimoto@spacenet.tn.cornell.edu>
-Phillip C. Brisco <phillip.craig.brisco@ccmail.census.gov>
-Philippe Defert <Philippe.Defert@cern.ch>
-Philippe De Muyter <phdm@info.ucl.ac.be>
-Roland Roberts <rroberts@muller.com>
-Ruslan Ermilov <ru@freebsd.org>
-Shannon Hill <hill@synnet.com>
-Sotiris Vassilopoulos <Sotiris.Vassilopoulos@betatech.gr>
-Stewart Levin <stew@sep.stanford.edu>
-Sydoruk Stepan <step@unitex.kiev.ua>
-Tom 'moof' Spindler <dogcow@ccs.neu.edu>
-Tom Tromey <tromey@creche.cygnus.com>
-Ulrich Drepper <drepper@cygnus.com>
-UEBAYASHI Masao <masao@nf.enveng.titech.ac.jp>
-Volker Borchert <bt@teknon.de>
-Wichert Akkerman <wakkerma@wi.leidenuniv.nl>
-William Bader <william@nscs.fast.net>
+Aharon Robbins <arnold@gnu.org>
+Akim Demaille <akim@epita.fr>
+Alain Magloire <alainm@gnu.org>
+Andreas Schwab <schwab@suse.de>
+Andreas Ley <andy@rz.uni-karlsruhe.de>
+Bastiaan "Darquan" Stougie <darquan@zonnet.nl>
+Ben Elliston <bje@cygnus.com>
+Bernd Strieder <strieder@student.uni-kl.de>
+Bernhard Rosenkraenzer <bero@redhat.com>
+Bob Proulx <rwp@hprwp.fc.hp.com>
+Brian Youmans <3diff@gnu.org>
+Bruno Haible <haible@ilog.fr>
+Christian Groessler <cpg@aladdin.de>
+David Clissold <cliss@austin.ibm.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 <laroche@redhat.com>
+Franc,ois Pinard <pinard@IRO.UMontreal.CA>
+Gerald Stoller <gerald_stoller@hotmail.com>
+Grant McDorman <grant@isgtec.com>
+Greg Louis <glouis@dynamicro.on.ca>
+Guglielmo 'bond' Bondioni <g.bondioni@libero.it>
+H. Merijn Brand <h.m.brand@hccnet.nl>
+Harald Hanche-Olsen <hanche@math.ntnu.no>
+Hans-Bernhard Broeker <broeker@physik.rwth-aachen.de>
+Heikki Korpela <heko@iki.fi>
+Isamu Hasegawa <isamu@yamato.ibm.com>
+Jeff Bailey <jbailey@nisa.net>
+Jim Hand <jhand@austx.tandem.com>
+Jim Meyering <meyering@asic.sc.ti.com>
+Jochen Hein <jochen.hein@delphi.central.de>
+Joel N. Weber II <devnull@gnu.org>
+John Hughes <john@nitelite.calvacom.fr>
+Jorge Stolfi <stolfi@dcc.unicamp.br>
+Juan Manuel Guerrero <ST001906@HRZ1.HRZ.TU-Darmstadt.De>
+Karl Berry <karl@cs.umb.edu>
+Karl Heuer <kwzh@gnu.org>
+Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
+Kazuro Furukawa <furukawa@apricot.kek.jp>
+Keith Bostic <bostic@bsdi.com>
+Krishna Sethuraman <krishna@sgihub.corp.sgi.com>
+Kurt D Schwehr <kdschweh@insci14.ucsd.edu>
+Mark Waite <markw@mddmew.fc.hp.com>
+Martin P.J. Zinser <zinser@decus.de>
+Martin Rex <martin.rex@sap-ag.de>
+Michael Aichlmayr <mikla@nx.com>
+Miles Bader <miles@ccs.mt.nec.co.jp>
+Olaf Kirch <okir@ns.lst.de>
+Paul Eggert <eggert@twinsun.com>
+Paul Kimoto <kimoto@spacenet.tn.cornell.edu>
+Phillip C. Brisco <phillip.craig.brisco@ccmail.census.gov>
+Philippe Defert <Philippe.Defert@cern.ch>
+Philippe De Muyter <phdm@info.ucl.ac.be>
+Philip Hazel <ph10@cus.cam.ac.uk>
+Roland Roberts <rroberts@muller.com>
+Ruslan Ermilov <ru@freebsd.org>
+Santiago Vila <sanvila@unex.es>
+Shannon Hill <hill@synnet.com>
+Sotiris Vassilopoulos <Sotiris.Vassilopoulos@betatech.gr>
+Stewart Levin <stew@sep.stanford.edu>
+Sydoruk Stepan <step@unitex.kiev.ua>
+Tapani Tarvainen <tt@mit.jyu.fi>
+Tom 'moof' Spindler <dogcow@ccs.neu.edu>
+Tom Tromey <tromey@creche.cygnus.com>
+Ulrich Drepper <drepper@cygnus.com>
+UEBAYASHI Masao <masao@nf.enveng.titech.ac.jp>
+Uwe H. Steinfeld <usteinfeld@gmx.net>
+Volker Borchert <bt@teknon.de>
+Wichert Akkerman <wichert@cistron.nl>
+William Bader <william@nscs.fast.net>
+Wolfgang Schludi <schludi@syscomp.de>
diff --git a/gnu/usr.bin/grep/closeout.c b/gnu/usr.bin/grep/closeout.c
new file mode 100644
index 0000000..4fdac32
--- /dev/null
+++ b/gnu/usr.bin/grep/closeout.c
@@ -0,0 +1,121 @@
+/* closeout.c - close standard output
+ Copyright (C) 1998, 1999, 2000, 2001 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
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ 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. */
+
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#if ENABLE_NLS
+# include <libintl.h>
+# define _(Text) gettext (Text)
+#else
+# define _(Text) Text
+#endif
+
+#if HAVE_STDLIB_H
+# include <stdlib.h>
+#endif
+#ifndef EXIT_FAILURE
+# define EXIT_FAILURE 1
+#endif
+
+#include <stdio.h>
+
+#include <errno.h>
+#ifndef errno
+extern int errno;
+#endif
+
+#include "closeout.h"
+#include "error.h"
+#include "quotearg.h"
+#if 0
+#include "__fpending.h"
+#endif
+
+static int default_exit_status = EXIT_FAILURE;
+static const char *file_name;
+
+/* Set the value to be used for the exit status when close_stdout is called.
+ This is useful when it is not convenient to call close_stdout_status,
+ e.g., when close_stdout is called via atexit. */
+void
+close_stdout_set_status (int status)
+{
+ default_exit_status = status;
+}
+
+/* Set the file name to be reported in the event an error is detected
+ by close_stdout_status. */
+void
+close_stdout_set_file_name (const char *file)
+{
+ file_name = file;
+}
+
+/* Close standard output, exiting with status STATUS on failure.
+ If a program writes *anything* to stdout, that program should `fflush'
+ stdout and make sure that it succeeds before exiting. Otherwise,
+ suppose that you go to the extreme of checking the return status
+ of every function that does an explicit write to stdout. The last
+ printf can succeed in writing to the internal stream buffer, and yet
+ the fclose(stdout) could still fail (due e.g., to a disk full error)
+ when it tries to write out that buffered data. Thus, you would be
+ left with an incomplete output file and the offending program would
+ exit successfully.
+
+ FIXME: note the fflush suggested above is implicit in the fclose
+ we actually do below. Consider doing only the fflush and/or using
+ setvbuf to inhibit buffering.
+
+ Besides, it's wasteful to check the return value from every call
+ that writes to stdout -- just let the internal stream state record
+ the failure. That's what the ferror test is checking below.
+
+ It's important to detect such failures and exit nonzero because many
+ tools (most notably `make' and other build-management systems) depend
+ on being able to detect failure in other tools via their exit status. */
+
+void
+close_stdout_status (int status)
+{
+ int e = ferror (stdout) ? 0 : -1;
+
+#if 0
+ if (__fpending (stdout) == 0)
+ return;
+#endif
+
+ if (fclose (stdout) != 0)
+ e = errno;
+
+ if (0 < e)
+ {
+ char const *write_error = _("write error");
+ if (file_name)
+ error (status, e, "%s: %s", quotearg_colon (file_name), write_error);
+ else
+ error (status, e, "%s", write_error);
+ }
+}
+
+/* Close standard output, exiting with status EXIT_FAILURE on failure. */
+void
+close_stdout (void)
+{
+ close_stdout_status (default_exit_status);
+}
diff --git a/gnu/usr.bin/grep/closeout.h b/gnu/usr.bin/grep/closeout.h
new file mode 100644
index 0000000..80f24e4
--- /dev/null
+++ b/gnu/usr.bin/grep/closeout.h
@@ -0,0 +1,17 @@
+#ifndef CLOSEOUT_H
+# define CLOSEOUT_H 1
+
+# ifndef PARAMS
+# if defined PROTOTYPES || (defined __STDC__ && __STDC__)
+# define PARAMS(Args) Args
+# else
+# define PARAMS(Args) ()
+# endif
+# endif
+
+void close_stdout_set_status PARAMS ((int status));
+void close_stdout_set_file_name PARAMS ((const char *file));
+void close_stdout PARAMS ((void));
+void close_stdout_status PARAMS ((int status));
+
+#endif
diff --git a/gnu/usr.bin/grep/doc/grep.texi b/gnu/usr.bin/grep/doc/grep.texi
index beb2410..32b27c4 100644
--- a/gnu/usr.bin/grep/doc/grep.texi
+++ b/gnu/usr.bin/grep/doc/grep.texi
@@ -35,7 +35,8 @@ Published by the Free Software Foundation,
59 Temple Place - Suite 330
Boston, MA 02111-1307, USA
-Copyright 2000 Free Software Foundation, Inc.
+@c man begin COPYRIGHT
+Copyright @copyright{} 2000, 2001 Free Software Foundation, Inc.
Permission is granted to make and distribute verbatim copies of
this manual provided the copyright notice and this permission notice
@@ -43,20 +44,19 @@ are preserved on all copies.
@ignore
Permission is granted to process this file through TeX and print the
-results, provided the printed document carries copying permission
+results, provided the printed document carries a copying permission
notice identical to this one except for the removal of this paragraph
(this paragraph not being relevant to the printed manual).
@end ignore
-Permission is granted to copy and distribute modified versions of this
-manual under the conditions for verbatim copying, provided that the entire
-resulting derived work is distributed under the terms of a permission
-notice identical to this one.
-
-Permission is granted to copy and distribute translations of this manual
-into another language, under the above conditions for modified versions,
-except that this permission notice may be stated in a translation approved
-by the Foundation.
+Permission is granted to copy, distribute and/or modify this document
+under the terms of the GNU Free Documentation License, Version 1.1 or
+any later version published by the Free Software Foundation; with the
+Invariant Sections being ``GNU General Public License'' and ``GNU Free
+Documentation License'', with no Front-Cover Texts, and with no
+Back-Cover Texts. A copy of the license is included in the section
+entitled ``GNU Free Documentation License'' (@pxref{Copying}).
+@c man end
@end ifinfo
@setchapternewpage off
@@ -68,29 +68,21 @@ by the Foundation.
@page
@vskip 0pt plus 1filll
-Copyright @copyright{} 2000 Free Software Foundation, Inc.
+Copyright @copyright{} 2000, 2001 Free Software Foundation, Inc.
@sp 2
Published by the Free Software Foundation, @*
59 Temple Place - Suite 330, @*
Boston, MA 02111-1307, USA
-Permission is granted to make and distribute verbatim copies of
-this manual provided the copyright notice and this permission notice
-are preserved on all copies.
-
-Permission is granted to copy and distribute modified versions of this
-manual under the conditions for verbatim copying, provided that the entire
-resulting derived work is distributed under the terms of a permission
-notice identical to this one.
-
-Permission is granted to copy and distribute translations of this manual
-into another language, under the above conditions for modified versions,
-except that this permission notice may be stated in a translation approved
-by the Foundation.
-
+Permission is granted to copy, distribute and/or modify this document
+under the terms of the GNU Free Documentation License, Version 1.1 or
+any later version published by the Free Software Foundation; with the
+Invariant Sections being ``GNU General Public License'' and ``GNU Free
+Documentation License'', with no Front-Cover Texts, and with no
+Back-Cover Texts. A copy of the license is included in the section
+entitled ``GNU Free Documentation License''.
@end titlepage
-@page
@ifnottex
@@ -111,13 +103,14 @@ This document was produced for version @value{VERSION} of @sc{gnu}
* Regular Expressions:: Regular Expressions.
* Usage:: Examples.
* Reporting Bugs:: Reporting Bugs.
+* Copying:: License terms.
* Concept Index:: A menu with all the topics in this manual.
* Index:: A menu with all @command{grep} commands
and command-line options.
@end menu
-@node Introduction
+@node Introduction, Invoking, Top, Top
@chapter Introduction
@cindex Searching for a pattern.
@@ -147,7 +140,7 @@ extensions.
@item -c
@itemx --count
@opindex -c
-@opindex -count
+@opindex --count
@cindex counting lines
Suppress normal output; instead print a count of matching
lines for each input file. With the @samp{-v}, @samp{--invert-match} option,
@@ -192,6 +185,13 @@ The scanning of every file will stop on the first match.
@cindex line numbering
Prefix each line of output with the line number within its input file.
+@item -o
+@itemx --only-matching
+@opindex -o
+@opindex --only-matching
+@cindex only matching
+Print only the part of matching lines that actually matches @var{pattern}.
+
@item -q
@itemx --quiet
@itemx --silent
@@ -199,8 +199,9 @@ Prefix each line of output with the line number within its input file.
@opindex --quiet
@opindex --silent
@cindex quiet, silent
-Quiet; suppress normal output. The scanning of every file will stop on
-the first match. Also see the @samp{-s} or @samp{--no-messages} option.
+Quiet; do not write anything to standard output. Exit immediately with
+zero status if any match is found, even if an error was detected. Also
+see the @samp{-s} or @samp{--no-messages} option.
@item -s
@itemx --no-messages
@@ -254,12 +255,18 @@ Print @var{num} lines of trailing context after matching lines.
Print @var{num} lines of leading context before matching lines.
@item -C @var{num}
-@itemx --context=[@var{num}]
+@itemx --context=@var{num}
@opindex -C
@opindex --context
@cindex context
-Print @var{num} lines (default 2) of output context.
+Print @var{num} lines of output context.
+@item --colour[=@var{WHEN}]
+@itemx --color[=@var{WHEN}]
+@opindex --colour
+@cindex highlight, color, colour
+The matching string is surrounded by the marker specify in @var{GREP_COLOR}.
+@var{WHEN} may be `never', `always', or `auto'.
@item -@var{num}
@opindex -NUM
@@ -308,6 +315,17 @@ byte offsets
depend on whether the @samp{-u} (@samp{--unix-byte-offsets}) option is
used; see below.
+@item -D @var{action}
+@itemx --devices=@var{action}
+@opindex -D
+@opindex --devices
+@cindex device search
+If an input file is a device, FIFO or socket, use @var{action} to process it.
+By default, @var{action} is @samp{read}, which means that devices are
+read just as if they were ordinary files.
+If @var{action} is @samp{skip}, devices, FIFOs and sockets are silently
+skipped.
+
@item -d @var{action}
@itemx --directories=@var{action}
@opindex -d
@@ -317,10 +335,10 @@ If an input file is a directory, use @var{action} to process it.
By default, @var{action} is @samp{read}, which means that directories are
read just as if they were ordinary files (some operating systems
and filesystems disallow this, and will cause @command{grep} to print error
-messages for every directory). If @var{action} is @samp{skip},
-directories are silently skipped. If @var{action} is @samp{recurse},
-@command{grep} reads all files under each directory, recursively; this is
-equivalent to the @samp{-r} option.
+messages for every directory or silently skip them). If @var{action} is
+@samp{skip}, directories are silently skipped. If @var{action} is
+@samp{recurse}, @command{grep} reads all files under each directory,
+recursively; this is equivalent to the @samp{-r} option.
@item -H
@itemx --with-filename
@@ -336,6 +354,18 @@ Print the filename for each match.
@cindex no filename prefix
Suppress the prefixing of filenames on output when multiple files are searched.
+@item --line-buffered
+@opindex --line-buffered
+@cindex line buffering
+Set the line buffering policy, this can be a performance penality.
+
+@item --label=@var{LABEL}
+@opindex --label
+@cindex changing name of standard input
+Displays input actually coming from standard input as input coming from file
+@var{LABEL}. This is especially useful for tools like zgrep, e.g.
+@command{gzip -cd foo.gz |grep --label=foo something}
+
@item -L
@itemx --files-without-match
@opindex -L
@@ -372,14 +402,69 @@ a non-word constituent character. Word-constituent
characters are letters, digits, and the underscore.
@item -r
+@itemx -R
@itemx --recursive
@opindex -r
@opindex --recursive
@cindex recursive search
@cindex searching directory trees
For each directory mentioned in the command line, read and process all
-files in that directory, recursively. This is the same as the @samp{-d
-recurse} option.
+files in that directory, recursively. This is the same as the
+@samp{--directories=recurse} option.
+
+@item --include=@var{file_pattern}
+@opindex --include
+@cindex include files
+@cindex searching directory trees
+When processing directories recursively, only files matching @var{file_pattern}
+will be search.
+
+@item --exclude=@var{file_pattern}
+@opindex --exclude
+@cindex exclude files
+@cindex searching directory trees
+When processing directories recursively, skip files matching @var{file_pattern}.
+
+@item -m @var{num}
+@itemx --max-count=@var{num}
+@opindex -m
+@opindex --max-count
+@cindex max-count
+Stop reading a file after @var{num} matching lines. If the input is
+standard input from a regular file, and @var{num} matching lines are
+output, @command{grep} ensures that the standard input is positioned to
+just after the last matching line before exiting, regardless of the
+presence of trailing context lines. This enables a calling process
+to resume a search. For example, the following shell script makes use
+of it:
+
+@example
+while grep -m 1 PATTERN
+do
+ echo xxxx
+done < FILE
+@end example
+
+But the following probably will not work because a pipe is not a regular
+file:
+
+@example
+# This probably will not work.
+cat FILE |
+while grep -m 1 PATTERN
+do
+ echo xxxx
+done
+@end example
+
+When @command{grep} stops after NUM matching lines, it outputs
+any trailing context lines. Since context does not include matching
+lines, @command{grep} will stop when it encounters another matching line.
+When the @samp{-c} or @samp{--count} option is also used,
+@command{grep} does not output a count greater than @var{num}.
+When the @samp{-v} or @samp{--invert-match} option is
+also used, @command{grep} stops after outputting @var{num}
+non-matching lines.
@item -y
@opindex -y
@@ -460,9 +545,20 @@ matching engine is used. @xref{Grep Programs}.
@section Environment Variables
Grep's behavior is affected by the following environment variables.
+
+A locale @code{LC_@var{foo}} is specified by examining the three
+environment variables @env{LC_ALL}, @env{LC_@var{foo}}, and @env{LANG},
+in that order. The first of these variables that is set specifies the
+locale. For example, if @env{LC_ALL} is not set, but @env{LC_MESSAGES}
+is set to @samp{pt_BR}, then Brazilian Portuguese is used for the
+@code{LC_MESSAGES} locale. The C locale is used if none of these
+environment variables are set, or if the locale catalog is not
+installed, or if @command{grep} was not compiled with national language
+support (@sc{nls}).
+
@cindex environment variables
-@table @code
+@table @env
@item GREP_OPTIONS
@vindex GREP_OPTIONS
@@ -476,23 +572,24 @@ any explicit options. Option specifications are separated by
whitespace. A backslash escapes the next character, so it can be used to
specify an option containing whitespace or a backslash.
+@item GREP_COLOR
+@vindex GREP_COLOR
+@cindex highlight markers
+This variable specifies the surrounding markers use to highlight the matching
+text. The default is control ascii red.
+
@item LC_ALL
-@itemx LC_MESSAGES
+@itemx LC_COLLATE
@itemx LANG
@vindex LC_ALL
-@vindex LC_MESSAGES
+@vindex LC_COLLATE
@vindex LANG
-@cindex language of messages
-@cindex message language
+@cindex character type
@cindex national language support
@cindex NLS
-@cindex translation of message language
-These variables specify the @code{LC_MESSAGES} locale, which determines
-the language that @command{grep} uses for messages. The locale is determined
-by the first of these variables that is set. American English is used
-if none of these environment variables are set, or if the message
-catalog is not installed, or if @command{grep} was not compiled with national
-language support (@sc{nls}).
+These variables specify the @code{LC_COLLATE} locale, which determines
+the collating sequence used to interpret range expressions like
+@samp{[a-z]}.
@item LC_ALL
@itemx LC_CTYPE
@@ -504,11 +601,22 @@ language support (@sc{nls}).
@cindex national language support
@cindex NLS
These variables specify the @code{LC_CTYPE} locale, which determines the
-type of characters, e.g., which characters are whitespace. The locale is
-determined by the first of these variables that is set. The @sc{posix}
-locale is used if none of these environment variables are set, or if the
-locale catalog is not installed, or if @command{grep} was not compiled with
-national language support (@sc{nls}).
+type of characters, e.g., which characters are whitespace.
+
+@item LC_ALL
+@itemx LC_MESSAGES
+@itemx LANG
+@vindex LC_ALL
+@vindex LC_MESSAGES
+@vindex LANG
+@cindex language of messages
+@cindex message language
+@cindex national language support
+@cindex NLS
+@cindex translation of message language
+These variables specify the @code{LC_MESSAGES} locale, which determines
+the language that @command{grep} uses for messages. The default C
+locale uses American English messages.
@item POSIXLY_CORRECT
@vindex POSIXLY_CORRECT
@@ -539,10 +647,10 @@ only when @code{POSIXLY_CORRECT} is not set.
@node Diagnostics
@chapter Diagnostics
-Normally, exit status is 0 if matches were found, and 1 if no matches
-were found (the @samp{-v} option inverts the sense of the exit status).
-Exit status is 2 if there were syntax errors in the pattern,
-inaccessible input files, or other system errors.
+Normally, exit status is 0 if selected lines are found and 1 otherwise.
+But the exit status is 2 if an error occurred, unless the @option{-q} or
+@option{--quiet} or @option{--silent} option is used and a selected line
+is found.
@node Grep Programs
@chapter @command{grep} programs
@@ -550,7 +658,7 @@ inaccessible input files, or other system errors.
@command{grep} searches the named input files (or standard input if no
files are named, or the file name @file{-} is given) for lines containing
a match to the given pattern. By default, @command{grep} prints the
-matching lines. There are three major variants of @command{grep},
+matching lines. There are four major variants of @command{grep},
controlled by the following options.
@table @samp
@@ -560,24 +668,30 @@ controlled by the following options.
@opindex -G
@opindex --basic-regexp
@cindex matching basic regular expressions
-Interpret pattern as a basic regular expression. This is the default.
+Interpret the pattern as a basic regular expression. This is the default.
@item -E
@itemx --extended-regexp
@opindex -E
@opindex --extended-regexp
@cindex matching extended regular expressions
-Interpret pattern as an extended regular expression.
-
+Interpret the pattern as an extended regular expression.
@item -F
@itemx --fixed-strings
@opindex -F
@opindex --fixed-strings
@cindex matching fixed strings
-Interpret pattern as a list of fixed strings, separated
+Interpret the pattern as a list of fixed strings, separated
by newlines, any of which is to be matched.
+@item -P
+@itemx --perl-regexp
+@opindex -P
+@opindex --perl-regexp
+@cindex matching Perl regular expressions
+Interpret the pattern as a Perl regular expression.
+
@end table
In addition, two variant programs @sc{egrep} and @sc{fgrep} are available.
@@ -592,8 +706,8 @@ A @dfn{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.
@command{grep} understands two different versions of regular expression
-syntax: ``basic'' and ``extended''. In @sc{gnu} @command{grep}, there is no
-difference in available functionality using either syntax.
+syntax: ``basic''(BRE) and ``extended''(ERE). In @sc{gnu} @command{grep},
+there is no difference in available functionality using either syntax.
In other implementations, basic regular expressions are less powerful.
The following description applies to extended regular expressions;
differences for basic regular expressions are summarized afterwards.
@@ -602,17 +716,92 @@ The fundamental building blocks are the regular expressions that match
a single character. Most characters, including all letters and digits,
are regular expressions that match themselves. Any metacharacter
with special meaning may be quoted by preceding it with a backslash.
-A list of characters enclosed by @samp{[} and @samp{]} matches any
-single character in that list; if the first character of the list is the
-caret @samp{^}, then it
-matches any character @strong{not} in the list. For example, the regular
-expression @samp{[0123456789]} matches any single digit.
-A range of characters may be specified by giving the first
-and last characters, separated by a hyphen.
-
-Finally, certain named classes of characters are predefined, as follows.
+
+A regular expression may be followed by one of several
+repetition operators:
+
+@table @samp
+
+@item .
+@opindex .
+@cindex dot
+@cindex period
+The period @samp{.} matches any single character.
+
+@item ?
+@opindex ?
+@cindex question mark
+@cindex match sub-expression at most once
+The preceding item is optional and will be matched at most once.
+
+@item *
+@opindex *
+@cindex asterisk
+@cindex match sub-expression zero or more times
+The preceding item will be matched zero or more times.
+
+@item +
+@opindex +
+@cindex plus sign
+The preceding item will be matched one or more times.
+
+@item @{@var{n}@}
+@opindex @{n@}
+@cindex braces, one argument
+@cindex match sub-expression n times
+The preceding item is matched exactly @var{n} times.
+
+@item @{@var{n},@}
+@opindex @{n,@}
+@cindex braces, second argument omitted
+@cindex match sub-expression n or more times
+The preceding item is matched n or more times.
+
+@item @{@var{n},@var{m}@}
+@opindex @{n,m@}
+@cindex braces, two arguments
+The preceding item is matched at least @var{n} times, but not more than
+@var{m} times.
+
+@end table
+
+Two regular expressions may be concatenated; the resulting regular
+expression matches any string formed by concatenating two substrings
+that respectively match the concatenated subexpressions.
+
+Two regular expressions may be joined by the infix operator @samp{|}; the
+resulting regular expression matches any string matching either subexpression.
+
+Repetition takes precedence over concatenation, which in turn
+takes precedence over alternation. A whole subexpression may be
+enclosed in parentheses to override these precedence rules.
+
+@section Character Class
+
+@cindex bracket expression
+@cindex character class
+A @dfn{bracket expression} is a list of characters enclosed by @samp{[} and
+@samp{]}. It matches any single character in that list; if the first
+character of the list is the caret @samp{^}, then it matches any character
+@strong{not} in the list. For example, the regular expression
+@samp{[0123456789]} matches any single digit.
+
+@cindex range expression
+Within a bracket expression, a @dfn{range expression} consists of two
+characters separated by a hyphen. It matches any single character that
+sorts between the two characters, inclusive, using the locale's
+collating sequence and character set. For example, in the default C
+locale, @samp{[a-d]} is equivalent to @samp{[abcd]}. Many locales sort
+characters in dictionary order, and in these locales @samp{[a-d]} is
+typically not equivalent to @samp{[abcd]}; it might be equivalent to
+@samp{[aBbCcDd]}, for example. To obtain the traditional interpretation
+of bracket expressions, you can use the C locale by setting the
+@env{LC_ALL} environment variable to the value @samp{C}.
+
+Finally, certain named classes of characters are predefined within
+bracket expressions, as follows.
Their interpretation depends on the @code{LC_CTYPE} locale; the
-interpretation below is that of the @sc{posix} locale, which is the default
+interpretation below is that of the C locale, which is the default
if no @code{LC_CTYPE} locale is specified.
@cindex classes of characters
@@ -696,86 +885,100 @@ Hexadecimal digits:
@end table
For example, @samp{[[:alnum:]]} means @samp{[0-9A-Za-z]}, except the latter
-depends upon the @sc{posix} locale and the @sc{ascii} character
+depends upon the C locale and the @sc{ascii} character
encoding, whereas the former is independent of locale and character set.
(Note that the brackets in these class names are
part of the symbolic names, and must be included in addition to
-the brackets delimiting the bracket list.) Most metacharacters lose
-their special meaning inside lists. To include a literal @samp{]}, place it
-first in the list. Similarly, to include a literal @samp{^}, place it anywhere
-but first. Finally, to include a literal @samp{-}, place it last.
+the brackets delimiting the bracket list.)
-The period @samp{.} matches any single character. The symbol @samp{\w}
-is a synonym for @samp{[[:alnum:]]} and @samp{\W} is a synonym for
-@samp{[^[:alnum]]}.
+Most metacharacters lose their special meaning inside lists.
-The caret @samp{^} and the dollar sign @samp{$} are metacharacters that
-respectively match the empty string at the beginning and end
-of a line. The symbols @samp{\<} and @samp{\>} respectively match the
-empty string at the beginning and end of a word. The symbol
-@samp{\b} matches the empty string at the edge of a word, and @samp{\B}
-matches the empty string provided it's not at the edge of a word.
+@table @samp
+@item ]
+ends the list if it's not the first list item. So, if you want to make
+the @samp{]} character a list item, you must put it first.
-A regular expression may be followed by one of several
-repetition operators:
+@item [.
+represents the open collating symbol.
+
+@item .]
+represents the close collating symbol.
+
+@item [=
+represents the open equivalence class.
+@item =]
+represents the close equivalence class.
+
+@item [:
+represents the open character class followed by a valid character class name.
+
+@item :]
+represents the close character class followed by a valid character class name.
+
+@item -
+represents the range if it's not first or last in a list or the ending point
+of a range.
+
+@item ^
+represents the characters not in the list. If you want to make the @samp{^}
+character a list item, place it anywhere but first.
+
+@end table
+
+@section Backslash Character
+@cindex backslash
+
+The @samp{\} when followed by certain ordinary characters take a special
+meaning :
@table @samp
-@item ?
-@opindex ?
-@cindex question mark
-@cindex match sub-expression at most once
-The preceding item is optional and will be matched at most once.
+@item @samp{\b}
+Match the empty string at the edge of a word.
-@item *
-@opindex *
-@cindex asterisk
-@cindex match sub-expression zero or more times
-The preceding item will be matched zero or more times.
+@item @samp{\B}
+Match the empty string provided it's not at the edge of a word.
-@item +
-@opindex +
-@cindex plus sign
-The preceding item will be matched one or more times.
+@item @samp{\<}
+Match the empty string at the beginning of word.
-@item @{@var{n}@}
-@opindex @{n@}
-@cindex braces, one argument
-@cindex match sub-expression n times
-The preceding item is matched exactly @var{n} times.
+@item @samp{\>}
+Match the empty string at the end of word.
-@item @{@var{n},@}
-@opindex @{n,@}
-@cindex braces, second argument omitted
-@cindex match sub-expression n or more times
-The preceding item is matched n or more times.
+@item @samp{\w}
+Match word constituent, it is a synonym for @samp{[[:alnum:]]}.
-@item @{@var{n},@var{m}@}
-@opindex @{n,m@}
-@cindex braces, two arguments
-The preceding item is matched at least @var{n} times, but not more than
-@var{m} times.
+@item @samp{\W}
+Match non word constituent, it is a synonym for @samp{[^[:alnum:]]}.
@end table
-Two regular expressions may be concatenated; the resulting regular
-expression matches any string formed by concatenating two substrings
-that respectively match the concatenated subexpressions.
+For example , @samp{\brat\b} matches the separate word @samp{rat},
+@samp{c\Brat\Be} matches @samp{crate}, but @samp{dirty \Brat} doesn't
+match @samp{dirty rat}.
-Two regular expressions may be joined by the infix operator @samp{|}; the
-resulting regular expression matches any string matching either
-subexpression.
+@section Anchoring
+@cindex anchoring
-Repetition takes precedence over concatenation, which in turn
-takes precedence over alternation. A whole subexpression may be
-enclosed in parentheses to override these precedence rules.
+The caret @samp{^} and the dollar sign @samp{$} are metacharacters that
+respectively match the empty string at the beginning and end of a line.
+
+@section Back-reference
+@cindex back-reference
-The backreference @samp{\@var{n}}, where @var{n} is a single digit, matches the
-substring previously matched by the @var{n}th parenthesized subexpression
-of the regular expression.
+The back-reference @samp{\@var{n}}, where @var{n} is a single digit, matches
+the substring previously matched by the @var{n}th parenthesized subexpression
+of the regular expression. For example, @samp{(a)\1} matches @samp{aa}.
+When use with alternation if the group does not participate in the match, then
+the back-reference makes the whole match fail. For example, @samp{a(.)|b\1}
+will not match @samp{ba}. When multiple regular expressions are given with
+@samp{-e} or from a file @samp{-f file}, the back-referecences are local to
+each expression.
+@section Basic vs Extended
@cindex basic regular expressions
+
In basic regular expressions the metacharacters @samp{?}, @samp{+},
@samp{@{}, @samp{|}, @samp{(}, and @samp{)} lose their special meaning;
instead use the backslashed versions @samp{\?}, @samp{\+}, @samp{\@{},
@@ -825,7 +1028,7 @@ How can I list just the names of matching files?
@example
grep -l 'main' *.c
-@end example
+@end example
@noindent
lists the names of all C files in the current directory whose contents
@@ -848,12 +1051,23 @@ the following command searches only C files:
find /home/gigi -name '*.c' -print | xargs grep 'hello' /dev/null
@end smallexample
+This differs from the command:
+
+@example
+grep -r 'hello' *.c
+@end example
+
+which merely looks for @samp{hello} in all files in the current
+directory whose names end in @samp{.c}. Here the @option{-r} is
+probably unnecessary, as recursion occurs only in the unlikely event
+that one of @samp{.c} files is a directory.
+
@item
What if a pattern has a leading @samp{-}?
@example
grep -e '--cut here--' *
-@end example
+@end example
@noindent
searches for all lines matching @samp{--cut here--}. Without @samp{-e},
@@ -899,6 +1113,12 @@ Append @file{/dev/null}:
grep 'eli' /etc/passwd /dev/null
@end example
+gets you:
+
+@smallexample
+/etc/passwd:eli:DNGUTF58.IMe.:98:11:Eli Smith:/home/do/eli:/bin/bash
+@end smallexample
+
@item
Why do people use strange regular expressions on @command{ps} output?
@@ -909,6 +1129,9 @@ ps -ef | grep '[c]ron'
If the pattern had been written without the square brackets, it would
have matched not only the @command{ps} output line for @command{cron},
but also the @command{ps} output line for @command{grep}.
+Note that some platforms @command{ps} limit the ouput to the width
+of the screen, grep does not have any limit on the length of a line
+except the available memory.
@item
Why does @command{grep} report ``Binary file matches''?
@@ -948,23 +1171,905 @@ Use the special file name @samp{-}:
@example
cat /etc/passwd | grep 'alain' - /etc/motd
@end example
+
+@item
+@cindex palindromes
+How to express palindromes in a regular expression?
+
+It can be done by using the back referecences, for example a palindrome
+of 4 chararcters can be written in BRE.
+
+@example
+grep -w -e '\(.\)\(.\).\2\1' file
+@end example
+
+It matches the word "radar" or "civic".
+
+Guglielmo Bondioni proposed a single RE that finds all the palindromes up to 19
+characters long.
+
+@example
+egrep -e '^(.?)(.?)(.?)(.?)(.?)(.?)(.?)(.?)(.?).?\9\8\7\6\5\4\3\2\1$' file
+@end example
+
+Note this is done by using GNU ERE extensions, it might not be portable on
+other greps.
+
+@item
+Why are my expressions whith the vertical bar fail?
+
+@example
+/bin/echo "ba" | egrep '(a)\1|(b)\1'
+@end example
+
+The first alternate branch fails then the first group was not in the match
+this will make the second alternate branch fails. For example, "aaba" will
+match, the first group participate in the match and can be reuse in the
+second branch.
+
+@item
+What do @command{grep, fgrep, egrep} stand for ?
+
+grep comes from the way line editing was done on Unix. For example,
+@command{ed} uses this syntax to print a list of matching lines on the screen.
+
+@example
+global/regular expression/print
+g/re/p
+@end example
+
+@command{fgrep} stands for Fixed @command{grep}, @command{egrep} Extended
+@command{grep}.
+
@end enumerate
-@node Reporting Bugs
+@node Reporting Bugs, Copying, Usage, Top
@chapter Reporting bugs
@cindex Bugs, reporting
Email bug reports to @email{bug-gnu-utils@@gnu.org}.
Be sure to include the word ``grep'' somewhere in the ``Subject:'' field.
-Large repetition counts in the @samp{@{m,n@}} construct may cause
+Large repetition counts in the @samp{@{n,m@}} construct may cause
@command{grep} to use lots of memory. In addition, certain other
obscure regular expressions require exponential time and
space, and may cause grep to run out of memory.
-Backreferences are very slow, and may require exponential time.
+Back-references are very slow, and may require exponential time.
+
+@node Copying, GNU General Public License, Reporting Bugs, Top
+@chapter Copying
+@cindex Copying
+GNU grep is licensed under the GNU GPL, which makes it @dfn{free
+software}.
+
+Please note that ``free'' in ``free software'' refers to liberty, not
+price. As some GNU project advocates like to point out, think of ``free
+speech'' rather than ``free beer''. The exact and legally binding
+distribution terms are spelled out below; in short, you have the right
+(freedom) to run and change grep and distribute it to other people, and
+even---if you want---charge money for doing either. The important
+restriction is that you have to grant your recipients the same rights
+and impose the same restrictions.
+
+This method of licensing software is also known as @dfn{open source}
+because, among other things, it makes sure that all recipients will
+receive the source code along with the program, and be able to improve
+it. The GNU project prefers the term ``free software'' for reasons
+outlined at
+@url{http://www.gnu.org/philosophy/free-software-for-freedom.html}.
+
+The exact license terms are defined by this paragraph and the GNU
+General Public License it refers to:
+
+@quotation
+GNU grep is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation; either version 2 of the License, or (at your
+option) any later version.
+
+GNU grep is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+A copy of the GNU General Public License is included as part of this
+manual; if you did not receive it, write to the Free Software
+Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+@end quotation
+
+In addition to this, this manual is free in the same sense:
+
+@quotation
+Permission is granted to copy, distribute and/or modify this document
+under the terms of the GNU Free Documentation License, Version 1.1 or
+any later version published by the Free Software Foundation; with the
+Invariant Sections being ``GNU General Public License'' and ``GNU Free
+Documentation License'', with no Front-Cover Texts, and with no
+Back-Cover Texts. A copy of the license is included in the section
+entitled ``GNU Free Documentation License''.
+@end quotation
+
+@c #### Maybe we should wrap these licenses in ifinfo? Stallman says
+@c that the GFDL needs to be present in the manual, and to me it would
+@c suck to include the license for the manual and not the license for
+@c the program.
+
+The full texts of the GNU General Public License and of the GNU Free
+Documentation License are available below.
+
+@menu
+* GNU General Public License:: GNU GPL
+* GNU Free Documentation License:: GNU FDL
+@end menu
+
+@node GNU General Public License, GNU Free Documentation License, Copying, Copying
+@section GNU General Public License
+@center Version 2, June 1991
+@cindex GPL, GNU General Public License
+
+@display
+Copyright @copyright{} 1989, 1991 Free Software Foundation, Inc.
+675 Mass Ave, Cambridge, MA 02139, USA
+
+Everyone is permitted to copy and distribute verbatim copies
+of this license document, but changing it is not allowed.
+@end display
+
+@unnumberedsec Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software---to make sure the software is free for all its users. This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it. (Some other Free Software Foundation software is covered by
+the GNU Library General Public License instead.) You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+ To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have. You must make sure that they, too, receive or can get the
+source code. And you must show them these terms so they know their
+rights.
+
+ We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+ Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software. If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+ Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary. To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+@iftex
+@unnumberedsec TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+@end iftex
+@ifinfo
+@center TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+@end ifinfo
+
+@enumerate
+@item
+This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License. The ``Program'', below,
+refers to any such program or work, and a ``work based on the Program''
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language. (Hereinafter, translation is included without limitation in
+the term ``modification''.) Each licensee is addressed as ``you''.
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+@item
+You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+@item
+You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+@enumerate a
+@item
+You must cause the modified files to carry prominent notices
+stating that you changed the files and the date of any change.
+
+@item
+You must cause any work that you distribute or publish, that in
+whole or in part contains or is derived from the Program or any
+part thereof, to be licensed as a whole at no charge to all third
+parties under the terms of this License.
+
+@item
+If the modified program normally reads commands interactively
+when run, you must cause it, when started running for such
+interactive use in the most ordinary way, to print or display an
+announcement including an appropriate copyright notice and a
+notice that there is no warranty (or else, saying that you provide
+a warranty) and that users may redistribute the program under
+these conditions, and telling the user how to view a copy of this
+License. (Exception: if the Program itself is interactive but
+does not normally print such an announcement, your work based on
+the Program is not required to print an announcement.)
+@end enumerate
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+@item
+You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+@enumerate a
+@item
+Accompany it with the complete corresponding machine-readable
+source code, which must be distributed under the terms of Sections
+1 and 2 above on a medium customarily used for software interchange; or,
+
+@item
+Accompany it with a written offer, valid for at least three
+years, to give any third party, for a charge no more than your
+cost of physically performing source distribution, a complete
+machine-readable copy of the corresponding source code, to be
+distributed under the terms of Sections 1 and 2 above on a medium
+customarily used for software interchange; or,
+
+@item
+Accompany it with the information you received as to the offer
+to distribute corresponding source code. (This alternative is
+allowed only for noncommercial distribution and only if you
+received the program in object code or executable form with such
+an offer, in accord with Subsection b above.)
+@end enumerate
+
+The source code for a work means the preferred form of the work for
+making modifications to it. For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable. However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+@item
+You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License. Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+@item
+You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Program or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+@item
+Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+@item
+If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all. For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+@item
+If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded. In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+@item
+The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Program
+specifies a version number of this License which applies to it and ``any
+later version'', you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation. If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+@item
+If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission. For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this. Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+@iftex
+@heading NO WARRANTY
+@end iftex
+@ifinfo
+@center NO WARRANTY
+@end ifinfo
+@cindex no warranty
+
+@item
+BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM ``AS IS'' WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+@item
+IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+@end enumerate
+
+@iftex
+@heading END OF TERMS AND CONDITIONS
+@end iftex
+@ifinfo
+@center END OF TERMS AND CONDITIONS
+@end ifinfo
+
+@page
+@unnumberedsec How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the ``copyright'' line and a pointer to where the full notice is found.
+
+@smallexample
+@var{one line to give the program's name and an idea of what it does.}
+Copyright (C) 19@var{yy} @var{name of author}
+
+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 the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+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., 675 Mass Ave, Cambridge, MA 02139, USA.
+@end smallexample
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+@smallexample
+Gnomovision version 69, Copyright (C) 19@var{yy} @var{name of author}
+Gnomovision comes with ABSOLUTELY NO WARRANTY; for details
+type `show w'. This is free software, and you are welcome
+to redistribute it under certain conditions; type `show c'
+for details.
+@end smallexample
+
+The hypothetical commands @samp{show w} and @samp{show c} should show
+the appropriate parts of the General Public License. Of course, the
+commands you use may be called something other than @samp{show w} and
+@samp{show c}; they could even be mouse-clicks or menu items---whatever
+suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a ``copyright disclaimer'' for the program, if
+necessary. Here is a sample; alter the names:
+
+@smallexample
+@group
+Yoyodyne, Inc., hereby disclaims all copyright
+interest in the program `Gnomovision'
+(which makes passes at compilers) written
+by James Hacker.
+
+@var{signature of Ty Coon}, 1 April 1989
+Ty Coon, President of Vice
+@end group
+@end smallexample
+
+This General Public License does not permit incorporating your program into
+proprietary programs. If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library. If this is what you want to do, use the GNU Library General
+Public License instead of this License.
+
+@node GNU Free Documentation License, Concept Index, GNU General Public License, Copying
+@section GNU Free Documentation License
+@center Version 1.1, March 2000
+@cindex FDL, GNU Free Documentation License
+
+@display
+Copyright (C) 2000 Free Software Foundation, Inc.
+59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+Everyone is permitted to copy and distribute verbatim copies
+of this license document, but changing it is not allowed.
+@end display
+@sp 1
+@enumerate 0
+@item
+PREAMBLE
+
+The purpose of this License is to make a manual, textbook, or other
+written document ``free'' in the sense of freedom: to assure everyone
+the effective freedom to copy and redistribute it, with or without
+modifying it, either commercially or noncommercially. Secondarily,
+this License preserves for the author and publisher a way to get
+credit for their work, while not being considered responsible for
+modifications made by others.
+
+This License is a kind of ``copyleft'', which means that derivative
+works of the document must themselves be free in the same sense. It
+complements the GNU General Public License, which is a copyleft
+license designed for free software.
+
+We have designed this License in order to use it for manuals for free
+software, because free software needs free documentation: a free
+program should come with manuals providing the same freedoms that the
+software does. But this License is not limited to software manuals;
+it can be used for any textual work, regardless of subject matter or
+whether it is published as a printed book. We recommend this License
+principally for works whose purpose is instruction or reference.
+
+@sp 1
+@item
+APPLICABILITY AND DEFINITIONS
+
+This License applies to any manual or other work that contains a
+notice placed by the copyright holder saying it can be distributed
+under the terms of this License. The ``Document'', below, refers to any
+such manual or work. Any member of the public is a licensee, and is
+addressed as ``you''.
+
+A ``Modified Version'' of the Document means any work containing the
+Document or a portion of it, either copied verbatim, or with
+modifications and/or translated into another language.
+
+A ``Secondary Section'' is a named appendix or a front-matter section of
+the Document that deals exclusively with the relationship of the
+publishers or authors of the Document to the Document's overall subject
+(or to related matters) and contains nothing that could fall directly
+within that overall subject. (For example, if the Document is in part a
+textbook of mathematics, a Secondary Section may not explain any
+mathematics.) The relationship could be a matter of historical
+connection with the subject or with related matters, or of legal,
+commercial, philosophical, ethical or political position regarding
+them.
+
+The ``Invariant Sections'' are certain Secondary Sections whose titles
+are designated, as being those of Invariant Sections, in the notice
+that says that the Document is released under this License.
+
+The ``Cover Texts'' are certain short passages of text that are listed,
+as Front-Cover Texts or Back-Cover Texts, in the notice that says that
+the Document is released under this License.
+
+A ``Transparent'' copy of the Document means a machine-readable copy,
+represented in a format whose specification is available to the
+general public, whose contents can be viewed and edited directly and
+straightforwardly with generic text editors or (for images composed of
+pixels) generic paint programs or (for drawings) some widely available
+drawing editor, and that is suitable for input to text formatters or
+for automatic translation to a variety of formats suitable for input
+to text formatters. A copy made in an otherwise Transparent file
+format whose markup has been designed to thwart or discourage
+subsequent modification by readers is not Transparent. A copy that is
+not ``Transparent'' is called ``Opaque''.
+
+Examples of suitable formats for Transparent copies include plain
+ASCII without markup, Texinfo input format, LaTeX input format, SGML
+or XML using a publicly available DTD, and standard-conforming simple
+HTML designed for human modification. Opaque formats include
+PostScript, PDF, proprietary formats that can be read and edited only
+by proprietary word processors, SGML or XML for which the DTD and/or
+processing tools are not generally available, and the
+machine-generated HTML produced by some word processors for output
+purposes only.
+
+The ``Title Page'' means, for a printed book, the title page itself,
+plus such following pages as are needed to hold, legibly, the material
+this License requires to appear in the title page. For works in
+formats which do not have any title page as such, ``Title Page'' means
+the text near the most prominent appearance of the work's title,
+preceding the beginning of the body of the text.
+@sp 1
+@item
+VERBATIM COPYING
+
+You may copy and distribute the Document in any medium, either
+commercially or noncommercially, provided that this License, the
+copyright notices, and the license notice saying this License applies
+to the Document are reproduced in all copies, and that you add no other
+conditions whatsoever to those of this License. You may not use
+technical measures to obstruct or control the reading or further
+copying of the copies you make or distribute. However, you may accept
+compensation in exchange for copies. If you distribute a large enough
+number of copies you must also follow the conditions in section 3.
+
+You may also lend copies, under the same conditions stated above, and
+you may publicly display copies.
+@sp 1
+@item
+COPYING IN QUANTITY
+
+If you publish printed copies of the Document numbering more than 100,
+and the Document's license notice requires Cover Texts, you must enclose
+the copies in covers that carry, clearly and legibly, all these Cover
+Texts: Front-Cover Texts on the front cover, and Back-Cover Texts on
+the back cover. Both covers must also clearly and legibly identify
+you as the publisher of these copies. The front cover must present
+the full title with all words of the title equally prominent and
+visible. You may add other material on the covers in addition.
+Copying with changes limited to the covers, as long as they preserve
+the title of the Document and satisfy these conditions, can be treated
+as verbatim copying in other respects.
+
+If the required texts for either cover are too voluminous to fit
+legibly, you should put the first ones listed (as many as fit
+reasonably) on the actual cover, and continue the rest onto adjacent
+pages.
+
+If you publish or distribute Opaque copies of the Document numbering
+more than 100, you must either include a machine-readable Transparent
+copy along with each Opaque copy, or state in or with each Opaque copy
+a publicly-accessible computer-network location containing a complete
+Transparent copy of the Document, free of added material, which the
+general network-using public has access to download anonymously at no
+charge using public-standard network protocols. If you use the latter
+option, you must take reasonably prudent steps, when you begin
+distribution of Opaque copies in quantity, to ensure that this
+Transparent copy will remain thus accessible at the stated location
+until at least one year after the last time you distribute an Opaque
+copy (directly or through your agents or retailers) of that edition to
+the public.
+
+It is requested, but not required, that you contact the authors of the
+Document well before redistributing any large number of copies, to give
+them a chance to provide you with an updated version of the Document.
+@sp 1
+@item
+MODIFICATIONS
+
+You may copy and distribute a Modified Version of the Document under
+the conditions of sections 2 and 3 above, provided that you release
+the Modified Version under precisely this License, with the Modified
+Version filling the role of the Document, thus licensing distribution
+and modification of the Modified Version to whoever possesses a copy
+of it. In addition, you must do these things in the Modified Version:
+
+A. Use in the Title Page (and on the covers, if any) a title distinct
+ from that of the Document, and from those of previous versions
+ (which should, if there were any, be listed in the History section
+ of the Document). You may use the same title as a previous version
+ if the original publisher of that version gives permission.@*
+B. List on the Title Page, as authors, one or more persons or entities
+ responsible for authorship of the modifications in the Modified
+ Version, together with at least five of the principal authors of the
+ Document (all of its principal authors, if it has less than five).@*
+C. State on the Title page the name of the publisher of the
+ Modified Version, as the publisher.@*
+D. Preserve all the copyright notices of the Document.@*
+E. Add an appropriate copyright notice for your modifications
+ adjacent to the other copyright notices.@*
+F. Include, immediately after the copyright notices, a license notice
+ giving the public permission to use the Modified Version under the
+ terms of this License, in the form shown in the Addendum below.@*
+G. Preserve in that license notice the full lists of Invariant Sections
+ and required Cover Texts given in the Document's license notice.@*
+H. Include an unaltered copy of this License.@*
+I. Preserve the section entitled ``History'', and its title, and add to
+ it an item stating at least the title, year, new authors, and
+ publisher of the Modified Version as given on the Title Page. If
+ there is no section entitled ``History'' in the Document, create one
+ stating the title, year, authors, and publisher of the Document as
+ given on its Title Page, then add an item describing the Modified
+ Version as stated in the previous sentence.@*
+J. Preserve the network location, if any, given in the Document for
+ public access to a Transparent copy of the Document, and likewise
+ the network locations given in the Document for previous versions
+ it was based on. These may be placed in the ``History'' section.
+ You may omit a network location for a work that was published at
+ least four years before the Document itself, or if the original
+ publisher of the version it refers to gives permission.@*
+K. In any section entitled ``Acknowledgements'' or ``Dedications'',
+ preserve the section's title, and preserve in the section all the
+ substance and tone of each of the contributor acknowledgements
+ and/or dedications given therein.@*
+L. Preserve all the Invariant Sections of the Document,
+ unaltered in their text and in their titles. Section numbers
+ or the equivalent are not considered part of the section titles.@*
+M. Delete any section entitled ``Endorsements''. Such a section
+ may not be included in the Modified Version.@*
+N. Do not retitle any existing section as ``Endorsements''
+ or to conflict in title with any Invariant Section.@*
+@sp 1
+If the Modified Version includes new front-matter sections or
+appendices that qualify as Secondary Sections and contain no material
+copied from the Document, you may at your option designate some or all
+of these sections as invariant. To do this, add their titles to the
+list of Invariant Sections in the Modified Version's license notice.
+These titles must be distinct from any other section titles.
+
+You may add a section entitled ``Endorsements'', provided it contains
+nothing but endorsements of your Modified Version by various
+parties--for example, statements of peer review or that the text has
+been approved by an organization as the authoritative definition of a
+standard.
+
+You may add a passage of up to five words as a Front-Cover Text, and a
+passage of up to 25 words as a Back-Cover Text, to the end of the list
+of Cover Texts in the Modified Version. Only one passage of
+Front-Cover Text and one of Back-Cover Text may be added by (or
+through arrangements made by) any one entity. If the Document already
+includes a cover text for the same cover, previously added by you or
+by arrangement made by the same entity you are acting on behalf of,
+you may not add another; but you may replace the old one, on explicit
+permission from the previous publisher that added the old one.
+
+The author(s) and publisher(s) of the Document do not by this License
+give permission to use their names for publicity for or to assert or
+imply endorsement of any Modified Version.
+@sp 1
+@item
+COMBINING DOCUMENTS
+
+You may combine the Document with other documents released under this
+License, under the terms defined in section 4 above for modified
+versions, provided that you include in the combination all of the
+Invariant Sections of all of the original documents, unmodified, and
+list them all as Invariant Sections of your combined work in its
+license notice.
+
+The combined work need only contain one copy of this License, and
+multiple identical Invariant Sections may be replaced with a single
+copy. If there are multiple Invariant Sections with the same name but
+different contents, make the title of each such section unique by
+adding at the end of it, in parentheses, the name of the original
+author or publisher of that section if known, or else a unique number.
+Make the same adjustment to the section titles in the list of
+Invariant Sections in the license notice of the combined work.
+
+In the combination, you must combine any sections entitled ``History''
+in the various original documents, forming one section entitled
+``History''; likewise combine any sections entitled ``Acknowledgements'',
+and any sections entitled ``Dedications''. You must delete all sections
+entitled ``Endorsements.''
+@sp 1
+@item
+COLLECTIONS OF DOCUMENTS
+
+You may make a collection consisting of the Document and other documents
+released under this License, and replace the individual copies of this
+License in the various documents with a single copy that is included in
+the collection, provided that you follow the rules of this License for
+verbatim copying of each of the documents in all other respects.
+
+You may extract a single document from such a collection, and distribute
+it individually under this License, provided you insert a copy of this
+License into the extracted document, and follow this License in all
+other respects regarding verbatim copying of that document.
+@sp 1
+@item
+AGGREGATION WITH INDEPENDENT WORKS
+
+A compilation of the Document or its derivatives with other separate
+and independent documents or works, in or on a volume of a storage or
+distribution medium, does not as a whole count as a Modified Version
+of the Document, provided no compilation copyright is claimed for the
+compilation. Such a compilation is called an ``aggregate'', and this
+License does not apply to the other self-contained works thus compiled
+with the Document, on account of their being thus compiled, if they
+are not themselves derivative works of the Document.
+
+If the Cover Text requirement of section 3 is applicable to these
+copies of the Document, then if the Document is less than one quarter
+of the entire aggregate, the Document's Cover Texts may be placed on
+covers that surround only the Document within the aggregate.
+Otherwise they must appear on covers around the whole aggregate.
+@sp 1
+@item
+TRANSLATION
+
+Translation is considered a kind of modification, so you may
+distribute translations of the Document under the terms of section 4.
+Replacing Invariant Sections with translations requires special
+permission from their copyright holders, but you may include
+translations of some or all Invariant Sections in addition to the
+original versions of these Invariant Sections. You may include a
+translation of this License provided that you also include the
+original English version of this License. In case of a disagreement
+between the translation and the original English version of this
+License, the original English version will prevail.
+@sp 1
+@item
+TERMINATION
+
+You may not copy, modify, sublicense, or distribute the Document except
+as expressly provided for under this License. Any other attempt to
+copy, modify, sublicense or distribute the Document is void, and will
+automatically terminate your rights under this License. However,
+parties who have received copies, or rights, from you under this
+License will not have their licenses terminated so long as such
+parties remain in full compliance.
+@sp 1
+@item
+FUTURE REVISIONS OF THIS LICENSE
+
+The Free Software Foundation may publish new, revised versions
+of the GNU Free Documentation License from time to time. Such new
+versions will be similar in spirit to the present version, but may
+differ in detail to address new problems or concerns. See
+http://www.gnu.org/copyleft/.
+
+Each version of the License is given a distinguishing version number.
+If the Document specifies that a particular numbered version of this
+License ``or any later version'' applies to it, you have the option of
+following the terms and conditions either of that specified version or
+of any later version that has been published (not as a draft) by the
+Free Software Foundation. If the Document does not specify a version
+number of this License, you may choose any version ever published (not
+as a draft) by the Free Software Foundation.
+
+@end enumerate
+
+@unnumberedsec ADDENDUM: How to use this License for your documents
+
+To use this License in a document you have written, include a copy of
+the License in the document and put the following copyright and
+license notices just after the title page:
+
+@smallexample
+@group
+
+ Copyright (C) @var{year} @var{your name}.
+ Permission is granted to copy, distribute and/or modify this document
+ under the terms of the GNU Free Documentation License, Version 1.1
+ or any later version published by the Free Software Foundation;
+ with the Invariant Sections being @var{list their titles}, with the
+ Front-Cover Texts being @var{list}, and with the Back-Cover Texts being @var{list}.
+ A copy of the license is included in the section entitled ``GNU
+ Free Documentation License''.
+@end group
+@end smallexample
+If you have no Invariant Sections, write ``with no Invariant Sections''
+instead of saying which ones are invariant. If you have no
+Front-Cover Texts, write ``no Front-Cover Texts'' instead of
+``Front-Cover Texts being @var{list}''; likewise for Back-Cover Texts.
+
+If your document contains nontrivial examples of program code, we
+recommend releasing these examples in parallel under your choice of
+free software license, such as the GNU General Public License,
+to permit their use in free software.
@page
-@node Concept Index
+@node Concept Index, Index, GNU Free Documentation License, Top
@unnumbered Concept Index
This is a general index of all issues discussed in this manual, with the
@@ -973,7 +2078,7 @@ exception of the @command{grep} commands and command-line options.
@printindex cp
@page
-@node Index
+@node Index,, Concept Index, Top
@unnumbered Index
This is an alphabetical list of all @command{grep} commands, command-line
diff --git a/gnu/usr.bin/grep/doc/version.texi b/gnu/usr.bin/grep/doc/version.texi
index c87a09f..4350a83 100644
--- a/gnu/usr.bin/grep/doc/version.texi
+++ b/gnu/usr.bin/grep/doc/version.texi
@@ -1,3 +1,4 @@
-@set UPDATED 2 February 2000
-@set EDITION 2.4.2
-@set VERSION 2.4.2
+@set UPDATED 23 January 2002
+@set UPDATED-MONTH January 2002
+@set EDITION 2.5.1
+@set VERSION 2.5.1
diff --git a/gnu/usr.bin/grep/error.c b/gnu/usr.bin/grep/error.c
new file mode 100644
index 0000000..c78b6cf
--- /dev/null
+++ b/gnu/usr.bin/grep/error.c
@@ -0,0 +1,276 @@
+/* Error handler for noninteractive utilities
+ Copyright (C) 1990-1998, 2000 Free Software Foundation, Inc.
+
+ This file is part of the GNU C Library. Its master source is NOT part of
+ the C library, however. The master source lives in /gd/gnu/lib.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ 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. */
+
+/* Written by David MacKenzie <djm@gnu.ai.mit.edu>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdio.h>
+#if HAVE_LIBINTL_H
+# include <libintl.h>
+#endif
+
+#if HAVE_VPRINTF || HAVE_DOPRNT || _LIBC
+# if __STDC__
+# include <stdarg.h>
+# define VA_START(args, lastarg) va_start(args, lastarg)
+# else
+# include <varargs.h>
+# define VA_START(args, lastarg) va_start(args)
+# endif
+#else
+# define va_alist a1, a2, a3, a4, a5, a6, a7, a8
+# define va_dcl char *a1, *a2, *a3, *a4, *a5, *a6, *a7, *a8;
+#endif
+
+#if STDC_HEADERS || _LIBC
+# include <stdlib.h>
+# include <string.h>
+#else
+void exit ();
+#endif
+
+#include "error.h"
+
+#ifndef HAVE_DECL_STRERROR_R
+"this configure-time declaration test was not run"
+#endif
+#if !HAVE_DECL_STRERROR_R
+char *strerror_r ();
+#endif
+
+#ifndef _
+# define _(String) String
+#endif
+
+/* If NULL, error will flush stdout, then print on stderr the program
+ name, a colon and a space. Otherwise, error will call this
+ function without parameters instead. */
+void (*error_print_progname) (
+#if __STDC__ - 0
+ void
+#endif
+ );
+
+/* This variable is incremented each time `error' is called. */
+unsigned int error_message_count;
+
+#ifdef _LIBC
+/* In the GNU C library, there is a predefined variable for this. */
+
+# define program_name program_invocation_name
+# include <errno.h>
+
+/* In GNU libc we want do not want to use the common name `error' directly.
+ Instead make it a weak alias. */
+# define error __error
+# define error_at_line __error_at_line
+
+# ifdef USE_IN_LIBIO
+# include <libio/iolibio.h>
+# define fflush(s) _IO_fflush (s)
+# endif
+
+#else /* not _LIBC */
+
+/* The calling program should define program_name and set it to the
+ name of the executing program. */
+extern char *program_name;
+
+# ifdef HAVE_STRERROR_R
+# define __strerror_r strerror_r
+# else
+# if HAVE_STRERROR
+# ifndef strerror /* On some systems, strerror is a macro */
+char *strerror ();
+# endif
+# else
+static char *
+private_strerror (errnum)
+ int errnum;
+{
+ extern char *sys_errlist[];
+ extern int sys_nerr;
+
+ if (errnum > 0 && errnum <= sys_nerr)
+ return _(sys_errlist[errnum]);
+ return _("Unknown system error");
+}
+# define strerror private_strerror
+# endif /* HAVE_STRERROR */
+# endif /* HAVE_STRERROR_R */
+#endif /* not _LIBC */
+
+/* Print the program name and error message MESSAGE, which is a printf-style
+ format string with optional args.
+ If ERRNUM is nonzero, print its corresponding system error message.
+ Exit with status STATUS if it is nonzero. */
+/* VARARGS */
+
+void
+#if defined VA_START && __STDC__
+error (int status, int errnum, const char *message, ...)
+#else
+error (status, errnum, message, va_alist)
+ int status;
+ int errnum;
+ char *message;
+ va_dcl
+#endif
+{
+#ifdef VA_START
+ va_list args;
+#endif
+
+ if (error_print_progname)
+ (*error_print_progname) ();
+ else
+ {
+ fflush (stdout);
+ fprintf (stderr, "%s: ", program_name);
+ }
+
+#ifdef VA_START
+ VA_START (args, message);
+# if HAVE_VPRINTF || _LIBC
+ vfprintf (stderr, message, args);
+# else
+ _doprnt (message, args, stderr);
+# endif
+ va_end (args);
+#else
+ fprintf (stderr, message, a1, a2, a3, a4, a5, a6, a7, a8);
+#endif
+
+ ++error_message_count;
+ if (errnum)
+ {
+#if defined HAVE_STRERROR_R || _LIBC
+ char errbuf[1024];
+# if HAVE_WORKING_STRERROR_R || _LIBC
+ fprintf (stderr, ": %s", __strerror_r (errnum, errbuf, sizeof errbuf));
+# else
+ /* Don't use __strerror_r's return value because on some systems
+ (at least DEC UNIX 4.0[A-D]) strerror_r returns `int'. */
+ __strerror_r (errnum, errbuf, sizeof errbuf);
+ fprintf (stderr, ": %s", errbuf);
+# endif
+#else
+ fprintf (stderr, ": %s", strerror (errnum));
+#endif
+ }
+ putc ('\n', stderr);
+ fflush (stderr);
+ if (status)
+ exit (status);
+}
+
+/* Sometimes we want to have at most one error per line. This
+ variable controls whether this mode is selected or not. */
+int error_one_per_line;
+
+void
+#if defined VA_START && __STDC__
+error_at_line (int status, int errnum, const char *file_name,
+ unsigned int line_number, const char *message, ...)
+#else
+error_at_line (status, errnum, file_name, line_number, message, va_alist)
+ int status;
+ int errnum;
+ const char *file_name;
+ unsigned int line_number;
+ char *message;
+ va_dcl
+#endif
+{
+#ifdef VA_START
+ va_list args;
+#endif
+
+ if (error_one_per_line)
+ {
+ static const char *old_file_name;
+ static unsigned int old_line_number;
+
+ if (old_line_number == line_number &&
+ (file_name == old_file_name || !strcmp (old_file_name, file_name)))
+ /* Simply return and print nothing. */
+ return;
+
+ old_file_name = file_name;
+ old_line_number = line_number;
+ }
+
+ if (error_print_progname)
+ (*error_print_progname) ();
+ else
+ {
+ fflush (stdout);
+ fprintf (stderr, "%s:", program_name);
+ }
+
+ if (file_name != NULL)
+ fprintf (stderr, "%s:%d: ", file_name, line_number);
+
+#ifdef VA_START
+ VA_START (args, message);
+# if HAVE_VPRINTF || _LIBC
+ vfprintf (stderr, message, args);
+# else
+ _doprnt (message, args, stderr);
+# endif
+ va_end (args);
+#else
+ fprintf (stderr, message, a1, a2, a3, a4, a5, a6, a7, a8);
+#endif
+
+ ++error_message_count;
+ if (errnum)
+ {
+#if defined HAVE_STRERROR_R || _LIBC
+ char errbuf[1024];
+# if HAVE_WORKING_STRERROR_R || _LIBC
+ fprintf (stderr, ": %s", __strerror_r (errnum, errbuf, sizeof errbuf));
+# else
+ /* Don't use __strerror_r's return value because on some systems
+ (at least DEC UNIX 4.0[A-D]) strerror_r returns `int'. */
+ __strerror_r (errnum, errbuf, sizeof errbuf);
+ fprintf (stderr, ": %s", errbuf);
+# endif
+#else
+ fprintf (stderr, ": %s", strerror (errnum));
+#endif
+ }
+ putc ('\n', stderr);
+ fflush (stderr);
+ if (status)
+ exit (status);
+}
+
+#ifdef _LIBC
+/* Make the weak alias. */
+# undef error
+# undef error_at_line
+weak_alias (__error, error)
+weak_alias (__error_at_line, error_at_line)
+#endif
diff --git a/gnu/usr.bin/grep/error.h b/gnu/usr.bin/grep/error.h
new file mode 100644
index 0000000..20f7582
--- /dev/null
+++ b/gnu/usr.bin/grep/error.h
@@ -0,0 +1,78 @@
+/* Declaration for error-reporting function
+ Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
+
+
+ NOTE: The canonical source of this file is maintained with the GNU C Library.
+ Bugs can be reported to bug-glibc@prep.ai.mit.edu.
+
+ 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 the
+ Free Software Foundation; either version 2, or (at your option) any
+ later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ 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. */
+
+#ifndef _ERROR_H
+#define _ERROR_H 1
+
+#ifndef __attribute__
+/* This feature is available in gcc versions 2.5 and later. */
+# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
+# define __attribute__(Spec) /* empty */
+# endif
+/* The __-protected variants of `format' and `printf' attributes
+ are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */
+# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
+# define __format__ format
+# define __printf__ printf
+# endif
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#if defined (__STDC__) && __STDC__
+
+/* Print a message with `fprintf (stderr, FORMAT, ...)';
+ if ERRNUM is nonzero, follow it with ": " and strerror (ERRNUM).
+ If STATUS is nonzero, terminate the program with `exit (STATUS)'. */
+
+extern void error (int status, int errnum, const char *format, ...)
+ __attribute__ ((__format__ (__printf__, 3, 4)));
+
+extern void error_at_line (int status, int errnum, const char *fname,
+ unsigned int lineno, const char *format, ...)
+ __attribute__ ((__format__ (__printf__, 5, 6)));
+
+/* If NULL, error will flush stdout, then print on stderr the program
+ name, a colon and a space. Otherwise, error will call this
+ function without parameters instead. */
+extern void (*error_print_progname) (void);
+
+#else
+void error ();
+void error_at_line ();
+extern void (*error_print_progname) ();
+#endif
+
+/* This variable is incremented each time `error' is called. */
+extern unsigned int error_message_count;
+
+/* Sometimes we want to have at most one error per line. This
+ variable controls whether this mode is selected or not. */
+extern int error_one_per_line;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* error.h */
diff --git a/gnu/usr.bin/grep/exclude.c b/gnu/usr.bin/grep/exclude.c
new file mode 100644
index 0000000..1925a39
--- /dev/null
+++ b/gnu/usr.bin/grep/exclude.c
@@ -0,0 +1,128 @@
+/* exclude.c -- exclude file names
+ Copyright 1992, 1993, 1994, 1997, 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
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING.
+ If not, write to the Free Software Foundation,
+ 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+
+/* Written by Paul Eggert <eggert@twinsun.com> */
+
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <errno.h>
+#ifndef errno
+extern int errno;
+#endif
+#include <exclude.h>
+#include <fnmatch.h>
+#include <stdio.h>
+#include <sys/types.h>
+
+void *xmalloc PARAMS ((size_t));
+void *xrealloc PARAMS ((void *, size_t));
+
+/* Keep track of excluded file name patterns. */
+
+struct exclude
+ {
+ char const **exclude;
+ int exclude_alloc;
+ int exclude_count;
+ };
+
+struct exclude *
+new_exclude (void)
+{
+ struct exclude *ex = (struct exclude *) xmalloc (sizeof (struct exclude));
+ ex->exclude_count = 0;
+ ex->exclude_alloc = 64;
+ ex->exclude = (char const **) xmalloc (ex->exclude_alloc * sizeof (char *));
+ return ex;
+}
+
+int
+excluded_filename (struct exclude const *ex, char const *f, int options)
+{
+ char const * const *exclude = ex->exclude;
+ int exclude_count = ex->exclude_count;
+ int i;
+
+ for (i = 0; i < exclude_count; i++)
+ if (fnmatch (exclude[i], f, options) == 0)
+ return 1;
+
+ return 0;
+}
+
+void
+add_exclude (struct exclude *ex, char const *pattern)
+{
+ if (ex->exclude_alloc <= ex->exclude_count)
+ ex->exclude = (char const **) xrealloc (ex->exclude,
+ ((ex->exclude_alloc *= 2)
+ * sizeof (char *)));
+
+ ex->exclude[ex->exclude_count++] = pattern;
+}
+
+int
+add_exclude_file (void (*add_func) PARAMS ((struct exclude *, char const *)),
+ struct exclude *ex, char const *filename, char line_end)
+{
+ int use_stdin = filename[0] == '-' && !filename[1];
+ FILE *in;
+ char *buf;
+ char *p;
+ char const *pattern;
+ char const *lim;
+ size_t buf_alloc = 1024;
+ size_t buf_count = 0;
+ int c;
+ int e = 0;
+
+ if (use_stdin)
+ in = stdin;
+ else if (! (in = fopen (filename, "r")))
+ return -1;
+
+ buf = xmalloc (buf_alloc);
+
+ while ((c = getc (in)) != EOF)
+ {
+ buf[buf_count++] = c;
+ if (buf_count == buf_alloc)
+ buf = xrealloc (buf, buf_alloc *= 2);
+ }
+
+ buf = xrealloc (buf, buf_count + 1);
+
+ if (ferror (in))
+ e = errno;
+
+ if (!use_stdin && fclose (in) != 0)
+ e = errno;
+
+ for (pattern = p = buf, lim = buf + buf_count; p <= lim; p++)
+ if (p < lim ? *p == line_end : buf < p && p[-1])
+ {
+ *p = '\0';
+ (*add_func) (ex, pattern);
+ pattern = p + 1;
+ }
+
+ errno = e;
+ return e ? -1 : 0;
+}
diff --git a/gnu/usr.bin/grep/exclude.h b/gnu/usr.bin/grep/exclude.h
new file mode 100644
index 0000000..8a48a00
--- /dev/null
+++ b/gnu/usr.bin/grep/exclude.h
@@ -0,0 +1,35 @@
+/* exclude.h -- declarations for excluding file names
+ Copyright 1992, 1993, 1994, 1997, 1999 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
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING.
+ If not, write to the Free Software Foundation,
+ 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+
+/* Written by Paul Eggert <eggert@twinsun.com> */
+
+#ifndef PARAMS
+# if defined PROTOTYPES || (defined __STDC__ && __STDC__)
+# define PARAMS(Args) Args
+# else
+# define PARAMS(Args) ()
+# endif
+#endif
+
+struct exclude;
+
+struct exclude *new_exclude PARAMS ((void));
+void add_exclude PARAMS ((struct exclude *, char const *));
+int add_exclude_file PARAMS ((void (*) (struct exclude *, char const *),
+ struct exclude *, char const *, char));
+int excluded_filename PARAMS ((struct exclude const *, char const *, int));
diff --git a/gnu/usr.bin/grep/hard-locale.c b/gnu/usr.bin/grep/hard-locale.c
new file mode 100644
index 0000000..1c75b39
--- /dev/null
+++ b/gnu/usr.bin/grep/hard-locale.c
@@ -0,0 +1,85 @@
+/* hard-locale.c -- Determine whether a locale is hard.
+ Copyright 1997, 1998, 1999 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
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ 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. */
+
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#ifndef __GNUC__
+# ifdef HAVE_ALLOCA_H
+# include <alloca.h>
+# else
+# ifdef _AIX
+ # pragma alloca
+# else
+# ifdef _WIN32
+# include <malloc.h>
+# include <io.h>
+# else
+# ifndef alloca
+char *alloca ();
+# endif
+# endif
+# endif
+# endif
+#endif
+
+#if HAVE_LOCALE_H
+# include <locale.h>
+#endif
+
+#if HAVE_STRING_H
+# include <string.h>
+#endif
+
+/* Return nonzero if the current CATEGORY locale is hard, i.e. if you
+ can't get away with assuming traditional C or POSIX behavior. */
+int
+hard_locale (int category)
+{
+#if ! (defined ENABLE_NLS && HAVE_SETLOCALE)
+ return 0;
+#else
+
+ int hard = 1;
+ char const *p = setlocale (category, 0);
+
+ if (p)
+ {
+# if defined __GLIBC__ && __GLIBC__ >= 2
+ if (strcmp (p, "C") == 0 || strcmp (p, "POSIX") == 0)
+ hard = 0;
+# else
+ char *locale = alloca (strlen (p) + 1);
+ strcpy (locale, p);
+
+ /* Temporarily set the locale to the "C" and "POSIX" locales to
+ find their names, so that we can determine whether one or the
+ other is the caller's locale. */
+ if (((p = setlocale (category, "C")) && strcmp (p, locale) == 0)
+ || ((p = setlocale (category, "POSIX")) && strcmp (p, locale) == 0))
+ hard = 0;
+
+ /* Restore the caller's locale. */
+ setlocale (category, locale);
+# endif
+ }
+
+ return hard;
+
+#endif
+}
diff --git a/gnu/usr.bin/grep/hard-locale.h b/gnu/usr.bin/grep/hard-locale.h
new file mode 100644
index 0000000..5b054d9
--- /dev/null
+++ b/gnu/usr.bin/grep/hard-locale.h
@@ -0,0 +1,18 @@
+#ifndef HARD_LOCALE_H_
+# define HARD_LOCALE_H_ 1
+
+# if HAVE_CONFIG_H
+# include <config.h>
+# endif
+
+# ifndef PARAMS
+# if defined PROTOTYPES || (defined __STDC__ && __STDC__)
+# define PARAMS(Args) Args
+# else
+# define PARAMS(Args) ()
+# endif
+# endif
+
+int hard_locale PARAMS ((int));
+
+#endif /* HARD_LOCALE_H_ */
diff --git a/gnu/usr.bin/grep/isdir.c b/gnu/usr.bin/grep/isdir.c
new file mode 100644
index 0000000..01cf8d5
--- /dev/null
+++ b/gnu/usr.bin/grep/isdir.c
@@ -0,0 +1,42 @@
+/* isdir.c -- determine whether a directory exists
+ Copyright (C) 1990, 1998 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
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ 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. */
+
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#if STAT_MACROS_BROKEN
+# undef S_ISDIR
+#endif
+
+#if !defined S_ISDIR && defined S_IFDIR
+# define S_ISDIR(Mode) (((Mode) & S_IFMT) == S_IFDIR)
+#endif
+
+/* If PATH is an existing directory or symbolic link to a directory,
+ return nonzero, else 0. */
+
+int
+isdir (const char *path)
+{
+ struct stat stats;
+
+ return stat (path, &stats) == 0 && S_ISDIR (stats.st_mode);
+}
diff --git a/gnu/usr.bin/grep/quotearg.c b/gnu/usr.bin/grep/quotearg.c
new file mode 100644
index 0000000..2a7ba4c
--- /dev/null
+++ b/gnu/usr.bin/grep/quotearg.c
@@ -0,0 +1,613 @@
+/* quotearg.c - quote arguments for output
+ Copyright (C) 1998, 1999, 2000, 2001 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
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ 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. */
+
+/* Written by Paul Eggert <eggert@twinsun.com> */
+
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#if HAVE_STDDEF_H
+# include <stddef.h> /* For the definition of size_t on windows w/MSVC. */
+#endif
+#include <sys/types.h>
+#include <quotearg.h>
+#include <xalloc.h>
+
+#include <ctype.h>
+
+#if ENABLE_NLS
+# include <libintl.h>
+# define _(text) gettext (text)
+#else
+# define _(text) text
+#endif
+#define N_(text) text
+
+#if HAVE_LIMITS_H
+# include <limits.h>
+#endif
+#ifndef CHAR_BIT
+# define CHAR_BIT 8
+#endif
+#ifndef UCHAR_MAX
+# define UCHAR_MAX ((unsigned char) -1)
+#endif
+
+#if HAVE_C_BACKSLASH_A
+# define ALERT_CHAR '\a'
+#else
+# define ALERT_CHAR '\7'
+#endif
+
+#if HAVE_STDLIB_H
+# include <stdlib.h>
+#endif
+
+#if HAVE_STRING_H
+# include <string.h>
+#endif
+
+#if HAVE_WCHAR_H
+# include <wchar.h>
+#endif
+
+#if !HAVE_MBRTOWC
+/* Disable multibyte processing entirely. Since MB_CUR_MAX is 1, the
+ other macros are defined only for documentation and to satisfy C
+ syntax. */
+# undef MB_CUR_MAX
+# define MB_CUR_MAX 1
+# define mbrtowc(pwc, s, n, ps) ((*(pwc) = *(s)) != 0)
+# define mbsinit(ps) 1
+# define iswprint(wc) ISPRINT ((unsigned char) (wc))
+#endif
+
+#ifndef iswprint
+# if HAVE_WCTYPE_H
+# include <wctype.h>
+# endif
+# if !defined iswprint && !HAVE_ISWPRINT
+# define iswprint(wc) 1
+# endif
+#endif
+
+#define INT_BITS (sizeof (int) * CHAR_BIT)
+
+#if defined (STDC_HEADERS) || (!defined (isascii) && !defined (HAVE_ISASCII))
+# define IN_CTYPE_DOMAIN(c) 1
+#else
+# define IN_CTYPE_DOMAIN(c) isascii(c)
+#endif
+
+/* Undefine to protect against the definition in wctype.h of solaris2.6. */
+#undef ISPRINT
+#define ISPRINT(c) (IN_CTYPE_DOMAIN (c) && isprint (c))
+
+struct quoting_options
+{
+ /* Basic quoting style. */
+ enum quoting_style style;
+
+ /* Quote the characters indicated by this bit vector even if the
+ quoting style would not normally require them to be quoted. */
+ int quote_these_too[(UCHAR_MAX / INT_BITS) + 1];
+};
+
+/* Names of quoting styles. */
+char const *const quoting_style_args[] =
+{
+ "literal",
+ "shell",
+ "shell-always",
+ "c",
+ "escape",
+ "locale",
+ "clocale",
+ 0
+};
+
+/* Correspondences to quoting style names. */
+enum quoting_style const quoting_style_vals[] =
+{
+ literal_quoting_style,
+ shell_quoting_style,
+ shell_always_quoting_style,
+ c_quoting_style,
+ escape_quoting_style,
+ locale_quoting_style,
+ clocale_quoting_style
+};
+
+/* The default quoting options. */
+static struct quoting_options default_quoting_options;
+
+/* Allocate a new set of quoting options, with contents initially identical
+ to O if O is not null, or to the default if O is null.
+ It is the caller's responsibility to free the result. */
+struct quoting_options *
+clone_quoting_options (struct quoting_options *o)
+{
+ struct quoting_options *p
+ = (struct quoting_options *) xmalloc (sizeof (struct quoting_options));
+ *p = *(o ? o : &default_quoting_options);
+ return p;
+}
+
+/* Get the value of O's quoting style. If O is null, use the default. */
+enum quoting_style
+get_quoting_style (struct quoting_options *o)
+{
+ return (o ? o : &default_quoting_options)->style;
+}
+
+/* In O (or in the default if O is null),
+ set the value of the quoting style to S. */
+void
+set_quoting_style (struct quoting_options *o, enum quoting_style s)
+{
+ (o ? o : &default_quoting_options)->style = s;
+}
+
+/* In O (or in the default if O is null),
+ set the value of the quoting options for character C to I.
+ Return the old value. Currently, the only values defined for I are
+ 0 (the default) and 1 (which means to quote the character even if
+ it would not otherwise be quoted). */
+int
+set_char_quoting (struct quoting_options *o, char c, int i)
+{
+ unsigned char uc = c;
+ int *p = (o ? o : &default_quoting_options)->quote_these_too + uc / INT_BITS;
+ int shift = uc % INT_BITS;
+ int r = (*p >> shift) & 1;
+ *p ^= ((i & 1) ^ r) << shift;
+ return r;
+}
+
+/* MSGID approximates a quotation mark. Return its translation if it
+ has one; otherwise, return either it or "\"", depending on S. */
+static char const *
+gettext_quote (char const *msgid, enum quoting_style s)
+{
+ char const *translation = _(msgid);
+ if (translation == msgid && s == clocale_quoting_style)
+ translation = "\"";
+ return translation;
+}
+
+/* Place into buffer BUFFER (of size BUFFERSIZE) a quoted version of
+ argument ARG (of size ARGSIZE), using QUOTING_STYLE and the
+ non-quoting-style part of O to control quoting.
+ Terminate the output with a null character, and return the written
+ size of the output, not counting the terminating null.
+ If BUFFERSIZE is too small to store the output string, return the
+ value that would have been returned had BUFFERSIZE been large enough.
+ If ARGSIZE is -1, use the string length of the argument for ARGSIZE.
+
+ This function acts like quotearg_buffer (BUFFER, BUFFERSIZE, ARG,
+ ARGSIZE, O), except it uses QUOTING_STYLE instead of the quoting
+ style specified by O, and O may not be null. */
+
+static size_t
+quotearg_buffer_restyled (char *buffer, size_t buffersize,
+ char const *arg, size_t argsize,
+ enum quoting_style quoting_style,
+ struct quoting_options const *o)
+{
+ size_t i;
+ size_t len = 0;
+ char const *quote_string = 0;
+ size_t quote_string_len = 0;
+ int backslash_escapes = 0;
+ int unibyte_locale = MB_CUR_MAX == 1;
+
+#define STORE(c) \
+ do \
+ { \
+ if (len < buffersize) \
+ buffer[len] = (c); \
+ len++; \
+ } \
+ while (0)
+
+ switch (quoting_style)
+ {
+ case c_quoting_style:
+ STORE ('"');
+ backslash_escapes = 1;
+ quote_string = "\"";
+ quote_string_len = 1;
+ break;
+
+ case escape_quoting_style:
+ backslash_escapes = 1;
+ break;
+
+ case locale_quoting_style:
+ case clocale_quoting_style:
+ {
+ /* Get translations for open and closing quotation marks.
+
+ The message catalog should translate "`" to a left
+ quotation mark suitable for the locale, and similarly for
+ "'". If the catalog has no translation,
+ locale_quoting_style quotes `like this', and
+ clocale_quoting_style quotes "like this".
+
+ For example, an American English Unicode locale should
+ translate "`" to U+201C (LEFT DOUBLE QUOTATION MARK), and
+ should translate "'" to U+201D (RIGHT DOUBLE QUOTATION
+ MARK). A British English Unicode locale should instead
+ translate these to U+2018 (LEFT SINGLE QUOTATION MARK) and
+ U+2019 (RIGHT SINGLE QUOTATION MARK), respectively. */
+
+ char const *left = gettext_quote (N_("`"), quoting_style);
+ char const *right = gettext_quote (N_("'"), quoting_style);
+ for (quote_string = left; *quote_string; quote_string++)
+ STORE (*quote_string);
+ backslash_escapes = 1;
+ quote_string = right;
+ quote_string_len = strlen (quote_string);
+ }
+ break;
+
+ case shell_always_quoting_style:
+ STORE ('\'');
+ quote_string = "'";
+ quote_string_len = 1;
+ break;
+
+ default:
+ break;
+ }
+
+ for (i = 0; ! (argsize == (size_t) -1 ? arg[i] == '\0' : i == argsize); i++)
+ {
+ unsigned char c;
+ unsigned char esc;
+
+ if (backslash_escapes
+ && quote_string_len
+ && i + quote_string_len <= argsize
+ && memcmp (arg + i, quote_string, quote_string_len) == 0)
+ STORE ('\\');
+
+ c = arg[i];
+ switch (c)
+ {
+ case '?':
+ switch (quoting_style)
+ {
+ case shell_quoting_style:
+ goto use_shell_always_quoting_style;
+
+ case c_quoting_style:
+ if (i + 2 < argsize && arg[i + 1] == '?')
+ switch (arg[i + 2])
+ {
+ case '!': case '\'':
+ case '(': case ')': case '-': case '/':
+ case '<': case '=': case '>':
+ /* Escape the second '?' in what would otherwise be
+ a trigraph. */
+ i += 2;
+ c = arg[i + 2];
+ STORE ('?');
+ STORE ('\\');
+ STORE ('?');
+ break;
+ }
+ break;
+
+ default:
+ break;
+ }
+ break;
+
+ case ALERT_CHAR: esc = 'a'; goto c_escape;
+ case '\b': esc = 'b'; goto c_escape;
+ case '\f': esc = 'f'; goto c_escape;
+ case '\n': esc = 'n'; goto c_and_shell_escape;
+ case '\r': esc = 'r'; goto c_and_shell_escape;
+ case '\t': esc = 't'; goto c_and_shell_escape;
+ case '\v': esc = 'v'; goto c_escape;
+ case '\\': esc = c; goto c_and_shell_escape;
+
+ c_and_shell_escape:
+ if (quoting_style == shell_quoting_style)
+ goto use_shell_always_quoting_style;
+ c_escape:
+ if (backslash_escapes)
+ {
+ c = esc;
+ goto store_escape;
+ }
+ break;
+
+ case '#': case '~':
+ if (i != 0)
+ break;
+ /* Fall through. */
+ case ' ':
+ case '!': /* special in bash */
+ case '"': case '$': case '&':
+ case '(': case ')': case '*': case ';':
+ case '<': case '>': case '[':
+ case '^': /* special in old /bin/sh, e.g. SunOS 4.1.4 */
+ case '`': case '|':
+ /* A shell special character. In theory, '$' and '`' could
+ be the first bytes of multibyte characters, which means
+ we should check them with mbrtowc, but in practice this
+ doesn't happen so it's not worth worrying about. */
+ if (quoting_style == shell_quoting_style)
+ goto use_shell_always_quoting_style;
+ break;
+
+ case '\'':
+ switch (quoting_style)
+ {
+ case shell_quoting_style:
+ goto use_shell_always_quoting_style;
+
+ case shell_always_quoting_style:
+ STORE ('\'');
+ STORE ('\\');
+ STORE ('\'');
+ break;
+
+ default:
+ break;
+ }
+ break;
+
+ case '%': case '+': case ',': case '-': case '.': case '/':
+ case '0': case '1': case '2': case '3': case '4': case '5':
+ case '6': case '7': case '8': case '9': case ':': case '=':
+ case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
+ case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':
+ case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
+ case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
+ case 'Y': case 'Z': case ']': case '_': case 'a': case 'b':
+ case 'c': case 'd': case 'e': case 'f': case 'g': case 'h':
+ case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
+ case 'o': case 'p': case 'q': case 'r': case 's': case 't':
+ case 'u': case 'v': case 'w': case 'x': case 'y': case 'z':
+ case '{': case '}':
+ /* These characters don't cause problems, no matter what the
+ quoting style is. They cannot start multibyte sequences. */
+ break;
+
+ default:
+ /* If we have a multibyte sequence, copy it until we reach
+ its end, find an error, or come back to the initial shift
+ state. For C-like styles, if the sequence has
+ unprintable characters, escape the whole sequence, since
+ we can't easily escape single characters within it. */
+ {
+ /* Length of multibyte sequence found so far. */
+ size_t m;
+
+ int printable;
+
+ if (unibyte_locale)
+ {
+ m = 1;
+ printable = ISPRINT (c);
+ }
+ else
+ {
+ mbstate_t mbstate;
+ memset (&mbstate, 0, sizeof mbstate);
+
+ m = 0;
+ printable = 1;
+ if (argsize == (size_t) -1)
+ argsize = strlen (arg);
+
+ do
+ {
+ wchar_t w;
+ size_t bytes = mbrtowc (&w, &arg[i + m],
+ argsize - (i + m), &mbstate);
+ if (bytes == 0)
+ break;
+ else if (bytes == (size_t) -1)
+ {
+ printable = 0;
+ break;
+ }
+ else if (bytes == (size_t) -2)
+ {
+ printable = 0;
+ while (i + m < argsize && arg[i + m])
+ m++;
+ break;
+ }
+ else
+ {
+ if (! iswprint (w))
+ printable = 0;
+ m += bytes;
+ }
+ }
+ while (! mbsinit (&mbstate));
+ }
+
+ if (1 < m || (backslash_escapes && ! printable))
+ {
+ /* Output a multibyte sequence, or an escaped
+ unprintable unibyte character. */
+ size_t ilim = i + m;
+
+ for (;;)
+ {
+ if (backslash_escapes && ! printable)
+ {
+ STORE ('\\');
+ STORE ('0' + (c >> 6));
+ STORE ('0' + ((c >> 3) & 7));
+ c = '0' + (c & 7);
+ }
+ if (ilim <= i + 1)
+ break;
+ STORE (c);
+ c = arg[++i];
+ }
+
+ goto store_c;
+ }
+ }
+ }
+
+ if (! (backslash_escapes
+ && o->quote_these_too[c / INT_BITS] & (1 << (c % INT_BITS))))
+ goto store_c;
+
+ store_escape:
+ STORE ('\\');
+
+ store_c:
+ STORE (c);
+ }
+
+ if (quote_string)
+ for (; *quote_string; quote_string++)
+ STORE (*quote_string);
+
+ if (len < buffersize)
+ buffer[len] = '\0';
+ return len;
+
+ use_shell_always_quoting_style:
+ return quotearg_buffer_restyled (buffer, buffersize, arg, argsize,
+ shell_always_quoting_style, o);
+}
+
+/* Place into buffer BUFFER (of size BUFFERSIZE) a quoted version of
+ argument ARG (of size ARGSIZE), using O to control quoting.
+ If O is null, use the default.
+ Terminate the output with a null character, and return the written
+ size of the output, not counting the terminating null.
+ If BUFFERSIZE is too small to store the output string, return the
+ value that would have been returned had BUFFERSIZE been large enough.
+ If ARGSIZE is -1, use the string length of the argument for ARGSIZE. */
+size_t
+quotearg_buffer (char *buffer, size_t buffersize,
+ char const *arg, size_t argsize,
+ struct quoting_options const *o)
+{
+ struct quoting_options const *p = o ? o : &default_quoting_options;
+ return quotearg_buffer_restyled (buffer, buffersize, arg, argsize,
+ p->style, p);
+}
+
+/* Use storage slot N to return a quoted version of the string ARG.
+ OPTIONS specifies the quoting options.
+ The returned value points to static storage that can be
+ reused by the next call to this function with the same value of N.
+ N must be nonnegative. N is deliberately declared with type "int"
+ to allow for future extensions (using negative values). */
+static char *
+quotearg_n_options (int n, char const *arg,
+ struct quoting_options const *options)
+{
+ /* Preallocate a slot 0 buffer, so that the caller can always quote
+ one small component of a "memory exhausted" message in slot 0. */
+ static char slot0[256];
+ static unsigned int nslots = 1;
+ struct slotvec
+ {
+ size_t size;
+ char *val;
+ };
+ static struct slotvec slotvec0 = {sizeof slot0, slot0};
+ static struct slotvec *slotvec = &slotvec0;
+
+ if (nslots <= n)
+ {
+ int n1 = n + 1;
+ size_t s = n1 * sizeof (struct slotvec);
+ if (! (0 < n1 && n1 == s / sizeof (struct slotvec)))
+ abort ();
+ if (slotvec == &slotvec0)
+ {
+ slotvec = (struct slotvec *) xmalloc (sizeof (struct slotvec));
+ *slotvec = slotvec0;
+ }
+ slotvec = (struct slotvec *) xrealloc (slotvec, s);
+ memset (slotvec + nslots, 0, (n1 - nslots) * sizeof (struct slotvec));
+ nslots = n;
+ }
+
+ {
+ size_t size = slotvec[n].size;
+ char *val = slotvec[n].val;
+ size_t qsize = quotearg_buffer (val, size, arg, (size_t) -1, options);
+
+ if (size <= qsize)
+ {
+ slotvec[n].size = size = qsize + 1;
+ slotvec[n].val = val = xrealloc (val == slot0 ? 0 : val, size);
+ quotearg_buffer (val, size, arg, (size_t) -1, options);
+ }
+
+ return val;
+ }
+}
+
+char *
+quotearg_n (unsigned int n, char const *arg)
+{
+ return quotearg_n_options (n, arg, &default_quoting_options);
+}
+
+char *
+quotearg (char const *arg)
+{
+ return quotearg_n (0, arg);
+}
+
+char *
+quotearg_n_style (unsigned int n, enum quoting_style s, char const *arg)
+{
+ struct quoting_options o;
+ o.style = s;
+ memset (o.quote_these_too, 0, sizeof o.quote_these_too);
+ return quotearg_n_options (n, arg, &o);
+}
+
+char *
+quotearg_style (enum quoting_style s, char const *arg)
+{
+ return quotearg_n_style (0, s, arg);
+}
+
+char *
+quotearg_char (char const *arg, char ch)
+{
+ struct quoting_options options;
+ options = default_quoting_options;
+ set_char_quoting (&options, ch, 1);
+ return quotearg_n_options (0, arg, &options);
+}
+
+char *
+quotearg_colon (char const *arg)
+{
+ return quotearg_char (arg, ':');
+}
diff --git a/gnu/usr.bin/grep/quotearg.h b/gnu/usr.bin/grep/quotearg.h
new file mode 100644
index 0000000..f6463b1
--- /dev/null
+++ b/gnu/usr.bin/grep/quotearg.h
@@ -0,0 +1,110 @@
+/* quotearg.h - quote arguments for output
+ Copyright (C) 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
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ 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. */
+
+/* Written by Paul Eggert <eggert@twinsun.com> */
+
+/* Basic quoting styles. */
+enum quoting_style
+ {
+ literal_quoting_style, /* --quoting-style=literal */
+ shell_quoting_style, /* --quoting-style=shell */
+ shell_always_quoting_style, /* --quoting-style=shell-always */
+ c_quoting_style, /* --quoting-style=c */
+ escape_quoting_style, /* --quoting-style=escape */
+ locale_quoting_style, /* --quoting-style=locale */
+ clocale_quoting_style /* --quoting-style=clocale */
+ };
+
+/* For now, --quoting-style=literal is the default, but this may change. */
+#ifndef DEFAULT_QUOTING_STYLE
+# define DEFAULT_QUOTING_STYLE literal_quoting_style
+#endif
+
+/* Names of quoting styles and their corresponding values. */
+extern char const *const quoting_style_args[];
+extern enum quoting_style const quoting_style_vals[];
+
+struct quoting_options;
+
+#ifndef PARAMS
+# if defined PROTOTYPES || defined __STDC__
+# define PARAMS(Args) Args
+# else
+# define PARAMS(Args) ()
+# endif
+#endif
+
+/* The functions listed below set and use a hidden variable
+ that contains the default quoting style options. */
+
+/* Allocate a new set of quoting options, with contents initially identical
+ to O if O is not null, or to the default if O is null.
+ It is the caller's responsibility to free the result. */
+struct quoting_options *clone_quoting_options
+ PARAMS ((struct quoting_options *o));
+
+/* Get the value of O's quoting style. If O is null, use the default. */
+enum quoting_style get_quoting_style PARAMS ((struct quoting_options *o));
+
+/* In O (or in the default if O is null),
+ set the value of the quoting style to S. */
+void set_quoting_style PARAMS ((struct quoting_options *o,
+ enum quoting_style s));
+
+/* In O (or in the default if O is null),
+ set the value of the quoting options for character C to I.
+ Return the old value. Currently, the only values defined for I are
+ 0 (the default) and 1 (which means to quote the character even if
+ it would not otherwise be quoted). */
+int set_char_quoting PARAMS ((struct quoting_options *o, char c, int i));
+
+/* Place into buffer BUFFER (of size BUFFERSIZE) a quoted version of
+ argument ARG (of size ARGSIZE), using O to control quoting.
+ If O is null, use the default.
+ Terminate the output with a null character, and return the written
+ size of the output, not counting the terminating null.
+ If BUFFERSIZE is too small to store the output string, return the
+ value that would have been returned had BUFFERSIZE been large enough.
+ If ARGSIZE is -1, use the string length of the argument for ARGSIZE. */
+size_t quotearg_buffer PARAMS ((char *buffer, size_t buffersize,
+ char const *arg, size_t argsize,
+ struct quoting_options const *o));
+
+/* Use storage slot N to return a quoted version of the string ARG.
+ Use the default quoting options.
+ The returned value points to static storage that can be
+ reused by the next call to this function with the same value of N.
+ N must be nonnegative. */
+char *quotearg_n PARAMS ((unsigned int n, char const *arg));
+
+/* Equivalent to quotearg_n (0, ARG). */
+char *quotearg PARAMS ((char const *arg));
+
+/* Use style S and storage slot N to return a quoted version of the string ARG.
+ This is like quotearg_n (N, ARG), except that it uses S with no other
+ options to specify the quoting method. */
+char *quotearg_n_style PARAMS ((unsigned int n, enum quoting_style s,
+ char const *arg));
+
+/* Equivalent to quotearg_n_style (0, S, ARG). */
+char *quotearg_style PARAMS ((enum quoting_style s, char const *arg));
+
+/* Like quotearg (ARG), except also quote any instances of CH. */
+char *quotearg_char PARAMS ((char const *arg, char ch));
+
+/* Equivalent to quotearg_char (ARG, ':'). */
+char *quotearg_colon PARAMS ((char const *arg));
diff --git a/gnu/usr.bin/grep/savedir.c b/gnu/usr.bin/grep/savedir.c
index e969407..9357cad 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, 1999, 2000 Free Software Foundation, Inc.
+ Copyright (C) 1990, 1997, 1998, 1999, 2000, 2001 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
@@ -66,17 +66,41 @@ char *realloc ();
char *stpcpy ();
#endif
+#include <fnmatch.h>
#include "savedir.h"
+char *path;
+size_t pathlen;
+
+static int
+isdir1 (const char *dir, const char *file)
+{
+ int status;
+ int slash;
+ size_t dirlen = strlen (dir);
+ size_t filelen = strlen (file);
+ if ((dirlen + filelen + 2) > pathlen)
+ {
+ path = calloc (dirlen + 1 + filelen + 1, sizeof (*path));
+ pathlen = dirlen + filelen + 2;
+ }
+ strcpy (path, dir);
+ slash = (path[dirlen] != '/');
+ path[dirlen] = '/';
+ strcpy (path + dirlen + slash , file);
+ status = isdir (path);
+ return status;
+}
+
/* Return a freshly allocated string containing the filenames
in directory DIR, separated by '\0' characters;
the end is marked by two '\0' characters in a row.
NAME_SIZE is the number of bytes to initially allocate
for the string; it will be enlarged as needed.
Return NULL if DIR cannot be opened or if out of memory. */
-
char *
-savedir (const char *dir, off_t name_size)
+savedir (const char *dir, off_t name_size, struct exclude *included_patterns,
+ struct exclude *excluded_patterns)
{
DIR *dirp;
struct dirent *dp;
@@ -109,6 +133,17 @@ savedir (const char *dir, off_t name_size)
{
off_t size_needed = (namep - name_space) + NAMLEN (dp) + 2;
+ if ((included_patterns || excluded_patterns)
+ && !isdir1 (dir, dp->d_name))
+ {
+ if (included_patterns
+ && !excluded_filename (included_patterns, dp->d_name, 0))
+ continue;
+ if (excluded_patterns
+ && excluded_filename (excluded_patterns, dp->d_name, 0))
+ continue;
+ }
+
if (size_needed > name_size)
{
char *new_name_space;
@@ -134,5 +169,11 @@ savedir (const char *dir, off_t name_size)
free (name_space);
return NULL;
}
+ if (path)
+ {
+ free (path);
+ path = NULL;
+ pathlen = 0;
+ }
return name_space;
}
diff --git a/gnu/usr.bin/grep/savedir.h b/gnu/usr.bin/grep/savedir.h
index 89be04d..49c331b 100644
--- a/gnu/usr.bin/grep/savedir.h
+++ b/gnu/usr.bin/grep/savedir.h
@@ -1,6 +1,8 @@
#if !defined SAVEDIR_H_
# define SAVEDIR_H_
+#include "exclude.h"
+
# ifndef PARAMS
# if defined PROTOTYPES || (defined __STDC__ && __STDC__)
# define PARAMS(Args) Args
@@ -9,7 +11,8 @@
# endif
# endif
-char *
-savedir PARAMS ((const char *dir, off_t name_size));
+extern char *
+savedir PARAMS ((const char *dir, off_t name_size,
+ struct exclude *, struct exclude *));
#endif
diff --git a/gnu/usr.bin/grep/system.h b/gnu/usr.bin/grep/system.h
index a6654b6..99906d8a 100644
--- a/gnu/usr.bin/grep/system.h
+++ b/gnu/usr.bin/grep/system.h
@@ -53,18 +53,16 @@ extern char *sys_errlist[];
#endif
/* Some operating systems treat text and binary files differently. */
-#if O_BINARY
+#ifdef __BEOS__
+# undef O_BINARY /* BeOS 5 has O_BINARY and O_TEXT, but they have no effect. */
+#endif
+#ifdef HAVE_DOS_FILE_CONTENTS
# include <io.h>
# ifdef HAVE_SETMODE
# define SET_BINARY(fd) setmode (fd, O_BINARY)
# else
# define SET_BINARY(fd) _setmode (fd, O_BINARY)
# endif
-#else
-# ifndef O_BINARY
-# define O_BINARY 0
-# define SET_BINARY(fd) (void)0
-# endif
#endif
#ifdef HAVE_DOS_FILE_NAMES
@@ -80,14 +78,15 @@ extern char *sys_errlist[];
# define FILESYSTEM_PREFIX_LEN(f) 0
#endif
-/* This assumes _WIN32, like DJGPP, has D_OK. Does it? In what header? */
-#ifdef D_OK
+int isdir PARAMS ((char const *));
+
+#ifdef HAVE_DIR_EACCES_BUG
# ifdef EISDIR
# define is_EISDIR(e, f) \
((e) == EISDIR \
- || ((e) == EACCES && access (f, D_OK) == 0 && ((e) = EISDIR, 1)))
+ || ((e) == EACCES && isdir (f) && ((e) = EISDIR, 1)))
# else
-# define is_EISDIR(e, f) ((e) == EACCES && access (f, D_OK) == 0)
+# define is_EISDIR(e, f) ((e) == EACCES && isdir (f))
# endif
#endif
diff --git a/gnu/usr.bin/grep/tests/backref.sh b/gnu/usr.bin/grep/tests/backref.sh
new file mode 100755
index 0000000..83f6dcc
--- /dev/null
+++ b/gnu/usr.bin/grep/tests/backref.sh
@@ -0,0 +1,38 @@
+#!/bin/sh
+# Test that backrefs are local to regex.
+#
+#
+
+: ${srcdir=.}
+
+failures=0
+
+# checking for a palindrome
+echo "radar" | ${GREP} -e '\(.\)\(.\).\2\1' > /dev/null 2>&1
+if test $? -ne 0 ; then
+ echo "backref: palindrome, test \#1 failed"
+ failures=1
+fi
+
+# hit hard with the `Bond' tests
+echo "civic" | ${GREP} -E -e '^(.?)(.?)(.?)(.?)(.?)(.?)(.?)(.?)(.?).?\9\8\7\6\5\4\3\2\1$' > /dev/null 2>&1
+if test $? -ne 0 ; then
+ echo "Options: Bond, test \#2 failed"
+ failures=1
+fi
+
+# backref are local should be error
+echo "123" | ${GREP} -e 'a\(.\)' -e 'b\1' > /dev/null 2>&1
+if test $? -ne 2 ; then
+ echo "Options: Backref not local, test \#3 failed"
+ failures=1
+fi
+
+# Pattern should faile
+echo "123" | ${GREP} -e '[' -e ']' > /dev/null 2>&1
+if test $? -ne 2 ; then
+ echo "Options: Compiled not local, test \#3 failed"
+ failures=1
+fi
+
+exit $failures
diff --git a/gnu/usr.bin/grep/tests/bre.awk b/gnu/usr.bin/grep/tests/bre.awk
index 9c9fef8..16a5814 100644
--- a/gnu/usr.bin/grep/tests/bre.awk
+++ b/gnu/usr.bin/grep/tests/bre.awk
@@ -8,7 +8,8 @@ BEGIN {
$0 ~ /^#/ { next; }
NF == 3 {
- printf ("status=`echo '%s' | { ${GREP} -e '%s' > /dev/null 2>&1; echo $?; cat >/dev/null; }`\n",$3, $2);
+# printf ("status=`echo '%s' | { ${GREP} -e '%s' > /dev/null 2>&1; echo $?; cat >/dev/null; }`\n",$3, $2);
+ printf ("status=`echo '%s' | { ${GREP} -e '%s' > /dev/null 2>&1; echo $? ; }`\n",$3, $2);
printf ("if test $status -ne %s ; then\n", $1);
printf ("\techo Spencer bre test \\#%d failed\n", ++n);
printf ("\tfailures=1\n");
diff --git a/gnu/usr.bin/grep/tests/bre.sh b/gnu/usr.bin/grep/tests/bre.sh
index eecdd3e..e7ccf0a 100755
--- a/gnu/usr.bin/grep/tests/bre.sh
+++ b/gnu/usr.bin/grep/tests/bre.sh
@@ -1,4 +1,4 @@
-#! /bin/sh
+#!/bin/sh
# Regression test for GNU grep.
: ${srcdir=.}
diff --git a/gnu/usr.bin/grep/tests/bre.tests b/gnu/usr.bin/grep/tests/bre.tests
index 1ed159d..33d1689 100644
--- a/gnu/usr.bin/grep/tests/bre.tests
+++ b/gnu/usr.bin/grep/tests/bre.tests
@@ -17,7 +17,7 @@
2@\(\{1\}a\)@BADRPT@TO CORRECT
0@^*@*
2@^\{1\}@BADRPT@TO CORRECT
-0@\{@{
+0@{@{
1@a\(b*\)c\1d@abbcbd
1@a\(b*\)c\1d@abbcbbbd
1@^\(.\)\1@abc
diff --git a/gnu/usr.bin/grep/tests/empty.sh b/gnu/usr.bin/grep/tests/empty.sh
index 8c75196..d4225fe 100755
--- a/gnu/usr.bin/grep/tests/empty.sh
+++ b/gnu/usr.bin/grep/tests/empty.sh
@@ -1,4 +1,4 @@
-#! /bin/sh
+#!/bin/sh
# test that the empty file means no pattern
# and an empty pattern means match all.
@@ -6,25 +6,28 @@
failures=0
-# should return 0 found a match
-echo "abcd" | ${GREP} -E -e '' > /dev/null 2>&1
-if test $? -ne 0 ; then
- echo "Status: Wrong status code, test \#1 failed"
- failures=1
-fi
+for options in '-E' '-E -w' '-F -x' '-G -w -x'; do
-# should return 1 found no match
-echo "abcd" | ${GREP} -E -f /dev/null > /dev/null 2>&1
-if test $? -ne 1 ; then
- echo "Status: Wrong status code, test \#2 failed"
- failures=1
-fi
+ # should return 0 found a match
+ echo "" | ${GREP} $options -e '' > /dev/null 2>&1
+ if test $? -ne 0 ; then
+ echo "Status: Wrong status code, test \#1 failed ($options)"
+ failures=1
+ fi
-# should return 0 found a match
-echo "abcd" | ${GREP} -E -f /dev/null -e "abc" > /dev/null 2>&1
-if test $? -ne 0 ; then
- echo "Status: Wrong status code, test \#3 failed"
- failures=1
-fi
+ # should return 1 found no match
+ echo "abcd" | ${GREP} $options -f /dev/null > /dev/null 2>&1
+ if test $? -ne 1 ; then
+ echo "Status: Wrong status code, test \#2 failed ($options)"
+ failures=1
+ fi
+
+ # should return 0 found a match
+ echo "abcd" | ${GREP} $options -f /dev/null -e "abcd" > /dev/null 2>&1
+ if test $? -ne 0 ; then
+ echo "Status: Wrong status code, test \#3 failed ($options)"
+ failures=1
+ fi
+done
exit $failures
diff --git a/gnu/usr.bin/grep/tests/ere.awk b/gnu/usr.bin/grep/tests/ere.awk
index 8f6a5b5..234d219 100644
--- a/gnu/usr.bin/grep/tests/ere.awk
+++ b/gnu/usr.bin/grep/tests/ere.awk
@@ -8,7 +8,8 @@ BEGIN {
$0 ~ /^#/ { next; }
NF == 3 {
- printf ("status=`echo '%s' | { ${GREP} -E -e '%s' > /dev/null 2>&1; echo $?; cat >/dev/null; }`\n",$3, $2);
+# printf ("status=`echo '%s' | { ${GREP} -E -e '%s' > /dev/null 2>&1; echo $?; cat >/dev/null; }`\n",$3, $2);
+ printf ("status=`echo '%s' | { ${GREP} -E -e '%s' > /dev/null 2>&1; echo $?; }`\n",$3, $2);
printf ("if test $status -ne %s ; then\n", $1);
printf ("\techo Spencer ere test \\#%d failed\n", ++n);
printf ("\tfailures=1\n");
diff --git a/gnu/usr.bin/grep/tests/ere.sh b/gnu/usr.bin/grep/tests/ere.sh
index 5bf1695..d57e2fa 100755
--- a/gnu/usr.bin/grep/tests/ere.sh
+++ b/gnu/usr.bin/grep/tests/ere.sh
@@ -1,4 +1,4 @@
-#! /bin/sh
+#!/bin/sh
# Regression test for GNU grep.
: ${srcdir=.}
diff --git a/gnu/usr.bin/grep/tests/file.sh b/gnu/usr.bin/grep/tests/file.sh
new file mode 100755
index 0000000..3db95be
--- /dev/null
+++ b/gnu/usr.bin/grep/tests/file.sh
@@ -0,0 +1,59 @@
+#!/bin/sh
+# Test for POSIX.2 options for grep
+#
+# grep -E -f pattern_file file
+# grep -F -f pattern_file file
+# grep -G -f pattern_file file
+#
+
+: ${srcdir=.}
+
+failures=0
+
+cat <<EOF >patfile
+radar
+MILES
+GNU
+EOF
+
+# match
+echo "miles" | ${GREP} -i -E -f patfile > /dev/null 2>&1
+if test $? -ne 0 ; then
+ echo "File_pattern: Wrong status code, test \#1 failed"
+ failures=1
+fi
+
+# match
+echo "GNU" | ${GREP} -G -f patfile > /dev/null 2>&1
+if test $? -ne 0 ; then
+ echo "File_pattern: Wrong status code, test \#2 failed"
+ failures=1
+fi
+
+# checking for no match
+echo "ridar" | ${GREP} -F -f patfile > /dev/null 2>&1
+if test $? -ne 1 ; then
+ echo "File_pattern: Wrong status code, test \#3 failed"
+ failures=1
+fi
+
+cat <<EOF >patfile
+
+EOF
+# empty pattern : every match
+echo "abbcd" | ${GREP} -F -f patfile > /dev/null 2>&1
+if test $? -ne 0 ; then
+ echo "File_pattern: Wrong status code, test \#4 failed"
+ failures=1
+fi
+
+cp /dev/null patfile
+
+# null pattern : no match
+echo "abbcd" | ${GREP} -F -f patfile > /dev/null 2>&1
+if test $? -ne 1 ; then
+ echo "File_pattern: Wrong status code, test \#5 failed"
+ failures=1
+fi
+
+exit $failures
diff --git a/gnu/usr.bin/grep/tests/formatbre.awk b/gnu/usr.bin/grep/tests/formatbre.awk
new file mode 100644
index 0000000..68a9c62
--- /dev/null
+++ b/gnu/usr.bin/grep/tests/formatbre.awk
@@ -0,0 +1,55 @@
+#
+# Basic Regular Expression
+
+# kip comments
+$0 ~ /^#/ { next; }
+
+# skip those option specific to regexec/regcomp
+$2 ~ /[msnr$#p^]/ { next; }
+
+# skip empty lines
+$0 ~ /^$/ { next; }
+
+# debug
+#{ printf ("<%s> <%s> <%s> <%s>\n", $1, $2, $3, $4); }
+
+# subreg expresion
+NF >= 5 { next; }
+
+# errors
+NF == 3 {
+# gsub (/@/, ",");
+# it means empty lines
+ gsub (/\"\"/, "");
+# escapes
+ gsub (/\\\'/, "\\\'\'");
+# error in regex
+ if (index ($2, "C") != 0)
+ {
+ if (index ($2, "b") != 0)
+ printf ("2@%s@%s\n", $1, $3);
+ }
+# erro no match
+ else
+ {
+ if (index ($2, "b") != 0)
+ printf ("1@%s@%s\n", $1, $3);
+ }
+ next;
+}
+
+# ok
+NF == 4 {
+# skip those magic cookies can't rely on echo to gnerate them
+ if (match($3, /[NSTZ]/))
+ next;
+
+# gsub (/@/, ",");
+# it means empty lines
+ gsub (/\"\"/, "");
+# escape escapes
+ gsub (/\\\'/, "\\\'\'");
+
+ if (index ($2, "b") != 0)
+ printf ("0@%s@%s\n", $1, $3);
+}
diff --git a/gnu/usr.bin/grep/tests/formatere.awk b/gnu/usr.bin/grep/tests/formatere.awk
new file mode 100644
index 0000000..ba60439
--- /dev/null
+++ b/gnu/usr.bin/grep/tests/formatere.awk
@@ -0,0 +1,60 @@
+#
+# Extended Regular Expression
+
+# skip comments
+$0 ~ /^#/ { next; }
+
+# skip specifics to regcomp/regexec
+$2 ~ /[msnr$#p^]/ { next; }
+
+# jump empty lines
+$0 ~ /^$/ { next; }
+
+# subreg skip
+NF >= 5 { next; }
+
+# debug
+#{ printf ("<%s> <%s> <%s> <%s>\n", $1, $2, $3, $4); }
+
+# errors
+NF == 3 {
+# nuke any remaining '@'
+# gsub (/@/, ",");
+# it means empty lines
+ gsub (/\"\"/, "");
+# escapes
+ gsub (/\\\'/, "\\\'\'");
+# error in regex
+ if (index ($2, "C") != 0)
+ {
+ if (index ($2, "b") == 0)
+ printf ("2@%s@%s\n", $1, $3);
+ }
+# error not matching
+ else
+ {
+ if (index ($2, "b") == 0)
+ printf ("1@%s@%s\n", $1, $3);
+ }
+ next;
+}
+
+# ok
+NF == 4 {
+# skip those magic cookies can't rely on echo to gnerate them
+ if (match($3, /[NSTZ]/))
+ next;
+
+# nuke any remaining '@'
+# gsub (/@/, ",");
+# it means empty lines
+ gsub (/\"\"/, "");
+# escape escapes
+ gsub (/\\\'/, "\\\'\'");
+
+ if (index ($2, "b") == 0)
+ {
+ printf ("0@%s@%s\n", $1, $3);
+ }
+ next;
+}
diff --git a/gnu/usr.bin/grep/tests/khadafy.sh b/gnu/usr.bin/grep/tests/khadafy.sh
index 141b3d8..e3d2cde 100755
--- a/gnu/usr.bin/grep/tests/khadafy.sh
+++ b/gnu/usr.bin/grep/tests/khadafy.sh
@@ -1,4 +1,4 @@
-#! /bin/sh
+#!/bin/sh
# Regression test for GNU grep.
: ${srcdir=.}
diff --git a/gnu/usr.bin/grep/tests/options.sh b/gnu/usr.bin/grep/tests/options.sh
index 3415018..0f18529 100755
--- a/gnu/usr.bin/grep/tests/options.sh
+++ b/gnu/usr.bin/grep/tests/options.sh
@@ -1,4 +1,4 @@
-#! /bin/sh
+#!/bin/sh
# Test for POSIX.2 options for grep
#
# grep [ -E| -F][ -c| -l| -q ][-insvx] -e pattern_list
diff --git a/gnu/usr.bin/grep/tests/spencer1.awk b/gnu/usr.bin/grep/tests/spencer1.awk
index 70c6118..ba7aeb6 100644
--- a/gnu/usr.bin/grep/tests/spencer1.awk
+++ b/gnu/usr.bin/grep/tests/spencer1.awk
@@ -4,7 +4,8 @@ BEGIN {
}
$0 !~ /^#/ && NF = 3 {
- printf ("status=`echo '%s'| { ${GREP} -E -e '%s' > /dev/null 2>&1; echo $?; cat >/dev/null; }`\n",$3, $2);
+# printf ("status=`echo '%s'| { ${GREP} -E -e '%s' > /dev/null 2>&1; echo $?; cat >/dev/null; }`\n",$3, $2);
+ printf ("status=`echo '%s'| { ${GREP} -E -e '%s' >/dev/null 2>&1 ; echo $?; }`\n",$3, $2);
printf ("if test $status -ne %s ; then\n", $1);
printf ("\techo Spencer test \\#%d failed\n", ++n);
printf ("\tfailures=1\n");
diff --git a/gnu/usr.bin/grep/tests/spencer1.sh b/gnu/usr.bin/grep/tests/spencer1.sh
index f09b3fa..2391761a 100755
--- a/gnu/usr.bin/grep/tests/spencer1.sh
+++ b/gnu/usr.bin/grep/tests/spencer1.sh
@@ -1,4 +1,4 @@
-#! /bin/sh
+#!/bin/sh
# Regression test for GNU grep.
: ${srcdir=.}
diff --git a/gnu/usr.bin/grep/tests/spencer2.sh b/gnu/usr.bin/grep/tests/spencer2.sh
new file mode 100755
index 0000000..a26869c
--- /dev/null
+++ b/gnu/usr.bin/grep/tests/spencer2.sh
@@ -0,0 +1,13 @@
+#!/bin/sh
+# Regression test for GNU grep.
+
+: ${srcdir=.}
+
+failures=0
+
+# . . . and the following by Henry Spencer.
+
+${AWK-awk} -f $srcdir/scriptgen.awk $srcdir/spencer2.tests > tmp2.script
+
+sh tmp2.script && exit $failures
+exit 1
diff --git a/gnu/usr.bin/grep/tests/spencer2.tests b/gnu/usr.bin/grep/tests/spencer2.tests
new file mode 100644
index 0000000..47b6191
--- /dev/null
+++ b/gnu/usr.bin/grep/tests/spencer2.tests
@@ -0,0 +1,317 @@
+0@a@a
+0@abc@abc
+0@abc|de@abc
+0@a|b|c@abc
+0@a(b)c@abc
+1@a\(b\)c@abc
+2@a(@EPAREN
+2@a(@a(
+0@a\(@a(
+1@a\(@EPAREN
+1@a\(b@EPAREN
+2@a(b@EPAREN
+2@a(b@a(b
+2@a)@a)
+2@)@)
+2@a)@a)
+1@a\)@EPAREN
+1@\)@EPAREN
+0@a()b@ab
+1@a\(\)b@ab
+0@^abc$@abc
+1@a^b@a^b
+1@a^b@a^b
+1@a$b@a$b
+1@a$b@a$b
+0@^@abc
+0@$@abc
+1@^$@""
+1@$^@""
+1@\($\)\(^\)@""
+0@^^@""
+0@$$@""
+1@b$@abNc
+1@b$@abNc
+1@^b$@aNbNc
+1@^b$@aNbNc
+1@^$@aNNb
+1@^$@abc
+1@^$@abcN
+1@$^@aNNb
+1@\($\)\(^\)@aNNb
+0@^^@aNNb
+0@$$@aNNb
+0@^a@a
+0@a$@a
+0@^a@aNb
+1@^b@aNb
+0@a$@bNa
+1@b$@bNa
+0@a*(^b$)c*@b
+1@a*\(^b$\)c*@b
+0@|@EMPTY
+0@|@|
+0@*@BADRPT
+0@*@*
+0@+@BADRPT
+0@?@BADRPT
+1@""@EMPTY
+0@()@abc
+1@\(\)@abc
+0@a||b@EMPTY
+0@|ab@EMPTY
+0@ab|@EMPTY
+1@(|a)b@EMPTY
+1@(a|)b@EMPTY
+1@(*a)@BADRPT
+1@(+a)@BADRPT
+1@(?a)@BADRPT
+1@({1}a)@BADRPT
+1@\(\{1\}a\)@BADRPT
+1@(a|*b)@BADRPT
+1@(a|+b)@BADRPT
+1@(a|?b)@BADRPT
+1@(a|{1}b)@BADRPT
+0@^*@BADRPT
+0@^*@*
+0@^+@BADRPT
+0@^?@BADRPT
+0@^{1}@BADRPT
+1@^\{1\}@BADRPT
+0@a.c@abc
+0@a[bc]d@abd
+0@a\*c@a*c
+1@ac@abc
+1@a\bc@ac
+1@\{@BADRPT
+0@a\[b@a[b
+2@a[b@EBRACK
+0@a$@a
+1@a$@a$
+1@a\$@a
+0@a\$@a$
+1@a\$@a
+1@a\$@a\$
+2@a\(b\)\2c@ESUBREG
+2@a\(b\1\)c@ESUBREG
+2@a\(b*\)c\1d@abbcbd
+2@a\(b*\)c\1d@abbcbbbd
+2@^\(.\)\1@abc
+2@a\(\([bc]\)\2\)*d@abbccd
+2@a\(\([bc]\)\2\)*d@abbcbd
+2@a\(\(b\)*\2\)*d@abbbd
+2@\(a\)\1bcd@aabcd
+2@\(a\)\1bc*d@aabcd
+2@\(a\)\1bc*d@aabd
+2@\(a\)\1bc*d@aabcccd
+2@\(a\)\1bc*[ce]d@aabcccd
+2@^\(a\)\1b\(c\)*cd$@aabcccd
+0@ab*c@abc
+0@ab+c@abc
+0@ab?c@abc
+1@a\(*\)b@a*b
+1@a\(**\)b@ab
+1@a\(***\)b@BADRPT
+0@*a@*a
+0@**a@a
+1@***a@BADRPT
+2@{@{
+2@{abc@{abc
+2@{1@BADRPT
+0@{1}@BADRPT
+2@a{b@a{b
+0@a{1}b@ab
+1@a\{1\}b@ab
+0@a{1,}b@ab
+1@a\{1,\}b@ab
+0@a{1,2}b@aab
+1@a\{1,2\}b@aab
+2@a{1@EBRACE
+1@a\{1@EBRACE
+2@a{1a@EBRACE
+1@a\{1a@EBRACE
+2@a{1a}@BADBR
+1@a\{1a\}@BADBR
+0@a{,2}@a{,2}
+1@a\{,2\}@BADBR
+0@a{,}@a{,}
+1@a\{,\}@BADBR
+2@a{1,x}@BADBR
+1@a\{1,x\}@BADBR
+2@a{1,x@EBRACE
+1@a\{1,x@EBRACE
+1@a{300}@BADBR
+1@a\{300\}@BADBR
+1@a{1,0}@BADBR
+1@a\{1,0\}@BADBR
+0@ab{0,0}c@abcac
+1@ab\{0,0\}c@abcac
+0@ab{0,1}c@abcac
+1@ab\{0,1\}c@abcac
+0@ab{0,3}c@abbcac
+1@ab\{0,3\}c@abbcac
+0@ab{1,1}c@acabc
+1@ab\{1,1\}c@acabc
+0@ab{1,3}c@acabc
+1@ab\{1,3\}c@acabc
+0@ab{2,2}c@abcabbc
+1@ab\{2,2\}c@abcabbc
+0@ab{2,4}c@abcabbc
+1@ab\{2,4\}c@abcabbc
+0@a**@BADRPT
+1@a++@BADRPT
+0@a??@BADRPT
+0@a*+@BADRPT
+0@a*?@BADRPT
+0@a+*@BADRPT
+0@a+?@BADRPT
+0@a?*@BADRPT
+0@a?+@BADRPT
+1@a{1}{1}@BADRPT
+0@a*{1}@BADRPT
+1@a+{1}@BADRPT
+0@a?{1}@BADRPT
+0@a{1}*@BADRPT
+1@a{1}+@BADRPT
+0@a{1}?@BADRPT
+2@a*{b}@a{b}
+1@a\{1\}\{1\}@BADRPT
+1@a*\{1\}@BADRPT
+1@a\{1\}*@BADRPT
+0@a[b]c@abc
+0@a[ab]c@abc
+0@a[^ab]c@adc
+0@a[]b]c@a]c
+0@a[[b]c@a[c
+0@a[-b]c@a-c
+0@a[^]b]c@adc
+0@a[^-b]c@adc
+0@a[b-]c@a-c
+2@a[b@EBRACK
+2@a[]@EBRACK
+0@a[1-3]c@a2c
+1@a[3-1]c@ERANGE
+1@a[1-3-5]c@ERANGE
+1@a[[.-.]--]c@a-c
+2@a[1-@ERANGE
+2@a[[.@EBRACK
+2@a[[.x@EBRACK
+2@a[[.x.@EBRACK
+1@a[[.x.]@EBRACK
+1@a[[.x.]]@ax
+1@a[[.x,.]]@ECOLLATE
+1@a[[.one.]]b@a1b
+1@a[[.notdef.]]b@ECOLLATE
+1@a[[.].]]b@a]b
+0@a[[:alpha:]]c@abc
+2@a[[:notdef:]]c@ECTYPE
+2@a[[:@EBRACK
+2@a[[:alpha@EBRACK
+2@a[[:alpha:]@EBRACK
+2@a[[:alpha,:]@ECTYPE
+2@a[[:]:]]b@ECTYPE
+2@a[[:-:]]b@ECTYPE
+2@a[[:alph:]]@ECTYPE
+2@a[[:alphabet:]]@ECTYPE
+1@[[:blank:]]+@aSSTb
+1@[[:cntrl:]]+@aNTb
+0@[[:digit:]]+@a019b
+0@[[:graph:]]+@Sa%bS
+0@[[:lower:]]+@AabC
+0@[[:print:]]+@NaSbN
+0@[[:punct:]]+@S%-&T
+1@[[:space:]]+@aSNTb
+0@[[:upper:]]+@aBCd
+0@[[:xdigit:]]+@p0f3Cq
+1@a[[=b=]]c@abc
+2@a[[=@EBRACK
+2@a[[=b@EBRACK
+2@a[[=b=@EBRACK
+1@a[[=b=]@EBRACK
+1@a[[=b,=]]@ECOLLATE
+1@a[[=one=]]b@a1b
+0@a(((b)))c@abc
+0@a(b|(c))d@abd
+0@a(b*|c)d@abbd
+0@a[ab]{20}@aaaaabaaaabaaaabaaaab
+0@a[ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab]@aaaaabaaaabaaaabaaaab
+0@a[ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab](wee|week)(knights|night)@aaaaabaaaabaaaabaaaabweeknights
+0@12345678901234567890123456789@a12345678901234567890123456789b
+0@123456789012345678901234567890@a123456789012345678901234567890b
+0@1234567890123456789012345678901@a1234567890123456789012345678901b
+0@12345678901234567890123456789012@a12345678901234567890123456789012b
+0@123456789012345678901234567890123@a123456789012345678901234567890123b
+0@1234567890123456789012345678901234567890123456789012345678901234567890@a1234567890123456789012345678901234567890123456789012345678901234567890b
+0@[ab][cd][ef][gh][ij][kl][mn]@xacegikmoq
+0@[ab][cd][ef][gh][ij][kl][mn][op]@xacegikmoq
+0@[ab][cd][ef][gh][ij][kl][mn][op][qr]@xacegikmoqy
+0@[ab][cd][ef][gh][ij][kl][mn][op][q]@xacegikmoqy
+0@abc@xabcy
+2@a\(b\)?c\1d@acd
+1@aBc@Abc
+1@a[Bc]*d@abBCcd
+1@0[[:upper:]]1@0a1
+1@0[[:lower:]]1@0A1
+1@a[^b]c@abc
+0@a[^b]c@aBc
+0@a[^b]c@adc
+0@[a]b[c]@abc
+0@[a]b[a]@aba
+0@[abc]b[abc]@abc
+0@[abc]b[abd]@abd
+0@a(b?c)+d@accd
+0@(wee|week)(knights|night)@weeknights
+0@(we|wee|week|frob)(knights|night|day)@weeknights
+0@a[bc]d@xyzaaabcaababdacd
+0@a[ab]c@aaabc
+0@abc@abc
+0@a*@b
+0@/\*.*\*/@/*x*/
+0@/\*.*\*/@/*x*/y/*z*/
+0@/\*([^*]|\*[^/])*\*/@/*x*/
+0@/\*([^*]|\*[^/])*\*/@/*x*/y/*z*/
+0@/\*([^*]|\*[^/])*\*/@/*x**/y/*z*/
+0@/\*([^*]|\*+[^*/])*\*+/@/*x*/
+0@/\*([^*]|\*+[^*/])*\*+/@/*x*/y/*z*/
+0@/\*([^*]|\*+[^*/])*\*+/@/*x**/y/*z*/
+0@/\*([^*]|\*+[^*/])*\*+/@/*x****/y/*z*/
+0@/\*([^*]|\*+[^*/])*\*+/@/*x**x*/y/*z*/
+0@/\*([^*]|\*+[^*/])*\*+/@/*x***x/y/*z*/
+0@[abc]@a(b)c
+0@[abc]@a(d)c
+0@[abc]@a(bc)d
+0@[abc]@a(dc)d
+0@.@a()c
+0@b.*c@b(bc)c
+0@b.*@b(bc)c
+0@.*c@b(bc)c
+0@abc@abc
+0@abc@xabcy
+1@abc@xyz
+0@a*b@aba*b
+0@a*b@ab
+1@""@EMPTY
+1@aZb@a
+1@aZb@a
+0@aZb@(aZb)
+0@aZ*b@(ab)
+0@a.b@(aZb)
+0@a.*@(aZb)c
+2@[[:<:]]a@a
+2@[[:<:]]a@ba
+2@[[:<:]]a@-a
+2@a[[:>:]]@a
+2@a[[:>:]]@ab
+2@a[[:>:]]@a-
+2@[[:<:]]a.c[[:>:]]@axcd-dayc-dazce-abc
+2@[[:<:]]a.c[[:>:]]@axcd-dayc-dazce-abc-q
+2@[[:<:]]a.c[[:>:]]@axc-dayc-dazce-abc
+2@[[:<:]]b.c[[:>:]]@a_bxc-byc_d-bzc-q
+2@[[:<:]].x..[[:>:]]@y_xa_-_xb_y-_xc_-axdc
+2@[[:<:]]a_b[[:>:]]@x_a_b
+0@(A[1])|(A[2])|(A[3])|(A[4])|(A[5])|(A[6])|(A[7])|(A[8])|(A[9])|(A[A])@A1
+0@abcdefghijklmnop@abcdefghijklmnop
+0@abcdefghijklmnopqrstuv@abcdefghijklmnopqrstuv
+0@CC[13]1|a{21}[23][EO][123][Es][12]a{15}aa[34][EW]aaaaaaa[X]a@CC11
+0@a?b@ab
+1@-\{0,1\}[0-9]*$@-5
diff --git a/gnu/usr.bin/grep/tests/status.sh b/gnu/usr.bin/grep/tests/status.sh
index 50fc912..94f5929 100755
--- a/gnu/usr.bin/grep/tests/status.sh
+++ b/gnu/usr.bin/grep/tests/status.sh
@@ -1,4 +1,4 @@
-#! /bin/sh
+#!/bin/sh
# Test for status code for GNU grep.
# status code
# 0 match found
@@ -24,15 +24,29 @@ if test $? -ne 1 ; then
fi
# the filename MMMMMMMM.MMM should not exist hopefully
-# should return 2 file not found
-if test -b MMMMMMMM.MMM; then
+if test -r MMMMMMMM.MMM; then
echo "Please remove MMMMMMMM.MMM to run check"
else
- ${GREP} -E -e 'abc' MMMMMMMM.MMM> /dev/null 2>&1
+ # should return 2 file not found
+ ${GREP} -E -e 'abc' MMMMMMMM.MMM > /dev/null 2>&1
if test $? -ne 2 ; then
echo "Status: Wrong status code, test \#3 failed"
failures=1
fi
+
+ # should return 2 file not found
+ ${GREP} -E -s -e 'abc' MMMMMMMM.MMM > /dev/null 2>&1
+ if test $? -ne 2 ; then
+ echo "Status: Wrong status code, test \#4 failed"
+ failures=1
+ fi
+
+ # should return 0 found a match
+ echo "abcd" | ${GREP} -E -q -s 'abc' MMMMMMMM.MMM - > /dev/null 2>&1
+ if test $? -ne 0 ; then
+ echo "Status: Wrong status code, test \#5 failed"
+ failures=1
+ fi
fi
exit $failures
diff --git a/gnu/usr.bin/grep/tests/tests b/gnu/usr.bin/grep/tests/tests
new file mode 100644
index 0000000..8ed938d
--- /dev/null
+++ b/gnu/usr.bin/grep/tests/tests
@@ -0,0 +1,475 @@
+# regular expression test set
+# Lines are at least three fields, separated by one or more tabs. "" stands
+# for an empty field. First field is an RE. Second field is flags. If
+# C flag given, regcomp() is expected to fail, and the third field is the
+# error name (minus the leading REG_).
+#
+# Otherwise it is expected to succeed, and the third field is the string to
+# try matching it against. If there is no fourth field, the match is
+# expected to fail. If there is a fourth field, it is the substring that
+# the RE is expected to match. If there is a fifth field, it is a comma-
+# separated list of what the subexpressions should match, with - indicating
+# no match for that one. In both the fourth and fifth fields, a (sub)field
+# starting with @ indicates that the (sub)expression is expected to match
+# a null string followed by the stuff after the @; this provides a way to
+# test where null strings match. The character `N' in REs and strings
+# is newline, `S' is space, `T' is tab, `Z' is NUL.
+#
+# The full list of flags:
+# - placeholder, does nothing
+# b RE is a BRE, not an ERE
+# & try it as both an ERE and a BRE
+# C regcomp() error expected, third field is error name
+# i REG_ICASE
+# m ("mundane") REG_NOSPEC
+# s REG_NOSUB (not really testable)
+# n REG_NEWLINE
+# ^ REG_NOTBOL
+# $ REG_NOTEOL
+# # REG_STARTEND (see below)
+# p REG_PEND
+#
+# For REG_STARTEND, the start/end offsets are those of the substring
+# enclosed in ().
+
+# basics
+a & a a
+abc & abc abc
+abc|de - abc abc
+a|b|c - abc a
+
+# parentheses and perversions thereof
+a(b)c - abc abc
+a\(b\)c b abc abc
+a( C EPAREN
+a( b a( a(
+a\( - a( a(
+a\( bC EPAREN
+a\(b bC EPAREN
+a(b C EPAREN
+a(b b a(b a(b
+# gag me with a right parenthesis -- 1003.2 goofed here (my fault, partly)
+a) - a) a)
+) - ) )
+# end gagging (in a just world, those *should* give EPAREN)
+a) b a) a)
+a\) bC EPAREN
+\) bC EPAREN
+a()b - ab ab
+a\(\)b b ab ab
+
+# anchoring and REG_NEWLINE
+^abc$ & abc abc
+a^b - a^b
+a^b b a^b a^b
+a$b - a$b
+a$b b a$b a$b
+^ & abc @abc
+$ & abc @
+^$ & "" @
+$^ - "" @
+\($\)\(^\) b "" @
+# stop retching, those are legitimate (although disgusting)
+^^ - "" @
+$$ - "" @
+##b$ & abNc
+##b$ &n abNc b
+##^b$ & aNbNc
+##^b$ &n aNbNc b
+##^$ &n aNNb @Nb
+^$ n abc
+##^$ n abcN @
+##$^ n aNNb @Nb
+##\($\)\(^\) bn aNNb @Nb
+##^^ n^ aNNb @Nb
+##$$ n aNNb @NN
+^a ^ a
+a$ $ a
+##^a ^n aNb
+##^b ^n aNb b
+##a$ $n bNa
+##b$ $n bNa b
+a*(^b$)c* - b b
+a*\(^b$\)c* b b b
+
+# certain syntax errors and non-errors
+| C EMPTY
+| b | |
+* C BADRPT
+* b * *
++ C BADRPT
+? C BADRPT
+"" &C EMPTY
+() - abc @abc
+\(\) b abc @abc
+a||b C EMPTY
+|ab C EMPTY
+ab| C EMPTY
+(|a)b C EMPTY
+(a|)b C EMPTY
+(*a) C BADRPT
+(+a) C BADRPT
+(?a) C BADRPT
+({1}a) C BADRPT
+\(\{1\}a\) bC BADRPT
+(a|*b) C BADRPT
+(a|+b) C BADRPT
+(a|?b) C BADRPT
+(a|{1}b) C BADRPT
+^* C BADRPT
+^* b * *
+^+ C BADRPT
+^? C BADRPT
+^{1} C BADRPT
+^\{1\} bC BADRPT
+
+# metacharacters, backslashes
+a.c & abc abc
+a[bc]d & abd abd
+a\*c & a*c a*c
+a\\b & a\b a\b
+a\\\*b & a\*b a\*b
+a\bc & abc abc
+a\ &C EESCAPE
+a\\bc & a\bc a\bc
+\{ bC BADRPT
+a\[b & a[b a[b
+a[b &C EBRACK
+# trailing $ is a peculiar special case for the BRE code
+a$ & a a
+a$ & a$
+a\$ & a
+a\$ & a$ a$
+a\\$ & a
+a\\$ & a$
+a\\$ & a\$
+a\\$ & a\ a\
+
+# back references, ugh
+##a\(b\)\2c bC ESUBREG
+##a\(b\1\)c bC ESUBREG
+a\(b*\)c\1d b abbcbbd abbcbbd bb
+a\(b*\)c\1d b abbcbd
+a\(b*\)c\1d b abbcbbbd
+^\(.\)\1 b abc
+a\([bc]\)\1d b abcdabbd abbd b
+a\(\([bc]\)\2\)*d b abbccd abbccd
+a\(\([bc]\)\2\)*d b abbcbd
+# actually, this next one probably ought to fail, but the spec is unclear
+a\(\(b\)*\2\)*d b abbbd abbbd
+# here is a case that no NFA implementation does right
+\(ab*\)[ab]*\1 b ababaaa ababaaa a
+# check out normal matching in the presence of back refs
+\(a\)\1bcd b aabcd aabcd
+\(a\)\1bc*d b aabcd aabcd
+\(a\)\1bc*d b aabd aabd
+\(a\)\1bc*d b aabcccd aabcccd
+\(a\)\1bc*[ce]d b aabcccd aabcccd
+^\(a\)\1b\(c\)*cd$ b aabcccd aabcccd
+
+# ordinary repetitions
+ab*c & abc abc
+ab+c - abc abc
+ab?c - abc abc
+a\(*\)b b a*b a*b
+a\(**\)b b ab ab
+a\(***\)b bC BADRPT
+*a b *a *a
+**a b a a
+***a bC BADRPT
+
+# the dreaded bounded repetitions
+{ & { {
+{abc & {abc {abc
+{1 C BADRPT
+{1} C BADRPT
+a{b & a{b a{b
+a{1}b - ab ab
+a\{1\}b b ab ab
+a{1,}b - ab ab
+a\{1,\}b b ab ab
+a{1,2}b - aab aab
+a\{1,2\}b b aab aab
+a{1 C EBRACE
+a\{1 bC EBRACE
+a{1a C EBRACE
+a\{1a bC EBRACE
+a{1a} C BADBR
+a\{1a\} bC BADBR
+a{,2} - a{,2} a{,2}
+a\{,2\} bC BADBR
+a{,} - a{,} a{,}
+a\{,\} bC BADBR
+a{1,x} C BADBR
+a\{1,x\} bC BADBR
+a{1,x C EBRACE
+a\{1,x bC EBRACE
+a{300} C BADBR
+a\{300\} bC BADBR
+a{1,0} C BADBR
+a\{1,0\} bC BADBR
+ab{0,0}c - abcac ac
+ab\{0,0\}c b abcac ac
+ab{0,1}c - abcac abc
+ab\{0,1\}c b abcac abc
+ab{0,3}c - abbcac abbc
+ab\{0,3\}c b abbcac abbc
+ab{1,1}c - acabc abc
+ab\{1,1\}c b acabc abc
+ab{1,3}c - acabc abc
+ab\{1,3\}c b acabc abc
+ab{2,2}c - abcabbc abbc
+ab\{2,2\}c b abcabbc abbc
+ab{2,4}c - abcabbc abbc
+ab\{2,4\}c b abcabbc abbc
+((a{1,10}){1,10}){1,10} - a a a,a
+
+# multiple repetitions
+a** &C BADRPT
+a++ C BADRPT
+a?? C BADRPT
+a*+ C BADRPT
+a*? C BADRPT
+a+* C BADRPT
+a+? C BADRPT
+a?* C BADRPT
+a?+ C BADRPT
+a{1}{1} C BADRPT
+a*{1} C BADRPT
+a+{1} C BADRPT
+a?{1} C BADRPT
+a{1}* C BADRPT
+a{1}+ C BADRPT
+a{1}? C BADRPT
+a*{b} - a{b} a{b}
+a\{1\}\{1\} bC BADRPT
+a*\{1\} bC BADRPT
+a\{1\}* bC BADRPT
+
+# brackets, and numerous perversions thereof
+a[b]c & abc abc
+a[ab]c & abc abc
+a[^ab]c & adc adc
+a[]b]c & a]c a]c
+a[[b]c & a[c a[c
+a[-b]c & a-c a-c
+a[^]b]c & adc adc
+a[^-b]c & adc adc
+a[b-]c & a-c a-c
+a[b &C EBRACK
+a[] &C EBRACK
+a[1-3]c & a2c a2c
+a[3-1]c &C ERANGE
+a[1-3-5]c &C ERANGE
+a[[.-.]--]c & a-c a-c
+a[1- &C ERANGE
+a[[. &C EBRACK
+a[[.x &C EBRACK
+a[[.x. &C EBRACK
+a[[.x.] &C EBRACK
+a[[.x.]] & ax ax
+a[[.x,.]] &C ECOLLATE
+a[[.one.]]b & a1b a1b
+a[[.notdef.]]b &C ECOLLATE
+a[[.].]]b & a]b a]b
+a[[:alpha:]]c & abc abc
+a[[:notdef:]]c &C ECTYPE
+a[[: &C EBRACK
+a[[:alpha &C EBRACK
+a[[:alpha:] &C EBRACK
+a[[:alpha,:] &C ECTYPE
+a[[:]:]]b &C ECTYPE
+a[[:-:]]b &C ECTYPE
+a[[:alph:]] &C ECTYPE
+a[[:alphabet:]] &C ECTYPE
+##[[:alnum:]]+ - -%@a0X- a0X
+##[[:alpha:]]+ - -%@aX0- aX
+[[:blank:]]+ - aSSTb SST
+##[[:cntrl:]]+ - aNTb NT
+[[:digit:]]+ - a019b 019
+##[[:graph:]]+ - Sa%bS a%b
+[[:lower:]]+ - AabC ab
+##[[:print:]]+ - NaSbN aSb
+##[[:punct:]]+ - S%-&T %-&
+[[:space:]]+ - aSNTb SNT
+[[:upper:]]+ - aBCd BC
+[[:xdigit:]]+ - p0f3Cq 0f3C
+a[[=b=]]c & abc abc
+a[[= &C EBRACK
+a[[=b &C EBRACK
+a[[=b= &C EBRACK
+a[[=b=] &C EBRACK
+a[[=b,=]] &C ECOLLATE
+a[[=one=]]b & a1b a1b
+
+# complexities
+a(((b)))c - abc abc
+a(b|(c))d - abd abd
+a(b*|c)d - abbd abbd
+# just gotta have one DFA-buster, of course
+a[ab]{20} - aaaaabaaaabaaaabaaaab aaaaabaaaabaaaabaaaab
+# and an inline expansion in case somebody gets tricky
+a[ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab] - aaaaabaaaabaaaabaaaab aaaaabaaaabaaaabaaaab
+# and in case somebody just slips in an NFA...
+a[ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab](wee|week)(knights|night) - aaaaabaaaabaaaabaaaabweeknights aaaaabaaaabaaaabaaaabweeknights
+# fish for anomalies as the number of states passes 32
+12345678901234567890123456789 - a12345678901234567890123456789b 12345678901234567890123456789
+123456789012345678901234567890 - a123456789012345678901234567890b 123456789012345678901234567890
+1234567890123456789012345678901 - a1234567890123456789012345678901b 1234567890123456789012345678901
+12345678901234567890123456789012 - a12345678901234567890123456789012b 12345678901234567890123456789012
+123456789012345678901234567890123 - a123456789012345678901234567890123b 123456789012345678901234567890123
+# and one really big one, beyond any plausible word width
+1234567890123456789012345678901234567890123456789012345678901234567890 - a1234567890123456789012345678901234567890123456789012345678901234567890b 1234567890123456789012345678901234567890123456789012345678901234567890
+# fish for problems as brackets go past 8
+[ab][cd][ef][gh][ij][kl][mn] - xacegikmoq acegikm
+[ab][cd][ef][gh][ij][kl][mn][op] - xacegikmoq acegikmo
+[ab][cd][ef][gh][ij][kl][mn][op][qr] - xacegikmoqy acegikmoq
+[ab][cd][ef][gh][ij][kl][mn][op][q] - xacegikmoqy acegikmoq
+
+# subtleties of matching
+abc & xabcy abc
+a\(b\)?c\1d b acd
+aBc i Abc Abc
+a[Bc]*d i abBCcd abBCcd
+0[[:upper:]]1 &i 0a1 0a1
+0[[:lower:]]1 &i 0A1 0A1
+a[^b]c &i abc
+a[^b]c &i aBc
+a[^b]c &i adc adc
+[a]b[c] - abc abc
+[a]b[a] - aba aba
+[abc]b[abc] - abc abc
+[abc]b[abd] - abd abd
+a(b?c)+d - accd accd
+(wee|week)(knights|night) - weeknights weeknights
+(we|wee|week|frob)(knights|night|day) - weeknights weeknights
+a[bc]d - xyzaaabcaababdacd abd
+a[ab]c - aaabc abc
+abc s abc abc
+a* & b @b
+
+# Let's have some fun -- try to match a C comment.
+# first the obvious, which looks okay at first glance...
+/\*.*\*/ - /*x*/ /*x*/
+# but...
+/\*.*\*/ - /*x*/y/*z*/ /*x*/y/*z*/
+# okay, we must not match */ inside; try to do that...
+/\*([^*]|\*[^/])*\*/ - /*x*/ /*x*/
+/\*([^*]|\*[^/])*\*/ - /*x*/y/*z*/ /*x*/
+# but...
+/\*([^*]|\*[^/])*\*/ - /*x**/y/*z*/ /*x**/y/*z*/
+# and a still fancier version, which does it right (I think)...
+/\*([^*]|\*+[^*/])*\*+/ - /*x*/ /*x*/
+/\*([^*]|\*+[^*/])*\*+/ - /*x*/y/*z*/ /*x*/
+/\*([^*]|\*+[^*/])*\*+/ - /*x**/y/*z*/ /*x**/
+/\*([^*]|\*+[^*/])*\*+/ - /*x****/y/*z*/ /*x****/
+/\*([^*]|\*+[^*/])*\*+/ - /*x**x*/y/*z*/ /*x**x*/
+/\*([^*]|\*+[^*/])*\*+/ - /*x***x/y/*z*/ /*x***x/y/*z*/
+
+# subexpressions
+a(b)(c)d - abcd abcd b,c
+a(((b)))c - abc abc b,b,b
+a(b|(c))d - abd abd b,-
+a(b*|c|e)d - abbd abbd bb
+a(b*|c|e)d - acd acd c
+a(b*|c|e)d - ad ad @d
+a(b?)c - abc abc b
+a(b?)c - ac ac @c
+a(b+)c - abc abc b
+a(b+)c - abbbc abbbc bbb
+a(b*)c - ac ac @c
+(a|ab)(bc([de]+)f|cde) - abcdef abcdef a,bcdef,de
+# the regression tester only asks for 9 subexpressions
+a(b)(c)(d)(e)(f)(g)(h)(i)(j)k - abcdefghijk abcdefghijk b,c,d,e,f,g,h,i,j
+a(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)l - abcdefghijkl abcdefghijkl b,c,d,e,f,g,h,i,j,k
+a([bc]?)c - abc abc b
+a([bc]?)c - ac ac @c
+a([bc]+)c - abc abc b
+a([bc]+)c - abcc abcc bc
+a([bc]+)bc - abcbc abcbc bc
+a(bb+|b)b - abb abb b
+a(bbb+|bb+|b)b - abb abb b
+a(bbb+|bb+|b)b - abbb abbb bb
+a(bbb+|bb+|b)bb - abbb abbb b
+(.*).* - abcdef abcdef abcdef
+##(a*)* - bc @b @b
+
+# do we get the right subexpression when it is used more than once?
+a(b|c)*d - ad ad -
+a(b|c)*d - abcd abcd c
+a(b|c)+d - abd abd b
+a(b|c)+d - abcd abcd c
+a(b|c?)+d - ad ad @d
+a(b|c?)+d - abcd abcd @d
+a(b|c){0,0}d - ad ad -
+a(b|c){0,1}d - ad ad -
+a(b|c){0,1}d - abd abd b
+a(b|c){0,2}d - ad ad -
+a(b|c){0,2}d - abcd abcd c
+a(b|c){0,}d - ad ad -
+a(b|c){0,}d - abcd abcd c
+a(b|c){1,1}d - abd abd b
+a(b|c){1,1}d - acd acd c
+a(b|c){1,2}d - abd abd b
+a(b|c){1,2}d - abcd abcd c
+a(b|c){1,}d - abd abd b
+a(b|c){1,}d - abcd abcd c
+a(b|c){2,2}d - acbd acbd b
+a(b|c){2,2}d - abcd abcd c
+a(b|c){2,4}d - abcd abcd c
+a(b|c){2,4}d - abcbd abcbd b
+a(b|c){2,4}d - abcbcd abcbcd c
+a(b|c){2,}d - abcd abcd c
+a(b|c){2,}d - abcbd abcbd b
+##a(b+|((c)*))+d - abd abd @d,@d,-
+##a(b+|((c)*))+d - abcd abcd @d,@d,-
+
+# check out the STARTEND option
+[abc] &# a(b)c b
+[abc] &# a(d)c
+[abc] &# a(bc)d b
+[abc] &# a(dc)d c
+. &# a()c
+b.*c &# b(bc)c bc
+b.* &# b(bc)c bc
+.*c &# b(bc)c bc
+
+# plain strings, with the NOSPEC flag
+abc m abc abc
+abc m xabcy abc
+abc m xyz
+a*b m aba*b a*b
+a*b m ab
+"" mC EMPTY
+
+# cases involving NULs
+aZb & a a
+aZb &p a
+#aZb &p# (aZb) aZb
+aZ*b &p# (ab) ab
+#a.b &# (aZb) aZb
+#a.* &# (aZb)c aZb
+
+# word boundaries (ick)
+[[:<:]]a & a a
+[[:<:]]a & ba
+[[:<:]]a & -a a
+a[[:>:]] & a a
+a[[:>:]] & ab
+a[[:>:]] & a- a
+[[:<:]]a.c[[:>:]] & axcd-dayc-dazce-abc abc
+[[:<:]]a.c[[:>:]] & axcd-dayc-dazce-abc-q abc
+[[:<:]]a.c[[:>:]] & axc-dayc-dazce-abc axc
+[[:<:]]b.c[[:>:]] & a_bxc-byc_d-bzc-q bzc
+[[:<:]].x..[[:>:]] & y_xa_-_xb_y-_xc_-axdc _xc_
+[[:<:]]a_b[[:>:]] & x_a_b
+
+# past problems, and suspected problems
+(A[1])|(A[2])|(A[3])|(A[4])|(A[5])|(A[6])|(A[7])|(A[8])|(A[9])|(A[A]) - A1 A1
+abcdefghijklmnop i abcdefghijklmnop abcdefghijklmnop
+abcdefghijklmnopqrstuv i abcdefghijklmnopqrstuv abcdefghijklmnopqrstuv
+(ALAK)|(ALT[AB])|(CC[123]1)|(CM[123]1)|(GAMC)|(LC[23][EO ])|(SEM[1234])|(SL[ES][12])|(SLWW)|(SLF )|(SLDT)|(VWH[12])|(WH[34][EW])|(WP1[ESN]) - CC11 CC11
+CC[13]1|a{21}[23][EO][123][Es][12]a{15}aa[34][EW]aaaaaaa[X]a - CC11 CC11
+Char \([a-z0-9_]*\)\[.* b Char xyz[k Char xyz[k xyz
+a?b - ab ab
+-\{0,1\}[0-9]*$ b -5 -5
diff --git a/gnu/usr.bin/grep/tests/warning.sh b/gnu/usr.bin/grep/tests/warning.sh
index d2dc6d5..bfca533 100755
--- a/gnu/usr.bin/grep/tests/warning.sh
+++ b/gnu/usr.bin/grep/tests/warning.sh
@@ -1,4 +1,4 @@
-#! /bin/sh
+#!/bin/sh
#
# Tell them not to be alarmed.
diff --git a/gnu/usr.bin/grep/xalloc.h b/gnu/usr.bin/grep/xalloc.h
new file mode 100644
index 0000000..098a6c2
--- /dev/null
+++ b/gnu/usr.bin/grep/xalloc.h
@@ -0,0 +1,87 @@
+/* xalloc.h -- malloc with out-of-memory checking
+ Copyright (C) 1990-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
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ 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. */
+
+#ifndef XALLOC_H_
+# define XALLOC_H_
+
+# ifndef PARAMS
+# if defined PROTOTYPES || (defined __STDC__ && __STDC__)
+# define PARAMS(Args) Args
+# else
+# define PARAMS(Args) ()
+# endif
+# endif
+
+# ifndef __attribute__
+# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8) || __STRICT_ANSI__
+# define __attribute__(x)
+# endif
+# endif
+
+# ifndef ATTRIBUTE_NORETURN
+# define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
+# endif
+
+/* Exit value when the requested amount of memory is not available.
+ It is initialized to EXIT_FAILURE, but the caller may set it to
+ some other value. */
+extern int xalloc_exit_failure;
+
+/* If this pointer is non-zero, run the specified function upon each
+ allocation failure. It is initialized to zero. */
+extern void (*xalloc_fail_func) PARAMS ((void));
+
+/* If XALLOC_FAIL_FUNC is undefined or a function that returns, this
+ message is output. It is translated via gettext.
+ Its value is "memory exhausted". */
+extern char const xalloc_msg_memory_exhausted[];
+
+/* This function is always triggered when memory is exhausted. It is
+ in charge of honoring the three previous items. This is the
+ function to call when one wants the program to die because of a
+ memory allocation failure. */
+extern void xalloc_die PARAMS ((void)) ATTRIBUTE_NORETURN;
+
+void *xmalloc PARAMS ((size_t n));
+void *xcalloc PARAMS ((size_t n, size_t s));
+void *xrealloc PARAMS ((void *p, size_t n));
+char *xstrdup PARAMS ((const char *str));
+
+# define XMALLOC(Type, N_items) ((Type *) xmalloc (sizeof (Type) * (N_items)))
+# define XCALLOC(Type, N_items) ((Type *) xcalloc (sizeof (Type), (N_items)))
+# define XREALLOC(Ptr, Type, N_items) \
+ ((Type *) xrealloc ((void *) (Ptr), sizeof (Type) * (N_items)))
+
+/* Declare and alloc memory for VAR of type TYPE. */
+# define NEW(Type, Var) Type *(Var) = XMALLOC (Type, 1)
+
+/* Free VAR only if non NULL. */
+# define XFREE(Var) \
+ do { \
+ if (Var) \
+ free (Var); \
+ } while (0)
+
+/* Return a pointer to a malloc'ed copy of the array SRC of NUM elements. */
+# define CCLONE(Src, Num) \
+ (memcpy (xmalloc (sizeof (*Src) * (Num)), (Src), sizeof (*Src) * (Num)))
+
+/* Return a malloc'ed copy of SRC. */
+# define CLONE(Src) CCLONE (Src, 1)
+
+
+#endif /* !XALLOC_H_ */
diff --git a/gnu/usr.bin/grep/xmalloc.c b/gnu/usr.bin/grep/xmalloc.c
new file mode 100644
index 0000000..2f103d6
--- /dev/null
+++ b/gnu/usr.bin/grep/xmalloc.c
@@ -0,0 +1,116 @@
+/* xmalloc.c -- malloc with out of memory checking
+ Copyright (C) 1990-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
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ 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. */
+
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <sys/types.h>
+
+#if STDC_HEADERS
+# include <stdlib.h>
+#else
+void *calloc ();
+void *malloc ();
+void *realloc ();
+void free ();
+#endif
+
+#if ENABLE_NLS
+# include <libintl.h>
+# define _(Text) gettext (Text)
+#else
+# define textdomain(Domain)
+# define _(Text) Text
+#endif
+#define N_(Text) Text
+
+#include "error.h"
+#include "xalloc.h"
+
+#ifndef EXIT_FAILURE
+# define EXIT_FAILURE 1
+#endif
+
+#ifndef HAVE_DONE_WORKING_MALLOC_CHECK
+"you must run the autoconf test for a properly working malloc -- see malloc.m4"
+#endif
+
+#ifndef HAVE_DONE_WORKING_REALLOC_CHECK
+"you must run the autoconf test for a properly working realloc --see realloc.m4"
+#endif
+
+/* Exit value when the requested amount of memory is not available.
+ The caller may set it to some other value. */
+int xalloc_exit_failure = EXIT_FAILURE;
+
+/* If non NULL, call this function when memory is exhausted. */
+void (*xalloc_fail_func) PARAMS ((void)) = 0;
+
+/* If XALLOC_FAIL_FUNC is NULL, or does return, display this message
+ before exiting when memory is exhausted. Goes through gettext. */
+char const xalloc_msg_memory_exhausted[] = N_("memory exhausted");
+
+void
+xalloc_die (void)
+{
+ if (xalloc_fail_func)
+ (*xalloc_fail_func) ();
+ error (xalloc_exit_failure, 0, "%s", _(xalloc_msg_memory_exhausted));
+ /* The `noreturn' cannot be given to error, since it may return if
+ its first argument is 0. To help compilers understand the
+ xalloc_die does terminate, call exit. */
+ exit (EXIT_FAILURE);
+}
+
+/* Allocate N bytes of memory dynamically, with error checking. */
+
+void *
+xmalloc (size_t n)
+{
+ void *p;
+
+ p = malloc (n);
+ if (p == 0)
+ xalloc_die ();
+ return p;
+}
+
+/* Change the size of an allocated block of memory P to N bytes,
+ with error checking. */
+
+void *
+xrealloc (void *p, size_t n)
+{
+ p = realloc (p, n);
+ if (p == 0)
+ xalloc_die ();
+ return p;
+}
+
+/* Allocate memory for N elements of S bytes, with error checking. */
+
+void *
+xcalloc (size_t n, size_t s)
+{
+ void *p;
+
+ p = calloc (n, s);
+ if (p == 0)
+ xalloc_die ();
+ return p;
+}
diff --git a/gnu/usr.bin/grep/xstrtol.c b/gnu/usr.bin/grep/xstrtol.c
new file mode 100644
index 0000000..07023d9
--- /dev/null
+++ b/gnu/usr.bin/grep/xstrtol.c
@@ -0,0 +1,282 @@
+/* A more useful interface to strtol.
+ Copyright (C) 1995, 1996, 1998-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
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ 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. */
+
+/* Written by Jim Meyering. */
+
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#ifndef __strtol
+# define __strtol strtol
+# define __strtol_t long int
+# define __xstrtol xstrtol
+#endif
+
+/* Some pre-ANSI implementations (e.g. SunOS 4)
+ need stderr defined if assertion checking is enabled. */
+#include <stdio.h>
+
+#if STDC_HEADERS
+# include <stdlib.h>
+#endif
+
+#if HAVE_STRING_H
+# include <string.h>
+#else
+# include <strings.h>
+# ifndef strchr
+# define strchr index
+# endif
+#endif
+
+#include <assert.h>
+#include <ctype.h>
+
+#include <errno.h>
+#ifndef errno
+extern int errno;
+#endif
+
+#if HAVE_LIMITS_H
+# include <limits.h>
+#endif
+
+#ifndef CHAR_BIT
+# define CHAR_BIT 8
+#endif
+
+/* The extra casts work around common compiler bugs. */
+#define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
+/* The outer cast is needed to work around a bug in Cray C 5.0.3.0.
+ It is necessary at least when t == time_t. */
+#define TYPE_MINIMUM(t) ((t) (TYPE_SIGNED (t) \
+ ? ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1) : (t) 0))
+#define TYPE_MAXIMUM(t) (~ (t) 0 - TYPE_MINIMUM (t))
+
+#if defined (STDC_HEADERS) || (!defined (isascii) && !defined (HAVE_ISASCII))
+# define IN_CTYPE_DOMAIN(c) 1
+#else
+# define IN_CTYPE_DOMAIN(c) isascii(c)
+#endif
+
+#define ISSPACE(c) (IN_CTYPE_DOMAIN (c) && isspace (c))
+
+#include "xstrtol.h"
+
+#ifndef strtol
+long int strtol ();
+#endif
+
+#ifndef strtoul
+unsigned long int strtoul ();
+#endif
+
+#ifndef strtoumax
+uintmax_t strtoumax ();
+#endif
+
+static int
+bkm_scale (__strtol_t *x, int scale_factor)
+{
+ __strtol_t product = *x * scale_factor;
+ if (*x != product / scale_factor)
+ return 1;
+ *x = product;
+ return 0;
+}
+
+static int
+bkm_scale_by_power (__strtol_t *x, int base, int power)
+{
+ while (power--)
+ if (bkm_scale (x, base))
+ return 1;
+
+ return 0;
+}
+
+/* FIXME: comment. */
+
+strtol_error
+__xstrtol (const char *s, char **ptr, int strtol_base,
+ __strtol_t *val, const char *valid_suffixes)
+{
+ char *t_ptr;
+ char **p;
+ __strtol_t tmp;
+
+ assert (0 <= strtol_base && strtol_base <= 36);
+
+ p = (ptr ? ptr : &t_ptr);
+
+ if (! TYPE_SIGNED (__strtol_t))
+ {
+ const char *q = s;
+ while (ISSPACE ((unsigned char) *q))
+ ++q;
+ if (*q == '-')
+ return LONGINT_INVALID;
+ }
+
+ errno = 0;
+ tmp = __strtol (s, p, strtol_base);
+ if (errno != 0)
+ return LONGINT_OVERFLOW;
+ if (*p == s)
+ return LONGINT_INVALID;
+
+ /* Let valid_suffixes == NULL mean `allow any suffix'. */
+ /* FIXME: update all callers except the ones that allow suffixes
+ after the number, changing last parameter NULL to `""'. */
+ if (!valid_suffixes)
+ {
+ *val = tmp;
+ return LONGINT_OK;
+ }
+
+ if (**p != '\0')
+ {
+ int base = 1024;
+ int suffixes = 1;
+ int overflow;
+
+ if (!strchr (valid_suffixes, **p))
+ {
+ *val = tmp;
+ return LONGINT_INVALID_SUFFIX_CHAR;
+ }
+
+ if (strchr (valid_suffixes, '0'))
+ {
+ /* The ``valid suffix'' '0' is a special flag meaning that
+ an optional second suffix is allowed, which can change
+ the base, e.g. "100MD" for 100 megabytes decimal. */
+
+ switch (p[0][1])
+ {
+ case 'B':
+ suffixes++;
+ break;
+
+ case 'D':
+ base = 1000;
+ suffixes++;
+ break;
+ }
+ }
+
+ switch (**p)
+ {
+ case 'b':
+ overflow = bkm_scale (&tmp, 512);
+ break;
+
+ case 'B':
+ overflow = bkm_scale (&tmp, 1024);
+ break;
+
+ case 'c':
+ overflow = 0;
+ break;
+
+ case 'E': /* Exa */
+ overflow = bkm_scale_by_power (&tmp, base, 6);
+ break;
+
+ case 'G': /* Giga */
+ overflow = bkm_scale_by_power (&tmp, base, 3);
+ break;
+
+ case 'k': /* kilo */
+ overflow = bkm_scale_by_power (&tmp, base, 1);
+ break;
+
+ case 'M': /* Mega */
+ case 'm': /* 'm' is undocumented; for backward compatibility only */
+ overflow = bkm_scale_by_power (&tmp, base, 2);
+ break;
+
+ case 'P': /* Peta */
+ overflow = bkm_scale_by_power (&tmp, base, 5);
+ break;
+
+ case 'T': /* Tera */
+ overflow = bkm_scale_by_power (&tmp, base, 4);
+ break;
+
+ case 'w':
+ overflow = bkm_scale (&tmp, 2);
+ break;
+
+ case 'Y': /* Yotta */
+ overflow = bkm_scale_by_power (&tmp, base, 8);
+ break;
+
+ case 'Z': /* Zetta */
+ overflow = bkm_scale_by_power (&tmp, base, 7);
+ break;
+
+ default:
+ *val = tmp;
+ return LONGINT_INVALID_SUFFIX_CHAR;
+ break;
+ }
+
+ if (overflow)
+ return LONGINT_OVERFLOW;
+
+ (*p) += suffixes;
+ }
+
+ *val = tmp;
+ return LONGINT_OK;
+}
+
+#ifdef TESTING_XSTRTO
+
+# include <stdio.h>
+# include "error.h"
+
+char *program_name;
+
+int
+main (int argc, char** argv)
+{
+ strtol_error s_err;
+ int i;
+
+ program_name = argv[0];
+ for (i=1; i<argc; i++)
+ {
+ char *p;
+ __strtol_t val;
+
+ s_err = __xstrtol (argv[i], &p, 0, &val, "bckmw");
+ if (s_err == LONGINT_OK)
+ {
+ printf ("%s->%lu (%s)\n", argv[i], val, p);
+ }
+ else
+ {
+ STRTOL_FATAL_ERROR (argv[i], "arg", s_err);
+ }
+ }
+ exit (0);
+}
+
+#endif /* TESTING_XSTRTO */
diff --git a/gnu/usr.bin/grep/xstrtol.h b/gnu/usr.bin/grep/xstrtol.h
new file mode 100644
index 0000000..7a9a024
--- /dev/null
+++ b/gnu/usr.bin/grep/xstrtol.h
@@ -0,0 +1,64 @@
+#ifndef XSTRTOL_H_
+# define XSTRTOL_H_ 1
+
+# if HAVE_INTTYPES_H
+# include <inttypes.h> /* for uintmax_t */
+# endif
+
+# ifndef PARAMS
+# if defined PROTOTYPES || (defined __STDC__ && __STDC__)
+# define PARAMS(Args) Args
+# else
+# define PARAMS(Args) ()
+# endif
+# endif
+
+# ifndef _STRTOL_ERROR
+enum strtol_error
+ {
+ LONGINT_OK, LONGINT_INVALID, LONGINT_INVALID_SUFFIX_CHAR, LONGINT_OVERFLOW
+ };
+typedef enum strtol_error strtol_error;
+# endif
+
+# define _DECLARE_XSTRTOL(name, type) \
+ strtol_error \
+ name PARAMS ((const char *s, char **ptr, int base, \
+ type *val, const char *valid_suffixes));
+_DECLARE_XSTRTOL (xstrtol, long int)
+_DECLARE_XSTRTOL (xstrtoul, unsigned long int)
+_DECLARE_XSTRTOL (xstrtoumax, uintmax_t)
+
+# define _STRTOL_ERROR(Exit_code, Str, Argument_type_string, Err) \
+ do \
+ { \
+ switch ((Err)) \
+ { \
+ case LONGINT_OK: \
+ abort (); \
+ \
+ case LONGINT_INVALID: \
+ error ((Exit_code), 0, "invalid %s `%s'", \
+ (Argument_type_string), (Str)); \
+ break; \
+ \
+ case LONGINT_INVALID_SUFFIX_CHAR: \
+ error ((Exit_code), 0, "invalid character following %s `%s'", \
+ (Argument_type_string), (Str)); \
+ break; \
+ \
+ case LONGINT_OVERFLOW: \
+ error ((Exit_code), 0, "%s `%s' too large", \
+ (Argument_type_string), (Str)); \
+ break; \
+ } \
+ } \
+ while (0)
+
+# define STRTOL_FATAL_ERROR(Str, Argument_type_string, Err) \
+ _STRTOL_ERROR (2, Str, Argument_type_string, Err)
+
+# define STRTOL_FAIL_WARN(Str, Argument_type_string, Err) \
+ _STRTOL_ERROR (0, Str, Argument_type_string, Err)
+
+#endif /* not XSTRTOL_H_ */
diff --git a/gnu/usr.bin/grep/xstrtoumax.c b/gnu/usr.bin/grep/xstrtoumax.c
new file mode 100644
index 0000000..04d7cf9
--- /dev/null
+++ b/gnu/usr.bin/grep/xstrtoumax.c
@@ -0,0 +1,31 @@
+/* xstrtoumax.c -- A more useful interface to strtoumax.
+ Copyright 1999 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
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ 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. */
+
+/* Written by Paul Eggert. */
+
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#if HAVE_INTTYPES_H
+# include <inttypes.h>
+#endif
+
+#define __strtol strtoumax
+#define __strtol_t uintmax_t
+#define __xstrtol xstrtoumax
+#include "xstrtol.c"
OpenPOWER on IntegriCloud