[net.sources] Aztec C source - more.c

dcn@ihuxl.UUCP (Dave Newkirk) (11/14/83)

/* more - print file a page at a time */

#include "stdio.h"

#define PAGESIZE 24

int lines ;

main(argc, argv)
int argc ;
char *argv[] ;
{
	FILE *input ;


	argc-- ; argv++ ;

	lines = 0 ;

	for( ; argc > 0 ; argc--, argv++ )
		if( (input=fopen(*argv,"r")) == NULL ) {
			fprintf(stderr, "more: can't open %s\n", *argv) ;
			exit(1) ;
		}
		else {
			more( input ) ;
			fclose( input ) ;
		}

	exit(0) ;

} /* end main */


/* more - print file page at time */

more( in )
FILE *in ;
{
	int c ;

	while( (c=agetc(in)) != EOF ) {
		aputc(c, stdout) ;
		if( c == NL )
			lines++ ;
		if( lines >= PAGESIZE ) {
			lines = 1 ;
			printf("MORE") ;
			c = agetc(stdin) ;
			ioctl(1, 18, 0) ;
			if( c == 'q' )
				exit(0) ;
		}
	}

} /* end more */