Revision: 8077 https://osdn.net/projects/ttssh2/scm/svn/commits/8077 Author: zmatsuo Date: 2019-09-06 22:26:10 +0900 (Fri, 06 Sep 2019) Log Message: ----------- i18n対応 - comportinfo.cpp のエンコーディングをshift jisにした - GetI18nStrW()#i18n.c をいつでも(Unicode/ANSIビルドどちらでも)使えるようにした - lngファイル - とりあえず日本語のみ - セクションは仮決め Modified Paths: -------------- branches/comportinfo/installer/release/lang/Japanese.lng branches/comportinfo/teraterm/common/i18n.c branches/comportinfo/teraterm/common/i18n.h branches/comportinfo/teraterm/common/ttlib.c branches/comportinfo/teraterm/common/ttlib.h branches/comportinfo/teraterm/ttpcmn/comportinfo.cpp branches/comportinfo/teraterm/ttpcmn/comportinfo.h branches/comportinfo/teraterm/ttpcmn/ttcmn.c branches/comportinfo/teraterm/ttpdlg/ttdlg.c -------------- next part -------------- Modified: branches/comportinfo/installer/release/lang/Japanese.lng =================================================================== --- branches/comportinfo/installer/release/lang/Japanese.lng 2019-09-06 13:25:52 UTC (rev 8076) +++ branches/comportinfo/installer/release/lang/Japanese.lng 2019-09-06 13:26:10 UTC (rev 8077) @@ -1138,3 +1138,9 @@ DLG_INTERVAL=\x8AԊu(\x95b)(&I) DLG_COMMAND=\x83R\x83}\x83\x93\x83h(&C) DLG_ADD_NEWLINE=\x89\xFC\x8Ds\x82\xF0\x92lj\xC1(&A) + +[Tera Term.ComInfo] +FRIENDLY_NAME=\x83t\x83\x8C\x83\x93\x83h\x83\x8A\x81[\x96\xBC +DEVICE_INSTANCE_ID=\x83f\x83o\x83C\x83X\x83C\x83\x93\x83X\x83^\x83\x93\x83XID +DEVICE_MANUFACTURER=\x90\xBB\x91\xA2\x8C\xB3 +DRIVER_VERSION=\x83h\x83\x89\x83C\x83o\x81[\x83o\x81[\x83W\x83\x87\x83\x93 Modified: branches/comportinfo/teraterm/common/i18n.c =================================================================== --- branches/comportinfo/teraterm/common/i18n.c 2019-09-06 13:25:52 UTC (rev 8076) +++ branches/comportinfo/teraterm/common/i18n.c 2019-09-06 13:26:10 UTC (rev 8077) @@ -33,9 +33,9 @@ #include <assert.h> #include <tchar.h> +DllExport void WINAPI GetI18nStrW(const char *section, const char *key, wchar_t *buf, int buf_len, const wchar_t *def, const char *iniFile) +{ #if defined(UNICODE) -DllExport void GetI18nStrW(const char *section, const char *key, wchar_t *buf, int buf_len, const wchar_t *def, const char *iniFile) -{ wchar_t sectionW[64]; wchar_t keyW[128]; wchar_t iniFileW[MAX_PATH]; @@ -43,9 +43,15 @@ MultiByteToWideChar(CP_ACP, 0, key, -1, keyW, _countof(keyW)); MultiByteToWideChar(CP_ACP, 0, iniFile, -1, iniFileW, _countof(iniFileW)); GetPrivateProfileStringW(sectionW, keyW, def, buf, buf_len, iniFileW); +#else + char tmp[MAX_UIMSG]; + char defA[MAX_UIMSG]; + WideCharToMultiByte(CP_ACP, 0, def, -1, defA, _countof(defA), NULL, NULL); + GetPrivateProfileStringA(section, key, defA, tmp, _countof(tmp), iniFile); + MultiByteToWideChar(CP_ACP, 0, tmp, -1, buf, buf_len); +#endif RestoreNewLineW(buf); } -#endif DllExport void WINAPI GetI18nStr(const char *section, const char *key, PCHAR buf, int buf_len, const char *def, const char *iniFile) { Modified: branches/comportinfo/teraterm/common/i18n.h =================================================================== --- branches/comportinfo/teraterm/common/i18n.h 2019-09-06 13:25:52 UTC (rev 8076) +++ branches/comportinfo/teraterm/common/i18n.h 2019-09-06 13:26:10 UTC (rev 8077) @@ -46,9 +46,7 @@ const char *key; } DlgTextInfo; -#if defined(UNICODE) DllExport void WINAPI GetI18nStrW(const char *section, const char *key, wchar_t *buf, int buf_len, const wchar_t *def, const char *iniFile); -#endif DllExport void WINAPI GetI18nStr(const char *section, const char *key, PCHAR buf, int buf_len, const char *def, const char *iniFile); DllExport int WINAPI GetI18nLogfont(const char *section, const char *key, PLOGFONTA logfont, int ppi, const char *iniFile); DllExport void WINAPI SetI18DlgStrs(const char *section, HWND hDlgWnd, Modified: branches/comportinfo/teraterm/common/ttlib.c =================================================================== --- branches/comportinfo/teraterm/common/ttlib.c 2019-09-06 13:25:52 UTC (rev 8076) +++ branches/comportinfo/teraterm/common/ttlib.c 2019-09-06 13:26:10 UTC (rev 8077) @@ -805,6 +805,46 @@ memcpy(Text, buf, size); } +void RestoreNewLineW(wchar_t *Text) +{ + int i, j=0; + int size= wcslen(Text); + wchar_t *buf = (wchar_t *)_alloca((size+1) * sizeof(wchar_t)); + + memset(buf, 0, (size+1) * sizeof(wchar_t)); + for (i=0; i<size; i++) { + if (Text[i] == L'\\' && i<size ) { + switch (Text[i+1]) { + case L'\\': + buf[j] = L'\\'; + i++; + break; + case L'n': + buf[j] = L'\n'; + i++; + break; + case L't': + buf[j] = L'\t'; + i++; + break; + case L'0': + buf[j] = L'\0'; + i++; + break; + default: + buf[j] = L'\\'; + } + j++; + } + else { + buf[j] = Text[i]; + j++; + } + } + /* use memcpy to copy with '\0' */ + memcpy(Text, buf, size * sizeof(wchar_t)); +} + BOOL GetNthString(PCHAR Source, int Nth, int Size, PCHAR Dest) { int i, j, k; Modified: branches/comportinfo/teraterm/common/ttlib.h =================================================================== --- branches/comportinfo/teraterm/common/ttlib.h 2019-09-06 13:25:52 UTC (rev 8076) +++ branches/comportinfo/teraterm/common/ttlib.h 2019-09-06 13:26:10 UTC (rev 8077) @@ -67,6 +67,7 @@ void ParseStrftimeFileName(PCHAR FName, int destlen); void ConvFName(PCHAR HomeDir, PCHAR Temp, int templen, PCHAR DefExt, PCHAR FName, int destlen); void RestoreNewLine(PCHAR Text); +void RestoreNewLineW(wchar_t *Text); BOOL GetNthString(PCHAR Source, int Nth, int Size, PCHAR Dest); void GetNthNum(PCHAR Source, int Nth, int far *Num); int GetNthNum2(PCHAR Source, int Nth, int defval); Modified: branches/comportinfo/teraterm/ttpcmn/comportinfo.cpp =================================================================== --- branches/comportinfo/teraterm/ttpcmn/comportinfo.cpp 2019-09-06 13:25:52 UTC (rev 8076) +++ branches/comportinfo/teraterm/ttpcmn/comportinfo.cpp 2019-09-06 13:26:10 UTC (rev 8077) @@ -1,4 +1,4 @@ -/* +/* * Copyright (C) 2019 TeraTerm Project * All rights reserved. * @@ -26,7 +26,6 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -//#include <stdio.h> #include <windows.h> #include <devguid.h> #include <setupapi.h> @@ -83,8 +82,17 @@ return !IsWindowsNTKernel(); } +#if 0 +static void GetI18nStrW(const char *section, const char *key, wchar_t *buf, int buf_len, + const wchar_t *def, const char *iniFile) +{ + (void)iniFile; + wcscpy_s(buf, buf_len, def); +} +#endif + /** - * ポート名を取得 + * \x83|\x81[\x83g\x96\xBC\x82\xF0\x8E擾 */ static BOOL GetComPortName(HDEVINFO hDevInfo, SP_DEVINFO_DATA *DeviceInfoData, wchar_t **str) { @@ -98,7 +106,7 @@ DICS_FLAG_GLOBAL, 0, DIREG_DEV, KEY_READ); if (hKey == NULL){ - // ポート名が取得できない? + // \x83|\x81[\x83g\x96\xBC\x82\xAA\x8E擾\x82ł\xAB\x82Ȃ\xA2? *str = NULL; return FALSE; } @@ -106,7 +114,7 @@ wchar_t* port_name = NULL; long r; if (pRegQueryValueExW != NULL && !IsWindows9X()) { - // 9x系ではうまく動作しない + // 9x\x8Cn\x82ł͂\xA4\x82܂\xAD\x93\xAE\x8D삵\x82Ȃ\xA2 r = pRegQueryValueExW(hKey, L"PortName", 0, &dwType, NULL, &byte_len); port_name = (wchar_t* )malloc(byte_len); @@ -140,27 +148,32 @@ } /** - * プロパティ取得 + * \x83v\x83\x8D\x83p\x83e\x83B\x8E擾 */ -static void GetComPropartys(HDEVINFO hDevInfo, SP_DEVINFO_DATA *DeviceInfoData, +static void GetComPropartys(HDEVINFO hDevInfo, SP_DEVINFO_DATA *DeviceInfoData, const char *lang, wchar_t **friendly_name, wchar_t **str) { typedef struct { const wchar_t *name; + const char *key; const DEVPROPKEY *PropertyKey; DWORD Property; } list_t; static const list_t list[] = { - { L"フレンドリー名(Device Friendly Name)", + { L"Device Friendly Name", + "FRIENDLY_NAME", &DEVPKEY_Device_FriendlyName, SPDRP_FRIENDLYNAME }, - { L"デバイスインスタンスID(Device Instance ID)", + { L"Device Instance ID", + "DEVICE_INSTANCE_ID", &DEVPKEY_Device_InstanceId, SPDRP_MAXIMUM_PROPERTY }, - { L"製造元(Device Manufacturer)", + { L"Device Manufacturer", + "DEVICE_MANUFACTURER", &DEVPKEY_Device_Manufacturer, SPDRP_MFG }, - { L"ドライバーバージョン(Driver Version)", + { L"Driver Version", + "DRIVER_VERSION", &DEVPKEY_Device_DriverVersion, SPDRP_MAXIMUM_PROPERTY } }; @@ -188,7 +201,7 @@ r = pSetupDiGetDevicePropertyW(hDevInfo, DeviceInfoData, p->PropertyKey, &ulPropertyType, (PBYTE)str_prop, size, &size, 0); } else if (p->PropertyKey == &DEVPKEY_Device_InstanceId) { - // InstanceIdはA系で決め打ち + // InstanceId\x82\xCDA\x8Cn\x82Ō\x88\x82ߑł\xBF DWORD len_a; SetupDiGetDeviceInstanceIdA(hDevInfo, DeviceInfoData, @@ -212,7 +225,7 @@ } else if (p->Property == SPDRP_MAXIMUM_PROPERTY) { r = FALSE; } else if (pSetupDiGetDeviceRegistryPropertyW != NULL && !IsWindows9X()) { - // 9x系ではうまく動作しない + // 9x\x8Cn\x82ł͂\xA4\x82܂\xAD\x93\xAE\x8D삵\x82Ȃ\xA2 DWORD dwPropType; r = pSetupDiGetDeviceRegistryPropertyW(hDevInfo, DeviceInfoData, @@ -255,12 +268,14 @@ free(str_prop_a); } if (r != FALSE) { - size_t name_len = wcslen(p->name); + wchar_t name[MAX_UIMSG]; + GetI18nStrW("Tera Term.ComInfo", p->key, name, _countof(name), p->name, lang); + size_t name_len = wcslen(name); size_t prop_len = wcslen(str_prop); len = len + (name_len + (i==0?1:2) + 2 + 2 + prop_len); s = (wchar_t *)realloc(s, sizeof(wchar_t) * len); if (i != 0) wcscat_s(s, len, L"\r\n"); - wcscat_s(s, len, p->name); + wcscat_s(s, len, name); wcscat_s(s, len, L"\r\n "); wcscat_s(s, len, str_prop); } @@ -275,7 +290,7 @@ *str = s; } -/* 配列ソート用 */ +/* \x94z\x97\xF1\x83\\x81[\x83g\x97p */ static int sort_sub(const void *a_, const void *b_) { const ComPortInfo_t *a = (ComPortInfo_t *)a_; @@ -290,14 +305,14 @@ } /** - * comポートの情報を取得する + * com\x83|\x81[\x83g\x82̏\xEE\x95\xF1\x82\xF0\x8E擾\x82\xB7\x82\xE9 * - * @param[out] count 情報数(0のときcomポートなし) - * @return 情報へのポインタ(配列)、ポート番号の小さい順 - * NULLのときcomポートなし - * 使用後ComPortInfoFree()を呼ぶこと + * @param[out] count \x8F\xEE\x95\xF1\x90\x94(0\x82̂Ƃ\xABcom\x83|\x81[\x83g\x82Ȃ\xB5) + * @return \x8F\xEE\x95\xF1\x82ւ̃|\x83C\x83\x93\x83^(\x94z\x97\xF1)\x81A\x83|\x81[\x83g\x94ԍ\x86\x82̏\xAC\x82\xB3\x82\xA2\x8F\x87 + * NULL\x82̂Ƃ\xABcom\x83|\x81[\x83g\x82Ȃ\xB5 + * \x8Eg\x97p\x8C\xE3ComPortInfoFree()\x82\xF0\x8CĂԂ\xB1\x82\xC6 */ -ComPortInfo_t * WINAPI ComPortInfoGet(int *count) +ComPortInfo_t * WINAPI ComPortInfoGet(int *count, const char *lang) { int comport_count = 0; ComPortInfo_t *comport_infos = NULL; @@ -327,7 +342,7 @@ if (!SetupDiEnumDeviceInfo(hDevInfo, i, &DeviceInfoData)) break; - // ポート名取得 ("COM1"など) + // \x83|\x81[\x83g\x96\xBC\x8E擾 ("COM1"\x82Ȃ\xC7) wchar_t *port_name; if (!GetComPortName(hDevInfo, &DeviceInfoData, &port_name)) { continue; @@ -337,10 +352,10 @@ port_no = _wtoi(port_name+3); } - // 情報取得 + // \x8F\xEE\x95\xF1\x8E擾 wchar_t *str_friendly_name; wchar_t *str_prop; - GetComPropartys(hDevInfo, &DeviceInfoData, &str_friendly_name, &str_prop); + GetComPropartys(hDevInfo, &DeviceInfoData, lang, &str_friendly_name, &str_prop); comport_count++; comport_infos = (ComPortInfo_t *)realloc(comport_infos, @@ -352,7 +367,7 @@ p->property = str_prop; } - /* ポート名順に並べる */ + /* \x83|\x81[\x83g\x96\xBC\x8F\x87\x82ɕ\xC0\x82ׂ\xE9 */ qsort(comport_infos, comport_count, sizeof(comport_infos[0]), sort_sub); *count = comport_count; @@ -369,9 +384,3 @@ } free(info); } - -/* - * Local Variables: - * coding:utf-8-with-signature - * End: - */ Modified: branches/comportinfo/teraterm/ttpcmn/comportinfo.h =================================================================== --- branches/comportinfo/teraterm/ttpcmn/comportinfo.h 2019-09-06 13:25:52 UTC (rev 8076) +++ branches/comportinfo/teraterm/ttpcmn/comportinfo.h 2019-09-06 13:26:10 UTC (rev 8077) @@ -45,7 +45,7 @@ wchar_t *property; } ComPortInfo_t; -DllExport ComPortInfo_t * WINAPI ComPortInfoGet(int *count); +DllExport ComPortInfo_t * WINAPI ComPortInfoGet(int *count, const char *lang); DllExport void WINAPI ComPortInfoFree(ComPortInfo_t *info, int count); #ifdef __cplusplus Modified: branches/comportinfo/teraterm/ttpcmn/ttcmn.c =================================================================== --- branches/comportinfo/teraterm/ttpcmn/ttcmn.c 2019-09-06 13:25:52 UTC (rev 8076) +++ branches/comportinfo/teraterm/ttpcmn/ttcmn.c 2019-09-06 13:26:10 UTC (rev 8077) @@ -2493,7 +2493,7 @@ BOOL found; int i; int count; - ComPortInfo_t *info = ComPortInfoGet(&count); + ComPortInfo_t *info = ComPortInfoGet(&count, pm->ts.UILanguageFile); if (count == 0) return 0; found = FALSE; Modified: branches/comportinfo/teraterm/ttpdlg/ttdlg.c =================================================================== --- branches/comportinfo/teraterm/ttpdlg/ttdlg.c 2019-09-06 13:25:52 UTC (rev 8076) +++ branches/comportinfo/teraterm/ttpdlg/ttdlg.c 2019-09-06 13:26:10 UTC (rev 8077) @@ -1561,7 +1561,7 @@ j = 0; w = 1; - ComPortInfoPtr = ComPortInfoGet(&ComPortInfoCount); + ComPortInfoPtr = ComPortInfoGet(&ComPortInfoCount, UILanguageFile); if (ComPortInfoCount > 0) { for (i=0; i<ComPortInfoCount; i++) { ComPortInfo_t *p = &ComPortInfoPtr[i];