diff options
author | Ron Yorston <rmy@pobox.com> | 2020-05-29 10:49:00 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2020-05-29 11:03:33 +0100 |
commit | 53c09d0e1720bd927a2995f87df324a9854f1771 (patch) | |
tree | 982b357d9d188cfb6a1d488ebaba6c42d818209f /findutils | |
parent | d4247a9f03290a96433e18dba538404005a21311 (diff) | |
parent | 45fa3f18adf57ef9d743038743d9c90573aeeb91 (diff) | |
download | busybox-w32-53c09d0e1720bd927a2995f87df324a9854f1771.tar.gz busybox-w32-53c09d0e1720bd927a2995f87df324a9854f1771.tar.bz2 busybox-w32-53c09d0e1720bd927a2995f87df324a9854f1771.zip |
Merge branch 'busybox' into mergeFRP-3466-g53c09d0e1
Diffstat (limited to 'findutils')
-rw-r--r-- | findutils/grep.c | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/findutils/grep.c b/findutils/grep.c index 5b8644c36..55e9c0a8f 100644 --- a/findutils/grep.c +++ b/findutils/grep.c | |||
@@ -650,6 +650,13 @@ static void load_regexes_from_file(llist_t *fopt) | |||
650 | } | 650 | } |
651 | } | 651 | } |
652 | 652 | ||
653 | static void load_pattern_list(llist_t **lst, char *pattern) | ||
654 | { | ||
655 | char *p; | ||
656 | while ((p = strsep(&pattern, "\n")) != NULL) | ||
657 | llist_add_to(lst, new_grep_list_data(p, 0)); | ||
658 | } | ||
659 | |||
653 | static int FAST_FUNC file_action_grep(const char *filename, | 660 | static int FAST_FUNC file_action_grep(const char *filename, |
654 | struct stat *statbuf, | 661 | struct stat *statbuf, |
655 | void* matched, | 662 | void* matched, |
@@ -754,16 +761,19 @@ int grep_main(int argc UNUSED_PARAM, char **argv) | |||
754 | #endif | 761 | #endif |
755 | invert_search = ((option_mask32 & OPT_v) != 0); /* 0 | 1 */ | 762 | invert_search = ((option_mask32 & OPT_v) != 0); /* 0 | 1 */ |
756 | 763 | ||
757 | { /* convert char **argv to grep_list_data_t */ | 764 | { /* convert char **argv to pattern_list */ |
758 | llist_t *cur; | 765 | llist_t *cur, *new = NULL; |
759 | for (cur = pattern_head; cur; cur = cur->link) | 766 | for (cur = pattern_head; cur; cur = cur->link) |
760 | cur->data = new_grep_list_data(cur->data, 0); | 767 | load_pattern_list(&new, cur->data); |
768 | llist_free(pattern_head, NULL); | ||
769 | pattern_head = new; | ||
761 | } | 770 | } |
762 | if (option_mask32 & OPT_f) { | 771 | if (option_mask32 & OPT_f) { |
763 | load_regexes_from_file(fopt); | 772 | load_regexes_from_file(fopt); |
764 | if (!pattern_head) { /* -f EMPTY_FILE? */ | 773 | if (!pattern_head) { /* -f EMPTY_FILE? */ |
765 | /* GNU grep treats it as "nothing matches" */ | 774 | /* GNU grep treats it as "nothing matches" except when -x */ |
766 | llist_add_to(&pattern_head, new_grep_list_data((char*) "", 0)); | 775 | const char *data = (option_mask32 & OPT_x) ? ".*" : ""; |
776 | llist_add_to(&pattern_head, new_grep_list_data((char*)data, 0)); | ||
767 | invert_search ^= 1; | 777 | invert_search ^= 1; |
768 | } | 778 | } |
769 | } | 779 | } |
@@ -805,11 +815,9 @@ int grep_main(int argc UNUSED_PARAM, char **argv) | |||
805 | /* if we didn't get a pattern from -e and no command file was specified, | 815 | /* if we didn't get a pattern from -e and no command file was specified, |
806 | * first parameter should be the pattern. no pattern, no worky */ | 816 | * first parameter should be the pattern. no pattern, no worky */ |
807 | if (pattern_head == NULL) { | 817 | if (pattern_head == NULL) { |
808 | char *pattern; | ||
809 | if (*argv == NULL) | 818 | if (*argv == NULL) |
810 | bb_show_usage(); | 819 | bb_show_usage(); |
811 | pattern = new_grep_list_data(*argv++, 0); | 820 | load_pattern_list(&pattern_head, *argv++); |
812 | llist_add_to(&pattern_head, pattern); | ||
813 | } | 821 | } |
814 | 822 | ||
815 | /* argv[0..(argc-1)] should be names of file to grep through. If | 823 | /* argv[0..(argc-1)] should be names of file to grep through. If |