xref: /csrg-svn/usr.bin/hexdump/hexsyntax.c (revision 55201)
141456Sbostic /*-
241456Sbostic  * Copyright (c) 1990 The Regents of the University of California.
341456Sbostic  * All rights reserved.
441456Sbostic  *
541456Sbostic  * %sccs.include.redist.c%
641456Sbostic  */
741456Sbostic 
841456Sbostic #ifndef lint
9*55201Sbostic static char sccsid[] = "@(#)hexsyntax.c	5.3 (Berkeley) 07/14/92";
1041456Sbostic #endif /* not lint */
1141456Sbostic 
1241456Sbostic #include <sys/types.h>
13*55201Sbostic 
1441456Sbostic #include <stdio.h>
15*55201Sbostic #include <stdlib.h>
16*55201Sbostic #include <string.h>
1741456Sbostic #include "hexdump.h"
1841456Sbostic 
1941456Sbostic off_t skip;				/* bytes to skip */
2041456Sbostic 
21*55201Sbostic void
2241456Sbostic newsyntax(argc, argvp)
2341456Sbostic 	int argc;
2441456Sbostic 	char ***argvp;
2541456Sbostic {
2641456Sbostic 	extern enum _vflag vflag;
2741456Sbostic 	extern FS *fshead;
28*55201Sbostic 	extern int length;
2941456Sbostic 	int ch;
3041456Sbostic 	char *p, **argv;
3141456Sbostic 
3241456Sbostic 	argv = *argvp;
3341456Sbostic 	while ((ch = getopt(argc, argv, "bcde:f:n:os:vx")) != EOF)
3441456Sbostic 		switch (ch) {
3541456Sbostic 		case 'b':
3641456Sbostic 			add("\"%07.7_Ax\n\"");
3741456Sbostic 			add("\"%07.7_ax \" 16/1 \"%03o \" \"\\n\"");
3841456Sbostic 			break;
3941456Sbostic 		case 'c':
4041456Sbostic 			add("\"%07.7_Ax\n\"");
4141456Sbostic 			add("\"%07.7_ax \" 16/1 \"%3_c \" \"\\n\"");
4241456Sbostic 			break;
4341456Sbostic 		case 'd':
4441456Sbostic 			add("\"%07.7_Ax\n\"");
4541459Sbostic 			add("\"%07.7_ax \" 8/2 \"  %05u \" \"\\n\"");
4641456Sbostic 			break;
4741456Sbostic 		case 'e':
4841456Sbostic 			add(optarg);
4941456Sbostic 			break;
5041456Sbostic 		case 'f':
5141456Sbostic 			addfile(optarg);
5241456Sbostic 			break;
5341456Sbostic 		case 'n':
54*55201Sbostic 			if ((length = atoi(optarg)) < 0)
55*55201Sbostic 				err("%s: bad length value", optarg);
5641456Sbostic 			break;
5741456Sbostic 		case 'o':
5841456Sbostic 			add("\"%07.7_Ax\n\"");
5941459Sbostic 			add("\"%07.7_ax \" 8/2 \" %06o \" \"\\n\"");
6041456Sbostic 			break;
6141456Sbostic 		case 's':
62*55201Sbostic 			if ((skip = strtol(optarg, &p, 0)) < 0)
63*55201Sbostic 				err("%s: bad skip value", optarg);
6441456Sbostic 			switch(*p) {
6541456Sbostic 			case 'b':
6641456Sbostic 				skip *= 512;
6741456Sbostic 				break;
6841456Sbostic 			case 'k':
6941456Sbostic 				skip *= 1024;
7041456Sbostic 				break;
7141456Sbostic 			case 'm':
7241456Sbostic 				skip *= 1048576;
7341456Sbostic 				break;
7441456Sbostic 			}
7541456Sbostic 			break;
7641456Sbostic 		case 'v':
7741456Sbostic 			vflag = ALL;
7841456Sbostic 			break;
7941456Sbostic 		case 'x':
8041456Sbostic 			add("\"%07.7_Ax\n\"");
8141459Sbostic 			add("\"%07.7_ax \" 8/2 \"   %04x \" \"\\n\"");
8241456Sbostic 			break;
8341456Sbostic 		case '?':
8441456Sbostic 			usage();
8541456Sbostic 		}
8641456Sbostic 
8741456Sbostic 	if (!fshead) {
8841456Sbostic 		add("\"%07.7_Ax\n\"");
8941456Sbostic 		add("\"%07.7_ax \" 8/2 \"%04x \" \"\\n\"");
9041456Sbostic 	}
9141456Sbostic 
9241456Sbostic 	*argvp += optind;
9341456Sbostic }
9441456Sbostic 
95*55201Sbostic void
9641456Sbostic usage()
9741456Sbostic {
9841456Sbostic 	(void)fprintf(stderr,
9941456Sbostic "hexdump: [-bcdovx] [-e fmt] [-f fmt_file] [-n length] [-s skip] [file ...]\n");
10041456Sbostic 	exit(1);
10141456Sbostic }
102