[Ttssh2-commit] [6453] クリップボードの内容のコピーと、AddCR , Bracketed Paste Mode の処理を分離

svnno****@sourc***** svnno****@sourc*****
2016年 8月 1日 (月) 18:01:22 JST


Revision: 6453
          http://sourceforge.jp/projects/ttssh2/scm/svn/commits/6453
Author:   doda
Date:     2016-08-01 18:01:22 +0900 (Mon, 01 Aug 2016)
Log Message:
-----------
クリップボードの内容のコピーと、AddCR, Bracketed Paste Mode の処理を分離
間に他の確認/加工処理を入れやすくする為

Modified Paths:
--------------
    trunk/teraterm/teraterm/clipboar.c

-------------- next part --------------
Modified: trunk/teraterm/teraterm/clipboar.c
===================================================================
--- trunk/teraterm/teraterm/clipboar.c	2016-08-01 09:01:20 UTC (rev 6452)
+++ trunk/teraterm/teraterm/clipboar.c	2016-08-01 09:01:22 UTC (rev 6453)
@@ -139,6 +139,8 @@
 	}
 }
 
+#define BracketStartLen	(sizeof(BracketStart)-1)
+#define BracketEndLen	(sizeof(BracketEnd)-1)
 void CBStartPaste(HWND HWin, BOOL AddCR, BOOL Bracketed)
 {
 	static char BracketStart[] = "\033[200~";
@@ -147,7 +149,7 @@
 	PCHAR TmpPtr;
 	LPWSTR TmpPtrW;
 	HGLOBAL TmpHandle;
-	int BuffLen, BracketLen;
+	unsigned int StrLen = 0, BuffLen = 0;
 
 	if (! cv.Ready) {
 		return;
@@ -201,7 +203,7 @@
 			}
 
 			if (Bracketed) {
-				BuffLen += sizeof(BracketStart) + sizeof(BracketEnd);
+				BuffLen += BracketStartLen + BracketEndLen;
 			}
 
 			if (AddCR) {
@@ -210,44 +212,69 @@
 
 			if ((CBMemHandle = GlobalAlloc(GHND, BuffLen)) != NULL) {
 				if ((CBMemPtr = GlobalLock(CBMemHandle)) != NULL) {
-					if (Bracketed) {
-						strncpy_s(CBMemPtr, BuffLen, BracketStart, _TRUNCATE);
-						BracketLen = strlen(CBMemPtr);
-					}
-					else {
-						BracketLen = 0;
-					}
-
 					if (Cf == CF_UNICODETEXT) {
-						WideCharToMultiByte(CP_ACP, 0, TmpPtrW, -1, CBMemPtr+BracketLen, BuffLen-BracketLen, NULL, NULL);
+						WideCharToMultiByte(CP_ACP, 0, TmpPtrW, -1, CBMemPtr, BuffLen, NULL, NULL);
 					}
 					else {
-						strncat_s(CBMemPtr, BuffLen, TmpPtr, _TRUNCATE);
+						strncpy_s(CBMemPtr, BuffLen, TmpPtr, _TRUNCATE);
 					}
 
-					if (Bracketed) {
-						strncat_s(CBMemPtr, BuffLen, BracketEnd, _TRUNCATE);
-					}
-
-					if (AddCR) {
-						strncat_s(CBMemPtr, BuffLen, "\r", _TRUNCATE);
-					}
-
-					CBMemPtr = NULL;
-
 					TalkStatus = IdTalkCB;
 				}
-				GlobalUnlock(CBMemHandle);
-				CBMemPtr = NULL;
 			}
 			GlobalUnlock(TmpHandle);
 		}
 		CloseClipboard();
 	}
 
+	// \x93\\x82\xE8\x95t\x82\xAF\x82̏\x80\x94\x{142A90}\xB3\x8F\xED\x82ɏo\x97\x88\x82\xBD\x8Fꍇ\x82\xCD IdTalkCB \x82ƂȂ\xE9
+
 	if (TalkStatus != IdTalkCB) {
+		// \x8F\x80\x94\x{142A8D}s\x82\xA6\x82Ȃ\xA9\x82\xC1\x82\xBD\x8Fꍇ\x82͓\\x82\xE8\x95t\x82\xAF\x82𒆒f\x82\xB7\x82\xE9
 		CBEndPaste();
+		return;
 	}
+
+	// \x93\\x82\xE8\x95t\x82\xAF\x91O\x82ɃN\x83\x8A\x83b\x83v\x83{\x81[\x83h\x82̓\xE0\x97e\x82\xF0\x8Am\x94F/\x89\xC1\x8DH\x93\x99\x82\xB7\x82\xE9\x8Fꍇ\x82͂\xB1\x82\xB1\x82ōs\x82\xA4
+
+	// AddCR / Bracket \x97p\x82̗̈悪\x82\xA0\x82邩\x82̊m\x94F\x81A\x96\xB3\x82\xAF\x82\xEA\x82Βlj\xC1\x8Am\x95\xDB
+	StrLen = strlen(CBMemPtr);
+	BuffLen = StrLen + 1; // strlen + NUL
+	if (AddCR) {
+		BuffLen++;
+	}
+	if (Bracketed) {
+		BuffLen += BracketStartLen + BracketEndLen;
+	}
+
+	if (GlobalSize(CBMemHandle) < BuffLen) {
+		GlobalUnlock(CBMemHandle);
+		CBMemPtr = NULL;
+		if ((TmpHandle = GlobalReAlloc(CBMemHandle, BuffLen, 0)) == NULL) {
+			/*
+			 * \x95s\x91\xAB\x95\xAA\x82̊m\x95ێ\xB8\x94s\x82\xB5\x82\xBD\x8E\x9E\x82\xCD CR/Bracket \x96\xB3\x82\xB5\x82œ\\x82\xE8\x95t\x82\xAF\x82\xF0\x8Ds\x82\xA4\x82ׂ\xAB\x82\xA9\x81A
+			 * \x82\xBB\x82\xEA\x82Ƃ\xE0\x93\\x82\xE8\x95t\x82\xAF\x8E\xA9\x91̂𒆎~\x82\xB7\x82\xE9(CBEndPaste()\x82\xF0\x8CĂ\xD4)\x82ׂ\xAB\x82\xA9\x81B
+			 */
+			// CBEndPaste();
+			return;
+		}
+		CBMemHandle = TmpHandle;
+		CBMemPtr = GlobalLock(CBMemHandle);
+	}
+
+	if (AddCR) {
+		CBMemPtr[StrLen++] = '\r';
+	}
+
+	if (Bracketed) {
+		BuffLen = GlobalSize(CBMemHandle);
+		memmove_s(CBMemPtr+BracketStartLen, BuffLen-BracketStartLen, CBMemPtr, StrLen);
+		memcpy_s(CBMemPtr, BuffLen, BracketStart, BracketStartLen);
+		strncat_s(CBMemPtr, BuffLen, BracketEnd, _TRUNCATE);
+	}
+
+	GlobalUnlock(CBMemHandle);
+	CBMemPtr = NULL;
 }
 
 void CBStartPasteB64(HWND HWin, PCHAR header, PCHAR footer)



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