summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Baumann <abaumann@yahoo.com>2012-08-10 14:44:17 +0200
committerAndreas Baumann <abaumann@yahoo.com>2012-08-10 14:44:17 +0200
commit4a6b24a567142317a24a98d2ab998f5093a581cc (patch)
tree522107a269c040e69b933fc9f69fe330703562b5
parent9fe78b708868dcb5bdbfc88ed96dee18c6f1f6b3 (diff)
downloadcrawler-4a6b24a567142317a24a98d2ab998f5093a581cc.tar.gz
crawler-4a6b24a567142317a24a98d2ab998f5093a581cc.tar.bz2
first porting attempts to Windows:
nmake support from Wolframe module loader adapted tests for typeinfo and template trickery
-rw-r--r--.gitignore5
-rwxr-xr-xMakefile.W329
-rw-r--r--makefiles/nmake/clean.mk40
-rw-r--r--makefiles/nmake/compiler.mk93
-rwxr-xr-xmakefiles/nmake/config.mk65
-rw-r--r--makefiles/nmake/doc.mk18
-rw-r--r--makefiles/nmake/dochelp.mk6
-rwxr-xr-xmakefiles/nmake/help.mk50
-rwxr-xr-xmakefiles/nmake/platform.mk27
-rw-r--r--makefiles/nmake/sub.mk28
-rw-r--r--makefiles/nmake/top.mk35
-rwxr-xr-x[-rw-r--r--]src/GNUmakefile1
-rwxr-xr-x[-rw-r--r--]src/Logger.hpp28
-rwxr-xr-xsrc/Makefile.W3255
-rwxr-xr-x[-rw-r--r--]src/ModuleLoader.hpp30
-rwxr-xr-x[-rw-r--r--]src/RewindInputStream.hpp3
-rwxr-xr-x[-rw-r--r--]src/TypeInfo.hpp14
-rwxr-xr-x[-rw-r--r--]src/crawlingwolf.cpp33
-rw-r--r--tests/Makefile.W3213
-rwxr-xr-xtests/url/Makefile.W3238
-rwxr-xr-x[-rw-r--r--]tests/utils/GNUmakefile2
-rwxr-xr-xtests/utils/Makefile.W3238
-rwxr-xr-xtests/utils/exec_test17
-rwxr-xr-xtests/utils/exec_test.cmd15
-rw-r--r--utils/Makefile.W3213
-rwxr-xr-xutils/win32/Makefile.W3233
-rw-r--r--utils/win32/README2
-rwxr-xr-xutils/win32/dos2unix.cpp19
28 files changed, 711 insertions, 19 deletions
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 <n>: 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
index 11bc63f..f30d750 100644..100755
--- 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
index b62b799..93513d0 100644..100755
--- a/src/Logger.hpp
+++ b/src/Logger.hpp
@@ -9,7 +9,12 @@
#include <cstdio>
#include <cstring>
+#ifndef _WIN32
#include <sys/time.h>
+#else
+#define WIN32_MEAN_AND_LEAN
+#include <windows.h>
+#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 "<timestamp error>";
+ }
+
+ static DWORD first = GetTickCount( );
+
+ char result[LEN] = { 0 };
+ _snprintf( result, LEN, "%s.%03ld", buf, (long)( GetTickCount( ) - first ) % 1000 );
+
+ return result;
+}
+
+#endif
+
template<typename T>
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
index 8ecccc3..e7aae37 100644..100755
--- a/src/ModuleLoader.hpp
+++ b/src/ModuleLoader.hpp
@@ -7,7 +7,12 @@
#include <stdexcept>
#include <typeinfo>
+#ifndef _WIN32
#include <dlfcn.h>
+#else
+#define WIN32_MEAN_AND_LEAN
+#include <windows.h>
+#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<string>::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
index 9ca66b7..2b7e743 100644..100755
--- 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
index dc718ff..1e049ca 100644..100755
--- 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
index 9a3a027..d5a7ba9 100644..100755
--- a/src/crawlingwolf.cpp
+++ b/src/crawlingwolf.cpp
@@ -15,22 +15,48 @@
#include <vector>
#include <list>
+#ifndef _WIN32
#include <signal.h>
+#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<string> 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
index ce6df00..8fec5ce 100644..100755
--- 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 <iostream>
+#include <string>
+
+#include <io.h>
+#include <fcntl.h>
+
+using namespace std;
+
+int main( void )
+{
+ _setmode( _fileno( stdout ), _O_BINARY );
+
+ string line;
+ while( getline( cin, line ) ) {
+ cout << line << "\n";
+ }
+
+ return 0;
+}