fixed some code for win32

This commit is contained in:
hyunghwan.chung 2018-10-14 14:06:58 +00:00
parent ab8716f7ab
commit f3f77ae9f2
7 changed files with 99 additions and 13 deletions

15
moo/configure vendored
View File

@ -21441,6 +21441,11 @@ $as_echo "#define MOO_UNICODE_SIZE 4" >>confdefs.h
$as_echo "#define MOO_ENABLE_UNICODE 1" >>confdefs.h $as_echo "#define MOO_ENABLE_UNICODE 1" >>confdefs.h
if test "${platform_win32}" = "yes"
then
CFLAGS="$CFLAGS -DUNICODE -D_UNICODE"
CXXFLAGS="$CXXFLAGS -DUNICODE -D_UNICODE"
fi
elif test "${enable_unicode}" = "yes:2" elif test "${enable_unicode}" = "yes:2"
then then
@ -21449,6 +21454,11 @@ $as_echo "#define MOO_UNICODE_SIZE 2" >>confdefs.h
$as_echo "#define MOO_ENABLE_UNICODE 1" >>confdefs.h $as_echo "#define MOO_ENABLE_UNICODE 1" >>confdefs.h
if test "${platform_win32}" = "yes"
then
CFLAGS="$CFLAGS -DUNICODE -D_UNICODE"
CXXFLAGS="$CXXFLAGS -DUNICODE -D_UNICODE"
fi
elif test "${enable_unicode}" = "yes" elif test "${enable_unicode}" = "yes"
then then
@ -21457,6 +21467,11 @@ $as_echo "#define MOO_UNICODE_SIZE 1" >>confdefs.h
$as_echo "#define MOO_ENABLE_UNICODE 1" >>confdefs.h $as_echo "#define MOO_ENABLE_UNICODE 1" >>confdefs.h
if test "${platform_win32}" = "yes"
then
CFLAGS="$CFLAGS -DUNICODE -D_UNICODE"
CXXFLAGS="$CXXFLAGS -DUNICODE -D_UNICODE"
fi
elif test "${enable_unicode}" = "no:4" elif test "${enable_unicode}" = "no:4"
then then

View File

@ -667,14 +667,29 @@ if test "${enable_unicode}" = "yes:4"
then then
AC_DEFINE([MOO_UNICODE_SIZE],[4],[Unicode character type size]) AC_DEFINE([MOO_UNICODE_SIZE],[4],[Unicode character type size])
AC_DEFINE([MOO_ENABLE_UNICODE],[1],[Use the unicode character type as the default character type]) AC_DEFINE([MOO_ENABLE_UNICODE],[1],[Use the unicode character type as the default character type])
if test "${platform_win32}" = "yes"
then
[CFLAGS="$CFLAGS -DUNICODE -D_UNICODE"]
[CXXFLAGS="$CXXFLAGS -DUNICODE -D_UNICODE"]
fi
elif test "${enable_unicode}" = "yes:2" elif test "${enable_unicode}" = "yes:2"
then then
AC_DEFINE([MOO_UNICODE_SIZE],[2],[Unicode character type size]) AC_DEFINE([MOO_UNICODE_SIZE],[2],[Unicode character type size])
AC_DEFINE([MOO_ENABLE_UNICODE],[1],[Use the unicode character type as the default character type]) AC_DEFINE([MOO_ENABLE_UNICODE],[1],[Use the unicode character type as the default character type])
if test "${platform_win32}" = "yes"
then
[CFLAGS="$CFLAGS -DUNICODE -D_UNICODE"]
[CXXFLAGS="$CXXFLAGS -DUNICODE -D_UNICODE"]
fi
elif test "${enable_unicode}" = "yes" elif test "${enable_unicode}" = "yes"
then then
AC_DEFINE([MOO_UNICODE_SIZE],[1],[Unicode character type size]) AC_DEFINE([MOO_UNICODE_SIZE],[1],[Unicode character type size])
AC_DEFINE([MOO_ENABLE_UNICODE],[1],[Use the unicode character type as the default character type]) AC_DEFINE([MOO_ENABLE_UNICODE],[1],[Use the unicode character type as the default character type])
if test "${platform_win32}" = "yes"
then
[CFLAGS="$CFLAGS -DUNICODE -D_UNICODE"]
[CXXFLAGS="$CXXFLAGS -DUNICODE -D_UNICODE"]
fi
elif test "${enable_unicode}" = "no:4" elif test "${enable_unicode}" = "no:4"
then then
AC_DEFINE([MOO_UNICODE_SIZE],[4],[Unicode character type size]) AC_DEFINE([MOO_UNICODE_SIZE],[4],[Unicode character type size])

View File

@ -116,9 +116,15 @@ endif
bin_PROGRAMS = moo bin_PROGRAMS = moo
moo_SOURCES = main.c moo_SOURCES = main.c
if WIN32
moo_SOURCES += poll-msw.c poll-msw.h
endif
moo_CPPFLAGS = $(CPPFLAGS_ALL_COMMON) $(CPPFLAGS_PFMOD) moo_CPPFLAGS = $(CPPFLAGS_ALL_COMMON) $(CPPFLAGS_PFMOD)
moo_LDFLAGS = $(LDFLAGS_ALL_COMMON) moo_LDFLAGS = $(LDFLAGS_ALL_COMMON)
moo_LDADD = $(LIBADD_LIB_COMMON) -lmoo $(PTHREAD_LIBS) moo_LDADD = $(LIBADD_LIB_COMMON) -lmoo $(PTHREAD_LIBS)
if WIN32
moo_LDADD += $(SOCKET_LIBS)
endif
if ENABLE_STATIC_MODULE if ENABLE_STATIC_MODULE
moo_DEPENDENCIES = libmoo.la moo_DEPENDENCIES = libmoo.la
endif endif

View File

@ -110,8 +110,11 @@ host_triplet = @host@
@ENABLE_MOD_X11_TRUE@@ENABLE_STATIC_MODULE_TRUE@am__append_13 = -lmoo-x11 @ENABLE_MOD_X11_TRUE@@ENABLE_STATIC_MODULE_TRUE@am__append_13 = -lmoo-x11
@ENABLE_MOD_X11_TRUE@@ENABLE_STATIC_MODULE_TRUE@am__append_14 = $(abs_builddir)/../mod/libmoo-x11.la @ENABLE_MOD_X11_TRUE@@ENABLE_STATIC_MODULE_TRUE@am__append_14 = $(abs_builddir)/../mod/libmoo-x11.la
bin_PROGRAMS = moo$(EXEEXT) bin_PROGRAMS = moo$(EXEEXT)
@WIN32_TRUE@am__append_15 = poll-msw.c poll-msw.h
@WIN32_TRUE@am__append_16 = $(SOCKET_LIBS)
@ENABLE_STATIC_MODULE_FALSE@moo_DEPENDENCIES = $(am__DEPENDENCIES_5) \ @ENABLE_STATIC_MODULE_FALSE@moo_DEPENDENCIES = $(am__DEPENDENCIES_5) \
@ENABLE_STATIC_MODULE_FALSE@ $(am__DEPENDENCIES_1) @ENABLE_STATIC_MODULE_FALSE@ $(am__DEPENDENCIES_1) \
@ENABLE_STATIC_MODULE_FALSE@ $(am__DEPENDENCIES_6)
subdir = lib subdir = lib
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/ax_check_sign.m4 \ am__aclocal_m4_deps = $(top_srcdir)/m4/ax_check_sign.m4 \
@ -180,8 +183,11 @@ libmoo_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
$(libmoo_la_LDFLAGS) $(LDFLAGS) -o $@ $(libmoo_la_LDFLAGS) $(LDFLAGS) -o $@
PROGRAMS = $(bin_PROGRAMS) PROGRAMS = $(bin_PROGRAMS)
am_moo_OBJECTS = moo-main.$(OBJEXT) am__moo_SOURCES_DIST = main.c poll-msw.c poll-msw.h
@WIN32_TRUE@am__objects_1 = moo-poll-msw.$(OBJEXT)
am_moo_OBJECTS = moo-main.$(OBJEXT) $(am__objects_1)
moo_OBJECTS = $(am_moo_OBJECTS) moo_OBJECTS = $(am_moo_OBJECTS)
@WIN32_TRUE@am__DEPENDENCIES_6 = $(am__DEPENDENCIES_1)
moo_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ moo_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
$(moo_LDFLAGS) $(LDFLAGS) -o $@ $(moo_LDFLAGS) $(LDFLAGS) -o $@
@ -220,7 +226,7 @@ am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
am__v_CCLD_0 = @echo " CCLD " $@; am__v_CCLD_0 = @echo " CCLD " $@;
am__v_CCLD_1 = am__v_CCLD_1 =
SOURCES = $(libmoo_la_SOURCES) $(moo_SOURCES) SOURCES = $(libmoo_la_SOURCES) $(moo_SOURCES)
DIST_SOURCES = $(libmoo_la_SOURCES) $(moo_SOURCES) DIST_SOURCES = $(libmoo_la_SOURCES) $(am__moo_SOURCES_DIST)
am__can_run_installinfo = \ am__can_run_installinfo = \
case $$AM_UPDATE_INFO_DIR in \ case $$AM_UPDATE_INFO_DIR in \
n|no|NO) false;; \ n|no|NO) false;; \
@ -481,10 +487,11 @@ libmoo_la_LIBADD = $(LIBADD_LIB_COMMON) $(am__append_6) \
@ENABLE_STATIC_MODULE_TRUE@libmoo_la_DEPENDENCIES = $(abs_builddir)/../mod/libmoo-stdio.la \ @ENABLE_STATIC_MODULE_TRUE@libmoo_la_DEPENDENCIES = $(abs_builddir)/../mod/libmoo-stdio.la \
@ENABLE_STATIC_MODULE_TRUE@ $(am__append_8) $(am__append_10) \ @ENABLE_STATIC_MODULE_TRUE@ $(am__append_8) $(am__append_10) \
@ENABLE_STATIC_MODULE_TRUE@ $(am__append_12) $(am__append_14) @ENABLE_STATIC_MODULE_TRUE@ $(am__append_12) $(am__append_14)
moo_SOURCES = main.c moo_SOURCES = main.c $(am__append_15)
moo_CPPFLAGS = $(CPPFLAGS_ALL_COMMON) $(CPPFLAGS_PFMOD) moo_CPPFLAGS = $(CPPFLAGS_ALL_COMMON) $(CPPFLAGS_PFMOD)
moo_LDFLAGS = $(LDFLAGS_ALL_COMMON) moo_LDFLAGS = $(LDFLAGS_ALL_COMMON)
moo_LDADD = $(LIBADD_LIB_COMMON) -lmoo $(PTHREAD_LIBS) moo_LDADD = $(LIBADD_LIB_COMMON) -lmoo $(PTHREAD_LIBS) \
$(am__append_16)
@ENABLE_STATIC_MODULE_TRUE@moo_DEPENDENCIES = libmoo.la @ENABLE_STATIC_MODULE_TRUE@moo_DEPENDENCIES = libmoo.la
all: moo-cfg.h all: moo-cfg.h
$(MAKE) $(AM_MAKEFLAGS) all-am $(MAKE) $(AM_MAKEFLAGS) all-am
@ -654,6 +661,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmoo_la-utf8.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmoo_la-utf8.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmoo_la-utl.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmoo_la-utl.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/moo-main.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/moo-main.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/moo-poll-msw.Po@am__quote@
.c.o: .c.o:
@am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\ @am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\
@ -833,6 +841,20 @@ moo-main.obj: main.c
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(moo_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o moo-main.obj `if test -f 'main.c'; then $(CYGPATH_W) 'main.c'; else $(CYGPATH_W) '$(srcdir)/main.c'; fi` @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(moo_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o moo-main.obj `if test -f 'main.c'; then $(CYGPATH_W) 'main.c'; else $(CYGPATH_W) '$(srcdir)/main.c'; fi`
moo-poll-msw.o: poll-msw.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(moo_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT moo-poll-msw.o -MD -MP -MF $(DEPDIR)/moo-poll-msw.Tpo -c -o moo-poll-msw.o `test -f 'poll-msw.c' || echo '$(srcdir)/'`poll-msw.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/moo-poll-msw.Tpo $(DEPDIR)/moo-poll-msw.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='poll-msw.c' object='moo-poll-msw.o' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(moo_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o moo-poll-msw.o `test -f 'poll-msw.c' || echo '$(srcdir)/'`poll-msw.c
moo-poll-msw.obj: poll-msw.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(moo_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT moo-poll-msw.obj -MD -MP -MF $(DEPDIR)/moo-poll-msw.Tpo -c -o moo-poll-msw.obj `if test -f 'poll-msw.c'; then $(CYGPATH_W) 'poll-msw.c'; else $(CYGPATH_W) '$(srcdir)/poll-msw.c'; fi`
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/moo-poll-msw.Tpo $(DEPDIR)/moo-poll-msw.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='poll-msw.c' object='moo-poll-msw.obj' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(moo_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o moo-poll-msw.obj `if test -f 'poll-msw.c'; then $(CYGPATH_W) 'poll-msw.c'; else $(CYGPATH_W) '$(srcdir)/poll-msw.c'; fi`
mostlyclean-libtool: mostlyclean-libtool:
-rm -f *.lo -rm -f *.lo

View File

@ -46,6 +46,14 @@
# if defined(MOO_HAVE_CFG_H) && defined(MOO_ENABLE_LIBLTDL) # if defined(MOO_HAVE_CFG_H) && defined(MOO_ENABLE_LIBLTDL)
# include <ltdl.h> # include <ltdl.h>
# define USE_LTDL # define USE_LTDL
# else
# define USE_WIN_DLL
/* TODO: write sys_dl_error() properly */
# define sys_dl_error() win_dlerror()
# define sys_dl_open(x) LoadLibraryExA(x, MOO_NULL, 0)
# define sys_dl_openext(x) LoadLibraryExA(x, MOO_NULL, 0)
# define sys_dl_close(x) FreeLibrary(x)
# define sys_dl_getsym(x,n) GetProcAddress(x,n)
# endif # endif
# include "poll-msw.h" # include "poll-msw.h"
@ -110,7 +118,7 @@
# define sys_dl_close(x) dlclose(x) # define sys_dl_close(x) dlclose(x)
# define sys_dl_getsym(x,n) dlsym(x,n) # define sys_dl_getsym(x,n) dlsym(x,n)
# elif defined(__APPLE__) || defined(__MACOSX__) # elif defined(__APPLE__) || defined(__MACOSX__)
# define USE_MACH_O # define USE_MACH_O_DYLD
# include <mach-o/dyld.h> # include <mach-o/dyld.h>
# define sys_dl_error() mach_dlerror() # define sys_dl_error() mach_dlerror()
# define sys_dl_open(x) mach_dlopen(x) # define sys_dl_open(x) mach_dlopen(x)
@ -203,7 +211,7 @@
# else # else
# if defined(USE_DLFCN) # if defined(USE_DLFCN)
# define MOO_DEFAULT_PFMODPOSTFIX ".so" # define MOO_DEFAULT_PFMODPOSTFIX ".so"
# elif defined(USE_MACH_O) # elif defined(USE_MACH_O_DYLD)
# define MOO_DEFAULT_PFMODPOSTFIX ".dylib" # define MOO_DEFAULT_PFMODPOSTFIX ".dylib"
# else # else
# define MOO_DEFAULT_PFMODPOSTFIX "" # define MOO_DEFAULT_PFMODPOSTFIX ""
@ -828,7 +836,27 @@ static void syserrstrb (moo_t* moo, int syserr, moo_bch_t* buf, moo_oow_t len)
/* ========================================================================= */ /* ========================================================================= */
#if defined(USE_MACH_O) #if defined(USE_WIN_DLL)
static const char* win_dlerror (void)
{
/* TODO: handle wchar_t, moo_ooch_t etc? */
static char buf[256];
DWORD rc;
rc = FormatMessageA (
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
buf, MOO_COUNTOF(buf), MOO_NULL
);
while (rc > 0 && buf[rc - 1] == '\r' || buf[rc - 1] == '\n')
{
buf[--rc] = '\0';
}
return buf;
}
#elif defined(USE_MACH_O_DYLD)
static const char* mach_dlerror_str = ""; static const char* mach_dlerror_str = "";
static void* mach_dlopen (const char* path) static void* mach_dlopen (const char* path)
@ -897,7 +925,7 @@ static const char* mach_dlerror (void)
static void* dl_open (moo_t* moo, const moo_ooch_t* name, int flags) static void* dl_open (moo_t* moo, const moo_ooch_t* name, int flags)
{ {
#if defined(USE_LTDL) || defined(USE_DLFCN) || defined(USE_MACH_O) #if defined(USE_LTDL) || defined(USE_DLFCN) || defined(USE_MACH_O_DYLD) || defined(USE_WIN_DLL)
moo_bch_t stabuf[128], * bufptr; moo_bch_t stabuf[128], * bufptr;
moo_oow_t ucslen, bcslen, bufcapa; moo_oow_t ucslen, bcslen, bufcapa;
void* handle; void* handle;
@ -1045,7 +1073,7 @@ static void* dl_open (moo_t* moo, const moo_ooch_t* name, int flags)
static void dl_close (moo_t* moo, void* handle) static void dl_close (moo_t* moo, void* handle)
{ {
#if defined(USE_LTDL) || defined(USE_DLFCN) || defined(USE_MACH_O) #if defined(USE_LTDL) || defined(USE_DLFCN) || defined(USE_MACH_O_DYLD) || defined(USE_WIN_DLL)
MOO_DEBUG1 (moo, "Closed DL handle %p\n", handle); MOO_DEBUG1 (moo, "Closed DL handle %p\n", handle);
sys_dl_close (handle); sys_dl_close (handle);
@ -1057,7 +1085,7 @@ static void dl_close (moo_t* moo, void* handle)
static void* dl_getsym (moo_t* moo, void* handle, const moo_ooch_t* name) static void* dl_getsym (moo_t* moo, void* handle, const moo_ooch_t* name)
{ {
#if defined(USE_LTDL) || defined(USE_DLFCN) || defined(USE_MACH_O) #if defined(USE_LTDL) || defined(USE_DLFCN) || defined(USE_MACH_O_DYLD) || defined(USE_WIN_DLL)
moo_bch_t stabuf[64], * bufptr; moo_bch_t stabuf[64], * bufptr;
moo_oow_t bufcapa, ucslen, bcslen, i; moo_oow_t bufcapa, ucslen, bcslen, i;
const moo_bch_t* symname; const moo_bch_t* symname;

View File

@ -84,7 +84,6 @@
typedef signed char moo_int8_t; typedef signed char moo_int8_t;
#endif #endif
/* moo_int16_t */ /* moo_int16_t */
#if defined(MOO_SIZEOF_SHORT) && (MOO_SIZEOF_SHORT == 2) #if defined(MOO_SIZEOF_SHORT) && (MOO_SIZEOF_SHORT == 2)
# define MOO_HAVE_UINT16_T # define MOO_HAVE_UINT16_T

View File

@ -29,8 +29,9 @@
#include <moo-utl.h> #include <moo-utl.h>
#include <string.h> #include <string.h>
#if defined(_WIN32)
#if defined(_WIN32)
# include <windows.h>
#elif defined(__DOS__) #elif defined(__DOS__)
#else #else