From owner-svn-src-stable-11@freebsd.org Wed Oct 3 17:21:46 2018 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id BD47310A7759; Wed, 3 Oct 2018 17:21:46 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 702A886823; Wed, 3 Oct 2018 17:21:46 +0000 (UTC) (envelope-from kevans@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 mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 67DEF19FC3; Wed, 3 Oct 2018 17:21:46 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w93HLkC5015251; Wed, 3 Oct 2018 17:21:46 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w93HLkcG015250; Wed, 3 Oct 2018 17:21:46 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201810031721.w93HLkcG015250@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Wed, 3 Oct 2018 17:21:46 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r339164 - stable/11/usr.bin/diff X-SVN-Group: stable-11 X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: stable/11/usr.bin/diff X-SVN-Commit-Revision: 339164 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 03 Oct 2018 17:21:47 -0000 Author: kevans Date: Wed Oct 3 17:21:45 2018 New Revision: 339164 URL: https://svnweb.freebsd.org/changeset/base/339164 Log: MFC r338040: diff(1): Refactor -B a little bit Instead of doing a second pass to skip empty lines if we've specified -I, go ahead and check both at once. Ignore critera has been split out into its own function to try and keep the logic cleaner. Modified: stable/11/usr.bin/diff/diffreg.c Directory Properties: stable/11/ (props changed) Modified: stable/11/usr.bin/diff/diffreg.c ============================================================================== --- stable/11/usr.bin/diff/diffreg.c Wed Oct 3 17:20:30 2018 (r339163) +++ stable/11/usr.bin/diff/diffreg.c Wed Oct 3 17:21:45 2018 (r339164) @@ -202,7 +202,8 @@ static void unsort(struct line *, int, int *); static void change(char *, FILE *, char *, FILE *, int, int, int, int, int *); static void sort(struct line *, int); static void print_header(const char *, const char *); -static int ignoreline(char *); +static bool ignoreline_pattern(char *); +static bool ignoreline(char *, bool); static int asciifile(FILE *); static int fetch(long *, int, int, FILE *, int, int, int); static int newcand(int, int, int); @@ -1018,8 +1019,8 @@ preadline(int fd, size_t rlen, off_t off) return (line); } -static int -ignoreline(char *line) +static bool +ignoreline_pattern(char *line) { int ret; @@ -1028,6 +1029,20 @@ ignoreline(char *line) return (ret == 0); /* if it matched, it should be ignored. */ } +static bool +ignoreline(char *line, bool skip_blanks) +{ + + if (ignore_pats != NULL && skip_blanks) + return (ignoreline_pattern(line) || *line == '\0'); + if (ignore_pats != NULL) + return (ignoreline_pattern(line)); + if (skip_blanks) + return (*line == '\0'); + /* No ignore criteria specified */ + return (false); +} + /* * Indicate that there is a difference between lines a and b of the from file * to get to lines c to d of the to file. If a is greater then b then there @@ -1043,12 +1058,14 @@ change(char *file1, FILE *f1, char *file2, FILE *f2, i long curpos; int i, nc, f; const char *walk; + bool skip_blanks; + skip_blanks = (*pflags & D_SKIPBLANKLINES); restart: if ((diff_format != D_IFDEF || diff_format == D_GFORMAT) && a > b && c > d) return; - if (ignore_pats != NULL) { + if (ignore_pats != NULL || skip_blanks) { char *line; /* * All lines in the change, insert, or delete must @@ -1059,7 +1076,7 @@ restart: for (i = a; i <= b; i++) { line = preadline(fileno(f1), ixold[i] - ixold[i - 1], ixold[i - 1]); - if (!ignoreline(line)) + if (!ignoreline(line, skip_blanks)) goto proceed; } } @@ -1067,36 +1084,11 @@ restart: for (i = c; i <= d; i++) { line = preadline(fileno(f2), ixnew[i] - ixnew[i - 1], ixnew[i - 1]); - if (!ignoreline(line)) + if (!ignoreline(line, skip_blanks)) goto proceed; } } return; - } - if (*pflags & D_SKIPBLANKLINES) { - char *line; - /* - * All lines in the change, insert, or delete must not be - * empty for the change to be ignored. - */ - if (a <= b) { /* Changes and deletes. */ - for (i = a; i <= b; i++) { - line = preadline(fileno(f1), - ixold[i] - ixold[i - 1], ixold[i - 1]); - if (*line != '\0') - goto proceed; - } - } - if (a > b || c <= d) { /* Changes and inserts. */ - for (i = c; i <= d; i++) { - line = preadline(fileno(f2), - ixnew[i] - ixnew[i - 1], ixnew[i - 1]); - if (*line != '\0') - goto proceed; - } - } - return; - } proceed: if (*pflags & D_HEADER && diff_format != D_BRIEF) {