xref: /csrg-svn/usr.bin/hexdump/hexdump.c (revision 41455)
138857Sbostic /*
238857Sbostic  * Copyright (c) 1989 The Regents of the University of California.
338857Sbostic  * All rights reserved.
438857Sbostic  *
538857Sbostic  * Redistribution and use in source and binary forms are permitted
638857Sbostic  * provided that the above copyright notice and this paragraph are
738857Sbostic  * duplicated in all such forms and that any documentation,
838857Sbostic  * advertising materials, and other materials related to such
938857Sbostic  * distribution and use acknowledge that the software was developed
1038857Sbostic  * by the University of California, Berkeley.  The name of the
1138857Sbostic  * University may not be used to endorse or promote products derived
1238857Sbostic  * from this software without specific prior written permission.
1338857Sbostic  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
1438857Sbostic  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
1538857Sbostic  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
1638857Sbostic  */
1738857Sbostic 
1838857Sbostic #ifndef lint
1938857Sbostic char copyright[] =
2038857Sbostic "@(#) Copyright (c) 1989 The Regents of the University of California.\n\
2138857Sbostic  All rights reserved.\n";
2238857Sbostic #endif /* not lint */
2338857Sbostic 
2438857Sbostic #ifndef lint
25*41455Sbostic static char sccsid[] = "@(#)hexdump.c	5.4 (Berkeley) 05/08/90";
2638857Sbostic #endif /* not lint */
2738857Sbostic 
2838857Sbostic #include <sys/types.h>
2938857Sbostic #include <stdio.h>
3038857Sbostic #include "hexdump.h"
3138857Sbostic 
3238857Sbostic FS *fshead;				/* head of format strings */
3338857Sbostic int blocksize;				/* data block size */
3438857Sbostic int exitval;				/* final exit value */
35*41455Sbostic int length = -1;			/* max bytes to read */
3638857Sbostic 
3738857Sbostic main(argc, argv)
3838857Sbostic 	int argc;
3938857Sbostic 	char **argv;
4038857Sbostic {
41*41455Sbostic 	extern int errno;
4238857Sbostic 	register FS *tfs;
4338857Sbostic 	char *p, *rindex();
4438857Sbostic 
45*41455Sbostic 	if (!(p = rindex(argv[0], 'o')) || strcmp(p, "od"))
46*41455Sbostic 		newsyntax(argc, &argv);
47*41455Sbostic 	else
48*41455Sbostic 		oldsyntax(argc, &argv);
4938857Sbostic 
5038857Sbostic 	/* figure out the data block size */
5138857Sbostic 	for (blocksize = 0, tfs = fshead; tfs; tfs = tfs->nextfs) {
5238857Sbostic 		tfs->bcnt = size(tfs);
5338857Sbostic 		if (blocksize < tfs->bcnt)
5438857Sbostic 			blocksize = tfs->bcnt;
5538857Sbostic 	}
5638857Sbostic 	/* rewrite the rules, do syntax checking */
5738857Sbostic 	for (tfs = fshead; tfs; tfs = tfs->nextfs)
5838857Sbostic 		rewrite(tfs);
5938857Sbostic 
6038857Sbostic 	(void)next(argv);
6138857Sbostic 	display();
6238857Sbostic 	exit(exitval);
6338857Sbostic }
64