diff options
author | Ron Yorston <rmy@pobox.com> | 2013-02-07 14:25:54 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2013-02-07 14:25:54 +0000 |
commit | b604585914e032b28bef3e337a978e56a9069cda (patch) | |
tree | b2ee0a3fb38d10397c602d0fe215ea3bbbf334c0 /findutils | |
parent | 0eda07c7ff8cf1fc11bc1bda5383f884d7adf031 (diff) | |
parent | ba76b7a40b929878833731f76306b1c977cc8650 (diff) | |
download | busybox-w32-b604585914e032b28bef3e337a978e56a9069cda.tar.gz busybox-w32-b604585914e032b28bef3e337a978e56a9069cda.tar.bz2 busybox-w32-b604585914e032b28bef3e337a978e56a9069cda.zip |
Merge branch 'busybox' into merge
Diffstat (limited to 'findutils')
-rw-r--r-- | findutils/find.c | 4 | ||||
-rw-r--r-- | findutils/grep.c | 39 |
2 files changed, 35 insertions, 8 deletions
diff --git a/findutils/find.c b/findutils/find.c index b521e5b08..2235b5049 100644 --- a/findutils/find.c +++ b/findutils/find.c | |||
@@ -878,8 +878,8 @@ static action*** parse_params(char **argv) | |||
878 | IF_FEATURE_FIND_EXEC( "-exec\0" ) | 878 | IF_FEATURE_FIND_EXEC( "-exec\0" ) |
879 | IF_FEATURE_FIND_PAREN( "(\0" ) | 879 | IF_FEATURE_FIND_PAREN( "(\0" ) |
880 | /* All options/actions starting from here require argument */ | 880 | /* All options/actions starting from here require argument */ |
881 | "-name\0" | 881 | "-name\0" |
882 | "-iname\0" | 882 | "-iname\0" |
883 | IF_FEATURE_FIND_PATH( "-path\0" ) | 883 | IF_FEATURE_FIND_PATH( "-path\0" ) |
884 | #if ENABLE_DESKTOP | 884 | #if ENABLE_DESKTOP |
885 | IF_FEATURE_FIND_PATH( "-wholename\0") | 885 | IF_FEATURE_FIND_PATH( "-wholename\0") |
diff --git a/findutils/grep.c b/findutils/grep.c index 5b8ae3bff..6b47f4327 100644 --- a/findutils/grep.c +++ b/findutils/grep.c | |||
@@ -352,10 +352,34 @@ static int grep_file(FILE *file) | |||
352 | while (pattern_ptr) { | 352 | while (pattern_ptr) { |
353 | gl = (grep_list_data_t *)pattern_ptr->data; | 353 | gl = (grep_list_data_t *)pattern_ptr->data; |
354 | if (FGREP_FLAG) { | 354 | if (FGREP_FLAG) { |
355 | found |= (((option_mask32 & OPT_i) | 355 | char *match; |
356 | ? strcasestr(line, gl->pattern) | 356 | char *str = line; |
357 | : strstr(line, gl->pattern) | 357 | opt_f_again: |
358 | ) != NULL); | 358 | match = ((option_mask32 & OPT_i) |
359 | ? strcasestr(str, gl->pattern) | ||
360 | : strstr(str, gl->pattern) | ||
361 | ); | ||
362 | if (match) { | ||
363 | if (option_mask32 & OPT_x) { | ||
364 | if (match != str) | ||
365 | goto opt_f_not_found; | ||
366 | if (str[strlen(gl->pattern)] != '\0') | ||
367 | goto opt_f_not_found; | ||
368 | } else | ||
369 | if (option_mask32 & OPT_w) { | ||
370 | char c = (match != str) ? match[-1] : ' '; | ||
371 | if (!isalnum(c) && c != '_') { | ||
372 | c = match[strlen(gl->pattern)]; | ||
373 | if (!c || (!isalnum(c) && c != '_')) | ||
374 | goto opt_f_found; | ||
375 | } | ||
376 | str = match + 1; | ||
377 | goto opt_f_again; | ||
378 | } | ||
379 | opt_f_found: | ||
380 | found = 1; | ||
381 | opt_f_not_found: ; | ||
382 | } | ||
359 | } else { | 383 | } else { |
360 | if (!(gl->flg_mem_alocated_compiled & COMPILED)) { | 384 | if (!(gl->flg_mem_alocated_compiled & COMPILED)) { |
361 | gl->flg_mem_alocated_compiled |= COMPILED; | 385 | gl->flg_mem_alocated_compiled |= COMPILED; |
@@ -384,7 +408,8 @@ static int grep_file(FILE *file) | |||
384 | if (option_mask32 & OPT_x) { | 408 | if (option_mask32 & OPT_x) { |
385 | found = (gl->matched_range.rm_so == 0 | 409 | found = (gl->matched_range.rm_so == 0 |
386 | && line[gl->matched_range.rm_eo] == '\0'); | 410 | && line[gl->matched_range.rm_eo] == '\0'); |
387 | } else if (!(option_mask32 & OPT_w)) { | 411 | } else |
412 | if (!(option_mask32 & OPT_w)) { | ||
388 | found = 1; | 413 | found = 1; |
389 | } else { | 414 | } else { |
390 | char c = ' '; | 415 | char c = ' '; |
@@ -395,6 +420,8 @@ static int grep_file(FILE *file) | |||
395 | if (!c || (!isalnum(c) && c != '_')) | 420 | if (!c || (!isalnum(c) && c != '_')) |
396 | found = 1; | 421 | found = 1; |
397 | } | 422 | } |
423 | //BUG: "echo foop foo | grep -w foo" should match, but doesn't: | ||
424 | //we bail out on first "mismatch" because it's not a word. | ||
398 | } | 425 | } |
399 | } | 426 | } |
400 | } | 427 | } |
@@ -646,7 +673,7 @@ int grep_main(int argc UNUSED_PARAM, char **argv) | |||
646 | 673 | ||
647 | if (opts & OPT_C) { | 674 | if (opts & OPT_C) { |
648 | /* -C unsets prev -A and -B, but following -A or -B | 675 | /* -C unsets prev -A and -B, but following -A or -B |
649 | may override it */ | 676 | * may override it */ |
650 | if (!(opts & OPT_A)) /* not overridden */ | 677 | if (!(opts & OPT_A)) /* not overridden */ |
651 | lines_after = Copt; | 678 | lines_after = Copt; |
652 | if (!(opts & OPT_B)) /* not overridden */ | 679 | if (!(opts & OPT_B)) /* not overridden */ |