aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatheus Izvekov <mizvekov@gmail.com>2010-01-18 16:07:07 -0200
committerDenys Vlasenko <vda.linux@googlemail.com>2010-01-20 02:45:05 +0100
commitfe1ce2e43e612d7b07118cf139a8b61d76bea893 (patch)
treece8b6457e532b62c0ced45b0a33257d781f3c346
parentb7a044043ceae800a1f7abd69b107876ad5e9d40 (diff)
downloadbusybox-w32-fe1ce2e43e612d7b07118cf139a8b61d76bea893.tar.gz
busybox-w32-fe1ce2e43e612d7b07118cf139a8b61d76bea893.tar.bz2
busybox-w32-fe1ce2e43e612d7b07118cf139a8b61d76bea893.zip
diff: implement flag -B (Ignore changes whose lines are all blank)
>>From 7c3ce93213590bd0592435dc27d1272d0fd3309b Mon Sep 17 00:00:00 2001 From: Matheus Izvekov <mizvekov@gmail.com> Date: Mon, 18 Jan 2010 15:52:31 -0200 Subject: [PATCH] diff: implement flag -B (Ignore changes whose lines are all blank) function old new delta diffreg 1196 1240 +44 .rodata 6538 6561 +23 packed_usage 457 478 +21 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/0 up/down: 88/0) Total: 88 bytes text data bss dec hex filename 70123 733 8576 79432 13648 busybox_old 70190 733 8576 79499 1368b busybox_unstripped Signed-off-by: Matheus Izvekov <mizvekov@gmail.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--editors/diff.c28
-rw-r--r--include/usage.h3
2 files changed, 19 insertions, 12 deletions
diff --git a/editors/diff.c b/editors/diff.c
index ef2030527..772610477 100644
--- a/editors/diff.c
+++ b/editors/diff.c
@@ -84,27 +84,31 @@
84#define dbg_error_msg(...) ((void)0) 84#define dbg_error_msg(...) ((void)0)
85#endif 85#endif
86 86
87enum { /* print_status() and diffreg() return values */ 87enum { /* print_status() and diffreg() return values */
88 STATUS_SAME, /* files are the same */ 88 STATUS_SAME, /* files are the same */
89 STATUS_DIFFER, /* files differ */ 89 STATUS_DIFFER, /* files differ */
90 STATUS_BINARY, /* binary files differ */ 90 STATUS_BINARY, /* binary files differ */
91}; 91};
92 92
93enum { /* Commandline flags */ 93enum { /* Commandline flags */
94 FLAG_a, 94 FLAG_a,
95 FLAG_b, 95 FLAG_b,
96 FLAG_d, 96 FLAG_d,
97 FLAG_i, 97 FLAG_i,
98 FLAG_L, /* unused */ 98 FLAG_L, /* never used, handled by getopt32 */
99 FLAG_N, 99 FLAG_N,
100 FLAG_q, 100 FLAG_q,
101 FLAG_r, 101 FLAG_r,
102 FLAG_s, 102 FLAG_s,
103 FLAG_S, /* unused */ 103 FLAG_S, /* never used, handled by getopt32 */
104 FLAG_t, 104 FLAG_t,
105 FLAG_T, 105 FLAG_T,
106 FLAG_U, /* unused */ 106 FLAG_U, /* never used, handled by getopt32 */
107 FLAG_w, 107 FLAG_w,
108 FLAG_u, /* ignored, this is the default */
109 FLAG_p, /* not implemented */
110 FLAG_B,
111 FLAG_E, /* not implemented */
108}; 112};
109#define FLAG(x) (1 << FLAG_##x) 113#define FLAG(x) (1 << FLAG_##x)
110 114
@@ -578,6 +582,8 @@ static bool diff(FILE_and_pos_t ft[2], char *file[2])
578 int idx = -1, i = 1; 582 int idx = -1, i = 1;
579 583
580 do { 584 do {
585 bool nonempty = false;
586
581 while (1) { 587 while (1) {
582 struct context_vec v; 588 struct context_vec v;
583 589
@@ -606,6 +612,7 @@ static bool diff(FILE_and_pos_t ft[2], char *file[2])
606 ) { 612 ) {
607 break; 613 break;
608 } 614 }
615 nonempty |= (v.a >= v.b) && (v.c >= v.d);
609 vec = xrealloc_vector(vec, 6, ++idx); 616 vec = xrealloc_vector(vec, 6, ++idx);
610 vec[idx] = v; 617 vec[idx] = v;
611 } 618 }
@@ -617,7 +624,7 @@ static bool diff(FILE_and_pos_t ft[2], char *file[2])
617 } 624 }
618 if (idx < 0) 625 if (idx < 0)
619 continue; 626 continue;
620 if (!(option_mask32 & FLAG(q))) { 627 if (!(option_mask32 & FLAG(q)) && !((option_mask32 & FLAG(B)) && !nonempty)) {
621 struct context_vec *cvp = vec; 628 struct context_vec *cvp = vec;
622 int lowa = MAX(1, cvp->a - opt_U_context); 629 int lowa = MAX(1, cvp->a - opt_U_context);
623 int upb = MIN(nlen[0], vec[idx].b + opt_U_context); 630 int upb = MIN(nlen[0], vec[idx].b + opt_U_context);
@@ -880,8 +887,7 @@ int diff_main(int argc UNUSED_PARAM, char **argv)
880 887
881 /* exactly 2 params; collect multiple -L <label>; -U N */ 888 /* exactly 2 params; collect multiple -L <label>; -U N */
882 opt_complementary = "=2:L::U+"; 889 opt_complementary = "=2:L::U+";
883 getopt32(argv, "abdiL:NqrsS:tTU:wu" 890 getopt32(argv, "abdiL:NqrsS:tTU:wupBE",
884 "p" /* ignored (for compatibility) */,
885 &L_arg, &s_start, &opt_U_context); 891 &L_arg, &s_start, &opt_U_context);
886 argv += optind; 892 argv += optind;
887 while (L_arg) { 893 while (L_arg) {
diff --git a/include/usage.h b/include/usage.h
index 168d6e1e5..7b8564278 100644
--- a/include/usage.h
+++ b/include/usage.h
@@ -852,13 +852,14 @@
852 "Relay DHCP requests between clients and server" \ 852 "Relay DHCP requests between clients and server" \
853 853
854#define diff_trivial_usage \ 854#define diff_trivial_usage \
855 "[-abdiNqrTstw] [-L LABEL] [-S FILE] [-U LINES] FILE1 FILE2" 855 "[-abBdiNqrTstw] [-L LABEL] [-S FILE] [-U LINES] FILE1 FILE2"
856#define diff_full_usage "\n\n" \ 856#define diff_full_usage "\n\n" \
857 "Compare files line by line and output the differences between them.\n" \ 857 "Compare files line by line and output the differences between them.\n" \
858 "This implementation supports unified diffs only.\n" \ 858 "This implementation supports unified diffs only.\n" \
859 "\nOptions:" \ 859 "\nOptions:" \
860 "\n -a Treat all files as text" \ 860 "\n -a Treat all files as text" \
861 "\n -b Ignore changes in the amount of whitespace" \ 861 "\n -b Ignore changes in the amount of whitespace" \
862 "\n -B Ignore changes whose lines are all blank" \
862 "\n -d Try hard to find a smaller set of changes" \ 863 "\n -d Try hard to find a smaller set of changes" \
863 "\n -i Ignore case differences" \ 864 "\n -i Ignore case differences" \
864 "\n -L Use LABEL instead of the filename in the unified header" \ 865 "\n -L Use LABEL instead of the filename in the unified header" \