X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/3dc64903b825fa73e61846bd792edf249e1bf425..0005c1812a7d446900254e612762469ea0c111bb:/lib-src/hexl.c diff --git a/lib-src/hexl.c b/lib-src/hexl.c index bd6220e0ba..0dfdddf468 100644 --- a/lib-src/hexl.c +++ b/lib-src/hexl.c @@ -1,7 +1,36 @@ +/* Convert files for Emacs Hexl mode. + Copyright (C) 1989, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. + +This file is not considered part of GNU Emacs. + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software Foundation, +Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#ifdef HAVE_CONFIG_H +#include +#endif + #include #include -#ifdef MSDOS +#ifdef DOS_NT #include +#if __DJGPP__ >= 2 +#include +#endif +#endif +#ifdef WINDOWSNT +#include #endif #define DEFAULT_GROUPING 0x01 @@ -16,6 +45,9 @@ int base = DEFAULT_BASE, un_flag = FALSE, iso_flag = FALSE, endian = 1; int group_by = DEFAULT_GROUPING; char *progname; +void usage(); + +int main (argc, argv) int argc; char *argv[]; @@ -41,7 +73,7 @@ main (argc, argv) ** dump filename ** - (as filename == stdin) */ - + while (*argv && *argv[0] == '-' && (*argv)[1]) { /* A switch! */ @@ -130,13 +162,18 @@ main (argc, argv) { char buf[18]; -#ifdef MSDOS +#ifdef DOS_NT +#if (__DJGPP__ >= 2) || (defined WINDOWSNT) + if (!isatty (fileno (stdout))) + setmode (fileno (stdout), O_BINARY); +#else (stdout)->_flag &= ~_IOTEXT; /* print binary */ _setmode (fileno (stdout), O_BINARY); +#endif #endif for (;;) { - register int i, c, d; + register int i, c = 0, d; #define hexchar(x) (isdigit (x) ? x - '0' : x - 'a' + 10) @@ -174,16 +211,21 @@ main (argc, argv) } else { -#ifdef MSDOS +#ifdef DOS_NT +#if (__DJGPP__ >= 2) || (defined WINDOWSNT) + if (!isatty (fileno (fp))) + setmode (fileno (fp), O_BINARY); +#else (fp)->_flag &= ~_IOTEXT; /* read binary */ _setmode (fileno (fp), O_BINARY); +#endif #endif address = 0; string[0] = ' '; string[17] = '\0'; for (;;) { - register int i, c; + register int i, c = 0; for (i=0; i < 16; ++i) { @@ -198,7 +240,7 @@ main (argc, argv) else { if (!i) - printf ("%08x: ", address); + printf ("%08lx: ", address); if (iso_flag) string[i+1] = @@ -228,11 +270,17 @@ main (argc, argv) fclose (fp); } while (*argv != NULL); - return 0; + return EXIT_SUCCESS; } +void usage () { fprintf (stderr, "usage: %s [-de] [-iso]\n", progname); - exit (1); + exit (EXIT_FAILURE); } + +/* arch-tag: 20e04fb7-926e-4e48-be86-64fe869ecdaa + (do not change this comment) */ + +/* hexl.c ends here */