diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2003-07-15 23:17:57 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2003-07-15 23:17:57 +0000 |
commit | f65e5bdcfff4372832c42d776c3316e4fac2dae4 (patch) | |
tree | 572a4257c8c7d31cf866ef166b11f2b06931036b /usr.bin/diff | |
parent | fd88c4dfd25d01aebe5ac774ed9a47cd91ff70da (diff) |
Fix line ranges for unidiffs. Problem noted by otto@
Diffstat (limited to 'usr.bin/diff')
-rw-r--r-- | usr.bin/diff/diffreg.c | 39 |
1 files changed, 27 insertions, 12 deletions
diff --git a/usr.bin/diff/diffreg.c b/usr.bin/diff/diffreg.c index 576bc38f12b..9ca4cbcec89 100644 --- a/usr.bin/diff/diffreg.c +++ b/usr.bin/diff/diffreg.c @@ -1,4 +1,4 @@ -/* $OpenBSD: diffreg.c,v 1.32 2003/07/09 00:39:26 millert Exp $ */ +/* $OpenBSD: diffreg.c,v 1.33 2003/07/15 23:17:56 millert Exp $ */ /* * Copyright (C) Caldera International Inc. 2001-2002. @@ -65,7 +65,7 @@ */ #ifndef lint -static const char rcsid[] = "$OpenBSD: diffreg.c,v 1.32 2003/07/09 00:39:26 millert Exp $"; +static const char rcsid[] = "$OpenBSD: diffreg.c,v 1.33 2003/07/15 23:17:56 millert Exp $"; #endif /* not lint */ #include <sys/param.h> @@ -184,6 +184,7 @@ static void fetch(long *, int, int, FILE *, char *, int); static void output(char *, FILE *, char *, FILE *); static void check(char *, FILE *, char *, FILE *); static void range(int, int, char *); +static void uni_range(int, int); static void dump_context_vec(FILE *, FILE *); static void dump_unified_vec(FILE *, FILE *); static void prepare(int, FILE *); @@ -880,6 +881,25 @@ output(char *file1, FILE *f1, char *file2, FILE *f2) } } +static __inline void +range(int a, int b, char *separator) +{ + printf("%d", a > b ? b : a); + if (a < b) + printf("%s%d", separator, b); +} + +static __inline void +uni_range(int a, int b) +{ + if (a < b) + printf("%d,%d", a, b - a + 1); + else if (a == b) + printf("%d", b); + else + printf("%d,0", b); +} + /* * The following struct is used to record change information when * doing a "context" or "unified" diff. (see routine "change" to @@ -987,14 +1007,6 @@ change(char *file1, FILE *f1, char *file2, FILE *f2, int a, int b, int c, int d) } static void -range(int a, int b, char *separator) -{ - printf("%d", a > b ? b : a); - if (a < b) - printf("%s%d", separator, b); -} - -static void fetch(long *f, int a, int b, FILE *lb, char *s, int oldfile) { int i, j, c, col, nc; @@ -1261,8 +1273,11 @@ dump_unified_vec(FILE *f1, FILE *f2) lowc = max(1, cvp->c - context); upd = min(len[1], context_vec_ptr->d + context); - printf("@@ -%d,%d +%d,%d @@\n", lowa, upb - lowa + 1, - lowc, upd - lowc + 1); + fputs("@@ -", stdout); + uni_range(lowa, upb); + fputs(" +", stdout); + uni_range(lowc, upd); + fputs(" @@\n", stdout); /* * Output changes in "unified" diff format--the old and new lines |