[Ttssh2-commit] [3369] 送信文字列に使えるエスケープシーケンスを追加

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2009年 4月 30日 (木) 00:07:54 JST


Revision: 3369
          http://svn.sourceforge.jp/view?root=ttssh2&view=rev&rev=3369
Author:   doda
Date:     2009-04-30 00:07:54 +0900 (Thu, 30 Apr 2009)

Log Message:
-----------
送信文字列に使えるエスケープシーケンスを追加
  \ooo -- 8進数値指定(最大3桁)
  \xhh -- 16進数値指定(2桁固定)

8進数値指定をサポートしたため、\0の扱いが変わる。
今までは \012 は NUL 1 2 となったが、これからは LF として解釈される。
\0の後ろに数字が来ない場合は共にNULとして解釈される。

Modified Paths:
--------------
    trunk/TTXSamples/TTXRecurringCommand/TTXRecurringCommand.c


-------------- next part --------------
Modified: trunk/TTXSamples/TTXRecurringCommand/TTXRecurringCommand.c
===================================================================
--- trunk/TTXSamples/TTXRecurringCommand/TTXRecurringCommand.c	2009-04-29 09:08:26 UTC (rev 3368)
+++ trunk/TTXSamples/TTXRecurringCommand/TTXRecurringCommand.c	2009-04-29 15:07:54 UTC (rev 3369)
@@ -1,3 +1,4 @@
+#include <ctype.h>
 #include "teraterm.h"
 #include "tttypes.h"
 #include "ttplugin.h"
@@ -31,8 +32,8 @@
 	int interval;
 	BOOL enable;
 	int cmdLen;
-	char command[50];
-	char orgCommand[50];
+	unsigned char command[50];
+	unsigned char orgCommand[50];
 } TInstVar;
 
 typedef TInstVar FAR * PTInstVar;
@@ -87,18 +88,18 @@
 // \n, \t“™‚ð“WŠJ‚·‚éB
 // common/ttlib.c:RestoreNewLine()‚ªƒx[ƒXB
 //
-void RestoreNewLine(PCHAR Text)
+void UnEscapeStr(BYTE *Text)
 {
-	unsigned int i, j=0;
+	unsigned int i, j=0, k;
 	size_t size;
-	char *buf;
+	unsigned char *buf;
 
 	size = strlen(Text);
 	buf = malloc(size+1);
 
 	memset(buf, 0, size+1);
 	for (i=0; i<size; i++) {
-		if (Text[i] == '\\' && i<size ) {
+		if (Text[i] == '\\') {
 			switch (Text[i+1]) {
 				case '\\':
 					buf[j] = '\\';
@@ -136,9 +137,43 @@
 					buf[j] = '\033';
 					i++;
 					break;
+				case 'x':
+					if (isxdigit(Text[i+2]) && isxdigit(Text[i+3])) {
+						i+=2;
+						// buf[j] = ((Text[i]|0x20) - (isalpha(Text[i])?'a'-10:'0')) << 4;
+						if (isalpha(Text[i]))
+							buf[j] = (Text[i]|0x20) - 'a' + 10;
+						else
+							buf[j] = Text[i] - '0';
+						buf[j] <<= 4;
+
+						i++;
+						// buf[j] += ((Text[i]|0x20) - (isalpha(Text[i])?'a'-10:'0'));
+						if (isalpha(Text[i]))
+							buf[j] += (Text[i]|0x20) - 'a' + 10;
+						else
+							buf[j] += Text[i] - '0';
+					}
+					else {
+						buf[j++] = '\\';
+						buf[j] = 'x';
+						i++;
+					}
+					break;
 				case '0':
-					buf[j] = '\0';
-					i++;
+				case '1':
+				case '2':
+				case '3':
+				case '4':
+				case '5':
+				case '6':
+				case '7':
+					buf[j] = 0;
+					for (k=0; k<3; k++, i++) {
+						if (Text[i+1] < '0' || Text[i+1] > '7')
+							break;
+						buf[j] = (buf[j] << 3) + Text[i+1] - '0';
+					}
 					break;
 				default:
 					buf[j] = '\\';
@@ -311,7 +346,7 @@
 
 	GetPrivateProfileString(SECTION, "Command", "", pvar->orgCommand, sizeof(pvar->orgCommand), fn);
 	strncpy_s(pvar->command, sizeof(pvar->command), pvar->orgCommand, _TRUNCATE);
-	RestoreNewLine(pvar->command);
+	UnEscapeStr(pvar->command);
 	pvar->cmdLen = (int)strlen(pvar->command);
 
 	pvar->interval = GetPrivateProfileInt(SECTION, "Interval", DEFAULT_INTERVAL, fn);
@@ -383,7 +418,7 @@
 
 			GetDlgItemText(dlg, IDC_COMMAND, pvar->orgCommand, sizeof(pvar->orgCommand));
 			strncpy_s(pvar->command, sizeof(pvar->command), pvar->orgCommand, _TRUNCATE);
-			RestoreNewLine(pvar->command);
+			UnEscapeStr(pvar->command);
 			pvar->cmdLen = (int)strlen(pvar->command);
 
 			if (pvar->cv->Ready) {



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