Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/uniq Allow -c with -d/-u. While uniq -cu isn't that ...



details:   https://anonhg.NetBSD.org/src/rev/1a97492e05e2
branches:  trunk
changeset: 757945:1a97492e05e2
user:      dholland <dholland%NetBSD.org@localhost>
date:      Wed Oct 06 06:43:26 2010 +0000

description:
Allow -c with -d/-u. While uniq -cu isn't that useful, uniq -cd often is.
No objection on tech-userlevel, and the arbitrary restriction has been
irritating me for ages.

diffstat:

 usr.bin/uniq/uniq.1 |   4 ++--
 usr.bin/uniq/uniq.c |  18 +++++++-----------
 2 files changed, 9 insertions(+), 13 deletions(-)

diffs (66 lines):

diff -r 546697903c6c -r 1a97492e05e2 usr.bin/uniq/uniq.1
--- a/usr.bin/uniq/uniq.1       Wed Oct 06 05:24:01 2010 +0000
+++ b/usr.bin/uniq/uniq.1       Wed Oct 06 06:43:26 2010 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: uniq.1,v 1.11 2007/01/06 02:18:24 christos Exp $
+.\"    $NetBSD: uniq.1,v 1.12 2010/10/06 06:43:26 dholland Exp $
 .\"
 .\" Copyright (c) 1991, 1993
 .\"    The Regents of the University of California.  All rights reserved.
@@ -40,7 +40,7 @@
 .Nd report or filter out repeated lines in a file
 .Sh SYNOPSIS
 .Nm
-.Op Fl c | Fl d | Fl u
+.Op Fl cdu
 .Op Fl f Ar fields
 .Op Fl s Ar chars
 .Oo
diff -r 546697903c6c -r 1a97492e05e2 usr.bin/uniq/uniq.c
--- a/usr.bin/uniq/uniq.c       Wed Oct 06 05:24:01 2010 +0000
+++ b/usr.bin/uniq/uniq.c       Wed Oct 06 06:43:26 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uniq.c,v 1.15 2008/07/21 14:19:27 lukem Exp $  */
+/*     $NetBSD: uniq.c,v 1.16 2010/10/06 06:43:26 dholland Exp $       */
 
 /*
  * Copyright (c) 1989, 1993
@@ -42,7 +42,7 @@
 #if 0
 static char sccsid[] = "@(#)uniq.c     8.3 (Berkeley) 5/4/95";
 #endif
-__RCSID("$NetBSD: uniq.c,v 1.15 2008/07/21 14:19:27 lukem Exp $");
+__RCSID("$NetBSD: uniq.c,v 1.16 2010/10/06 06:43:26 dholland Exp $");
 #endif /* not lint */
 
 #include <err.h>
@@ -107,13 +107,6 @@
 done:  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;
-
        switch(argc) {
        case 0:
                ifp = stdin;
@@ -192,10 +185,13 @@
 show(FILE *ofp, const char *str)
 {
 
-       if (cflag && *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);
+       }
 }
 
 static const char *



Home | Main Index | Thread Index | Old Index