CVS commit: src/usr.bin/uniq

2019-04-23 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Apr 23 17:35:11 UTC 2019

Modified Files:
src/usr.bin/uniq: uniq.c

Log Message:
remove unused label


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/usr.bin/uniq/uniq.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/uniq/uniq.c
diff -u src/usr.bin/uniq/uniq.c:1.21 src/usr.bin/uniq/uniq.c:1.22
--- src/usr.bin/uniq/uniq.c:1.21	Tue Apr 23 10:40:12 2019
+++ src/usr.bin/uniq/uniq.c	Tue Apr 23 13:35:10 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: uniq.c,v 1.21 2019/04/23 14:40:12 uwe Exp $	*/
+/*	$NetBSD: uniq.c,v 1.22 2019/04/23 17:35:10 christos Exp $	*/
 
 /*
  * Copyright (c) 1989, 1993
@@ -42,7 +42,7 @@ __COPYRIGHT("@(#) Copyright (c) 1989, 19
 #if 0
 static char sccsid[] = "@(#)uniq.c	8.3 (Berkeley) 5/4/95";
 #endif
-__RCSID("$NetBSD: uniq.c,v 1.21 2019/04/23 14:40:12 uwe Exp $");
+__RCSID("$NetBSD: uniq.c,v 1.22 2019/04/23 17:35:10 christos Exp $");
 #endif /* not lint */
 
 #include 
@@ -102,7 +102,7 @@ main (int argc, char *argv[])
 			usage();
 	}
 
-done:	argc -= optind;
+	argc -= optind;
 	argv +=optind;
 
 	switch(argc) {



CVS commit: src/usr.bin/uniq

2019-04-23 Thread Valeriy E. Ushakov
Module Name:src
Committed By:   uwe
Date:   Tue Apr 23 14:40:12 UTC 2019

Modified Files:
src/usr.bin/uniq: uniq.c

Log Message:
Don't pass '-' to getopt(3).  My guess is that *very* old getopt
didn't handle "--" terminator, so this code was working around it and
not quite correctly at that.

Fixes weird output from

  $ uniq --long-option
  uniq: uniq: No such file or directory

(for more fun, run that command from /usr/bin as root).

Pointed out by Andreas Krey.


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/usr.bin/uniq/uniq.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/uniq/uniq.c
diff -u src/usr.bin/uniq/uniq.c:1.20 src/usr.bin/uniq/uniq.c:1.21
--- src/usr.bin/uniq/uniq.c:1.20	Sun Oct 16 06:17:51 2016
+++ src/usr.bin/uniq/uniq.c	Tue Apr 23 14:40:12 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: uniq.c,v 1.20 2016/10/16 06:17:51 abhinav Exp $	*/
+/*	$NetBSD: uniq.c,v 1.21 2019/04/23 14:40:12 uwe Exp $	*/
 
 /*
  * Copyright (c) 1989, 1993
@@ -42,7 +42,7 @@ __COPYRIGHT("@(#) Copyright (c) 1989, 19
 #if 0
 static char sccsid[] = "@(#)uniq.c	8.3 (Berkeley) 5/4/95";
 #endif
-__RCSID("$NetBSD: uniq.c,v 1.20 2016/10/16 06:17:51 abhinav Exp $");
+__RCSID("$NetBSD: uniq.c,v 1.21 2019/04/23 14:40:12 uwe Exp $");
 #endif /* not lint */
 
 #include 
@@ -75,11 +75,8 @@ main (int argc, char *argv[])
 	setprogname(argv[0]);
 	ifp = ofp = NULL;
 	obsolete(argv);
-	while ((ch = getopt(argc, argv, "-cdf:s:u")) != -1)
+	while ((ch = getopt(argc, argv, "cdf:s:u")) != -1)
 		switch (ch) {
-		case '-':
-			--optind;
-			goto done;
 		case 'c':
 			cflag = 1;
 			break;



CVS commit: src/usr.bin/uniq

2016-10-16 Thread Abhinav Upadhyay
Module Name:src
Committed By:   abhinav
Date:   Sun Oct 16 06:17:52 UTC 2016

Modified Files:
src/usr.bin/uniq: uniq.c

Log Message:
Fix the bug introduced in the previous commit.

The lengths of the lines being compared were not correct. Essentially, we
were comparing the length of the buffers instead of the length of the strings.

This patch also avoids calling skip() twice for the same line.

Thanks to Rin Okuyama for the patch.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/usr.bin/uniq/uniq.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/uniq/uniq.c
diff -u src/usr.bin/uniq/uniq.c:1.19 src/usr.bin/uniq/uniq.c:1.20
--- src/usr.bin/uniq/uniq.c:1.19	Fri Oct 14 19:43:59 2016
+++ src/usr.bin/uniq/uniq.c	Sun Oct 16 06:17:51 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: uniq.c,v 1.19 2016/10/14 19:43:59 abhinav Exp $	*/
+/*	$NetBSD: uniq.c,v 1.20 2016/10/16 06:17:51 abhinav Exp $	*/
 
 /*
  * Copyright (c) 1989, 1993
@@ -42,7 +42,7 @@ __COPYRIGHT("@(#) Copyright (c) 1989, 19
 #if 0
 static char sccsid[] = "@(#)uniq.c	8.3 (Berkeley) 5/4/95";
 #endif
-__RCSID("$NetBSD: uniq.c,v 1.19 2016/10/14 19:43:59 abhinav Exp $");
+__RCSID("$NetBSD: uniq.c,v 1.20 2016/10/16 06:17:51 abhinav Exp $");
 #endif /* not lint */
 
 #include 
@@ -65,12 +65,12 @@ static void usage(void) __dead;
 int
 main (int argc, char *argv[])
 {
-	const char *t1, *t2;
+	const char *prevp, *thisp;
 	FILE *ifp, *ofp;
 	int ch;
 	char *prevline, *thisline, *p;
 	size_t prevlinesize, thislinesize, psize;
-	size_t prevlinecompsize, thislinecompsize;
+	size_t prevlen, thislen;
 
 	setprogname(argv[0]);
 	ifp = ofp = NULL;
@@ -127,11 +127,16 @@ done:	argc -= optind;
 
 	if ((p = fgetln(ifp, )) == NULL)
 		return 0;
-	prevlinesize = psize;
+	prevlinesize = prevlen = psize;
 	if ((prevline = malloc(prevlinesize + 1)) == NULL)
 		err(1, "malloc");
 	(void)memcpy(prevline, p, prevlinesize);
 	prevline[prevlinesize] = '\0';
+	
+	if (numfields || numchars)
+		prevp = skip(prevline, );
+	else
+		prevp = prevline;
 
 	thislinesize = psize;
 	if ((thisline = malloc(thislinesize + 1)) == NULL)
@@ -143,22 +148,19 @@ done:	argc -= optind;
 err(1, "realloc");
 			thislinesize = psize;
 		}
+		thislen = psize;
 		(void)memcpy(thisline, p, psize);
 		thisline[psize] = '\0';
-		thislinecompsize = thislinesize;
-		prevlinecompsize = prevlinesize;
 
 		/* If requested get the chosen fields + character offsets. */
 		if (numfields || numchars) {
-			t1 = skip(thisline, );
-			t2 = skip(prevline, );
+			thisp = skip(thisline, );
 		} else {
-			t1 = thisline;
-			t2 = prevline;
+			thisp = thisline;
 		}
 
 		/* If different, print; set previous to new value. */
-		if (thislinecompsize != prevlinecompsize || strcmp(t1, t2)) {
+		if (thislen != prevlen || strcmp(thisp, prevp)) {
 			char *t;
 			size_t ts;
 
@@ -169,6 +171,8 @@ done:	argc -= optind;
 			ts = prevlinesize;
 			prevlinesize = thislinesize;
 			thislinesize = ts;
+			prevp = thisp;
+			prevlen = thislen;
 			repeats = 0;
 		} else
 			++repeats;



CVS commit: src/usr.bin/uniq

2016-10-14 Thread Abhinav Upadhyay
Module Name:src
Committed By:   abhinav
Date:   Fri Oct 14 19:43:59 UTC 2016

Modified Files:
src/usr.bin/uniq: uniq.c

Log Message:
A small optimization: since we already know the length of the lines, check
if the lenghts are equal before calling strcmp(3). Most of the times, the call
to strcmp(3) can be saved if the lines are not of the same length.

Thanks to Christos for the reviews


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/usr.bin/uniq/uniq.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/uniq/uniq.c
diff -u src/usr.bin/uniq/uniq.c:1.18 src/usr.bin/uniq/uniq.c:1.19
--- src/usr.bin/uniq/uniq.c:1.18	Sun Aug 26 14:14:16 2012
+++ src/usr.bin/uniq/uniq.c	Fri Oct 14 19:43:59 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: uniq.c,v 1.18 2012/08/26 14:14:16 wiz Exp $	*/
+/*	$NetBSD: uniq.c,v 1.19 2016/10/14 19:43:59 abhinav Exp $	*/
 
 /*
  * Copyright (c) 1989, 1993
@@ -42,7 +42,7 @@ __COPYRIGHT("@(#) Copyright (c) 1989, 19
 #if 0
 static char sccsid[] = "@(#)uniq.c	8.3 (Berkeley) 5/4/95";
 #endif
-__RCSID("$NetBSD: uniq.c,v 1.18 2012/08/26 14:14:16 wiz Exp $");
+__RCSID("$NetBSD: uniq.c,v 1.19 2016/10/14 19:43:59 abhinav Exp $");
 #endif /* not lint */
 
 #include 
@@ -58,7 +58,7 @@ static int numchars, numfields, repeats;
 
 static FILE *file(const char *, const char *);
 static void show(FILE *, const char *);
-static const char *skip(const char *);
+static const char *skip(const char *, size_t *);
 static void obsolete(char *[]);
 static void usage(void) __dead;
 
@@ -70,6 +70,7 @@ main (int argc, char *argv[])
 	int ch;
 	char *prevline, *thisline, *p;
 	size_t prevlinesize, thislinesize, psize;
+	size_t prevlinecompsize, thislinecompsize;
 
 	setprogname(argv[0]);
 	ifp = ofp = NULL;
@@ -144,18 +145,20 @@ done:	argc -= optind;
 		}
 		(void)memcpy(thisline, p, psize);
 		thisline[psize] = '\0';
+		thislinecompsize = thislinesize;
+		prevlinecompsize = prevlinesize;
 
 		/* If requested get the chosen fields + character offsets. */
 		if (numfields || numchars) {
-			t1 = skip(thisline);
-			t2 = skip(prevline);
+			t1 = skip(thisline, );
+			t2 = skip(prevline, );
 		} else {
 			t1 = thisline;
 			t2 = prevline;
 		}
 
 		/* If different, print; set previous to new value. */
-		if (strcmp(t1, t2)) {
+		if (thislinecompsize != prevlinecompsize || strcmp(t1, t2)) {
 			char *t;
 			size_t ts;
 
@@ -195,11 +198,12 @@ show(FILE *ofp, const char *str)
 }
 
 static const char *
-skip(const char *str)
+skip(const char *str, size_t *linesize)
 {
 	int infield, nchars, nfields;
+	size_t ls = *linesize;
 
-	for (nfields = numfields, infield = 0; nfields && *str; ++str)
+	for (nfields = numfields, infield = 0; nfields && *str; ++str, --ls)
 		if (isspace((unsigned char)*str)) {
 			if (infield) {
 infield = 0;
@@ -207,8 +211,9 @@ skip(const char *str)
 			}
 		} else if (!infield)
 			infield = 1;
-	for (nchars = numchars; nchars-- && *str; ++str)
+	for (nchars = numchars; nchars-- && *str; ++str, --ls)
 		continue;
+	*linesize = ls;
 	return str;
 }
 



CVS commit: src/usr.bin/uniq

2012-08-26 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Sun Aug 26 14:13:50 UTC 2012

Modified Files:
src/usr.bin/uniq: uniq.1

Log Message:
- improve punctuation;
- improve wording (explicitly mention the name of the optional
  additional arguments within the text, using macros as well);
- create separate section, and use `.Ex' macro, for exit status
  information;
- bump date.

Patch from Bug Hunting.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/usr.bin/uniq/uniq.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/uniq/uniq.1
diff -u src/usr.bin/uniq/uniq.1:1.12 src/usr.bin/uniq/uniq.1:1.13
--- src/usr.bin/uniq/uniq.1:1.12	Wed Oct  6 06:43:26 2010
+++ src/usr.bin/uniq/uniq.1	Sun Aug 26 14:13:50 2012
@@ -1,4 +1,4 @@
-.\	$NetBSD: uniq.1,v 1.12 2010/10/06 06:43:26 dholland Exp $
+.\	$NetBSD: uniq.1,v 1.13 2012/08/26 14:13:50 wiz Exp $
 .\
 .\ Copyright (c) 1991, 1993
 .\	The Regents of the University of California.  All rights reserved.
@@ -32,7 +32,7 @@
 .\
 .\ @(#)uniq.1	8.1 (Berkeley) 6/6/93
 .\
-.Dd January 6, 2007
+.Dd August 26, 2012
 .Dt UNIQ 1
 .Os
 .Sh NAME
@@ -70,7 +70,7 @@ Ignore the first
 in each input line when doing comparisons.
 A field is a string of non-blank characters separated from adjacent fields
 by blanks.
-Field numbers are one based, i.e. the first field is field one.
+Field numbers are one based, i.e., the first field is field one.
 .It Fl s Ar chars
 Ignore the first
 .Ar chars
@@ -82,7 +82,7 @@ option, the first
 characters after the first
 .Ar fields
 fields will be ignored.
-Character numbers are one based, i.e. the first character is character one.
+Character numbers are one based, i.e., the first character is character one.
 .It Fl u
 Don't output lines that are repeated in the input.
 .\.It Fl Ns Ar n
@@ -105,13 +105,15 @@ Don't output lines that are repeated in 
 .\number.
 .El
 .Pp
-If additional arguments are specified on the command line, the first
-such argument is used as the name of an input file, the second is used
-as the name of an output file.
-.Pp
-The
-.Nm
-utility exits 0 on success, and \*[Gt]0 if an error occurs.
+Additional arguments
+.Ar input_file
+and
+.Ar output_file
+may be specified on the command line,
+where the former is then used as the name of an input file,
+and the latter as the name of an output file.
+.Sh EXIT STATUS
+.Ex -std
 .Sh COMPATIBILITY
 The historic
 .Cm \\(pl Ns Ar number



CVS commit: src/usr.bin/uniq

2012-08-26 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Sun Aug 26 14:14:16 UTC 2012

Modified Files:
src/usr.bin/uniq: uniq.c

Log Message:
- synchronize `usage' message with man page.

Patch from Bug Hunting.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/usr.bin/uniq/uniq.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/uniq/uniq.c
diff -u src/usr.bin/uniq/uniq.c:1.17 src/usr.bin/uniq/uniq.c:1.18
--- src/usr.bin/uniq/uniq.c:1.17	Wed Oct  6 07:59:18 2010
+++ src/usr.bin/uniq/uniq.c	Sun Aug 26 14:14:16 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: uniq.c,v 1.17 2010/10/06 07:59:18 wiz Exp $	*/
+/*	$NetBSD: uniq.c,v 1.18 2012/08/26 14:14:16 wiz Exp $	*/
 
 /*
  * Copyright (c) 1989, 1993
@@ -42,7 +42,7 @@ __COPYRIGHT(@(#) Copyright (c) 1989, 19
 #if 0
 static char sccsid[] = @(#)uniq.c	8.3 (Berkeley) 5/4/95;
 #endif
-__RCSID($NetBSD: uniq.c,v 1.17 2010/10/06 07:59:18 wiz Exp $);
+__RCSID($NetBSD: uniq.c,v 1.18 2012/08/26 14:14:16 wiz Exp $);
 #endif /* not lint */
 
 #include err.h
@@ -251,7 +251,7 @@ obsolete(char *argv[])
 static void
 usage(void)
 {
-	(void)fprintf(stderr, Usage: %s [-cdu] [-f fields] [-s chars] 
-	[input [output]]\n, getprogname());
+	(void)fprintf(stderr, usage: %s [-cdu] [-f fields] [-s chars] 
+	[input_file [output_file]]\n, getprogname());
 	exit(1);
 }



CVS commit: src/usr.bin/uniq

2010-10-06 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Wed Oct  6 06:43:26 UTC 2010

Modified Files:
src/usr.bin/uniq: uniq.1 uniq.c

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/usr.bin/uniq/uniq.1
cvs rdiff -u -r1.15 -r1.16 src/usr.bin/uniq/uniq.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/uniq/uniq.1
diff -u src/usr.bin/uniq/uniq.1:1.11 src/usr.bin/uniq/uniq.1:1.12
--- src/usr.bin/uniq/uniq.1:1.11	Sat Jan  6 02:18:24 2007
+++ src/usr.bin/uniq/uniq.1	Wed Oct  6 06:43:26 2010
@@ -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

Index: src/usr.bin/uniq/uniq.c
diff -u src/usr.bin/uniq/uniq.c:1.15 src/usr.bin/uniq/uniq.c:1.16
--- src/usr.bin/uniq/uniq.c:1.15	Mon Jul 21 14:19:27 2008
+++ src/usr.bin/uniq/uniq.c	Wed Oct  6 06:43:26 2010
@@ -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 *



CVS commit: src/usr.bin/uniq

2010-10-06 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Wed Oct  6 07:59:18 UTC 2010

Modified Files:
src/usr.bin/uniq: uniq.c

Log Message:
Sync usage with man page.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/usr.bin/uniq/uniq.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/uniq/uniq.c
diff -u src/usr.bin/uniq/uniq.c:1.16 src/usr.bin/uniq/uniq.c:1.17
--- src/usr.bin/uniq/uniq.c:1.16	Wed Oct  6 06:43:26 2010
+++ src/usr.bin/uniq/uniq.c	Wed Oct  6 07:59:18 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: uniq.c,v 1.16 2010/10/06 06:43:26 dholland Exp $	*/
+/*	$NetBSD: uniq.c,v 1.17 2010/10/06 07:59:18 wiz 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.16 2010/10/06 06:43:26 dholland Exp $);
+__RCSID($NetBSD: uniq.c,v 1.17 2010/10/06 07:59:18 wiz Exp $);
 #endif /* not lint */
 
 #include err.h
@@ -251,7 +251,7 @@
 static void
 usage(void)
 {
-	(void)fprintf(stderr, Usage: %s [-c | -du] [-f fields] [-s chars] 
+	(void)fprintf(stderr, Usage: %s [-cdu] [-f fields] [-s chars] 
 	[input [output]]\n, getprogname());
 	exit(1);
 }