aboutsummaryrefslogtreecommitdiff
path: root/toys/pending
diff options
context:
space:
mode:
authorM. Farkas-Dyck <strake888@gmail.com>2013-08-01 15:46:45 -0500
committerM. Farkas-Dyck <strake888@gmail.com>2013-08-01 15:46:45 -0500
commit1fa68247345fa6e2cefe4fb4d88ef75f614b18c4 (patch)
treedd8203ea3a7c8a36991636eef3eb43564d27dcc4 /toys/pending
parent3595eff0bfb6fd66f990d872ed16a5d565c77fc5 (diff)
downloadtoybox-1fa68247345fa6e2cefe4fb4d88ef75f614b18c4.tar.gz
Found the fault. My method of -w fails sans -E, so I just disallow it.
Kernel build never uses -w sans -E anyhow.
Diffstat (limited to 'toys/pending')
-rw-r--r--toys/pending/grep.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/toys/pending/grep.c b/toys/pending/grep.c
index ae38988f..8810580b 100644
--- a/toys/pending/grep.c
+++ b/toys/pending/grep.c
@@ -46,7 +46,7 @@ GLOBALS(
)
static void do_grep (int fd, char *name) {
- int n = 0, nMatch = 0;
+ int n = 0, nMatch = 0, which = toys.optflags & FLAG_w ? 2 : 0;
for (;;) {
char *x, *y;
@@ -75,11 +75,11 @@ static void do_grep (int fd, char *name) {
if (!(toys.optflags & FLAG_h)) printf ("%s:", name);
if ( (toys.optflags & FLAG_n)) printf ("%d:", n);
if ( (toys.optflags & FLAG_b)) printf ("%ld:", lseek (0, 0, SEEK_CUR) - strlen (y) +
- (toys.optflags & FLAG_o ? matches[2].rm_so : 0));
+ (toys.optflags & FLAG_o ? matches[which].rm_so : 0));
if (!(toys.optflags & FLAG_o)) fputs (x, stdout);
else {
- y += matches[2].rm_so;
- printf ("%.*s\n", matches[2].rm_eo - matches[2].rm_so, y++);
+ y += matches[which].rm_so;
+ printf ("%.*s\n", matches[which].rm_eo - matches[which].rm_so, y++);
}
}
if (!(toys.optflags & FLAG_o)) break;
@@ -145,7 +145,7 @@ void buildRE (void) {
toys.optc--; toys.optargs++;
}
- TT.re_xs = xmsprintf (toys.optflags & FLAG_w ? "(^|[^_[:alnum:]])(%s)($|[^_[:alnum:]])" : "()(%s)()", TT.re_xs);
+ TT.re_xs = xmsprintf (toys.optflags & FLAG_w ? "(^|[^_[:alnum:]])(%s)($|[^_[:alnum:]])" : "%s", TT.re_xs);
if (regcomp (&re, TT.re_xs,
(toys.optflags & (FLAG_E | FLAG_F) ? REG_EXTENDED : 0) |
@@ -156,6 +156,8 @@ void buildRE (void) {
}
void grep_main (void) {
+ if (toys.optflags & FLAG_w && !(toys.optflags & FLAG_E || toys.optflags & FLAG_F)) error_exit ("must not use -w sans -E");
+
buildRE ();
if (toys.optflags & FLAG_c) TT.mode = 'c';