[Ttssh2-commit] [5731] インデント等調整

svnno****@sourc***** svnno****@sourc*****
2014年 12月 2日 (火) 15:52:42 JST


Revision: 5731
          http://sourceforge.jp/projects/ttssh2/scm/svn/commits/5731
Author:   maya
Date:     2014-12-02 15:52:42 +0900 (Tue, 02 Dec 2014)
Log Message:
-----------
インデント等調整
  https://sourceforge.jp/ticket/browse.php?group_id=1412&tid=34623 から、コード的に変更のない部分だけ抽出

Modified Paths:
--------------
    trunk/teraterm/ttpfile/ymodem.c

-------------- next part --------------
Modified: trunk/teraterm/ttpfile/ymodem.c
===================================================================
--- trunk/teraterm/ttpfile/ymodem.c	2014-12-02 06:50:45 UTC (rev 5730)
+++ trunk/teraterm/ttpfile/ymodem.c	2014-12-02 06:52:42 UTC (rev 5731)
@@ -192,18 +192,21 @@
 	int i;
 	WORD Check;
 
-	if (yv->CheckLen==1) /* CheckSum */
+	// CheckSum.
+	if (1 == yv->CheckLen)
 	{
-		/* Calc sum */
+		// Calc sum.
 		Check = 0;
 		for (i = 0 ; i <= yv->DataLen-1 ; i++)
-			Check = Check + (BYTE)(PktBuf[3+i]);
+			Check = Check + (BYTE)(PktBuf[3 + i]);
 		return (Check & 0xff);
 	}
-	else { /* CRC */
+	else
+	{
+		// CRC.
 		Check = 0;
 		for (i = 0 ; i <= yv->DataLen-1 ; i++)
-			Check = UpdateCRC(PktBuf[3+i],Check);
+			Check = UpdateCRC(PktBuf[3 + i],Check);
 		return (Check);
 	}
 }
@@ -212,12 +215,13 @@
 {
 	WORD Check;
 
-	Check = YCalcCheck(yv,yv->PktIn);
-	if (yv->CheckLen==1) /* Checksum */
-		return ((BYTE)Check==yv->PktIn[yv->DataLen+3]);
+	Check = YCalcCheck(yv, yv->PktIn);
+	// Checksum.
+	if (1 == yv->CheckLen)
+		return ((BYTE)Check == yv->PktIn[yv->DataLen + 3]);
 	else
-		return ((HIBYTE(Check)==yv->PktIn[yv->DataLen+3]) &&
-		(LOBYTE(Check)==yv->PktIn[yv->DataLen+4]));  
+		return ((HIBYTE(Check) == yv->PktIn[yv->DataLen + 3]) &&
+		        (LOBYTE(Check) == yv->PktIn[yv->DataLen + 4]));  
 }
 
 static void initialize_file_info(PFileVar fv, PYVar yv)
@@ -306,9 +310,8 @@
 		time_t tm = time(NULL);
 
 		_snprintf_s(buf, sizeof(buf), _TRUNCATE, "YMODEM %s start: %s\n", 
-			yv->YMode == IdYSend ? "Send" : "Recv",
-			ctime(&tm) 
-			);
+		            yv->YMode == IdYSend ? "Send" : "Recv",
+		            ctime(&tm));
 		_lwrite(fv->LogFile, buf, strlen(buf));
 	}
 
@@ -320,7 +323,7 @@
 		//strcpy(ts->YModemRcvCommand, "rb");
 		if (ts->YModemRcvCommand[0] != '\0') {
 			_snprintf_s(inistr, sizeof(inistr), _TRUNCATE, "%s\015", 
-				ts->YModemRcvCommand);
+			            ts->YModemRcvCommand);
 			YWrite(fv,yv,cv, inistr , strlen(inistr));
 		}
 
@@ -387,97 +390,97 @@
 	while ((c>0) && (! GetPkt))
 	{
 		switch (yv->PktReadMode) {
-		  case XpktSOH:
-			  // SOH \x82\xA9 STX \x82\xA9\x82Ńu\x83\x8D\x83b\x83N\x92\xB7\x82\xAA\x8C\x88\x82܂\xE9\x81B
-			  if (b==SOH)
-			  {
-				  yv->PktIn[0] = b;
-				  yv->PktReadMode = XpktBLK;
-				  yv->DataLen = SOH_DATALEN;
-				  FTSetTimeOut(fv,yv->TOutShort);
-			  }
-			  else if (b==STX)
-			  {
-				  yv->PktIn[0] = b;
-				  yv->PktReadMode = XpktBLK;
-				  yv->DataLen = STX_DATALEN;
-				  FTSetTimeOut(fv,yv->TOutShort);
-			  }
-			  else if (b==EOT)
-			  {
-				  // EOT\x82\xAA\x97\x88\x82\xBD\x82\xE7\x81A1\x82‚̃t\x83@\x83C\x83\x8B\x8E\xF3\x90M\x82\xAA\x8A\xAE\x97\xB9\x82\xB5\x82\xBD\x82\xB1\x82Ƃ\xF0\x8E\xA6\x82\xB7\x81B
-				  if (fv->FileOpen) {
-					  fv->FileOpen = 0;
-					  _lclose(fv->FileHandle);
-					  fv->FileHandle = -1;
+		case XpktSOH:
+			// SOH \x82\xA9 STX \x82\xA9\x82Ńu\x83\x8D\x83b\x83N\x92\xB7\x82\xAA\x8C\x88\x82܂\xE9\x81B
+			if (b==SOH)
+			{
+				yv->PktIn[0] = b;
+				yv->PktReadMode = XpktBLK;
+				yv->DataLen = SOH_DATALEN;
+				FTSetTimeOut(fv,yv->TOutShort);
+			}
+			else if (b==STX)
+			{
+				yv->PktIn[0] = b;
+				yv->PktReadMode = XpktBLK;
+				yv->DataLen = STX_DATALEN;
+				FTSetTimeOut(fv,yv->TOutShort);
+			}
+			else if (b==EOT)
+			{
+				// EOT\x82\xAA\x97\x88\x82\xBD\x82\xE7\x81A1\x82‚̃t\x83@\x83C\x83\x8B\x8E\xF3\x90M\x82\xAA\x8A\xAE\x97\xB9\x82\xB5\x82\xBD\x82\xB1\x82Ƃ\xF0\x8E\xA6\x82\xB7\x81B
+				if (fv->FileOpen) {
+					fv->FileOpen = 0;
+					_lclose(fv->FileHandle);
+					fv->FileHandle = -1;
 
-					  if (fv->FileMtime > 0) {
+					if (fv->FileMtime > 0) {
 						SetFMtime(fv->FullName, fv->FileMtime);
-					  }
+					}
 
-					  // 1\x89\xF1\x96ڂ\xCCEOT\x82ɑ΂\xB5\x82\xC4NAK\x82\xF0\x95Ԃ\xB7
-					  b = NAK;
-					  YWrite(fv,yv,cv,&b, 1);
-					  return TRUE;
-				  }
+					// 1\x89\xF1\x96ڂ\xCCEOT\x82ɑ΂\xB5\x82\xC4NAK\x82\xF0\x95Ԃ\xB7
+					b = NAK;
+					YWrite(fv,yv,cv,&b, 1);
+					return TRUE;
+				}
 
-				  initialize_file_info(fv, yv);
+				initialize_file_info(fv, yv);
 
-				  // EOT\x82ɑ΂\xB5\x82\xC4ACK\x82\xF0\x95Ԃ\xB7
-				  b = ACK;
-				  YWrite(fv,yv,cv,&b, 1);
+				// EOT\x82ɑ΂\xB5\x82\xC4ACK\x82\xF0\x95Ԃ\xB7
+				b = ACK;
+				YWrite(fv,yv,cv,&b, 1);
 
-				  // \x8E\x9F\x82̃t\x83@\x83C\x83\x8B\x91\x97\x90M\x82𑣂\xB7\x82\xBD\x82߁A'C'\x82𑗂\xE9\x81B
-		  		  YSendNAK(fv,yv,cv);
+				// \x8E\x9F\x82̃t\x83@\x83C\x83\x8B\x91\x97\x90M\x82𑣂\xB7\x82\xBD\x82߁A'C'\x82𑗂\xE9\x81B
+				YSendNAK(fv,yv,cv);
 
-				  return TRUE;
-			  }
-			  else {
-				  /* flush comm buffer */
-				  cv->InBuffCount = 0;
-				  cv->InPtr = 0;
-				  return TRUE;
-			  }
-			  break;
-		  case XpktBLK:
-			  yv->PktIn[1] = b;
-			  yv->PktReadMode = XpktBLK2;
-			  FTSetTimeOut(fv,yv->TOutShort);
-			  break;
-		  case XpktBLK2:
-			  nak = 1;
-			  yv->PktIn[2] = b;
-			  if ((b ^ yv->PktIn[1]) == 0xff) {
-				  nak = 0;
-				  if (yv->SendFileInfo) {
-					  if (yv->PktIn[1] == (BYTE)(yv->PktNum + 1))  // \x8E\x9F\x82̃u\x83\x8D\x83b\x83N\x94ԍ\x86\x82\xA9
-						  nak = 0;
-				  }
-			  }
+				return TRUE;
+			}
+			else {
+				/* flush comm buffer */
+				cv->InBuffCount = 0;
+				cv->InPtr = 0;
+				return TRUE;
+			}
+			break;
+		case XpktBLK:
+			yv->PktIn[1] = b;
+			yv->PktReadMode = XpktBLK2;
+			FTSetTimeOut(fv,yv->TOutShort);
+			break;
+		case XpktBLK2:
+			nak = 1;
+			yv->PktIn[2] = b;
+			if ((b ^ yv->PktIn[1]) == 0xff) {
+				nak = 0;
+				if (yv->SendFileInfo) {
+					if (yv->PktIn[1] == (BYTE)(yv->PktNum + 1))  // \x8E\x9F\x82̃u\x83\x8D\x83b\x83N\x94ԍ\x86\x82\xA9
+						nak = 0;
+				}
+			}
 
-			  if (nak == 0)
-			  {
-				  yv->PktBufPtr = 3;
-				  yv->PktBufCount = yv->DataLen + yv->CheckLen;
-				  yv->PktReadMode = XpktDATA;
-				  FTSetTimeOut(fv,yv->TOutShort);
-			  }
-			  else
-				  YSendNAK(fv,yv,cv);
-			  break;
-		  case XpktDATA:
-			  yv->PktIn[yv->PktBufPtr] = b;
-			  yv->PktBufPtr++;
-			  yv->PktBufCount--;
-			  GetPkt = yv->PktBufCount==0;
-			  if (GetPkt)
-			  {
-				  FTSetTimeOut(fv,yv->TOutLong);
-				  yv->PktReadMode = XpktSOH;
-			  }
-			  else
-				  FTSetTimeOut(fv,yv->TOutShort);
-			  break;
+			if (nak == 0)
+			{
+				yv->PktBufPtr = 3;
+				yv->PktBufCount = yv->DataLen + yv->CheckLen;
+				yv->PktReadMode = XpktDATA;
+				FTSetTimeOut(fv,yv->TOutShort);
+			}
+			else
+				YSendNAK(fv,yv,cv);
+			break;
+		case XpktDATA:
+			yv->PktIn[yv->PktBufPtr] = b;
+			yv->PktBufPtr++;
+			yv->PktBufCount--;
+			GetPkt = yv->PktBufCount==0;
+			if (GetPkt)
+			{
+				FTSetTimeOut(fv,yv->TOutLong);
+				yv->PktReadMode = XpktSOH;
+			}
+			else
+				FTSetTimeOut(fv,yv->TOutShort);
+			break;
 		}
 
 		if (! GetPkt) c = YRead1Byte(fv,yv,cv,&b);
@@ -541,8 +544,8 @@
 		p = &(yv->PktIn[3]);
 		name = p;
 		strncpy_s(&(fv->FullName[fv->DirLen]),
-				  sizeof(fv->FullName) - fv->DirLen, name,
-				  _TRUNCATE);
+		          sizeof(fv->FullName) - fv->DirLen, name,
+		          _TRUNCATE);
 		if (!FTCreateFile(fv))
 			return FALSE;
 		nameend = name + 1 + strlen(name);
@@ -614,45 +617,62 @@
 	BYTE firstch, lastrx;
 
 	SendFlag = FALSE;
-	if (yv->PktBufCount==0)
+	if (0 == yv->PktBufCount)
 	{
+		// Main read loop.
 		i = YRead1Byte(fv,yv,cv,&b);
-		do {
+		do
+		{
 			if (i==0) return TRUE;
 			firstch = b;
 
-			switch (b) {
+			// Analyze responce.
+			switch (b)
+			{
 			case ACK:
 				// 1\x89\xF1\x96ڂ\xCCEOT\x91\x97\x90M\x8C\xE3\x82\xCCACK\x8E\xF3\x90M\x82ŁA\x81u1\x83t\x83@\x83C\x83\x8B\x91\x97\x90M\x81v\x82̏I\x82\xED\x82\xE8\x82Ƃ\xB7\x82\xE9\x81B
-				if (yv->SendEot) {
+				// If we already send EOT, ACK means that client confirms it.
+				if (yv->SendEot)
+				{
+					// Reset the flag.
 					yv->SendEot = 0;
 
 					// \x91\x97\x90M\x83t\x83@\x83C\x83\x8B\x82\xAA\x8Ec\x82\xC1\x82Ă\xA2\x82Ȃ\xA2\x8Fꍇ\x82́A\x81u\x91S\x82Ẵt\x83@\x83C\x83\x8B\x82\xF0\x93]\x91\x97\x8FI\x97\xB9\x81v\x82\xF0\x92ʒm\x82\xB7\x82\xE9\x81B
-					if (!GetNextFname(fv)) {
+					if (!GetNextFname(fv))
+					{
+						// If it is the last file.
 						yv->LastSendEot = 1;
 						break;
-					} else {
+					}
+					else
+					{
+						// Process with next file.
 						initialize_file_info(fv, yv);
 					}
 				}
 
-				if (! fv->FileOpen) // \x82\xE0\x82\xA4\x91\x97\x90M\x82\xB7\x82\xE9\x83t\x83@\x83C\x83\x8B\x82\xAA\x82Ȃ\xA2\x8Fꍇ\x82́A\x90\xB3\x8F\xED\x8FI\x97\xB9\x81B
+				// If client confirms that last (empty) packed was received.
+				// \x82\xE0\x82\xA4\x91\x97\x90M\x82\xB7\x82\xE9\x83t\x83@\x83C\x83\x8B\x82\xAA\x82Ȃ\xA2\x8Fꍇ\x82́A\x90\xB3\x8F\xED\x8FI\x97\xB9\x81B
+				if (!fv->FileOpen)
 				{
 					fv->Success = TRUE;
 					return FALSE;
 				}
-				else if (yv->PktNumSent==(BYTE)(yv->PktNum+1))  // \x8E\x9F\x82̃u\x83\x8D\x83b\x83N\x82𑗂\xE9
+				// \x8E\x9F\x82̃u\x83\x8D\x83b\x83N\x82𑗂\xE9
+				else if (yv->PktNumSent == (BYTE)(yv->PktNum + 1))
 				{
 					// \x83u\x83\x8D\x83b\x83N0\x81i\x83t\x83@\x83C\x83\x8B\x8F\xEE\x95\xF1\x81j\x91\x97\x90M\x8C\xE3\x82́AACK \x82\xC6 'C' \x82\xF0\x98A\x91\xB1\x82\xB5\x82Ď\xF3\x90M\x82\xB7\x82邱\x82Ƃ\xC9
 					// \x82Ȃ\xC1\x82Ă\xA2\x82邽\x82߁A\x8E\x9F\x82\xCC'C'\x82\xF0\x91҂B(2010.6.20 yutaka)
-					if ((yv->PktNum==0) && (yv->PktNumOffset==0)) {
-						yv->SendFileInfo = 1;   // \x91\x97\x90M\x8Dς݃t\x83\x89\x83Oon
+					if ((yv->PktNum==0) && (yv->PktNumOffset==0))
+					{
+						// It is an ACK for file info, wait for 'C' by some reason (?).
+						// \x91\x97\x90M\x8Dς݃t\x83\x89\x83Oon
+						yv->SendFileInfo = 1;
 						SendFlag = FALSE;
 						break;
 					}
-
 					yv->PktNum = yv->PktNumSent;
-					if (yv->PktNum==0)
+					if (0 == yv->PktNum)
 						yv->PktNumOffset = yv->PktNumOffset + 256;
 					SendFlag = TRUE;
 				}
@@ -660,9 +680,10 @@
 
 			case NAK:
 				// 1\x89\xF1\x96ڂ\xCCEOT\x91\x97\x90M\x8C\xE3\x82\xCCNAK\x8E\xF3\x90M\x82ŁA\x8DŌ\xE3"EOT"\x82𑗂\xE9\x81B
-				if (yv->SendEot) {
+				if (yv->SendEot)
+				{
 					yv->PktNum = yv->PktNumSent;
-					if (yv->PktNum==0)
+					if (0 == yv->PktNum)
 						yv->PktNumOffset = yv->PktNumOffset + 256;
 				}
 
@@ -675,18 +696,20 @@
 			case 0x43:  // 'C'(43h)
 			case 0x47:  // 'G'(47h)
 				// 'C'\x82\xF0\x8E󂯎\xE6\x82\xE9\x82ƁA\x83u\x83\x8D\x83b\x83N\x82̑\x97\x90M\x82\xF0\x8AJ\x8En\x82\xB7\x82\xE9\x81B
-				if ((yv->PktNum==0) && (yv->PktNumOffset==0))
+				if ((0 == yv->PktNum) && (0 == yv->PktNumOffset))
 				{
 					// \x83t\x83@\x83C\x83\x8B\x8F\xEE\x95񑗐M\x8C\xE3\x81AACK -> 'C' \x82Ǝ\xF3\x90M\x82\xB5\x82\xBD\x82̂ŁA\x8E\x9F\x82̃u\x83\x8D\x83b\x83N\x82𑗐M\x82\xB7\x82\xE9\x81B
-					if (yv->SendFileInfo) {
+					if (yv->SendFileInfo)
+					{
 						yv->PktNum = yv->PktNumSent;
-						if (yv->PktNum==0)
+						if (0 == yv->PktNum)
 							yv->PktNumOffset = yv->PktNumOffset + 256;
 					}
 
 					SendFlag = TRUE;
 				}
-				else if (yv->LastSendEot) {
+				else if (yv->LastSendEot)
+				{
 					SendFlag = TRUE;
 				}
 				break;
@@ -695,10 +718,11 @@
 		} while (!SendFlag);
 
 		// reset timeout timer
-		FTSetTimeOut(fv,TimeOutVeryLong);
+		FTSetTimeOut(fv, TimeOutVeryLong);
 
 		// \x8C㑱\x82̃T\x81[\x83o\x82\xA9\x82\xE7\x82̃f\x81[\x83^\x82\xF0\x93ǂݎ̂Ă\xE9\x81B
-		do {
+		do
+		{
 			lastrx = firstch;
 			i = YRead1Byte(fv,yv,cv,&b);
 			if (i != 0) {
@@ -713,7 +737,13 @@
 			}
 		} while (i != 0);
 
-		if (yv->LastSendEot) { // \x83I\x81[\x83\x8B\x83[\x83\x8D\x82̃u\x83\x8D\x83b\x83N\x82𑗐M\x82\xB5\x82āA\x82\xE0\x82\xA4\x83t\x83@\x83C\x83\x8B\x82\xAA\x82Ȃ\xA2\x82\xB1\x82Ƃ\xF0\x92m\x82点\x82\xE9\x81B
+		//================================
+		// Last packet case.
+		//================================
+		// \x83I\x81[\x83\x8B\x83[\x83\x8D\x82̃u\x83\x8D\x83b\x83N\x82𑗐M\x82\xB5\x82āA\x82\xE0\x82\xA4\x83t\x83@\x83C\x83\x8B\x82\xAA\x82Ȃ\xA2\x82\xB1\x82Ƃ\xF0\x92m\x82点\x82\xE9\x81B
+		if (yv->LastSendEot)
+		{
+			// Clear the flag.
 			yv->LastSendEot = 0;
 
 			if (yv->DataLen == SOH_DATALEN)
@@ -730,34 +760,49 @@
 				i++;
 			}
 
-			Check = YCalcCheck(yv,yv->PktOut);
-			if (yv->CheckLen==1) /* Checksum */
-				yv->PktOut[yv->DataLen+3] = (BYTE)Check;
-			else {
-				yv->PktOut[yv->DataLen+3] = HIBYTE(Check);
-				yv->PktOut[yv->DataLen+4] = LOBYTE(Check);
+			Check = YCalcCheck(yv, yv->PktOut);
+			if (1 == yv->CheckLen)
+			{
+				yv->PktOut[yv->DataLen + 3] = (BYTE)Check;
 			}
+			else
+			{
+				yv->PktOut[yv->DataLen + 3] = HIBYTE(Check);
+				yv->PktOut[yv->DataLen + 4] = LOBYTE(Check);
+			}
+
 			yv->PktBufCount = 3 + yv->DataLen + yv->CheckLen;
 			//fv->Success = TRUE;
+		}
 
-		} 
-		else if (yv->PktNumSent==yv->PktNum) /* make a new packet */
+		//================================
+		// First or 256th packet case.
+		//================================
+
+		// Start a new sequence.
+		else if (yv->PktNumSent==yv->PktNum)
 		{
+			 /* make a new packet */
 			BYTE *dataptr = &yv->PktOut[3];
 			int eot = 0;  // End Of Transfer
 
-			if (yv->DataLen == SOH_DATALEN)
+			if (SOH_DATALEN == yv->DataLen)
 				yv->PktOut[0] = SOH;
 			else
 				yv->PktOut[0] = STX;
 			yv->PktOut[1] = yv->PktNumSent;
-			yv->PktOut[2] = ~ yv->PktNumSent;
+			yv->PktOut[2] = ~yv->PktNumSent;
 
 			// \x83u\x83\x8D\x83b\x83N\x94ԍ\x86\x82̃J\x83E\x83\x93\x83g\x83A\x83b\x83v\x81BYMODEM\x82ł\xCD"0"\x82\xA9\x82\xE7\x8AJ\x8En\x82\xB7\x82\xE9\x81B
 			yv->PktNumSent++;
 
+			//================================
+			// First packet case.
+			//================================
 			// \x83u\x83\x8D\x83b\x83N0
-			if (yv->SendFileInfo == 0) { // \x83t\x83@\x83C\x83\x8B\x8F\xEE\x95\xF1\x82̑\x97\x90M
+			// \x83t\x83@\x83C\x83\x8B\x8F\xEE\x95\xF1\x82̑\x97\x90M
+			if (yv->SendFileInfo == 0)
+			{
 				int ret, total;
 				BYTE buf[1024 + 10];
 
@@ -766,18 +811,20 @@
 				// (2011.3.21 yutaka)
 				//yv->SendFileInfo = 1;   // \x91\x97\x90M\x8Dς݃t\x83\x89\x83Oon
 
-				/* timestamp */
+				// Timestamp.
 				fv->FileMtime = GetFMtime(fv->FullName);
 
 				ret = _snprintf_s(buf, sizeof(buf), _TRUNCATE, "%s",
-					&(fv->FullName[fv->DirLen]));
-				buf[ret] = 0x00;  // NUL
+				                  &(fv->FullName[fv->DirLen]));
+				// NULL-terminated string.
+				buf[ret] = 0x00;
 				total = ret + 1;
 
 				ret = _snprintf_s(&(buf[total]), sizeof(buf) - total, _TRUNCATE, "%lu %lo %o",
-					fv->FileSize, fv->FileMtime, 0644|_S_IFREG);
+				                  fv->FileSize, fv->FileMtime, 0644|_S_IFREG);
 				total += ret;
 
+				// Padding.
 				i = total;
 				while (i <= yv->DataLen)
 				{
@@ -788,10 +835,17 @@
 				// \x83f\x81[\x83^\x83R\x83s\x81[
 				memcpy(dataptr, buf, yv->DataLen);
 
-			} else {
+			}
+
+			//================================
+			// 256th packet case.
+			//================================
+
+			else
+			{
 				i = 1;
 				while ((i<=yv->DataLen) && fv->FileOpen &&
-					(_lread(fv->FileHandle,&b,1)==1))
+				       (1 == _lread(fv->FileHandle, &b, 1)))
 				{
 					yv->PktOut[2+i] = b;
 					i++;
@@ -821,29 +875,44 @@
 
 			}
 
-			if (eot == 0) {  // \x83f\x81[\x83^\x83u\x83\x8D\x83b\x83N
-				Check = YCalcCheck(yv,yv->PktOut);
-				if (yv->CheckLen==1) /* Checksum */
-					yv->PktOut[yv->DataLen+3] = (BYTE)Check;
+			// \x83f\x81[\x83^\x83u\x83\x8D\x83b\x83N
+			if (0 == eot)
+			{
+				// Add CRC if not End-of-Tranfer.
+				Check = YCalcCheck(yv, yv->PktOut);
+				// Checksum.
+				if (1 == yv->CheckLen)
+					yv->PktOut[yv->DataLen + 3] = (BYTE)Check;
 				else {
-					yv->PktOut[yv->DataLen+3] = HIBYTE(Check);
-					yv->PktOut[yv->DataLen+4] = LOBYTE(Check);
+					yv->PktOut[yv->DataLen + 3] = HIBYTE(Check);
+					yv->PktOut[yv->DataLen + 4] = LOBYTE(Check);
 				}
 				yv->PktBufCount = 3 + yv->DataLen + yv->CheckLen;
 
-			} else {  // EOT
+			}
+			else
+			{
+				// EOT.
 				yv->PktOut[0] = EOT;
 				yv->PktBufCount = 1;
 
-				yv->SendEot = 1;  // EOT\x83t\x83\x89\x83Oon\x81B\x8E\x9F\x82\xCDNAK\x82\xF0\x8A\xFA\x91҂\xB7\x82\xE9\x81B
+				// EOT\x83t\x83\x89\x83Oon\x81B\x8E\x9F\x82\xCDNAK\x82\xF0\x8A\xFA\x91҂\xB7\x82\xE9\x81B
+				yv->SendEot = 1;
 				yv->LastSendEot = 0;
 			}
+		}
 
-		}
-		else { /* resend packet */
+		//================================
+		// TODO: Analyze resend case.
+		//================================
+
+		else
+		{
+			// Resend packet.
 			yv->PktBufCount = 3 + yv->DataLen + yv->CheckLen;
 		}
 
+		// Reset counter.
 		yv->PktBufPtr = 0;
 	}
 	/* a NAK or C could have arrived while we were buffering.  Consume it. */
@@ -864,26 +933,31 @@
 	} while (i != 0);
 
 
+	// Write bytes to COM.
 	i = 1;
 	while ((yv->PktBufCount>0) && (i>0))
 	{
 		b = yv->PktOut[yv->PktBufPtr];
-		i = YWrite(fv,yv,cv,&b, 1);
-		if (i>0)
+		i = YWrite(fv, yv, cv, &b, 1);
+		if (i > 0)
 		{
-			yv->PktBufCount--;
-			yv->PktBufPtr++;
+			--yv->PktBufCount;
+			++yv->PktBufPtr;
 		}
 	}
 
-	if (yv->PktBufCount==0)
+	// Update dialog window.
+	if (0 == yv->PktBufCount)
 	{
-		if (yv->PktNumSent == 0) {
+		if (0 == yv->PktNumSent)
+		{
 			SetDlgNum(fv->HWin, IDC_PROTOPKTNUM, yv->PktNumOffset + 256);
 		}
-		else {
+		else
+		{
 			SetDlgNum(fv->HWin, IDC_PROTOPKTNUM, yv->PktNumOffset + yv->PktNumSent);
 		}
+
 		SetDlgNum(fv->HWin, IDC_PROTOBYTECOUNT, fv->ByteCount);
 		SetDlgPercent(fv->HWin, IDC_PROTOPERCENT, IDC_PROTOPROGRESS,
 		              fv->ByteCount, fv->FileSize, &fv->ProgStat);



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