annotate lib-src/hexl.c @ 55442:a47704955f8d

Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'. Likewise, replace 1 with `EXIT_FAILURE'. (main): Use `EXIT_SUCCESS' or `EXIT_FAILURE' for return value.
author Thien-Thi Nguyen <ttn@gnuvola.org>
date Sat, 08 May 2004 15:23:35 +0000
parents 695cf19ef79e
children 5d803fae362c 4c90ffeb71c5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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.
4a529ce5a52e Add copyright and permission notices.
Richard M. Stallman <rms@gnu.org>
parents: 19338
diff changeset
2 Copyright (C) 1989 Free Software Foundation, Inc
4a529ce5a52e Add copyright and permission notices.
Richard M. Stallman <rms@gnu.org>
parents: 19338
diff changeset
3
4a529ce5a52e Add copyright and permission notices.
Richard M. Stallman <rms@gnu.org>
parents: 19338
diff changeset
4 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
5
4a529ce5a52e Add copyright and permission notices.
Richard M. Stallman <rms@gnu.org>
parents: 19338
diff changeset
6 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
7 it under the terms of the GNU General Public License as published by
4a529ce5a52e Add copyright and permission notices.
Richard M. Stallman <rms@gnu.org>
parents: 19338
diff changeset
8 the Free Software Foundation; either version 2 of the License, or
4a529ce5a52e Add copyright and permission notices.
Richard M. Stallman <rms@gnu.org>
parents: 19338
diff changeset
9 (at your option) any later version.
4a529ce5a52e Add copyright and permission notices.
Richard M. Stallman <rms@gnu.org>
parents: 19338
diff changeset
10
4a529ce5a52e Add copyright and permission notices.
Richard M. Stallman <rms@gnu.org>
parents: 19338
diff changeset
11 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
12 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
13 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
14 GNU General Public License for more details.
4a529ce5a52e Add copyright and permission notices.
Richard M. Stallman <rms@gnu.org>
parents: 19338
diff changeset
15
4a529ce5a52e Add copyright and permission notices.
Richard M. Stallman <rms@gnu.org>
parents: 19338
diff changeset
16 You should have received a copy of the GNU General Public License
4a529ce5a52e Add copyright and permission notices.
Richard M. Stallman <rms@gnu.org>
parents: 19338
diff changeset
17 along with this program; if not, write to the Free Software Foundation,
4a529ce5a52e Add copyright and permission notices.
Richard M. Stallman <rms@gnu.org>
parents: 19338
diff changeset
18 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
4a529ce5a52e Add copyright and permission notices.
Richard M. Stallman <rms@gnu.org>
parents: 19338
diff changeset
19
15903
0a93a0afdd74 Include <config.h>, so DOS_NT is defined on MSDOS.
Richard M. Stallman <rms@gnu.org>
parents: 15100
diff changeset
20 #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
21 #include <config.h>
0a93a0afdd74 Include <config.h>, so DOS_NT is defined on MSDOS.
Richard M. Stallman <rms@gnu.org>
parents: 15100
diff changeset
22 #endif
0a93a0afdd74 Include <config.h>, so DOS_NT is defined on MSDOS.
Richard M. Stallman <rms@gnu.org>
parents: 15100
diff changeset
23
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
24 #include <stdio.h>
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
25 #include <ctype.h>
15100
85edb1a5281a [DOSNT]: Include fcntl.h.
Richard M. Stallman <rms@gnu.org>
parents: 15019
diff changeset
26 #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
27 #include <fcntl.h>
15008
aca392dc5b0f [DJGPP v2]: Include io.h.
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
28 #if __DJGPP__ >= 2
aca392dc5b0f [DJGPP v2]: Include io.h.
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
29 #include <io.h>
aca392dc5b0f [DJGPP v2]: Include io.h.
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
30 #endif
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
31 #endif
15100
85edb1a5281a [DOSNT]: Include fcntl.h.
Richard M. Stallman <rms@gnu.org>
parents: 15019
diff changeset
32 #ifdef WINDOWSNT
85edb1a5281a [DOSNT]: Include fcntl.h.
Richard M. Stallman <rms@gnu.org>
parents: 15019
diff changeset
33 #include <io.h>
85edb1a5281a [DOSNT]: Include fcntl.h.
Richard M. Stallman <rms@gnu.org>
parents: 15019
diff changeset
34 #endif
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
35
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
36 #define DEFAULT_GROUPING 0x01
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
37 #define DEFAULT_BASE 16
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
38
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
39 #undef TRUE
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
40 #undef FALSE
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
41 #define TRUE (1)
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
42 #define FALSE (0)
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
43
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
44 int base = DEFAULT_BASE, un_flag = FALSE, iso_flag = FALSE, endian = 1;
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
45 int group_by = DEFAULT_GROUPING;
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
46 char *progname;
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
47
9491
dd3b83e4ceb0 Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents: 8026
diff changeset
48 void usage();
dd3b83e4ceb0 Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents: 8026
diff changeset
49
dd3b83e4ceb0 Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents: 8026
diff changeset
50 int
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
51 main (argc, argv)
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
52 int argc;
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
53 char *argv[];
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
54 {
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
55 register long address;
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
56 char string[18];
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
57 FILE *fp;
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
58
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
59 progname = *argv++; --argc;
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
60
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
61 /*
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
62 ** -hex hex dump
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
63 ** -oct Octal dump
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
64 ** -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
65 ** -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
66 ** -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
67 ** -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
68 ** -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
69 ** -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
70 ** -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
71 ** -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
72 ** -- End switch list.
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
73 ** <filename> dump filename
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
74 ** - (as filename == stdin)
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
75 */
42439
d8a417105504 Remove unnecessary whitespaces.
Pavel Janík <Pavel@Janik.cz>
parents: 19339
diff changeset
76
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
77 while (*argv && *argv[0] == '-' && (*argv)[1])
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
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 /* A switch! */
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
80 if (!strcmp (*argv, "--"))
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
81 {
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
82 --argc; argv++;
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
83 break;
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, "-un") || !strcmp (*argv, "-de"))
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
86 {
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
87 un_flag = TRUE;
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, "-hex"))
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
91 {
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
92 base = 16;
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, "-iso"))
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
96 {
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
97 iso_flag = TRUE;
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, "-oct"))
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
101 {
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
102 base = 8;
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
103 --argc; argv++;
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
104 }
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
105 else if (!strcmp (*argv, "-big-endian"))
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
106 {
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
107 endian = 1;
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
108 --argc; argv++;
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
109 }
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
110 else if (!strcmp (*argv, "-little-endian"))
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
111 {
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
112 endian = 0;
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
113 --argc; argv++;
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
114 }
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
115 else if (!strcmp (*argv, "-group-by-8-bits"))
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
116 {
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
117 group_by = 0x00;
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
118 --argc; argv++;
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
119 }
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
120 else if (!strcmp (*argv, "-group-by-16-bits"))
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
121 {
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
122 group_by = 0x01;
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
123 --argc; argv++;
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
124 }
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
125 else if (!strcmp (*argv, "-group-by-32-bits"))
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
126 {
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
127 group_by = 0x03;
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
128 --argc; argv++;
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
129 }
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
130 else if (!strcmp (*argv, "-group-by-64-bits"))
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
131 {
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
132 group_by = 0x07;
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
133 endian = 0;
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
134 --argc; argv++;
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
135 }
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
136 else
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
137 {
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
138 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
139 *argv);
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
140 usage ();
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
141 }
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
142 }
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
143
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
144 do
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
145 {
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
146 if (*argv == NULL)
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
147 fp = stdin;
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
148 else
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
149 {
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
150 char *filename = *argv++;
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
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 (!strcmp (filename, "-"))
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
153 fp = stdin;
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
154 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
155 {
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
156 perror (filename);
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
157 continue;
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
158 }
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
159 }
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
160
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
161 if (un_flag)
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
162 {
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
163 char buf[18];
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
164
15100
85edb1a5281a [DOSNT]: Include fcntl.h.
Richard M. Stallman <rms@gnu.org>
parents: 15019
diff changeset
165 #ifdef DOS_NT
85edb1a5281a [DOSNT]: Include fcntl.h.
Richard M. Stallman <rms@gnu.org>
parents: 15019
diff changeset
166 #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
167 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
168 setmode (fileno (stdout), O_BINARY);
15008
aca392dc5b0f [DJGPP v2]: Include io.h.
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
169 #else
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
170 (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
171 _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
172 #endif
15008
aca392dc5b0f [DJGPP v2]: Include io.h.
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
173 #endif
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
174 for (;;)
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
175 {
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
176 register int i, c, d;
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
177
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
178 #define hexchar(x) (isdigit (x) ? x - '0' : x - 'a' + 10)
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
179
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
180 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
181
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
182 for (i=0; i < 16; ++i)
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
183 {
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
184 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
185 break;
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
186
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
187 d = getc (fp);
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
188 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
189 putchar (c);
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
190
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
191 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
192 getc (fp);
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
193 }
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
194
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
195 if (c == ' ')
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
196 {
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
197 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
198 ;
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
199
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
200 if (c == EOF)
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
201 break;
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
202 }
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
203 else
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
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 (i < 16)
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
206 break;
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
207
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
208 fread (buf, 1, 18, fp); /* skip 18 bytes */
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
209 }
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
210 }
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
211 }
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
212 else
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
213 {
15100
85edb1a5281a [DOSNT]: Include fcntl.h.
Richard M. Stallman <rms@gnu.org>
parents: 15019
diff changeset
214 #ifdef DOS_NT
85edb1a5281a [DOSNT]: Include fcntl.h.
Richard M. Stallman <rms@gnu.org>
parents: 15019
diff changeset
215 #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
216 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
217 setmode (fileno (fp), O_BINARY);
15008
aca392dc5b0f [DJGPP v2]: Include io.h.
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
218 #else
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
219 (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
220 _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
221 #endif
15008
aca392dc5b0f [DJGPP v2]: Include io.h.
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
222 #endif
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
223 address = 0;
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
224 string[0] = ' ';
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
225 string[17] = '\0';
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
226 for (;;)
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
227 {
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
228 register int i, c;
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
229
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
230 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
231 {
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
232 if ((c = getc (fp)) == EOF)
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
233 {
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
234 if (!i)
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
235 break;
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
236
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
237 fputs (" ", stdout);
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
238 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
239 }
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
240 else
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 if (!i)
19338
653a7898590b (main): Use %08lx instead of %08x in printf because the
Richard M. Stallman <rms@gnu.org>
parents: 15903
diff changeset
243 printf ("%08lx: ", address);
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
244
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
245 if (iso_flag)
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
246 string[i+1] =
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
247 (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
248 else
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
249 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
250
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
251 printf ("%02x", c);
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
252 }
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
253
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
254 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
255 putchar (' ');
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
256 }
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
257
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
258 if (i)
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
259 puts (string);
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
260
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
261 if (c == EOF)
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
262 break;
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
263
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
264 address += 0x10;
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
265
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
266 }
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
267 }
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
268
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
269 if (fp != stdin)
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
270 fclose (fp);
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
271
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
272 } 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
273 return EXIT_SUCCESS;
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
274 }
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
275
9491
dd3b83e4ceb0 Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents: 8026
diff changeset
276 void
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
277 usage ()
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
278 {
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
279 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
280 exit (EXIT_FAILURE);
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
281 }
52401
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 42439
diff changeset
282
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 42439
diff changeset
283 /* arch-tag: 20e04fb7-926e-4e48-be86-64fe869ecdaa
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 42439
diff changeset
284 (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
285
a47704955f8d Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 52401
diff changeset
286 /* hexl.c ends here */