// // Attempt to load libintl.dll. If it doesn't work, use dummy functions. // "dir" is the directory where the libintl.dll might be. // Return 1 for success, 0 for failure. // static int dyn_libintl_init(char *dir) { int i; static struct { char *name; FARPROC *ptr; } libintl_entry[] = { {(char *)"gettext", (FARPROC*)&dyn_libintl_gettext}, {(char *)"textdomain", (FARPROC*)&dyn_libintl_textdomain}, {(char *)"bindtextdomain", (FARPROC*)&dyn_libintl_bindtextdomain}, {NULL, NULL} }; // No need to initialize twice. if (hLibintlDLL) return 1; // Load gettext library, first try the Vim runtime directory, then search // the path. strcat(dir, GETTEXT_DLL); hLibintlDLL = LoadLibrary(dir); if (!hLibintlDLL) { hLibintlDLL = LoadLibrary(GETTEXT_DLL); if (!hLibintlDLL) return 0; } // Get the addresses of the functions we need. for (i = 0; libintl_entry[i].name != NULL && libintl_entry[i].ptr != NULL; ++i) { if ((*libintl_entry[i].ptr = GetProcAddress(hLibintlDLL, libintl_entry[i].name)) == NULL) { dyn_libintl_end(); return 0; } } return 1; }
static void dyn_gettext_free(void) { dyn_libintl_end(); }
// // Attempt to load libintl.dll. If it doesn't work, use dummy functions. // "dir" is the directory where the libintl.dll might be. // Return 1 for success, 0 for failure. // static int dyn_libintl_init(char *dir) { int i; static struct { char *name; FARPROC *ptr; } libintl_entry[] = { {(char *)"gettext", (FARPROC*)&dyn_libintl_gettext}, {(char *)"textdomain", (FARPROC*)&dyn_libintl_textdomain}, {(char *)"bindtextdomain", (FARPROC*)&dyn_libintl_bindtextdomain}, {NULL, NULL} }; DWORD len, len2; LPWSTR buf = NULL; LPWSTR buf2 = NULL; // No need to initialize twice. if (hLibintlDLL) return 1; // Load gettext library from $VIMRUNTIME\GvimExt{64,32} directory. // Add the directory to $PATH temporarily. len = GetEnvironmentVariableW(L"PATH", NULL, 0); len2 = MAX_PATH + 1 + len; buf = (LPWSTR)malloc(len * sizeof(WCHAR)); buf2 = (LPWSTR)malloc(len2 * sizeof(WCHAR)); if (buf != NULL && buf2 != NULL) { GetEnvironmentVariableW(L"PATH", buf, len); #ifdef _WIN64 _snwprintf(buf2, len2, L"%S\\GvimExt64;%s", dir, buf); #else _snwprintf(buf2, len2, L"%S\\GvimExt32;%s", dir, buf); #endif SetEnvironmentVariableW(L"PATH", buf2); hLibintlDLL = LoadLibrary(GETTEXT_DLL); #ifdef GETTEXT_DLL_ALT if (!hLibintlDLL) hLibintlDLL = LoadLibrary(GETTEXT_DLL_ALT); #endif SetEnvironmentVariableW(L"PATH", buf); } free(buf); free(buf2); if (!hLibintlDLL) return 0; // Get the addresses of the functions we need. for (i = 0; libintl_entry[i].name != NULL && libintl_entry[i].ptr != NULL; ++i) { if ((*libintl_entry[i].ptr = GetProcAddress(hLibintlDLL, libintl_entry[i].name)) == NULL) { dyn_libintl_end(); return 0; } } return 1; }