Mercurial > emacs
annotate lib-src/hexl.c @ 6536:4fa1c2b2f1e9
(this_command, last_command): Declared.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Fri, 25 Mar 1994 23:49:50 +0000 |
parents | 44e193cc8f49 |
children | 6d1d2e86fb37 |
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 | |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
15 extern void exit (), perror (); |
26 | 16 |
17 int base = DEFAULT_BASE, un_flag = FALSE, iso_flag = FALSE, endian = 1; | |
18 int group_by = DEFAULT_GROUPING; | |
19 char *progname; | |
20 | |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
21 main (argc, argv) |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
22 int argc; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
23 char *argv[]; |
26 | 24 { |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
25 register long address; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
26 char string[18]; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
27 FILE *fp; |
26 | 28 |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
29 progname = *argv++; --argc; |
26 | 30 |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
31 /* |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
32 ** -hex hex dump |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
33 ** -oct Octal dump |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
34 ** -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
|
35 ** -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
|
36 ** -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
|
37 ** -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
|
38 ** -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
|
39 ** -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
|
40 ** -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
|
41 ** -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
|
42 ** -- End switch list. |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
43 ** <filename> dump filename |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
44 ** - (as filename == stdin) |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
45 */ |
26 | 46 |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
47 while (*argv && *argv[0] == '-' && (*argv)[1]) |
26 | 48 { |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
49 /* A switch! */ |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
50 if (!strcmp (*argv, "--")) |
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 --argc; argv++; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
53 break; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
54 } |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
55 else if (!strcmp (*argv, "-un") || !strcmp (*argv, "-de")) |
26 | 56 { |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
57 un_flag = TRUE; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
58 --argc; argv++; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
59 } |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
60 else if (!strcmp (*argv, "-hex")) |
26 | 61 { |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
62 base = 16; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
63 --argc; argv++; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
64 } |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
65 else if (!strcmp (*argv, "-iso")) |
26 | 66 { |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
67 iso_flag = TRUE; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
68 --argc; argv++; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
69 } |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
70 else if (!strcmp (*argv, "-oct")) |
26 | 71 { |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
72 base = 8; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
73 --argc; argv++; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
74 } |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
75 else if (!strcmp (*argv, "-big-endian")) |
26 | 76 { |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
77 endian = 1; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
78 --argc; argv++; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
79 } |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
80 else if (!strcmp (*argv, "-little-endian")) |
26 | 81 { |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
82 endian = 0; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
83 --argc; argv++; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
84 } |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
85 else if (!strcmp (*argv, "-group-by-8-bits")) |
26 | 86 { |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
87 group_by = 0x00; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
88 --argc; argv++; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
89 } |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
90 else if (!strcmp (*argv, "-group-by-16-bits")) |
26 | 91 { |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
92 group_by = 0x01; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
93 --argc; argv++; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
94 } |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
95 else if (!strcmp (*argv, "-group-by-32-bits")) |
26 | 96 { |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
97 group_by = 0x03; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
98 --argc; argv++; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
99 } |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
100 else if (!strcmp (*argv, "-group-by-64-bits")) |
26 | 101 { |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
102 group_by = 0x07; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
103 endian = 0; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
104 --argc; argv++; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
105 } |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
106 else |
26 | 107 { |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
108 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
|
109 *argv); |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
110 usage (); |
26 | 111 } |
112 } | |
113 | |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
114 do |
26 | 115 { |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
116 if (*argv == NULL) |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
117 fp = stdin; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
118 else |
26 | 119 { |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
120 char *filename = *argv++; |
26 | 121 |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
122 if (!strcmp (filename, "-")) |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
123 fp = stdin; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
124 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
|
125 { |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
126 perror (filename); |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
127 continue; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
128 } |
26 | 129 } |
130 | |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
131 if (un_flag) |
26 | 132 { |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
133 char buf[18]; |
26 | 134 |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
135 #ifdef MSDOS |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
136 (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
|
137 _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
|
138 #endif |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
139 for (;;) |
26 | 140 { |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
141 register int i, c, d; |
26 | 142 |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
143 #define hexchar(x) (isdigit (x) ? x - '0' : x - 'a' + 10) |
26 | 144 |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
145 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
|
146 |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
147 for (i=0; i < 16; ++i) |
26 | 148 { |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
149 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
|
150 break; |
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 d = getc (fp); |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
153 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
|
154 putchar (c); |
26 | 155 |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
156 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
|
157 getc (fp); |
26 | 158 } |
159 | |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
160 if (c == ' ') |
26 | 161 { |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
162 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
|
163 ; |
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 if (c == EOF) |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
166 break; |
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 else |
26 | 169 { |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
170 if (i < 16) |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
171 break; |
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 fread (buf, 1, 18, fp); /* skip 18 bytes */ |
26 | 174 } |
175 } | |
176 } | |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
177 else |
26 | 178 { |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
179 #ifdef MSDOS |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
180 (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
|
181 _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
|
182 #endif |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
183 address = 0; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
184 string[0] = ' '; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
185 string[17] = '\0'; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
186 for (;;) |
26 | 187 { |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
188 register int i, c; |
26 | 189 |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
190 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
|
191 { |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
192 if ((c = getc (fp)) == EOF) |
26 | 193 { |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
194 if (!i) |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
195 break; |
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 fputs (" ", stdout); |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
198 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
|
199 } |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
200 else |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
201 { |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
202 if (!i) |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
203 printf ("%08x: ", address); |
26 | 204 |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
205 if (iso_flag) |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
206 string[i+1] = |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
207 (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
|
208 else |
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] = (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
|
210 |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
211 printf ("%02x", c); |
26 | 212 } |
213 | |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
214 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
|
215 putchar (' '); |
26 | 216 } |
217 | |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
218 if (i) |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
219 puts (string); |
26 | 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 (c == EOF) |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
222 break; |
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 address += 0x10; |
26 | 225 |
226 } | |
227 } | |
228 | |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
229 if (fp != stdin) |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
230 fclose (fp); |
26 | 231 |
232 } 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
|
233 return 0; |
26 | 234 } |
235 | |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
236 usage () |
26 | 237 { |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
238 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
|
239 exit (1); |
26 | 240 } |