xref: /original-bsd/usr.bin/hexdump/hexdump.c (revision d15729d4)
1 /*
2  * Copyright (c) 1989 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 #ifndef lint
9 char copyright[] =
10 "@(#) Copyright (c) 1989 The Regents of the University of California.\n\
11  All rights reserved.\n";
12 #endif /* not lint */
13 
14 #ifndef lint
15 static char sccsid[] = "@(#)hexdump.c	5.5 (Berkeley) 06/01/90";
16 #endif /* not lint */
17 
18 #include <sys/types.h>
19 #include <stdio.h>
20 #include "hexdump.h"
21 
22 FS *fshead;				/* head of format strings */
23 int blocksize;				/* data block size */
24 int exitval;				/* final exit value */
25 int length = -1;			/* max bytes to read */
26 
27 main(argc, argv)
28 	int argc;
29 	char **argv;
30 {
31 	extern int errno;
32 	register FS *tfs;
33 	char *p, *rindex();
34 
35 	if (!(p = rindex(argv[0], 'o')) || strcmp(p, "od"))
36 		newsyntax(argc, &argv);
37 	else
38 		oldsyntax(argc, &argv);
39 
40 	/* figure out the data block size */
41 	for (blocksize = 0, tfs = fshead; tfs; tfs = tfs->nextfs) {
42 		tfs->bcnt = size(tfs);
43 		if (blocksize < tfs->bcnt)
44 			blocksize = tfs->bcnt;
45 	}
46 	/* rewrite the rules, do syntax checking */
47 	for (tfs = fshead; tfs; tfs = tfs->nextfs)
48 		rewrite(tfs);
49 
50 	(void)next(argv);
51 	display();
52 	exit(exitval);
53 }
54