Use err(3) instead of local redefinition. Cosmetic in usage().
This commit is contained in:
parent
aa736575ab
commit
af647767ed
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=28368
@ -47,5 +47,4 @@ typedef struct {
|
||||
#define NCHARS (UCHAR_MAX + 1) /* Number of possible characters. */
|
||||
#define OOBCH (UCHAR_MAX + 1) /* Out of band character value. */
|
||||
|
||||
void err __P((const char *fmt, ...));
|
||||
int next __P((STR *));
|
||||
|
@ -32,18 +32,22 @@
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)str.c 8.2 (Berkeley) 4/28/95";
|
||||
#endif
|
||||
static const char rcsid[] =
|
||||
"$Id$";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <ctype.h>
|
||||
#include <err.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "extern.h"
|
||||
|
||||
@ -188,10 +192,10 @@ genclass(s)
|
||||
tmp.name = s->str;
|
||||
if ((cp = (CLASS *)bsearch(&tmp, classes, sizeof(classes) /
|
||||
sizeof(CLASS), sizeof(CLASS), c_class)) == NULL)
|
||||
err("unknown class %s", s->str);
|
||||
errx(1, "unknown class %s", s->str);
|
||||
|
||||
if ((cp->set = p = malloc((NCHARS + 1) * sizeof(int))) == NULL)
|
||||
err("%s", strerror(errno));
|
||||
errx(1, "malloc");
|
||||
bzero(p, (NCHARS + 1) * sizeof(int));
|
||||
for (cnt = 0, func = cp->func; cnt < NCHARS; ++cnt)
|
||||
if ((func)(cnt))
|
||||
@ -221,11 +225,11 @@ genequiv(s)
|
||||
if (*s->str == '\\') {
|
||||
s->equiv[0] = backslash(s);
|
||||
if (*s->str != '=')
|
||||
err("misplaced equivalence equals sign");
|
||||
errx(1, "misplaced equivalence equals sign");
|
||||
} else {
|
||||
s->equiv[0] = s->str[0];
|
||||
if (s->str[1] != '=')
|
||||
err("misplaced equivalence equals sign");
|
||||
errx(1, "misplaced equivalence equals sign");
|
||||
}
|
||||
s->str += 2;
|
||||
s->cnt = 0;
|
||||
@ -259,14 +263,14 @@ genseq(s)
|
||||
char *ep;
|
||||
|
||||
if (s->which == STRING1)
|
||||
err("sequences only valid in string2");
|
||||
errx(1, "sequences only valid in string2");
|
||||
|
||||
if (*s->str == '\\')
|
||||
s->lastch = backslash(s);
|
||||
else
|
||||
s->lastch = *s->str++;
|
||||
if (*s->str != '*')
|
||||
err("misplaced sequence asterisk");
|
||||
errx(1, "misplaced sequence asterisk");
|
||||
|
||||
switch (*++s->str) {
|
||||
case '\\':
|
||||
@ -284,7 +288,7 @@ genseq(s)
|
||||
break;
|
||||
}
|
||||
}
|
||||
err("illegal sequence count");
|
||||
errx(1, "illegal sequence count");
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
|
@ -58,7 +58,7 @@
|
||||
.Ar string1 string2
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Nm tr
|
||||
.Nm
|
||||
utility copies the standard input to the standard output with substitution
|
||||
or deletion of selected characters.
|
||||
.Pp
|
||||
@ -225,7 +225,7 @@ it's interpreted as a decimal value.
|
||||
.El
|
||||
.Pp
|
||||
The
|
||||
.Nm tr
|
||||
.Nm
|
||||
utility exits 0 on success, and >0 if an error occurs.
|
||||
.Sh EXAMPLES
|
||||
The following examples are shown as given to the shell:
|
||||
@ -261,13 +261,13 @@ represent the three characters ``a'', ``-'' and ``z'' will have to be
|
||||
rewritten as ``a\e-z''.
|
||||
.Pp
|
||||
The
|
||||
.Nm tr
|
||||
.Nm
|
||||
utility has historically not permitted the manipulation of NUL bytes in
|
||||
its input and, additionally, stripped NUL's from its input stream.
|
||||
This implementation has removed this behavior as a bug.
|
||||
.Pp
|
||||
The
|
||||
.Nm tr
|
||||
.Nm
|
||||
utility has historically been extremely forgiving of syntax errors,
|
||||
for example, the
|
||||
.Fl c
|
||||
@ -277,7 +277,7 @@ options were ignored unless two strings were specified.
|
||||
This implementation will not permit illegal syntax.
|
||||
.Sh STANDARDS
|
||||
The
|
||||
.Nm tr
|
||||
.Nm
|
||||
utility is expected to be
|
||||
.St -p1003.2
|
||||
compatible.
|
||||
|
@ -32,18 +32,23 @@
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char copyright[] =
|
||||
static const char copyright[] =
|
||||
"@(#) Copyright (c) 1988, 1993\n\
|
||||
The Regents of the University of California. All rights reserved.\n";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)tr.c 8.2 (Berkeley) 5/4/95";
|
||||
#endif
|
||||
static const char rcsid[] =
|
||||
"$Id$";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <locale.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@ -202,7 +207,7 @@ main(argc, argv)
|
||||
*p++ = OOBCH;
|
||||
|
||||
if (!next(&s2))
|
||||
err("empty string2");
|
||||
errx(1, "empty string2");
|
||||
|
||||
/* If string2 runs out of characters, use the last one specified. */
|
||||
if (sflag)
|
||||
@ -256,38 +261,10 @@ setup(string, arg, str, cflag)
|
||||
static void
|
||||
usage()
|
||||
{
|
||||
(void)fprintf(stderr, "usage: tr [-cs] string1 string2\n");
|
||||
(void)fprintf(stderr, " tr [-c] -d string1\n");
|
||||
(void)fprintf(stderr, " tr [-c] -s string1\n");
|
||||
(void)fprintf(stderr, " tr [-c] -ds string1 string2\n");
|
||||
(void)fprintf(stderr, "%s\n%s\n%s\n%s\n",
|
||||
"usage: tr [-cs] string1 string2",
|
||||
" tr [-c] -d string1",
|
||||
" tr [-c] -s string1",
|
||||
" tr [-c] -ds string1 string2");
|
||||
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, "tr: ");
|
||||
(void)vfprintf(stderr, fmt, ap);
|
||||
va_end(ap);
|
||||
(void)fprintf(stderr, "\n");
|
||||
exit(1);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user