#include<stdio.h>
#include<bios.h>
#include<dos.h>
#include<stdlib.h>
#include<string.h>
#define SPV 100000
#define PAL 24
#define BUL 255
union REGS din,dout;
static int k,pflag;
static long speed;
main(int argc,char *argv[])
{
 int fflag,line,count=0;
 long j;
 char *c,buf[BUL];
 FILE *fp,*prn;
 prn=stdprn;
 if(argc==1)
   {
    printf("Usage: TYPE1 filename [/P] [startline]\n");
    printf("      ESC --- quit\n");
    printf("    SPACE --- Pause\n");
    printf("        P --- print (on/off)\n");
    printf("        L --- more (off/on)\n");
    printf("        > --- quick\n");
    printf("        < --- unquick\n");
    exit(0);
   }
 if((strstr(argv[1],"/p"))==NULL)
   {
    pflag=0;
    c=strcpy(c,argv[1]);
   }
  else
   {
    pflag=1;
    line=strlen(argv[1])-2;
    c=strncat(c,argv[1],line);
   }
 if((fp=fopen(c,"r"))==NULL)
   {
    printf("FILE %s cannot open !\n",c);
    exit(0);
   }
 if(argc==3)
   {
    line=atoi(argv[2]);
    while(line>1)
      {
       line--;
       count++;
       if((fgets(buf,BUL,fp))==NULL) exit(0);
      }
   }
 speed=SPV;
 k=PAL;
 fflag=1;
 line=count=0;
 while(fflag)
   {
    g(0);
    if((fgets(buf,BUL,fp))==NULL) fflag=0;
     else
      {
       line++;
       count++;
       if(line>=k)
         {
          line=0;
          if(k!=1)g(1);
         }
       printf("%s\r",buf);
       if(pflag)
         {
          if(biosprint(2,0,0)!=0x90)g(1);
          if(biosprint(2,0,0)==0x90)
            {
	     fprintf(prn," %3d",count);
             fputs(buf,prn);
            }
           else pflag=0;
         }
       j=0;
       while(j<speed)j++;
      }
   }
 close(fp);
}
gc(int a)
{
 din.h.ah=a;
 int86(0x21,&din,&dout);
}
g(int a)
{
 gc(0x0b);
 while((dout.h.al==0xff)||(a!=0))
   {
    gc(0x07);
    switch(dout.h.al)
     {
      case 0x1b:exit(0);break;
      case 0x20:gc(0x07);break;
      case 0x2e:speed-=10000;break;
      case 0x2c:speed+=10000;break;
      case 0x6c:if(k==PAL)k=1;else k=PAL;break;
      case 0x70:if(pflag==1)pflag=0;else pflag=1;break;
     }
    gc(0x0b);
    if(a!=0)a--;
   }
}



