1303 files changed, 32187 insertions, 57138 deletions
diff --git a/editors/diff.c b/editors/diff.c index 1961de6..b275a21 100644 --- a/editors/diff.c +++ b/editors/diff.c @@ -125,6 +125,7 @@ //usage: "\n -w Ignore all whitespace" #include "libbb.h" +#include "common_bufsiz.h" #if 0 # define dbg_error_msg(...) bb_error_msg(__VA_ARGS__) @@ -363,7 +364,7 @@ static void stone(const int *a, int n, const int *b, int *J, int pref) } struct line { - /* 'serial' is not used in the begining, so we reuse it + /* 'serial' is not used in the beginning, so we reuse it * to store line offsets, thus reducing memory pressure */ union { @@ -433,7 +434,7 @@ static void fetch(FILE_and_pos_t *ft, const off_t *ix, int a, int b, int ch) for (j = 0, col = 0; j < ix[i] - ix[i - 1]; j++) { int c = fgetc(ft->ft_fp); if (c == EOF) { - printf("\n\\ No newline at end of file\n"); + puts("\n\\ No newline at end of file"); return; } ft->ft_pos++; @@ -658,8 +659,8 @@ static bool diff(FILE* fp[2], char *file[2]) } for (j = 0; j < 2; j++) - for (k = v[j].a; k < v[j].b; k++) - nonempty |= (ix[j][k+1] - ix[j][k] != 1); + for (k = v[j].a; k <= v[j].b; k++) + nonempty |= (ix[j][k] - ix[j][k - 1] != 1); vec = xrealloc_vector(vec, 6, ++idx); memcpy(vec[idx], v, sizeof(v)); @@ -692,7 +693,7 @@ static bool diff(FILE* fp[2], char *file[2]) continue; printf(",%d", (a < b) ? b - a + 1 : 0); } - printf(" @@\n"); + puts(" @@"); /* * Output changes in "unified" diff format--the old and new lines * are printed together. @@ -747,13 +748,15 @@ static int diffreg(char *file[2]) unlink(name); if (bb_copyfd_eof(fd, fd_tmp) < 0) xfunc_die(); - if (fd) /* Prevents closing of stdin */ + if (fd != STDIN_FILENO) close(fd); fd = fd_tmp; + xlseek(fd, 0, SEEK_SET); } fp[i] = fdopen(fd, "r"); } + setup_common_bufsiz(); while (1) { const size_t sz = COMMON_BUFSIZE / 2; char *const buf0 = bb_common_bufsiz1; @@ -986,11 +989,11 @@ int diff_main(int argc UNUSED_PARAM, char **argv) INIT_G(); /* exactly 2 params; collect multiple -L <label>; -U N */ - opt_complementary = "=2:L::U+"; + opt_complementary = "=2"; #if ENABLE_FEATURE_DIFF_LONG_OPTIONS applet_long_options = diff_longopts; #endif - getopt32(argv, "abdiL:NqrsS:tTU:wupBE", + getopt32(argv, "abdiL:*NqrsS:tTU:+wupBE", &L_arg, &s_start, &opt_U_context); argv += optind; while (L_arg) |