[Ttssh2-commit] [8006] リモートからのクリップボード読み取りの Unicode 対応

Back to archive index
scmno****@osdn***** scmno****@osdn*****
2019年 8月 22日 (木) 12:37:12 JST


Revision: 8006
          https://osdn.net/projects/ttssh2/scm/svn/commits/8006
Author:   doda
Date:     2019-08-22 12:37:11 +0900 (Thu, 22 Aug 2019)
Log Message:
-----------
リモートからのクリップボード読み取りの Unicode 対応

ASCII 以外の文字が含まれている場合、送信漢字コード設定が UTF-8 以外だと期待通り動かないかも。

Modified Paths:
--------------
    branches/unicode_buf/teraterm/teraterm/clipboar.c
    branches/unicode_buf/teraterm/teraterm/clipboar.h
    branches/unicode_buf/teraterm/teraterm/vtterm.c

-------------- next part --------------
Modified: branches/unicode_buf/teraterm/teraterm/clipboar.c
===================================================================
--- branches/unicode_buf/teraterm/teraterm/clipboar.c	2019-08-21 15:03:17 UTC (rev 8005)
+++ branches/unicode_buf/teraterm/teraterm/clipboar.c	2019-08-22 03:37:11 UTC (rev 8006)
@@ -43,6 +43,7 @@
 #include "ttcommon.h"
 #include "ttlib.h"
 #include "dlglib.h"
+#include "codeconv.h"
 
 #include "clipboar.h"
 #include "tt_res.h"
@@ -980,6 +981,98 @@
 	}
 }
 
+void CBStartPasteB64W(HWND HWin, PCHAR header, PCHAR footer)
+{
+	size_t mb_len, b64_len, header_len = 0, footer_len = 0;
+	clipboard_work_t *p;
+	wchar_t *str_w = NULL;
+	char *str_mb = NULL;
+	char *str_b64 = NULL;
+
+	if (! cv.Ready) {
+		return;
+	}
+	if (TalkStatus!=IdTalkKeyb) {
+		return;
+	}
+
+	CBEchoOnly = FALSE;
+
+	p = &cbwork;
+	if (p->send_str != NULL) {
+		// \x91\x97\x90M\x92\x86?
+		return;
+	}
+
+	str_w = GetClipboardTextW(HWin, FALSE);
+	if (str_w == NULL) {
+		// \x83N\x83\x8A\x83b\x83v\x83{\x81[\x83h\x82\xA9\x82當\x8E\x9A\x97\xF1\x82\xF0\x8E擾\x82ł\xAB\x82Ȃ\xA9\x82\xC1\x82\xBD
+		goto error;
+		return;
+	}
+	p->send_str = str_w;
+
+	if (ts.Language == IdUtf8 || ts.KanjiCodeSend == IdUTF8) {
+		str_mb = ToU8W(str_w);
+	}
+	else {
+		str_mb = ToCharW(str_w);
+	}
+
+	if (str_mb == NULL) {
+		goto error;
+	}
+
+	if (header != NULL) {
+		header_len = strlen(header);
+	}
+	if (footer != NULL) {
+		footer_len = strlen(footer);
+	}
+
+	mb_len = strlen(str_mb);
+	b64_len = (mb_len + 2) / 3 * 4 + header_len + footer_len + 1;
+
+	if ((str_b64 = malloc(b64_len)) == NULL) {;
+		goto error;
+	}
+
+	if (header_len > 0) {
+		strncpy_s(str_b64, b64_len, header, _TRUNCATE);
+	}
+
+	b64encode(str_b64 + header_len, b64_len - header_len, str_mb, mb_len);
+
+	if (footer_len > 0) {
+		strncat_s(str_b64, b64_len, footer, _TRUNCATE);
+	}
+
+	free(str_w);
+	if ((str_w = ToWcharA(str_b64)) == NULL) {
+		goto error;
+	}
+
+	free(str_mb);
+	free(str_b64);
+
+	// \x93\\x82\xE8\x95t\x82\xAF\x82̏\x80\x94\x{142A90}\xB3\x8F\xED\x82ɏo\x97\x88\x82\xBD
+	p->send_str = str_w;
+	p->send_index = 0;
+	p->waited = FALSE;
+	p->str_len = wcslen(p->send_str);
+	p->send_left = p->str_len;
+	TalkStatus = IdTalkCB;
+
+	return;
+
+error:
+	free(str_w);
+	free(str_mb);
+	free(str_b64);
+	CBEndPaste();
+	return;
+}
+
 // \x82\xB1\x82̊֐\x94\x82̓N\x83\x8A\x83b\x83v\x83{\x81[\x83h\x82\xA8\x82\xE6\x82\xD1DDE\x83f\x81[\x83^\x82\xF0\x92[\x96\x96\x82֑\x97\x82荞\x82ށB
 //
 // CBMemHandle\x83n\x83\x93\x83h\x83\x8B\x82̓O\x83\x8D\x81[\x83o\x83\x8B\x95ϐ\x94\x82Ȃ̂ŁA\x82\xB1\x82̊֐\x94\x82\xAA\x8FI\x97\xB9\x82\xB7\x82\xE9\x82܂ł́A

Modified: branches/unicode_buf/teraterm/teraterm/clipboar.h
===================================================================
--- branches/unicode_buf/teraterm/teraterm/clipboar.h	2019-08-21 15:03:17 UTC (rev 8005)
+++ branches/unicode_buf/teraterm/teraterm/clipboar.h	2019-08-22 03:37:11 UTC (rev 8006)
@@ -47,6 +47,7 @@
 void CBStartPaste(HWND HWin, BOOL AddCR, BOOL Bracketed);
 void CBStartPasteW(HWND HWin, BOOL AddCR, BOOL Bracketed);
 void CBStartPasteB64(HWND HWin, PCHAR header, PCHAR footer);
+void CBStartPasteB64W(HWND HWin, PCHAR header, PCHAR footer);
 void CBSend(void);
 void CBSendW(void);
 void CBEcho(void);

Modified: branches/unicode_buf/teraterm/teraterm/vtterm.c
===================================================================
--- branches/unicode_buf/teraterm/teraterm/vtterm.c	2019-08-21 15:03:17 UTC (rev 8005)
+++ branches/unicode_buf/teraterm/teraterm/vtterm.c	2019-08-22 03:37:11 UTC (rev 8006)
@@ -4839,7 +4839,11 @@
 				}
 				strncpy_s(hdr, sizeof(hdr), "\033]52;", _TRUNCATE);
 				if (strncat_s(hdr, sizeof(hdr), buff, p - buff) == 0) {
+#if UNICODE_INTERNAL_BUFF
+					CBStartPasteB64W(HVTWin, hdr, "\033\\");
+#else
 					CBStartPasteB64(HVTWin, hdr, "\033\\");
+#endif
 				}
 			}
 			else if (ts.NotifyClipboardAccess) {


Ttssh2-commit メーリングリストの案内
Back to archive index