diff options
author | Denis Vlasenko | 2009-03-20 22:17:13 +0000 |
---|---|---|
committer | Denis Vlasenko | 2009-03-20 22:17:13 +0000 |
commit | 83518d18a34a3ddfcaac1739930d8469f5bc2442 (patch) | |
tree | 2af665365a69f2689288cc13bb65efbb59e7d520 /findutils/grep.c | |
parent | 0b28103cc774eb1ee62362cf61d52c32d44ec2cf (diff) | |
download | busybox-83518d18a34a3ddfcaac1739930d8469f5bc2442.zip busybox-83518d18a34a3ddfcaac1739930d8469f5bc2442.tar.gz |
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 6a6ddb6..723c351 100644 --- a/findutils/grep.c +++ b/findutils/grep.c @@ -28,7 +28,9 @@ USE_FEATURE_GREP_CONTEXT("A:B:C:") \ USE_FEATURE_GREP_EGREP_ALIAS("E") \ USE_DESKTOP("w") \ + USE_EXTRA_COMPAT("z") \ "aI" + /* ignored: -a "assume all files to be text" */ /* ignored: -I "assume binary files have no matches" */ @@ -54,6 +56,7 @@ enum { USE_FEATURE_GREP_CONTEXT( OPTBIT_C ,) /* -C NUM: -A and -B combined */ USE_FEATURE_GREP_EGREP_ALIAS(OPTBIT_E ,) /* extended regexp */ USE_DESKTOP( OPTBIT_w ,) /* whole word match */ + USE_EXTRA_COMPAT( OPTBIT_z ,) /* input is NUL terminated */ OPT_l = 1 << OPTBIT_l, OPT_n = 1 << OPTBIT_n, OPT_q = 1 << OPTBIT_q, @@ -75,6 +78,7 @@ enum { OPT_C = USE_FEATURE_GREP_CONTEXT( (1 << OPTBIT_C)) + 0, OPT_E = USE_FEATURE_GREP_EGREP_ALIAS((1 << OPTBIT_E)) + 0, OPT_w = USE_DESKTOP( (1 << OPTBIT_w)) + 0, + OPT_z = USE_EXTRA_COMPAT( (1 << OPTBIT_z)) + 0, }; #define PRINT_FILES_WITH_MATCHES (option_mask32 & OPT_l) @@ -84,6 +88,7 @@ enum { #define PRINT_MATCH_COUNTS (option_mask32 & OPT_c) #define FGREP_FLAG (option_mask32 & OPT_F) #define PRINT_FILES_WITHOUT_MATCHES (option_mask32 & OPT_L) +#define NUL_DELIMITED (option_mask32 & OPT_z) struct globals { int max_matches; @@ -186,7 +191,7 @@ static void print_line(const char *line, size_t line_len, int linenum, char deco puts(line); #else fwrite(line, 1, line_len, stdout); - putchar('\n'); + putchar(NUL_DELIMITED ? '\0' : '\n'); #endif } } @@ -197,12 +202,13 @@ static ssize_t FAST_FUNC bb_getline(char **line_ptr, size_t *line_alloc_len, FIL { ssize_t res_sz; char *line; + int delim = (NUL_DELIMITED ? '\0' : '\n'); - res_sz = getline(line_ptr, line_alloc_len, file); + res_sz = getdelim(line_ptr, line_alloc_len, delim, file); line = *line_ptr; if (res_sz > 0) { - if (line[res_sz - 1] == '\n') + if (line[res_sz - 1] == delim) line[--res_sz] = '\0'; } else { free(line); /* uclibc allocates a buffer even on EOF. WTF? */ @@ -407,8 +413,11 @@ static int grep_file(FILE *file) #endif /* Did we print all context after last requested match? */ if ((option_mask32 & OPT_m) - && !print_n_lines_after && nmatches == max_matches) + && !print_n_lines_after + && nmatches == max_matches + ) { break; + } } /* while (read line) */ /* special-case file post-processing for options where we don't print line |