]>
code.delx.au - gnu-emacs/blob - lib-src/hexl.c
7 #define DEFAULT_GROUPING 0x01
8 #define DEFAULT_BASE 16
15 int base
= DEFAULT_BASE
, un_flag
= FALSE
, iso_flag
= FALSE
, endian
= 1;
16 int group_by
= DEFAULT_GROUPING
;
23 register long address
;
27 progname
= *argv
++; --argc
;
36 ** -iso iso character set.
37 ** -big-endian Big Endian
38 ** -little-endian Little Endian
39 ** -un || -de from hexl format to binary.
40 ** -- End switch list.
41 ** <filename> dump filename
42 ** - (as filename == stdin)
45 while (*argv
&& *argv
[0] == '-' && (*argv
)[1])
48 if (!strcmp (*argv
, "--"))
53 else if (!strcmp (*argv
, "-un") || !strcmp (*argv
, "-de"))
58 else if (!strcmp (*argv
, "-hex"))
63 else if (!strcmp (*argv
, "-iso"))
68 else if (!strcmp (*argv
, "-oct"))
73 else if (!strcmp (*argv
, "-big-endian"))
78 else if (!strcmp (*argv
, "-little-endian"))
83 else if (!strcmp (*argv
, "-group-by-8-bits"))
88 else if (!strcmp (*argv
, "-group-by-16-bits"))
93 else if (!strcmp (*argv
, "-group-by-32-bits"))
98 else if (!strcmp (*argv
, "-group-by-64-bits"))
106 fprintf (stderr
, "%s: invalid switch: \"%s\".\n", progname
,
118 char *filename
= *argv
++;
120 if (!strcmp (filename
, "-"))
122 else if ((fp
= fopen (filename
, "r")) == NULL
)
134 (stdout
)->_flag
&= ~_IOTEXT
; /* print binary */
135 _setmode (fileno (stdout
), O_BINARY
);
139 register int i
, c
, d
;
141 #define hexchar(x) (isdigit (x) ? x - '0' : x - 'a' + 10)
143 fread (buf
, 1, 10, fp
); /* skip 10 bytes */
145 for (i
=0; i
< 16; ++i
)
147 if ((c
= getc (fp
)) == ' ' || c
== EOF
)
151 c
= hexchar (c
) * 0x10 + hexchar (d
);
154 if ((i
&group_by
) == group_by
)
160 while ((c
= getc (fp
)) != '\n' && c
!= EOF
)
171 fread (buf
, 1, 18, fp
); /* skip 18 bytes */
178 (fp
)->_flag
&= ~_IOTEXT
; /* read binary */
179 _setmode (fileno (fp
), O_BINARY
);
188 for (i
=0; i
< 16; ++i
)
190 if ((c
= getc (fp
)) == EOF
)
201 printf ("%08x: ", address
);
205 (c
< 0x20 || (c
>= 0x7F && c
< 0xa0)) ? '.' :c
;
207 string
[i
+1] = (c
< 0x20 || c
>= 0x7F) ? '.' : c
;
212 if ((i
&group_by
) == group_by
)
230 } while (*argv
!= NULL
);
236 fprintf (stderr
, "usage: %s [-de] [-iso]\n", progname
);