aboutsummaryrefslogtreecommitdiff
path: root/usr.bin/grep
Commit message (Collapse)AuthorAgeFilesLines
* bsdgrep: fix -w -v matching improperly with certain patternsEd Maste2017-05-021-3/+24
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | -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 Notes: svn path=/head/; revision=317665
* Only expect :grep_r_implied to pass with bsdgrep(1)Enji Cooper2017-04-221-2/+36
| | | | | | | | | The test fails with gnu grep from base and ports. Sponsored by: Dell EMC Isilon Notes: svn path=/head/; revision=317300
* bsdgrep: add BSD_GREP_FASTMATCH knob for built-in fastmatchEd Maste2017-04-214-9/+34
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 Notes: svn path=/head/; revision=317254
* bsdgrep: fix zero-length matches without the -o flagEd Maste2017-04-171-3/+3
| | | | | | | | | | | | | | 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 Notes: svn path=/head/; revision=317052
* bsdgrep: remove output separators between overlapping segmentsEd Maste2017-04-171-6/+27
| | | | | | | | | | | | | | | | | | 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 Notes: svn path=/head/; revision=317051
* bsdgrep: for -r, use the working directory if none specifiedEd Maste2017-04-174-2/+61
| | | | | | | | | | | | | | 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/ Notes: svn path=/head/; revision=317050
* bsdgrep: add -z/--null-data supportEd Maste2017-04-175-10/+21
| | | | | | | | | | | | | | -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 Notes: svn path=/head/; revision=317049
* bsdgrep: Handle special case of single-byte NUL patternEd Maste2017-04-051-1/+5
| | | | | | | | | | PR: 202022 Submitted by: Kyle Evans <kevans91 at ksu.edu> MFC after: 1 month Differential Revision: https://reviews.freebsd.org/D10102 Notes: svn path=/head/; revision=316542
* bsdgrep: create additional tests for coverage on recent fixesEd Maste2017-04-051-0/+16
| | | | | | | | | | | | | | | | | | 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 Notes: svn path=/head/; revision=316536
* bsdgrep(1): Fix errors with invalid expressionsConrad Meyer2017-04-041-2/+2
| | | | | | | | | | | | | 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 Notes: svn path=/head/; revision=316495
* bsdgrep(1): Rip out "xmalloc" bitsConrad Meyer2017-04-046-463/+31
| | | | | | | | | | | | | | | | 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 Notes: svn path=/head/; revision=316492
* bsdgrep: revert color changes from r316477Ed Maste2017-04-041-2/+2
| | | | | | | | | | | | | 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 Notes: svn path=/head/; revision=316491
* bsdgrep: Initialize vars to avoid a false positive GCC warningEd Maste2017-04-041-0/+3
| | | | | | | | | Reported by: lwhsu MFC after: 1 month MFC with: r316477 Notes: svn path=/head/; revision=316489
* bsdgrep(1): create rgrep linkConrad Meyer2017-04-042-1/+7
| | | | | | | | | | | | | | 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 Notes: svn path=/head/; revision=316484
* bsdgrep: fix matching behaviourEd Maste2017-04-031-17/+52
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - 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 Notes: svn path=/head/; revision=316477
* bsdgrep: treat rgrep as grep -rEd Maste2017-04-031-0/+3
| | | | | | | Submitted by: Kyle Evans <kevans91@ksu.edu> Notes: svn path=/head/; revision=316473
* bsdgrep: document ignored option -uEd Maste2017-02-191-0/+2
| | | | | | | | | | | | | 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 Notes: svn path=/head/; revision=313955
* bsdgrep: fix EOF handling with --mmapEd Maste2017-02-191-5/+11
| | | | | | | | | | | | | 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 Notes: svn path=/head/; revision=313948
* Fix a segfault in bsdgrep when parsing the invalid extended regexps "?"Dimitry Andric2016-08-021-1/+1
| | | | | | | | | | | | | | | | 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 Notes: svn path=/head/; revision=303676
* Remove usage of _WITH_GETLINE from usr.binBaptiste Daroussin2016-07-301-1/+0
| | | | Notes: svn path=/head/; revision=303526
* Call basename() in a portable way.Ed Schouten2016-07-281-5/+10
| | | | | | | | | 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. Notes: svn path=/head/; revision=303444
* Merge ^/user/ngie/release-pkg-fix-tests to unbreak how test files are installedEnji Cooper2016-05-041-31/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 Notes: svn path=/head/; revision=299094
* MFHGlen Barber2016-03-141-1/+1
|\ | | | | | | | | | | | | Sponsored by: The FreeBSD Foundation Notes: svn path=/projects/release-pkg/; revision=296869
| * Fix a bug in bsdgrep that caused the program to hang in a tight loop forIan Lepore2016-03-131-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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). Notes: svn path=/head/; revision=296799
* | MFHGlen Barber2016-03-101-0/+11
|\| | | | | | | | | | | | | Sponsored by: The FreeBSD Foundation Notes: svn path=/projects/release-pkg/; revision=296625
| * DIRDEPS_BUILD: Connect MK_TESTS.Bryan Drewery2016-03-091-0/+11
| | | | | | | | | | | | | | Sponsored by: EMC / Isilon Storage Division Notes: svn path=/head/; revision=296587
* | First pass to fix the 'tests' packages.Glen Barber2016-02-021-0/+4
|/ | | | | | | Sponsored by: The FreeBSD Foundation Notes: svn path=/projects/release-pkg/; revision=295171
* Refactor the test/ Makefiles after recent changes to bsd.test.mk (r289158) andEnji Cooper2015-10-121-7/+3
| | | | | | | | | | | | | | | 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 Notes: svn path=/head/; revision=289172
* Bump GCC max-inline-insns-single in libiconv_modules and grepPedro F. Giffuni2015-07-261-0/+2
| | | | | | | | | | 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. Notes: svn path=/head/; revision=285884
* new dependsSimon J. Gerraty2015-06-161-1/+0
| | | | Notes: svn path=/head/; revision=284481
* Add META_MODE support.Simon J. Gerraty2015-06-132-0/+26
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | 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 Notes: svn path=/head/; revision=284345
| * Avoid bogus MLINKS when MK_LZMA_SUPPORT=yes and MK_BSD_GREP=noSimon J. Gerraty2015-06-081-0/+2
| | | | | | | | Notes: svn path=/projects/bmake/; revision=284173
| * dirdeps.mk now sets DEP_RELDIRSimon J. Gerraty2015-06-081-2/+0
| | | | | | | | Notes: svn path=/projects/bmake/; revision=284172
| * Merge sync of headSimon J. Gerraty2015-05-274-38/+55
| |\ | |/ |/| | | Notes: svn path=/projects/bmake/; revision=283595
| * Merge from head@274682Simon J. Gerraty2014-11-194-3/+48
| |\ | | | | | | | | | Notes: svn path=/projects/bmake/; revision=274683
| * \ Merge head from 7/28Simon J. Gerraty2014-08-194-9/+21
| |\ \ | | | | | | | | | | | | Notes: svn path=/projects/bmake/; revision=270164
| * | | Updated dependenciesSimon J. Gerraty2014-05-161-1/+0
| | | | | | | | | | | | | | | | Notes: svn path=/projects/bmake/; revision=266219
| * | | Updated dependenciesSimon J. Gerraty2014-05-101-0/+2
| | | | | | | | | | | | | | | | Notes: svn path=/projects/bmake/; revision=265802
| * | | Merge from headSimon J. Gerraty2014-05-081-1/+1
| |\ \ \ | | | | | | | | | | | | | | | Notes: svn path=/projects/bmake/; revision=265720
| * \ \ \ Merge headSimon J. Gerraty2014-04-285-34/+34
| |\ \ \ \ | | | | | | | | | | | | | | | | | | Notes: svn path=/projects/bmake/; revision=265044
| * \ \ \ \ Merge from headSimon J. Gerraty2013-09-052-3/+3
| |\ \ \ \ \ | | | | | | | | | | | | | | | | | | | | | Notes: svn path=/projects/bmake/; revision=255263
| * | | | | | Updated dependenciesSimon J. Gerraty2013-03-111-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Notes: svn path=/projects/bmake/; revision=248169
| * | | | | | Updated dependenciesSimon J. Gerraty2013-02-161-2/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Notes: svn path=/projects/bmake/; revision=246868
| * | | | | | Sync with HEAD.David E. O'Brien2013-02-086-11/+36
| |\ \ \ \ \ \ | | | | | | | | | | | | | | | | | | | | | | | | Notes: svn path=/projects/bmake/; revision=246555
| * \ \ \ \ \ \ Sync from headSimon J. Gerraty2012-11-042-5/+6
| |\ \ \ \ \ \ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | Notes: svn path=/projects/bmake/; revision=242545
| * | | | | | | | Sync FreeBSD's bmake branch with Juniper's internal bmake branch.Marcel Moolenaar2012-08-221-0/+23
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Requested by: Simon Gerraty <sjg@juniper.net> Notes: svn path=/projects/bmake/; revision=239572
* | | | | | | | | bsdgrep: fix regression in the -f option since r268799Pedro F. Giffuni2015-03-211-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Caused by an incomplete merge from NetBSD. PR: 198725 MFC after: 3 days Notes: svn path=/head/; revision=280307
* | | | | | | | | Create MANLINKS for lzgrep, etc when MK_LZMA_SUPPORT != noEnji Cooper2015-01-301-7/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | MFC after: 3 days Sponsored by: EMC / Isilon Storage Division Notes: svn path=/head/; revision=277939
* | | | | | | | | Fix xz handling for files larger than 32K.Xin LI2015-01-211-21/+40
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Submitted by: Stefan Ehmann <shoesoft gmx net> PR: bin/186861 MFC after: 2 weeks Notes: svn path=/head/; revision=277463
* | | | | | | | | Add a ${CP} alias for copying files in the build.Will Andrews2015-01-161-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 Notes: svn path=/head/; revision=277273