aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/diff
diff options
context:
space:
mode:
authorrsc <devnull@localhost>2005-01-29 16:50:51 +0000
committerrsc <devnull@localhost>2005-01-29 16:50:51 +0000
commita2d6635774d29561984a85d59c60d23ece3a0af7 (patch)
tree7b6d02db950256ccd4a1d5072e53668dde3f198e /src/cmd/diff
parent33baa59ecc75651b3666cef7a5b19eb91840d40c (diff)
downloadplan9port-a2d6635774d29561984a85d59c60d23ece3a0af7.tar.gz
plan9port-a2d6635774d29561984a85d59c60d23ece3a0af7.tar.bz2
plan9port-a2d6635774d29561984a85d59c60d23ece3a0af7.zip
add diff -a
Diffstat (limited to 'src/cmd/diff')
-rw-r--r--src/cmd/diff/diffio.c28
-rw-r--r--src/cmd/diff/main.c15
2 files changed, 30 insertions, 13 deletions
diff --git a/src/cmd/diff/diffio.c b/src/cmd/diff/diffio.c
index 5317539b..80371144 100644
--- a/src/cmd/diff/diffio.c
+++ b/src/cmd/diff/diffio.c
@@ -302,6 +302,7 @@ change(int a, int b, int c, int d)
range(a, b, " ");
break;
case 'c':
+ case 'a':
if(nchanges%1024 == 0)
changes = erealloc(changes, (nchanges+1024)*sizeof(changes[0]));
ch = &changes[nchanges++];
@@ -348,24 +349,39 @@ flushchanges(void)
for(i=0; i<nchanges; ){
j = changeset(i);
- a = changes[i].a;
- b = changes[j-1].b;
- c = changes[i].c;
- d = changes[j-1].d;
+ a = changes[i].a-Lines;
+ b = changes[j-1].b+Lines;
+ c = changes[i].c-Lines;
+ d = changes[j-1].d+Lines;
+ if(a < 1)
+ a = 1;
+ if(c < 1)
+ c = 1;
+ if(b > len[0])
+ b = len[0];
+ if(d > len[1])
+ d = len[1];
+ if(mode == 'a'){
+ a = 1;
+ b = len[0];
+ c = 1;
+ d = len[1];
+ j = nchanges;
+ }
Bprint(&stdout, "%s:", file1);
range(a, b, ",");
Bprint(&stdout, " - ");
Bprint(&stdout, "%s:", file2);
range(c, d, ",");
Bputc(&stdout, '\n');
- at = a-Lines;
+ at = a;
for(; i<j; i++){
fetch(ixold, at, changes[i].a-1, input[0], " ");
fetch(ixold, changes[i].a, changes[i].b, input[0], "< ");
fetch(ixnew, changes[i].c, changes[i].d, input[1], "> ");
at = changes[i].b+1;
}
- fetch(ixold, at, b+Lines, input[0], " ");
+ fetch(ixold, at, b, input[0], " ");
}
nchanges = 0;
}
diff --git a/src/cmd/diff/main.c b/src/cmd/diff/main.c
index ab114d4d..d1ed1249 100644
--- a/src/cmd/diff/main.c
+++ b/src/cmd/diff/main.c
@@ -8,7 +8,7 @@
Biobuf stdout;
-static char *tmp[] = {"/tmp/diff1", "/tmp/diff2"};
+static char *tmp[] = {"/tmp/diff1XXXXXXXXXXX", "/tmp/diff2XXXXXXXXXXX"};
static int whichtmp;
static char *progname;
static char usage[] = "diff [ -efmnbwr ] file1 ... file2\n";
@@ -26,8 +26,6 @@ void
done(int status)
{
rmtmpfiles();
-Bflush(&stdout);
-Bterm(&stdout);
switch(status)
{
case 0:
@@ -83,8 +81,11 @@ mktmpfile(int input, Dir **sb)
char buf[8192];
atnotify(catch, 1);
- p = tmp[whichtmp++];
+/*
+ p = mktemp(tmp[whichtmp++]);
fd = create(p, OWRITE, 0600);
+*/
+ fd = mkstemp(p=tmp[whichtmp++]);
if (fd < 0) {
panic(mflag ? 0: 2, "cannot create %s: %r\n", p);
return 0;
@@ -172,7 +173,6 @@ diff(char *f, char *t, int level)
}
free(fsb);
free(tsb);
-
Return:
rmtmpfiles();
}
@@ -189,10 +189,12 @@ main(int argc, char *argv[])
while (--argc && (*++argv)[0] == '-' && (*argv)[1]) {
for (p = *argv+1; *p; p++) {
switch (*p) {
- case 'c':
+
case 'e':
case 'f':
case 'n':
+ case 'c':
+ case 'a':
mode = *p;
break;
@@ -238,7 +240,6 @@ main(int argc, char *argv[])
free(tsb);
for (i = 0; i < argc-1; i++)
diff(argv[i], argv[argc-1], 0);
-
done(anychange);
/*NOTREACHED*/
}