summaryrefslogtreecommitdiffstats
path: root/usr.bin/uniq
diff options
context:
space:
mode:
authortjr <tjr@FreeBSD.org>2002-05-30 00:07:14 +0000
committertjr <tjr@FreeBSD.org>2002-05-30 00:07:14 +0000
commit60d1ab01d7d0344f0d2313c5eb05bfa76b9c8f15 (patch)
treeeb37c045d97e5fb55348fdce816bda92e6f5d3cf /usr.bin/uniq
parent2d9a2285efeefa07b1e51441cecaadce92de9af1 (diff)
downloadFreeBSD-src-60d1ab01d7d0344f0d2313c5eb05bfa76b9c8f15.zip
FreeBSD-src-60d1ab01d7d0344f0d2313c5eb05bfa76b9c8f15.tar.gz
Accept an input file name of "-" to mean standard input, as required by
P1003.2.
Diffstat (limited to 'usr.bin/uniq')
-rw-r--r--usr.bin/uniq/uniq.115
-rw-r--r--usr.bin/uniq/uniq.c21
2 files changed, 20 insertions, 16 deletions
diff --git a/usr.bin/uniq/uniq.1 b/usr.bin/uniq/uniq.1
index 4e37c14..e19bed6 100644
--- a/usr.bin/uniq/uniq.1
+++ b/usr.bin/uniq/uniq.1
@@ -54,8 +54,19 @@
.Sh DESCRIPTION
The
.Nm
-utility reads the standard input comparing adjacent lines, and writes
-a copy of each unique input line to the standard output.
+utility reads the specified
+.Ar input_file
+comparing adjacent lines, and writes a copy of each unique input line to
+the
+.Ar output_file .
+If
+.Ar input_file
+is a single dash
+.Pq Sq \&-
+or absent, the standard input is read.
+If
+.Ar output_file
+is absent, standard output is used for output.
The second and succeeding copies of identical adjacent input lines are
not written.
Repeated lines in the input will not be detected if they are not adjacent,
diff --git a/usr.bin/uniq/uniq.c b/usr.bin/uniq/uniq.c
index 2d2b980..98f9eda 100644
--- a/usr.bin/uniq/uniq.c
+++ b/usr.bin/uniq/uniq.c
@@ -122,22 +122,15 @@ main (argc, argv)
} else if (!dflag && !uflag)
dflag = uflag = 1;
- switch(argc) {
- case 0:
- ifp = stdin;
- ofp = stdout;
- break;
- case 1:
- ifp = file(argv[0], "r");
- ofp = stdout;
- break;
- case 2:
+ if (argc > 2)
+ usage();
+
+ ifp = stdin;
+ ofp = stdout;
+ if (argc > 0 && strcmp(argv[0], "-") != 0)
ifp = file(argv[0], "r");
+ if (argc > 1)
ofp = file(argv[1], "w");
- break;
- default:
- usage();
- }
prevline = malloc(MAXLINELEN);
thisline = malloc(MAXLINELEN);
OpenPOWER on IntegriCloud