annotate lib-src/hexl.c @ 15019:30bc23af98e3

(main) [DJGPP v2]: Don't change to binary for a tty.
author Richard M. Stallman <rms@gnu.org>
date Sun, 14 Apr 1996 17:11:47 +0000
parents 2a4f0129d30d
children 85edb1a5281a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1 #include <stdio.h>
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2 #include <ctype.h>
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
3 #ifdef MSDOS
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
4 #include <fcntl.h>
15008
aca392dc5b0f [DJGPP v2]: Include io.h.
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
5 #if __DJGPP__ >= 2
aca392dc5b0f [DJGPP v2]: Include io.h.
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
6 #include <io.h>
aca392dc5b0f [DJGPP v2]: Include io.h.
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
7 #endif
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
8 #endif
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
9
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
10 #define DEFAULT_GROUPING 0x01
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
11 #define DEFAULT_BASE 16
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
12
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
13 #undef TRUE
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
14 #undef FALSE
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
15 #define TRUE (1)
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
16 #define FALSE (0)
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
17
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
18 int base = DEFAULT_BASE, un_flag = FALSE, iso_flag = FALSE, endian = 1;
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
19 int group_by = DEFAULT_GROUPING;
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
20 char *progname;
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
21
9491
dd3b83e4ceb0 Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents: 8026
diff changeset
22 void usage();
dd3b83e4ceb0 Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents: 8026
diff changeset
23
dd3b83e4ceb0 Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents: 8026
diff changeset
24 int
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
25 main (argc, argv)
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
26 int argc;
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
27 char *argv[];
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
28 {
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
29 register long address;
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
30 char string[18];
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
31 FILE *fp;
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
32
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
33 progname = *argv++; --argc;
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
34
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
35 /*
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
36 ** -hex hex dump
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
37 ** -oct Octal dump
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
38 ** -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
39 ** -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
40 ** -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
41 ** -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
42 ** -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
43 ** -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
44 ** -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
45 ** -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
46 ** -- End switch list.
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
47 ** <filename> dump filename
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
48 ** - (as filename == stdin)
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
49 */
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
50
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
51 while (*argv && *argv[0] == '-' && (*argv)[1])
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
52 {
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
53 /* A switch! */
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
54 if (!strcmp (*argv, "--"))
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
55 {
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
56 --argc; argv++;
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
57 break;
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
58 }
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
59 else if (!strcmp (*argv, "-un") || !strcmp (*argv, "-de"))
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 un_flag = TRUE;
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
62 --argc; argv++;
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 else if (!strcmp (*argv, "-hex"))
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
65 {
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
66 base = 16;
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
67 --argc; argv++;
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
68 }
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
69 else if (!strcmp (*argv, "-iso"))
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
70 {
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
71 iso_flag = TRUE;
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
72 --argc; argv++;
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
73 }
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
74 else if (!strcmp (*argv, "-oct"))
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
75 {
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
76 base = 8;
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
77 --argc; argv++;
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
78 }
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
79 else if (!strcmp (*argv, "-big-endian"))
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 endian = 1;
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 }
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
84 else if (!strcmp (*argv, "-little-endian"))
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
85 {
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
86 endian = 0;
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
87 --argc; argv++;
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
88 }
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
89 else if (!strcmp (*argv, "-group-by-8-bits"))
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
90 {
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
91 group_by = 0x00;
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
92 --argc; argv++;
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
93 }
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
94 else if (!strcmp (*argv, "-group-by-16-bits"))
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
95 {
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
96 group_by = 0x01;
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
97 --argc; argv++;
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
98 }
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
99 else if (!strcmp (*argv, "-group-by-32-bits"))
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
100 {
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
101 group_by = 0x03;
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
102 --argc; argv++;
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
103 }
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
104 else if (!strcmp (*argv, "-group-by-64-bits"))
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
105 {
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
106 group_by = 0x07;
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
107 endian = 0;
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
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 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
113 *argv);
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
114 usage ();
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
115 }
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
116 }
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
117
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
118 do
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
119 {
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
120 if (*argv == NULL)
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
121 fp = stdin;
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
122 else
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 char *filename = *argv++;
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
125
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
126 if (!strcmp (filename, "-"))
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
127 fp = stdin;
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
128 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
129 {
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
130 perror (filename);
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
131 continue;
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
132 }
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
133 }
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
134
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
135 if (un_flag)
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
136 {
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
137 char buf[18];
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
138
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
139 #ifdef MSDOS
15008
aca392dc5b0f [DJGPP v2]: Include io.h.
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
140 #if __DJGPP__ >= 2
15018
2a4f0129d30d (main) [DJGPP v2]: Don't change to binary for a tty.
Richard M. Stallman <rms@gnu.org>
parents: 15008
diff changeset
141 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
142 setmode (fileno (stdout), O_BINARY);
15008
aca392dc5b0f [DJGPP v2]: Include io.h.
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
143 #else
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
144 (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
145 _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
146 #endif
15008
aca392dc5b0f [DJGPP v2]: Include io.h.
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
147 #endif
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
148 for (;;)
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 register int i, c, d;
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 #define hexchar(x) (isdigit (x) ? x - '0' : x - 'a' + 10)
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 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
155
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
156 for (i=0; i < 16; ++i)
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
157 {
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
158 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
159 break;
26
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 d = getc (fp);
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
162 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
163 putchar (c);
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 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
166 getc (fp);
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
167 }
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
168
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
169 if (c == ' ')
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
170 {
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
171 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
172 ;
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
173
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
174 if (c == EOF)
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
175 break;
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
176 }
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
177 else
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
178 {
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
179 if (i < 16)
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
180 break;
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, 18, fp); /* skip 18 bytes */
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
183 }
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
184 }
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 else
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
187 {
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
188 #ifdef MSDOS
15008
aca392dc5b0f [DJGPP v2]: Include io.h.
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
189 #if __DJGPP__ >= 2
15019
30bc23af98e3 (main) [DJGPP v2]: Don't change to binary for a tty.
Richard M. Stallman <rms@gnu.org>
parents: 15018
diff changeset
190 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
191 setmode (fileno (fp), O_BINARY);
15008
aca392dc5b0f [DJGPP v2]: Include io.h.
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
192 #else
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
193 (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
194 _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
195 #endif
15008
aca392dc5b0f [DJGPP v2]: Include io.h.
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
196 #endif
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
197 address = 0;
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
198 string[0] = ' ';
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
199 string[17] = '\0';
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
200 for (;;)
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 register int i, c;
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
203
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
204 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
205 {
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
206 if ((c = getc (fp)) == EOF)
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 if (!i)
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
209 break;
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
210
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
211 fputs (" ", stdout);
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
212 string[i+1] = '\0';
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
213 }
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
214 else
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
215 {
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
216 if (!i)
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
217 printf ("%08x: ", address);
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
218
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
219 if (iso_flag)
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
220 string[i+1] =
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
221 (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
222 else
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
223 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
224
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
225 printf ("%02x", c);
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
226 }
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 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
229 putchar (' ');
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
230 }
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 if (i)
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
233 puts (string);
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
234
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
235 if (c == EOF)
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
236 break;
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
237
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
238 address += 0x10;
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
239
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
240 }
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
241 }
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
242
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
243 if (fp != stdin)
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
244 fclose (fp);
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
245
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
246 } while (*argv != NULL);
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
247 return 0;
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
248 }
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
249
9491
dd3b83e4ceb0 Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents: 8026
diff changeset
250 void
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
251 usage ()
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
252 {
5445
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
253 fprintf (stderr, "usage: %s [-de] [-iso]\n", progname);
44e193cc8f49 Fix up whitespace. Get rid of spurious casts to void.
Richard M. Stallman <rms@gnu.org>
parents: 26
diff changeset
254 exit (1);
26
7c9f757a985a entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
255 }