2014-06-03 Jim Meyering
version 2.20
* NEWS: Record release date.
2014-05-30 Jim Meyering
grep: fix --max-count=N (-m N) to stop reading after Nth match
With --max-count=N (-m N), grep is supposed to stop reading input
after it has found the Nth match. However, a recent context-
related change made it so grep would always read to end of file.
* src/grep.c (prtext): Don't let a negative "out_after" value
make "pending" line count negative.
* tests/max-count-overread: New test, for this.
* tests/Makefile.am (TESTS): Add it.
* NEWS (Bug fixes): Mention it.
* THANKS: Add names of two recent bug reporters.
This bug was introduced by commit v2.18-139-g5122195.
Reported by Marc Aldorasi in http://bugs.gnu.org/17640.
2014-05-29 Jim Meyering
dfa: fix off-by-one under-allocation from recent change
Commit v2.19-10-gc32ff67 mistakenly made this change:
-realloc_trans_if_necessary (d, 1);
+realloc_trans_if_necessary (d, 0);
which led to a heap buffer overflow.
* src/dfa.c (dfaexec): Allocate space for one state, as before.
2014-05-28 Norihiro Tanaka
dfa: fix bug with regex containing multiple begin/end-line constraints
grep -E 'a(b$|c$)' would mistakenly match "aa".
* src/dfa.c (dfamust): When resetting 'is' in OR, also reset
'begline' and 'endline' of 'must'.
* NEWS (Bug fixes): Mention it.
This bug was introduced via commit v2.18-85-g2c94326.
Reported by Péter Radics in .
2014-05-26 Norihiro Tanaka
dfa: simplify building initial state
build_state_zero doesn't need the struct dfa to be initialized,
so remove the initialization and simplify.
* src/dfa.c (build_state_zero): Remove.
(dfaexec): Call realloc_trans_if_necessary and build_state directly.
dfa: revert "grep: do not count newline before the start of buffer"
This reverts commit 5dc3af2806d21455b818be3f9da26c372e4a7f8d.
The previous change renders that commit unnecessary.
dfa: do not clear the first state of a transition table
If number of DFA states reaches 1024, build_state clears transition
tables to save memory. However, the initial state is always used,
so clearing it just wastes time.
* src/dfa.c (build_state): Do not clear the initial state's
transition and failure tables.
grep: remove unnecessary argument
* src/grep.c (do_execute): Remove argument 'start_ptr'. It's always null.
All uses changed.
2014-05-24 Paul Eggert
grep: --exclude-dir=FOO/ now ignores the trailing slash
Problem reported by Khaled Ziyaeen; see: http://bugs.gnu.org/17481
* NEWS, doc/grep.texi (File and Directory Selection): Document this.
* src/grep.c (main): Implement this.
* tests/include-exclude: Test this.
dist: don't distribute lib/colorize.c
'configure' creates this file, so it shouldn't be distributed; see:
http://bugs.gnu.org/17480
* configure.ac (COLORIZE_SOURCE): New macro.
Don't use AC_CONFIG_LINKS for lib/colorize.c.
* lib/Makefile.am (nodist_libgreputils_a_SOURCES): New macro.
(libgreputils_a_SOURCES): Remove colorize.c.
(CLEANFILES): Add colorize.c
(colorize.c): New rule.
2014-05-23 behoffski
maint: uncapitalize first letter of two dfaerror message strings
* dfa.c (lex): Make two message strings consistent with all of
the others: do not capitalize the first letter of the first word.
2014-05-23 Jim Meyering
maint: revert "grep: port mb_next_wc to RHEL 6.5 x86-64"
This reverts commit v2.18-148-ga6ae68d.
Now that we have gnulib change v0.1-131-g2a045bc, "mbrlen, mbrtowc:
fix bug with empty input", this work-around is no longer needed.
gnulib: update, for mbrlen/mbrtowc empty input bug fix
2014-05-22 Jim Meyering
maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
version 2.19
* NEWS: Record release date.
2014-05-21 Jim Meyering
maint: avoid new false-positive syntax-check failure
* cfg.mk (exclude_file_name_regexp--sc_prohibit_doubled_word):
Exempt new test file that contains legitimate use of "in in".
2014-05-17 Norihiro Tanaka
tests: add test case for newline-count fix
* tests/count-newline: New test.
* tests/Makefile.am (TESTS): Add it.
2014-05-16 Norihiro Tanaka
grep: do not count newline before the start of buffer
* src/dfa.c (build_state): When checking whether the previous
character was a newline, do not count any newline before the
start of the buffer.
2014-05-15 Paul Eggert
grep: port mb_next_wc to RHEL 6.5 x86-64
* src/searchutils.c (mb_next_wc): Work around glibc bug 16950; see:
https://sourceware.org/bugzilla/show_bug.cgi?id=16950
This bug was masked in the other GNU/Linux tests I made. It was
exposed on RHEL 6.5 x86-64, where the compiler (GCC Red Hat 4.4.7-4)
happened to use temporaries in a different way.
Also see recent changes to the Gnulib documentation in this area:
http://lists.gnu.org/archive/html/bug-gnulib/2014-05/msg00013.html
tests: port mb-non-UTF8-performance to RHEL 6.5
* tests/mb-non-UTF8-performance (timeout): Use an integer,
as 'timeout 1.234' doesn't work in EUC locales.
2014-05-12 Paul Eggert
egrep, fgrep: port to Solaris 10 /bin/sh
This old shell doesn't grok ${0%/*}; see: http://bugs.gnu.org/17471
* src/Makefile.am (egrep fgrep): Don't assume the shell does substrings.
* src/egrep.sh (dir): New var, so that the substring calculation is
done only once (which is a small win even with newer shells),
and so that the calculation is easier to edit on older shells.
2014-05-10 Jim Meyering
maint: NEWS: adjust wording to reflect move
* NEWS (Improvements): Correct direction-relative wording,
now that the referent is below, not above.
maint: NEWS: move "Improvements" to the top
* NEWS: Move the small "Improvements" section to precede
the longer "Bug fixes" one.
gnulib: update submodule to latest, and bootstrap
* gnulib: Update submodule.
* bootstrap: Update from gnulib.
2014-05-10 Paul Eggert
dfa: omit double includes
* src/dfa.c: Don't include stddef.h or stdbool.h, as dfa.h includes
them already, and it's the same module as we are.
Suggested by Aharon Robbins in: http://bugs.gnu.org/17458
dfa: fix bug with \< etc in multibyte locales
Problem reported by Stephane Chazelas in: http://bugs.gnu.org/16867
* NEWS: Document the fix.
* src/dfa.c (dfaoptimize): Remove any superset if changing from
UTF-8 to unibyte, and if the pattern has no backreferences.
(dfassbuild): In multibyte locales, treat \< \> \b \B as
backreferences in the DFA, since the DFA relies on unibyte
tests to check them.
(dfacomp): Optimize after building the superset, so that
dfassbuild can depend on d->multibyte. A downside is that
dfaoptimize must remove supersets that are likely slower than the
DFA after optimization, but that's been done in the
above-described change.
* tests/Makefile.am (XFAIL_TESTS): Remove word-delim-multibyte,
since the test works now.
tests: add test case for -C 0 change
* tests/context-0: New test.
* tests/Makefile.am (TESTS): Add it.
grep: -A 0, -B 0, -C 0 now output a separator
Problem reported by Dan Jacobson in: http://bugs.gnu.org/17380
* NEWS:
* doc/grep.texi (Context Line Control): Document this.
* src/grep.c (prtext): Output a separator even if context is zero.
(main): Default context is now -1, not 0.
2014-05-09 Paul Eggert
grep: minor improvements to retry-DFA-superset patch
* src/dfasearch.c (EGexecute): Avoid unnecessary test in a context
where memrchr cannot return a null pointer.
2014-05-09 Norihiro Tanaka
grep: retry DFA superset after matching multiple lines
* src/dfasearch.c (EGexecute): Without this patch, the code reverts
to KWset when the DFA superset matches multiple lines.
However, if the DFA superset matches multiple lines, it most likely
also matches a single line, and reverting to KWset means dfafast
won't work effectively. Change the code so that it retries the DFA
superset immediately after it matches multipline lines. On my platform
this improves the performance of "LC_ALL=C grep '\(ab\)cd\1d' k" from
3.48 to 2.14 seconds realtime, where k contains the output of
"yes abcdabc | head -50000000".
dfa: fix inconsistency in multibyte locales
* src/dfa.c (dfaexec): Use the same exit condition in multibyte
locales as in unibyte.
2014-05-08 Jim Meyering
maint: mark some breakless cases with /* fallthrough */ comment
* src/dfa.c (addtok_mb, dfaanalyze): Add comment so that it is
clear that the "break" statement is deliberately omitted.
2014-05-08 Paul Eggert
dfa: assume C89 for CHAR_BIT
* src/dfa.c (CHARBITS): Remove. All uses replaced by CHAR_BIT.
(NOTCHAR): Now an enum, since it need not be a macro.
dfa: don't assume unsigned int is exactly 32 bits wide
Sun C 5.12 (sparc) warns of the potential unportability.
* src/dfa.c (charclass_word): New type, for clarity.
All relevant uses of 'unsigned' changed.
(CHARCLASS_WORD_BITS): Rename from INTBITS. All uses changed.
Now an enum, since it needn't be a macro.
(CHARCLASS_WORD_MASK): New macro.
(CHARCLASS_WORDS): Rename from CHARCLASS_INTS. All uses changed.
(setbit, clrbit): Cast 1 to charclass_word, for clarity.
(notset, add_utf8_anychar, dfastats):
Don't assume unsigned int is exactly 32 bits wide.
(dfastate): Don't rely on implementation-defined conversion of
greater-than-INT_MAX unsigned to int. Change bit test to resemble
tstbit more.
maint: fix indenting to pacify 'prohibit_tab_based_indentation'
* src/dfa.c: Use spaces and not tabs to indent some lines.
grep: simplify and clarify invert-related code
* src/grep.c (out_invert, prtext): Use bool for booleans.
(prline): Remove unnecessary '!!' on a value that is always 0 or 1.
(prtext): Remove last arg NLINESP; use !out_invert instead. All uses
changed. Move decls to nearer uses, since we can assume C99 here.
Update 'outleft' and 'after_last_match' here; it's simpler.
(grepbuf): Compute return value by subtracting new from old 'outleft',
rather than by keeping a separate running total. Avoid code duplication
by arranging for prtext to be called from one place, not three.
2014-05-08 Norihiro Tanaka
grep: improve performance of -v when combined with -L, -l or -q
Problem reported by Jörn Hees in: http://bugs.gnu.org/17427
* src/grep.c (grepbuf, grep): When -v is combined with -L, -l, or -q,
don't read data unnecessarily after a non-match is found.
2014-05-06 Paul Eggert
doc: mention performance changes
* NEWS: Discuss recent performance improvements and downgrades.
dfa: clarify use of "if"
The phrase "Y is true if X" is logically equivalent to "X implies Y",
but often "X if and only if Y" was intended.
* src/dfa.c, src/dfa.h: Reword to avoid the incorrect use of "if".
dfa: minor performance improvement for previous change
* src/dfa.c (struct dfa): New member 'fast'. Remove 'has_backref'.
All uses changed.
2014-05-06 Norihiro Tanaka
dfa: speed up 'dfaisfast'
* src/dfa.c (struct dfa): New member 'has_backref'.
(addtok_mb): Set it.
(dfaisfast): Use it.
2014-05-05 Paul Eggert
grep: fix -w match next to a multibyte letter
* NEWS: Document this.
* src/dfasearch.c, src/kwsearch.c (WCHAR): Remove.
(wordchar): New static function.
* src/dfasearch.c (EGexecute):
* src/kwsearch.c (Fexecute): Use the new functions, so that the
code works correctly if a multibyte character adjacent to the
match has two or more bytes.
* src/search.h, src/searchutils.c (mb_prev_wc, mb_next_wc):
New functions.
* tests/word-delim-multibyte: Add a test for grep -w (which now
passes), and a test for \> (which still fails). The \< test also
still fails.
grep: improve internal API for multibyte boundary
* src/search.h, src/searchutils.c (mb_goback): Rename from
is_mb_middle. Omit last arg. Return number of bytes to go back,
not just a boolean. All uses changed.
* src/dfasearch.c (EGexecute):
* src/kwsearch.c (Fexecute): Adjust to API change.
* src/kwsearch.c (Fexecute): Eliminate common subexpression.
grep: fix encoding-error incompatibilities among regex, DFA, KWset
This follows up to http://bugs.gnu.org/17376 and fixes a different
set of incompatibilities, namely between the regex matcher and the
other matchers, when the pattern contains encoding errors.
The GNU regex matcher is not consistent in this area: sometimes
an encoding error matches only itself, and sometimes it
matches part of a multibyte character. There is no documentation
for grep's behavior in this area and users don't seem to care,
and it's simpler to defer to the regex matcher for problematic
cases like these.
* NEWS: Document this.
* src/dfa.c (ctok): Remove. All uses removed.
(parse_bracket_exp, atom): Use BACKREF if a pattern contains
an encoding error, so that the matcher will revert to regex.
* src/dfasearch.c, src/grep.c, src/pcresearch.c, src/searchutils.c:
Don't include dfa.h, since search.h now does that for us.
* src/dfasearch.c (EGexecute):
* src/kwsearch.c (Fexecute): In a UTF-8 locale, there's no need to
worry about matching part of a multibyte character.
* src/grep.c (contains_encoding_error): New static function.
(main): Use it, so that grep -F is consistent with plain fgrep
when the pattern contains an encoding error.
* src/search.h: Include dfa.h, so that kwsearch.c can call using_utf8.
* src/searchutils.c (is_mb_middle): Remove UTF-8-specific code.
Callers now ensure that we are in a non-UTF-8 locale.
The code was clearly wrong, anyway.
* tests/fgrep-infloop, tests/invalid-multibyte-infloop:
* tests/prefix-of-multibyte:
Do not require that grep have a particular behavor for this test.
It's OK to match (exit status 0), not match (exit status 1), or
report an error (exit status 2), since the pattern contains an
encoding error and grep's behavior is not specified for such
patterns. Test only that KWset, DFA, and regex agree.
* tests/prefix-of-multibyte: Add tests for ABCABC and __..._ABCABC___.
2014-05-04 Paul Eggert
dfa: minor simplification
* src/dfa.c (parse_bracket_exp): Use enum, not macro, and move var
to just the scope it's needed.
grep: simplify and fix problems with KWset-DFA agreement patch
* src/dfa.c (dfambcache, parse_bracket_exp): Simplify.
(mbs_to_wchar, wctok, FETCH_WC, match_anychar, match_mb_charset)
(check_matching_with_multibyte_ops, transit_state_consume_1char)
(transit_state, dfaexec): Use wint_t, not wchar_t, so that
WEOF is treated correctly on platforms where WEOF is not a valid
wchar_t value.
(ctok, lex): Use int, not unsigned int, for characters,
so that EOF is treated more naturally.
(parse_bracket_exp): Use NOTCHAR to mark uninitialized char, since
FETCH_WC can now set the char to EOF.
(lex): Remove unnecessary test for EOF.
(parse_bracket_exp, atom): Swap then and else parts, to put
the small one first; this is more readable here.
* src/searchutils.c (is_mb_middle): Simplify.
tests: improve coverage for prefix-of-multibyte
* tests/prefix-of-multibyte: Also test the regex version.
2014-05-04 Norihiro Tanaka
grep: make KWset and DFA agree about invalid sequences in patterns
See: http://bugs.gnu.org/17376
* src/dfa.c (dfambcache): Don't cache invalid sequences, because they can't be
represented by wide characters.
(dfambcache, mbs_to_wchar): Return WEOF for invalid sequences.
(ctok): New global variable.
(parse_bracket_exp, atom, match_anychar, match_mb_charset): Don't allow WEOF.
(lex): Set 'ctok'.
* src/kwsearch.c (Fexecute):
* src/searchutils.c (is_mb_middle): Don't check here.
* tests/invalid-multibyte-infloop: Adjust to fixed behavior.
* tests/prefix-of-multibyte: Add test cases for this bug.
2014-05-03 Jim Meyering
maint: make ChangeLog generation more robust
* Makefile.am (gen-ChangeLog): Sync changes from GNU coreutils,
to ensure exit status is propagated, and to support an optional
git-log-fix file.
2014-05-03 Paul Eggert
grep: clarify EGexecute slightly
* src/dfasearch.c (EGexecute): Change if-then-else to !if-else-then.
2014-05-03 Norihiro Tanaka
grep: fix the bug in previous patch.
* src/dfasearch.c (EGexecute): Do it.
2014-04-30 Paul Eggert
grep: simplify EGexecute further
* src/dfa.c, src/dfa.h (dfasuperset): Arg is now const pointer.
Now pure.
* src/dfasearch.c (EGexecute): Coalesce some duplicate code.
Don't worry about memrchr returning NULL when that's impossible.
2014-04-30 Norihiro Tanaka
grep: adjust timing back to kwset when dfaisfast is true
* src/dfasearch.c (EGexecute): If DFA fails after kwset succeeds,
the code doesn't return to kwset until it reaches the end of the buffer
or finds a match. Because of this, although some cases speed up,
others slow down.
Adjust the heuristic for switching to the DFA, so that it
is more likely to switch at the right times.
2014-04-30 Norihiro Tanaka
grep: simplify superset
* src/dfa.h (dfahint): Remove decl.
(dfasuperset): New decl.
* src/dfa.c (dfahint): Remove.
(dfassbuild): Rename from dfasuperset.
(dfasuperset): New function. It returns the superset of D.
* src/dfasearch.c: Use dfasuperset instead of dfahint, and simplify.
dfa: optimize memory allocation
* src/dfa.c (epsclosure): get the value of 'visited' from the argument.
(dfaanalyze): Define and allocate variable 'visited'.
(dfastate): Use not 'insert' but 'merge' to insert positions for
state 0 of DFA.
2014-04-29 Norihiro Tanaka
kwset: improve performance by inlining tr
Without this change, older versions of GCC won't inline 'tr', and this
can hurt performance significantly. See: http://bugs.gnu.org/17229#64
* src/kwset.c (tr): Make it inline.
2014-04-27 Jim Meyering
gnulib: update to latest
* gnulib: This fixes a bug whereby running bootstrap
would remove our build-aux/git-log-fix file.
2014-04-27 Paul Eggert
kwset: improve performance by inlining more
Problem reported by Norihiro Tanaka in .
* src/kwset.c (bmexec_trans): Rename from bmexec, and make it inline.
(bmexec): New implementation, which calls bmexec_trans. This helps
GCC inline more aggressively with the default optimization, and
improves performance 25% with the reported benchmark on my host.
2014-04-26 Paul Eggert
kwset: speed up by using memchr2
Idea suggested by Eric Blake in: http://bugs.gnu.org/17229#43
* bootstrap.conf (gnulib_modules): Add memchr2.
* src/kwset.c: Include stdint.h, for uintptr_t. Include memchr2.h.
(struct kwset): New members gc1, gc2, gc1help.
(tr): Move earlier, so it can be used earlier.
(kwsprep): Initialize struct kwset's new members.
(memchr_kwset): Rename from memchr_trans. Combine C and TRANS args into
new arg KWSET. All uses changed. Use memchr2 when appropriate.
(bmexec): Use new members instead of recomputing their values.
Increase advance_heuristic; it's just a guess, but memchr2 probably
makes it reasonable to increase it.
kwset: improve performance when large Boyer-Moore key doesn't match
* src/kwset.c (bmexec): As a heuristic, prefer memchr to seeking
by delta1 only when the latter doesn't advance much.
dfa: fix index bug in previous patch, and simplify
* src/dfa.c, src/dfa.h (dfaisfast): Arg is const pointer.
* src/dfa.c (dfaisfast): Simplify, since supersets never contain BACKREF.
* src/dfa.h (dfaisfast): Declare to be pure.
* src/dfasearch.c (EGexecute): Fix typo that could cause buffer
read overrun when !dfafast. Hoist duplicate computation out
of an if's then and else parts.
2014-04-26 Norihiro Tanaka
grep: speed up for a case to repeat failure in DFA after success in kwset
A DFA is typically much faster if it is unibyte and does not set BACKREF.
Skip kwset if the DFA is fast. For example:
yes abcdabc | head -50000000 >k
env LC_ALL=C time -p src/grep -i 'abcd.bd' k
This improved real-time from 4.86 to 1.34 s.
* src/dfa.c, src/dfa.h (dfaisfast): New function.
* src/dfasearch.c (EGexecute): Use it.
2014-04-24 Paul Eggert
dfa: fix recently-introduced memory leak
Problem reported by Aharon Robbins in: http://bugs.gnu.org/17341
* src/dfa.c (dfasuperset): free after dfafree.
misc: fix doc and test bugs re grep -z
Problem reported by Stephane Chazelas in: http://bugs.gnu.org/16871
* doc/grep.texi (Usage): Remove incorrect example with -P.
* tests/pcre: Improve test so that it actually tests whether \s
matches a newline.
dfa: minor simplification of dfaexec
* src/dfa.c (dfaexec): Streamline updating of returned values.
Don't bother to check d->multibyte before updating mbp.
Avoid duplicate p > end test.
2014-04-24 Paul Eggert
dfa: simplify and be more consistent about MB_CUR_MAX
* src/dfa.c (struct dfa): New member 'multibyte',
replacing 'mb_cur_max'. All uses changed. Use this new member
consistently, instead of sometimes referring to MB_CUR_MAX directly.
dfa: fix comment
* src/dfa.c (maybe_realloc): Fix comment to match behavior better.
2014-04-24 Norihiro Tanaka
grep: skip checking of multibyte character boundary, reaching at eolbyte
* src/dfa.c (dfaexec): Skip checking of multibyte character boundary,
reaching at eolbyte.
2014-04-24 Paul Eggert
dfa: fix incorrect comment that led to heap overrun
* dfa.c (maybe_realloc): Fix comment to match behavior.
dfa: minor tuneup of dfamust memory savings patch
* src/dfa.c (allocmust): Use xmalloc, not xzalloc.
Initialize the must completely, so that the caller need not
invoke resetmust. All callers changed.
(dfamust): Omit asserts that aren't needed on typical machines
where dereferencing NULL dumps core. Don't leak memory if the
pattern contains a NUL byte.
2014-04-24 Norihiro Tanaka
grep: avoid wasting memory for large patterns in dfamust
* src/dfa.c (struct must): New member 'prev'. It points to the
previous must.
(allocmust): New function.
(freemust): New function.
(dfamust): Use it.
2014-04-24 Jim Meyering
grep: fix new heap write buffer overrun
* src/dfa.c (parse_bracket_exp): Fix off-by-one allocation error.
Exposed by running the tests with an ASAN-enabled binary (i.e.,
created using gcc's -fsanitize=address option). Introduced by
commit v2.18-70-gd3d9612, "dfa: simplify range char allocation".
2014-04-24 Paul Eggert
build: suppress unsafe-loop-optimizations warnings
I ran into one of these while trying out GCC 4.9.0's new
-fsanitize=undefined option. The warning told me that GCC didn't
do an unsafe optimization, but in 'grep' this is not typically a
symptom of a programming error.
* configure.ac (WERROR_CFLAGS): Suppress -Wunsafe-loop-optimizations.
2014-04-23 Paul Eggert
dfa: fix memory leak reintroduced by previous patch
Reported by Norihiro Tanaka in .
* src/dfa.c (dfaexec): Allocate mb_match_lens and mb_follows only
if not already allocated.
(free_mbdata): Null out mb_match_lens to mark it as being freed.
2014-04-23 Jim Meyering
tests: use consistent spelling for locale name, en_US.UTF-8
* tests/pcre-infloop: Spell locale name, en_US.UTF-8, consistently,
converting this one use from "en_US.utf8", which would provoke a
test failure on OS/X.
2014-04-23 Paul Eggert
dfa: omit static variables that limited dfaexec to one struct dfa
Problem reported by Aharon Robbins in: http://bugs.gnu.org/17328
* src/dfa.c (struct dfa): New member mbs.
mb_follows is now a position_set, not a pointer to one;
this simplifies memory allocation. All uses changed.
(mbs_to_wchar): Put DFA arg at the end, in place of the mbstate_t *arg,
since the DFA now contains an mbstate_t. All uses changed.
(mbs): Remove static variable.
(dfaexec): Remove static bool that attempted to optimize memory
allocation, as this wasn't correct for Gawk. Perhaps we can think
of a better way to optimize memory.
2014-04-22 Paul Eggert
kwset: simplify and speed up Boyer-Moore unibyte -i in some cases
This improves the performance of, for example,
yes jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj | head -10000000 | grep -i jk
in a unibyte locale.
* src/kwset.c (memchr_trans): New function.
(bmexec): Use it. Simplify the code and remove some of the
confusing gotos and breaks and labels. Do not treat glibc memchr
as a special case; if non-glibc memchr is slow, that is lower
priority and I suppose we can try to work around the problem in
gnulib.
2014-04-22 Norihiro Tanaka
grep: speed-up by using memchr() in Boyer-Moore searching
memchr() of glibc is faster than seeking by delta1 on some platforms.
When there is no chance to match for a while, use it on them.
* src/kwset.c (bmexec): Use memchr() in Boyer-Moore searching.
2014-04-22 Paul Eggert
kwset: simplify Boyer-Moore with unibyte -i
This change doesn't significantly affect performance on my platform,
and should make the code easier to maintain.
* src/kwset.c (BM_DELTA2_SEARCH, LAST_SHIFT, TRANS):
Remove these macros, in favor of ...
(tr, bm_delta2_search): New functions. All uses changed.
The latter function is inline because this improves code size and
runtime CPU slightly on x86-64 with gcc -O2 (GCC 4.9.0).
(bmexec): Prefer tr when that's simpler.
2014-04-22 Norihiro Tanaka
grep: may also use Boyer-Moore algorithm for case-insensitive matching
* src/kwset.c (BM_DELTA2_SEARCH, LAST_SHIFT, TRANS): New macro.
(bmexec): Use character translation table.
(kwsexec): Call bmexec for case-insensitive matching.
(kwsprep): Change the `if' condition.
2014-04-21 Paul Eggert
grep: -P now rejects invalid input sequences in UTF-8 locales
See and .
* NEWS: Document this.
* src/pcresearch.c (Pexecute): Do not use PCRE_NO_UTF8_CHECK,
as this leads to undefined behavior when the input is not UTF-8.
* tests/pcre-infloop, tests/pcre-invalid-utf8-input:
Exit status is now 2, not 1, when grep -P is given invalid UTF-8
data in a UTF-8 locale.
dfa: minor improvements to previous patch
* src/dfa.c (dfamust): Use &=, not if-then.
* src/dfa.h (struct dfamust):
* src/dfasearch.c (begline, hwsmusts): Use bool for boolean.
* src/dfasearch.c (kwsmusts):
* src/kwsearch.c (Fcompile): Prefer decls after statements.
* src/dfasearch.c (kwsmusts): Avoid conditional branch.
* src/kwsearch.c (Fcompile): Unify the two calls to kwsincr.
2014-04-21 Norihiro Tanaka
grep: speed-up for exact matching with begline and endline constraints.
dfamust turns on the flag when a state exactly matches the proposed one.
However, when the state has begline and/or endline constraints, turns
off it.
This patch enables to match a state exactly, even if the state has
begline and/or endline constraints. If a exact string has one of their
constrations, the string adding eolbyte to a head and/or foot is pushed
to kwsincr(). In addition, if it has begline constration, start
searching from just before the position of the text.
* src/dfa.c (variable must): New members `begline' and `endline'.
(dfamust): Consideration of begline and endline constrations.
* src/dfa.h (struct dfamust): New members `begline' and `endline'.
* src/dfasearch.c (kwsmusts): If a exact string has begline constration,
start searching from just before the position of the text.
(EGexecute): Same as above.
* src/kwsearch.c (Fexecute): Same as above.
2014-04-20 Paul Eggert
dfa: fix bug that caused NUL to be mishandled in patterns
This bug was introduced in the early-2012 patches that fixed some
context-handling bugs. Bisecting found commit
d8951d3f4e1bbd564809aa8e713d8333bda2f802 (2012-02-05 18:00:43 +0100),
but it apears the underlying problem was introduced in commit
8b47c4cf6556933f59226c234b0fe984f6c77dc7 (2012-01-03 11:22:09 +0100).
* NEWS: Mention bug fix.
* src/dfa.c (char_context): Consider NUL to be a newline only if -z.
* tests/Makefile.am (TESTS): Add null-byte.
* tests/null-byte: New file.
2014-04-19 Jim Meyering
build: reenable some compiler warning options
2014-04-18 Paul Eggert
dfa: fix pointer type conversion bug
The code converted between size_t * and ptrdiff_t *, which wasn't
diagnosed by modern x86-64 GCC but isn't portable. Problem
reported by Norihiro Tanaka in .
* configure.ac (WERROR_CFLAGS): Don't add -Wno-pointer-sign.
We want GCC to diagnose pointer signedness problems, as they
violate the C standard and other compilers no doubt complain too.
* src/dfa.c (struct dfa): Change type of salloc to size_t.
(realloc_trans_if_necessary): Convert signed value to size_t before
passing its address to x2nrealloc. Changing the type of tralloc
to size_t might have led to problems elsewhere.
2014-04-18 Jim Meyering
maint: Revert "dfa: avoid new NULL dereference"
This reverts commit 5190041fe515743ef4545abf287d243bc025c701.
It was only a bug if one neglected to update to the latest gnulib.
With the newer xn2realloc, there is no problem.
dfa: avoid new NULL dereference
* src/dfa.c (dfa_charclass_index): Restore a "+ 1" mistakenly omitted
during recent improvements. Introduced in v2.18-66-g6a60fd5.
2014-04-17 Paul Eggert
dfa: minor cleanup
* src/dfa.c (MAX): Remove; no longer used.
2014-04-17 Norihiro Tanaka
dfa: speed up by checking multibyte characters on demand
If dfaexec() runs in non-UTF8 locales, length and wide character
representation are checked for all characters of a line in a input
string. However, if matched early in the line, results for remaining
characters are wasted.
This patch checks multibyte characters on demand. It should work
faster for early matches, and reduces memory requirements.
* src/dfa.c (struct dfa): Remove members mblen_buf, nmblen_buf,
inputwcs, ninputwcs. All uses removed.
(buf_begin, buf_end, prepare_wc_buf): Remove. All uses removed.
(SKIP_REMAINS_MB_IF_INITIAL_STATE): Remove. This is now expanded
when used.
(match_anychar, match_mb_charset, check_matching_with_multibyte_ops):
New arg wc, mbclen. Remove arg idx. All uses changed.
(transit_state_consume_1char): New arg wc. All uses changed.
(transit_state): New arg 'end'. All uses changed.
2014-04-17 Paul Eggert
dfa: trans reallocation microoptimization
* src/dfa.c (realloc_trans_if_necessary):
Help the compiler avoid unnecessary reloads.
dfa: simplify dfmust initialization
* src/dfa.c (dfamust): Don't initialize musts twice.
Use zcalloc, not xmalloc followed by zeroing.
Make result a const pointer.
dfa: simplify freelist
* src/dfa.c (freelist): Don't null out array while freeing its
pointers; the caller can do that if needed.
(resetmust): Null out zeroth entry of array.
dfa: avoid duplicate strlen when allocating memory
* src/dfa.c (dfamust): Use xstrdup, not strlen (twice) + xmemdup.
dfa: simplify memory allocation
* src/dfa.c (icatalloc, freelist, enlist, comsubs, addlists, inboth)
(dfamust): Don't worry about null arguments or results,
as memory allocators no longer can return null pointers.
(dfamust): Invoke malloc just once when building a concatenated string.
dfa: simplify position set and element count allocation
* src/dfa.c (dfaanalyze): Allocation position set info all at one go,
and similarly for element count info.
dfa: simplify multibyte_prop allocation
* src/dfa.c (struct dfa): Simplify by removing nmultibyte_prop;
it should always be the same as talloc. All uses changed.
dfa: simplify range char allocation
* src/dfa.c (struct dfa): Simplify by allocating one array of ranges
rather than one for range starts and another for range ends.
All uses changed.
dfa: simplify transition table allocation
* src/dfa.c (struct dfa): Remove member 'realtrans', as it can
be computed from 'trans'. All uses changed.
(realloc_trans_if_necessary): Move earlier, to avoid a forward decl.
Use x2nrealloc to compute new size, rather than doing it by hand,
which omits a check for unlikely overflow.
(realloc_trans_if_necessary, dfafree): Adjust to the fact that
d->trans now might be either NULL, or 1 + the pointer to free.
(build_state, build_state_zero): Use realloc_trans_if_necessary
instead of duplicating its code.
dfa: better size-overflow check
* src/dfa.c (dfasuperset): Let xnmalloc do the multiplication,
to check for size arithmetic overflow better.
dfa: avoid unnecessary work and other initialization
* src/dfa.c (dfaanalyze, dfainit):
Don't bother allocating when x2nrealloc will do it for us.
(dfastate): Allocate grps and labels on the stack, as their
size is known at compile time.
(build_state): Use xmalloc, not xnmalloc, since the multiplication
can be done at compile-time.
dfa: clarify memory allocation and port to IRIX
This change was prompted by a porting problem:
IRIX defines its own MALLOC macro, which clashes with ours.
More generally, the MALLOC etc. macros are confusing, as they
look like functions but do not have C-function semantics.
A functional style makes the code easier to read, and though
it lengthens the code a bit here it'll make other
simplifications easier.
* src/dfa.c (XNMALLOC, XCALLOC, CALLOC, MALLOC, REALLOC): Remove.
All uses replaced by xnmalloc etc.
(REALLOC_IF_NECESSARY): Remove; all uses replaced by ....
(maybe_realloc): New function.
(copy, merge): Free and allocate rather than realloc, as we
needn't save the contents.
2014-04-14 Jim Meyering
tests: detect an infloop-inducing bug in grep -P (pcre-8.35)
* tests/pcre-infloop: New test.
* tests/Makefile.am (TESTS): Add it.
2014-04-12 Paul Eggert
build: update gnulib submodule to latest
2014-04-11 Paul Eggert
grep: improvements for the open-CSET patch
* src/dfa.c (dfamust): Simplify by removing some duplicate code.
Optimize patterns like [aaa] even when not case-folding.
Avoid an unnecessary copy of the charclass.
2014-04-11 Norihiro Tanaka
grep: open CSET and transform into uppercase when MB_CUR_MAX == 1
In unibyte locales with -i, kwset matching isn't helpful, because
dfamust doesn't extract the CSET entries. Fix dmamust so that it
does that, and makes it possible to take out a longer fixed string
from tokens.
* src/dfa.c (dfamust): open CSET and transform into uppercase
when MB_CUR_MAX == 1.
2014-04-11 Paul Eggert
grep: cleanup for HAS_DOS_FILE_CONTENTS issue
While cleaning up the empty-string fix, I noticed that one part of
the code worried about CRLF in pattern files whereas another part
did not. Fix this by using the same approach in both places,
and make the CRLF code more modular in the process.
* src/dosbuf.c (dos_binary, dos_unix_byte_offsets): New functions.
(undossify_input, dossified_pos): Do nothing if ! O_BINARY.
* src/grep.c: Always include dosbuf.c so that the code is
checked statically even on non-DOS hosts.
(dos_binary, dos_unix_byte_offsets): New decls.
(undossify_input): Declare unconditionally.
* src/grep.c (fillbuf, print_line_head, main):
* src/kwsearch.c (Fcompile):
Simplify by not worrying about HAVE_DOS_FILE_CONTENTS.
* src/grep.c (main): fopen with "rt" if O_TEXT; this is simpler
than worrying about HAVE_DOS_FILE_CONTENTS elsewhere.
* src/system.h (HAVE_DOS_FILE_CONTENTS): Remove.
grep: cleanup for empty-string fix
* NEWS: Document it.
* src/dfasearch.c (GEAcompile):
* src/kwsearch.c (Fcompile):
Use C99-style decls to simplify. Avoid duplicate code.
* tests/empty-line: Add some more tests like this.
2014-04-11 Norihiro Tanaka
grep: no match for the empty string included in multiple patterns
* src/dfasearch.c (EGAcompile): Fix it.
* src/kwsearch.c (Fcompile): Fix it.
2014-04-08 Paul Eggert
grep: remove bool_bf
The extra complexity of this microoptimization wasn't ever much help,
and currently it generated bigger code with gcc -O2 (x86-64).
* src/dfa.c (bool_bf): Remove. All uses replaced by plain 'bool',
without a bitfield.
2014-04-08 Jim Meyering
maint: avoid sc_po_check syntax-check failure (kwset.c)
* po/POTFILES.in: Remove kwset.c from this list, since it
no longer contains a translatable diagnostic.
2014-04-08 Paul Eggert
grep: port better to hosts with nonstandard nl_langinfo
On some hosts, nl_langinfo returns strings other than "UTF-8" when
UTF-8 is used, and (worse) return "UTF-8" even if the encoding is
single-byte. Work around these problems by trying a sample
character instead.
* src/dfa.c, src/pcresearch.c, src/searchutils.c:
Don't include .
* src/dfa.c (using_utf8): Test for UTF-8 by trying a character
rather than by invoking nl_langinfo (CODESET); this is more
portable in practice, and removes a dependency on
HAVE_LANGINFO_CODESET.
* src/pcresearch.c: Include dfa.h, for using_utf8.
(Pcompile): Use using_utf8 rather than nl_langinfo.
2014-04-07 Paul Eggert
grep: prefer bool in DFA internals
* src/dfa.c (bool_bf): New type.
(dfa_state): Use it, as this seems to generate slightly better
code with GCC.
(struct mb_char_classes, struct dfa, equal, case_fold, dfasyntax)
(laststart, parse_bracket_exp, lex, dfaparse, dfaanalyze, dfastate)
(match_mb_charset, dfamust):
Use bool for boolean.
(using_utf8) [!HAVE_LANGINFO_CODESET]: Tune.
(dfaanalyze): Prefer & to && and | to || on booleans; it's simpler here.
(dfastate): Simplify charclass nonzero testing. Redo has_mbcset
test so that the compiler's more likely to optimize it.
2014-04-07 Norihiro Tanaka
grep: prefer regex to DFA for ANYCHAR in multibyte locales
* src/dfa.c (dfa_state): New member has_mbcset.
Rename backref to has_backref, and make it of type bool too.
All uses changed.
(state_index, dfastate): Initialize new member.
(dfaexec): Prefer regex to DFA for ANYCHAR in multibyte locales.
2014-04-07 Paul Eggert
grep: remove trival_case_ignore
This optimization is no longer needed, given the other
optimizations recently installed. Derived from a patch by
Norihiro Tanaka; see .
* bootstrap.conf (gnulib_modules): Remove assert-h.
* src/dfa.c (CASE_FOLDED_BUFSIZE): Move here from dfa.h.
Remove now-unnecessary static assert.
(case_folded_counterparts): Now static.
* src/dfa.h (CASE_FOLDED_BUFSIZE, case_folded_counterparts):
Remove decls; no longer public.
* src/dfasearch.c (kwsmusts): Use kwset even if fill MB_CUR_MAX > 1
and case-insensitive.
* src/grep.c (MBRTOWC, WCRTOMB): Remove.
(fgrep_to_grep_pattern): Use mbrtowc, not MBRTOWC.
(trivial_case_ignore): Remove; this optimization is no longer needed.
All uses removed.
grep: simplify memory allocation in kwset
* src/kwset.c: Include kwset.h first, to check its prereqs.
Include xalloc.h, for xmalloc.
(kwsalloc): Use xmalloc, not malloc, so that the caller need not
worry about memory allocation failure.
(kwsalloc, kwsincr, kwsprep): Do not worry about obstack_alloc
returning NULL, as that's not possible.
(kwsalloc, kwsincr, kwsprep, bmexec, cwexec, kwsexec, kwsfree):
Omit unnecessary conversion between struct kwset * and kwset_t.
(kwsincr, kwsprep): Return void since memory-allocation failure is
not possible now. All uses changed.
* src/kwset.h: Include , for size_t, so that this
include file doesn't require other files to be included first.
grep: minor cleanups for Galil speedups
* src/kwset.c: Update citations.
Include stdbool.h.
(kwsincr, kwsprep): Clarify by using C99 decls after statements.
(kwsprep): Clarify by using MIN. Avoid a couple of buffer copies
when !TRANS.
(bmexec): Use bool for boolean. Prefer "continue;" to ";".
2014-04-07 Norihiro Tanaka
grep: use the Galil rule for Boyer-Moore algorithm in KWSet
The Boyer-Moore algorithm is O(m*n), which means it may be much
slower than the DFA. Its Galil rule variant is O(n) and increases
efficiency in the typical case; it skips sections that are known
to match and does not compare more than once for a position in the text.
To use the Galil rule, look for the delta2 shift at each position
from the trie instead of the 'mind2' value.
* src/kwset.c (struct kwset): Replace member 'mind2' with 'shift'.
(kwsprep): Look for the delta2 shift.
(bmexec): Use it.
2014-04-06 Paul Eggert
grep: cleanup DFA superset optimization
* src/dfa.c (dfa_charclass_index): New function, with body of
old dfa_charclass but with an extra parameter D.
(charclass_index): Reimplement in terms of dfa_charclass_index.
(dfahint): Clarify.
(dfasuperset): Do not assign to 'dfa' static variable. Instead,
use a local, and use the new dfa_charclass_index function. This
doesn't fix any bugs, but it's clearer. Initialize a few more
members, to simplify dfafree. Copy the charclasses with
just one memcpy call. Don't assign nonnull to D->superset until
it's known to be valid; that's simpler.
(dfafree, dfaalloc): Simplify based on dfasuperset initializations.
* src/dfa.h (dfahint): Add comment.
* src/dfasearch.c (EGexecute): Simplify use of memchr.
Simplify by using memrchr. Fix typo that could cause a buffer
read overrun.
2014-04-06 Norihiro Tanaka
grep: optimization with the superset of DFA
The superset of a DFA is like the DFA, except that for speed
ANYCHAR, MBCSET and BACKREF are replaced by (CSET full bits) STAR,
and mb_cur_max is 1. For example, for 'a\(b\)c\1':
original: a b CAT c CAT BACKREF CAT
superset: a b CAT c CAT CSET STAR CAT (The CSET has all bits set.)
If a string matches a DFA, it matches the DFA's superset.
Using the superset to filter can dramatically improve performance,
over 200x in some cases. See .
* src/dfa.c (struct dfa): New member 'superset'.
(dfahint, dfasuperset): New functions.
(dfacomp): Create and analyze the superset.
(dfafree): Free only non-NULL items.
(dfaalloc): Initialize superset member.
(dfaoptimize): If succeed in optimization for UTF-8 locale, don't use
the superset.
* src/dfa.h (dfahint): New decl.
* src/dfasearch.c (EGexecute): Use dfahint.
2014-04-06 Jim Meyering
build: avoid OS X 10.8.5 build failure due to lack of static_assert
* bootstrap.conf (gnulib_modules): Add assert-h, to accommodate the
new use of static_assert on systems lacking support for that construct.
Without this change, compilation of dfa.c failed on OS X 10.8.5 with
gcc-4.9.0 20140324. We should be using gnulib's assert-h module,
regardless, for its nominal improved portability, since grep includes
assert.h and uses assert.
2014-04-05 Norihiro Tanaka
grep: fix performance bug with regex in line-by-line mode
* src/dfasearch.c (EGexecute): Match line-by-line with regex.
2014-04-05 Paul Eggert
grep: minor improvements to previous patch
* src/dfa.c (MAX): New macro.
(match_anychar, match_mb_charset, transit_state_consume_1char):
Use it to simplify assignments.
(SKIP_REMAINS_MB_IF_INITIAL_STATE): Prefer != 0 for unsigned.
(free_mbdata): Omit an unnecessary 'free'.
2014-04-05 Norihiro Tanaka
grep: reuse multibyte DFA buffers in non-UTF8 locales
* src/dfa.c (struct dfa): New members 'mblen_buf', 'nmblen_buf',
'inputwcs', 'ninputwcs', 'mb_follows' and 'mb_match_lens'.
(mblen_buf, inputwcs): Remove static vars.
(SKIP_REMAINS_MB_IF_INITIAL_STATE, match_anychar, match_mb_charset)
(transit_state_consume_1char, transit_state, prepare_wc_buf):
Use new members instead of global variables.
(check_matching_with_multibyte_ops): Use new members
instead of new allocation.
(dfaexec): Initialize new members.
(free_mbdata): Free new members.
2014-04-05 Paul Eggert
grep: simplify dfa.c by having it not include mbsupport.h directly
* src/mbsupport.h: Remove.
* src/Makefile.am (noinst_HEADERS): Remove mbsupport.h.
* src/dfa.c, src/grep.c, src/search.h: Don't include mbsupport.h.
* src/dfa.c: Include wchar.h and wctype.h unconditionally, as
this simplifies the use of dfa.c in grep, and it does no harm
in gawk.
(setlocale, static_assert): Remove gawk-specific hacks, as
gawk now does these itself.
(struct dfa, dfambcache, mbs_to_wchar)
(is_valid_unibyte_character, setbit_wc, using_utf8, FETCH_WC)
(addtok_wc, add_utf8_anychar, atom, state_index, epsclosure)
(dfaanalyze, dfastate, prepare_wc_buf, dfaoptimize, dfafree, dfamust):
* src/dfasearch.c (EGexecute):
* src/grep.c (main):
* src/searchutils.c (mbtoupper):
Assume MBS_SUPPORT.
2014-04-01 Norihiro Tanaka
dfa: avoid re-building a state built previously
* src/dfa.c (dfaexec): Avoid to re-build a state built previously.
2014-03-28 Paul Eggert
dfa: improve port to freestanding DJGPP
Suggested by Aharon Robbins (Bug#17056).
* src/dfa.c (setlocale) [!LC_ALL]: Return NULL, not "C",
reverting part of a recent change.
(using_simple_locale): Return true if setlocale returns null.
2014-03-28 Jim Meyering
tests: placate "make syntax-check" re compare arg ordering
* tests/euc-mb: Reverse order of arguments to compare.
Be consistent in ordering compare arguments: expected followed
by actual.
2014-03-28 Paul Eggert
dfa: avoid an indirection and port wint_t usage
* src/dfa.c (struct dfa): Put mbrtowc_cache directly into struct dfa
rather than having a pointer; this saves a malloc and an indirection.
All uses changed.
(dfambcache): Port to hosts where wint_t * can't be cast to wchar_t *.
2014-03-28 Norihiro Tanaka
grep: take mbrtowc_cache into new member of struct dfa
When struct dfa more than one are used at the same time, mbrtowc cache
may be conflict. So, take mbrtowc_cache into new member of struct dfa,
and define each mbrtowc cache for them.
* src/dfa.c (struct dfa): New member `mbrtowc_cache'.
(dfambcache): Rename from build_mbrtowc_cache. Add dependency on struct dfa.
(mbs_to_wchar): Add dependency on struct dfa.
(FETCH_WC): Use it.
(prepare_wc_buf): Use it. Add dependency on struct dfa.
(dfacomp): Call it.
(dfafree): Release it.
2014-03-28 Paul Eggert
dfa: cache results of mbrtowc for speed
Idea suggested by Norihiro Tanaka in Bug#16842.
* src/dfa.c (mbrtowc_cache): New static var.
(build_mbrtowc_cache, mbs_to_wchar): New functions.
(FETCH_WC) [MBS_SUPPORT]: Speed up by using mbs_to_wchar
instead of mbrtowc and wctob.
(FETCH_WC) [!MBS_SUPPORT]: Rewrite in terms of old FETCH macro.
(FETCH): Remove; no longer used.
(lex): Simplify by avoiding the need for FETCH.
(prepare_wc_buf) [MBS_SUPPORT]: Speed up by using mbs_to_wchar.
Simplify the loop.
(dfacomp): Initialize the cache.
2014-03-27 Norihiro Tanaka
grep: perform the kwset-helping DFA match in narrower range
When kwsexec gives us the offset of a potential match, we compute
line begin/end and then run the DFA matcher to see if there really
is a match on that line. When the beginning of the line, BEG, is
not on a multibyte character boundary, advance BEG until it on such
a boundary, before running the DFA search.
* src/dfasearch.c (EGexecute): As above. Add a comment.
* tests/euc-mb: Add a test case that exercises this code.
This addresses http://debbugs.gnu.org/17095.
2014-03-26 Jim Meyering
maint: fix "make dist"
* src/Makefile.am (egrep fgrep): Specify egrep.sh via
$(srcdir)/egrep.sh, so non-srcdir builds work once again.
2014-03-26 Paul Eggert
dfa: improve port to freestanding DJGPP
* src/dfa.c (setlocale) [!LC_ALL]: Return "C", not NULL (Bug#17056).
(using_simple_locale): Store setlocale result in a ptr-to-const.
egrep, fgrep: improve diagnostics from shell scripts
This should fix Bug#17098.
* src/Makefile.am (EXTRA_DIST): Add egrep.sh.
(egrep fgrep): Depend on egrep.sh and Makefile.
Build from new file egrep.sh, as this makes the build process
easier to follow. Arrange for $0 to look nicer in subgrep.
* src/egrep.sh: New file.
2014-03-23 Paul Eggert
dfa: avoid undefined behavior
* src/dfa.c (FETCH_WC, addtok_wc): Don't rely on undefined behavior
when converting an out-of-range value to 'int'.
(FETCH_WC, prepare_wc_buf): Don't rely on conversion state after
mbrtowc returns a special value, as it's undefined for (size_t) -1.
(prepare_wc_buf): Simplify test for valid character.
grep: fix and simplify grep -iF optimization
* src/grep.c (check_any_alphabets): Remove.
(fgrep_to_grep_pattern): Fix problems when mbrtowc returns -1 or -2.
Simplify a bit.
(main): Don't bother optimizing 'grep -iF PAT' when PAT contains no
alphabetics; it's so rare it's not worth the complexity.
2014-03-23 Norihiro Tanaka
grep: optimization for fgrep with changing the macher to grep macher.
fgrep macher is only use kwset engine. However, it's very slow for
case-insensitive matching in multibyte locales.
And so, if the matcher is fgrep and case-insensitive and keys including
any alphabets, change it into grep matcher by escape of keys. OTOH, if
keys include no alphabet, turn match_icase flag off.
I prepare following string to measure the performance.
yes $(printf '%078dm' 0)| head -1000000 | tr 0 a > in
A=`printf '\xef\xbc\xa1'` # FULLWIDTH LATIN CAPITAL LETTER A
I run three tests with this patch (best-of-5 trials):
env LC_ALL=en_US.UTF-8 time -p src/fgrep -i "$A" in
real 8.54 user 7.13 sys 1.16
Back out that commit (temporarily), recompile, and rerun the experiment:
env LC_ALL=en_US.UTF-8 time -p src/fgrep -i "$A" in
real 0.07 user 0.02 sys 0.05
* src/fgrep.c (Gcompile) New function.
* src/main.c (check_any_alphabets) New function.
(fgrep_to_grep_pattern) New function.
(main) Use them.
2014-03-23 Paul Eggert
egrep, fgrep: go back to shell scripts
Although egrep's and fgrep's switch from shell scripts to
executables may have made sense in 2005, it complicated
maintenance and recently has caused subtle performance bugs.
Go back to the old way of doing things, as it's simpler and more
easily separated from the mainstream implementation. This should
be good enough nowadays, as POSIX has withdrawn egrep/fgrep and
portable applications should be using -E/-F anyway.
* po/POTFILES.in: Remove src/egrep.c, src/fgrep.c, src/main.c.
* src/Makefile.am (bin_PROGRAMS): Remove egrep, fgrep.
(bin_SCRIPTS): New macro.
(grep_SOURCES): Move searchutils.c, dfa.c, dfasearch.c, kwset.c,
kwsearch.c, pcresearch.c here from libgrep_a_SOURCES.
(egrep_SOURCES, fgrep_SOURCES, noinst_LIBRARIES, libgrep_a_SOURCES):
Remove.
(LDADD): Remove libgrep.a.
(egrep, fgrep): New rules.
(CLEANFILES): New macro.
* src/grep.c: Rename from src/main.c.
(usage, setmatcher, main):
Simplify, since there's now just one executable.
(Gcompile, Ecompile, Acompile, GAcompile, PAcompile, matchers):
Move here from the (removed) src/grep.c.
(compile_fp_t, execute_fp_t, struct matcher, matchers):
Move here from src/grep.h, as they no longer need to be public.
(struct matcher.name): Avoid one level of indirection/relocation.
(do_execute, main): Fix a performance bug when it was compiled
as 'fgrep', due to confusion about which matcher was which.
(main): Fix a performance bug with -P, likewise.
* src/grep.h (before_options, after_options): Remove.
* src/egrep.c, src/fgrep.c, src/grep.c: Remove.
dfa: port to freestanding DJGPP (Bug#17056)
* src/dfa.c (setlocale) [!LC_ALL]: Define a dummy.
2014-03-16 Jim Meyering
tests: avoid false-positive failure on some AMD CPUs
* tests/mb-non-UTF8-performance: Avoid false-positive failure
when run on certain AMD processors.
2014-03-10 Jim Meyering
tests: make a performance-measuring test less system-sensitive
Andreas Schwab reported in http://debbugs.gnu.org/16941
that this test would timeout and fail on m68k-suse-linux.
Rather than testing absolute duration with a limit tuned
to today's hardware, compare performance of grep with LC_ALL=C
against that same command using LC_ALL=ja_JP.eucJP.
* tests/init.cfg (require_hi_res_time_): New function.
* tests/mb-non-UTF8-performance: Rewrite to use it:
record absolute duration D of the first (normally much faster)
command, and set a timeout of 8*D for the command running in
an affected locale.
2014-03-09 Paul Eggert
maint: pacify 'make dist'
* src/dfa.c (parse_bracket_exp): Reindent with spaces.
* src/dfa.h (case_folded_counterparts): Prefix decl with 'extern'.
* src/main.c: Don't include assert.h.
2014-03-07 Paul Eggert
fgrep: fix case-fold incompatibility with plain 'grep'
fgrep converted to lowercase, whereas the regex code converted
to uppercase. The resulting behaviors don't agree in offbeat
cases like Greek sigmas and Turkish Is. Fix this by changing
fgrep to agree with the regex code.
* src/kwsearch.c (Fcompile, Fexecute):
* src/searchutils.c (kwsinit, mbtoupper):
Convert to uppercase, not to lowercase, for compatibility with
plain 'grep'.
* src/search.h, src/searchutils.c (mbtoupper):
Rename from mbtolower, since it now converts to uppercase.
All uses changed.
* tests/case-fold-titlecase: Add tests for this.
grep: fix case-fold mismatches between DFA and regex
The DFA code and the regex code didn't use the same semantics for
case-folding. The regex code says that the data char d matches
the pattern char p if uc (d) == uc (p). POSIX is unclear in this
area; the simplest fix for now is to change the DFA code to agree
with the regex code. See .
* src/dfa.c (static_assert): New macro, if not already defined.
(setbit_case_fold_c): Assume MB_CUR_MAX is 1 and that case_fold
is nonzero; all callers changed.
(setbit_case_fold_c, parse_bracket_exp, lex, atom):
Case-fold like the regex code does.
(lonesome_lower): New constant.
(case_folded_counterparts): New function.
(parse_bracket_exp): Prefer plain setbit when case-folding is
not needed.
* src/dfa.h (CASE_FOLDED_BUFSIZE): New constant.
(case_folded_counterparts): New function decl.
* src/main.c (trivial_case_ignore): Case-fold like the regex code does.
(main): Try to improve comment re trivial_case_ignore.
* tests/case-fold-titlecase: Add lots more test cases.
2014-03-06 Paul Eggert
build: update gnulib submodule to latest
doc: do not overpromise --ignore-case's behavior
* NEWS: Omit vague statement about titlecase that could be
misinterpreted, and is more trouble than it's worth.
* doc/grep.texi: Add @documentencoding. Fix copyright range to
use endash not hyphen.
(Matching Control): Do not overpromise what --ignore-case will do.
Give examples of corner cases where the documentation does not
specify behavior.
2014-03-05 Paul Eggert
maint: remove differences from gnulib regex code
These don't seem to be needed with GCC 4.8.2, and are making
maintenance harder. If we need to disable warnings with older
compilers, we can add pragmas to the gnulib versions. See
.
* gl/lib/regcomp.c.diff, gl/lib/regex_internal.c.diff:
* gl/lib/regex_internal.h.diff, gl/lib/regexec.c.diff:
Remove.
* cfg.mk (exclude_file_name_regexp--sc_prohibit_tab_based_indentation):
Don't mention gl/* files.
2014-03-03 Paul Eggert
grep: fix comment
* src/main.c (trivial_case_ignore): Fix comment typo.
2014-03-03 Norihiro Tanaka
grep: avoid to add same character to a bracket expression
* src/main.c (trivial_ignore_case): Only when uppercase and/or
lowercase is different from original character, add it to new pattern.
2014-03-02 Paul Eggert
grep: fix some unlikely bugs in trivial_case_ignore
* src/main.c (MBRTOWC, WCRTOMB): Reformat as per usual GNU style.
(trivial_case_ignore): Don't overrun buffer in the unusual case
when a character has both lowercase and uppercase counterparts.
Don't rely on undefined behavior when assigning out-of-range value
to an 'int'. Simplify by avoiding unnecessary buffer copies.
Work even with shift encodings, by using mbsinit to
disable the optimization if we are not in the initial state
when we replace B by [BCD].
2014-03-02 Norihiro Tanaka
grep: revert removal of trivial_case_ignore
Revive trivial_case_ignore function in order to be able to use kwset.
* src/main.c (MBRTOWC, WCRTOMB): New macros.
(trivial_case_ignore): New function.
(main): Use it.
2014-03-02 Norihiro Tanaka
grep: optimization of bracket expression for non-UTF8 locales
* src/dfa.c (addtok): Replace an MBCSET with a CSET even in
non-UTF8 locales, and even when it has individual characters.
2014-03-01 Paul Eggert
doc: describe titlecase fix better
* NEWS: Document behavior on lowercase text too.
Suggested by Eric Blake in .
* doc/grep.texi (Matching Control): Specify behavior of -i
more precisely.
2014-02-28 Paul Eggert
grep: minor tuning for mb_case_map_apply
* src/kwsearch.c (mb_case_map_apply): Avoid unnecessary widening of
size_t to intmax_t. Avoid unnecessary reinitialization of k.
grep: avoid 'inline' when it doesn't matter
These days, compilers generally do just fine without advice from
users about 'inline', and there's little need for 'static inline',
just as there's little need for 'register'.
* src/dfa.c (to_uchar):
* src/dosbuf.c (guess_type, undossify_input, dossified_pos):
* src/main.c (undossify_input):
No longer inline.
* src/search.h (mb_case_map_apply): Move from here ...
* src/kwsearch.c (mb_case_map_apply): ... to here, and
make it no longer 'inline'.
grep: fix bugs with -i and titlecase
* NEWS: Document this.
* src/dfa.c (setbit_wc): Simplify.
(setbit_c): Remove; no longer used.
(setbit_case_fold_c, parse_bracket_exp, atom):
Don't mishandle titlecase. For 'atom', this removes the need for
the refactoring of Bug#16729.
(lex): Use the slower approach only for letters that have a
differing case.
* tests/case-fold-titlecase: New file.
* tests/Makefile.am (TESTS): Add it.
grep: remove lint
* src/main.c (MBRTOWC, WCRTOMB): Remove no-longer-used macros.
2014-02-28 Norihiro Tanaka
grep: remove trivial_case_ignore
* src/main.c (trivial_case_ignore): Remove.
(main): Remove its use; this optimization is no longer needed.
grep: don't match line-by-line for case-insensitive with grep and awk
* src/main.c (matcher): Move decl up.
(do_execute): With the grep or awk matchers,
no need to match line by line.
2014-02-27 Jim Meyering
maint: dfa: pass NULL, not 0, as 2nd arg to setlocale
* src/dfa.c (using_simple_locale): Use NULL, not 0.
2014-02-27 Paul Eggert
* src/dfa.c (prednames): POSIX allows [[:xdigit:]] to match multibyte chars.
* src/dfa.c (parse_bracket_exp): Parenthesize.
grep: fix multiple bugs with bracket expressions
* NEWS: Document this.
* src/dfa.c (using_simple_locale): New function.
(parse_bracket_exp): Handle bracket expressions like [a-[.z.]]
correctly. Don't assume that dfaexec handles expressions like
[^a-z] correctly, as they can match multiple characters in some
locales.
* tests/posix-bracket: New file.
* tests/Makefile.am (TESTS): Add it.
2014-02-25 Stephane Chazelas
align grep -Pw with grep -w
For the -w option, with -P, we used to look for the pattern surrounded by
word boundaries. That's different from what grep -w does and what the
documentation describes. Now align with grep -w and the documentation by
using PCRE look-behind and look-ahead operators to match the pattern if
it is not surrounded by word constituents.
* src/pcresearch.c (Pcompile): Use (?
grep -P: fix it so backreferences now work with -w and -x
To implement -w and -x, we bracket the search term with parentheses.
However, that set of parentheses had the default semantics of
"capturing", i.e., creating a backreferenceable matched quantity.
Instead, use (?:...), to create a non-capturing group.
* src/pcresearch.c (Pcompile): Use (?:...) rather than (...).
* NEWS (Bug fixes): Mention it.
* tests/pcre-wx-backref: New file.
* tests/Makefile.am (TESTS): Add it.
This addresses http://debbugs.gnu.org/16865
2014-02-20 Jim Meyering
maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
version 2.18
* NEWS: Record release date.
tests: test for the non-UTF8 multi-byte performance regression
Test for the just-fixed performance regression.
With a 100-200x differential, it is reasonable to expect that
a very slow system will be able to complete the designated
task in a few seconds, while with the bug, even a very fast
system would exceed the timeout.
* tests/mb-non-UTF8-performance: New file.
* tests/Makefile.am (TESTS): Add it.
* tests/init.cfg (require_JP_EUC_locale_): New function.
grep -i: avoid a performance regression in multibyte non-UTF8 locales
* src/main.c: Include dfa.h.
(trivial_case_ignore): Perform this optimization only for UTF8 locales.
This rectifies a 100-200x performance regression in non-UTF8 multi-byte
locales like ja_JP.eucJP. The regression was introduced by the 10x
UTF8/grep-i speedup, commit v2.16-4-g97318f5.
* NEWS (Bug fixes): Mention it.
Reported by Norihiro Tanaka in http://debbugs.gnu.org/16232#50
maint: give dfa.c's using_utf8 function external scope
* src/dfa.c (using_utf8): Remove "static inline".
* src/dfa.h (using_utf8): Declare it.
* src/searchutils.c (is_mb_middle): Use using_utf8 rather than
rolling our own.
2014-02-20 Paul Eggert
tests: test [^^-^] in unibyte locales
This is a bug in the current dfa.c, which was reintroduced by the
recent reversion from RRI.
* tests/unibyte-negated-circumflex: New file.
* tests/Makefile.am (TESTS): Add it.
* tests/init.cfg (require_unibyte_locale): New function.
grep: fix bug with patterns like [^^-~] in unibyte locales
* NEWS: Document this.
* src/dfa.c (parse_bracket_exp): Escape patterns like [^^-~], or
Awk patterns like [\^-\]], so that they are not misinterpreted by
the system regex library. Check for system regex failure due to
memory exhaustion.
2014-02-17 Jim Meyering
maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
version 2.17
* NEWS: Record release date.
2014-02-17 Paolo Bonzini
revert "grep: DFA now uses rational ranges in unibyte locales"
The correct course of action for grep is to defer range interpretation
to regex, because otherwise you can get mismatches between regexes with
backreferences and those without.
For example, [A-Z]. will use RRI but ([A-Z])\1 won't, with the confusing
result that the first regex won't match a superset of the language
described by the second regex.
The source of the confusion is that, even though grep's dfa.c was changed
to use range checking instead of strcoll, that code is only invoked if
dfaexec is called with backref = NULL, and that never happens for grep!
In the end, all that's needed for RRI is compiling --with-included-regex,
and in that case the patch is almost a no-op. Almost, because there
are corner cases that aren't handled correctly (e.g. [a-[.e.]], or
regular expressions that include a NUL character), but this can be
handled separately.
* NEWS: Revert paragraph introduced by commit v2.16-7-g1078b64.
* src/dfa.c (parse_bracket_exp): Revert back to regcomp/regexec.
2014-02-16 Mike Frysinger
maint: ignore configure.lineno
* .gitignore: Add configure.lineno.
2014-02-11 Benno Schulenberg
help: remove surplus newline
* src/main.c (usage): Remove inconsistent \n introduced by previous
patch.
2014-02-10 Benno Schulenberg
help: fix a line ending, and use the same word for similar things
* src/main.c (usage): Change a stray 'n' to a newline, and use
the word "display" for showing version info as for help text.
2014-02-09 Norihiro Tanaka
speed up mb-boundary-detection after each preliminary match
After each kwsexec or dfaexec match, we must determine whether
the tentative match falls in the middle of a multi-byte character.
That is what our is_mb_middle function does, but it was expensive,
even when most input consisted of single-byte characters. The main
cost was for each call to mbrlen. This change constructs and uses
a cache of the lengths returned by mbrlen for unibyte values.
The largest speed-up (3x to 7x, CPU-dependent) is when most
lines contain a match, yet few are printed, e.g., when using
grep -v common-pattern ... to filter out all but a few lines.
* src/search.h (build_mbclen_cache): Declare it.
* src/main.c: Include "search.h".
[MBS_SUPPORT] (main): Call build_mbclen_cache in a multibyte locale.
* src/searchutils.c [HAVE_LANGINFO_CODESET]: Include .
(mbclen_cache): New global.
(build_mbclen_cache): New function.
(is_mb_middle) [HAVE_LANGINFO_CODESET]: Use it.
* NEWS (Improvements): Mention it.
2014-02-01 Jim Meyering
maint: use to_uchar function rather than explicit casts
* src/system.h (to_uchar): Define function.
* src/kwsearch.c (Fexecute): Use to_uchar twice in place of casts.
* src/dfasearch.c (EGexecute): Likewise.
* src/main.c (prepend_args): Likewise.
* src/kwset.c (U): Define in terms of to_uchar.
* src/dfa.c (match_mb_charset): Use to_uchar, not an explicit cast.
2014-01-27 Jim Meyering
maint: remove vestiges of support for long-disabled --mmap option
This option was disabled in March of 2010, and began to elicit a
warning in January of 2012. Its time has come.
* doc/grep.in.1: Remove mention.
* doc/grep.texi: Likewise.
* src/main.c (GROUP_SEPARATOR_OPTION, usage, MMAP_OPTION)
(long_options, main): Remove all traces.
* tests/Makefile.am (check_PROGRAMS): Remove mention of ignore-mmap.
* tests/ignore-mmap: Remove file.
* NEWS (Maintenance): Mention it.
2014-01-26 Jim Meyering
maint: move two local variable declarations
* src/dfasearch.c (kwsmusts): Move one declaration down to the point
of definition. Move another into the sole scope where it is used.
2014-01-26 Norihiro Tanaka
dfasearch: skip kwset optimization when multi-byte+case-insensitive
Now that DFA searching works with multi-byte locales, the only remaining
reason to case-convert the searched input is the kwset optimization.
But multi-byte case-conversion is so expensive that it's not
worthwhile even to attempt that optimization.
* src/dfasearch.c (kwsmusts): Skip this function in ignore-case mode
when the locale is multi-byte.
(EGexecute): Now that this code need not handle multi-byte case-ignoring
matches, remove the expensive copy/case-conversion code.
With no case-converted buffer, there is no longer any need to call
mb_case_map_apply, so remove it and associated code.
(kwsincr_case): Remove function. Now, every use of this function
is equivalent to a use of kwsincr. Replace all uses.
* tests/turkish-eyes: Test all of -E, -F and -G.
2014-01-25 Norihiro Tanaka
dfa: remove GREP-ifdef'd code in favor of code used by gawk
For many years, gawk and grep have used different #ifdef'd bits of
code relating to how the DFA matcher matches multibyte characters.
Remove the GREP-specific code in favor of the code gawk uses. This
permits us to avoid still more cases in which grep must resort to
the expensive process of copying/case-converting each input line
before matching against a case-converted regexp.
* src/dfa.c (parse_bracket_exp, atom): As above.
2014-01-25 Jim Meyering
gnulib: update to latest
2014-01-17 Paul Eggert
grep: DFA now uses rational ranges in unibyte locales
Problem reported by Aharon Robbins in .
* NEWS:
* doc/grep.texi (Environment Variables)
(Character Classes and Bracket Expressions):
Document this.
* src/dfa.c (parse_bracket_exp): Treat unibyte locales like multibyte.
2014-01-17 Aharon Robbins
grep: add undocumented '-X gawk' and '-X posixawk' options
See .
* src/grep.c (GAcompile, PAcompile): New functions.
(const): Use them.
2014-01-10 Pádraig Brady
tests: remove superfluous uses of printf
* tests/turkish-eyes: Remove unnecessary uses of printf.
2014-01-09 Jim Meyering
grep: make --ignore-case (-i) faster (sometimes 10x) in multibyte locales
These days, nearly everyone uses a multibyte locale, and grep is often
used with the --ignore-case (-i) option, but that option imposes a very
high cost in order to handle some unusual cases in just a few multibyte
locales. This change gets most of the performance of using LC_ALL=C
without eliminating the ability to search for multibyte strings.
With the following example, I see an 11x speed-up with a 2.3GHz i7:
Generate a 10M-line file, with each line consisting of 40 'j's:
yes jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj | head -10000000 > k
Time searching it for the simple/noexistent string "foobar",
first with this patch (best-of-5 trials):
LC_ALL=en_US.UTF-8 env time src/grep -i foobar k
1.10 real 1.03 user 0.07 sys
Back out that commit (temporarily), recompile, and rerun the experiment:
git log -1 -p|patch -R -p1; make
LC_ALL=en_US.UTF-8 env time src/grep -i foobar k
12.50 real 12.41 user 0.08 sys
The trick is to realize that for some search strings, it is easy
to convert to an equivalent one that is handled much more efficiently.
E.g., convert this command:
grep -i foobar k
to this:
grep '[fF][oO][oO][bB][aA][rR]' k
That allows the matcher to search in buffer mode, rather than having to
extract/case-convert/search each line separately. Currently, we perform
this conversion only when search strings contain neither '\' nor '['.
See the comments for more detail.
* src/main.c (trivial_case_ignore): New function.
(main): When possible, transform the regexp so we can drop the -i.
* tests/turkish-eyes: New file.
* tests/Makefile.am (TESTS): Use it.
* NEWS (Improvements): Mention it.
2014-01-07 Paul Eggert
tests: port Solaris 10 /bin/sh patch back to GNU/Linux
Problem reported by Jim Meyering.
* tests/bre, tests/ere, tests/spencer1-locale:
Prefer re_shell, not re_shell_.
* tests/init.sh (re_shell): New var, which is exported instead of
re_shell_.
Port to Solaris 10 /bin/sh.
Problem reported by Dagobert Michelsen in .
* tests/bre, tests/ere, tests/spencer1-locale:
Prefer re_shell_ to SHELL, if re_shell_ is set.
* tests/init.sh (re_shell_): Export if it's used.
2014-01-01 Jim Meyering
maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
version 2.16
* NEWS: Record release date.
gnulib: update to latest, for maint.mk fix
maint: update copyright dates for 2014
Do that by running "make update-copyright".
gnulib: update to latest
2013-12-31 Jim Meyering
pcre: use PCRE_NO_UTF8_CHECK properly
In order to obtain the behavior we want, i.e., to disable
error-on-invalid-UTF-in-input, apply this PCRE option in
pcre_exec, not when compiling.
* src/pcresearch.c (Pexecute): Use PCRE_NO_UTF8_CHECK here, ...
(Pcompile): ...rather than here.
* tests/pcre-invalid-utf8-input: Adjust test case to test for this.
2013-12-26 Jim Meyering
maint: fix inconsistent spacing in expression
* src/main.c (prline): Fix inconsistent spacing in expression:
s/ / /.
2013-12-26 behoffski
maint: fix a garbled comment
* src/dfa.c (XNMALLOC, etc.): Fix garbled comment wording.
2013-12-23 Jim Meyering
maint: fix/improve a comment
* src/main.c (prline): Replace untrue FIXME comment with one
telling how the hard-to-reach code can be exercised.
2013-12-21 Santiago Ruano Rincón
pcre: tell grep -P to relax its stance on invalid multibyte chars
Do not exit-2 for invalid UTF-8 characters. Just prior to this
change, this command would match no lines and fail like this:
$ printf 'j\x82\nj\n'|LC_ALL=en_US.UTF-8 grep -P j|cat -A; echo $?
grep: invalid UTF-8 byte sequence in input
2
After this change, the same command matches both lines, and succeeds:
jM-^B$
j$
0
* src/pcresearch.c (Pcompile): Use PCRE_NO_UTF8_CHECK, too, and
add a comment.
* tests/pcre-utf8: Add a test and a comment.
This change did not work with Debian unstable pcre-8.31-2
or with some 8.33 and 8.34-based versions, but does work with
Fedora 20's 8.33 and with a built-from-latest source library.
Based on a patch by Santiago Ruano Rincón.
See http://bugs.gnu.org/15758/
2013-12-21 Jim Meyering
tests: avoid FP failure due to exhausted memory
* tests/long-line-vs-2GiB-read: Don't declare the test "failed"
when running out of memory. In that case, skip it.
2013-12-18 Jim Meyering
maint: add comments and split some long lines
* src/main.c (do_execute): Add a comment.
Split some lines longer than 80 bytes.
pcre: avoid a nominal leak
* src/pcresearch.c (Pcompile)[HAVE_LIBPCRE && !PCRE_STUDY_JIT_COMPILE]:
We would leak "re" if built with HAVE_LIBPCRE but without
PCRE_STUDY_JIT_COMPILE. Move the free out one level.
maint: indent cpp directives to reflect nesting
* src/pcresearch.c: Insert spaces after a few "#", to indent
cpp directives to reflect their nesting.
grep: handle lines longer than INT_MAX on more systems
When trying to exercize some long-line-handling code, I ran these
commands:
$ dd bs=1 seek=2G of=big < /dev/null; grep -l x big; echo $?
grep: big: Invalid argument
2
grep should not have issued that diagnostic, and it should
have exited with status 1, not 2. What happened?
grep read the 2GiB of NULs, doubled its buffer size,
copied the 2GiB into the new 4GiB buffer, and proceeded
to call "read" with a byte-count argument of 2^32.
On at least Darwin 12.5.0, that makes read fail with EINVAL.
The solution is to use gnulib's safe_read wrapper.
* src/main.c: Include "safe-read.h"
(fillbuf): Use safe_read, rather than bare read. The latter
cannot handle a read size of 2^32 on some systems.
* bootstrap.conf (gnulib_modules): Add safe-read.
* tests/long-line-vs-2GiB-read: New file.
* tests/Makefile.am (TESTS): Add it.
* NEWS (Bug fixes): Mention it.
2013-11-25 Jim Meyering
tests: port to non-GNU sed
* tests/multibyte-white-space (utf8_space_characters): The generation
of test inputs relied on GNU sed's interpretation of \<, but that is
not portable, and caused spurious test failures. Adjust the sed regexp
to work on all versions.
Reported by Karl Dubost in http://bugs.gnu.org/15953.
2013-11-22 Jim Meyering
maint: minor cleanup: xmalloc+strcpy -> xmemdup
* src/main.c (main): Replace an xmalloc+strcpy combination
with an equivalent use of xmemdup.
2013-11-21 Jim Meyering
Paul Eggert
dfa: avoid undefined behavior of "1 << 31"
* src/dfa.c (charclass): Change type from "int" to "unsigned int".
(tstbit): Rather than shifting "1" left to form a mask, shift the
LHS bits the right and use "1" as the mask. Also, return bool, rather
than "int".
(setbit, clrbit, dfastate): Don't shift "1" (aka (int)1) left by 31 bits.
Instead, use "1U" as the operand, to avoid undefined behavior.
Spotted by gcc's new -fsanitize=undefined.
2013-11-02 Jim Meyering
grep: fix regression with -P vs. invalid UTF-8 input
* src/pcresearch.c (Pexecute): Don't abort upon unexpected
PCRE-specific error code. Explicitly handle PCRE_ERROR_BADUTF8,
and change the default to print a diagnostic including the unhandled
integer PCRE error code and exit with status 2.
* tests/pcre-invalid-utf8-input: New file.
* tests/Makefile.am (TESTS): Add it.
* NEWS (Bug fixes): Mention it.
* THANKS: Update.
Reported by Dave Reisner in http://bugs.gnu.org/15758.
grep: fix regression involving \s and \S
Commit v2.14-40-g01ec90b made \s and \S work with multi-byte
characters, but it made it so any use like \s*, \s+, \s?, \s{3}
would malfunction in a multi-byte locale.
* src/dfa.c (lex): Also reset laststart.
* tests/backslash-s-and-repetition-operators: New file.
* tests/Makefile.am (TESTS): Add it.
* NEWS (Bug fixes): Mention it.
* THANKS: Update.
Reported by Mirraz Mirraz in http://bugs.gnu.org/15773.
2013-11-01 Jim Meyering
maint: NEWS: document a release-related bug fix
* NEWS (Bug fixes): Add an entry for a fix pulled from gnulib.
2013-10-26 Jim Meyering
build: update gnulib submodule to latest
This pulls in a gnulib fix for maint.mk that ensures the procedure
described in README-release actually does what we want. Before this
change, that procedure resulted in a grep-2.15 tarball that would
lead to a grep binary whose --version- reported version number was
2.14.51... rather than the expected 2.15.
maint: avoid automake deprecation warning re ACLOCAL_AMFLAGS
* Makefile.am (ACLOCAL_AMFLAGS): Don't use this deprecated variable.
* configure.ac (AC_CONFIG_MACRO_DIRS): Use this instead.
(AUTOMAKE_OPTIONS): Require automake-1.12.
maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
version 2.15
* NEWS: Record release date.
2013-10-25 Paul Eggert
build: port to AIX
Problem reported by Pavel Kharitonov in .
* src/Makefile.am (LDADD): Add $(LIBTHREAD).
build: avoid duplicate -funit-at-a-time etc. options
* configure.ac (WERROR_CFLAGS): Don't add -fdiagnostics-show-option
and -funit-at-a-time, as Gnulib does that for us now, and we're
merely piling on duplicats.
2013-10-24 Jim Meyering
tests: port more tests to bourne shells with hex-challenged printf
* tests/pcre-utf8: Convert the hex \xHH literals for the euro symbol
to octal \OOO.
* tests/turkish-I: Likewise for "I with dot".
* tests/turkish-I-without-dot: Likewise for another Turkish I: U+0131.
maint: clean up an ugly 'while' condition
* src/main.c (get_nondigit_option): Separate a slightly baroque
"while" expression into two separate statements, both inside the loop.
2013-10-23 Jim Meyering
tests: port to bourne shells whose printf doesn't grok hex
Use octal escapes, not hex, in printf(1) format strings,
and in one case, use $AWK's printf so we can continue
to use the table of hex values.
* tests/char-class-multibyte: Use printf octal escapes, not hex,
for portability to shells like dash and Solaris 10's /bin/sh.
* tests/backslash-s-vs-invalid-multitype: Likewise.
* tests/surrogate-pair: Likewise.
* tests/unibyte-bracket-expr: Count in decimal and convert to octal.
* tests/multibyte-white-space (hex_printf): New function.
Use it in place of printf so we can retain the table of hex digits
without hitting the limitation of some bourne shells.
Reported by Paul Eggert in http://bugs.gnu.org/15690#11
2013-10-21 Jim Meyering
gnulib: update to latest
maint: remove now-unused wcscoll module
* bootstrap.conf (gnulib_modules): Remove wcscoll; no longer used.
2013-10-20 Paul Eggert
build: avoid chatter from Automake 1.14
* configure.ac (AM_INIT_AUTOMAKE): Add subdir-objects.
build: port shell pattern to Solaris 10
* configure.ac: Don't use unquoted '^' in a pattern, as this
breaks 'configure' on Solaris 10, whose /bin/sh complains about it,
which causes 'configure' to exit even before it finds a decent shell.
Unix 7th edition shell accepted '^' as an alias for '|'.
build: port to platforms that predefine _FORTIFY_SOURCE
Problem reported by Brenton Hoff (Bug#15663).
* configure.ac (_FORTIFY_SOURCE): Don't define if already defined.
This is what Emacs does.
2013-10-20 Jim Meyering
build: update gnulib submodule to latest
2013-10-19 Jim Meyering
tests: extend the multibyte-white-space test
* tests/multibyte-white-space (utf8_space_characters): Add more
single-byte whitespace characters. Align RHS hex values and
make the sed substitution less rigid, to accommodate.
Also, ensure that grep '\S' exits with status 1.
maint: update bootstrap to latest from gnulib
* bootstrap: Update from gnulib.
maint: fix typo in NEWS
* NEWS: Fix/improve example commands in most recent entry.
The LC_ALL envvar setting goes before grep, not before printf.
Don't reference src/ in the second example command, and do specify
the locale.
2013-10-09 Jim Meyering
tests: add a test for better coverage of some tricky code
* tests/spencer1.tests: Add a non-range bracket expression representing the
same regexp, to cover the alternate code path, the one that does not require
a regcomp/exec call to interpret the regexp.
2013-10-01 Jim Meyering
tests: ensure neither \s nor \S matches an invalid multibyte character
* tests/backslash-S-vs-invalid-multitype: New file.
Prompted by the bug report from Roman at
http://savannah.gnu.org/bugs/?40009
* tests/Makefile.am (TESTS): Add it.
dfa: fix \s and \S to work for multibyte
* src/dfa.c (lex): In multibyte mode, we can't treat \s and \S as we do
in single-byte mode. Map them to [[:space:]] and [^[:space:]] respectively,
to make the DFA matcher use the regex-matcher for this term.
* tests/multibyte-white-space: New file. Test for the bug.
* tests/Makefile.am (TESTS): Add it.
This bug was introduced with the addition of DFA support
for \s and \S in commit v2.5.4-112-gf979ca0.
2013-09-30 Jim Meyering
maint: change all references: s/POSIX\.2/POSIX/
There is no longer any point in referring to POSIX.N.
POSIX is sufficient.
* doc/grep.in.1: As above.
* src/main.c (main): Likewise.
* tests/file: Likewise.
* tests/options: Likewise.
* ChangeLog: Likewise.
* NEWS: Likewise.
* cfg.mk: Update, to match changed NEWS.
Inspired by Glenn Golden's suggestion in http://bugs.gnu.org/15486
2013-09-22 Jim Meyering
dfa: remove dead disjunct
* src/dfa.c (parse_bracket_exp): Remove dead disjunct.
At that point, we know MB_CUR_MAX <= 1, so the test,
MB_CUR_MAX > 1 && ... is always false. Remove the disjunct.
maint: dfa: improve comments and formatting
* src/dfa.c (add_utf8_anychar): Correct wording/alignment of a comment.
(dfaexec): Add curly braces around multi-line while statement within
a "then" block.
(ANYCHAR): Clarify comment: "." does not match an invalid UTF8 character.
(parse_bracket_exp) Improve comment.
2013-09-08 Jim Meyering
dfa: appease a static analyzer, and save 95 stack bytes
* src/dfa.c (MAX_BRACKET_STRING_LEN): Rename from BRACKET_BUFFER_SIZE
and decrease from 128 to 32.
(parse_bracket_exp): Add one byte more than MAX_BRACKET_STRING_LEN
to the length of "str" buffer, to avoid appearance that we may store
the trailing NUL beyond the end of buffer. A string of length 32
or greater is rejected by earlier processing, so would never reach
this code. Addresses http://bugs.gnu.org/15307
2013-09-01 Corinna Vinschen
fix Cygwin UTF-16 surrogate-pair handling with -i
grep -i would segfault on systems using UTF-16-based wchar_t (Cygwin)
when converting an input string containing certain 4-byte UTF-8
sequences to lower case. The conversions to wchar_t and back to
a UTF-8 multibyte string did not take surrogate pairs into account.
* src/searchutils.c (mbtolower) [__CYGWIN__]: Detect and handle
surrogate pairs when converting.
* NEWS (Bug fixes): Mention it.
* tests/surrogate-pair: New test.
* tests/Makefile.am (TESTS): Add it.
Reported by: Jim Burwell
2013-08-19 Paul Eggert
doc: mention how to use the latest gnulib
* README-hacking: Steal some text from coreutils/README-hacking.
2013-08-10 Jim Meyering
build: update gnulib-related code
* gnulib: Update submodule to latest.
* bootstrap: Update from gnulib.
* gl/lib/regex_internal.h.diff: Update to reflect gnulib changes.
* bootstrap.conf: Partial sync from coreutils.
2013-08-09 Jim Meyering
tests: simplify and factor newest test
* tests/char-class-multibyte2: Simplify file names.
Factor out $e_acute, so that the grep argument representation
is ascii (though the value is still UTF8).
doc: NEWS: mention the DFA segfault fix
* NEWS (Bug fixes): List the DFA segfault fix.
2013-07-05 Paul Eggert
Redo comments and white space to better approach GNU style.
2013-07-05 Paolo Bonzini
tests: add testcase for previous change
* tests/Makefile.am (TESTS): add char-class-multibyte2.
* tests/char-class-multibyte2: New file.
2013-07-05 Mike Haertel
dfa: fix multibyte character in brackets with repetition
Let FOO stand for any multibyte (e.g. CJK character) in the regexp.
It turns out the following much simpler regexp:
([^.]*[FOO]){1,2}
is sufficient to cause the crash.
In the first step of its parsing, DFA transforms regexp from human
readable syntax into reverse-polish form. For regexps of the form a{m,n}
repeat counts, it simply builds repeated copies of the representation
of a, with appropriate inserted CAT and QMARK operators. For the above
example with a regexp of the form a{1,2} it would build:
QMARK
CAT
When building repeated copies of RPN representations, additional
copies of the RPN representations are made by calling a function
copytoks() with arguments consisting of the start position and
length of the original copy.
The problem is that the current code for copytoks() is simply
incorrect. It operates by calling addtok() for each individual
token in the source range being copied. But, in the particular
case that the token being added is MBCSET, addtok():
(1) incorrectly assumes that the character set being added to be added
is the one most (addtok has no argument to indicate which cset is
being added, so it just uses the latest one)
(2) attempts to do some token sequence expansion into more primitive
operators so things like [FOO] are matched efficiently.
Both of these assumptions are incorrect in the case that addtok()
is being called from copytoks(): (1) is simply not true, and
(2) is redundant--the expansion has already been done token sequence
being copied, so there is no need to do the expansion again.
The correct function to add exactly one token, without further expansion,
is addtok_mb(). So here is my proposed fix, which is that copytoks()
should never call addtok(), but instead directly call addtok_mb()
(which is what addtok() eventually calls).
* src/dfa.c (copytoks): Rewrite using addtok_mb directly.
2013-05-28 Jim Meyering
maint: align backslashes consistently
* tests/Makefile.am: Most backslashes were aligned with TABs,
so adjust the few that used spaces to conform.
grep -F: avoid an infinite loop with invalid multi-byte search string
* src/kwsearch.c (Fexecute): Avoid an infinite loop when processing
a fixed (-F) multibyte search string that is an invalid byte sequence
in the current locale and that matches the bytes of the input twice
on a line. Reported by Daisuke GOTO in
http://thread.gmane.org/gmane.comp.gnu.grep.bugs/4773
* tests/invalid-multibyte-infloop: New test.
* tests/Makefile.am (TESTS): Add it.
* NEWS (Bug fixes): Mention it.
2013-04-18 Paul Eggert
* cfg.mk (old_NEWS_hash): Update.
doc: document EREs like a{,10}
Problem reported by Eric Blake in
.
* NEWS: Document the bug fix.
* doc/grep.in.1: Restore documentation for this feature, but mention
that it is a GNU extension.
* doc/grep.texi (Fundamental Structure): Mention that this feature
is a GNU extension.
2013-04-02 Paul Eggert
build: make dfa.c closer to Gawk's
* src/dfa.c: Include , not .
stddef.h is smaller and is all we need and is portable nowadays.
Include and only if MBS_SUPPORT.
2013-01-15 Paul Eggert
grep: make dfa.h standalone
Problem reported by Aharon Robbins in
.
* src/dfa.c: Include dfa.h first, so that it's tested standalone.
No need to include , since we are in charge of dfa.h and
know that it includes .
* src/dfa.h: Include and , so that it's standalone.
2013-01-11 Stefano Lattarini
build: update gettext version to 0.18.2
* configure.ac (AM_GNU_GETTEXT_VERSION): Update to 0.18.2.
This is necessary to have the gettext-provided m4 files to use
AC_PROG_MKDIR_P rather than AM_PROG_MKDIR_P. This latter macro,
planned to disappear in Automake 1.14, has already been removed
in the development version of Automake, so that, without this
change, grep fails to bootstrap with bleeding-edge Automake.
2013-01-11 Paul Eggert
build: update gnulib submodule to latest
2013-01-11 Stefano Lattarini
build: remove redundant use of $(INCLUDES)
* lib/Makefile.am (INCLUDES): Remove. Automake automatically adds
$(srcdir) and $(top_builddir) to the C preprocessor search path.
INCLUDES is deprecated in Automake 1.13 (causing a runtime
warning), and will be removed in Automake 1.14.
2013-01-04 Jim Meyering
build: update gnulib submodule to latest
maint: update all copyright year number ranges
Run "make update-copyright".
2012-11-20 Paul Eggert
grep: normalize diagnostics
* src/pcresearch.c (Pcompile): Use similar format diagnostics
as elsewhere, and translate them.
2012-11-19 Paul Eggert
grep: diagnose read errors from -f dir, porting to Solaris
Problem reported by Dennis Clarke for Solaris 10 in
.
* src/main.c (main): For -f F, diagnose any read errors
encountered when reading F.
* tests/Makefile.am (XFAIL_TESTS): Remove grep-dir.
* tests/grep-dir: Don't assume that directories cannot be read
via fread, as POSIX allows this and it can happen on Solaris.
2012-11-09 Paolo Bonzini
pcre: add PCRE-JIT support for grep
* NEWS: Document new feature.
* src/pcresearch.c [PCRE_STUDY_JIT_COMPILE] (jit_stack): New.
[PCRE_STUDY_JIT_COMPILE] (Pcompile): JIT-compile the regular expression
and allocate a stack for it. Based on a patch from Zoltan Herczeg.
* THANKS: Add Zoltan to the list.
2012-10-24 Paul Eggert
build: go back to AC_PROG_CC
* configure.ac: Go back to using AC_PROG_CC rather than AC_PROG_CC_STDC,
as the latter is obsolescent and the Autoconf bug involving the former
has been fixed.
2012-10-24 Jim Meyering
build: use AC_PROG_CC_STDC rather than AC_PROG_CC
* configure.ac: Use AC_PROG_CC_STDC rather than AC_PROG_CC,
to accommodate autoconf-2.69-37+.
build: update gnulib submodule to latest
2012-10-23 Eric Blake
build: default to --enable-gcc-warnings in a git tree
Anyone building from cloned sources can be assumed to have a new
enough environment, such that enabling gcc warnings by default will
be useful. Tarballs still default to no warnings, and the default
can still be overridden with --disable-gcc-warnings.
* configure.ac (gl_gcc_warnings): Set default based on environment.
2012-10-03 Jim Meyering
maint: factor out STREQ definition
* src/main.c (STREQ): Remove definition.
* src/pcresearch.c: (STREQ): Likewise.
* src/system.h (STREQ): Define it here instead.
maint: correct syntax-check failures; adjust NEWS
* tests/pcre-utf8: Reverse order of compare arguments.
Remove all copyright year numbers except 2012.
Use skip_ "diagnostic...", rather than a bare "exit 77".
* NEWS: Start with a concise description of the bug.
* src/pcresearch.c (STREQ): Define, so that we can...
(Pcompile): use STREQ, not strcmp.
2012-10-03 Paolo Bonzini
tests: include UTF-8 testcases for grep -P
* tests/Makefile.am (TESTS): Add pcre-utf8.
* tests/pcre-utf8: New file.
2012-10-03 Petr Pisar
pcresearch: set UTF-8 flag correctly for UTF-8 locales
Otherwise, Unicode properties (\p{XXX}) do not work with characters
outside the 7-bit ASCII character set.
* src/pcresearch.c (Pcompile): Look for UTF-8 locales and set PCRE_UTF8
if one is found.
2012-10-03 Jaroslav Škarvada
doc: fix a formatting bug in grep.1 template
* doc/grep.in.1: Insert .TP before the paragraph describing
--dereference-recursive (-R).
2012-10-03 Jim Meyering
maint: placate gcc's -Wjump-misses-init warning
* src/kwsearch.c (Fexecute): Replace a "goto" and "return" with
a simple return statement, eliminating the label, since that was
the sole use.
* src/dfasearch.c (EGexecute): Likewise.
2012-09-01 Jim Meyering
build: update gnulib submodule to latest
2012-09-01 Eric Blake
build: work with new glibc when not optimizing
Starting with glibc 2.15, the system headers refuse to compile
unconditional use of FORTIFY_SOURCE if optimization is disabled
but -Werror is in effect.
* configure.ac (FORTIFY_SOURCE): Make conditional.
2012-08-19 Jim Meyering
maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
version 2.14
* NEWS: Record release date.
2012-08-07 Jim Meyering
build: update gnulib and bootstrap
tests: test for bug with -i and ^$ in a multi-byte locale
* tests/empty-line-mb: New file.
* tests/Makefile.am (TESTS): Add it.
grep -i '^$' in a multi-byte locale could report a false match
* src/dfasearch.c (EGexecute): Do not match the sentinel "newline"
that is appended to each buffer.
This bug may sound like a big deal (it certainly surprised me), but
realize that only the empty-line-matching regular expression '^$'
can trigger it, and then only when you add the unnecessary (and
arguably superfluous) -i, *and* run the command in a multi-byte
locale. Using a multi-byte locale for such a regular expression
is also pointless, and hurts performance.
* NEWS (Bug fixes): Mention it.
Reported by Alexander Katassonov
2012-08-06 Jim Meyering
tests: fix a skip diagnostic that mentioned the wrong locale
* tests/init.cfg (require_tr_utf8_locale_): s/en_US/tr_TR/
2012-08-02 Jim Meyering
tests: skip failing test on FS/system that lack SEEK_HOLE support
* tests/big-hole: Test for SEEK_HOLE support. If not available,
skip this test. Hence, this test is now skipped on linux-3.5.0 with
ext4 or tmpfs. The test runs (and passes) with at least btrfs, xfs,
or ocfs2.
* bootstrap.conf (gnulib_modules): Use the perl module.
2012-07-30 Jim Meyering
maint: optimize long-line processing
* src/main.c (grep): Use memrchr rather than an open-coded loop,
reducing the cost of the replaced code by 50% when processing very
long lines. If there were a rawmemrchr function (analogous to glibc's
rawmemchr), then the performance improvement would be even greater.
2012-07-27 Paul Eggert
maint: remove stat-size
* bootstrap.conf (gnulib_modules): Remove stat-size.
* src/main.c: Don't include stat-size.h; no longer needed.
grep: don't falsely report compressed text files as binary
* NEWS: Document this.
* src/main.c (file_is_binary): Remove the heuristic based on
st_blocks, as it does not work for compressed file systems.
On Solaris, it'd be cheap to test whether the file system is known
to be uncompressed, which allow the heuristic, but Solaris has
SEEK_HOLE so there's little point.
grep: don't falsely report tiny text files as binary
* NEWS: Document this.
* src/main.c (file_is_binary): When we are already at apparent
EOF, skip the file-size check, as some servers use zero blocks
to store binary files. Reported by Martin Carroll in
.
2012-07-26 Paul Eggert
doc: document -r/-R in man page
* doc/grep.in.1: Document -r vs. -R.
2012-07-21 Jim Meyering
tests: avoid false positive upon kernel OOM-kill
* tests/big-match (skip_diagnostic): Handle case of 139 (SIGKILL)
with no diagnostic.
build: update gnulib and bootstrap
maint: fix misspellings in old ChangeLog
* ChangeLog-2009: Fix typos.
2012-07-19 Paul Eggert
grep: fix ptrdiff/size_t clash
Reported by Jaroslav Škarvada in .
* src/dfasearch.c (EGexecute): Use size_t, not ptrdiff_t, for lengths.
Use regoff_t to store re_match's output, and test it before converting
it to size_t.
2012-07-06 Jim Meyering
maint: correct log typo, to reflect in generated ChangeLog
* Makefile.am (gen-ChangeLog): Use --amend, now that we must
make our first log correction.
* build-aux/git-log-fix: New file.
2012-07-04 Jim Meyering
maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
version 2.13
* NEWS: Record release date.
build: update gnulib submodule, bootstrap, init.sh
2012-06-17 Jim Meyering
tests: add another turkish-I-related test case
* tests/turkish-I-without-dot: Also exercise the case in which
the original string and the lower-case buffer have precisely
the same length (22 bytes here), yet internal offsets do differ.
2012-06-16 Jim Meyering
grep -i: work also when converting to lower-case inflates byte count
Commit v2.12-16-g7aa698d addressed the case in which the lower-case
representation of an input byte occupies fewer bytes than the original.
However, even with commit v2.12-20-g074842d, grep -i would still
misbehave when converting a character to lower-case increased its
byte count. The map-manipulation code assumed that the case conversion
could only shrink the byte count. With the consideration that it may
also inflate it, the deltas recorded in the map array must be signed,
and we must account for the one-to-two-or-more mapping when the
original-to-lower-case conversion causes the byte count to increase.
* src/searchutils.c (mbtolower): When a lower-case character occupies
more than one byte, set its remaining map slots to zero. Change the
type of the map to be signed, and compute the change in character
byte count as new_length - old_length.
* src/search.h: Include , for decl of intmax_t.
(mb_case_map_apply): Adjust for signed increments:
each map entry is now signed.
(mb_len_map_t): Define type. Thanks to Paul Eggert for noticing
in review that using a bare "char" as the base type would be wrong on
systems for which it is a signed type (as with gcc's -funsigned-char).
* src/kwsearch.c (Fcompile, Fexecute): Likewise.
* src/dfasearch.c (kwsincr_case, EGexecute): Likewise.
* tests/turkish-I-without-dot: New test. Thanks to Paolo Bonzini
for the tip that in the tr_TR.utf8 locale, mapping "I" to lower case
increases the character's byte count.
* tests/Makefile.am (TESTS): Add it.
* tests/init.cfg (require_tr_utf8_locale_): New function.
* NEWS (Bug fixes): Expand the existing entry.
2012-06-12 Paul Eggert
grep: handle -i when chars differ in length but line does not
* src/searchutils.c (mbtolower): Return the map back to the caller
if any input character's length differs from the corresponding output
character's, not merely if the total string length differs.
Problem reported by Johannes Meixner in
.
2012-06-07 Jim Meyering
tests: extend coverage of dfa.c's match_mb_charset
Add a test case to increase test coverage of part of dfa.c (the DFA
matcher used by grep and gawk). While thinking about removing the few
remaining uses of strncpy in dfa.c, I found that none of the existing
tests covered the 40+ lines of code at the end of match_mb_charset,
so constructed this test case to demonstrate that it's not dead code
* tests/dfa-coverage: New test, for improved coverage.
* tests/Makefile.am (TESTS): Add it.
2012-06-05 Jim Meyering
build: fix a subtly twisted "make distcheck" failure
"make distcheck" would fail when, during a test build,
an attempt to overwrite the deliberately-write-protected
$(srcdir)/grep.pot file would fail.
* bootstrap.conf (bootstrap_epilogue): Don't let the existence of
a large sparse file in the build directory induce "make distcheck"
failure. The existence of a large sparse test file named 8T-or-so
would make po/Makefile.in.in's use of grep (to search for "GNU grep"
as an indication that this is a GNU package) exit 2 without generating
any output, which made the first xgettext use --package-name=grep,
while that same search for "GNU grep" would succeed when run
from a pristine from-tarball build, thus making the second
xgettext invocation use --package-name='GNU grep'.
That mismatch:
-"Project-Id-Version: grep 2.12.18-1080\n"
+"Project-Id-Version: GNU grep 2.12.18-1080\n"
led to the attempt by Makefile.in.in's grep.pot-update rule to
overwrite ../../grep.pot in the read-only po/ source directory.
2012-06-03 Jim Meyering
build: update gnulib submodule, bootstrap and init.sh
cfg.mk: Exempt dfa.c from the new no-strncpy test, for now.
2012-06-02 Jim Meyering
grep: fix how -i works with a match containing the Turkish I-with-dot
Fix a long-standing problem in the way grep's -i interacts with
data whose byte count changes when we convert it to lower case.
For example, the UTF-8 Turkish I-with-dot (İ) occupies two bytes,
but its lower case analog, i, occupies just one byte. The code
converts both search string and the haystack data to lower case,
and then searches for the modified string in the modified buffer.
The trouble arose when using a lowercase buffer
pair to manipulate the original (longer) buffer.
The solution is to change mbtolower to return additional information:
a malloc'd mapping vector. With that, the caller maps the lowercase-
relative to numbers that refer to the original buffer.
This mapping is used only when lengths actually differ, so the cost
in general should be small.
* src/searchutils.c (mbtolower): Add the new map parameter.
* src/search.h (mb_case_map_apply): New function.
* src/kwsearch.c (Fexecute): Update mbtolower caller, and upon
success, apply the new map.
* src/dfasearch.c (EGexecute): Likewise.
* tests/Makefile.am (XFAIL_TESTS): Remove turkish-I from this list;
that test is no longer expected to fail.
* NEWS (Bug fixes): Mention it.
Reported by Ilya Basin in
http://thread.gmane.org/gmane.comp.gnu.grep.bugs/3413 and later
by Strahinja Kustudic in http://savannah.gnu.org/bugs/?36567
2012-06-01 Paul Eggert
grep: remove unnecessary "what-if-signal?" code
* src/main.c (fillbuf): Don't worry about EINTR when closing --
not possible, since we're not catching signals.
2012-05-16 Paul Eggert
grep: avoid nominal integer overflow
* src/dfa.c (add_utf8_anychar): Avoid signed integer overflow.
Although this works on all platforms we know about, strictly
speaking the behavior is undefined, and Sun C 5.8 warns about it.
2012-05-15 Jim Meyering
maint: avoid nit-picky syntax-check test failure; tweak big-hole test
* NEWS: Restore deleted newline in "old" NEWS, to fix a syntax-check
test failure.
* tests/big-hole: Use awk, rather than a shell loop: saves 3000 lines
of verbose shell output in the .log file.
2012-05-15 Paul Eggert
grep: sparse files are now considered binary
* NEWS: Document this.
* doc/grep.texi (File and Directory Selection): Likewise.
* bootstrap.conf (gnulib_modules): Add stat-size.
* src/main.c: Include stat-size.h.
(usable_st_size): New function, mostly stolen from coreutils.
(fillbuf): Use it.
(file_is_binary): New function, which looks for holes too.
(grep): Use it.
* tests/Makefile.am (TESTS): Add big-hole.
* tests/big-hole: New file.
2012-05-06 Paul Eggert
maint: quote 'like this' or "like this", not `like this'
See .
* ChangeLog-2009, HACKING, NEWS, README-hacking, cfg.mk, configure.ac:
* lib/colorize-w32.c, m4/pcre.m4:
* src/Makefile.am, src/dfa.c, src/dosbuf.c, src/main.c:
* tests/backref, tests/help-version, tests/tests:
In commentary, quote 'like this' or "like this" rather than
`like this' or ``like this''.
* cfg.mk (old_NEWS_hash): Update due to changed old NEWS.
* doc/grep.texi (General Output Control): Quote sample text
with @samp, not with `...'.
* src/main.c (usage):
* tests/help-version: Quote 'like this' rather than `like this'
in diagnostics.
exclude: process exclude and include directives in order
Also, change exclude and include directives so that they apply to
command-line arguments too. This restores the pre-2.6 behavior,
and fixes a bug reported by Quentin Arce in
.
* NEWS: Document this.
* src/main.c (included_patterns): Remove. All uses removed.
(skipped_file): New function.
(grepdirent): New arg command_line; all callers changed. This is
needed because non-command-line files can invoke fts_open, and
their directory entries need to be distinguished from top-level
directory entries. Move code into the new skipped_file function.
(grepdesc): Check whether a command-line argument should be skipped.
(main): --include and --exclude options now share excluded_patterns
rather than having separate variables included_patterns and
excluded_patterns.
* tests/include-exclude: Add a test to detect the fixed bug.
build: update gnulib submodule to latest
2012-04-30 Jim Meyering
cosmetic: binary operator goes *after* the newline, when split
* src/dfa.c (match_mb_charset): Join split lines.
(parse_bracket_exp): Move "||" from end of first split line
to the beginning of the continued line.
* src/dosbuf.c (dossified_pos): Likewise, but for "&&".
grep: -K is not an option: remove it from list
The presence of "K" in the short-option string meant that
an erroneous "grep -K ..." would fail with a bare Usage/Try...
message, without the usual "invalid option -- 'K'". With this
removal, now grep prints the expected invalid option diagnostic.
* src/main.c (short_options): Remove "K".
Reported by Петр Досычев in
http://thread.gmane.org/gmane.comp.gnu.grep.bugs/4488
2012-04-29 Paolo Bonzini
dfa: small fixes to single-byte range computation
* src/dfa.c (parse_bracket_exp): Do not call regexec with an invalid
subject. Move declarations before all statements.
2012-04-27 Paolo Bonzini
dfa: do not use hard-locale
* bootstrap.conf (gnulib_modules): Remove hard-locale.
* src/dfa.c (hard_LC_COLLATE): Remove.
(dfaparse): Do not initialize it.
(parse_bracket_exp): Always go through system regex matcher to find
single byte characters matching a range.
drop support for Makefile.boot
* Makefile.am: Do not distribute README-boot and Makefile.boot.
* NEWS: Mention this change.
* README-alpha: Do not mention README-boot and Makefile.boot.
* Makefile.boot: Remove.
* README-boot: Remove.
2012-04-27 Aharon Robbins
dfa: do not use strcoll to match multibyte characters in ranges
This does not affect the behavior of grep, which always defers
to glibc or gnulib when matching ranges.
* src/dfa.c (match_mb_charset): Compare wc directly to the range
endpoints.
dfa: include stdbool.h explicitly
* src/dfa.c: Include stdbool.h explicitly
2012-04-23 Jim Meyering
maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
version 2.12
* NEWS: Record release date.
build: update gnulib submodule to latest
tests: skip annoyingly long gnulib lock tests
* bootstrap.conf (avoided_gnulib_modules): Define.
(gnulib_tool_option_extras): Use it.
2012-04-22 Jim Meyering
tests: avoid spurious quote-mismatch failure on OS/X
* tests/in-eq-out-infloop: Simplify expected error output, eliminating
expected quotes altogether, thus avoiding spurious OS/X-specific
failure due to mismatch of multi-byte vs. single-byte quotes.
2012-04-17 Jim Meyering
build: update gnulib submodule to latest
* bootstrap: Also update this file.
2012-04-17 Jim Meyering