Annotation of src/usr.bin/hexdump/hexsyntax.c, Revision 1.2
1.2 ! deraadt 1: /* $OpenBSD$ */
! 2:
1.1 deraadt 3: /*-
4: * Copyright (c) 1990 The Regents of the University of California.
5: * All rights reserved.
6: *
7: * Redistribution and use in source and binary forms, with or without
8: * modification, are permitted provided that the following conditions
9: * are met:
10: * 1. Redistributions of source code must retain the above copyright
11: * notice, this list of conditions and the following disclaimer.
12: * 2. Redistributions in binary form must reproduce the above copyright
13: * notice, this list of conditions and the following disclaimer in the
14: * documentation and/or other materials provided with the distribution.
15: * 3. All advertising materials mentioning features or use of this software
16: * must display the following acknowledgement:
17: * This product includes software developed by the University of
18: * California, Berkeley and its contributors.
19: * 4. Neither the name of the University nor the names of its contributors
20: * may be used to endorse or promote products derived from this software
21: * without specific prior written permission.
22: *
23: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33: * SUCH DAMAGE.
34: */
35:
36: #ifndef lint
37: /*static char sccsid[] = "from: @(#)hexsyntax.c 5.2 (Berkeley) 5/8/90";*/
1.2 ! deraadt 38: static char rcsid[] = "$OpenBSD: hexsyntax.c,v 1.1.1.1 1995/10/18 08:45:23 deraadt Exp $";
1.1 deraadt 39: #endif /* not lint */
40:
41: #include <sys/types.h>
42: #include <stdio.h>
43: #include "hexdump.h"
44:
45: off_t skip; /* bytes to skip */
46:
47: newsyntax(argc, argvp)
48: int argc;
49: char ***argvp;
50: {
51: extern enum _vflag vflag;
52: extern FS *fshead;
53: extern char *optarg;
54: extern int length, optind;
55: int ch;
56: char *p, **argv;
57:
58: argv = *argvp;
59: while ((ch = getopt(argc, argv, "bcde:f:n:os:vx")) != EOF)
60: switch (ch) {
61: case 'b':
62: add("\"%07.7_Ax\n\"");
63: add("\"%07.7_ax \" 16/1 \"%03o \" \"\\n\"");
64: break;
65: case 'c':
66: add("\"%07.7_Ax\n\"");
67: add("\"%07.7_ax \" 16/1 \"%3_c \" \"\\n\"");
68: break;
69: case 'd':
70: add("\"%07.7_Ax\n\"");
71: add("\"%07.7_ax \" 8/2 \" %05u \" \"\\n\"");
72: break;
73: case 'e':
74: add(optarg);
75: break;
76: case 'f':
77: addfile(optarg);
78: break;
79: case 'n':
80: if ((length = atoi(optarg)) < 0) {
81: (void)fprintf(stderr,
82: "hexdump: bad length value.\n");
83: exit(1);
84: }
85: break;
86: case 'o':
87: add("\"%07.7_Ax\n\"");
88: add("\"%07.7_ax \" 8/2 \" %06o \" \"\\n\"");
89: break;
90: case 's':
91: if ((skip = strtol(optarg, &p, 0)) < 0) {
92: (void)fprintf(stderr,
93: "hexdump: bad skip value.\n");
94: exit(1);
95: }
96: switch(*p) {
97: case 'b':
98: skip *= 512;
99: break;
100: case 'k':
101: skip *= 1024;
102: break;
103: case 'm':
104: skip *= 1048576;
105: break;
106: }
107: break;
108: case 'v':
109: vflag = ALL;
110: break;
111: case 'x':
112: add("\"%07.7_Ax\n\"");
113: add("\"%07.7_ax \" 8/2 \" %04x \" \"\\n\"");
114: break;
115: case '?':
116: usage();
117: exit(1);
118: }
119:
120: if (!fshead) {
121: add("\"%07.7_Ax\n\"");
122: add("\"%07.7_ax \" 8/2 \"%04x \" \"\\n\"");
123: }
124:
125: *argvp += optind;
126: }
127:
128: usage()
129: {
130: (void)fprintf(stderr,
131: "hexdump: [-bcdovx] [-e fmt] [-f fmt_file] [-n length] [-s skip] [file ...]\n");
132: exit(1);
133: }