Update first part of zmodem sources

This commit is contained in:
Michiel Broek 2004-11-07 13:35:34 +00:00
parent cb2d964597
commit 706d0fcfe7
3 changed files with 208 additions and 230 deletions

View File

@ -62,6 +62,7 @@ static int zgethex(void);
static int zgeth1(void); static int zgeth1(void);
static void garbitch(void); static void garbitch(void);
#include "../config.h" #include "../config.h"
#include "../lib/mbselib.h" #include "../lib/mbselib.h"
#include "../lib/nodelist.h" #include "../lib/nodelist.h"
@ -196,17 +197,15 @@ void zsbhdr(int len, int type, register char *shdr)
BUFFER_BYTE(ZPAD); BUFFER_BYTE(ZDLE); BUFFER_BYTE(ZPAD); BUFFER_BYTE(ZDLE);
switch (Crc32t=Txfcs32) { switch (Crc32t=Txfcs32) {
case 2: case 2: zsbh32(len, shdr, type, Usevhdrs?ZVBINR32:ZBINR32);
zsbh32(len, shdr, type, Usevhdrs?ZVBINR32:ZBINR32); BUFFER_FLUSH();
BUFFER_FLUSH(); break; break;
case 1: case 1: zsbh32(len, shdr, type, Usevhdrs?ZVBIN32:ZBIN32);
zsbh32(len, shdr, type, Usevhdrs?ZVBIN32:ZBIN32); break; break;
default: default: if (Usevhdrs) {
if (Usevhdrs) {
BUFFER_BYTE(ZVBIN); BUFFER_BYTE(ZVBIN);
zsendline(len); zsendline(len);
} } else
else
BUFFER_BYTE(ZBIN); BUFFER_BYTE(ZBIN);
zsendline(type); zsendline(type);
crc = updcrc16(type, 0); crc = updcrc16(type, 0);
@ -270,8 +269,7 @@ void zshhdr(int len, int type, register char *shdr)
if (Usevhdrs) { if (Usevhdrs) {
BUFFER_BYTE(ZVHEX); BUFFER_BYTE(ZVHEX);
zputhex(len); zputhex(len);
} } else
else
BUFFER_BYTE(ZHEX); BUFFER_BYTE(ZHEX);
zputhex(type); zputhex(type);
Crc32t = 0; Crc32t = 0;
@ -313,16 +311,16 @@ void zsdata(register char *buf, int length, int frameend)
BUFFER_CLEAR(); BUFFER_CLEAR();
switch (Crc32t) { switch (Crc32t) {
case 1: case 1: zsda32(buf, length, frameend);
zsda32(buf, length, frameend); break; break;
case 2: case 2: zsdar32(buf, length, frameend);
zsdar32(buf, length, frameend); break; break;
default: default: crc = 0;
crc = 0;
for (;--length >= 0; ++buf) { for (;--length >= 0; ++buf) {
zsendline(*buf); crc = updcrc16((0377 & *buf), crc); zsendline(*buf); crc = updcrc16((0377 & *buf), crc);
} }
BUFFER_BYTE(ZDLE); BUFFER_BYTE(frameend); BUFFER_BYTE(ZDLE);
BUFFER_BYTE(frameend);
crc = updcrc16(frameend, crc); crc = updcrc16(frameend, crc);
crc = updcrc16(0,updcrc16(0,crc)); crc = updcrc16(0,updcrc16(0,crc));

View File

@ -6,23 +6,14 @@
void get_frame_buffer(void); void get_frame_buffer(void);
void free_frame_buffer(void); void free_frame_buffer(void);
void zsbhdr(int, int, register char *); void zsbhdr(int, int, register char *);
void zsbh32(int, register char *, int, int);
void zshhdr(int, int, register char *); void zshhdr(int, int, register char *);
void zsdata(register char *, int, int); void zsdata(register char *, int, int);
void zsda32(register char *, int, int);
int zrdata(register char *, int); int zrdata(register char *, int);
int zrdat32(register char *, int); int zrdat32(register char *, int);
void garbitch(void);
int zgethdr(char *); int zgethdr(char *);
int zrbhdr(register char *); int zrbhdr(register char *);
int zrbhd32(register char *);
int zrhhdr(char *);
void zputhex(register int);
void zsendline(int); void zsendline(int);
int zgethex(void);
int zgeth1(void);
int zdlread(void); int zdlread(void);
int noxrd7(void);
void stohdr(long); void stohdr(long);
long rclhdr(register char *); long rclhdr(register char *);

View File

@ -66,28 +66,24 @@ void zsdar32(char *buf, int length, int frameend)
++n; continue; ++n; continue;
} }
switch (n) { switch (n) {
case 0: case 0: zsendline(l);
zsendline(l);
crc = updcrc32(l, crc); crc = updcrc32(l, crc);
if (l == ZRESC) { if (l == ZRESC) {
zsendline(0100); crc = updcrc32(0100, crc); zsendline(0100); crc = updcrc32(0100, crc);
} }
l = c; break; l = c; break;
case 1: case 1: if (l != ZRESC) {
if (l != ZRESC) {
zsendline(l); zsendline(l); zsendline(l); zsendline(l);
crc = updcrc32(l, crc); crc = updcrc32(l, crc);
crc = updcrc32(l, crc); crc = updcrc32(l, crc);
n = 0; l = c; break; n = 0; l = c; break;
} }
/* **** FALL THRU TO **** */ /* **** FALL THRU TO **** */
default: default: zsendline(ZRESC); crc = updcrc32(ZRESC, crc);
zsendline(ZRESC); crc = updcrc32(ZRESC, crc);
if (l == 040 && n < 34) { if (l == 040 && n < 34) {
n += 036; n += 036;
zsendline(n); crc = updcrc32(n, crc); zsendline(n); crc = updcrc32(n, crc);
} } else {
else {
n += 0101; n += 0101;
zsendline(n); crc = updcrc32(n, crc); zsendline(n); crc = updcrc32(n, crc);
zsendline(l); crc = updcrc32(l, crc); zsendline(l); crc = updcrc32(l, crc);
@ -125,8 +121,7 @@ crcfoo:
case GOTCRCE: case GOTCRCE:
case GOTCRCG: case GOTCRCG:
case GOTCRCQ: case GOTCRCQ:
case GOTCRCW: case GOTCRCW: d = c; c &= 0377;
d = c; c &= 0377;
crc = updcrc32(c, crc); crc = updcrc32(c, crc);
if ((c = zdlread()) & ~0377) if ((c = zdlread()) & ~0377)
goto crcfoo; goto crcfoo;
@ -146,30 +141,24 @@ crcfoo:
} }
Rxcount = length - (end - buf); Rxcount = length - (end - buf);
Syslog('z', "zrdatr32: %d %s", Rxcount, Syslog('z', "zrdatr32: %d %s", Rxcount, Zendnames[(d-GOTCRCE)&3]);
Zendnames[(d-GOTCRCE)&3]);
return d; return d;
case GOTCAN: case GOTCAN: Syslog('+', "Zmodem: Sender Canceled");
Syslog('+', "Zmodem: Sender Canceled");
return ZCAN; return ZCAN;
case TIMEOUT: case TIMEOUT: Syslog('+', "Zmodem: TIMEOUT");
Syslog('+', "Zmodem: TIMEOUT");
return c; return c;
default: default: Syslog('+', "Zmodem: Bad data subpacket");
Syslog('+', "Zmodem: Bad data subpacket");
return c; return c;
} }
} }
crc = updcrc32(c, crc); crc = updcrc32(c, crc);
switch (d) { switch (d) {
case 0: case 0: if (c == ZRESC) {
if (c == ZRESC) {
d = -1; continue; d = -1; continue;
} }
*buf++ = c; continue; *buf++ = c; continue;
case -1: case -1: if (c >= 040 && c < 0100) {
if (c >= 040 && c < 0100) {
d = c - 035; c = 040; goto spaces; d = c - 035; c = 040; goto spaces;
} }
if (c == 0100) { if (c == 0100) {
@ -177,8 +166,7 @@ crcfoo:
*buf++ = ZRESC; continue; *buf++ = ZRESC; continue;
} }
d = c; continue; d = c; continue;
default: default: d -= 0100;
d -= 0100;
if (d < 1) if (d < 1)
goto badpkt; goto badpkt;
spaces: spaces:
@ -189,6 +177,7 @@ spaces:
d = 0; continue; d = 0; continue;
} }
} }
badpkt: badpkt:
Syslog('+', "Zmodem: Data subpacket too long"); Syslog('+', "Zmodem: Data subpacket too long");
return TERROR; return TERROR;