View | Details | Raw Unified | Return to bug 36783
Collapse All | Expand All

(-)conv.c (-6 / +4 lines)
Lines 48-54 Link Here
48
	PR *pr;
48
	PR *pr;
49
	u_char *p;
49
	u_char *p;
50
{
50
{
51
	extern int deprecated;
52
	char buf[10];
51
	char buf[10];
53
	char const *str;
52
	char const *str;
54
53
Lines 58-64 Link Here
58
		goto strpr;
57
		goto strpr;
59
	/* case '\a': */
58
	/* case '\a': */
60
	case '\007':
59
	case '\007':
61
		if (deprecated)		/* od didn't know about \a */
60
		if (odmode)		/* od didn't know about \a */
62
			break;
61
			break;
63
		str = "\\a";
62
		str = "\\a";
64
		goto strpr;
63
		goto strpr;
Lines 78-84 Link Here
78
		str = "\\t";
77
		str = "\\t";
79
		goto strpr;
78
		goto strpr;
80
	case '\v':
79
	case '\v':
81
		if (deprecated)
80
		if (odmode)
82
			break;
81
			break;
83
		str = "\\v";
82
		str = "\\v";
84
		goto strpr;
83
		goto strpr;
Lines 101-107 Link Here
101
	PR *pr;
100
	PR *pr;
102
	u_char *p;
101
	u_char *p;
103
{
102
{
104
	extern int deprecated;
105
	static char const * list[] = {
103
	static char const * list[] = {
106
		"nul", "soh", "stx", "etx", "eot", "enq", "ack", "bel",
104
		"nul", "soh", "stx", "etx", "eot", "enq", "ack", "bel",
107
		 "bs",  "ht",  "lf",  "vt",  "ff",  "cr",  "so",  "si",
105
		 "bs",  "ht",  "lf",  "vt",  "ff",  "cr",  "so",  "si",
Lines 112-125 Link Here
112
						/* od used nl, not lf */
110
						/* od used nl, not lf */
113
	if (*p <= 0x1f) {
111
	if (*p <= 0x1f) {
114
		*pr->cchar = 's';
112
		*pr->cchar = 's';
115
		if (deprecated && *p == 0x0a)
113
		if (odmode && *p == 0x0a)
116
			(void)printf(pr->fmt, "nl");
114
			(void)printf(pr->fmt, "nl");
117
		else
115
		else
118
			(void)printf(pr->fmt, list[*p]);
116
			(void)printf(pr->fmt, list[*p]);
119
	} else if (*p == 0x7f) {
117
	} else if (*p == 0x7f) {
120
		*pr->cchar = 's';
118
		*pr->cchar = 's';
121
		(void)printf(pr->fmt, "del");
119
		(void)printf(pr->fmt, "del");
122
	} else if (deprecated && *p == 0x20) {	/* od replaced space with sp */
120
	} else if (odmode && *p == 0x20) {	/* od replaced space with sp */
123
		*pr->cchar = 's';
121
		*pr->cchar = 's';
124
		(void)printf(pr->fmt, " sp");
122
		(void)printf(pr->fmt, " sp");
125
	} else if (isprint(*p)) {
123
	} else if (isprint(*p)) {
(-)display.c (-3 / +2 lines)
Lines 228-234 Link Here
228
u_char *
228
u_char *
229
get()
229
get()
230
{
230
{
231
	extern int length;
232
	static int ateof = 1;
231
	static int ateof = 1;
233
	static u_char *curp, *savp;
232
	static u_char *curp, *savp;
234
	register int n;
233
	register int n;
Lines 255-260 Link Here
255
		 * block and set the end flag.
254
		 * block and set the end flag.
256
		 */
255
		 */
257
		if (!length || (ateof && !next((char **)NULL))) {
256
		if (!length || (ateof && !next((char **)NULL))) {
257
			if (odmode && address < skip)
258
				errx(1, "cannot skip past end of input");
258
			if (need == blocksize)
259
			if (need == blocksize)
259
				return((u_char *)NULL);
260
				return((u_char *)NULL);
260
			if (vflag != ALL && 
261
			if (vflag != ALL && 
Lines 298-305 Link Here
298
			nread += n;
299
			nread += n;
299
	}
300
	}
300
}
301
}
301
302
extern off_t skip;			/* bytes to skip */
303
302
304
int
303
int
305
next(argv)
304
next(argv)
(-)hexdump.h (+3 lines)
Lines 73-78 Link Here
73
73
74
extern FS *fshead;			/* head of format strings list */
74
extern FS *fshead;			/* head of format strings list */
75
extern int blocksize;			/* data block size */
75
extern int blocksize;			/* data block size */
76
extern int odmode;			/* are we acting as od(1)? */
77
extern int length;			/* amount of data to read */
78
extern off_t skip;			/* amount of data to skip at start */
76
enum _vflag { ALL, DUP, FIRST, WAIT };	/* -v values */
79
enum _vflag { ALL, DUP, FIRST, WAIT };	/* -v values */
77
80
78
void	 add(const char *);
81
void	 add(const char *);
(-)hexsyntax.c (-1 lines)
Lines 58-64 Link Here
58
{
58
{
59
	extern enum _vflag vflag;
59
	extern enum _vflag vflag;
60
	extern FS *fshead;
60
	extern FS *fshead;
61
	extern int length;
62
	int ch;
61
	int ch;
63
	char *p, **argv;
62
	char *p, **argv;
64
63
(-)od.1 (-21 / +133 lines)
Lines 40-46 Link Here
40
.Nd octal, decimal, hex, ASCII dump
40
.Nd octal, decimal, hex, ASCII dump
41
.Sh SYNOPSIS
41
.Sh SYNOPSIS
42
.Nm
42
.Nm
43
.Op Fl aBbcDdeFfHhIiLlOovXx
43
.Op Fl aBbcDdeFfHhIiLlOosvXx
44
.Op Fl A Ar base
45
.Op Fl j Ar skip
46
.Op Fl N Ar length
47
.Op Fl t Ar type
44
.Sm off
48
.Sm off
45
.Oo
49
.Oo
46
.Op Cm \&+
50
.Op Cm \&+
Lines 51-83 Link Here
51
.Sm on
55
.Sm on
52
.Ar file
56
.Ar file
53
.Sh DESCRIPTION
57
.Sh DESCRIPTION
54
.Nm Od
58
The
55
has been deprecated in favor of
59
.Nm
56
.Xr hexdump 1 .
60
utility is a filter which displays the specified files, or standard
57
.Pp
61
input if no files are specified, in a user specified format.
58
.Nm Hexdump ,
59
if called as
60
.Nm ,
61
provides compatibility for the options listed above.
62
.Pp
62
.Pp
63
It does not provide compatibility for the
63
The options are as follows:
64
.Fl s
64
.Bl -tag -width Fl
65
option (see
65
.It Fl A Ar base
66
.Xr strings 1 )
66
Specify the input address base.
67
or the
67
.Ar base
68
.Fl P ,
68
may be one of
69
.Fl p ,
69
.Ql d ,
70
.Ql o ,
71
.Ql x
72
or
73
.Ql n ,
74
which specify decimal, octal, hexadecimal
75
addresses or no address, respectively.
76
.It Fl a
77
Equivalent to
78
.Fl t Ar a .
79
.It Fl B , Fl o
80
Equivalent to
81
.Fl t Ar o2 .
82
.It Fl b
83
Equivalent to
84
.Fl t Ar o1 .
85
.It Fl c
86
Equivalent to
87
.Fl t Ar c .
88
.It Fl D
89
Equivalent to
90
.Fl t Ar u4 .
91
.It Fl e , Fl F
92
Equivalent to
93
.Fl t Ar fD .
94
.It Fl f
95
Equivalent to
96
.Fl t Ar fF .
97
.It Fl H , Fl X
98
Equivalent to
99
.Fl t Ar x4 .
100
.It Fl h , Fl x
101
Equivalent to
102
.Fl t Ar x2 .
103
.It Fl I , Fl L , Fl l
104
Equivalent to
105
.Fl t Ar dL .
106
.It Fl i
107
Equivalent to
108
.Fl t Ar dI .
109
.It Fl j Ar skip
110
Skip
111
.Ar skip
112
bytes of the combined input before dumping. The number may be followed by one
113
of
114
.Ql b ,
115
.Ql k
116
or
117
.Ql m
118
which specify the units of the number as blocks (512 bytes), kilobytes and
119
megabytes, respectively.
120
.It Fl N Ar length
121
Dump at most
122
.Ar length
123
bytes of input.
124
.It Fl O
125
Equivalent to
126
.Fl t Ar o4 .
127
.It Fl s
128
Equivalent to
129
.Fl t Ar d2 .
130
.It Fl t Ar type
131
Specify the output format.
132
.Ar type
133
is a string containing one or more of the following kinds of type specifiers:
134
.Bl -tag -width indent
135
.It Cm a
136
Named characters
137
.Pq Sq ASCII .
138
.It Cm c
139
Characters.
140
.It Cm [d|o|u|x][C|S|I|L| Ns Ar n Ns ]
141
Signed decimal
142
.Pq Ql d ,
143
octal
144
.Pq Ql o ,
145
unsigned decimal
146
.Pq Ql u
147
or
148
hexadecimal
149
.Pq Ql x .
150
Followed by an optional size specifier, which may be either
151
.Ql C Pq "char" ,
152
.Ql S Pq "short" ,
153
.Ql I Pq "int" ,
154
.Ql L Pq "long" ,
155
or a byte count as a decimal integer.
156
.It Cm f[F|D|L| Ns Ar n Ns ]
157
Floating-point number.
158
Followed by an optional size specifier, which may be either
159
.Ql F Pq "float" ,
160
.Ql D Pq "double"
70
or
161
or
71
.Fl w
162
.Ql L Pq "long double" .
72
options, nor is compatibility provided for the ``label'' component
163
.El
73
of the offset syntax.
164
.It Fl v
165
Write all input data, instead of replacing lines of duplicate values with a
166
.Ql * .
167
.El
168
.Pp
169
Multiple options that specify output format may be used; the output will
170
contain one line for each format.
171
.Pp
172
If no output format is specified,
173
.Fl t Ar oS
174
is assumed.
175
.Sh DIAGNOSTICS
176
.Ex -std
74
.Sh SEE ALSO
177
.Sh SEE ALSO
75
.Xr hexdump 1 ,
178
.Xr hexdump 1 ,
76
.Xr strings 1
179
.Xr strings 1
77
.Sh BUGS
180
.Sh STANDARDS
78
Quite a few.
181
The
182
.Nm
183
utility is expected to conform to
184
.St -p1003.1-2001 .
79
.Sh HISTORY
185
.Sh HISTORY
80
A
186
A
81
.Nm
187
.Nm
82
command appeared in
188
command appeared in
83
.At v1 .
189
.At v1 .
190
.Sh BUGS
191
The
192
.Sq "long double"
193
data type,
194
.Fl t Ar fL ,
195
is not supported.
(-)odsyntax.c (-54 / +187 lines)
Lines 43-58 Link Here
43
43
44
#include <ctype.h>
44
#include <ctype.h>
45
#include <err.h>
45
#include <err.h>
46
#include <errno.h>
46
#include <stdio.h>
47
#include <stdio.h>
47
#include <stdlib.h>
48
#include <stdlib.h>
48
#include <unistd.h>
49
#include <unistd.h>
49
50
50
#include "hexdump.h"
51
#include "hexdump.h"
51
52
52
int deprecated;
53
#define PADDING	"         "
53
54
55
int odmode;
56
57
static void odadd(const char *);
58
static void odformat(const char *);
54
static void odoffset(int, char ***);
59
static void odoffset(int, char ***);
55
static void odprecede(void);
56
60
57
void
61
void
58
oldsyntax(argc, argvp)
62
oldsyntax(argc, argvp)
Lines 62-152 Link Here
62
	extern enum _vflag vflag;
66
	extern enum _vflag vflag;
63
	extern FS *fshead;
67
	extern FS *fshead;
64
	int ch;
68
	int ch;
65
	char **argv;
69
	char **argv, *end;
70
71
	/* Add initial (default) address format. -A may change it later. */
72
#define	TYPE_OFFSET	7
73
	add("\"%07.7_Ao\n\"");
74
	add("\"%07.7_ao  \"");
66
75
67
	deprecated = 1;
76
	odmode = 1;
68
	argv = *argvp;
77
	argv = *argvp;
69
	while ((ch = getopt(argc, argv, "aBbcDdeFfHhIiLlOoPpswvXx")) != -1)
78
	while ((ch = getopt(argc, argv, "A:aBbcDdeFfHhIij:LlN:Oost:vXx")) != -1)
70
		switch (ch) {
79
		switch (ch) {
80
		case 'A':
81
			switch (*optarg) {
82
			case 'd':
83
			case 'o':
84
			case 'x':
85
				fshead->nextfu->fmt[TYPE_OFFSET] = *optarg;
86
				fshead->nextfs->nextfu->fmt[TYPE_OFFSET] = *optarg;
87
				break;
88
			case 'n':
89
				fshead->nextfu->fmt = "";
90
				fshead->nextfs->nextfu->fmt = PADDING;
91
				break;
92
			default:
93
				errx(1, "%s: invalid address base", optarg);
94
			}
95
			break;
71
		case 'a':
96
		case 'a':
72
			odprecede();
97
			odformat("a");
73
			add("16/1 \"%3_u \" \"\\n\"");
74
			break;
98
			break;
75
		case 'B':
99
		case 'B':
76
		case 'o':
100
		case 'o':
77
			odprecede();
101
			odformat("o2");
78
			add("8/2 \" %06o \" \"\\n\"");
79
			break;
102
			break;
80
		case 'b':
103
		case 'b':
81
			odprecede();
104
			odformat("o1");
82
			add("16/1 \"%03o \" \"\\n\"");
83
			break;
105
			break;
84
		case 'c':
106
		case 'c':
85
			odprecede();
107
			odformat("c");
86
			add("16/1 \"%3_c \" \"\\n\"");
87
			break;
108
			break;
88
		case 'd':
109
		case 'd':
89
			odprecede();
110
			odformat("u2");
90
			add("8/2 \"  %05u \" \"\\n\"");
91
			break;
111
			break;
92
		case 'D':
112
		case 'D':
93
			odprecede();
113
			odformat("u4");
94
			add("4/4 \"     %010u \" \"\\n\"");
95
			break;
114
			break;
96
		case 'e':		/* undocumented in od */
115
		case 'e':		/* undocumented in od */
97
		case 'F':
116
		case 'F':
98
			odprecede();
117
			odformat("fD");
99
			add("2/8 \"          %21.14e \" \"\\n\"");
100
			break;
118
			break;
101
102
		case 'f':
119
		case 'f':
103
			odprecede();
120
			odformat("fF");
104
			add("4/4 \" %14.7e \" \"\\n\"");
105
			break;
121
			break;
106
		case 'H':
122
		case 'H':
107
		case 'X':
123
		case 'X':
108
			odprecede();
124
			odformat("x4");
109
			add("4/4 \"       %08x \" \"\\n\"");
110
			break;
125
			break;
111
		case 'h':
126
		case 'h':
112
		case 'x':
127
		case 'x':
113
			odprecede();
128
			odformat("x2");
114
			add("8/2 \"   %04x \" \"\\n\"");
115
			break;
129
			break;
116
		case 'I':
130
		case 'I':
117
		case 'L':
131
		case 'L':
118
		case 'l':
132
		case 'l':
119
			odprecede();
133
			odformat("dL");
120
			add("4/4 \"    %11d \" \"\\n\"");
121
			break;
134
			break;
122
		case 'i':
135
		case 'i':
123
			odprecede();
136
			odformat("dI");
124
			add("8/2 \" %6d \" \"\\n\"");
137
			break;
138
		case 'j':
139
			errno = 0;
140
			skip = (off_t)strtoul(optarg, &end, 0);
141
			if (*end == 'b')
142
				skip *= 512;
143
			else if (*end == 'k')
144
				skip *= 1024;
145
			else if (*end == 'm')
146
				skip *= 1048576L;
147
			if (errno != 0 || strlen(end) > 1)
148
				errx(1, "%s: invalid skip amount", optarg);
149
			break;
150
		case 'N':
151
			if ((length = atoi(optarg)) <= 0)
152
				errx(1, "%s: invalid length", optarg);
125
			break;
153
			break;
126
		case 'O':
154
		case 'O':
127
			odprecede();
155
			odformat("o4");
128
			add("4/4 \"    %011o \" \"\\n\"");
156
			break;
157
		case 's':
158
			odformat("d2");
129
			break;
159
			break;
160
		case 't':
161
			odformat(optarg);
162
			break;
130
		case 'v':
163
		case 'v':
131
			vflag = ALL;
164
			vflag = ALL;
132
			break;
165
			break;
133
		case 'P':
134
		case 'p':
135
		case 's':
136
		case 'w':
137
		case '?':
166
		case '?':
138
		default:
167
		default:
139
			warnx("od(1) has been deprecated for hexdump(1)");
140
			if (ch != '?')
141
				warnx("hexdump(1) compatibility doesn't support the -%c option%s",
142
				    ch, ch == 's' ? "; see strings(1)" : "");
143
			usage();
168
			usage();
144
		}
169
		}
145
170
146
	if (!fshead) {
171
	if (fshead->nextfs->nextfs == NULL)
147
		add("\"%07.7_Ao\n\"");
172
		odformat("oS");
148
		add("\"%07.7_ao  \" 8/2 \"%06o \" \"\\n\"");
149
	}
150
173
151
	argc -= optind;
174
	argc -= optind;
152
	*argvp += optind;
175
	*argvp += optind;
Lines 160-166 Link Here
160
	int argc;
183
	int argc;
161
	char ***argvp;
184
	char ***argvp;
162
{
185
{
163
	extern off_t skip;
164
	unsigned char *p, *num, *end;
186
	unsigned char *p, *num, *end;
165
	int base;
187
	int base;
166
188
Lines 241-247 Link Here
241
	 * If the offset uses a non-octal base, the base of the offset
263
	 * If the offset uses a non-octal base, the base of the offset
242
	 * is changed as well.  This isn't pretty, but it's easy.
264
	 * is changed as well.  This isn't pretty, but it's easy.
243
	 */
265
	 */
244
#define	TYPE_OFFSET	7
245
	if (base == 16) {
266
	if (base == 16) {
246
		fshead->nextfu->fmt[TYPE_OFFSET] = 'x';
267
		fshead->nextfu->fmt[TYPE_OFFSET] = 'x';
247
		fshead->nextfs->nextfu->fmt[TYPE_OFFSET] = 'x';
268
		fshead->nextfs->nextfu->fmt[TYPE_OFFSET] = 'x';
Lines 254-268 Link Here
254
	(*argvp)[1] = NULL;
275
	(*argvp)[1] = NULL;
255
}
276
}
256
277
278
static void
279
odformat(const char *fmt)
280
{
281
	size_t size;
282
	unsigned long long n;
283
	int digits;
284
	char *hdfmt, fchar, *end;
285
286
	while (*fmt != '\0') {
287
		switch ((fchar = *fmt++)) {
288
		case 'a':
289
			odadd("16/1 \"%3_u \" \"\\n\"");
290
			break;
291
		case 'c':
292
			odadd("16/1 \"%3_c \" \"\\n\"");
293
			break;
294
		case 'o':
295
		case 'u':
296
		case 'd':
297
		case 'x':
298
			size = sizeof(int);
299
			switch (*fmt) {
300
			case 'C':
301
				size = sizeof(char);
302
				fmt++;
303
				break;
304
			case 'I':
305
				size = sizeof(int);
306
				fmt++;
307
				break;
308
			case 'L':
309
				size = sizeof(long);
310
				fmt++;
311
				break;
312
			case 'S':
313
				size = sizeof(short);
314
				fmt++;
315
				break;
316
			default:
317
				if (isdigit(*fmt)) {
318
					errno = 0;
319
					size = strtol(fmt, &end, 10);
320
					if (errno != 0 || size <= 0)
321
						errx(1, "bad size");
322
					if (size != sizeof(char) &&
323
					    size != sizeof(short) &&
324
					    size != sizeof(int) &&
325
					    size != sizeof(long))
326
						errx(1,
327
						    "unsupported int size %ld",
328
						    size);
329
					fmt = (const char *)end;
330
				}
331
			}
332
			n = (1ULL << (8 * size)) - 1;
333
			digits = 0;
334
			while (n != 0) {
335
				digits++;
336
				n >>= (fchar == 'o' || fchar == 'd') ? 3 : 4;
337
			}
338
			asprintf(&hdfmt, "%d/%d \"%%%s%d%c \" \"\\n\"",
339
			    16 / size, size, fchar == 'd' ? "" : "0",
340
			    digits, fchar);
341
			if (hdfmt == NULL)
342
				err(1, NULL);
343
			odadd(hdfmt);
344
			free(hdfmt);
345
			break;
346
		case 'f':
347
			size = sizeof(double);
348
			switch (*fmt) {
349
			case 'F':
350
				size = sizeof(float);
351
				fmt++;
352
				break;
353
			case 'D':
354
				size = sizeof(double);
355
				fmt++;
356
				break;
357
			case 'L':
358
				size = sizeof(long double);
359
				fmt++;
360
				break;
361
			default:
362
				if (isdigit(*fmt)) {
363
					errno = 0;
364
					size = strtol(fmt, &end, 10);
365
					if (errno != 0 || size <= 0)
366
						errx(1, "bad size");
367
					fmt = (const char *)end;
368
				}
369
			}
370
			switch (size) {
371
			case sizeof(float):
372
				odadd("4/4 \" %14.7e \" \"\\n\"");
373
				break;
374
			case sizeof(double):
375
				odadd("2/8 \" %21.14e \" \"\\n\"");
376
				break;
377
			case sizeof(long double):
378
#ifdef notyet
379
				odadd("1/16 \" %21.14Le \" \"\\n\"");
380
				break;
381
#endif
382
			default:
383
				errx(1, "unsupported FP size %ld", size);
384
			}
385
			break;
386
		default:
387
			errx(1, "%s: bad format", fmt);
388
		}
389
	}
390
}
391
257
static void
392
static void
258
odprecede()
393
odadd(const char *fmt)
259
{
394
{
260
	static int first = 1;
395
	static int needpad;
261
396
262
	if (first) {
397
	if (needpad)
263
		first = 0;
398
		add("\""PADDING"\"");
264
		add("\"%07.7_Ao\n\"");
399
	add(fmt);
265
		add("\"%07.7_ao  \"");
400
	needpad = 1;
266
	} else
267
		add("\"         \"");
268
}
401
}

Return to bug 36783