diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-06-07 05:19:31 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-06-07 05:19:31 +0000 |
commit | a05c0716c256a95861c01d06b5319f3149fca33a (patch) | |
tree | 0d877b4070cd8228e19146365a7888b7305bc6ff /findutils/grep.c | |
parent | 401de648a797c5931df1ade02c26270c82c3a345 (diff) | |
download | busybox-w32-a05c0716c256a95861c01d06b5319f3149fca33a.tar.gz busybox-w32-a05c0716c256a95861c01d06b5319f3149fca33a.tar.bz2 busybox-w32-a05c0716c256a95861c01d06b5319f3149fca33a.zip |
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/grep.c')
-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 6af1b46e1..fc7893860 100644 --- a/findutils/grep.c +++ b/findutils/grep.c | |||
@@ -126,7 +126,7 @@ struct globals { | |||
126 | typedef struct grep_list_data_t { | 126 | typedef struct grep_list_data_t { |
127 | char *pattern; | 127 | char *pattern; |
128 | regex_t preg; | 128 | regex_t preg; |
129 | #define PATTERN_MEM_A 1 | 129 | #define ALLOCATED 1 |
130 | #define COMPILED 2 | 130 | #define COMPILED 2 |
131 | int flg_mem_alocated_compiled; | 131 | int flg_mem_alocated_compiled; |
132 | } grep_list_data_t; | 132 | } grep_list_data_t; |
@@ -363,10 +363,10 @@ static void load_regexes_from_file(llist_t *fopt) | |||
363 | 363 | ||
364 | fopt = cur->link; | 364 | fopt = cur->link; |
365 | free(cur); | 365 | free(cur); |
366 | f = xfopen(ffile, "r"); | 366 | f = xfopen_stdin(ffile); |
367 | while ((line = xmalloc_fgetline(f)) != NULL) { | 367 | while ((line = xmalloc_fgetline(f)) != NULL) { |
368 | llist_add_to(&pattern_head, | 368 | llist_add_to(&pattern_head, |
369 | new_grep_list_data(line, PATTERN_MEM_A)); | 369 | new_grep_list_data(line, ALLOCATED)); |
370 | } | 370 | } |
371 | } | 371 | } |
372 | } | 372 | } |
@@ -486,7 +486,7 @@ int grep_main(int argc, char **argv) | |||
486 | argc--; | 486 | argc--; |
487 | } | 487 | } |
488 | 488 | ||
489 | /* argv[(optind)..(argc-1)] should be names of file to grep through. If | 489 | /* argv[0..(argc-1)] should be names of file to grep through. If |
490 | * there is more than one file to grep, we will print the filenames. */ | 490 | * there is more than one file to grep, we will print the filenames. */ |
491 | if (argc > 1) | 491 | if (argc > 1) |
492 | print_filename = 1; | 492 | print_filename = 1; |
@@ -535,9 +535,9 @@ int grep_main(int argc, char **argv) | |||
535 | grep_list_data_t *gl = (grep_list_data_t *)pattern_head_ptr->data; | 535 | grep_list_data_t *gl = (grep_list_data_t *)pattern_head_ptr->data; |
536 | 536 | ||
537 | pattern_head = pattern_head->link; | 537 | pattern_head = pattern_head->link; |
538 | if ((gl->flg_mem_alocated_compiled & PATTERN_MEM_A)) | 538 | if (gl->flg_mem_alocated_compiled & ALLOCATED) |
539 | free(gl->pattern); | 539 | free(gl->pattern); |
540 | if ((gl->flg_mem_alocated_compiled & COMPILED)) | 540 | if (gl->flg_mem_alocated_compiled & COMPILED) |
541 | regfree(&(gl->preg)); | 541 | regfree(&(gl->preg)); |
542 | free(gl); | 542 | free(gl); |
543 | free(pattern_head_ptr); | 543 | free(pattern_head_ptr); |