/* -*-c,save-*- */

#include <stdio.h>

#define FAST register

#define LOCAL static

#define GLOBAL extern

#define BLOCK_SIZE 32





main(argc,argv)

int argc;

char *argv[];

{FAST FILE *infile;

 FILE *fopenb();

 char block_buff[BLOCK_SIZE];

 FAST int rec_num,bytes;

 

 	if (argc != 2) {

	    fprintf(stderr,"Usage: tohex infile [>outfile]\n");

	    abort(1);

	    }

	infile = fopenb(argv[1],"r");

	if (infile == NULL) {

	    perror("tohex: fopenb error");

	    abort(2);

	    }

	rec_num = 0;

	while ((bytes = fread(&block_buff[0],1,BLOCK_SIZE,infile)) > 0) {

	    put_hex(&block_buff[0],bytes,rec_num++);

	    }

	put_hex(block_buff,0,rec_num);

	fclose(infile);

	}

put_hex(buff,buffsiz,recnum)

FAST char *buff;

FAST int buffsiz,recnum;

{

    FAST int checksum,n;

    

    printf(";%02x%04x",buffsiz,recnum);

    checksum = buffsiz + (recnum & 0x00ff) + ((recnum >> 8) & 0x00ff);

    while ((buffsiz--)>0) {

	n = *buff++;

	n &= 0x00ff;

	checksum += n;

	printf("%02x",n);

	}

    printf("%04x\n",checksum);

    }

buffsiz--)>0) {

	n = *buff++;

	n &= 0x00ff;

	checksum += n;

	printf("%02x",n);

	}

    printf("%