⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rzsz.sh

📁 Linux下基于Z-MODEM的串口通讯程序源码
💻 SH
📖 第 1 页 / 共 5 页
字号:
X					if ((c &= 0177) < 7)X						goto ignore;X				} else if (name)X					goto thisbin; X			}X			if (c == SUB) {X				if (linno == 1 && name)	/* ARC or ZOO file */X					goto thisbin;X				break;X			}X			if (c == '\r' && Unmac)X				c = '\n';X			*p++ = c;X			if (c == '\n')X				break;X		}X		*p = '\0';X		if (n < nlong)X			nlong = n;XX		if (n == 0 && name) {thisbin:X			if (n) {X				fprintf(stderr, "%s: %s is a binary file", Progname, name);X				fprintf(stderr, " line=%d char =%2X\n", linno, c);X			} else {X				fprintf(stderr, "line=%d char =%2X\n", linno, c);X				fprintf(stderr, "%s: %s has long line!\n", Progname, name);X				if (!Unmac)X					fprintf(stderr, "Try unmac?\n");X			}X			Munged = 1;  fclose(fin);  fclose(fout);X			unlink(outnam);  return;X		}XX		if (Todos) {X			if (*--p == '\n' && p[-1] != '\r') {X				*p++ = '\r'; *p++ = '\n'; *p = 0;X			}X		} else if (Tomac) {X			if (*--p == '\n') {X				if (p[-1] == '\r')X					--p;X				*p++ = '\r'; *p = 0;X			}X		} else {X			if (*--p == '\n' && *--p == '\r') {X				while (p>(Lbuf+1) && p[-1] == '\r')X					--p;X				if (Stripsp)X					while (p>(Lbuf+1) && isspace(p[-1]))X						--p;X				*p++ = '\n'; *p = 0;X			}X		}X		if (Lbuf[1] && fputs(Lbuf+1, fout) == EOF) {X			xperror(outnam); exit(2);X		}X		switch (c) {X		case EOF:X			if (ferror(fin)) {X				xperror(name); exit(3);X			}X		case SUB:X			if (Tocpm) {X				fpos = ftell(fout);X				do {X					putc(SUB, fout);X				} while (++fpos & 127);X			}closeit:X			if ( !name)X				return;X			fclose(fout); fclose(fin);X			if (st.st_nlink > 1) X				sprintf(Lbuf, "trap '' 1 2 3 15; cp %s %s", outnam, name);X			elseX				sprintf(Lbuf, "mv %s %s", outnam, name);X			system(Lbuf);X			times.actime = st.st_atime;X			times.modtime = st.st_mtime;X			if (utime(name, &times)) {X				xperror("Can't set file date");X			}X			if (st.st_nlink > 1) X				unlink(outnam);X			nlong = LL - nlong;X			if (nlong > 132)X				fprintf(stderr, "Longest line in %s has %d bytes.\n",X				  name ? name:"stdin", nlong);X			return;X		}X		if (Lineflush)X			fflush(fout);X	}}Xvoidxperror(s)char *s;{X	register char *p;X	extern int sys_nerr;#ifndef LINUXX	extern char *sys_errlist[];#endifX	extern errno;XX	if (errno >= sys_nerr)X		p = "Gloryovsky: a New Error!";X	elseX		p = sys_errlist[errno];X	fprintf(stderr, "%s: %s: %s\n", Progname, s, p);}XSHAR_EOF  (set 20 02 08 31 07 44 47 'undos.c'; eval "$shar_touch") &&  chmod 0644 'undos.c' ||  $echo 'restore of' 'undos.c' 'failed'  if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \  && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then    md5sum -c << SHAR_EOF >/dev/null 2>&1 \    || $echo 'undos.c:' 'MD5 check failed'879f8c3c1e31b9ff4662f719b73b4dbf  undos.cSHAR_EOF  else    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'undos.c'`"    test 7626 -eq "$shar_count" ||    $echo 'undos.c:' 'original size' '7626,' 'current size' "$shar_count!"  fifi# ============= zmr.c ==============if test -f 'zmr.c' && test "$first_param" != -c; then  $echo 'x -' SKIPPING 'zmr.c' '(file already exists)'else  $echo 'x -' extracting 'zmr.c' '(text)'  sed 's/^X//' << 'SHAR_EOF' > 'zmr.c' &&/*X * File: zmr.cX * Copyright 1988, 2002 Omen Technology Inc All Rights ReservedX *X *X * X * This module implements ZMODEM Run Length Encoding, anX * extension that was not funded by the original TelenetX * development contract.X * X *  This software may be freely used for educational (didacticX *  only) purposes.  This software may also be freely used toX *  support file transfer operations to or from licensed OmenX *  Technology products.  Use with other commercial or sharewareX *  programs (Crosstalk, Procomm, etc.) REQUIRES REGISTRATION.X *X *  Any programs which use part or all of this software must beX *  provided in source form with this notice intact except byX *  written permission from Omen Technology Incorporated.X * X * Use of this software for commercial or administrative purposesX * except when exclusively limited to interfacing Omen TechnologyX * products requires a per port license payment of $20.00 US perX * port (less in quantity).  Use of this code by inclusion,X * 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 *	ZMODEM RLE compression and decompression functionsX */X/* Send data subpacket RLE encoded with 32 bit FCS */zsdar32(buf, length, frameend)char *buf;{X	register int c, l, n;X	register unsigned long crc;XX	crc = 0xFFFFFFFFL;  l = *buf++ & 0377;X	for (n = 0; --length >= 0; ++buf) {X		if ((c = *buf & 0377) == l && n < 126 && length>0) {X			++n;  continue;X		}X		switch (n) {X		case 0:X			zsendline(l);X			crc = UPDC32(l, crc);X			if (l == ZRESC) {X				zsendline(0100); crc = UPDC32(0100, crc);X			}X			l = c; break;X		case 1:X			if (l != ZRESC) {X				zsendline(l); zsendline(l);X				crc = UPDC32(l, crc);X				crc = UPDC32(l, crc);X				n = 0; l = c; break;X			}X			/* **** FALL THRU TO **** */X		default:X			zsendline(ZRESC); crc = UPDC32(ZRESC, crc);X			if (l == 040 && n < 34) {X				n += 036;X				zsendline(n); crc = UPDC32(n, crc);X			}X			else {X				n += 0101;X				zsendline(n); crc = UPDC32(n, crc);X				zsendline(l); crc = UPDC32(l, crc);X			}X			n = 0; l = c; break;X		}X	}X	xsendline(ZDLE); xsendline(frameend);X	crc = UPDC32(frameend, crc);XX	crc = ~crc;X	for (length=4; --length >= 0;) {X		zsendline((int)crc);  crc >>= 8;X	}}XX/* Receive data subpacket RLE encoded with 32 bit FCS */zrdatr32(buf, length)register char *buf;{X	register int c;X	register unsigned long crc;X	register char *end;X	register int d;XX	crc = 0xFFFFFFFFL;  Rxcount = 0;  end = buf + length;X	d = 0;	/* Use for RLE decoder state */X	while (buf <= end) {X		if ((c = zdlread()) & ~0377) {crcfoo:X			switch (c) {X			case GOTCRCE:X			case GOTCRCG:X			case GOTCRCQ:X			case GOTCRCW:X				d = c;  c &= 0377;X				crc = UPDC32(c, crc);X				if ((c = zdlread()) & ~0377)X					goto crcfoo;X				crc = UPDC32(c, crc);X				if ((c = zdlread()) & ~0377)X					goto crcfoo;X				crc = UPDC32(c, crc);X				if ((c = zdlread()) & ~0377)X					goto crcfoo;X				crc = UPDC32(c, crc);X				if ((c = zdlread()) & ~0377)X					goto crcfoo;X				crc = UPDC32(c, crc);X				if (crc != 0xDEBB20E3) {X					zperr1(badcrc);X					return ERROR;X				}X				Rxcount = length - (end - buf);#ifndef DSZX				vfile("zrdatr32: %d %s", Rxcount,X				  Zendnames[d-GOTCRCE&3]);#endifX				return d;X			case GOTCAN:X				zperr1("Sender Canceled");X				return ZCAN;X			case TIMEOUT:X				zperr1("TIMEOUT");X				return c;X			default:X				zperr1("Bad data subpacket");X				return c;X			}X		}X		crc = UPDC32(c, crc);X		switch (d) {X		case 0:X			if (c == ZRESC) {X				d = -1;  continue;X			}X			*buf++ = c;  continue;X		case -1:X			if (c >= 040 && c < 0100) {X				d = c - 035; c = 040;  goto spaces;X			}X			if (c == 0100) {X				d = 0;X				*buf++ = ZRESC;  continue;X			}X			d = c;  continue;X		default:X			d -= 0100;X			if (d < 1)X				goto badpkt;spaces:X			if ((buf + d) > end)X				goto badpkt;X			while ( --d >= 0)X				*buf++ = c;X			d = 0;  continue;X		}X	}badpkt:X	zperr1("Data subpacket too long");X	return ERROR;}X/* End of zmr.c */SHAR_EOF  (set 20 02 07 02 08 14 21 'zmr.c'; eval "$shar_touch") &&  chmod 0644 'zmr.c' ||  $echo 'restore of' 'zmr.c' 'failed'  if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \  && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then    md5sum -c << SHAR_EOF >/dev/null 2>&1 \    || $echo 'zmr.c:' 'MD5 check failed'aa4ea8e279bc846bd2dbb7a1201c72c7  zmr.cSHAR_EOF  else    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'zmr.c'`"    test 4351 -eq "$shar_count" ||    $echo 'zmr.c:' 'original size' '4351,' 'current size' "$shar_count!"  fifi# ============= sz.c ==============if test -f 'sz.c' && test "$first_param" != -c; then  $echo 'x -' SKIPPING 'sz.c' '(file already exists)'else  $echo 'x -' extracting 'sz.c' '(text)'  sed 's/^X//' << 'SHAR_EOF' > 'sz.c' &&#define VERSION "3.73 1-30-03"#define PUBDIR "/usr/spool/uucppublic"X/*X **************************************************************************X *X * sz.c By Chuck Forsberg,  Omen Technology INCX *    Copyright 2003 Omen Technology Inc All Rights ReservedX * 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 * X * This software may be freely used for educational (didacticX * only) purposes.  "Didactic" means it is used as a study itemX * in a course teaching the workings of computer protocols.X * X * This software may also be freely used to support file transferX * operations to or from duly licensed Omen Technology products.X * This includes DSZ, GSZ, ZCOMM, Professional-YAM and PowerCom.X * Institutions desiring to use rz/sz this way should add theX * following to the sz compile line:	-DCOMPLX * Programs based on stolen or public domain ZMODEM materials areX * not included.  Use with other commercial or shareware programsX * (Crosstalk, Procomm, etc.) REQUIRES REGISTRATION.X * 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.rz" 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 user or asX * specified in the mailer.rz registration form.  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 *  USG UNIX (3.0) ioctl conventions courtesy Jeff MartinX */Xchar *Copyrsz = "Copyright 2000 Omen Technology Inc All Rights Reserved";Xchar *substr();X#define LOGFILE "/tmp/szlog"#define LOGFILE2 "szlog"#include <stdio.h>#include <signal.h>#include <ctype.h>#include <errno.h>extern int errno;#define STATICX#define PATHLEN 1000#define OK 0#define FALSE 0#ifdef TRUE#undef TRUE#endif#define TRUE 1#define ERROR (-1)/* 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 ETX 3#define EOT 4#define ACK 6#define NAK 025#define SYN 026#define CPMEOF 032#define ESC 033#define WANTCRC 0103	/* send C not NAK to get crc not checksum */#define WANTG 0107	/* Send G not NAK to get nonstop batch xmsn */#define TIMEOUT (-2)#define RCDO (-3)#define GCOUNT (-4)#define RETRYMAX 10XX#define HOWMANY 2STATIC int Zmodem=0;		/* ZMODEM protocol requested by receiver */unsigned Baudrate = 9600;		/* Default, set by first mode() call */STATIC unsigned Txwindow;	/* Control the size of the transmitted window */STATIC unsigned Txwspac;	/* Spacing between zcrcq requests */STATIC unsigned Txwcnt;	/* Counter used to space ack requests */STATIC long Lrxpos;	/* Receiver's last reported offset */STATIC int errors;char endmsg[80] = {0};	/* Possible message to display on exit */char Zsendmask[33];	/* Additional control chars to mask */X#include "rbsb.c"	/* most of the system dependent stuff here */X#include "crctab.c"XSTATIC int Totfiles, Filesleft;STATIC long Totbytes, Totalleft;X/*X * Attention string to be executed by receiver to interrupt streaming dataX *  when an error is detected.  A pause (0336) may be needed before theX *  ^C (03) or after it.X */#ifdef READCHECKSTATIC char Myattn[] = { 0 };#else#ifdef USGSTATIC char Myattn[] = { 03, 0336, 0 };#endif#endifXFILE *in;XSTATIC int Canseek = 1;	/* 1: Can seek 0: only rewind -1: neither (pipe) */X#ifndef SMALL#ifndef TXBSIZE#define TXBSIZE 32768#endifX#define TXBMASK (TXBSIZE-1)STATIC char Txb[TXBSIZE + 1024];	/* Circular buffer for

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -