diff options
author | Karl Berry <karl@freefriends.org> | 2010-05-26 18:13:06 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2010-05-26 18:13:06 +0000 |
commit | 3d8da5c85f9bb90eb80ac3fa22edf45b448140fb (patch) | |
tree | ea7e7459cb562b1bec12164edbcf295647c0202b /Build/source/extra/xz-4.999.9beta-124-gb637/debug/hex2bin.c | |
parent | 102ace285218431079cbea4914f3faaad0c7383e (diff) |
new xz release
git-svn-id: svn://tug.org/texlive/trunk@18518 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/extra/xz-4.999.9beta-124-gb637/debug/hex2bin.c')
-rw-r--r-- | Build/source/extra/xz-4.999.9beta-124-gb637/debug/hex2bin.c | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/Build/source/extra/xz-4.999.9beta-124-gb637/debug/hex2bin.c b/Build/source/extra/xz-4.999.9beta-124-gb637/debug/hex2bin.c new file mode 100644 index 00000000000..73246244746 --- /dev/null +++ b/Build/source/extra/xz-4.999.9beta-124-gb637/debug/hex2bin.c @@ -0,0 +1,53 @@ +/////////////////////////////////////////////////////////////////////////////// +// +/// \file hex2bin.c +/// \brief Converts hexadecimal input strings to binary +// +// Author: Lasse Collin +// +// This file has been put into the public domain. +// You can do whatever you want with this file. +// +/////////////////////////////////////////////////////////////////////////////// + +#include "sysdefs.h" +#include <stdio.h> +#include <ctype.h> + + +static int +getbin(int x) +{ + if (x >= '0' && x <= '9') + return x - '0'; + + if (x >= 'A' && x <= 'F') + return x - 'A' + 10; + + return x - 'a' + 10; +} + + +int +main(void) +{ + while (true) { + int byte = getchar(); + if (byte == EOF) + return 0; + if (!isxdigit(byte)) + continue; + + const int digit = getchar(); + if (digit == EOF || !isxdigit(digit)) { + fprintf(stderr, "Invalid input\n"); + return 1; + } + + byte = (getbin(byte) << 4) | getbin(digit); + if (putchar(byte) == EOF) { + perror(NULL); + return 1; + } + } +} |