]> code.delx.au - gnu-emacs/blobdiff - lib-src/hexl.c
doh, fixing year in ChangeLog entries introduced by last two commits
[gnu-emacs] / lib-src / hexl.c
index f271fd3afffd42e05d44d7398db7b7134d5439a2..490f72731b4277fce153859a5668d667e86c369f 100644 (file)
@@ -1,6 +1,5 @@
 /* Convert files for Emacs Hexl mode.
-   Copyright (C) 1989, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
-                 2009, 2010, 2011, 2012  Free Software Foundation, Inc.
+   Copyright (C) 1989, 2001-2015 Free Software Foundation, Inc.
 
 Author: Keith Gabryelski
 (according to authors.el)
@@ -21,40 +20,25 @@ You should have received a copy of the GNU General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 
-#ifdef HAVE_CONFIG_H
 #include <config.h>
-#endif
 
 #include <stdio.h>
 #include <ctype.h>
-#ifdef DOS_NT
-#include <fcntl.h>
-#if __DJGPP__ >= 2
-#include <io.h>
-#endif
-#endif
-#ifdef WINDOWSNT
-#include <io.h>
-#endif
+
+#include <binary-io.h>
 
 #define DEFAULT_GROUPING       0x01
 #define DEFAULT_BASE           16
 
-#undef TRUE
-#undef FALSE
-#define TRUE  (1)
-#define FALSE (0)
-
-int base = DEFAULT_BASE, un_flag = FALSE, iso_flag = FALSE, endian = 1;
+int base = DEFAULT_BASE;
+bool un_flag = false, iso_flag = false, endian = true;
 int group_by = DEFAULT_GROUPING;
 char *progname;
 
-void usage();
+_Noreturn void usage (void);
 
 int
-main (argc, argv)
-     int argc;
-     char *argv[];
+main (int argc, char **argv)
 {
   register long address;
   char string[18];
@@ -88,7 +72,7 @@ main (argc, argv)
        }
       else if (!strcmp (*argv, "-un") || !strcmp (*argv, "-de"))
        {
-         un_flag = TRUE;
+         un_flag = true;
          --argc; argv++;
        }
       else if (!strcmp (*argv, "-hex"))
@@ -98,7 +82,7 @@ main (argc, argv)
        }
       else if (!strcmp (*argv, "-iso"))
        {
-         iso_flag = TRUE;
+         iso_flag = true;
          --argc; argv++;
        }
       else if (!strcmp (*argv, "-oct"))
@@ -108,12 +92,12 @@ main (argc, argv)
        }
       else if (!strcmp (*argv, "-big-endian"))
        {
-         endian = 1;
+         endian = true;
          --argc; argv++;
        }
       else if (!strcmp (*argv, "-little-endian"))
        {
-         endian = 0;
+         endian = false;
          --argc; argv++;
        }
       else if (!strcmp (*argv, "-group-by-8-bits"))
@@ -134,7 +118,7 @@ main (argc, argv)
       else if (!strcmp (*argv, "-group-by-64-bits"))
        {
          group_by = 0x07;
-         endian = 0;
+         endian = false;
          --argc; argv++;
        }
       else
@@ -164,24 +148,18 @@ main (argc, argv)
 
       if (un_flag)
        {
-         char buf[18];
-
-#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
+         SET_BINARY (fileno (stdout));
+
          for (;;)
            {
-             register int i, c = 0, d;
+             int i, c = 0, d;
+             char buf[18];
 
 #define hexchar(x) (isdigit (x) ? x - '0' : x - 'a' + 10)
 
-             fread (buf, 1, 10, fp); /* skip 10 bytes */
+             /* Skip 10 bytes.  */
+             if (fread (buf, 1, 10, fp) != 10)
+               break;
 
              for (i=0; i < 16; ++i)
                {
@@ -209,21 +187,15 @@ main (argc, argv)
                  if (i < 16)
                    break;
 
-                 fread (buf, 1, 18, fp); /* skip 18 bytes */
+                 /* Skip 18 bytes.  */
+                 if (fread (buf, 1, 18, fp) != 18)
+                   break;
                }
            }
        }
       else
        {
-#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
+         SET_BINARY (fileno (fp));
          address = 0;
          string[0] = ' ';
          string[17] = '\0';
@@ -278,13 +250,11 @@ main (argc, argv)
 }
 
 void
-usage ()
+usage (void)
 {
   fprintf (stderr, "usage: %s [-de] [-iso]\n", progname);
   exit (EXIT_FAILURE);
 }
 
-/* arch-tag: 20e04fb7-926e-4e48-be86-64fe869ecdaa
-   (do not change this comment) */
 
 /* hexl.c ends here */