Use err(3) instead of local redefinition. Cosmetic in usage().

This commit is contained in:
Philippe Charnier 1997-08-18 07:24:58 +00:00
parent aa736575ab
commit af647767ed
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=28368
4 changed files with 30 additions and 50 deletions

View File

@ -47,5 +47,4 @@ typedef struct {
#define NCHARS (UCHAR_MAX + 1) /* Number of possible characters. */ #define NCHARS (UCHAR_MAX + 1) /* Number of possible characters. */
#define OOBCH (UCHAR_MAX + 1) /* Out of band character value. */ #define OOBCH (UCHAR_MAX + 1) /* Out of band character value. */
void err __P((const char *fmt, ...));
int next __P((STR *)); int next __P((STR *));

View File

@ -32,18 +32,22 @@
*/ */
#ifndef lint #ifndef lint
#if 0
static char sccsid[] = "@(#)str.c 8.2 (Berkeley) 4/28/95"; static char sccsid[] = "@(#)str.c 8.2 (Berkeley) 4/28/95";
#endif
static const char rcsid[] =
"$Id$";
#endif /* not lint */ #endif /* not lint */
#include <sys/cdefs.h> #include <sys/cdefs.h>
#include <sys/types.h> #include <sys/types.h>
#include <errno.h> #include <ctype.h>
#include <err.h>
#include <stddef.h> #include <stddef.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <ctype.h>
#include "extern.h" #include "extern.h"
@ -188,10 +192,10 @@ genclass(s)
tmp.name = s->str; tmp.name = s->str;
if ((cp = (CLASS *)bsearch(&tmp, classes, sizeof(classes) / if ((cp = (CLASS *)bsearch(&tmp, classes, sizeof(classes) /
sizeof(CLASS), sizeof(CLASS), c_class)) == NULL) 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) if ((cp->set = p = malloc((NCHARS + 1) * sizeof(int))) == NULL)
err("%s", strerror(errno)); errx(1, "malloc");
bzero(p, (NCHARS + 1) * sizeof(int)); bzero(p, (NCHARS + 1) * sizeof(int));
for (cnt = 0, func = cp->func; cnt < NCHARS; ++cnt) for (cnt = 0, func = cp->func; cnt < NCHARS; ++cnt)
if ((func)(cnt)) if ((func)(cnt))
@ -221,11 +225,11 @@ genequiv(s)
if (*s->str == '\\') { if (*s->str == '\\') {
s->equiv[0] = backslash(s); s->equiv[0] = backslash(s);
if (*s->str != '=') if (*s->str != '=')
err("misplaced equivalence equals sign"); errx(1, "misplaced equivalence equals sign");
} else { } else {
s->equiv[0] = s->str[0]; s->equiv[0] = s->str[0];
if (s->str[1] != '=') if (s->str[1] != '=')
err("misplaced equivalence equals sign"); errx(1, "misplaced equivalence equals sign");
} }
s->str += 2; s->str += 2;
s->cnt = 0; s->cnt = 0;
@ -259,14 +263,14 @@ genseq(s)
char *ep; char *ep;
if (s->which == STRING1) if (s->which == STRING1)
err("sequences only valid in string2"); errx(1, "sequences only valid in string2");
if (*s->str == '\\') if (*s->str == '\\')
s->lastch = backslash(s); s->lastch = backslash(s);
else else
s->lastch = *s->str++; s->lastch = *s->str++;
if (*s->str != '*') if (*s->str != '*')
err("misplaced sequence asterisk"); errx(1, "misplaced sequence asterisk");
switch (*++s->str) { switch (*++s->str) {
case '\\': case '\\':
@ -284,7 +288,7 @@ genseq(s)
break; break;
} }
} }
err("illegal sequence count"); errx(1, "illegal sequence count");
/* NOTREACHED */ /* NOTREACHED */
} }

View File

@ -58,7 +58,7 @@
.Ar string1 string2 .Ar string1 string2
.Sh DESCRIPTION .Sh DESCRIPTION
The The
.Nm tr .Nm
utility copies the standard input to the standard output with substitution utility copies the standard input to the standard output with substitution
or deletion of selected characters. or deletion of selected characters.
.Pp .Pp
@ -225,7 +225,7 @@ it's interpreted as a decimal value.
.El .El
.Pp .Pp
The The
.Nm tr .Nm
utility exits 0 on success, and >0 if an error occurs. utility exits 0 on success, and >0 if an error occurs.
.Sh EXAMPLES .Sh EXAMPLES
The following examples are shown as given to the shell: 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''. rewritten as ``a\e-z''.
.Pp .Pp
The The
.Nm tr .Nm
utility has historically not permitted the manipulation of NUL bytes in utility has historically not permitted the manipulation of NUL bytes in
its input and, additionally, stripped NUL's from its input stream. its input and, additionally, stripped NUL's from its input stream.
This implementation has removed this behavior as a bug. This implementation has removed this behavior as a bug.
.Pp .Pp
The The
.Nm tr .Nm
utility has historically been extremely forgiving of syntax errors, utility has historically been extremely forgiving of syntax errors,
for example, the for example, the
.Fl c .Fl c
@ -277,7 +277,7 @@ options were ignored unless two strings were specified.
This implementation will not permit illegal syntax. This implementation will not permit illegal syntax.
.Sh STANDARDS .Sh STANDARDS
The The
.Nm tr .Nm
utility is expected to be utility is expected to be
.St -p1003.2 .St -p1003.2
compatible. compatible.

View File

@ -32,18 +32,23 @@
*/ */
#ifndef lint #ifndef lint
static char copyright[] = static const char copyright[] =
"@(#) Copyright (c) 1988, 1993\n\ "@(#) Copyright (c) 1988, 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
static char sccsid[] = "@(#)tr.c 8.2 (Berkeley) 5/4/95"; static char sccsid[] = "@(#)tr.c 8.2 (Berkeley) 5/4/95";
#endif
static const char rcsid[] =
"$Id$";
#endif /* not lint */ #endif /* not lint */
#include <locale.h> #include <locale.h>
#include <sys/types.h> #include <sys/types.h>
#include <err.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -202,7 +207,7 @@ main(argc, argv)
*p++ = OOBCH; *p++ = OOBCH;
if (!next(&s2)) if (!next(&s2))
err("empty string2"); errx(1, "empty string2");
/* If string2 runs out of characters, use the last one specified. */ /* If string2 runs out of characters, use the last one specified. */
if (sflag) if (sflag)
@ -256,38 +261,10 @@ setup(string, arg, str, cflag)
static void static void
usage() usage()
{ {
(void)fprintf(stderr, "usage: tr [-cs] string1 string2\n"); (void)fprintf(stderr, "%s\n%s\n%s\n%s\n",
(void)fprintf(stderr, " tr [-c] -d string1\n"); "usage: tr [-cs] string1 string2",
(void)fprintf(stderr, " tr [-c] -s string1\n"); " tr [-c] -d string1",
(void)fprintf(stderr, " tr [-c] -ds string1 string2\n"); " tr [-c] -s string1",
" tr [-c] -ds string1 string2");
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, "tr: ");
(void)vfprintf(stderr, fmt, ap);
va_end(ap);
(void)fprintf(stderr, "\n");
exit(1);
/* NOTREACHED */
}