WARNSify, fix .Nm usage, deprecate register, getopt returns -1, use <err.h>
This commit is contained in:
parent
0fad87214f
commit
8512105c8e
@ -1,4 +1,4 @@
|
|||||||
.\" $NetBSD: uniq.1,v 1.5 1994/12/06 07:51:15 jtc Exp $
|
.\" $NetBSD: uniq.1,v 1.6 1997/10/20 02:27:04 lukem Exp $
|
||||||
.\"
|
.\"
|
||||||
.\" Copyright (c) 1991, 1993
|
.\" Copyright (c) 1991, 1993
|
||||||
.\" The Regents of the University of California. All rights reserved.
|
.\" The Regents of the University of California. All rights reserved.
|
||||||
@ -43,7 +43,7 @@
|
|||||||
.Nm uniq
|
.Nm uniq
|
||||||
.Nd report or filter out repeated lines in a file
|
.Nd report or filter out repeated lines in a file
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.Nm uniq
|
.Nm
|
||||||
.Op Fl c | Fl d | Fl u
|
.Op Fl c | Fl d | Fl u
|
||||||
.Op Fl f Ar fields
|
.Op Fl f Ar fields
|
||||||
.Op Fl s Ar chars
|
.Op Fl s Ar chars
|
||||||
@ -53,7 +53,7 @@
|
|||||||
.Oc
|
.Oc
|
||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
||||||
The
|
The
|
||||||
.Nm uniq
|
.Nm
|
||||||
utility reads the standard input comparing adjacent lines, and writes
|
utility reads the standard input comparing adjacent lines, and writes
|
||||||
a copy of each unique input line to the standard output.
|
a copy of each unique input line to the standard output.
|
||||||
The second and succeeding copies of identical adjacent input lines are
|
The second and succeeding copies of identical adjacent input lines are
|
||||||
@ -114,7 +114,7 @@ such argument is used as the name of an input file, the second is used
|
|||||||
as the name of an output file.
|
as the name of an output file.
|
||||||
.Pp
|
.Pp
|
||||||
The
|
The
|
||||||
.Nm uniq
|
.Nm
|
||||||
utility exits 0 on success, and >0 if an error occurs.
|
utility exits 0 on success, and >0 if an error occurs.
|
||||||
.Sh COMPATIBILITY
|
.Sh COMPATIBILITY
|
||||||
The historic
|
The historic
|
||||||
@ -126,7 +126,7 @@ options have been deprecated but are still supported in this implementation.
|
|||||||
.Xr sort 1
|
.Xr sort 1
|
||||||
.Sh STANDARDS
|
.Sh STANDARDS
|
||||||
The
|
The
|
||||||
.Nm uniq
|
.Nm
|
||||||
utility is expected to be
|
utility is expected to be
|
||||||
.St -p1003.2
|
.St -p1003.2
|
||||||
compatible.
|
compatible.
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $NetBSD: uniq.c,v 1.7 1995/08/31 22:03:48 jtc Exp $ */
|
/* $NetBSD: uniq.c,v 1.8 1997/10/20 02:27:05 lukem Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 1989, 1993
|
* Copyright (c) 1989, 1993
|
||||||
@ -36,19 +36,20 @@
|
|||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <sys/cdefs.h>
|
||||||
#ifndef lint
|
#ifndef lint
|
||||||
static char copyright[] =
|
__COPYRIGHT("@(#) Copyright (c) 1989, 1993\n\
|
||||||
"@(#) Copyright (c) 1989, 1993\n\
|
The Regents of the University of California. All rights reserved.\n");
|
||||||
The Regents of the University of California. All rights reserved.\n";
|
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
#ifndef lint
|
#ifndef lint
|
||||||
#if 0
|
#if 0
|
||||||
static char sccsid[] = "@(#)uniq.c 8.3 (Berkeley) 5/4/95";
|
static char sccsid[] = "@(#)uniq.c 8.3 (Berkeley) 5/4/95";
|
||||||
#endif
|
#endif
|
||||||
static char rcsid[] = "$NetBSD: uniq.c,v 1.7 1995/08/31 22:03:48 jtc Exp $";
|
__RCSID("$NetBSD: uniq.c,v 1.8 1997/10/20 02:27:05 lukem Exp $");
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
|
#include <err.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
@ -61,8 +62,8 @@ static char rcsid[] = "$NetBSD: uniq.c,v 1.7 1995/08/31 22:03:48 jtc Exp $";
|
|||||||
int cflag, dflag, uflag;
|
int cflag, dflag, uflag;
|
||||||
int numchars, numfields, repeats;
|
int numchars, numfields, repeats;
|
||||||
|
|
||||||
void err __P((const char *, ...));
|
|
||||||
FILE *file __P((char *, char *));
|
FILE *file __P((char *, char *));
|
||||||
|
int main __P((int, char **));
|
||||||
void show __P((FILE *, char *));
|
void show __P((FILE *, char *));
|
||||||
char *skip __P((char *));
|
char *skip __P((char *));
|
||||||
void obsolete __P((char *[]));
|
void obsolete __P((char *[]));
|
||||||
@ -73,13 +74,14 @@ main (argc, argv)
|
|||||||
int argc;
|
int argc;
|
||||||
char *argv[];
|
char *argv[];
|
||||||
{
|
{
|
||||||
register char *t1, *t2;
|
char *t1, *t2;
|
||||||
FILE *ifp, *ofp;
|
FILE *ifp, *ofp;
|
||||||
int ch;
|
int ch;
|
||||||
char *prevline, *thisline, *p;
|
char *prevline, *thisline, *p;
|
||||||
|
|
||||||
|
ifp = ofp = NULL;
|
||||||
obsolete(argv);
|
obsolete(argv);
|
||||||
while ((ch = getopt(argc, argv, "-cdf:s:u")) != EOF)
|
while ((ch = getopt(argc, argv, "-cdf:s:u")) != -1)
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case '-':
|
case '-':
|
||||||
--optind;
|
--optind;
|
||||||
@ -93,12 +95,13 @@ main (argc, argv)
|
|||||||
case 'f':
|
case 'f':
|
||||||
numfields = strtol(optarg, &p, 10);
|
numfields = strtol(optarg, &p, 10);
|
||||||
if (numfields < 0 || *p)
|
if (numfields < 0 || *p)
|
||||||
err("illegal field skip value: %s", optarg);
|
errx(1, "illegal field skip value: %s", optarg);
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
numchars = strtol(optarg, &p, 10);
|
numchars = strtol(optarg, &p, 10);
|
||||||
if (numchars < 0 || *p)
|
if (numchars < 0 || *p)
|
||||||
err("illegal character skip value: %s", optarg);
|
errx(1, "illegal character skip value: %s",
|
||||||
|
optarg);
|
||||||
break;
|
break;
|
||||||
case 'u':
|
case 'u':
|
||||||
uflag = 1;
|
uflag = 1;
|
||||||
@ -138,7 +141,7 @@ done: argc -= optind;
|
|||||||
prevline = malloc(MAXLINELEN);
|
prevline = malloc(MAXLINELEN);
|
||||||
thisline = malloc(MAXLINELEN);
|
thisline = malloc(MAXLINELEN);
|
||||||
if (prevline == NULL || thisline == NULL)
|
if (prevline == NULL || thisline == NULL)
|
||||||
err("%s", strerror(errno));
|
err(1, "malloc");
|
||||||
|
|
||||||
if (fgets(prevline, MAXLINELEN, ifp) == NULL)
|
if (fgets(prevline, MAXLINELEN, ifp) == NULL)
|
||||||
exit(0);
|
exit(0);
|
||||||
@ -180,15 +183,15 @@ show(ofp, str)
|
|||||||
|
|
||||||
if (cflag && *str)
|
if (cflag && *str)
|
||||||
(void)fprintf(ofp, "%4d %s", repeats + 1, str);
|
(void)fprintf(ofp, "%4d %s", repeats + 1, str);
|
||||||
if (dflag && repeats || uflag && !repeats)
|
if ((dflag && repeats) || (uflag && !repeats))
|
||||||
(void)fprintf(ofp, "%s", str);
|
(void)fprintf(ofp, "%s", str);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
skip(str)
|
skip(str)
|
||||||
register char *str;
|
char *str;
|
||||||
{
|
{
|
||||||
register int infield, nchars, nfields;
|
int infield, nchars, nfields;
|
||||||
|
|
||||||
for (nfields = numfields, infield = 0; nfields && *str; ++str)
|
for (nfields = numfields, infield = 0; nfields && *str; ++str)
|
||||||
if (isspace(*str)) {
|
if (isspace(*str)) {
|
||||||
@ -209,7 +212,7 @@ file(name, mode)
|
|||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
|
||||||
if ((fp = fopen(name, mode)) == NULL)
|
if ((fp = fopen(name, mode)) == NULL)
|
||||||
err("%s: %s", name, strerror(errno));
|
err(1, "%s", name);
|
||||||
return(fp);
|
return(fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -220,7 +223,7 @@ obsolete(argv)
|
|||||||
int len;
|
int len;
|
||||||
char *ap, *p, *start;
|
char *ap, *p, *start;
|
||||||
|
|
||||||
while (ap = *++argv) {
|
while ((ap = *++argv) != NULL) {
|
||||||
/* Return if "--" or not an option of any form. */
|
/* Return if "--" or not an option of any form. */
|
||||||
if (ap[0] != '-') {
|
if (ap[0] != '-') {
|
||||||
if (ap[0] != '+')
|
if (ap[0] != '+')
|
||||||
@ -235,7 +238,7 @@ obsolete(argv)
|
|||||||
*/
|
*/
|
||||||
len = strlen(ap);
|
len = strlen(ap);
|
||||||
if ((start = p = malloc(len + 3)) == NULL)
|
if ((start = p = malloc(len + 3)) == NULL)
|
||||||
err("%s", strerror(errno));
|
err(1, "malloc");
|
||||||
*p++ = '-';
|
*p++ = '-';
|
||||||
*p++ = ap[0] == '+' ? 's' : 'f';
|
*p++ = ap[0] == '+' ? 's' : 'f';
|
||||||
(void)strcpy(p, ap + 1);
|
(void)strcpy(p, ap + 1);
|
||||||
@ -250,32 +253,3 @@ usage()
|
|||||||
"usage: uniq [-c | -du] [-f fields] [-s chars] [input [output]]\n");
|
"usage: uniq [-c | -du] [-f fields] [-s chars] [input [output]]\n");
|
||||||
exit(1);
|
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