From: Eric S. Raymond Date: Mon, 3 Dec 2012 22:06:43 +0000 (-0500) Subject: Magic number elimination. X-Git-Tag: 1.8~3 X-Git-Url: http://thyrsus.com/gitweb/?a=commitdiff_plain;h=d722dbc976d0a0b967a163ee661d015b165b145a;p=hexdump.git Magic number elimination. --- diff --git a/hexdump.c b/hexdump.c index 4732ef9..3dfe3ba 100644 --- a/hexdump.c +++ b/hexdump.c @@ -11,8 +11,10 @@ hexdump.c -- generate CP/M style hex dumps #include #include -#define DEFWIDTH 16 /* Default # chars to show per line */ -#define MAXWIDTH 128 /* Maximum # of bytes per line */ +#define DEFWIDTH 16 /* Default # chars to show per line */ +#define MAXWIDTH 128 /* Maximum # of bytes per line */ +#define HEXPERBYTE 3 /* Two hex characters plus space */ +#define HEXOVERHEAD 7 /* fixed overhead per line of hex */ static long linebytes = DEFWIDTH; /* # of bytes to print per line */ static bool eflag = false; /* display ebcdic if true */ @@ -109,7 +111,7 @@ static void dumpfile(FILE *f) /* update counters and things */ ai++; - hpos += 3; + hpos += HEXPERBYTE; } /* At end-of-line or EOF, show ASCII or EBCDIC version of data. */ @@ -117,7 +119,7 @@ static void dumpfile(FILE *f) { if (!cflag) { - while (hpos < linebytes * 3 + 7) + while (hpos < linebytes * HEXPERBYTE + HEXOVERHEAD) { hpos++; (void) putchar(' ');