[ttssh2-commit] [9493] 新しい接続時のコマンドラインを Unicode 化

Back to archive index
scmno****@osdn***** scmno****@osdn*****
2021年 10月 23日 (土) 01:10:27 JST


Revision: 9493
          https://osdn.net/projects/ttssh2/scm/svn/commits/9493
Author:   zmatsuo
Date:     2021-10-23 01:10:27 +0900 (Sat, 23 Oct 2021)
Log Message:
-----------
新しい接続時のコマンドラインを Unicode 化

Modified Paths:
--------------
    trunk/teraterm/teraterm/vtwin.cpp

-------------- next part --------------
Modified: trunk/teraterm/teraterm/vtwin.cpp
===================================================================
--- trunk/teraterm/teraterm/vtwin.cpp	2021-10-22 16:10:18 UTC (rev 9492)
+++ trunk/teraterm/teraterm/vtwin.cpp	2021-10-22 16:10:27 UTC (rev 9493)
@@ -3506,6 +3506,14 @@
 	return e;
 }
 
+/**
+ *	\x90V\x82\xB5\x82\xA2\x90ڑ\xB1
+ *
+ *	TODO
+ *		\x8E\x9F\x82̕ϐ\x94\x82\xAA\x83R\x83}\x83\x93\x83h\x83\x89\x83C\x83\x93\x92\xB7\x82̏\xE3\x8C\xC0\x82̈\xEA\x88\xF6\x82ƂȂ\xC1\x82Ă\xA2\x82\xE9
+ *		- hostname[HostNameMaxLength] (\x83z\x83X\x83g\x96\xBC\x81A\x83R\x83}\x83\x93\x83h\x83\x89\x83C\x83\x93)
+ *		- command[MAXPATHLEN + HostNameMaxLength]
+ */
 void CVTWindow::OnFileNewConnection()
 {
 	if (Connecting) return;
@@ -3526,20 +3534,11 @@
 	GetHNRec.MaxComPort = ts.MaxComPort;
 	GetHNRec.HostName = hostname;
 
-	HelpId = HlpFileNewConnection;
 	SetDialogFont(ts.DialogFontName, ts.DialogFontPoint, ts.DialogFontCharSet,
 				  ts.UILanguageFile, "Tera Term", "DLG_SYSTEM_FONT");
 	BOOL r = (*GetHostName)(HVTWin,&GetHNRec);
 
 	if (r) {
-		char Command[MAXPATHLEN + HostNameMaxLength];
-		char Command2[MAXPATHLEN + HostNameMaxLength];
-
-		strncpy_s(Command, _countof(Command), "ttermpro ", _TRUNCATE);
-		char *hostnameA = ToCharW(hostname);
-		strncat_s(Command, _countof(Command), hostnameA, _TRUNCATE);
-		free(hostnameA);
-
 		if ((GetHNRec.PortType==IdTCPIP) && LoadTTSET()) {
 			if (ts.HistoryList) {
 				(*AddHostToList)(ts.SetupFNameW, hostname);
@@ -3552,6 +3551,7 @@
 			FreeTTSET();
 		}
 
+		static const wchar_t *ttermpro = L"ttermpro";
 		if (! cv.Ready) {
 			ts.PortType = GetHNRec.PortType;
 			ts.Telnet = GetHNRec.Telnet;
@@ -3560,10 +3560,12 @@
 			ts.ComPort = GetHNRec.ComPort;
 
 			if ((GetHNRec.PortType==IdTCPIP) && LoadTTSET()) {
-				wchar_t *commandW = ToWcharA(Command);
-				(*ParseParam)(commandW, &ts, NULL);
+				wchar_t command[MAXPATHLEN + HostNameMaxLength];
+				wcsncpy_s(command, _countof(command), ttermpro, _TRUNCATE);
+				wcsncat_s(command, _countof(command), L" ", _TRUNCATE);
+				wcsncat_s(command, _countof(command), hostname, _TRUNCATE);
+				(*ParseParam)(command, &ts, NULL);
 				FreeTTSET();
-				free(commandW);
 			}
 			SetKeyMap();
 			if (ts.MacroFN[0]!=0) {
@@ -3578,39 +3580,38 @@
 			ResetSetup();
 		}
 		else {
+			wchar_t Command[MAXPATHLEN + HostNameMaxLength];
+
 			if (GetHNRec.PortType==IdSerial) {
-				char comport[5];
-				Command[8] = 0;
-				strncat_s(Command,sizeof(Command)," /C=",_TRUNCATE);
-				_snprintf_s(comport, sizeof(comport), _TRUNCATE, "%d", GetHNRec.ComPort);
-				strncat_s(Command,sizeof(Command),comport,_TRUNCATE);
+				_snwprintf_s(Command, _countof(Command), _TRUNCATE, L"%s /C=%d", ttermpro, GetHNRec.ComPort);
 			}
 			else {
-				char tcpport[6];
-				DeleteComment(Command2, sizeof(Command2), &Command[9]);
-				Command[9] = 0;
+				wcsncpy_s(Command, _countof(Command), ttermpro, _TRUNCATE);
+				wcsncat_s(Command, _countof(Command), L" ", _TRUNCATE);
 				if (GetHNRec.Telnet==0)
-					strncat_s(Command,sizeof(Command)," /T=0",_TRUNCATE);
+					wcsncat_s(Command,_countof(Command), L" /T=0",_TRUNCATE);
 				else
-					strncat_s(Command,sizeof(Command)," /T=1",_TRUNCATE);
+					wcsncat_s(Command,_countof(Command), L" /T=1",_TRUNCATE);
 				if (GetHNRec.TCPPort != 0) {
-					strncat_s(Command,sizeof(Command)," /P=",_TRUNCATE);
-					_snprintf_s(tcpport, sizeof(tcpport), _TRUNCATE, "%d", GetHNRec.TCPPort);
-					strncat_s(Command,sizeof(Command),tcpport,_TRUNCATE);
+					wchar_t tcpport[16];
+					_snwprintf_s(tcpport, _countof(tcpport), _TRUNCATE, L" /P=%d", GetHNRec.TCPPort);
+					wcsncat_s(Command,_countof(Command),tcpport,_TRUNCATE);
 				}
 				/********************************/
 				/* \x82\xB1\x82\xB1\x82Ƀv\x83\x8D\x83g\x83R\x83\x8B\x8F\x88\x97\x9D\x82\xF0\x93\xFC\x82\xEA\x82\xE9 */
 				/********************************/
 				if (GetHNRec.ProtocolFamily == AF_INET) {
-					strncat_s(Command,sizeof(Command)," /4",_TRUNCATE);
+					wcsncat_s(Command,_countof(Command), L" /4",_TRUNCATE);
 				} else if (GetHNRec.ProtocolFamily == AF_INET6) {
-					strncat_s(Command,sizeof(Command)," /6",_TRUNCATE);
+					wcsncat_s(Command,_countof(Command), L" /6",_TRUNCATE);
 				}
-				strncat_s(Command,sizeof(Command)," ",_TRUNCATE);
-				strncat_s(Command,sizeof(Command),Command2,_TRUNCATE);
+				wchar_t *hostname_nocomment = DeleteCommentW(hostname);
+				wcsncat_s(Command,_countof(Command), L" ", _TRUNCATE);
+				wcsncat_s(Command,_countof(Command), hostname_nocomment, _TRUNCATE);
+				free(hostname_nocomment);
 			}
-			TTXSetCommandLine(Command, sizeof(Command), &GetHNRec); /* TTPLUG */
-			WinExec(Command,SW_SHOW);
+			TTXSetCommandLine(Command, _countof(Command), &GetHNRec); /* TTPLUG */
+			TTWinExec(Command);
 		}
 	}
 	else {/* canceled */
@@ -3625,10 +3626,8 @@
 // (2004.12.6 yutaka)
 void CVTWindow::OnDuplicateSession()
 {
-	char Command[1024];
+	wchar_t Command[1024];
 	const char *exec = "ttermpro";
-	STARTUPINFO si;
-	PROCESS_INFORMATION pi;
 	char cygterm_cfg[MAX_PATH];
 	FILE *fp;
 	char buf[256], *head, *body;
@@ -3675,18 +3674,18 @@
 		OnCygwinConnection();
 		return;
 	} else if (cv.TelFlag) { // telnet
-		_snprintf_s(Command, sizeof(Command), _TRUNCATE,
-		            "%s %s:%d /DUPLICATE /nossh",
-		            exec, ts.HostName, ts.TCPPort);
+		_snwprintf_s(Command, _countof(Command), _TRUNCATE,
+					 L"%hs %hs:%d /DUPLICATE /nossh",
+					 exec, ts.HostName, ts.TCPPort);
 
 	} else if (cv.isSSH) { // SSH
 		// \x82\xB1\x82\xB1\x82̏\x88\x97\x9D\x82\xCD TTSSH \x91\xA4\x82ɂ\xE2\x82点\x82\xE9\x82ׂ\xAB (2004.12.7 yutaka)
 		// TTSSH\x91\xA4\x82ł̃I\x83v\x83V\x83\x87\x83\x93\x90\xB6\x90\xAC\x82\xF0\x92lj\xC1\x81B(2005.4.8 yutaka)
-		_snprintf_s(Command, sizeof(Command), _TRUNCATE,
-		            "%s %s:%d /DUPLICATE",
-		            exec, ts.HostName, ts.TCPPort);
+		_snwprintf_s(Command, _countof(Command), _TRUNCATE,
+					 L"%hs %hs:%d /DUPLICATE",
+					 exec, ts.HostName, ts.TCPPort);
 
-		TTXSetCommandLine(Command, sizeof(Command), NULL); /* TTPLUG */
+		TTXSetCommandLine(Command, _countof(Command), NULL); /* TTPLUG */
 
 	} else {
 		// telnet/ssh/cygwin\x90ڑ\xB1\x88ȊO\x82ł͕\xA1\x90\xBB\x82\xF0\x8Ds\x82\xED\x82Ȃ\xA2\x81B
@@ -3697,16 +3696,12 @@
 	// cf. http://sourceforge.jp/ticket/browse.php?group_id=1412&tid=24682
 	// (2011.3.27 yutaka)
 	if (strlen(ts.KeyCnfFN) > 0) {
-		strncat_s(Command, sizeof(Command), " /K=", _TRUNCATE);
-		strncat_s(Command, sizeof(Command), ts.KeyCnfFN, _TRUNCATE);
+		wcsncat_s(Command, _countof(Command), L" /K=", _TRUNCATE);
+		wcsncat_s(Command, _countof(Command), ts.KeyCnfFNW, _TRUNCATE);
 	}
 
-	memset(&si, 0, sizeof(si));
-	GetStartupInfo(&si);
-	memset(&pi, 0, sizeof(pi));
-
-	if (CreateProcess(NULL, Command, NULL, NULL, FALSE, 0,
-	                  NULL, NULL, &si, &pi) == 0) {
+	DWORD e = TTWinExec(Command);
+	if (e != NO_ERROR) {
 		static const TTMessageBoxInfoW info = {
 			"Tera Term",
 			"MSG_ERROR", L"ERROR",
@@ -3713,10 +3708,7 @@
 			"MSG_EXEC_TT_ERROR", L"Can't execute Tera Term. (%d)",
 			MB_OK | MB_ICONWARNING
 		};
-		TTMessageBoxW(HVTWin, &info, ts.UILanguageFileW, GetLastError());
-	} else {
-		CloseHandle(pi.hThread);
-		CloseHandle(pi.hProcess);
+		TTMessageBoxW(HVTWin, &info, ts.UILanguageFileW, e);
 	}
 }
 
@@ -3744,8 +3736,6 @@
 	size_t envbufflen;
 	const char *exename = "cygterm.exe";
 	char cygterm[MAX_PATH];
-	STARTUPINFO si;
-	PROCESS_INFORMATION pi;
 
 	if (strlen(ts.CygwinDirectory) > 0) {
 		if (SearchPath(ts.CygwinDirectory, "bin\\cygwin1", ".dll", sizeof(file), file, &filename) > 0) {
@@ -3815,16 +3805,12 @@
 	}
 
 found_path:;
-	memset(&si, 0, sizeof(si));
-	GetStartupInfo(&si);
-	memset(&pi, 0, sizeof(pi));
-
 	strncpy_s(cygterm, sizeof(cygterm), ts.HomeDir, _TRUNCATE);
 	AppendSlash(cygterm, sizeof(cygterm));
 	strncat_s(cygterm, sizeof(cygterm), exename, _TRUNCATE);
 
-	if (CreateProcess(NULL, cygterm, NULL, NULL, FALSE, 0,
-	                  NULL, NULL, &si, &pi) == 0) {
+	DWORD e = TTWinExecA(cygterm);
+	if (e != NO_ERROR) {
 		static const TTMessageBoxInfoW info = {
 			"Tera Term",
 			"MSG_ERROR", L"ERROR",
@@ -3832,9 +3818,6 @@
 			MB_OK | MB_ICONWARNING
 		};
 		TTMessageBoxW(HVTWin, &info, ts.UILanguageFileW);
-	} else {
-		CloseHandle(pi.hThread);
-		CloseHandle(pi.hProcess);
 	}
 }
 


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