/****************************************************************
 *	Module name  :	view.c                                  *
 *	Purpose      :	Like TYPE but scrolls both ways         *
 *	Created      :	??-??-89				* 
 *	Last edited  : 	24-08-89		Version 1.0	*
 * 	Copyright    :	G R Buckeridge				*
 ****************************************************************/

#include stdio.h
#include gb.h
#define PAGE_LEN 30
#define MAXINT 32767

main(argc,argv)
int argc;
char *argv[];

	{

	FAST char argv_buffer[MAXARGS * 2 +132];
	FILE *in;
	FAST char ln[100],ll[100],*p,last;
	int count,i,s,f,k,c,THIS_PAGE;
	
	count=0;
		
	cpm_cmd_line (&argc,&argv,argv_buffer); /* for reading command line */

	if (argc<2 || argc>3)  
		{
		help();
		exit(0);
		}

	in=fopen(argv[1],"r");
	if (in == NULL)
		{
		printf("Can't open file %s\n",argv[1]);
		exit(0);
		}

	THIS_PAGE=PAGE_LEN;
	
	if (!(c=strcmp(argv[2],"P")))
		{
		pron();
		THIS_PAGE=MAXINT;
		}

loop:
	s=1;
	f=strcmp(argv[2],"C")
		? THIS_PAGE
		: MAXINT;
	
	for (i=s;i<f && (p=fgets(ln,100,in))!=NULL;i++)

		{
		printf("%s",ln);
		count++;

		if (!c)
			{
		if(p!=NULL)
			strcpy(ll,ln);
		fprintf(LST,"%s",ln);
 			}
		if (keyhit() && f!=PAGE_LEN)
			{
			rawin();
			goto end;
			}
		else if(keyhit())
			rawin();
		}		
	if(p!=NULL)
		{
		printf("\t\t\33pScroll UP or DOWN using CURSOR KEYS - Any other key to quit.\33q");
		k=rawin();
		clrln();
		if(k==30) goto loop;
		else if (k==31) 
			{
			fclose(in);
			in=fopen(argv[1],"r");
			count-=(PAGE_LEN*2)-6;
			for (i=1;i<count;i++)
				p=fgets(ln,100,in);	
			cls();
				 goto loop;
			}		
		}
end:
	if (!c)
		{
		if((last=ln[strlen(ll)-1])!=0x0a && last>>0 )
			fprintf(LST,"\n");
		proff();
		}
		
	fclose(in);
	}

void help()
	
	{
	printf("\nVIEW.COM - Like TYPE but scrolls in both directions\n\n");
	printf("   VIEW <filename>      lists to vdu with prompts\n");
	printf("   VIEW <filename> C    lists to vdu continuously\n");
	printf("   VIEW <filename> P    lists to printer\n\n");
	printf("   ctrl_S  and ctrl_Q have their normal effect\n");
	printf("   Press any key to abort in 'C' or 'P' mode.\n");
	}

#include ?gb.lib
#include ?cpm.lib
#include ?stdio.lib

	prin