aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBernhard Reutner-Fischer <rep.dot.nop@gmail.com>2007-01-07 15:56:09 +0000
committerBernhard Reutner-Fischer <rep.dot.nop@gmail.com>2007-01-07 15:56:09 +0000
commit7ae93f0fe7783518e59e425e6fbc44271520a2a2 (patch)
tree69bd16b7f5818b1dfb725ac9e50361a09113264c
parent5568b722d46157867959685ee2b35649c6ab16df (diff)
downloadbusybox-w32-7ae93f0fe7783518e59e425e6fbc44271520a2a2.tar.gz
busybox-w32-7ae93f0fe7783518e59e425e6fbc44271520a2a2.tar.bz2
busybox-w32-7ae93f0fe7783518e59e425e6fbc44271520a2a2.zip
- FIXME: someone broke diff -r
- minor shrinkage i had lying around text data bss dec hex filename 7002 8 88 7098 1bba diff.o.orig 6936 8 81 7025 1b71 diff.o
-rw-r--r--coreutils/diff.c96
1 files changed, 48 insertions, 48 deletions
diff --git a/coreutils/diff.c b/coreutils/diff.c
index 872b78830..f9865e971 100644
--- a/coreutils/diff.c
+++ b/coreutils/diff.c
@@ -67,6 +67,7 @@
67 67
68/* XXX: FIXME: the following variables should be static, but gcc currently 68/* XXX: FIXME: the following variables should be static, but gcc currently
69 * creates a much bigger object if we do this. [which version of gcc? --vda] */ 69 * creates a much bigger object if we do this. [which version of gcc? --vda] */
70/* 4.x, IIRC also 3.x --bernhard */
70/* This is the default number of lines of context. */ 71/* This is the default number of lines of context. */
71int context = 3; 72int context = 3;
72int status; 73int status;
@@ -75,7 +76,7 @@ const char *label1;
75const char *label2; 76const char *label2;
76struct stat stb1, stb2; 77struct stat stb1, stb2;
77char **dl; 78char **dl;
78USE_FEATURE_DIFF_DIR(static int dl_count;) 79USE_FEATURE_DIFF_DIR(int dl_count;)
79 80
80struct cand { 81struct cand {
81 int x; 82 int x;
@@ -108,7 +109,7 @@ static int clen;
108static int len[2]; 109static int len[2];
109static int pref, suff; /* length of prefix and suffix */ 110static int pref, suff; /* length of prefix and suffix */
110static int slen[2]; 111static int slen[2];
111static int anychange; 112static smallint anychange;
112static long *ixnew; /* will be overlaid on file[1] */ 113static long *ixnew; /* will be overlaid on file[1] */
113static long *ixold; /* will be overlaid on klist */ 114static long *ixold; /* will be overlaid on klist */
114static struct cand *clist; /* merely a free storage pot for candidates */ 115static struct cand *clist; /* merely a free storage pot for candidates */
@@ -129,9 +130,9 @@ static void print_only(const char *path, size_t dirlen, const char *entry)
129 130
130static void print_status(int val, char *path1, char *path2, char *entry) 131static void print_status(int val, char *path1, char *path2, char *entry)
131{ 132{
132 const char *const _entry = entry ? entry : ""; 133 const char * const _entry = entry ? entry : "";
133 char *_path1 = entry ? concat_path_file(path1, _entry) : path1; 134 char * const _path1 = entry ? concat_path_file(path1, _entry) : path1;
134 char *_path2 = entry ? concat_path_file(path2, _entry) : path2; 135 char * const _path2 = entry ? concat_path_file(path2, _entry) : path2;
135 136
136 switch (val) { 137 switch (val) {
137 case D_ONLY: 138 case D_ONLY:
@@ -173,8 +174,10 @@ static void print_status(int val, char *path1, char *path2, char *entry)
173 free(_path2); 174 free(_path2);
174 } 175 }
175} 176}
176 177static void fiddle_sum(int *sum, int t)
177 178{
179 *sum = (int)(*sum * 127 + t);
180}
178/* 181/*
179 * Hash function taken from Robert Sedgewick, Algorithms in C, 3d ed., p 578. 182 * Hash function taken from Robert Sedgewick, Algorithms in C, 3d ed., p 578.
180 */ 183 */
@@ -186,23 +189,14 @@ static int readhash(FILE * f)
186 sum = 1; 189 sum = 1;
187 space = 0; 190 space = 0;
188 if (!(option_mask32 & FLAG_b) && !(option_mask32 & FLAG_w)) { 191 if (!(option_mask32 & FLAG_b) && !(option_mask32 & FLAG_w)) {
189 if (FLAG_i) 192 for (i = 0; (t = getc(f)) != '\n'; i++) {
190 for (i = 0; (t = getc(f)) != '\n'; i++) { 193 if (t == EOF) {
191 if (t == EOF) { 194 if (i == 0)
192 if (i == 0) 195 return 0;
193 return 0; 196 break;
194 break;
195 }
196 sum = sum * 127 + t;
197 } else
198 for (i = 0; (t = getc(f)) != '\n'; i++) {
199 if (t == EOF) {
200 if (i == 0)
201 return 0;
202 break;
203 }
204 sum = sum * 127 + t;
205 } 197 }
198 fiddle_sum(&sum, t);
199 }
206 } else { 200 } else {
207 for (i = 0;;) { 201 for (i = 0;;) {
208 switch (t = getc(f)) { 202 switch (t = getc(f)) {
@@ -218,7 +212,7 @@ static int readhash(FILE * f)
218 i++; 212 i++;
219 space = 0; 213 space = 0;
220 } 214 }
221 sum = sum * 127 + t; 215 fiddle_sum(&sum, t);
222 i++; 216 i++;
223 continue; 217 continue;
224 case EOF: 218 case EOF:
@@ -298,10 +292,12 @@ static void prune(void)
298 int i, j; 292 int i, j;
299 293
300 for (pref = 0; pref < len[0] && pref < len[1] && 294 for (pref = 0; pref < len[0] && pref < len[1] &&
301 file[0][pref + 1].value == file[1][pref + 1].value; pref++); 295 file[0][pref + 1].value == file[1][pref + 1].value; pref++)
296 ;
302 for (suff = 0; suff < len[0] - pref && suff < len[1] - pref && 297 for (suff = 0; suff < len[0] - pref && suff < len[1] - pref &&
303 file[0][len[0] - suff].value == file[1][len[1] - suff].value; 298 file[0][len[0] - suff].value == file[1][len[1] - suff].value;
304 suff++); 299 suff++)
300 ;
305 for (j = 0; j < 2; j++) { 301 for (j = 0; j < 2; j++) {
306 sfile[j] = file[j] + pref; 302 sfile[j] = file[j] + pref;
307 slen[j] = len[j] - pref - suff; 303 slen[j] = len[j] - pref - suff;
@@ -621,12 +617,12 @@ static void uni_range(int a, int b)
621} 617}
622 618
623 619
624static int fetch(long *f, int a, int b, FILE * lb, int ch) 620static void fetch(long *f, int a, int b, FILE * lb, int ch)
625{ 621{
626 int i, j, c, lastc, col, nc; 622 int i, j, c, lastc, col, nc;
627 623
628 if (a > b) 624 if (a > b)
629 return 0; 625 return;
630 for (i = a; i <= b; i++) { 626 for (i = a; i <= b; i++) {
631 fseek(lb, f[i - 1], SEEK_SET); 627 fseek(lb, f[i - 1], SEEK_SET);
632 nc = f[i] - f[i - 1]; 628 nc = f[i] - f[i - 1];
@@ -638,8 +634,8 @@ static int fetch(long *f, int a, int b, FILE * lb, int ch)
638 col = 0; 634 col = 0;
639 for (j = 0, lastc = '\0'; j < nc; j++, lastc = c) { 635 for (j = 0, lastc = '\0'; j < nc; j++, lastc = c) {
640 if ((c = getc(lb)) == EOF) { 636 if ((c = getc(lb)) == EOF) {
641 puts("\n\\ No newline at end of file"); 637 printf("\n\\ No newline at end of file\n");
642 return 0; 638 return;
643 } 639 }
644 if (c == '\t' && (option_mask32 & FLAG_t)) { 640 if (c == '\t' && (option_mask32 & FLAG_t)) {
645 do { 641 do {
@@ -651,7 +647,7 @@ static int fetch(long *f, int a, int b, FILE * lb, int ch)
651 } 647 }
652 } 648 }
653 } 649 }
654 return 0; 650 return;
655} 651}
656 652
657 653
@@ -695,12 +691,11 @@ static void dump_unified_vec(FILE * f1, FILE * f2)
695 lowc = MAX(1, cvp->c - context); 691 lowc = MAX(1, cvp->c - context);
696 upd = MIN(len[1], context_vec_ptr->d + context); 692 upd = MIN(len[1], context_vec_ptr->d + context);
697 693
698 fputs("@@ -", stdout); 694 printf("@@ -");
699 uni_range(lowa, upb); 695 uni_range(lowa, upb);
700 fputs(" +", stdout); 696 printf(" +");
701 uni_range(lowc, upd); 697 uni_range(lowc, upd);
702 fputs(" @@", stdout); 698 printf(" @@\n");
703 putchar('\n');
704 699
705 /* 700 /*
706 * Output changes in "unified" diff format--the old and new lines 701 * Output changes in "unified" diff format--the old and new lines
@@ -894,13 +889,12 @@ static void output(char *file1, FILE * f1, char *file2, FILE * f2)
894 * 3*(number of k-candidates installed), typically about 889 * 3*(number of k-candidates installed), typically about
895 * 6n words for files of length n. 890 * 6n words for files of length n.
896 */ 891 */
897static int diffreg(char *ofile1, char *ofile2, int flags) 892static unsigned diffreg(char * ofile1, char * ofile2, int flags)
898{ 893{
899 char *file1 = ofile1; 894 char *file1 = ofile1;
900 char *file2 = ofile2; 895 char *file2 = ofile2;
901 FILE *f1 = stdin; 896 FILE *f1 = stdin, *f2 = stdin;
902 FILE *f2 = stdin; 897 unsigned rval;
903 int rval = D_SAME;
904 int i; 898 int i;
905 899
906 anychange = 0; 900 anychange = 0;
@@ -908,6 +902,9 @@ static int diffreg(char *ofile1, char *ofile2, int flags)
908 902
909 if (S_ISDIR(stb1.st_mode) != S_ISDIR(stb2.st_mode)) 903 if (S_ISDIR(stb1.st_mode) != S_ISDIR(stb2.st_mode))
910 return (S_ISDIR(stb1.st_mode) ? D_MISMATCH1 : D_MISMATCH2); 904 return (S_ISDIR(stb1.st_mode) ? D_MISMATCH1 : D_MISMATCH2);
905
906 rval = D_SAME;
907
911 if (LONE_DASH(file1) && LONE_DASH(file2)) 908 if (LONE_DASH(file1) && LONE_DASH(file2))
912 goto closem; 909 goto closem;
913 910
@@ -980,10 +977,8 @@ static int diffreg(char *ofile1, char *ofile2, int flags)
980 if (rval == D_SAME) 977 if (rval == D_SAME)
981 rval = D_DIFFER; 978 rval = D_DIFFER;
982 } 979 }
983 if (f1 != NULL) 980 fclose_if_not_stdin(f1);
984 fclose(f1); 981 fclose_if_not_stdin(f2);
985 if (f2 != NULL)
986 fclose(f2);
987 if (file1 != ofile1) 982 if (file1 != ofile1)
988 free(file1); 983 free(file1);
989 if (file2 != ofile2) 984 if (file2 != ofile2)
@@ -998,19 +993,23 @@ static void do_diff(char *dir1, char *path1, char *dir2, char *path2)
998 int flags = D_HEADER; 993 int flags = D_HEADER;
999 int val; 994 int val;
1000 995
1001 char *fullpath1 = xasprintf("%s/%s", dir1, path1); 996 char *fullpath1 = concat_path_file(dir1, path1);
1002 char *fullpath2 = xasprintf("%s/%s", dir2, path2); 997 char *fullpath2 = concat_path_file(dir2, path2);
1003 998
1004 if (stat(fullpath1, &stb1) != 0) { 999 if (stat(fullpath1, &stb1) != 0) {
1005 flags |= D_EMPTY1; 1000 flags |= D_EMPTY1;
1006 memset(&stb1, 0, sizeof(stb1)); 1001 memset(&stb1, 0, sizeof(stb1));
1007 fullpath1 = xasprintf("%s/%s", dir1, path2); 1002 if (ENABLE_FEATURE_CLEAN_UP)
1003 free(fullpath1);
1004 fullpath1 = concat_path_file(dir1, path2);
1008 } 1005 }
1009 if (stat(fullpath2, &stb2) != 0) { 1006 if (stat(fullpath2, &stb2) != 0) {
1010 flags |= D_EMPTY2; 1007 flags |= D_EMPTY2;
1011 memset(&stb2, 0, sizeof(stb2)); 1008 memset(&stb2, 0, sizeof(stb2));
1012 stb2.st_mode = stb1.st_mode; 1009 stb2.st_mode = stb1.st_mode;
1013 fullpath2 = xasprintf("%s/%s", dir2, path1); 1010 if (ENABLE_FEATURE_CLEAN_UP)
1011 free(fullpath2);
1012 fullpath2 = concat_path_file(dir2, path1);
1014 } 1013 }
1015 1014
1016 if (stb1.st_mode == 0) 1015 if (stb1.st_mode == 0)
@@ -1173,7 +1172,7 @@ static void diffdir(char *p1, char *p2)
1173 1172
1174int diff_main(int argc, char **argv) 1173int diff_main(int argc, char **argv)
1175{ 1174{
1176 int gotstdin = 0; 1175 smallint gotstdin = 0;
1177 char *U_opt; 1176 char *U_opt;
1178 char *f1, *f2; 1177 char *f1, *f2;
1179 llist_t *L_arg = NULL; 1178 llist_t *L_arg = NULL;
@@ -1234,6 +1233,7 @@ int diff_main(int argc, char **argv)
1234 f2 = concat_path_file(f2, f1); 1233 f2 = concat_path_file(f2, f1);
1235 xstat(f2, &stb2); 1234 xstat(f2, &stb2);
1236 } 1235 }
1236/* XXX: FIXME: */
1237/* We can't diff e.g. stdin supplied by a pipe - we use rewind(), fseek(). 1237/* We can't diff e.g. stdin supplied by a pipe - we use rewind(), fseek().
1238 * This can be fixed (volunteers?) */ 1238 * This can be fixed (volunteers?) */
1239 if (!S_ISREG(stb1.st_mode) || !S_ISREG(stb2.st_mode)) 1239 if (!S_ISREG(stb1.st_mode) || !S_ISREG(stb2.st_mode))