Mercurial > emacs
annotate lib-src/hexl.c @ 87160:1c8ae140143d
(allout-write-file-hook-handler): Revert previous change.
author | Glenn Morris <rgm@gnu.org> |
---|---|
date | Fri, 07 Dec 2007 05:17:08 +0000 |
parents | 1f2482de3237 |
children | 5714ff101fd9 f55f9811f5d7 |
rev | line source |
---|---|
19339
4a529ce5a52e
Add copyright and permission notices.
Richard M. Stallman <rms@gnu.org>
parents:
19338
diff
changeset
|
1 /* Convert files for Emacs Hexl mode. |
75250
6d19c76d81c5
Update copyright for years from Emacs 21 to present (mainly adding
Glenn Morris <rgm@gnu.org>
parents:
68647
diff
changeset
|
2 Copyright (C) 1989, 2001, 2002, 2003, 2004, 2005, |
6d19c76d81c5
Update copyright for years from Emacs 21 to present (mainly adding
Glenn Morris <rgm@gnu.org>
parents:
68647
diff
changeset
|
3 2006, 2007 Free Software Foundation, Inc. |
19339
4a529ce5a52e
Add copyright and permission notices.
Richard M. Stallman <rms@gnu.org>
parents:
19338
diff
changeset
|
4 |
4a529ce5a52e
Add copyright and permission notices.
Richard M. Stallman <rms@gnu.org>
parents:
19338
diff
changeset
|
5 This file is not considered part of GNU Emacs. |
4a529ce5a52e
Add copyright and permission notices.
Richard M. Stallman <rms@gnu.org>
parents:
19338
diff
changeset
|
6 |
4a529ce5a52e
Add copyright and permission notices.
Richard M. Stallman <rms@gnu.org>
parents:
19338
diff
changeset
|
7 This program is free software; you can redistribute it and/or modify |
4a529ce5a52e
Add copyright and permission notices.
Richard M. Stallman <rms@gnu.org>
parents:
19338
diff
changeset
|
8 it under the terms of the GNU General Public License as published by |
78257
1f2482de3237
Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents:
75250
diff
changeset
|
9 the Free Software Foundation; either version 3, or (at your option) |
1f2482de3237
Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents:
75250
diff
changeset
|
10 any later version. |
19339
4a529ce5a52e
Add copyright and permission notices.
Richard M. Stallman <rms@gnu.org>
parents:
19338
diff
changeset
|
11 |
4a529ce5a52e
Add copyright and permission notices.
Richard M. Stallman <rms@gnu.org>
parents:
19338
diff
changeset
|
12 This program is distributed in the hope that it will be useful, |
4a529ce5a52e
Add copyright and permission notices.
Richard M. Stallman <rms@gnu.org>
parents:
19338
diff
changeset
|
13 but WITHOUT ANY WARRANTY; without even the implied warranty of |
4a529ce5a52e
Add copyright and permission notices.
Richard M. Stallman <rms@gnu.org>
parents:
19338
diff
changeset
|
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4a529ce5a52e
Add copyright and permission notices.
Richard M. Stallman <rms@gnu.org>
parents:
19338
diff
changeset
|
15 GNU General Public License for more details. |
4a529ce5a52e
Add copyright and permission notices.
Richard M. Stallman <rms@gnu.org>
parents:
19338
diff
changeset
|
16 |
4a529ce5a52e
Add copyright and permission notices.
Richard M. Stallman <rms@gnu.org>
parents:
19338
diff
changeset
|
17 You should have received a copy of the GNU General Public License |
78257
1f2482de3237
Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents:
75250
diff
changeset
|
18 along with this program; see the file COPYING. If not, write to the |
1f2482de3237
Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents:
75250
diff
changeset
|
19 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
1f2482de3237
Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents:
75250
diff
changeset
|
20 Boston, MA 02110-1301, USA. */ |
19339
4a529ce5a52e
Add copyright and permission notices.
Richard M. Stallman <rms@gnu.org>
parents:
19338
diff
changeset
|
21 |
15903
0a93a0afdd74
Include <config.h>, so DOS_NT is defined on MSDOS.
Richard M. Stallman <rms@gnu.org>
parents:
15100
diff
changeset
|
22 #ifdef HAVE_CONFIG_H |
0a93a0afdd74
Include <config.h>, so DOS_NT is defined on MSDOS.
Richard M. Stallman <rms@gnu.org>
parents:
15100
diff
changeset
|
23 #include <config.h> |
0a93a0afdd74
Include <config.h>, so DOS_NT is defined on MSDOS.
Richard M. Stallman <rms@gnu.org>
parents:
15100
diff
changeset
|
24 #endif |
0a93a0afdd74
Include <config.h>, so DOS_NT is defined on MSDOS.
Richard M. Stallman <rms@gnu.org>
parents:
15100
diff
changeset
|
25 |
26 | 26 #include <stdio.h> |
27 #include <ctype.h> | |
15100
85edb1a5281a
[DOSNT]: Include fcntl.h.
Richard M. Stallman <rms@gnu.org>
parents:
15019
diff
changeset
|
28 #ifdef DOS_NT |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
29 #include <fcntl.h> |
15008
aca392dc5b0f
[DJGPP v2]: Include io.h.
Richard M. Stallman <rms@gnu.org>
parents:
9491
diff
changeset
|
30 #if __DJGPP__ >= 2 |
aca392dc5b0f
[DJGPP v2]: Include io.h.
Richard M. Stallman <rms@gnu.org>
parents:
9491
diff
changeset
|
31 #include <io.h> |
aca392dc5b0f
[DJGPP v2]: Include io.h.
Richard M. Stallman <rms@gnu.org>
parents:
9491
diff
changeset
|
32 #endif |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
33 #endif |
15100
85edb1a5281a
[DOSNT]: Include fcntl.h.
Richard M. Stallman <rms@gnu.org>
parents:
15019
diff
changeset
|
34 #ifdef WINDOWSNT |
85edb1a5281a
[DOSNT]: Include fcntl.h.
Richard M. Stallman <rms@gnu.org>
parents:
15019
diff
changeset
|
35 #include <io.h> |
85edb1a5281a
[DOSNT]: Include fcntl.h.
Richard M. Stallman <rms@gnu.org>
parents:
15019
diff
changeset
|
36 #endif |
26 | 37 |
38 #define DEFAULT_GROUPING 0x01 | |
39 #define DEFAULT_BASE 16 | |
40 | |
41 #undef TRUE | |
42 #undef FALSE | |
43 #define TRUE (1) | |
44 #define FALSE (0) | |
45 | |
46 int base = DEFAULT_BASE, un_flag = FALSE, iso_flag = FALSE, endian = 1; | |
47 int group_by = DEFAULT_GROUPING; | |
48 char *progname; | |
49 | |
9491
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
8026
diff
changeset
|
50 void usage(); |
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
8026
diff
changeset
|
51 |
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
8026
diff
changeset
|
52 int |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
53 main (argc, argv) |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
54 int argc; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
55 char *argv[]; |
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 register long address; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
58 char string[18]; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
59 FILE *fp; |
26 | 60 |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
61 progname = *argv++; --argc; |
26 | 62 |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
63 /* |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
64 ** -hex hex dump |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
65 ** -oct Octal dump |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
66 ** -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
|
67 ** -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
|
68 ** -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
|
69 ** -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
|
70 ** -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
|
71 ** -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
|
72 ** -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
|
73 ** -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
|
74 ** -- End switch list. |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
75 ** <filename> dump filename |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
76 ** - (as filename == stdin) |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
77 */ |
42439
d8a417105504
Remove unnecessary whitespaces.
Pavel Janík <Pavel@Janik.cz>
parents:
19339
diff
changeset
|
78 |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
79 while (*argv && *argv[0] == '-' && (*argv)[1]) |
26 | 80 { |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
81 /* A switch! */ |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
82 if (!strcmp (*argv, "--")) |
26 | 83 { |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
84 --argc; argv++; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
85 break; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
86 } |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
87 else if (!strcmp (*argv, "-un") || !strcmp (*argv, "-de")) |
26 | 88 { |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
89 un_flag = TRUE; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
90 --argc; argv++; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
91 } |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
92 else if (!strcmp (*argv, "-hex")) |
26 | 93 { |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
94 base = 16; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
95 --argc; argv++; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
96 } |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
97 else if (!strcmp (*argv, "-iso")) |
26 | 98 { |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
99 iso_flag = TRUE; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
100 --argc; argv++; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
101 } |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
102 else if (!strcmp (*argv, "-oct")) |
26 | 103 { |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
104 base = 8; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
105 --argc; argv++; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
106 } |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
107 else if (!strcmp (*argv, "-big-endian")) |
26 | 108 { |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
109 endian = 1; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
110 --argc; argv++; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
111 } |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
112 else if (!strcmp (*argv, "-little-endian")) |
26 | 113 { |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
114 endian = 0; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
115 --argc; argv++; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
116 } |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
117 else if (!strcmp (*argv, "-group-by-8-bits")) |
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 group_by = 0x00; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
120 --argc; argv++; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
121 } |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
122 else if (!strcmp (*argv, "-group-by-16-bits")) |
26 | 123 { |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
124 group_by = 0x01; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
125 --argc; argv++; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
126 } |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
127 else if (!strcmp (*argv, "-group-by-32-bits")) |
26 | 128 { |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
129 group_by = 0x03; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
130 --argc; argv++; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
131 } |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
132 else if (!strcmp (*argv, "-group-by-64-bits")) |
26 | 133 { |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
134 group_by = 0x07; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
135 endian = 0; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
136 --argc; argv++; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
137 } |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
138 else |
26 | 139 { |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
140 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
|
141 *argv); |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
142 usage (); |
26 | 143 } |
144 } | |
145 | |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
146 do |
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 if (*argv == NULL) |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
149 fp = stdin; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
150 else |
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 char *filename = *argv++; |
26 | 153 |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
154 if (!strcmp (filename, "-")) |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
155 fp = stdin; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
156 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
|
157 { |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
158 perror (filename); |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
159 continue; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
160 } |
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 (un_flag) |
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 char buf[18]; |
26 | 166 |
15100
85edb1a5281a
[DOSNT]: Include fcntl.h.
Richard M. Stallman <rms@gnu.org>
parents:
15019
diff
changeset
|
167 #ifdef DOS_NT |
85edb1a5281a
[DOSNT]: Include fcntl.h.
Richard M. Stallman <rms@gnu.org>
parents:
15019
diff
changeset
|
168 #if (__DJGPP__ >= 2) || (defined WINDOWSNT) |
15018
2a4f0129d30d
(main) [DJGPP v2]: Don't change to binary for a tty.
Richard M. Stallman <rms@gnu.org>
parents:
15008
diff
changeset
|
169 if (!isatty (fileno (stdout))) |
2a4f0129d30d
(main) [DJGPP v2]: Don't change to binary for a tty.
Richard M. Stallman <rms@gnu.org>
parents:
15008
diff
changeset
|
170 setmode (fileno (stdout), O_BINARY); |
15008
aca392dc5b0f
[DJGPP v2]: Include io.h.
Richard M. Stallman <rms@gnu.org>
parents:
9491
diff
changeset
|
171 #else |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
172 (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
|
173 _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
|
174 #endif |
15008
aca392dc5b0f
[DJGPP v2]: Include io.h.
Richard M. Stallman <rms@gnu.org>
parents:
9491
diff
changeset
|
175 #endif |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
176 for (;;) |
26 | 177 { |
58078
5d803fae362c
(main): Init local var c to silence compiler.
Kim F. Storm <storm@cua.dk>
parents:
55442
diff
changeset
|
178 register int i, c = 0, d; |
26 | 179 |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
180 #define hexchar(x) (isdigit (x) ? x - '0' : x - 'a' + 10) |
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 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
|
183 |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
184 for (i=0; i < 16; ++i) |
26 | 185 { |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
186 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
|
187 break; |
26 | 188 |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
189 d = getc (fp); |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
190 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
|
191 putchar (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 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
|
194 getc (fp); |
26 | 195 } |
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 (c == ' ') |
26 | 198 { |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
199 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
|
200 ; |
26 | 201 |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
202 if (c == EOF) |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
203 break; |
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 else |
26 | 206 { |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
207 if (i < 16) |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
208 break; |
26 | 209 |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
210 fread (buf, 1, 18, fp); /* skip 18 bytes */ |
26 | 211 } |
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 else |
26 | 215 { |
15100
85edb1a5281a
[DOSNT]: Include fcntl.h.
Richard M. Stallman <rms@gnu.org>
parents:
15019
diff
changeset
|
216 #ifdef DOS_NT |
85edb1a5281a
[DOSNT]: Include fcntl.h.
Richard M. Stallman <rms@gnu.org>
parents:
15019
diff
changeset
|
217 #if (__DJGPP__ >= 2) || (defined WINDOWSNT) |
15019
30bc23af98e3
(main) [DJGPP v2]: Don't change to binary for a tty.
Richard M. Stallman <rms@gnu.org>
parents:
15018
diff
changeset
|
218 if (!isatty (fileno (fp))) |
30bc23af98e3
(main) [DJGPP v2]: Don't change to binary for a tty.
Richard M. Stallman <rms@gnu.org>
parents:
15018
diff
changeset
|
219 setmode (fileno (fp), O_BINARY); |
15008
aca392dc5b0f
[DJGPP v2]: Include io.h.
Richard M. Stallman <rms@gnu.org>
parents:
9491
diff
changeset
|
220 #else |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
221 (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
|
222 _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
|
223 #endif |
15008
aca392dc5b0f
[DJGPP v2]: Include io.h.
Richard M. Stallman <rms@gnu.org>
parents:
9491
diff
changeset
|
224 #endif |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
225 address = 0; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
226 string[0] = ' '; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
227 string[17] = '\0'; |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
228 for (;;) |
26 | 229 { |
58078
5d803fae362c
(main): Init local var c to silence compiler.
Kim F. Storm <storm@cua.dk>
parents:
55442
diff
changeset
|
230 register int i, c = 0; |
26 | 231 |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
232 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
|
233 { |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
234 if ((c = getc (fp)) == EOF) |
26 | 235 { |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
236 if (!i) |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
237 break; |
26 | 238 |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
239 fputs (" ", stdout); |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
240 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
|
241 } |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
242 else |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
243 { |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
244 if (!i) |
19338
653a7898590b
(main): Use %08lx instead of %08x in printf because the
Richard M. Stallman <rms@gnu.org>
parents:
15903
diff
changeset
|
245 printf ("%08lx: ", address); |
26 | 246 |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
247 if (iso_flag) |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
248 string[i+1] = |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
249 (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
|
250 else |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
251 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
|
252 |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
253 printf ("%02x", c); |
26 | 254 } |
255 | |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
256 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
|
257 putchar (' '); |
26 | 258 } |
259 | |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
260 if (i) |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
261 puts (string); |
26 | 262 |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
263 if (c == EOF) |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
264 break; |
26 | 265 |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
266 address += 0x10; |
26 | 267 |
268 } | |
269 } | |
270 | |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
271 if (fp != stdin) |
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
272 fclose (fp); |
26 | 273 |
274 } while (*argv != NULL); | |
55442
a47704955f8d
Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
275 return EXIT_SUCCESS; |
26 | 276 } |
277 | |
9491
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
8026
diff
changeset
|
278 void |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
279 usage () |
26 | 280 { |
5445
44e193cc8f49
Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents:
26
diff
changeset
|
281 fprintf (stderr, "usage: %s [-de] [-iso]\n", progname); |
55442
a47704955f8d
Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
282 exit (EXIT_FAILURE); |
26 | 283 } |
52401 | 284 |
285 /* arch-tag: 20e04fb7-926e-4e48-be86-64fe869ecdaa | |
286 (do not change this comment) */ | |
55442
a47704955f8d
Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
287 |
a47704955f8d
Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
288 /* hexl.c ends here */ |