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*41459Sbostic static char sccsid[] = "@(#)hexsyntax.c 5.2 (Berkeley) 05/08/90"; 1041456Sbostic #endif /* not lint */ 1141456Sbostic 1241456Sbostic #include <sys/types.h> 1341456Sbostic #include <stdio.h> 1441456Sbostic #include "hexdump.h" 1541456Sbostic 1641456Sbostic off_t skip; /* bytes to skip */ 1741456Sbostic 1841456Sbostic newsyntax(argc, argvp) 1941456Sbostic int argc; 2041456Sbostic char ***argvp; 2141456Sbostic { 2241456Sbostic extern enum _vflag vflag; 2341456Sbostic extern FS *fshead; 2441456Sbostic extern char *optarg; 2541456Sbostic extern int length, optind; 2641456Sbostic int ch; 2741456Sbostic char *p, **argv; 2841456Sbostic 2941456Sbostic argv = *argvp; 3041456Sbostic while ((ch = getopt(argc, argv, "bcde:f:n:os:vx")) != EOF) 3141456Sbostic switch (ch) { 3241456Sbostic case 'b': 3341456Sbostic add("\"%07.7_Ax\n\""); 3441456Sbostic add("\"%07.7_ax \" 16/1 \"%03o \" \"\\n\""); 3541456Sbostic break; 3641456Sbostic case 'c': 3741456Sbostic add("\"%07.7_Ax\n\""); 3841456Sbostic add("\"%07.7_ax \" 16/1 \"%3_c \" \"\\n\""); 3941456Sbostic break; 4041456Sbostic case 'd': 4141456Sbostic add("\"%07.7_Ax\n\""); 42*41459Sbostic add("\"%07.7_ax \" 8/2 \" %05u \" \"\\n\""); 4341456Sbostic break; 4441456Sbostic case 'e': 4541456Sbostic add(optarg); 4641456Sbostic break; 4741456Sbostic case 'f': 4841456Sbostic addfile(optarg); 4941456Sbostic break; 5041456Sbostic case 'n': 5141456Sbostic if ((length = atoi(optarg)) < 0) { 5241456Sbostic (void)fprintf(stderr, 5341456Sbostic "hexdump: bad length value.\n"); 5441456Sbostic exit(1); 5541456Sbostic } 5641456Sbostic break; 5741456Sbostic case 'o': 5841456Sbostic add("\"%07.7_Ax\n\""); 59*41459Sbostic add("\"%07.7_ax \" 8/2 \" %06o \" \"\\n\""); 6041456Sbostic break; 6141456Sbostic case 's': 6241456Sbostic if ((skip = strtol(optarg, &p, 0)) < 0) { 6341456Sbostic (void)fprintf(stderr, 6441456Sbostic "hexdump: bad skip value.\n"); 6541456Sbostic exit(1); 6641456Sbostic } 6741456Sbostic switch(*p) { 6841456Sbostic case 'b': 6941456Sbostic skip *= 512; 7041456Sbostic break; 7141456Sbostic case 'k': 7241456Sbostic skip *= 1024; 7341456Sbostic break; 7441456Sbostic case 'm': 7541456Sbostic skip *= 1048576; 7641456Sbostic break; 7741456Sbostic } 7841456Sbostic break; 7941456Sbostic case 'v': 8041456Sbostic vflag = ALL; 8141456Sbostic break; 8241456Sbostic case 'x': 8341456Sbostic add("\"%07.7_Ax\n\""); 84*41459Sbostic add("\"%07.7_ax \" 8/2 \" %04x \" \"\\n\""); 8541456Sbostic break; 8641456Sbostic case '?': 8741456Sbostic usage(); 8841456Sbostic exit(1); 8941456Sbostic } 9041456Sbostic 9141456Sbostic if (!fshead) { 9241456Sbostic add("\"%07.7_Ax\n\""); 9341456Sbostic add("\"%07.7_ax \" 8/2 \"%04x \" \"\\n\""); 9441456Sbostic } 9541456Sbostic 9641456Sbostic *argvp += optind; 9741456Sbostic } 9841456Sbostic 9941456Sbostic usage() 10041456Sbostic { 10141456Sbostic (void)fprintf(stderr, 10241456Sbostic "hexdump: [-bcdovx] [-e fmt] [-f fmt_file] [-n length] [-s skip] [file ...]\n"); 10341456Sbostic exit(1); 10441456Sbostic } 105