From d4cd1dd91c8df6adb1a07bd55878e4a3585af427 Mon Sep 17 00:00:00 2001 From: Jean-Francois Dockes Date: Sun, 30 Aug 2015 11:19:18 +0200 Subject: [PATCH] 1st mods to get a build under windows. Does not build yet, far from it --HG-- branch : WINDOWSPORT --- src/bincimapmime/convert.h | 2 +- src/bincimapmime/mime-inputsource.h | 2 +- src/common/conf_post.h | 34 +++ src/common/rclconfig.cpp | 8 +- src/common/rclinit.cpp | 19 +- src/common/syngroups.cpp | 2 +- src/index/fetcher.cpp | 3 +- src/index/fsindexer.cpp | 1 - src/index/mimetype.cpp | 2 + src/index/recollindex.cpp | 27 +- src/internfile/extrameta.cpp | 2 + src/internfile/internfile.cpp | 2 +- src/internfile/mh_execm.h | 2 + src/internfile/mh_mail.cpp | 2 +- src/internfile/mh_mbox.cpp | 41 ++- src/internfile/mh_symlink.h | 2 +- src/internfile/mimehandler.cpp | 1 - src/internfile/uncomp.cpp | 4 + src/rcldb/daterange.cpp | 2 +- src/rcldb/rcldb.cpp | 7 +- src/rcldb/rclterms.cpp | 12 +- src/rcldb/stemdb.cpp | 3 +- src/utils/circache.cpp | 4 +- src/utils/conftree.cpp | 4 +- src/utils/copyfile.cpp | 9 +- src/utils/execmd.h | 4 +- src/utils/fileudi.cpp | 1 + src/utils/fstreewalk.cpp | 4 +- src/utils/idfile.cpp | 6 +- src/utils/pathut.cpp | 38 ++- src/utils/smallut.cpp | 90 ++++++- src/utils/smallut.h | 16 +- src/windows/Win32ProjectRecoll.sln | 41 +++ src/windows/Win32ProjectRecoll.vcxproj | 216 +++++++++++++++ .../Win32ProjectRecoll.vcxproj.filters | 231 ++++++++++++++++ src/windows/dirent.c | 148 +++++++++++ src/windows/dirent.h | 50 ++++ src/windows/fnmatch.c | 188 +++++++++++++ src/windows/fnmatch.h | 38 +++ src/windows/recollindex/recollindex.vcxproj | 156 +++++++++++ .../recollindex/recollindex.vcxproj.filters | 22 ++ src/windows/targetver.h | 8 + src/xaposix/config.h | 249 ++++++++++++++++++ src/xaposix/realtime.h | 107 ++++++++ src/xaposix/safe.cc | 31 +++ src/xaposix/safeerrno.h | 36 +++ src/xaposix/safefcntl.h | 4 +- src/xaposix/safewindows.h | 45 ++++ 48 files changed, 1855 insertions(+), 71 deletions(-) create mode 100644 src/windows/Win32ProjectRecoll.sln create mode 100644 src/windows/Win32ProjectRecoll.vcxproj create mode 100644 src/windows/Win32ProjectRecoll.vcxproj.filters create mode 100644 src/windows/dirent.c create mode 100644 src/windows/dirent.h create mode 100644 src/windows/fnmatch.c create mode 100644 src/windows/fnmatch.h create mode 100644 src/windows/recollindex/recollindex.vcxproj create mode 100644 src/windows/recollindex/recollindex.vcxproj.filters create mode 100644 src/windows/targetver.h create mode 100644 src/xaposix/config.h create mode 100644 src/xaposix/realtime.h create mode 100644 src/xaposix/safe.cc create mode 100644 src/xaposix/safeerrno.h create mode 100644 src/xaposix/safewindows.h diff --git a/src/bincimapmime/convert.h b/src/bincimapmime/convert.h index 30b034f8..8ea1f964 100644 --- a/src/bincimapmime/convert.h +++ b/src/bincimapmime/convert.h @@ -122,7 +122,7 @@ namespace Binc { for (std::string::const_iterator i = s_in.begin(); i != s_in.end(); ++i) { unsigned char c = (unsigned char)*i; if (c <= 31 || c >= 127 || c == '\"' || c == '\\') - return "{" + toString(s_in.length()) + "}\r\n" + s_in; + return "{" + toString((unsigned long)s_in.length()) + "}\r\n" + s_in; } return "\"" + s_in + "\""; diff --git a/src/bincimapmime/mime-inputsource.h b/src/bincimapmime/mime-inputsource.h index 2e507e4a..9648e604 100644 --- a/src/bincimapmime/mime-inputsource.h +++ b/src/bincimapmime/mime-inputsource.h @@ -25,7 +25,7 @@ */ #ifndef mime_inputsource_h_included #define mime_inputsource_h_included - +#include "autoconfig.h" // Data source for MIME parser // Note about large files: we might want to change the unsigned int diff --git a/src/common/conf_post.h b/src/common/conf_post.h index 71373d50..b9f55663 100644 --- a/src/common/conf_post.h +++ b/src/common/conf_post.h @@ -26,3 +26,37 @@ # define STD_SHARED_PTR RefCntr #endif +#ifdef _WIN32 +#include "safewindows.h" +typedef int pid_t; +inline int readlink(const char *cp, void *buf, int cnt) { + return -1; +} +#define HAVE_STRUCT_TIMESPEC +#define strdup _strdup +#define timegm _mkgmtime +// gmtime is supposedly thread-safe on windows +#define gmtime_r(A, B) gmtime(A) +#define localtime_r(A,B) localtime(A) + +typedef DWORD32 u_int32_t; +typedef DWORD64 u_int64_t; +typedef unsigned __int8 u_int8_t; +typedef int mode_t; +typedef int ssize_t; +#define strncasecmp _strnicmp +#define ftruncate _chsize +#define PATH_MAX MAX_PATH +#define MAXPATHLEN PATH_MAX +#define R_OK 4 +#define W_OK 2 +#define X_OK 4 +#define RECOLL_DATADIR "C:\\recoll\\" +#define S_ISLNK(X) false +#define lstat stat +#define fseeko _fseeki64 +#define ftello _ftelli64 + +#endif + + diff --git a/src/common/rclconfig.cpp b/src/common/rclconfig.cpp index fe26e9d4..229782e0 100644 --- a/src/common/rclconfig.cpp +++ b/src/common/rclconfig.cpp @@ -19,11 +19,13 @@ #include #include +#ifndef _WIN32 #include +#include +#endif #include #include "safesysstat.h" #include "safeunistd.h" -#include #ifdef __FreeBSD__ #include #endif @@ -200,6 +202,7 @@ RclConfig::RclConfig(const string *argcnf) // is called from the main thread at once, by constructing a config // from recollinit if (o_localecharset.empty()) { +#ifndef _WIN32 const char *cp; cp = nl_langinfo(CODESET); // We don't keep US-ASCII. It's better to use a superset @@ -217,6 +220,9 @@ RclConfig::RclConfig(const string *argcnf) // Use cp1252 instead of iso-8859-1, it's a superset. o_localecharset = string(cstr_cp1252); } +#else + o_localecharset = "UTF-8"; +#endif LOGDEB1(("RclConfig::getDefCharset: localecharset [%s]\n", o_localecharset.c_str())); } diff --git a/src/common/rclinit.cpp b/src/common/rclinit.cpp index a3963987..0184dda8 100644 --- a/src/common/rclinit.cpp +++ b/src/common/rclinit.cpp @@ -31,9 +31,13 @@ #include "pathut.h" #include "unac.h" #include "smallut.h" +#ifndef _WIN32 #include "execmd.h" +#endif +#ifndef _WIN32 static const int catchedSigs[] = {SIGINT, SIGQUIT, SIGTERM, SIGUSR1, SIGUSR2}; +#endif static pthread_t mainthread_id; @@ -52,7 +56,9 @@ RclConfig *recollinit(RclInitFlags flags, // We ignore SIGPIPE always. All pieces of code which can write to a pipe // must check write() return values. +#ifndef _WIN32 signal(SIGPIPE, SIG_IGN); +#endif // Make sure the locale is set. This is only for converting file names // to utf8 for indexing. @@ -63,6 +69,7 @@ RclConfig *recollinit(RclInitFlags flags, // Install app signal handler if (sigcleanup) { +#ifndef _WIN32 struct sigaction action; action.sa_handler = sigcleanup; action.sa_flags = 0; @@ -73,8 +80,8 @@ RclConfig *recollinit(RclInitFlags flags, perror("Sigaction failed"); } } +#endif } - DebugLog::getdbl()->setloglevel(DEBDEB1); DebugLog::setfilename("stderr"); if (getenv("RECOLL_LOGDATE")) @@ -116,6 +123,7 @@ RclConfig *recollinit(RclInitFlags flags, DebugLog::getdbl()->setloglevel(lev); } // Install log rotate sig handler +#ifndef _WIN32 { struct sigaction action; action.sa_handler = siglogreopen; @@ -127,6 +135,7 @@ RclConfig *recollinit(RclInitFlags flags, } } } +#endif // Make sure the locale charset is initialized (so that multiple // threads don't try to do it at once). @@ -146,7 +155,9 @@ RclConfig *recollinit(RclInitFlags flags, unac_set_except_translations(unacex.c_str()); #ifndef IDX_THREADS +#ifndef _WIN32 ExecCmd::useVfork(true); +#endif #else // Keep threads init behind log init, but make sure it's done before // we do the vfork choice ! The latter is not used any more actually, @@ -156,11 +167,15 @@ RclConfig *recollinit(RclInitFlags flags, bool novfork; config->getConfParam("novfork", &novfork); if (novfork) { +#ifndef _WIN32 LOGDEB0(("rclinit: will use fork() for starting commands\n")); ExecCmd::useVfork(false); +#endif } else { +#ifndef _WIN32 LOGDEB0(("rclinit: will use vfork() for starting commands\n")); ExecCmd::useVfork(true); +#endif } #endif @@ -183,6 +198,7 @@ RclConfig *recollinit(RclInitFlags flags, // to block possible signals void recoll_threadinit() { +#ifndef _WIN32 sigset_t sset; sigemptyset(&sset); @@ -190,6 +206,7 @@ void recoll_threadinit() sigaddset(&sset, catchedSigs[i]); sigaddset(&sset, SIGHUP); pthread_sigmask(SIG_BLOCK, &sset, 0); +#endif } bool recoll_ismainthread() diff --git a/src/common/syngroups.cpp b/src/common/syngroups.cpp index e6da110b..65ec2593 100644 --- a/src/common/syngroups.cpp +++ b/src/common/syngroups.cpp @@ -110,7 +110,7 @@ bool SynGroups::setfile(const string& fn) lnum++; { - int ll = strlen(cline); + size_t ll = strlen(cline); while (ll > 0 && (cline[ll-1] == '\n' || cline[ll-1] == '\r')) { cline[ll-1] = 0; ll--; diff --git a/src/index/fetcher.cpp b/src/index/fetcher.cpp index d6106480..5d205487 100644 --- a/src/index/fetcher.cpp +++ b/src/index/fetcher.cpp @@ -14,9 +14,8 @@ * Free Software Foundation, Inc., * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#ifdef HAVE_CONFIG_H #include "autoconfig.h" -#endif + #include "debuglog.h" diff --git a/src/index/fsindexer.cpp b/src/index/fsindexer.cpp index a9b41294..feaf5678 100644 --- a/src/index/fsindexer.cpp +++ b/src/index/fsindexer.cpp @@ -43,7 +43,6 @@ #include "fileudi.h" #include "cancelcheck.h" #include "rclinit.h" -#include "execmd.h" #include "extrameta.h" using namespace std; diff --git a/src/index/mimetype.cpp b/src/index/mimetype.cpp index aa18756a..d53d331c 100644 --- a/src/index/mimetype.cpp +++ b/src/index/mimetype.cpp @@ -27,7 +27,9 @@ using namespace std; #include "mimetype.h" #include "debuglog.h" +#ifndef _WIN32 #include "execmd.h" +#endif #include "rclconfig.h" #include "smallut.h" #include "idfile.h" diff --git a/src/index/recollindex.cpp b/src/index/recollindex.cpp index f20a699d..9ae807e7 100644 --- a/src/index/recollindex.cpp +++ b/src/index/recollindex.cpp @@ -14,16 +14,16 @@ * Free Software Foundation, Inc., * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#ifdef HAVE_CONFIG_H #include "autoconfig.h" -#endif #include #include #include +#ifndef _WIN32 #include #include -#include +#endif +#include "safefcntl.h" #include "safeunistd.h" #include @@ -45,7 +45,9 @@ using namespace std; #include "beaglequeue.h" #include "recollindex.h" #include "fsindexer.h" +#ifndef _WIN32 #include "rclionice.h" +#endif #include "execmd.h" #include "checkretryfailed.h" @@ -177,11 +179,13 @@ static void makeIndexerOrExit(RclConfig *config, bool inPlaceReset) void rclIxIonice(const RclConfig *config) { +#ifndef _WIN32 string clss, classdata; if (!config->getConfParam("monioniceclass", clss) || clss.empty()) clss = "3"; config->getConfParam("monioniceclassdata", classdata); rclionice(clss, classdata); +#endif } class MakeListWalkerCB : public FsTreeWalkerCB { @@ -393,8 +397,10 @@ int main(int argc, char **argv) // The reexec struct is used by the daemon to shed memory after // the initial indexing pass and to restart when the configuration // changes +#ifndef _WIN32 o_reexec = new ReExec; o_reexec->init(argc, argv); +#endif thisprog = argv[0]; argc--; argv++; @@ -463,7 +469,9 @@ int main(int argc, char **argv) cerr << "Configuration problem: " << reason << endl; exit(1); } +#ifndef _WIN32 o_reexec->atexit(cleanup); +#endif vector nonexist; if (!checktopdirs(config, nonexist)) @@ -483,7 +491,7 @@ int main(int argc, char **argv) if ((op_flags & OPT_E)) { exit(0); } - +#ifndef _WIN32 string rundir; config->getConfParam("idxrundir", rundir); if (!rundir.compare("tmp")) { @@ -501,6 +509,7 @@ int main(int argc, char **argv) rundir.c_str(), errno)); } } +#endif bool rezero((op_flags & OPT_z) != 0); bool inPlaceReset((op_flags & OPT_Z) != 0); @@ -522,12 +531,13 @@ int main(int argc, char **argv) // Log something at LOGINFO to reset the trace file. Else at level // 3 it's not even truncated if all docs are up to date. LOGINFO(("recollindex: starting up\n")); - +#ifndef _WIN32 if (setpriority(PRIO_PROCESS, 0, 20) != 0) { LOGINFO(("recollindex: can't setpriority(), errno %d\n", errno)); } // Try to ionice. This does not work on all platforms rclIxIonice(config); +#endif if (op_flags & (OPT_i|OPT_e)) { lockorexit(&pidfile); @@ -596,15 +606,17 @@ int main(int argc, char **argv) lockorexit(&pidfile); if (!(op_flags&OPT_D)) { LOGDEB(("recollindex: daemonizing\n")); +#ifndef _WIN32 if (daemon(0,0) != 0) { fprintf(stderr, "daemon() failed, errno %d\n", errno); LOGERR(("daemon() failed, errno %d\n", errno)); exit(1); } +#endif } // Need to rewrite pid, it changed pidfile.write_pid(); - +#ifndef _WIN32 // Not too sure if I have to redo the nice thing after daemon(), // can't hurt anyway (easier than testing on all platforms...) if (setpriority(PRIO_PROCESS, 0, 20) != 0) { @@ -612,6 +624,7 @@ int main(int argc, char **argv) } // Try to ionice. This does not work on all platforms rclIxIonice(config); +#endif if (sleepsecs > 0) { LOGDEB(("recollindex: sleeping %d\n", sleepsecs)); @@ -639,6 +652,7 @@ int main(int argc, char **argv) } } deleteZ(confindexer); +#ifndef _WIN32 o_reexec->insertArgs(vector(1, "-n")); LOGINFO(("recollindex: reexecuting with -n after initial full pass\n")); // Note that -n will be inside the reexec when we come @@ -646,6 +660,7 @@ int main(int argc, char **argv) // starting a config change exec to ensure that we do a // purging pass in this case. o_reexec->reexec(); +#endif } if (updater) { updater->status.phase = DbIxStatus::DBIXS_MONITOR; diff --git a/src/internfile/extrameta.cpp b/src/internfile/extrameta.cpp index 3466c1a6..2f83fb9a 100644 --- a/src/internfile/extrameta.cpp +++ b/src/internfile/extrameta.cpp @@ -93,6 +93,7 @@ void docFieldsFromXattrs(RclConfig *cfg, const map& xfields, void reapMetaCmds(RclConfig* cfg, const string& path, map& cfields) { +#ifndef _WIN32 const vector& reapers = cfg->getMDReapers(); if (reapers.empty()) return; @@ -111,6 +112,7 @@ void reapMetaCmds(RclConfig* cfg, const string& path, cfields[rp->fieldname] = output; } } +#endif } // Set fields from external commands diff --git a/src/internfile/internfile.cpp b/src/internfile/internfile.cpp index 50962697..2801824e 100644 --- a/src/internfile/internfile.cpp +++ b/src/internfile/internfile.cpp @@ -216,7 +216,7 @@ void FileInterner::init(const string &f, const struct stat *stp, RclConfig *cnf, m_mimetype = l_mime; RecollFilter *df = getMimeHandler(l_mime, m_cfg, !m_forPreview); - if (!df or df->is_unknown()) { + if (!df || df->is_unknown()) { // No real handler for this type, for now :( LOGDEB(("FileInterner:: unprocessed mime: [%s] [%s]\n", l_mime.c_str(), f.c_str())); diff --git a/src/internfile/mh_execm.h b/src/internfile/mh_execm.h index c2b29242..70c6b7c9 100644 --- a/src/internfile/mh_execm.h +++ b/src/internfile/mh_execm.h @@ -98,7 +98,9 @@ text/plainData: 10 class MimeHandlerExecMultiple : public MimeHandlerExec { ///////// // Things not reset by "clear()", additionally to those in MimeHandlerExec +#ifndef _WIN32 ExecCmd m_cmd; +#endif /////// End un-cleared stuff. public: diff --git a/src/internfile/mh_mail.cpp b/src/internfile/mh_mail.cpp index 23870e07..32721c65 100644 --- a/src/internfile/mh_mail.cpp +++ b/src/internfile/mh_mail.cpp @@ -18,7 +18,7 @@ #include #include #include -#include +#include "safeunistd.h" #include #include diff --git a/src/internfile/mh_mbox.cpp b/src/internfile/mh_mbox.cpp index ee7e25a8..445b9d14 100644 --- a/src/internfile/mh_mbox.cpp +++ b/src/internfile/mh_mbox.cpp @@ -22,7 +22,11 @@ #include #include "safesysstat.h" #include +#ifndef _WIN32 #include +#else +#include +#endif #include #include @@ -70,6 +74,14 @@ static PTMutexInit o_mcache_mutex; * offsets for all message "From_" lines follow. The format is purely * binary, values are not even byte-swapped to be proc-idependant. */ + +#ifdef _WIN32 +// vc++ does not let define an array of size o_b1size because non-const?? +#define M_o_b1size 1024 +#else +#define M_o_b1size o_b1size; +#endif + class MboxCache { public: typedef MimeHandlerMbox::mbhoff_type mbhoff_type; @@ -98,7 +110,7 @@ public: } FpKeeper keeper(&fp); - char blk1[o_b1size]; + char blk1[M_o_b1size]; if (fread(blk1, 1, o_b1size, fp) != o_b1size) { LOGDEB0(("MboxCache::get_offsets: read blk1 errno %d\n", errno)); return -1; @@ -226,7 +238,6 @@ private: }; const size_t MboxCache::o_b1size = 1024; - static class MboxCache o_mcache; static const string cstr_keyquirks("mhmboxquirks"); @@ -376,9 +387,20 @@ static const char *frompat = // exactly like: From ^M (From followed by space and eol). We only // test for this if QUIRKS_TBIRD is set static const char *miniTbirdFrom = "^From $"; - +#ifndef _WIN32 static regex_t fromregex; static regex_t minifromregex; +#define M_regexec(A,B,C,D,E) regexec(&(A),B,C,D,E) +#else +basic_regex fromregex; +basic_regex minifromregex; +#define REG_ICASE std::regex_constants::icase +#define REG_NOSUB std::regex_constants::nosubs +#define REG_EXTENDED std::regex_constants::extended +#define M_regexec(A, B, C, D, E) regex_match(B,A) + +#endif + static bool regcompiled; static PTMutexInit o_regex_mutex; @@ -390,8 +412,13 @@ static void compileregexes() // that we are alone. if (regcompiled) return; +#ifndef _WIN32 regcomp(&fromregex, frompat, REG_NOSUB|REG_EXTENDED); regcomp(&minifromregex, miniTbirdFrom, REG_NOSUB|REG_EXTENDED); +#else + fromregex = basic_regex(frompat, REG_NOSUB | REG_EXTENDED); + minifromregex = basic_regex(miniTbirdFrom, REG_NOSUB | REG_EXTENDED); +#endif regcompiled = true; } @@ -440,9 +467,9 @@ bool MimeHandlerMbox::next_document() (off = o_mcache.get_offset(m_config, m_udi, mtarg)) >= 0 && fseeko(fp, (off_t)off, SEEK_SET) >= 0 && fgets(line, LL, fp) && - (!regexec(&fromregex, line, 0, 0, 0) || + (!M_regexec(fromregex, line, 0, 0, 0) || ((m_quirks & MBOXQUIRK_TBIRD) && - !regexec(&minifromregex, line, 0, 0, 0))) ) { + !M_regexec(minifromregex, line, 0, 0, 0))) ) { LOGDEB0(("MimeHandlerMbox: Cache: From_ Ok\n")); fseeko(fp, (off_t)off, SEEK_SET); m_msgnum = mtarg -1; @@ -485,9 +512,9 @@ bool MimeHandlerMbox::next_document() /* The 'F' compare is redundant but it improves performance A LOT */ if (line[0] == 'F' && ( - !regexec(&fromregex, line, 0, 0, 0) || + !M_regexec(fromregex, line, 0, 0, 0) || ((m_quirks & MBOXQUIRK_TBIRD) && - !regexec(&minifromregex, line, 0, 0, 0))) + !M_regexec(minifromregex, line, 0, 0, 0))) ) { LOGDEB1(("MimeHandlerMbox: msgnum %d, " "From_ at line %d: [%s]\n", m_msgnum, m_lineno, line)); diff --git a/src/internfile/mh_symlink.h b/src/internfile/mh_symlink.h index f144ecf6..dd0c769c 100644 --- a/src/internfile/mh_symlink.h +++ b/src/internfile/mh_symlink.h @@ -18,7 +18,7 @@ #define _MH_SYMLINK_H_INCLUDED_ #include -#include +#include "safeunistd.h" #include #include "cstr.h" diff --git a/src/internfile/mimehandler.cpp b/src/internfile/mimehandler.cpp index 4e72cb52..bb0d09ff 100644 --- a/src/internfile/mimehandler.cpp +++ b/src/internfile/mimehandler.cpp @@ -31,7 +31,6 @@ using namespace std; #include "rclconfig.h" #include "smallut.h" #include "md5ut.h" - #include "mh_exec.h" #include "mh_execm.h" #include "mh_html.h" diff --git a/src/internfile/uncomp.cpp b/src/internfile/uncomp.cpp index 2ce1c1be..61556967 100644 --- a/src/internfile/uncomp.cpp +++ b/src/internfile/uncomp.cpp @@ -108,8 +108,12 @@ bool Uncomp::uncompressfile(const string& ifn, } // Execute command and retrieve output file name, check that it exists +#ifndef _WIN32 ExecCmd ex; int status = ex.doexec(cmd, args, 0, &tfile); +#else + int status = -1; +#endif if (status || tfile.empty()) { LOGERR(("uncompressfile: doexec: failed for [%s] status 0x%x\n", ifn.c_str(), status)); diff --git a/src/rcldb/daterange.cpp b/src/rcldb/daterange.cpp index ab747587..6800a2e4 100644 --- a/src/rcldb/daterange.cpp +++ b/src/rcldb/daterange.cpp @@ -29,7 +29,7 @@ #include using namespace std; -#include "xapian.h" +#include #include "debuglog.h" #include "rclconfig.h" diff --git a/src/rcldb/rcldb.cpp b/src/rcldb/rcldb.cpp index ef92b82a..4905c0a4 100644 --- a/src/rcldb/rcldb.cpp +++ b/src/rcldb/rcldb.cpp @@ -18,7 +18,7 @@ #include #include -#include +#include "safeunistd.h" #include #include @@ -1420,10 +1420,11 @@ bool Db::addOrUpdate(const string &udi, const string &parent_udi, Doc &doc) time_t mtime = atoll(doc.dmtime.empty() ? doc.fmtime.c_str() : doc.dmtime.c_str()); struct tm tmb; - localtime_r(&mtime, &tmb); + struct tm *tmbp = &tmb; + tmbp = localtime_r(&mtime, &tmb); char buf[9]; snprintf(buf, 9, "%04d%02d%02d", - tmb.tm_year+1900, tmb.tm_mon + 1, tmb.tm_mday); + tmbp->tm_year+1900, tmbp->tm_mon + 1, tmbp->tm_mday); // Date (YYYYMMDD) newdocument.add_boolean_term(wrap_prefix(xapday_prefix) + string(buf)); // Month (YYYYMM) diff --git a/src/rcldb/rclterms.cpp b/src/rcldb/rclterms.cpp index ab3f3379..7832abc8 100644 --- a/src/rcldb/rclterms.cpp +++ b/src/rcldb/rclterms.cpp @@ -401,10 +401,14 @@ bool Db::idxTermMatch(int typ_sens, const string &lang, const string &root, // first wildcard character. We only scan the part of the // index where this matches string is; - switch (es) { - case string::npos: is = prefix + root; break; - case 0: is = prefix; break; - default: is = prefix + root.substr(0, es); break; + if (es == string::npos) { + is = prefix + root; + } + else if (es == 0) { + is = prefix; + + } else { + is = prefix + root.substr(0, es); } LOGDEB2(("termMatch: initsec: [%s]\n", is.c_str())); diff --git a/src/rcldb/stemdb.cpp b/src/rcldb/stemdb.cpp index 1a5d40fe..2481c9bf 100644 --- a/src/rcldb/stemdb.cpp +++ b/src/rcldb/stemdb.cpp @@ -22,11 +22,12 @@ #include "autoconfig.h" -#include +#include "safeunistd.h" #include #include #include +#include using namespace std; #include diff --git a/src/utils/circache.cpp b/src/utils/circache.cpp index 5d152b91..445eba1a 100644 --- a/src/utils/circache.cpp +++ b/src/utils/circache.cpp @@ -184,7 +184,7 @@ public: // Offset of last write (newest header) off_t m_nheadoffs; // Pad size for newest entry. - int m_npadsize; + off_t m_npadsize; // Keep history or only last entry bool m_uniquentries; ///////////////////// End header entries @@ -1009,7 +1009,7 @@ bool CirCache::put(const string& udi, const ConfSimple *iconf, // Data compression ? const char *datap = data.c_str(); - unsigned int datalen = data.size(); + size_t datalen = data.size(); unsigned short flags = 0; TempBuf compbuf; if (!(iflags & NoCompHint)) { diff --git a/src/utils/conftree.cpp b/src/utils/conftree.cpp index 97103da7..dcde3a5e 100644 --- a/src/utils/conftree.cpp +++ b/src/utils/conftree.cpp @@ -14,9 +14,7 @@ * Free Software Foundation, Inc., * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif +#include "autoconfig.h" #ifndef TEST_CONFTREE diff --git a/src/utils/copyfile.cpp b/src/utils/copyfile.cpp index 290027dd..4cf69733 100644 --- a/src/utils/copyfile.cpp +++ b/src/utils/copyfile.cpp @@ -15,14 +15,18 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef TEST_COPYFILE +#include "autoconfig.h" + #include #include #include "safefcntl.h" #include #include "safesysstat.h" #include "safeunistd.h" +#ifndef _WIN32 #include #include +#endif #include @@ -43,7 +47,7 @@ bool copyfile(const char *src, const char *dst, string &reason, int flags) LOGDEB(("copyfile: %s to %s\n", src, dst)); - if ((sfd = ::open(src, O_RDONLY)) < 0) { + if ((sfd = ::open(src, O_RDONLY, 0)) < 0) { reason += string("open ") + src + ": " + strerror(errno); goto out; } @@ -149,6 +153,7 @@ bool renameormove(const char *src, const char *dst, string &reason) return false; } +#ifndef _WIN32 // Try to preserve modes, owner, times. This may fail for a number // of reasons if ((st1.st_mode & 0777) != (st.st_mode & 0777)) { @@ -167,7 +172,7 @@ bool renameormove(const char *src, const char *dst, string &reason) times[1].tv_sec = st.st_mtime; times[1].tv_usec = 0; utimes(dst, times); - +#endif // All ok, get rid of origin if (unlink(src) < 0) { reason += string("Can't unlink ") + src + "Error : " + strerror(errno); diff --git a/src/utils/execmd.h b/src/utils/execmd.h index 9b42956a..13e1c5b6 100644 --- a/src/utils/execmd.h +++ b/src/utils/execmd.h @@ -16,7 +16,7 @@ */ #ifndef _EXECMD_H_INCLUDED_ #define _EXECMD_H_INCLUDED_ - +#ifndef _WIN32 #include #include @@ -279,5 +279,5 @@ private: std::string m_reason; std::stack m_atexitfuncs; }; - +#endif /* !_WIN32 */ #endif /* _EXECMD_H_INCLUDED_ */ diff --git a/src/utils/fileudi.cpp b/src/utils/fileudi.cpp index 77799747..bf4b3d7e 100644 --- a/src/utils/fileudi.cpp +++ b/src/utils/fileudi.cpp @@ -15,6 +15,7 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef TEST_FILEUDI +#include "autoconfig.h" #include #include diff --git a/src/utils/fstreewalk.cpp b/src/utils/fstreewalk.cpp index f8853401..6e97c678 100644 --- a/src/utils/fstreewalk.cpp +++ b/src/utils/fstreewalk.cpp @@ -14,9 +14,8 @@ * Free Software Foundation, Inc., * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#ifdef HAVE_CONFIG_H + #include "autoconfig.h" -#endif #ifndef TEST_FSTREEWALK @@ -25,6 +24,7 @@ #include #include #include +#include "safesysstat.h" #include #include diff --git a/src/utils/idfile.cpp b/src/utils/idfile.cpp index 0a148f15..a6ab359e 100644 --- a/src/utils/idfile.cpp +++ b/src/utils/idfile.cpp @@ -15,6 +15,8 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef TEST_IDFILE +#include "autoconfig.h" + #include #include #include @@ -82,11 +84,11 @@ static string idFileInternal(istream& input, const char *fn) } // gcount includes the \n - int ll = input.gcount() - 1; + std::streamsize ll = input.gcount() - 1; if (ll > 0) gotnonempty = true; - LOGDEB2(("idfile: lnum %d ll %d: [%s]\n", lnum, ll, cline)); + LOGDEB2(("idfile: lnum %d ll %u: [%s]\n", lnum, (unsigned int)ll, cline)); // Check for a few things that can't be found in a mail file, // (optimization to get a quick negative) diff --git a/src/utils/pathut.cpp b/src/utils/pathut.cpp index 4b6d1a58..451fcbf5 100644 --- a/src/utils/pathut.cpp +++ b/src/utils/pathut.cpp @@ -19,17 +19,19 @@ #include "autoconfig.h" #include -#include -#include -#include +#include "safefcntl.h" +#include "safeunistd.h" +#include "dirent.h" +#ifndef _WIN32 #include #include +#include +#include +#endif #include #include #include -#include #include "safesysstat.h" -#include // Let's include all files where statfs can be defined and hope for no // conflict... @@ -61,6 +63,9 @@ using namespace std; bool fsocc(const string &path, int *pc, long long *blocks) { +#ifdef _WIN32 + return false; +#else #ifdef sun struct statvfs buf; if (statvfs(path.c_str(), &buf) != 0) { @@ -94,6 +99,7 @@ bool fsocc(const string &path, int *pc, long long *blocks) } } return true; +#endif } const string& tmplocation() @@ -112,6 +118,7 @@ const string& tmplocation() bool maketmpdir(string& tdir, string& reason) { +#ifndef _WIN32 tdir = path_cat(tmplocation(), "rcltmpXXXXXX"); char *cp = strdup(tdir.c_str()); @@ -146,11 +153,15 @@ bool maketmpdir(string& tdir, string& reason) #endif return true; +#else + return false; +#endif } TempFileInternal::TempFileInternal(const string& suffix) : m_noremove(false) { +#ifndef _WIN32 string filename = path_cat(tmplocation(), "rcltmpfXXXXXX"); char *cp = strdup(filename.c_str()); if (!cp) { @@ -177,6 +188,7 @@ TempFileInternal::TempFileInternal(const string& suffix) m_reason = string("Could not open/create") + m_filename; m_filename.erase(); } +#endif } TempFileInternal::~TempFileInternal() @@ -285,6 +297,9 @@ string path_suffix(const string& s) string path_home() { +#ifdef _WIN32 + return "c:\\"; +#else uid_t uid = getuid(); struct passwd *entry = getpwuid(uid); @@ -299,10 +314,14 @@ string path_home() string homedir = entry->pw_dir; path_catslash(homedir); return homedir; +#endif } string path_tildexpand(const string &s) { +#ifdef _WIN32 + return s; +#else if (s.empty() || s[0] != '~') return s; string o = s; @@ -318,6 +337,7 @@ string path_tildexpand(const string &s) o.replace(0, l+1, entry->pw_dir); } return o; +#endif } string path_absolute(const string &is) @@ -402,6 +422,9 @@ bool makepath(const string& ipath) vector path_dirglob(const string &dir, const string pattern) { +#ifdef _WIN32 + return vector(); +#else vector res; glob_t mglob; string mypat=path_cat(dir, pattern); @@ -413,6 +436,7 @@ vector path_dirglob(const string &dir, const string pattern) } globfree(&mglob); return res; +#endif } bool path_isdir(const string& path) @@ -679,6 +703,9 @@ int Pidfile::flopen() m_reason = "fcntl lock failed"; return -1; } +#else +#ifdef _WIN32 + return 0; #else int operation = LOCK_EX | LOCK_NB; if (flock(m_fd, operation) == -1) { @@ -688,6 +715,7 @@ int Pidfile::flopen() m_reason = "flock failed"; return -1; } +#endif // ! win32 #endif // ! sun if (ftruncate(m_fd, 0) != 0) { diff --git a/src/utils/smallut.cpp b/src/utils/smallut.cpp index 8087eeef..d19a2367 100644 --- a/src/utils/smallut.cpp +++ b/src/utils/smallut.cpp @@ -708,10 +708,80 @@ typedef int clockid_t; #undef USE_CLOCK_GETTIME #endif +#ifdef WIN32 +#include "safewindows.h" +// Note: struct timespec is defined by pthread.h (from pthreads-w32) +#ifndef CLOCK_REALTIME +#define CLOCK_REALTIME 0 +#endif + +LARGE_INTEGER getFILETIMEoffset() +{ + SYSTEMTIME s; + FILETIME f; + LARGE_INTEGER t; + + s.wYear = 1970; + s.wMonth = 1; + s.wDay = 1; + s.wHour = 0; + s.wMinute = 0; + s.wSecond = 0; + s.wMilliseconds = 0; + SystemTimeToFileTime(&s, &f); + t.QuadPart = f.dwHighDateTime; + t.QuadPart <<= 32; + t.QuadPart |= f.dwLowDateTime; + return (t); +} + +int clock_gettime(int X, struct timespec *tv) +{ + LARGE_INTEGER t; + FILETIME f; + double microseconds; + static LARGE_INTEGER offset; + static double frequencyToMicroseconds; + static int initialized = 0; + static BOOL usePerformanceCounter = 0; + + if (!initialized) { + LARGE_INTEGER performanceFrequency; + initialized = 1; + usePerformanceCounter = QueryPerformanceFrequency(&performanceFrequency); + if (usePerformanceCounter) { + QueryPerformanceCounter(&offset); + frequencyToMicroseconds = (double)performanceFrequency.QuadPart / 1000000.; + } + else { + offset = getFILETIMEoffset(); + frequencyToMicroseconds = 10.; + } + } + if (usePerformanceCounter) QueryPerformanceCounter(&t); + else { + GetSystemTimeAsFileTime(&f); + t.QuadPart = f.dwHighDateTime; + t.QuadPart <<= 32; + t.QuadPart |= f.dwLowDateTime; + } + + t.QuadPart -= offset.QuadPart; + microseconds = (double)t.QuadPart / frequencyToMicroseconds; + t.QuadPart = (long long)microseconds; + tv->tv_sec = t.QuadPart / 1000000; + tv->tv_nsec = (t.QuadPart % 1000000) * 1000; + return (0); +} +#define USE_CLOCK_GETTIME +#else /* -> !_WIN32 */ + #ifndef USE_CLOCK_GETTIME #include #endif +#endif + static void gettime(clockid_t clk_id, struct timespec *ts) { #ifndef USE_CLOCK_GETTIME @@ -740,29 +810,29 @@ Chrono::Chrono() } // Reset and return value before rest in milliseconds -long Chrono::restart() +time_t Chrono::restart() { struct timespec tv; gettime(CLOCK_REALTIME, &tv); - long ret = MILLIS(tv); + time_t ret = MILLIS(tv); m_secs = tv.tv_sec; m_nsecs = tv.tv_nsec; return ret; } // Get current timer value, milliseconds -long Chrono::millis(int frozen) +time_t Chrono::millis(int frozen) { return nanos() / 1000000; } // -long Chrono::micros(int frozen) +time_t Chrono::micros(int frozen) { return nanos() / 1000; } -long long Chrono::nanos(int frozen) +time_t Chrono::nanos(int frozen) { if (frozen) { return NANOS(frozen_tv); @@ -773,12 +843,12 @@ long long Chrono::nanos(int frozen) } } -float Chrono::secs(int frozen) +double Chrono::secs(int frozen) { struct timespec tv; gettime(CLOCK_REALTIME, &tv); - float secs = (float)(frozen?frozen_tv.tv_sec:tv.tv_sec - m_secs); - float nsecs = (float)(frozen?frozen_tv.tv_nsec:tv.tv_nsec - m_nsecs); + double secs = (double)(frozen?frozen_tv.tv_sec:tv.tv_sec - m_secs); + double nsecs = (double)(frozen?frozen_tv.tv_nsec:tv.tv_nsec - m_nsecs); return secs + nsecs * 1e-9; } @@ -818,7 +888,7 @@ static bool parsedate(vector::const_iterator& it, return false; } if (it == end || sscanf(it++->c_str(), "%d", &dip->d1) != 1) { - return -1; + return false; } return true; @@ -1062,7 +1132,7 @@ void catstrerror(string *reason, const char *what, int _errno) reason->append(" : "); -#ifdef sun +#if defined(sun) || defined(_WIN32) // Note: sun strerror is noted mt-safe ?? reason->append(strerror(_errno)); #else diff --git a/src/utils/smallut.h b/src/utils/smallut.h index 6a5b1193..8cd14f50 100644 --- a/src/utils/smallut.h +++ b/src/utils/smallut.h @@ -153,7 +153,7 @@ class Chrono { public: Chrono(); /** Reset origin */ - long restart(); + time_t restart(); /** Snapshot current time */ static void refnow(); /** Get current elapsed since creation or restart @@ -162,14 +162,14 @@ class Chrono { * allow for using one actual system call to get values from many * chrono objects, like when examining timeouts in a queue) */ - long millis(int frozen = 0); - long ms() {return millis();} - long micros(int frozen = 0); - long long nanos(int frozen = 0); - float secs(int frozen = 0); + time_t millis(int frozen = 0); + time_t ms() {return millis();} + time_t micros(int frozen = 0); + time_t nanos(int frozen = 0); + double secs(int frozen = 0); private: - long m_secs; - long m_nsecs; + time_t m_secs; + time_t m_nsecs; }; /** Temp buffer with automatic deallocation */ diff --git a/src/windows/Win32ProjectRecoll.sln b/src/windows/Win32ProjectRecoll.sln new file mode 100644 index 00000000..fa3c0246 --- /dev/null +++ b/src/windows/Win32ProjectRecoll.sln @@ -0,0 +1,41 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.23107.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Win32ProjectRecoll", "Win32ProjectRecoll.vcxproj", "{23FF40E1-BA87-4E5F-9B22-2EB760FF403D}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "recollindex", "recollindex\recollindex.vcxproj", "{A513D65F-798C-4166-B66E-49F69ADA4F59}" + ProjectSection(ProjectDependencies) = postProject + {23FF40E1-BA87-4E5F-9B22-2EB760FF403D} = {23FF40E1-BA87-4E5F-9B22-2EB760FF403D} + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {23FF40E1-BA87-4E5F-9B22-2EB760FF403D}.Debug|x64.ActiveCfg = Debug|Win32 + {23FF40E1-BA87-4E5F-9B22-2EB760FF403D}.Debug|x64.Build.0 = Debug|Win32 + {23FF40E1-BA87-4E5F-9B22-2EB760FF403D}.Debug|x86.ActiveCfg = Debug|Win32 + {23FF40E1-BA87-4E5F-9B22-2EB760FF403D}.Debug|x86.Build.0 = Debug|Win32 + {23FF40E1-BA87-4E5F-9B22-2EB760FF403D}.Release|x64.ActiveCfg = Release|x64 + {23FF40E1-BA87-4E5F-9B22-2EB760FF403D}.Release|x64.Build.0 = Release|x64 + {23FF40E1-BA87-4E5F-9B22-2EB760FF403D}.Release|x86.ActiveCfg = Release|Win32 + {23FF40E1-BA87-4E5F-9B22-2EB760FF403D}.Release|x86.Build.0 = Release|Win32 + {A513D65F-798C-4166-B66E-49F69ADA4F59}.Debug|x64.ActiveCfg = Debug|Win32 + {A513D65F-798C-4166-B66E-49F69ADA4F59}.Debug|x64.Build.0 = Debug|Win32 + {A513D65F-798C-4166-B66E-49F69ADA4F59}.Debug|x86.ActiveCfg = Debug|Win32 + {A513D65F-798C-4166-B66E-49F69ADA4F59}.Debug|x86.Build.0 = Debug|Win32 + {A513D65F-798C-4166-B66E-49F69ADA4F59}.Release|x64.ActiveCfg = Release|x64 + {A513D65F-798C-4166-B66E-49F69ADA4F59}.Release|x64.Build.0 = Release|x64 + {A513D65F-798C-4166-B66E-49F69ADA4F59}.Release|x86.ActiveCfg = Release|Win32 + {A513D65F-798C-4166-B66E-49F69ADA4F59}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/src/windows/Win32ProjectRecoll.vcxproj b/src/windows/Win32ProjectRecoll.vcxproj new file mode 100644 index 00000000..af25731b --- /dev/null +++ b/src/windows/Win32ProjectRecoll.vcxproj @@ -0,0 +1,216 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + {23FF40E1-BA87-4E5F-9B22-2EB760FF403D} + Win32Proj + Win32ProjectRecoll + 8.1 + + + + StaticLibrary + true + v140 + Unicode + + + StaticLibrary + false + v140 + true + Unicode + + + StaticLibrary + true + v140 + Unicode + + + StaticLibrary + false + v140 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + + NotUsing + Level3 + Disabled + WIN32;__WIN32__;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions) + false + C:\xapian\xapian-core-1.2.8\include;C:\Users\Bill\recoll\src\internfile;C:\Users\Bill\recoll\src\rcldb;C:\Users\Bill\recoll\src\index;C:\Users\Bill\recoll\src\bincimapmime;C:\Users\Bill\recoll\src\unac;C:\Users\Bill\recoll\src\windows;C:\zlib\include;C:\pthreads-w32\Pre-built.2\include;C:\Users\Bill\recoll\src\xaposix;C:\Users\Bill\recoll\src\common;C:\Users\Bill\recoll\src\utils;%(AdditionalIncludeDirectories) + 4800 + + + Windows + true + + + + + NotUsing + Level3 + Disabled + _DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions) + false + C:\xapian\xapian-core-1.2.8\include;C:\Users\Bill\recoll\src\internfile;C:\Users\Bill\recoll\src\rcldb;C:\Users\Bill\recoll\src\index;C:\Users\Bill\recoll\src\bincimapmime;C:\Users\Bill\recoll\src\unac;C:\Users\Bill\recoll\src\windows;C:\zlib\include;C:\pthreads-w32\Pre-built.2\include;C:\Users\Bill\recoll\src\xaposix;C:\Users\Bill\recoll\src\common;C:\Users\Bill\recoll\src\utils;%(AdditionalIncludeDirectories) + 4800 + + + Windows + true + + + + + Level3 + Use + MaxSpeed + true + true + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + true + + + Windows + true + true + true + + + + + Level3 + Use + MaxSpeed + true + true + NDEBUG;_LIB;%(PreprocessorDefinitions) + true + + + Windows + true + true + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/windows/Win32ProjectRecoll.vcxproj.filters b/src/windows/Win32ProjectRecoll.vcxproj.filters new file mode 100644 index 00000000..81155e34 --- /dev/null +++ b/src/windows/Win32ProjectRecoll.vcxproj.filters @@ -0,0 +1,231 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + \ No newline at end of file diff --git a/src/windows/dirent.c b/src/windows/dirent.c new file mode 100644 index 00000000..61685613 --- /dev/null +++ b/src/windows/dirent.c @@ -0,0 +1,148 @@ +/* + + Implementation of POSIX directory browsing functions and types for Win32. + + Author: Kevlin Henney (kevlin@acm.org, kevlin@curbralan.com) + History: Created March 1997. Updated June 2003 and July 2012. + Rights: See end of file. + +*/ + +#include +#include +#include /* _findfirst and _findnext set errno iff they return -1 */ +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +typedef ptrdiff_t handle_type; /* C99's intptr_t not sufficiently portable */ + +struct DIR +{ + handle_type handle; /* -1 for failed rewind */ + struct _finddata_t info; + struct dirent result; /* d_name null iff first time */ + char *name; /* null-terminated char string */ +}; + +DIR *opendir(const char *name) +{ + DIR *dir = 0; + + if(name && name[0]) + { + size_t base_length = strlen(name); + const char *all = /* search pattern must end with suitable wildcard */ + strchr("/\\", name[base_length - 1]) ? "*" : "/*"; + + if((dir = (DIR *) malloc(sizeof *dir)) != 0 && + (dir->name = (char *) malloc(base_length + strlen(all) + 1)) != 0) + { + strcat(strcpy(dir->name, name), all); + + if((dir->handle = + (handle_type) _findfirst(dir->name, &dir->info)) != -1) + { + dir->result.d_name = 0; + } + else /* rollback */ + { + free(dir->name); + free(dir); + dir = 0; + } + } + else /* rollback */ + { + free(dir); + dir = 0; + errno = ENOMEM; + } + } + else + { + errno = EINVAL; + } + + return dir; +} + +int closedir(DIR *dir) +{ + int result = -1; + + if(dir) + { + if(dir->handle != -1) + { + result = _findclose(dir->handle); + } + + free(dir->name); + free(dir); + } + + if(result == -1) /* map all errors to EBADF */ + { + errno = EBADF; + } + + return result; +} + +struct dirent *readdir(DIR *dir) +{ + struct dirent *result = 0; + + if(dir && dir->handle != -1) + { + if(!dir->result.d_name || _findnext(dir->handle, &dir->info) != -1) + { + result = &dir->result; + result->d_name = dir->info.name; + } + } + else + { + errno = EBADF; + } + + return result; +} + +void rewinddir(DIR *dir) +{ + if(dir && dir->handle != -1) + { + _findclose(dir->handle); + dir->handle = (handle_type) _findfirst(dir->name, &dir->info); + dir->result.d_name = 0; + } + else + { + errno = EBADF; + } +} + +#ifdef __cplusplus +} +#endif + +/* + + Copyright Kevlin Henney, 1997, 2003, 2012. All rights reserved. + + Permission to use, copy, modify, and distribute this software and its + documentation for any purpose is hereby granted without fee, provided + that this copyright and permissions notice appear in all copies and + derivatives. + + This software is supplied "as is" without express or implied warranty. + + But that said, if there are any problems please get in touch. + +*/ diff --git a/src/windows/dirent.h b/src/windows/dirent.h new file mode 100644 index 00000000..bbbfce52 --- /dev/null +++ b/src/windows/dirent.h @@ -0,0 +1,50 @@ +#ifndef DIRENT_INCLUDED +#define DIRENT_INCLUDED + +/* + + Declaration of POSIX directory browsing functions and types for Win32. + + Author: Kevlin Henney (kevlin@acm.org, kevlin@curbralan.com) + History: Created March 1997. Updated June 2003. + Rights: See end of file. + +*/ + +#ifdef __cplusplus +extern "C" +{ +#endif + +typedef struct DIR DIR; + +struct dirent +{ + char *d_name; +}; + +DIR *opendir(const char *); +int closedir(DIR *); +struct dirent *readdir(DIR *); +void rewinddir(DIR *); + +/* + + Copyright Kevlin Henney, 1997, 2003. All rights reserved. + + Permission to use, copy, modify, and distribute this software and its + documentation for any purpose is hereby granted without fee, provided + that this copyright and permissions notice appear in all copies and + derivatives. + + This software is supplied "as is" without express or implied warranty. + + But that said, if there are any problems please get in touch. + +*/ + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/windows/fnmatch.c b/src/windows/fnmatch.c new file mode 100644 index 00000000..cf0f1242 --- /dev/null +++ b/src/windows/fnmatch.c @@ -0,0 +1,188 @@ +/* Copyright (C) 1992 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Library General Public License as +published by the Free Software Foundation; either version 2 of the +License, or (at your option) any later version. + +The GNU C Library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Library General Public License for more details. */ + +/* Modified slightly by Brian Berliner and + Jim Blandy for CVS use */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +/* Some file systems are case-insensitive. If FOLD_FN_CHAR is + #defined, it maps the character C onto its "canonical" form. In a + case-insensitive system, it would map all alphanumeric characters + to lower case. Under Windows NT, / and \ are both path component + separators, so FOLD_FN_CHAR would map them both to /. */ +#ifndef FOLD_FN_CHAR +#define FOLD_FN_CHAR(c) (c) +#endif + +/* IGNORE(@ */ +/* #include */ +/* @) */ +#include +#include + +#if !defined(__GNU_LIBRARY__) && !defined(STDC_HEADERS) +extern int errno; +#endif + +/* Match STRING against the filename pattern PATTERN, returning zero if + it matches, nonzero if not. */ +int +#if __STDC__ +fnmatch (const char *pattern, const char *string, int flags) +#else +fnmatch (pattern, string, flags) + char *pattern; + char *string; + int flags; +#endif +{ + register const char *p = pattern, *n = string; + register char c; + + if ((flags & ~__FNM_FLAGS) != 0) + { + errno = EINVAL; + return -1; + } + + while ((c = *p++) != '\0') + { + switch (c) + { + case '?': + if (*n == '\0') + return FNM_NOMATCH; + else if ((flags & FNM_PATHNAME) && *n == '/') + return FNM_NOMATCH; + else if ((flags & FNM_PERIOD) && *n == '.' && + (n == string || ((flags & FNM_PATHNAME) && n[-1] == '/'))) + return FNM_NOMATCH; + break; + + case '\\': + if (!(flags & FNM_NOESCAPE)) + c = *p++; + if (*n != c) + return FNM_NOMATCH; + break; + + case '*': + if ((flags & FNM_PERIOD) && *n == '.' && + (n == string || ((flags & FNM_PATHNAME) && n[-1] == '/'))) + return FNM_NOMATCH; + + for (c = *p++; c == '?' || c == '*'; c = *p++, ++n) + if (((flags & FNM_PATHNAME) && *n == '/') || + (c == '?' && *n == '\0')) + return FNM_NOMATCH; + + if (c == '\0') + return 0; + + { + char c1 = (!(flags & FNM_NOESCAPE) && c == '\\') ? *p : c; + for (--p; *n != '\0'; ++n) + if ((c == '[' || *n == c1) && + fnmatch(p, n, flags & ~FNM_PERIOD) == 0) + return 0; + return FNM_NOMATCH; + } + + case '[': + { + /* Nonzero if the sense of the character class is inverted. */ + register int not; + + if (*n == '\0') + return FNM_NOMATCH; + + if ((flags & FNM_PERIOD) && *n == '.' && + (n == string || ((flags & FNM_PATHNAME) && n[-1] == '/'))) + return FNM_NOMATCH; + + not = (*p == '!' || *p == '^'); + if (not) + ++p; + + c = *p++; + for (;;) + { + register char cstart = c, cend = c; + + if (!(flags & FNM_NOESCAPE) && c == '\\') + cstart = cend = *p++; + + if (c == '\0') + /* [ (unterminated) loses. */ + return FNM_NOMATCH; + + c = *p++; + + if ((flags & FNM_PATHNAME) && c == '/') + /* [/] can never match. */ + return FNM_NOMATCH; + + if (c == '-' && *p != ']') + { + cend = *p++; + if (!(flags & FNM_NOESCAPE) && cend == '\\') + cend = *p++; + if (cend == '\0') + return FNM_NOMATCH; + c = *p++; + } + + if (*n >= cstart && *n <= cend) + goto matched; + + if (c == ']') + break; + } + if (!not) + return FNM_NOMATCH; + break; + + matched:; + /* Skip the rest of the [...] that already matched. */ + while (c != ']') + { + if (c == '\0') + /* [... (unterminated) loses. */ + return FNM_NOMATCH; + + c = *p++; + if (!(flags & FNM_NOESCAPE) && c == '\\') + /* 1003.2d11 is unclear if this is right. %%% */ + ++p; + } + if (not) + return FNM_NOMATCH; + } + break; + + default: + if (FOLD_FN_CHAR (c) != FOLD_FN_CHAR (*n)) + return FNM_NOMATCH; + } + + ++n; + } + + if (*n == '\0') + return 0; + + return FNM_NOMATCH; +} diff --git a/src/windows/fnmatch.h b/src/windows/fnmatch.h new file mode 100644 index 00000000..200c8925 --- /dev/null +++ b/src/windows/fnmatch.h @@ -0,0 +1,38 @@ +/* Copyright (C) 1992 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Library General Public License as +published by the Free Software Foundation; either version 2 of the +License, or (at your option) any later version. + +The GNU C Library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Library General Public License for more details. */ + +#ifndef _FNMATCH_H + +#define _FNMATCH_H 1 + +/* Bits set in the FLAGS argument to `fnmatch'. */ +#undef FNM_PATHNAME +#define FNM_PATHNAME (1 << 0)/* No wildcard can ever match `/'. */ +#undef FNM_NOESCAPE +#define FNM_NOESCAPE (1 << 1)/* Backslashes don't quote special chars. */ +#undef FNM_PERIOD +#define FNM_PERIOD (1 << 2)/* Leading `.' is matched only explicitly. */ +#undef __FNM_FLAGS +#define __FNM_FLAGS (FNM_PATHNAME|FNM_NOESCAPE|FNM_PERIOD) + +/* Value returned by `fnmatch' if STRING does not match PATTERN. */ +#undef FNM_NOMATCH +#define FNM_NOMATCH 1 + +/* Match STRING against the filename pattern PATTERN, + returning zero if it matches, FNM_NOMATCH if not. */ +extern int fnmatch (const char *pattern, const char *string, int flags); + + +#endif /* fnmatch.h */ + diff --git a/src/windows/recollindex/recollindex.vcxproj b/src/windows/recollindex/recollindex.vcxproj new file mode 100644 index 00000000..c3613a8d --- /dev/null +++ b/src/windows/recollindex/recollindex.vcxproj @@ -0,0 +1,156 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + {A513D65F-798C-4166-B66E-49F69ADA4F59} + Win32Proj + recollindex + 8.1 + + + + Application + true + v140 + Unicode + + + Application + false + v140 + true + Unicode + + + Application + true + v140 + Unicode + + + Application + false + v140 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + true + + + false + + + false + + + + + + Level3 + Disabled + __WIN32__;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + C:\pthreads-w32\Pre-built.2\include;C:\Users\Bill\recoll\src\xaposix;C:\Users\Bill\recoll\src\utils;C:\Users\Bill\recoll\src\unac;C:\Users\Bill\recoll\src\rcldb;C:\Users\Bill\recoll\src\internfile;C:\Users\Bill\recoll\src\index;C:\Users\Bill\recoll\src\common;%(AdditionalIncludeDirectories) + + + Console + true + C:\xapian\xapian-core-1.2.8\win32\Debug;C:\Users\Bill\recoll\src\windows\Debug;C:\pthreads-w32\Pre-built.2\lib\x86;%(AdditionalLibraryDirectories) + C:\Users\Bill\recoll\src\windows\Debug\Win32ProjectRecoll.lib;C:\xapian\xapian-core-1.2.8\win32\Debug\xapian-core.lib;C:\zlib\lib\zdll.lib;Ws2_32.lib;Rpcrt4.lib;pthreadVC2.lib;%(AdditionalDependencies) + + + + + + + Level3 + Disabled + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + C:\pthreads-w32\Pre-built.2\include;C:\Users\Bill\recoll\src\xaposix;C:\Users\Bill\recoll\src\utils;C:\Users\Bill\recoll\src\unac;C:\Users\Bill\recoll\src\rcldb;C:\Users\Bill\recoll\src\internfile;C:\Users\Bill\recoll\src\index;C:\Users\Bill\recoll\src\common;%(AdditionalIncludeDirectories) + + + Console + true + C:\xapian\xapian-core-1.2.8\win32\Debug;C:\Users\Bill\recoll\src\windows\x64\Debug;C:\pthreads-w32\Pre-built.2\lib\x64;%(AdditionalLibraryDirectories) + pthreadVC2.lib;Win32ProjectRecoll.lib;xapian-core.lib;%(AdditionalDependencies) + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + + + Console + true + true + true + + + + + Level3 + + + MaxSpeed + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + + + Console + true + true + true + + + + + + + + + \ No newline at end of file diff --git a/src/windows/recollindex/recollindex.vcxproj.filters b/src/windows/recollindex/recollindex.vcxproj.filters new file mode 100644 index 00000000..7888c808 --- /dev/null +++ b/src/windows/recollindex/recollindex.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + \ No newline at end of file diff --git a/src/windows/targetver.h b/src/windows/targetver.h new file mode 100644 index 00000000..90e767bf --- /dev/null +++ b/src/windows/targetver.h @@ -0,0 +1,8 @@ +#pragma once + +// Including SDKDDKVer.h defines the highest available Windows platform. + +// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and +// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. + +#include diff --git a/src/xaposix/config.h b/src/xaposix/config.h new file mode 100644 index 00000000..a9d5b902 --- /dev/null +++ b/src/xaposix/config.h @@ -0,0 +1,249 @@ +/* config.h. Generated from config.h.in by configure. */ +/* config.h.in. Generated from configure.ac by autoheader. */ + +/* Define if ftime returns void */ +/* #undef FTIME_RETURNS_VOID */ + +/* Define to 1 if you have the `closefrom' function. */ +/* #undef HAVE_CLOSEFROM */ + +/* Define to 1 if you have the `dirfd' function. */ +#define HAVE_DIRFD 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_DLFCN_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_FCNTL_H 1 + +/* Define to 1 if you have the `fork' function. */ +#define HAVE_FORK 1 + +/* Define to 1 if you have the `fsync' function. */ +#define HAVE_FSYNC 1 + +/* Define to 1 if you have the `ftime' function. */ +#define HAVE_FTIME 1 + +/* Define to 1 if you have the `gethostname' function. */ +#define HAVE_GETHOSTNAME 1 + +/* Define to 1 if you have the `getrlimit' function. */ +#define HAVE_GETRLIMIT 1 + +/* Define to 1 if you have the `getrusage' function. */ +#define HAVE_GETRUSAGE 1 + +/* Define to 1 if you have the `gettimeofday' function. */ +#define HAVE_GETTIMEOFDAY 1 + +/* Define to 1 if you have the `hstrerror' function. */ +#define HAVE_HSTRERROR 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_INTTYPES_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_LIMITS_H 1 + +/* Define to 1 if you have the `link' function. */ +#define HAVE_LINK 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_MEMORY_H 1 + +/* Define if pread is available on this system */ +#define HAVE_PREAD 1 + +/* Define if pwrite is available on this system */ +#define HAVE_PWRITE 1 + +/* Define to 1 if you have the `setenv' function. */ +#define HAVE_SETENV 1 + +/* Define to 1 if you have the `sigaction' function. */ +#define HAVE_SIGACTION 1 + +/* Define to 1 if you have the `sigsetjmp' function */ +#define HAVE_SIGSETJMP 1 + +/* Define to 1 if you have the 'socketpair' function. */ +#define HAVE_SOCKETPAIR 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDINT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDLIB_H 1 + +/* Define to 1 if you have the `strerror' function. */ +#define HAVE_STRERROR 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRINGS_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRING_H 1 + +/* Define to 1 if you have the `sysconf' function. */ +#define HAVE_SYSCONF 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_ERRNO_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_RESOURCE_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_SELECT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_UTSNAME_H 1 + +/* Define to 1 if you have the `times' function. */ +#define HAVE_TIMES 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_UNISTD_H 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_UUID_H */ + +/* Define to 1 if you have the 'uuid_unparse_lower' function. */ +#define HAVE_UUID_UNPARSE_LOWER 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_UUID_UUID_H 1 + +/* Define if a suitable valgrind is installed */ +#define HAVE_VALGRIND 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_VALGRIND_MEMCHECK_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_ZLIB_H 1 + +/* Define to the sub-directory in which libtool stores uninstalled libraries. + */ +#define LT_OBJDIR ".libs/" + +/* Name of package */ +#define PACKAGE "xapian-core" + +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT "http://xapian.org/bugs" + +/* Define to the full name of this package. */ +#define PACKAGE_NAME "xapian-core" + +/* Define to the full name and version of this package. */ +#define PACKAGE_STRING "xapian-core 1.2.14" + +/* Define to the one symbol short name of this package. */ +#define PACKAGE_TARNAME "xapian-core" + +/* Define to the home page for this package. */ +#define PACKAGE_URL "" + +/* Define to the version of this package. */ +#define PACKAGE_VERSION "1.2.14" + +/* explicit prototype needed for pread (if any) */ +/* #undef PREAD_PROTOTYPE */ + +/* explicit prototype needed for pwrite (if any) */ +/* #undef PWRITE_PROTOTYPE */ + +/* The size of `int', as computed by sizeof. */ +#define SIZEOF_INT 4 + +/* The size of `long', as computed by sizeof. */ +#define SIZEOF_LONG 8 + +/* Define to the name of a function implementing snprintf but not caring about + ISO C99 return value semantics (if one exists) */ +#define SNPRINTF snprintf + +/* Define to the name of a function implementing snprintf with ISO C99 + semantics (if one exists) */ +#define SNPRINTF_ISO snprintf + +/* type to use for 5th parameter to getsockopt */ +#define SOCKLEN_T socklen_t + +/* Define to 1 if you have the ANSI C header files. */ +#define STDC_HEADERS 1 + +/* Define if the testsuite should use RTTI */ +#define USE_RTTI 1 + +/* Version number of package */ +#define VERSION "1.2.14" + +/* Define if you want assertions (causes some slow-down) */ +/* #undef XAPIAN_ASSERTIONS */ + +/* Define if you want paranoid assertions (causes significant slow-down) */ +/* #undef XAPIAN_ASSERTIONS_PARANOID */ + +/* Define if you want a log of methods called and other debug messages */ +/* #undef XAPIAN_DEBUG_LOG */ + +/* Number of bits in a file offset, on hosts where this is settable. */ +/* #undef _FILE_OFFSET_BITS */ + +/* Define for large files, on AIX-style hosts. */ +/* #undef _LARGE_FILES */ + +/* Define on mingw to the minimum msvcrt version to assume */ +/* #undef __MSVCRT_VERSION__ */ + +/* Define to `int' if does not define. */ +/* #undef mode_t */ + +/* Define to `int' if does not define. */ +/* #undef pid_t */ + +/* Define to `int' if does not define. */ +/* #undef ssize_t */ + +/* Disable stupid MSVC "performance" warning for converting int to bool. */ +#ifdef _MSC_VER +# pragma warning(disable:4800) +#endif + +/* _FORTIFY_SOURCE is only supported by GCC >= 4.1 and glibc >= 2.3.4, but it + * shouldn't cause a problem to define it where it's not supported and some + * distros may have backported support, so hardcoding version checks is + * counter-productive. + * + * Check if _FORTIFY_SOURCE is already defined to allow the user to override + * our choice with "./configure CPPFLAGS=-D_FORTIFY_SOURCE=0" or "...=1". + */ +#if defined __GNUC__ && !defined _FORTIFY_SOURCE +# define _FORTIFY_SOURCE 2 +#endif + +/* For GCC >= 3.0 (and Intel's C++ compiler, which also defines __GNUC__), + * we can use __builtin_expect to give the compiler hints about branch + * prediction. See HACKING for how to use these. + */ +#if defined __GNUC__ +/* The arguments of __builtin_expect() are both long, so use !! to ensure that + * the first argument is always an integer expression, and always 0 or 1, but + * still has the same truth value for the if or while it is used in. + */ +# define rare(COND) __builtin_expect(!!(COND), 0) +# define usual(COND) __builtin_expect(!!(COND), 1) +#else +# define rare(COND) (COND) +# define usual(COND) (COND) +#endif + diff --git a/src/xaposix/realtime.h b/src/xaposix/realtime.h new file mode 100644 index 00000000..d2186d04 --- /dev/null +++ b/src/xaposix/realtime.h @@ -0,0 +1,107 @@ +/** @file realtime.h + * @brief Functions for handling a time or time interval in a double. + */ +/* Copyright (C) 2010,2013 Olly Betts + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef XAPIAN_INCLUDED_REALTIME_H +#define XAPIAN_INCLUDED_REALTIME_H + +#include +#include +#include "safeerrno.h" +#include "safeunistd.h" + +#ifndef __WIN32__ +# ifdef HAVE_FTIME +# include +# endif +# ifdef HAVE_GETTIMEOFDAY +# include +# endif +#else +# include +# include +extern void xapian_sleep_milliseconds(unsigned int millisecs); +#endif + +namespace RealTime { + +/// Return the current time. +inline double now() { +#ifndef __WIN32__ + // POSIX.1-2008 stopped specifying ftime(), so prefer gettimeofday(). +# ifdef HAVE_GETTIMEOFDAY + struct timeval tv; + if (usual(gettimeofday(&tv, NULL) == 0)) + return tv.tv_sec + (tv.tv_usec * 1e-6); + return double(std::time(NULL)); +# elif defined HAVE_FTIME + struct timeb tp; +# ifdef FTIME_RETURNS_VOID + ftime(&tp); +# else + if (rare(ftime(&tp) != 0)) + return double(std::time(NULL)); +# endif + return tp.time + (tp.millitm * 1e-3); +# else + return double(std::time(NULL)); +# endif +#else + struct __timeb64 tp; + _ftime64(&tp); + return tp.time + tp.millitm * 1e-3; +#endif +} + +/** Return the end time for a timeout in @a timeout seconds. + * + * If @a timeout is 0, that means "no timeout", so 0 is returned. Otherwise + * the current time plus @a timeout seconds is returned. + */ +inline double end_time(double timeout) { + return (timeout == 0.0 ? timeout : timeout + now()); +} + +/// Sleep until the time represented by this object. +inline void sleep(double t) { +#ifndef __WIN32__ + double delta; + struct timeval tv; + do { + delta = t - RealTime::now(); + if (delta <= 0.0) + return; + tv.tv_sec = long(delta); + tv.tv_usec = long(std::fmod(delta, 1.0) * 1e6); + } while (select(0, NULL, NULL, NULL, &tv) < 0 && errno == EINTR); +#else + double delta = t - RealTime::now(); + if (delta <= 0.0) + return; + while (rare(delta > 4294967.0)) { + xapian_sleep_milliseconds(4294967000u); + delta -= 4294967.0; + } + xapian_sleep_milliseconds(unsigned(delta * 1000.0)); +#endif +} + +} + +#endif // XAPIAN_INCLUDED_REALTIME_H diff --git a/src/xaposix/safe.cc b/src/xaposix/safe.cc new file mode 100644 index 00000000..33ffc2f8 --- /dev/null +++ b/src/xaposix/safe.cc @@ -0,0 +1,31 @@ +/** @file safe.cc + * @brief Helper functions for safe*.h + */ +/* Copyright (C) 2007 Olly Betts + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +#include "safewindows.h" + +// Used by safeunistd.h: +void +xapian_sleep_milliseconds(unsigned int millisecs) +{ + Sleep(millisecs); +} + + diff --git a/src/xaposix/safeerrno.h b/src/xaposix/safeerrno.h new file mode 100644 index 00000000..6ce0fdc9 --- /dev/null +++ b/src/xaposix/safeerrno.h @@ -0,0 +1,36 @@ +/* safeerrno.h: #include , but working around broken platforms. + * + * Copyright (C) 2006,2007 Olly Betts + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 + * USA + */ + +#ifndef XAPIAN_INCLUDED_SAFEERRNO_H +#define XAPIAN_INCLUDED_SAFEERRNO_H + +//#ifndef PACKAGE +//# error You must #include before #include "safeerrno.h" +//#endif + +// Compaq's C++ compiler requires sys/errno.h to be included, followed by +// errno.h, otherwise you don't get EINTR or most of the other EXXX codes +// defined. +#if defined __DECCXX && defined HAVE_SYS_ERRNO_H +# include +#endif +#include + +#endif // XAPIAN_INCLUDED_SAFEERRNO_H diff --git a/src/xaposix/safefcntl.h b/src/xaposix/safefcntl.h index 6248351e..e8e591f8 100644 --- a/src/xaposix/safefcntl.h +++ b/src/xaposix/safefcntl.h @@ -34,7 +34,9 @@ #ifdef _MSC_VER // MSVC #define-s open but also defines a function called open, so just undef // the macro. -# undef open +// Jf/recoll: don't do this, open() seems to be finally deprecated in vs 2015, we need _open(). Hopefully recoll has +// no open() methods.. +//# undef open #else inline int fcntl_open_(const char *filename, int flags, mode_t mode) { diff --git a/src/xaposix/safewindows.h b/src/xaposix/safewindows.h new file mode 100644 index 00000000..745190e9 --- /dev/null +++ b/src/xaposix/safewindows.h @@ -0,0 +1,45 @@ +/* safewindows.h: #include without all the bloat and damage. + * + * Copyright (C) 2005,2007 Olly Betts + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA + */ + +#ifndef XAPIAN_INCLUDED_SAFEWINDOWS_H +#define XAPIAN_INCLUDED_SAFEWINDOWS_H + +#if !defined __CYGWIN__ && !defined __WIN32__ +# error Including safewindows.h, but neither __CYGWIN__ nor __WIN32__ defined! +#endif + +// Prevent windows.h from defining min and max macros. +#ifndef NOMINMAX +# define NOMINMAX +#endif + +// Prevent windows.h from including lots of obscure win32 api headers +// which we don't care about and will just slow down compilation and +// increase the risk of symbol collisions. +#define WIN32_LEAN_AND_MEAN +#define NOGDI +#include + +// FOF_NOERRORUI isn't defined by older versions of the mingw headers. +#ifndef FOF_NOERRORUI +# define FOF_NOERRORUI 1024 +#endif + +#endif // XAPIAN_INCLUDED_SAFEWINDOWS_H