diff options
author | Denis Vlasenko | 2008-06-07 05:19:31 +0000 |
---|---|---|
committer | Denis Vlasenko | 2008-06-07 05:19:31 +0000 |
commit | a05c0716c256a95861c01d06b5319f3149fca33a (patch) | |
tree | 0d877b4070cd8228e19146365a7888b7305bc6ff /findutils | |
parent | 401de648a797c5931df1ade02c26270c82c3a345 (diff) | |
download | busybox-a05c0716c256a95861c01d06b5319f3149fca33a.zip busybox-a05c0716c256a95861c01d06b5319f3149fca33a.tar.gz |
grep: make "-f -" work (+ testsuite)
diff: small code shrink
function old new delta
grep_main 722 714 -8
diffreg 1825 1793 -32
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-40) Total: -40 bytes
Diffstat (limited to 'findutils')
-rw-r--r-- | findutils/grep.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/findutils/grep.c b/findutils/grep.c index 6af1b46..fc78938 100644 --- a/findutils/grep.c +++ b/findutils/grep.c @@ -126,7 +126,7 @@ struct globals { typedef struct grep_list_data_t { char *pattern; regex_t preg; -#define PATTERN_MEM_A 1 +#define ALLOCATED 1 #define COMPILED 2 int flg_mem_alocated_compiled; } grep_list_data_t; @@ -363,10 +363,10 @@ static void load_regexes_from_file(llist_t *fopt) fopt = cur->link; free(cur); - f = xfopen(ffile, "r"); + f = xfopen_stdin(ffile); while ((line = xmalloc_fgetline(f)) != NULL) { llist_add_to(&pattern_head, - new_grep_list_data(line, PATTERN_MEM_A)); + new_grep_list_data(line, ALLOCATED)); } } } @@ -486,7 +486,7 @@ int grep_main(int argc, char **argv) argc--; } - /* argv[(optind)..(argc-1)] should be names of file to grep through. If + /* argv[0..(argc-1)] should be names of file to grep through. If * there is more than one file to grep, we will print the filenames. */ if (argc > 1) print_filename = 1; @@ -535,9 +535,9 @@ int grep_main(int argc, char **argv) grep_list_data_t *gl = (grep_list_data_t *)pattern_head_ptr->data; pattern_head = pattern_head->link; - if ((gl->flg_mem_alocated_compiled & PATTERN_MEM_A)) + if (gl->flg_mem_alocated_compiled & ALLOCATED) free(gl->pattern); - if ((gl->flg_mem_alocated_compiled & COMPILED)) + if (gl->flg_mem_alocated_compiled & COMPILED) regfree(&(gl->preg)); free(gl); free(pattern_head_ptr); |