Accept an input file name of "-" to mean standard input, as required by

P1003.2.
This commit is contained in:
Tim J. Robbins 2002-05-30 00:07:14 +00:00
parent a9986a105a
commit 38b1ff46af
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=97529
2 changed files with 21 additions and 17 deletions

View File

@ -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,

View File

@ -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:
ifp = file(argv[0], "r");
ofp = file(argv[1], "w");
break;
default:
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");
prevline = malloc(MAXLINELEN);
thisline = malloc(MAXLINELEN);