/*
 *	hexify.c
 *
 *	read a binary file, produce a text (7 bit wide ASCII) file
 *
 *	decus c version, presumed unix compliant, but not compatible
 */

/*
 * 02feb85 pf	allow for zero-length records: give a blank line in
 *		hex file. useful for t2b output records.
 *
 * bug:		the output always begins with a superflous '\n'
 */

#include <stdio.h>
extern int $$ferr;
#include <algol68.h>

#define BUFSIZ 1024
char buf[BUFSIZ];		/* some machines have small stacks */

main(argc,argv)
int	argc;
char	**argv;
BEGIN
int	fd;		/* handle of input file */
int howlong;		/* length of input buffer in chars */
register char *p;	/* scan input buffer */
register int test;	/* used to put '\n' after 32 %02x outputs */
register char *nd;	/* end of buffer scan */

	fd = fopen(argv[1],"ur");
	WHILE	(TRUE)
	DO	howlong = fget(buf,BUFSIZ,fd);
		IF	(ferror(fd))
		THEN	error("read fail $$ferr=%oo",$$ferr);
		FI
		IF	(feof(fd))
		THEN	break;
		FI
		nd = buf+howlong;
		FOR	(p=buf;	p<nd;	p++)
		DO	test = p-buf;
			IF	(!((test)%32)&&(test))
			THEN	putchar('\n');
			FI
			printf("%02x",*p&0xFF);
		OD
		putchar('\n');
	OD
END

/* end: hexify.c */
