home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / benchmar / cdrop / xmrglf1.c < prev    next >
Encoding:
C/C++ Source or Header  |  1985-10-02  |  1.8 KB  |  81 lines

  1. /* xmrglf1.c - Xmodem receive using G'Leaf Comm lib */
  2. #include "stdio.h"
  3. #include "gf.h"
  4. #include "asiports.h"
  5.  
  6. #define  CARD  2        /* which RS-232 port to use */
  7.  
  8. char combuf[1150] ;
  9. char obuf[1150] ;
  10. int port = 1 ;
  11.  
  12.  
  13. main(argc,argv)
  14.  int argc ;
  15.  char *argv[] ;
  16.  {
  17.     int c , err , n , t ,speed , lstat , mstat ;
  18.  
  19.     if( argc < 3 )
  20.       { printf(" no file name or baud rate \n");
  21.         exit(5) ;
  22.       }
  23.  
  24.     sscanf(argv[2],"%d",&speed) ;
  25.     asisetup(port,ASINOUT,0,combuf,1000,obuf,1000) ;
  26.     asdtr(port,ON) ;
  27.     asiinit(port,speed,0,1,8) ;
  28.     asistart(port,ASINOUT) ;
  29.  
  30.     eltime() ;
  31.     err = rcv_filet(argv[1],&n) ;
  32.     t = eltime() ;
  33.     printf("  %4d Ticks  or %8.2f Secs \n",t,((float) t) / 18.2) ;
  34.     printf("  rcv_file - err=%d     no recs. xmtted=%d \n",err,n) ;
  35.  
  36.     asiquit(port) ;
  37.  }
  38.  
  39.  
  40. int rcv_file(fn,pn) 
  41.  char fn[] ;            /* file name */
  42.  int *pn ;            /* put record count here */
  43.  {
  44.     FILE *fd ;
  45.     char buf[140] ;
  46.     int block , ret ,nw ;
  47.     struct XMBUF locparms ;
  48.  
  49.     fd = fopen(fn,"wb") ;
  50.     if( fd == NULL )
  51.       { printf(" can't open file \n");
  52.         return(-1) ;
  53.       }
  54.  
  55.     block = 1 ;
  56.     ret = -200 ;
  57.     while( 1 == 1 )
  58.       { locparms.xblocknum = block ;
  59.         ret = asixrecvbuf(port,buf,&locparms) ;
  60.         if( ret == 0 )
  61.           {
  62.             nw = fwrite(buf,1,128,fd) ;
  63.             printf(" block %4d - rcvd OK \n",block );
  64.           }
  65.         else if( locparms.xstatus == 6 )
  66.       { printf(" rcvd EOT \n") ;
  67.             asiputc(port,ACK) ;
  68.             break ;
  69.           }
  70.         else
  71.           { printf(" block %4d - error %d \n",block);
  72.             break ;
  73.           }
  74.         block ++ ;
  75.       }
  76.     fclose(fd) ;
  77.     *pn = block ;
  78.     return( ret ) ;
  79.  }
  80. 
  81.