home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / telecomm / autolog / autolog.c next >
C/C++ Source or Header  |  1989-06-03  |  3KB  |  157 lines

  1. #include <osbind.h>
  2. #include <bios.h>
  3. #include <aesbind.h>
  4. #include <gemdefs.h>
  5. #include <special2.h>
  6.  
  7. char buffer[25],keybuffer[100],text[1000],name[16],filename[128];
  8. char buffer2[25],ret[]="\n",*cp,*kb,*tx;
  9.  
  10. int rsinput,key,button,ii,checkinput,result;
  11. int drv,count,backcount,gchk;
  12.  
  13. FILE *fp;
  14.  
  15. long keyinp,textlen;
  16.  
  17. main()
  18. {
  19.     appl_init();            /* open application    */
  20.     graf_mouse(M_OFF,0);    /* turn mouse off    */
  21.     cls;
  22.     title();
  23.     checkinput=0;
  24.     kb=keybuffer;
  25.     tx=text;
  26.     backcount=0;
  27.     gchk=0;
  28.  
  29.     get_input();            /* accept input        */
  30. }
  31.  
  32. get_input()
  33. {
  34.     for(;;)
  35.     {
  36.         while(Bconstat(1)==-1)    /* loop while char is ready    */
  37.         {
  38.             if(checkinput==1)
  39.             {
  40.                 save_data();    /* save buffer, reset flag    */
  41.                 checkinput=0;
  42.                 backcount=0;
  43.             }
  44.             
  45.             rsinput=Bconin(1);    /* get char from seriel        */
  46.                     
  47.             if (rsinput=='>')
  48.                 gchk=1;
  49.             
  50.             if (buffer[3]==13 || buffer[3]==10)
  51.             {
  52.                 gchk=0;
  53.                 for(ii=0;ii<=24;ii++)
  54.                 {
  55.                     buffer[ii]=0;    
  56.                     buffer2[ii]=0;
  57.                 }
  58.             }    
  59.             
  60.             if((rsinput>=32 && rsinput<=126 && gchk==0)|| rsinput==13)
  61.             {
  62.                 for(ii=24;ii>0;ii--) /* build buffer        */
  63.                     buffer[ii]=buffer[ii-1];
  64.                 buffer[0]=rsinput;
  65.             }
  66.             
  67.             Cconout(rsinput);        /* print character        */
  68.         }
  69.         
  70.         if (Bconstat(2)==-1)
  71.         { 
  72.             keyinp=Bconin(2);
  73.             key=keyinp & 0xff;         
  74.             if (keyinp==3866624)    /* check for F1            */
  75.                 save_file();        /* save capture            */
  76.             if(keyinp==6356992)        /* check for UNDO        */
  77.                 quit();                /* quit program            */
  78.             gchk=0;
  79.             if (key==8 && backcount>0)
  80.             {
  81.                 backcount--;        /* count # of char inputted */
  82.                 *kb--=0;            /* erase character        */
  83.                 Bconout(1,(int)key); /* output to seriel    */
  84.                 for (ii=0;ii<3;ii++)
  85.                     Cconout((int)Bconin(1)); /* print echo char */
  86.             }
  87.             
  88.             if (key>=1 && key<=126 && key!=8)
  89.             {
  90.                 backcount++;        /* count # of char inputted */
  91.                 if (backcount==100)
  92.                 {
  93.                     kb==keybuffer; /* check for overflow        */
  94.                     backcount=0;
  95.                     for (ii=0;ii<100;ii++)
  96.                         keybuffer[ii]=0;
  97.                 }
  98.                 Bconout(1,(int)key);
  99.                 key=(key==13) ? '|' : key;  /* handle carr ret    */
  100.                 *kb++=key;                /* save input            */
  101.                 checkinput=1;
  102.             }
  103.             if ((key>=32 && key<=126) || key==13)
  104.                 Cconout((int)Bconin(1));    /* print echo char    */
  105.         } 
  106.     }
  107. }
  108.  
  109. save_data()
  110. {
  111.     count=0;
  112.     for(ii=24;ii>=0;ii--)
  113.     {
  114.         if (buffer[ii]>31)
  115.         {
  116.             buffer2[count]=buffer[ii];
  117.             count++;
  118.         }
  119.     }
  120.     
  121.     strcat(text,">WA ");            /* the WAIT command        */
  122.     strcat(text,buffer2);            /* string to wait for    */
  123.     strcat(text,"|");                /* RETURN character        */
  124.     strcat(text,ret);                /* REAL carr return        */
  125.     strcat(text,keybuffer);            /* copy response        */
  126.     strcat(text,ret);
  127.     
  128.     kb=keybuffer;                    /* reset pointer        */
  129.     for(ii=0;ii<100;ii++)            /* clear buffer            */
  130.         keybuffer[ii]=0;
  131. }
  132.  
  133. save_file()
  134. {
  135.     get_file(filename,"*.DO");
  136.     
  137.     if (filename[0]!=0)
  138.     {
  139.         fp=fopen(filename,"w");        /* create file    */
  140.         fwrite(text,1,strlen(text),fp);
  141.         fclose(fp);    
  142.         quit();
  143.     }
  144. }
  145.  
  146. quit()
  147. {
  148.     appl_exit();                /* close application        */
  149.     printf("\33f\n");            /* turn cursor off            */
  150.     exit(0);
  151. }
  152.  
  153. title()
  154. {
  155.     printf("\33j                     \33p Bob Areddy's Autolog  (c) 1989 \33q\33k\n");
  156. }
  157.