From c6cd06cfce5817ae95e75697e1b8fb51c1fa11b1 Mon Sep 17 00:00:00 2001 From: Yevgen Muntyan <17531749+muntyan@users.noreply.github.com> Date: Tue, 15 Jan 2008 00:43:03 -0600 Subject: [PATCH] Win32 flags and headers --- .hgignore | 2 +- m4/moo-flags.m4 | 7 ++ moo/mooapp/mooappabout.h | 1 - moo/mooapp/smclient/eggsmclient-win32.c | 2 - moo/mooedit/mooeditfiltersettings.c | 2 - moo/mooedit/mooprintpreview.c | 3 +- moo/mooterm/mooterm-prefs.c | 1 - moo/mooutils/Makefile.am | 3 + moo/mooutils/moofilewatch.c | 2 +- moo/mooutils/moospawn.c | 1 - moo/mooutils/mooutils-fs.c | 5 +- moo/mooutils/mooutils-misc.h | 26 +----- moo/mooutils/mooutils-thread.c | 4 +- moo/mooutils/mooutils-win32.c | 110 +++++++++++++----------- 14 files changed, 78 insertions(+), 91 deletions(-) diff --git a/.hgignore b/.hgignore index 2d355c45..77ccd6c9 100644 --- a/.hgignore +++ b/.hgignore @@ -6,7 +6,7 @@ Makefile(\.in)?$ ^(autom4te\.cache|build)/ ^(compile|mkinstalldirs|config\..*|configargs\.h|configure|depcomp|install-sh|intltool-(extract|merge|update)|libtool|ltmain\.sh|missing|stamp-h1|aclocal\.m4)$ ^intltool-(extract|merge|update)\.in$ -^medit/medit(-credits\.h|\.(desktop|iss))?$ +^medit/medit(\.(desktop|iss))?$ ^po(-gsv)?/(\.intltool-merge-cache|POTFILES|stamp-it|missing|moo\.pot|notexist|Makefile\.in\.in) ^tests/pyapp\.py$ ^moo/moo(-config\.h|\.pc)$ diff --git a/m4/moo-flags.m4 b/m4/moo-flags.m4 index 00f469aa..fffdfdef 100644 --- a/m4/moo-flags.m4 +++ b/m4/moo-flags.m4 @@ -61,6 +61,12 @@ AC_DEFUN_ONCE([MOO_AC_FLAGS],[ MOO_LIBS="$MOO_LIBS $GTKHTML_LIBS" fi + if test "x$MOO_OS_MINGW" = xyes; then + MOO_CFLAGS="$MOO_CFLAGS -DWIN32_LEAN_AND_MEAN -DUNICODE" + MOO_WIN32_CFLAGS="-I$moo_top_src_dir/$1/mooutils/moowin32/mingw" + AC_DEFINE(HAVE_MMAP, [1], [using fake mmap on windows]) + fi + ################################################################################ # MooEdit stuff # @@ -69,6 +75,7 @@ AC_DEFUN_ONCE([MOO_AC_FLAGS],[ MOO_LIBS="$MOO_LIBS $XML_LIBS" fi + AC_SUBST(MOO_WIN32_CFLAGS) AC_SUBST(MOO_CFLAGS) AC_SUBST(MOO_LIBS) diff --git a/moo/mooapp/mooappabout.h b/moo/mooapp/mooappabout.h index 5a7b164e..f148fa61 100644 --- a/moo/mooapp/mooappabout.h +++ b/moo/mooapp/mooappabout.h @@ -26,7 +26,6 @@ #endif #ifdef __WIN32__ -#define WIN32_LEAN_AND_MEAN #include #endif diff --git a/moo/mooapp/smclient/eggsmclient-win32.c b/moo/mooapp/smclient/eggsmclient-win32.c index 1b5f71bc..a5731de0 100644 --- a/moo/mooapp/smclient/eggsmclient-win32.c +++ b/moo/mooapp/smclient/eggsmclient-win32.c @@ -22,8 +22,6 @@ #include "eggsmclient-private.h" #include -#define WIN32_LEAN_AND_MEAN -#define UNICODE #include #define EGG_TYPE_SM_CLIENT_WIN32 (egg_sm_client_win32_get_type ()) diff --git a/moo/mooedit/mooeditfiltersettings.c b/moo/mooedit/mooeditfiltersettings.c index 6953283d..e2492554 100644 --- a/moo/mooedit/mooeditfiltersettings.c +++ b/moo/mooedit/mooeditfiltersettings.c @@ -19,9 +19,7 @@ #include "mooutils/mooutils-debug.h" #include #include -#ifndef __WIN32__ #include -#endif MOO_DEBUG_INIT(filters, FALSE) diff --git a/moo/mooedit/mooprintpreview.c b/moo/mooedit/mooprintpreview.c index d3cdf89a..d8cbbdcd 100644 --- a/moo/mooedit/mooprintpreview.c +++ b/moo/mooedit/mooprintpreview.c @@ -17,7 +17,7 @@ #define MOOEDIT_COMPILATION #include "mooedit/mooprintpreview.h" #include "mooedit/mootextprint-private.h" -#include "mooedit/mooprintpreview-glade.h" +#include "mooprintpreview-glade.h" #include "mooutils/mooutils-gobject.h" #include "mooutils/mooutils-misc.h" #include "mooutils/mooutils-debug.h" @@ -26,7 +26,6 @@ MOO_DEBUG_INIT(printing, TRUE) #ifdef __WIN32__ -#define WIN32_LEAN_AND_MEAN #include #include #endif diff --git a/moo/mooterm/mooterm-prefs.c b/moo/mooterm/mooterm-prefs.c index c64a1c2a..c2a722e5 100644 --- a/moo/mooterm/mooterm-prefs.c +++ b/moo/mooterm/mooterm-prefs.c @@ -13,7 +13,6 @@ #define MOOTERM_COMPILATION #ifdef __WIN32__ -#define WIN32_LEAN_AND_MEAN #include #endif diff --git a/moo/mooutils/Makefile.am b/moo/mooutils/Makefile.am index 81484b3a..eb91fe93 100644 --- a/moo/mooutils/Makefile.am +++ b/moo/mooutils/Makefile.am @@ -160,6 +160,9 @@ EXTRA_DIST = \ $(thread_sources) \ $(win32_sources) \ $(objc_sources) \ + moowin32/mingw/fnmatch.h \ + moowin32/mingw/netinet/in.h \ + moowin32/mingw/sys/mman.h \ pixmaps/medit.png \ pixmaps/medit.ico \ pixmaps/hide.png \ diff --git a/moo/mooutils/moofilewatch.c b/moo/mooutils/moofilewatch.c index bcfd06a5..b2d76081 100644 --- a/moo/mooutils/moofilewatch.c +++ b/moo/mooutils/moofilewatch.c @@ -23,7 +23,6 @@ #endif #ifdef __WIN32__ -#include "mooutils/mooutils-thread.h" #include #include #include @@ -43,6 +42,7 @@ #include "mooutils/mooutils-misc.h" #include "mooutils/moofilewatch.h" #include "mooutils/moomarshals.h" +#include "mooutils/mooutils-thread.h" #if 1 diff --git a/moo/mooutils/moospawn.c b/moo/mooutils/moospawn.c index fd6fb214..47f4457c 100644 --- a/moo/mooutils/moospawn.c +++ b/moo/mooutils/moospawn.c @@ -22,7 +22,6 @@ #include #include #else -#define WIN32_LEAN_AND_MEAN #include #endif diff --git a/moo/mooutils/mooutils-fs.c b/moo/mooutils/mooutils-fs.c index 2fc6a564..82654031 100644 --- a/moo/mooutils/mooutils-fs.c +++ b/moo/mooutils/mooutils-fs.c @@ -27,12 +27,15 @@ #include #ifdef __WIN32__ -#define WIN32_LEAN_AND_MEAN #include #include #include #endif +#ifndef S_IRWXU +#define S_IRWXU 0 +#endif + #ifdef HAVE_SYS_WAIT_H #include #endif diff --git a/moo/mooutils/mooutils-misc.h b/moo/mooutils/mooutils-misc.h index 8ca51801..45527d2c 100644 --- a/moo/mooutils/mooutils-misc.h +++ b/moo/mooutils/mooutils-misc.h @@ -201,11 +201,8 @@ G_END_DECLS G_BEGIN_DECLS -#define fnmatch _moo_win32_fnmatch -#define gettimeofday _moo_win32_gettimeofday - -char *moo_win32_get_app_dir (void); -char *moo_win32_get_dll_dir (const char *dll); +char *moo_win32_get_app_dir (void); +char *moo_win32_get_dll_dir (const char *dll); void _moo_win32_add_data_dirs (GPtrArray *list, const char *prefix); @@ -216,25 +213,6 @@ gboolean _moo_win32_open_uri (const char *uri); void _moo_win32_show_fatal_error (const char *domain, const char *logmsg); -int _moo_win32_fnmatch (const char *pattern, - const char *string, - int flags); -int _moo_win32_gettimeofday (struct timeval *tp, - gpointer tzp); - -void *_moo_win32_mmap (gpointer start, - guint64 length, - int prot, - int flags, - int fd, - guint64 offset); -int _moo_win32_munmap (gpointer start, - gsize length); - -#define PROT_READ 1 -#define MAP_SHARED 1 -#define MAP_FAILED ((gpointer) -1) - G_END_DECLS diff --git a/moo/mooutils/mooutils-thread.c b/moo/mooutils/mooutils-thread.c index 1ad623a4..4e6f2367 100644 --- a/moo/mooutils/mooutils-thread.c +++ b/moo/mooutils/mooutils-thread.c @@ -23,9 +23,7 @@ #endif #ifdef __WIN32__ #include -#endif - -#ifdef __WIN32__ +#include #ifndef pipe #define pipe(phandles) _pipe (phandles, 4096, _O_BINARY) #endif diff --git a/moo/mooutils/mooutils-win32.c b/moo/mooutils/mooutils-win32.c index 15701672..4929e347 100644 --- a/moo/mooutils/mooutils-win32.c +++ b/moo/mooutils/mooutils-win32.c @@ -14,14 +14,15 @@ #include "config.h" #endif -#define WIN32_LEAN_AND_MEAN #include "mooutils/mooutils-misc.h" #include "mooutils/mooutils-fs.h" +#include #include #include #include #include #include +#include #include @@ -35,16 +36,19 @@ DllMain (HINSTANCE hinstDLL, DWORD fdwReason, G_GNUC_UNUSED LPVOID lpvReserved) { - char *tem; - wchar_t wcbfr[1000]; + char *name = NULL; + wchar_t buf[MAX_PATH+1]; switch (fdwReason) { case DLL_PROCESS_ATTACH: - GetModuleFileNameW ((HMODULE) hinstDLL, wcbfr, G_N_ELEMENTS (wcbfr)); - tem = g_utf16_to_utf8 (wcbfr, -1, NULL, NULL, NULL); - libmoo_dll_name = g_path_get_basename (tem); - g_free (tem); + if (GetModuleFileNameW ((HMODULE) hinstDLL, buf, G_N_ELEMENTS (buf))) + name = g_utf16_to_utf8 (buf, -1, NULL, NULL, NULL); + if (name) + libmoo_dll_name = g_path_get_basename (name); + if (!libmoo_dll_name) + libmoo_dll_name = g_strdup ("libmoo.dll"); + g_free (name); break; } @@ -140,38 +144,40 @@ moo_win32_get_app_dir (void) char * moo_win32_get_dll_dir (const char *dll) { + wchar_t *dll_utf16 = NULL; char *dir; char *dllname = NULL; HMODULE handle; + wchar_t buf[MAX_PATH+1]; - handle = GetModuleHandle (dll); + if (dll) + { + GError *error = NULL; + + dll_utf16 = g_utf8_to_utf16 (dll, -1, NULL, NULL, &error); + + if (!dll_utf16) + { + g_critical ("could not convert name '%s' to UTF16: %s", + dll, error ? error->message : ""); + g_error_free (error); + return g_strdup ("."); + } + } + + handle = GetModuleHandleW (dll_utf16); g_return_val_if_fail (handle != NULL, g_strdup (".")); - if (G_WIN32_HAVE_WIDECHAR_API ()) - { - wchar_t buf[MAX_PATH+1]; - - if (GetModuleFileNameW (handle, buf, G_N_ELEMENTS (buf)) > 0) - dllname = g_utf16_to_utf8 (buf, -1, NULL, NULL, NULL); - } - else - { - gchar buf[MAX_PATH+1]; - - if (GetModuleFileNameA (handle, buf, G_N_ELEMENTS (buf)) > 0) - dllname = g_locale_to_utf8 (buf, -1, NULL, NULL, NULL); - } + if (GetModuleFileNameW (handle, buf, G_N_ELEMENTS (buf)) > 0) + dllname = g_utf16_to_utf8 (buf, -1, NULL, NULL, NULL); if (dllname) - { dir = g_path_get_dirname (dllname); - g_free (dllname); - } else - { dir = g_strdup ("."); - } + g_free (dllname); + g_free (dll_utf16); return dir; } @@ -183,7 +189,7 @@ _moo_win32_open_uri (const char *uri) g_return_val_if_fail (uri != NULL, FALSE); - h = ShellExecute (NULL, "open", uri, NULL, NULL, SW_SHOWNORMAL); + h = ShellExecuteA (NULL, "open", uri, NULL, NULL, SW_SHOWNORMAL); if ((int)h <= 32) { @@ -214,35 +220,35 @@ _moo_win32_show_fatal_error (const char *domain, PLEASE_REPORT, logmsg); #undef PLEASE_REPORT - MessageBox (NULL, msg, "Error", - MB_ICONERROR | MB_APPLMODAL | MB_SETFOREGROUND); + MessageBoxA (NULL, msg, "Error", + MB_ICONERROR | MB_APPLMODAL | MB_SETFOREGROUND); g_free (msg); } -int -_moo_win32_gettimeofday (struct timeval *tp, - G_GNUC_UNUSED gpointer tzp) -{ - time_t sec; - - if (tp == NULL || tzp != NULL) - { - errno = EINVAL; - return -1; - } - - sec = time (NULL); - - if (sec == (time_t) -1) - return -1; - - tp->tv_sec = sec; - tp->tv_usec = 0; - - return 0; -} +// int +// _moo_win32_gettimeofday (struct timeval *tp, +// G_GNUC_UNUSED gpointer tzp) +// { +// time_t sec; +// +// if (tp == NULL || tzp != NULL) +// { +// errno = EINVAL; +// return -1; +// } +// +// sec = time (NULL); +// +// if (sec == (time_t) -1) +// return -1; +// +// tp->tv_sec = sec; +// tp->tv_usec = 0; +// +// return 0; +// } int