Changeset 3621 in MondoRescue for branches/3.3/mindi-busybox/findutils/grep.c
- Timestamp:
- Dec 20, 2016, 4:07:32 PM (7 years ago)
- Location:
- branches/3.3
- Files:
-
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/3.3/mindi-busybox/findutils/grep.c
r3232 r3621 59 59 60 60 #include "libbb.h" 61 #include "common_bufsiz.h" 61 62 #include "xregex.h" 62 63 … … 202 203 const char *cur_file; /* the current file we are reading */ 203 204 } FIX_ALIASING; 204 #define G (*(struct globals*) &bb_common_bufsiz1)205 #define G (*(struct globals*)bb_common_bufsiz1) 205 206 #define INIT_G() do { \ 206 struct G_sizecheck { \ 207 char G_sizecheck[sizeof(G) > COMMON_BUFSIZE ? -1 : 1]; \ 208 }; \ 207 setup_common_bufsiz(); \ 208 BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \ 209 209 } while (0) 210 210 #define max_matches (G.max_matches ) … … 374 374 } 375 375 } else { 376 #if ENABLE_EXTRA_COMPAT 377 unsigned start_pos; 378 #else 379 int match_flg; 380 #endif 381 char *match_at; 382 376 383 if (!(gl->flg_mem_alocated_compiled & COMPILED)) { 377 384 gl->flg_mem_alocated_compiled |= COMPILED; … … 388 395 gl->matched_range.rm_so = 0; 389 396 gl->matched_range.rm_eo = 0; 390 #endif 397 match_flg = 0; 398 #else 399 start_pos = 0; 400 #endif 401 match_at = line; 402 opt_w_again: 403 //bb_error_msg("'%s' start_pos:%d line_len:%d", match_at, start_pos, line_len); 391 404 if ( 392 405 #if !ENABLE_EXTRA_COMPAT 393 regexec(&gl->compiled_regex, line, 1, &gl->matched_range, 0) == 0394 #else 395 re_search(&gl->compiled_regex, line, line_len,396 /*start:*/ 0, /*range:*/ line_len,406 regexec(&gl->compiled_regex, match_at, 1, &gl->matched_range, match_flg) == 0 407 #else 408 re_search(&gl->compiled_regex, match_at, line_len, 409 start_pos, /*range:*/ line_len, 397 410 &gl->matched_range) >= 0 398 411 #endif … … 400 413 if (option_mask32 & OPT_x) { 401 414 found = (gl->matched_range.rm_so == 0 402 && line[gl->matched_range.rm_eo] == '\0');415 && match_at[gl->matched_range.rm_eo] == '\0'); 403 416 } else 404 417 if (!(option_mask32 & OPT_w)) { … … 406 419 } else { 407 420 char c = ' '; 408 if (gl->matched_range.rm_so) 409 c = line[gl->matched_range.rm_so - 1]; 421 if (match_at > line || gl->matched_range.rm_so != 0) { 422 c = match_at[gl->matched_range.rm_so - 1]; 423 } 410 424 if (!isalnum(c) && c != '_') { 411 c = line[gl->matched_range.rm_eo]; 412 if (!c || (!isalnum(c) && c != '_')) 413 found = 1; 425 c = match_at[gl->matched_range.rm_eo]; 414 426 } 415 //BUG: "echo foop foo | grep -w foo" should match, but doesn't: 416 //we bail out on first "mismatch" because it's not a word. 427 if (!isalnum(c) && c != '_') { 428 found = 1; 429 } else { 430 /* 431 * Why check gl->matched_range.rm_eo? 432 * Zero-length match makes -w skip the line: 433 * "echo foo | grep ^" prints "foo", 434 * "echo foo | grep -w ^" prints nothing. 435 * Without such check, we can loop forever. 436 */ 437 #if !ENABLE_EXTRA_COMPAT 438 if (gl->matched_range.rm_eo != 0) { 439 match_at += gl->matched_range.rm_eo; 440 match_flg |= REG_NOTBOL; 441 goto opt_w_again; 442 } 443 #else 444 if (gl->matched_range.rm_eo > start_pos) { 445 start_pos = gl->matched_range.rm_eo; 446 goto opt_w_again; 447 } 448 #endif 449 } 417 450 } 418 451 } … … 636 669 recursive_action(dir, 637 670 /* recurse=yes */ ACTION_RECURSE | 638 /* followLinks= no */671 /* followLinks=command line only */ ACTION_FOLLOWLINKS_L0 | 639 672 /* depthFirst=yes */ ACTION_DEPTHFIRST, 640 673 /* fileAction= */ file_action_grep, … … 651 684 int matched; 652 685 llist_t *fopt = NULL; 686 #if ENABLE_FEATURE_GREP_CONTEXT 687 int Copt, opts; 688 #endif 689 INIT_G(); 690 691 /* For grep, exitcode of 1 is "not found". Other errors are 2: */ 692 xfunc_error_retval = 2; 653 693 654 694 /* do normal option parsing */ 655 695 #if ENABLE_FEATURE_GREP_CONTEXT 656 int Copt, opts;657 658 696 /* -H unsets -h; -C unsets -A,-B; -e,-f are lists; 659 697 * -m,-A,-B,-C have numeric param */ … … 711 749 712 750 #if !ENABLE_EXTRA_COMPAT 713 if (!(option_mask32 & (OPT_o | OPT_w )))751 if (!(option_mask32 & (OPT_o | OPT_w | OPT_x))) 714 752 reflags = REG_NOSUB; 715 753 #endif
Note:
See TracChangeset
for help on using the changeset viewer.