[Ttssh2-commit] [6140] パラメータの Dequote を変更。パラメータの途中から quote を行えるようにした。

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2015年 11月 16日 (月) 20:58:56 JST


Revision: 6140
          http://sourceforge.jp/projects/ttssh2/scm/svn/commits/6140
Author:   doda
Date:     2015-11-16 20:58:56 +0900 (Mon, 16 Nov 2015)
Log Message:
-----------
パラメータの Dequote を変更。パラメータの途中から quote を行えるようにした。
[ttssh2-devel 2738], https://osdn.jp/ticket/browse.php?group_id=1412&tid=35713

Modified Paths:
--------------
    trunk/TTXSamples/TTXRecurringCommand/TTXRecurringCommand.c
    trunk/teraterm/common/ttlib.c
    trunk/teraterm/ttpmacro/ttmdlg.cpp
    trunk/teraterm/ttpset/ttset.c
    trunk/ttssh2/ttxssh/ttxssh.c

-------------- next part --------------
Modified: trunk/TTXSamples/TTXRecurringCommand/TTXRecurringCommand.c
===================================================================
--- trunk/TTXSamples/TTXRecurringCommand/TTXRecurringCommand.c	2015-11-15 18:13:06 UTC (rev 6139)
+++ trunk/TTXSamples/TTXRecurringCommand/TTXRecurringCommand.c	2015-11-16 11:58:56 UTC (rev 6140)
@@ -387,15 +387,14 @@
 
 static void PASCAL FAR TTXParseParam(PCHAR Param, PTTSet ts, PCHAR DDETopic) {
 	char buff[1024];
-	char option2[1024];
 	PCHAR next;
 	pvar->origParseParam(Param, ts, DDETopic);
 
 	next = Param;
 	while (next = GetParam(buff, sizeof(buff), next)) {
+		DequoteParam(buff, sizeof(buff), buff);
 		if (_strnicmp(buff, "/F=", 3) == 0) {
-			DequoteParam(option2, sizeof(option2), buff + 3);
-			ReadINI(option2, ts);
+			ReadINI(buff+3, ts);
 		}
 	}
 

Modified: trunk/teraterm/common/ttlib.c
===================================================================
--- trunk/teraterm/common/ttlib.c	2015-11-15 18:13:06 UTC (rev 6139)
+++ trunk/teraterm/common/ttlib.c	2015-11-16 11:58:56 UTC (rev 6140)
@@ -1097,58 +1097,37 @@
 
 void FAR PASCAL DequoteParam(PCHAR dest, int dest_len, PCHAR src)
 {
-	int i, j;
-	char q, c;
+	BOOL quoted = FALSE;
+	PCHAR dest_end = dest + dest_len - 1;
 
-	dest[0] = 0;
-	if (src[0] == 0)
-		return;
-	i = 0;
-	/* quoting char */
-	q = src[i];
-	/* only '"' is used as quoting char */
-	if (q == '"')
-		i++;
+	if (src == dest) {
+		while (*src != '\0' && *src != '"' && dest < dest_end) {
+			src++; dest++;
+		}
+	}
 
-	c = src[i];
-	i++;
-	j = 0;
-	while (c != 0 && j<dest_len) {
-		if (c != '"') {
-			dest[j] = c;
-			j++;
+	while (*src != '\0' && dest < dest_end) {
+		if (*src != '"' || (*++src == '"' && quoted)) {
+			*dest++ = *src++;
 		}
 		else {
-			if (q == '"' && src[i] == '"') {
-				dest[j] = c;
-				j++;
-				i++;
-			}
-			else if (q == '"' && src[i] == '\0') {
-				break;
-			}
-			else {
-				dest[j] = c;
-				j++;
-			}
+			quoted = !quoted;
 		}
-		c = src[i];
-		i++;
 	}
 
-	dest[j] = 0;
+	*dest = '\0';
 }
 
 void FAR PASCAL DeleteComment(PCHAR dest, int dest_size, PCHAR src)
 {
 	BOOL quoted = FALSE;
-	PCHAR tail = dest + dest_size - 1;
+	PCHAR dest_end = dest + dest_size - 1;
 
-	while (*src != '\0' && dest < tail && (quoted || *src != ';')) {
+	while (*src != '\0' && dest < dest_end && (quoted || *src != ';')) {
 		*dest++ = *src;
 
 		if (*src++ == '"') {
-			if (*src == '"' && dest < tail) {
+			if (*src == '"' && dest < dest_end) {
 				*dest++ = *src++;
 			}
 			else {

Modified: trunk/teraterm/ttpmacro/ttmdlg.cpp
===================================================================
--- trunk/teraterm/ttpmacro/ttmdlg.cpp	2015-11-15 18:13:06 UTC (rev 6139)
+++ trunk/teraterm/ttpmacro/ttmdlg.cpp	2015-11-16 11:58:56 UTC (rev 6140)
@@ -42,54 +42,13 @@
 
 static PStatDlg StatDlg = NULL;
 
-#if 0
 extern "C" {
-BOOL NextParam(PCHAR Param, int *i, PCHAR Temp, int Size)
-{
-	int j;
-	char c;
-	BOOL Quoted;
-
-	if ((unsigned int) (*i) >= strlen(Param)) {
-		return FALSE;
-	}
-	j = 0;
-
-	while (Param[*i] == ' ' || Param[*i] == '\t') {
-		(*i)++;
-	}
-
-	Quoted = FALSE;
-	c = Param[*i];
-	(*i)++;
-	while ((c != 0) && (j < Size - 1) &&
-	       (Quoted || ((c != ' ') && (c != ';') && (c != '\t')))) {
-		if (c == '"')
-			Quoted = !Quoted;
-		Temp[j] = c;
-		j++;
-		c = Param[*i];
-		(*i)++;
-	}
-	if (!Quoted && (c == ';')) {
-		(*i)--;
-	}
-
-	Temp[j] = 0;
-	return (strlen(Temp) > 0);
-}
-}
-#endif
-
-extern "C" {
 void ParseParam(PBOOL IOption, PBOOL VOption)
 {
 	int i, j, k;
 	char *Param;
 	char Temp[MaxStrLen];
-#if 1
 	PCHAR start, cur, next;
-#endif
 
 	// Get home directory
 	if (GetModuleFileName(AfxGetInstanceHandle(),FileName,sizeof(FileName)) == 0) {
@@ -112,26 +71,18 @@
 	SleepFlag = FALSE;
 	*IOption = FALSE;
 	*VOption = FALSE;
-	// 256\x83o\x83C\x83g\x88ȏ\xE3\x82̃R\x83}\x83\x93\x83h\x83\x89\x83C\x83\x93\x83p\x83\x89\x83\x81\x81[\x83^\x8Ew\x92肪\x82\xA0\x82\xE9\x82ƁABOF(Buffer Over Flow)\x82\xC5
-	// \x97\x8E\x82\xBF\x82\xE9\x83o\x83O\x82\xF0\x8FC\x90\xB3\x81B(2007.5.25 yutaka)
 	Param = GetCommandLine();
 	i = 0;
+
 	// the first term shuld be executable filename of TTMACRO
-#if 1
 	start = GetParam(Temp, sizeof(Temp), Param);
-#else
-	NextParam(Param, &i, Temp, sizeof(Temp));
-#endif
 	j = 0;
 
-#if 1
 	cur = start;
 	while (next = GetParam(Temp, sizeof(Temp), cur)) {
-#else
-	while (NextParam(Param, &i, Temp, sizeof(Temp))) {
-#endif
+		DequoteParam(Temp, sizeof(Temp), Temp);
 		if (_strnicmp(Temp,"/D=",3)==0) { // DDE option
-			strncpy_s(TopicName, sizeof(TopicName), &Temp[3], _TRUNCATE);  // BOF\x91΍\xF4
+			strncpy_s(TopicName, sizeof(TopicName), &Temp[3], _TRUNCATE);
 		}
 		else if (_strnicmp(Temp,"/I",2)==0) {
 			*IOption = TRUE;
@@ -143,38 +94,20 @@
 			*VOption = TRUE;
 		}
 		else {
-			j++;
-			if (j==1) {
-				DequoteParam(FileName, sizeof(FileName), Temp);
+			switch (++j) {
+				case 1: strncpy_s(FileName, sizeof(FileName), Temp, _TRUNCATE); break;
+				case 2: strncpy_s(Param2,   sizeof(Param2),   Temp, _TRUNCATE); break;
+				case 3: strncpy_s(Param3,   sizeof(Param3),   Temp, _TRUNCATE); break;
+				case 4: strncpy_s(Param4,   sizeof(Param4),   Temp, _TRUNCATE); break;
+				case 5: strncpy_s(Param5,   sizeof(Param5),   Temp, _TRUNCATE); break;
+				case 6: strncpy_s(Param6,   sizeof(Param6),   Temp, _TRUNCATE); break;
+				case 7: strncpy_s(Param7,   sizeof(Param7),   Temp, _TRUNCATE); break;
+				case 8: strncpy_s(Param8,   sizeof(Param8),   Temp, _TRUNCATE); break;
+				case 9: strncpy_s(Param9,   sizeof(Param9),   Temp, _TRUNCATE); break;
+				default: ;/* nothing to do */
 			}
-			else if (j==2) {
-				DequoteParam(Param2, sizeof(Param2), Temp);
-			}
-			else if (j==3) {
-				DequoteParam(Param3, sizeof(Param3), Temp);
-			}
-			else if (j==4) {
-				DequoteParam(Param4, sizeof(Param4), Temp);
-			}
-			else if (j==5) {
-				DequoteParam(Param5, sizeof(Param5), Temp);
-			}
-			else if (j==6) {
-				DequoteParam(Param6, sizeof(Param6), Temp);
-			}
-			else if (j==7) {
-				DequoteParam(Param7, sizeof(Param7), Temp);
-			}
-			else if (j==8) {
-				DequoteParam(Param8, sizeof(Param8), Temp);
-			}
-			else if (j==9) {
-				DequoteParam(Param9, sizeof(Param9), Temp);
-			}
 		}
-#if 1
 		cur = next;
-#endif
 	}
 
 	ParamCnt = j;

Modified: trunk/teraterm/ttpset/ttset.c
===================================================================
--- trunk/teraterm/ttpset/ttset.c	2015-11-15 18:13:06 UTC (rev 6139)
+++ trunk/teraterm/ttpset/ttset.c	2015-11-16 11:58:56 UTC (rev 6140)
@@ -3595,9 +3595,7 @@
 	DWORD ParamBaud = BaudNone;
 	BOOL HostNameFlag = FALSE;
 	BOOL JustAfterHost = FALSE;
-#if 1
 	PCHAR start, cur, next;
-#endif
 
 	ts->HostName[0] = 0;
 	//ts->KeyCnfFN[0] = 0;
@@ -3615,21 +3613,13 @@
 		DDETopic[0] = 0;
 	i = 0;
 	/* the first term shuld be executable filename of Tera Term */
-#if 1
 	start = GetParam(Temp, sizeof(Temp), Param);
-#else
-	NextParam(Param, &i, Temp, sizeof(Temp));
-#endif
 
-#if 1
 	cur = start;
 	while (next = GetParam(Temp, sizeof(Temp), cur)) {
-#else
-	param_top = i;
-	while (NextParam(Param, &i, Temp, sizeof(Temp))) {
-#endif
+		DequoteParam(Temp, sizeof(Temp), Temp);
 		if (_strnicmp(Temp, "/F=", 3) == 0) {	/* setup filename */
-			DequoteParam(Temp2, sizeof(Temp2), &Temp[3]);
+			strncpy_s(Temp2, sizeof(Temp2), &Temp[3], _TRUNCATE);
 			if (strlen(Temp2) > 0) {
 				ConvFName(ts->HomeDir, Temp2, sizeof(Temp2), ".INI", Temp,
 				          sizeof(Temp));
@@ -3640,18 +3630,13 @@
 				}
 			}
 		}
-#if 1
 		cur = next;
-#endif
 	}
 
-#if 1
 	cur = start;
 	while (next = GetParam(Temp, sizeof(Temp), cur)) {
-#else
-	i = param_top;
-	while (NextParam(Param, &i, Temp, sizeof(Temp))) {
-#endif
+		DequoteParam(Temp, sizeof(Temp), Temp);
+
 		if (HostNameFlag) {
 			JustAfterHost = TRUE;
 			HostNameFlag = FALSE;
@@ -3698,7 +3683,7 @@
 			ts->HostDialogOnStartup = TRUE;
 		}
 		else if (_strnicmp(Temp, "/FD=", 4) == 0) {	/* file transfer directory */
-			DequoteParam(Temp2, sizeof(Temp2), &Temp[4]);
+			strncpy_s(Temp2, sizeof(Temp2), &Temp[4], _TRUNCATE);
 			if (strlen(Temp2) > 0) {
 				_getcwd(TempDir, sizeof(TempDir));
 				if (_chdir(Temp2) == 0)
@@ -3712,7 +3697,7 @@
 		else if (_stricmp(Temp, "/I") == 0)	/* iconize */
 			ts->Minimize = 1;
 		else if (_strnicmp(Temp, "/K=", 3) == 0) {	/* Keyboard setup file */
-			DequoteParam(Temp2, sizeof(Temp2), &Temp[3]);
+			strncpy_s(Temp2, sizeof(Temp2), &Temp[3], _TRUNCATE);
 			ConvFName(ts->HomeDir, Temp2, sizeof(Temp2), ".CNF",
 			          ts->KeyCnfFN, sizeof(ts->KeyCnfFN));
 		}
@@ -3741,8 +3726,7 @@
 			}
 		}
 		else if (_strnicmp(Temp, "/L=", 3) == 0) {	/* log file */
-			DequoteParam(Temp2, sizeof(Temp2), &Temp[3]);
-			strncpy_s(ts->LogFN, sizeof(ts->LogFN), Temp2, _TRUNCATE);
+			strncpy_s(ts->LogFN, sizeof(ts->LogFN), &Temp[3], _TRUNCATE);
 		}
 		else if (_strnicmp(Temp, "/LA=", 4) == 0) {	/* language */
 			switch (Temp[4]) {
@@ -3764,14 +3748,14 @@
 			}
 		}
 		else if (_strnicmp(Temp, "/MN=", 4) == 0) {	/* multicastname */
-			DequoteParam(ts->MulticastName, sizeof(ts->MulticastName), &Temp[4]);
+			strncpy_s(ts->MulticastName, sizeof(ts->MulticastName), &Temp[4], _TRUNCATE);
 		}
 		else if (_strnicmp(Temp, "/M=", 3) == 0) {	/* macro filename */
 			if ((Temp[3] == 0) || (Temp[3] == '*'))
 				strncpy_s(ts->MacroFN, sizeof(ts->MacroFN), "*",
 				          _TRUNCATE);
 			else {
-				DequoteParam(Temp2, sizeof(Temp2), &Temp[3]);
+				strncpy_s(Temp2, sizeof(Temp2), &Temp[3], _TRUNCATE);
 				ConvFName(ts->HomeDir, Temp2, sizeof(Temp2), ".TTL",
 				          ts->MacroFN, sizeof(ts->MacroFN));
 			}
@@ -3793,7 +3777,7 @@
 				ParamTCP = 65535;
 		}
 		else if (_strnicmp(Temp, "/R=", 3) == 0) {	/* Replay filename */
-			DequoteParam(Temp2, sizeof(Temp2), &Temp[3]);
+			strncpy_s(Temp2, sizeof(Temp2), &Temp[3], _TRUNCATE);
 			ConvFName(ts->HomeDir, Temp2, sizeof(Temp2), "", ts->HostName,
 			          sizeof(ts->HostName));
 			if (strlen(ts->HostName) > 0)
@@ -3817,7 +3801,7 @@
 			ts->HideWindow = 1;
 		}
 		else if (_strnicmp(Temp, "/W=", 3) == 0) {	/* Window title */
-			DequoteParam(ts->Title, sizeof(ts->Title), &Temp[3]);
+			strncpy_s(ts->Title, sizeof(ts->Title), &Temp[3], _TRUNCATE);
 		}
 		else if (_strnicmp(Temp, "/X=", 3) == 0) {	/* Window pos (X) */
 			if (sscanf(&Temp[3], "%d", &pos) == 1) {
@@ -3865,9 +3849,7 @@
 			}
 		}
 		JustAfterHost = FALSE;
-#if 1
 		cur = next;
-#endif
 	}
 
 	// Language \x82\xAA\x95ύX\x82\xB3\x82ꂽ\x82\xA9\x82\xE0\x82\xB5\x82\xEA\x82Ȃ\xA2\x82̂ŁA

Modified: trunk/ttssh2/ttxssh/ttxssh.c
===================================================================
--- trunk/ttssh2/ttxssh/ttxssh.c	2015-11-15 18:13:06 UTC (rev 6139)
+++ trunk/ttssh2/ttxssh/ttxssh.c	2015-11-16 11:58:56 UTC (rev 6140)
@@ -1701,16 +1701,17 @@
 
 	cur = start;
 	while (next = GetParam(option, opt_len, cur)) {
+		DequoteParam(option, opt_len, option);
 		action = OPTION_NONE;
 
 		if ((option[0] == '-' || option[0] == '/')) {
 			if (MATCH_STR(option + 1, "ssh") == 0) {
 				if (MATCH_STR(option + 4, "-f=") == 0) {
-					DequoteParam(option2, opt_len, option + 7);
+					strncpy_s(option2, opt_len, option + 7, _TRUNCATE);
 					read_ssh_options_from_user_file(pvar, option2);
 					action = OPTION_CLEAR;
 				} else if (MATCH_STR(option + 4, "-consume=") == 0) {
-					DequoteParam(option2, opt_len, option + 13);
+					strncpy_s(option2, opt_len, option + 13, _TRUNCATE);
 					read_ssh_options_from_user_file(pvar, option2);
 					DeleteFile(option2);
 					action = OPTION_CLEAR;
@@ -1718,7 +1719,7 @@
 
 			// ttermpro.exe \x82\xCC /F= \x8Ew\x92\xE8\x82ł\xE0 TTSSH \x82̐ݒ\xE8\x82\xF0\x93ǂ\xDE (2006.10.11 maya)
 			} else if (MATCH_STR_I(option + 1, "f=") == 0) {
-				DequoteParam(option2, opt_len, option + 3);
+				strncpy_s(option2, opt_len, option + 3, _TRUNCATE);
 				read_ssh_options_from_user_file(pvar, option2);
 				// Tera Term\x91\xA4\x82ł\xE0\x89\xF0\x8E߂\xB7\x82\xE9\x95K\x97v\x82\xAA\x82\xA0\x82\xE9\x82̂ŏ\xC1\x82\xB3\x82Ȃ\xA2
 			}
@@ -1739,6 +1740,7 @@
 
 	cur = start;
 	while (next = GetParam(option, opt_len, cur)) {	
+		DequoteParam(option, opt_len, option);
 		action = OPTION_NONE;
 
 		if ((option[0] == '-' || option[0] == '/')) {
@@ -1904,16 +1906,13 @@
 				}
 
 			} else if (MATCH_STR(option + 1, "user=") == 0) {
-				DequoteParam(option2, opt_len, option + 6);
-				_snprintf_s(pvar->ssh2_username, sizeof(pvar->ssh2_username), _TRUNCATE, "%s", option2);
+				_snprintf_s(pvar->ssh2_username, sizeof(pvar->ssh2_username), _TRUNCATE, "%s", option+6);
 
 			} else if (MATCH_STR(option + 1, "passwd=") == 0) {
-				DequoteParam(option2, opt_len, option + 8);
-				_snprintf_s(pvar->ssh2_password, sizeof(pvar->ssh2_password), _TRUNCATE, "%s", option2);
+				_snprintf_s(pvar->ssh2_password, sizeof(pvar->ssh2_password), _TRUNCATE, "%s", option+8);
 
 			} else if (MATCH_STR(option + 1, "keyfile=") == 0) {
-				DequoteParam(option2, opt_len, option + 9);
-				_snprintf_s(pvar->ssh2_keyfile, sizeof(pvar->ssh2_keyfile), _TRUNCATE, "%s", option2);
+				_snprintf_s(pvar->ssh2_keyfile, sizeof(pvar->ssh2_keyfile), _TRUNCATE, "%s", option+9);
 
 			} else if (MATCH_STR(option + 1, "ask4passwd") == 0) {
 				// \x83p\x83X\x83\x8F\x81[\x83h\x82𕷂\xAD (2006.9.18 maya)



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