From owner-svn-src-stable@freebsd.org Tue May 30 16:55:17 2017 Return-Path: Delivered-To: svn-src-stable@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 46187B8821F; Tue, 30 May 2017 16:55:17 +0000 (UTC) (envelope-from emaste@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 1CA916F5A4; Tue, 30 May 2017 16:55:17 +0000 (UTC) (envelope-from emaste@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v4UGtGbe027633; Tue, 30 May 2017 16:55:16 GMT (envelope-from emaste@FreeBSD.org) Received: (from emaste@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v4UGtGLp027631; Tue, 30 May 2017 16:55:16 GMT (envelope-from emaste@FreeBSD.org) Message-Id: <201705301655.v4UGtGLp027631@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: emaste set sender to emaste@FreeBSD.org using -f From: Ed Maste Date: Tue, 30 May 2017 16:55:16 +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: r319226 - stable/11/usr.bin/uniq X-SVN-Group: stable-11 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 30 May 2017 16:55:17 -0000 Author: emaste Date: Tue May 30 16:55:15 2017 New Revision: 319226 URL: https://svnweb.freebsd.org/changeset/base/319226 Log: MFC r318316: uniq: allow -c to be used with -d or -u Bring in some bits from NetBSD and lift the restriction in uniq(1) that -c cannot be used with the -d and -u options. This restriction seems unnecessary and is supported at least by GNU, OpenBSD, and NetBSD. Lift the restriction and simplify the show() logic a little bit to maintain functionality when -c is provided with -d/-u. Also with this change, -d and -u are now actually a mutually exclusive, albeit valid, combination. Given that they both indicate opposite behavior, uniq(1) will no longer output anything if both -d and -u are supplied. This is in line with NetBSD as well as GNU. Adjust the man page and usage() to reflect that -c is its own standalone option. PR: 200553 Submitted by: Kyle Evans Modified: stable/11/usr.bin/uniq/uniq.1 stable/11/usr.bin/uniq/uniq.c Directory Properties: stable/11/ (props changed) Modified: stable/11/usr.bin/uniq/uniq.1 ============================================================================== --- stable/11/usr.bin/uniq/uniq.1 Tue May 30 16:46:25 2017 (r319225) +++ stable/11/usr.bin/uniq/uniq.1 Tue May 30 16:55:15 2017 (r319226) @@ -31,7 +31,7 @@ .\" From: @(#)uniq.1 8.1 (Berkeley) 6/6/93 .\" $FreeBSD$ .\" -.Dd December 17, 2009 +.Dd May 15, 2017 .Dt UNIQ 1 .Os .Sh NAME @@ -39,7 +39,8 @@ .Nd report or filter out repeated lines in a file .Sh SYNOPSIS .Nm -.Op Fl c | Fl d | Fl u +.Op Fl c +.Op Fl d | Fl u .Op Fl i .Op Fl f Ar num .Op Fl s Ar chars Modified: stable/11/usr.bin/uniq/uniq.c ============================================================================== --- stable/11/usr.bin/uniq/uniq.c Tue May 30 16:46:25 2017 (r319225) +++ stable/11/usr.bin/uniq/uniq.c Tue May 30 16:55:15 2017 (r319226) @@ -130,13 +130,6 @@ main (int argc, char *argv[]) argc -= optind; argv += optind; - /* If no flags are set, default is -d -u. */ - if (cflag) { - if (dflag || uflag) - usage(); - } else if (!dflag && !uflag) - dflag = uflag = 1; - if (argc > 2) usage(); @@ -183,9 +176,6 @@ main (int argc, char *argv[]) } tprev = convert(prevline); - if (!cflag && uflag && dflag) - show(ofp, prevline); - tthis = NULL; while (getline(&thisline, &thisbuflen, ifp) >= 0) { if (tthis != NULL) @@ -201,8 +191,7 @@ main (int argc, char *argv[]) if (comp) { /* If different, print; set previous to new value. */ - if (cflag || !dflag || !uflag) - show(ofp, prevline); + show(ofp, prevline); p = prevline; b1 = prevbuflen; prevline = thisline; @@ -210,8 +199,6 @@ main (int argc, char *argv[]) if (tprev != NULL) free(tprev); tprev = tthis; - if (!cflag && uflag && dflag) - show(ofp, prevline); thisline = p; thisbuflen = b1; tthis = NULL; @@ -221,8 +208,7 @@ main (int argc, char *argv[]) } if (ferror(ifp)) err(1, "%s", ifn); - if (cflag || !dflag || !uflag) - show(ofp, prevline); + show(ofp, prevline); exit(0); } @@ -287,9 +273,11 @@ static void show(FILE *ofp, const char *str) { + if ((dflag && repeats == 0) || (uflag && repeats > 0)) + return; if (cflag) (void)fprintf(ofp, "%4d %s", repeats + 1, str); - if ((dflag && repeats) || (uflag && !repeats)) + else (void)fprintf(ofp, "%s", str); } @@ -352,6 +340,6 @@ static void usage(void) { (void)fprintf(stderr, -"usage: uniq [-c | -d | -u] [-i] [-f fields] [-s chars] [input [output]]\n"); +"usage: uniq [-c] [-d | -u] [-i] [-f fields] [-s chars] [input [output]]\n"); exit(1); }