📄 crzsz.sh
字号:
X @echo ""Xnext:X LIBS=-lposixX $(CC) -g -posix $(OFLAG) -DPOSIX -DMD=2 crz.c -o crzX size crzX -rm -f crb crxX ln crz crbX ln crz crxX $(CC) -g -posix $(OFLAG) -DPOSIX csz.c -o cszX size cszX -rm -f csb csx czcommand czcommandiX ln csz csbX ln csz csxX ln csz czcommandX ln csz czcommandiXundos: undos.cX cc -O undos.c -o undosX -rm -f tounix todos unmac tomac tocpm unparityX ln undos tounixX ln undos todosX ln undos unmacX ln undos tomacX ln undos tocpmX ln undos unparityXXlint:X lint -DUSG -DSV -DOLD csz.c >/tmp/csz.fluffX lint -DUSG -DSV -DOLD crz.c >/tmp/crz.fluffXXcsz: nothingcsb: nothingcrz: nothingcrb: nothingSHAR_EOFchmod 0664 Makefile ||echo 'restore of Makefile failed'Wc_c="`wc -c < 'Makefile'`"test 8177 -eq "$Wc_c" || echo 'Makefile: original size 8177, current size' "$Wc_c"fi# ============= crz.c ==============if test -f 'crz.c' -a X"$1" != X"-c"; then echo 'x - skipping crz.c (File already exists)'elseecho 'x - extracting crz.c (Text)'sed 's/^X//' << 'SHAR_EOF' > 'crz.c' &&#define VERSION "1.03 10-01-99"X/*X *X * crz.c By Chuck ForsbergX * Copyright 1999 Omen Technology Inc All Rights ReservedX *X * A program for Unix to receive files and commands from computers runningX * Professional-YAM, PowerCom, YAM, IMP, or programs supporting XMODEM.X * crz uses Unix buffered input to reduce wasted CPU time.X *X * X *********************************************************************X *********************************************************************X * X *X * This version implements numerous enhancements including ZMODEMX * Run Length Encoding and variable length headers. TheseX * features were not funded by the original Telenet developmentX * contract.X * X * Any programs which incorporate part or all of this code must beX * provided in source form with this notice intact except byX * prior written permission from Omen Technology Incorporated.X * This includes compiled executables of this program.X *X * The .doc files and the file "mailer.crz" must also be included.X * X * Use of this software for commercial or administrative purposesX * except when exclusively limited to interfacing Omen TechnologyX * products requires license payment of $20.00 US per userX * (less in quantity, see mailer.crz). Use of this code byX * inclusion, decompilation, reverse engineering or any other meansX * constitutes agreement to these conditions and acceptance ofX * liability to license the materials and payment of reasonableX * legal costs necessary to enforce this license agreement.X *X *X * Omen Technology IncX * Post Office Box 4681X * Portland OR 97208X *X * This code is made available in the hope it will be useful,X * BUT WITHOUT ANY WARRANTY OF ANY KIND OR LIABILITY FOR ANYX * DAMAGES OF ANY KIND.X *X *X * -DMD may be added to compiler command line to compile inX * Directory-creating routines from Public Domain TAR by John GilmoreX *X * USG UNIX (3.0) ioctl conventions courtesy Jeff MartinX */Xchar *Copyright = "Copyright 1998 Omen Technology Inc All Rights Reserved";XX#define LOGFILE "/tmp/crzlog"#define LOGFILE2 "crzlog"#include <stdio.h>#include <signal.h>#include <ctype.h>#include <errno.h>extern int errno;X#define OK 0#define FALSE 0#define TRUE 1#define ERROR (-1)X/*X * Max value for HOWMANY is 255.X * A larger value reduces system overhead but may evoke kernel bugs.X */#ifndef HOWMANY#define HOWMANY 96#endifX/* Ward Christensen / CP/M parameters - Don't change these! */#define ENQ 005#define CAN ('X'&037)#define XOFF ('s'&037)#define XON ('q'&037)#define SOH 1#define STX 2#define EOT 4#define ACK 6#define NAK 025#define CPMEOF 032#define WANTCRC 0103 /* send C not NAK to get crc not checksum */#define TIMEOUT (-2)#define RCDO (-3)#define GCOUNT (-4)#define ERRORMAX 5#define RETRYMAX 5#define WCEOT (-10)#define PATHLEN 257 /* ready for 4.2 bsd ? */#define UNIXFILE 0xF000 /* The S_IFMT file mask bit for stat */Xint Zmodem=0; /* ZMODEM protocol requested */int Nozmodem = 0; /* If invoked as "rb" */unsigned Baudrate = 9600;XX#include "rbsb.c" /* most of the system dependent stuff here */#include "crctab.c"char endmsg[90] = {0}; /* Possible message to display on exit */char Zsendmask[33]; /* Additional control chars to mask */Xchar *substr();FILE *fout;XX/* send cancel string to get the other end to shut up */canit(){X static char canistr[] = {X 24,24,24,24,24,24,24,24,24,24,8,8,8,8,8,8,8,8,8,8,0X };XX zmputs(canistr);X Lleft=0; /* Do read next time ... */}X/*X * Routine to calculate the free bytes on the current file systemX * ~0 means many free bytes (unknown)X */long getfree(){X return(2147483647); /* many free bytes ... */}Xint Lastrx;long rxbytes;int Crcflg;int Firstsec;int Eofseen; /* indicates cpm eof (^Z) has been received */int errors;X#define DEFBYTL 2000000000L /* default rx file size */long Bytesleft; /* number of bytes of incoming file left */long Modtime; /* Unix style mod time for incoming file */int Filemode; /* Unix style mode for incoming file */long Totalleft;long Filesleft;char Pathname[PATHLEN];char *Progname; /* the name by which we were called */Xint Batch=0;int Thisbinary; /* current file is to be received in bin mode */int Rxbinary=FALSE; /* receive all files in bin mode */int Rxascii=FALSE; /* receive files in ascii (translate) mode */int Blklen; /* record length of received packets */X#ifdef SEGMENTSint chinseg = 0; /* Number of characters received in this data seg */char secbuf[1+(SEGMENTS+1)*1024];#elsechar secbuf[1025];#endifXXtime_t timep[2];char Lzmanag; /* Local file management request */char Lzconv; /* Local ZMODEM file conversion request */char zconv; /* ZMODEM file conversion request */char zmanag; /* ZMODEM file management request */char ztrans; /* ZMODEM file transport request */int Zctlesc; /* Encode control characters */int Zrwindow = 1400; /* RX window size (controls garbage count) */X/*X * Log an errorX */voidzperr1(s,p,u)char *s, *p, *u;{X fprintf(stderr, "Retry %d: ", errors);X fprintf(stderr, s);X fprintf(stderr, "\n");}Xvoidzperr2(s,p,u)char *s, *p, *u;{X fprintf(stderr, "Retry %d: ", errors);X fprintf(stderr, s, p);X fprintf(stderr, "\n");}Xvoidzperr3(s,p,u)char *s, *p, *u;{X fprintf(stderr, "Retry %d: ", errors);X fprintf(stderr, s, p, u);X fprintf(stderr, "\n");}X#include "zm.c"#include "zmr.c"Xint tryzhdrtype=ZRINIT; /* Header type to send corresponding to Last rx close */X/* called by signal interrupt or terminate to clean things up */voidbibi(n){X if (Zmodem)X zmputs(Attn);X canit(); mode(0);X fprintf(stderr, "crz: caught signal %d; exiting status 3", n);X exit(3);}Xmain(argc, argv)char *argv[];{X register char *cp;X register npats;X char *virgin, **patts;X int exitcode = 0;XX Rxtimeout = 100;X setbuf(stderr, NULL);XX chkinvok(virgin=argv[0]);X Tty = 1; Ttystream = stdout;X npats = 0;X while (--argc) {X cp = *++argv;X if (*cp == '-') {X ++cp;X while( *cp) {X if (isdigit(*cp)) {X ++cp; continue;X }X switch(*cp++) {X case 'a':X Rxascii=TRUE; break;X case 'c':X Crcflg = TRUE; break;X case 't':X if (isdigit(*cp))X Rxtimeout = atoi(cp);X else {X if (--argc < 1)X usage();X Rxtimeout = atoi(*++argv);X }X if (Rxtimeout<1 || Rxtimeout>1000)X usage();X break;X case 'w':X if (isdigit(*cp))X Zrwindow = atoi(cp);X else {X if (--argc < 1)X usage();X Zrwindow = atoi(*++argv);X }X break;X case 'v':X ++Verbose; break;X case 'y':X Lzmanag = ZMCLOB;X 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 if (freopen(LOGFILE2, "a", stderr)==NULL) {X fprintf(stderr, "Can't open log file!\n");X exit(2);X }X setbuf(stderr, NULL);X fprintf(stderr, "argv[0]=%s Progname=%s\n", virgin, Progname);X }*/X vfile("%s %s for %s tty=%s\n", Progname, VERSION, OS, Nametty);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=1;X canit();X }X if (exitcode && !Zmodem) /* bellow again with all thy might. */X canit();X if (endmsg[0])X fprintf(stderr, " %s: %s\r\n", Progname, endmsg);X fprintf(stderr, "%s %s finished.\r\n", Progname, VERSION);X fflush(stderr);#ifndef REGISTEREDX /* Removing or disabling this code without registering is theft */X if (!Usevhdrs) {X fprintf(stderr, "\n\n\n**** UNREGISTERED COPY *****\r\n");X fprintf(stderr, "Please read the License Agreement in crz.doc\r\n");X fflush(stderr);X sleep(10);X }#endifX mode(0);X if(exitcode)X exit(1);X exit(0);X /* NOTREACHED */}XXusage(){X fprintf(stderr,X "Receive Files and Commands with ZMODEM/YMODEM/XMODEM Protocol\n\n");X fprintf(stderr,"Usage: crz [-v] [-wN] [-tT] (ZMODEM)\n");X fprintf(stderr,"or crb [-avy] [-tT] (YMODEM)\n");X fprintf(stderr,"or crx [-acvy] [-tT] file (XMODEM)\n\n");X fprintf(stderr,"Supports the following incoming ZMODEM options given to the sending program:\n\X compression (-Z), binary (-b), ASCII CR/LF>NL (-a), newer(-n),\n\X newer+longer(-N), protect (-p), Crash Recovery (-r),\n\X clobber (-y), match+clobber (-Y), and append (-+).\n\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\n");X fprintf(stderr,"Copyright (c) 1998 Omen Technology INC All Rights Reserved\n");X fprintf(stderr,X "See crz.doc and README for option descriptions and licensing information.\n\n");#ifndef REGISTEREDX fprintf(stderr, "\n\n\n **** UNREGISTERED COPY *****\r\n");X fprintf(stderr, "Please read the License Agreement in crz.doc\r\n");#endifX exit(2);}X/*X * Let's receive something already.X */XXwcreceive(argc, argp)char **argp;{X register c;XX if (Batch || argc==0) {X Crcflg=1;X if (c=tryz()) {X if (c == ZCOMPL)X return OK;X if (c == ERROR)X goto fubar;X c = rzfiles();X if (c)X goto fubar;X } else {X for (;;) {X if (wcrxpn(secbuf)== ERROR)X goto fubar;X if (secbuf[0]==0)X return OK;X if (procheader(secbuf))X goto fubar;X if (wcrx()==ERROR)X goto fubar;X }X }X } else {X Bytesleft = DEFBYTL; Filemode = 0; Modtime = 0L;XX procheader(""); strcpy(Pathname, *argp);X if ((fout=fopen(Pathname, "w")) == NULL)X return ERROR;X fprintf(stderr, "\ncrz: Receive file %s open.\r\n", Pathname);X if (wcrx()==ERROR)X goto fubar;X }X return OK;fubar:X canit();X Modtime = 1;X if (fout)X fclose(fout);X return ERROR;}XX/*X * Fetch a pathname from the other end as a C ctyle ASCIZ string.X * Length is indeterminate as long as less than BlklenX * A null string represents no more files (YMODEM)X */wcrxpn(rpn)char *rpn; /* receive a pathname */{X register c;XX purgeline();Xet_tu:X Firstsec=TRUE; Eofseen=FALSE;X sendline(Crcflg?WANTCRC:NAK); flushmo();X Lleft=0; /* Do read next time ... */X switch (c = wcgetsec(rpn, 100)) {X case WCEOT:X zperr2( "Pathname fetch returned %d", c);X sendline(ACK); flushmo();X Lleft=0; /* Do read next time ... */X readline(1);X goto et_tu;X case 0:X sendline(ACK); flushmo(); return OK;X default:X return ERROR;X }}X/*X * Adapted from CMODEM13.C, written byX * Jack M. Wierda and Roderick W. HartX */Xwcrx(){X register int sectnum, sectcurr;X register char sendchar;X int cblklen; /* bytes to dump this block */XX Firstsec=TRUE;sectnum=0; Eofseen=FALSE;X sendchar=Crcflg?WANTCRC:NAK;XX for (;;) {X sendline(sendchar); /* send it now, we're ready! */X flushmo();X Lleft=0; /* Do read next time ... */X sectcurr=wcgetsec(secbuf, (sectnum&0177)?50:130);X if (sectcurr==(sectnum+1 &0377)) {X fprintf(stderr, "Sector %3d %2dk\n", sectcurr, sectcurr/8 );X sectnum++;X cblklen = Bytesleft>Blklen ? Blklen:Bytesleft;X if (putsec(secbuf, cblklen)==ERROR)X return ERROR;X if ((Bytesleft-=cblklen) < 0)X Bytesleft = 0;X sendchar=ACK;X }X else if (sectcurr==(sectnum&0377)) {X zperr1( "Received dup Sector");X sendchar=ACK;X }X else if (sectcurr==WCEOT) {X if (closeit())X return ERROR;X sendline(ACK); flushmo();X Lleft=0; /* Do read next time ... */X return OK;X }X else if (sectcurr==ERROR)X return ERROR;X else {X zperr1( "Sync Error");X return ERROR;X }X }X /* NOTREACHED */}X/*X * Wcgetsec fetches a Ward Christensen type sector.X * Returns sector number encountered or ERROR if valid sector not received,X * or CAN CAN receivedX * or WCEOT if eot sectorX * time is timeout for first char, set to 4 seconds thereafterX ***************** NO ACK IS SENT IF SECTOR IS RECEIVED OK **************X * (Caller must do that when he is good and ready to get next sector)X */X
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -