1 /* Synched up with: FSF 19.28. */
12 #if __STDC__ || defined(STDC_HEADERS)
18 #define DEFAULT_GROUPING 0x01
19 #define DEFAULT_BASE 16
26 int base = DEFAULT_BASE, un_flag = FALSE, iso_flag = FALSE, endian = 1;
27 int group_by = DEFAULT_GROUPING;
33 main (int argc, char *argv[])
35 register long address;
39 progname = *argv++; --argc;
48 ** -iso iso character set.
49 ** -big-endian Big Endian
50 ** -little-endian Little Endian
51 ** -un || -de from hexl format to binary.
52 ** -- End switch list.
53 ** <filename> dump filename
54 ** - (as filename == stdin)
57 while (*argv && *argv[0] == '-' && (*argv)[1])
60 if (!strcmp (*argv, "--"))
65 else if (!strcmp (*argv, "-un") || !strcmp (*argv, "-de"))
70 else if (!strcmp (*argv, "-hex"))
75 else if (!strcmp (*argv, "-iso"))
80 else if (!strcmp (*argv, "-oct"))
85 else if (!strcmp (*argv, "-big-endian"))
90 else if (!strcmp (*argv, "-little-endian"))
95 else if (!strcmp (*argv, "-group-by-8-bits"))
100 else if (!strcmp (*argv, "-group-by-16-bits"))
105 else if (!strcmp (*argv, "-group-by-32-bits"))
110 else if (!strcmp (*argv, "-group-by-64-bits"))
118 (void) fprintf (stderr, "%s: invalid switch: \"%s\".\n", progname,
130 char *filename = *argv++;
132 if (!strcmp (filename, "-"))
134 else if ((fp = fopen (filename, "r")) == NULL)
146 _setmode (_fileno (stdout), O_BINARY);
150 register int i, c, d;
152 #define hexchar(x) (isdigit (x) ? x - '0' : x - 'a' + 10)
154 fread (buf, 1, 10, fp); /* skip 10 bytes */
156 for (i=0; i < 16; ++i)
158 if ((c = getc (fp)) == ' ' || c == EOF)
162 c = hexchar (c) * 0x10 + hexchar (d);
165 if ((i&group_by) == group_by)
171 while ((c = getc (fp)) != '\n' && c != EOF)
182 fread (buf, 1, 18, fp); /* skip 18 bytes */
189 _setmode (_fileno (fp), O_BINARY);
198 for (i=0; i < 16; ++i)
200 if ((c = getc (fp)) == EOF)
211 (void) printf ("%08lx: ", address);
215 (c < 0x20 || (c >= 0x7F && c < 0xa0)) ? '.' :c;
217 string[i+1] = (c < 0x20 || c >= 0x7F) ? '.' : c;
219 (void) printf ("%02x", c);
222 if ((i&group_by) == group_by)
240 } while (*argv != NULL);
247 (void) fprintf (stderr, "usage: %s [-de] [-iso]\n", progname);