diff options
author | Michael Shalayeff <mickey@cvs.openbsd.org> | 2001-11-02 19:41:07 +0000 |
---|---|---|
committer | Michael Shalayeff <mickey@cvs.openbsd.org> | 2001-11-02 19:41:07 +0000 |
commit | 3b7d55a85ac35adb10d6980e2b01aa24853c29c7 (patch) | |
tree | 03a9df0116c7d0a2252f83f0956f11f6b3b29133 /usr.bin/hexdump | |
parent | ef2ab22bf582092e9e71bf271565532885ba7750 (diff) |
replace fprintf(stderr)/exit w/ err/warn
Diffstat (limited to 'usr.bin/hexdump')
-rw-r--r-- | usr.bin/hexdump/display.c | 34 | ||||
-rw-r--r-- | usr.bin/hexdump/hexsyntax.c | 24 | ||||
-rw-r--r-- | usr.bin/hexdump/odsyntax.c | 14 | ||||
-rw-r--r-- | usr.bin/hexdump/parse.c | 99 |
4 files changed, 59 insertions, 112 deletions
diff --git a/usr.bin/hexdump/display.c b/usr.bin/hexdump/display.c index 9584ee59dc1..ff65a421bfd 100644 --- a/usr.bin/hexdump/display.c +++ b/usr.bin/hexdump/display.c @@ -1,4 +1,4 @@ -/* $OpenBSD: display.c,v 1.6 2001/07/12 05:17:10 deraadt Exp $ */ +/* $OpenBSD: display.c,v 1.7 2001/11/02 19:41:06 mickey Exp $ */ /* * Copyright (c) 1989 The Regents of the University of California. @@ -35,7 +35,7 @@ #ifndef lint /*static char sccsid[] = "from: @(#)display.c 5.11 (Berkeley) 3/9/91";*/ -static char rcsid[] = "$OpenBSD: display.c,v 1.6 2001/07/12 05:17:10 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: display.c,v 1.7 2001/11/02 19:41:06 mickey Exp $"; #endif /* not lint */ #include <sys/param.h> @@ -46,6 +46,7 @@ static char rcsid[] = "$OpenBSD: display.c,v 1.6 2001/07/12 05:17:10 deraadt Exp #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <err.h> #include "hexdump.h" enum _vflag vflag = FIRST; @@ -255,8 +256,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; } @@ -299,8 +299,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; @@ -329,22 +328,16 @@ doskip(fname, statok) struct stat sbuf; if (statok) { - if (fstat(fileno(stdin), &sbuf)) { - (void)fprintf(stderr, "hexdump: %s: %s.\n", - fname, strerror(errno)); - exit(1); - } + if (fstat(fileno(stdin), &sbuf)) + err(1, "%s", fname); if (skip >= sbuf.st_size) { skip -= sbuf.st_size; address += sbuf.st_size; return; } } - if (fseek(stdin, skip, SEEK_SET)) { - (void)fprintf(stderr, "hexdump: %s: %s.\n", - fname, strerror(errno)); - exit(1); - } + if (fseek(stdin, skip, SEEK_SET)) + err(1, "%s", fname); savaddress = address += skip; skip = 0; } @@ -356,14 +349,7 @@ emalloc(size) char *p; if (!(p = malloc((u_int)size))) - nomem(); + err(1, "malloc"); bzero(p, size); return(p); } - -void -nomem() -{ - (void)fprintf(stderr, "hexdump: %s.\n", strerror(errno)); - exit(1); -} diff --git a/usr.bin/hexdump/hexsyntax.c b/usr.bin/hexdump/hexsyntax.c index 000f3161ca9..c77bf7f8c8a 100644 --- a/usr.bin/hexdump/hexsyntax.c +++ b/usr.bin/hexdump/hexsyntax.c @@ -1,4 +1,4 @@ -/* $OpenBSD: hexsyntax.c,v 1.4 2001/07/12 05:17:10 deraadt Exp $ */ +/* $OpenBSD: hexsyntax.c,v 1.5 2001/11/02 19:41:06 mickey Exp $ */ /*- * Copyright (c) 1990 The Regents of the University of California. @@ -35,7 +35,7 @@ #ifndef lint /*static char sccsid[] = "from: @(#)hexsyntax.c 5.2 (Berkeley) 5/8/90";*/ -static char rcsid[] = "$OpenBSD: hexsyntax.c,v 1.4 2001/07/12 05:17:10 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: hexsyntax.c,v 1.5 2001/11/02 19:41:06 mickey Exp $"; #endif /* not lint */ #include <sys/types.h> @@ -43,6 +43,7 @@ static char rcsid[] = "$OpenBSD: hexsyntax.c,v 1.4 2001/07/12 05:17:10 deraadt E #include <stdlib.h> #include <limits.h> #include <unistd.h> +#include <err.h> #include "hexdump.h" off_t skip; /* bytes to skip */ @@ -81,22 +82,16 @@ newsyntax(argc, argvp) addfile(optarg); break; case 'n': - if ((length = atoi(optarg)) < 0) { - (void)fprintf(stderr, - "hexdump: bad length value.\n"); - exit(1); - } + if ((length = atoi(optarg)) < 0) + errx(1, "bad length value"); break; case 'o': add("\"%07.7_Ax\n\""); add("\"%07.7_ax \" 8/2 \" %06o \" \"\\n\""); break; case 's': - if ((skip = strtol(optarg, &p, 0)) < 0) { - (void)fprintf(stderr, - "hexdump: bad skip value.\n"); - exit(1); - } + if ((skip = strtol(optarg, &p, 0)) < 0) + errx(1, "bad skip value"); switch(*p) { case 'b': skip *= 512; @@ -132,7 +127,8 @@ newsyntax(argc, argvp) void usage() { - (void)fprintf(stderr, -"hexdump: [-bcdovx] [-e fmt] [-f fmt_file] [-n length] [-s skip] [file ...]\n"); + extern char *__progname; + fprintf(stderr, "usage: %s [-bcdovx] [-e fmt] [-f fmt_file] " + "[-n length] [-s skip] [file ...]", __progname); exit(1); } diff --git a/usr.bin/hexdump/odsyntax.c b/usr.bin/hexdump/odsyntax.c index ae38ff61e1b..738962dfc29 100644 --- a/usr.bin/hexdump/odsyntax.c +++ b/usr.bin/hexdump/odsyntax.c @@ -1,4 +1,4 @@ -/* $OpenBSD: odsyntax.c,v 1.6 2001/09/30 07:17:03 pvalchev Exp $ */ +/* $OpenBSD: odsyntax.c,v 1.7 2001/11/02 19:41:06 mickey Exp $ */ /*- * Copyright (c) 1990 The Regents of the University of California. @@ -35,13 +35,14 @@ #ifndef lint /*static char sccsid[] = "from: @(#)odsyntax.c 5.4 (Berkeley) 3/8/91";*/ -static char rcsid[] = "$OpenBSD: odsyntax.c,v 1.6 2001/09/30 07:17:03 pvalchev Exp $"; +static char rcsid[] = "$OpenBSD: odsyntax.c,v 1.7 2001/11/02 19:41:06 mickey Exp $"; #endif /* not lint */ #include <sys/types.h> #include <stdlib.h> -#include <ctype.h> #include <stdio.h> +#include <ctype.h> +#include <err.h> #include "hexdump.h" int deprecated; @@ -131,11 +132,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", + warnx("hexdump(1) compatibility doesn't" + "support the -%c option%s", ch, ch == 's' ? "; see strings(1)." : "."); usage(); } diff --git a/usr.bin/hexdump/parse.c b/usr.bin/hexdump/parse.c index db8b6ed7d76..b512e5fadc8 100644 --- a/usr.bin/hexdump/parse.c +++ b/usr.bin/hexdump/parse.c @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.c,v 1.6 2001/09/30 07:17:03 pvalchev Exp $ */ +/* $OpenBSD: parse.c,v 1.7 2001/11/02 19:41:06 mickey Exp $ */ /* * Copyright (c) 1989 The Regents of the University of California. @@ -35,7 +35,7 @@ #ifndef lint /*static char sccsid[] = "from: @(#)parse.c 5.6 (Berkeley) 3/9/91";*/ -static char rcsid[] = "$OpenBSD: parse.c,v 1.6 2001/09/30 07:17:03 pvalchev Exp $"; +static char rcsid[] = "$OpenBSD: parse.c,v 1.7 2001/11/02 19:41:06 mickey Exp $"; #endif /* not lint */ #include <sys/types.h> @@ -44,8 +44,15 @@ static char rcsid[] = "$OpenBSD: parse.c,v 1.6 2001/09/30 07:17:03 pvalchev Exp #include <stdlib.h> #include <ctype.h> #include <string.h> +#include <err.h> #include "hexdump.h" +void addfile __P((char *)); +void add __P((char *)); +int size __P((FS *)); +void rewrite __P((FS *)); +void escape __P((char *)); + FU *endfu; /* format at end-of-data */ void @@ -56,15 +63,13 @@ addfile(name) FILE *fp; size_t len; - if (!(fp = fopen(name, "r"))) { - (void)fprintf(stderr, "hexdump: can't read %s.\n", name); - exit(1); - } + if (!(fp = fopen(name, "r"))) + err(1, "%s", name); while ((p = fgetln(fp, &len))) { if (*(p + len - 1) == '\n') *(p + len - 1) = '\0'; else { - (void)fprintf(stderr, "hexdump: incomplete line.\n"); + warnx("incomplete line"); continue; } for (; *p && isspace(*p); ++p); @@ -113,7 +118,7 @@ add(fmt) if (isdigit(*p)) { for (savep = p; isdigit(*p); ++p); if (!isspace(*p) && *p != '/') - badfmt(fmt); + errx(1, "bad format {%s}", fmt); /* may overwrite either white space or slash */ tfu->reps = atoi(savep); tfu->flags = F_SETREP; @@ -129,7 +134,7 @@ add(fmt) if (isdigit(*p)) { for (savep = p; isdigit(*p); ++p); if (!isspace(*p)) - badfmt(fmt); + errx(1, "bad format {%s}", fmt); tfu->bcnt = atoi(savep); /* skip trailing white space */ for (++p; isspace(*p); ++p); @@ -137,12 +142,12 @@ add(fmt) /* format */ if (*p != '"') - badfmt(fmt); + errx(1, "bad format {%s}", fmt); for (savep = ++p; *p != '"';) if (*p++ == 0) - badfmt(fmt); + errx(1, "bad format {%s}", fmt); if (!(tfu->fmt = malloc(p - savep + 1))) - nomem(); + err(1, "malloc"); (void) strncpy(tfu->fmt, savep, p - savep); tfu->fmt[p - savep] = '\0'; escape(tfu->fmt); @@ -150,10 +155,10 @@ add(fmt) } /* no single fu in fmt */ if (tfs->nextfu == NULL) - badfmt(fmt); + errx(1, "bad format {%s}", fmt); } -static char *spec = ".#-+ 0123456789"; +static const char *spec = ".#-+ 0123456789"; int size(fs) FS *fs; @@ -277,8 +282,7 @@ rewrite(fs) pr->bcnt = 1; break; default: - p1[1] = '\0'; - badcnt(p1); + errx(1, "bad byte count for conversion character \'%c\'", *p1); } break; case 'd': case 'i': @@ -297,7 +301,7 @@ rewrite(fs) goto sw1; default: p1[2] = '\0'; - badconv(p1); + errx(1, "bad conversion character %%%s", p1); } /* NOTREACHED */ case 'o': case 'u': case 'x': case 'X': @@ -313,8 +317,7 @@ sw1: switch(fu->bcnt) { pr->bcnt = 2; break; default: - p1[1] = '\0'; - badcnt(p1); + errx(1, "bad byte count for conversion character \'%c\'", *p1); } break; case 'e': case 'E': case 'f': case 'g': case 'G': @@ -327,15 +330,14 @@ sw1: switch(fu->bcnt) { pr->bcnt = 4; break; default: - p1[1] = '\0'; - badcnt(p1); + errx(1, "bad byte count for conversion character \'%c\'", *p1); } break; case 's': pr->flags = F_STR; switch(sokay) { case NOTOKAY: - badsfmt(); + errx(1, "%%s requires a precision or a byte count"); case USEBCNT: pr->bcnt = fu->bcnt; break; @@ -361,7 +363,7 @@ sw1: switch(fu->bcnt) { break; default: p1[3] = '\0'; - badconv(p1); + errx(1, "bad conversion character %%%s", p1); } break; case 'c': @@ -381,17 +383,16 @@ sw2: switch(fu->bcnt) { break; default: p1[2] = '\0'; - badcnt(p1); + errx(1, "bad byte count for conversion character \'%s\'", p1); } break; default: p1[2] = '\0'; - badconv(p1); + errx(1, "bad conversion character %%%s", p1); } break; default: - p1[1] = '\0'; - badconv(p1); + errx(1, "bad conversion character %%%c", *p1); } /* @@ -401,17 +402,15 @@ sw2: switch(fu->bcnt) { savech = *p2; p1[(pr->flags&F_ADDRESS)?2:1] = '\0'; if (!(pr->fmt = strdup(fmtp))) - nomem(); + err(1, "malloc"); *p2 = savech; pr->cchar = pr->fmt + (p1 - fmtp); fmtp = p2; /* only one conversion character if byte count */ - if (!(pr->flags&F_ADDRESS) && fu->bcnt && nconv++) { - (void)fprintf(stderr, - "hexdump: byte count with multiple conversion characters.\n"); - exit(1); - } + if (!(pr->flags&F_ADDRESS) && fu->bcnt && nconv++) + errx(1, + "byte count with multiple conversion characters"); } /* * if format unit byte count not specified, figure it out @@ -448,7 +447,6 @@ sw2: switch(fu->bcnt) { } } - void escape(p1) register char *p1; @@ -491,36 +489,3 @@ escape(p1) } } } - -void -badcnt(s) - char *s; -{ - (void)fprintf(stderr, - "hexdump: bad byte count for conversion character %s.\n", s); - exit(1); -} - -void -badsfmt() -{ - (void)fprintf(stderr, - "hexdump: %%s requires a precision or a byte count.\n"); - exit(1); -} - -void -badfmt(fmt) - char *fmt; -{ - (void)fprintf(stderr, "hexdump: bad format {%s}\n", fmt); - exit(1); -} - -void -badconv(ch) - char *ch; -{ - (void)fprintf(stderr, "hexdump: bad conversion character %%%s.\n", ch); - exit(1); -} |