/*
 * inordp.c
 *
 * determine if lines in a file are in textually ascending order
 *
 * in:	argv[1] = input filename
 *
 * out:	stdout lists record numbers of any out-of-order records,
 *	along with the two records contents
 */

#include <stdio.h>
#include <algol68.h>

#define BUFSIZ 1000
char buffer[BUFSIZ];
char last[BUFSIZ];

FILE	*inf;
extern int $$ferr;

long int recnum;

main(argc,argv)
char **argv;
BEGIN
register int	howlong;	/* char length of this record */
	IF	((inf=fopen(argv[1],"ur"))==NULL)
	THEN	error("can't find %s\7\n",argv[1]);
	FI;
	last[0] = 0;
	FOR	(recnum=1;	!feof(inf);	recnum++)
	DO	howlong = fget(buffer,BUFSIZ,inf);
		IF	(ferror(inf))
		THEN	error("read failure $$ferr=%oo\7\n",$$ferr);
		FI;
		IF	(feof(inf))
		THEN	exit();			/* break; */
		FI;
		buffer[howlong] = 0;
		IF	(strcmp(buffer,last)<0)
		THEN	printf("%12ld.:\"%s\"\n%12ld.:\"%s\"\n"
				,recnum-1,last,recnum,buffer);
		FI
		copy(last,buffer,howlong+1);
	OD;
END

/* end: inordp.c */
