diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2009-03-20 22:17:13 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2009-03-20 22:17:13 +0000 |
commit | 83518d18a34a3ddfcaac1739930d8469f5bc2442 (patch) | |
tree | 2af665365a69f2689288cc13bb65efbb59e7d520 /findutils/grep.c | |
parent | 0b28103cc774eb1ee62362cf61d52c32d44ec2cf (diff) | |
download | busybox-w32-83518d18a34a3ddfcaac1739930d8469f5bc2442.tar.gz busybox-w32-83518d18a34a3ddfcaac1739930d8469f5bc2442.tar.bz2 busybox-w32-83518d18a34a3ddfcaac1739930d8469f5bc2442.zip |
Compatibility fixes:
grep: support -z
find: support --mindepth
together +45 bytes
cpio: support -p (configurable, +230 bytes)
libbb: tweaks for cpio
Diffstat (limited to 'findutils/grep.c')
-rw-r--r-- | findutils/grep.c | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/findutils/grep.c b/findutils/grep.c index 6a6ddb679..723c3511a 100644 --- a/findutils/grep.c +++ b/findutils/grep.c | |||
@@ -28,7 +28,9 @@ | |||
28 | USE_FEATURE_GREP_CONTEXT("A:B:C:") \ | 28 | USE_FEATURE_GREP_CONTEXT("A:B:C:") \ |
29 | USE_FEATURE_GREP_EGREP_ALIAS("E") \ | 29 | USE_FEATURE_GREP_EGREP_ALIAS("E") \ |
30 | USE_DESKTOP("w") \ | 30 | USE_DESKTOP("w") \ |
31 | USE_EXTRA_COMPAT("z") \ | ||
31 | "aI" | 32 | "aI" |
33 | |||
32 | /* ignored: -a "assume all files to be text" */ | 34 | /* ignored: -a "assume all files to be text" */ |
33 | /* ignored: -I "assume binary files have no matches" */ | 35 | /* ignored: -I "assume binary files have no matches" */ |
34 | 36 | ||
@@ -54,6 +56,7 @@ enum { | |||
54 | USE_FEATURE_GREP_CONTEXT( OPTBIT_C ,) /* -C NUM: -A and -B combined */ | 56 | USE_FEATURE_GREP_CONTEXT( OPTBIT_C ,) /* -C NUM: -A and -B combined */ |
55 | USE_FEATURE_GREP_EGREP_ALIAS(OPTBIT_E ,) /* extended regexp */ | 57 | USE_FEATURE_GREP_EGREP_ALIAS(OPTBIT_E ,) /* extended regexp */ |
56 | USE_DESKTOP( OPTBIT_w ,) /* whole word match */ | 58 | USE_DESKTOP( OPTBIT_w ,) /* whole word match */ |
59 | USE_EXTRA_COMPAT( OPTBIT_z ,) /* input is NUL terminated */ | ||
57 | OPT_l = 1 << OPTBIT_l, | 60 | OPT_l = 1 << OPTBIT_l, |
58 | OPT_n = 1 << OPTBIT_n, | 61 | OPT_n = 1 << OPTBIT_n, |
59 | OPT_q = 1 << OPTBIT_q, | 62 | OPT_q = 1 << OPTBIT_q, |
@@ -75,6 +78,7 @@ enum { | |||
75 | OPT_C = USE_FEATURE_GREP_CONTEXT( (1 << OPTBIT_C)) + 0, | 78 | OPT_C = USE_FEATURE_GREP_CONTEXT( (1 << OPTBIT_C)) + 0, |
76 | OPT_E = USE_FEATURE_GREP_EGREP_ALIAS((1 << OPTBIT_E)) + 0, | 79 | OPT_E = USE_FEATURE_GREP_EGREP_ALIAS((1 << OPTBIT_E)) + 0, |
77 | OPT_w = USE_DESKTOP( (1 << OPTBIT_w)) + 0, | 80 | OPT_w = USE_DESKTOP( (1 << OPTBIT_w)) + 0, |
81 | OPT_z = USE_EXTRA_COMPAT( (1 << OPTBIT_z)) + 0, | ||
78 | }; | 82 | }; |
79 | 83 | ||
80 | #define PRINT_FILES_WITH_MATCHES (option_mask32 & OPT_l) | 84 | #define PRINT_FILES_WITH_MATCHES (option_mask32 & OPT_l) |
@@ -84,6 +88,7 @@ enum { | |||
84 | #define PRINT_MATCH_COUNTS (option_mask32 & OPT_c) | 88 | #define PRINT_MATCH_COUNTS (option_mask32 & OPT_c) |
85 | #define FGREP_FLAG (option_mask32 & OPT_F) | 89 | #define FGREP_FLAG (option_mask32 & OPT_F) |
86 | #define PRINT_FILES_WITHOUT_MATCHES (option_mask32 & OPT_L) | 90 | #define PRINT_FILES_WITHOUT_MATCHES (option_mask32 & OPT_L) |
91 | #define NUL_DELIMITED (option_mask32 & OPT_z) | ||
87 | 92 | ||
88 | struct globals { | 93 | struct globals { |
89 | int max_matches; | 94 | int max_matches; |
@@ -186,7 +191,7 @@ static void print_line(const char *line, size_t line_len, int linenum, char deco | |||
186 | puts(line); | 191 | puts(line); |
187 | #else | 192 | #else |
188 | fwrite(line, 1, line_len, stdout); | 193 | fwrite(line, 1, line_len, stdout); |
189 | putchar('\n'); | 194 | putchar(NUL_DELIMITED ? '\0' : '\n'); |
190 | #endif | 195 | #endif |
191 | } | 196 | } |
192 | } | 197 | } |
@@ -197,12 +202,13 @@ static ssize_t FAST_FUNC bb_getline(char **line_ptr, size_t *line_alloc_len, FIL | |||
197 | { | 202 | { |
198 | ssize_t res_sz; | 203 | ssize_t res_sz; |
199 | char *line; | 204 | char *line; |
205 | int delim = (NUL_DELIMITED ? '\0' : '\n'); | ||
200 | 206 | ||
201 | res_sz = getline(line_ptr, line_alloc_len, file); | 207 | res_sz = getdelim(line_ptr, line_alloc_len, delim, file); |
202 | line = *line_ptr; | 208 | line = *line_ptr; |
203 | 209 | ||
204 | if (res_sz > 0) { | 210 | if (res_sz > 0) { |
205 | if (line[res_sz - 1] == '\n') | 211 | if (line[res_sz - 1] == delim) |
206 | line[--res_sz] = '\0'; | 212 | line[--res_sz] = '\0'; |
207 | } else { | 213 | } else { |
208 | free(line); /* uclibc allocates a buffer even on EOF. WTF? */ | 214 | free(line); /* uclibc allocates a buffer even on EOF. WTF? */ |
@@ -407,8 +413,11 @@ static int grep_file(FILE *file) | |||
407 | #endif | 413 | #endif |
408 | /* Did we print all context after last requested match? */ | 414 | /* Did we print all context after last requested match? */ |
409 | if ((option_mask32 & OPT_m) | 415 | if ((option_mask32 & OPT_m) |
410 | && !print_n_lines_after && nmatches == max_matches) | 416 | && !print_n_lines_after |
417 | && nmatches == max_matches | ||
418 | ) { | ||
411 | break; | 419 | break; |
420 | } | ||
412 | } /* while (read line) */ | 421 | } /* while (read line) */ |
413 | 422 | ||
414 | /* special-case file post-processing for options where we don't print line | 423 | /* special-case file post-processing for options where we don't print line |