version 1.76, 2010/07/15 18:31:33 |
version 1.77, 2010/07/15 21:32:37 |
|
|
int d; /* end line in new file */ |
int d; /* end line in new file */ |
}; |
}; |
|
|
|
#define diff_output printf |
static FILE *opentemp(const char *); |
static FILE *opentemp(const char *); |
static void output(char *, FILE *, char *, FILE *, int); |
static void output(char *, FILE *, char *, FILE *, int); |
static void check(FILE *, FILE *, int); |
static void check(FILE *, FILE *, int); |
|
|
#define c i0 |
#define c i0 |
if ((c = getc(f1)) == EOF) |
if ((c = getc(f1)) == EOF) |
return; |
return; |
putchar(c); |
diff_output("%c", c); |
} |
} |
#undef c |
#undef c |
} |
} |
|
|
static void |
static void |
range(int a, int b, char *separator) |
range(int a, int b, char *separator) |
{ |
{ |
printf("%d", a > b ? b : a); |
diff_output("%d", a > b ? b : a); |
if (a < b) |
if (a < b) |
printf("%s%d", separator, b); |
diff_output("%s%d", separator, b); |
} |
} |
|
|
static void |
static void |
uni_range(int a, int b) |
uni_range(int a, int b) |
{ |
{ |
if (a < b) |
if (a < b) |
printf("%d,%d", a, b - a + 1); |
diff_output("%d,%d", a, b - a + 1); |
else if (a == b) |
else if (a == b) |
printf("%d", b); |
diff_output("%d", b); |
else |
else |
printf("%d,0", b); |
diff_output("%d,0", b); |
} |
} |
|
|
static char * |
static char * |
|
|
} |
} |
proceed: |
proceed: |
if (*pflags & D_HEADER) { |
if (*pflags & D_HEADER) { |
printf("%s %s %s\n", diffargs, file1, file2); |
diff_output("%s %s %s\n", diffargs, file1, file2); |
*pflags &= ~D_HEADER; |
*pflags &= ~D_HEADER; |
} |
} |
if (diff_format == D_CONTEXT || diff_format == D_UNIFIED) { |
if (diff_format == D_CONTEXT || diff_format == D_UNIFIED) { |
|
|
case D_NORMAL: |
case D_NORMAL: |
case D_EDIT: |
case D_EDIT: |
range(a, b, ","); |
range(a, b, ","); |
putchar(a > b ? 'a' : c > d ? 'd' : 'c'); |
diff_output("%c", a > b ? 'a' : c > d ? 'd' : 'c'); |
if (diff_format == D_NORMAL) |
if (diff_format == D_NORMAL) |
range(c, d, ","); |
range(c, d, ","); |
putchar('\n'); |
diff_output("\n"); |
break; |
break; |
case D_REVERSE: |
case D_REVERSE: |
putchar(a > b ? 'a' : c > d ? 'd' : 'c'); |
diff_output("%c", a > b ? 'a' : c > d ? 'd' : 'c'); |
range(a, b, " "); |
range(a, b, " "); |
putchar('\n'); |
diff_output("\n"); |
break; |
break; |
case D_NREVERSE: |
case D_NREVERSE: |
if (a > b) |
if (a > b) |
printf("a%d %d\n", b, d - c + 1); |
diff_output("a%d %d\n", b, d - c + 1); |
else { |
else { |
printf("d%d %d\n", a, b - a + 1); |
diff_output("d%d %d\n", a, b - a + 1); |
if (!(c > d)) |
if (!(c > d)) |
/* add changed lines */ |
/* add changed lines */ |
printf("a%d %d\n", b, d - c + 1); |
diff_output("a%d %d\n", b, d - c + 1); |
} |
} |
break; |
break; |
} |
} |
if (diff_format == D_NORMAL || diff_format == D_IFDEF) { |
if (diff_format == D_NORMAL || diff_format == D_IFDEF) { |
fetch(ixold, a, b, f1, '<', 1, *pflags); |
fetch(ixold, a, b, f1, '<', 1, *pflags); |
if (a <= b && c <= d && diff_format == D_NORMAL) |
if (a <= b && c <= d && diff_format == D_NORMAL) |
puts("---"); |
diff_output("---\n"); |
} |
} |
i = fetch(ixnew, c, d, f2, diff_format == D_NORMAL ? '>' : '\0', 0, *pflags); |
i = fetch(ixnew, c, d, f2, diff_format == D_NORMAL ? '>' : '\0', 0, *pflags); |
if (i != 0 && diff_format == D_EDIT) { |
if (i != 0 && diff_format == D_EDIT) { |
|
|
* it. We have to add a substitute command to change this |
* it. We have to add a substitute command to change this |
* back and restart where we left off. |
* back and restart where we left off. |
*/ |
*/ |
puts("."); |
diff_output(".\n"); |
printf("%ds/^\\.\\././\n", a); |
diff_output("%ds/^\\.\\././\n", a); |
a += i; |
a += i; |
c += i; |
c += i; |
goto restart; |
goto restart; |
} |
} |
if ((diff_format == D_EDIT || diff_format == D_REVERSE) && c <= d) |
if ((diff_format == D_EDIT || diff_format == D_REVERSE) && c <= d) |
puts("."); |
diff_output(".\n"); |
if (inifdef) { |
if (inifdef) { |
printf("#endif /* %s */\n", ifdefname); |
diff_output("#endif /* %s */\n", ifdefname); |
inifdef = 0; |
inifdef = 0; |
} |
} |
} |
} |
|
|
/* print through if append (a>b), else to (nb: 0 vs 1 orig) */ |
/* print through if append (a>b), else to (nb: 0 vs 1 orig) */ |
nc = f[a > b ? b : a - 1] - curpos; |
nc = f[a > b ? b : a - 1] - curpos; |
for (i = 0; i < nc; i++) |
for (i = 0; i < nc; i++) |
putchar(getc(lb)); |
diff_output("%c", getc(lb)); |
} |
} |
if (a > b) |
if (a > b) |
return (0); |
return (0); |
if (diff_format == D_IFDEF) { |
if (diff_format == D_IFDEF) { |
if (inifdef) { |
if (inifdef) { |
printf("#else /* %s%s */\n", |
diff_output("#else /* %s%s */\n", |
oldfile == 1 ? "!" : "", ifdefname); |
oldfile == 1 ? "!" : "", ifdefname); |
} else { |
} else { |
if (oldfile) |
if (oldfile) |
printf("#ifndef %s\n", ifdefname); |
diff_output("#ifndef %s\n", ifdefname); |
else |
else |
printf("#ifdef %s\n", ifdefname); |
diff_output("#ifdef %s\n", ifdefname); |
} |
} |
inifdef = 1 + oldfile; |
inifdef = 1 + oldfile; |
} |
} |
|
|
fseek(lb, f[i - 1], SEEK_SET); |
fseek(lb, f[i - 1], SEEK_SET); |
nc = f[i] - f[i - 1]; |
nc = f[i] - f[i - 1]; |
if (diff_format != D_IFDEF && ch != '\0') { |
if (diff_format != D_IFDEF && ch != '\0') { |
putchar(ch); |
diff_output("%c", ch); |
if (Tflag && (diff_format == D_NORMAL || diff_format == D_CONTEXT |
if (Tflag && (diff_format == D_NORMAL || diff_format == D_CONTEXT |
|| diff_format == D_UNIFIED)) |
|| diff_format == D_UNIFIED)) |
putchar('\t'); |
diff_output("\t"); |
else if (diff_format != D_UNIFIED) |
else if (diff_format != D_UNIFIED) |
putchar(' '); |
diff_output(" "); |
} |
} |
col = 0; |
col = 0; |
for (j = 0, lastc = '\0'; j < nc; j++, lastc = c) { |
for (j = 0, lastc = '\0'; j < nc; j++, lastc = c) { |
|
|
diff_format == D_NREVERSE) |
diff_format == D_NREVERSE) |
warnx("No newline at end of file"); |
warnx("No newline at end of file"); |
else |
else |
puts("\n\\ No newline at end of file"); |
diff_output("\n\\ No newline at end of " |
|
"file\n"); |
return (0); |
return (0); |
} |
} |
if (c == '\t' && (flags & D_EXPANDTABS)) { |
if (c == '\t' && (flags & D_EXPANDTABS)) { |
do { |
do { |
putchar(' '); |
diff_output(" "); |
} while (++col & 7); |
} while (++col & 7); |
} else { |
} else { |
if (diff_format == D_EDIT && j == 1 && c == '\n' |
if (diff_format == D_EDIT && j == 1 && c == '\n' |
|
|
* giving the caller an offset |
* giving the caller an offset |
* from which to restart. |
* from which to restart. |
*/ |
*/ |
puts("."); |
diff_output(".\n"); |
return (i - a + 1); |
return (i - a + 1); |
} |
} |
putchar(c); |
diff_output("%c", c); |
col++; |
col++; |
} |
} |
} |
} |
|
|
lowc = MAX(1, cvp->c - diff_context); |
lowc = MAX(1, cvp->c - diff_context); |
upd = MIN(len[1], context_vec_ptr->d + diff_context); |
upd = MIN(len[1], context_vec_ptr->d + diff_context); |
|
|
printf("***************"); |
diff_output("***************"); |
if ((flags & D_PROTOTYPE)) { |
if ((flags & D_PROTOTYPE)) { |
f = match_function(ixold, lowa-1, f1); |
f = match_function(ixold, lowa-1, f1); |
if (f != NULL) { |
if (f != NULL) |
putchar(' '); |
diff_output(" %s", f); |
fputs(f, stdout); |
|
} |
|
} |
} |
printf("\n*** "); |
diff_output("\n*** "); |
range(lowa, upb, ","); |
range(lowa, upb, ","); |
printf(" ****\n"); |
diff_output(" ****\n"); |
|
|
/* |
/* |
* Output changes to the "old" file. The first loop suppresses |
* Output changes to the "old" file. The first loop suppresses |
|
|
fetch(ixold, b + 1, upb, f1, ' ', 0, flags); |
fetch(ixold, b + 1, upb, f1, ' ', 0, flags); |
} |
} |
/* output changes to the "new" file */ |
/* output changes to the "new" file */ |
printf("--- "); |
diff_output("--- "); |
range(lowc, upd, ","); |
range(lowc, upd, ","); |
printf(" ----\n"); |
diff_output(" ----\n"); |
|
|
do_output = 0; |
do_output = 0; |
for (cvp = context_vec_start; cvp <= context_vec_ptr; cvp++) |
for (cvp = context_vec_start; cvp <= context_vec_ptr; cvp++) |
|
|
lowc = MAX(1, cvp->c - diff_context); |
lowc = MAX(1, cvp->c - diff_context); |
upd = MIN(len[1], context_vec_ptr->d + diff_context); |
upd = MIN(len[1], context_vec_ptr->d + diff_context); |
|
|
fputs("@@ -", stdout); |
diff_output("@@ -"); |
uni_range(lowa, upb); |
uni_range(lowa, upb); |
fputs(" +", stdout); |
diff_output(" +"); |
uni_range(lowc, upd); |
uni_range(lowc, upd); |
fputs(" @@", stdout); |
diff_output(" @@"); |
if ((flags & D_PROTOTYPE)) { |
if ((flags & D_PROTOTYPE)) { |
f = match_function(ixold, lowa-1, f1); |
f = match_function(ixold, lowa-1, f1); |
if (f != NULL) { |
if (f != NULL) |
putchar(' '); |
diff_output(" %s", f); |
fputs(f, stdout); |
|
} |
|
} |
} |
putchar('\n'); |
diff_output("\n"); |
|
|
/* |
/* |
* Output changes in "unified" diff format--the old and new lines |
* Output changes in "unified" diff format--the old and new lines |
|
|
print_header(const char *file1, const char *file2) |
print_header(const char *file1, const char *file2) |
{ |
{ |
if (label[0] != NULL) |
if (label[0] != NULL) |
printf("%s %s\n", diff_format == D_CONTEXT ? "***" : "---", |
diff_output("%s %s\n", diff_format == D_CONTEXT ? "***" : "---", |
label[0]); |
label[0]); |
else |
else |
printf("%s %s\t%s", diff_format == D_CONTEXT ? "***" : "---", |
diff_output("%s %s\t%s", diff_format == D_CONTEXT ? "***" : "---", |
file1, ctime(&stb1.st_mtime)); |
file1, ctime(&stb1.st_mtime)); |
if (label[1] != NULL) |
if (label[1] != NULL) |
printf("%s %s\n", diff_format == D_CONTEXT ? "---" : "+++", |
diff_output("%s %s\n", diff_format == D_CONTEXT ? "---" : "+++", |
label[1]); |
label[1]); |
else |
else |
printf("%s %s\t%s", diff_format == D_CONTEXT ? "---" : "+++", |
diff_output("%s %s\t%s", diff_format == D_CONTEXT ? "---" : "+++", |
file2, ctime(&stb2.st_mtime)); |
file2, ctime(&stb2.st_mtime)); |
} |
} |