2
* Copyright (c) 1990 The Regents of the University of California.
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions
8
* 1. Redistributions of source code must retain the above copyright
9
* notice, this list of conditions and the following disclaimer.
10
* 2. Redistributions in binary form must reproduce the above copyright
11
* notice, this list of conditions and the following disclaimer in the
12
* documentation and/or other materials provided with the distribution.
13
* 3. All advertising materials mentioning features or use of this software
14
* must display the following acknowledgement:
15
* This product includes software developed by the University of
16
* California, Berkeley and its contributors.
17
* 4. Neither the name of the University nor the names of its contributors
18
* may be used to endorse or promote products derived from this software
19
* without specific prior written permission.
21
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34
/* 1999-02-22 Arkadiusz Mi�kiewicz <misiek@pld.ORG.PL>
35
* - added Native Language Support
38
#include <sys/types.h>
41
#include <ctype.h> /* for isdigit() */
42
#include <unistd.h> /* for getopt() */
46
static void odoffset(int, char ***);
47
static void odprecede(void);
52
oldsyntax(int argc, char ***argvp)
59
while ((ch = getopt(argc, argv, "aBbcDdeFfHhIiLlOoPpswvXx")) != -1)
63
add("16/1 \"%3_u \" \"\\n\"");
68
add("8/2 \" %06o \" \"\\n\"");
72
add("16/1 \"%03o \" \"\\n\"");
76
add("16/1 \"%3_c \" \"\\n\"");
80
add("8/2 \" %05u \" \"\\n\"");
84
add("4/4 \" %010u \" \"\\n\"");
86
case 'e': /* undocumented in od */
89
add("2/8 \" %21.14e \" \"\\n\"");
94
add("4/4 \" %14.7e \" \"\\n\"");
99
add("4/4 \" %08x \" \"\\n\"");
104
add("8/2 \" %04x \" \"\\n\"");
110
add("4/4 \" %11d \" \"\\n\"");
114
add("8/2 \" %6d \" \"\\n\"");
118
add("4/4 \" %011o \" \"\\n\"");
130
_("od: od(1) has been deprecated for hexdump(1).\n"));
133
_("od: hexdump(1) compatibility doesn't support the -%c option%s\n"),
134
ch, ch == 's' ? _("; see strings(1).") : ".");
139
add("\"%07.7_Ao\n\"");
140
add("\"%07.7_ao \" 8/2 \"%06o \" \"\\n\"");
147
odoffset(argc, argvp);
150
#define ishexdigit(c) \
151
((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'))
154
odoffset(int argc, char ***argvp)
161
* The offset syntax of od(1) was genuinely bizarre. First, if
162
* it started with a plus it had to be an offset. Otherwise, if
163
* there were at least two arguments, a number or lower-case 'x'
164
* followed by a number makes it an offset. By default it was
165
* octal; if it started with 'x' or '0x' it was hex. If it ended
166
* in a '.', it was decimal. If a 'b' or 'B' was appended, it
167
* multiplied the number by 512 or 1024 byte units. There was
168
* no way to assign a block count to a hex offset.
170
* We assume it's a file if the offset is bad.
172
p = argc == 1 ? (*argvp)[0] : (*argvp)[1];
176
if (*p != '+' && (argc < 2 ||
177
(!isdigit((unsigned char)p[0]) &&
178
(p[0] != 'x' || !ishexdigit(p[1])))))
183
* skip over leading '+', 'x[0-9a-fA-f]' or '0x', and
188
if (p[0] == 'x' && ishexdigit(p[1])) {
191
} else if (p[0] == '0' && p[1] == 'x') {
196
/* skip over the number */
198
for (num = p; ishexdigit(*p); ++p);
200
for (num = p; isdigit((unsigned char)*p); ++p);
202
/* check for no number */
206
/* if terminates with a '.', base is decimal */
213
skip = strtol(num, &end, base ? base : 8);
215
/* if end isn't the same as p, we got a non-octal digit */
225
} else if (*p == 'b') {
237
* If the offset uses a non-octal base, the base of
238
* the offset is changed as well. This isn't pretty,
241
#define TYPE_OFFSET 7
243
fshead->nextfu->fmt[TYPE_OFFSET] = 'x';
244
fshead->nextfs->nextfu->fmt[TYPE_OFFSET] = 'x';
245
} else if (base == 10) {
246
fshead->nextfu->fmt[TYPE_OFFSET] = 'd';
247
fshead->nextfs->nextfu->fmt[TYPE_OFFSET] = 'd';
250
/* Terminate file list. */
257
static int first = 1;
261
add("\"%07.7_Ao\n\"");
262
add("\"%07.7_ao \"");