[fa.info-mac] fromhex for UNIX

info-mac@uw-beaver (info-mac) (07/26/84)

From: Bill Croft <croft@safe>
From: Mark H. Nodine and Bill Croft

Back in the days before macput/macget, programs were downloaded to the
Mac by saving the MacTerminal scrolloff in a file, and running a 
program on the Mac called "fromhex" that converted this hex file to a binary
resource file.

People still distribute their programs in this (.dl) format 
because it can be sent through the mail or ftped in ASCII mode.
Here is a version of "fromhex" for UNIX:
----
/* fromhex.c, UNIX version */

#include <stdio.h>

int bytes,sum;

main()
{
	register i,v;
	register n;

	n = 0;
	v = 0;
	while ((i = getchar()) != EOF) {
		i &= 0177;
		if (i == '|') 
			break;
		if (i < 0100 || i > 0117)
			continue;
		v = (v << 4) | (i & 0xF);
		if ((++n & 1) == 0) {
			putchar(v);
			sum += v;
			v = 0;
			bytes++;
		}
	}
	n = 0;
	for (i = 0 ; i < 8 ; i++)
		n = (n << 4) | (getchar() & 0xF);
	if (n != (bytes + sum))
		fprintf(stderr, "bad checksum\n");
	else
		fprintf(stderr, "checksum good!\n");
	exit(0);
}

This program is a filter, so you should invoke it something like
  fromhex <neatprog.dl >neatprog.rsrc
  macput -r neatprog.rsrc
This halves the amount of time it takes to download neatprog.

P.S. Thanks to so many of you who are providing programs for downloading!