[ttssh2-commit] [10739] ログファイル名に使用できない書式があったので使えるようにした

Back to archive index
scmno****@osdn***** scmno****@osdn*****
2023年 6月 6日 (火) 22:20:12 JST


Revision: 10739
          https://osdn.net/projects/ttssh2/scm/svn/commits/10739
Author:   zmatsuo
Date:     2023-06-06 22:20:12 +0900 (Tue, 06 Jun 2023)
Log Message:
-----------
ログファイル名に使用できない書式があったので使えるようにした

- Visual Studio 2022 の strftime() で使用できる書式を使えるようにした
  - "%C"などが使用できなかった
- コンパイラがVS2015より新しいとき新しい書式が使えるよう修正

ticket #46476

Ticket Links:
------------
    https://osdn.net/projects/ttssh2/tracker/detail/46476

Modified Paths:
--------------
    trunk/teraterm/common/ttlib_static_cpp.cpp

-------------- next part --------------
Modified: trunk/teraterm/common/ttlib_static_cpp.cpp
===================================================================
--- trunk/teraterm/common/ttlib_static_cpp.cpp	2023-06-04 12:28:20 UTC (rev 10738)
+++ trunk/teraterm/common/ttlib_static_cpp.cpp	2023-06-06 13:20:12 UTC (rev 10739)
@@ -1737,6 +1737,31 @@
 	return dest;
 }
 
+/**
+ *	strftime formatting code
+ *
+ *	@retval	TRUE	\x8Eg\x97p\x89”\
+ *	@retval	FALSE	\x8Eg\x97p\x95s\x89\xC2
+ */
+static BOOL IsValidStrftimeCode(const wchar_t c)
+{
+#if !defined(__MINGW32__) && (_MSC_VER >= 1900) // 1900=VS2015
+	// VS2022\x82\xCCstrftime()\x82Ŏg\x82\xA6\x82鏑\x8E\xAE\x8Ew\x92\xE8\x83R\x81[\x83h
+	//	- VS2015-2022\x82̃\x89\x83\x93\x83^\x83C\x83\x80\x82͌݊\xB7\x90\xAB\x82\xAA\x82\xA0\x82\xE9\x82Ǝv\x82\xED\x82\xEA\x82\xE9\x82̂\xC52015\x88ȏ\xE3\x82̂Ƃ\xAB
+	//	- MinGW\x8E\x9E\x82̓\x89\x83\x93\x83^\x83C\x83\x80\x82̃o\x81[\x83W\x83\x87\x83\x93\x82\xAA\x82킩\x82\xE7\x82Ȃ̂ŏ]\x97\x88\x82̏\x91\x8E\xAE\x8Ew\x92\xE8\x83R\x81[\x83h\x82\xF0\x8Eg\x97p\x82\xB7\x82\xE9
+	static const wchar_t strftimeChars[] = L"aAbBcCdDeFgGhHIjmMnprRStTuUVwWxXyYzZ%";
+#else
+	static const wchar_t strftimeChars[] = L"aAbBcdHIjmMpSUwWxXyYzZ%";
+#endif
+
+	if (wcschr(strftimeChars, c) != NULL) {
+		return TRUE;
+	}
+	else {
+		return FALSE;
+	}
+}
+
 // strftime \x82ɓn\x82\xB9\x82Ȃ\xA2\x95\xB6\x8E\x9A\x82\xAA\x8A܂܂\xEA\x82Ă\xA2\x82邩\x8Am\x82\xA9\x82߂\xE9
 BOOL isInvalidStrftimeCharW(const wchar_t *format)
 {
@@ -1750,35 +1775,13 @@
 				if (format[i+2] != 0 && format[i+1] == '#') {
 					p = i+2;
 				}
-				switch (format[p]) {
-					case 'a':
-					case 'A':
-					case 'b':
-					case 'B':
-					case 'c':
-					case 'd':
-					case 'H':
-					case 'I':
-					case 'j':
-					case 'm':
-					case 'M':
-					case 'p':
-					case 'S':
-					case 'U':
-					case 'w':
-					case 'W':
-					case 'x':
-					case 'X':
-					case 'y':
-					case 'Y':
-					case 'z':
-					case 'Z':
-					case '%':
-						i = p;
-						break;
-					default:
-						return TRUE;
+				if (IsValidStrftimeCode(format[p])) {
+					i = p;
 				}
+				else {
+					// \x8Eg\x82\xA6\x82Ȃ\xA2\x8F\x91\x8E\xAE
+					return TRUE;
+				}
 			}
 			else {
 				// % \x82ŏI\x82\xED\x82\xC1\x82Ă\xA2\x82\xE9\x8Fꍇ\x82̓G\x83\x89\x81[\x82Ƃ\xB7\x82\xE9
@@ -1787,73 +1790,51 @@
 		}
 	}
 
-	return FALSE;;
+	return FALSE;
 }
 
 // strftime \x82ɓn\x82\xB9\x82Ȃ\xA2\x95\xB6\x8E\x9A\x82\xF0\x8D폜\x82\xB7\x82\xE9
-void deleteInvalidStrftimeCharW(wchar_t *FName)
+void deleteInvalidStrftimeCharW(wchar_t *format)
 {
 	size_t i, j=0, len, p;
 
-	len = wcslen(FName);
+	len = wcslen(format);
 	for (i=0; i<len; i++) {
-		if (FName[i] == '%') {
-			if (FName[i+1] != 0) {
+		if (format[i] == '%') {
+			if (format[i+1] != 0) {
 				p = i+1;
-				if (FName[i+2] != 0 && FName[i+1] == '#') {
+				if (format[i+2] != 0 && format[i+1] == '#') {
 					p = i+2;
 				}
-				switch (FName[p]) {
-					case 'a':
-					case 'A':
-					case 'b':
-					case 'B':
-					case 'c':
-					case 'd':
-					case 'H':
-					case 'I':
-					case 'j':
-					case 'm':
-					case 'M':
-					case 'p':
-					case 'S':
-					case 'U':
-					case 'w':
-					case 'W':
-					case 'x':
-					case 'X':
-					case 'y':
-					case 'Y':
-					case 'z':
-					case 'Z':
-					case '%':
-						FName[j] = FName[i]; // %
+				if (IsValidStrftimeCode(format[p])) {
+					format[j] = format[i]; // %
+					j++;
+					i++;
+					if (p-i == 2) {
+						format[j] = format[i]; // #
 						j++;
 						i++;
-						if (p-i == 2) {
-							FName[j] = FName[i]; // #
-							j++;
-							i++;
-						}
-						FName[j] = FName[i];
-						j++;
-						break;
-					default:
-						i++; // %
-						if (p-i == 2) {
-							i++; // #
-						}
+					}
+					format[j] = format[i];
+					j++;
 				}
+				else {
+					// \x8Eg\x82\xA6\x82Ȃ\xA2\x8F\x91\x8E\xAE
+					i++; // %
+					if (p-i == 2) {
+						i++; // #
+					}
+				}
 			}
 			// % \x82ŏI\x82\xED\x82\xC1\x82Ă\xA2\x82\xE9\x8Fꍇ\x82̓R\x83s\x81[\x82\xB5\x82Ȃ\xA2
 		}
 		else {
-			FName[j] = FName[i];
+			format[j] = format[i];
 			j++;
 		}
 	}
 
-	FName[j] = 0;
+	format[j] = 0;
 }
 
 /**


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