/* ufilter3.c - prototype filter program - line (actually record) oriented */
/* this modularises input & output : so you can easily break RPG cycle */

	/***************************************\
	*					*
	*	fails for binary files		*
	*					*
	\***************************************/

#include <stdio.h>
#include <algol68.h>
#define BUFSIZ 4096
char buffer[BUFSIZ];
main(argc,argv)
char **argv;
BEGIN
int	howlong;	/* char length of this record */
char *	recinp();

	WHILE	(recinp(buffer,BUFSIZ,&howlong))
	DO	recout(buffer,howlong);
	OD
END

char * recinp(buf,max,len)	/* NULL if eof. buffer address */
char *	buf;
int	max;
int *	len;			/* length of buffer */
BEGIN
	* len = fget(buf,max,stdin);
	IF	(ferror(stdin))
	THEN	error("read failure $$ferr=%oo\7\n",$$ferr);
	FI
	return (feof(stdin)?NULL:buffer);
END

recout(where,len)
char *	where;
int	len;
BEGIN
	fput(where,len,stdout);
	IF	(ferror(stdout))
	THEN	error("write failed $$ferr=%oo\7\n",$$ferr);
	FI
END

/* end: ufilter3.c */
