Commit Graph

46 Commits

Author SHA1 Message Date
sin
875f433666 Argh - include strings.h 2014-11-21 00:03:30 +00:00
sin
ce86a05f36 Import strcasestr() from musl and remove -D_GNU_SOURCE 2014-11-20 23:46:06 +00:00
sin
ea4f58ff02 Include strings.h for strcasecmp 2014-11-20 23:38:02 +00:00
sin
8767e4b320 Properly handle multiline patterns in grep(1)
We should be POSIX compliant now.
2014-11-20 19:56:44 +00:00
sin
b6a41b688b If we have a match any pattern also match against blank lines 2014-11-20 18:20:10 +00:00
sin
f4d8ff9598 Properly handle -F and -i 2014-11-20 17:40:47 +00:00
sin
64aac9b504 Just use int for mode 2014-11-20 17:26:57 +00:00
sin
fe48fbc4e1 Break out on first match 2014-11-20 17:03:09 +00:00
sin
a1844fae70 Implement grep -f 2014-11-20 16:58:32 +00:00
sin
5ba4f37ec3 Handle null BRE/ERE and do not add a pattern to the list if it already exists 2014-11-20 16:46:57 +00:00
sin
7627a5069c Implement grep -x 2014-11-20 14:47:47 +00:00
sin
e34ce44192 Test directly, no need for intermediate assignment 2014-11-20 14:37:59 +00:00
sin
6866bcdec8 Implement grep -F 2014-11-20 14:35:55 +00:00
sin
728f36aa77 Implement grep -s 2014-11-20 14:14:41 +00:00
Evan Gates
84b08427a1 remove agetline 2014-11-18 21:05:28 +00:00
sin
afa2e6ec54 Use SLIST_* instead of TAILQ_* in grep(1)
The order of evaluation is unspecified by POSIX so we do not need
to process the patterns in-order.
2014-11-17 10:59:51 +00:00
Hiltjo Posthuma
f6552e3669 grep: add -h (inverse of -H) aswell 2014-11-17 10:05:10 +00:00
Hiltjo Posthuma
1822f70d12 csplit, grep: use eregcomp 2014-11-16 14:37:10 +00:00
sin
67fcc79046 Use queue.h in grep(1) 2014-11-16 12:39:15 +00:00
Hiltjo Posthuma
865869fb28 grep: add -H flag 2014-11-16 11:23:18 +00:00
FRIGN
e17b9cdd0a Convert codebase to use emalloc.c utility-functions
This also definitely increases readability and makes OOM-conditions
more consistent.
2014-11-16 10:22:39 +00:00
FRIGN
ec8246bbc6 Un-boolify sbase
It actually makes the binaries smaller, the code easier to read
(gems like "val == true", "val == false" are gone) and actually
predictable in the sense of that we actually know what we're
working with (one bitwise operator was quite adventurous and
should now be fixed).

This is also more consistent with the other suckless projects
around which don't use boolean types.
2014-11-14 10:54:20 +00:00
FRIGN
eee98ed3a4 Fix coding style
It was about damn time. Consistency is very important in such a
big codebase.
2014-11-13 18:08:43 +00:00
Michael Forney
6327290cf2 grep: Fix -c flag 2014-11-02 09:46:52 +00:00
Michael Forney
1ca8a314f8 grep: Remove newlines before matching a line
Otherwise, a pattern with a '$' anchor will never match and POSIX says that

  "By default, an input line shall be selected if any pattern ... matches any
   part of the line excluding the terminating <newline>"
2014-11-02 09:46:46 +00:00
Hiltjo Posthuma
97fb4a1f9c grep: improvements
improvements:
- improve statuscode behaviour
  - don't exit if a file in a series fails. exit 2 if an error occured
    in a file series. don't exit if there is a read error (like: grep
     input file is a directory).
- use agetline instead of agets().

with the simple test: time seq 1 100000000 | grep 'a'
its 12 seconds (from 24 seconds) on my machine.

Signed-off-by: Hiltjo Posthuma <hiltjo@codemadness.org>
2014-06-01 18:02:01 +01:00
sin
4896bdf6de Revert "Make grep more memory-efficient"
This reverts commit d9a098ae6bc07188cbaefcd188e5911dec41815d.

Conflicts:
	grep.c

Hiltjo Posthuma <hiltjo@codemadness.org> said:

(Re)compiling the regex for each line doesn't make sense (imho) and
slows it down a lot.

A simple test:

time seq 1 100000000 | grep 'a'

sbase grep (before patch):
    0m22.21s real     0m0.00s user     0m0.00s system

sbase grep (after patch):
    2m16.28s real     0m0.00s user     0m0.00s system

coreutils grep:
    0m1.15s real     0m0.00s user     0m0.00s system

So the patch should be reverted I think.
2014-05-12 12:06:40 +01:00
sin
11eef783fe Declare error buffer at start of block 2014-05-12 00:40:29 +01:00
FRIGN
fb1bfe24bb Make grep more memory-efficient 2014-05-12 00:32:50 +01:00
dwts
459161481a use always static for usage and keep usage definition above main 2014-04-22 14:49:23 +01:00
sin
f526ad099f Implement -e support for grep 2013-10-05 13:51:45 +01:00
Connor Lane Smith
c68bba6867 grep: fix ARGC() 2012-06-09 18:49:02 +01:00
Connor Lane Smith
c2c5ea9c60 grep: ARGBEGIN 2012-05-31 19:38:25 +01:00
Robert Ransom
e6238dda31 grep: Remove trailing newline before trying to match RE
This unbreaks the "$" operator
and some uses of grep with other REs
(e.g. 'grep . TODO' to remove empty lines).
2012-05-22 00:05:03 +00:00
Connor Lane Smith
1360f568bb grep: better regerror message 2012-05-12 18:01:27 +01:00
Connor Lane Smith
cd73d1b330 grep: check regcomp succeeds 2012-05-12 17:54:36 +01:00
Connor Lane Smith
8ec404cdec update cmp, grep 2011-06-18 06:42:24 +01:00
Connor Lane Smith
de221bc6f5 grep: cleanup 2011-06-04 12:00:23 +01:00
Connor Lane Smith
763409841f grep -E 2011-06-04 11:57:31 +01:00
Connor Lane Smith
6427386b02 grep: default REG_NOSUB 2011-05-29 20:38:15 +01:00
Connor Lane Smith
d6a9e35d0b really long lines 2011-05-25 20:40:47 +01:00
Connor Lane Smith
f458397d5a no, getopt.h is gnu specific 2011-05-24 18:58:36 +01:00
pancake
da547fb294 add missing #include <getopt.h>
do not override CC in config.mk
2011-05-24 14:34:26 +02:00
Connor Lane Smith
4c6c379812 handle -- 2011-05-24 11:05:36 +01:00
Connor Lane Smith
9714d7b1d3 getopt 2011-05-24 01:13:34 +01:00
Connor Lane Smith
8e26716a5a initial commit 2011-05-23 02:36:34 +01:00