Revision: 9399 https://osdn.net/projects/ttssh2/scm/svn/commits/9399 Author: zmatsuo Date: 2021-09-05 00:14:04 +0900 (Sun, 05 Sep 2021) Log Message: ----------- plugin AddValueToList() を利用しているところを Unicode化 - iniファイル内のリスト(キュー)に値を追加 - AddHostToList() - teraterm/broadcast.cpp Modified Paths: -------------- branches/plugin_unicode/teraterm/teraterm/broadcast.cpp branches/plugin_unicode/teraterm/teraterm/ttsetup.h branches/plugin_unicode/teraterm/teraterm/vtwin.cpp branches/plugin_unicode/teraterm/ttpset/ttset.c -------------- next part -------------- Modified: branches/plugin_unicode/teraterm/teraterm/broadcast.cpp =================================================================== --- branches/plugin_unicode/teraterm/teraterm/broadcast.cpp 2021-09-04 15:13:52 UTC (rev 9398) +++ branches/plugin_unicode/teraterm/teraterm/broadcast.cpp 2021-09-04 15:14:04 UTC (rev 9399) @@ -87,25 +87,25 @@ * buf\x82̒\xBC\x8C\xE3\x82ɂ\xCD \0 \x82͕t\x82\xA9\x82Ȃ\xA2 */ -#define BROADCAST_LOGFILE "broadcast.log" +#define BROADCAST_LOGFILE L"broadcast.log" -static void ApplyBroadCastCommandHisotry(HWND Dialog, char *historyfile) +static void ApplyBroadCastCommandHisotry(HWND Dialog, wchar_t *historyfile) { - char EntName[13]; - char Command[HostNameMaxLength+1]; + wchar_t EntName[13]; + wchar_t Command[HostNameMaxLength+1]; int i = 1; SendDlgItemMessage(Dialog, IDC_COMMAND_EDIT, CB_RESETCONTENT, 0, 0); do { - _snprintf_s(EntName, sizeof(EntName), _TRUNCATE, "Command%d", i); - GetPrivateProfileStringA("BroadcastCommands",EntName,"", + _snwprintf_s(EntName, _countof(EntName), _TRUNCATE, L"Command%d", i); + GetPrivateProfileStringW(L"BroadcastCommands",EntName, L"", Command,sizeof(Command), historyfile); - if (strlen(Command) > 0) { - SendDlgItemMessage(Dialog, IDC_COMMAND_EDIT, CB_ADDSTRING, - 0, (LPARAM)Command); + if (Command[0] != 0) { + SendDlgItemMessageW(Dialog, IDC_COMMAND_EDIT, CB_ADDSTRING, + 0, (LPARAM)Command); } i++; - } while ((i <= ts.MaxBroadcatHistory) && (strlen(Command)>0)); + } while ((i <= ts.MaxBroadcatHistory) && (Command[0] != 0)); SendDlgItemMessage(Dialog, IDC_COMMAND_EDIT, EM_LIMITTEXT, HostNameMaxLength-1, 0); @@ -419,7 +419,6 @@ }; LRESULT checked; LRESULT history; - char historyfile[MAX_PATH]; static HWND hwndBroadcast = NULL; // Broadcast dropdown static HWND hwndBroadcastEdit = NULL; // Edit control on Broadcast dropdown // for resize @@ -443,7 +442,7 @@ } break; - case WM_INITDIALOG: + case WM_INITDIALOG: { // \x83\x89\x83W\x83I\x83{\x83^\x83\x93\x82̃f\x83t\x83H\x83\x8B\x83g\x82\xCD CR \x82ɂ\xB7\x82\xE9\x81B SendMessage(GetDlgItem(hWnd, IDC_RADIO_CR), BM_SETCHECK, BST_CHECKED, 0); // \x83f\x83t\x83H\x83\x8B\x83g\x82Ń`\x83F\x83b\x83N\x83{\x83b\x83N\x83X\x82\xF0 checked \x8F\xF3\x91Ԃɂ\xB7\x82\xE9\x81B @@ -452,8 +451,9 @@ if (ts.BroadcastCommandHistory) { SendMessage(GetDlgItem(hWnd, IDC_HISTORY_CHECK), BM_SETCHECK, BST_CHECKED, 0); } - GetDefaultFName(ts.HomeDir, BROADCAST_LOGFILE, historyfile, sizeof(historyfile)); + wchar_t *historyfile = GetDefaultFNameW(ts.HomeDirW, BROADCAST_LOGFILE); ApplyBroadCastCommandHisotry(hWnd, historyfile); + free(historyfile); // \x83G\x83f\x83B\x83b\x83g\x83R\x83\x93\x83g\x83\x8D\x81[\x83\x8B\x82Ƀt\x83H\x81[\x83J\x83X\x82\xF0\x82\xA0\x82Ă\xE9 SetFocus(GetDlgItem(hWnd, IDC_COMMAND_EDIT)); @@ -512,6 +512,7 @@ SetTimer(hWnd, list_timer_id, list_timer_tick, NULL); return FALSE; + } case WM_COMMAND: switch (wp) { @@ -583,15 +584,14 @@ // \x83u\x83\x8D\x81[\x83h\x83L\x83\x83\x83X\x83g\x83R\x83}\x83\x93\x83h\x82̗\x9A\x97\xF0\x82\xF0\x95ۑ\xB6 (2007.3.3 maya) history = SendMessage(GetDlgItem(hWnd, IDC_HISTORY_CHECK), BM_GETCHECK, 0, 0); if (history) { - GetDefaultFName(ts.HomeDir, BROADCAST_LOGFILE, historyfile, sizeof(historyfile)); + wchar_t *historyfile = GetDefaultFNameW(ts.HomeDirW, BROADCAST_LOGFILE); if (LoadTTSET()) { - char *bufA = ToCharW(buf); // TODO wchar_t \x91Ή\x9E - (*AddValueToList)(historyfile, bufA, "BroadcastCommands", "Command", + (*AddValueToList)(historyfile, buf, L"BroadcastCommands", L"Command", ts.MaxBroadcatHistory); - free(bufA); FreeTTSET(); } ApplyBroadCastCommandHisotry(hWnd, historyfile); + free(historyfile); ts.BroadcastCommandHistory = TRUE; } else { @@ -638,8 +638,9 @@ case IDC_COMMAND_EDIT: if (HIWORD(wp) == CBN_DROPDOWN) { - GetDefaultFName(ts.HomeDir, BROADCAST_LOGFILE, historyfile, sizeof(historyfile)); + wchar_t *historyfile = GetDefaultFNameW(ts.HomeDirW, BROADCAST_LOGFILE); ApplyBroadCastCommandHisotry(hWnd, historyfile); + free(historyfile); } return FALSE; Modified: branches/plugin_unicode/teraterm/teraterm/ttsetup.h =================================================================== --- branches/plugin_unicode/teraterm/teraterm/ttsetup.h 2021-09-04 15:13:52 UTC (rev 9398) +++ branches/plugin_unicode/teraterm/teraterm/ttsetup.h 2021-09-04 15:14:04 UTC (rev 9399) @@ -48,14 +48,14 @@ typedef void (PASCAL *PReadKeyboardCnf)(const wchar_t *FName, PKeyMap KeyMap, BOOL ShowWarning); //typedef void (PASCAL *PCopyHostList)(PCHAR IniSrc, PCHAR IniDest); typedef void (PASCAL *PCopyHostList)(const wchar_t *IniSrc, const wchar_t *IniDest); -typedef void (PASCAL *PAddHostToList) - (PCHAR FName, PCHAR Host); +//typedef void (PASCAL *PAddHostToList)(PCHAR FName, PCHAR Host); +typedef void (PASCAL *PAddHostToList)(const wchar_t *FName, const wchar_t *Host); typedef void (PASCAL *PParseParam) (PCHAR Param, PTTSet ts, PCHAR DDETopic); //typedef void (PASCAL *PCopySerialList)(PCHAR IniSrc, PCHAR IniDest, PCHAR section, PCHAR key, int MaxList); typedef void (PASCAL *PCopySerialList)(const wchar_t *IniSrc, const wchar_t *IniDest, const wchar_t *section, const wchar_t *key, int MaxList); -typedef void (PASCAL *PAddValueToList) - (PCHAR FName, PCHAR Host, PCHAR section, PCHAR key, int MaxList); +//typedef void (PASCAL *PAddValueToList)(PCHAR FName, PCHAR Host, PCHAR section, PCHAR key, int MaxList); +typedef void (PASCAL *PAddValueToList)(const wchar_t *FName, const wchar_t *Host, const wchar_t *section, const wchar_t *key, int MaxList); extern PReadIniFile ReadIniFile; extern PWriteIniFile WriteIniFile; Modified: branches/plugin_unicode/teraterm/teraterm/vtwin.cpp =================================================================== --- branches/plugin_unicode/teraterm/teraterm/vtwin.cpp 2021-09-04 15:13:52 UTC (rev 9398) +++ branches/plugin_unicode/teraterm/teraterm/vtwin.cpp 2021-09-04 15:14:04 UTC (rev 9399) @@ -3499,7 +3499,9 @@ if ((*GetHostName)(HVTWin,&GetHNRec)) { if ((GetHNRec.PortType==IdTCPIP) && LoadTTSET()) { if (ts.HistoryList) { - (*AddHostToList)(ts.SetupFName,GetHNRec.HostName); + wchar_t *HostNameW = ToWcharA(GetHNRec.HostName); + (*AddHostToList)(ts.SetupFNameW, HostNameW); + free(HostNameW); } if (ts.JumpList) { add_session_to_jumplist(GetHNRec.HostName, GetHNRec.SetupFN); Modified: branches/plugin_unicode/teraterm/ttpset/ttset.c =================================================================== --- branches/plugin_unicode/teraterm/ttpset/ttset.c 2021-09-04 15:13:52 UTC (rev 9398) +++ branches/plugin_unicode/teraterm/ttpset/ttset.c 2021-09-04 15:14:04 UTC (rev 9399) @@ -55,7 +55,6 @@ #ifndef CLEARTYPE_QUALITY #define CLEARTYPE_QUALITY 5 #endif -#define INI_FILE_IS_UNICODE 1 #define Section "Tera Term" #define SectionW L"Tera Term" @@ -161,7 +160,6 @@ return (ret); } -#if INI_FILE_IS_UNICODE #undef GetPrivateProfileInt #undef GetPrivateProfileString #define GetPrivateProfileInt(p1, p2, p3, p4) GetPrivateProfileIntAFileW(p1, p2, p3, p4) @@ -168,7 +166,6 @@ #define GetPrivateProfileString(p1, p2, p3, p4, p5, p6) GetPrivateProfileStringAFileW(p1, p2, p3, p4, p5, p6) #define GetPrivateProfileStringA(p1, p2, p3, p4, p5, p6) GetPrivateProfileStringAFileW(p1, p2, p3, p4, p5, p6) #define WritePrivateProfileStringA(p1, p2, p3, p4) WritePrivateProfileStringAFileW(p1, p2, p3, p4) -#endif /* * \x83V\x83\x8A\x83A\x83\x8B\x83|\x81[\x83g\x8A֘A\x82̐ݒ\xE8 @@ -3626,40 +3623,31 @@ WritePrivateProfileStringW(NULL, NULL, NULL, IniDest); } -void PASCAL AddValueToList(PCHAR FNameA, PCHAR Host, PCHAR section, - PCHAR key, int MaxList) +void PASCAL AddValueToList(const wchar_t *FName, const wchar_t *Host, const wchar_t *section, + const wchar_t *key, int MaxList) { - HANDLE MemH; - PCHAR MemP; - char EntName[13]; + wchar_t *MemP; + wchar_t EntName[13]; int i, j, Len; BOOL Update; -#if INI_FILE_IS_UNICODE - wchar_t *FName = ToWcharA(FNameA); -#else - char *FName = FNameA; -#endif if ((FName[0] == 0) || (Host[0] == 0)) return; - MemH = GlobalAlloc(GHND, (HostNameMaxLength + 1) * MaxList); - if (MemH == NULL) - return; - MemP = GlobalLock(MemH); + MemP = malloc((HostNameMaxLength + 1) * sizeof(wchar_t) * MaxList); if (MemP != NULL) { - strncpy_s(MemP, (HostNameMaxLength + 1) * MaxList, Host, _TRUNCATE); - j = strlen(Host) + 1; + wcsncpy_s(MemP, (HostNameMaxLength + 1) * MaxList, Host, _TRUNCATE); + j = wcslen(Host) + 1; i = 1; Update = TRUE; do { - _snprintf_s(EntName, sizeof(EntName), _TRUNCATE, "%s%i", key, i); + _snwprintf_s(EntName, _countof(EntName), _TRUNCATE, L"%s%i", key, i); /* Get a hostname */ - GetPrivateProfileStringA(section, EntName, "", + GetPrivateProfileStringW(section, EntName, L"", &MemP[j], HostNameMaxLength + 1, FName); - Len = strlen(&MemP[j]); - if (_stricmp(&MemP[j], Host) == 0) { + Len = wcslen(&MemP[j]); + if (_wcsicmp(&MemP[j], Host) == 0) { if (i == 1) Update = FALSE; } @@ -3670,25 +3658,24 @@ } while ((i <= MaxList) && Update); if (Update) { - WritePrivateProfileStringA(section, NULL, NULL, FName); + WritePrivateProfileStringW(section, NULL, NULL, FName); j = 0; i = 1; do { - _snprintf_s(EntName, sizeof(EntName), _TRUNCATE, "%s%i", key, i); + _snwprintf_s(EntName, _countof(EntName), _TRUNCATE, L"%s%i", key, i); if (MemP[j] != 0) - WritePrivateProfileStringA(section, EntName, &MemP[j], + WritePrivateProfileStringW(section, EntName, &MemP[j], FName); - j = j + strlen(&MemP[j]) + 1; + j = j + wcslen(&MemP[j]) + 1; i++; } while ((i <= MaxList) && (MemP[j] != 0)); /* update file */ - WritePrivateProfileString(NULL, NULL, NULL, FName); + WritePrivateProfileStringW(NULL, NULL, NULL, FName); } - GlobalUnlock(MemH); + free(MemP); } - GlobalFree(MemH); } /* copy hostlist from source IniFile to dest IniFile */ @@ -3697,9 +3684,9 @@ CopySerialList(IniSrc, IniDest, L"Hosts", L"Host", MAXHOSTLIST); } -void PASCAL AddHostToList(PCHAR FName, PCHAR Host) +void PASCAL AddHostToList(const wchar_t *FName, const wchar_t *Host) { - AddValueToList(FName, Host, "Hosts", "Host", MAXHOSTLIST); + AddValueToList(FName, Host, L"Hosts", L"Host", MAXHOSTLIST); } #if 0 BOOL NextParam(PCHAR Param, int *i, PCHAR Temp, int Size)