aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-03-24 16:19:21 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-03-24 16:19:21 +0000
commit7fe0ebac5f22a810ee25ea182582ee71d6bf86b2 (patch)
treed3fb51f5e56ee6d7e291eb43dd36c62bb7753609
parent73132b9c1204500239032f4e36602d41051d29c2 (diff)
downloadbusybox-w32-7fe0ebac5f22a810ee25ea182582ee71d6bf86b2.tar.gz
busybox-w32-7fe0ebac5f22a810ee25ea182582ee71d6bf86b2.tar.bz2
busybox-w32-7fe0ebac5f22a810ee25ea182582ee71d6bf86b2.zip
diff: reordering and renaming of variables
function old new delta diff_main 843 848 +5 get_recursive_dirlist 177 180 +3 add_to_dirlist 64 66 +2 change 329 326 -3 files_differ 182 176 -6 diffreg 1823 1808 -15 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/3 up/down: 10/-24) Total: -14 bytes
-rw-r--r--editors/diff.c133
1 files changed, 66 insertions, 67 deletions
diff --git a/editors/diff.c b/editors/diff.c
index 4886f6306..7a6422564 100644
--- a/editors/diff.c
+++ b/editors/diff.c
@@ -95,54 +95,53 @@ struct context_vec {
95#define g_read_buf bb_common_bufsiz1 95#define g_read_buf bb_common_bufsiz1
96 96
97struct globals { 97struct globals {
98 USE_FEATURE_DIFF_DIR(char **dl;) 98 bool anychange;
99 smallint exit_status;
100 int opt_U_context;
101 size_t max_context; /* size of context_vec_start */
99 USE_FEATURE_DIFF_DIR(int dl_count;) 102 USE_FEATURE_DIFF_DIR(int dl_count;)
100 int status; 103 USE_FEATURE_DIFF_DIR(char **dl;)
101 /* This is the default number of lines of context. */ 104 char *opt_S_start;
102 int context;
103 size_t max_context;
104 char *start;
105 const char *label1; 105 const char *label1;
106 const char *label2; 106 const char *label2;
107 struct line *file[2]; 107 int *J; /* will be overlaid on class */
108 int *J; /* will be overlaid on class */
109 int clen; 108 int clen;
110 int len[2]; 109 int pref, suff; /* length of prefix and suffix */
111 int pref, suff; /* length of prefix and suffix */ 110 int nlen[2];
112 int slen[2]; 111 int slen[2];
113 bool anychange; 112 int clistlen; /* the length of clist */
114 long *ixnew; /* will be overlaid on file[1] */ 113 struct cand *clist; /* merely a free storage pot for candidates */
115 long *ixold; /* will be overlaid on klist */ 114 long *ixnew; /* will be overlaid on nfile[1] */
116 struct cand *clist; /* merely a free storage pot for candidates */ 115 long *ixold; /* will be overlaid on klist */
117 int clistlen; /* the length of clist */ 116 struct line *nfile[2];
118 struct line *sfile[2]; /* shortened by pruning common prefix/suffix */ 117 struct line *sfile[2]; /* shortened by pruning common prefix/suffix */
119 struct context_vec *context_vec_start; 118 struct context_vec *context_vec_start;
120 struct context_vec *context_vec_end; 119 struct context_vec *context_vec_end;
121 struct context_vec *context_vec_ptr; 120 struct context_vec *context_vec_ptr;
122 struct stat stb1, stb2;
123 char *tempname1, *tempname2; 121 char *tempname1, *tempname2;
122 struct stat stb1, stb2;
124}; 123};
125#define G (*ptr_to_globals) 124#define G (*ptr_to_globals)
126#define dl (G.dl ) 125#define anychange (G.anychange )
127#define dl_count (G.dl_count ) 126#define exit_status (G.exit_status )
128#define context (G.context ) 127#define opt_U_context (G.opt_U_context )
129#define max_context (G.max_context ) 128#define max_context (G.max_context )
130#define status (G.status ) 129#define dl_count (G.dl_count )
131#define start (G.start ) 130#define dl (G.dl )
131#define opt_S_start (G.opt_S_start )
132#define label1 (G.label1 ) 132#define label1 (G.label1 )
133#define label2 (G.label2 ) 133#define label2 (G.label2 )
134#define file (G.file )
135#define J (G.J ) 134#define J (G.J )
136#define clen (G.clen ) 135#define clen (G.clen )
137#define len (G.len )
138#define pref (G.pref ) 136#define pref (G.pref )
139#define suff (G.suff ) 137#define suff (G.suff )
138#define nlen (G.nlen )
140#define slen (G.slen ) 139#define slen (G.slen )
141#define anychange (G.anychange ) 140#define clistlen (G.clistlen )
141#define clist (G.clist )
142#define ixnew (G.ixnew ) 142#define ixnew (G.ixnew )
143#define ixold (G.ixold ) 143#define ixold (G.ixold )
144#define clist (G.clist ) 144#define nfile (G.nfile )
145#define clistlen (G.clistlen )
146#define sfile (G.sfile ) 145#define sfile (G.sfile )
147#define context_vec_start (G.context_vec_start ) 146#define context_vec_start (G.context_vec_start )
148#define context_vec_end (G.context_vec_end ) 147#define context_vec_end (G.context_vec_end )
@@ -153,7 +152,7 @@ struct globals {
153#define tempname2 (G.tempname2 ) 152#define tempname2 (G.tempname2 )
154#define INIT_G() do { \ 153#define INIT_G() do { \
155 SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \ 154 SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \
156 context = 3; \ 155 opt_U_context = 3; \
157 max_context = 64; \ 156 max_context = 64; \
158} while (0) 157} while (0)
159 158
@@ -353,8 +352,8 @@ static void prepare(int i, FILE *fp /*, off_t filesize*/)
353 } 352 }
354 p[++j].value = h; 353 p[++j].value = h;
355 } 354 }
356 len[i] = j; 355 nlen[i] = j;
357 file[i] = p; 356 nfile[i] = p;
358} 357}
359 358
360 359
@@ -362,16 +361,16 @@ static void prune(void)
362{ 361{
363 int i, j; 362 int i, j;
364 363
365 for (pref = 0; pref < len[0] && pref < len[1] && 364 for (pref = 0; pref < nlen[0] && pref < nlen[1] &&
366 file[0][pref + 1].value == file[1][pref + 1].value; pref++) 365 nfile[0][pref + 1].value == nfile[1][pref + 1].value; pref++)
367 continue; 366 continue;
368 for (suff = 0; suff < len[0] - pref && suff < len[1] - pref && 367 for (suff = 0; suff < nlen[0] - pref && suff < nlen[1] - pref &&
369 file[0][len[0] - suff].value == file[1][len[1] - suff].value; 368 nfile[0][nlen[0] - suff].value == nfile[1][nlen[1] - suff].value;
370 suff++) 369 suff++)
371 continue; 370 continue;
372 for (j = 0; j < 2; j++) { 371 for (j = 0; j < 2; j++) {
373 sfile[j] = file[j] + pref; 372 sfile[j] = nfile[j] + pref;
374 slen[j] = len[j] - pref - suff; 373 slen[j] = nlen[j] - pref - suff;
375 for (i = 0; i <= slen[j]; i++) 374 for (i = 0; i <= slen[j]; i++)
376 sfile[j][i].serial = i; 375 sfile[j][i].serial = i;
377 } 376 }
@@ -516,8 +515,8 @@ static void unravel(int p)
516 struct cand *q; 515 struct cand *q;
517 int i; 516 int i;
518 517
519 for (i = 0; i <= len[0]; i++) 518 for (i = 0; i <= nlen[0]; i++)
520 J[i] = i <= pref ? i : i > len[0] - suff ? i + len[1] - len[0] : 0; 519 J[i] = i <= pref ? i : i > nlen[0] - suff ? i + nlen[1] - nlen[0] : 0;
521 for (q = clist + p; q->y != 0; q = clist + q->pred) 520 for (q = clist + p; q->y != 0; q = clist + q->pred)
522 J[q->x + pref] = q->y + pref; 521 J[q->x + pref] = q->y + pref;
523} 522}
@@ -563,7 +562,7 @@ static NOINLINE void check(FILE *f1, FILE *f2)
563 ixold[0] = ixnew[0] = 0; 562 ixold[0] = ixnew[0] = 0;
564 jackpot = 0; 563 jackpot = 0;
565 ctold = ctnew = 0; 564 ctold = ctnew = 0;
566 for (i = 1; i <= len[0]; i++) { 565 for (i = 1; i <= nlen[0]; i++) {
567 if (J[i] == 0) { 566 if (J[i] == 0) {
568 ixold[i] = ctold += skipline(f1); 567 ixold[i] = ctold += skipline(f1);
569 continue; 568 continue;
@@ -645,7 +644,7 @@ static NOINLINE void check(FILE *f1, FILE *f2)
645 ixnew[j] = ctnew; 644 ixnew[j] = ctnew;
646 j++; 645 j++;
647 } 646 }
648 for (; j <= len[1]; j++) 647 for (; j <= nlen[1]; j++)
649 ixnew[j] = ctnew += skipline(f2); 648 ixnew[j] = ctnew += skipline(f2);
650} 649}
651 650
@@ -764,10 +763,10 @@ static void dump_unified_vec(FILE *f1, FILE *f2)
764 return; 763 return;
765 764
766 b = d = 0; /* gcc */ 765 b = d = 0; /* gcc */
767 lowa = MAX(1, cvp->a - context); 766 lowa = MAX(1, cvp->a - opt_U_context);
768 upb = MIN(len[0], context_vec_ptr->b + context); 767 upb = MIN(nlen[0], context_vec_ptr->b + opt_U_context);
769 lowc = MAX(1, cvp->c - context); 768 lowc = MAX(1, cvp->c - opt_U_context);
770 upd = MIN(len[1], context_vec_ptr->d + context); 769 upd = MIN(nlen[1], context_vec_ptr->d + opt_U_context);
771 770
772 printf("@@ -"); 771 printf("@@ -");
773 uni_range(lowa, upb); 772 uni_range(lowa, upb);
@@ -875,8 +874,8 @@ static void change(char *file1, FILE *f1, char *file2, FILE *f2,
875 * Print the context/unidiff header first time through. 874 * Print the context/unidiff header first time through.
876 */ 875 */
877 print_header(file1, file2); 876 print_header(file1, file2);
878 } else if (a > context_vec_ptr->b + (2 * context) + 1 877 } else if (a > context_vec_ptr->b + (2 * opt_U_context) + 1
879 && c > context_vec_ptr->d + (2 * context) + 1 878 && c > context_vec_ptr->d + (2 * opt_U_context) + 1
880 ) { 879 ) {
881 /* 880 /*
882 * If this change is more than 'context' lines from the 881 * If this change is more than 'context' lines from the
@@ -902,9 +901,9 @@ static void output(char *file1, FILE *f1, char *file2, FILE *f2)
902 901
903 rewind(f1); 902 rewind(f1);
904 rewind(f2); 903 rewind(f2);
905 m = len[0]; 904 m = nlen[0];
906 J[0] = 0; 905 J[0] = 0;
907 J[m + 1] = len[1] + 1; 906 J[m + 1] = nlen[1] + 1;
908 for (i0 = 1; i0 <= m; i0 = i1 + 1) { 907 for (i0 = 1; i0 <= m; i0 = i1 + 1) {
909 while (i0 <= m && J[i0] == J[i0 - 1] + 1) 908 while (i0 <= m && J[i0] == J[i0 - 1] + 1)
910 i0++; 909 i0++;
@@ -919,7 +918,7 @@ static void output(char *file1, FILE *f1, char *file2, FILE *f2)
919 } 918 }
920 if (m == 0) { 919 if (m == 0) {
921// change() seeks! 920// change() seeks!
922 change(file1, f1, file2, f2, 1, 0, 1, len[1]); 921 change(file1, f1, file2, f2, 1, 0, 1, nlen[1]);
923 } 922 }
924 if (anychange != 0 && !(option_mask32 & FLAG_q)) { 923 if (anychange != 0 && !(option_mask32 & FLAG_q)) {
925// dump_unified_vec() seeks! 924// dump_unified_vec() seeks!
@@ -993,9 +992,9 @@ static void output(char *file1, FILE *f1, char *file2, FILE *f2)
993 * are not both DIRectories. */ 992 * are not both DIRectories. */
994static unsigned diffreg(char *file1, char *file2, int flags) 993static unsigned diffreg(char *file1, char *file2, int flags)
995{ 994{
996 int *member; /* will be overlaid on file[1] */ 995 int *member; /* will be overlaid on nfile[1] */
997 int *class; /* will be overlaid on file[0] */ 996 int *class; /* will be overlaid on nfile[0] */
998 int *klist; /* will be overlaid on file[0] after class */ 997 int *klist; /* will be overlaid on nfile[0] after class */
999 FILE *f1; 998 FILE *f1;
1000 FILE *f2; 999 FILE *f2;
1001 unsigned rval; 1000 unsigned rval;
@@ -1025,13 +1024,13 @@ static unsigned diffreg(char *file1, char *file2, int flags)
1025 i = files_differ(f1, f2, flags); 1024 i = files_differ(f1, f2, flags);
1026 if (i != 1) { /* not different? */ 1025 if (i != 1) { /* not different? */
1027 if (i != 0) /* error? */ 1026 if (i != 0) /* error? */
1028 status |= 2; 1027 exit_status |= 2;
1029 goto closem; 1028 goto closem;
1030 } 1029 }
1031 1030
1032 if (!asciifile(f1) || !asciifile(f2)) { 1031 if (!asciifile(f1) || !asciifile(f2)) {
1033 rval = D_BINARY; 1032 rval = D_BINARY;
1034 status |= 1; 1033 exit_status |= 1;
1035 goto closem; 1034 goto closem;
1036 } 1035 }
1037 1036
@@ -1042,11 +1041,11 @@ static unsigned diffreg(char *file1, char *file2, int flags)
1042 sort(sfile[0], slen[0]); 1041 sort(sfile[0], slen[0]);
1043 sort(sfile[1], slen[1]); 1042 sort(sfile[1], slen[1]);
1044 1043
1045 member = (int *) file[1]; 1044 member = (int *) nfile[1];
1046 equiv(sfile[0], slen[0], sfile[1], slen[1], member); 1045 equiv(sfile[0], slen[0], sfile[1], slen[1], member);
1047 member = xrealloc(member, (slen[1] + 2) * sizeof(int)); 1046 member = xrealloc(member, (slen[1] + 2) * sizeof(int));
1048 1047
1049 class = (int *) file[0]; 1048 class = (int *) nfile[0];
1050 unsort(sfile[0], slen[0], class); 1049 unsort(sfile[0], slen[0], class);
1051 class = xrealloc(class, (slen[0] + 2) * sizeof(int)); 1050 class = xrealloc(class, (slen[0] + 2) * sizeof(int));
1052 1051
@@ -1058,13 +1057,13 @@ static unsigned diffreg(char *file1, char *file2, int flags)
1058 free(member); 1057 free(member);
1059 free(class); 1058 free(class);
1060 1059
1061 J = xrealloc(J, (len[0] + 2) * sizeof(int)); 1060 J = xrealloc(J, (nlen[0] + 2) * sizeof(int));
1062 unravel(klist[i]); 1061 unravel(klist[i]);
1063 free(clist); 1062 free(clist);
1064 free(klist); 1063 free(klist);
1065 1064
1066 ixold = xrealloc(ixold, (len[0] + 2) * sizeof(long)); 1065 ixold = xrealloc(ixold, (nlen[0] + 2) * sizeof(long));
1067 ixnew = xrealloc(ixnew, (len[1] + 2) * sizeof(long)); 1066 ixnew = xrealloc(ixnew, (nlen[1] + 2) * sizeof(long));
1068// Rewind inside! 1067// Rewind inside!
1069 check(f1, f2); 1068 check(f1, f2);
1070// Rewind inside! 1069// Rewind inside!
@@ -1072,7 +1071,7 @@ static unsigned diffreg(char *file1, char *file2, int flags)
1072 1071
1073 closem: 1072 closem:
1074 if (anychange) { 1073 if (anychange) {
1075 status |= 1; 1074 exit_status |= 1;
1076 if (rval == D_SAME) 1075 if (rval == D_SAME)
1077 rval = D_DIFFER; 1076 rval = D_DIFFER;
1078 } 1077 }
@@ -1216,10 +1215,10 @@ static void diffdir(char *p1, char *p2)
1216 dirlist2 = get_recursive_dirlist(p2); 1215 dirlist2 = get_recursive_dirlist(p2);
1217 1216
1218 /* If -S was set, find the starting point. */ 1217 /* If -S was set, find the starting point. */
1219 if (start) { 1218 if (opt_S_start) {
1220 while (*dirlist1 != NULL && strcmp(*dirlist1, start) < 0) 1219 while (*dirlist1 != NULL && strcmp(*dirlist1, opt_S_start) < 0)
1221 dirlist1++; 1220 dirlist1++;
1222 while (*dirlist2 != NULL && strcmp(*dirlist2, start) < 0) 1221 while (*dirlist2 != NULL && strcmp(*dirlist2, opt_S_start) < 0)
1223 dirlist2++; 1222 dirlist2++;
1224 if ((*dirlist1 == NULL) || (*dirlist2 == NULL)) 1223 if ((*dirlist1 == NULL) || (*dirlist2 == NULL))
1225 bb_error_msg(bb_msg_invalid_arg, "NULL", "-S"); 1224 bb_error_msg(bb_msg_invalid_arg, "NULL", "-S");
@@ -1268,7 +1267,7 @@ int diff_main(int argc ATTRIBUTE_UNUSED, char **argv)
1268 opt_complementary = "=2:L::U+"; 1267 opt_complementary = "=2:L::U+";
1269 getopt32(argv, "abdiL:NqrsS:tTU:wu" 1268 getopt32(argv, "abdiL:NqrsS:tTU:wu"
1270 "p" /* ignored (for compatibility) */, 1269 "p" /* ignored (for compatibility) */,
1271 &L_arg, &start, &context); 1270 &L_arg, &opt_S_start, &opt_U_context);
1272 /*argc -= optind;*/ 1271 /*argc -= optind;*/
1273 argv += optind; 1272 argv += optind;
1274 while (L_arg) { 1273 while (L_arg) {
@@ -1307,7 +1306,7 @@ int diff_main(int argc ATTRIBUTE_UNUSED, char **argv)
1307 if (S_ISDIR(stb1.st_mode) && S_ISDIR(stb2.st_mode)) { 1306 if (S_ISDIR(stb1.st_mode) && S_ISDIR(stb2.st_mode)) {
1308#if ENABLE_FEATURE_DIFF_DIR 1307#if ENABLE_FEATURE_DIFF_DIR
1309 diffdir(f1, f2); 1308 diffdir(f1, f2);
1310 return status; 1309 return exit_status;
1311#else 1310#else
1312 bb_error_msg_and_die("no support for directory comparison"); 1311 bb_error_msg_and_die("no support for directory comparison");
1313#endif 1312#endif
@@ -1330,5 +1329,5 @@ int diff_main(int argc ATTRIBUTE_UNUSED, char **argv)
1330 * they are not both DIRestories */ 1329 * they are not both DIRestories */
1331 print_status((gotstdin > 1 ? D_SAME : diffreg(f1, f2, 0)), 1330 print_status((gotstdin > 1 ? D_SAME : diffreg(f1, f2, 0)),
1332 f1, f2 /*, NULL*/); 1331 f1, f2 /*, NULL*/);
1333 return status; 1332 return exit_status;
1334} 1333}