tadd diff -a - plan9port - [fork] Plan 9 from user space
 (HTM) git clone git://src.adamsgaard.dk/plan9port
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit a2d6635774d29561984a85d59c60d23ece3a0af7
 (DIR) parent 33baa59ecc75651b3666cef7a5b19eb91840d40c
 (HTM) Author: rsc <devnull@localhost>
       Date:   Sat, 29 Jan 2005 16:50:51 +0000
       
       add diff -a
       
       Diffstat:
         M src/cmd/diff/diffio.c               |      28 ++++++++++++++++++++++------
         M src/cmd/diff/main.c                 |      15 ++++++++-------
       
       2 files changed, 30 insertions(+), 13 deletions(-)
       ---
 (DIR) diff --git a/src/cmd/diff/diffio.c b/src/cmd/diff/diffio.c
       t@@ -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++];
       t@@ -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;
        }
 (DIR) diff --git a/src/cmd/diff/main.c b/src/cmd/diff/main.c
       t@@ -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";
       t@@ -26,8 +26,6 @@ void
        done(int status)
        {
                rmtmpfiles();
       -Bflush(&stdout);
       -Bterm(&stdout);
                switch(status)
                {
                case 0:
       t@@ -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;
       t@@ -172,7 +173,6 @@ diff(char *f, char *t, int level)
                }
                free(fsb);
                free(tsb);
       -
        Return:
                rmtmpfiles();
        }
       t@@ -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;
        
       t@@ -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*/
        }