Revision: 8976 https://osdn.net/projects/ttssh2/scm/svn/commits/8976 Author: zmatsuo Date: 2020-11-02 00:29:51 +0900 (Mon, 02 Nov 2020) Log Message: ----------- ymodem.c のみで使用する構造体を移動 - ttftypes.h から ymodem.c へ移動 Modified Paths: -------------- branches/proto_unicode/teraterm/common/ttftypes.h branches/proto_unicode/teraterm/teraterm/filesys_proto.cpp branches/proto_unicode/teraterm/ttpfile/ttfile_proto.cpp branches/proto_unicode/teraterm/ttpfile/ymodem.c branches/proto_unicode/teraterm/ttpfile/ymodem.h -------------- next part -------------- Modified: branches/proto_unicode/teraterm/common/ttftypes.h =================================================================== --- branches/proto_unicode/teraterm/common/ttftypes.h 2020-11-01 15:29:37 UTC (rev 8975) +++ branches/proto_unicode/teraterm/common/ttftypes.h 2020-11-01 15:29:51 UTC (rev 8976) @@ -176,6 +176,7 @@ #define XnakC 2 #endif +#if 0 /* YMODEM */ typedef struct { BYTE PktIn[1030], PktOut[1030]; @@ -213,6 +214,7 @@ #define YnakC 1 #define YnakG 2 +#endif /* ZMODEM */ typedef struct { Modified: branches/proto_unicode/teraterm/teraterm/filesys_proto.cpp =================================================================== --- branches/proto_unicode/teraterm/teraterm/filesys_proto.cpp 2020-11-01 15:29:37 UTC (rev 8975) +++ branches/proto_unicode/teraterm/teraterm/filesys_proto.cpp 2020-11-01 15:29:51 UTC (rev 8976) @@ -63,8 +63,9 @@ #define PFileVar PFileVarProto #endif #include "tt_res.h" +#include "kermit.h" #include "xmodem.h" -#include "kermit.h" +#include "ymodem.h" #if 0 #define FS_BRACKET_NONE 0 @@ -756,7 +757,9 @@ vsize = 0; break; case PROTO_YM: - vsize = sizeof(TYVar); +// vsize = sizeof(TYVar); + YCreate(fv); + vsize = 0; break; case PROTO_ZM: vsize = sizeof(TZVar); @@ -799,8 +802,12 @@ _ProtoSetOpt(fv, XMODEM_TEXT_FLAG, 1 - (Opt2 & 1)); break; case PROTO_YM: +#if 0 ((PYVar)ProtoVar)->YMode = Mode; ((PYVar)ProtoVar)->YOpt = Opt1; +#endif + _ProtoSetOpt(fv, YMODEM_MODE, Mode); + _ProtoSetOpt(fv, YMODEM_OPT, Opt1); break; case PROTO_ZM: ((PZVar)ProtoVar)->BinFlag = (Opt1 & 1) != 0; Modified: branches/proto_unicode/teraterm/ttpfile/ttfile_proto.cpp =================================================================== --- branches/proto_unicode/teraterm/ttpfile/ttfile_proto.cpp 2020-11-01 15:29:37 UTC (rev 8975) +++ branches/proto_unicode/teraterm/ttpfile/ttfile_proto.cpp 2020-11-01 15:29:51 UTC (rev 8976) @@ -63,7 +63,7 @@ fv->Init(fv,cv,ts); break; case PROTO_YM: - YInit(fv,(PYVar)pv,cv,ts); + fv->Init(fv,cv,ts); break; case PROTO_ZM: ZInit(fv,(PZVar)pv,cv,ts); @@ -90,14 +90,7 @@ Ok = fv->Parse(fv, cv); break; case PROTO_YM: - switch (((PYVar)pv)->YMode) { - case IdYReceive: - Ok = YReadPacket(fv,(PYVar)pv,cv); - break; - case IdYSend: - Ok = YSendPacket(fv,(PYVar)pv,cv); - break; - } + Ok = fv->Parse(fv, cv); break; case PROTO_ZM: Ok = ZParse(fv,(PZVar)pv,cv); @@ -129,7 +122,7 @@ fv->TimeOutProc(fv,cv); break; case PROTO_YM: - YTimeOutProc(fv,(PYVar)pv,cv); + fv->TimeOutProc(fv,cv); break; case PROTO_ZM: ZTimeOutProc(fv,(PZVar)pv,cv); @@ -153,7 +146,7 @@ fv->Cancel(fv,cv); break; case PROTO_YM: - YCancel(fv, (PYVar)pv,cv); + fv->Cancel(fv,cv); break; case PROTO_ZM: ZCancel((PZVar)pv); Modified: branches/proto_unicode/teraterm/ttpfile/ymodem.c =================================================================== --- branches/proto_unicode/teraterm/ttpfile/ymodem.c 2020-11-01 15:29:37 UTC (rev 8975) +++ branches/proto_unicode/teraterm/ttpfile/ymodem.c 2020-11-01 15:29:51 UTC (rev 8976) @@ -46,6 +46,43 @@ #include "ymodem.h" +/* YMODEM */ +typedef struct { + BYTE PktIn[1030], PktOut[1030]; + int PktBufCount, PktBufPtr; + BYTE PktNum, PktNumSent; + int PktNumOffset; + int PktReadMode; + WORD YMode, YOpt, TextFlag; + WORD NAKMode; + int NAKCount; + WORD __DataLen, CheckLen; + BOOL CRRecv; + int TOutShort; + int TOutLong; + int TOutInit; + int TOutInitCRC; + int TOutVLong; + int SendFileInfo; + int SendEot; + int LastSendEot; + WORD DataLen; + BYTE LastMessage; + BOOL RecvFilesize; +} TYVar; +typedef TYVar *PYVar; + + /* YMODEM states */ +#define YpktSOH 0x01 +#define YpktSTX 0x02 +#define YpktEOT 0x04 +#define YpktACK 0x06 +#define YpktNAK 0x15 +#define YpktCAN 0x18 + +#define YnakC 1 +#define YnakG 2 + // \x83f\x81[\x83^\x93]\x91\x97\x83T\x83C\x83Y\x81BYMODEM\x82ł\xCD 128 or 1024 byte \x82\xF0\x83T\x83|\x81[\x83g\x82\xB7\x82\xE9\x81B #define SOH_DATALEN 128 #define STX_DATALEN 1024 @@ -156,7 +193,7 @@ yv->NAKCount = 9; } else { - YCancel(fv,yv,cv); + YCancel(fv,cv); return; } } @@ -197,7 +234,7 @@ yv->NAKCount = 9; } else { - YCancel(fv,yv,cv); + YCancel(fv,cv); return; } } @@ -297,9 +334,10 @@ yv->LastMessage = 0; } -void YInit(PFileVarProto fv, PYVar yv, PComVar cv, PTTSet ts) +void YInit(PFileVarProto fv, PComVar cv, PTTSet ts) { char inistr[MAX_PATH + 10]; + PYVar yv = fv->data; if (yv->YMode == IdYSend) { if (!GetNextFname(fv)) { @@ -384,17 +422,19 @@ } } -void YCancel(PFileVarProto fv, PYVar yv, PComVar cv) +void YCancel(PFileVarProto fv, PComVar cv) { // five cancels & five backspaces per spec BYTE cancel[] = { CAN, CAN, CAN, CAN, CAN, BS, BS, BS, BS, BS }; + PYVar yv = fv->data; YWrite(fv,yv,cv, (PCHAR)&cancel, sizeof(cancel)); yv->YMode = 0; // quit } -void YTimeOutProc(PFileVarProto fv, PYVar yv, PComVar cv) +void YTimeOutProc(PFileVarProto fv, PComVar cv) { + PYVar yv = fv->data; switch (yv->YMode) { case IdYSend: yv->YMode = 0; // quit @@ -553,7 +593,7 @@ d = yv->PktIn[1] - yv->PktNum; if (d>1) { - YCancel(fv,yv,cv); + YCancel(fv,cv); return FALSE; } @@ -1046,3 +1086,55 @@ return TRUE; } + +BOOL YParse(PFileVarProto fv, PComVar cv) +{ + PYVar pv = fv->data; + switch (pv->YMode) { + case IdYReceive: + return YReadPacket(fv,pv,cv); + break; + case IdYSend: + return YSendPacket(fv,pv,cv); + break; + default: + return FALSE; + } +} + +static int SetOptV(PFileVarProto fv, int request, va_list ap) +{ + PYVar pv = fv->data; + switch(request) { + case YMODEM_MODE: { + int Mode = va_arg(ap, int); + pv->YMode = Mode; + return 0; + } + case YMODEM_OPT: { + WORD Opt1 = va_arg(ap, WORD); + pv->YOpt = Opt1; + return 0; + } + } + return -1; +} + +BOOL YCreate(PFileVarProto fv) +{ + PYVar pv; + pv = malloc(sizeof(TYVar)); + if (pv == NULL) { + return FALSE; + } + memset(pv, 0, sizeof(*pv)); + fv->data = pv; + + fv->Init = YInit; + fv->Parse = YParse; + fv->TimeOutProc = YTimeOutProc; + fv->Cancel = YCancel; + fv->SetOptV = SetOptV; + + return TRUE; +} Modified: branches/proto_unicode/teraterm/ttpfile/ymodem.h =================================================================== --- branches/proto_unicode/teraterm/ttpfile/ymodem.h 2020-11-01 15:29:37 UTC (rev 8975) +++ branches/proto_unicode/teraterm/ttpfile/ymodem.h 2020-11-01 15:29:51 UTC (rev 8976) @@ -34,12 +34,18 @@ extern "C" { #endif +enum { + YMODEM_MODE, + YMODEM_OPT, +}; + /* prototypes */ -void YInit(PFileVarProto fv, PYVar yv, PComVar cv, PTTSet ts); -void YCancel(PFileVarProto fv, PYVar yv, PComVar cv); -void YTimeOutProc(PFileVarProto fv, PYVar yv, PComVar cv); -BOOL YReadPacket(PFileVarProto fv, PYVar yv, PComVar cv); -BOOL YSendPacket(PFileVarProto fv, PYVar yv, PComVar cv); +BOOL YCreate(PFileVarProto fv); +#if 1 +void YInit(PFileVarProto fv, PComVar cv, PTTSet ts); +void YCancel(PFileVarProto fv, PComVar cv); +void YTimeOutProc(PFileVarProto fv, PComVar cv); +#endif #ifdef __cplusplus }