[Ttssh2-commit] [5882] http://osdn.jp/ticket/browse.php?group_id=1412&tid= 35182 引数の解析処理を統一する

アーカイブの一覧に戻る

svnno****@sourc***** svnno****@sourc*****
2015年 5月 23日 (土) 21:42:04 JST


Revision: 5882
          http://sourceforge.jp/projects/ttssh2/scm/svn/commits/5882
Author:   maya
Date:     2015-05-23 21:42:04 +0900 (Sat, 23 May 2015)
Log Message:
-----------
http://osdn.jp/ticket/browse.php?group_id=1412&tid=35182 引数の解析処理を統一する
  コマンドラインオプションの分解処理を ttlib.c の GetParam() にまとめた
  各オプションのクォート解除処理を ttlib.c の DequoteParam() にまとめた

Modified Paths:
--------------
    trunk/TTProxy/TTProxy.h
    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/TTProxy/TTProxy.h
===================================================================
--- trunk/TTProxy/TTProxy.h	2015-05-23 12:41:04 UTC (rev 5881)
+++ trunk/TTProxy/TTProxy.h	2015-05-23 12:42:04 UTC (rev 5882)
@@ -129,6 +129,7 @@
 	static void PASCAL TTXParseParam(PCHAR param, PTTSet ts, PCHAR DDETopic) {
 		int param_len=strlen(param);
 		char option[1024];
+		char option2[1024];
 		int opt_len = sizeof(option);
 		int action;
 		PCHAR start, cur, next;
@@ -144,7 +145,8 @@
 
 			if ((option[0] == '-' || option[0] == '/')) {
 				if ((option[1] == 'F' || option[1] == 'f') && option[2] == '=') {
-					read_options(get_teraterm_dir_relative_name(option + 3));
+					DequoteParam(option2, sizeof(option2), option + 3);
+					read_options(get_teraterm_dir_relative_name(option2));
 				}
 			}
 
@@ -169,7 +171,8 @@
 				if (strlen(option + 1) >= 6 && option[6] == '=') {
 					option[6] = '\0';
 					if (_stricmp(option + 1, "proxy") == 0) {
-						ProxyWSockHook::parseURL(option + 7, TRUE);
+						DequoteParam(option2, sizeof(option2), option + 7);
+						ProxyWSockHook::parseURL(option2, TRUE);
 						action = OPTION_CLEAR;
 					}else{
 						option[6] = '=';

Modified: trunk/TTXSamples/TTXRecurringCommand/TTXRecurringCommand.c
===================================================================
--- trunk/TTXSamples/TTXRecurringCommand/TTXRecurringCommand.c	2015-05-23 12:41:04 UTC (rev 5881)
+++ trunk/TTXSamples/TTXRecurringCommand/TTXRecurringCommand.c	2015-05-23 12:42:04 UTC (rev 5882)
@@ -386,16 +386,18 @@
 //
 
 static void PASCAL FAR TTXParseParam(PCHAR Param, PTTSet ts, PCHAR DDETopic) {
-        char buff[1024];
-        PCHAR next;
-        pvar->origParseParam(Param, ts, DDETopic);
+	char buff[1024];
+	char option2[1024];
+	PCHAR next;
+	pvar->origParseParam(Param, ts, DDETopic);
 
-        next = Param;
-        while (next = GetParam(buff, sizeof(buff), next)) {
-                if (_strnicmp(buff, "/F=", 3) == 0) {
-                        ReadINI(&buff[3], ts);
-                }
-        }
+	next = Param;
+	while (next = GetParam(buff, sizeof(buff), next)) {
+		if (_strnicmp(buff, "/F=", 3) == 0) {
+			DequoteParam(option2, sizeof(option2), buff + 3);
+			ReadINI(option2, ts);
+		}
+	}
 
 	return;
 }

Modified: trunk/teraterm/common/ttlib.c
===================================================================
--- trunk/teraterm/common/ttlib.c	2015-05-23 12:41:04 UTC (rev 5881)
+++ trunk/teraterm/common/ttlib.c	2015-05-23 12:42:04 UTC (rev 5882)
@@ -1070,7 +1070,29 @@
 		return NULL;
 	}
 
+#if 1
 	while (*param != '\0' && (quoted || (*param != ';' && *param != ' ' && *param != '\t'))) {
+		if (*param == '"') {
+			if ((!quoted && *(param+1) != '"') || (quoted && *(param+1) != '"')) {
+				quoted = !quoted;
+			}
+			else {
+				if (i < size - 1) {
+					buff[i++] = *param;
+				}
+				param++;
+			}
+		}
+		if (i < size - 1) {
+			buff[i++] = *param;
+		}
+		param++;
+	}
+	if (!quoted && (buff[i-1] == ';')) {
+		i--;
+	}
+#else
+	while (*param != '\0' && (quoted || (*param != ';' && *param != ' ' && *param != '\t'))) {
 		if (*param == '"' && (*++param != '"' || !quoted)) {
 			quoted = !quoted;
 			continue;
@@ -1080,6 +1102,7 @@
 		}
 		param++;
 	}
+#endif
 
 	buff[i] = '\0';
 	return (param);

Modified: trunk/teraterm/ttpmacro/ttmdlg.cpp
===================================================================
--- trunk/teraterm/ttpmacro/ttmdlg.cpp	2015-05-23 12:41:04 UTC (rev 5881)
+++ trunk/teraterm/ttpmacro/ttmdlg.cpp	2015-05-23 12:42:04 UTC (rev 5882)
@@ -42,6 +42,7 @@
 
 static PStatDlg StatDlg = NULL;
 
+#if 0
 extern "C" {
 BOOL NextParam(PCHAR Param, int *i, PCHAR Temp, int Size)
 {
@@ -78,6 +79,7 @@
 	return (strlen(Temp) > 0);
 }
 }
+#endif
 
 extern "C" {
 void ParseParam(PBOOL IOption, PBOOL VOption)
@@ -85,6 +87,9 @@
 	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,10 +117,19 @@
 	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
 		if (_strnicmp(Temp,"/D=",3)==0) { // DDE option
 			strncpy_s(TopicName, sizeof(TopicName), &Temp[3], _TRUNCATE);  // BOF\x91΍\xF4
 		}
@@ -158,6 +172,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-05-23 12:41:04 UTC (rev 5881)
+++ trunk/teraterm/ttpset/ttset.c	2015-05-23 12:42:04 UTC (rev 5882)
@@ -3149,7 +3149,7 @@
 {
 	AddValueToList(FName, Host, "Hosts", "Host", MAXHOSTLIST);
 }
-
+#if 0
 BOOL NextParam(PCHAR Param, int *i, PCHAR Temp, int Size)
 {
 	int j;
@@ -3184,7 +3184,7 @@
 	Temp[j] = 0;
 	return (strlen(Temp) > 0);
 }
-
+#endif
 #ifndef NO_INET6
 static void ParseHostName(char *HostStr, WORD * port)
 {
@@ -3290,6 +3290,9 @@
 	DWORD ParamBaud = BaudNone;
 	BOOL HostNameFlag = FALSE;
 	BOOL JustAfterHost = FALSE;
+#if 1
+	PCHAR start, cur, next;
+#endif
 
 	ts->HostName[0] = 0;
 	//ts->KeyCnfFN[0] = 0;
@@ -3307,10 +3310,19 @@
 		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
 		if (_strnicmp(Temp, "/F=", 3) == 0) {	/* setup filename */
 			DequoteParam(Temp2, sizeof(Temp2), &Temp[3]);
 			if (strlen(Temp2) > 0) {
@@ -3323,10 +3335,18 @@
 				}
 			}
 		}
+#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
 		if (HostNameFlag) {
 			JustAfterHost = TRUE;
 			HostNameFlag = FALSE;
@@ -3540,6 +3560,9 @@
 			}
 		}
 		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-05-23 12:41:04 UTC (rev 5881)
+++ trunk/ttssh2/ttxssh/ttxssh.c	2015-05-23 12:42:04 UTC (rev 5882)
@@ -1637,6 +1637,7 @@
 	int param_len=strlen(param);
 	int opt_len = param_len+1;
 	char *option = (char *)calloc(opt_len, sizeof(char));
+	char *option2 = (char *)calloc(opt_len, sizeof(char));
 	int action;
 	PCHAR start, cur, next;
 
@@ -1654,17 +1655,20 @@
 		if ((option[0] == '-' || option[0] == '/')) {
 			if (MATCH_STR(option + 1, "ssh") == 0) {
 				if (MATCH_STR(option + 4, "-f=") == 0) {
-					read_ssh_options_from_user_file(pvar, option + 7);
+					DequoteParam(option2, opt_len, option + 7);
+					read_ssh_options_from_user_file(pvar, option2);
 					action = OPTION_CLEAR;
 				} else if (MATCH_STR(option + 4, "-consume=") == 0) {
-					read_ssh_options_from_user_file(pvar, option + 13);
-					DeleteFile(option + 13);
+					DequoteParam(option2, opt_len, option + 13);
+					read_ssh_options_from_user_file(pvar, option2);
+					DeleteFile(option2);
 					action = OPTION_CLEAR;
 				}
 
 			// 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) {
-				read_ssh_options_from_user_file(pvar, option + 3);
+				DequoteParam(option2, opt_len, option + 3);
+				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
 			}
 		}
@@ -1832,13 +1836,16 @@
 				}
 
 			} else if (MATCH_STR(option + 1, "user=") == 0) {
-				_snprintf_s(pvar->ssh2_username, sizeof(pvar->ssh2_username), _TRUNCATE, "%s", option + 6);
+				DequoteParam(option2, opt_len, option + 6);
+				_snprintf_s(pvar->ssh2_username, sizeof(pvar->ssh2_username), _TRUNCATE, "%s", option2);
 
 			} else if (MATCH_STR(option + 1, "passwd=") == 0) {
-				_snprintf_s(pvar->ssh2_password, sizeof(pvar->ssh2_password), _TRUNCATE, "%s", option + 8);
+				DequoteParam(option2, opt_len, option + 8);
+				_snprintf_s(pvar->ssh2_password, sizeof(pvar->ssh2_password), _TRUNCATE, "%s", option2);
 
 			} else if (MATCH_STR(option + 1, "keyfile=") == 0) {
-				_snprintf_s(pvar->ssh2_keyfile, sizeof(pvar->ssh2_keyfile), _TRUNCATE, "%s", option + 9);
+				DequoteParam(option2, opt_len, option + 9);
+				_snprintf_s(pvar->ssh2_keyfile, sizeof(pvar->ssh2_keyfile), _TRUNCATE, "%s", option2);
 
 			} else if (MATCH_STR(option + 1, "ask4passwd") == 0) {
 				// \x83p\x83X\x83\x8F\x81[\x83h\x82𕷂\xAD (2006.9.18 maya)



Ttssh2-commit メーリングリストの案内
アーカイブの一覧に戻る