141456Sbostic /*-
262031Sbostic * Copyright (c) 1990, 1993
362031Sbostic * The Regents of the University of California. All rights reserved.
441456Sbostic *
541456Sbostic * %sccs.include.redist.c%
641456Sbostic */
741456Sbostic
841456Sbostic #ifndef lint
9*69238Sbostic static char sccsid[] = "@(#)hexsyntax.c 8.2 (Berkeley) 05/04/95";
1041456Sbostic #endif /* not lint */
1141456Sbostic
1241456Sbostic #include <sys/types.h>
1355201Sbostic
1441456Sbostic #include <stdio.h>
1555201Sbostic #include <stdlib.h>
1655201Sbostic #include <string.h>
17*69238Sbostic #include <unistd.h>
18*69238Sbostic
1941456Sbostic #include "hexdump.h"
2041456Sbostic
2141456Sbostic off_t skip; /* bytes to skip */
2241456Sbostic
2355201Sbostic void
newsyntax(argc,argvp)2441456Sbostic newsyntax(argc, argvp)
2541456Sbostic int argc;
2641456Sbostic char ***argvp;
2741456Sbostic {
2841456Sbostic extern enum _vflag vflag;
2941456Sbostic extern FS *fshead;
3055201Sbostic extern int length;
3141456Sbostic int ch;
3241456Sbostic char *p, **argv;
3341456Sbostic
3441456Sbostic argv = *argvp;
3541456Sbostic while ((ch = getopt(argc, argv, "bcde:f:n:os:vx")) != EOF)
3641456Sbostic switch (ch) {
3741456Sbostic case 'b':
3841456Sbostic add("\"%07.7_Ax\n\"");
3941456Sbostic add("\"%07.7_ax \" 16/1 \"%03o \" \"\\n\"");
4041456Sbostic break;
4141456Sbostic case 'c':
4241456Sbostic add("\"%07.7_Ax\n\"");
4341456Sbostic add("\"%07.7_ax \" 16/1 \"%3_c \" \"\\n\"");
4441456Sbostic break;
4541456Sbostic case 'd':
4641456Sbostic add("\"%07.7_Ax\n\"");
4741459Sbostic add("\"%07.7_ax \" 8/2 \" %05u \" \"\\n\"");
4841456Sbostic break;
4941456Sbostic case 'e':
5041456Sbostic add(optarg);
5141456Sbostic break;
5241456Sbostic case 'f':
5341456Sbostic addfile(optarg);
5441456Sbostic break;
5541456Sbostic case 'n':
5655201Sbostic if ((length = atoi(optarg)) < 0)
5755201Sbostic err("%s: bad length value", optarg);
5841456Sbostic break;
5941456Sbostic case 'o':
6041456Sbostic add("\"%07.7_Ax\n\"");
6141459Sbostic add("\"%07.7_ax \" 8/2 \" %06o \" \"\\n\"");
6241456Sbostic break;
6341456Sbostic case 's':
6455201Sbostic if ((skip = strtol(optarg, &p, 0)) < 0)
6555201Sbostic err("%s: bad skip value", optarg);
6641456Sbostic switch(*p) {
6741456Sbostic case 'b':
6841456Sbostic skip *= 512;
6941456Sbostic break;
7041456Sbostic case 'k':
7141456Sbostic skip *= 1024;
7241456Sbostic break;
7341456Sbostic case 'm':
7441456Sbostic skip *= 1048576;
7541456Sbostic break;
7641456Sbostic }
7741456Sbostic break;
7841456Sbostic case 'v':
7941456Sbostic vflag = ALL;
8041456Sbostic break;
8141456Sbostic case 'x':
8241456Sbostic add("\"%07.7_Ax\n\"");
8341459Sbostic add("\"%07.7_ax \" 8/2 \" %04x \" \"\\n\"");
8441456Sbostic break;
8541456Sbostic case '?':
8641456Sbostic usage();
8741456Sbostic }
8841456Sbostic
8941456Sbostic if (!fshead) {
9041456Sbostic add("\"%07.7_Ax\n\"");
9141456Sbostic add("\"%07.7_ax \" 8/2 \"%04x \" \"\\n\"");
9241456Sbostic }
9341456Sbostic
9441456Sbostic *argvp += optind;
9541456Sbostic }
9641456Sbostic
9755201Sbostic void
usage()9841456Sbostic usage()
9941456Sbostic {
10041456Sbostic (void)fprintf(stderr,
10141456Sbostic "hexdump: [-bcdovx] [-e fmt] [-f fmt_file] [-n length] [-s skip] [file ...]\n");
10241456Sbostic exit(1);
10341456Sbostic }
104