Commit Graph

189 Commits

Author SHA1 Message Date
Kyle Evans
05ad821531 bsdgrep: add a primitive literal matcher
fgrep/grep -F will error out at runtime if compiled with a regex(3)
that does not define REG_NOSPEC or REG_LITERAL. glibc is one such regex(3)
implementation, and as it turns out they don't support literal matching at
all.

Provide a primitive literal matcher for use with glibc and other
implementations that don't support literal matching so that we don't
completely lose fgrep/grep -F if compiled against libgnuregex on stable/10,
stable/11, or other systems that we don't necessarily support.

This is a wholly unoptimized implementation with no plans to optimize it as
of now. This is due to both its use-case being primarily on unsupported
systems in the near-distant future and that it's reinventing the wheel that
we already have available as a feature of regex(3).

Reviewed by:	cem, emaste, ngie
Approved by:	emaste (mentor)
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D12056
2017-08-24 01:23:33 +00:00
Kyle Evans
de3d7a8286 bsdgrep: cast pmatch.rm_so to fix build when linking against libgnuregex
Reported by:	many
Approved by:	emaste (mentor)
MFC after:	immediate
2017-08-17 13:40:45 +00:00
Enji Cooper
d511b20a69 Add HAS_TESTS to all Makefiles that are currently using the
`SUBDIR.${MK_TESTS}+= tests` idiom.

This is a follow up to r321912.
2017-08-02 08:50:42 +00:00
Enji Cooper
4b330699f8 Convert traditional ${MK_TESTS} conditional idiom for including test
directories to SUBDIR.${MK_TESTS} idiom

This is being done to pave the way for future work (and homogenity) in
^/projects/make-check-sandbox .

No functional change intended.

MFC after:	1 weeks
2017-08-02 08:35:51 +00:00
Kyle Evans
0e95794283 bsdgrep(1): Don't exit before processing every file
Given an empty pattern (i.e. grep "" A B), bsdgrep(1) would previously exit()
with the appropriate exit code upon encountering an empty file. Likely intended
as an optimization, but this behavior is technically incorrect since an empty
pattern should match every line.

PR:		220924
Reviewed by:	emaste, cem (earlier version), ngie
Approved by:	emaste (mentor)
Differential Revision:	https://reviews.freebsd.org/D11698
2017-07-25 01:50:37 +00:00
Kyle Evans
26e1c38fbb Update copyright e-mail address to @FreeBSD.org address
Approved by:	emaste (mentor)
Differential Revision:	https://reviews.freebsd.org/D11508
2017-07-06 19:53:30 +00:00
Bryan Drewery
c99b67a794 Utilize SYSROOT from r320119 in places where DESTDIR may be wanting WORLDTMP.
Since buildenv exports SYSROOT all of these uses will now look in
WORLDTMP by default.

sys/boot/efi/loader/Makefile
        A LIBSTAND hack is no longer required for buildenv.

MFC after:	2 weeks
Sponsored by:	Dell EMC Isilon
2017-06-19 20:47:24 +00:00
Ed Maste
b05c7cdeb1 bsdgrep: bump version number and add Kyle Evans copyright
The following changes have been made over the last couple of months:

Features:

 - With bsdgrep -r, the working directory is implied if no directory is
   specified
 - bsdgrep will now behave as bsdgrep -r does when it's named rgrep
 - bsdgrep now understands -z/--null-data to use \0 as EOL
 - GNU regex compatibility is now indicated with a "GNU compatible" in
   the version string

Fixes:

 - --mmap no longer hangs when coming across an EOF without an
   accompanying EOL
 - -o/--color matching generally improved, now produces earliest /
   longest matches
 - Context output now more closely aligns with GNU grep
 - Zero-length matches no longer exhibit broken behavior
 - Every output line now honors -b/-H/-n flags

Tests have been added for previous regressions as well as other
previously untested behaviors.

Various other fixes have been commited, and refactoring for further /
later improvements has taken place.

(The original submission changed the version string to 2.5.2, but I
decided to use 2.6.0 to reflect the addition of new features.)

Submitted by:	Kyle Evans <kevans91@ksu.edu>
Differential Revision:	https://reviews.freebsd.org/D10982
2017-05-29 13:10:01 +00:00
Enji Cooper
80c5ef109c :rgrep : use atf-check to check the exit code/save the output of grep -r instead
of calling grep -r without it, and saving the output to a file

This ensures that any errors thrown via grep -r are caught, not lost, and uses
existing atf-sh idioms for saving files.

Tested with:	bsdgrep, gnu grep (base, ports)
Sponsored by:	Dell EMC Isilon
2017-05-27 22:40:20 +00:00
Ed Maste
6068d3b2c9 bsdgrep: use safer sizeof() construct
Submitted by:	Kyle Evans <kevans91@ksu.edu>
2017-05-26 03:35:59 +00:00
Ed Maste
8bf4606408 bsdgrep: correct assumptions to prepare for chunking
Correct a couple of minor BSD grep assumptions that are valid for line
processing but not future chunk-based processing.

Submitted by:	Kyle Evans <kevans91@ksu.edu>
Reviewed by:	bapt, cem
Differential Revision:	https://reviews.freebsd.org/D10824
2017-05-26 02:30:26 +00:00
Ed Maste
6d635d3b32 bsdgrep: Correct per-line line metadata printing
Metadata printing with -b, -H, or -n flags suffered from a few flaws:

1) -b/offset printing was broken when used in conjunction with -o

2) With -o, bsdgrep did not print metadata for every match/line, just
   the first match of a line

3) There were no tests for this

Address these issues by outputting this data per-match if the -o flag is
specified, and prior to outputting any matches if -o but not --color,
since --color alone will not generate a new line of output for every
iteration over the matches.

To correct -b output, fudge the line offset as we're printing matches.

While here, make sure we're using grep_printline in -A context.  Context
printing should *never* look at the parsing context, just the line.

The tests included do not pass with gnugrep in base due to it exhibiting
similar quirky behavior that bsdgrep previously exhibited.

Submitted by:	Kyle Evans <kevans91@ksu.edu>
Reviewed by:	cem
Differential Revision:	https://reviews.freebsd.org/D10580
2017-05-20 11:20:03 +00:00
Ed Maste
fe8c9d5bf1 bsdgrep: emit more than MAX_LINE_MATCHES per line
We should not set an arbitrary cap on the number of matches on a line,
and in any case MAX_LINE_MATCHES of 32 is much too low.  Instead, if we
match more than MAX_LINE_MATCHES, keep processing and matching from the
last match until all are found.

For the regression test, we produce 4096 matches (larger than we expect
we'll ever set MAX_LINE_MATCHES) and make sure we actually get 4096
lines of output with the -o flag.

We'll also make sure that every distinct line is getting its own line
number to detect line metadata not being printed as appropriate along
the way.

PR:		218811
Submitted by:	Kyle Evans <kevans91@ksu.edu>
Reported by:	jbeich
Reviewed by:	cem
Differential Revision:	https://reviews.freebsd.org/D10577
2017-05-20 03:51:31 +00:00
Ed Maste
9a1452026e bsdgrep: fix segfault with --mmap
r313948 partially fixed --mmap behavior but was incomplete.  This commit
generally reverts it and does it the more correct way- by just consuming
the rest of the buffer and moving on.

PR:		219402
Submitted by:	Kyle Evans <kevans91@ksu.edu>
Reviewed by:	cem
Differential Revision:	https://reviews.freebsd.org/D10820
2017-05-20 00:42:47 +00:00
Ed Maste
b5fc583c27 bsdgrep: don't allow negative -A / -B / -C
Previously, when given a negative -A/-B/-C argument bsdgrep would
overflow the respective context flag(s) and exhibited surprising
behavior.

Fix this by removing unsignedness of Aflag/Bflag and erroring out if
we're given a value < 0.  Also adjust the type used to track 'tail'
context in procfile() so that it accurately reflects the Aflag value
rather than overflowing and losing trailing context.

This also fixes an inconsistency previously existing between -n and
-C "n" behavior.  They are now both limited to LLONG_MAX, to be
consistent.

Add some test cases to make sure grep errors out properly for both
negative context values as well as non-numeric context values rather
than giving bogus matches.

Submitted by:	Kyle Evans <kevans91@ksu.edu>
Reviewed by:	cem
Differential Revision:	https://reviews.freebsd.org/D10675
2017-05-15 17:51:01 +00:00
Bryan Drewery
07676084ec DIRDEPS_BUILD: Update dependencies.
Sponsored by:	Dell EMC Isilon
2017-05-09 01:48:23 +00:00
Ed Maste
e2127de812 bsdgrep: don't ouptut matches with -c, -l, -L
Refactoring done in r317703 broke -c, -l, and -L flags implying
suppression of match printing.  Fortunately this is just a matter of not
doing any printing of the resulting matches and context printing was not
broken in this refactoring.

Add some regression tests since this area may still see further
refactoring, include different context flags as well even though they
were not broken in this case.

PR:		219077
Submitted by:	Kyle kevans91@ksu.edu
Reported by:	markj
Reviewed by:	cem, ngie
Differential Revision:	https://reviews.freebsd.org/D10607
2017-05-05 17:35:05 +00:00
Ed Maste
83fd8885c4 bsdgrep: correct uninitialized variable introduced in r317703
CID:		1374747
Submitted by:	Kyle Evans <kevans91@ksu.edu>
2017-05-03 13:47:02 +00:00
Ed Maste
476d209821 bsdgrep: avoid use of magic number for REG_NOSPEC
Submitted by:	Kyle Evans <kevans91 at ksu.edu>
Differential Revision:	https://reviews.freebsd.org/D10420
2017-05-02 21:08:38 +00:00
Ed Maste
41e04e8c77 bsdgrep: fix escape map building for multibyte strings
In BSD grep, fix escape map building in the regex parser. It was
previously using memory not explicitly initialized, and the MBS escape
map was being built based on a version of the pattern with escapes
already parsed out.

This is Kyle's change, but I restored the broken style that already
exists in this file.

Submitted by:	Kyle Evans <kevans91 at ksu.edu>
Reviewed by:	cem, Kyle Evans (my style changes)
Differential Revision:	https://reviews.freebsd.org/D10098
2017-05-02 20:44:06 +00:00
Ed Maste
a4f3f02be6 bsdgrep: fix -w flag matching with an empty pattern
-w flag matching with an empty pattern was generally 'broken', allowing
matches to occur on any line whether or not it actually matches -w
criteria.

This fix required a good amount of refactoring to address.  procline()
is altered to *only* process the line and return whether it was a match
or not, necessary to be able to short-circuit the whole function in case
of this matchall flag. -m flag handling is moved out as well because it
suffers from the same fate as context handling if we bypass any actual
pattern matching.

The matching context (matches, mostly) didn't previously exist outside
of procline(), so we go ahead and create context object for file
processing bits to pass around.  grep_printline() was created due to
this, for the scenarios where the matches don't actually matter and we
just want to print a line or two, a la flushing the context queue and
no -o or --color specified.

Damage from this broken behavior would have been mitigated by the fact
that it is unlikely users would invoke grep -w with an empty pattern.

This was identified while checking PR 105221 for problems it this may
cause in BSD grep, but PR 105221 is *not* a report of this behavior.

Submitted by:	Kyle Evans <kevans91 at ksu.edu>
Differential Revision:	https://reviews.freebsd.org/D10433
2017-05-02 20:39:33 +00:00
Ed Maste
a535623c78 bsdgrep: correct test sense from r317700
Kyle's change in review D10098 was correct. I introduced the error when
extracting a portion of that change.
2017-05-02 20:08:04 +00:00
Ed Maste
e0780d5479 bsdgrep: use calloc where appropriate in grep's tre-fastmatch
Also apply style(9) to a related NULL check.

Submitted by:	Kyle Evans <kevans91 at ksu.edu> (D10098)
2017-05-02 19:56:42 +00:00
Ed Maste
f76958b1c2 bsdgrep: correct nls usage data after r317049
r317049 added -z/--null-data to BSD grep but missed the update to nls
catalogs.

Submitted by:	Kyle Evans <kevans91 at ksu.edu>
Differential Revision:	https://reviews.freebsd.org/D10456
2017-05-02 13:47:15 +00:00
Ed Maste
cc41ba26bb bsdgrep: Add GNU compatible version string indicator
As reported in r218614 it's useful to have an indication of whether or not
BSD grep was built with GNU_GREP_COMPAT.

Submitted by:	Kyle Evans <kevans91 at ksu.edu>
Reported by:	mandree
Differential Revision:	https://reviews.freebsd.org/D10451
2017-05-02 13:38:20 +00:00
Ed Maste
945fc991b2 bsdgrep: fix -w -v matching improperly with certain patterns
-w and -v flag matching was mostly functional but had some minor
problems:

1. -w flag processing only allowed one iteration through pattern
   matching on a line. This was problematic if one pattern could match
   more than once, or if there were multiple patterns and the earliest/
   longest match was not the most ideal, and

2. Previous work "fixed" things to not further process a line if the
   first iteration through patterns produced no matches. This is clearly
   wrong if we're dealing with the more restrictive -w matching.

#2 breakage could have also occurred before recent broad rewrites, but
it would be more arbitrary based on input patterns as to whether or not
it actually affected things.

Fix both of these by forcing a retry of the patterns after advancing
just past the start of the first match if we're doing more restrictive
-w matching and we didn't get any hits to start with. Also move -v flag
processing outside of the loop so that we have a greater change to match
in the more restrictive cases. This wasn't strictly wrong, but it could
be a little more error prone.

While here, introduce some regressions tests for this behavior and fix
some excessive wrapping nearby that hindered readability. GNU grep
passes these new tests.

PR:		218467, 218811
Submitted by:	Kyle Evans <kevans91 at ksu.edu>
Reviewed by:	cem, ngie
Differential Revision:	https://reviews.freebsd.org/D10329
2017-05-02 02:32:10 +00:00
Enji Cooper
22c00e3b85 Only expect :grep_r_implied to pass with bsdgrep(1)
The test fails with gnu grep from base and ports.

Sponsored by:	Dell EMC Isilon
2017-04-22 21:40:31 +00:00
Ed Maste
3f39ffc893 bsdgrep: add BSD_GREP_FASTMATCH knob for built-in fastmatch
Bugs have been found in the fastmatch implementation as used in bsdgrep.
Some have been fixed (r316495) while fixes for others are in review
(D10098).

In comparison with the fastmatch implementation, Kyle Evans found that:

- regex(3)'s performance with literal expressions offers a speed
  improvement over fastmatch

- regex(3)'s performance, both with simple BREs and EREs, seems to be
  comparable

The regex implementation was imported in r226035, and the commit message
reports:

    This is a temporary solution until the whole regex library is
    not replaced so that BSD grep development can continue and the
    backported code gets some review and testing. This change only
    improves scalability slightly, there is no big performance boost
    yet but several minor bugs have been found and fixed.

Introduce a WITH_/WITHOUT_BSD_GREP_FASTMATCH knob to support testing
of both approaches.

PR:		175314, 194823
Submitted by:	Kyle Evans <kevans91 at ksu.edu>
Reviewed by:	bdrewery (in part)
Differential Revision:	https://reviews.freebsd.org/D10282
2017-04-21 14:36:09 +00:00
Ed Maste
e06ffa3230 bsdgrep: fix zero-length matches without the -o flag
r316477 broke zero-length matches when not using the -o flag, by
skipping over them entirely.

Add a regression test so that it doesn't break again in the future.

Submitted by:	Kyle Evans <kevans91 at ksu.edu>
Reviewed by:	cem emaste ngie
Differential Revision:	https://reviews.freebsd.org/D10333
2017-04-17 14:59:55 +00:00
Ed Maste
22130a21ba bsdgrep: remove output separators between overlapping segments
Make bsdgrep more sensitive to context overlaps.  If it's printing
context that either overlaps or is immediately adjacent to another bit
of context, don't print a separator.

- Non-overlapping segments no longer have two separators between them

- Overlapping segments no longer have separators between them with
  overlapping sections repeated

Submitted by:	Kyle Evans <kevans91 at ksu.edu>
Reviewed by:	cem
Differential Revision:	https://reviews.freebsd.org/D10105
2017-04-17 13:36:30 +00:00
Ed Maste
a461896a2f bsdgrep: for -r, use the working directory if none specified
This is more sensible than the previous behaviour of grepping stdin,
and matches newer GNU grep behaviour.

PR:		216307
Submitted by:	Kyle Evans <kevans91 at ksu.edu>
Reviewed by:	cem, emaste, ngie
Relnotes:	Yes
Differential Revision:	https://reviews.freebsd.org/
2017-04-17 13:22:39 +00:00
Ed Maste
5ee1ea02fd bsdgrep: add -z/--null-data support
-z treats input and output data as sequences of lines terminated by a
zero byte instead of a newline. This brings it more in line with GNU grep
and brings us closer to passing the current tests with BSD grep.

Submitted by:	Kyle Evans <kevans91 at ksu.edu>
Reviewed by:	cem
Relnotes:	Yes
Differential Revision:	https://reviews.freebsd.org/D10101
2017-04-17 13:14:18 +00:00
Ed Maste
d204af1e41 bsdgrep: Handle special case of single-byte NUL pattern
PR:		202022
Submitted by:	Kyle Evans <kevans91 at ksu.edu>
MFC after:	1 month
Differential Revision:	https://reviews.freebsd.org/D10102
2017-04-05 20:11:05 +00:00
Ed Maste
799c5faa8b bsdgrep: create additional tests for coverage on recent fixes
Create additional tests to cover regressions that were discovered by
PRs linked to reviews D10098, D10102, and D10104.

It is worth noting that neither bsdgrep(1) nor gnugrep(1) in the base
system currently pass all of these tests, and gnugrep(1) not quite being
up to snuff was also noted in at least one of the PRs.

PR:		175314 202022 195763 180990 197555 197531 181263 209116
Submitted by:	Kyle Evans <kevans91@ksu.edu>
Reviewed by:	cem, ngie, emaste
MFC after:	1 month
Differential Revision:	https://reviews.freebsd.org/D10112
2017-04-05 18:41:44 +00:00
Conrad Meyer
f48d142551 bsdgrep(1): Fix errors with invalid expressions
Invalid expressions with an ultimate compiled pattern length of 0 (e.g.,
"grep -E {") were not taken into account and caused a segfault while trying
to fill in the good suffix table.

Submitted by:	Kyle Evans <kevans91 at ksu.edu>
Reviewed by:	me
Differential Revision:	https://reviews.freebsd.org/D10113
2017-04-04 17:05:37 +00:00
Conrad Meyer
5dc41cb0f2 bsdgrep(1): Rip out "xmalloc" bits
xmalloc was a debug malloc implementation, but the x{malloc,calloc,free}
functions default to calling the malloc(3) equivalents.

Instead of relying on this malloc shim, we can devise better ways to debug
malloc issues that aren't misleading upon initial inspection.  (I.e., using
jemalloc's various built-in debugging capabilities.)

Submitted by:	Kyle Evans <kevans91 at ksu.edu>
Reviewed by:	emaste, cem
Differential Revision:	https://reviews.freebsd.org/D10269
2017-04-04 16:08:51 +00:00
Ed Maste
a5ed868511 bsdgrep: revert color changes from r316477
r316477 changed the color output to match exactly the in-tree GNU grep,
but introduces unnecessary escape sequences.

Submitted by:	Kyle Evans <kevans91 at ksu.edu>
Reported by:	ache
MFC after:	1 month
MFC with:	r316477
2017-04-04 14:17:50 +00:00
Ed Maste
a734ae9c14 bsdgrep: Initialize vars to avoid a false positive GCC warning
Reported by:	lwhsu
MFC after:	1 month
MFC with:	r316477
2017-04-04 13:34:19 +00:00
Conrad Meyer
bf10f246fe bsdgrep(1): create rgrep link
Create a convenience rgrep link for bsdgrep(1) that observes 'grep -r'
behavior.

A follow-up to r316473.

Submitted by:	Kyle Evans <kevans91 at ksu.edu>
Reviewed by:	emaste (earlier version), cem
Differential Revision:	https://reviews.freebsd.org/D10109
2017-04-04 05:56:42 +00:00
Ed Maste
87c485cfb5 bsdgrep: fix matching behaviour
- Set REG_NOTBOL if we've already matched beginning of line and we're
  examining later parts

- For each pattern we examine, apply it to the remaining bits of the
  line rather than (potentially) smaller subsets

- Check for REG_NOSUB after we've looked at all patterns initially
  matching the line

- Keep track of the last match we made to later determine if we're
  simply not matching any longer or if we need to proceed another byte
  because we hit a zero-length match

- Match the earliest and longest bit of each line before moving the
  beginning of what we match to further in the line, past the end of the
  longest match; this generally matches how gnugrep(1) seems to behave,
  and seems like pretty good behavior to me

- Finally, bail out of printing any matches if we were set to print all
  (empty pattern) but -o (output matches) was set

PR:		195763, 180990, 197555, 197531, 181263, 209116
Submitted by:	"Kyle Evans" <kevans91@ksu.edu>
Reviewed by:	cem
MFC after:	1 month
Relnotes:	Yes
Differential Revision:	https://reviews.freebsd.org/D10104
2017-04-03 23:16:51 +00:00
Ed Maste
491b8b1623 bsdgrep: treat rgrep as grep -r
Submitted by:	   Kyle Evans <kevans91@ksu.edu>
2017-04-03 21:10:02 +00:00
Ed Maste
6b91f51703 bsdgrep: document ignored option -u
MSDOS and Windows GNU grep uses -u to mean "print byte offsets as if
running on an UNIX system." The option has no effect on systems that
do not use CRLF line endings.

PR:		171200
Submitted by:	deeptech71@gmail.com, Anders Jensen-Waud
MFC after:	1 month
2017-02-19 17:40:24 +00:00
Ed Maste
5dff7be120 bsdgrep: fix EOF handling with --mmap
Rework part of the loop in grep_fgetln to return the rest of the line
and ensure that we still advance the buffer by the length of the rest
of the line.

PR:		165471
Submitted by:	Kyle Evans <kevans91@ksu.edu>
MFC after:	1 month
2017-02-19 17:23:27 +00:00
Dimitry Andric
00f060000f Fix a segfault in bsdgrep when parsing the invalid extended regexps "?"
or "+" (these are invalid, because there is no preceding operand).

When bsdgrep attempts to emulate GNU grep in discarding and ignoring the
invalid ? or + operators, some later logic in tre_compile_fast() goes
beyond the end of the buffer, leading to a crash.

Fix this by bailing out, and reporting a bad pattern instead.

Reported by:	Steve Kargl
MFC after:	1 week
2016-08-02 20:25:22 +00:00
Baptiste Daroussin
a43d43d574 Remove usage of _WITH_GETLINE from usr.bin 2016-07-30 01:07:47 +00:00
Ed Schouten
33f5799a81 Call basename() in a portable way.
Pull a copy of the filename string before calling basename(). Change the
loop to not return on its own, so we can put a free() statement at the
bottom.
2016-07-28 15:19:47 +00:00
Enji Cooper
430f7286a5 Merge ^/user/ngie/release-pkg-fix-tests to unbreak how test files are installed
after r298107

Summary of changes:

- Replace all instances of FILES/TESTS with ${PACKAGE}FILES. This ensures that
  namespacing is kept with FILES appropriately, and that this shouldn't need
  to be repeated if the namespace changes -- only the definition of PACKAGE
  needs to be changed
- Allow PACKAGE to be overridden by callers instead of forcing it to always be
  `tests`. In the event we get to the point where things can be split up
  enough in the base system, it would make more sense to group the tests
  with the blocks they're a part of, e.g. byacc with byacc-tests, etc
- Remove PACKAGE definitions where possible, i.e. where FILES wasn't used
  previously.
- Remove unnecessary TESTSPACKAGE definitions; this has been elided into
  bsd.tests.mk
- Remove unnecessary BINDIRs used previously with ${PACKAGE}FILES;
  ${PACKAGE}FILESDIR is now automatically defined in bsd.test.mk.
- Fix installation of files under data/ subdirectories in lib/libc/tests/hash
  and lib/libc/tests/net/getaddrinfo
- Remove unnecessary .include <bsd.own.mk>s (some opportunistic cleanup)

Document the proposed changes in share/examples/tests/tests/... via examples
so it's clear that ${PACKAGES}FILES is the suggested way forward in terms of
replacing FILES. share/mk/bsd.README didn't seem like the appropriate method
of communicating that info.

MFC after: never probably
X-MFC with: r298107
PR: 209114
Relnotes: yes
Tested with: buildworld, installworld, checkworld; buildworld, packageworld
Sponsored by: EMC / Isilon Storage Division
2016-05-04 23:20:53 +00:00
Glen Barber
538354481e MFH
Sponsored by:	The FreeBSD Foundation
2016-03-14 18:54:29 +00:00
Ian Lepore
79b05c7ff0 Fix a bug in bsdgrep that caused the program to hang in a tight loop for
some combinations of command line options and search patterns.  The code was
examining regexec flags looking for a regcomp flag value.  The fix is to
look in the struct field where the decoded regcomp flag was stored when the
regex was compiled.

With this fix, it's possible to build WITHOUT_GNU_GREP_COMPAT and
WITH_BSDGREP and have a usable GPL-free grep (which of course lacks gnugrep
extensions).  It now passes the kyua tests except for one test that requires
the -z/--null-data gnu extension, and one test involving outputting context
lines across multiple files which appears to sometimes output an extra
delimiter line ("--") between matches (a rather obscure failure of a rather
obscure feature, so bsdgrep should be generally usable now).
2016-03-13 14:53:12 +00:00
Glen Barber
7d536dc855 MFH
Sponsored by:	The FreeBSD Foundation
2016-03-10 21:16:01 +00:00
Bryan Drewery
15c433351f DIRDEPS_BUILD: Connect MK_TESTS.
Sponsored by:	EMC / Isilon Storage Division
2016-03-09 22:46:01 +00:00
Glen Barber
43faedc133 First pass to fix the 'tests' packages.
Sponsored by:	The FreeBSD Foundation
2016-02-02 22:26:49 +00:00
Enji Cooper
b2d48be1bc Refactor the test/ Makefiles after recent changes to bsd.test.mk (r289158) and
netbsd-tests.test.mk (r289151)

- Eliminate explicit OBJTOP/SRCTOP setting
- Convert all ad hoc NetBSD test integration over to netbsd-tests.test.mk
- Remove unnecessary TESTSDIR setting
- Use SRCTOP where possible for clarity

MFC after: 2 weeks
Sponsored by: EMC / Isilon Storage Divison
2015-10-12 08:16:03 +00:00
Pedro F. Giffuni
3c0948a6b2 Bump GCC max-inline-insns-single in libiconv_modules and grep
This is required by our FORTIFY_SOURCE implementation as it
does more inlining. As a rule of thumb, FORTIFY_SOURCE doubles
the number  of inlines except that in grep inlining
blows up for some reason.
2015-07-26 00:11:04 +00:00
Simon J. Gerraty
2ef6d5a7b9 new depends 2015-06-16 23:37:19 +00:00
Simon J. Gerraty
ccfb965433 Add META_MODE support.
Off by default, build behaves normally.
WITH_META_MODE we get auto objdir creation, the ability to
start build from anywhere in the tree.

Still need to add real targets under targets/ to build packages.

Differential Revision:       D2796
Reviewed by: brooks imp
2015-06-13 19:20:56 +00:00
Simon J. Gerraty
87750562a1 Avoid bogus MLINKS when MK_LZMA_SUPPORT=yes and MK_BSD_GREP=no 2015-06-08 23:37:17 +00:00
Simon J. Gerraty
44d314f704 dirdeps.mk now sets DEP_RELDIR 2015-06-08 23:35:17 +00:00
Simon J. Gerraty
98e0ffaefb Merge sync of head 2015-05-27 01:19:58 +00:00
Pedro F. Giffuni
2fa7a2afac bsdgrep: fix regression in the -f option since r268799
Caused by an incomplete merge from NetBSD.

PR:		198725
MFC after:	3 days
2015-03-21 00:21:30 +00:00
Enji Cooper
b7c2ba84c9 Create MANLINKS for lzgrep, etc when MK_LZMA_SUPPORT != no
MFC after: 3 days
Sponsored by: EMC / Isilon Storage Division
2015-01-30 18:07:46 +00:00
Xin LI
a5e43ff69e Fix xz handling for files larger than 32K.
Submitted by:	Stefan Ehmann <shoesoft gmx net>
PR:		bin/186861
MFC after:	2 weeks
2015-01-21 01:11:37 +00:00
Will Andrews
7a37b5fc17 Add a ${CP} alias for copying files in the build.
Some users build FreeBSD as non-root in Perforce workspaces.  By default,
Perforce sets files read-only unless they're explicitly being edited.
As a result, the -f argument must be used to cp in order to override the
read-only flag when copying source files to object directories.  Bare use of
'cp' should be avoided in the future.

Update all current users of 'cp' in the src tree.

Reviewed by:	emaste
MFC after:	1 week
Sponsored by:	Spectra Logic
2015-01-16 21:39:08 +00:00
Baptiste Daroussin
3e11bd9e2a Convert to usr.bin/ to LIBADD
Reduce overlinking
2014-11-25 14:29:10 +00:00
Simon J. Gerraty
9268022b74 Merge from head@274682 2014-11-19 01:07:58 +00:00
Enji Cooper
1e7075e0a4 Integrate usr.bin/grep/tests from NetBSD into atf/kyua
Sponsored by: EMC / Isilon Storage Division
2014-10-09 01:53:23 +00:00
Pedro F. Giffuni
55a803b32a bsdgrep: Work-around for segmentation fault.
Fix by David Carlier.

Obtained from:	HardenedBSD
PR:		167921
MFC after:	1 month
2014-09-25 19:22:26 +00:00
Will Andrews
76479f1d3f Fix incremental builds involving non-root users with read-only source files.
Makefiles should not assume that source files can be overwritten.  This is the
common case for Perforce source trees.

This is a followup commit to r211243 in the same vein.

MFC after:	1 month
Sponsored by:	Spectra Logic
MFSpectraBSD:	r1036319 on 2014/01/29, r1046711 on 2014/03/06
2014-09-18 14:41:57 +00:00
Simon J. Gerraty
ee7b0571c2 Merge head from 7/28 2014-08-19 06:50:54 +00:00
Gabor Kovesdan
2ac5b1c763 - Do not look for more matching lines if -L is specified
Submitted by:   eadler (based on)
MFC after:	2 weeks
2014-08-18 12:29:28 +00:00
Pedro F. Giffuni
8e5fc70f15 grep: fix some memory leaks.
Add memory leak fix missing from r268799.

Obtained from:	NetBSD
2014-07-17 15:59:13 +00:00
Pedro F. Giffuni
f3f50de623 grep: fix some memory leaks.
Bring a couple of changes from NetBSD:

queue.c (CVS Rev. 1.4. 1.5)
Fix memory leaks.
NULL does not need a cast.

grep.c (CVS Rev. 1.6)
Use the more portable getline.

Obtained from:	NetBSD
MFC after:	3 days
2014-07-17 15:48:11 +00:00
Pedro F. Giffuni
78bef01fe4 grep: Fix type.
Obtained from:	NetBSD (CVS rev. 1.17)
MFC after:	3 days
2014-07-17 14:51:50 +00:00
Glen Barber
66edec08b0 Fix a bug in bsdgrep(1) where patterns are not correctly
detected.

Certain criteria must be met for this bug to show up:

 * the -w flag is specified, and
 * neither -o or --color are specified, and
 * the pattern is part of another word in the line, and
 * the other word that contains the pattern occurs first

PR:		181973
MFC after:	3 days
Sponsored by:	The FreeBSD Foundation
2014-06-20 21:53:50 +00:00
Simon J. Gerraty
fae50821ae Updated dependencies 2014-05-16 14:09:51 +00:00
Simon J. Gerraty
76b28ad6ab Updated dependencies 2014-05-10 05:16:28 +00:00
Simon J. Gerraty
cc3f4b9965 Merge from head 2014-05-08 23:54:15 +00:00
Warner Losh
c6063d0da8 Use src.opts.mk in preference to bsd.own.mk except where we need stuff
from the latter.
2014-05-06 04:22:01 +00:00
Simon J. Gerraty
3b8f084595 Merge head 2014-04-28 07:50:45 +00:00
Pedro F. Giffuni
b1a409863f Various style(9) fixes and typos in grep, sort and patch.
MFC after:	3 days
2014-04-21 22:52:18 +00:00
Warner Losh
74b229cb2b Don't test WITHOUT_FOO in program makefiles, test MK_FOO instead. 2014-04-01 14:24:32 +00:00
Joel Dahl
7e700c30d2 mdoc: minor paragraph fixes. 2014-02-08 13:37:02 +00:00
Simon J. Gerraty
d1d0158641 Merge from head 2013-09-05 20:18:59 +00:00
Andrey A. Chernov
f1135552c6 grep -i does not work for simple patterns and single byte locales, like
LANG=ru_RU.KOI8-R grep -i <some single KOI8-R letter>
Fix it.

MFC after:      3 days
2013-07-30 18:16:43 +00:00
Jung-uk Kim
ee852b9c75 Adjust CFLAGS to pick up correct regex.h and posix/regex.h. Note this
actually reverts r250860 and r250861.

Reported by:	gjb, tinderbox
2013-06-06 11:59:38 +00:00
Mark Johnston
e16c1e1fd2 Revert r246917, as it is causing incorrect behaviour as reported on
freebsd-current.

PR:		bin/175213
Approved by:	emaste (co-mentor)
2013-03-12 19:18:10 +00:00
Simon J. Gerraty
7cf3a1c6b2 Updated dependencies 2013-03-11 17:21:52 +00:00
Mark Johnston
43e1adfa05 Strengthen the check in IS_OUT_OF_BOUNDS to ensure that (j - 1) is a
valid index into the input buffer.

PR:		bin/175213
Reviewed by:	gabor
Approved by:	emaste (co-mentor)
MFC after:	1 week
2013-02-17 19:48:23 +00:00
Simon J. Gerraty
f5f7c05209 Updated dependencies 2013-02-16 01:23:54 +00:00
David E. O'Brien
d9a447559b Sync with HEAD. 2013-02-08 16:10:16 +00:00
Gabor Kovesdan
cd64c5881d - Avoid unnecessary strdup()
Submitted by:	ache
MFC after:	5 days
2013-01-20 11:58:49 +00:00
David E. O'Brien
9b6b681624 Following r226271, allow disabling lzma support with "WITHOUT_LZMA_SUPPORT".
Correct r226271 which should have used WITHOUT_BZIP2_SUPPORT per r166255.

Obtained from:	Juniper Networks
2013-01-08 18:37:12 +00:00
Mark Johnston
f46b2b9f64 Fix a segfault when bsdgrep -i is given an empty pattern string.
PR:		bin/172865
Reviewed by:	gabor
Approved by:	emaste (co-mentor)
MFC after:	1 week
2013-01-05 22:04:40 +00:00
Gabor Kovesdan
e411593d4b - Fix handling of the case when multiple patterns are specified in a single
command line argument, separated by newlines

PR:		bin/173673
Submitted by:	ache
MFC after:	1 week
2013-01-05 14:52:31 +00:00
Eitan Adler
924500b74d Make bsdgrep behave as gnugrep and as documented: -m should only stop
reading the specific file, not any file.

Tested by:	frogs (irc)
Reviewed by:	gabor
Approved by:	cperciva (implicit)
MFC after:	1 week
2012-12-20 17:38:14 +00:00
Simon J. Gerraty
23090366f7 Sync from head 2012-11-04 02:52:03 +00:00
Ed Schouten
bf70becee6 More -Wmissing-variable-declarations fixes.
In addition to adding `static' where possible:

- bin/date: Move `retval' into extern.h to make it visible to date.c.
- bin/ed: Move globally used variables into ed.h.
- sbin/camcontrol: Move `verbose' into camcontrol.h and fix shadow warnings.
- usr.bin/calendar: Remove unneeded variables.
- usr.bin/chat: Make `line' local instead of global.
- usr.bin/elfdump: Comment out unneeded function.
- usr.bin/rlogin: Use _Noreturn instead of __dead2.
- usr.bin/tset: Pull `Ospeed' into extern.h.
- usr.sbin/mfiutil: Put global variables in mfiutil.h.
- usr.sbin/pkg: Remove unused `os_corres'.
- usr.sbin/quotaon, usr.sbin/repquota: Remove unused `qfname'.
2012-10-19 14:49:42 +00:00
Marcel Moolenaar
7750ad47a9 Sync FreeBSD's bmake branch with Juniper's internal bmake branch.
Requested by: Simon Gerraty <sjg@juniper.net>
2012-08-22 19:25:57 +00:00
Eitan Adler
63491e82be Remove duplicate line from usage
PR:		bin/164139
Submitted by:	Yuri Pankov <yuri.pankov@gmail.com>
Approved by:	nwhitehorn
MFC after:	3 days
2012-01-15 17:01:28 +00:00
Ed Schouten
8375d51296 Add missing "static const" to long options table.
This table is only used in this C file and passed to getopt_long(), so
we can safely add static and const to it.
2011-12-10 18:21:03 +00:00