[Ttssh2-commit] [5162] logrotate マクロコマンドを追加した。

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2013年 3月 23日 (土) 18:03:14 JST


Revision: 5162
          http://sourceforge.jp/projects/ttssh2/scm/svn/commits/5162
Author:   yutakapon
Date:     2013-03-23 18:03:14 +0900 (Sat, 23 Mar 2013)
Log Message:
-----------
logrotate マクロコマンドを追加した。

logrotate 'size' 2048
logrotate 'halt'

Modified Paths:
--------------
    trunk/teraterm/common/helpid.h
    trunk/teraterm/common/ttftypes.h
    trunk/teraterm/teraterm/filesys.cpp
    trunk/teraterm/teraterm/ttdde.c
    trunk/teraterm/ttpmacro/ttl.c
    trunk/teraterm/ttpmacro/ttmdde.h
    trunk/teraterm/ttpmacro/ttmparse.c
    trunk/teraterm/ttpmacro/ttmparse.h

-------------- next part --------------
Modified: trunk/teraterm/common/helpid.h
===================================================================
--- trunk/teraterm/common/helpid.h	2013-03-22 21:03:32 UTC (rev 5161)
+++ trunk/teraterm/common/helpid.h	2013-03-23 09:03:14 UTC (rev 5162)
@@ -249,6 +249,7 @@
 #define HlpMacroCommandLoginfo          92152
 #define HlpMacroCommandLogopen          92060
 #define HlpMacroCommandLogpause         92061
+#define HlpMacroCommandLogrotate        92201
 #define HlpMacroCommandLogstart         92062
 #define HlpMacroCommandLogwrite         92063
 #define HlpMacroCommandLoop             92127

Modified: trunk/teraterm/common/ttftypes.h
===================================================================
--- trunk/teraterm/common/ttftypes.h	2013-03-22 21:03:32 UTC (rev 5161)
+++ trunk/teraterm/common/ttftypes.h	2013-03-23 09:03:14 UTC (rev 5162)
@@ -63,6 +63,12 @@
 #define TitQVRcv    "Quick-VAN Receive"
 #define TitQVSend   "Quick-VAN Send"
 
+// log rotate mode
+enum rotate_mode {
+	ROTATE_NONE,
+	ROTATE_SIZE
+};
+
 typedef struct {
   HWND HMainWin;
   HWND HWin;
@@ -99,6 +105,11 @@
   int ProgStat;
 
   DWORD StartTime;
+
+  // log rotate
+  enum rotate_mode RotateMode;
+  LONG RotateSize;
+
 } TFileVar;
 typedef TFileVar far *PFileVar;
 

Modified: trunk/teraterm/teraterm/filesys.cpp
===================================================================
--- trunk/teraterm/teraterm/filesys.cpp	2013-03-22 21:03:32 UTC (rev 5161)
+++ trunk/teraterm/teraterm/filesys.cpp	2013-03-23 09:03:14 UTC (rev 5162)
@@ -22,6 +22,8 @@
 #include "filesys.h"
 #include "ftlib.h"
 
+#include <io.h>
+
 #define FS_BRACKET_NONE  0
 #define FS_BRACKET_START 1
 #define FS_BRACKET_END   2
@@ -530,6 +532,8 @@
 	}
 	LogVar->ByteCount = 0;
 
+	LogVar->RotateMode = ROTATE_NONE;
+
 	if (! OpenFTDlg(LogVar)) {
 		FileTransEnd(OpLog);
 		return FALSE;
@@ -647,6 +651,58 @@
 	logfile_unlock();
 }
 
+// \x83\x8D\x83O\x82\xF0\x83\x8D\x81[\x83e\x81[\x83g\x82\xB7\x82\xE9\x81B
+// (2013.3.21 yutaka)
+static void LogRotate(void)
+{
+	const int loopmax = 10000;  // XXX
+	char filename[1024];
+	int i;
+	int dwShareMode = 0;
+
+	if (! LogVar->FileOpen) return;
+
+	if (LogVar->RotateMode == ROTATE_NONE)
+		return;
+
+	if (LogVar->RotateMode == ROTATE_SIZE) {
+		if (LogVar->ByteCount <= LogVar->RotateSize) 
+			return;
+		//OutputDebugPrintf("%s: mode %d size %ld\n", __FUNCTION__, LogVar->RotateMode, LogVar->ByteCount);
+	} else {
+		return;
+	}
+
+	logfile_lock();
+	// \x83\x8D\x83O\x83T\x83C\x83Y\x82\xF0\x8Dď\x89\x8A\x{227B0B7}\x82\xE9\x81B
+	LogVar->ByteCount = 0;
+
+	// \x82\xA2\x82\xC1\x82\xBD\x82񍡂̃t\x83@\x83C\x83\x8B\x82\xF0\x83N\x83\x8D\x81[\x83Y\x82\xB5\x82āA\x95ʖ\xBC\x82̃t\x83@\x83C\x83\x8B\x82\xF0\x83I\x81[\x83v\x83\x93\x82\xB7\x82\xE9\x81B
+	_lclose(LogVar->FileHandle);
+
+	for (i = 1 ; i < loopmax ; i++) {
+		_snprintf_s(filename, sizeof(filename), _TRUNCATE, "%s.%d", LogVar->FullName, i);
+		if (_access_s(filename, 0) != 0)
+			break;
+	}
+	if (i >= loopmax) {
+		// TODO:
+	}
+
+	// \x95ʃt\x83@\x83C\x83\x8B\x82Ƀ\x8A\x83l\x81[\x83\x80\x81B
+	rename(LogVar->FullName, filename);
+
+	// \x8DăI\x81[\x83v\x83\x93
+	if (ts.LogLockExclusive) {
+		dwShareMode = FILE_SHARE_READ;
+	}
+	LogVar->FileHandle = (int)CreateFile(LogVar->FullName, GENERIC_WRITE, dwShareMode, NULL,
+	                                     CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
+
+	logfile_unlock();
+
+}
+
 void LogToFile()
 {
 	PCHAR Buf;
@@ -738,6 +794,10 @@
 	if (((cv.FilePause & OpLog) !=0) || cv.ProtoFlag) return;
 	if (FLogDlg!=NULL)
 		FLogDlg->RefreshNum();
+
+	// \x83\x8D\x83O\x81E\x83\x8D\x81[\x83e\x81[\x83g
+	LogRotate();
+
 }
 
 BOOL CreateLogBuf()

Modified: trunk/teraterm/teraterm/ttdde.c
===================================================================
--- trunk/teraterm/teraterm/ttdde.c	2013-03-22 21:03:32 UTC (rev 5161)
+++ trunk/teraterm/teraterm/ttdde.c	2013-03-23 09:03:14 UTC (rev 5162)
@@ -337,6 +337,7 @@
 #define CmdYmodemRecv   'T'
 #define CmdDispStr      'U'
 #define CmdLogInfo      'V'
+#define CmdLogRotate    'W'
 
 HDDEDATA AcceptExecute(HSZ TopicHSz, HDDEDATA Data)
 {
@@ -506,6 +507,23 @@
 		strncpy_s(ts.KeyCnfFN, sizeof(ts.KeyCnfFN),ParamFileName, _TRUNCATE);
 		PostMessage(HVTWin,WM_USER_ACCELCOMMAND,IdCmdLoadKeyMap,0);
 		break;
+
+	case CmdLogRotate:
+		if (LogVar != NULL) {
+			char *p = ParamFileName;
+			int s;
+
+			if (strncmp(p, "size", 4) == 0) {
+				s = atoi(&p[5]);
+				LogVar->RotateMode = ROTATE_SIZE;
+				LogVar->RotateSize = s;
+
+			} else if (strncmp(p, "halt", 4) == 0) {
+				LogVar->RotateMode = ROTATE_NONE;
+			}
+		}
+		break;
+
 	case CmdLogClose:
 		if (LogVar != NULL) FileTransEnd(OpLog);
 		break;

Modified: trunk/teraterm/ttpmacro/ttl.c
===================================================================
--- trunk/teraterm/ttpmacro/ttl.c	2013-03-22 21:03:32 UTC (rev 5161)
+++ trunk/teraterm/ttpmacro/ttl.c	2013-03-23 09:03:14 UTC (rev 5162)
@@ -2862,6 +2862,47 @@
 	return Err;
 }
 
+//
+// logrotate size value
+// logrotate halt
+//
+WORD TTLLogRotate() 
+{
+	WORD Err;
+	char Str[MaxStrLen];
+	char buf[MaxStrLen*2];
+	int size;
+
+	Err = 0;
+	GetStrVal(Str, &Err);
+	if ((Err==0) && (! Linked))
+		Err = ErrLinkFirst;
+	if (Err!=0) return Err;
+
+	Err = ErrSyntax;
+	if (strcmp(Str, "size") == 0) {
+		if (CheckParameterGiven()) {
+			Err = 0;
+			size = 0;
+			GetIntVal(&size, &Err);
+			if (size < 128)
+				Err = ErrSyntax;
+			if (Err == 0)
+				_snprintf_s(buf, sizeof(buf), _TRUNCATE, "%s %u", Str, size);
+		}
+
+	} else if (strcmp(Str, "halt") == 0) {
+		Err = 0;
+		_snprintf_s(buf, sizeof(buf), _TRUNCATE, "%s", Str);
+	} 
+	if (Err!=0) return Err;
+
+	SetFile(buf);
+	Err = SendCmnd(CmdLogRotate, 0);
+
+	return Err;
+}
+
 WORD TTLLogInfo() 
 {
 	WORD Err;
@@ -5407,6 +5448,8 @@
 			Err = TTLLogOpen(); break;
 		case RsvLogPause:
 			Err = TTLCommCmd(CmdLogPause,0); break;
+		case RsvLogRotate:
+			Err = TTLLogRotate(); break;
 		case RsvLogStart:
 			Err = TTLCommCmd(CmdLogStart,0); break;
 		case RsvLogWrite:

Modified: trunk/teraterm/ttpmacro/ttmdde.h
===================================================================
--- trunk/teraterm/ttpmacro/ttmdde.h	2013-03-22 21:03:32 UTC (rev 5161)
+++ trunk/teraterm/ttpmacro/ttmdde.h	2013-03-23 09:03:14 UTC (rev 5162)
@@ -60,6 +60,7 @@
 #define CmdYmodemRecv   'T'
 #define CmdDispStr      'U'
 #define CmdLogInfo      'V'
+#define CmdLogRotate    'W'
 
 #ifdef __cplusplus
 extern "C" {

Modified: trunk/teraterm/ttpmacro/ttmparse.c
===================================================================
--- trunk/teraterm/ttpmacro/ttmparse.c	2013-03-22 21:03:32 UTC (rev 5161)
+++ trunk/teraterm/ttpmacro/ttmparse.c	2013-03-23 09:03:14 UTC (rev 5162)
@@ -257,6 +257,7 @@
 		else if (_stricmp(Str,"loginfo")==0) *WordId = RsvLogInfo;
 		else if (_stricmp(Str,"logopen")==0) *WordId = RsvLogOpen;
 		else if (_stricmp(Str,"logpause")==0) *WordId = RsvLogPause;
+		else if (_stricmp(Str,"logrotate")==0) *WordId = RsvLogRotate;
 		else if (_stricmp(Str,"logstart")==0) *WordId = RsvLogStart;
 		else if (_stricmp(Str,"logwrite")==0) *WordId = RsvLogWrite;
 		else if (_stricmp(Str,"loop")==0) *WordId = RsvLoop;

Modified: trunk/teraterm/ttpmacro/ttmparse.h
===================================================================
--- trunk/teraterm/ttpmacro/ttmparse.h	2013-03-22 21:03:32 UTC (rev 5161)
+++ trunk/teraterm/ttpmacro/ttmparse.h	2013-03-23 09:03:14 UTC (rev 5162)
@@ -227,6 +227,7 @@
 #define RsvListBox      198
 #define RsvGetIPv4Addr  199
 #define RsvGetIPv6Addr  200
+#define RsvLogRotate    201
 
 #define RsvOperator     1000
 #define RsvBNot         1001



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