1 /* Convert files for Emacs Hexl mode.
2 Copyright (C) 1989 Free Software Foundation, Inc
4 This file is not considered part of GNU Emacs.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software Foundation,
18 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
36 #define DEFAULT_GROUPING 0x01
37 #define DEFAULT_BASE 16
44 int base
= DEFAULT_BASE
, un_flag
= FALSE
, iso_flag
= FALSE
, endian
= 1;
45 int group_by
= DEFAULT_GROUPING
;
55 register long address
;
59 progname
= *argv
++; --argc
;
68 ** -iso iso character set.
69 ** -big-endian Big Endian
70 ** -little-endian Little Endian
71 ** -un || -de from hexl format to binary.
72 ** -- End switch list.
73 ** <filename> dump filename
74 ** - (as filename == stdin)
77 while (*argv
&& *argv
[0] == '-' && (*argv
)[1])
80 if (!strcmp (*argv
, "--"))
85 else if (!strcmp (*argv
, "-un") || !strcmp (*argv
, "-de"))
90 else if (!strcmp (*argv
, "-hex"))
95 else if (!strcmp (*argv
, "-iso"))
100 else if (!strcmp (*argv
, "-oct"))
105 else if (!strcmp (*argv
, "-big-endian"))
110 else if (!strcmp (*argv
, "-little-endian"))
115 else if (!strcmp (*argv
, "-group-by-8-bits"))
120 else if (!strcmp (*argv
, "-group-by-16-bits"))
125 else if (!strcmp (*argv
, "-group-by-32-bits"))
130 else if (!strcmp (*argv
, "-group-by-64-bits"))
138 fprintf (stderr
, "%s: invalid switch: \"%s\".\n", progname
,
150 char *filename
= *argv
++;
152 if (!strcmp (filename
, "-"))
154 else if ((fp
= fopen (filename
, "r")) == NULL
)
166 #if (__DJGPP__ >= 2) || (defined WINDOWSNT)
167 if (!isatty (fileno (stdout
)))
168 setmode (fileno (stdout
), O_BINARY
);
170 (stdout
)->_flag
&= ~_IOTEXT
; /* print binary */
171 _setmode (fileno (stdout
), O_BINARY
);
176 register int i
, c
, d
;
178 #define hexchar(x) (isdigit (x) ? x - '0' : x - 'a' + 10)
180 fread (buf
, 1, 10, fp
); /* skip 10 bytes */
182 for (i
=0; i
< 16; ++i
)
184 if ((c
= getc (fp
)) == ' ' || c
== EOF
)
188 c
= hexchar (c
) * 0x10 + hexchar (d
);
191 if ((i
&group_by
) == group_by
)
197 while ((c
= getc (fp
)) != '\n' && c
!= EOF
)
208 fread (buf
, 1, 18, fp
); /* skip 18 bytes */
215 #if (__DJGPP__ >= 2) || (defined WINDOWSNT)
216 if (!isatty (fileno (fp
)))
217 setmode (fileno (fp
), O_BINARY
);
219 (fp
)->_flag
&= ~_IOTEXT
; /* read binary */
220 _setmode (fileno (fp
), O_BINARY
);
230 for (i
=0; i
< 16; ++i
)
232 if ((c
= getc (fp
)) == EOF
)
243 printf ("%08lx: ", address
);
247 (c
< 0x20 || (c
>= 0x7F && c
< 0xa0)) ? '.' :c
;
249 string
[i
+1] = (c
< 0x20 || c
>= 0x7F) ? '.' : c
;
254 if ((i
&group_by
) == group_by
)
272 } while (*argv
!= NULL
);
279 fprintf (stderr
, "usage: %s [-de] [-iso]\n", progname
);
283 /* arch-tag: 20e04fb7-926e-4e48-be86-64fe869ecdaa
284 (do not change this comment) */