Use err(3) instead of local redefinition, incorporate `hd' in usage str.

This commit is contained in:
Philippe Charnier 1997-07-10 06:48:24 +00:00
parent c851008590
commit 1073170298
6 changed files with 48 additions and 58 deletions

View File

@ -32,18 +32,22 @@
*/
#ifndef lint
#if 0
static char sccsid[] = "@(#)display.c 8.1 (Berkeley) 6/6/93";
#endif
static const char rcsid[] =
"$Id$";
#endif /* not lint */
#include <sys/param.h>
#include <sys/stat.h>
#include <unistd.h>
#include <errno.h>
#include <ctype.h>
#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "hexdump.h"
enum _vflag vflag = FIRST;
@ -263,8 +267,7 @@ get()
length == -1 ? need : MIN(length, need), stdin);
if (!n) {
if (ferror(stdin))
(void)fprintf(stderr, "hexdump: %s: %s\n",
_argv[-1], strerror(errno));
warn("%s", _argv[-1]);
ateof = 1;
continue;
}
@ -307,8 +310,7 @@ next(argv)
for (;;) {
if (*_argv) {
if (!(freopen(*_argv, "r", stdin))) {
(void)fprintf(stderr, "hexdump: %s: %s\n",
*_argv, strerror(errno));
warn("%s", *_argv);
exitval = 1;
++_argv;
continue;
@ -339,7 +341,7 @@ doskip(fname, statok)
if (statok) {
if (fstat(fileno(stdin), &sb))
err("%s: %s", fname, strerror(errno));
err(1, "%s", fname);
if (S_ISREG(sb.st_mode) && skip >= sb.st_size) {
address += sb.st_size;
skip -= sb.st_size;
@ -348,7 +350,7 @@ doskip(fname, statok)
}
if (S_ISREG(sb.st_mode)) {
if (fseek(stdin, skip, SEEK_SET))
err("%s: %s", fname, strerror(errno));
err(1, "%s", fname);
address += skip;
skip = 0;
} else {
@ -375,5 +377,5 @@ emalloc(size)
void
nomem()
{
err("%s", strerror(errno));
err(1, NULL);
}

View File

@ -32,18 +32,21 @@
*/
#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[] = "@(#)hexdump.c 8.1 (Berkeley) 6/6/93";
#endif
static const char rcsid[] =
"$Id$";
#endif /* not lint */
#include <sys/types.h>
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@ -81,32 +84,3 @@ main(argc, argv)
display();
exit(exitval);
}
#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, "hexdump: ");
(void)vfprintf(stderr, fmt, ap);
va_end(ap);
(void)fprintf(stderr, "\n");
exit(1);
/* NOTREACHED */
}

View File

@ -85,7 +85,6 @@ void conv_c __P((PR *, u_char *));
void conv_u __P((PR *, u_char *));
void display __P((void));
void doskip __P((char *, int));
void err __P((const char *, ...));
void *emalloc __P((int));
void escape __P((char *));
u_char *get __P((void));

View File

@ -32,11 +32,16 @@
*/
#ifndef lint
#if 0
static char sccsid[] = "@(#)hexsyntax.c 8.2 (Berkeley) 5/4/95";
#endif
static const char rcsid[] =
"$Id$";
#endif /* not lint */
#include <sys/types.h>
#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -92,7 +97,7 @@ newsyntax(argc, argvp)
break;
case 'n':
if ((length = atoi(optarg)) < 0)
err("%s: bad length value", optarg);
errx(1, "%s: bad length value", optarg);
break;
case 'o':
add("\"%07.7_Ax\n\"");
@ -100,7 +105,7 @@ newsyntax(argc, argvp)
break;
case 's':
if ((skip = strtol(optarg, &p, 0)) < 0)
err("%s: bad skip value", optarg);
errx(1, "%s: bad skip value", optarg);
switch(*p) {
case 'b':
skip *= 512;
@ -135,7 +140,10 @@ newsyntax(argc, argvp)
void
usage()
{
(void)fprintf(stderr,
"hexdump: [-bcCdovx] [-e fmt] [-f fmt_file] [-n length] [-s skip] [file ...]\n");
(void)fprintf(stderr, "%s\n%s\n%s\n%s\n",
"usage: hexdump [-bcCdovx] [-e fmt] [-f fmt_file] [-n length]",
" [-s skip] [file ...]",
" hd [-bcdovx] [-e fmt] [-f fmt_file] [-n length]",
" [-s skip] [file ...]");
exit(1);
}

View File

@ -32,12 +32,17 @@
*/
#ifndef lint
#if 0
static char sccsid[] = "@(#)odsyntax.c 8.2 (Berkeley) 5/4/95";
#endif
static const char rcsid[] =
"$Id$";
#endif /* not lint */
#include <sys/types.h>
#include <ctype.h>
#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
@ -131,12 +136,10 @@ oldsyntax(argc, argvp)
case 'w':
case '?':
default:
(void)fprintf(stderr,
"od: od(1) has been deprecated for hexdump(1).\n");
warnx("od(1) has been deprecated for hexdump(1)");
if (ch != '?')
(void)fprintf(stderr,
"od: hexdump(1) compatibility doesn't support the -%c option%s\n",
ch, ch == 's' ? "; see strings(1)." : ".");
warnx("hexdump(1) compatibility doesn't support the -%c option%s",
ch, ch == 's' ? "; see strings(1)" : "");
usage();
}

View File

@ -32,12 +32,16 @@
*/
#ifndef lint
#if 0
static char sccsid[] = "@(#)parse.c 8.1 (Berkeley) 6/6/93";
#endif
static const char rcsid[] =
"$Id$";
#endif /* not lint */
#include <sys/types.h>
#include <errno.h>
#include <err.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
@ -57,10 +61,10 @@ addfile(name)
char buf[2048 + 1];
if ((fp = fopen(name, "r")) == NULL)
err("%s: %s\n", name, strerror(errno));
err(1, "%s", name);
while (fgets(buf, sizeof(buf), fp)) {
if (!(p = index(buf, '\n'))) {
(void)fprintf(stderr, "hexdump: line too long.\n");
warnx("line too long");
while ((ch = getchar()) != '\n' && ch != EOF);
continue;
}
@ -391,7 +395,7 @@ isint2: switch(fu->bcnt) {
/* Only one conversion character if byte count. */
if (!(pr->flags&F_ADDRESS) && fu->bcnt && nconv++)
err("byte count with multiple conversion characters");
errx(1, "byte count with multiple conversion characters");
}
/*
* If format unit byte count not specified, figure it out
@ -483,25 +487,25 @@ void
badcnt(s)
char *s;
{
err("%s: bad byte count", s);
errx(1, "%s: bad byte count", s);
}
void
badsfmt()
{
err("%%s: requires a precision or a byte count\n");
errx(1, "%%s: requires a precision or a byte count");
}
void
badfmt(fmt)
char *fmt;
{
err("\"%s\": bad format\n", fmt);
errx(1, "\"%s\": bad format", fmt);
}
void
badconv(ch)
char *ch;
{
err("%%%s: bad conversion character\n", ch);
errx(1, "%%%s: bad conversion character", ch);
}