1 /* Synched up with: FSF 19.28. */
11 #if __STDC__ || defined(STDC_HEADERS)
17 #define DEFAULT_GROUPING 0x01
18 #define DEFAULT_BASE 16
25 int base = DEFAULT_BASE, un_flag = FALSE, iso_flag = FALSE, endian = 1;
26 int group_by = DEFAULT_GROUPING;
32 main (int argc, char *argv[])
34 register long address;
38 progname = *argv++; --argc;
47 ** -iso iso character set.
48 ** -big-endian Big Endian
49 ** -little-endian Little Endian
50 ** -un || -de from hexl format to binary.
51 ** -- End switch list.
52 ** <filename> dump filename
53 ** - (as filename == stdin)
56 while (*argv && *argv[0] == '-' && (*argv)[1])
59 if (!strcmp (*argv, "--"))
64 else if (!strcmp (*argv, "-un") || !strcmp (*argv, "-de"))
69 else if (!strcmp (*argv, "-hex"))
74 else if (!strcmp (*argv, "-iso"))
79 else if (!strcmp (*argv, "-oct"))
84 else if (!strcmp (*argv, "-big-endian"))
89 else if (!strcmp (*argv, "-little-endian"))
94 else if (!strcmp (*argv, "-group-by-8-bits"))
99 else if (!strcmp (*argv, "-group-by-16-bits"))
104 else if (!strcmp (*argv, "-group-by-32-bits"))
109 else if (!strcmp (*argv, "-group-by-64-bits"))
117 (void) fprintf (stderr, "%s: invalid switch: \"%s\".\n", progname,
129 char *filename = *argv++;
131 if (!strcmp (filename, "-"))
133 else if ((fp = fopen (filename, "r")) == NULL)
145 (stdout)->_flag &= ~_IOTEXT; /* print binary */
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 (fp)->_flag &= ~_IOTEXT; /* read binary */
190 _setmode (fileno (fp), O_BINARY);
199 for (i=0; i < 16; ++i)
201 if ((c = getc (fp)) == EOF)
212 (void) printf ("%08lx: ", address);
216 (c < 0x20 || (c >= 0x7F && c < 0xa0)) ? '.' :c;
218 string[i+1] = (c < 0x20 || c >= 0x7F) ? '.' : c;
220 (void) printf ("%02x", c);
223 if ((i&group_by) == group_by)
241 } while (*argv != NULL);
248 (void) fprintf (stderr, "usage: %s [-de] [-iso]\n", progname);