Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/kenlm
diff options
context:
space:
mode:
authorHieu Hoang <hieuhoang@gmail.com>2011-11-14 19:17:41 +0400
committerHieu Hoang <hieuhoang@gmail.com>2011-11-14 19:17:41 +0400
commit94f3c1ac8b91a1173adc1b2093e2867e5218349a (patch)
treef159925d62b3c9f6c1e839408aaabebcbdd22b23 /kenlm
parentcf97e1108d866f133c74082e7dcdb39701a7ff4f (diff)
low hanging fruit visual studio fixes.
Diffstat (limited to 'kenlm')
-rw-r--r--kenlm/kenlm.vcxproj3
-rw-r--r--kenlm/lm/build_binary.cc7
-rw-r--r--kenlm/lm/ngram_query.cc2
-rw-r--r--kenlm/util/file.cc2
-rw-r--r--kenlm/util/file_piece.cc2
-rw-r--r--kenlm/util/portability.cc74
-rw-r--r--kenlm/util/portability.hh127
7 files changed, 212 insertions, 5 deletions
diff --git a/kenlm/kenlm.vcxproj b/kenlm/kenlm.vcxproj
index cbdfc5562..9b9a4d8b8 100644
--- a/kenlm/kenlm.vcxproj
+++ b/kenlm/kenlm.vcxproj
@@ -107,6 +107,7 @@
<None Include="util\key_value_packing.hh" />
<None Include="util\mmap.hh" />
<None Include="util\murmur_hash.hh" />
+ <None Include="util\portability.hh" />
<None Include="util\probing_hash_table.hh" />
<None Include="util\proxy_iterator.hh" />
<None Include="util\scoped.hh" />
@@ -127,7 +128,6 @@
<ClCompile Include="lm\read_arpa.cc" />
<ClCompile Include="lm\search_hashed.cc" />
<ClCompile Include="lm\search_trie.cc" />
- <ClCompile Include="lm\sri_test.cc" />
<ClCompile Include="lm\trie.cc" />
<ClCompile Include="lm\trie_sort.cc" />
<ClCompile Include="lm\virtual_interface.cc" />
@@ -139,6 +139,7 @@
<ClCompile Include="util\file_piece.cc" />
<ClCompile Include="util\mmap.cc" />
<ClCompile Include="util\murmur_hash.cc" />
+ <ClCompile Include="util\portability.cc" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
diff --git a/kenlm/lm/build_binary.cc b/kenlm/lm/build_binary.cc
index 5a0d98dc6..f313002fe 100644
--- a/kenlm/lm/build_binary.cc
+++ b/kenlm/lm/build_binary.cc
@@ -1,5 +1,6 @@
#include "lm/model.hh"
#include "util/file_piece.hh"
+#include "util/portability.hh"
#include <cstdlib>
#include <exception>
@@ -9,6 +10,10 @@
#include <math.h>
#include <stdlib.h>
+#ifdef WIN32
+#include "util/getopt.hh"
+#endif
+
namespace lm {
namespace ngram {
namespace {
@@ -86,7 +91,7 @@ void ShowSizes(const char *file, const lm::ngram::Config &config) {
prefix = 'G';
divide = 1 << 30;
}
- long int length = std::max<long int>(2, lrint(ceil(log10(max_length / divide))));
+ long int length = std::max<long int>(2, lrint(ceil(log10((double) max_length / divide))));
std::cout << "Memory estimate:\ntype ";
// right align bytes.
for (long int i = 0; i < length - 2; ++i) std::cout << ' ';
diff --git a/kenlm/lm/ngram_query.cc b/kenlm/lm/ngram_query.cc
index 50ceef5c8..1a87bef60 100644
--- a/kenlm/lm/ngram_query.cc
+++ b/kenlm/lm/ngram_query.cc
@@ -9,8 +9,8 @@
#include <ctype.h>
#if !defined(_WIN32) && !defined(_WIN64)
#include <sys/resource.h>
-#endif
#include <sys/time.h>
+#endif
float FloatSec(const struct timeval &tv) {
return static_cast<float>(tv.tv_sec) + (static_cast<float>(tv.tv_usec) / 1000000000.0);
diff --git a/kenlm/util/file.cc b/kenlm/util/file.cc
index 954182a07..81d1d490c 100644
--- a/kenlm/util/file.cc
+++ b/kenlm/util/file.cc
@@ -1,6 +1,7 @@
#include "util/file.hh"
#include "util/exception.hh"
+#include "util/portability.hh"
#include <cstdlib>
#include <cstdio>
@@ -9,7 +10,6 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
-#include <unistd.h>
#include <stdint.h>
#if defined(_WIN32) || defined(_WIN64)
diff --git a/kenlm/util/file_piece.cc b/kenlm/util/file_piece.cc
index d0101e129..43b578b65 100644
--- a/kenlm/util/file_piece.cc
+++ b/kenlm/util/file_piece.cc
@@ -3,6 +3,7 @@
#include "util/exception.hh"
#include "util/file.hh"
#include "util/mmap.hh"
+#include "util/portability.hh"
#include <iostream>
#include <string>
@@ -14,7 +15,6 @@
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
-#include <unistd.h>
#ifdef HAVE_ZLIB
#include <zlib.h>
diff --git a/kenlm/util/portability.cc b/kenlm/util/portability.cc
new file mode 100644
index 000000000..2efd74cba
--- /dev/null
+++ b/kenlm/util/portability.cc
@@ -0,0 +1,74 @@
+
+#include <stdlib.h>
+#include <errno.h>
+#include "util/portability.hh"
+
+#ifdef WIN32
+
+int RUSAGE_SELF = 0;
+
+int sysconf(int) { return 0; }
+int msync(void*, int, int) { return 0; }
+int munmap(void *, int) { return 0; }
+void *mmap(void*, int, int, int, FD, OFF_T) { return 0; }
+int write(int, const void *, int) {return 0; }
+
+//FILE *popen(const char*, const char*) { return 0; }
+//int pclose(FILE *) { return 0; }
+int close(FD fd) { return 0; }
+
+
+// to be implemented by boost
+int mkdtemp(const char*) { return 0; }
+
+// done
+long lrint(float x)
+{
+ long ret = (long) x;
+ return ret;
+}
+
+float strtof(const char *begin, char **end)
+{
+ double ret = strtod(begin, end);
+ return (float) ret;
+}
+
+
+int ftruncate (FD hfile, unsigned int size)
+{
+ unsigned int curpos;
+ /*
+ HANDLE hfile;
+
+ if (fd < 0)
+ {
+ errno = EBADF;
+ return -1;
+ }
+
+ hfile = (HANDLE) _get_osfhandle (fd);
+ */
+ curpos = SetFilePointer (hfile, 0, NULL, FILE_CURRENT);
+ if (curpos == ~0
+ || SetFilePointer (hfile, size, NULL, FILE_BEGIN) == ~0
+ || !SetEndOfFile (hfile))
+ {
+ int error = GetLastError ();
+ switch (error)
+ {
+ case ERROR_INVALID_HANDLE:
+ errno = EBADF;
+ break;
+ default:
+ errno = EIO;
+ break;
+ }
+ return -1;
+ }
+ return 0;
+}
+
+#endif
+
+
diff --git a/kenlm/util/portability.hh b/kenlm/util/portability.hh
new file mode 100644
index 000000000..7066f50f5
--- /dev/null
+++ b/kenlm/util/portability.hh
@@ -0,0 +1,127 @@
+
+#pragma once
+
+#include <assert.h>
+#include <stdint.h>
+
+#ifdef WIN32
+
+#include <windows.h>
+#include <direct.h>
+#include <io.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/stat.h>
+#include "util/getopt.hh"
+
+#undef max
+#undef min
+
+typedef HANDLE FD;
+
+const FD kBadFD = INVALID_HANDLE_VALUE;
+
+typedef int ssize_t;
+
+#define _SC_PAGE_SIZE 1
+#define MS_SYNC 1
+
+int sysconf(int);
+int msync(void*, int, int);
+int ftruncate(FD, unsigned int);
+
+long lrint(float);
+
+/*
+struct timeval
+{
+ float tv_sec, tv_usec;
+};
+
+struct rusage
+{
+ timeval ru_utime, ru_stime;
+};
+*/
+
+//inline int getrusage(int, struct rusage*) { return 0; }
+//extern int RUSAGE_SELF;
+
+typedef __int64 OFF_T;
+//#define OFF_T __int64
+
+#ifndef S_ISDIR
+#define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
+#endif
+
+#ifndef S_ISREG
+#define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
+#endif
+
+int mkdtemp(const char*);
+int munmap(void *, int);
+void *mmap(void*, int, int, int, FD, OFF_T);
+
+#define PROT_READ 1
+#define PROT_WRITE 1
+#define MAP_FAILED (void*) 0x1
+#define MAP_SHARED 1
+#define MAP_ANON 1
+#define MAP_PRIVATE 1
+#define S_IRUSR 1
+#define S_IROTH 1
+#define S_IRGRP 1
+
+int write(int, const void *, int);
+#define S_IRUSR 1
+#define S_IWUSR 1
+
+//const char *strerror_r(int, const char *buf, int);
+
+float strtof(const char *begin, char **end);
+//FILE *popen(const char*, const char*);
+//int pclose(FILE *);
+int close(FD fd);
+
+#define dup(x) _dup(x)
+#define rmdir(x) _rmdir(x)
+#define strerror_r(errNum, buffer, numberOfElements) strerror_s(buffer, numberOfElements);
+
+#else // assume UNIX OS
+
+#include <stdint.h>
+#include <sys/resource.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+typedef int FD;
+const FD kBadFD = -1;
+
+typedef off_t OFF_T;
+
+#endif
+
+#ifdef __GNUC__
+#define UTIL_FUNC_NAME __PRETTY_FUNCTION__
+#else
+#ifdef _WIN32
+#define UTIL_FUNC_NAME __FUNCTION__
+#else
+#define UTIL_FUNC_NAME NULL
+#endif
+#endif
+
+/* Bit-level packing routines */
+#ifdef __APPLE__
+ #include <architecture/byte_order.h>
+#elif __linux__
+ #include <endian.h>
+#elif WIN32
+ // nothing
+#else
+ #include <arpa/nameser_compat.h>
+#endif
+