From 5e07282d6426cdbdc10b64f1f6aa3ae257784645 Mon Sep 17 00:00:00 2001 From: ray Date: Thu, 15 Jul 2010 21:32:37 +0000 Subject: [PATCH] cvs and rcs use diff_output() to print everything since it is not always to stdout. A large number of differences are due to this. This diff reduces many more differences between diff and cvs/rcs. Personally I think it's kinda ugly. =( "Looks fine" millert --- usr.bin/diff/diffreg.c | 102 ++++++++++++++++++++--------------------- 1 file changed, 50 insertions(+), 52 deletions(-) diff --git a/usr.bin/diff/diffreg.c b/usr.bin/diff/diffreg.c index aed215507ae..56e8ca44925 100644 --- a/usr.bin/diff/diffreg.c +++ b/usr.bin/diff/diffreg.c @@ -1,4 +1,4 @@ -/* $OpenBSD: diffreg.c,v 1.76 2010/07/15 18:31:33 ray Exp $ */ +/* $OpenBSD: diffreg.c,v 1.77 2010/07/15 21:32:37 ray Exp $ */ /* * Copyright (C) Caldera International Inc. 2001-2002. @@ -172,6 +172,7 @@ struct context_vec { int d; /* end line in new file */ }; +#define diff_output printf static FILE *opentemp(const char *); static void output(char *, FILE *, char *, FILE *, int); static void check(FILE *, FILE *, int); @@ -937,7 +938,7 @@ output(char *file1, FILE *f1, char *file2, FILE *f2, int flags) #define c i0 if ((c = getc(f1)) == EOF) return; - putchar(c); + diff_output("%c", c); } #undef c } @@ -952,20 +953,20 @@ output(char *file1, FILE *f1, char *file2, FILE *f2, int flags) static void range(int a, int b, char *separator) { - printf("%d", a > b ? b : a); + diff_output("%d", a > b ? b : a); if (a < b) - printf("%s%d", separator, b); + diff_output("%s%d", separator, b); } static void uni_range(int a, int b) { if (a < b) - printf("%d,%d", a, b - a + 1); + diff_output("%d,%d", a, b - a + 1); else if (a == b) - printf("%d", b); + diff_output("%d", b); else - printf("%d,0", b); + diff_output("%d,0", b); } static char * @@ -1037,7 +1038,7 @@ restart: } proceed: if (*pflags & D_HEADER) { - printf("%s %s %s\n", diffargs, file1, file2); + diff_output("%s %s %s\n", diffargs, file1, file2); *pflags &= ~D_HEADER; } if (diff_format == D_CONTEXT || diff_format == D_UNIFIED) { @@ -1084,31 +1085,31 @@ proceed: case D_NORMAL: case D_EDIT: 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) range(c, d, ","); - putchar('\n'); + diff_output("\n"); break; case D_REVERSE: - putchar(a > b ? 'a' : c > d ? 'd' : 'c'); + diff_output("%c", a > b ? 'a' : c > d ? 'd' : 'c'); range(a, b, " "); - putchar('\n'); + diff_output("\n"); break; case D_NREVERSE: if (a > b) - printf("a%d %d\n", b, d - c + 1); + diff_output("a%d %d\n", b, d - c + 1); else { - printf("d%d %d\n", a, b - a + 1); + diff_output("d%d %d\n", a, b - a + 1); if (!(c > d)) /* add changed lines */ - printf("a%d %d\n", b, d - c + 1); + diff_output("a%d %d\n", b, d - c + 1); } break; } if (diff_format == D_NORMAL || diff_format == D_IFDEF) { fetch(ixold, a, b, f1, '<', 1, *pflags); 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); if (i != 0 && diff_format == D_EDIT) { @@ -1119,16 +1120,16 @@ proceed: * it. We have to add a substitute command to change this * back and restart where we left off. */ - puts("."); - printf("%ds/^\\.\\././\n", a); + diff_output(".\n"); + diff_output("%ds/^\\.\\././\n", a); a += i; c += i; goto restart; } if ((diff_format == D_EDIT || diff_format == D_REVERSE) && c <= d) - puts("."); + diff_output(".\n"); if (inifdef) { - printf("#endif /* %s */\n", ifdefname); + diff_output("#endif /* %s */\n", ifdefname); inifdef = 0; } } @@ -1147,19 +1148,19 @@ fetch(long *f, int a, int b, FILE *lb, int ch, int oldfile, int flags) /* print through if append (a>b), else to (nb: 0 vs 1 orig) */ nc = f[a > b ? b : a - 1] - curpos; for (i = 0; i < nc; i++) - putchar(getc(lb)); + diff_output("%c", getc(lb)); } if (a > b) return (0); if (diff_format == D_IFDEF) { if (inifdef) { - printf("#else /* %s%s */\n", + diff_output("#else /* %s%s */\n", oldfile == 1 ? "!" : "", ifdefname); } else { if (oldfile) - printf("#ifndef %s\n", ifdefname); + diff_output("#ifndef %s\n", ifdefname); else - printf("#ifdef %s\n", ifdefname); + diff_output("#ifdef %s\n", ifdefname); } inifdef = 1 + oldfile; } @@ -1167,12 +1168,12 @@ fetch(long *f, int a, int b, FILE *lb, int ch, int oldfile, int flags) fseek(lb, f[i - 1], SEEK_SET); nc = f[i] - f[i - 1]; if (diff_format != D_IFDEF && ch != '\0') { - putchar(ch); + diff_output("%c", ch); if (Tflag && (diff_format == D_NORMAL || diff_format == D_CONTEXT || diff_format == D_UNIFIED)) - putchar('\t'); + diff_output("\t"); else if (diff_format != D_UNIFIED) - putchar(' '); + diff_output(" "); } col = 0; for (j = 0, lastc = '\0'; j < nc; j++, lastc = c) { @@ -1181,12 +1182,13 @@ fetch(long *f, int a, int b, FILE *lb, int ch, int oldfile, int flags) diff_format == D_NREVERSE) warnx("No newline at end of file"); else - puts("\n\\ No newline at end of file"); + diff_output("\n\\ No newline at end of " + "file\n"); return (0); } if (c == '\t' && (flags & D_EXPANDTABS)) { do { - putchar(' '); + diff_output(" "); } while (++col & 7); } else { if (diff_format == D_EDIT && j == 1 && c == '\n' @@ -1198,10 +1200,10 @@ fetch(long *f, int a, int b, FILE *lb, int ch, int oldfile, int flags) * giving the caller an offset * from which to restart. */ - puts("."); + diff_output(".\n"); return (i - a + 1); } - putchar(c); + diff_output("%c", c); col++; } } @@ -1354,17 +1356,15 @@ dump_context_vec(FILE *f1, FILE *f2, int flags) lowc = MAX(1, cvp->c - diff_context); upd = MIN(len[1], context_vec_ptr->d + diff_context); - printf("***************"); + diff_output("***************"); if ((flags & D_PROTOTYPE)) { f = match_function(ixold, lowa-1, f1); - if (f != NULL) { - putchar(' '); - fputs(f, stdout); - } + if (f != NULL) + diff_output(" %s", f); } - printf("\n*** "); + diff_output("\n*** "); range(lowa, upb, ","); - printf(" ****\n"); + diff_output(" ****\n"); /* * Output changes to the "old" file. The first loop suppresses @@ -1403,9 +1403,9 @@ dump_context_vec(FILE *f1, FILE *f2, int flags) fetch(ixold, b + 1, upb, f1, ' ', 0, flags); } /* output changes to the "new" file */ - printf("--- "); + diff_output("--- "); range(lowc, upd, ","); - printf(" ----\n"); + diff_output(" ----\n"); do_output = 0; for (cvp = context_vec_start; cvp <= context_vec_ptr; cvp++) @@ -1459,19 +1459,17 @@ dump_unified_vec(FILE *f1, FILE *f2, int flags) lowc = MAX(1, cvp->c - diff_context); upd = MIN(len[1], context_vec_ptr->d + diff_context); - fputs("@@ -", stdout); + diff_output("@@ -"); uni_range(lowa, upb); - fputs(" +", stdout); + diff_output(" +"); uni_range(lowc, upd); - fputs(" @@", stdout); + diff_output(" @@"); if ((flags & D_PROTOTYPE)) { f = match_function(ixold, lowa-1, f1); - if (f != NULL) { - putchar(' '); - fputs(f, stdout); - } + if (f != NULL) + diff_output(" %s", f); } - putchar('\n'); + diff_output("\n"); /* * Output changes in "unified" diff format--the old and new lines @@ -1520,15 +1518,15 @@ static void print_header(const char *file1, const char *file2) { if (label[0] != NULL) - printf("%s %s\n", diff_format == D_CONTEXT ? "***" : "---", + diff_output("%s %s\n", diff_format == D_CONTEXT ? "***" : "---", label[0]); 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)); if (label[1] != NULL) - printf("%s %s\n", diff_format == D_CONTEXT ? "---" : "+++", + diff_output("%s %s\n", diff_format == D_CONTEXT ? "---" : "+++", label[1]); 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)); } -- 2.20.1