From 4a6b24a567142317a24a98d2ab998f5093a581cc Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Fri, 10 Aug 2012 14:44:17 +0200 Subject: first porting attempts to Windows: nmake support from Wolframe module loader adapted tests for typeinfo and template trickery --- .gitignore | 5 +++ Makefile.W32 | 9 +++++ makefiles/nmake/clean.mk | 40 +++++++++++++++++++ makefiles/nmake/compiler.mk | 93 +++++++++++++++++++++++++++++++++++++++++++++ makefiles/nmake/config.mk | 65 +++++++++++++++++++++++++++++++ makefiles/nmake/doc.mk | 18 +++++++++ makefiles/nmake/dochelp.mk | 6 +++ makefiles/nmake/help.mk | 50 ++++++++++++++++++++++++ makefiles/nmake/platform.mk | 27 +++++++++++++ makefiles/nmake/sub.mk | 28 ++++++++++++++ makefiles/nmake/top.mk | 35 +++++++++++++++++ src/GNUmakefile | 1 + src/Logger.hpp | 28 ++++++++++++++ src/Makefile.W32 | 55 +++++++++++++++++++++++++++ src/ModuleLoader.hpp | 30 +++++++++++++++ src/RewindInputStream.hpp | 3 +- src/TypeInfo.hpp | 14 ++++++- src/crawlingwolf.cpp | 33 +++++++++++++++- tests/Makefile.W32 | 13 +++++++ tests/url/Makefile.W32 | 38 ++++++++++++++++++ tests/utils/GNUmakefile | 2 +- tests/utils/Makefile.W32 | 38 ++++++++++++++++++ tests/utils/exec_test | 17 +-------- tests/utils/exec_test.cmd | 15 ++++++++ utils/Makefile.W32 | 13 +++++++ utils/win32/Makefile.W32 | 33 ++++++++++++++++ utils/win32/README | 2 + utils/win32/dos2unix.cpp | 19 +++++++++ 28 files changed, 711 insertions(+), 19 deletions(-) create mode 100755 Makefile.W32 create mode 100644 makefiles/nmake/clean.mk create mode 100644 makefiles/nmake/compiler.mk create mode 100755 makefiles/nmake/config.mk create mode 100644 makefiles/nmake/doc.mk create mode 100644 makefiles/nmake/dochelp.mk create mode 100755 makefiles/nmake/help.mk create mode 100755 makefiles/nmake/platform.mk create mode 100644 makefiles/nmake/sub.mk create mode 100644 makefiles/nmake/top.mk mode change 100644 => 100755 src/GNUmakefile mode change 100644 => 100755 src/Logger.hpp create mode 100755 src/Makefile.W32 mode change 100644 => 100755 src/ModuleLoader.hpp mode change 100644 => 100755 src/RewindInputStream.hpp mode change 100644 => 100755 src/TypeInfo.hpp mode change 100644 => 100755 src/crawlingwolf.cpp create mode 100644 tests/Makefile.W32 create mode 100755 tests/url/Makefile.W32 mode change 100644 => 100755 tests/utils/GNUmakefile create mode 100755 tests/utils/Makefile.W32 create mode 100755 tests/utils/exec_test.cmd create mode 100644 utils/Makefile.W32 create mode 100755 utils/win32/Makefile.W32 create mode 100644 utils/win32/README create mode 100755 utils/win32/dos2unix.cpp diff --git a/.gitignore b/.gitignore index b28a811..f631773 100644 --- a/.gitignore +++ b/.gitignore @@ -1,11 +1,16 @@ *.DIFF *.RES +*.ERR *.d *.o +*.obj *.sho++ *.db *.a +*.lib *.so +*.exe +*.exe.manifest *~ tests/*/test1 tests/*/test2 diff --git a/Makefile.W32 b/Makefile.W32 new file mode 100755 index 0000000..cd0942c --- /dev/null +++ b/Makefile.W32 @@ -0,0 +1,9 @@ +TOPDIR = . + +#SUBDIRS = libfetch streamhtmlparser googleurl sqlite3 src tests +SUBDIRS = utils src tests + +PACKAGE_NAME = CrawlingWolf +PACKAGE_VERSION = 0.0.1 + +!INCLUDE $(TOPDIR)\makefiles\nmake\top.mk diff --git a/makefiles/nmake/clean.mk b/makefiles/nmake/clean.mk new file mode 100644 index 0000000..6019e56 --- /dev/null +++ b/makefiles/nmake/clean.mk @@ -0,0 +1,40 @@ +# cleans up directories +# +# requires: +# - SUBDIRS: for recursive cleaning +# - local_clean, local_distclean targets in local GNUmakefile +# - all artifacts to clean (the rest is cleaned with wildcards): +# - OBJS, DLL_OBJS +# +# provides: +# - target: clean +# - target: distclean + +clean_recursive: + @if not "$(SUBDIRS)" == "" @for %%d IN ( $(SUBDIRS) ) do @cd %%d & $(MAKE) /nologo /f Makefile.w32 clean & cd .. + +clean: clean_recursive local_clean + -@erase *.bak 2>NUL + -@erase *~ 2>NUL + -@erase *.d 2>NUL + -@erase *.exe 2>NUL + -@erase *.exe.manifest 2>NUL + -@erase *.obj 2>NUL + -@erase $(OBJS) 2>NUL + -@erase *.pdb 2>NUL + -@erase *.rc 2>NUL + -@erase *.res 2>NUL + -@erase MSG*.bin 2>NUL + -@erase *.dllobj 2>NUL + -@erase *.dll 2>NUL + -@erase *.lib 2>NUL + -@erase $(DLL_OBJS) 2>NUL + -@erase *.exp 2>NUL + -@erase *.ilk 2>NUL + -@erase *.idb 2>NUL + -@erase *.manifest 2>NUL + +distclean_recursive: + @if not "$(SUBDIRS)" == "" @for %%d IN ( $(SUBDIRS) ) do @cd %%d & $(MAKE) /nologo /f Makefile.w32 distclean & cd .. + +distclean: distclean_recursive local_distclean clean diff --git a/makefiles/nmake/compiler.mk b/makefiles/nmake/compiler.mk new file mode 100644 index 0000000..f4461de --- /dev/null +++ b/makefiles/nmake/compiler.mk @@ -0,0 +1,93 @@ +# sets compiler settings +# +# requires: +# - INCLUDE_DIRS: directories searched for includes (/I) +# - INCLUDE_CFLAGS: specific compilation flags (C) +# - INCLUDE_CXXFLAGS: specific compilation flags (C++) +# - INCLUDE_LDFLAGS: library flags like like link location (/L) +# - INCLUDE_LIBS: additional libraries to link against (e.g. advapi32.dll) +# provides: +# - generic implicit rules for compilation/linking +# + +# TODO: which flags to enable? +# /nologo: disable MS disclaimer +# /EHsc: enable C++ exception handling +# /Ox: optimize what you can +# /Zi: enable debug information +# /MD: multithreaded runtime +# /W : show warnings (level 1 to 4) +# /Wp64: warn about possible 64-bit issues +# using /W2 for now, /W3 shows lots of problems +# in boost/asio/openssl (size_t -> int conversion) +# /Wp64 breaks Qt and SSL +# /Wall: enable all warnings (produces tons of warnings!) +# /WX: treat warnings as errors + +# compilation flags and compilers (release) +!IFNDEF DEBUG +COMMON_COMPILE_FLAGS = /MD /W2 /WX /nologo /O2 /EHsc /c $(INCLUDE_DIRS) +!ENDIF + +# compilation flags and compilers (debug) +!IFDEF DEBUG +COMMON_COMPILE_FLAGS = /MDd /Zi /W2 /WX /nologo /O2 /EHsc /c $(INCLUDE_DIRS) +!ENDIF + +COMPILE_FLAGS = $(COMMON_COMPILE_FLAGS) + +CXX_COMPILE_FLAGS = $(COMMON_COMPILE_FLAGS) /EHsc + +CFLAGS = $(COMPILE_FLAGS) $(PLATFORM_COMPILE_FLAGS) $(INCLUDE_CFLAGS) $(DEBUGLEVELFLAGS) +CXXFLAGS = $(CXX_COMPILE_FLAGS) $(PLATFORM_COMPILE_FLAGS) $(INCLUDE_CXXFLAGS) $(DEBUGLEVELFLAGS) +CC = cl.exe +CXX = cl.exe +MC = mc.exe +MT = mt.exe +RC = rc.exe + +# linking flags (release) +!IFNDEF DEBUG +LDFLAGS = /nologo /manifest $(INCLUDE_LDFLAGS) +STATIC_LDFLAGS = /nologo $(INCLUDE_LDFLAGS) +!ENDIF + +# linking flags (debug) +!IFDEF DEBUG +LDFLAGS = /nologo /manifest /debug $(INCLUDE_LDFLAGS) +STATIC_LDFLAGS = /nologo $(INCLUDE_LDFLAGS) +!ENDIF + +LIBS = $(INCLUDE_LIBS) +LINK = link.exe +CXX_LINK = link.exe + +.SUFFIXES: .c .cpp .cc .obj .exe .mc .rc .res + +.c.obj: + $(CC) $(CFLAGS) /Fo$@ $< + +.cpp.obj: + $(CXX) $(CXXFLAGS) /Fo$@ $< + +.cc.obj: + $(CXX) $(CXXFLAGS) /Fo$@ $< + +.c.dllobj: + $(CC) $(CFLAGS) /D "BUILD_SHARED" /Fo$@ $< + +.cpp.dllobj: + $(CXX) $(CXXFLAGS) /D "BUILD_SHARED" /Fo$@ $< + +.cc.dllobj: + $(CXX) $(CXXFLAGS) /D "BUILD_SHARED" /Fo$@ $< + +.obj.exe: + $(CXX_LINK) $(LDFLAGS) $(LIBS) /out:$@ $(OBJS) $** + $(MT) -nologo -manifest $@.manifest -outputresource:$@;1 + +.mc.rc: + "$(MC)" -h $(@D) -r $(@D) $< + +.rc.res: + $(RC) $< diff --git a/makefiles/nmake/config.mk b/makefiles/nmake/config.mk new file mode 100755 index 0000000..a3d0484 --- /dev/null +++ b/makefiles/nmake/config.mk @@ -0,0 +1,65 @@ +# Configuration supposed to be configured here by the user +# +# must configure: +# +# optionally: +# - OPENSSL_DIR: location of the OpenSSL library (WITH_SSL=1 only) +# - PGSQL_DIR: location of Postgres libpq and header files (WITH_PGSQL=1 only) + +# please customize + +# OpenSSL (http://www.slproweb.com/products/Win32OpenSSL.html) +############################################################## + +OPENSSL_DIR = C:\OpenSSL\openssl-1.0.1-win32-debug + +# Postgresql libpq +# (http://www.postgresql.org/) +############################## + +PGSQL_DIR = C:\cygwin\home\Andreas Baumann\postgresql-9.1.3-win32-debug + +# enable depending on libintl.dll and libiconv.dll (deployment only) +PGDLL_WITHOUT_MAJOR_VERSION = 1 + +# libxml2 +######### + +LIBXML2_DIR = C:\cygwin\home\Andreas Baumann\libxml2-2.7.8-win32-debug + +# libxslt +######### + +LIBXSLT_DIR = C:\cygwin\home\Andreas Baumann\libxslt-1.1.26-win32-debug + +# Windows Installer (WIX) +# used for deployment only! +######################### + +WIX_DIR = C:\Program Files\Windows Installer XML v3.5 + +#WIX_LIBS = dutil_2008.lib wcautil_2008.lib +WIX_LIBS = dutil_2008_x64.lib wcautil_2008_x64.lib + +# architecture of resulting msi +#WIX_ARCH = x86 +WIX_ARCH = x64 + +#PGDLL_LIBRARIES=1 + +#PGDLL_WITHOUT_MAJOR_VERSION=1 + +# DocBook and Stylesheets +######################### + +XSLT_HTMLHELP_STYLESHEET = C:\cygwin\home\Andreas Baumann\docbook-xsl-1.76.1\htmlhelp\htmlhelp.xsl + +# Doxygen binary to generate API documentation (for docu and deployment) +######################################################################## + +DOXYGEN = C:\Program Files\Doxygen\bin\doxygen.exe + +# Microsoft HTML Help Workshop (for documentation building and deployment) +########################################################################## + +HHC_LOCATION = C:\Program Files\HTML Help Workshop\hhc.exe diff --git a/makefiles/nmake/doc.mk b/makefiles/nmake/doc.mk new file mode 100644 index 0000000..bd9ee2d --- /dev/null +++ b/makefiles/nmake/doc.mk @@ -0,0 +1,18 @@ +# makefile for a sub package +# +# requires: +# - TOPDIR +# +# provides: +# - target: help + +!INCLUDE $(TOPDIR)\makefiles\nmake\platform.mk + +all: local_all + +test: local_test + +clean: local_clean + +help: + @more $(TOPDIR)\makefiles\nmake\dochelp.mk diff --git a/makefiles/nmake/dochelp.mk b/makefiles/nmake/dochelp.mk new file mode 100644 index 0000000..d578117 --- /dev/null +++ b/makefiles/nmake/dochelp.mk @@ -0,0 +1,6 @@ + +Available targets: + +make doc create all documentation (except man pages and epub) +make doc-doxygen build CHM version of doxygen documentation +make doc-htmlhelp build CHM version of the Wolframe documentation diff --git a/makefiles/nmake/help.mk b/makefiles/nmake/help.mk new file mode 100755 index 0000000..f2bdf8f --- /dev/null +++ b/makefiles/nmake/help.mk @@ -0,0 +1,50 @@ + +Available targets: + +nmake [all] create all artifacts +nmake test create test binaries and execute tests and execute + fast tests +nmake longtest execute all tests, including long lasting ones +nmake doc build the documentation +nmake clean clean up build artifacts +nmake distclean clean up all generated artifacts +nmake help show this very help page + +Available optional features: + +WITH_SSL=1 use OpenSSL additionally for communication encryption + +frontier implementations: + +WITH_SYSTEM_SQLITE3=1 use the system version of sqlite3 +WITH_LOCAL_SQLITE=1 use the bundled version of sqlite3 +WITH_PGSQL=1 build the Postgresql frontier + +fetcher protocol implementations: + +WITH_SYSTEM_LIBFETCH=1 use the system version of BSD libfetch +WITH_LOCAL_LIBFETCH=1 use the bundled version of BSD libfetch + +parser implementations: + +WITH_LOCAL_STREAMHTMLPARSER=1 use Google stream HTML 4 parser + +WITH_LIBXML2=1 build the libxml2 parser + +URL parsing and normalization: + +WITH_LOCAL_GOOGLEURL=1 use Google URL for normalization/parsing +WITH_ICU=1 enable ICU support for URL parsing in Google URL + +scripting support: + +WITH_LUA=1 use Lua for configuration and scripting + +Avaliable optional features during testing only: + +DEBUG=1 build using debug compiler and linker flags + +Example: +nmake /nologo /f Makefile.W32 WITH_SSL=1 WITH_SQLITE3=1 WITH_PGSQL=1 + WITH_LOCAL_LIBFETCH=1 WITH_LIBXML2=1 WITH_LOCAL_GOOGLEURL=1 + WITH_ICU=1 WITH_LUA=1 diff --git a/makefiles/nmake/platform.mk b/makefiles/nmake/platform.mk new file mode 100755 index 0000000..3a04b36 --- /dev/null +++ b/makefiles/nmake/platform.mk @@ -0,0 +1,27 @@ +# Sets Windows specific variables +# +# provides: +# - OPENSSL_LIBS: libraries to link against for SSL/TLS support + +!INCLUDE $(TOPDIR)\makefiles\nmake\config.mk + +# OpenSSL +######### + +!IFDEF WITH_SSL +OPENSSL_LIBS = libeay32.lib ssleay32.lib +!ENDIF + +# WIX Microsoft Installer (for deployment) +########################################## + +CANDLE = "$(WIX_DIR)\bin\candle.exe" +LIGHT = "$(WIX_DIR)\bin\light.exe" +LIT = "$(WIX_DIR)\bin\lit.exe" +SMOKE = "$(WIX_DIR)\bin\smoke.exe" +SETUPBLD = "$(WIX_DIR)\bin\setupbld.exe" + +# XSLT processor +################ + +XSLTPROC = $(LIBXSLT_DIR)\bin\xsltproc.exe diff --git a/makefiles/nmake/sub.mk b/makefiles/nmake/sub.mk new file mode 100644 index 0000000..056031d --- /dev/null +++ b/makefiles/nmake/sub.mk @@ -0,0 +1,28 @@ +# makefile for a sub package +# +# requires: +# - TOPDIR +# - SUBDIRS +# - INCLUDE_DIRS +# +# provides: +# - target: all +# - target 'test' +# - target 'longtest' +# indirectly (via clean.mk): +# - target 'clean' +# - target 'distclean' + +!INCLUDE $(TOPDIR)\makefiles\nmake\platform.mk +!INCLUDE $(TOPDIR)\makefiles\nmake\compiler.mk + +all: local_all + @if not "$(SUBDIRS)" == "" @for %%d IN ( $(SUBDIRS) ) do @cd %%d & $(MAKE) /nologo /f Makefile.w32 all & cd .. + +test: $(OBJS) $(TEST_OBJS) $(CPPOBJS) $(BIN_OBJS) $(BINS) $(CPP_BINS) $(TEST_BIN_OBJS) $(TEST_BINS) $(TEST_CPP_BINS) local_test + @if not "$(SUBDIRS)" == "" @for %%d IN ( $(SUBDIRS) ) do @cd %%d & $(MAKE) /nologo /f Makefile.w32 test & cd .. + +longtest: $(OBJS) $(TEST_OBJS) $(CPPOBJS) $(BIN_OBJS) $(BINS) $(CPP_BINS) $(TEST_BIN_OBJS) $(TEST_BINS) $(TEST_CPP_BINS) local_test + @if not "$(SUBDIRS)" == "" @for %%d IN ( $(SUBDIRS) ) do @cd %%d & $(MAKE) /nologo /f Makefile.w32 longtest & cd .. + +!INCLUDE $(TOPDIR)\makefiles\nmake\clean.mk diff --git a/makefiles/nmake/top.mk b/makefiles/nmake/top.mk new file mode 100644 index 0000000..f31c040 --- /dev/null +++ b/makefiles/nmake/top.mk @@ -0,0 +1,35 @@ +# top-level makefile for a package +# +# requires: +# - TOPDIR +# - SUBDIRS +# +# provides: +# - target 'all' +# - target 'clean' +# - target 'distclean' +# - target 'test' +# - target 'longtest' +# - target 'doc' +# - target 'help' + +all: + @if not "$(SUBDIRS)" == "" @for %%d IN ( $(SUBDIRS) ) do @cd %%d & $(MAKE) /nologo /f Makefile.w32 all & cd .. + +clean: + @if not "$(SUBDIRS)" == "" @for %%d IN ( $(SUBDIRS) ) do @cd %%d & $(MAKE) /nologo /f Makefile.w32 clean & cd .. + +distclean: + @if not "$(SUBDIRS)" == "" @for %%d IN ( $(SUBDIRS) ) do @cd %%d & $(MAKE) /nologo /f Makefile.w32 distclean & cd .. + +test: all + @if not "$(SUBDIRS)" == "" @for %%d IN ( $(SUBDIRS) ) do @cd %%d & $(MAKE) /nologo /f Makefile.w32 test & cd .. + +longtest: test + @if not "$(SUBDIRS)" == "" @for %%d IN ( $(SUBDIRS) ) do @cd %%d & $(MAKE) /nologo /f Makefile.w32 longtest & cd .. + +doc: + @cd docs & $(MAKE) /nologo /f Makefile.W32 doc + +help: + @type makefiles\nmake\help.mk diff --git a/src/GNUmakefile b/src/GNUmakefile old mode 100644 new mode 100755 index 11bc63f..f30d750 --- a/src/GNUmakefile +++ b/src/GNUmakefile @@ -9,6 +9,7 @@ INCLUDE_CPPFLAGS = \ INCLUDE_LDFLAGS = \ INCLUDE_DIRS = \ + -I. INCLUDE_LIBS = \ diff --git a/src/Logger.hpp b/src/Logger.hpp old mode 100644 new mode 100755 index b62b799..93513d0 --- a/src/Logger.hpp +++ b/src/Logger.hpp @@ -9,7 +9,12 @@ #include #include +#ifndef _WIN32 #include +#else +#define WIN32_MEAN_AND_LEAN +#include +#endif using namespace std; @@ -26,6 +31,8 @@ enum LogLevel { logDEBUG4 }; +#ifndef _WIN32 + static inline string timestamp( ) { time_t t; @@ -46,6 +53,27 @@ static inline string timestamp( ) return result; } +#else + +static inline string timestamp( ) +{ + enum { LEN = 255 }; + char buf[LEN]; + + if( GetTimeFormat( LOCALE_USER_DEFAULT, 0, 0, "HH':'mm':'ss", buf, LEN ) == 0 ) { + return ""; + } + + static DWORD first = GetTickCount( ); + + char result[LEN] = { 0 }; + _snprintf( result, LEN, "%s.%03ld", buf, (long)( GetTickCount( ) - first ) % 1000 ); + + return result; +} + +#endif + template class Log { diff --git a/src/Makefile.W32 b/src/Makefile.W32 new file mode 100755 index 0000000..ddedac3 --- /dev/null +++ b/src/Makefile.W32 @@ -0,0 +1,55 @@ +TOPDIR = .. + +#SUBDIRS = modules + +!INCLUDE $(TOPDIR)\makefiles\nmake\platform.mk + +INCLUDE_CXXFLAGS = \ + /D_WIN32_WINNT=0x504 + +INCLUDE_DIRS = \ + /I. + +INCLUDE_LDFLAGS = \ + +INCLUDE_LIBS = \ + +LOCAL_STATIC_LIB_OBJS = \ + URL.obj \ + MIMEType.obj + +LOCAL_STATIC_LIB = \ + crawlingwolf.lib + +CPP_OBJS = \ + $(LOCAL_STATIC_LIB_OBJS) + +CPP_BINS = \ + crawlingwolf.exe + +all: $(CPP_OBJS) $(CPP_BINS) + +!INCLUDE $(TOPDIR)\makefiles\nmake\sub.mk + +crawlingwolf.exe: crawlingwolf.obj $(CPP_OBJS) + +$(LOCAL_STATIC_LIB): $(LOCAL_STATIC_LIB_OBJS) + $(LINK) /lib /nologo /out:$@ $(STATIC_LDFLAGS) $? + +local_all: $(LOCAL_STATIC_LIB) + +local_clean: + @-erase $(LOCAL_STATIC_LIB) 2>NUL + @-erase $(CPP_OBJS) 2>NUL + @-erase test.bat 2>NUL + +local_distclean: + +local_test: + +copy_prereq: + +run: copy_prereq + @-echo echo Running Crawlingwolf... > test.bat + @-echo crawlingwolf.exe >> test.bat + @-test.bat diff --git a/src/ModuleLoader.hpp b/src/ModuleLoader.hpp old mode 100644 new mode 100755 index 8ecccc3..e7aae37 --- a/src/ModuleLoader.hpp +++ b/src/ModuleLoader.hpp @@ -7,7 +7,12 @@ #include #include +#ifndef _WIN32 #include +#else +#define WIN32_MEAN_AND_LEAN +#include +#endif #include "ModuleRegistry.hpp" @@ -16,7 +21,11 @@ template< typename Interface, typename CtorParams = NullType > struct Module { +#ifndef _WIN32 void *handle; +#else + HMODULE handle; +#endif ModuleRegistry< Interface, CtorParams > *registry; }; @@ -38,16 +47,33 @@ class BaseModuleLoader { Module< Interface, CtorParams> m; for( std::vector::const_iterator it = files.begin( ); it != files.end( ); it++ ) { +#ifndef _WIN32 m.handle = dlopen( it->c_str( ), RTLD_NOW ); +#else + m.handle = LoadLibrary( it->c_str( ) ); +#endif if( !m.handle ) { +#ifndef _WIN32 throw std::runtime_error( dlerror( ) ); +#else + // TODO: error message here + throw std::runtime_error( "Module load error" ); +#endif } std::string registryName = "registry_" + demangle( typeid( Interface ) ); +#ifndef _WIN32 m.registry = static_cast< ModuleRegistry< Interface, CtorParams > *>( dlsym( m.handle, registryName.c_str( ) ) ); +#else + m.registry = ( ModuleRegistry< Interface, CtorParams > *)( GetProcAddress( m.handle, registryName.c_str( ) ) ); +#endif if( !m.registry ) { +#ifndef _WIN32 dlclose( m.handle ); +#else + (void)FreeLibrary( m.handle ); +#endif throw std::runtime_error( "missing module registry" ); } @@ -59,7 +85,11 @@ class BaseModuleLoader { { for( typename mapType::iterator it = m_modules.begin( ); it != m_modules.end( ); it++ ) { if( (*it).second.handle ) { +#ifndef _WIN32 dlclose( (*it).second.handle ); +#else + (void)FreeLibrary( (*it).second.handle ); +#endif (*it).second.handle = 0; } } diff --git a/src/RewindInputStream.hpp b/src/RewindInputStream.hpp old mode 100644 new mode 100755 index 9ca66b7..2b7e743 --- a/src/RewindInputStream.hpp +++ b/src/RewindInputStream.hpp @@ -15,8 +15,9 @@ class RewindInputStream : public std::istream { virtual void rewind( ) = 0; protected: + RewindInputStream( const URL &url ) - : m_baseUrl( url ) + : m_baseUrl( url ), std::istream( 0 ) { } diff --git a/src/TypeInfo.hpp b/src/TypeInfo.hpp old mode 100644 new mode 100755 index dc718ff..1e049ca --- a/src/TypeInfo.hpp +++ b/src/TypeInfo.hpp @@ -40,7 +40,19 @@ std::string demangle( const std::type_info &info ) #else -#error "C++ demangling not ported!" +#ifdef _WIN32 + +std::string demangle( const std::type_info &info ) +{ + return info.name( ); +} + +#else + +#error "type.name() demangling not implemented!" + +#endif // _WIN32 + #endif // defined( __GNUG__ ) && defined( __GLIBCXX__ ) diff --git a/src/crawlingwolf.cpp b/src/crawlingwolf.cpp old mode 100644 new mode 100755 index 9a3a027..d5a7ba9 --- a/src/crawlingwolf.cpp +++ b/src/crawlingwolf.cpp @@ -15,22 +15,48 @@ #include #include +#ifndef _WIN32 #include +#else +#define WIN32_MEAN_AND_LEAN +#endif using namespace std; static bool term = false; +#ifndef _WIN32 + static void terminate_func( int sig ) { (void)sig; term = true; } +#else + +BOOL WINAPI termHandler( DWORD ctrlType ) +{ + switch( ctrlType ){ + case CTRL_C_EVENT: + case CTRL_BREAK_EVENT: + case CTRL_CLOSE_EVENT: + case CTRL_LOGOFF_EVENT: + case CTRL_SHUTDOWN_EVENT: + term = true; + return TRUE; + default: + return FALSE; + } +} + +#endif + int main( void ) { FILELog::reportingLevel( ) = logINFO; - + +#ifndef _WIN32 struct sigaction sa; memset( &sa, 0, sizeof( struct sigaction ) ); sa.sa_handler = terminate_func; @@ -38,6 +64,11 @@ int main( void ) if( sigaction( SIGINT, &sa, NULL ) < 0 ) { cerr << "Unable to install termianation signal handler" << endl; } +#else + SetConsoleCtrlHandler( termHandler, TRUE ); +#endif + + LOG( logNOTICE ) << "Loading modules"; vector normalizerModules; normalizerModules.push_back( "./modules/urlnormalizer/simpleurl/mod_urlnormalizer_simple.so" ); diff --git a/tests/Makefile.W32 b/tests/Makefile.W32 new file mode 100644 index 0000000..b227403 --- /dev/null +++ b/tests/Makefile.W32 @@ -0,0 +1,13 @@ +TOPDIR = .. + +SUBDIRS = utils url + +!INCLUDE $(TOPDIR)\makefiles\nmake\sub.mk + +local_all: + +local_clean: + +local_distclean: + +local_test: diff --git a/tests/url/Makefile.W32 b/tests/url/Makefile.W32 new file mode 100755 index 0000000..c2d74e7 --- /dev/null +++ b/tests/url/Makefile.W32 @@ -0,0 +1,38 @@ +TOPDIR = ..\.. + +SUBDIRS = + +!INCLUDE $(TOPDIR)\makefiles\nmake\platform.mk + +INCLUDE_CXXFLAGS = \ + /D_WIN32_WINNT=0x504 + +INCLUDE_DIRS = \ + /I. \ + /I$(TOPDIR)\src + +INCLUDE_LDFLAGS = \ + +INCLUDE_LIBS = \ + +TEST_CPP_BINS = \ + test1.exe \ + test2.exe + +OBJS = + +!INCLUDE $(TOPDIR)\makefiles\nmake\sub.mk + +test1.exe: test1.obj +test2.exe: test2.obj + +local_all: + +local_clean: + @-erase -f *.RES *.DIFF *.ERR 2>NUL + +local_distclean: + +local_test: + @-exec_test test1 "TypeList and TypeTraits" + @-exec_test test2 "TypeInfo C++ demangle" diff --git a/tests/utils/GNUmakefile b/tests/utils/GNUmakefile old mode 100644 new mode 100755 index ce6df00..8fec5ce --- a/tests/utils/GNUmakefile +++ b/tests/utils/GNUmakefile @@ -3,7 +3,7 @@ TOPDIR = ../.. SUBDIRS = INCLUDE_DIRS = \ - -I$(TOPDIR)/src + -I. -I$(TOPDIR)/src INCLUDE_LDFLAGS = diff --git a/tests/utils/Makefile.W32 b/tests/utils/Makefile.W32 new file mode 100755 index 0000000..c2d74e7 --- /dev/null +++ b/tests/utils/Makefile.W32 @@ -0,0 +1,38 @@ +TOPDIR = ..\.. + +SUBDIRS = + +!INCLUDE $(TOPDIR)\makefiles\nmake\platform.mk + +INCLUDE_CXXFLAGS = \ + /D_WIN32_WINNT=0x504 + +INCLUDE_DIRS = \ + /I. \ + /I$(TOPDIR)\src + +INCLUDE_LDFLAGS = \ + +INCLUDE_LIBS = \ + +TEST_CPP_BINS = \ + test1.exe \ + test2.exe + +OBJS = + +!INCLUDE $(TOPDIR)\makefiles\nmake\sub.mk + +test1.exe: test1.obj +test2.exe: test2.obj + +local_all: + +local_clean: + @-erase -f *.RES *.DIFF *.ERR 2>NUL + +local_distclean: + +local_test: + @-exec_test test1 "TypeList and TypeTraits" + @-exec_test test2 "TypeInfo C++ demangle" diff --git a/tests/utils/exec_test b/tests/utils/exec_test index b49999b..d2d606f 100755 --- a/tests/utils/exec_test +++ b/tests/utils/exec_test @@ -2,20 +2,7 @@ BINARY=$1 TITLE=$2 -PLATFORM=$3 -LINUX_DIST=$4 -LINUX_REV=$5 - -if test "x${PLATFORM}" = "xLINUX"; then -SPECIAL="${PLATFORM}_${LINUX_DIST}_${LINUX_REV}" -else -SPECIAL="${PLATFORM}" -fi printf "$BINARY: $TITLE .. " -./$BINARY | sed 's/\(time: .* ms\)//g' >$BINARY.RES 2>&1 -if test -f $BINARY.MUST.$SPECIAL; then - diff $BINARY.MUST.$SPECIAL $BINARY.RES > $BINARY.DIFF && printf "OK\n" || printf "ERROR\n" -else - diff $BINARY.MUST $BINARY.RES > $BINARY.DIFF && printf "OK\n" || printf "ERROR\n" -fi +./$BINARY >$BINARY.RES 2>&1 +diff $BINARY.MUST $BINARY.RES > $BINARY.DIFF && printf "OK\n" || printf "ERROR\n" diff --git a/tests/utils/exec_test.cmd b/tests/utils/exec_test.cmd new file mode 100755 index 0000000..81a6222 --- /dev/null +++ b/tests/utils/exec_test.cmd @@ -0,0 +1,15 @@ +@echo off + +set BINARY=%1 +set TITLE=%2 + +%BINARY% >%BINARY%.OUT 2>%BINARY%.ERR +..\..\utils\win32\dos2unix <%BINARY%.OUT >%BINARY%.RES +erase /q %BINARY%.OUT +echo n | comp %BINARY%.MUST %BINARY%.RES > %BINARY%.DIFF 2>NUL +if ERRORLEVEL 1 GOTO FAIL +echo %BINARY%: %TITLE%.. OK +goto END +:FAIL +echo %BINARY%: %TITLE% .. ERROR +:END diff --git a/utils/Makefile.W32 b/utils/Makefile.W32 new file mode 100644 index 0000000..455376c --- /dev/null +++ b/utils/Makefile.W32 @@ -0,0 +1,13 @@ +TOPDIR = .. + +SUBDIRS = win32 + +!INCLUDE $(TOPDIR)\makefiles\nmake\sub.mk + +local_all: + +local_clean: + +local_distclean: + +local_test: diff --git a/utils/win32/Makefile.W32 b/utils/win32/Makefile.W32 new file mode 100755 index 0000000..2edb2d1 --- /dev/null +++ b/utils/win32/Makefile.W32 @@ -0,0 +1,33 @@ +TOPDIR = ..\.. + +SUBDIRS = + +!INCLUDE $(TOPDIR)\makefiles\nmake\platform.mk + +INCLUDE_CXXFLAGS = \ + /D_WIN32_WINNT=0x504 + +INCLUDE_DIRS = \ + /I. \ + /I$(TOPDIR)\src + +INCLUDE_LDFLAGS = \ + +INCLUDE_LIBS = \ + +CPP_BINS = \ + dos2unix.exe + +OBJS = + +!INCLUDE $(TOPDIR)\makefiles\nmake\sub.mk + +dos2unix.exe: dos2unix.obj + +local_all: + +local_clean: + +local_distclean: + +local_test: diff --git a/utils/win32/README b/utils/win32/README new file mode 100644 index 0000000..53fcb66 --- /dev/null +++ b/utils/win32/README @@ -0,0 +1,2 @@ +Utilities for Windows, mainly used for testing, so that we don't have +to pull in a lot of third party tools diff --git a/utils/win32/dos2unix.cpp b/utils/win32/dos2unix.cpp new file mode 100755 index 0000000..7010d0b --- /dev/null +++ b/utils/win32/dos2unix.cpp @@ -0,0 +1,19 @@ +#include +#include + +#include +#include + +using namespace std; + +int main( void ) +{ + _setmode( _fileno( stdout ), _O_BINARY ); + + string line; + while( getline( cin, line ) ) { + cout << line << "\n"; + } + + return 0; +} -- cgit v1.2.3-54-g00ecf