[Ttssh2-commit] [5165] logrotate マクロコマンドに世代数を指定できるようにした。

svnno****@sourc***** svnno****@sourc*****
2013年 3月 23日 (土) 19:39:50 JST


Revision: 5165
          http://sourceforge.jp/projects/ttssh2/scm/svn/commits/5165
Author:   yutakapon
Date:     2013-03-23 19:39:50 +0900 (Sat, 23 Mar 2013)
Log Message:
-----------
logrotate マクロコマンドに世代数を指定できるようにした。

Modified Paths:
--------------
    trunk/doc/en/html/macro/command/logrotate.html
    trunk/doc/ja/html/macro/command/logrotate.html
    trunk/teraterm/common/ttftypes.h
    trunk/teraterm/teraterm/filesys.cpp
    trunk/teraterm/teraterm/ttdde.c
    trunk/teraterm/ttpmacro/ttl.c

-------------- next part --------------
Modified: trunk/doc/en/html/macro/command/logrotate.html
===================================================================
--- trunk/doc/en/html/macro/command/logrotate.html	2013-03-23 09:32:31 UTC (rev 5164)
+++ trunk/doc/en/html/macro/command/logrotate.html	2013-03-23 10:39:50 UTC (rev 5165)
@@ -18,17 +18,22 @@
 </p>
 
 <pre class="macro-syntax">
-logrotate 'size' &lt;num&gt;
+logrotate 'size' &lt;size&gt;
+logrotate 'rotate' &lt;count&gt;
 logrotate 'halt'
 </pre>
 
 <h2>Parameters</h2>
 
 <dl>
-	<dt class="macro">'size' &lt;num&gt;</dt>
-	<dd>When a log file size is over &lt;num&gt; byte, the log file is be rotated.<br>
-	    The &lt;num&gt; value must be larger than 128.</dd>
+	<dt class="macro">'size' &lt;size&gt;</dt>
+	<dd>When a log file size is over &lt;size&gt; byte, the log file is be rotated.<br>
+	    The &lt;size&gt; value must be larger than 128.</dd>
 
+	<dt class="macro">'rotate' &lt;count&gt;</dt>
+	<dd>Log files are rotated &lt;count&gt; times before being removed.<br>
+	    The &lt;count&gt; value must be larger than 1.</dd>
+
 	<dt class="macro">'halt'</dt>
 	<dd>The log rotation is stopped.</dd>
 </dl>
@@ -36,15 +41,22 @@
 <h2>Example</h2>
 
 <pre class="macro-example">
-getspecialfolder str "Desktop"
+; Open log
+getspecialfolder str "MyDocuments"
 changedir str
 logopen 'teraterm_sample.log' 0 0
+
 ; Start log rotation
 logrotate 'size' 2048
+logrotate 'rotate' 3
+
 pause 600
 ; Stop log rotation
 logrotate 'halt'
+
 pause 600
+
+; Close log
 logclose
 </pre>
 

Modified: trunk/doc/ja/html/macro/command/logrotate.html
===================================================================
--- trunk/doc/ja/html/macro/command/logrotate.html	2013-03-23 09:32:31 UTC (rev 5164)
+++ trunk/doc/ja/html/macro/command/logrotate.html	2013-03-23 10:39:50 UTC (rev 5165)
@@ -18,7 +18,8 @@
 </p>
 
 <pre class="macro-syntax">
-logrotate 'size' &lt;num&gt;
+logrotate 'size' &lt;size&gt;
+logrotate 'rotate' &lt;count&gt;
 logrotate 'halt'
 </pre>
 
@@ -26,10 +27,14 @@
 <h2>\x83p\x83\x89\x83\x81\x81[\x83^</h2>
 
 <dl>
-	<dt class="macro">'size' &lt;num&gt;</dt>
-	<dd>\x83\x8D\x83O\x82̃T\x83C\x83Y\x82\xAA&lt;num&gt;\x83o\x83C\x83g\x82𒴂\xA6\x82Ă\xA2\x82\xEA\x82΁A\x83\x8D\x81[\x83e\x81[\x83V\x83\x87\x83\x93\x82\xF0\x8Ds\x82\xA4\x81B<br>
-	    &lt;num&gt;\x82\xCD128\x88ȏ\xE3\x82ł\xA0\x82邱\x82ƁB</dd>
+	<dt class="macro">'size' &lt;size&gt;</dt>
+	<dd>\x83\x8D\x83O\x82̃T\x83C\x83Y\x82\xAA&lt;size&gt;\x83o\x83C\x83g\x82𒴂\xA6\x82Ă\xA2\x82\xEA\x82΁A\x83\x8D\x81[\x83e\x81[\x83V\x83\x87\x83\x93\x82\xF0\x8Ds\x82\xA4\x81B<br>
+	    &lt;size&gt;\x82\xCD128\x88ȏ\xE3\x82ł\xA0\x82邱\x82ƁB</dd>
 
+	<dt class="macro">'rotate' &lt;count&gt;</dt>
+	<dd>\x83\x8D\x83O\x83t\x83@\x83C\x83\x8B\x82̐\xA2\x91\xE3\x82\xF0&lt;count&gt;\x82ɂ\xB7\x82\xE9\x81B<br>
+	    &lt;count&gt;\x82\xCD1\x88ȏ\xE3\x82ł\xA0\x82邱\x82ƁB</dd>
+
 	<dt class="macro">'halt'</dt>
 	<dd>\x83\x8D\x81[\x83e\x81[\x83V\x83\x87\x83\x93\x82\xF0\x92\xE2\x8E~\x82\xB7\x82\xE9\x81B</dd>
 </dl>
@@ -38,15 +43,22 @@
 <h2>\x97\xE1</h2>
 
 <pre class="macro-example">
-getspecialfolder str "Desktop"
+; Open log
+getspecialfolder str "MyDocuments"
 changedir str
 logopen 'teraterm_sample.log' 0 0
+
 ; Start log rotation
 logrotate 'size' 2048
+logrotate 'rotate' 3
+
 pause 600
 ; Stop log rotation
 logrotate 'halt'
+
 pause 600
+
+; Close log
 logclose
 </pre>
 

Modified: trunk/teraterm/common/ttftypes.h
===================================================================
--- trunk/teraterm/common/ttftypes.h	2013-03-23 09:32:31 UTC (rev 5164)
+++ trunk/teraterm/common/ttftypes.h	2013-03-23 10:39:50 UTC (rev 5165)
@@ -109,6 +109,7 @@
   // log rotate
   enum rotate_mode RotateMode;
   LONG RotateSize;
+  int RotateStep;
 
 } TFileVar;
 typedef TFileVar far *PFileVar;

Modified: trunk/teraterm/teraterm/filesys.cpp
===================================================================
--- trunk/teraterm/teraterm/filesys.cpp	2013-03-23 09:32:31 UTC (rev 5164)
+++ trunk/teraterm/teraterm/filesys.cpp	2013-03-23 10:39:50 UTC (rev 5165)
@@ -655,9 +655,10 @@
 // (2013.3.21 yutaka)
 static void LogRotate(void)
 {
-	const int loopmax = 10000;  // XXX
+	int loopmax = 10000;  // XXX
 	char filename[1024];
-	int i;
+	char newfile[1024], oldfile[1024];
+	int i, k;
 	int dwShareMode = 0;
 
 	if (! LogVar->FileOpen) return;
@@ -680,17 +681,32 @@
 	// \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++) {
+	// \x90\xA2\x91ネ\x81[\x83e\x81[\x83V\x83\x87\x83\x93\x82̃X\x83e\x83b\x83v\x90\x94\x82̎w\x92肪\x82\xA0\x82邩
+	if (LogVar->RotateStep > 0)
+		loopmax = LogVar->RotateStep;
+
+	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:
+	if (i > loopmax) {
+		// \x90\xA2\x91オ\x82\xA2\x82\xC1\x82ς\xA2\x82ɂȂ\xC1\x82\xBD\x82\xE7\x81A\x8DŌẪt\x83@\x83C\x83\x8B\x82\xA9\x82\xE7\x94p\x8A\xFC\x82\xB7\x82\xE9\x81B
+		i = loopmax;
 	}
 
 	// \x95ʃt\x83@\x83C\x83\x8B\x82Ƀ\x8A\x83l\x81[\x83\x80\x81B
-	rename(LogVar->FullName, filename);
+	for (k = i-1 ; k >= 0 ; k--) {
+		if (k == 0)
+			strncpy_s(oldfile, sizeof(oldfile), LogVar->FullName, _TRUNCATE);
+		else
+			_snprintf_s(oldfile, sizeof(oldfile), _TRUNCATE, "%s.%d", LogVar->FullName, k);
+		_snprintf_s(newfile, sizeof(newfile), _TRUNCATE, "%s.%d", LogVar->FullName, k+1);
+		remove(newfile);
+		if (rename(oldfile, newfile) != 0) {
+			OutputDebugPrintf("%s: rename %d\n", __FUNCTION__, errno);
+		}
+	}
 
 	// \x8DăI\x81[\x83v\x83\x93
 	if (ts.LogLockExclusive) {

Modified: trunk/teraterm/teraterm/ttdde.c
===================================================================
--- trunk/teraterm/teraterm/ttdde.c	2013-03-23 09:32:31 UTC (rev 5164)
+++ trunk/teraterm/teraterm/ttdde.c	2013-03-23 10:39:50 UTC (rev 5165)
@@ -518,8 +518,14 @@
 				LogVar->RotateMode = ROTATE_SIZE;
 				LogVar->RotateSize = s;
 
+			} else if (strncmp(p, "rotate", 6) == 0) {
+				s = atoi(&p[7]);
+				LogVar->RotateStep = s;
+
 			} else if (strncmp(p, "halt", 4) == 0) {
 				LogVar->RotateMode = ROTATE_NONE;
+				LogVar->RotateSize = 0;
+				LogVar->RotateStep = 0;
 			}
 		}
 		break;

Modified: trunk/teraterm/ttpmacro/ttl.c
===================================================================
--- trunk/teraterm/ttpmacro/ttl.c	2013-03-23 09:32:31 UTC (rev 5164)
+++ trunk/teraterm/ttpmacro/ttl.c	2013-03-23 10:39:50 UTC (rev 5165)
@@ -2864,6 +2864,7 @@
 
 //
 // logrotate size value
+// logrotate rotate num
 // logrotate halt
 //
 WORD TTLLogRotate() 
@@ -2871,7 +2872,7 @@
 	WORD Err;
 	char Str[MaxStrLen];
 	char buf[MaxStrLen*2];
-	int size;
+	int size, num;
 
 	Err = 0;
 	GetStrVal(Str, &Err);
@@ -2880,7 +2881,7 @@
 	if (Err!=0) return Err;
 
 	Err = ErrSyntax;
-	if (strcmp(Str, "size") == 0) {
+	if (strcmp(Str, "size") == 0) {   // \x83\x8D\x81[\x83e\x81[\x83g\x83T\x83C\x83Y
 		if (CheckParameterGiven()) {
 			Err = 0;
 			size = 0;
@@ -2891,6 +2892,17 @@
 				_snprintf_s(buf, sizeof(buf), _TRUNCATE, "%s %u", Str, size);
 		}
 
+	} else if (strcmp(Str, "rotate") == 0) {  // \x83\x8D\x81[\x83e\x81[\x83g\x82̐\xA2\x91㐔
+		if (CheckParameterGiven()) {
+			Err = 0;
+			num = 0;
+			GetIntVal(&num, &Err);
+			if (num <= 0)
+				Err = ErrSyntax;
+			if (Err == 0)
+				_snprintf_s(buf, sizeof(buf), _TRUNCATE, "%s %u", Str, num);
+		}
+
 	} else if (strcmp(Str, "halt") == 0) {
 		Err = 0;
 		_snprintf_s(buf, sizeof(buf), _TRUNCATE, "%s", Str);



Ttssh2-commit メーリングリストの案内