Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10 UW 5/3/83; site uw-beaver
Path: utzoo!watmath!clyde!burl!ulysses!cbosgd!mhuxj!houxm!vax135!cornell!uw-beaver!info-mac
From: info-mac@uw-beaver (info-mac)
Newsgroups: fa.info-mac
Subject: FROMHEX.C and TOHEX.C (by popular demand)
Message-ID:
Date: Thu, 8-Nov-84 02:05:39 EST
Article-I.D.: uw-beave.2145
Posted: Thu Nov 8 02:05:39 1984
Date-Received: Fri, 9-Nov-84 07:46:27 EST
Sender: yenbut@uw-beave
Organization: U of Washington Computer Science
Lines: 191
From: Ed Pattermann
FROMHEX.C
#include "quickdraw.h"
#include "osintf.h"
#include "toolintf.h"
#define bufsize 512
#define InName "C"
#define OutName "C prog"
int rout, rin, io, i;
int l, val, bytes, sum, getsum;
char bin[bufsize], bout[bufsize];
int count, szin, bini, bouti;
FInfo fInfo;
putflush()
{
if (bouti)
{
count = bouti;
io = FSWrite(rout, &count, bout);
bouti = 0;
}
}
putchar(ch)
int ch;
{
bout[bouti++] = (char) ch;
if (bouti == bufsize)
putflush();
}
int getchar()
{
if (bini == bufsize)
{
bini = 0;
count = bufsize;
io = FSRead(rin, &count, bin);
}
return ((int) bin[bini++]);
}
badnews()
{
int j;
io = FSClose(rin);
io = FSClose(rout);
SysBeep(1);
for (j = 0; j > 1;
io = Allocate(rout, &count);
if (io)
badnews();
val = 0;
bytes = 0;
sum = 0;
getsum = 0;
while (szin && !getsum)
{
l = getchar() & 127;
szin--;
if ((l >= 64) && (l > 1;
val = 0;
for (i = 1; i
char hex[] = "@ABCDEFGHIJKLMNO";
int bytes,sum;
unsigned long htonl();
main(argc,argv)
char **argv;
{
register i,len;
register char *cp;
len = 0;
while ((i = getchar()) != EOF) {
bytes++;
sum += i;
putchar(hex[i>>4]);
putchar(hex[i&0xF]);
if (++len > 32) {
putchar('\n');
len = 0;
}
}
fprintf(stderr, "bytes %d, sum %d\n", bytes, sum);
putchar('|');
sum += bytes;
sum = htonl(sum);
cp = (char *)∑
for (len = 0 ; len >4]);
putchar(hex[i&0xF]);
}
putchar('\n');
exit(0);
}
#define nohtonl
#ifdef nohtonl /* if not in library */
/*
* "Host" to "net" byte order swappers.
*/
unsigned short htons(a)
unsigned short a;
{
unsigned short result;
register char *sp = (char *)&a;
register char *dp = (char *)&result;
dp[1] = *sp++;
dp[0] = *sp;
return (result);
}
unsigned long htonl(a)
unsigned long a;
{
unsigned long result;
register char *sp = (char *)&a;
register char *dp = (char *)&result;
dp[3] = *sp++;
dp[2] = *sp++;
dp[1] = *sp++;
dp[0] = *sp;
return (result);
}
#endif
-------
