From 0938248f2468d054a0514c4055ac77e27e94049c Mon Sep 17 00:00:00 2001 From: Chris Pressey Date: Sat, 5 Feb 2005 01:05:12 +0000 Subject: [PATCH] Raise WARNS to 6: - Move the print() function above the display() function so that it can be inlined by the compiler. - Un-nest extern declarations; put them into the shared header file. - Initialize some local variables. --- usr.bin/hexdump/Makefile | 3 +- usr.bin/hexdump/display.c | 113 +++++++++++++++++++------------------- usr.bin/hexdump/hexdump.h | 4 +- usr.bin/hexdump/parse.c | 6 +- 4 files changed, 64 insertions(+), 62 deletions(-) diff --git a/usr.bin/hexdump/Makefile b/usr.bin/hexdump/Makefile index 3ea96520a8..4481f44410 100644 --- a/usr.bin/hexdump/Makefile +++ b/usr.bin/hexdump/Makefile @@ -1,8 +1,9 @@ # @(#)Makefile 8.1 (Berkeley) 6/6/93 # $FreeBSD: src/usr.bin/hexdump/Makefile,v 1.3.8.1 2001/04/25 11:29:22 ru Exp $ -# $DragonFly: src/usr.bin/hexdump/Makefile,v 1.2 2003/06/17 04:29:27 dillon Exp $ +# $DragonFly: src/usr.bin/hexdump/Makefile,v 1.3 2005/02/05 01:05:12 cpressey Exp $ PROG= hexdump +WARNS?= 6 SRCS= conv.c display.c hexdump.c hexsyntax.c odsyntax.c parse.c MAN= hexdump.1 od.1 MLINKS= hexdump.1 hd.1 diff --git a/usr.bin/hexdump/display.c b/usr.bin/hexdump/display.c index 8963b07dc6..82051c563a 100644 --- a/usr.bin/hexdump/display.c +++ b/usr.bin/hexdump/display.c @@ -32,7 +32,7 @@ * * @(#)display.c 8.1 (Berkeley) 6/6/93 * $FreeBSD: src/usr.bin/hexdump/display.c,v 1.4.2.2 2002/07/23 14:27:06 tjr Exp $ - * $DragonFly: src/usr.bin/hexdump/display.c,v 1.4 2004/08/30 18:06:49 eirikn Exp $ + * $DragonFly: src/usr.bin/hexdump/display.c,v 1.5 2005/02/05 01:05:12 cpressey Exp $ */ #include @@ -53,61 +53,6 @@ static off_t eaddress; /* end address */ static __inline void print(PR *, u_char *); -void -display(void) -{ - extern FU *endfu; - register FS *fs; - register FU *fu; - register PR *pr; - register int cnt; - register u_char *bp; - off_t saveaddress; - u_char savech, *savebp; - - while ((bp = get())) - for (fs = fshead, savebp = bp, saveaddress = address; fs; - fs = fs->nextfs, bp = savebp, address = saveaddress) - for (fu = fs->nextfu; fu; fu = fu->nextfu) { - if (fu->flags&F_IGNORE) - break; - for (cnt = fu->reps; cnt; --cnt) - for (pr = fu->nextpr; pr; address += pr->bcnt, - bp += pr->bcnt, pr = pr->nextpr) { - if (eaddress && address >= eaddress && - !(pr->flags & (F_TEXT|F_BPAD))) - bpad(pr); - if (cnt == 1 && pr->nospace) { - savech = *pr->nospace; - *pr->nospace = '\0'; - } - print(pr, bp); - if (cnt == 1 && pr->nospace) - *pr->nospace = savech; - } - } - if (endfu) { - /* - * If eaddress not set, error or file size was multiple of - * blocksize, and no partial block ever found. - */ - if (!eaddress) { - if (!address) - return; - eaddress = address; - } - for (pr = endfu->nextpr; pr; pr = pr->nextpr) - switch(pr->flags) { - case F_ADDRESS: - (void)printf(pr->fmt, (quad_t)eaddress); - break; - case F_TEXT: - (void)printf("%s", pr->fmt); - break; - } - } -} - static __inline void print(PR *pr, u_char *bp) { @@ -205,6 +150,61 @@ print(PR *pr, u_char *bp) } } +void +display(void) +{ + + FS *fs; + register FU *fu; + register PR *pr; + register int cnt; + register u_char *bp; + off_t saveaddress; + u_char savech = '\0', *savebp; + + while ((bp = get())) + for (fs = fshead, savebp = bp, saveaddress = address; fs; + fs = fs->nextfs, bp = savebp, address = saveaddress) + for (fu = fs->nextfu; fu; fu = fu->nextfu) { + if (fu->flags&F_IGNORE) + break; + for (cnt = fu->reps; cnt; --cnt) + for (pr = fu->nextpr; pr; address += pr->bcnt, + bp += pr->bcnt, pr = pr->nextpr) { + if (eaddress && address >= eaddress && + !(pr->flags & (F_TEXT|F_BPAD))) + bpad(pr); + if (cnt == 1 && pr->nospace) { + savech = *pr->nospace; + *pr->nospace = '\0'; + } + print(pr, bp); + if (cnt == 1 && pr->nospace) + *pr->nospace = savech; + } + } + if (endfu) { + /* + * If eaddress not set, error or file size was multiple of + * blocksize, and no partial block ever found. + */ + if (!eaddress) { + if (!address) + return; + eaddress = address; + } + for (pr = endfu->nextpr; pr; pr = pr->nextpr) + switch(pr->flags) { + case F_ADDRESS: + (void)printf(pr->fmt, (quad_t)eaddress); + break; + case F_TEXT: + (void)printf("%s", pr->fmt); + break; + } + } +} + void bpad(PR *pr) { @@ -303,7 +303,6 @@ get(void) int next(char **argv) { - extern int exitval; static int done; int statok; diff --git a/usr.bin/hexdump/hexdump.h b/usr.bin/hexdump/hexdump.h index 3ef73c7d94..9e6ea6f924 100644 --- a/usr.bin/hexdump/hexdump.h +++ b/usr.bin/hexdump/hexdump.h @@ -32,7 +32,7 @@ * * @(#)hexdump.h 8.1 (Berkeley) 6/6/93 * $FreeBSD: src/usr.bin/hexdump/hexdump.h,v 1.2.6.1 2002/07/23 14:27:06 tjr Exp $ - * $DragonFly: src/usr.bin/hexdump/hexdump.h,v 1.2 2003/06/17 04:29:27 dillon Exp $ + * $DragonFly: src/usr.bin/hexdump/hexdump.h,v 1.3 2005/02/05 01:05:12 cpressey Exp $ */ typedef struct _pr { @@ -79,6 +79,8 @@ extern int length; /* amount of data to read */ extern off_t skip; /* amount of data to skip at start */ enum _vflag { ALL, DUP, FIRST, WAIT }; /* -v values */ extern enum _vflag vflag; +extern FU *endfu; +extern int exitval; void add(const char *); void addfile(char *); diff --git a/usr.bin/hexdump/parse.c b/usr.bin/hexdump/parse.c index b15fde6824..6c4bb94a4e 100644 --- a/usr.bin/hexdump/parse.c +++ b/usr.bin/hexdump/parse.c @@ -32,7 +32,7 @@ * * @(#)parse.c 8.1 (Berkeley) 6/6/93 * $FreeBSD: src/usr.bin/hexdump/parse.c,v 1.4.2.1 2002/07/23 14:27:06 tjr Exp $ - * $DragonFly: src/usr.bin/hexdump/parse.c,v 1.4 2004/08/30 18:06:49 eirikn Exp $ + * $DragonFly: src/usr.bin/hexdump/parse.c,v 1.5 2005/02/05 01:05:12 cpressey Exp $ */ #include @@ -204,11 +204,11 @@ void rewrite(FS *fs) { enum { NOTOKAY, USEBCNT, USEPREC } sokay; - register PR *pr, **nextpr; + register PR *pr, **nextpr = NULL; register FU *fu; unsigned char *p1, *p2, *fmtp; char savech, cs[3]; - int nconv, prec; + int nconv, prec = 0; for (fu = fs->nextfu; fu; fu = fu->nextfu) { /* -- 2.41.0