summaryrefslogtreecommitdiff
path: root/src/libutil
diff options
context:
space:
mode:
authorAndreas Baumann <abaumann@yahoo.com>2012-09-07 16:38:44 +0200
committerAndreas Baumann <abaumann@yahoo.com>2012-09-07 16:38:44 +0200
commit26310b6ff3b4cb92cc9bb462536a9c5235fc3389 (patch)
treeeb7cb931ba1c512b217ae138eafb4776a9c614e2 /src/libutil
parent4cb96d5377df049bd49bb6c0a109d89fcbd015ff (diff)
downloadcrawler-26310b6ff3b4cb92cc9bb462536a9c5235fc3389.tar.gz
crawler-26310b6ff3b4cb92cc9bb462536a9c5235fc3389.tar.bz2
added a libutil for porting stuff and helpers
Diffstat (limited to 'src/libutil')
-rwxr-xr-xsrc/libutil/GNUmakefile37
-rwxr-xr-xsrc/libutil/Makefile.W3249
-rwxr-xr-xsrc/libutil/win32/errormsg.cpp27
-rwxr-xr-xsrc/libutil/win32/stringutils.cpp21
4 files changed, 134 insertions, 0 deletions
diff --git a/src/libutil/GNUmakefile b/src/libutil/GNUmakefile
new file mode 100755
index 0000000..9bb47f5
--- /dev/null
+++ b/src/libutil/GNUmakefile
@@ -0,0 +1,37 @@
+TOPDIR = ../..
+
+SUBDIRS =
+
+-include $(TOPDIR)/makefiles/gmake/platform.mk
+
+INCLUDE_CPPFLAGS = \
+
+INCLUDE_LDFLAGS = \
+
+INCLUDE_DIRS = \
+ -I$(TOPDIR)/include/util
+
+INCLUDE_LIBS = \
+
+STATIC_LIB = libutil.a
+
+DYNAMIC_LIB = libutil.so
+DYNAMIC_LIB_MAJOR = 0
+DYNAMIC_LIB_MINOR = 0
+DYNAMIC_LIB_PATCH = 0
+
+CPP_OBJS = \
+
+-include $(TOPDIR)/makefiles/gmake/sub.mk
+
+local_all:
+
+local_clean:
+
+local_distclean:
+
+local_install:
+
+local_uninstall:
+
+local_test:
diff --git a/src/libutil/Makefile.W32 b/src/libutil/Makefile.W32
new file mode 100755
index 0000000..2a5630f
--- /dev/null
+++ b/src/libutil/Makefile.W32
@@ -0,0 +1,49 @@
+TOPDIR = ..\..
+
+SUBDIRS =
+
+!INCLUDE $(TOPDIR)\makefiles\nmake\platform.mk
+
+INCLUDE_CXXFLAGS = \
+ /D_WIN32_WINNT=0x504 \
+ /DBUILDING_UTIL
+
+INCLUDE_DIRS = \
+ /I. \
+ /I$(TOPDIR)\include\util
+
+INCLUDE_LDFLAGS = \
+
+INCLUDE_LIBS = \
+
+CPP_OBJS = \
+ win32\errormsg.obj \
+ win32\stringutils.obj
+
+DYNAMIC_CPP_OBJS = \
+ win32\errormsg.dllobj \
+ win32\stringutils.dllobj
+
+STATIC_LIB = \
+ utilstatic.lib
+
+DYNAMIC_LIB = \
+ util.dll
+
+!INCLUDE $(TOPDIR)\makefiles\nmake\sub.mk
+
+$(DYNAMIC_LIB): $(DYNAMIC_CPP_OBJS)
+ $(LINK) /nologo /dll /out:$@ $(LDFLAGS) $(LIBS) $?
+
+$(STATIC_LIB): $(CPP_OBJS)
+ $(LINK) /lib /nologo /out:$@ $(STATIC_LDFLAGS) $(LIBS) $?
+
+local_all: $(DYNAMIC_LIB) $(STATIC_LIB)
+
+local_clean:
+ @-erase $(DYNAMIC_LIB) $(STATIC_LIB) 2>NUL
+ @-erase win32\*.obj win32\*.dllobj 2>NUL
+
+local_distclean:
+
+local_test:
diff --git a/src/libutil/win32/errormsg.cpp b/src/libutil/win32/errormsg.cpp
new file mode 100755
index 0000000..c0a65d8
--- /dev/null
+++ b/src/libutil/win32/errormsg.cpp
@@ -0,0 +1,27 @@
+#include "win32/errormsg.hpp"
+
+using namespace std;
+
+#define WIN32_MEAN_AND_LEAN
+#include <windows.h>
+
+string getLastError( )
+{
+ LPTSTR buf;
+ DWORD size;
+
+ DWORD lastErr = GetLastError( );
+
+ if( !FormatMessage(
+ FORMAT_MESSAGE_ALLOCATE_BUFFER |
+ FORMAT_MESSAGE_FROM_SYSTEM |
+ FORMAT_MESSAGE_IGNORE_INSERTS |
+ FORMAT_MESSAGE_MAX_WIDTH_MASK,
+ NULL, lastErr, 0, (LPTSTR)&buf,
+ 0, NULL ) ) {
+ return "<no message available>";
+ }
+
+ return string( buf );
+}
+
diff --git a/src/libutil/win32/stringutils.cpp b/src/libutil/win32/stringutils.cpp
new file mode 100755
index 0000000..607735c
--- /dev/null
+++ b/src/libutil/win32/stringutils.cpp
@@ -0,0 +1,21 @@
+#include "win32/stringutils.hpp"
+
+using namespace std;
+
+#define WIN32_MEAN_AND_LEAN
+#include <windows.h>
+
+std::wstring s2ws( const std::string &s )
+{
+ // get size for buffer and allocate it
+ int len;
+ int slength = (int)s.length( )+1;
+ len = MultiByteToWideChar( CP_ACP, 0, s.c_str( ), slength, 0, 0 );
+ wchar_t *buf = new wchar_t[len];
+
+ // convert
+ MultiByteToWideChar( CP_ACP, 0, s.c_str( ), slength, buf, len );
+ std::wstring res( buf );
+ delete[] buf;
+ return res;
+}