1
0
mirror of https://git.savannah.gnu.org/git/gperf.git synced 2025-12-02 21:19:24 +00:00

Use binary mode for input. Produce prettier output.

This commit is contained in:
Bruno Haible
2000-08-20 20:56:37 +00:00
parent ac65860e4b
commit baf0680111

View File

@@ -6,6 +6,20 @@
#include <stdio.h> #include <stdio.h>
/* Support for SET_BINARY. */
#include <fcntl.h>
#if !defined O_BINARY && defined _O_BINARY
# define O_BINARY _O_BINARY
#endif
#ifdef __BEOS__
# undef O_BINARY
#endif
#if O_BINARY
# define SET_BINARY(f) setmode (f, O_BINARY)
#else
# define SET_BINARY(f) (void)0
#endif
#define MAX_LEN 80 #define MAX_LEN 80
int int
@@ -17,6 +31,9 @@ main (argc, argv)
char buf[2*MAX_LEN]; char buf[2*MAX_LEN];
int buflen; int buflen;
/* We need to read stdin in binary mode. */
SET_BINARY (0);
for (;;) for (;;)
{ {
/* Simulate gets(buf) with 2 bytes per character. */ /* Simulate gets(buf) with 2 bytes per character. */
@@ -33,11 +50,11 @@ main (argc, argv)
break; break;
if (in_word_set (buf, buflen) && verbose) if (in_word_set (buf, buflen) && verbose)
printf ("in word set "); printf ("in word set:");
else if (verbose) else if (verbose)
printf ("NOT in word set "); printf ("NOT in word set:");
for (p = buf; p < buf + buflen; p++) for (p = buf; p < buf + buflen; p += 2)
printf ("%02X", (unsigned char) *p); printf (" %02X%02X", (unsigned char) p[0], (unsigned char) p[1]);
printf("\n"); printf("\n");
} }