Audit uniq(1)
Refactor the manpage and small style-changes in uniq.c. Remove unnecessary "else", we catch argc > 2 earlier already.
This commit is contained in:
parent
5af4cdcd60
commit
4af8889396
2
README
2
README
@ -82,7 +82,7 @@ The following tools are implemented ('*' == finished, '#' == UTF-8 support,
|
|||||||
=*| tty yes none
|
=*| tty yes none
|
||||||
=*| uname yes none
|
=*| uname yes none
|
||||||
#*| unexpand yes none
|
#*| unexpand yes none
|
||||||
=* uniq yes none
|
=*| uniq yes none
|
||||||
=*| unlink yes none
|
=*| unlink yes none
|
||||||
=* uudecode yes none
|
=* uudecode yes none
|
||||||
=* uuencode yes none
|
=* uuencode yes none
|
||||||
|
29
uniq.1
29
uniq.1
@ -1,4 +1,4 @@
|
|||||||
.Dd January 30, 2015
|
.Dd March 17, 2015
|
||||||
.Dt UNIQ 1
|
.Dt UNIQ 1
|
||||||
.Os sbase
|
.Os sbase
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
@ -8,8 +8,8 @@
|
|||||||
.Nm
|
.Nm
|
||||||
.Op Fl c
|
.Op Fl c
|
||||||
.Op Fl d | u
|
.Op Fl d | u
|
||||||
.Op Fl f Ar fields
|
.Op Fl f Ar num
|
||||||
.Op Fl s Ar chars
|
.Op Fl s Ar num
|
||||||
.Op Ar input Op Ar output
|
.Op Ar input Op Ar output
|
||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
||||||
.Nm
|
.Nm
|
||||||
@ -20,29 +20,24 @@ duplicate lines to the
|
|||||||
.Ar output
|
.Ar output
|
||||||
file. If no
|
file. If no
|
||||||
.Ar input
|
.Ar input
|
||||||
file is given,
|
file is given
|
||||||
.Nm
|
.Nm
|
||||||
reads from stdin. If no
|
reads from stdin. If no
|
||||||
.Ar output
|
.Ar output
|
||||||
file is given, then
|
file is given
|
||||||
.Nm
|
.Nm
|
||||||
writes to stdout.
|
writes to stdout.
|
||||||
.Sh OPTIONS
|
.Sh OPTIONS
|
||||||
.Bl -tag -width Ds
|
.Bl -tag -width Ds
|
||||||
.It Fl c
|
.It Fl c
|
||||||
Prefixes each line with a count of its consecutive occurrences in the input.
|
Prefix each line with the number of consecutive occurrences in
|
||||||
.It Fl d
|
.Ar input .
|
||||||
Suppresses non-duplicate lines (thus 'uniq -d' prints only duplicates).
|
.It Fl d | Fl u
|
||||||
.It Fl u
|
Print duplicate | unique lines only.
|
||||||
Suppresses non-unique lines (thus 'uniq -u' prints only uniques).
|
.It Fl f Ar num | Fl s Ar num
|
||||||
.It Fl f Ar fields
|
|
||||||
Ignore the first
|
Ignore the first
|
||||||
.Ar fields
|
.Ar num
|
||||||
in each input line when doing comparisons.
|
fields | characters in each input line when doing comparisons.
|
||||||
.It Fl s Ar chars
|
|
||||||
Ignore the first
|
|
||||||
.Ar chars
|
|
||||||
characters in each input line when doing comparisons.
|
|
||||||
.El
|
.El
|
||||||
.Sh STANDARDS
|
.Sh STANDARDS
|
||||||
The
|
The
|
||||||
|
15
uniq.c
15
uniq.c
@ -30,6 +30,7 @@ uniqskip(const char *l)
|
|||||||
lo++;
|
lo++;
|
||||||
}
|
}
|
||||||
for (; s && *lo && *lo != '\n'; --s, ++lo);
|
for (; s && *lo && *lo != '\n'; --s, ++lo);
|
||||||
|
|
||||||
return lo;
|
return lo;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,7 +76,7 @@ uniq(FILE *fp, FILE *ofp)
|
|||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
ssize_t len;
|
ssize_t len;
|
||||||
|
|
||||||
while ((len = getline(&buf, &size, fp)) != -1)
|
while ((len = getline(&buf, &size, fp)) >= 0)
|
||||||
uniqline(ofp, buf, (size_t)len);
|
uniqline(ofp, buf, (size_t)len);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,23 +121,19 @@ main(int argc, char *argv[])
|
|||||||
if (argc > 2)
|
if (argc > 2)
|
||||||
usage();
|
usage();
|
||||||
|
|
||||||
if (argc == 0) {
|
if (!argc) {
|
||||||
uniq(stdin, stdout);
|
uniq(stdin, stdout);
|
||||||
} else if (argc >= 1) {
|
} else {
|
||||||
if (strcmp(argv[0], "-") && !(fp = fopen(argv[0], "r")))
|
if (strcmp(argv[0], "-") && !(fp = fopen(argv[0], "r")))
|
||||||
eprintf("fopen %s:", argv[0]);
|
eprintf("fopen %s:", argv[0]);
|
||||||
if (argc == 2) {
|
if (argc == 2) {
|
||||||
if (strcmp(argv[1], "-") &&
|
if (strcmp(argv[1], "-") && !(ofp = fopen(argv[1], "w")))
|
||||||
!(ofp = fopen(argv[1], "w")))
|
|
||||||
eprintf("fopen %s:", argv[1]);
|
eprintf("fopen %s:", argv[1]);
|
||||||
}
|
}
|
||||||
uniq(fp, ofp);
|
uniq(fp, ofp);
|
||||||
if (fp != stdin)
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
} else
|
}
|
||||||
usage();
|
|
||||||
uniqfinish(ofp);
|
uniqfinish(ofp);
|
||||||
if (ofp != stdout)
|
|
||||||
fclose(ofp);
|
fclose(ofp);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user