/* lastrec.c - emit only last non-empty record if any */
/* ufilter3.c - prototype filter program - line (actually record) oriented */

#include <stdio.h>
#include <algol68.h>
#define BUFSIZ (16384)
char buffer[BUFSIZ];
int	savelong;
char	save[BUFSIZ];

main(argc,argv)
int	argc;
char	**argv;
BEGIN
register int	howlong;	/* char length of this record */

	stdin  -> _flag |= IO_NOS | _IONBF;
	stdout -> _flag |= IO_NOS | _IONBF;

	savelong = 0;
	WHILE	(!feof(stdin))
	DO	howlong = fget(buffer,BUFSIZ,stdin);
		IF	(ferror(stdin))
		THEN	error("read failure $$ferr=%oo\7\n",$$ferr);
		FI
		IF	(feof(stdin))
		THEN	break;
		FI
		IF	(howlong)
		THEN	copy(save,buffer,howlong);
			savelong = howlong;
		FI
	OD
	IF	(savelong)
	THEN	fput(save,savelong,stdout);
	FI
	IF	(ferror(stdout))
	THEN	error("write failed $$ferr=%oo\7\n",$$ferr);
	FI
END

/* end: ufilter3.c */
/* end: lastrec.c */
