logging now uses c++ streams

This commit is contained in:
Jean-Francois Dockes
2016-07-12 09:41:04 +02:00
parent 7c4223088b
commit f6a999de84
123 changed files with 1974 additions and 2760 deletions
+6 -6
View File
@@ -20,7 +20,7 @@
#include "cstr.h"
#include "beaglequeuecache.h"
#include "circache.h"
#include "debuglog.h"
#include "log.h"
#include "rclconfig.h"
#include "pathut.h"
#include "rcldoc.h"
@@ -34,12 +34,11 @@ BeagleQueueCache::BeagleQueueCache(RclConfig *cnf)
int maxmbs = 40;
cnf->getConfParam("webcachemaxmbs", &maxmbs);
if ((m_cache = new CirCache(ccdir)) == 0) {
LOGERR(("BeagleQueueCache: cant create CirCache object\n"));
LOGERR("BeagleQueueCache: cant create CirCache object\n" );
return;
}
if (!m_cache->create(off_t(maxmbs)*1000*1024, CirCache::CC_CRUNIQUE)) {
LOGERR(("BeagleQueueCache: cache file creation failed: %s\n",
m_cache->getReason().c_str()));
LOGERR("BeagleQueueCache: cache file creation failed: " << (m_cache->getReason()) << "\n" );
delete m_cache;
m_cache = 0;
return;
@@ -59,11 +58,11 @@ bool BeagleQueueCache::getFromCache(const string& udi, Rcl::Doc &dotdoc,
string dict;
if (m_cache == 0) {
LOGERR(("BeagleQueueCache::getFromCache: cache is null\n"));
LOGERR("BeagleQueueCache::getFromCache: cache is null\n" );
return false;
}
if (!m_cache->get(udi, dict, &data)) {
LOGDEB(("BeagleQueueCache::getFromCache: get failed\n"));
LOGDEB("BeagleQueueCache::getFromCache: get failed\n" );
return false;
}
@@ -86,3 +85,4 @@ bool BeagleQueueCache::getFromCache(const string& udi, Rcl::Doc &dotdoc,
dotdoc.meta[Rcl::Doc::keyudi] = udi;
return true;
}
+6 -8
View File
@@ -29,7 +29,6 @@
#ifdef _WIN32
#include "safewindows.h"
#undef RCL_ICONV_INBUF_CONST
#ifdef _MSC_VER
// gmtime is supposedly thread-safe on windows
@@ -47,15 +46,15 @@ typedef int mode_t;
#else // End _MSC_VER -> Gminw
#define timegm portable_timegm
#undef RCL_ICONV_INBUF_CONST
#define timegm portable_timegm
#endif // GMinw only
typedef int pid_t;
inline int readlink(const char *cp, void *buf, int cnt) {
return -1;
inline int readlink(const char *cp, void *buf, int cnt)
{
return -1;
}
#define MAXPATHLEN PATH_MAX
@@ -72,9 +71,8 @@ typedef int ssize_t;
#ifndef X_OK
#define X_OK 4
#endif
#define RECOLL_DATADIR "C:\\recoll\\"
#define S_ISLNK(X) false
#define lstat stat
#endif
#endif // _WIN32
+40 -56
View File
@@ -42,7 +42,7 @@
#include "rclutil.h"
#include "rclconfig.h"
#include "conftree.h"
#include "debuglog.h"
#include "log.h"
#include "smallut.h"
#include "textsplit.h"
#include "readfile.h"
@@ -67,10 +67,9 @@ string RclConfig::o_origcwd;
bool ParamStale::needrecompute()
{
LOGDEB2(("ParamStale:: needrecompute. parent gen %d mine %d\n",
parent->m_keydirgen, savedkeydirgen));
LOGDEB2("ParamStale:: needrecompute. parent gen " << (parent->m_keydirgen) << " mine " << (savedkeydirgen) << "\n" );
if (active && parent->m_keydirgen != savedkeydirgen) {
LOGDEB2(("ParamState:: needrecompute. conffile %p\n", conffile));
LOGDEB2("ParamState:: needrecompute. conffile " << (conffile) << "\n" );
savedkeydirgen = parent->m_keydirgen;
string newvalue;
@@ -79,8 +78,7 @@ bool ParamStale::needrecompute()
conffile->get(paramname, newvalue, parent->m_keydir);
if (newvalue.compare(savedvalue)) {
savedvalue = newvalue;
LOGDEB2(("ParamState:: needrecompute. return true newvalue [%s]\n",
newvalue.c_str()));
LOGDEB2("ParamState:: needrecompute. return true newvalue [" << (newvalue) << "]\n" );
return true;
}
}
@@ -216,8 +214,7 @@ RclConfig::RclConfig(const string *argcnf)
// interface, Windows will never use utf-8
o_localecharset = "UTF-8";
#endif
LOGDEB1(("RclConfig::getDefCharset: localecharset [%s]\n",
o_localecharset.c_str()));
LOGDEB1("RclConfig::getDefCharset: localecharset [" << (o_localecharset) << "]\n" );
}
const char *cp;
@@ -425,8 +422,7 @@ bool RclConfig::getConfParam(const string &name, vector<int> *vip,
char *ep;
vip->push_back(strtol(vs[i].c_str(), &ep, 0));
if (ep == vs[i].c_str()) {
LOGDEB(("RclConfig::getConfParam: bad int value in [%s]\n",
name.c_str()));
LOGDEB("RclConfig::getConfParam: bad int value in [" << (name) << "]\n" );
return false;
}
}
@@ -442,16 +438,16 @@ void RclConfig::initThrConf()
vector<int> vq;
vector<int> vt;
if (!getConfParam("thrQSizes", &vq)) {
LOGINFO(("RclConfig::initThrConf: no thread info (queues)\n"));
LOGINFO("RclConfig::initThrConf: no thread info (queues)\n" );
goto out;
}
// If the first queue size is 0, autoconf is requested.
if (vq.size() > 0 && vq[0] == 0) {
LOGDEB(("RclConfig::initThrConf: autoconf requested\n"));
LOGDEB("RclConfig::initThrConf: autoconf requested\n" );
CpuConf cpus;
if (!getCpuConf(cpus) || cpus.ncpus < 1) {
LOGERR(("RclConfig::initThrConf: could not retrieve cpu conf\n"));
LOGERR("RclConfig::initThrConf: could not retrieve cpu conf\n" );
cpus.ncpus = 1;
}
// Arbitrarily set threads config based on number of CPUS. This also
@@ -477,12 +473,12 @@ void RclConfig::initThrConf()
}
if (!getConfParam("thrTCounts", &vt) ) {
LOGINFO(("RclConfig::initThrConf: no thread info (threads)\n"));
LOGINFO("RclConfig::initThrConf: no thread info (threads)\n" );
goto out;
}
if (vq.size() != 3 || vt.size() != 3) {
LOGINFO(("RclConfig::initThrConf: bad thread info vector sizes\n"));
LOGINFO("RclConfig::initThrConf: bad thread info vector sizes\n" );
goto out;
}
@@ -499,14 +495,13 @@ out:
") ";
}
LOGDEB(("RclConfig::initThrConf: chosen config (ql,nt): %s\n",
sconf.str().c_str()));
LOGDEB("RclConfig::initThrConf: chosen config (ql,nt): " << (sconf.str()) << "\n" );
}
pair<int,int> RclConfig::getThrConf(ThrStage who) const
{
if (m_thrConf.size() != 3) {
LOGERR(("RclConfig::getThrConf: bad data in rclconfig\n"));
LOGERR("RclConfig::getThrConf: bad data in rclconfig\n" );
return pair<int,int>(-1,-1);
}
return m_thrConf[who];
@@ -516,8 +511,7 @@ vector<string> RclConfig::getTopdirs() const
{
vector<string> tdl;
if (!getConfParam("topdirs", &tdl)) {
LOGERR(("RclConfig::getTopdirs: no top directories in config or "
"bad list format\n"));
LOGERR("RclConfig::getTopdirs: no top directories in config or bad list format\n" );
return tdl;
}
@@ -601,7 +595,7 @@ typedef multiset<SfString, SuffCmp> SuffixStore;
bool RclConfig::inStopSuffixes(const string& fni)
{
LOGDEB2(("RclConfig::inStopSuffixes(%s)\n", fni.c_str()));
LOGDEB2("RclConfig::inStopSuffixes(" << (fni) << ")\n" );
// Beware: both needrecompute() need to be called always hence the
// bizarre way we do things
bool needrecompute = m_stpsuffstate.needrecompute();
@@ -610,7 +604,7 @@ bool RclConfig::inStopSuffixes(const string& fni)
// Need to initialize the suffixes
delete STOPSUFFIXES;
if ((m_stopsuffixes = new SuffixStore) == 0) {
LOGERR(("RclConfig::inStopSuffixes: out of memory\n"));
LOGERR("RclConfig::inStopSuffixes: out of memory\n" );
return false;
}
// Let the old customisation have priority: if recoll_noindex
@@ -637,11 +631,10 @@ bool RclConfig::inStopSuffixes(const string& fni)
stringtolower(fn);
SuffixStore::const_iterator it = STOPSUFFIXES->find(fn);
if (it != STOPSUFFIXES->end()) {
LOGDEB2(("RclConfig::inStopSuffixes: Found (%s) [%s]\n",
fni.c_str(), (*it).m_str.c_str()));
LOGDEB2("RclConfig::inStopSuffixes: Found (" << (fni) << ") [" << ((*it).m_str) << "]\n" );
return true;
} else {
LOGDEB2(("RclConfig::inStopSuffixes: not found [%s]\n", fni.c_str()));
LOGDEB2("RclConfig::inStopSuffixes: not found [" << (fni) << "]\n" );
return false;
}
}
@@ -718,18 +711,18 @@ string RclConfig::getMimeHandlerDef(const string &mtype, bool filtertypes)
}
if (!m_restrictMTypes.empty() &&
!m_restrictMTypes.count(stringtolower(mtype))) {
LOGDEB2(("RclConfig::getMimeHandlerDef: not in mime type list\n"));
LOGDEB2("RclConfig::getMimeHandlerDef: not in mime type list\n" );
return hs;
}
if (!m_excludeMTypes.empty() &&
m_excludeMTypes.count(stringtolower(mtype))) {
LOGDEB2(("RclConfig::getMimeHandlerDef: in excluded mime list\n"));
LOGDEB2("RclConfig::getMimeHandlerDef: in excluded mime list\n" );
return hs;
}
}
if (!mimeconf->get(mtype, hs, "index")) {
LOGDEB1(("getMimeHandler: no handler for '%s'\n", mtype.c_str()));
LOGDEB1("getMimeHandler: no handler for '" << (mtype) << "'\n" );
}
return hs;
}
@@ -820,7 +813,7 @@ void RclConfig::storeMissingHelperDesc(const string &s)
FILE *fp = fopen(fmiss.c_str(), "w");
if (fp) {
if (s.size() > 0 && fwrite(s.c_str(), s.size(), 1, fp) != 1) {
LOGERR(("storeMissingHelperDesc: fwrite failed\n"));
LOGERR("storeMissingHelperDesc: fwrite failed\n" );
}
fclose(fp);
}
@@ -830,7 +823,7 @@ void RclConfig::storeMissingHelperDesc(const string &s)
// things for speed (theses are used a lot during indexing)
bool RclConfig::readFieldsConfig(const string& cnferrloc)
{
LOGDEB2(("RclConfig::readFieldsConfig\n"));
LOGDEB2("RclConfig::readFieldsConfig\n" );
m_fields = new ConfStack<ConfSimple>("fields", m_cdirs, true);
if (m_fields == 0 || !m_fields->ok()) {
m_reason = string("No/bad fields file in: ") + cnferrloc;
@@ -848,8 +841,7 @@ bool RclConfig::readFieldsConfig(const string& cnferrloc)
ConfSimple attrs;
FieldTraits ft;
if (!valueSplitAttributes(val, ft.pfx, attrs)) {
LOGERR(("readFieldsConfig: bad config line for [%s]: [%s]\n",
it->c_str(), val.c_str()));
LOGERR("readFieldsConfig: bad config line for [" << *it << "]: [" << (val) << "]\n" );
return 0;
}
string tval;
@@ -862,8 +854,7 @@ bool RclConfig::readFieldsConfig(const string& cnferrloc)
if (attrs.get("noterms", tval))
ft.noterms = stringToBool(tval);
m_fldtotraits[stringtolower(*it)] = ft;
LOGDEB2(("readFieldsConfig: [%s] -> [%s] %d %.1f\n",
it->c_str(), ft.pfx.c_str(), ft.wdfinc, ft.boost));
LOGDEB2("readFieldsConfig: [" << *it << "] -> [" << (ft.pfx) << "] " << (ft.wdfinc) << " " << (ft.boost) << "\n" );
}
// Add prefixes for aliases and build alias-to-canonic map while
@@ -909,9 +900,7 @@ bool RclConfig::readFieldsConfig(const string& cnferrloc)
#if 0
for (map<string, FieldTraits>::const_iterator it = m_fldtotraits.begin();
it != m_fldtotraits.end(); it++) {
LOGDEB(("readFieldsConfig: [%s] -> [%s] %d %.1f\n",
it->c_str(), it->second.pfx.c_str(), it->second.wdfinc,
it->second.boost));
LOGDEB("readFieldsConfig: [" << *it << "] -> [" << (it->second.pfx) << "] " << (it->second.wdfinc) << " " << (it->second.boost) << "\n" );
}
#endif
@@ -944,12 +933,10 @@ bool RclConfig::getFieldTraits(const string& _fld, const FieldTraits **ftpp,
map<string, FieldTraits>::const_iterator pit = m_fldtotraits.find(fld);
if (pit != m_fldtotraits.end()) {
*ftpp = &pit->second;
LOGDEB1(("RclConfig::getFieldTraits: [%s]->[%s]\n",
_fld.c_str(), pit->second.pfx.c_str()));
LOGDEB1("RclConfig::getFieldTraits: [" << (_fld) << "]->[" << (pit->second.pfx) << "]\n" );
return true;
} else {
LOGDEB1(("RclConfig::getFieldTraits: no prefix for field [%s]\n",
fld.c_str()));
LOGDEB1("RclConfig::getFieldTraits: no prefix for field [" << (fld) << "]\n" );
*ftpp = 0;
return false;
}
@@ -971,11 +958,10 @@ string RclConfig::fieldCanon(const string& f) const
string fld = stringtolower(f);
map<string, string>::const_iterator it = m_aliastocanon.find(fld);
if (it != m_aliastocanon.end()) {
LOGDEB1(("RclConfig::fieldCanon: [%s] -> [%s]\n",
f.c_str(), it->second.c_str()));
LOGDEB1("RclConfig::fieldCanon: [" << (f) << "] -> [" << (it->second) << "]\n" );
return it->second;
}
LOGDEB1(("RclConfig::fieldCanon: [%s] -> [%s]\n", f.c_str(), fld.c_str()));
LOGDEB1("RclConfig::fieldCanon: [" << (f) << "] -> [" << (fld) << "]\n" );
return fld;
}
@@ -984,8 +970,7 @@ string RclConfig::fieldQCanon(const string& f) const
string fld = stringtolower(f);
map<string, string>::const_iterator it = m_aliastoqcanon.find(fld);
if (it != m_aliastoqcanon.end()) {
LOGDEB1(("RclConfig::fieldQCanon: [%s] -> [%s]\n",
f.c_str(), it->second.c_str()));
LOGDEB1("RclConfig::fieldQCanon: [" << (f) << "] -> [" << (it->second) << "]\n" );
return it->second;
}
return fieldCanon(f);
@@ -1031,8 +1016,7 @@ bool RclConfig::setMimeViewerAllEx(const string& allex)
string RclConfig::getMimeViewerDef(const string &mtype, const string& apptag,
bool useall) const
{
LOGDEB2(("RclConfig::getMimeViewerDef: mtype [%s] apptag [%s]\n",
mtype.c_str(), apptag.c_str()));
LOGDEB2("RclConfig::getMimeViewerDef: mtype [" << (mtype) << "] apptag [" << (apptag) << "]\n" );
string hs;
if (mimeview == 0)
return hs;
@@ -1216,19 +1200,17 @@ string RclConfig::getPidfile() const
void RclConfig::urlrewrite(const string& dbdir, string& url) const
{
LOGDEB2(("RclConfig::urlrewrite: dbdir [%s] url [%s]\n",
dbdir.c_str(), url.c_str()));
LOGDEB2("RclConfig::urlrewrite: dbdir [" << (dbdir) << "] url [" << (url) << "]\n" );
// Do path translations exist for this index ?
if (m_ptrans == 0 || !m_ptrans->hasSubKey(dbdir)) {
LOGDEB2(("RclConfig::urlrewrite: no paths translations (m_ptrans %p)\n",
m_ptrans));
LOGDEB2("RclConfig::urlrewrite: no paths translations (m_ptrans " << (m_ptrans) << ")\n" );
return;
}
string path = fileurltolocalpath(url);
if (path.empty()) {
LOGDEB2(("RclConfig::urlrewrite: not file url\n"));
LOGDEB2("RclConfig::urlrewrite: not file url\n" );
return;
}
@@ -1387,7 +1369,7 @@ bool RclConfig::getUncompressor(const string &mtype, vector<string>& cmd) const
vector<string> tokens;
stringToStrings(hs, tokens);
if (tokens.empty()) {
LOGERR(("getUncompressor: empty spec for mtype %s\n", mtype.c_str()));
LOGERR("getUncompressor: empty spec for mtype " << (mtype) << "\n" );
return false;
}
vector<string>::iterator it = tokens.begin();
@@ -1405,7 +1387,7 @@ bool RclConfig::getUncompressor(const string &mtype, vector<string>& cmd) const
if (!stringlowercmp("python", *it) || !stringlowercmp("perl", *it)) {
it++;
if (tokens.size() < 3) {
LOGERR(("getUncpressor: python/perl cmd: no script?. [%s]\n", mtype.c_str()));
LOGERR("getUncpressor: python/perl cmd: no script?. [" << (mtype) << "]\n" );
} else {
*it = findFilter(*it);
}
@@ -1552,7 +1534,8 @@ void RclConfig::initParamStale(ConfNull *cnf, ConfNull *mimemap)
using namespace std;
#include "debuglog.h"
#include "log.h"
#include "rclinit.h"
#include "rclconfig.h"
#include "cstr.h"
@@ -1727,3 +1710,4 @@ int main(int argc, char **argv)
}
#endif // TEST_RCLCONFIG
+1 -1
View File
@@ -315,7 +315,7 @@ class RclConfig {
string findFilter(const string& cmd) const;
/** Thread config init is not done automatically because not all
programs need it and it uses debuglog so that it's better to
programs need it and it uses the debug log so that it's better to
call it after primary init */
void initThrConf();
+7 -10
View File
@@ -28,7 +28,7 @@
#include <string.h>
#endif
#include "debuglog.h"
#include "log.h"
#include "rclconfig.h"
#include "rclinit.h"
#include "pathut.h"
@@ -60,7 +60,7 @@ static pthread_t mainthread_id;
static void siglogreopen(int)
{
if (recoll_ismainthread())
DebugLog::reopen();
Logger::getTheLog("")->reopen("");
}
// We would like to block SIGCHLD globally, but we can't because
@@ -258,10 +258,7 @@ RclConfig *recollinit(RclInitFlags flags,
// to utf8 for indexing.
setlocale(LC_CTYPE, "");
DebugLog::getdbl()->setloglevel(DEBDEB1);
DebugLog::setfilename("stderr");
if (getenv("RECOLL_LOGDATE"))
DebugLog::getdbl()->logdate(1);
Logger::getTheLog("")->setLogLevel(Logger::LLDEB1);
initAsyncSigs(sigcleanup);
@@ -297,15 +294,15 @@ RclConfig *recollinit(RclInitFlags flags,
if (!logfilename.empty()) {
logfilename = path_tildexpand(logfilename);
// If not an absolute path or , compute relative to config dir
if (!path_isabsolute(logfilename) &&
!DebugLog::DebugLog::isspecialname(logfilename.c_str())) {
if (!path_isabsolute(logfilename) &&
logfilename.compare("stderr")) {
logfilename = path_cat(config->getConfDir(), logfilename);
}
DebugLog::setfilename(logfilename.c_str());
Logger::getTheLog("")->reopen(logfilename);
}
if (!loglevel.empty()) {
int lev = atoi(loglevel.c_str());
DebugLog::getdbl()->setloglevel(lev);
Logger::getTheLog("")->setLogLevel(Logger::LogLevel(lev));
}
// Make sure the locale charset is initialized (so that multiple
+13 -17
View File
@@ -19,7 +19,7 @@
#include "syngroups.h"
#include "debuglog.h"
#include "log.h"
#include "smallut.h"
#include <errno.h>
@@ -68,11 +68,11 @@ SynGroups::SynGroups()
bool SynGroups::setfile(const string& fn)
{
LOGDEB(("SynGroups::setfile(%s)\n", fn.c_str()));
LOGDEB("SynGroups::setfile(" << (fn) << ")\n" );
if (!m) {
m = new Internal;
if (!m) {
LOGERR(("SynGroups:setfile:: new Internal failed: no mem ?\n"));
LOGERR("SynGroups:setfile:: new Internal failed: no mem ?\n" );
return false;
}
}
@@ -86,8 +86,7 @@ bool SynGroups::setfile(const string& fn)
ifstream input;
input.open(fn.c_str(), ios::in);
if (!input.is_open()) {
LOGERR(("SynGroups:setfile:: could not open %s errno %d\n",
fn.c_str(), errno));
LOGERR("SynGroups:setfile:: could not open " << (fn) << " errno " << (errno) << "\n" );
return false;
}
@@ -102,8 +101,7 @@ bool SynGroups::setfile(const string& fn)
getline(input, cline);
if (!input.good()) {
if (input.bad()) {
LOGERR(("Syngroup::setfile(%s):Parse: input.bad()\n",
fn.c_str()));
LOGERR("Syngroup::setfile(" << (fn) << "):Parse: input.bad()\n" );
return false;
}
// Must be eof ? But maybe we have a partial line which
@@ -144,16 +142,14 @@ bool SynGroups::setfile(const string& fn)
vector<string> words;
if (!stringToStrings(line, words)) {
LOGERR(("SynGroups:setfile: %s: bad line %d: %s\n",
fn.c_str(), lnum, line.c_str()));
LOGERR("SynGroups:setfile: " << (fn) << ": bad line " << (lnum) << ": " << (line) << "\n" );
continue;
}
if (words.empty())
continue;
if (words.size() == 1) {
LOGERR(("Syngroup::setfile(%s):single term group at line %d ??\n",
fn.c_str(), lnum));
LOGERR("Syngroup::setfile(" << (fn) << "):single term group at line " << (lnum) << " ??\n" );
continue;
}
@@ -162,8 +158,7 @@ bool SynGroups::setfile(const string& fn)
it != words.end(); it++) {
m->terms[*it] = m->groups.size()-1;
}
LOGDEB1(("SynGroups::setfile: group: [%s]\n",
stringsToString(m->groups.back()).c_str()));
LOGDEB1("SynGroups::setfile: group: [" << (stringsToString(m->groups.back())) << "]\n" );
}
m->ok = true;
return true;
@@ -178,14 +173,13 @@ vector<string> SynGroups::getgroup(const string& term)
STD_UNORDERED_MAP<string, unsigned int>::const_iterator it1 =
m->terms.find(term);
if (it1 == m->terms.end()) {
LOGDEB1(("SynGroups::getgroup: [%s] not found in direct map\n",
term.c_str()));
LOGDEB1("SynGroups::getgroup: [" << (term) << "] not found in direct map\n" );
return ret;
}
unsigned int idx = it1->second;
if (idx >= m->groups.size()) {
LOGERR(("SynGroups::getgroup: line index higher than line count !\n"));
LOGERR("SynGroups::getgroup: line index higher than line count !\n" );
return ret;
}
return m->groups[idx];
@@ -194,7 +188,8 @@ vector<string> SynGroups::getgroup(const string& term)
#else
#include "syngroups.h"
#include "debuglog.h"
#include "log.h"
#include <string>
#include <iostream>
@@ -252,3 +247,4 @@ int main(int argc, char **argv)
}
#endif
+18 -22
View File
@@ -27,7 +27,7 @@
#include UNORDERED_SET_INCLUDE
#include "textsplit.h"
#include "debuglog.h"
#include "log.h"
//#define UTF8ITER_CHECK
#include "utf8iter.h"
#include "uproplist.h"
@@ -221,7 +221,7 @@ bool TextSplit::o_deHyphenate = false;
inline bool TextSplit::emitterm(bool isspan, string &w, int pos,
size_t btstart, size_t btend)
{
LOGDEB2(("TextSplit::emitterm: [%s] pos %d\n", w.c_str(), pos));
LOGDEB2("TextSplit::emitterm: [" << (w) << "] pos " << (pos) << "\n" );
int l = int(w.length());
@@ -252,7 +252,7 @@ inline bool TextSplit::emitterm(bool isspan, string &w, int pos,
m_prevlen = int(w.length());
return ret;
}
LOGDEB2(("TextSplit::emitterm:dup: [%s] pos %d\n", w.c_str(), pos));
LOGDEB2("TextSplit::emitterm:dup: [" << (w) << "] pos " << (pos) << "\n" );
}
return true;
}
@@ -369,10 +369,7 @@ bool TextSplit::words_from_span(size_t bp)
inline bool TextSplit::doemit(bool spanerase, size_t _bp)
{
int bp = int(_bp);
LOGDEB2(("TextSplit::doemit: sper %d bp %d spp %d spanwords %u wS %d wL %d "
"inn %d span [%s]\n",
spanerase, bp, m_spanpos, m_words_in_span.size(),
m_wordStart, m_wordLen, m_inNumber, m_span.c_str()));
LOGDEB2("TextSplit::doemit: sper " << (spanerase) << " bp " << (bp) << " spp " << (m_spanpos) << " spanwords " << (m_words_in_span.size()) << " wS " << (m_wordStart) << " wL " << (m_wordLen) << " inn " << (m_inNumber) << " span [" << (m_span) << "]\n" );
if (m_wordLen) {
// We have a current word. Remember it
@@ -468,12 +465,12 @@ static inline bool isdigit(int what, unsigned int flgs)
*/
bool TextSplit::text_to_words(const string &in)
{
LOGDEB1(("TextSplit::text_to_words: docjk %d (%d) %s%s%s [%s]\n",
o_processCJK, o_CJKNgramLen,
m_flags & TXTS_NOSPANS ? " nospans" : "",
m_flags & TXTS_ONLYSPANS ? " onlyspans" : "",
m_flags & TXTS_KEEPWILD ? " keepwild" : "",
in.substr(0,50).c_str()));
LOGDEB1("TextSplit::text_to_words: docjk " << o_processCJK << "(" <<
o_CJKNgramLen << ")" <<
(m_flags & TXTS_NOSPANS ? " nospans" : "") <<
(m_flags & TXTS_ONLYSPANS ? " onlyspans" : "") <<
(m_flags & TXTS_KEEPWILD ? " keepwild" : "") <<
"[" << in.substr(0,50) << "]\n");
if (in.empty())
return true;
@@ -495,7 +492,7 @@ bool TextSplit::text_to_words(const string &in)
nonalnumcnt++;
if (c == (unsigned int)-1) {
LOGERR(("Textsplit: error occured while scanning UTF-8 string\n"));
LOGERR("Textsplit: error occured while scanning UTF-8 string\n" );
return false;
}
@@ -509,7 +506,7 @@ bool TextSplit::text_to_words(const string &in)
// Hand off situation to the cjk routine.
if (!cjk_to_words(&it, &c)) {
LOGERR(("Textsplit: scan error in cjk handler\n"));
LOGERR("Textsplit: scan error in cjk handler\n" );
return false;
}
@@ -805,7 +802,7 @@ bool TextSplit::text_to_words(const string &in)
// be better off converting the whole buffer to utf32 on entry...
bool TextSplit::cjk_to_words(Utf8Iter *itp, unsigned int *cp)
{
LOGDEB1(("cjk_to_words: m_wordpos %d\n", m_wordpos));
LOGDEB1("cjk_to_words: m_wordpos " << (m_wordpos) << "\n" );
Utf8Iter &it = *itp;
// We use an offset buffer to remember the starts of the utf-8
@@ -908,9 +905,8 @@ bool TextSplit::hasVisibleWhite(const string &in)
Utf8Iter it(in);
for (; !it.eof(); it++) {
unsigned int c = (unsigned char)*it;
LOGDEB3(("TextSplit::hasVisibleWhite: testing 0x%04x\n", c));
if (c == (unsigned int)-1) {
LOGERR(("hasVisibleWhite: error while scanning UTF-8 string\n"));
LOGERR("hasVisibleWhite: error while scanning UTF-8 string\n" );
return false;
}
if (visiblewhite.find(c) != visiblewhite.end())
@@ -931,10 +927,8 @@ template <class T> bool u8stringToStrings(const string &s, T &tokens)
unsigned int c = *it;
if (visiblewhite.find(c) != visiblewhite.end())
c = ' ';
LOGDEB3(("TextSplit::stringToStrings: 0x%04x\n", c));
if (c == (unsigned int)-1) {
LOGERR(("TextSplit::stringToStrings: error while "
"scanning UTF-8 string\n"));
LOGERR("TextSplit::stringToStrings: error while scanning UTF-8 string\n" );
return false;
}
@@ -1011,7 +1005,8 @@ bool TextSplit::stringToStrings(const string &s, vector<string> &tokens)
#include "textsplit.h"
#include "readfile.h"
#include "debuglog.h"
#include "log.h"
#include "transcode.h"
#include "unacpp.h"
#include "termproc.h"
@@ -1244,3 +1239,4 @@ int main(int argc, char **argv)
}
}
#endif // TEST
+8 -7
View File
@@ -24,7 +24,7 @@
#include "unacpp.h"
#include "unac.h"
#include "debuglog.h"
#include "log.h"
#include "utf8iter.h"
bool unacmaybefold(const string &in, string &out,
@@ -68,7 +68,7 @@ bool unacmaybefold(const string &in, string &out,
// testing user-entered terms, so we don't really care.
bool unaciscapital(const string& in)
{
LOGDEB2(("unaciscapital: [%s]\n", in.c_str()));
LOGDEB2("unaciscapital: [" << (in) << "]\n" );
if (in.empty())
return false;
Utf8Iter it(in);
@@ -77,7 +77,7 @@ bool unaciscapital(const string& in)
string lower;
if (!unacmaybefold(shorter, lower, "UTF-8", UNACOP_FOLD)) {
LOGINFO(("unaciscapital: unac/fold failed for [%s]\n", in.c_str()));
LOGINFO("unaciscapital: unac/fold failed for [" << (in) << "]\n" );
return false;
}
Utf8Iter it1(lower);
@@ -88,13 +88,13 @@ bool unaciscapital(const string& in)
}
bool unachasuppercase(const string& in)
{
LOGDEB2(("unachasuppercase: [%s]\n", in.c_str()));
LOGDEB2("unachasuppercase: [" << (in) << "]\n" );
if (in.empty())
return false;
string lower;
if (!unacmaybefold(in, lower, "UTF-8", UNACOP_FOLD)) {
LOGINFO(("unachasuppercase: unac/fold failed for [%s]\n", in.c_str()));
LOGINFO("unachasuppercase: unac/fold failed for [" << (in) << "]\n" );
return false;
}
if (lower != in)
@@ -104,13 +104,13 @@ bool unachasuppercase(const string& in)
}
bool unachasaccents(const string& in)
{
LOGDEB2(("unachasaccents: [%s]\n", in.c_str()));
LOGDEB2("unachasaccents: [" << (in) << "]\n" );
if (in.empty())
return false;
string noac;
if (!unacmaybefold(in, noac, "UTF-8", UNACOP_UNAC)) {
LOGINFO(("unachasaccents: unac/unac failed for [%s]\n", in.c_str()));
LOGINFO("unachasaccents: unac/unac failed for [" << (in) << "]\n" );
return false;
}
if (noac != in)
@@ -247,3 +247,4 @@ int main(int argc, char **argv)
}
#endif