Mercurial > emacs
annotate lib-src/hexl.c @ 7730:3846302b9c9c
(insert-directory): Use expanded file name to find handler.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sat, 28 May 1994 12:33:08 +0000 |
parents | 6d1d2e86fb37 |
children | cd7741bac302 |
rev | line source |
---|---|
26 | 1 #include <stdio.h> |
2 #include <ctype.h> | |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
3 #ifdef MSDOS |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
4 #include <fcntl.h> |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
5 #endif |
26 | 6 |
7 #define DEFAULT_GROUPING 0x01 | |
8 #define DEFAULT_BASE 16 | |
9 | |
10 #undef TRUE | |
11 #undef FALSE | |
12 #define TRUE (1) | |
13 #define FALSE (0) | |
14 | |
7196
6d1d2e86fb37
[MSDOS]: Don't define proto type for exit.
Richard M. Stallman <rms@gnu.org>
parents:
5445
diff
changeset
|
15 #ifndef MSDOS |
6d1d2e86fb37
[MSDOS]: Don't define proto type for exit.
Richard M. Stallman <rms@gnu.org>
parents:
5445
diff
changeset
|
16 /* Defined volatile by std.h in MsDos. */ |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
17 extern void exit (), perror (); |
7196
6d1d2e86fb37
[MSDOS]: Don't define proto type for exit.
Richard M. Stallman <rms@gnu.org>
parents:
5445
diff
changeset
|
18 #endif |
26 | 19 |
20 int base = DEFAULT_BASE, un_flag = FALSE, iso_flag = FALSE, endian = 1; | |
21 int group_by = DEFAULT_GROUPING; | |
22 char *progname; | |
23 | |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
24 main (argc, argv) |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
25 int argc; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
26 char *argv[]; |
26 | 27 { |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
28 register long address; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
29 char string[18]; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
30 FILE *fp; |
26 | 31 |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
32 progname = *argv++; --argc; |
26 | 33 |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
34 /* |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
35 ** -hex hex dump |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
36 ** -oct Octal dump |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
37 ** -group-by-8-bits |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
38 ** -group-by-16-bits |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
39 ** -group-by-32-bits |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
40 ** -group-by-64-bits |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
41 ** -iso iso character set. |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
42 ** -big-endian Big Endian |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
43 ** -little-endian Little Endian |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
44 ** -un || -de from hexl format to binary. |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
45 ** -- End switch list. |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
46 ** <filename> dump filename |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
47 ** - (as filename == stdin) |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
48 */ |
26 | 49 |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
50 while (*argv && *argv[0] == '-' && (*argv)[1]) |
26 | 51 { |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
52 /* A switch! */ |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
53 if (!strcmp (*argv, "--")) |
26 | 54 { |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
55 --argc; argv++; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
56 break; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
57 } |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
58 else if (!strcmp (*argv, "-un") || !strcmp (*argv, "-de")) |
26 | 59 { |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
60 un_flag = TRUE; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
61 --argc; argv++; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
62 } |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
63 else if (!strcmp (*argv, "-hex")) |
26 | 64 { |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
65 base = 16; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
66 --argc; argv++; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
67 } |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
68 else if (!strcmp (*argv, "-iso")) |
26 | 69 { |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
70 iso_flag = TRUE; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
71 --argc; argv++; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
72 } |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
73 else if (!strcmp (*argv, "-oct")) |
26 | 74 { |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
75 base = 8; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
76 --argc; argv++; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
77 } |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
78 else if (!strcmp (*argv, "-big-endian")) |
26 | 79 { |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
80 endian = 1; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
81 --argc; argv++; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
82 } |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
83 else if (!strcmp (*argv, "-little-endian")) |
26 | 84 { |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
85 endian = 0; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
86 --argc; argv++; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
87 } |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
88 else if (!strcmp (*argv, "-group-by-8-bits")) |
26 | 89 { |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
90 group_by = 0x00; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
91 --argc; argv++; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
92 } |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
93 else if (!strcmp (*argv, "-group-by-16-bits")) |
26 | 94 { |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
95 group_by = 0x01; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
96 --argc; argv++; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
97 } |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
98 else if (!strcmp (*argv, "-group-by-32-bits")) |
26 | 99 { |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
100 group_by = 0x03; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
101 --argc; argv++; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
102 } |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
103 else if (!strcmp (*argv, "-group-by-64-bits")) |
26 | 104 { |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
105 group_by = 0x07; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
106 endian = 0; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
107 --argc; argv++; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
108 } |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
109 else |
26 | 110 { |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
111 fprintf (stderr, "%s: invalid switch: \"%s\".\n", progname, |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
112 *argv); |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
113 usage (); |
26 | 114 } |
115 } | |
116 | |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
117 do |
26 | 118 { |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
119 if (*argv == NULL) |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
120 fp = stdin; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
121 else |
26 | 122 { |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
123 char *filename = *argv++; |
26 | 124 |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
125 if (!strcmp (filename, "-")) |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
126 fp = stdin; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
127 else if ((fp = fopen (filename, "r")) == NULL) |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
128 { |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
129 perror (filename); |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
130 continue; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
131 } |
26 | 132 } |
133 | |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
134 if (un_flag) |
26 | 135 { |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
136 char buf[18]; |
26 | 137 |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
138 #ifdef MSDOS |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
139 (stdout)->_flag &= ~_IOTEXT; /* print binary */ |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
140 _setmode (fileno (stdout), O_BINARY); |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
141 #endif |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
142 for (;;) |
26 | 143 { |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
144 register int i, c, d; |
26 | 145 |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
146 #define hexchar(x) (isdigit (x) ? x - '0' : x - 'a' + 10) |
26 | 147 |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
148 fread (buf, 1, 10, fp); /* skip 10 bytes */ |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
149 |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
150 for (i=0; i < 16; ++i) |
26 | 151 { |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
152 if ((c = getc (fp)) == ' ' || c == EOF) |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
153 break; |
26 | 154 |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
155 d = getc (fp); |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
156 c = hexchar (c) * 0x10 + hexchar (d); |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
157 putchar (c); |
26 | 158 |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
159 if ((i&group_by) == group_by) |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
160 getc (fp); |
26 | 161 } |
162 | |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
163 if (c == ' ') |
26 | 164 { |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
165 while ((c = getc (fp)) != '\n' && c != EOF) |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
166 ; |
26 | 167 |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
168 if (c == EOF) |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
169 break; |
26 | 170 } |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
171 else |
26 | 172 { |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
173 if (i < 16) |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
174 break; |
26 | 175 |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
176 fread (buf, 1, 18, fp); /* skip 18 bytes */ |
26 | 177 } |
178 } | |
179 } | |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
180 else |
26 | 181 { |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
182 #ifdef MSDOS |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
183 (fp)->_flag &= ~_IOTEXT; /* read binary */ |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
184 _setmode (fileno (fp), O_BINARY); |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
185 #endif |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
186 address = 0; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
187 string[0] = ' '; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
188 string[17] = '\0'; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
189 for (;;) |
26 | 190 { |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
191 register int i, c; |
26 | 192 |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
193 for (i=0; i < 16; ++i) |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
194 { |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
195 if ((c = getc (fp)) == EOF) |
26 | 196 { |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
197 if (!i) |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
198 break; |
26 | 199 |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
200 fputs (" ", stdout); |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
201 string[i+1] = '\0'; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
202 } |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
203 else |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
204 { |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
205 if (!i) |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
206 printf ("%08x: ", address); |
26 | 207 |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
208 if (iso_flag) |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
209 string[i+1] = |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
210 (c < 0x20 || (c >= 0x7F && c < 0xa0)) ? '.' :c; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
211 else |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
212 string[i+1] = (c < 0x20 || c >= 0x7F) ? '.' : c; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
213 |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
214 printf ("%02x", c); |
26 | 215 } |
216 | |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
217 if ((i&group_by) == group_by) |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
218 putchar (' '); |
26 | 219 } |
220 | |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
221 if (i) |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
222 puts (string); |
26 | 223 |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
224 if (c == EOF) |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
225 break; |
26 | 226 |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
227 address += 0x10; |
26 | 228 |
229 } | |
230 } | |
231 | |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
232 if (fp != stdin) |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
233 fclose (fp); |
26 | 234 |
235 } while (*argv != NULL); | |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
236 return 0; |
26 | 237 } |
238 | |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
239 usage () |
26 | 240 { |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
241 fprintf (stderr, "usage: %s [-de] [-iso]\n", progname); |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
242 exit (1); |
26 | 243 } |