add a -i (case-insensitive) option. unfortunately this is not unicode aware yet, but it's still useful. Reference: /n/atom/patch/applied/diff-i Date: Mon Sep 28 07:05:47 CES 2015 Signed-off-by: quanstro@quanstro.net --- /sys/src/cmd/diff/diff.h Mon Sep 28 07:04:30 2015 +++ /sys/src/cmd/diff/diff.h Mon Sep 28 07:04:31 2015 @@ -2,6 +2,7 @@ char bflag; /* ignore multiple and trailing blanks */ char rflag; /* recurse down directory trees */ char mflag; /* pseudo flag: doing multiple files, one dir */ +char iflag; int anychange; extern Biobuf stdout; extern int binary; --- /sys/src/cmd/diff/diffio.c Mon Sep 28 07:04:33 2015 +++ /sys/src/cmd/diff/diffio.c Mon Sep 28 07:04:34 2015 @@ -47,6 +47,14 @@ return p - buf; } +static int +caseadj(int c) +{ + if(iflag && c >= 'A' && c <= 'Z') + c += 0x20; + return c; +} + #define HALFLONG 16 #define low(x) (x&((1L<>HALFLONG) @@ -59,7 +67,7 @@ static int readhash(Biobuf *bp, char *buf) { - long sum; + long sum, c; unsigned shift; char *p; int len, space; @@ -73,7 +81,7 @@ { case 0: while (len--) { - sum += (long)*p++ << (shift &= (HALFLONG-1)); + sum += caseadj(*p++) << (shift &= (HALFLONG-1)); shift += 7; } break; @@ -82,7 +90,8 @@ * coalesce multiple white-space */ for (space = 0; len--; p++) { - if (isspace(*p)) { + c = caseadj(*p); + if (isspace(c)) { space++; continue; } @@ -90,7 +99,7 @@ shift += 7; space = 0; } - sum += (long)*p << (shift &= (HALFLONG-1)); + sum += c << (shift &= (HALFLONG-1)); shift += 7; } break; @@ -99,11 +108,10 @@ * strip all white-space */ while (len--) { - if (isspace(*p)) { - p++; + c = caseadj(*p++); + if (isspace(c)) continue; - } - sum += (long)*p++ << (shift &= (HALFLONG-1)); + sum += c << (shift &= (HALFLONG-1)); shift += 7; } break; --- /sys/src/cmd/diff/diffreg.c Mon Sep 28 07:04:36 2015 +++ /sys/src/cmd/diff/diffreg.c Mon Sep 28 07:04:38 2015 @@ -316,7 +316,7 @@ flushchanges(); } -#define BUF 32768 +#define BUF 4096 static int cmp(Biobuf* b1, Biobuf* b2) { --- /sys/src/cmd/diff/main.c Mon Sep 28 07:04:39 2015 +++ /sys/src/cmd/diff/main.c Mon Sep 28 07:04:40 2015 @@ -11,7 +11,7 @@ static char *tmp[] = {"/tmp/diff1XXXXXXXXXXX", "/tmp/diff2XXXXXXXXXXX"}; static int whichtmp; static char *progname; -static char usage[] = "diff [-abcefmnrw] file1 ... file2\n"; +static char usage[] = "diff [-abcefimnrw] file1 ... file2\n"; static void rmtmpfiles(void) @@ -209,6 +209,10 @@ case 'm': mflag = 1; + break; + + case 'i': + iflag = 1; break; case 'h': --- /sys/man/1/diff Mon Sep 28 07:04:42 2015 +++ /sys/man/1/diff Mon Sep 28 07:04:43 2015 @@ -4,7 +4,7 @@ .SH SYNOPSIS .B diff [ -.B -abcefmnrw +.B -abcefimnrw ] .I file1 ... file2 .SH DESCRIPTION @@ -93,6 +93,13 @@ .B -w option causes all white-space to be removed from input lines before applying the difference algorithm. +The +.B -i +option causes case to be folded before applying the difference +algorithm, and may be combined with either +.B -b +or +.BR -w . .PP The .B -n @@ -174,3 +181,7 @@ .I diff on directories, the notion of what is a text file is open to debate. +.PP +The +.B -i +flag is not Unicode aware.