home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
rtsi.com
/
2014.01.www.rtsi.com.tar
/
www.rtsi.com
/
OS9
/
OSK
/
CMDS
/
cowen_tools.lzh
/
hex.c
< prev
next >
Wrap
Text File
|
1992-02-22
|
2KB
|
68 lines
/*
This program accepts pairs of hex digits from the infile, and outputs
them to outfile as ASCII characters.
Spaces and newlines are ignored.
The program terminates on any non - hex character.
The most common use would be to check the effects of sequences of control
codes to a terminal.
This program is copyright (1989) by Cowen Software Ltd
of 21/23 Bristol Ave, Manchester, England, GB-M19 3NU
It is made available for any OS9/68K user freely,
but may not be sold for profit, other than a reasonable
handling charge
*/
#include <stdio.h>
#include <ctype.h>
extern int errno;
main (argc,argv)
int argc;
char *argv[];
{
if ( argc == 2 && argv[1][0] == '-' )
{
if (argv[1][1] == '?' )
{ fprintf (stderr,"\nSyntax: hex");
fprintf (stderr,"\nFunction: reads hex digits, outputs as ASCII.\n");
}
else fprintf (stderr,"\n Unknown option");
_exit(1);
}
else
{
while (1)
{
int achar;
achar = getd() * 16 + getd();
putchar(achar);
fflush(stdout);
}
}
}
getd()
{
char digit;
int freply;
while (1)
{
freply = read(0,&digit,1);
if (freply == 0)
_exit(0);
digit = toupper(digit);
if (digit >= '0' && digit <= '9')
return (digit - '0');
if (digit >= 'A' && digit <= 'F')
return (digit - 'A' + 10);
if ( !(digit == '\n' || digit == ' ') )
{ fprintf(stderr,"\n");
fflush(stderr);
_exit(0);
}
}
}