[net.sources] page.c

cunningh@noscvax.UUCP (11/22/83)

/*
 *  page.c  **  19 Nov 83 
 *  Developed for the AZTEC C system for the Apple ][+, Apple //e computer.
 *  more.c from aluxe!ira, converted to page.c by noscvax!cunningh.
 */
 
#include "kbctl.h"
#include "stdio.h"
 
#define SCRNSIZE 24
#define MAXLINE 1000
#define NEWPAGE ioctl( 1, KB_CLEAR)
 
char	str_e[] = "  End of  ";
char	str_m[] = "--More--  ";
char	str_more[] = "  [Hit 'space' to continue, 'q' to quit] ";
int		file_len;
 
main(argc, argv)
	int	argc;
	char	*argv[];
	{
	char	line[MAXLINE], *s;
	long	lineno;
	int	flag, srnsize, len;
	FILE * fp, *fopen();
 
	flag = lineno = 0;
	srnsize = SCRNSIZE - 2;
	while (--argc > 0 && (*++argv)[0] == '-' )
		for (s = argv[0] + 1; *s != '\0'; s++)
			switch (*s)
				{
				default:
					printf("page: illegal option %c\n", *s );
					argc = 0;
					break;
				}
	if ( argc < 1 ) 
		{
		printf("Usage: page file1 [ file2 file3 .. ]\n");
		exit(1);
		}
	 else
		*--argv;
	if ( argc >= 2 )
		flag = 1;
	while ( --argc >= 0 )
		{
		if ((fp = fopen(*++argv, "r")) == NULL)
			{
			printf("page: can't open %s\n", *argv);
			exit(1);
			}
		NEWPAGE;
		if (flag)
			{
			printf(":::::::::::::::::::\n");
			printf("%s\n",*argv);
			printf(":::::::::::::::::::\n");
			lineno = 2;
			}
		fp->bufsiz = 2048;
		file_len = strlen (*argv);
		while ( (len = getline(line, MAXLINE, fp)) > 0)
			{
			lineno++;
			write( 1, line, len );
			if ( lineno % srnsize == 0 )
				{
				if ( more(str_m,*argv) == -1 )
					exit(0);
				lineno = 0;
				}
			}
			fclose(fp);
			if ( (argc >= 1) )
				{
				fflush(stdout);
				if ( more(str_e,*argv) == -1 )
					exit(0);
				}
			lineno = 0;
		}
	}
 
 
getline(s, lim, fp)
char	*s;
int	lim;
FILE *fp;
{
	char	c, *pc;
 
	pc = s;
	while (--lim > 0 && (c = agetc(fp) ) != EOF && c != '\n' )
		*pc++ = c;
	if (c == '\n' )
		*pc++ = c;
	*pc = '\0';
	return((int)(pc - s));
}
 
 
more(msg,file)
	char   *msg;
	char	*file;
	{
	int	c;
 
	ioctl ( 1, KB_INV, 1 );
	write ( 1, msg, 11);
	write ( 1, file, file_len);
	write ( 1, str_more, 42 );
	ioctl ( 1, KB_INV, 0 );
	c = getchar();
	ioctl ( 1, KB_CURS, ( 23 << 8 ) | 0 );
	ioctl ( 1, KB_CLEOL );
	if ( c != ' ' && c != 'q' )
		more(file);
	if ( c == 'q' )
		return(-1);
	NEWPAGE;
	}
 
-- 
Bob Cunningham			 ..sdcsvax!noscvax!cunningh
21 17' 35" N  157 49' 38" W        MILNET:  cunningh@nosc-cc