Path: utzoo!mnetor!uunet!husc6!cmcl2!brl-adm!brl-smoke!w8sdz From: w8sdz@brl-smoke.ARPA (Keith B. Petersen ) Newsgroups: comp.binaries.ibm.pc Subject: Zmodem for Unix and VAX/VMS (repost) part 1of3 Message-ID: <7814@brl-smoke.ARPA> Date: 3 May 88 04:15:26 GMT Reply-To: w8sdz@brl-smoke.UUCP (Keith B. Petersen (WSMR|towson) ) Followup-To: comp.binaries.ibm.pc.d Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 1829 Keywords: xmodem,ymodem,zmodem,unix,vax/vms Summary: Chuck Forsberg's Zmodem now supports VAX/VMS as well as Unix This is a repost of Zmodem for Unix and VAX/VMS, by Chuck Forsberg. Sorry for the problems with the previous posting. To extract the files, use the unshar script or unshar.c program previously posted to this newsgroup. ---- Cut Here and unpack ---- #!/bin/sh # shar: Shell Archiver (v1.20) # Packed Tue May 3 00:05:21 EDT 1988 by brl-smoke!w8sdz # from directory /pmsmoke/other/w8sdz/upload # # This is part 1 of a multipart archive # do not concatenate these parts, unpack them in order with /bin/sh # # Run the following text with /bin/sh to create: # Makefile # README # crc.1 # crc.c # crctab.c # gz # minirb.1 # minirb.c # ptest.sh # rbsb.c # rz.1 # rz.c # sz.1 # sz.c # vmodem.h # vrzsz.c # vvmodem.c # zm.c # zmodem.h # zupl.t # if test -r s2_seq_.tmp then echo "Must unpack archives in sequence!" next=`cat s2_seq_.tmp`; echo "Please unpack part $next next" exit 1; fi echo "x - extracting Makefile (Text)" sed 's/^X//' << 'SHAR_EOF' > Makefile && X# Makefile for Unix/Xenix rz and sz programs X# the makefile is not too well tested yet X Xnothing: X @echo X @echo "Please study the #ifdef's in crctab.c rbsb.c, rz.c and sz.c," X @echo "then type 'make system' where system is one of:" X @echo " sysvr3 SYSTEM 5.3 Unix with mkdir(2)" X @echo " sysv SYSTEM 3/5 Unix" X @echo " xenix Xenix" X @echo " x386 386 Xenix" X @echo " bsd Berkeley 4.x BSD, Ultrix, V7" X @echo X Xusenet: X shar -f /tmp/rzsz README Makefile zmodem.h zm.c sz.c rz.c rbsb.c \ X crc.c vmodem.h vvmodem.c vrzsz.c crctab.c minirb.c \ X *.1 gz ptest.sh zupl.t X Xshar: X shar -f /tmp/rzsz -m 2000000 README Makefile zmodem.h zm.c \ X vmodem.h vvmodem.c vrzsz.c sz.c rz.c crctab.c \ X crc.c rbsb.c minirb.c *.1 gz ptest.sh zupl.t X Xunixforum: shar X compress -b12 /tmp/rzsz.sh X Xarc: X rm -f /tmp/rzsz.arc X arc a /tmp/rzsz README Makefile zmodem.h zm.c sz.c rz.c \ X vmodem.h vvmodem.c vrzsz.c crctab.c rbsb.c \ X crc.c *.1 gz ptest.sh zupl.t minirb.c X chmod og-w /tmp/rzsz.arc X mv /tmp/rzsz.arc /t/yam X Xzoo: X rm -f /tmp/rzsz.zoo X zoo a /tmp/rzsz README Makefile zmodem.h zm.c sz.c rz.c \ X vmodem.h vvmodem.c vrzsz.c crctab.c rbsb.c *.1 \ X crc.c gz ptest.sh zupl.t minirb.c X chmod og-w /tmp/rzsz.zoo X mv /tmp/rzsz.zoo /t/yam X X.PRECIOUS:rz sz X Xxenix: X cc -M0 -Ox -K -i -DNFGVMIN -DREADCHECK sz.c -lx -o sz X size sz X -ln sz sb X -ln sz sx X cc -M0 -Ox -K -i -DMD rz.c -o rz X size rz X -ln rz rb X -ln rz rx X Xx386: X cc -Ox -DMD rz.c -o rz X size rz X -ln rz rb X -ln rz rx X cc -Ox -DNFGVMIN -DREADCHECK sz.c -lx -o sz X size sz X -ln sz sb X -ln sz sx X Xsysv: X cc -O -DMD rz.c -o rz X size rz X -ln rz rb X -ln rz rx X cc -DSV -O -DNFGVMIN sz.c -o sz X size sz X -ln sz sb X -ln sz sx X Xsysvr3: X cc -O -DMD=2 rz.c -o rz X size rz X -ln rz rb X -ln rz rx X cc -DSV -O -DNFGVMIN sz.c -o sz X size sz X -ln sz sb X -ln sz sx X Xbsd: X cc -DMD=2 -Dstrchr=index -DV7 -O rz.c -o rz X size rz X -ln rz rb X -ln rz rx X cc -DV7 -O -DNFGVMIN sz.c -o sz X size sz X -ln sz sb X -ln sz sx X Xsz: nothing Xsb: nothing Xrz: nothing Xrb: nothing SHAR_EOF chmod 0644 Makefile || echo "restore of Makefile fails" echo "x - extracting README (Text)" sed 's/^X//' << 'SHAR_EOF' > README && XNew for April 1988: VMS C flavors of rz and sz especially for tired Xfrog stompers. The following performance log entries give the story! X X 2400 Z splat.arc 3968 220 18 0 0 0 512 30 (rz) 0 ccvax off X 2400 K splat.arc 3968 110 36 0 0 0 89 -1 get -1 ccvax off X XThe contents of RZSZ.ARC are designed to be uploaded to a Unix or Xenix Xsystem by ZCOMM or Professional-YAM using the supplied zupl.t script. XConnect to your Unix/Xenix system, select an empty directory, and then Xgive the YAM/ZCOMM command: "source zupl.t". This will upload minirb.c, Xcompile it, and then use minirb to upload the rz/sz files. X XOnce these files are on your Unix system, you can type "make". XThe Makefile will list the various systems it knows how to Xcompile the programs for, and the command to do so (e.g., "make bsd"). X XThe Makefile is self explanatory; just say "make". X XNaturally, rz and sz work best with comm programs that seamlessly Xsupport ZMODEM command and file AutoDownload (Pro-YAM and ZCOMM). X XThe "DSZ" shareware program allows ZMODEM file transfers with Xtraditional DOS comm programs, but it must be called manually. X(The computer should do that for you!) DSZ provides a "mini term Xfunction" that supports ZMODEM AutoDownload. DSZ (part of DSZ.ARC) and Xthe ZMODEM protocol description (YZMODEM.ARC) are on TeleGodzilla and Xother fine bulletin boards. X XChuck Forsberg WA7KGX Author of Pro-YAM communications Tools for PCDOS and Unix X...!tektronix!reed!omen!caf Omen Technology Inc "The High Reliability Software" X 17505-V Northwest Sauvie Island Road Portland OR 97231 Voice: 503-621-3406 XTeleGodzilla BBS: 621-3746 2400/1200 CIS:70007,2304 Genie:CAF Source:TCE022 X omen Any ACU 1200 1-503-621-3746 se:--se: link ord: Giznoid in:--in: uucp X omen!/usr/spool/uucppublic/FILES lists all uucp-able files, updated hourly SHAR_EOF chmod 0644 README || echo "restore of README fails" echo "x - extracting crc.1 (Text)" sed 's/^X//' << 'SHAR_EOF' > crc.1 && X.TH CRC 1 OMEN X.SH NAME Xcrc \- checksum files X.SH SYNOPSIS X.B crc Xfile ... X.SH DESCRIPTION XFor each file, X.I crc\^ Xcalculates and prints a 32-bit CRC, Xthe byte count, and the file name. XIt is typically used to validate files transferred between Xdifferent systems, and is useful in detecting subtle disk corruption. X.I Crc\^ Xuses a checksum compatible with the XDOS Xversion of crc, Xas well as the "crc" command in ZCOMM and Professional-YAM X(high reliability communications programs). X XThe 32-bit CRC used is the frame Xcheck sequence in ADCCP (ANSI X3.66, also known as FIPS PUB 71 Xand FED-STD-1003, the U.S. versions of CCITT's X.25 link-level Xprotocol). X X32 bit CRC code courtesy Gary S. Brown. X.SH BUGS XAlthough most unlikely, Xfiles with different data may still produce the same crc value. X.SH "SEE ALSO" Xchek(1), tocpm(1), sum(1), wc(1). SHAR_EOF chmod 0644 crc.1 || echo "restore of crc.1 fails" echo "x - extracting crc.c (Text)" sed 's/^X//' << 'SHAR_EOF' > crc.c && X/*% cc -O -K -dos % -o crc.exe X*/ X X/* X * Crc - 32 BIT ANSI X3.66 CRC checksum files X */ X#include X#define OK 0 X#define ERROR (-1) X#define LINT_ARGS X X/**********************************************************************\ X|* *| X|* Demonstration program to compute the 32-bit CRC used as the frame *| X|* check sequence in ADCCP (ANSI X3.66, also known as FIPS PUB 71 *| X|* and FED-STD-1003, the U.S. versions of CCITT's X.25 link-level *| X|* protocol). The 32-bit FCS was added via the Federal Register, *| X|* 1 June 1982, p.23798. I presume but don't know for certain that *| X|* this polynomial is or will be included in CCITT V.41, which *| X|* defines the 16-bit CRC (often called CRC-CCITT) polynomial. FIPS *| X|* PUB 78 says that the 32-bit FCS reduces otherwise undetected *| X|* errors by a factor of 10^-5 over 16-bit FCS. *| X|* *| X\**********************************************************************/ X X/* Need an unsigned type capable of holding 32 bits; */ Xtypedef unsigned long int UNS_32_BITS; X X/* X * Copyright (C) 1986 Gary S. Brown. You may use this program, or X * code or tables extracted from it, as desired without restriction. X */ X/* First, the polynomial itself and its table of feedback terms. The */ X/* polynomial is */ X/* 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 */ X/* Note that we take it "backwards" and put the highest-order term in */ X/* the lowest-order bit. The X^32 term is "implied"; the LSB is the */ X/* X^31 term, etc. The X^0 term (usually shown as "+1") results in */ X/* the MSB being 1. */ X X/* Note that the usual hardware shift register implementation, which */ X/* is what we're using (we're merely optimizing it by doing eight-bit */ X/* chunks at a time) shifts bits into the lowest-order term. In our */ X/* implementation, that means shifting towards the right. Why do we */ X/* do it this way? Because the calculated CRC must be transmitted in */ X/* order from highest-order term to lowest-order term. UARTs transmit */ X/* characters in order from LSB to MSB. By storing the CRC this way, */ X/* we hand it to the UART in the order low-byte to high-byte; the UART */ X/* sends each low-bit to hight-bit; and the result is transmission bit */ X/* by bit from highest- to lowest-order term without requiring any bit */ X/* shuffling on our part. Reception works similarly. */ X X/* The feedback terms table consists of 256, 32-bit entries. Notes: */ X/* */ X/* 1. The table can be generated at runtime if desired; code to do so */ X/* is shown later. It might not be obvious, but the feedback */ X/* terms simply represent the results of eight shift/xor opera- */ X/* tions for all combinations of data and CRC register values. */ X/* */ X/* 2. The CRC accumulation logic is the same for all CRC polynomials, */ X/* be they sixteen or thirty-two bits wide. You simply choose the */ X/* appropriate table. Alternatively, because the table can be */ X/* generated at runtime, you can start by generating the table for */ X/* the polynomial in question and use exactly the same "updcrc", */ X/* if your application needn't simultaneously handle two CRC */ X/* polynomials. (Note, however, that XMODEM is strange.) */ X/* */ X/* 3. For 16-bit CRCs, the table entries need be only 16 bits wide; */ X/* of course, 32-bit entries work OK if the high 16 bits are zero. */ X/* */ X/* 4. The values must be right-shifted by eight bits by the "updcrc" */ X/* logic; the shift must be unsigned (bring in zeroes). On some */ X/* hardware you could probably optimize the shift in assembler by */ X/* using byte-swap instructions. */ X Xstatic UNS_32_BITS crc_32_tab[] = { /* CRC polynomial 0xedb88320 */ X0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, X0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, X0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, X0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, X0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, X0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, X0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f, X0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, X0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, X0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, X0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, X0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, X0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, X0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, X0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, X0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, X0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, X0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, X0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7, X0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, X0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, X0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79, X0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, X0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, X0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, X0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, X0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, X0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, X0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, X0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, X0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, X0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d X}; X X#define UPDC32(octet, crc) (crc_32_tab[((crc) ^ (octet)) & 0xff] ^ ((crc) >> 8)) X Xmain(argc, argp) Xchar **argp; X{ X register errors = 0; X X while( --argc > 0) X errors |= crc32file( *++argp); X exit(errors != 0); X} X Xcrc32file(name) Xchar *name; X{ X register FILE *fin; X register unsigned long oldcrc32; X register unsigned long crc32; X register unsigned long oldcrc; X register c; X register long charcnt; X X oldcrc32 = 0xFFFFFFFF; charcnt = 0; X#ifdef M_I86SM X if ((fin=fopen(name, "rb"))==NULL) X#else X if ((fin=fopen(name, "r"))==NULL) X#endif X { X perror(name); X return ERROR; X } X while ((c=getc(fin))!=EOF) { X ++charcnt; X oldcrc32 = UPDC32(c, oldcrc32); X } X X if (ferror(fin)) { X perror(name); X charcnt = -1; X } X fclose(fin); X X crc32 = oldcrc32; oldcrc = oldcrc32 = ~oldcrc32; X X/* X crc32 = UPDC32((oldcrc32 & 0377), crc32); oldcrc32 >>=8; X crc32 = UPDC32((oldcrc32 & 0377), crc32); oldcrc32 >>=8; X crc32 = UPDC32((oldcrc32 & 0377), crc32); oldcrc32 >>=8; X crc32 = UPDC32((oldcrc32 & 0377), crc32); oldcrc32 >>=8; X printf("%08lX ", crc32); X*/ X X printf("%08lX %7ld %s\n", oldcrc, charcnt, name); X X return OK; X} X SHAR_EOF chmod 0644 crc.c || echo "restore of crc.c fails" echo "x - extracting crctab.c (Text)" sed 's/^X//' << 'SHAR_EOF' > crctab.c && X/* X * Crc calculation stuff X */ X X/* crctab calculated by Mark G. Mendel, Network Systems Corporation */ Xstatic unsigned short crctab[256] = { X 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7, X 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef, X 0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6, X 0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de, X 0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485, X 0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d, X 0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4, X 0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc, X 0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823, X 0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b, X 0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12, X 0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a, X 0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41, X 0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49, X 0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70, X 0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78, X 0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f, X 0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067, X 0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e, X 0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256, X 0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d, X 0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405, X 0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c, X 0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634, X 0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab, X 0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3, X 0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a, X 0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92, X 0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9, X 0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1, X 0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8, X 0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0 X}; X X/* X * updcrc macro derived from article Copyright (C) 1986 Stephen Satchell. X * NOTE: First srgument must be in range 0 to 255. X * Second argument is referenced twice. X * X * Programmers may incorporate any or all code into their programs, X * giving proper credit within the source. Publication of the X * source routines is permitted so long as proper credit is given X * to Stephen Satchell, Satchell Evaluations and Chuck Forsberg, X * Omen Technology. X */ X X#define updcrc(cp, crc) ( crctab[((crc >> 8) & 255)] ^ (crc << 8) ^ cp) X X/* X * Copyright (C) 1986 Gary S. Brown. You may use this program, or X * code or tables extracted from it, as desired without restriction. X */ X X/* First, the polynomial itself and its table of feedback terms. The */ X/* polynomial is */ X/* 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 */ X/* Note that we take it "backwards" and put the highest-order term in */ X/* the lowest-order bit. The X^32 term is "implied"; the LSB is the */ X/* X^31 term, etc. The X^0 term (usually shown as "+1") results in */ X/* the MSB being 1. */ X X/* Note that the usual hardware shift register implementation, which */ X/* is what we're using (we're merely optimizing it by doing eight-bit */ X/* chunks at a time) shifts bits into the lowest-order term. In our */ X/* implementation, that means shifting towards the right. Why do we */ X/* do it this way? Because the calculated CRC must be transmitted in */ X/* order from highest-order term to lowest-order term. UARTs transmit */ X/* characters in order from LSB to MSB. By storing the CRC this way, */ X/* we hand it to the UART in the order low-byte to high-byte; the UART */ X/* sends each low-bit to hight-bit; and the result is transmission bit */ X/* by bit from highest- to lowest-order term without requiring any bit */ X/* shuffling on our part. Reception works similarly. */ X X/* The feedback terms table consists of 256, 32-bit entries. Notes: */ X/* */ X/* The table can be generated at runtime if desired; code to do so */ X/* is shown later. It might not be obvious, but the feedback */ X/* terms simply represent the results of eight shift/xor opera- */ X/* tions for all combinations of data and CRC register values. */ X/* */ X/* The values must be right-shifted by eight bits by the "updcrc" */ X/* logic; the shift must be unsigned (bring in zeroes). On some */ X/* hardware you could probably optimize the shift in assembler by */ X/* using byte-swap instructions. */ X Xstatic long cr3tab[] = { /* CRC polynomial 0xedb88320 */ X0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, X0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, X0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, X0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, X0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, X0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, X0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f, X0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, X0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, X0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, X0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, X0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, X0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, X0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, X0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, X0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, X0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, X0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, X0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7, X0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, X0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, X0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79, X0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, X0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, X0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, X0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, X0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, X0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, X0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, X0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, X0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, X0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d X}; X X#ifdef NFGM Xlong XUPDC32(b, c) Xlong c; X{ X return (cr3tab[((int)c ^ b) & 0xff] ^ ((c >> 8) & 0x00FFFFFF)); X} X X#else X X#define UPDC32(b, c) (cr3tab[((int)c ^ b) & 0xff] ^ ((c >> 8) & 0x00FFFFFF)) X#endif X X/* End of crctab.c */ SHAR_EOF chmod 0644 crctab.c || echo "restore of crctab.c fails" echo "x - extracting gz (Text)" sed 's/^X//' << 'SHAR_EOF' > gz && Xexec sz -c "sz $*" SHAR_EOF chmod 0644 gz || echo "restore of gz fails" echo "x - extracting minirb.1 (Text)" sed 's/^X//' << 'SHAR_EOF' > minirb.1 && X'\" Revision Level X'\" Last Delta 09-08-87 X.TH MINIRB 1 OMEN X.SH NAME Xminirb \- Bootstrap YMODEM Batch file receive X.SH SYNOPSIS X.B minirb X.SH DESCRIPTION X.I Minirb Xreceives one or more files with YMODEM batch file transfer protocol. X.I Minirb Xwas developed for use as a bootstrap to simplify uploading of the longer X.I rz Xand X.I sz Xprograms, such as are contained in the X.I rzsz.zoo X"zoo" archive or the X.I rzsz.sh Xshell archive. X.SH SEE ALSO XYMODEM.DOC, XProfessional-YAM manual, Xsz(omen) X.SH NOTES XThe source file X.I minirb.c Xhas been ruthlessly pruned X(4k, 175 lines) Xto simplify uploading without benefit of Xan error correcting file transfer protocol. XDo not reformat or add tabs to the source file Xas this would complicate uploading. X XPlease read the uploading suggestions in the chapter X.I "File Transfer Basics" Xin the Professional-YAM or ZCOMM user's manual. X X.I Minirb Xuses 8 bit checksum which may not be compatible with some programs Xclaiming to support YMODEM batch transfers. X X.I Minirb Xuses the XYMODEM header Xfile length information Xto avoid storing extraneous characters. X.I Minirb Xdeletes carriage returns and CPMEOF (^Z) characters Xencountered in uploaded files. X X.I Minirb Xcalls stty(1) to set and reset raw tty mode. SHAR_EOF chmod 0644 minirb.1 || echo "restore of minirb.1 fails" echo "x - extracting minirb.c (Text)" sed 's/^X//' << 'SHAR_EOF' > minirb.c && X/* X * minirb.c By Chuck Forsberg Omen Technology INC X * "The High Reliability Communications Software" X * X * A bootstrap program for Unix to receive files from computers running X * YMODEM Batch (Professional-YAM, PowerCom, ZCOMM, etc.). X * X * Minirb uses system(3) to call stty, avoiding system dependent code. X * program strips CR and CPMEOF (^Z) characters (see putsec()). X * Please refer to rz.c for comments, etc. X */ Xchar * Version = "minirb 2.00 05-25-87"; X X#include X#include X#include X X#define OK 0 X#define FALSE 0 X#define TRUE 1 X#define ERROR (-1) X#define CAN ('X'&037) X#define SOH 1 X#define STX 2 X#define EOT 4 X#define ACK 6 X#define NAK 025 X#define TIMEOUT (-2) X#define RETRYMAX 9 X#define WCEOT (-10) X XFILE *fout; Xlong Bytesleft; Xint Blklen; Xchar secbuf[1024]; Xchar linbuf[1024]; Xint Lleft=0; Xjmp_buf tohere; X Xalrm() { longjmp(tohere, -1); } X Xbibi(n) { X canit(); mode(0); X fprintf(stderr, "minirb: caught signal %d; exiting", n); X exit(128+n); X} X Xmode(n) { X if (n) system("stty raw -echo"); X else system("stty echo -raw"); X} X Xmain() { X mode(1); X if (signal(SIGINT, bibi) == SIG_IGN) { X signal(SIGINT, SIG_IGN); signal(SIGKILL, SIG_IGN); X } else { X signal(SIGINT, bibi); signal(SIGKILL, bibi); X } X printf("minirb: Now send file(s) with \042sb file ...\042 command\r\n"); X X if (wcreceive()==ERROR) X canit(); X mode(0); exit(0); X} X Xwcreceive() { X for (;;) { X if (wcrxpn(secbuf) == ERROR) break; X if (secbuf[0]==0) return OK; X if (procheader(secbuf)==ERROR || wcrx()==ERROR) break; X } X canit(); return ERROR; X} X X Xwcrxpn(rpn) char *rpn; { X register c; X X purgeline(); Xet_tu: X sendline(NAK); Lleft=0; X while ((c = wcgetsec(rpn, 100)) != 0) { X if (c == WCEOT) { sendline(ACK); Lleft=0; readline(1); goto et_tu; } X return ERROR; X } X sendline(ACK); return OK; X} X Xwcrx() { X register int sectnum, sectcurr, sendchar, cblklen; X X sectnum=0; sendchar=NAK; X for (;;) { X sendline(sendchar); Lleft=0; X sectcurr=wcgetsec(secbuf, 50); X if (sectcurr==(sectnum+1 & 0377)) { X sectnum++; cblklen = Bytesleft>Blklen ? Blklen:Bytesleft; X putsec(secbuf, cblklen); X if ((Bytesleft-=cblklen) < 0) Bytesleft = 0; X sendchar=ACK; X } X else if (sectcurr==(sectnum&0377)) sendchar=ACK; X else if (sectcurr==WCEOT) { X if (fclose(fout)==ERROR) return ERROR; X sendline(ACK); Lleft=0; return OK; X } X else if (sectcurr==ERROR) return ERROR; X else return ERROR; X } X} X Xwcgetsec(rxbuf, maxtime) char *rxbuf; int maxtime; { X register checksum, wcj, firstch; register char *p; int sectcurr, errors; X for (errors=0; errors=0; ) { X if ((firstch=readline(1)) < 0) goto bilge; X checksum += (*p++ = firstch); X } X if ((firstch=readline(1)) < 0) goto bilge; X if (((checksum-firstch)&0377)==0) return sectcurr; X } X } X else if (firstch==EOT) return WCEOT; X else if (firstch==CAN) return ERROR; Xbilge: X while(readline(1)!=TIMEOUT) X ; X maxtime=40; sendline(NAK); Lleft=0; X } X canit(); return ERROR; X} X Xreadline(timeout) int timeout; { X register n; static char *cdq; X X if (--Lleft >= 0) return (*cdq++ & 0377); X n = timeout/10; X if (n < 2) n = 3; X if (setjmp(tohere)) { Lleft = 0; return TIMEOUT; } X signal(SIGALRM, alrm); alarm(n); X Lleft=read(0, cdq=linbuf, 1024); alarm(0); X if (Lleft < 1) return TIMEOUT; X --Lleft; return (*cdq++ & 0377); X} X Xpurgeline() { Lleft = 0; lseek(0, 0L, 2); } X X Xprocheader(name) char *name; { X register char *p; X X Bytesleft = 2000000000L; p = name + 1 + strlen(name); X if (*p) sscanf(p, "%ld", &Bytesleft); X if ((fout=fopen(name, "w")) == NULL) return ERROR; X return OK; X} X Xputsec(p, n) char *p; int n; X{ for (; --n>=0; ++p) if (*p != 015 && *p != 032) putc(*p, fout); } X Xsendline(c) { char d; d = c; write(1, &d, 1); } X Xchar canistr[] = { 24,24,24,24,24,24,24,24,0 }; X Xcanit() { printf(canistr); Lleft=0; } X X/* END of minirb.c */ X SHAR_EOF chmod 0644 minirb.c || echo "restore of minirb.c fails" echo "x - extracting ptest.sh (Text)" sed 's/^X//' << 'SHAR_EOF' > ptest.sh && X#a short test for sz and rz using a named pipe - no modem used. X/etc/mknod fifo p Xsz fifo Xrm fifo SHAR_EOF chmod 0644 ptest.sh || echo "restore of ptest.sh fails" echo "x - extracting rbsb.c (Text)" sed 's/^X//' << 'SHAR_EOF' > rbsb.c && X/* X * X * Rev 03-06-1988 X * This file contains Unix specific code for setting terminal modes, X * very little is specific to ZMODEM or YMODEM per se (that code is in X * sz.c and rz.c). The CRC-16 routines used by XMODEM, YMODEM, and ZMODEM X * are also in this file, a fast table driven macro version X * X * V7/BSD HACKERS: SEE NOTES UNDER mode(2) !!! X * X * This file is #included so the main file can set parameters such as HOWMANY. X * See the main files (rz.c/sz.c) for compile instructions. X */ X X#ifdef V7 X#include X#include X#include X#define OS "V7/BSD" X#ifdef LLITOUT Xlong Locmode; /* Saved "local mode" for 4.x BSD "new driver" */ Xlong Locbit = LLITOUT; /* Bit SUPPOSED to disable output translations */ X#include X#endif X#endif X X#ifndef OS X#ifndef USG X#define USG X#endif X#endif X X#ifdef USG X#include X#include X#include X#include X#define OS "SYS III/V" X#define MODE2OK X#include X#endif X X#if HOWMANY > 255 XHowmany must be 255 or less X#endif X X/* X * return 1 iff stdout and stderr are different devices X * indicating this program operating with a modem on a X * different line X */ Xint Fromcu; /* Were called from cu or yam */ Xfrom_cu() X{ X struct stat a, b; X X fstat(1, &a); fstat(2, &b); X Fromcu = a.st_rdev != b.st_rdev; X return; X} Xcucheck() X{ X if (Fromcu) X fprintf(stderr,"Please read the manual page BUGS chapter!\r\n"); X} X X Xstruct { X unsigned baudr; X int speedcode; X} speeds[] = { X 110, B110, X 300, B300, X 600, B600, X 1200, B1200, X 2400, B2400, X 4800, B4800, X 9600, B9600, X 19200, EXTA, X 38400, EXTB, X 0, X}; X Xint Twostop; /* Use two stop bits */ X X X#ifndef READCHECK X#ifdef FIONREAD X#define READCHECK X/* X * Return non 0 iff something to read from io descriptor f X */ Xrdchk(f) X{ X static long lf; X X ioctl(f, FIONREAD, &lf); X return ((int) lf); X} X#endif X#ifdef SV X#define READCHECK X#include X Xchar checked = '\0' ; X/* X * Nonblocking I/O is a bit different in System V, Release 2 X */ Xrdchk(f) X{ X int lf, savestat; X X savestat = fcntl(f, F_GETFL) ; X fcntl(f, F_SETFL, savestat | O_NDELAY) ; X lf = read(f, &checked, 1) ; X fcntl(f, F_SETFL, savestat) ; X return(lf) ; X} X#endif X#endif X X Xstatic unsigned Xgetspeed(code) X{ X register n; X X for (n=0; speeds[n].baudr; ++n) X if (speeds[n].speedcode == code) X return speeds[n].baudr; X return 38400; /* Assume fifo if ioctl failed */ X} X X X X#ifdef ICANON Xstruct termio oldtty, tty; X#else Xstruct sgttyb oldtty, tty; Xstruct tchars oldtch, tch; X#endif X Xint iofd = 0; /* File descriptor for ioctls & reads */ X X/* X * mode(n) X * 3: save old tty stat, set raw mode with flow control X * 2: set XON/XOFF for sb/sz with ZMODEM or YMODEM-g X * 1: save old tty stat, set raw mode X * 0: restore original tty mode X */ Xmode(n) X{ X static did0 = FALSE; X X vfile("mode:%d", n); X switch(n) { X#ifdef USG X case 2: /* Un-raw mode used by sz, sb when -g detected */ X if(!did0) X (void) ioctl(iofd, TCGETA, &oldtty); X tty = oldtty; X X tty.c_iflag = BRKINT|IXON; X X tty.c_oflag = 0; /* Transparent output */ X X tty.c_cflag &= ~PARENB; /* Disable parity */ X tty.c_cflag |= CS8; /* Set character size = 8 */ X if (Twostop) X tty.c_cflag |= CSTOPB; /* Set two stop bits */ X X X#ifdef READCHECK X tty.c_lflag = Zmodem ? 0 : ISIG; X tty.c_cc[VINTR] = Zmodem ? -1:030; /* Interrupt char */ X#else X tty.c_lflag = ISIG; X tty.c_cc[VINTR] = Zmodem ? 03:030; /* Interrupt char */ X#endif X tty.c_cc[VQUIT] = -1; /* Quit char */ X#ifdef NFGVMIN X tty.c_cc[VMIN] = 1; X#else X tty.c_cc[VMIN] = 3; /* This many chars satisfies reads */ X#endif X tty.c_cc[VTIME] = 1; /* or in this many tenths of seconds */ X X (void) ioctl(iofd, TCSETAW, &tty); X did0 = TRUE; X return OK; X case 1: X case 3: X if(!did0) X (void) ioctl(iofd, TCGETA, &oldtty); X tty = oldtty; X X tty.c_iflag = n==3 ? (IGNBRK|IXOFF) : IGNBRK; X X /* No echo, crlf mapping, INTR, QUIT, delays, no erase/kill */ X tty.c_lflag &= ~(ECHO | ICANON | ISIG); X X tty.c_oflag = 0; /* Transparent output */ X X tty.c_cflag &= ~PARENB; /* Same baud rate, disable parity */ X tty.c_cflag |= CS8; /* Set character size = 8 */ X if (Twostop) X tty.c_cflag |= CSTOPB; /* Set two stop bits */ X#ifdef NFGVMIN X tty.c_cc[VMIN] = 1; /* This many chars satisfies reads */ X#else X tty.c_cc[VMIN] = HOWMANY; /* This many chars satisfies reads */ X#endif X tty.c_cc[VTIME] = 1; /* or in this many tenths of seconds */ X (void) ioctl(iofd, TCSETAW, &tty); X did0 = TRUE; X Baudrate = getspeed(tty.c_cflag & CBAUD); X return OK; X#endif X#ifdef V7 X /* X * NOTE: this should transmit all 8 bits and at the same time X * respond to XOFF/XON flow control. If no FIONREAD or other X * READCHECK alternative, also must respond to INTRRUPT char X * This doesn't work with V7. It should work with LLITOUT, X * but LLITOUT was broken on the machine I tried it on. X */ X case 2: /* Un-raw mode used by sz, sb when -g detected */ X if(!did0) { X ioctl(iofd, TIOCEXCL, 0); X ioctl(iofd, TIOCGETP, &oldtty); X ioctl(iofd, TIOCGETC, &oldtch); X#ifdef LLITOUT X ioctl(TIOCLGET, &Locmode); /* Get "local mode" */ X#endif X } X tty = oldtty; X tch = oldtch; X#ifdef READCHECK X tch.t_intrc = Zmodem ? -1:030; /* Interrupt char */ X#else X tch.t_intrc = Zmodem ? 03:030; /* Interrupt char */ X#endif X tty.sg_flags |= (ODDP|EVENP|CBREAK); X tty.sg_flags &= ~(ALLDELAY|CRMOD|ECHO|LCASE); X ioctl(iofd, TIOCSETP, &tty); X ioctl(iofd, TIOCSETC, &tch); X#ifdef LLITOUT X ioctl(TIOCLBIS, &Locbit); X#endif X bibi(99); /* un-raw doesn't work w/o lit out */ X did0 = TRUE; X return OK; X case 1: X case 3: X if(!did0) { X ioctl(iofd, TIOCEXCL, 0); X ioctl(iofd, TIOCGETP, &oldtty); X ioctl(iofd, TIOCGETC, &oldtch); X#ifdef LLITOUT X ioctl(TIOCLGET, &Locmode); /* Get "local mode" */ X#endif X } X tty = oldtty; X tty.sg_flags |= RAW; X tty.sg_flags &= ~ECHO; X ioctl(iofd, TIOCSETP, &tty); X did0 = TRUE; X Baudrate = getspeed(tty.sg_ospeed); X return OK; X#endif X case 0: X if(!did0) X return ERROR; X#ifdef USG X (void) ioctl(iofd, TCSBRK, 1); /* Wait for output to drain */ X (void) ioctl(iofd, TCFLSH, 1); /* Flush input queue */ X (void) ioctl(iofd, TCSETAW, &oldtty); /* Restore modes */ X (void) ioctl(iofd, TCXONC,1); /* Restart output */ X#endif X#ifdef V7 X ioctl(iofd, TIOCSETP, &oldtty); X ioctl(iofd, TIOCSETC, &oldtch); X ioctl(iofd, TIOCNXCL, 0); X#ifdef LLITOUT X ioctl(TIOCLSET, &Locmode); /* Restore "local mode" */ X#endif X#endif X X return OK; X default: X return ERROR; X } X} X Xsendbrk() X{ X#ifdef V7 X#ifdef TIOCSBRK X#define CANBREAK X sleep(1); X ioctl(iofd, TIOCSBRK, 0); X sleep(1); X ioctl(iofd, TIOCCBRK, 0); X#endif X#endif X#ifdef USG X#define CANBREAK X ioctl(iofd, TCSBRK, 0); X#endif X} X X/* End of rbsb.c */ SHAR_EOF chmod 0644 rbsb.c || echo "restore of rbsb.c fails" echo "x - extracting rz.1 (Text)" sed 's/^X//' << 'SHAR_EOF' > rz.1 && X'\" Revision Level X'\" Last Delta 04-22-88 X.TH RZ 1 OMEN X.SH NAME Xrx, rb, rz \- XMODEM, YMODEM, ZMODEM (Batch) file receive X.SH SYNOPSIS X.B rz X.RB [\- "\ +abepqtuvy" ] X.br X.B rb X.RB [\- "\ +abqtuvy" ] X.br X.B rx X.RB [\- "\ abceqtuv" ] X.I file X.br X.B gz X.I "file ..." X.br X.RB [ \- ][ v ] rzCOMMAND X.SH DESCRIPTION XThis program uses error correcting protocols to receive Xfiles over a dial-in serial port from a variety of programs running under XPC-DOS, CP/M, X.SM Unix, Xand other operating systems. XIt is invoked from a shell prompt Xmanually, or automatically as a result of an X"sz file ..." command given to the calling program. X XWhile X.I rz Xis smart enough to be called from X.I cu(1), Xvery few versions of X.I cu(1) Xare smart enough to allow X.I rz Xto work properly. XUnix flavors of Professional-YAM are available for such dial-out application. X X X.B Rz X(Receive ZMODEM) Xreceives files with the ZMODEM batch protocol. XPathnames are supplied by the sending program, Xand directories are made if necessary (and possible). XNormally, the X"rz" command is automatically issued by the calling ZMODEM program, Xbut some defective ZMODEM implementations may require starting X.I rz Xthe old fashioned way. X X X.B Rb Xreceives file(s) with YMODEM, Xaccepting either standard 128 byte sectors or X1024 byte sectors X(YAM sb X.B -k Xoption). XThe user should determine when Xthe 1024 byte block length Xactually improves throughput without causing lost data Xor even system crashes. X XIf True YMODEM (Omen Technology trademark) file information (file length, etc.) Xis received, Xthe file length controls the number of bytes written to Xthe output dataset, Xand the modify time and file mode X(iff non zero) Xare set accordingly. X XIf no True YMODEM file information is received, Xslashes in the pathname are changed to underscore, Xand any trailing period in the pathname is eliminated. XThis conversion is useful for files received from CP/M systems. XWith YMODEM, each file name is converted to lower case Xunless it contains one or more lower case letters. X X X.B Rx Xreceives a single X.I file Xwith XMODEM or XMODEM-1k protocol. XThe user should determine when Xthe 1024 byte block length Xactually improves throughput without causing problems. XThe user must supply the file name to both sending and receiving programs. XUp to 1023 garbage characters may be added to the received file. X X.B Gz Xis a shell script which calls X.I sz Xto command Pro-YAM or ZCOMM to transmit the specified files. XPathnames used with X.I gz Xmust be escaped if they have special significance to the Unix shell. X.br XEXAMPLE: Xgz "-a C:*.c D:*.h" X X X.B Rz Xmay be invoked as X.B rzCOMMAND X(with an optional leading \- as generated by login(1)). XFor each received file, X.I rz Xwill pipe the file to ``COMMAND filename'' Xwhere filename is the name of the transmitted file Xwith the file contents as standard input. X XEach file transfer is acknowledged when COMMAND exits with 0 status. XA non zero exit status terminates transfers. X XA typical use for this form is X.I rzrmail Xwhich calls rmail(1) Xto post mail to the user specified by the transmitted file name. XFor example, sending the file "caf" from a PC-DOS system to X.I rzrmail Xon a X.SM Unix Xsystem Xwould result in the contents of the DOS file "caf" being mailed to user "caf". X XOn some X.SM Unix Xsystems, the login directory must contain a link to XCOMMAND as login sets SHELL=rsh which disallows absolute Xpathnames. XIf invoked with a leading ``v'', X.I rz Xwill report progress to /tmp/rzlog. XThe following entry works for X.SM Unix XSYS III/V: X.ce Xrzrmail::5:1::/bin:/usr/local/rzrmail XIf the SHELL environment variable includes X.I "rsh" Xor X.I "rksh" X(restricted shell), X.I rz Xwill not accept absolute pathnames Xor references to a parent directory, Xwill not modify an existing file, and Xremoves any files received in error. X XIf X.B rz Xis invoked with stdout and stderr to different datasets, XVerbose is set to 2, causing frame by frame progress reports Xto stderr. XThis may be disabled with the X.B q Xoption. X X.PP XThe meanings of the available options are: X.PP X.PD 0 X.TP X.B a XConvert files to X.SM Unix Xconventions by stripping carriage returns and all characters Xbeginning with the first Control Z (CP/M end of file). X.TP X.B b XBinary X(tell it like it is) Xfile transfer override. X.TP X.B c XRequest 16 bit CRC. XXMODEM file transfers default to 8 bit checksum. XYMODEM and ZMODEM normally use 16 bit CRC. X.TP X.B D XOutput file data to /dev/null; for testing. X(Unix only) X.TP X.B e XForce sender to escape all control characters; Xnormally XON, XOFF, DLE, CR-@-CR, and Ctrl-X are escaped. X.TP X.B p X(ZMODEM) Protect: skip file if destination file exists. X.TP X.B q XQuiet suppresses verbosity. X.TP X.B "t tim" XChange timeout to X.I tim Xtenths of seconds. X.TP X.B v XVerbose Xcauses a list of file Xnames to be appended to X/tmp/rzlog . XMore v's generate more output. X.TP X.B y XYes, clobber any existing files with the same name. X.PD X.ne 6 X.SH EXAMPLES X.RE X(Pro-YAM command) X.RS X.I X.br XPro-YAM Command: X.I "sz *.h *.c" X.br X(This automatically invokes X.I rz Xon the connected system.) X.RE X.SH SEE ALSO XZMODEM.DOC, XYMODEM.DOC, XProfessional-YAM, Xcrc(omen), Xsz(omen), Xusq(omen), Xundos(omen) X XCompile time options required Xfor various operating systems are described in the Xsource file. X.SH NOTES XSending serial data to timesharing minicomputers Xat sustained high speeds Xhas been known to cause lockups, system halts, kernel panics, Xand occasional antisocial behaviour. XWhen experimenting with high speed input to a Xsystem, consider rebooting the system Xif the file transfers are not successful, Xespecially if the personality of the system appears altered. X XThe Unix "ulimit" parameter must be set high enough Xto permit large file transfers. X XThe TTY input buffering on some systems may not allow long blocks Xor streaming input at high speed. XYou should suspect this problem when you Xcan't send data to the Unix system at high speeds using ZMODEM, XYMODEM-1k or XMODEM-1k, Xwhen YMODEM with 128 byte blocks works properly. XIf the system's tty line handling is really broken, the serial port Xor the entire system may not survive the onslaught of long bursts Xof high speed data. X XThe DSZ or Pro-YAM X.B "zmodem l" Xnumeric parameter may be set to a value between 64 and 1024 to limit the Xburst length ("zmodem pl128"). X X32 bit CRC code courtesy Gary S. Brown. XDirectory creation code from John Gilmore's PD TAR program. X.SH BUGS XCalling X.I rz Xfrom most versions of cu(1) doesn't work because cu's receive process Xfights X.I rz Xfor characters from the modem. X XPrograms that do not properly implement the specified file transfer protocol Xmay cause X.I sz Xto "hang" the port for a minute or two. XEvery reported instance of this problem has been corrected by using XZCOMM, Pro-YAM, or other program with a correct implementation Xof the specified protocol. X XMany programs claiming to support YMODEM only support XMODEM with 1k blocks, Xand they often don't get that quite right. X XPathnames are restricted to 127 characters. XIn XMODEM single file mode, the pathname given on the command line Xis still processed as described above. XThe ASCII option\'s CR/LF to NL translation merely deletes CR\'s; Xundos(omen) performs a more intelligent translation. X.SH "VMS VERSION" XThe VMS version does not set the file time. X XVMS C Standard I/O and RMS may interact to modify Xfile contents unexpectedly. X XThe VMS version does not support invocation as X.B rzCOMMAND . XThe current VMS version does not support XMODEM, XMODEM-1k, or YMODEM. X XAccording to the VMS documentation, Xthe buffered input routine used on the VMS version of X.I rz Xintroduces a delay Xof up to one second for each protocol transaction. XThis delay may be significant for very short files. XRemoving the "#define BUFREAD" line from rz.c will Xeliminate this delay at the expense of increased XCPU utilization. X XThe VMS version causes DCL to generate a random off the wall Xerror message under some error conditions; this is a result of Xthe incompatibility of the VMS "exit" function with the XUnix/MSDOS standard. X.SH "ZMODEM CAPABILITIES" X.I Rz Xsupports incoming ZMODEM binary (-b), ASCII (-a), Xprotect (-p), Xclobber (-y), Xand append (-+) Xrequests. XThe default is protect (-p) and binary (-b). X XThe Unix versions support ZMODEM command execution. X.SH FILES Xrz.c, crctab.c, rbsb.c, zm.c, zmodem.h Unix source files. X Xrz.c, crctab.c, vrzsz.c, zm.c, zmodem.h, vmodem.h, vvmodem.c, XVMS source files. X X/tmp/rzlog stores debugging output generated with -vv option X(rzlog on VMS). SHAR_EOF chmod 0644 rz.1 || echo "restore of rz.1 fails" echo "x - extracting rz.c (Text)" sed 's/^X//' << 'SHAR_EOF' > rz.c && X#define VERSION "2.02 04-22-88" X#define PUBDIR "/usr/spool/uucppublic" X X/*% cc -compat -M2 -Ox -K -i -DMD % -o rz; size rz; X<-xtx-*> cc386 -Ox -DMD -DSEGMENTS=8 rz.c -o $B/rz; size $B/rz X * X * rz.c By Chuck Forsberg X * X * cc -O rz.c -o rz USG (3.0) Unix X * cc -O -DV7 rz.c -o rz Unix V7, BSD 2.8 - 4.3 X * X * ln rz rb; ln rz rx For either system X * X * ln rz /usr/bin/rzrmail For remote mail. Make this the X * login shell. rzrmail then calls X * rmail(1) to deliver mail. X * X * To compile on VMS: X * X * define LNK$LIBRARY SYS$LIBRARY:VAXCRTL.OLB X * cc rz.c X * cc vvmodem.c X * link rz,vvmodem X * rz :== $disk:[username.subdir]rz.exe X * X * X * Unix is a trademark of Western Electric Company X * X * A program for Unix to receive files and commands from computers running X * Professional-YAM, PowerCom, YAM, IMP, or programs supporting XMODEM. X * rz uses Unix buffered input to reduce wasted CPU time. X * X * Iff the program is invoked by rzCOMMAND, output is piped to X * "COMMAND filename" (Unix only) X * X * Some systems (Venix, Coherent, Regulus) may not support tty raw mode X * read(2) the same way as Unix. ONEREAD must be defined to force one X * character reads for these systems. Added 7-01-84 CAF X * X * Alarm signal handling changed to work with 4.2 BSD 7-15-84 CAF X * X * BIX added 6-30-87 to support BIX(TM) upload protocol used by the X * Byte Information Exchange. X * X * NFGVMIN Updated 2-18-87 CAF for Xenix systems where c_cc[VMIN] X * doesn't work properly (even though it compiles without error!), X * X * SEGMENTS=n added 2-21-88 as a model for CP/M programs X * for CP/M-80 systems that cannot overlap modem and disk I/O. X * X * VMS flavor hacks begin with rz version 2.00 X * X * -DMD may be added to compiler command line to compile in X * Directory-creating routines from Public Domain TAR by John Gilmore X * X * HOWMANY may be tuned for best performance X * X * USG UNIX (3.0) ioctl conventions courtesy Jeff Martin X */ X X#ifdef vax11c X#include X#include X#define LOGFILE "rzlog.tmp" X#include X#include X#include X#include X#include X#define OS "VMS" X#define BUFREAD Xextern int errno; X#define SS_NORMAL SS$_NORMAL X#else X#define SS_NORMAL 0 X#define LOGFILE "/tmp/rzlog" X#include X#include X#include X#include X#include Xextern int errno; XFILE *popen(); X#endif X X#define OK 0 X#define FALSE 0 X#define TRUE 1 X#define ERROR (-1) X X/* X * Max value for HOWMANY is 255. X * A larger value reduces system overhead but may evoke kernel bugs. X * 133 corresponds to an XMODEM/CRC sector X */ X#ifndef HOWMANY X#define HOWMANY 133 X#endif X X/* Ward Christensen / CP/M parameters - Don't change these! */ X#define ENQ 005 X#define CAN ('X'&037) X#define XOFF ('s'&037) X#define XON ('q'&037) X#define SOH 1 X#define STX 2 X#define EOT 4 X#define ACK 6 X#define NAK 025 X#define CPMEOF 032 X#define WANTCRC 0103 /* send C not NAK to get crc not checksum */ X#define TIMEOUT (-2) X#define RCDO (-3) X#define ERRORMAX 5 X#define RETRYMAX 5 X#define WCEOT (-10) X#define PATHLEN 257 /* ready for 4.2 bsd ? */ X#define UNIXFILE 0xF000 /* The S_IFMT file mask bit for stat */ X Xint Zmodem=0; /* ZMODEM protocol requested */ Xint Nozmodem = 0; /* If invoked as "rb" */ Xunsigned Baudrate = 2400; X#ifdef vax11c X#include "vrzsz.c" /* most of the system dependent stuff here */ X#else X#include "rbsb.c" /* most of the system dependent stuff here */ X#endif X#include "crctab.c" X Xchar *substr(); XFILE *fout; X X/* X * Routine to calculate the free bytes on the current file system X * ~0 means many free bytes (unknown) X */ Xlong getfree() X{ X return(~0L); /* many free bytes ... */ X} X Xint Lastrx; Xint Crcflg; Xint Firstsec; Xint Eofseen; /* indicates cpm eof (^Z) has been received */ Xint errors; Xint Restricted=0; /* restricted; no /.. or ../ in filenames */ X#ifdef ONEREAD X/* Sorry, Regulus and some others don't work right in raw mode! */ Xint Readnum = 1; /* Number of bytes to ask for in read() from modem */ X#else Xint Readnum = HOWMANY; /* Number of bytes to ask for in read() from modem */ X#endif X X#define DEFBYTL 2000000000L /* default rx file size */ Xlong Bytesleft; /* number of bytes of incoming file left */ Xlong Modtime; /* Unix style mod time for incoming file */ Xint Filemode; /* Unix style mode for incoming file */ Xchar Pathname[PATHLEN]; Xchar *Progname; /* the name by which we were called */ X Xint Batch=0; Xint Topipe=0; Xint MakeLCPathname=TRUE; /* make received pathname lower case */ Xint Verbose=0; Xint Quiet=0; /* overrides logic that would otherwise set verbose */ Xint Nflag = 0; /* Don't really transfer files */ Xint Rxclob=FALSE; /* Clobber existing file */ Xint Rxbinary=FALSE; /* receive all files in bin mode */ Xint Rxascii=FALSE; /* receive files in ascii (translate) mode */ Xint Thisbinary; /* current file is to be received in bin mode */ Xint Blklen; /* record length of received packets */ X X#ifdef SEGMENTS Xint chinseg = 0; /* Number of characters received in this data seg */ Xchar secbuf[1+(SEGMENTS+1)*1024]; X#else Xchar secbuf[1025]; X#endif X X Xchar linbuf[HOWMANY]; Xint Lleft=0; /* number of characters in linbuf */ Xtime_t timep[2]; Xchar Lzmanag; /* Local file management request */ Xchar zconv; /* ZMODEM file conversion request */ Xchar zmanag; /* ZMODEM file management request */ Xchar ztrans; /* ZMODEM file transport request */ Xint Zctlesc; /* Encode control characters */ Xint Zrwindow = 1400; /* RX window size (controls garbage count) */ X Xjmp_buf tohere; /* For the interrupt on RX timeout */ X X#define xsendline(c) sendline(c) X#include "zm.c" X Xint tryzhdrtype=ZRINIT; /* Header type to send corresponding to Last rx close */ X Xalrm() X{ X longjmp(tohere, -1); X} X X/* called by signal interrupt or terminate to clean things up */ Xbibi(n) X{ X if (Zmodem) X zmputs(Attn); X canit(); mode(0); X fprintf(stderr, "rz: caught signal %d; exiting", n); X cucheck(); X exit(128+n); X} X Xmain(argc, argv) Xchar *argv[]; X{ X register char *cp; X register npats; X char *virgin, **patts; X char *getenv(); X int exitcode; X X Rxtimeout = 100; X setbuf(stderr, NULL); X if ((cp=getenv("SHELL")) && (substr(cp, "rsh") || substr(cp, "rksh"))) X Restricted=TRUE; X X from_cu(); X#ifdef vax11c X Progname = virgin = "rz"; X#else X chkinvok(virgin=argv[0]); /* if called as [-]rzCOMMAND set flag */ X#endif X npats = 0; X while (--argc) { X cp = *++argv; X if (*cp == '-') { X while( *++cp) { X switch(*cp) { X case '\\': X cp[1] = toupper(cp[1]); continue; X case '+': X Lzmanag = ZMAPND; break; X case 'a': X Rxascii=TRUE; break; X case 'b': X Rxbinary=TRUE; break; X case 'c': X Crcflg=TRUE; break; X#ifndef vax11c X case 'D': X Nflag = TRUE; break; X#endif X case 'e': X Zctlesc = 1; break; X case 'p': X Lzmanag = ZMPROT; break; X case 'q': X Quiet=TRUE; Verbose=0; break; X case 't': X if (--argc < 1) { X usage(); X } X Rxtimeout = atoi(*++argv); X if (Rxtimeout<10 || Rxtimeout>1000) X usage(); X break; X case 'w': X if (--argc < 1) { X usage(); X } X Zrwindow = atoi(*++argv); X break; X case 'u': X MakeLCPathname=FALSE; break; X case 'v': X ++Verbose; break; X case 'y': X Rxclob=TRUE; break; X default: X usage(); X } X } X } X else if ( !npats && argc>0) { X if (argv[0][0]) { X npats=argc; X patts=argv; X } X } X } X if (npats > 1) X usage(); X if (Batch && npats) X usage(); X if (Verbose) { X if (freopen(LOGFILE, "a", stderr)==NULL) { X printf("Can't open log file %s\n",LOGFILE); X exit(0200); X } X setbuf(stderr, NULL); X fprintf(stderr, "argv[0]=%s Progname=%s\n", virgin, Progname); X } X if (Fromcu && !Quiet) { X if (Verbose == 0) X Verbose = 2; X } X mode(1); X if (signal(SIGINT, bibi) == SIG_IGN) { X signal(SIGINT, SIG_IGN); signal(SIGKILL, SIG_IGN); X } X else { X signal(SIGINT, bibi); signal(SIGKILL, bibi); X } X signal(SIGTERM, bibi); X if (wcreceive(npats, patts)==ERROR) { X exitcode=0200; X canit(); X } X mode(0); X if (exitcode && !Zmodem) /* bellow again with all thy might. */ X canit(); X if (exitcode) X cucheck(); X exit(exitcode ? exitcode:SS_NORMAL); X} X X Xusage() X{ X cucheck(); X#ifdef vax11c X fprintf(stderr,"Usage: rz [-abeuvy]\n"); X#else X fprintf(stderr,"Usage: rz [-abeuvy] (ZMODEM)\n"); X fprintf(stderr,"or rb [-abuvy] (YMODEM)\n"); X fprintf(stderr,"or rx [-abcv] file (XMODEM or XMODEM-1k)\n"); X#endif X fprintf(stderr," -a ASCII transfer (strip CR)\n"); X fprintf(stderr," -b Binary transfer for all files\n"); X#ifndef vax11c X fprintf(stderr," -c Use 16 bit CRC (XMODEM)\n"); X#endif X fprintf(stderr," -e Escape control characters (ZMODEM)\n"); X fprintf(stderr," -v Verbose more v's give more info\n"); X fprintf(stderr," -y Yes, clobber existing file if any\n"); X fprintf(stderr,"%s %s for %s by Chuck Forsberg, Omen Technology INC\n", X Progname, VERSION, OS); X fprintf(stderr, "\t\t\042The High Reliability Software\042\n"); X exit(SS_NORMAL); X} X/* X * Debugging information output interface routine X */ X/* VARARGS1 */ Xvfile(f, a, b, c) Xregister char *f; X{ X if (Verbose > 2) { X fprintf(stderr, f, a, b, c); X fprintf(stderr, "\n"); X } X} X X/* X * Let's receive something already. X */ X Xchar *rbmsg = X"%s ready. To begin transfer, type \"%s file ...\" to your modem program\r\n\n"; X Xwcreceive(argc, argp) Xchar **argp; X{ X register c; X X if (Batch || argc==0) { X Crcflg=1; X if ( !Quiet) X fprintf(stderr, rbmsg, Progname, Nozmodem?"sb":"sz"); SHAR_EOF echo "End of part 1" echo "File rz.c is continued in part 2" echo "2" > s2_seq_.tmp exit 0 -- Keith Petersen Arpa: W8SDZ@SIMTEL20.ARPA Uucp: {bellcore,decwrl,harvard,lll-crg,ucbvax,uw-beaver}!simtel20.arpa!w8sdz GEnie: W8SDZ