[ttssh2-commit] [9435] ttpmacro コマンドライン Unicode化

Back to archive index
scmno****@osdn***** scmno****@osdn*****
2021年 9月 20日 (月) 00:15:00 JST


Revision: 9435
          https://osdn.net/projects/ttssh2/scm/svn/commits/9435
Author:   zmatsuo
Date:     2021-09-20 00:15:00 +0900 (Mon, 20 Sep 2021)
Log Message:
-----------
ttpmacro コマンドライン Unicode化

Modified Paths:
--------------
    trunk/teraterm/ttpmacro/ttl.cpp
    trunk/teraterm/ttpmacro/ttmbuff.c
    trunk/teraterm/ttpmacro/ttmbuff.h
    trunk/teraterm/ttpmacro/ttmdde.c
    trunk/teraterm/ttpmacro/ttmdlg.cpp
    trunk/teraterm/ttpmacro/ttmdlg.h
    trunk/teraterm/ttpmacro/ttmmain.cpp
    trunk/teraterm/ttpmacro/ttmparse.cpp
    trunk/teraterm/ttpmacro/ttmparse.h

-------------- next part --------------
Modified: trunk/teraterm/ttpmacro/ttl.cpp
===================================================================
--- trunk/teraterm/ttpmacro/ttl.cpp	2021-09-19 15:14:49 UTC (rev 9434)
+++ trunk/teraterm/ttpmacro/ttl.cpp	2021-09-19 15:15:00 UTC (rev 9435)
@@ -182,7 +182,8 @@
 BOOL InitTTL(HWND HWin)
 {
 	int i;
-	TStrVal Dir;
+	wchar_t *DirW;
+	char *Dir;
 	TVarId ParamsVarId;
 	char tmpname[10];
 	WORD Err;
@@ -214,12 +215,12 @@
 	NewIntVar("paramcnt",ParamCnt);  // \x83t\x83@\x83C\x83\x8B\x96\xBC\x82\xE0\x8A܂ވ\xF8\x90\x94\x82̌\x94 (2012.4.10 yutaka)
 
 	// \x8B\x8C\x8C`\x8E\xAE\x82̃p\x83\x89\x83\x81\x81[\x83^\x90ݒ\xE8 (param1 \x81` param9)
-	NewStrVar("param1", ShortName);
+	NewStrVar("param1", (u8)ShortName);
 	if (Params) {
 		for (i=2; i<=9; i++) {
 			_snprintf_s(tmpname, sizeof(tmpname), _TRUNCATE, "param%d", i);
 			if (ParamCnt >= i && Params[i] != NULL) {
-				NewStrVar(tmpname, Params[i]);
+				NewStrVar(tmpname, (u8)Params[i]);
 			}
 			else {
 				NewStrVar(tmpname, "");
@@ -233,7 +234,7 @@
 		GetStrAryVarByName(&ParamsVarId, "params", &Err);
 		if (Err == 0) {
 			if (ShortName[0] != 0) {
-				SetStrValInArray(ParamsVarId, 1, ShortName, &Err);
+				SetStrValInArray(ParamsVarId, 1, (u8)ShortName, &Err);
 			}
 			if (Params) {
 				for (i=0; i<=ParamCnt; i++) {
@@ -241,7 +242,7 @@
 						continue;
 					}
 					if (Params[i]) {
-						SetStrValInArray(ParamsVarId, i, Params[i], &Err);
+						SetStrValInArray(ParamsVarId, i, (u8)Params[i], &Err);
 						free(Params[i]);
 					}
 				}
@@ -268,8 +269,11 @@
 
 	UnlockVar();
 
-	ExtractDirName(FileName,Dir);
+	DirW = ExtractDirNameW(FileName);
+	Dir = ToU8W(DirW);
 	TTMSetDir(Dir);
+	free(DirW);
+	free(Dir);
 
 	if (SleepFlag)
 	{ // synchronization for startup macro
@@ -585,7 +589,7 @@
 
 	SetResult(0);
 	// link to Tera Term
-	if (strlen(TopicName)==0)
+	if (wcslen(TopicName)==0)
 	{
 		switch (mode) {
 		case RsvConnect:
@@ -595,13 +599,15 @@
 			strncpy_s(Cmnd, sizeof(Cmnd),CYGTERMCOMMAND, _TRUNCATE);
 			break;
 		}
+		char *TopicNameA = ToCharW(TopicName);
 		w = HIWORD(HMainWin);
-		Word2HexStr(w,TopicName);
+		Word2HexStr(w,TopicNameA);
 		w = LOWORD(HMainWin);
-		Word2HexStr(w,&(TopicName[4]));
-		strncat_s(Cmnd,sizeof(Cmnd),TopicName,_TRUNCATE);
+		Word2HexStr(w,&(TopicNameA[4]));
+		strncat_s(Cmnd,sizeof(Cmnd),TopicNameA,_TRUNCATE);
 		strncat_s(Cmnd,sizeof(Cmnd)," ",_TRUNCATE);
 		strncat_s(Cmnd,sizeof(Cmnd),Str,_TRUNCATE);
+		free(TopicNameA);
 		if (WinExec(Cmnd,SW_SHOW)<32)
 			return ErrCantConnect;
 		TTLStatus = IdTTLInitDDE;
@@ -2913,7 +2919,10 @@
 		Err = ErrCantOpen;
 		return Err;
 	}
-	if (! BuffInclude(Str)) {
+	wchar_t *StrW = ToWcharU8(Str);
+	BOOL r = BuffInclude(StrW);
+	free(StrW);
+	if (!r) {
 		Err = ErrCantOpen;
 		return Err;
 	}

Modified: trunk/teraterm/ttpmacro/ttmbuff.c
===================================================================
--- trunk/teraterm/ttpmacro/ttmbuff.c	2021-09-19 15:14:49 UTC (rev 9434)
+++ trunk/teraterm/ttpmacro/ttmbuff.c	2021-09-19 15:15:00 UTC (rev 9435)
@@ -39,6 +39,7 @@
 #include "ttmparse.h"
 #include "ttlib.h"
 #include "fileread.h"
+#include "codeconv.h"
 
 #include "ttmbuff.h"
 
@@ -122,9 +123,10 @@
 }
 
 
-BOOL LoadMacroFile(PCHAR FileName, int IBuff)
+static BOOL LoadMacroFile(const wchar_t *FileName, int IBuff)
 {
-	char basename[MAX_PATH];
+	wchar_t basename[MAX_PATH];
+	char *basenameU8;
 	size_t Len;
 
 	if ((FileName[0]==0) || (IBuff>MAXNESTLEVEL-1)) {
@@ -134,14 +136,15 @@
 	// include\x82ɐ\xAC\x8C\x{1C2D42}\xBD\x83t\x83@\x83C\x83\x8B\x82\xA9\x82\xE7\x81A\x83t\x83@\x83C\x83\x8B\x96\xBC\x82\xF0\x8BL\x98^\x82\xB7\x82\xE9\x81B
 	// \x83}\x83N\x83\x8D\x82̃G\x83\x89\x81[\x83_\x83C\x83A\x83\x8D\x83O\x82ŁA\x83t\x83@\x83C\x83\x8B\x96\xBC\x82\xF0\x95\\x8E\xA6\x82\xB5\x82\xBD\x82\xA2\x82\xBD\x82߁B
 	// (2013.9.8 yutaka)
-	if (GetFileTitleA(FileName, basename, sizeof(basename)) != 0)
-		strncpy_s(basename, sizeof(basename), FileName, _TRUNCATE);
-	strncpy_s(&BuffHandleFileName[IBuff][0], MAXFILENAME, basename, _TRUNCATE);
+	if (GetFileTitleW(FileName, basename, _countof(basename)) != 0)
+		wcsncpy_s(basename, _countof(basename), FileName, _TRUNCATE);
+	basenameU8 = ToU8W(basename);
+	strncpy_s(&BuffHandleFileName[IBuff][0], MAXFILENAME, basenameU8, _TRUNCATE);
+	free(basenameU8);
 
 	BuffPtr[IBuff] = 0;
 
-//	Buff[IBuff] = LoadFileAA(FileName, &Len);
-	Buff[IBuff] = LoadFileU8A(FileName, &Len);
+	Buff[IBuff] = LoadFileU8W(FileName, &Len);
 	if (Buff[IBuff] == NULL) {
 		BuffLen[IBuff] = 0;
 		return FALSE;
@@ -344,7 +347,7 @@
 	return TRUE;
 }
 
-BOOL InitBuff(PCHAR FileName)
+BOOL InitBuff(const wchar_t *FileName)
 {
 	int i;
 
@@ -435,7 +438,7 @@
 	return 0;
 }
 
-BOOL BuffInclude(PCHAR FileName)
+BOOL BuffInclude(const wchar_t *FileName)
 {
 	if (INest>=MAXNESTLEVEL-1) {
 		return FALSE;

Modified: trunk/teraterm/ttpmacro/ttmbuff.h
===================================================================
--- trunk/teraterm/ttpmacro/ttmbuff.h	2021-09-19 15:14:49 UTC (rev 9434)
+++ trunk/teraterm/ttpmacro/ttmbuff.h	2021-09-19 15:15:00 UTC (rev 9435)
@@ -33,7 +33,7 @@
 extern "C" {
 #endif
 
-BOOL InitBuff(PCHAR FileName);
+BOOL InitBuff(const wchar_t *FileName);
 void CloseBuff(int IBuff);
 BOOL GetNewLine();
 // goto
@@ -42,7 +42,7 @@
 WORD CallToLabel(int ILabel);
 WORD ReturnFromSub();
 // include file
-BOOL BuffInclude(PCHAR FileName);
+BOOL BuffInclude(const wchar_t *FileName);
 BOOL ExitBuffer();
 // for ... next
 int SetForLoop();

Modified: trunk/teraterm/ttpmacro/ttmdde.c
===================================================================
--- trunk/teraterm/ttpmacro/ttmdde.c	2021-09-19 15:14:49 UTC (rev 9434)
+++ trunk/teraterm/ttpmacro/ttmdde.c	2021-09-19 15:15:00 UTC (rev 9435)
@@ -275,7 +275,7 @@
 	}
 
 	Service= DdeCreateStringHandle(Inst, ServiceName, CP_WINANSI);
-	Topic  = DdeCreateStringHandle(Inst, TopicName, CP_WINANSI);
+	Topic  = DdeCreateStringHandleW(Inst, TopicName, CP_WINANSI);
 	Item   = DdeCreateStringHandle(Inst, ItemName, CP_WINANSI);
 	Item2  = DdeCreateStringHandle(Inst, ItemName2, CP_WINANSI);
 	if ((Service==0) || (Topic==0) ||

Modified: trunk/teraterm/ttpmacro/ttmdlg.cpp
===================================================================
--- trunk/teraterm/ttpmacro/ttmdlg.cpp	2021-09-19 15:14:49 UTC (rev 9434)
+++ trunk/teraterm/ttpmacro/ttmdlg.cpp	2021-09-19 15:15:00 UTC (rev 9435)
@@ -57,10 +57,10 @@
 
 char HomeDir[MAX_PATH];
 wchar_t *HomeDirW;
-char FileName[MAX_PATH];
-char TopicName[11];
-char ShortName[MAX_PATH];
-char **Params = NULL;
+wchar_t FileName[MAX_PATH];
+wchar_t TopicName[11];
+wchar_t ShortName[MAX_PATH];
+wchar_t **Params = NULL;
 int ParamCnt;
 int ParamsSize;
 BOOL SleepFlag;
@@ -73,10 +73,9 @@
 
 void ParseParam(PBOOL IOption, PBOOL VOption)
 {
-	int dirlen, fnpos;
-	char *Param, **ptmp;
-	char Temp[MaxStrLen];
-	PCHAR start, cur, next;
+	wchar_t *Param, **ptmp;
+	wchar_t Temp[MaxStrLen];
+	wchar_t *start, *cur, *next;
 
 	// go home directory
 	_chdir(HomeDir);
@@ -87,35 +86,35 @@
 	SleepFlag = FALSE;
 	*IOption = FALSE;
 	*VOption = FALSE;
-	Param = GetCommandLineA();
+	Param = GetCommandLineW();
 
 	ParamsSize = 50;
-	Params = (char **)malloc(sizeof(char*) * ParamsSize);
+	Params = (wchar_t **)malloc(sizeof(wchar_t *) * ParamsSize);
 	if (Params) {
-		Params[0] = _strdup(Param);
+		Params[0] = _wcsdup(Param);
 		Params[1] = NULL;
 	}
 
 	// the first term shuld be executable filename of TTMACRO
-	start = GetParam(Temp, sizeof(Temp), Param);
+	start = GetParam(Temp, _countof(Temp), Param);
 	ParamCnt = 0;
 
 	for (cur = start; next = GetParam(Temp, sizeof(Temp), cur); cur = next) {
-		DequoteParam(Temp, sizeof(Temp), Temp);
+		DequoteParam(Temp, _countof(Temp), Temp);
 		if (ParamCnt == 0) {
-			if (_strnicmp(Temp,"/D=",3)==0) { // DDE option
-				strncpy_s(TopicName, sizeof(TopicName), &Temp[3], _TRUNCATE);
+			if (_wcsnicmp(Temp,L"/D=",3)==0) { // DDE option
+				wcsncpy_s(TopicName, _countof(TopicName), &Temp[3], _TRUNCATE);
 				continue;
 			}
-			else if (_stricmp(Temp, "/I")==0) {
+			else if (_wcsicmp(Temp, L"/I")==0) {
 				*IOption = TRUE;
 				continue;
 			}
-			else if (_stricmp(Temp, "/S")==0) {
+			else if (_wcsicmp(Temp, L"/S")==0) {
 				SleepFlag = TRUE;
 				continue;
 			}
-			else if (_stricmp(Temp, "/V")==0) {
+			else if (_wcsicmp(Temp, L"/V")==0) {
 				*VOption = TRUE;
 				continue;
 			}
@@ -122,7 +121,7 @@
 		}
 
 		if (++ParamCnt == 1) {
-			strncpy_s(FileName, sizeof(FileName), Temp, _TRUNCATE);
+			wcsncpy_s(FileName, _countof(FileName), Temp, _TRUNCATE);
 			if (Params == NULL) {
 				break;
 			}
@@ -130,7 +129,7 @@
 		else {
 			if (ParamsSize <= ParamCnt) {
 				ParamsSize += 10;
-				ptmp = (char **)realloc(Params, sizeof(char*) * ParamsSize);
+				ptmp = (wchar_t **)realloc(Params, sizeof(wchar_t*) * ParamsSize);
 				if (ptmp == NULL) {
 					ParamCnt--;
 					break;
@@ -137,7 +136,7 @@
 				}
 				Params = ptmp;
 			}
-			Params[ParamCnt] = _strdup(Temp);
+			Params[ParamCnt] = _wcsdup(Temp);
 		}
 	}
 
@@ -145,17 +144,18 @@
 		FileName[0] = 0;
 	}
 	else if (FileName[0]!=0) {
-		if (GetFileNamePos(FileName, &dirlen, &fnpos)) {
-			FitFileName(&FileName[fnpos], sizeof(FileName) - fnpos, ".TTL");
-			strncpy_s(ShortName, sizeof(ShortName), &FileName[fnpos], _TRUNCATE);
+		size_t dirlen, fnpos;
+		if (GetFileNamePosW(FileName, &dirlen, &fnpos)) {
+			FitFileNameW(&FileName[fnpos], _countof(FileName) - fnpos, L".TTL");
+			wcsncpy_s(ShortName, _countof(ShortName), &FileName[fnpos], _TRUNCATE);
 			if (dirlen==0) {
-				strncpy_s(FileName, sizeof(FileName), HomeDir, _TRUNCATE);
-				AppendSlash(FileName, sizeof(FileName));
-				strncat_s(FileName, sizeof(FileName), ShortName, _TRUNCATE);
+				wcsncpy_s(FileName, _countof(FileName), HomeDirW, _TRUNCATE);
+				AppendSlashW(FileName, _countof(FileName));
+				wcsncat_s(FileName, _countof(FileName), ShortName, _TRUNCATE);
 			}
 
 			if (Params) {
-				Params[1] = _strdup(ShortName);
+				Params[1] = _wcsdup(ShortName);
 			}
 		}
 		else {
@@ -166,9 +166,9 @@
 
 BOOL GetFileName(HWND HWin)
 {
-	char FNFilter[31];
-	OPENFILENAME FNameRec;
-	char uimsg[MAX_UIMSG], uimsg2[MAX_UIMSG];
+	wchar_t FNFilter[31];
+	OPENFILENAMEW FNameRec;
+	wchar_t uimsg[MAX_UIMSG], uimsg2[MAX_UIMSG];
 
 	if (FileName[0]!=0) {
 		return FALSE;
@@ -176,11 +176,11 @@
 
 	memset(FNFilter, 0, sizeof(FNFilter));
 	memset(&FNameRec, 0, sizeof(OPENFILENAME));
-	get_lang_msg("FILEDLG_OPEN_MACRO_FILTER", uimsg, sizeof(uimsg), "Macro files (*.ttl)\\0*.ttl\\0\\0", UILanguageFile);
+	get_lang_msgW("FILEDLG_OPEN_MACRO_FILTER", uimsg, sizeof(uimsg), L"Macro files (*.ttl)\\0*.ttl\\0\\0", UILanguageFile);
 	memcpy(FNFilter, uimsg, sizeof(FNFilter));
 
 	// sizeof(OPENFILENAME) \x82ł\xCD Windows98/NT \x82ŏI\x97\xB9\x82\xB5\x82Ă\xB5\x82܂\xA4\x82\xBD\x82\xDF (2006.8.14 maya)
-	FNameRec.lStructSize = get_OPENFILENAME_SIZE();
+	FNameRec.lStructSize = get_OPENFILENAME_SIZEW();
 	FNameRec.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
 	FNameRec.hwndOwner = HWin;
 	FNameRec.lpstrFilter = FNFilter;
@@ -193,11 +193,11 @@
 	FNameRec.lpstrInitialDir = HomeDir;
 #endif
 	FNameRec.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
-	FNameRec.lpstrDefExt = "TTL";
-	get_lang_msg("FILEDLG_OPEN_MACRO_TITLE", uimsg2, sizeof(uimsg2), "MACRO: Open macro", UILanguageFile);
+	FNameRec.lpstrDefExt = L"TTL";
+	get_lang_msgW("FILEDLG_OPEN_MACRO_TITLE", uimsg2, sizeof(uimsg2), L"MACRO: Open macro", UILanguageFile);
 	FNameRec.lpstrTitle = uimsg2;
-	if (GetOpenFileName(&FNameRec)) {
-		strncpy_s(ShortName, sizeof(ShortName), &(FileName[FNameRec.nFileOffset]), _TRUNCATE);
+	if (GetOpenFileNameW(&FNameRec)) {
+		wcsncpy_s(ShortName, _countof(ShortName), &(FileName[FNameRec.nFileOffset]), _TRUNCATE);
 	}
 	else {
 		FileName[0] = 0;

Modified: trunk/teraterm/ttpmacro/ttmdlg.h
===================================================================
--- trunk/teraterm/ttpmacro/ttmdlg.h	2021-09-19 15:14:49 UTC (rev 9434)
+++ trunk/teraterm/ttpmacro/ttmdlg.h	2021-09-19 15:15:00 UTC (rev 9435)
@@ -52,10 +52,10 @@
 
 extern char HomeDir[MAX_PATH];
 extern wchar_t *HomeDirW;
-extern char FileName[MAX_PATH];
-extern char TopicName[11];
-extern char ShortName[MAX_PATH];
-extern char **Params;
+extern wchar_t FileName[MAX_PATH];
+extern wchar_t TopicName[11];
+extern wchar_t ShortName[MAX_PATH];
+extern wchar_t **Params;
 extern int ParamCnt;
 extern BOOL SleepFlag;
 

Modified: trunk/teraterm/ttpmacro/ttmmain.cpp
===================================================================
--- trunk/teraterm/ttpmacro/ttmmain.cpp	2021-09-19 15:14:49 UTC (rev 9434)
+++ trunk/teraterm/ttpmacro/ttmmain.cpp	2021-09-19 15:15:00 UTC (rev 9435)
@@ -250,7 +250,6 @@
 		{ IDC_CTRLPAUSESTART, "BTN_PAUSE" },
 		{ IDC_CTRLEND, "BTN_END" },
 	};
-	char Temp[MAX_PATH + 8]; // MAX_PATH + "MACRO - "(8)
 	BOOL IOption, VOption;
 	int CmdShow;
 	int fuLoad = LR_DEFAULTCOLOR;
@@ -293,9 +292,10 @@
 	// wait4all
 	register_macro_window(GetSafeHwnd());
 
-	strncpy_s(Temp, sizeof(Temp), "MACRO - ", _TRUNCATE);
-	strncat_s(Temp, sizeof(Temp), ShortName, _TRUNCATE);
-	SetWindowText(Temp);
+	wchar_t Temp[MAX_PATH + 8]; // MAX_PATH + "MACRO - "(8)
+	wcsncpy_s(Temp, _countof(Temp), L"MACRO - ", _TRUNCATE);
+	wcsncat_s(Temp, _countof(Temp), ShortName, _TRUNCATE);
+	SetWindowTextW(Temp);
 
 	// send the initialization signal to TT
 	SendCmnd(CmdInit,0);

Modified: trunk/teraterm/ttpmacro/ttmparse.cpp
===================================================================
--- trunk/teraterm/ttpmacro/ttmparse.cpp	2021-09-19 15:14:49 UTC (rev 9434)
+++ trunk/teraterm/ttpmacro/ttmparse.cpp	2021-09-19 15:15:00 UTC (rev 9435)
@@ -1935,7 +1935,7 @@
 	}
 }
 
-void SetStrValInArray(TVarId VarId, int Index, PCHAR Str, LPWORD Err)
+void SetStrValInArray(TVarId VarId, int Index, const char *Str, LPWORD Err)
 {
 	TVarId id;
 

Modified: trunk/teraterm/ttpmacro/ttmparse.h
===================================================================
--- trunk/teraterm/ttpmacro/ttmparse.h	2021-09-19 15:14:49 UTC (rev 9434)
+++ trunk/teraterm/ttpmacro/ttmparse.h	2021-09-19 15:15:00 UTC (rev 9435)
@@ -355,7 +355,7 @@
 void GetAryVar(PVarId VarId, WORD VarType, LPWORD Err);
 void GetAryVarByName(PVarId VarId, const char *Name, WORD VarType, LPWORD Err);
 void SetIntValInArray(TVarId VarId, int Index, int Val, LPWORD Err);
-void SetStrValInArray(TVarId VarId, int Index, PCHAR Str, LPWORD Err);
+void SetStrValInArray(TVarId VarId, int Index, const char *Str, LPWORD Err);
 int GetIntAryVarSize(TVarId VarId);
 int GetStrAryVarSize(TVarId VarId);
 


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