home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / os9 / os9dt.c < prev    next >
C/C++ Source or Header  |  2020-01-01  |  2KB  |  82 lines

  1. /* dterm.c */
  2. /* dumb terminal program by Robert A. Larson */
  3. /* designed to capture kermit for better file transfer */
  4.  
  5. /* use: dterm device [filename]... */
  6. /* where device is the device to use, i.e. /t2 */
  7. /* files greater than MAXCAPTURE characters will cause problems without warning */
  8. /* FLAG is a rarly used character, (^J) used to give commands to dterm */
  9. /* FLAG b will begin the file capture */
  10. /* FLAG e will end the file capture and write the file "captured" to the disk */
  11. /* FLAG c will exit dterm */
  12. /* FLAG FLAG will send itself */
  13.  
  14. #define MAXCAPTURE 40000 /* maximum size of file to capture */
  15. #define FLAG 10
  16. #define LF 10
  17.  
  18. #include <sgstat.h>
  19.  
  20. main(argc,argv)
  21. int argc;
  22. char **argv;
  23. {
  24.   char c;
  25.   int pn, pnc;
  26.   struct sgbuf sgold, sgnew;
  27.   int capture;
  28.   static char buf[MAXCAPTURE];
  29.   char *bufp;
  30.   argc-=2;
  31.   pn=open(*++argv,3);
  32.   getstat(0,0,&sgold); /* save status */
  33.   /* set stdin to not treat anything specially */
  34.   getstat(0,0,&sgnew);
  35.   sgnew.sg_backsp=0;
  36.   sgnew.sg_delete=0;
  37.   sgnew.sg_echo=0;
  38.   sgnew.sg_alf=0;
  39.   sgnew.sg_pause=0;
  40.   sgnew.sg_bspch=0;
  41.   sgnew.sg_dlnch=0;
  42.   sgnew.sg_psch=0;
  43.   sgnew.sg_kbich=0;
  44.   sgnew.sg_kbach=0;
  45.   sgnew.sg_bsech=0;
  46.   setstat(0,0,&sgnew);
  47.   capture=0;
  48.   bufp=&buf[0];
  49.   for(;;){
  50.     if(!getstat(1,pn)){
  51.       read(pn,&c,1);
  52.       c &= 0177;
  53.       if(c && capture && (c!=LF)) *bufp++=c;
  54.       write(1,&c,1);
  55.     }
  56.     if(!getstat(1,0)){
  57.       read(0,&c,1);
  58.       c &= 0177;
  59.       if(c==FLAG){
  60.         read(0,&c,1);
  61.         c &= 0177;
  62.         if(c=='c')break;
  63.         if(c=='b' && argc){
  64.           --argc;
  65.           pnc=creat(*++argv,3);
  66.           capture=1;
  67.           continue;
  68.         }
  69.         if(c=='e'){
  70.           capture=0;
  71.           write(pnc,&buf[0],bufp-&buf[0]);
  72.           close(pnc);
  73.           continue;
  74.         }
  75.       }
  76.       write(pn,&c,1);
  77.     }
  78.   }
  79.   close(pn);
  80.   setstat(0,0,&sgold);
  81. }
  82.