[Ttssh2-commit] [3819] YMODEM: 複数ファイルの送信をサポートした。

svnno****@sourc***** svnno****@sourc*****
2010年 3月 24日 (水) 13:28:46 JST


Revision: 3819
          http://sourceforge.jp/projects/ttssh2/svn/view?view=rev&revision=3819
Author:   yutakapon
Date:     2010-03-24 13:28:46 +0900 (Wed, 24 Mar 2010)

Log Message:
-----------
YMODEM: 複数ファイルの送信をサポートした。

Modified Paths:
--------------
    trunk/teraterm/common/ttftypes.h
    trunk/teraterm/teraterm/filesys.cpp
    trunk/teraterm/ttpfile/ttfile.c
    trunk/teraterm/ttpfile/ymodem.c


-------------- next part --------------
Modified: trunk/teraterm/common/ttftypes.h
===================================================================
--- trunk/teraterm/common/ttftypes.h	2010-03-23 15:35:27 UTC (rev 3818)
+++ trunk/teraterm/common/ttftypes.h	2010-03-24 04:28:46 UTC (rev 3819)
@@ -184,7 +184,6 @@
   int TOutLong;
   int SendFileInfo;
   int SendEot;
-  int ResendEot;
   int LastSendEot;
 } TYVar;
 typedef TYVar far *PYVar;

Modified: trunk/teraterm/teraterm/filesys.cpp
===================================================================
--- trunk/teraterm/teraterm/filesys.cpp	2010-03-23 15:35:27 UTC (rev 3818)
+++ trunk/teraterm/teraterm/filesys.cpp	2010-03-24 04:28:46 UTC (rev 3819)
@@ -1026,9 +1026,9 @@
 			((PXVar)ProtoVar)->XOpt = Opt1;
 			((PXVar)ProtoVar)->TextFlag = 1 - (Opt2 & 1);
 			break;
-		case PROTO_YM:  // TBD
+		case PROTO_YM:  
 			((PYVar)ProtoVar)->YMode = Mode;
-			((PYVar)ProtoVar)->YOpt = Yopt1K;  // TBD
+			((PYVar)ProtoVar)->YOpt = Opt1;
 			break;
 		case PROTO_ZM:
 			((PZVar)ProtoVar)->BinFlag = (Opt1 & 1) != 0;
@@ -1296,7 +1296,9 @@
 
 	if (mode==IdYSend)
 	{
-		Opt = ts.XmodemBin;
+		// ƒtƒ@ƒCƒ‹“]‘—Žž‚̃IƒvƒVƒ‡ƒ“‚Í"Yopt1K"‚ÉŒˆ‚ß‘Å‚¿B
+		// TODO: "Yopt1K", "YoptG", "YoptSingle"‚ð‹æ•Ê‚µ‚½‚¢‚È‚ç‚΁AIDD_FOPT‚ðŠg’£‚·‚é•K—v‚ ‚èB
+		Opt = Yopt1K;
 		FileVar->OpId = OpYSend;
 		if (strlen(&(FileVar->FullName[FileVar->DirLen]))==0)
 		{
@@ -1306,7 +1308,7 @@
 				ProtoEnd();
 				return;
 			}
-			ts.XmodemBin = Opt;
+			//ts.XmodemBin = Opt;
 		}
 		else
 		(*SetFileVar)(FileVar);

Modified: trunk/teraterm/ttpfile/ttfile.c
===================================================================
--- trunk/teraterm/ttpfile/ttfile.c	2010-03-23 15:35:27 UTC (rev 3818)
+++ trunk/teraterm/ttpfile/ttfile.c	2010-03-24 04:28:46 UTC (rev 3819)
@@ -592,7 +592,11 @@
 		ofn.lCustData = (DWORD)Option;
 		ofn.lpfnHook = (LPOFNHOOKPROC)(&TFn2Hook);
 		ofn.lpTemplateName = MAKEINTRESOURCE(IDD_FOPT);
+	} else 	if (FuncId==GMF_Y) {
+		// TODO: YMODEM
+
 	}
+
 	ofn.hInstance = hInst;
 
 	// ƒtƒBƒ‹ƒ^‚ªƒƒCƒ‹ƒhƒJ[ƒh‚Å‚Í‚È‚­A‚»‚̃tƒ@ƒCƒ‹‚ª‘¶Ý‚·‚éê‡

Modified: trunk/teraterm/ttpfile/ymodem.c
===================================================================
--- trunk/teraterm/ttpfile/ymodem.c	2010-03-23 15:35:27 UTC (rev 3818)
+++ trunk/teraterm/ttpfile/ymodem.c	2010-03-24 04:28:46 UTC (rev 3819)
@@ -1,5 +1,5 @@
 /* Tera Term
-Copyright(C) 2008 TeraTerm Project
+Copyright(C) 2008-2010 TeraTerm Project
 All rights reserved. */
 
 /* TTFILE.DLL, YMODEM protocol */
@@ -25,6 +25,10 @@
 #define TimeOutLong  20
 #define TimeOutVeryLong 60
 
+// ƒf[ƒ^“]‘—ƒTƒCƒYBYMODEM‚Å‚Í 128 or 1024 byte ‚ðƒTƒ|[ƒg‚·‚éB
+#define SOH_DATALEN	128
+#define STX_DATALEN	1024
+
 int YRead1Byte(PFileVar fv, PYVar yv, PComVar cv, LPBYTE b)
 {
 	if (CommRead1Byte(cv,b) == 0)
@@ -174,39 +178,25 @@
 		(LOBYTE(Check)==yv->PktIn[yv->DataLen+4]));  
 }
 
-void YInit
-(PFileVar fv, PYVar yv, PComVar cv, PTTSet ts)
+static void initialize_file_info(PFileVar fv, PYVar yv)
 {
-	char inistr[MAXPATHLEN + 10];
-
 	if (yv->YMode == IdYSend) {
-		if (! GetNextFname(fv))
-		{
-			return;
+		if (fv->FileOpen) {
+			_lclose(fv->FileHandle);
 		}
-		/* file open */
 		fv->FileHandle = _lopen(fv->FullName,OF_READ);
+		fv->FileSize = GetFSize(fv->FullName);
 	} else {
 		fv->FileHandle = -1;
+		fv->FileSize = 0;
 	}
 	fv->FileOpen = fv->FileHandle>0;
 
-	fv->LogFlag = ((ts->LogFlag & LOG_Y)!=0);
-	if (fv->LogFlag)
-		fv->LogFile = _lcreat("YMODEM.LOG",0);
-	fv->LogState = 0;
-	fv->LogCount = 0;
-
-	fv->FileSize = 0;
-	if ((yv->YMode==IdYSend) && fv->FileOpen) {
-		fv->FileSize = GetFSize(fv->FullName);
+	if (yv->YMode == IdYSend) {
 		InitDlgProgress(fv->HWin, IDC_PROTOPROGRESS, &fv->ProgStat);
-	}
-	else {
+	} else {
 		fv->ProgStat = -1;
 	}
-
-	SetWindowText(fv->HWin, fv->DlgCaption);
 	SetDlgItemText(fv->HWin, IDC_PROTOFNAME, &(fv->FullName[fv->DirLen]));
 
 	yv->PktNumOffset = 0;
@@ -214,14 +204,33 @@
 	yv->PktNumSent = 0;
 	yv->PktBufCount = 0;
 	yv->CRRecv = FALSE;
-
 	fv->ByteCount = 0;
-
 	yv->SendFileInfo = 0;
 	yv->SendEot = 0;
-	yv->ResendEot = 0;
 	yv->LastSendEot = 0;
+}
 
+void YInit
+(PFileVar fv, PYVar yv, PComVar cv, PTTSet ts)
+{
+	char inistr[MAXPATHLEN + 10];
+
+	if (yv->YMode == IdYSend) {
+		if (!GetNextFname(fv)) {
+			return;
+		}
+	} 
+
+	fv->LogFlag = ((ts->LogFlag & LOG_Y)!=0);
+	if (fv->LogFlag)
+		fv->LogFile = _lcreat("YMODEM.LOG",0);
+	fv->LogState = 0;
+	fv->LogCount = 0;
+
+	SetWindowText(fv->HWin, fv->DlgCaption);
+
+	initialize_file_info(fv, yv);
+
 	if (cv->PortType==IdTCPIP)
 	{
 		yv->TOutShort = TimeOutVeryLong;
@@ -234,7 +243,7 @@
 
 	YSetOpt(fv,yv,yv->YOpt);
 
-	if (yv->YOpt==XoptCheck)  // TODO
+	if (yv->YOpt == Yopt1K)  
 	{
 		yv->NAKMode = YnakC;
 		yv->NAKCount = 10;
@@ -259,7 +268,6 @@
 	case IdYSend:
 		yv->TextFlag = 0;
 
-
 		// ƒtƒ@ƒCƒ‹‘—MŠJŽn‘O‚ɁA"rb ƒtƒ@ƒCƒ‹–¼"‚ðŽ©“®“I‚ɌĂяo‚·B(2007.12.20 yutaka)
 		//strcpy(ts->YModemRcvCommand, "rb");
 		if (ts->YModemRcvCommand[0] != '\0') {
@@ -496,42 +504,34 @@
 			firstch = b;
 			switch (b) {
 			case ACK:
-				// 1‰ñ–Ú‚ÌEOT‘—MŒã‚ÌACKŽóM‚ŁAI‚í‚è‚Æ‚·‚éB
+				// 1‰ñ–Ú‚ÌEOT‘—MŒã‚ÌACKŽóM‚ŁAu1ƒtƒ@ƒCƒ‹‘—Mv‚̏I‚í‚è‚Æ‚·‚éB
 				if (yv->SendEot) {
 					yv->SendEot = 0;
-					yv->LastSendEot = 1;
-					break;
+
+					// ‘—Mƒtƒ@ƒCƒ‹‚ªŽc‚Á‚Ä‚¢‚È‚¢ê‡‚́Au‘S‚Ẵtƒ@ƒCƒ‹‚ð“]‘—I—¹v‚ð’Ê’m‚·‚éB
+					if (!GetNextFname(fv)) {
+						yv->LastSendEot = 1;
+						break;
+					} else {
+						initialize_file_info(fv, yv);
+					}
 				}
 
-				if (! fv->FileOpen)
+				if (! fv->FileOpen) // ‚à‚¤‘—M‚·‚éƒtƒ@ƒCƒ‹‚ª‚È‚¢ê‡‚́A³íI—¹B
 				{
 					fv->Success = TRUE;
 					return FALSE;
 				}
-				else if (yv->PktNumSent==(BYTE)(yv->PktNum+1))
+				else if (yv->PktNumSent==(BYTE)(yv->PktNum+1))  // ŽŸ‚̃uƒƒbƒN‚ð‘—‚é
 				{
 					yv->PktNum = yv->PktNumSent;
 					if (yv->PktNum==0)
 						yv->PktNumOffset = yv->PktNumOffset + 256;
 					SendFlag = TRUE;
 				}
-
 				break;
 
 			case NAK:
-				if (yv->PktNum == 0 && yv->YOpt == Xopt1K)
-				{
-					/* we wanted 1k with CRC, but the other end specified checksum */
-					/* keep the 1k block, but move back to checksum mode.          */
-					yv->YOpt = XoptCheck;
-					yv->CheckLen = 1;
-				}
-
-				// 1‰ñ–Ú‚ÌEOT‘—MŒã‚ÌNAKŽóM‚ŁAÄ“xEOT‚ð‘—‚éB
-				if (yv->SendEot) {
-					yv->ResendEot = 1;
-				}
-
 				SendFlag = TRUE;
 				break;
 
@@ -555,6 +555,7 @@
 		// reset timeout timer
 		FTSetTimeOut(fv,TimeOutVeryLong);
 
+		// Œã‘±‚̃T[ƒo‚©‚ç‚̃f[ƒ^‚ð“Ç‚ÝŽÌ‚Ä‚éB
 		do {
 			lastrx = firstch;
 			i = YRead1Byte(fv,yv,cv,&b);
@@ -564,13 +565,16 @@
 					// CAN(0x18)‚ª˜A‘±‚µ‚Ä‚­‚é‚ƁAƒtƒ@ƒCƒ‹‘—M‚ÌŽ¸”s‚ÆŒ©‚È‚·B
 					// ‚½‚Æ‚¦‚΁AƒT[ƒo‚É“¯–¼‚̃tƒ@ƒCƒ‹‚ª‘¶Ý‚·‚éê‡‚ȂǁB
 					// (2010.3.23 yutaka)
+					fv->Success = FALSE;       // failure
 					return FALSE;
 				}
 			}
 		} while (i != 0);
 
 		if (yv->LastSendEot) { // ƒI[ƒ‹ƒ[ƒ‚̃uƒƒbƒN‚𑗐M‚µ‚āA‚à‚¤ƒtƒ@ƒCƒ‹‚ª‚È‚¢‚±‚Æ‚ð’m‚点‚éB
-			if (yv->DataLen==128)
+			yv->LastSendEot = 0;
+
+			if (yv->DataLen == SOH_DATALEN)
 				yv->PktOut[0] = SOH;
 			else
 				yv->PktOut[0] = STX;
@@ -594,19 +598,12 @@
 			yv->PktBufCount = 3 + yv->DataLen + yv->CheckLen;
 
 		} 
-		else if (yv->ResendEot) {  // 2‰ñ–Ú‚ÌEOT‘—M
-			yv->PktOut[0] = EOT;
-			yv->PktBufCount = 1;
-
-			yv->LastSendEot = 1;
-
-		} 
 		else if (yv->PktNumSent==yv->PktNum) /* make a new packet */
 		{
 			BYTE *dataptr = &yv->PktOut[3];
 			int eot = 0;  // End Of Transfer
 
-			if (yv->DataLen==128)
+			if (yv->DataLen == SOH_DATALEN)
 				yv->PktOut[0] = SOH;
 			else
 				yv->PktOut[0] = STX;
@@ -694,9 +691,7 @@
 				yv->PktBufCount = 1;
 
 				yv->SendEot = 1;  // EOTƒtƒ‰ƒOonBŽŸ‚ÍNAK‚ðŠú‘Ò‚·‚éB
-				yv->ResendEot = 0;
 				yv->LastSendEot = 0;
-
 			}
 
 		}
@@ -707,6 +702,7 @@
 		yv->PktBufPtr = 0;
 	}
 	/* a NAK or C could have arrived while we were buffering.  Consume it. */
+	// Œã‘±‚̃T[ƒo‚©‚ç‚̃f[ƒ^‚ð“Ç‚ÝŽÌ‚Ä‚éB
 	do {
 		lastrx = firstch;
 		i = YRead1Byte(fv,yv,cv,&b);
@@ -716,6 +712,7 @@
 				// CAN(0x18)‚ª˜A‘±‚µ‚Ä‚­‚é‚ƁAƒtƒ@ƒCƒ‹‘—M‚ÌŽ¸”s‚ÆŒ©‚È‚·B
 				// ‚½‚Æ‚¦‚΁AƒT[ƒo‚É“¯–¼‚̃tƒ@ƒCƒ‹‚ª‘¶Ý‚·‚éê‡‚ȂǁB
 				// (2010.3.23 yutaka)
+				fv->Success = FALSE;       // failure
 				return FALSE;
 			}
 		}



Ttssh2-commit メーリングリストの案内