summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorMatthias Kilian <kili@cvs.openbsd.org>2007-11-09 20:04:04 +0000
committerMatthias Kilian <kili@cvs.openbsd.org>2007-11-09 20:04:04 +0000
commitdd2dd9571f2336983b4c3694a2bd7b16580538fe (patch)
tree4d1f9d92f2c673436b9e346ee7e2cf0cbdcbe7f7 /usr.bin
parent32d545cc1c0c5bef8a9b280f7d5a9e3ce45b9998 (diff)
Allow -c in conjunction with -d (and -u).
If field skipping is active, don't skip beyond the last non-blank of a field, and use isblank() instead of isspace() -- POSIX states that the longest string matching [[:blank:]]*[^[:blank:]]* makes up a field. Don't skip over trailing newlines. Help, testing and ok millert@
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/uniq/uniq.16
-rw-r--r--usr.bin/uniq/uniq.c44
2 files changed, 23 insertions, 27 deletions
diff --git a/usr.bin/uniq/uniq.1 b/usr.bin/uniq/uniq.1
index 866a58471c4..55c2c71a727 100644
--- a/usr.bin/uniq/uniq.1
+++ b/usr.bin/uniq/uniq.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: uniq.1,v 1.12 2007/05/31 19:20:19 jmc Exp $
+.\" $OpenBSD: uniq.1,v 1.13 2007/11/09 20:04:03 kili Exp $
.\" $NetBSD: uniq.1,v 1.5 1994/12/06 07:51:15 jtc Exp $
.\"
.\" Copyright (c) 1991, 1993
@@ -33,7 +33,7 @@
.\"
.\" @(#)uniq.1 8.1 (Berkeley) 6/6/93
.\"
-.Dd $Mdocdate: May 31 2007 $
+.Dd $Mdocdate: November 9 2007 $
.Dt UNIQ 1
.Os
.Sh NAME
@@ -70,7 +70,7 @@ Ignore the first
.Ar fields
in each input line when doing comparisons.
A field is a string of non-blank characters separated from adjacent fields
-by blanks.
+by blanks, with blanks considered part of the following field.
Field numbers are one based, i.e., the first field is field one.
.It Fl s Ar chars
Ignore the first
diff --git a/usr.bin/uniq/uniq.c b/usr.bin/uniq/uniq.c
index 04aa6328173..073bb334aaf 100644
--- a/usr.bin/uniq/uniq.c
+++ b/usr.bin/uniq/uniq.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uniq.c,v 1.15 2006/04/07 05:10:02 ray Exp $ */
+/* $OpenBSD: uniq.c,v 1.16 2007/11/09 20:04:03 kili Exp $ */
/* $NetBSD: uniq.c,v 1.7 1995/08/31 22:03:48 jtc Exp $ */
/*
@@ -43,7 +43,7 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)uniq.c 8.3 (Berkeley) 5/4/95";
#endif
-static char rcsid[] = "$OpenBSD: uniq.c,v 1.15 2006/04/07 05:10:02 ray Exp $";
+static char rcsid[] = "$OpenBSD: uniq.c,v 1.16 2007/11/09 20:04:03 kili Exp $";
#endif /* not lint */
#include <ctype.h>
@@ -111,11 +111,8 @@ 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)
+ /* If neither -d nor -u are set, default is -d -u. */
+ if (!dflag && !uflag)
dflag = uflag = 1;
switch(argc) {
@@ -175,27 +172,26 @@ main(int argc, char *argv[])
void
show(FILE *ofp, char *str)
{
-
- if (cflag && *str)
- (void)fprintf(ofp, "%4d %s", repeats + 1, str);
- if ((dflag && repeats) || (uflag && !repeats))
- (void)fprintf(ofp, "%s", str);
+ if ((dflag && repeats) || (uflag && !repeats)) {
+ if (cflag)
+ (void)fprintf(ofp, "%4d %s", repeats + 1, str);
+ else
+ (void)fprintf(ofp, "%s", str);
+ }
}
char *
skip(char *str)
{
- int infield, nchars, nfields;
-
- for (nfields = numfields, infield = 0; nfields && *str; ++str)
- if (isspace(*str)) {
- if (infield) {
- infield = 0;
- --nfields;
- }
- } else if (!infield)
- infield = 1;
- for (nchars = numchars; nchars-- && *str; ++str)
+ int nchars, nfields;
+
+ for (nfields = numfields; nfields && *str; nfields--) {
+ while (isblank(*str))
+ str++;
+ while (*str && !isblank(*str))
+ str++;
+ }
+ for (nchars = numchars; nchars-- && *str && *str != '\n'; ++str)
;
return (str);
}
@@ -245,7 +241,7 @@ __dead void
usage(void)
{
extern char *__progname;
-
+
(void)fprintf(stderr,
"usage: %s [-c | -d | -u] [-f fields] [-s chars] [input_file [output_file]]\n",
__progname);