summaryrefslogtreecommitdiff
path: root/usr.bin/cvs/diff_internals.c
diff options
context:
space:
mode:
authorTobias Stoeckmann <tobias@cvs.openbsd.org>2008-02-03 18:18:45 +0000
committerTobias Stoeckmann <tobias@cvs.openbsd.org>2008-02-03 18:18:45 +0000
commit596d463f3adebfac3f5ca7c83e6e8130fd1e39fb (patch)
tree099b0c9c755c0b7026fc21f42eb177cc08fffdbd /usr.bin/cvs/diff_internals.c
parent6f332ca68f94c1595e84bd2788f6dabd3d9327ad (diff)
Added rdiff support. In order to do this, some output and option fixes
had to be done for diff, too. OK joris@
Diffstat (limited to 'usr.bin/cvs/diff_internals.c')
-rw-r--r--usr.bin/cvs/diff_internals.c131
1 files changed, 96 insertions, 35 deletions
diff --git a/usr.bin/cvs/diff_internals.c b/usr.bin/cvs/diff_internals.c
index bc430ae00d3..f162467c6db 100644
--- a/usr.bin/cvs/diff_internals.c
+++ b/usr.bin/cvs/diff_internals.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: diff_internals.c,v 1.16 2008/01/31 20:11:28 tobias Exp $ */
+/* $OpenBSD: diff_internals.c,v 1.17 2008/02/03 18:18:44 tobias Exp $ */
/*
* Copyright (C) Caldera International Inc. 2001-2002.
* All rights reserved.
@@ -179,6 +179,8 @@ static void prune(void);
static void equiv(struct line *, int, struct line *, int, int *);
static void unravel(int);
static void unsort(struct line *, int, int *);
+static void diff_head(void);
+static void rdiff_head(void);
static void change(FILE *, FILE *, int, int, int, int);
static void sort(struct line *, int);
static int ignoreline(char *);
@@ -194,9 +196,10 @@ static int files_differ(FILE *, FILE *);
static char *match_function(const long *, int, FILE *);
static char *preadline(int, size_t, off_t);
-static int aflag, bflag, dflag, iflag, tflag, Tflag, wflag;
+static int aflag, bflag, dflag, tflag, Tflag, wflag;
static int context = 3;
int diff_format = D_NORMAL;
+int diff_iflag = 0;
int diff_pflag = 0;
char *diff_file = NULL;
RCSNUM *diff_rev1 = NULL;
@@ -303,7 +306,7 @@ cvs_diffreg(const char *file1, const char *file2, BUF *out)
lastline = 0;
lastmatchline = 0;
context_vec_ptr = context_vec_start - 1;
- chrtran = (iflag ? cup2low : clow2low);
+ chrtran = (diff_iflag ? cup2low : clow2low);
if (out != NULL)
diffbuf = out;
@@ -634,7 +637,7 @@ check(FILE *f1, FILE *f2)
ixnew[j] = ctnew += skipline(f2);
j++;
}
- if (bflag == 1 || wflag == 1 || iflag == 1) {
+ if (bflag == 1 || wflag == 1 || diff_iflag == 1) {
for (;;) {
c = getc(f1);
d = getc(f2);
@@ -852,6 +855,90 @@ ignoreline(char *line)
return (ret == 0); /* if it matched, it should be ignored. */
}
+static void
+diff_head(void)
+{
+ char buf[64];
+ struct tm *t;
+ time_t curr_time;
+
+ if (diff_rev1 != NULL) {
+ t = gmtime(&stb1.st_mtime);
+ } else {
+ time(&curr_time);
+ t = localtime(&curr_time);
+ }
+
+ (void)strftime(buf, sizeof(buf), "%d %b %G %H:%M:%S -0000", t);
+ diff_output("%s %s %s", diff_format == D_CONTEXT ? "***" : "---",
+ diff_file, buf);
+
+ if (diff_rev1 != NULL) {
+ rcsnum_tostr(diff_rev1, buf, sizeof(buf));
+ diff_output("\t%s", buf);
+ }
+
+ diff_output("\n");
+
+ if (diff_rev2 != NULL)
+ t = gmtime(&stb2.st_mtime);
+ else {
+ time(&curr_time);
+ t = localtime(&curr_time);
+ }
+
+ (void)strftime(buf, sizeof(buf), "%d %b %G %H:%M:%S -0000", t);
+ diff_output("%s %s %s", diff_format == D_CONTEXT ? "---" : "+++",
+ diff_file, buf);
+
+ if (diff_rev2 != NULL) {
+ rcsnum_tostr(diff_rev2, buf, sizeof(buf));
+ diff_output("\t%s", buf);
+ }
+
+ diff_output("\n");
+}
+
+static void
+rdiff_head(void)
+{
+ char buf[64];
+ struct tm *t;
+ time_t curr_time;
+
+ if (diff_rev1 != NULL) {
+ t = localtime(&stb1.st_mtime);
+ } else {
+ time(&curr_time);
+ t = localtime(&curr_time);
+ }
+
+ diff_output("%s ", diff_format == D_CONTEXT ? "***" : "---");
+
+ if (diff_rev1 == NULL) {
+ diff_output("%s", CVS_PATH_DEVNULL);
+ t = gmtime(&stb1.st_atime);
+ } else {
+ rcsnum_tostr(diff_rev1, buf, sizeof(buf));
+ diff_output("%s:%s", diff_file, buf);
+ }
+
+ (void)strftime(buf, sizeof(buf), "%a %b %e %H:%M:%S %G", t);
+ diff_output("\t%s\n", buf);
+
+ if (diff_rev2 != NULL) {
+ t = localtime(&stb2.st_mtime);
+ } else {
+ time(&curr_time);
+ t = localtime(&curr_time);
+ }
+
+ (void)strftime(buf, sizeof(buf), "%a %b %e %H:%M:%S %G", t);
+
+ diff_output("%s %s %s\n", diff_format == D_CONTEXT ? "---" : "+++",
+ diff_file, buf);
+}
+
/*
* Indicate that there is a difference between lines a and b of the from file
* to get to lines c to d of the to file. If a is greater then b then there
@@ -863,8 +950,6 @@ static void
change(FILE *f1, FILE *f2, int a, int b, int c, int d)
{
static size_t max_context = 64;
- char buf[64];
- struct tm *t;
int i;
if (diff_format != D_IFDEF && a > b && c > d)
@@ -911,35 +996,11 @@ proceed:
/*
* Print the context/unidiff header first time through.
*/
- t = localtime(&stb1.st_mtime);
- (void)strftime(buf, sizeof(buf),
- "%d %b %G %H:%M:%S", t);
-
- diff_output("%s %s %s",
- diff_format == D_CONTEXT ? "***" : "---", diff_file,
- buf);
-
- if (diff_rev1 != NULL) {
- rcsnum_tostr(diff_rev1, buf, sizeof(buf));
- diff_output("\t%s", buf);
- }
-
- diff_output("\n");
-
- t = localtime(&stb2.st_mtime);
- (void)strftime(buf, sizeof(buf),
- "%d %b %G %H:%M:%S", t);
-
- diff_output("%s %s %s",
- diff_format == D_CONTEXT ? "---" : "+++", diff_file,
- buf);
-
- if (diff_rev2 != NULL) {
- rcsnum_tostr(diff_rev2, buf, sizeof(buf));
- diff_output("\t%s", buf);
- }
+ if (cvs_cmdop == CVS_OP_RDIFF)
+ rdiff_head();
+ else
+ diff_head();
- diff_output("\n");
anychange = 1;
} else if (a > context_vec_ptr->b + (2 * context) + 1 &&
c > context_vec_ptr->d + (2 * context) + 1) {
@@ -1072,7 +1133,7 @@ readhash(FILE *f)
sum = 1;
space = 0;
if (bflag != 1 && wflag != 1) {
- if (iflag == 1)
+ if (diff_iflag == 1)
for (i = 0; (t = getc(f)) != '\n'; i++) {
if (t == EOF) {
if (i == 0)