Use err(3) instead of local redefinition.
This commit is contained in:
parent
d4d0763a7d
commit
213915d456
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=28503
@ -41,7 +41,7 @@
|
||||
.Nm uniq
|
||||
.Nd report or filter out repeated lines in a file
|
||||
.Sh SYNOPSIS
|
||||
.Nm uniq
|
||||
.Nm
|
||||
.Op Fl c | Fl d | Fl u
|
||||
.Op Fl f Ar fields
|
||||
.Op Fl s Ar chars
|
||||
@ -51,7 +51,7 @@
|
||||
.Oc
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Nm uniq
|
||||
.Nm
|
||||
utility reads the standard input comparing adjacent lines, and writes
|
||||
a copy of each unique input line to the standard output.
|
||||
The second and succeeding copies of identical adjacent input lines are
|
||||
@ -112,7 +112,7 @@ 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 uniq
|
||||
.Nm
|
||||
utility exits 0 on success, and >0 if an error occurs.
|
||||
.Sh COMPATIBILITY
|
||||
The historic
|
||||
@ -124,7 +124,7 @@ options have been deprecated but are still supported in this implementation.
|
||||
.Xr sort 1
|
||||
.Sh STANDARDS
|
||||
The
|
||||
.Nm uniq
|
||||
.Nm
|
||||
utility is expected to be
|
||||
.St -p1003.2
|
||||
compatible.
|
||||
|
@ -35,18 +35,22 @@
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char copyright[] =
|
||||
static const char copyright[] =
|
||||
"@(#) Copyright (c) 1989, 1993\n\
|
||||
The Regents of the University of California. All rights reserved.\n";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)uniq.c 8.3 (Berkeley) 5/4/95";
|
||||
#endif
|
||||
static const char rcsid[] =
|
||||
"$Id$";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <err.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
@ -56,12 +60,11 @@ static char sccsid[] = "@(#)uniq.c 8.3 (Berkeley) 5/4/95";
|
||||
int cflag, dflag, uflag;
|
||||
int numchars, numfields, repeats;
|
||||
|
||||
void err __P((const char *, ...));
|
||||
FILE *file __P((char *, char *));
|
||||
void show __P((FILE *, char *));
|
||||
char *skip __P((char *));
|
||||
void obsolete __P((char *[]));
|
||||
void usage __P((void));
|
||||
static void usage __P((void));
|
||||
|
||||
int
|
||||
main (argc, argv)
|
||||
@ -88,12 +91,12 @@ main (argc, argv)
|
||||
case 'f':
|
||||
numfields = strtol(optarg, &p, 10);
|
||||
if (numfields < 0 || *p)
|
||||
err("illegal field skip value: %s", optarg);
|
||||
errx(1, "illegal field skip value: %s", optarg);
|
||||
break;
|
||||
case 's':
|
||||
numchars = strtol(optarg, &p, 10);
|
||||
if (numchars < 0 || *p)
|
||||
err("illegal character skip value: %s", optarg);
|
||||
errx(1, "illegal character skip value: %s", optarg);
|
||||
break;
|
||||
case 'u':
|
||||
uflag = 1;
|
||||
@ -133,7 +136,7 @@ done: argc -= optind;
|
||||
prevline = malloc(MAXLINELEN);
|
||||
thisline = malloc(MAXLINELEN);
|
||||
if (prevline == NULL || thisline == NULL)
|
||||
err("%s", strerror(errno));
|
||||
errx(1, "malloc");
|
||||
|
||||
if (fgets(prevline, MAXLINELEN, ifp) == NULL)
|
||||
exit(0);
|
||||
@ -175,7 +178,7 @@ show(ofp, str)
|
||||
|
||||
if (cflag && *str)
|
||||
(void)fprintf(ofp, "%4d %s", repeats + 1, str);
|
||||
if (dflag && repeats || uflag && !repeats)
|
||||
if ((dflag && repeats) || (uflag && !repeats))
|
||||
(void)fprintf(ofp, "%s", str);
|
||||
}
|
||||
|
||||
@ -204,7 +207,7 @@ file(name, mode)
|
||||
FILE *fp;
|
||||
|
||||
if ((fp = fopen(name, mode)) == NULL)
|
||||
err("%s: %s", name, strerror(errno));
|
||||
err(1, "%s", name);
|
||||
return(fp);
|
||||
}
|
||||
|
||||
@ -215,7 +218,7 @@ obsolete(argv)
|
||||
int len;
|
||||
char *ap, *p, *start;
|
||||
|
||||
while (ap = *++argv) {
|
||||
while ((ap = *++argv)) {
|
||||
/* Return if "--" or not an option of any form. */
|
||||
if (ap[0] != '-') {
|
||||
if (ap[0] != '+')
|
||||
@ -230,7 +233,7 @@ obsolete(argv)
|
||||
*/
|
||||
len = strlen(ap);
|
||||
if ((start = p = malloc(len + 3)) == NULL)
|
||||
err("%s", strerror(errno));
|
||||
errx(1, "malloc");
|
||||
*p++ = '-';
|
||||
*p++ = ap[0] == '+' ? 's' : 'f';
|
||||
(void)strcpy(p, ap + 1);
|
||||
@ -238,39 +241,10 @@ obsolete(argv)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
usage()
|
||||
{
|
||||
(void)fprintf(stderr,
|
||||
"usage: uniq [-c | -du] [-f fields] [-s chars] [input [output]]\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
#if __STDC__
|
||||
#include <stdarg.h>
|
||||
#else
|
||||
#include <varargs.h>
|
||||
#endif
|
||||
|
||||
void
|
||||
#if __STDC__
|
||||
err(const char *fmt, ...)
|
||||
#else
|
||||
err(fmt, va_alist)
|
||||
char *fmt;
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
va_list ap;
|
||||
#if __STDC__
|
||||
va_start(ap, fmt);
|
||||
#else
|
||||
va_start(ap);
|
||||
#endif
|
||||
(void)fprintf(stderr, "uniq: ");
|
||||
(void)vfprintf(stderr, fmt, ap);
|
||||
va_end(ap);
|
||||
(void)fprintf(stderr, "\n");
|
||||
exit(1);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user