4 #define DEFAULT_GROUPING 0x01
5 #define DEFAULT_BASE 16
12 extern void exit(), perror();
14 int base
= DEFAULT_BASE
, un_flag
= FALSE
, iso_flag
= FALSE
, endian
= 1;
15 int group_by
= DEFAULT_GROUPING
;
22 register long address
;
26 progname
= *argv
++; --argc
;
35 ** -iso iso character set.
36 ** -big-endian Big Endian
37 ** -little-endian Little Endian
38 ** -un || -de from hexl format to binary.
39 ** -- End switch list.
40 ** <filename> dump filename
41 ** - (as filename == stdin)
44 while (*argv
&& *argv
[0] == '-' && (*argv
)[1])
47 if (!strcmp(*argv
, "--"))
51 } else if (!strcmp(*argv
, "-un") || !strcmp(*argv
, "-de"))
55 } else if (!strcmp(*argv
, "-hex"))
59 } else if (!strcmp(*argv
, "-iso"))
63 } else if (!strcmp(*argv
, "-oct"))
67 } else if (!strcmp(*argv
, "-big-endian"))
71 } else if (!strcmp(*argv
, "-little-endian"))
75 } else if (!strcmp(*argv
, "-group-by-8-bits"))
79 } else if (!strcmp(*argv
, "-group-by-16-bits"))
83 } else if (!strcmp(*argv
, "-group-by-32-bits"))
87 } else if (!strcmp(*argv
, "-group-by-64-bits"))
94 (void) fprintf(stderr
, "%s: invalid switch: \"%s\".\n", progname
,
106 char *filename
= *argv
++;
108 if (!strcmp(filename
, "-"))
111 if ((fp
= fopen(filename
, "r")) == NULL
)
124 register int i
, c
, d
;
126 #define hexchar(x) (isdigit(x) ? x - '0' : x - 'a' + 10)
128 (void) fread(buf
, 1, 10, fp
); /* skip 10 bytes */
130 for (i
=0; i
< 16; ++i
)
132 if ((c
= getc(fp
)) == ' ' || c
== EOF
)
136 c
= hexchar(c
) * 0x10 + hexchar(d
);
139 if ((i
&group_by
) == group_by
)
145 while ((c
= getc(fp
)) != '\n' && c
!= EOF
)
156 (void) fread(buf
, 1, 18, fp
); /* skip 18 bytes */
169 for (i
=0; i
< 16; ++i
)
171 if ((c
= getc(fp
)) == EOF
)
176 (void) fputs(" ", stdout
);
182 (void) printf("%08x: ", address
);
186 (c
< 0x20 || (c
>= 0x7F && c
< 0xa0)) ? '.' :c
;
188 string
[i
+1] = (c
< 0x20 || c
>= 0x7F) ? '.' : c
;
190 (void) printf("%02x", c
);
193 if ((i
&group_by
) == group_by
)
211 } while (*argv
!= NULL
);
217 (void) fprintf(stderr
, "usage: %s [-de] [-iso]\n", progname
);