Mercurial > vim
comparison src/GvimExt/gvimext.cpp @ 22924:db65bb242582 v8.2.2009
patch 8.2.2009: MS-Windows: setting $LANG in gvimext only causes problems
Commit: https://github.com/vim/vim/commit/382319211a96adce089673c80eda982cc5259d0d
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Nov 18 15:30:09 2020 +0100
patch 8.2.2009: MS-Windows: setting $LANG in gvimext only causes problems
Problem: MS-Windows: setting $LANG in gvimext only causes problems.
Solution: Do not set $LANG. (Ken Takata, closes https://github.com/vim/vim/issues/7325)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 18 Nov 2020 15:45:05 +0100 |
parents | 7e733046db1d |
children | ee2808fb1be9 |
comparison
equal
deleted
inserted
replaced
22923:277aa4652a3c | 22924:db65bb242582 |
---|---|
159 static char *null_libintl_textdomain(const char *); | 159 static char *null_libintl_textdomain(const char *); |
160 static char *null_libintl_bindtextdomain(const char *, const char *); | 160 static char *null_libintl_bindtextdomain(const char *, const char *); |
161 static int dyn_libintl_init(char *dir); | 161 static int dyn_libintl_init(char *dir); |
162 static void dyn_libintl_end(void); | 162 static void dyn_libintl_end(void); |
163 | 163 |
164 static wchar_t *oldenv = NULL; | |
165 static HINSTANCE hLibintlDLL = 0; | 164 static HINSTANCE hLibintlDLL = 0; |
166 static char *(*dyn_libintl_gettext)(const char *) = null_libintl_gettext; | 165 static char *(*dyn_libintl_gettext)(const char *) = null_libintl_gettext; |
167 static char *(*dyn_libintl_textdomain)(const char *) = null_libintl_textdomain; | 166 static char *(*dyn_libintl_textdomain)(const char *) = null_libintl_textdomain; |
168 static char *(*dyn_libintl_bindtextdomain)(const char *, const char *) | 167 static char *(*dyn_libintl_bindtextdomain)(const char *, const char *) |
169 = null_libintl_bindtextdomain; | 168 = null_libintl_bindtextdomain; |
203 buf = (LPWSTR)malloc(len * sizeof(WCHAR)); | 202 buf = (LPWSTR)malloc(len * sizeof(WCHAR)); |
204 buf2 = (LPWSTR)malloc(len2 * sizeof(WCHAR)); | 203 buf2 = (LPWSTR)malloc(len2 * sizeof(WCHAR)); |
205 if (buf != NULL && buf2 != NULL) | 204 if (buf != NULL && buf2 != NULL) |
206 { | 205 { |
207 GetEnvironmentVariableW(L"PATH", buf, len); | 206 GetEnvironmentVariableW(L"PATH", buf, len); |
208 #ifdef _WIN64 | 207 # ifdef _WIN64 |
209 _snwprintf(buf2, len2, L"%S\\GvimExt64;%s", dir, buf); | 208 _snwprintf(buf2, len2, L"%S\\GvimExt64;%s", dir, buf); |
210 #else | 209 # else |
211 _snwprintf(buf2, len2, L"%S\\GvimExt32;%s", dir, buf); | 210 _snwprintf(buf2, len2, L"%S\\GvimExt32;%s", dir, buf); |
212 #endif | 211 # endif |
213 SetEnvironmentVariableW(L"PATH", buf2); | 212 SetEnvironmentVariableW(L"PATH", buf2); |
214 hLibintlDLL = LoadLibrary(GETTEXT_DLL); | 213 hLibintlDLL = LoadLibrary(GETTEXT_DLL); |
215 #ifdef GETTEXT_DLL_ALT | 214 # ifdef GETTEXT_DLL_ALT |
216 if (!hLibintlDLL) | 215 if (!hLibintlDLL) |
217 hLibintlDLL = LoadLibrary(GETTEXT_DLL_ALT); | 216 hLibintlDLL = LoadLibrary(GETTEXT_DLL_ALT); |
218 #endif | 217 # endif |
219 SetEnvironmentVariableW(L"PATH", buf); | 218 SetEnvironmentVariableW(L"PATH", buf); |
220 } | 219 } |
221 free(buf); | 220 free(buf); |
222 free(buf2); | 221 free(buf2); |
223 if (!hLibintlDLL) | 222 if (!hLibintlDLL) |
271 // | 270 // |
272 static void | 271 static void |
273 dyn_gettext_load(void) | 272 dyn_gettext_load(void) |
274 { | 273 { |
275 char szBuff[BUFSIZE]; | 274 char szBuff[BUFSIZE]; |
276 char szLang[BUFSIZE]; | |
277 DWORD len; | 275 DWORD len; |
278 HKEY keyhandle; | |
279 int gotlang = 0; | |
280 | |
281 strcpy(szLang, "LANG="); | |
282 | |
283 // First try getting the language from the registry, this can be | |
284 // used to overrule the system language. | |
285 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\Vim\\Gvim", 0, | |
286 KEY_READ, &keyhandle) == ERROR_SUCCESS) | |
287 { | |
288 len = BUFSIZE; | |
289 if (RegQueryValueEx(keyhandle, "lang", 0, NULL, (BYTE*)szBuff, &len) | |
290 == ERROR_SUCCESS) | |
291 { | |
292 szBuff[len] = 0; | |
293 strcat(szLang, szBuff); | |
294 gotlang = 1; | |
295 } | |
296 RegCloseKey(keyhandle); | |
297 } | |
298 | |
299 if (!gotlang && getenv("LANG") == NULL) | |
300 { | |
301 // Get the language from the system. | |
302 // Could use LOCALE_SISO639LANGNAME, but it's not in Win95. | |
303 // LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use | |
304 // only the first two. | |
305 len = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME, | |
306 (LPTSTR)szBuff, BUFSIZE); | |
307 if (len >= 2 && _strnicmp(szBuff, "en", 2) != 0) | |
308 { | |
309 // There are a few exceptions (probably more) | |
310 if (_strnicmp(szBuff, "cht", 3) == 0 | |
311 || _strnicmp(szBuff, "zht", 3) == 0) | |
312 strcpy(szBuff, "zh_TW"); | |
313 else if (_strnicmp(szBuff, "chs", 3) == 0 | |
314 || _strnicmp(szBuff, "zhc", 3) == 0) | |
315 strcpy(szBuff, "zh_CN"); | |
316 else if (_strnicmp(szBuff, "jp", 2) == 0) | |
317 strcpy(szBuff, "ja"); | |
318 else | |
319 szBuff[2] = 0; // truncate to two-letter code | |
320 strcat(szLang, szBuff); | |
321 gotlang = 1; | |
322 } | |
323 } | |
324 if (gotlang) | |
325 putenv(szLang); | |
326 | 276 |
327 // Try to locate the runtime files. The path is used to find libintl.dll | 277 // Try to locate the runtime files. The path is used to find libintl.dll |
328 // and the vim.mo files. | 278 // and the vim.mo files. |
329 getRuntimeDir(szBuff); | 279 getRuntimeDir(szBuff); |
330 if (szBuff[0] != 0) | 280 if (szBuff[0] != 0) |
376 | 326 |
377 static void | 327 static void |
378 inc_cRefThisDLL() | 328 inc_cRefThisDLL() |
379 { | 329 { |
380 #ifdef FEAT_GETTEXT | 330 #ifdef FEAT_GETTEXT |
381 if (g_cRefThisDll == 0) { | 331 if (g_cRefThisDll == 0) |
382 dyn_gettext_load(); | 332 dyn_gettext_load(); |
383 oldenv = GetEnvironmentStringsW(); | |
384 } | |
385 #endif | 333 #endif |
386 InterlockedIncrement((LPLONG)&g_cRefThisDll); | 334 InterlockedIncrement((LPLONG)&g_cRefThisDll); |
387 } | 335 } |
388 | 336 |
389 static void | 337 static void |
390 dec_cRefThisDLL() | 338 dec_cRefThisDLL() |
391 { | 339 { |
392 #ifdef FEAT_GETTEXT | 340 #ifdef FEAT_GETTEXT |
393 if (InterlockedDecrement((LPLONG)&g_cRefThisDll) == 0) { | 341 if (InterlockedDecrement((LPLONG)&g_cRefThisDll) == 0) |
394 dyn_gettext_free(); | 342 dyn_gettext_free(); |
395 if (oldenv != NULL) { | |
396 FreeEnvironmentStringsW(oldenv); | |
397 oldenv = NULL; | |
398 } | |
399 } | |
400 #else | 343 #else |
401 InterlockedDecrement((LPLONG)&g_cRefThisDll); | 344 InterlockedDecrement((LPLONG)&g_cRefThisDll); |
402 #endif | 345 #endif |
403 } | 346 } |
404 | 347 |
965 if (!CreateProcessW(NULL, // No module name (use command line). | 908 if (!CreateProcessW(NULL, // No module name (use command line). |
966 cmdStrW, // Command line. | 909 cmdStrW, // Command line. |
967 NULL, // Process handle not inheritable. | 910 NULL, // Process handle not inheritable. |
968 NULL, // Thread handle not inheritable. | 911 NULL, // Thread handle not inheritable. |
969 FALSE, // Set handle inheritance to FALSE. | 912 FALSE, // Set handle inheritance to FALSE. |
970 oldenv == NULL ? 0 : CREATE_UNICODE_ENVIRONMENT, | 913 0, // No creation flags. |
971 oldenv, // Use unmodified environment block. | 914 NULL, // Use parent's environment block. |
972 NULL, // Use parent's starting directory. | 915 NULL, // Use parent's starting directory. |
973 &si, // Pointer to STARTUPINFO structure. | 916 &si, // Pointer to STARTUPINFO structure. |
974 &pi) // Pointer to PROCESS_INFORMATION structure. | 917 &pi) // Pointer to PROCESS_INFORMATION structure. |
975 ) | 918 ) |
976 { | 919 { |
1055 if (!CreateProcessW(NULL, // No module name (use command line). | 998 if (!CreateProcessW(NULL, // No module name (use command line). |
1056 cmdStrW, // Command line. | 999 cmdStrW, // Command line. |
1057 NULL, // Process handle not inheritable. | 1000 NULL, // Process handle not inheritable. |
1058 NULL, // Thread handle not inheritable. | 1001 NULL, // Thread handle not inheritable. |
1059 FALSE, // Set handle inheritance to FALSE. | 1002 FALSE, // Set handle inheritance to FALSE. |
1060 oldenv == NULL ? 0 : CREATE_UNICODE_ENVIRONMENT, | 1003 0, // No creation flags. |
1061 oldenv, // Use unmodified environment block. | 1004 NULL, // Use parent's environment block. |
1062 NULL, // Use parent's starting directory. | 1005 NULL, // Use parent's starting directory. |
1063 &si, // Pointer to STARTUPINFO structure. | 1006 &si, // Pointer to STARTUPINFO structure. |
1064 &pi) // Pointer to PROCESS_INFORMATION structure. | 1007 &pi) // Pointer to PROCESS_INFORMATION structure. |
1065 ) | 1008 ) |
1066 { | 1009 { |