home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume12 / zmodem / part01 next >
Encoding:
Internet Message Format  |  1987-10-18  |  40.0 KB

  1. Subject:  v12i021:  Zmodem file transfer programs, Part01/03
  2. Newsgroups: comp.sources.unix
  3. Sender: sources
  4. Approved: rs@uunet.UU.NET
  5.  
  6. Submitted-by: omen!caf
  7. Posting-number: Volume 12, Issue 21
  8. Archive-name: zmodem/part01
  9.  
  10. [  These package is a fast family of transfer programs between Unices,
  11.    PC's, etc.  The CRC kit is nice, too.  --r$  ]
  12.  
  13. Source code for Unix ZMODEM programs rz.c and sz.c and related files follows.
  14. ZMODEM is the ideal protocol for file transfer to and from Unix systems
  15. using a serial port. The source code has also been used for numerous ZMODEM
  16. versions, including the Opus bulletin board (Fido replacemet).  ZMODEM's
  17. pleasant user interface with automatic file and command download allows a
  18. Makefile to control a DOS machine running Pro-YAM, dor example.
  19.  
  20. #!/bin/sh
  21. # to extract, remove the header and type "sh filename"
  22. if `test ! -s ./rbsb.c`
  23. then
  24. echo "Writing ./rbsb.c"
  25. cat > ./rbsb.c << '\Rogue\Monster\'
  26. /*
  27.  *
  28.  * -rev 04-16-87
  29.  *  This file contains Unix specific code for setting terminal modes,
  30.  *  very little is specific to ZMODEM or YMODEM per se (that code is in
  31.  *  sz.c and rz.c).  The CRC-16 routines used by XMODEM, YMODEM, and ZMODEM
  32.  *  are also in this file, a fast table driven macro version
  33.  *
  34.  *   This file is #included so the main file can set parameters such as HOWMANY.
  35.  *   See the main files (rz.c/sz.c) for compile instructions.
  36.  */
  37.  
  38. #ifdef V7
  39. #include <sys/types.h>
  40. #include <sys/stat.h>
  41. #include <sgtty.h>
  42. #define OS "V7/BSD"
  43. #endif
  44.  
  45. #ifndef OS
  46. #ifndef USG
  47. #define USG
  48. #endif
  49. #endif
  50.  
  51. #ifdef USG
  52. #include <sys/types.h>
  53. #include <sys/stat.h>
  54. #include <termio.h>
  55. #include <sys/ioctl.h>
  56. #define OS "SYS III/V"
  57. #endif
  58.  
  59. #if HOWMANY  > 255
  60. Howmany must be 255 or less
  61. #endif
  62.  
  63. struct {
  64.     unsigned baudr;
  65.     int speedcode;
  66. } speeds[] = {
  67.     110,    B110,
  68.     300,    B300,
  69.     600,    B600,
  70.     1200,    B1200,
  71.     2400,    B2400,
  72.     4800,    B4800,
  73.     9600,    B9600,
  74.     19200,    EXTA,
  75.     9600,    EXTB,
  76.     0,
  77. };
  78.  
  79. int Twostop;        /* Use two stop bits */
  80.  
  81. static unsigned
  82. getspeed(code)
  83. {
  84.     register n;
  85.  
  86.     for (n=0; speeds[n].baudr; ++n)
  87.         if (speeds[n].speedcode == code)
  88.             return speeds[n].baudr;
  89.     return 0;
  90. }
  91.  
  92.  
  93.  
  94. #ifdef ICANON
  95. struct termio oldtty, tty;
  96. #else
  97. struct sgttyb oldtty, tty;
  98. struct tchars oldtch, tch;
  99. #endif
  100.  
  101. int iofd = 0;        /* File descriptor for ioctls & reads */
  102.  
  103. /*
  104.  * mode(n)
  105.  *  3: save old tty stat, set raw mode with flow control
  106.  *  2: set a cbreak, XON/XOFF control mode if using Pro-YAM's -g option
  107.  *  1: save old tty stat, set raw mode 
  108.  *  0: restore original tty mode
  109.  */
  110. mode(n)
  111. {
  112.     static did0 = FALSE;
  113.  
  114.     vfile("mode:%d", n);
  115.     switch(n) {
  116. #ifdef USG
  117.     case 2:    /* Cbreak mode used by sb when -g detected */
  118.         if(!did0)
  119.             (void) ioctl(iofd, TCGETA, &oldtty);
  120.         tty = oldtty;
  121.  
  122.         tty.c_iflag = BRKINT|IXON;
  123.  
  124.         tty.c_oflag = 0;    /* Transparent output */
  125.  
  126.         tty.c_cflag &= ~PARENB;    /* Disable parity */
  127.         tty.c_cflag |= CS8;    /* Set character size = 8 */
  128.         if (Twostop)
  129.             tty.c_cflag |= CSTOPB;    /* Set two stop bits */
  130.  
  131.         tty.c_lflag = 
  132. #ifdef XCLUDE
  133.           XCLUDE |
  134. #endif
  135.           Zmodem ? 0 : ISIG;
  136.  
  137.         tty.c_cc[VINTR] = 030;        /* Interrupt char */
  138.         tty.c_cc[VMIN] = 1;
  139.  
  140.         (void) ioctl(iofd, TCSETAW, &tty);
  141.         did0 = TRUE;
  142.         return OK;
  143.     case 1:
  144.     case 3:
  145.         if(!did0)
  146.             (void) ioctl(iofd, TCGETA, &oldtty);
  147.         tty = oldtty;
  148.  
  149.         tty.c_iflag = n==3 ? (IGNBRK|IXOFF) : IGNBRK;
  150.  
  151.          /* No echo, crlf mapping, INTR, QUIT, delays, no erase/kill */
  152.         tty.c_lflag &= ~(ECHO | ICANON | ISIG);
  153. #ifdef XCLUDE
  154.         tty.c_lflag |= XCLUDE;
  155. #endif
  156.  
  157.         tty.c_oflag = 0;    /* Transparent output */
  158.  
  159.         tty.c_cflag &= ~PARENB;    /* Same baud rate, disable parity */
  160.         tty.c_cflag |= CS8;    /* Set character size = 8 */
  161.         if (Twostop)
  162.             tty.c_cflag |= CSTOPB;    /* Set two stop bits */
  163. #ifdef NFGVMIN
  164.         tty.c_cc[VMIN] = 1; /* This many chars satisfies reads */
  165. #else
  166.         tty.c_cc[VMIN] = HOWMANY; /* This many chars satisfies reads */
  167. #endif
  168.         tty.c_cc[VTIME] = 1;    /* or in this many tenths of seconds */
  169.         (void) ioctl(iofd, TCSETAW, &tty);
  170.         did0 = TRUE;
  171.         Baudrate = getspeed(tty.c_cflag & CBAUD);
  172.         return OK;
  173. #endif
  174. #ifdef V7
  175.     case 2:    /*  This doesn't work ... */
  176.         printf("No mode(2) in V7/BSD!"); bibi(99);
  177.         if(!did0) {
  178.             ioctl(iofd, TIOCEXCL, 0);
  179.             ioctl(iofd, TIOCGETP, &oldtty);
  180.             ioctl(iofd, TIOCGETC, &oldtch);
  181.         }
  182.         tty = oldtty;
  183.         tch = oldtch;
  184.         tch.t_intrc = Zmodem ? 03:030;    /* Interrupt char */
  185.         tty.sg_flags |= (ODDP|EVENP|CBREAK);
  186.         tty.sg_flags &= ~(ALLDELAY|CRMOD|ECHO|LCASE);
  187.         ioctl(iofd, TIOCSETP, &tty);
  188.         ioctl(iofd, TIOCSETC, &tch);
  189.         did0 = TRUE;
  190.         return OK;
  191.     case 1:
  192.     case 3:
  193.         if(!did0) {
  194.             ioctl(iofd, TIOCEXCL, 0);
  195.             ioctl(iofd, TIOCGETP, &oldtty);
  196.             ioctl(iofd, TIOCGETC, &oldtch);
  197.         }
  198.         tty = oldtty;
  199.         tty.sg_flags |= RAW;
  200.         tty.sg_flags &= ~ECHO;
  201.         ioctl(iofd, TIOCSETP, &tty);
  202.         did0 = TRUE;
  203.         Baudrate = getspeed(tty.sg_ospeed);
  204.         return OK;
  205. #endif
  206.     case 0:
  207.         if(!did0)
  208.             return ERROR;
  209. #ifdef USG
  210.         (void) ioctl(iofd, TCSBRK, 1);    /* Wait for output to drain */
  211.         (void) ioctl(iofd, TCFLSH, 1);    /* Flush input queue */
  212.         (void) ioctl(iofd, TCSETAW, &oldtty);    /* Restore original modes */
  213.         (void) ioctl(iofd, TCXONC,1);    /* Restart output */
  214. #endif
  215. #ifdef V7
  216.         ioctl(iofd, TIOCSETP, &oldtty);
  217.         ioctl(iofd, TIOCSETC, &oldtch);
  218.         ioctl(iofd, TIOCNXCL, 0);
  219. #endif
  220.         return OK;
  221.     default:
  222.         return ERROR;
  223.     }
  224. }
  225.  
  226. sendbrk()
  227. {
  228. #ifdef V7
  229. #ifdef TIOCSBRK
  230. #define CANBREAK
  231.     sleep(1);
  232.     ioctl(iofd, TIOCSBRK, 0);
  233.     sleep(1);
  234.     ioctl(iofd, TIOCCBRK, 0);
  235. #endif
  236. #endif
  237. #ifdef USG
  238. #define CANBREAK
  239.     ioctl(iofd, TCSBRK, 0);
  240. #endif
  241. }
  242.  
  243. #ifdef FIONREAD
  244. #define READCHECK
  245. /*
  246.  *  Return non 0 iff something to read from io descriptor f
  247.  */
  248. rdchk(f)
  249. {
  250.     static long lf;
  251.  
  252.     ioctl(f, FIONREAD, &lf);
  253.     return ((int) lf);
  254. }
  255. #endif
  256. #ifdef SVR2
  257. #define READCHECK
  258. #include <fcntl.h>
  259.  
  260. char checked = '\0' ;
  261. /*
  262.  * Nonblocking I/O is a bit different in System V, Release 2
  263.  */
  264. rdchk(f)
  265. {
  266.     int lf, savestat = fcntl(f, F_GETFL) ;
  267.  
  268.     fcntl(f, F_SETFL, savestat | O_NDELAY) ;
  269.     lf = read(f, &checked, 1) ;
  270.     fcntl(f, F_SETFL, savestat) ;
  271.     return(lf) ;
  272. }
  273. #endif
  274.  
  275.  
  276. /* crctab calculated by Mark G. Mendel, Network Systems Corporation */
  277. static unsigned short crctab[256] = {
  278.     0x0000,  0x1021,  0x2042,  0x3063,  0x4084,  0x50a5,  0x60c6,  0x70e7,
  279.     0x8108,  0x9129,  0xa14a,  0xb16b,  0xc18c,  0xd1ad,  0xe1ce,  0xf1ef,
  280.     0x1231,  0x0210,  0x3273,  0x2252,  0x52b5,  0x4294,  0x72f7,  0x62d6,
  281.     0x9339,  0x8318,  0xb37b,  0xa35a,  0xd3bd,  0xc39c,  0xf3ff,  0xe3de,
  282.     0x2462,  0x3443,  0x0420,  0x1401,  0x64e6,  0x74c7,  0x44a4,  0x5485,
  283.     0xa56a,  0xb54b,  0x8528,  0x9509,  0xe5ee,  0xf5cf,  0xc5ac,  0xd58d,
  284.     0x3653,  0x2672,  0x1611,  0x0630,  0x76d7,  0x66f6,  0x5695,  0x46b4,
  285.     0xb75b,  0xa77a,  0x9719,  0x8738,  0xf7df,  0xe7fe,  0xd79d,  0xc7bc,
  286.     0x48c4,  0x58e5,  0x6886,  0x78a7,  0x0840,  0x1861,  0x2802,  0x3823,
  287.     0xc9cc,  0xd9ed,  0xe98e,  0xf9af,  0x8948,  0x9969,  0xa90a,  0xb92b,
  288.     0x5af5,  0x4ad4,  0x7ab7,  0x6a96,  0x1a71,  0x0a50,  0x3a33,  0x2a12,
  289.     0xdbfd,  0xcbdc,  0xfbbf,  0xeb9e,  0x9b79,  0x8b58,  0xbb3b,  0xab1a,
  290.     0x6ca6,  0x7c87,  0x4ce4,  0x5cc5,  0x2c22,  0x3c03,  0x0c60,  0x1c41,
  291.     0xedae,  0xfd8f,  0xcdec,  0xddcd,  0xad2a,  0xbd0b,  0x8d68,  0x9d49,
  292.     0x7e97,  0x6eb6,  0x5ed5,  0x4ef4,  0x3e13,  0x2e32,  0x1e51,  0x0e70,
  293.     0xff9f,  0xefbe,  0xdfdd,  0xcffc,  0xbf1b,  0xaf3a,  0x9f59,  0x8f78,
  294.     0x9188,  0x81a9,  0xb1ca,  0xa1eb,  0xd10c,  0xc12d,  0xf14e,  0xe16f,
  295.     0x1080,  0x00a1,  0x30c2,  0x20e3,  0x5004,  0x4025,  0x7046,  0x6067,
  296.     0x83b9,  0x9398,  0xa3fb,  0xb3da,  0xc33d,  0xd31c,  0xe37f,  0xf35e,
  297.     0x02b1,  0x1290,  0x22f3,  0x32d2,  0x4235,  0x5214,  0x6277,  0x7256,
  298.     0xb5ea,  0xa5cb,  0x95a8,  0x8589,  0xf56e,  0xe54f,  0xd52c,  0xc50d,
  299.     0x34e2,  0x24c3,  0x14a0,  0x0481,  0x7466,  0x6447,  0x5424,  0x4405,
  300.     0xa7db,  0xb7fa,  0x8799,  0x97b8,  0xe75f,  0xf77e,  0xc71d,  0xd73c,
  301.     0x26d3,  0x36f2,  0x0691,  0x16b0,  0x6657,  0x7676,  0x4615,  0x5634,
  302.     0xd94c,  0xc96d,  0xf90e,  0xe92f,  0x99c8,  0x89e9,  0xb98a,  0xa9ab,
  303.     0x5844,  0x4865,  0x7806,  0x6827,  0x18c0,  0x08e1,  0x3882,  0x28a3,
  304.     0xcb7d,  0xdb5c,  0xeb3f,  0xfb1e,  0x8bf9,  0x9bd8,  0xabbb,  0xbb9a,
  305.     0x4a75,  0x5a54,  0x6a37,  0x7a16,  0x0af1,  0x1ad0,  0x2ab3,  0x3a92,
  306.     0xfd2e,  0xed0f,  0xdd6c,  0xcd4d,  0xbdaa,  0xad8b,  0x9de8,  0x8dc9,
  307.     0x7c26,  0x6c07,  0x5c64,  0x4c45,  0x3ca2,  0x2c83,  0x1ce0,  0x0cc1,
  308.     0xef1f,  0xff3e,  0xcf5d,  0xdf7c,  0xaf9b,  0xbfba,  0x8fd9,  0x9ff8,
  309.     0x6e17,  0x7e36,  0x4e55,  0x5e74,  0x2e93,  0x3eb2,  0x0ed1,  0x1ef0
  310. };
  311.  
  312. /*
  313.  * updcrc macro derived from article Copyright (C) 1986 Stephen Satchell. 
  314.  *  NOTE: First srgument must be in range 0 to 255.
  315.  *        Second argument is referenced twice.
  316.  * 
  317.  * Programmers may incorporate any or all code into their programs, 
  318.  * giving proper credit within the source. Publication of the 
  319.  * source routines is permitted so long as proper credit is given 
  320.  * to Stephen Satchell, Satchell Evaluations and Chuck Forsberg, 
  321.  * Omen Technology.
  322.  */
  323.  
  324. #define updcrc(cp, crc) ( crctab[((crc >> 8) & 255)] ^ (crc << 8) ^ cp)
  325.  
  326. /*
  327.  * Copyright (C) 1986 Gary S. Brown.  You may use this program, or
  328.  * code or tables extracted from it, as desired without restriction.
  329.  */
  330.  
  331. /* First, the polynomial itself and its table of feedback terms.  The  */
  332. /* polynomial is                                                       */
  333. /* X^32+X^26+X^23+X^22+X^16+X^12+X^11+X^10+X^8+X^7+X^5+X^4+X^2+X^1+X^0 */
  334. /* Note that we take it "backwards" and put the highest-order term in  */
  335. /* the lowest-order bit.  The X^32 term is "implied"; the LSB is the   */
  336. /* X^31 term, etc.  The X^0 term (usually shown as "+1") results in    */
  337. /* the MSB being 1.                                                    */
  338.  
  339. /* Note that the usual hardware shift register implementation, which   */
  340. /* is what we're using (we're merely optimizing it by doing eight-bit  */
  341. /* chunks at a time) shifts bits into the lowest-order term.  In our   */
  342. /* implementation, that means shifting towards the right.  Why do we   */
  343. /* do it this way?  Because the calculated CRC must be transmitted in  */
  344. /* order from highest-order term to lowest-order term.  UARTs transmit */
  345. /* characters in order from LSB to MSB.  By storing the CRC this way,  */
  346. /* we hand it to the UART in the order low-byte to high-byte; the UART */
  347. /* sends each low-bit to hight-bit; and the result is transmission bit */
  348. /* by bit from highest- to lowest-order term without requiring any bit */
  349. /* shuffling on our part.  Reception works similarly.                  */
  350.  
  351. /* The feedback terms table consists of 256, 32-bit entries.  Notes:   */
  352. /*                                                                     */
  353. /*     The table can be generated at runtime if desired; code to do so */
  354. /*     is shown later.  It might not be obvious, but the feedback      */
  355. /*     terms simply represent the results of eight shift/xor opera-    */
  356. /*     tions for all combinations of data and CRC register values.     */
  357. /*                                                                     */
  358. /*     The values must be right-shifted by eight bits by the "updcrc"  */
  359. /*     logic; the shift must be unsigned (bring in zeroes).  On some   */
  360. /*     hardware you could probably optimize the shift in assembler by  */
  361. /*     using byte-swap instructions.                                   */
  362.  
  363. static long cr3tab[] = { /* CRC polynomial 0xedb88320 */
  364. 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,
  365. 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91,
  366. 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
  367. 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5,
  368. 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
  369. 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
  370. 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f,
  371. 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d,
  372. 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
  373. 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
  374. 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457,
  375. 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
  376. 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb,
  377. 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9,
  378. 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
  379. 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad,
  380. 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683,
  381. 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
  382. 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7,
  383. 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
  384. 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
  385. 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79,
  386. 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f,
  387. 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
  388. 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
  389. 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21,
  390. 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
  391. 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45,
  392. 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db,
  393. 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
  394. 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf,
  395. 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
  396. };
  397.  
  398. #ifdef NFGM
  399. long
  400. UPDC32(b, c)
  401. long c;
  402. {
  403.     return (cr3tab[((int)c ^ b) & 0xff] ^ ((c >> 8) & 0x00FFFFFF));
  404. }
  405.  
  406. #else
  407.  
  408. #define UPDC32(b, c) (cr3tab[((int)c ^ b) & 0xff] ^ ((c >> 8) & 0x00FFFFFF))
  409. #endif
  410.  
  411. /* End of rbsb.c */
  412. \Rogue\Monster\
  413. else
  414.   echo "will not over write ./rbsb.c"
  415. fi
  416. if [ `wc -c ./rbsb.c | awk '{printf $1}'` -ne 13703 ]
  417. then
  418. echo `wc -c ./rbsb.c | awk '{print "Got " $1 ", Expected " 13703}'`
  419. fi
  420. if `test ! -s ./minirb.c`
  421. then
  422. echo "Writing ./minirb.c"
  423. cat > ./minirb.c << '\Rogue\Monster\'
  424. /*
  425.  * minirb.c By Chuck Forsberg Omen Technology INC
  426.  *        "The High Reliability Communications Software"
  427.  *
  428.  * A bootstrap program for Unix to receive files from computers running
  429.  *  YMODEM Batch (Professional-YAM, PowerCom, ZCOMM, etc.).
  430.  *
  431.  *  Minirb uses system(3) to call stty, avoiding system dependent code.
  432.  *   program strips CR and CPMEOF (^Z) characters (see putsec()).
  433.  *  Please refer to rz.c for comments, etc.
  434.  */
  435. char * Version = "minirb 2.00 05-25-87";
  436.  
  437. #include <stdio.h>
  438. #include <signal.h>
  439. #include <setjmp.h>
  440.  
  441. #define OK 0
  442. #define FALSE 0
  443. #define TRUE 1
  444. #define ERROR (-1)
  445. #define CAN ('X'&037)
  446. #define SOH 1
  447. #define STX 2
  448. #define EOT 4
  449. #define ACK 6
  450. #define NAK 025
  451. #define TIMEOUT (-2)
  452. #define RETRYMAX 9
  453. #define WCEOT (-10)
  454.  
  455. FILE *fout;
  456. long Bytesleft;
  457. int Blklen;
  458. char secbuf[1024];
  459. char linbuf[1024];
  460. int Lleft=0;
  461. jmp_buf tohere;
  462.  
  463. alrm() { longjmp(tohere, -1); }
  464.  
  465. bibi(n) {
  466.  canit(); mode(0);
  467.  fprintf(stderr, "minirb: caught signal %d; exiting", n);
  468.  exit(128+n);
  469. }
  470.  
  471. mode(n) {
  472.  if (n) system("stty raw -echo");
  473.  else system("stty echo -raw");
  474. }
  475.  
  476. main() {
  477.  mode(1);
  478.  if (signal(SIGINT, bibi) == SIG_IGN) {
  479.   signal(SIGINT, SIG_IGN); signal(SIGKILL, SIG_IGN);
  480.  } else {
  481.   signal(SIGINT, bibi); signal(SIGKILL, bibi);
  482.  }
  483.  printf("minirb: Now send file(s) with \042sb file ...\042 command\r\n");
  484.  
  485.  if (wcreceive()==ERROR)
  486.   canit();
  487.  mode(0); exit(0);
  488. }
  489.  
  490. wcreceive() {
  491.  for (;;) {
  492.   if (wcrxpn(secbuf) == ERROR) break;
  493.   if (secbuf[0]==0) return OK;
  494.   if (procheader(secbuf)==ERROR || wcrx()==ERROR) break;
  495.  }
  496.  canit(); return ERROR;
  497. }
  498.  
  499.  
  500. wcrxpn(rpn) char *rpn; {
  501.  register c;
  502.  
  503.  purgeline();
  504. et_tu:
  505.  sendline(NAK); Lleft=0;
  506.  while ((c = wcgetsec(rpn, 100)) != 0) {
  507.   if (c == WCEOT) { sendline(ACK); Lleft=0; readline(1); goto et_tu; }
  508.   return ERROR;
  509.  }
  510.  sendline(ACK); return OK;
  511. }
  512.  
  513. wcrx() {
  514.  register int sectnum, sectcurr, sendchar, cblklen;
  515.  
  516.  sectnum=0; sendchar=NAK;
  517.  for (;;) {
  518.   sendline(sendchar); Lleft=0;
  519.   sectcurr=wcgetsec(secbuf, 50);
  520.   if (sectcurr==(sectnum+1 & 0377)) {
  521.    sectnum++; cblklen = Bytesleft>Blklen ? Blklen:Bytesleft;
  522.    putsec(secbuf, cblklen);
  523.    if ((Bytesleft-=cblklen) < 0) Bytesleft = 0;
  524.    sendchar=ACK;
  525.   }
  526.   else if (sectcurr==(sectnum&0377)) sendchar=ACK;
  527.   else if (sectcurr==WCEOT) {
  528.    if (fclose(fout)==ERROR) return ERROR;
  529.    sendline(ACK); Lleft=0; return OK;
  530.   }
  531.   else if (sectcurr==ERROR) return ERROR;
  532.   else return ERROR;
  533.  }
  534. }
  535.  
  536. wcgetsec(rxbuf, maxtime) char *rxbuf; int maxtime; {
  537.  register checksum, wcj, firstch; register char *p; int sectcurr, errors;
  538.  for (errors=0; errors<RETRYMAX; errors++) {
  539.   if ((firstch=readline(maxtime))==STX) { Blklen=1024; goto get2; }
  540.   if (firstch==SOH) {
  541.    Blklen=128;
  542. get2:
  543.    sectcurr=readline(1); checksum=0;
  544.    if ((sectcurr+(readline(1)))==0377) {
  545.     for (p=rxbuf,wcj=Blklen; --wcj>=0; ) {
  546.      if ((firstch=readline(1)) < 0) goto bilge;
  547.      checksum += (*p++ = firstch);
  548.     }
  549.     if ((firstch=readline(1)) < 0) goto bilge;
  550.     if (((checksum-firstch)&0377)==0) return sectcurr;
  551.    }
  552.   }
  553.   else if (firstch==EOT) return WCEOT;
  554.   else if (firstch==CAN) return ERROR;
  555. bilge:
  556.   while(readline(1)!=TIMEOUT)
  557.    ;
  558.   maxtime=40; sendline(NAK); Lleft=0;
  559.  }
  560.  canit(); return ERROR;
  561. }
  562.  
  563. readline(timeout) int timeout; {
  564.  register n; static char *cdq;
  565.  
  566.  if (--Lleft >= 0) return (*cdq++ & 0377);
  567.  n = timeout/10;
  568.  if (n < 2) n = 3;
  569.  if (setjmp(tohere)) { Lleft = 0; return TIMEOUT; }
  570.  signal(SIGALRM, alrm); alarm(n);
  571.  Lleft=read(0, cdq=linbuf, 1024); alarm(0);
  572.  if (Lleft < 1) return TIMEOUT;
  573.  --Lleft; return (*cdq++ & 0377);
  574. }
  575.  
  576. purgeline() { Lleft = 0; lseek(0, 0L, 2); }
  577.  
  578.  
  579. procheader(name) char *name; {
  580.  register char *p;
  581.  
  582.  Bytesleft = 2000000000L; p = name + 1 + strlen(name);
  583.  if (*p) sscanf(p, "%ld", &Bytesleft);
  584.  if ((fout=fopen(name, "w")) == NULL) return ERROR;
  585.  return OK;
  586. }
  587.  
  588. putsec(p, n) char *p; int n;
  589. { for (; --n>=0; ++p) if (*p != 015 && *p != 032) putc(*p, fout); }
  590.  
  591. sendline(c) { char d; d = c; write(1, &d, 1); }
  592.  
  593. char canistr[] = { 24,24,24,24,24,24,24,24,0 };
  594.  
  595. canit() { printf(canistr); Lleft=0; }
  596.  
  597. /* END of minirb.c */
  598.  
  599. \Rogue\Monster\
  600. else
  601.   echo "will not over write ./minirb.c"
  602. fi
  603. if [ `wc -c ./minirb.c | awk '{printf $1}'` -ne 4057 ]
  604. then
  605. echo `wc -c ./minirb.c | awk '{print "Got " $1 ", Expected " 4057}'`
  606. fi
  607. if `test ! -s ./minirb.1`
  608. then
  609. echo "Writing ./minirb.1"
  610. cat > ./minirb.1 << '\Rogue\Monster\'
  611. '\" Revision Level 
  612. '\" Last Delta     09-08-87
  613. .TH MINIRB 1 OMEN
  614. .SH NAME
  615. minirb \- Bootstrap YMODEM Batch file receive
  616. .SH SYNOPSIS
  617. .B minirb
  618. .SH DESCRIPTION
  619. .I Minirb
  620. receives one or more files with YMODEM batch file transfer protocol.
  621. .I Minirb
  622. was developed for use as a bootstrap to simplify uploading of the longer
  623. .I rz
  624. and
  625. .I sz
  626. programs, such as are contained in the
  627. .I rzsz.zoo
  628. "zoo" archive or the
  629. .I rzsz1et2.sh
  630. shell archive.
  631. .SH SEE ALSO
  632. YMODEM.DOC,
  633. Professional-YAM manual,
  634. sz(omen)
  635. .SH NOTES
  636. The source file
  637. .I minirb.c
  638. has been ruthlessly pruned to simplify uploading without benefit of
  639. any file transfer protocol.
  640. Do not reformat or add tabs to the source file
  641. as this would complicate uploading.
  642.  
  643. Please read the uploading suggestions in the chapter
  644. .I "File Transfer Basics"
  645. in the Professional-YAM or ZCOMM user's manual.
  646.  
  647. .I Minirb
  648. uses 8 bit checksum which may not be compatible with some programs
  649. claiming to support YMODEM batch transfers.
  650.  
  651. .I Minirb
  652. uses the
  653. YMODEM header
  654. file length information
  655. to avoid storing extraneous characters.
  656. .I Minirb
  657. deletes carriage returns and CPMEOF (^Z) characters
  658. encountered in uploaded files.
  659.  
  660. .I Minirb
  661. calls stty(1) to set and reset raw tty mode.
  662. \Rogue\Monster\
  663. else
  664.   echo "will not over write ./minirb.1"
  665. fi
  666. if [ `wc -c ./minirb.1 | awk '{printf $1}'` -ne 1213 ]
  667. then
  668. echo `wc -c ./minirb.1 | awk '{print "Got " $1 ", Expected " 1213}'`
  669. fi
  670. if `test ! -s ./rz.1`
  671. then
  672. echo "Writing ./rz.1"
  673. cat > ./rz.1 << '\Rogue\Monster\'
  674. '\" Revision Level 
  675. '\" Last Delta     05-28-87
  676. .TH RZ 1 OMEN
  677. .SH NAME
  678. rx, rb, rz \- XMODEM, YMODEM, ZMODEM (Batch) file receive
  679. .SH SYNOPSIS
  680. .B rz
  681. .RB [\- "\ +1abepqtuv" ]
  682. .br
  683. .B rb
  684. .RB [\- "\ +1abqtuv" ]
  685. .br
  686. .B rz
  687. .RB [\- "\ 1abceqtuv" ]
  688. .I file
  689. .br
  690. .B gz
  691. .I "file ..."
  692. .br
  693. .RB [ \- ][ v ] rzCOMMAND
  694. .SH DESCRIPTION
  695. This program uses error correcting protocol to receive
  696. files over a serial port from a variety of programs running under
  697. PC-DOS, CP/M,
  698. .SM Unix,
  699. and other operating systems.
  700.  
  701. The first form of
  702. .I rz
  703. (Receive ZMODEM)
  704. receives files with the ZMODEM batch protocol.
  705. If the sending program does not support ZMODEM,
  706. .I rz
  707. steps down to YMODEM protocol
  708. after 50 seconds.
  709. This delay can be eliminated by invoking the program as
  710. .I rb .
  711.  
  712. When receiving with XMODEM or YMODEM,
  713. .I Rz
  714. accepts either standard 128 byte sectors or
  715. 1024 byte sectors
  716. (YAM
  717. .B -k
  718. option).
  719. The user should determine when
  720. the longer block length
  721. actually improves throughput without causing problems.
  722.  
  723. If extended file information (file length, etc.)
  724. is received,
  725. the file length controls the number of bytes written to
  726. the output dataset (YMODEM only),
  727. and the modify time and file mode
  728. (iff non zero)
  729. are set accordingly.
  730.  
  731. If no extended file information is received,
  732. slashes in the pathname are changed to underscore,
  733. and any trailing period in the pathname is eliminated.
  734. This conversion is useful for files received from CP/M systems.
  735. With YMODEM, each file name is converted to lower case
  736. unless it contains one or more lower case letters.
  737.  
  738.  
  739. The second form of
  740. .I rz
  741. receives a single
  742. .I file
  743. with XMODEM protocol.
  744. The user must supply the file name to both sending and receiving programs.
  745.  
  746. .I Gz
  747. is a shell script which calls
  748. .I sz
  749. to command Pro-YAM or ZCOMM to transmit the specified files.
  750. Pathnames used with
  751. .I gz
  752. must be escaped if they have special significance to the Unix shell.
  753. .br
  754. EXAMPLE:
  755. gz "-a C:*.c D:*.h"
  756.  
  757.  
  758. The third form of
  759. .I rz
  760. is invoked as
  761. .B rzCOMMAND
  762. (with an optional leading \- as generated by login(1)).
  763. For each received file,
  764. rz will pipe the file to ``COMMAND filename''
  765. where filename is the name of the transmitted file
  766. with the file contents as standard input.
  767.  
  768. Each file transfer is acknowledged when COMMAND exits with 0 status.
  769. A non zero exit status terminates transfers.
  770.  
  771. A typical use for this form is
  772. .I rzrmail
  773. which calls rmail(1)
  774. to post mail to the user specified by the transmitted file name.
  775. For example, sending the file "caf" from a PC-DOS system to
  776. .I rzrmail
  777. on a
  778. .SM Unix
  779. system
  780. would result in the contents of the DOS file "caf" being mailed to user "caf".
  781.  
  782. On some
  783. .SM Unix
  784. systems, the login directory must contain a link to
  785. COMMAND as login sets SHELL=rsh which disallows absolute
  786. pathnames.
  787. If invoked with a leading ``v'',
  788. .I rz
  789. will report progress to /tmp/rzlog.
  790. The following entry works for
  791. .SM Unix
  792. 3.0:
  793. .ce
  794. rzrmail::5:1::/bin:/usr/local/rzrmail
  795. If the SHELL environment variable includes
  796. .I "rsh"
  797. or
  798. .I "rksh"
  799. (restricted shell),
  800. rz will not accept absolute pathnames
  801. or references to a parent directory,
  802. will not modify an existing file, and
  803. removes any files received in error.
  804.  
  805. If
  806. .B rz
  807. is invoked with stdout and stderr to different datasets,
  808. Verbose is set to 2, causing frame by frame progress reports
  809. to stderr.
  810. This may be disabled with the
  811. .B q
  812. option.
  813.  
  814. .PP
  815. The meanings of the available options are:
  816. .PP
  817. .PD 0
  818. .TP
  819. .B 1
  820. Use file descriptor 1 for ioctls and reads (Unix only).
  821. By default, file descriptor 0 is used for ioctls and reads.
  822. This option allows
  823. .B rz
  824. to be used with the
  825. .I Professional-YAM
  826. .B $
  827. command
  828. and some versions of ncu(1).
  829. .TP
  830. .B a
  831. Convert files to
  832. .SM Unix
  833. conventions by stripping carriage returns and all characters
  834. beginning with the first Control Z (CP/M end of file).
  835. .TP
  836. .B b
  837. Binary
  838. (tell it like it is)
  839. file transfer override.
  840. .TP
  841. .B c
  842. Request 16 bit CRC.
  843. XMODEM file transfers default to 8 bit checksum.
  844. YMODEM and ZMODEM normally use 16 bit CRC.
  845. .TP
  846. .B D
  847. Output file data to /dev/null; for testing.
  848. .TP
  849. .B e
  850. Force sender to escape all control characters;
  851. normally XON, XOFF, DLE, CR-@-CR, and Ctrl-X are escaped.
  852. .TP
  853. .B p
  854. (ZMODEM) Protect: skip file if destination file exists.
  855. .TP
  856. .B q
  857. Quiet suppresses verbosity.
  858. .TP
  859. .B "t tim"
  860. Change timeout to
  861. .I tim
  862. tenths of seconds.
  863. .TP
  864. .B v
  865. Verbose
  866. causes a list of file
  867. names to be appended to
  868. /tmp/rzlog .
  869. More v's generate more output.
  870. .PD
  871. .ne 6
  872. .SH EXAMPLES
  873. .RE
  874. (Pro-YAM command)
  875. .RS
  876. .I <ALT-2>
  877. .br
  878. Pro-YAM Command:
  879. .I "sz *.h *.c"
  880. .br
  881. (This automatically invokes
  882. .I rz
  883. on the connected system.)
  884. .RE
  885. .SH SEE ALSO
  886. ZMODEM.DOC,
  887. YMODEM.DOC,
  888. IMP(CP/M),
  889. Professional-YAM,
  890. sz(omen),
  891. usq(omen),
  892. undos(omen)
  893.  
  894. Compile time options required
  895. for various operating systems are described in the
  896. source file.
  897. .SH NOTES
  898. The Unix "ulimit" parameter must be set high enough
  899. to permit large file transfers.
  900.  
  901. The TTY input buffering on some systems may not allow long blocks
  902. or streaming input at high speed.
  903. You should suspect this problem when you
  904. can't send data to the Unix system at high speeds using ZMODEM
  905. when YMODEM with 128 byte blocks works properly.
  906. If the system's tty line handling is really broken, the serial port
  907. or the entire system may not survive the onslaught of long bursts
  908. of high speed data.
  909.  
  910. The DSZ or Pro-YAM
  911. .B "zmodem l"
  912. numeric parameter may be set to a value between 64 and 1024 to limit the
  913. burst length ("zmodem pl128").
  914.  
  915. 32 bit CRC code courtesy Gary S. Brown.
  916. .SH BUGS
  917. Calling
  918. .I rz
  919. from most versions of cu(1) doesn't work because cu's receive process
  920. fights
  921. .I rz
  922. for characters from the modem.
  923.  
  924. Pathnames are restricted to 127 characters.
  925. In XMODEM single file mode, the pathname given on the command line
  926. is still processed as described above.
  927. The ASCII option\'s CR/LF to NL translation merely deletes CR\'s;
  928. undos(omen) performs a more intelligent translation.
  929. .SH "VMS VERSION"
  930. Some of the #includes with file names enclosed with angle brackets <>
  931. may need to have the angle brackets changed to "", or vice versa.
  932.  
  933. The VMS version does not set binary mode according to the incoming
  934. file type.
  935. Non binary file processing consists of stripping all characters beginning
  936. with CPMEOF (^Z).
  937.  
  938. The VMS version does not set the file time.
  939.  
  940. At high speeds,
  941. VMS sometimes loses incoming characters, resulting in retries
  942. and degradation of throughput.
  943.  
  944. The mysterious
  945. VMS C Standard I/O Package and RMS may interact to modify
  946. file contents unexpectedly.
  947.  
  948. The VMS version does not support invocation as
  949. .B rzCOMMAND .
  950. ZMODEM has not yet been implemented on the VMS version.
  951. .SH "ZMODEM CAPABILITIES"
  952. .I Rz
  953. supports incoming ZMODEM binary (-b), ASCII (-a),
  954. protect (-p),
  955. and append (-+)
  956. requests, and ZMODEM command execution.
  957. .SH FILES
  958. rz.c, rbsb.c, zm.c, zmodem.h source files.
  959.  
  960. /tmp/rzlog stores debugging output generated with -vv option.
  961. \Rogue\Monster\
  962. else
  963.   echo "will not over write ./rz.1"
  964. fi
  965. if [ `wc -c ./rz.1 | awk '{printf $1}'` -ne 6788 ]
  966. then
  967. echo `wc -c ./rz.1 | awk '{print "Got " $1 ", Expected " 6788}'`
  968. fi
  969. if `test ! -s ./sz.1`
  970. then
  971. echo "Writing ./sz.1"
  972. cat > ./sz.1 << '\Rogue\Monster\'
  973. '\" Revision Level 
  974. '\" Last Delta     09-08-87
  975. .TH SZ 1 OMEN
  976. .SH NAME
  977. sx, sb, sz \- XMODEM, YMODEM, ZMODEM file send
  978. .SH SYNOPSIS
  979. sz
  980. .RB [\- +1abdefkLlNnopqTtuvyY ]
  981. .I file ...
  982. .br
  983. sb
  984. .RB [\- 1adfkqtuv ]
  985. .I file ...
  986. .br
  987. sx
  988. .RB [\- 1akqtuv ]
  989. .I file
  990. .br
  991. sz
  992. .RB [\- 1oqtv ]
  993. .B "-c COMMAND"
  994. .br
  995. sz
  996. .RB [\- 1oqtv ]
  997. .B "-i COMMAND"
  998. .SH DESCRIPTION
  999. .B Sz
  1000. uses the ZMODEM, YMODEM or XMODEM error correcting protocol to send
  1001. one or more files over a serial port to a variety of programs running under
  1002. PC-DOS, CP/M, Unix, VMS, and other operating systems.
  1003.  
  1004.  
  1005. The first form of
  1006. .B sz
  1007. sends one or more files with ZMODEM protocol.
  1008.  
  1009. ZMODEM
  1010. greatly simplifies file transfers compared to XMODEM.
  1011. In addition to a friendly user interface, ZMODEM
  1012. provides Personal Computer and other users
  1013. an efficient, accurate, and robust file transfer method.
  1014.  
  1015. ZMODEM provides complete
  1016. .B "END-TO-END"
  1017. data integrity between application programs.
  1018. ZMODEM's 32 bit CRC catches errors
  1019. that sneak into even the most advanced networks.
  1020.  
  1021. Advanced file management features include
  1022. AutoDownload (Automatic file Download initiated without user intervention),
  1023. Crash Recovery,
  1024. selective file transfers,
  1025. and preservation of
  1026. exact file date and length.
  1027.  
  1028. Output from another program may be piped to
  1029. .B sz
  1030. for transmission by denoting standard input with "-":
  1031. .ce
  1032. ps -ef | sz -
  1033. The program output is transmitted with the filename sPID.sz
  1034. where PID is the process ID of the
  1035. .B sz
  1036. program.
  1037. If the environment variable
  1038. .B ONAME
  1039. is set, that is used instead.
  1040. In this case, the Unix command:
  1041. .ce
  1042. ONAME=con ps -ef|sz -ay -
  1043. will send a "file" to the PC-DOS console display.
  1044. The
  1045. .B -y
  1046. option instructs the receiver to open the file for writing unconditionally.
  1047. The
  1048. .B -a
  1049. option
  1050. causes the receiver to convert Unix newlines to PC-DOS carriage returns
  1051. and linefeeds.
  1052.  
  1053.  
  1054. The second form is invoked as
  1055. .B sb
  1056. to batch send one or more files with ZMODEM or YMODEM protocol.
  1057. The initial ZMODEM initialization is not sent.
  1058. When requested by the receiver,
  1059. .B sb
  1060. supports
  1061. .B YMODEM-g
  1062. with "cbreak" tty mode, XON/XOFF flow control,
  1063. and interrupt character set to CAN (^X).
  1064. .B YMODEM-g
  1065. (Professional-YAM
  1066. .B g
  1067. option)
  1068. increases throughput over error free channels
  1069. (direct connection, X.PC, etc.)
  1070. by not acknowledging each transmitted sector.
  1071.  
  1072. On
  1073. .SM Unix
  1074. systems, additional information about the file is transmitted.
  1075. If the receiving program uses this information,
  1076. the transmitted file length controls the exact number of bytes written to
  1077. the output dataset,
  1078. and the modify time and file mode
  1079. are set accordingly.
  1080.  
  1081.  
  1082. The third form of
  1083. .B sz
  1084. is invoked as
  1085. .B sx
  1086. to send a single
  1087. .I file
  1088. with
  1089. .B XMODEM
  1090. or
  1091. .B XMODEM-1k
  1092. protocol
  1093. (sometimes incorrectly called "ymodem").
  1094. The user must supply the file name to both sending and receiving programs.
  1095.  
  1096. Iff
  1097. .B sz
  1098. is invoked with $SHELL set and iff that variable contains the
  1099. string
  1100. .I "rsh"
  1101. or
  1102. .I "rksh"
  1103. (restricted shell), sz operates in restricted mode.
  1104. Restricted mode restricts pathnames to the current directory and
  1105. PUBDIR (usually /usr/spool/uucppublic) and/or subdirectories
  1106. thereof.
  1107.  
  1108.  
  1109. The fourth form sends a single COMMAND to a ZMODEM receiver for execution.
  1110. .B Sz
  1111. exits with the COMMAND return value.
  1112. If COMMAND includes spaces or characters special to the shell,
  1113. it must be quoted.
  1114.  
  1115.  
  1116. The fifth form sends a single COMMAND to a ZMODEM receiver for execution.
  1117. .B Sz
  1118. exits as soon as the receiver has correctly received the command,
  1119. before it is executed.
  1120.  
  1121.  
  1122. If sz is invoked with stdout and stderr to different datasets,
  1123. Verbose is set to 2, causing frame by frame progress reports
  1124. to stderr.
  1125. This may be disabled with the
  1126. .B q
  1127. option.
  1128. .PP
  1129. The meanings of the available options are:
  1130. .PP
  1131. .PD 0
  1132. .TP
  1133. .B +
  1134. Instruct the receiver to append transmitted data to an existing file
  1135. (ZMODEM only).
  1136. .TP
  1137. .B 1
  1138. Use file descriptor 1 for ioctls and reads.
  1139. By default, file descriptor 0 is used.
  1140. This option allows
  1141. .B sz
  1142. to be used with the
  1143. .I Professional-YAM
  1144. $
  1145. command.
  1146. .TP
  1147. .B a
  1148. Convert NL characters in the transmitted file to CR/LF.
  1149. This is done by the sender for XMODEM and YMODEM, by the receiver
  1150. for ZMODEM.
  1151. .TP
  1152. .B b
  1153. (ZMODEM) Binary override: transfer file without any translation.
  1154. .TP
  1155. .B "c COMMAND"
  1156. Send COMMAND to the receiver for execution, return with COMMAND\'s exit status.
  1157. .TP
  1158. .B d
  1159. Change all instances of "." to "/" in the transmitted pathname.
  1160. Thus, C.omenB0000 (which is unacceptable to MSDOS or CP/M)
  1161. is transmitted as C/omenB0000.
  1162. If the resultant filename has more than 8 characters in the stem,
  1163. a "." is inserted to allow a total of eleven.
  1164. .TP
  1165. .B e
  1166. Escape all control characters;
  1167. normally XON, XOFF, DLE, CR-@-CR, and Ctrl-X are escaped.
  1168. .TP
  1169. .B f
  1170. Send Full pathname.
  1171. Normally directory prefixes are stripped from the transmitted
  1172. filename.
  1173. .TP
  1174. .B "i COMMAND"
  1175. Send COMMAND to the receiver for execution, return Immediately
  1176. upon the receiving program's successful recption of the command.
  1177. .TP
  1178. .B k
  1179. (XMODEM/YMODEM) Send files using 1024 byte blocks
  1180. rather than the default 128 byte blocks.
  1181. 1024 byte packets speed file transfers at high bit rates.
  1182. (ZMODEM streams the data for the best possible throughput.)
  1183. .TP
  1184. .B "L N"
  1185. Use ZMODEM sub-packets of length N.
  1186. A larger N (32 <= N <= 1024) gives slightly higher throughput,
  1187. a smaller N speeds error recovery.
  1188. The default is 128 below 300 baud, 256 above 300 baud, or 1024 above 2400 baud.
  1189. .TP
  1190. .B "l N"
  1191. Wait for the receiver to acknowledge correct data every
  1192. .B N
  1193. (32 <= N <= 1024)
  1194. characters.
  1195. This may be used to avoid network overrun when XOFF flow control is lacking.
  1196. .TP
  1197. .B n
  1198. (ZMODEM) Send each file if
  1199. destination file does not exist.
  1200. Overwrite destination file if
  1201. source file is newer than the destination file.
  1202. .TP
  1203. .B N
  1204. (ZMODEM) Send each file if
  1205. destination file does not exist.
  1206. Overwrite destination file if
  1207. source file is newer or longer than the destination file.
  1208. .TP
  1209. .B o
  1210. (ZMODEM) Disable automatic selection of 32 bit CRC.
  1211. .TP
  1212. .B p
  1213. (ZMODEM) Protect existing destination files by skipping transfer if the
  1214. destination file exists.
  1215. .TP
  1216. .B q
  1217. Quiet suppresses verbosity.
  1218. .TP
  1219. .B r
  1220. (ZMODEM) Resume interrupted file transfer.
  1221. If the source file is longer than the destination file,
  1222. the transfer commences at the offset in the source file that equals
  1223. the length of the destination file.
  1224. .TP
  1225. .B "t tim"
  1226. Change timeout to
  1227. .I tim
  1228. tenths of seconds.
  1229. .TP
  1230. .B u
  1231. Unlink the file after successful transmission.
  1232. .TP
  1233. .B v
  1234. Verbose
  1235. causes a list of file
  1236. names to be appended to
  1237. /tmp/szlog .
  1238. More v's generate more output.
  1239. .TP
  1240. .B y
  1241. Instruct a ZMODEM receiving program to overwrite any existing file
  1242. with the same name.
  1243. .TP
  1244. .B Y
  1245. Instruct a ZMODEM receiving program to overwrite any existing file
  1246. with the same name,
  1247. and to skip any source files that do have a file with the same
  1248. pathname on the destination system.
  1249. .PD
  1250. .SH EXAMPLES
  1251. .ne 7
  1252. .B "ZMODEM File Transfer"
  1253. .br
  1254. .B "$ sz \-a *.c"
  1255. .br
  1256. This single command transfers all .c files in the current Unix directory
  1257. with conversion
  1258. .RB ( \-a )
  1259. to end of line conventions appropriate to the receiving environment.
  1260. With ZMODEM AutoDownload enabled, Professional-YAM  and ZCOMM
  1261. will automatically recieve
  1262. the files after performing a security check.
  1263.  
  1264. .br
  1265. .B "$ sz \-Yan *.c *.h"
  1266. .br
  1267. Send only the .c and .h files that exist on both systems,
  1268. and are newer on the sending system than the
  1269. corresponding version on the receiving system, converting Unix to
  1270. DOS text format.
  1271.  
  1272. .B "ZMODEM Command Download"
  1273. .br
  1274.  cpszall:all
  1275.     sz \-c "c:;cd /yam/dist"
  1276.     sz \-ya $(YD)/*.me
  1277.     sz \-yqb y*.exe
  1278.     sz \-c "cd /yam"
  1279.     sz \-i "!insms"
  1280. .br
  1281. This Makefile fragment uses
  1282. .B sz
  1283. to issue commands to Professional-YAM to change current disk and directory.
  1284. Next,
  1285. .B sz
  1286. transfers the
  1287. .I .me
  1288. files from the $YD directory, commanding the receiver to overwrite the old files
  1289. and to convert from Unix end of line conventions to PC-DOS conventions.
  1290. The third line transfers some
  1291. .I .exe
  1292. files.
  1293. The fourth and fifth lines command Pro-YAM to
  1294. change directory and execute a PC-DOS batch file
  1295. .I insms .
  1296. Since the batch file takes considerable time, the
  1297. .B "\-i"
  1298. form is used to allow
  1299. .B sz
  1300. to exit immediately.
  1301.  
  1302. .B "XMODEM File Transfer"
  1303. (To Crosstalk)
  1304. .br
  1305. $
  1306. .B "sx \-a foo.c"
  1307. .br
  1308. .B "ESC"
  1309. .br
  1310. .B "rx foo.c"
  1311. .br
  1312. The above three commands transfer a single file
  1313. from Unix to a PC and Crosstalk with
  1314. .I sz
  1315. translating Unix newlines to DOS CR/LF.
  1316. This combination is much slower than ZMODEM.
  1317. .SH SEE ALSO
  1318. rz(omen),
  1319. ZMODEM.DOC,
  1320. YMODEM.DOC,
  1321. Professional-YAM,
  1322. IMP(CP/M),
  1323. sq(omen),
  1324. todos(omen),
  1325. tocpm(omen),
  1326. tomac(omen),
  1327. yam(omen)
  1328.  
  1329. Compile time options required for various operating systems are described in
  1330. the source file.
  1331. .SH "VMS VERSION"
  1332. The VMS version does not transmit the file date.
  1333. The VMS version calculates the file length by reading the file
  1334. and counting the bytes.
  1335.  
  1336. The VMS version does not support YMODEM-g or ZMODEM.
  1337.  
  1338. When VMS is lightly loaded, the response time may be too quick for MODEM7
  1339. unless the MODEM7
  1340. .B "q"
  1341. modifier is used.
  1342.  
  1343. The VMS C standard i/o package and RMS sometimes interact to modify
  1344. file contents unexpectedly.
  1345. .SH FILES
  1346. 32 bit CRC code courtesy Gary S. Brown.
  1347.  
  1348. sz.c, rbsb.c, zm.c, zmodem.h source files
  1349.  
  1350. /tmp/szlog stores debugging output (sz -vv)
  1351. .SH "TESTING FEATURE"
  1352. The command "sz -T file"
  1353. exercises the
  1354. .B Attn
  1355. sequence error recovery by commanding
  1356. errors with unterminated packets.
  1357. The receiving program should complain five times about
  1358. binary data packets being too long.
  1359. Each time
  1360. .B sz
  1361. is interrupted,
  1362. it should send a ZDATA header followed by another defective packet.
  1363. If the receiver does not detect five long data packets,
  1364. the
  1365. .B Attn
  1366. sequence is not interrupting the sender, and the
  1367. .B Myattn
  1368. string in
  1369. .B sz.c
  1370. must be modified.
  1371.  
  1372. After 5 packets,
  1373. .B sz
  1374. stops the "transfer" and
  1375. prints the total number of characters "sent" (Tcount).
  1376. The difference between Tcount and 5120 represents the number of characters
  1377. stored in various buffers when the Attn sequence is generated.
  1378. .SH BUGS
  1379. Calling
  1380. .I sz
  1381. from most versions of cu(1) doesn't work because cu's receive process
  1382. fights
  1383. .I sz
  1384. for characters from the modem.
  1385.  
  1386. Many programs claiming to support YMODEM only support XMODEM with 1k blocks,
  1387. and they often don't get that quite right.
  1388.  
  1389. XMODEM transfers add up to 127 garbage bytes per file (1023 bytes with
  1390. XMODEM-k).
  1391.  
  1392. YMODEM programs use the file length transmitted at the beginning of the
  1393. transfer to prune the file to the correct length; this may cause problems with
  1394. source files that grow during the course of the transfer.
  1395. This problem does not pertain to ZMODEM transfers, which preserve the exact
  1396. file length unconditionally.
  1397.  
  1398. Most ZMODEM options are merely passed to the receiving program;
  1399. some do not implement all these options.
  1400.  
  1401. Circular buffering and a ZMODEM sliding window should be used
  1402. when input is from pipes instead of acknowledging frames each 1024 bytes.
  1403. If no files can be opened,
  1404. .B sz
  1405. sends a ZMODEM command to echo a suitable complaint;
  1406. perhaps it should check for the presence of at least one accessible file before
  1407. getting hot and bothered.
  1408. The test mode leaves a zero length file on the receiving system.
  1409.  
  1410. Some high speed modems have a firmware bug that drops characters when the
  1411. direction of high speed transmissson is reversed.
  1412. The environment variable ZNULLS may be used to specify the number of nulls to
  1413. send before a ZDATA frame.
  1414. Values of 101 for a 4.77 mHz PC and 124 for an AT are typical.
  1415. \Rogue\Monster\
  1416. else
  1417.   echo "will not over write ./sz.1"
  1418. fi
  1419. if [ `wc -c ./sz.1 | awk '{printf $1}'` -ne 11303 ]
  1420. then
  1421. echo `wc -c ./sz.1 | awk '{print "Got " $1 ", Expected " 11303}'`
  1422. fi
  1423. if `test ! -s ./gz`
  1424. then
  1425. echo "Writing ./gz"
  1426. cat > ./gz << '\Rogue\Monster\'
  1427. sz -c "sz $*"
  1428. \Rogue\Monster\
  1429. else
  1430.   echo "will not over write ./gz"
  1431. fi
  1432. if [ `wc -c ./gz | awk '{printf $1}'` -ne 14 ]
  1433. then
  1434. echo `wc -c ./gz | awk '{print "Got " $1 ", Expected " 14}'`
  1435. fi
  1436. if `test ! -s ./ptest.sh`
  1437. then
  1438. echo "Writing ./ptest.sh"
  1439. cat > ./ptest.sh << '\Rogue\Monster\'
  1440. #a short test for sz and rz using a named pipe - no modem used.
  1441. /etc/mknod fifo p
  1442. sz <fifo /etc/motd |rz >fifo
  1443. rm fifo
  1444. \Rogue\Monster\
  1445. else
  1446.   echo "will not over write ./ptest.sh"
  1447. fi
  1448. if [ `wc -c ./ptest.sh | awk '{printf $1}'` -ne 119 ]
  1449. then
  1450. echo `wc -c ./ptest.sh | awk '{print "Got " $1 ", Expected " 119}'`
  1451. fi
  1452. if `test ! -s ./zupl.t`
  1453. then
  1454. echo "Writing ./zupl.t"
  1455. cat > ./zupl.t << '\Rogue\Monster\'
  1456.     :: ProYAM/ZCOMM script to upload minirb and rz/sz to *nix
  1457.     if S>1200 pt1
  1458.     ena -t
  1459.     if !fminirb.c echo "Can't find minirb.c !!";  abort
  1460.     putw "stty -echo; cat >minirb.c\r"
  1461.     f -xHr minirb.c
  1462.     putw "\r\4"
  1463.     putw "stty echo\r"
  1464.     dis -h
  1465.     pat 1 "rwx"
  1466.     pat 2 "%"
  1467.     put "cc minirb.c -o minirb; ls -l minirb\r"
  1468.     wait -f120
  1469.     if 1 goto okok
  1470.     echo "The compiiation appears to have failed."
  1471.     echo "Please compile minirb.c to minirb, then"
  1472.     echo "hit F5 to upload the rest of the rz/sz files."
  1473.     set f5
  1474. @putw minirb\r; sb README zmodem.h zm.c sz.c rz.c rbsb.c *.1 gz ptest.sh
  1475.     t
  1476.     return
  1477. okok:    echo "Minirb Compilation Appears Successful."
  1478.     put minirb\r
  1479.     sb README zmodem.h zm.c sz.c rz.c rbsb.c *.1 gz ptest.sh
  1480.     t
  1481.     return
  1482. \Rogue\Monster\
  1483. else
  1484.   echo "will not over write ./zupl.t"
  1485. fi
  1486. if [ `wc -c ./zupl.t | awk '{printf $1}'` -ne 703 ]
  1487. then
  1488. echo `wc -c ./zupl.t | awk '{print "Got " $1 ", Expected " 703}'`
  1489. fi
  1490. echo "Finished archive 1 of 3"
  1491. exit
  1492.  
  1493.