[Ttssh2-commit] [6767] ログのタイムスタンプのフォーマットを指定できるようにした

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2017年 6月 4日 (日) 21:54:47 JST


Revision: 6767
          http://sourceforge.jp/projects/ttssh2/scm/svn/commits/6767
Author:   maya
Date:     2017-06-04 21:54:47 +0900 (Sun, 04 Jun 2017)
Log Message:
-----------
ログのタイムスタンプのフォーマットを指定できるようにした

https://osdn.net/ticket/browse.php?group_id=1412&tid=36971

Modified Paths:
--------------
    trunk/installer/release/TERATERM.INI
    trunk/teraterm/common/ttlib.c
    trunk/teraterm/common/ttlib.h
    trunk/teraterm/common/tttypes.h
    trunk/teraterm/teraterm/filesys.cpp
    trunk/teraterm/ttpset/ttset.c

-------------- next part --------------
Modified: trunk/installer/release/TERATERM.INI
===================================================================
--- trunk/installer/release/TERATERM.INI	2017-06-02 16:10:58 UTC (rev 6766)
+++ trunk/installer/release/TERATERM.INI	2017-06-04 12:54:47 UTC (rev 6767)
@@ -538,6 +538,11 @@
 ; Lock Terminal Unique ID
 LockTUID=on
 
+; Timestamp format of Log each line
+;   %a %b %e %H:%M:%S.%N %Y ... Sun Jun  4 21:12:40.123 JST 2017
+;   %Y/%m/%d %H:%M:%S.%N    ... 2017/06/04 21:12:40.123
+LogTimestampFormat=%a %b %e %H:%M:%S.%N %Y
+
 ; Exclusive lock for log file
 LogLockExclusive=on
 

Modified: trunk/teraterm/common/ttlib.c
===================================================================
--- trunk/teraterm/common/ttlib.c	2017-06-02 16:10:58 UTC (rev 6766)
+++ trunk/teraterm/common/ttlib.c	2017-06-04 12:54:47 UTC (rev 6767)
@@ -1460,25 +1460,92 @@
 	return Table[lang][kcode];
 }
 
-char *mctimelocal()
+char *mctimelocal(char *format)
 {
-	SYSTEMTIME LocalTime;
+	SYSTEMTIME systime;
 	static char strtime[29];
 	char week[][4] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
 	char month[][4] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
 	                   "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
+	char tmp[5];
+	unsigned int i = strlen(format);
 
-	GetLocalTime(&LocalTime);
-	_snprintf_s(strtime, sizeof(strtime), _TRUNCATE,
-	            "%s %s %02d %02d:%02d:%02d.%03d %04d",
-	            week[LocalTime.wDayOfWeek],
-	            month[LocalTime.wMonth-1],
-	            LocalTime.wDay,
-	            LocalTime.wHour,
-	            LocalTime.wMinute,
-	            LocalTime.wSecond,
-	            LocalTime.wMilliseconds,
-	            LocalTime.wYear);
+	GetLocalTime(&systime);
+	memset(strtime, 0, sizeof(strtime));
+	for (i=0; i<strlen(format); i++) {
+		if (format[i] == '%') {
+			char c = format[i + 1];
+			switch (c) {
+				case 'a':
+					_snprintf_s(tmp, sizeof(tmp), _TRUNCATE, "%s", week[systime.wDayOfWeek]);
+					strncat_s(strtime, sizeof(strtime), tmp, _TRUNCATE);
+					i++;
+					break;
+				case 'b':
+					_snprintf_s(tmp, sizeof(tmp), _TRUNCATE, "%s", month[systime.wMonth - 1]);
+					strncat_s(strtime, sizeof(strtime), tmp, _TRUNCATE);
+					i++;
+					break;
+				case 'd':
+					_snprintf_s(tmp, sizeof(tmp), _TRUNCATE, "%02d", systime.wDay);
+					strncat_s(strtime, sizeof(strtime), tmp, _TRUNCATE);
+					i++;
+					break;
+				case 'e':
+					_snprintf_s(tmp, sizeof(tmp), _TRUNCATE, "%2d", systime.wDay);
+					strncat_s(strtime, sizeof(strtime), tmp, _TRUNCATE);
+					i++;
+					break;
+				case 'H':
+					_snprintf_s(tmp, sizeof(tmp), _TRUNCATE, "%02d", systime.wHour);
+					strncat_s(strtime, sizeof(strtime), tmp, _TRUNCATE);
+					i++;
+					break;
+				case 'N':
+					_snprintf_s(tmp, sizeof(tmp), _TRUNCATE, "%03d", systime.wMilliseconds);
+					strncat_s(strtime, sizeof(strtime), tmp, _TRUNCATE);
+					i++;
+					break;
+				case 'm':
+					_snprintf_s(tmp, sizeof(tmp), _TRUNCATE, "%02d", systime.wMonth);
+					strncat_s(strtime, sizeof(strtime), tmp, _TRUNCATE);
+					i++;
+					break;
+				case 'M':
+					_snprintf_s(tmp, sizeof(tmp), _TRUNCATE, "%02d", systime.wMinute);
+					strncat_s(strtime, sizeof(strtime), tmp, _TRUNCATE);
+					i++;
+					break;
+				case 'S':
+					_snprintf_s(tmp, sizeof(tmp), _TRUNCATE, "%02d", systime.wSecond);
+					strncat_s(strtime, sizeof(strtime), tmp, _TRUNCATE);
+					i++;
+					break;
+				case 'w':
+					_snprintf_s(tmp, sizeof(tmp), _TRUNCATE, "%d", systime.wDayOfWeek);
+					strncat_s(strtime, sizeof(strtime), tmp, _TRUNCATE);
+					i++;
+					break;
+				case 'Y':
+					_snprintf_s(tmp, sizeof(tmp), _TRUNCATE, "%04d", systime.wYear);
+					strncat_s(strtime, sizeof(strtime), tmp, _TRUNCATE);
+					i++;
+					break;
+				case '%':
+					strncat_s(strtime, sizeof(strtime), "%", _TRUNCATE);
+					i++;
+					break;
+				default:
+					_snprintf_s(tmp, sizeof(tmp), _TRUNCATE, "%c", format[i]);
+					strncat_s(strtime, sizeof(strtime), tmp, _TRUNCATE);
+					break;
+			}
+		}
+		else {
+			_snprintf_s(tmp, sizeof(tmp), _TRUNCATE, "%c", format[i]);
+			strncat_s(strtime, sizeof(strtime), tmp, _TRUNCATE);
+		}
+	}
 
 	return strtime;
 }

Modified: trunk/teraterm/common/ttlib.h
===================================================================
--- trunk/teraterm/common/ttlib.h	2017-06-02 16:10:58 UTC (rev 6766)
+++ trunk/teraterm/common/ttlib.h	2017-06-04 12:54:47 UTC (rev 6767)
@@ -63,7 +63,7 @@
 int KanjiCode2List(int lang, int kcode);
 int List2KanjiCode(int lang, int kcode);
 int KanjiCodeTranslate(int lang, int kcode);
-char *mctimelocal();
+char *mctimelocal(char *format);
 
 void b64encode(PCHAR dst, int dsize, PCHAR src, int len);
 int b64decode(PCHAR dst, int dsize, PCHAR src);

Modified: trunk/teraterm/common/tttypes.h
===================================================================
--- trunk/teraterm/common/tttypes.h	2017-06-02 16:10:58 UTC (rev 6766)
+++ trunk/teraterm/common/tttypes.h	2017-06-04 12:54:47 UTC (rev 6767)
@@ -619,6 +619,7 @@
 	int ZmodemTimeOutFin;
 	WORD WaitCom;
 	WORD Dummy5;	// \x8B\x8CTrimTrailingNLonPaste. PasteFlag\x82ɓ\x9D\x8D\x87\x82\xB5\x82\xBD\x88הp\x8E~\x81B\x91\xBC\x82֓]\x97p
+	char LogTimestampFormat[48];
 };
 
 typedef struct tttset TTTSet, *PTTSet;
@@ -1081,6 +1082,9 @@
  * Increment the number of this macro value
  * when you change TMap or member of TMap.
  *
+ * - At version 4.96, ttset_memfilemap was replaced with ttset_memfilemap_32.
+ *   added tttset.LogTimestampFormat
+ *
  * - At version 4.95, ttset_memfilemap was replaced with ttset_memfilemap_31.
  *   added tttset.NotifyClipboardAccess
  *
@@ -1262,4 +1266,4 @@
  *   added tttset.VTCompatTab.
  */
 
-#define TT_FILEMAPNAME "ttset_memfilemap_31"
+#define TT_FILEMAPNAME "ttset_memfilemap_32"

Modified: trunk/teraterm/teraterm/filesys.cpp
===================================================================
--- trunk/teraterm/teraterm/filesys.cpp	2017-06-02 16:10:58 UTC (rev 6766)
+++ trunk/teraterm/teraterm/filesys.cpp	2017-06-04 12:54:47 UTC (rev 6767)
@@ -957,7 +957,7 @@
 			{
 				tmp[0] = 0;
 				if ( ts.LogTimestamp && eLineEnd ) {
-					char *strtime = mctimelocal();
+					char *strtime = mctimelocal(ts.LogTimestampFormat);
 					/* 2007.05.24 Gentaro */
 					if( eLineEnd == Line_FileHead ){
 						strncat_s(tmp, sizeof(tmp), "\r\n", _TRUNCATE);
@@ -1012,7 +1012,7 @@
 							LocalTime.wHour, LocalTime.wMinute, LocalTime.wSecond,
 							LocalTime.wMilliseconds);
 	#else
-					char *strtime = mctimelocal();
+					char *strtime = mctimelocal(ts.LogTimestampFormat);
 	#endif
 	#else
 						time_t tick = time(NULL);

Modified: trunk/teraterm/ttpset/ttset.c
===================================================================
--- trunk/teraterm/ttpset/ttset.c	2017-06-02 16:10:58 UTC (rev 6766)
+++ trunk/teraterm/ttpset/ttset.c	2017-06-04 12:54:47 UTC (rev 6767)
@@ -1052,6 +1052,11 @@
 
 	ts->LogAllBuffIncludedInFirst = GetOnOff(Section, "LogIncludeScreenBuffer", FName, FALSE);
 
+	/* Timestamp format of Log each line */
+	GetPrivateProfileString(Section, "LogTimestampFormat", "%a %b %e %H:%M:%S.%N %Y",
+	                        ts->LogTimestampFormat, sizeof(ts->LogTimestampFormat),
+	                        FName);
+
 	/* File Transfer dialog visibility */
 	ts->FTHideDialog = GetOnOff(Section, "FTHideDialog", FName, FALSE);
 
@@ -2531,6 +2536,10 @@
 
 	WriteOnOff(Section, "LogIncludeScreenBuffer", FName, ts->LogAllBuffIncludedInFirst);
 
+	/* Timestamp format of Log each line */
+	WritePrivateProfileString(Section, "LogTimestampFormat",
+	                          ts->LogTimestampFormat, FName);
+
 	/* Default Log file name (2006.8.28 maya) */
 	WritePrivateProfileString(Section, "LogDefaultName",
 	                          ts->LogDefaultName, FName);



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