7 #define DEFAULT_GROUPING 0x01
8 #define DEFAULT_BASE 16
15 extern void exit (), perror ();
17 int base
= DEFAULT_BASE
, un_flag
= FALSE
, iso_flag
= FALSE
, endian
= 1;
18 int group_by
= DEFAULT_GROUPING
;
25 register long address
;
29 progname
= *argv
++; --argc
;
38 ** -iso iso character set.
39 ** -big-endian Big Endian
40 ** -little-endian Little Endian
41 ** -un || -de from hexl format to binary.
42 ** -- End switch list.
43 ** <filename> dump filename
44 ** - (as filename == stdin)
47 while (*argv
&& *argv
[0] == '-' && (*argv
)[1])
50 if (!strcmp (*argv
, "--"))
55 else if (!strcmp (*argv
, "-un") || !strcmp (*argv
, "-de"))
60 else if (!strcmp (*argv
, "-hex"))
65 else if (!strcmp (*argv
, "-iso"))
70 else if (!strcmp (*argv
, "-oct"))
75 else if (!strcmp (*argv
, "-big-endian"))
80 else if (!strcmp (*argv
, "-little-endian"))
85 else if (!strcmp (*argv
, "-group-by-8-bits"))
90 else if (!strcmp (*argv
, "-group-by-16-bits"))
95 else if (!strcmp (*argv
, "-group-by-32-bits"))
100 else if (!strcmp (*argv
, "-group-by-64-bits"))
108 fprintf (stderr
, "%s: invalid switch: \"%s\".\n", progname
,
120 char *filename
= *argv
++;
122 if (!strcmp (filename
, "-"))
124 else if ((fp
= fopen (filename
, "r")) == NULL
)
136 (stdout
)->_flag
&= ~_IOTEXT
; /* print binary */
137 _setmode (fileno (stdout
), O_BINARY
);
141 register int i
, c
, d
;
143 #define hexchar(x) (isdigit (x) ? x - '0' : x - 'a' + 10)
145 fread (buf
, 1, 10, fp
); /* skip 10 bytes */
147 for (i
=0; i
< 16; ++i
)
149 if ((c
= getc (fp
)) == ' ' || c
== EOF
)
153 c
= hexchar (c
) * 0x10 + hexchar (d
);
156 if ((i
&group_by
) == group_by
)
162 while ((c
= getc (fp
)) != '\n' && c
!= EOF
)
173 fread (buf
, 1, 18, fp
); /* skip 18 bytes */
180 (fp
)->_flag
&= ~_IOTEXT
; /* read binary */
181 _setmode (fileno (fp
), O_BINARY
);
190 for (i
=0; i
< 16; ++i
)
192 if ((c
= getc (fp
)) == EOF
)
203 printf ("%08x: ", address
);
207 (c
< 0x20 || (c
>= 0x7F && c
< 0xa0)) ? '.' :c
;
209 string
[i
+1] = (c
< 0x20 || c
>= 0x7F) ? '.' : c
;
214 if ((i
&group_by
) == group_by
)
232 } while (*argv
!= NULL
);
238 fprintf (stderr
, "usage: %s [-de] [-iso]\n", progname
);