1 /* Synched up with: FSF 19.28. */
12 #if __STDC__ || defined(STDC_HEADERS)
20 #define DEFAULT_GROUPING 0x01
21 #define DEFAULT_BASE 16
28 int base = DEFAULT_BASE, un_flag = FALSE, iso_flag = FALSE, endian = 1;
29 int group_by = DEFAULT_GROUPING;
35 main (int argc, char *argv[])
37 register long address;
41 progname = *argv++; --argc;
50 ** -iso iso character set.
51 ** -big-endian Big Endian
52 ** -little-endian Little Endian
53 ** -un || -de from hexl format to binary.
54 ** -- End switch list.
55 ** <filename> dump filename
56 ** - (as filename == stdin)
59 while (*argv && *argv[0] == '-' && (*argv)[1])
62 if (!strcmp (*argv, "--"))
67 else if (!strcmp (*argv, "-un") || !strcmp (*argv, "-de"))
72 else if (!strcmp (*argv, "-hex"))
77 else if (!strcmp (*argv, "-iso"))
82 else if (!strcmp (*argv, "-oct"))
87 else if (!strcmp (*argv, "-big-endian"))
92 else if (!strcmp (*argv, "-little-endian"))
97 else if (!strcmp (*argv, "-group-by-8-bits"))
102 else if (!strcmp (*argv, "-group-by-16-bits"))
107 else if (!strcmp (*argv, "-group-by-32-bits"))
112 else if (!strcmp (*argv, "-group-by-64-bits"))
120 (void) fprintf (stderr, "%s: invalid switch: \"%s\".\n", progname,
132 char *filename = *argv++;
134 if (!strcmp (filename, "-"))
136 else if ((fp = fopen (filename, "r")) == NULL)
148 _setmode (_fileno (stdout), O_BINARY);
152 register int i, c = 0, d;
154 #define hexchar(x) (isdigit (x) ? x - '0' : x - 'a' + 10)
156 fread (buf, 1, 10, fp); /* skip 10 bytes */
158 for (i=0; i < 16; ++i)
160 if ((c = getc (fp)) == ' ' || c == EOF)
164 c = hexchar (c) * 0x10 + hexchar (d);
167 if ((i&group_by) == group_by)
173 while ((c = getc (fp)) != '\n' && c != EOF)
184 fread (buf, 1, 18, fp); /* skip 18 bytes */
191 _setmode (_fileno (fp), O_BINARY);
198 register int i, c = 0;
200 for (i=0; i < 16; ++i)
202 if ((c = getc (fp)) == EOF)
213 (void) printf ("%08lx: ", address);
217 (c < 0x20 || (c >= 0x7F && c < 0xa0)) ? '.' :c;
219 string[i+1] = (c < 0x20 || c >= 0x7F) ? '.' : c;
221 (void) printf ("%02x", c);
224 if ((i&group_by) == group_by)
242 } while (*argv != NULL);
249 fprintf (stderr, "Usage: %s [-de] [-iso]\n", progname);