aboutsummaryrefslogtreecommitdiff
path: root/findutils
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2014-01-13 09:11:24 +0000
committerRon Yorston <rmy@pobox.com>2014-01-13 09:11:24 +0000
commite6edcba4f2fc20a3e9db75ebe82d7a71094fe17c (patch)
treeaf786c447cae6ca59e195b31fbae442c0b42d198 /findutils
parent215f730e98215bff8dfacafdaa70e4a11395ad53 (diff)
parent0f592d7fb94c5887528d0ee24020c2225ab71c28 (diff)
downloadbusybox-w32-e6edcba4f2fc20a3e9db75ebe82d7a71094fe17c.tar.gz
busybox-w32-e6edcba4f2fc20a3e9db75ebe82d7a71094fe17c.tar.bz2
busybox-w32-e6edcba4f2fc20a3e9db75ebe82d7a71094fe17c.zip
Merge branch 'busybox' into merge
Conflicts: include/platform.h scripts/basic/fixdep.c
Diffstat (limited to 'findutils')
-rw-r--r--findutils/find.c21
-rw-r--r--findutils/grep.c28
2 files changed, 45 insertions, 4 deletions
diff --git a/findutils/find.c b/findutils/find.c
index 53d8239c7..5d5e24bfb 100644
--- a/findutils/find.c
+++ b/findutils/find.c
@@ -1291,9 +1291,27 @@ int find_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
1291int find_main(int argc UNUSED_PARAM, char **argv) 1291int find_main(int argc UNUSED_PARAM, char **argv)
1292{ 1292{
1293 int i, firstopt, status = EXIT_SUCCESS; 1293 int i, firstopt, status = EXIT_SUCCESS;
1294 char **past_HLP, *saved;
1294 1295
1295 INIT_G(); 1296 INIT_G();
1296 1297
1298 /* "find -type f" + getopt("+HLP") => disaster.
1299 * Need to avoid getopt running into a non-HLP option.
1300 * Do this by temporarily storing NULL there:
1301 */
1302 past_HLP = argv;
1303 for (;;) {
1304 saved = *++past_HLP;
1305 if (!saved)
1306 break;
1307 if (saved[0] != '-')
1308 break;
1309 if (!saved[1])
1310 break; /* it is "-" */
1311 if ((saved+1)[strspn(saved+1, "HLP")] != '\0')
1312 break;
1313 }
1314 *past_HLP = NULL;
1297 /* "+": stop on first non-option */ 1315 /* "+": stop on first non-option */
1298 i = getopt32(argv, "+HLP"); 1316 i = getopt32(argv, "+HLP");
1299 if (i & (1<<0)) 1317 if (i & (1<<0))
@@ -1301,7 +1319,8 @@ int find_main(int argc UNUSED_PARAM, char **argv)
1301 if (i & (1<<1)) 1319 if (i & (1<<1))
1302 G.recurse_flags |= ACTION_FOLLOWLINKS | ACTION_DANGLING_OK; 1320 G.recurse_flags |= ACTION_FOLLOWLINKS | ACTION_DANGLING_OK;
1303 /* -P is default and is ignored */ 1321 /* -P is default and is ignored */
1304 argv += optind; 1322 argv = past_HLP; /* same result as "argv += optind;" */
1323 *past_HLP = saved;
1305 1324
1306 for (firstopt = 0; argv[firstopt]; firstopt++) { 1325 for (firstopt = 0; argv[firstopt]; firstopt++) {
1307 if (argv[firstopt][0] == '-') 1326 if (argv[firstopt][0] == '-')
diff --git a/findutils/grep.c b/findutils/grep.c
index 5bbe61100..f5f95cb95 100644
--- a/findutils/grep.c
+++ b/findutils/grep.c
@@ -381,6 +381,9 @@ static int grep_file(FILE *file)
381 opt_f_not_found: ; 381 opt_f_not_found: ;
382 } 382 }
383 } else { 383 } else {
384#if ENABLE_EXTRA_COMPAT
385 unsigned start_pos;
386#endif
384 char *match_at; 387 char *match_at;
385 388
386 if (!(gl->flg_mem_alocated_compiled & COMPILED)) { 389 if (!(gl->flg_mem_alocated_compiled & COMPILED)) {
@@ -397,15 +400,18 @@ static int grep_file(FILE *file)
397#if !ENABLE_EXTRA_COMPAT 400#if !ENABLE_EXTRA_COMPAT
398 gl->matched_range.rm_so = 0; 401 gl->matched_range.rm_so = 0;
399 gl->matched_range.rm_eo = 0; 402 gl->matched_range.rm_eo = 0;
403#else
404 start_pos = 0;
400#endif 405#endif
401 match_at = line; 406 match_at = line;
402 opt_w_again: 407 opt_w_again:
408//bb_error_msg("'%s' start_pos:%d line_len:%d", match_at, start_pos, line_len);
403 if ( 409 if (
404#if !ENABLE_EXTRA_COMPAT 410#if !ENABLE_EXTRA_COMPAT
405 regexec(&gl->compiled_regex, match_at, 1, &gl->matched_range, 0) == 0 411 regexec(&gl->compiled_regex, match_at, 1, &gl->matched_range, 0) == 0
406#else 412#else
407 re_search(&gl->compiled_regex, match_at, line_len, 413 re_search(&gl->compiled_regex, match_at, line_len,
408 /*start:*/ 0, /*range:*/ line_len, 414 start_pos, /*range:*/ line_len,
409 &gl->matched_range) >= 0 415 &gl->matched_range) >= 0
410#endif 416#endif
411 ) { 417 ) {
@@ -424,8 +430,24 @@ static int grep_file(FILE *file)
424 if (!c || (!isalnum(c) && c != '_')) { 430 if (!c || (!isalnum(c) && c != '_')) {
425 found = 1; 431 found = 1;
426 } else { 432 } else {
427 match_at += gl->matched_range.rm_eo; 433 /*
428 goto opt_w_again; 434 * Why check gl->matched_range.rm_eo?
435 * Zero-length match makes -w skip the line:
436 * "echo foo | grep ^" prints "foo",
437 * "echo foo | grep -w ^" prints nothing.
438 * Without such check, we can loop forever.
439 */
440#if !ENABLE_EXTRA_COMPAT
441 if (gl->matched_range.rm_eo != 0) {
442 match_at += gl->matched_range.rm_eo;
443 goto opt_w_again;
444 }
445#else
446 if (gl->matched_range.rm_eo > start_pos) {
447 start_pos = gl->matched_range.rm_eo;
448 goto opt_w_again;
449 }
450#endif
429 } 451 }
430 } 452 }
431 } 453 }