From 5197f0c2fee01c473b4876f6a49e784250f63640 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Sat, 18 Jan 2014 13:46:22 +0200 Subject: [PATCH] Fix file name handling on MS-Windows 9X. src/w32.c (maybe_load_unicows_dll): New function. src/emacs.c (main) [WINDOWSNT]: Call maybe_load_unicows_dll early on, to make sure we can convert file names to and from UTF-8 on Windows 9X. This fixes a failure to start up because Emacs cannot find term/w32-win.el. Reported by oslsachem . src/w32font.c [WINDOWSNT]: Include w32.h. (w32_load_unicows_or_gdi32): Call maybe_load_unicows_dll, instead of implementing the same stuff. Remove now unused g_b_init_is_windows_9x. src/w32.h (maybe_load_unicows_dll): Add prototype. nt/runemacs.c (ensure_unicows_dll): Don't tell in the message box that "emacs -nw" can do without UNICOWS.DLL on Windows 9X. See w32.c:maybe_load_unicows_dll and its callers for the reason. --- nt/ChangeLog | 6 ++++++ nt/runemacs.c | 2 -- src/ChangeLog | 17 +++++++++++++++++ src/emacs.c | 6 ++++++ src/w32.c | 34 ++++++++++++++++++++++++++++++++++ src/w32.h | 1 + src/w32font.c | 45 ++++----------------------------------------- 7 files changed, 68 insertions(+), 43 deletions(-) diff --git a/nt/ChangeLog b/nt/ChangeLog index c27b6fc38b..bf7dc90201 100644 --- a/nt/ChangeLog +++ b/nt/ChangeLog @@ -1,3 +1,9 @@ +2014-01-18 Eli Zaretskii + + * runemacs.c (ensure_unicows_dll): Don't tell in the message box + that "emacs -nw" can do without UNICOWS.DLL on Windows 9X. See + w32.c:maybe_load_unicows_dll and its callers for the reason. + 2014-01-11 Claudio Bley * inc/sys/stat.h (_WSTAT_DEFINED): Define, to avoid compilation diff --git a/nt/runemacs.c b/nt/runemacs.c index 20b6f0cab7..5b851f4b65 100644 --- a/nt/runemacs.c +++ b/nt/runemacs.c @@ -234,8 +234,6 @@ ensure_unicows_dll (void) "Emacs cannot load the UNICOWS.DLL library.\n" "This library is essential for using Emacs\n" "on this system. You need to install it.\n\n" - "However, you can still use Emacs by invoking\n" - "it with the '-nw' command-line option.\n\n" "Emacs will exit when you click OK.", "Emacs cannot load UNICOWS.DLL", MB_ICONERROR | MB_TASKMODAL diff --git a/src/ChangeLog b/src/ChangeLog index d7a1d1f08f..82a5d68b92 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,20 @@ +2014-01-18 Eli Zaretskii + + Fix file name handling on MS-Windows 9X. + * w32.c (maybe_load_unicows_dll): New function. + + * emacs.c (main) [WINDOWSNT]: Call maybe_load_unicows_dll early + on, to make sure we can convert file names to and from UTF-8 on + Windows 9X. This fixes a failure to start up because Emacs cannot + find term/w32-win.el. Reported by oslsachem . + + * w32font.c [WINDOWSNT]: Include w32.h. + (w32_load_unicows_or_gdi32): Call maybe_load_unicows_dll, instead + of implementing the same stuff. + Remove now unused g_b_init_is_windows_9x. + + * w32.h (maybe_load_unicows_dll): Add prototype. + 2014-01-17 Eli Zaretskii * menu.c (Fx_popup_menu): When invoking tty_menu_show, temporarily diff --git a/src/emacs.c b/src/emacs.c index ac9f79b6eb..af01e8431a 100644 --- a/src/emacs.c +++ b/src/emacs.c @@ -749,6 +749,12 @@ main (int argc, char **argv) early as possible. (unexw32.c calls this function as well, but the additional call here is harmless.) */ cache_system_info (); +#ifdef WINDOWSNT + /* On Windows 9X, we have to load UNICOWS.DLL as early as possible, + to have non-stub implementations of APIs we need to convert file + names between UTF-8 and the system's ANSI codepage. */ + maybe_load_unicows_dll (); +#endif #endif #ifdef RUN_TIME_REMAP diff --git a/src/w32.c b/src/w32.c index 8aca8c1b71..275b1e8d94 100644 --- a/src/w32.c +++ b/src/w32.c @@ -8923,6 +8923,40 @@ shutdown_handler (DWORD type) return FALSE; } +/* On Windows 9X, load UNICOWS.DLL and return its handle, or die. On + NT, return a handle to GDI32.DLL. */ +HANDLE +maybe_load_unicows_dll (void) +{ + if (os_subtype == OS_9X) + { + HANDLE ret = LoadLibrary ("Unicows.dll"); + if (ret) + return ret; + else + { + int button; + + button = MessageBox (NULL, + "Emacs cannot load the UNICOWS.DLL library.\n" + "This library is essential for using Emacs\n" + "on this system. You need to install it.\n\n" + "Emacs will exit when you click OK.", + "Emacs cannot load UNICOWS.DLL", + MB_ICONERROR | MB_TASKMODAL + | MB_SETFOREGROUND | MB_OK); + switch (button) + { + case IDOK: + default: + exit (1); + } + } + } + else + return LoadLibrary ("Gdi32.dll"); +} + /* globals_of_w32 is used to initialize those global variables that must always be initialized on startup even when the global variable diff --git a/src/w32.h b/src/w32.h index 03a6efa68d..0ca30c6012 100644 --- a/src/w32.h +++ b/src/w32.h @@ -163,6 +163,7 @@ extern LPBYTE w32_get_resource (char * key, LPDWORD type); extern void release_listen_threads (void); extern void init_ntproc (int); extern void term_ntproc (int); +extern HANDLE maybe_load_unicows_dll (void); extern void globals_of_w32 (void); extern void term_timers (void); diff --git a/src/w32font.c b/src/w32font.c index a3f7ea4afe..c56da91092 100644 --- a/src/w32font.c +++ b/src/w32font.c @@ -33,6 +33,9 @@ along with GNU Emacs. If not, see . */ #include "fontset.h" #include "font.h" #include "w32font.h" +#ifdef WINDOWSNT +#include "w32.h" +#endif /* Cleartype available on Windows XP, cleartype_natural from XP SP1. The latter does not try to fit cleartype smoothed fonts into the @@ -144,7 +147,6 @@ struct font_callback_data style variations if the font name is not specified. */ static void list_all_matching_fonts (struct font_callback_data *); -static BOOL g_b_init_is_w9x; static BOOL g_b_init_get_outline_metrics_w; static BOOL g_b_init_get_text_metrics_w; static BOOL g_b_init_get_glyph_outline_w; @@ -183,45 +185,7 @@ typedef BOOL (WINAPI * GetCharWidth32W_Proc) ( static HMODULE w32_load_unicows_or_gdi32 (void) { - static BOOL is_9x = 0; - OSVERSIONINFO os_ver; - HMODULE ret; - if (g_b_init_is_w9x == 0) - { - g_b_init_is_w9x = 1; - ZeroMemory (&os_ver, sizeof (OSVERSIONINFO)); - os_ver.dwOSVersionInfoSize = sizeof (OSVERSIONINFO); - if (GetVersionEx (&os_ver)) - is_9x = (os_ver.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS); - } - if (is_9x) - { - ret = LoadLibrary ("Unicows.dll"); - if (!ret) - { - int button; - - button = MessageBox (NULL, - "Emacs cannot load the UNICOWS.DLL library.\n" - "This library is essential for using Emacs\n" - "on this system. You need to install it.\n\n" - "However, you can still use Emacs by invoking\n" - "it with the '-nw' command-line option.\n\n" - "Emacs will exit when you click OK.", - "Emacs cannot load UNICOWS.DLL", - MB_ICONERROR | MB_TASKMODAL - | MB_SETFOREGROUND | MB_OK); - switch (button) - { - case IDOK: - default: - exit (1); - } - } - } - else - ret = LoadLibrary ("Gdi32.dll"); - return ret; + return maybe_load_unicows_dll (); } /* The following 3 functions call the problematic "wide" APIs via @@ -2753,7 +2717,6 @@ versions of Windows) characters. */); void globals_of_w32font (void) { - g_b_init_is_w9x = 0; g_b_init_get_outline_metrics_w = 0; g_b_init_get_text_metrics_w = 0; g_b_init_get_glyph_outline_w = 0; -- 2.20.1