xref: /csrg-svn/usr.bin/hexdump/hexdump.c (revision 62031)
138857Sbostic /*
2*62031Sbostic  * Copyright (c) 1989, 1993
3*62031Sbostic  *	The Regents of the University of California.  All rights reserved.
438857Sbostic  *
542734Sbostic  * %sccs.include.redist.c%
638857Sbostic  */
738857Sbostic 
838857Sbostic #ifndef lint
9*62031Sbostic static char copyright[] =
10*62031Sbostic "@(#) Copyright (c) 1989, 1993\n\
11*62031Sbostic 	The Regents of the University of California.  All rights reserved.\n";
1238857Sbostic #endif /* not lint */
1338857Sbostic 
1438857Sbostic #ifndef lint
15*62031Sbostic static char sccsid[] = "@(#)hexdump.c	8.1 (Berkeley) 06/06/93";
1638857Sbostic #endif /* not lint */
1738857Sbostic 
1838857Sbostic #include <sys/types.h>
1955201Sbostic 
2055201Sbostic #include <errno.h>
2155201Sbostic #include <stdlib.h>
2238857Sbostic #include <stdio.h>
2355201Sbostic #include <string.h>
2438857Sbostic #include "hexdump.h"
2538857Sbostic 
2638857Sbostic FS *fshead;				/* head of format strings */
2738857Sbostic int blocksize;				/* data block size */
2838857Sbostic int exitval;				/* final exit value */
2941455Sbostic int length = -1;			/* max bytes to read */
3038857Sbostic 
3155201Sbostic int
main(argc,argv)3238857Sbostic main(argc, argv)
3338857Sbostic 	int argc;
3455201Sbostic 	char *argv[];
3538857Sbostic {
3638857Sbostic 	register FS *tfs;
3755201Sbostic 	char *p;
3838857Sbostic 
3941455Sbostic 	if (!(p = rindex(argv[0], 'o')) || strcmp(p, "od"))
4041455Sbostic 		newsyntax(argc, &argv);
4141455Sbostic 	else
4241455Sbostic 		oldsyntax(argc, &argv);
4338857Sbostic 
4438857Sbostic 	/* figure out the data block size */
4538857Sbostic 	for (blocksize = 0, tfs = fshead; tfs; tfs = tfs->nextfs) {
4638857Sbostic 		tfs->bcnt = size(tfs);
4738857Sbostic 		if (blocksize < tfs->bcnt)
4838857Sbostic 			blocksize = tfs->bcnt;
4938857Sbostic 	}
5038857Sbostic 	/* rewrite the rules, do syntax checking */
5138857Sbostic 	for (tfs = fshead; tfs; tfs = tfs->nextfs)
5238857Sbostic 		rewrite(tfs);
5338857Sbostic 
5438857Sbostic 	(void)next(argv);
5538857Sbostic 	display();
5638857Sbostic 	exit(exitval);
5738857Sbostic }
5855201Sbostic 
5955201Sbostic #if __STDC__
6055201Sbostic #include <stdarg.h>
6155201Sbostic #else
6255201Sbostic #include <varargs.h>
6355201Sbostic #endif
6455201Sbostic 
6555201Sbostic void
6655201Sbostic #if __STDC__
err(const char * fmt,...)6755201Sbostic err(const char *fmt, ...)
6855201Sbostic #else
6955201Sbostic err(fmt, va_alist)
7055201Sbostic 	char *fmt;
7155201Sbostic         va_dcl
7255201Sbostic #endif
7355201Sbostic {
7455201Sbostic 	va_list ap;
7555201Sbostic #if __STDC__
7655201Sbostic 	va_start(ap, fmt);
7755201Sbostic #else
7855201Sbostic 	va_start(ap);
7955201Sbostic #endif
8055201Sbostic 	(void)fprintf(stderr, "hexdump: ");
8155201Sbostic 	(void)vfprintf(stderr, fmt, ap);
8255201Sbostic 	va_end(ap);
8355201Sbostic 	(void)fprintf(stderr, "\n");
8455201Sbostic 	exit(1);
8555201Sbostic 	/* NOTREACHED */
8655201Sbostic }
87