Use err(3) instead of local redefinition, incorporate `hd' in usage str.
This commit is contained in:
parent
c851008590
commit
1073170298
@ -32,18 +32,22 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef lint
|
#ifndef lint
|
||||||
|
#if 0
|
||||||
static char sccsid[] = "@(#)display.c 8.1 (Berkeley) 6/6/93";
|
static char sccsid[] = "@(#)display.c 8.1 (Berkeley) 6/6/93";
|
||||||
|
#endif
|
||||||
|
static const char rcsid[] =
|
||||||
|
"$Id$";
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include <err.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
#include "hexdump.h"
|
#include "hexdump.h"
|
||||||
|
|
||||||
enum _vflag vflag = FIRST;
|
enum _vflag vflag = FIRST;
|
||||||
@ -263,8 +267,7 @@ get()
|
|||||||
length == -1 ? need : MIN(length, need), stdin);
|
length == -1 ? need : MIN(length, need), stdin);
|
||||||
if (!n) {
|
if (!n) {
|
||||||
if (ferror(stdin))
|
if (ferror(stdin))
|
||||||
(void)fprintf(stderr, "hexdump: %s: %s\n",
|
warn("%s", _argv[-1]);
|
||||||
_argv[-1], strerror(errno));
|
|
||||||
ateof = 1;
|
ateof = 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -307,8 +310,7 @@ next(argv)
|
|||||||
for (;;) {
|
for (;;) {
|
||||||
if (*_argv) {
|
if (*_argv) {
|
||||||
if (!(freopen(*_argv, "r", stdin))) {
|
if (!(freopen(*_argv, "r", stdin))) {
|
||||||
(void)fprintf(stderr, "hexdump: %s: %s\n",
|
warn("%s", *_argv);
|
||||||
*_argv, strerror(errno));
|
|
||||||
exitval = 1;
|
exitval = 1;
|
||||||
++_argv;
|
++_argv;
|
||||||
continue;
|
continue;
|
||||||
@ -339,7 +341,7 @@ doskip(fname, statok)
|
|||||||
|
|
||||||
if (statok) {
|
if (statok) {
|
||||||
if (fstat(fileno(stdin), &sb))
|
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) {
|
if (S_ISREG(sb.st_mode) && skip >= sb.st_size) {
|
||||||
address += sb.st_size;
|
address += sb.st_size;
|
||||||
skip -= sb.st_size;
|
skip -= sb.st_size;
|
||||||
@ -348,7 +350,7 @@ doskip(fname, statok)
|
|||||||
}
|
}
|
||||||
if (S_ISREG(sb.st_mode)) {
|
if (S_ISREG(sb.st_mode)) {
|
||||||
if (fseek(stdin, skip, SEEK_SET))
|
if (fseek(stdin, skip, SEEK_SET))
|
||||||
err("%s: %s", fname, strerror(errno));
|
err(1, "%s", fname);
|
||||||
address += skip;
|
address += skip;
|
||||||
skip = 0;
|
skip = 0;
|
||||||
} else {
|
} else {
|
||||||
@ -375,5 +377,5 @@ emalloc(size)
|
|||||||
void
|
void
|
||||||
nomem()
|
nomem()
|
||||||
{
|
{
|
||||||
err("%s", strerror(errno));
|
err(1, NULL);
|
||||||
}
|
}
|
||||||
|
@ -32,18 +32,21 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef lint
|
#ifndef lint
|
||||||
static char copyright[] =
|
static const char 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
|
||||||
static char sccsid[] = "@(#)hexdump.c 8.1 (Berkeley) 6/6/93";
|
static char sccsid[] = "@(#)hexdump.c 8.1 (Berkeley) 6/6/93";
|
||||||
|
#endif
|
||||||
|
static const char rcsid[] =
|
||||||
|
"$Id$";
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <errno.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -81,32 +84,3 @@ main(argc, argv)
|
|||||||
display();
|
display();
|
||||||
exit(exitval);
|
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 */
|
|
||||||
}
|
|
||||||
|
@ -85,7 +85,6 @@ void conv_c __P((PR *, u_char *));
|
|||||||
void conv_u __P((PR *, u_char *));
|
void conv_u __P((PR *, u_char *));
|
||||||
void display __P((void));
|
void display __P((void));
|
||||||
void doskip __P((char *, int));
|
void doskip __P((char *, int));
|
||||||
void err __P((const char *, ...));
|
|
||||||
void *emalloc __P((int));
|
void *emalloc __P((int));
|
||||||
void escape __P((char *));
|
void escape __P((char *));
|
||||||
u_char *get __P((void));
|
u_char *get __P((void));
|
||||||
|
@ -32,11 +32,16 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef lint
|
#ifndef lint
|
||||||
|
#if 0
|
||||||
static char sccsid[] = "@(#)hexsyntax.c 8.2 (Berkeley) 5/4/95";
|
static char sccsid[] = "@(#)hexsyntax.c 8.2 (Berkeley) 5/4/95";
|
||||||
|
#endif
|
||||||
|
static const char rcsid[] =
|
||||||
|
"$Id$";
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
#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>
|
||||||
@ -92,7 +97,7 @@ newsyntax(argc, argvp)
|
|||||||
break;
|
break;
|
||||||
case 'n':
|
case 'n':
|
||||||
if ((length = atoi(optarg)) < 0)
|
if ((length = atoi(optarg)) < 0)
|
||||||
err("%s: bad length value", optarg);
|
errx(1, "%s: bad length value", optarg);
|
||||||
break;
|
break;
|
||||||
case 'o':
|
case 'o':
|
||||||
add("\"%07.7_Ax\n\"");
|
add("\"%07.7_Ax\n\"");
|
||||||
@ -100,7 +105,7 @@ newsyntax(argc, argvp)
|
|||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
if ((skip = strtol(optarg, &p, 0)) < 0)
|
if ((skip = strtol(optarg, &p, 0)) < 0)
|
||||||
err("%s: bad skip value", optarg);
|
errx(1, "%s: bad skip value", optarg);
|
||||||
switch(*p) {
|
switch(*p) {
|
||||||
case 'b':
|
case 'b':
|
||||||
skip *= 512;
|
skip *= 512;
|
||||||
@ -135,7 +140,10 @@ newsyntax(argc, argvp)
|
|||||||
void
|
void
|
||||||
usage()
|
usage()
|
||||||
{
|
{
|
||||||
(void)fprintf(stderr,
|
(void)fprintf(stderr, "%s\n%s\n%s\n%s\n",
|
||||||
"hexdump: [-bcCdovx] [-e fmt] [-f fmt_file] [-n length] [-s skip] [file ...]\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);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
@ -32,12 +32,17 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef lint
|
#ifndef lint
|
||||||
|
#if 0
|
||||||
static char sccsid[] = "@(#)odsyntax.c 8.2 (Berkeley) 5/4/95";
|
static char sccsid[] = "@(#)odsyntax.c 8.2 (Berkeley) 5/4/95";
|
||||||
|
#endif
|
||||||
|
static const char rcsid[] =
|
||||||
|
"$Id$";
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include <err.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@ -131,12 +136,10 @@ oldsyntax(argc, argvp)
|
|||||||
case 'w':
|
case 'w':
|
||||||
case '?':
|
case '?':
|
||||||
default:
|
default:
|
||||||
(void)fprintf(stderr,
|
warnx("od(1) has been deprecated for hexdump(1)");
|
||||||
"od: od(1) has been deprecated for hexdump(1).\n");
|
|
||||||
if (ch != '?')
|
if (ch != '?')
|
||||||
(void)fprintf(stderr,
|
warnx("hexdump(1) compatibility doesn't support the -%c option%s",
|
||||||
"od: hexdump(1) compatibility doesn't support the -%c option%s\n",
|
ch, ch == 's' ? "; see strings(1)" : "");
|
||||||
ch, ch == 's' ? "; see strings(1)." : ".");
|
|
||||||
usage();
|
usage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,12 +32,16 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef lint
|
#ifndef lint
|
||||||
|
#if 0
|
||||||
static char sccsid[] = "@(#)parse.c 8.1 (Berkeley) 6/6/93";
|
static char sccsid[] = "@(#)parse.c 8.1 (Berkeley) 6/6/93";
|
||||||
|
#endif
|
||||||
|
static const char rcsid[] =
|
||||||
|
"$Id$";
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <errno.h>
|
#include <err.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -57,10 +61,10 @@ addfile(name)
|
|||||||
char buf[2048 + 1];
|
char buf[2048 + 1];
|
||||||
|
|
||||||
if ((fp = fopen(name, "r")) == NULL)
|
if ((fp = fopen(name, "r")) == NULL)
|
||||||
err("%s: %s\n", name, strerror(errno));
|
err(1, "%s", name);
|
||||||
while (fgets(buf, sizeof(buf), fp)) {
|
while (fgets(buf, sizeof(buf), fp)) {
|
||||||
if (!(p = index(buf, '\n'))) {
|
if (!(p = index(buf, '\n'))) {
|
||||||
(void)fprintf(stderr, "hexdump: line too long.\n");
|
warnx("line too long");
|
||||||
while ((ch = getchar()) != '\n' && ch != EOF);
|
while ((ch = getchar()) != '\n' && ch != EOF);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -391,7 +395,7 @@ isint2: switch(fu->bcnt) {
|
|||||||
|
|
||||||
/* Only one conversion character if byte count. */
|
/* Only one conversion character if byte count. */
|
||||||
if (!(pr->flags&F_ADDRESS) && fu->bcnt && nconv++)
|
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
|
* If format unit byte count not specified, figure it out
|
||||||
@ -483,25 +487,25 @@ void
|
|||||||
badcnt(s)
|
badcnt(s)
|
||||||
char *s;
|
char *s;
|
||||||
{
|
{
|
||||||
err("%s: bad byte count", s);
|
errx(1, "%s: bad byte count", s);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
badsfmt()
|
badsfmt()
|
||||||
{
|
{
|
||||||
err("%%s: requires a precision or a byte count\n");
|
errx(1, "%%s: requires a precision or a byte count");
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
badfmt(fmt)
|
badfmt(fmt)
|
||||||
char *fmt;
|
char *fmt;
|
||||||
{
|
{
|
||||||
err("\"%s\": bad format\n", fmt);
|
errx(1, "\"%s\": bad format", fmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
badconv(ch)
|
badconv(ch)
|
||||||
char *ch;
|
char *ch;
|
||||||
{
|
{
|
||||||
err("%%%s: bad conversion character\n", ch);
|
errx(1, "%%%s: bad conversion character", ch);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user