From owner-svn-src-user@freebsd.org Sat Dec 31 00:49:31 2016 Return-Path: Delivered-To: svn-src-user@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id D3FC3C9690E for ; Sat, 31 Dec 2016 00:49:31 +0000 (UTC) (envelope-from bapt@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id AEAA31375; Sat, 31 Dec 2016 00:49:31 +0000 (UTC) (envelope-from bapt@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id uBV0nU1o088577; Sat, 31 Dec 2016 00:49:30 GMT (envelope-from bapt@FreeBSD.org) Received: (from bapt@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uBV0nUxW088575; Sat, 31 Dec 2016 00:49:30 GMT (envelope-from bapt@FreeBSD.org) Message-Id: <201612310049.uBV0nUxW088575@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: bapt set sender to bapt@FreeBSD.org using -f From: Baptiste Daroussin Date: Sat, 31 Dec 2016 00:49:30 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r310879 - user/bapt/diff X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 31 Dec 2016 00:49:31 -0000 Author: bapt Date: Sat Dec 31 00:49:30 2016 New Revision: 310879 URL: https://svnweb.freebsd.org/changeset/base/310879 Log: Implement diff --strip-trailing-cr Modified: user/bapt/diff/diff.c user/bapt/diff/diff.h user/bapt/diff/diffreg.c Modified: user/bapt/diff/diff.c ============================================================================== --- user/bapt/diff/diff.c Sat Dec 31 00:01:21 2016 (r310878) +++ user/bapt/diff/diff.c Sat Dec 31 00:49:30 2016 (r310879) @@ -50,6 +50,7 @@ regex_t ignore_re; #define OPTIONS "0123456789aBbC:cdD:efhI:iL:lnNPpqrS:sTtU:uwX:x:" enum { OPT_TSIZE = CHAR_MAX + 1, + OPT_STRIPCR, }; static struct option longopts[] = { @@ -78,6 +79,7 @@ static struct option longopts[] = { { "ignore-all-space", no_argument, 0, 'w' }, { "exclude", required_argument, 0, 'x' }, { "exclude-from", required_argument, 0, 'X' }, + { "strip-trailing-cr", no_argument, NULL, OPT_STRIPCR }, { "tabsize", optional_argument, NULL, OPT_TSIZE }, { NULL, 0, 0, '\0'} }; @@ -224,6 +226,9 @@ main(int argc, char **argv) usage(); } break; + case OPT_STRIPCR: + dflags |= D_STRIPCR; + break; default: usage(); break; Modified: user/bapt/diff/diff.h ============================================================================== --- user/bapt/diff/diff.h Sat Dec 31 00:01:21 2016 (r310878) +++ user/bapt/diff/diff.h Sat Dec 31 00:49:30 2016 (r310879) @@ -65,6 +65,7 @@ #define D_PROTOTYPE 0x080 /* Display C function prototype */ #define D_EXPANDTABS 0x100 /* Expand tabs to spaces */ #define D_IGNOREBLANKS 0x200 /* Ignore white space changes */ +#define D_STRIPCR 0x500 /* Strip trailing cr */ /* * Status values for print_status() and diffreg() return values Modified: user/bapt/diff/diffreg.c ============================================================================== --- user/bapt/diff/diffreg.c Sat Dec 31 00:01:21 2016 (r310878) +++ user/bapt/diff/diffreg.c Sat Dec 31 00:49:30 2016 (r310879) @@ -776,7 +776,7 @@ check(FILE *f1, FILE *f2, int flags) ixnew[j] = ctnew += skipline(f2); j++; } - if (flags & (D_FOLDBLANKS|D_IGNOREBLANKS|D_IGNORECASE)) { + if (flags & (D_FOLDBLANKS|D_IGNOREBLANKS|D_IGNORECASE|D_STRIPCR)) { for (;;) { c = getc(f1); d = getc(f2); @@ -795,6 +795,20 @@ check(FILE *f1, FILE *f2, int flags) } ctold++; ctnew++; + if (flags & D_STRIPCR) { + if (c == '\r') { + if ((c = getc(f1)) == '\n') { + ctnew++; + break; + } + } + if (d == '\r') { + if ((d = getc(f2)) == '\n') { + ctold++; + break; + } + } + } if ((flags & D_FOLDBLANKS) && isspace(c) && isspace(d)) { do { @@ -850,8 +864,9 @@ check(FILE *f1, FILE *f2, int flags) ixnew[j] = ctnew; j++; } - for (; j <= len[1]; j++) + for (; j <= len[1]; j++) { ixnew[j] = ctnew += skipline(f2); + } /* * if (jackpot) * fprintf(stderr, "jackpot\n"); @@ -1246,6 +1261,12 @@ readhash(FILE *f, int flags) if ((flags & (D_FOLDBLANKS|D_IGNOREBLANKS)) == 0) { if (flags & D_IGNORECASE) for (i = 0; (t = getc(f)) != '\n'; i++) { + if (flags & D_STRIPCR && t == '\r') { + t = getc(f); + if (t == '\n') + break; + ungetc(t, f); + } if (t == EOF) { if (i == 0) return (0); @@ -1255,6 +1276,12 @@ readhash(FILE *f, int flags) } else for (i = 0; (t = getc(f)) != '\n'; i++) { + if (flags & D_STRIPCR && t == '\r') { + t = getc(f); + if (t == '\n') + break; + ungetc(t, f); + } if (t == EOF) { if (i == 0) return (0); @@ -1265,8 +1292,8 @@ readhash(FILE *f, int flags) } else { for (i = 0;;) { switch (t = getc(f)) { - case '\t': case '\r': + case '\t': case '\v': case '\f': case ' ':