hexsyntax.c revision 50477
11556Srgrimes/*- 21556Srgrimes * Copyright (c) 1990, 1993 31556Srgrimes * The Regents of the University of California. All rights reserved. 41556Srgrimes * 51556Srgrimes * Redistribution and use in source and binary forms, with or without 61556Srgrimes * modification, are permitted provided that the following conditions 71556Srgrimes * are met: 81556Srgrimes * 1. Redistributions of source code must retain the above copyright 91556Srgrimes * notice, this list of conditions and the following disclaimer. 101556Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 111556Srgrimes * notice, this list of conditions and the following disclaimer in the 121556Srgrimes * documentation and/or other materials provided with the distribution. 131556Srgrimes * 3. All advertising materials mentioning features or use of this software 141556Srgrimes * must display the following acknowledgement: 151556Srgrimes * This product includes software developed by the University of 161556Srgrimes * California, Berkeley and its contributors. 171556Srgrimes * 4. Neither the name of the University nor the names of its contributors 181556Srgrimes * may be used to endorse or promote products derived from this software 191556Srgrimes * without specific prior written permission. 201556Srgrimes * 211556Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 221556Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 231556Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 241556Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 251556Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 261556Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 271556Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 281556Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 291556Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 301556Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 311556Srgrimes * SUCH DAMAGE. 321556Srgrimes */ 331556Srgrimes 341556Srgrimes#ifndef lint 351556Srgrimes#if 0 361556Srgrimesstatic char sccsid[] = "@(#)hexsyntax.c 8.2 (Berkeley) 5/4/95"; 37114433Sobrien#endif 381556Srgrimesstatic const char rcsid[] = 3920425Ssteve "$FreeBSD: head/usr.bin/hexdump/hexsyntax.c 50477 1999-08-28 01:08:13Z peter $"; 401556Srgrimes#endif /* not lint */ 411556Srgrimes 421556Srgrimes#include <sys/types.h> 431556Srgrimes 441556Srgrimes#include <err.h> 4536150Scharnier#include <stdio.h> 46114433Sobrien#include <stdlib.h> 4736150Scharnier#include <string.h> 4899110Sobrien#include <unistd.h> 4999110Sobrien 501556Srgrimes#include "hexdump.h" 511556Srgrimes 521556Srgrimesoff_t skip; /* bytes to skip */ 531556Srgrimes 541556Srgrimesvoid 551556Srgrimesnewsyntax(argc, argvp) 561556Srgrimes int argc; 5717987Speter char ***argvp; 5817987Speter{ 5953891Scracauer extern enum _vflag vflag; 6017987Speter extern FS *fshead; 611556Srgrimes extern int length; 621556Srgrimes int ch; 631556Srgrimes char *p, **argv; 641556Srgrimes 651556Srgrimes argv = *argvp; 661556Srgrimes if ((p = rindex(argv[0], 'h')) != NULL && 671556Srgrimes strcmp(p, "hd") == 0) { 681556Srgrimes /* "Canonical" format, implies -C. */ 691556Srgrimes add("\"%08.8_Ax\n\""); 701556Srgrimes add("\"%08.8_ax \" 8/1 \"%02x \" \" \" 8/1 \"%02x \" "); 711556Srgrimes add("\" |\" 16/1 \"%_p\" \"|\\n\""); 721556Srgrimes } 731556Srgrimes while ((ch = getopt(argc, argv, "bcCde:f:n:os:vx")) != -1) 741556Srgrimes switch (ch) { 751556Srgrimes case 'b': 761556Srgrimes add("\"%07.7_Ax\n\""); 771556Srgrimes add("\"%07.7_ax \" 16/1 \"%03o \" \"\\n\""); 781556Srgrimes break; 791556Srgrimes case 'c': 801556Srgrimes add("\"%07.7_Ax\n\""); 811556Srgrimes add("\"%07.7_ax \" 16/1 \"%3_c \" \"\\n\""); 821556Srgrimes break; 831556Srgrimes case 'C': 841556Srgrimes add("\"%08.8_Ax\n\""); 851556Srgrimes add("\"%08.8_ax \" 8/1 \"%02x \" \" \" 8/1 \"%02x \" "); 861556Srgrimes add("\" |\" 16/1 \"%_p\" \"|\\n\""); 871556Srgrimes break; 881556Srgrimes case 'd': 891556Srgrimes add("\"%07.7_Ax\n\""); 9017987Speter add("\"%07.7_ax \" 8/2 \" %05u \" \"\\n\""); 9117987Speter break; 9217987Speter case 'e': 9317987Speter add(optarg); 9417987Speter break; 9517987Speter case 'f': 9681602Speter addfile(optarg); 9717987Speter break; 9817987Speter case 'n': 9917987Speter if ((length = atoi(optarg)) < 0) 1001556Srgrimes errx(1, "%s: bad length value", optarg); 10190111Simp break; 10290111Simp case 'o': 10390111Simp add("\"%07.7_Ax\n\""); 10490111Simp add("\"%07.7_ax \" 8/2 \" %06o \" \"\\n\""); 10590111Simp break; 10690111Simp case 's': 10790111Simp if ((skip = strtol(optarg, &p, 0)) < 0) 10890111Simp errx(1, "%s: bad skip value", optarg); 10990111Simp switch(*p) { 11090111Simp case 'b': 11190111Simp skip *= 512; 1121556Srgrimes break; 1131556Srgrimes case 'k': 11417987Speter skip *= 1024; 11590111Simp break; 11617987Speter case 'm': 1171556Srgrimes skip *= 1048576; 11818016Speter break; 11981602Speter } 1201556Srgrimes break; 12153891Scracauer case 'v': 1221556Srgrimes vflag = ALL; 1231556Srgrimes break; 1241556Srgrimes case 'x': 1251556Srgrimes add("\"%07.7_Ax\n\""); 1261556Srgrimes add("\"%07.7_ax \" 8/2 \" %04x \" \"\\n\""); 1271556Srgrimes break; 1281556Srgrimes case '?': 1291556Srgrimes usage(); 1301556Srgrimes } 1311556Srgrimes 1321556Srgrimes if (!fshead) { 1331556Srgrimes add("\"%07.7_Ax\n\""); 13417987Speter add("\"%07.7_ax \" 8/2 \"%04x \" \"\\n\""); 13590111Simp } 13617987Speter 1371556Srgrimes *argvp += optind; 1381556Srgrimes} 1391556Srgrimes 1401556Srgrimesvoid 1411556Srgrimesusage() 1421556Srgrimes{ 1431556Srgrimes (void)fprintf(stderr, "%s\n%s\n%s\n%s\n", 1441556Srgrimes"usage: hexdump [-bcCdovx] [-e fmt] [-f fmt_file] [-n length]", 1451556Srgrimes" [-s skip] [file ...]", 1461556Srgrimes" hd [-bcdovx] [-e fmt] [-f fmt_file] [-n length]", 1471556Srgrimes" [-s skip] [file ...]"); 1481556Srgrimes exit(1); 1491556Srgrimes} 15017987Speter