comparison lib-src/hexl.c @ 5491:06dd936cde16

Merge some stuff in lib-src -------------------- ChangeLog entries follow: -------------------- lib-src/ChangeLog addition: 2010-02-19 Ben Wing <ben@xemacs.org> * digest-doc.c: * digest-doc.c (main): * emacs.csh: * hexl.c: * hexl.c (Gabryelski): * hexl.c (main): * hexl.c (usage): * sorted-doc.c: * sorted-doc.c (fatal): * sorted-doc.c (xstrdup): * sorted-doc.c (main): * vcdiff: Merge up to FSF 23.1.92.
author Ben Wing <ben@xemacs.org>
date Fri, 19 Feb 2010 22:13:17 -0600
parents abe6d1db359e
children
comparison
equal deleted inserted replaced
5030:422b4b4fb2a6 5491:06dd936cde16
1 /* Synched up with: FSF 19.28. */ 1 /* Convert files for Emacs Hexl mode.
2 2 Copyright (C) 1989, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
3 2009, 2010 Free Software Foundation, Inc.
4 Copyright (C) 2010 Ben Wing.
5
6 Author: Keith Gabryelski
7 (according to authors.el)
8
9 This file is not considered part of XEmacs.
10
11 This program is free software: you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23
24 /* Synced up with: GNU 23.1.92. */
25 /* Synced by: Ben Wing, 2-17-10. */
26
27 #ifdef HAVE_CONFIG_H
3 #include <config.h> 28 #include <config.h>
29 #endif
4 30
5 #include <stdio.h> 31 #include <stdio.h>
6 #include <ctype.h> 32 #include <ctype.h>
7 #ifdef WIN32_NATIVE 33 #ifdef WIN32_NATIVE
8 #include <io.h> 34 #include <io.h>
35 main (int argc, char *argv[]) 61 main (int argc, char *argv[])
36 { 62 {
37 register long address; 63 register long address;
38 char string[18]; 64 char string[18];
39 FILE *fp; 65 FILE *fp;
40 66
41 progname = *argv++; --argc; 67 progname = *argv++; --argc;
42 68
43 /* 69 /*
44 ** -hex hex dump 70 ** -hex hex dump
45 ** -oct Octal dump 71 ** -oct Octal dump
46 ** -group-by-8-bits 72 ** -group-by-8-bits
47 ** -group-by-16-bits 73 ** -group-by-16-bits
48 ** -group-by-32-bits 74 ** -group-by-32-bits
49 ** -group-by-64-bits 75 ** -group-by-64-bits
50 ** -iso iso character set. 76 ** -iso iso character set.
51 ** -big-endian Big Endian 77 ** -big-endian Big Endian
52 ** -little-endian Little Endian 78 ** -little-endian Little Endian
53 ** -un || -de from hexl format to binary. 79 ** -un || -de from hexl format to binary.
54 ** -- End switch list. 80 ** -- End switch list.
55 ** <filename> dump filename 81 ** <filename> dump filename
56 ** - (as filename == stdin) 82 ** - (as filename == stdin)
57 */ 83 */
58 84
59 while (*argv && *argv[0] == '-' && (*argv)[1]) 85 while (*argv && *argv[0] == '-' && (*argv)[1])
60 { 86 {
61 /* A switch! */ 87 /* A switch! */
62 if (!strcmp (*argv, "--")) 88 if (!strcmp (*argv, "--"))
63 { 89 {
115 endian = 0; 141 endian = 0;
116 --argc; argv++; 142 --argc; argv++;
117 } 143 }
118 else 144 else
119 { 145 {
120 (void) fprintf (stderr, "%s: invalid switch: \"%s\".\n", progname, 146 fprintf (stderr, "%s: invalid switch: \"%s\".\n", progname,
121 *argv); 147 *argv);
122 usage (); 148 usage ();
123 } 149 }
124 } 150 }
125 151
143 if (un_flag) 169 if (un_flag)
144 { 170 {
145 char buf[18]; 171 char buf[18];
146 172
147 #ifdef WIN32_NATIVE 173 #ifdef WIN32_NATIVE
148 _setmode (_fileno (stdout), O_BINARY); 174 if (!isatty (_fileno (stdout)))
175 _setmode (_fileno (stdout), O_BINARY);
149 #endif 176 #endif
150 for (;;) 177 for (;;)
151 { 178 {
152 register int i, c = 0, d; 179 register int i, c = 0, d;
153 180
186 } 213 }
187 } 214 }
188 else 215 else
189 { 216 {
190 #ifdef WIN32_NATIVE 217 #ifdef WIN32_NATIVE
191 _setmode (_fileno (fp), O_BINARY); 218 if (!isatty (_fileno (stdout)))
219 _setmode (_fileno (stdout), O_BINARY);
192 #endif 220 #endif
193 address = 0; 221 address = 0;
194 string[0] = ' '; 222 string[0] = ' ';
195 string[17] = '\0'; 223 string[17] = '\0';
196 for (;;) 224 for (;;)
208 string[i+1] = '\0'; 236 string[i+1] = '\0';
209 } 237 }
210 else 238 else
211 { 239 {
212 if (!i) 240 if (!i)
213 (void) printf ("%08lx: ", address); 241 printf ("%08lx: ", address);
214 242
215 if (iso_flag) 243 if (iso_flag)
216 string[i+1] = 244 string[i+1] =
217 (c < 0x20 || (c >= 0x7F && c < 0xa0)) ? '.' :c; 245 (c < 0x20 || (c >= 0x7F && c < 0xa0)) ? '.' :c;
218 else 246 else
219 string[i+1] = (c < 0x20 || c >= 0x7F) ? '.' : c; 247 string[i+1] = (c < 0x20 || c >= 0x7F) ? '.' : c;
220 248
221 (void) printf ("%02x", c); 249 printf ("%02x", c);
222 } 250 }
223 251
224 if ((i&group_by) == group_by) 252 if ((i&group_by) == group_by)
225 putchar (' '); 253 putchar (' ');
226 } 254 }
235 263
236 } 264 }
237 } 265 }
238 266
239 if (fp != stdin) 267 if (fp != stdin)
240 (void) fclose (fp); 268 fclose (fp);
241 269
242 } while (*argv != NULL); 270 } while (*argv != NULL);
243 return 0; 271 return EXIT_SUCCESS;
244 } 272 }
245 273
246 void 274 void
247 usage (void) 275 usage (void)
248 { 276 {
249 fprintf (stderr, "Usage: %s [-de] [-iso]\n", progname); 277 fprintf (stderr, "Usage: %s [-de] [-iso]\n", progname);
250 exit (1); 278 exit (EXIT_FAILURE);
251 } 279 }
280
281 /* arch-tag: 20e04fb7-926e-4e48-be86-64fe869ecdaa
282 (do not change this comment) */
283
284 /* hexl.c ends here */