annotate lib-src/hexl.c @ 112379:b14f98859016

Merge: build from gnulib a bit better; document autoreconf.
author Paul Eggert <eggert@cs.ucla.edu>
date Wed, 19 Jan 2011 15:59:52 -0800
parents ef719132ddfa
children b5017c649dfb
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.
101097
7851bdaa03ec Comment (add Author:, based on authors.el).
Glenn Morris <rgm@gnu.org>
parents: 100958
diff changeset
2 Copyright (C) 1989, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
112218
376148b31b5e Add 2011 to FSF/AIST copyright years.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
3 2009, 2010, 2011 Free Software Foundation, Inc.
101097
7851bdaa03ec Comment (add Author:, based on authors.el).
Glenn Morris <rgm@gnu.org>
parents: 100958
diff changeset
4
7851bdaa03ec Comment (add Author:, based on authors.el).
Glenn Morris <rgm@gnu.org>
parents: 100958
diff changeset
5 Author: Keith Gabryelski
7851bdaa03ec Comment (add Author:, based on authors.el).
Glenn Morris <rgm@gnu.org>
parents: 100958
diff changeset
6 (according to authors.el)
19339
4a529ce5a52e Add copyright and permission notices.
Richard M. Stallman <rms@gnu.org>
parents: 19338
diff changeset
7
4a529ce5a52e Add copyright and permission notices.
Richard M. Stallman <rms@gnu.org>
parents: 19338
diff changeset
8 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
9
94828
3a4bc081639c Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 79748
diff changeset
10 This program is free software: you can redistribute it and/or modify
19339
4a529ce5a52e Add copyright and permission notices.
Richard M. Stallman <rms@gnu.org>
parents: 19338
diff changeset
11 it under the terms of the GNU General Public License as published by
94828
3a4bc081639c Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 79748
diff changeset
12 the Free Software Foundation, either version 3 of the License, or
3a4bc081639c Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 79748
diff changeset
13 (at your option) any later version.
19339
4a529ce5a52e Add copyright and permission notices.
Richard M. Stallman <rms@gnu.org>
parents: 19338
diff changeset
14
4a529ce5a52e Add copyright and permission notices.
Richard M. Stallman <rms@gnu.org>
parents: 19338
diff changeset
15 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
16 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
17 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
18 GNU General Public License for more details.
4a529ce5a52e Add copyright and permission notices.
Richard M. Stallman <rms@gnu.org>
parents: 19338
diff changeset
19
4a529ce5a52e Add copyright and permission notices.
Richard M. Stallman <rms@gnu.org>
parents: 19338
diff changeset
20 You should have received a copy of the GNU General Public License
94828
3a4bc081639c Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 79748
diff changeset
21 along with this program. If not, see <http://www.gnu.org/licenses/>. */
3a4bc081639c Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 79748
diff changeset
22
19339
4a529ce5a52e Add copyright and permission notices.
Richard M. Stallman <rms@gnu.org>
parents: 19338
diff changeset
23
15903
0a93a0afdd74 Include <config.h>, so DOS_NT is defined on MSDOS.
Richard M. Stallman <rms@gnu.org>
parents: 15100
diff changeset
24 #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
25 #include <config.h>
0a93a0afdd74 Include <config.h>, so DOS_NT is defined on MSDOS.
Richard M. Stallman <rms@gnu.org>
parents: 15100
diff changeset
26 #endif
0a93a0afdd74 Include <config.h>, so DOS_NT is defined on MSDOS.
Richard M. Stallman <rms@gnu.org>
parents: 15100
diff changeset
27
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
28 #include <stdio.h>
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
29 #include <ctype.h>
15100
85edb1a5281a [DOSNT]: Include fcntl.h.
Richard M. Stallman <rms@gnu.org>
parents: 15019
diff changeset
30 #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
31 #include <fcntl.h>
15008
aca392dc5b0f [DJGPP v2]: Include io.h.
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
32 #if __DJGPP__ >= 2
aca392dc5b0f [DJGPP v2]: Include io.h.
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
33 #include <io.h>
aca392dc5b0f [DJGPP v2]: Include io.h.
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
34 #endif
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
35 #endif
15100
85edb1a5281a [DOSNT]: Include fcntl.h.
Richard M. Stallman <rms@gnu.org>
parents: 15019
diff changeset
36 #ifdef WINDOWSNT
85edb1a5281a [DOSNT]: Include fcntl.h.
Richard M. Stallman <rms@gnu.org>
parents: 15019
diff changeset
37 #include <io.h>
85edb1a5281a [DOSNT]: Include fcntl.h.
Richard M. Stallman <rms@gnu.org>
parents: 15019
diff changeset
38 #endif
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
39
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
40 #define DEFAULT_GROUPING 0x01
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
41 #define DEFAULT_BASE 16
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
42
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
43 #undef TRUE
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
44 #undef FALSE
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
45 #define TRUE (1)
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
46 #define FALSE (0)
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
47
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
48 int base = DEFAULT_BASE, un_flag = FALSE, iso_flag = FALSE, endian = 1;
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
49 int group_by = DEFAULT_GROUPING;
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
50 char *progname;
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
51
109511
09a43f890565 Add NO_RETURN specifiers to functions in lib-src.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109111
diff changeset
52 void usage(void) NO_RETURN;
9491
dd3b83e4ceb0 Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents: 8026
diff changeset
53
dd3b83e4ceb0 Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents: 8026
diff changeset
54 int
109111
52b76722152a Convert function definitions to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 106815
diff changeset
55 main (int argc, char **argv)
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
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
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 progname = *argv++; --argc;
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
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
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
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
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
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
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
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
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
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
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
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
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
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
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
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
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
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
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
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
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
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
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
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
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
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
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
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
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
143 }
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
144 }
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 do
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
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
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 char *filename = *argv++;
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
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
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
161 }
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 if (un_flag)
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
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
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
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
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
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
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 #define hexchar(x) (isdigit (x) ? x - '0' : x - 'a' + 10)
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
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
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
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
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
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
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
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
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
195 }
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 if (c == ' ')
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
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
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
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
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 else
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
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
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
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
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
211 }
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
212 }
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
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
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
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
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
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
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
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
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
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
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
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
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
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
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
254 }
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
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
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
258 }
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
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
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
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
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
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
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 }
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
269 }
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
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
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
273
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
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
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
276 }
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
277
9491
dd3b83e4ceb0 Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents: 8026
diff changeset
278 void
109111
52b76722152a Convert function definitions to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 106815
diff changeset
279 usage (void)
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
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
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
283 }
52401
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 42439
diff changeset
284
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 */