| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: odsyntax.c,v 1.26 2010/02/09 14:06:37 drochner Exp $ */ | | 1 | /* $NetBSD: odsyntax.c,v 1.27 2010/11/27 00:42:58 dholland Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 1990, 1993 | | 4 | * Copyright (c) 1990, 1993 |
5 | * The Regents of the University of California. All rights reserved. | | 5 | * The Regents of the University of California. All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
| @@ -28,27 +28,27 @@ | | | @@ -28,27 +28,27 @@ |
28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
29 | * SUCH DAMAGE. | | 29 | * SUCH DAMAGE. |
30 | */ | | 30 | */ |
31 | | | 31 | |
32 | #if HAVE_NBTOOL_CONFIG_H | | 32 | #if HAVE_NBTOOL_CONFIG_H |
33 | #include "nbtool_config.h" | | 33 | #include "nbtool_config.h" |
34 | #endif | | 34 | #endif |
35 | | | 35 | |
36 | #include <sys/cdefs.h> | | 36 | #include <sys/cdefs.h> |
37 | #if !defined(lint) | | 37 | #if !defined(lint) |
38 | #if 0 | | 38 | #if 0 |
39 | static char sccsid[] = "@(#)odsyntax.c 8.2 (Berkeley) 5/4/95"; | | 39 | static char sccsid[] = "@(#)odsyntax.c 8.2 (Berkeley) 5/4/95"; |
40 | #else | | 40 | #else |
41 | __RCSID("$NetBSD: odsyntax.c,v 1.26 2010/02/09 14:06:37 drochner Exp $"); | | 41 | __RCSID("$NetBSD: odsyntax.c,v 1.27 2010/11/27 00:42:58 dholland Exp $"); |
42 | #endif | | 42 | #endif |
43 | #endif /* not lint */ | | 43 | #endif /* not lint */ |
44 | | | 44 | |
45 | #include <sys/types.h> | | 45 | #include <sys/types.h> |
46 | | | 46 | |
47 | #include <ctype.h> | | 47 | #include <ctype.h> |
48 | #include <err.h> | | 48 | #include <err.h> |
49 | #include <stdio.h> | | 49 | #include <stdio.h> |
50 | #include <stdlib.h> | | 50 | #include <stdlib.h> |
51 | #include <unistd.h> | | 51 | #include <unistd.h> |
52 | #include <util.h> | | 52 | #include <util.h> |
53 | | | 53 | |
54 | #include "hexdump.h" | | 54 | #include "hexdump.h" |
| @@ -62,26 +62,27 @@ struct odformat { | | | @@ -62,26 +62,27 @@ struct odformat { |
62 | int minwidth; | | 62 | int minwidth; |
63 | }; | | 63 | }; |
64 | | | 64 | |
65 | struct odaddrformat { | | 65 | struct odaddrformat { |
66 | char type; | | 66 | char type; |
67 | char const *format1; | | 67 | char const *format1; |
68 | char const *format2; | | 68 | char const *format2; |
69 | }; | | 69 | }; |
70 | | | 70 | |
71 | int odmode; | | 71 | int odmode; |
72 | | | 72 | |
73 | static void odoffset(int, char ***); | | 73 | static void odoffset(int, char ***); |
74 | static void posixtypes(char const *); | | 74 | static void posixtypes(char const *); |
| | | 75 | static void odusage(void); |
75 | | | 76 | |
76 | void | | 77 | void |
77 | odsyntax(int argc, char ***argvp) | | 78 | odsyntax(int argc, char ***argvp) |
78 | { | | 79 | { |
79 | static char empty[] = "", padding[] = PADDING; | | 80 | static char empty[] = "", padding[] = PADDING; |
80 | int ch; | | 81 | int ch; |
81 | char *p, **argv; | | 82 | char *p, **argv; |
82 | | | 83 | |
83 | #define TYPE_OFFSET 7 | | 84 | #define TYPE_OFFSET 7 |
84 | add("\"%07.7_Ao\n\""); | | 85 | add("\"%07.7_Ao\n\""); |
85 | add("\"%07.7_ao \""); | | 86 | add("\"%07.7_ao \""); |
86 | | | 87 | |
87 | odmode = 1; | | 88 | odmode = 1; |
| @@ -166,27 +167,27 @@ odsyntax(int argc, char ***argvp) | | | @@ -166,27 +167,27 @@ odsyntax(int argc, char ***argvp) |
166 | errx(1, "%s: bad length value", optarg); | | 167 | errx(1, "%s: bad length value", optarg); |
167 | break; | | 168 | break; |
168 | case 'O': | | 169 | case 'O': |
169 | posixtypes("o4"); | | 170 | posixtypes("o4"); |
170 | break; | | 171 | break; |
171 | case 't': | | 172 | case 't': |
172 | posixtypes(optarg); | | 173 | posixtypes(optarg); |
173 | break; | | 174 | break; |
174 | case 'v': | | 175 | case 'v': |
175 | vflag = ALL; | | 176 | vflag = ALL; |
176 | break; | | 177 | break; |
177 | case '?': | | 178 | case '?': |
178 | default: | | 179 | default: |
179 | usage(); | | 180 | odusage(); |
180 | } | | 181 | } |
181 | | | 182 | |
182 | if (fshead->nextfs->nextfs == NULL) | | 183 | if (fshead->nextfs->nextfs == NULL) |
183 | posixtypes("oS"); | | 184 | posixtypes("oS"); |
184 | | | 185 | |
185 | argc -= optind; | | 186 | argc -= optind; |
186 | *argvp += optind; | | 187 | *argvp += optind; |
187 | | | 188 | |
188 | if (argc) | | 189 | if (argc) |
189 | odoffset(argc, argvp); | | 190 | odoffset(argc, argvp); |
190 | } | | 191 | } |
191 | | | 192 | |
192 | /* formats used for -t */ | | 193 | /* formats used for -t */ |
| @@ -236,27 +237,27 @@ posixtypes(char const *type_string) | | | @@ -236,27 +237,27 @@ posixtypes(char const *type_string) |
236 | switch(*type_string) { | | 237 | switch(*type_string) { |
237 | case 'F': | | 238 | case 'F': |
238 | nbytes = sizeof(float); | | 239 | nbytes = sizeof(float); |
239 | break; | | 240 | break; |
240 | case 'D': | | 241 | case 'D': |
241 | nbytes = sizeof(double); | | 242 | nbytes = sizeof(double); |
242 | break; | | 243 | break; |
243 | case 'L': | | 244 | case 'L': |
244 | nbytes = sizeof(long double); | | 245 | nbytes = sizeof(long double); |
245 | break; | | 246 | break; |
246 | default: | | 247 | default: |
247 | warnx("Bad type-size qualifier '%c'", | | 248 | warnx("Bad type-size qualifier '%c'", |
248 | *type_string); | | 249 | *type_string); |
249 | usage(); | | 250 | odusage(); |
250 | } | | 251 | } |
251 | type_string++; | | 252 | type_string++; |
252 | } else if (isdigit((unsigned char)*type_string)) { | | 253 | } else if (isdigit((unsigned char)*type_string)) { |
253 | nbytes = strtol(type_string, &tmp, 10); | | 254 | nbytes = strtol(type_string, &tmp, 10); |
254 | type_string = tmp; | | 255 | type_string = tmp; |
255 | } else | | 256 | } else |
256 | nbytes = 8; | | 257 | nbytes = 8; |
257 | break; | | 258 | break; |
258 | case 'd': | | 259 | case 'd': |
259 | case 'o': | | 260 | case 'o': |
260 | case 'u': | | 261 | case 'u': |
261 | case 'x': | | 262 | case 'x': |
262 | if (isupper((unsigned char)*type_string)) { | | 263 | if (isupper((unsigned char)*type_string)) { |
| @@ -266,37 +267,37 @@ posixtypes(char const *type_string) | | | @@ -266,37 +267,37 @@ posixtypes(char const *type_string) |
266 | break; | | 267 | break; |
267 | case 'S': | | 268 | case 'S': |
268 | nbytes = sizeof(short); | | 269 | nbytes = sizeof(short); |
269 | break; | | 270 | break; |
270 | case 'I': | | 271 | case 'I': |
271 | nbytes = sizeof(int); | | 272 | nbytes = sizeof(int); |
272 | break; | | 273 | break; |
273 | case 'L': | | 274 | case 'L': |
274 | nbytes = sizeof(long); | | 275 | nbytes = sizeof(long); |
275 | break; | | 276 | break; |
276 | default: | | 277 | default: |
277 | warnx("Bad type-size qualifier '%c'", | | 278 | warnx("Bad type-size qualifier '%c'", |
278 | *type_string); | | 279 | *type_string); |
279 | usage(); | | 280 | odusage(); |
280 | } | | 281 | } |
281 | type_string++; | | 282 | type_string++; |
282 | } else if (isdigit((unsigned char)*type_string)) { | | 283 | } else if (isdigit((unsigned char)*type_string)) { |
283 | nbytes = strtol(type_string, &tmp, 10); | | 284 | nbytes = strtol(type_string, &tmp, 10); |
284 | type_string = tmp; | | 285 | type_string = tmp; |
285 | } else | | 286 | } else |
286 | nbytes = 4; | | 287 | nbytes = 4; |
287 | break; | | 288 | break; |
288 | default: | | 289 | default: |
289 | usage(); | | 290 | odusage(); |
290 | } | | 291 | } |
291 | for (odf = odftab; odf->type != 0; odf++) | | 292 | for (odf = odftab; odf->type != 0; odf++) |
292 | if (odf->type == type && odf->nbytes == nbytes) | | 293 | if (odf->type == type && odf->nbytes == nbytes) |
293 | break; | | 294 | break; |
294 | if (odf->type == 0) | | 295 | if (odf->type == 0) |
295 | errx(1, "%c%d: format not supported", type, nbytes); | | 296 | errx(1, "%c%d: format not supported", type, nbytes); |
296 | (void)easprintf(&fmt, "%d/%d \"%*s%s \" \"\\n\"", | | 297 | (void)easprintf(&fmt, "%d/%d \"%*s%s \" \"\\n\"", |
297 | 16 / nbytes, nbytes, | | 298 | 16 / nbytes, nbytes, |
298 | 4 * nbytes - odf->minwidth, "", odf->format); | | 299 | 4 * nbytes - odf->minwidth, "", odf->format); |
299 | add(fmt); | | 300 | add(fmt); |
300 | } | | 301 | } |
301 | } | | 302 | } |
302 | | | 303 | |
| @@ -386,13 +387,22 @@ odoffset(int argc, char ***argvp) | | | @@ -386,13 +387,22 @@ odoffset(int argc, char ***argvp) |
386 | * is changed as well. This isn't pretty, but it's easy. | | 387 | * is changed as well. This isn't pretty, but it's easy. |
387 | */ | | 388 | */ |
388 | if (base == 16) { | | 389 | if (base == 16) { |
389 | fshead->nextfu->fmt[TYPE_OFFSET] = 'x'; | | 390 | fshead->nextfu->fmt[TYPE_OFFSET] = 'x'; |
390 | fshead->nextfs->nextfu->fmt[TYPE_OFFSET] = 'x'; | | 391 | fshead->nextfs->nextfu->fmt[TYPE_OFFSET] = 'x'; |
391 | } else if (base == 10) { | | 392 | } else if (base == 10) { |
392 | fshead->nextfu->fmt[TYPE_OFFSET] = 'd'; | | 393 | fshead->nextfu->fmt[TYPE_OFFSET] = 'd'; |
393 | fshead->nextfs->nextfu->fmt[TYPE_OFFSET] = 'd'; | | 394 | fshead->nextfs->nextfu->fmt[TYPE_OFFSET] = 'd'; |
394 | } | | 395 | } |
395 | | | 396 | |
396 | /* Terminate file list. */ | | 397 | /* Terminate file list. */ |
397 | (*argvp)[1] = NULL; | | 398 | (*argvp)[1] = NULL; |
398 | } | | 399 | } |
| | | 400 | |
| | | 401 | static void |
| | | 402 | odusage(void) |
| | | 403 | { |
| | | 404 | (void)warnx("Usage: od [-aBbcDdeFfHhIiLlOovXx] [-A base] [-j skip]" |
| | | 405 | " [-N length]"); |
| | | 406 | (void)warnx(" [-t type_string] [[+]offset[.][Bb]] [file ...]"); |
| | | 407 | exit(1); |
| | | 408 | } |