[Ttssh2-commit] [8908] 現在バッファをすべてログへ書き出しを Unicode化した

Back to archive index
scmno****@osdn***** scmno****@osdn*****
2020年 8月 19日 (水) 00:31:51 JST


Revision: 8908
          https://osdn.net/projects/ttssh2/scm/svn/commits/8908
Author:   zmatsuo
Date:     2020-08-19 00:31:51 +0900 (Wed, 19 Aug 2020)
Log Message:
-----------
現在バッファをすべてログへ書き出しを Unicode化した

- 別関数に分離, FLogOutputAllBuffer()

Modified Paths:
--------------
    trunk/teraterm/teraterm/buffer.c
    trunk/teraterm/teraterm/buffer.h
    trunk/teraterm/teraterm/filesys_log.cpp
    trunk/teraterm/teraterm/filesys_log.h
    trunk/teraterm/teraterm/vtwin.cpp

-------------- next part --------------
Modified: trunk/teraterm/teraterm/buffer.c
===================================================================
--- trunk/teraterm/teraterm/buffer.c	2020-08-18 15:31:42 UTC (rev 8907)
+++ trunk/teraterm/teraterm/buffer.c	2020-08-18 15:31:51 UTC (rev 8908)
@@ -1704,7 +1704,7 @@
 		if (too_samll != NULL) {
 			*too_samll = TRUE;
 		}
-		return 0;
+		return len;
 	}
 	if (too_samll != NULL) {
 		*too_samll = FALSE;
@@ -5256,7 +5256,54 @@
 	return (copysize);
 }
 
+/**
+ * \x91S\x83o\x83b\x83t\x83@\x82\xA9\x82\xE7\x8Ew\x92肵\x82\xBD\x8Ds\x82\xF0\x95Ԃ\xB7\x81B
+ * filesys_log.cpp \x82Ŏg\x97p\x82\xB3\x82\xEA\x82\xE9
+ *
+ * @param[in]	offset_y	\x8E擾\x82\xB7\x82\xE9\x8Ds(0...)
+ * @param[in]	bufsize		\x95\xB6\x8E\x9A\x90\x94
+ * @return		\x95\xB6\x8E\x9A\x90\x94
+ *				-1	\x8DŏI\x8Ds\x88ȍ~\x82\xF0\x8Ew\x92\xE8
+ */
+int BuffGetAnyLineDataW(int offset_y, wchar_t *buf, size_t bufsize)
+{
+	LONG Ptr;
+	size_t copysize;
+	size_t i;
+	size_t idx;
+	size_t left;
+	buff_char_t *b;
 
+	if (offset_y >= BuffEnd)
+		return -1;
+
+	memset(buf, 0, bufsize * sizeof(wchar_t));
+	copysize = min(NumOfColumns, bufsize - 1);
+	Ptr = GetLinePtr(offset_y);
+	b = &CodeBuffW[Ptr];
+	idx = 0;
+	left = copysize;
+	for (i = 0; i<copysize; i++) {
+		BOOL too_small;
+		size_t len;
+		if (IsBuffPadding(b)) {
+			continue;
+		}
+		len = expand_wchar(b, &buf[idx], left, &too_small);
+		if (too_small) {
+			break;
+		}
+		idx += len;
+		left -= len;
+		b++;
+		if (idx >= bufsize - 1) {
+			break;
+		}
+	}
+
+	return (int)idx;
+}
+
 BOOL BuffCheckMouseOnURL(int Xw, int Yw)
 {
 	int X, Y;

Modified: trunk/teraterm/teraterm/buffer.h
===================================================================
--- trunk/teraterm/teraterm/buffer.h	2020-08-18 15:31:42 UTC (rev 8907)
+++ trunk/teraterm/teraterm/buffer.h	2020-08-18 15:31:51 UTC (rev 8908)
@@ -148,7 +148,8 @@
 void BuffScrollRight(int count);
 int BuffGetCurrentLineData(char *buf, int bufsize);
 wchar_t *BuffGetLineStrW(int Sy, int *cx, size_t *length);
-int BuffGetAnyLineData(int offset_y, char *buf, int bufsize);		// from filesys.cpp
+int BuffGetAnyLineData(int offset_y, char *buf, int bufsize);
+int BuffGetAnyLineDataW(int offset_y, wchar_t *buf, size_t bufsize);
 BOOL BuffCheckMouseOnURL(int Xw, int Yw);
 wchar_t *BuffGetCharInfo(int Xw, int Yw);
 void BuffSetCursorCharAttr(int x, int y, TCharAttr Attr);

Modified: trunk/teraterm/teraterm/filesys_log.cpp
===================================================================
--- trunk/teraterm/teraterm/filesys_log.cpp	2020-08-18 15:31:42 UTC (rev 8907)
+++ trunk/teraterm/teraterm/filesys_log.cpp	2020-08-18 15:31:51 UTC (rev 8908)
@@ -122,6 +122,7 @@
 static BOOL CreateBinBuf(void);
 void LogPut1(BYTE b);
 static void OutputStr(const wchar_t *str);
+static void LogToFile(void);
 
 static BOOL OpenFTDlg_(PFileVar fv)
 {
@@ -760,38 +761,6 @@
 		StartThread(LogVar);
 	}
 
-	// \x8C\xBB\x8D݃o\x83b\x83t\x83@\x82ɂ\xA0\x82\xE9\x83f\x81[\x83^\x82\xF0\x82\xB7\x82ׂď\x91\x82\xAB\x8Fo\x82\xB5\x82Ă\xA9\x82\xE7\x81A
-	// \x83\x8D\x83O\x8D̎\xE6\x82\xF0\x8AJ\x8En\x82\xB7\x82\xE9\x81B
-	// (2013.9.29 yutaka)
-	if (ts.LogAllBuffIncludedInFirst) {
-		DWORD ofs, size, written_size;
-		char buf[512];
-		const char *crlf = "\r\n";
-		DWORD crlf_len = 2;
-		for (ofs = 0 ;  ; ofs++ ) {
-			// 1\x82‚̍s\x82\xF0\x8E擾\x82\xB7\x82\xE9\x81B\x95\xB6\x8E\x9A\x82\xBE\x82\xAF\x82Ȃ̂ŁA\x83G\x83X\x83P\x81[\x83v\x83V\x81[\x83P\x83\x93\x83X\x82͊܂܂\xEA\x82Ȃ\xA2\x81B
-			size = BuffGetAnyLineData(ofs, buf, sizeof(buf));
-			if (size == -1)
-				break;
-
-#if 0
-			if (ts.DeferredLogWriteMode) { // \x92x\x89\x84\x8F\x91\x82\xAB\x8D\x9E\x82\xDD
-				char *pbuf = (char *)malloc(size + 2);
-				memcpy(pbuf, buf, size);
-				pbuf[size] = '\r';
-				pbuf[size+1] = '\n';
-				Sleep(1);  // \x83X\x83\x8C\x83b\x83h\x83L\x83\x85\x81[\x82\xAA\x8D\xEC\x82\xE7\x82\xEA\x82\xE9\x82悤\x82ɁA\x83R\x83\x93\x83e\x83L\x83X\x83g\x83X\x83C\x83b\x83`\x82𑣂\xB7\x81B
-				PostThreadMessage(LogVar->LogThreadId, WM_DPC_LOGTHREAD_SEND, (WPARAM)pbuf, size + 2);
-			} else { // \x92\xBC\x8F\x91\x82\xAB\x81B\x83l\x83b\x83g\x83\x8F\x81[\x83N\x8Co\x97R\x82\xBE\x82ƒx\x82\xA2\x81B
-#endif
-				WriteFile(LogVar->FileHandle, buf, size, &written_size, NULL);
-				WriteFile(LogVar->FileHandle, crlf, crlf_len, &written_size, NULL);
-#if 0
-			}
-#endif
-		}
-	}
-
 	if (FileLog) {
 		cv.Log1Byte = LogPut1;
 	}
@@ -804,6 +773,30 @@
 }
 
 /**
+ * \x8C\xBB\x8D݃o\x83b\x83t\x83@\x82ɂ\xA0\x82\xE9\x83f\x81[\x83^\x82\xF0\x82\xB7\x82ׂă\x8D\x83O\x82ɏ\x91\x82\xAB\x8Fo\x82\xB7
+ * (2013.9.29 yutaka)
+ *
+ *	TODO
+ *		1\x8Ds\x82̒\xB7\x82\xB3
+ */
+void FLogOutputAllBuffer(void)
+{
+	DWORD ofs, written_size;
+	int size;
+	wchar_t buf[512];
+	for (ofs = 0 ;  ; ofs++ ) {
+		// 1\x82‚̍s\x82\xF0\x8E擾\x82\xB7\x82\xE9\x81B\x95\xB6\x8E\x9A\x82\xBE\x82\xAF\x82Ȃ̂ŁA\x83G\x83X\x83P\x81[\x83v\x83V\x81[\x83P\x83\x93\x83X\x82͊܂܂\xEA\x82Ȃ\xA2\x81B
+		size = BuffGetAnyLineDataW(ofs, buf, _countof(buf));
+		if (size == -1)
+			break;
+
+		OutputStr(buf);
+		OutputStr(L"\r\n");
+		LogToFile();
+	}
+}
+
+/**
  * \x83\x8D\x83O\x82\xD61byte\x8F\x91\x82\xAB\x8D\x9E\x82\xDD
  *		\x83o\x83b\x83t\x83@\x82֏\x91\x82\xAB\x8D\x9E\x82܂\xEA\x82\xE9
  *		\x8E\xC0\x8Dۂ̏\x91\x82\xAB\x8D\x9E\x82݂\xCD LogToFile() \x82ōs\x82\xED\x82\xEA\x82\xE9
@@ -1604,13 +1597,13 @@
 		break;
 	case 1:
 		// UTF-16LE
+		LogPut1(0xff);
 		LogPut1(0xfe);
-		LogPut1(0xff);
 		break;
 	case 2:
 		// UTF-16BE
+		LogPut1(0xfe);
 		LogPut1(0xff);
-		LogPut1(0xfe);
 		break;
 	default:
 		break;

Modified: trunk/teraterm/teraterm/filesys_log.h
===================================================================
--- trunk/teraterm/teraterm/filesys_log.h	2020-08-18 15:31:42 UTC (rev 8907)
+++ trunk/teraterm/teraterm/filesys_log.h	2020-08-18 15:31:51 UTC (rev 8908)
@@ -67,6 +67,7 @@
 void FLogSetCode(int code);
 void FLogOutputBOM(void);
 //void LogPut1(BYTE b);
+void FLogOutputAllBuffer(void);
 
 #ifdef __cplusplus
 }

Modified: trunk/teraterm/teraterm/vtwin.cpp
===================================================================
--- trunk/teraterm/teraterm/vtwin.cpp	2020-08-18 15:31:42 UTC (rev 8907)
+++ trunk/teraterm/teraterm/vtwin.cpp	2020-08-18 15:31:51 UTC (rev 8908)
@@ -4142,6 +4142,12 @@
 				if (info.bom) {
 					FLogOutputBOM();
 				}
+				// \x8C\xBB\x8D݃o\x83b\x83t\x83@\x82ɂ\xA0\x82\xE9\x83f\x81[\x83^\x82\xF0\x82\xB7\x82ׂď\x91\x82\xAB\x8Fo\x82\xB5\x82Ă\xA9\x82\xE7\x81A
+				// \x83\x8D\x83O\x8D̎\xE6\x82\xF0\x8AJ\x8En\x82\xB7\x82\xE9\x81B
+				// (2013.9.29 yutaka)
+				if (ts.LogAllBuffIncludedInFirst) {
+					FLogOutputAllBuffer();
+				}
 			}
 		}
 		else {


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