aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--editors/diff.c63
1 files changed, 25 insertions, 38 deletions
diff --git a/editors/diff.c b/editors/diff.c
index e3933e724..42aba9ae0 100644
--- a/editors/diff.c
+++ b/editors/diff.c
@@ -102,7 +102,7 @@ struct globals {
102 bool anychange; 102 bool anychange;
103 smallint exit_status; 103 smallint exit_status;
104 int opt_U_context; 104 int opt_U_context;
105 size_t max_context; /* size of context_vec_start */ 105 int context_idx;
106 IF_FEATURE_DIFF_DIR(int dl_count;) 106 IF_FEATURE_DIFF_DIR(int dl_count;)
107 IF_FEATURE_DIFF_DIR(char **dl;) 107 IF_FEATURE_DIFF_DIR(char **dl;)
108 char *opt_S_start; 108 char *opt_S_start;
@@ -119,9 +119,7 @@ struct globals {
119 long *ixold; /* will be overlaid on klist */ 119 long *ixold; /* will be overlaid on klist */
120 struct line *nfile[2]; 120 struct line *nfile[2];
121 struct line *sfile[2]; /* shortened by pruning common prefix/suffix */ 121 struct line *sfile[2]; /* shortened by pruning common prefix/suffix */
122 struct context_vec *context_vec_start; 122 struct context_vec *context_vector;
123 struct context_vec *context_vec_end;
124 struct context_vec *context_vec_ptr;
125 char *tempname1, *tempname2; 123 char *tempname1, *tempname2;
126 struct stat stb1, stb2; 124 struct stat stb1, stb2;
127}; 125};
@@ -129,7 +127,7 @@ struct globals {
129#define anychange (G.anychange ) 127#define anychange (G.anychange )
130#define exit_status (G.exit_status ) 128#define exit_status (G.exit_status )
131#define opt_U_context (G.opt_U_context ) 129#define opt_U_context (G.opt_U_context )
132#define max_context (G.max_context ) 130#define context_idx (G.context_idx )
133#define dl_count (G.dl_count ) 131#define dl_count (G.dl_count )
134#define dl (G.dl ) 132#define dl (G.dl )
135#define opt_S_start (G.opt_S_start ) 133#define opt_S_start (G.opt_S_start )
@@ -147,9 +145,7 @@ struct globals {
147#define ixold (G.ixold ) 145#define ixold (G.ixold )
148#define nfile (G.nfile ) 146#define nfile (G.nfile )
149#define sfile (G.sfile ) 147#define sfile (G.sfile )
150#define context_vec_start (G.context_vec_start ) 148#define context_vector (G.context_vector )
151#define context_vec_end (G.context_vec_end )
152#define context_vec_ptr (G.context_vec_ptr )
153#define stb1 (G.stb1 ) 149#define stb1 (G.stb1 )
154#define stb2 (G.stb2 ) 150#define stb2 (G.stb2 )
155#define tempname1 (G.tempname1 ) 151#define tempname1 (G.tempname1 )
@@ -157,7 +153,7 @@ struct globals {
157#define INIT_G() do { \ 153#define INIT_G() do { \
158 SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \ 154 SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \
159 opt_U_context = 3; \ 155 opt_U_context = 3; \
160 max_context = 64; \ 156 context_vector = xrealloc_vector(context_vector, 6, 0); \
161} while (0) 157} while (0)
162 158
163 159
@@ -230,11 +226,10 @@ static ALWAYS_INLINE int fiddle_sum(int sum, int t)
230} 226}
231static int readhash(FILE *fp) 227static int readhash(FILE *fp)
232{ 228{
233 int i, t, space; 229 int i, t;
234 int sum; 230 int sum;
235 231
236 sum = 1; 232 sum = 1;
237 space = 0;
238 i = 0; 233 i = 0;
239 if (!(option_mask32 & (FLAG_b | FLAG_w))) { 234 if (!(option_mask32 & (FLAG_b | FLAG_w))) {
240 while ((t = getc(fp)) != '\n') { 235 while ((t = getc(fp)) != '\n') {
@@ -247,8 +242,11 @@ static int readhash(FILE *fp)
247 i = 1; 242 i = 1;
248 } 243 }
249 } else { 244 } else {
245 int space = 0;
246
250 while (1) { 247 while (1) {
251 switch (t = getc(fp)) { 248 t = getc(fp);
249 switch (t) {
252 case '\t': 250 case '\t':
253 case '\r': 251 case '\r':
254 case '\v': 252 case '\v':
@@ -763,19 +761,19 @@ static int asciifile(FILE *f)
763/* dump accumulated "unified" diff changes */ 761/* dump accumulated "unified" diff changes */
764static void dump_unified_vec(FILE *f1, FILE *f2) 762static void dump_unified_vec(FILE *f1, FILE *f2)
765{ 763{
766 struct context_vec *cvp = context_vec_start; 764 struct context_vec *cvp = context_vector;
767 int lowa, upb, lowc, upd; 765 int lowa, upb, lowc, upd;
768 int a, b, c, d; 766 int a, b, c, d;
769 char ch; 767 char ch;
770 768
771 if (context_vec_start > context_vec_ptr) 769 if (context_idx < 0)
772 return; 770 return;
773 771
774 b = d = 0; /* gcc */ 772 b = d = 0; /* gcc */
775 lowa = MAX(1, cvp->a - opt_U_context); 773 lowa = MAX(1, cvp->a - opt_U_context);
776 upb = MIN(nlen[0], context_vec_ptr->b + opt_U_context); 774 upb = MIN(nlen[0], context_vector[context_idx].b + opt_U_context);
777 lowc = MAX(1, cvp->c - opt_U_context); 775 lowc = MAX(1, cvp->c - opt_U_context);
778 upd = MIN(nlen[1], context_vec_ptr->d + opt_U_context); 776 upd = MIN(nlen[1], context_vector[context_idx].d + opt_U_context);
779 777
780 printf("@@ -"); 778 printf("@@ -");
781 uni_range(lowa, upb); 779 uni_range(lowa, upb);
@@ -787,7 +785,7 @@ static void dump_unified_vec(FILE *f1, FILE *f2)
787 * Output changes in "unified" diff format--the old and new lines 785 * Output changes in "unified" diff format--the old and new lines
788 * are printed together. 786 * are printed together.
789 */ 787 */
790 for (; cvp <= context_vec_ptr; cvp++) { 788 for (; cvp <= &context_vector[context_idx]; cvp++) {
791 a = cvp->a; 789 a = cvp->a;
792 b = cvp->b; 790 b = cvp->b;
793 c = cvp->c; 791 c = cvp->c;
@@ -834,7 +832,7 @@ static void dump_unified_vec(FILE *f1, FILE *f2)
834 } 832 }
835 fetch(ixnew, d + 1, upd, f2, ' '); 833 fetch(ixnew, d + 1, upd, f2, ' ');
836 834
837 context_vec_ptr = context_vec_start - 1; 835 context_idx = -1;
838} 836}
839 837
840 838
@@ -866,25 +864,13 @@ static void change(const char *file1, FILE *f1, const char *file2, FILE *f2,
866 return; 864 return;
867 } 865 }
868 866
869 /*
870 * Allocate change records as needed.
871 */
872 if (context_vec_ptr == context_vec_end - 1) {
873 ptrdiff_t offset = context_vec_ptr - context_vec_start;
874
875 max_context <<= 1;
876 context_vec_start = xrealloc(context_vec_start,
877 max_context * sizeof(struct context_vec));
878 context_vec_end = context_vec_start + max_context;
879 context_vec_ptr = context_vec_start + offset;
880 }
881 if (anychange == 0) { 867 if (anychange == 0) {
882 /* 868 /*
883 * Print the context/unidiff header first time through. 869 * Print the context/unidiff header first time through.
884 */ 870 */
885 print_header(file1, file2); 871 print_header(file1, file2);
886 } else if (a > context_vec_ptr->b + (2 * opt_U_context) + 1 872 } else if (a > context_vector[context_idx].b + (2 * opt_U_context) + 1
887 && c > context_vec_ptr->d + (2 * opt_U_context) + 1 873 && c > context_vector[context_idx].d + (2 * opt_U_context) + 1
888 ) { 874 ) {
889 /* 875 /*
890 * If this change is more than 'context' lines from the 876 * If this change is more than 'context' lines from the
@@ -893,11 +879,12 @@ static void change(const char *file1, FILE *f1, const char *file2, FILE *f2,
893// dump_unified_vec() seeks! 879// dump_unified_vec() seeks!
894 dump_unified_vec(f1, f2); 880 dump_unified_vec(f1, f2);
895 } 881 }
896 context_vec_ptr++; 882 context_idx++;
897 context_vec_ptr->a = a; 883 context_vector = xrealloc_vector(context_vector, 6, context_idx);
898 context_vec_ptr->b = b; 884 context_vector[context_idx].a = a;
899 context_vec_ptr->c = c; 885 context_vector[context_idx].b = b;
900 context_vec_ptr->d = d; 886 context_vector[context_idx].c = c;
887 context_vector[context_idx].d = d;
901 anychange = 1; 888 anychange = 1;
902} 889}
903 890
@@ -1010,7 +997,7 @@ static unsigned diffreg(const char *file1, const char *file2, int flags)
1010 int i; 997 int i;
1011 998
1012 anychange = 0; 999 anychange = 0;
1013 context_vec_ptr = context_vec_start - 1; 1000 context_idx = -1;
1014 tempname1 = tempname2 = NULL; 1001 tempname1 = tempname2 = NULL;
1015 1002
1016 /* Is any of them a directory? Then it's simple */ 1003 /* Is any of them a directory? Then it's simple */