diff --git a/sys/src/cmd/diff/diff.h b/sys/src/cmd/diff/diff.h index 76fe050df..34a5dc010 100644 --- a/sys/src/cmd/diff/diff.h +++ b/sys/src/cmd/diff/diff.h @@ -22,5 +22,6 @@ Biobuf *prepare(int, char *); void panic(int, char *, ...); void check(Biobuf *, Biobuf *); void change(int, int, int, int); +void fileheader(void); void flushchanges(void); diff --git a/sys/src/cmd/diff/diffio.c b/sys/src/cmd/diff/diffio.c index 4f291ca26..146bef3bc 100644 --- a/sys/src/cmd/diff/diffio.c +++ b/sys/src/cmd/diff/diffio.c @@ -267,22 +267,16 @@ change(int a, int b, int c, int d) if (a > b && c > d) return; anychange = 1; - if (firstchange == 0) { - if (mflag) { - if(mode) { - buf[0] = '-'; - buf[1] = mode; - buf[2] = ' '; - buf[3] = '\0'; - } else { - buf[0] = '\0'; - } - Bprint(&stdout, "diff %s%s %s\n", buf, file1, file2); - } - if (mode == 'u') { - Bprint(&stdout, "--- %s\n", file1); - Bprint(&stdout, "+++ %s\n", file2); + if (mflag && firstchange == 0) { + if(mode) { + buf[0] = '-'; + buf[1] = mode; + buf[2] = ' '; + buf[3] = '\0'; + } else { + buf[0] = '\0'; } + Bprint(&stdout, "diff %s%s %s\n", buf, file1, file2); firstchange = 1; } verb = a > b ? 'a': c > d ? 'd': 'c'; @@ -345,6 +339,15 @@ changeset(int i) return nchanges; } +void +fileheader(void) +{ + if(mode != 'u') + return; + Bprint(&stdout, "--- %s\n", file1); + Bprint(&stdout, "+++ %s\n", file2); +} + void flushchanges(void) { diff --git a/sys/src/cmd/diff/diffreg.c b/sys/src/cmd/diff/diffreg.c index 7ef855994..6f6f144fc 100644 --- a/sys/src/cmd/diff/diffreg.c +++ b/sys/src/cmd/diff/diffreg.c @@ -285,6 +285,7 @@ output(void) m = len[0]; J[0] = 0; J[m+1] = len[1]+1; + fileheader(); if (mode != 'e') { for (i0 = 1; i0 <= m; i0 = i1+1) { while (i0 <= m && J[i0] == J[i0-1]+1)