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

📄 rzsz.sh

📁 Linux下基于Z-MODEM的串口通讯程序源码
💻 SH
📖 第 1 页 / 共 5 页
字号:
X			return c;X		crc = UPDC32(c, crc);#ifdef DEBUGZX		vfile("zrbhd32 c=%X  crc=%lX", c, crc);#endifX	}X	if (crc != 0xDEBB20E3) {X		zperr1(badcrc);X		return ERROR;X	}#ifdef ZMODEMX	Protocol = ZMODEM;#endifX	Zmodem = 1;X	return Rxtype;}XX/* Receive a hex style header (type and position) */zrhhdr(hdr)char *hdr;{X	register int c;X	register unsigned short crc;X	register int n;XX	if ((c = zgethex()) < 0)X		return c;X	Rxtype = c;X	crc = updcrc(c, 0);XX	for (n=Rxhlen; --n >= 0; ++hdr) {X		if ((c = zgethex()) < 0)X			return c;X		crc = updcrc(c, crc);X		*hdr = c;X	}X	if ((c = zgethex()) < 0)X		return c;X	crc = updcrc(c, crc);X	if ((c = zgethex()) < 0)X		return c;X	crc = updcrc(c, crc);X	if (crc & 0xFFFF) {X		zperr1(badcrc); return ERROR;X	}X	c = readline(Rxtimeout);X	if (c < 0)X		return c;X	c = readline(Rxtimeout);#ifdef ZMODEMX	Protocol = ZMODEM;#endifX	Zmodem = 1;X	if (c < 0)X		return c;X	return Rxtype;}X/* Send a byte as two hex digits */zputhex(c)register int c;{X	static char	digits[]	= "0123456789abcdef";X#ifdef DEBUGZX	if (Verbose>8)X		vfile("zputhex: %02X", c);#endifX	sendline(digits[(c&0xF0)>>4]);X	sendline(digits[(c)&0xF]);}X/*X * Send character c with ZMODEM escape sequence encoding.X */zsendline(c)register c;{X	switch (c &= 0377) {X	case 0377:X		lastsent = c;X		if (Zctlesc || Zsendmask[32]) {X			xsendline(ZDLE);  c = ZRUB1;X		}X		xsendline(c);X		break;X	case ZDLE:X		xsendline(ZDLE);  xsendline (lastsent = (c ^= 0100));X		break;X	case 021: case 023:X	case 0221: case 0223:X		xsendline(ZDLE);  c ^= 0100;  xsendline(lastsent = c);X		break;X	default:X		if (((c & 0140) == 0) && (Zctlesc || Zsendmask[c & 037])) {X			xsendline(ZDLE);  c ^= 0100;X		}X		xsendline(lastsent = c);X	}}X/* Decode two lower case hex digits into an 8 bit byte value */zgethex(){X	register int c;XX	c = zgeth1();#ifdef DEBUGZX	if (Verbose>8)X		vfile("zgethex: %02X", c);#endifX	return c;}zgeth1(){X	register int c, n;XX	if ((c = noxrd7()) < 0)X		return c;X	n = c - '0';X	if (n > 9)X		n -= ('a' - ':');X	if (n & ~0xF)X		return ERROR;X	if ((c = noxrd7()) < 0)X		return c;X	c -= '0';X	if (c > 9)X		c -= ('a' - ':');X	if (c & ~0xF)X		return ERROR;X	c += (n<<4);X	return c;}X/*X * Read a byte, checking for ZMODEM escape encodingX *  including CAN*5 which represents a quick abortX */zdlread(){X	register int c;Xagain:X	/* Quick check for non control characters */X	if ((c = readline(Rxtimeout)) & 0140)X		return c;X	switch (c) {X	case ZDLE:X		break;X	case 023:X	case 0223:X	case 021:X	case 0221:X		goto again;X	default:X		if (Zctlesc && !(c & 0140)) {X			goto again;X		}X		return c;X	}again2:X	if ((c = readline(Rxtimeout)) < 0)X		return c;X	if (c == CAN && (c = readline(Rxtimeout)) < 0)X		return c;X	if (c == CAN && (c = readline(Rxtimeout)) < 0)X		return c;X	if (c == CAN && (c = readline(Rxtimeout)) < 0)X		return c;X	switch (c) {X	case CAN:X		return GOTCAN;X	case ZCRCE:X	case ZCRCG:X	case ZCRCQ:X	case ZCRCW:X		return (c | GOTOR);X	case ZRUB0:X		return 0177;X	case ZRUB1:X		return 0377;X	case 023:X	case 0223:X	case 021:X	case 0221:X		goto again2;X	default:X		if (Zctlesc && ! (c & 0140)) {X			goto again2;X		}X		if ((c & 0140) ==  0100)X			return (c ^ 0100);X		break;X	}X	if (Verbose>1)X		zperr2("Bad escape sequence %x", c);X	return ERROR;}X/*X * Read a character from the modem line with timeout.X *  Eat parity, XON and XOFF characters.X */noxrd7(){X	register int c;XX	for (;;) {X		if ((c = readline(Rxtimeout)) < 0)X			return c;X		switch (c &= 0177) {X		case XON:X		case XOFF:X			continue;X		default:X			if (Zctlesc && !(c & 0140))X				continue;X		case '\r':X		case '\n':X		case ZDLE:X			return c;X		}X	}X	/* NOTREACHED */}X/* Store long integer pos in Txhdr */stohdr(pos)long pos;{X	Txhdr[ZP0] = pos;X	Txhdr[ZP1] = pos>>8;X	Txhdr[ZP2] = pos>>16;X	Txhdr[ZP3] = pos>>24;}X/* Recover a long integer from a header */longrclhdr(hdr)register char *hdr;{X	register long l;XX	l = (hdr[ZP3] & 0377);X	l = (l << 8) | (hdr[ZP2] & 0377);X	l = (l << 8) | (hdr[ZP1] & 0377);X	l = (l << 8) | (hdr[ZP0] & 0377);X	return l;}X/* End of zm.c */SHAR_EOF  (set 20 02 12 08 16 17 08 'zm.c'; eval "$shar_touch") &&  chmod 0644 'zm.c' ||  $echo 'restore of' 'zm.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 'zm.c:' 'MD5 check failed'4562186cb2236c6c7cd5d89f93942d3e  zm.cSHAR_EOF  else    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'zm.c'`"    test 17715 -eq "$shar_count" ||    $echo 'zm.c:' 'original size' '17715,' 'current size' "$shar_count!"  fifi# ============= undos.c ==============if test -f 'undos.c' && test "$first_param" != -c; then  $echo 'x -' SKIPPING 'undos.c' '(file already exists)'else  $echo 'x -' extracting 'undos.c' '(text)'  sed 's/^X//' << 'SHAR_EOF' > 'undos.c' &&/*% cc -xenix -M0 -compat -Osa -K -i % -o undosX *X * Undos - change DOS format files to Unix, etc.X */char ID[] =X  "Undos Rev 06-24-99 Copyright Omen Technology Inc All Rights Reserved\n";X/*X **************************************************************************X *X * undos.c By Chuck Forsberg,  Omen Technology INCX *    Copyright 1999 Omen Technology Inc All Rights ReservedX * X *********************************************************************X *********************************************************************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 * 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 userX * (less in quantity, see mailer.rz).  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 */XXX#include <stdio.h>#include <unistd.h>#include <stdlib.h>#include <ctype.h>#include <string.h>#include <sys/types.h>#include <sys/stat.h>#include <utime.h>X#define LL 10240#define SUB 032XX#if 0struct    utimbuf	   {X	time_t	   actime;	/* access time */X	time_t	   modtime;	/* modification time	*/};#endifXvoid usage(), xperror(), chngfmt();Xchar Lbuf[LL+2];char *Progname;int Todos = 0;int Tocpm = 0;int Tomac = 0;int Unmac = 0;int Strip = 0;int Stripsp = 0;int Graphics = 0;int Unparity = 0;int Munged = 0;int Lineflush = 0;	/* Flush output at end of each line */Xmain(argc, argv)char **argv;{X	Progname = *argv;X	if (! strcmp(Progname, "tocpm"))X		Todos = Tocpm = 1;X	if (! strcmp(Progname, "todos"))X		Todos = 1;X	if (! strcmp(Progname, "unmac"))X		Unmac = 1;X	if (! strcmp(Progname, "tomac"))X		Tomac = 1;X	if (! strcmp(Progname, "unparity"))X		Unparity = 1;XX	if (argc > 1) {X		if (! strcmp(argv[1], "-p")) {X			++Strip;  ++Stripsp; --argc; ++argv;X		}X		else if (! strcmp(argv[1], "-s")) {X			++Strip; --argc; ++argv;X		}X		else if (! strcmp(argv[1], "-g")) {X			Strip = 0;  ++Graphics; --argc; ++argv;X		}X	}XX	if (argc == 1)X		chngfmt(NULL);X	else if (argc<2 || *argv[1]== '-')X		usage();XX	while (--argc >= 1)X		chngfmt(*++argv);#ifndef REGISTEREDX	/* Removing or disabling this code without registering is theft */X	fprintf(stderr, "\n\n\n**** UNREGISTERED COPY *****\r\n");X	fprintf(stderr, "\n\n\nPlease read the License Agreement in sz.doc\n");X	sleep(10);#endifX	exit(Munged);}Xvoidusage(){X	fprintf(stderr, ID);X	fprintf(stderr, "\nUsage: {undos|tounix|todos|tocpm|unmac|tomac} [-p | -s | -g] [file ...]\n");X	fprintf(stderr, "	-p Strip trailing spaces, parity bit, ignore bytes < 007\n");X	fprintf(stderr, "	-s Strip parity bit, ignore bytes < 007\n");X	fprintf(stderr, "	-g Allow Graphics (line drawing) characters\n");X	fprintf(stderr, "-or-	unparity [file ...]\n");X	exit(1);}Xvoidchngfmt(name)char *name;{X	register c;X	register char *p;X	register n;X	register FILE *fin;X	FILE *fout;X	int linno = 0;X	long fpos;X	struct stat st, ost;X	struct utimbuf times;X	char outnam[64];X	int nlong = LL;XX	if (name) {X		if (stat(name, &st)) {X			xperror(name); return;X		}X		if ((st.st_mode & S_IFMT) != S_IFREG) {X			fprintf(stderr, "%s: %s is not a regular file\n", Progname, name);X			return;X		}X		if ((fin = fopen(name, "r")) == NULL) {X			xperror(name); return;X		}X		strcpy(outnam, "undosXXXXXX");X		mktemp(outnam);X		if ((fout = fopen(outnam, "w")) == NULL) {X			xperror(outnam); exit(2);X		}X	} else {X		fin = stdin; fout = stdout;X	}X	if (fstat(fileno(fout), &ost)) {X		xperror("Can't fstat output!"); return;X	}X	if ((ost.st_mode & S_IFMT) != S_IFREG) {X		Lineflush = 1;X	}XX	if (Unparity) {X		while ((c = getc(fin)) != EOF)X			if (putc((c & 0177), fout) == EOF) {X				xperror(outnam); exit(2);X			}X		goto closeit;X	}X	for (;;) {X		++linno;X		Lbuf[0] = 0;X		for (p=Lbuf+1, n=LL; --n>0; ) {ignore:X			if ((c = getc(fin)) == EOF)X				break;X			if ( !c)X				goto ignore;X			if (c & 0200 && !Graphics) {X				if (Strip) {X					if ((c &= 0177) < 7)X						goto ignore;X				} else if (name)X					goto thisbin; X			}X			if (c < '\7') {X				if (Strip) {

⌨️ 快捷键说明

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