home *** CD-ROM | disk | FTP | other *** search
/ minnie.tuhs.org / unixen.tar / unixen / PDP-11 / Distributions / ucb / 2.9-derivatives / 2.9-pro350 / misc / putfile.c < prev    next >
Encoding:
C/C++ Source or Header  |  1984-02-12  |  953 b   |  47 lines

  1. /* This little program downloads a file given as arg1 to the
  2.  * serial line given as arg2. It assumes that the prog. getfile
  3.  * is already running on the slave system at the other end of
  4.  * the line.
  5.  */
  6. #include <stdio.h>
  7. #include <sgtty.h>
  8.  
  9. struct sgttyb ttyb = { B9600, B9600, 0 , 0, RAW };
  10.  
  11. #define    PREFIX    05
  12. #define    ACK    07
  13. #define    NAK    011
  14. char buff[514];
  15. main(argc, argv)
  16. int argc;
  17. char *argv[];
  18. {
  19.     register int i, chk;
  20.     int ifl, ofl;
  21.     int cnt;
  22.     char ack;
  23.  
  24.     if (argc != 3 || (ifl = open(argv[1],0))<0 || (ofl = open(argv[2],2))<0
  25.         || ioctl(ofl, TIOCSETP, &ttyb)<0) {
  26.         printf("Usage: putfile infile outdev\n");
  27.         exit(2);
  28.     }
  29.     buff[0] = PREFIX;
  30.     cnt = 0;
  31.     while (read(ifl, &buff[1], 512) > 0) {
  32.         chk = 0;
  33.         for (i = 1; i <= 512; i++)
  34.             chk += buff[i];
  35.         buff[513] = chk;
  36.         do {
  37.             write(ofl, buff, 514);
  38.             read(ofl, &ack, 1);
  39.             if (ack == NAK) {
  40.                 printf("Err on blk=%d\n",cnt);
  41.                 fflush(stdout);
  42.             }
  43.         } while (ack != ACK);
  44.         cnt++;
  45.     }
  46. }
  47.