cleared out errant tabs

This commit is contained in:
Jean-Francois Dockes
2020-05-30 15:54:49 +02:00
parent 796db76fc6
commit 560041cab9
167 changed files with 18868 additions and 18868 deletions
+27 -27
View File
@@ -30,11 +30,11 @@ int DocSequence::getSeqSlice(int offs, int cnt, vector<ResListEntry>& result)
{
int ret = 0;
for (int num = offs; num < offs + cnt; num++, ret++) {
result.push_back(ResListEntry());
if (!getDoc(num, result.back().doc, &result.back().subHeader)) {
result.pop_back();
return ret;
}
result.push_back(ResListEntry());
if (!getDoc(num, result.back().doc, &result.back().subHeader)) {
result.pop_back();
return ret;
}
}
return ret;
}
@@ -43,8 +43,8 @@ bool DocSequence::getEnclosing(Rcl::Doc& doc, Rcl::Doc& pdoc)
{
std::shared_ptr<Rcl::Db> db = getDb();
if (!db) {
LOGERR("DocSequence::getEnclosing: no db\n" );
return false;
LOGERR("DocSequence::getEnclosing: no db\n" );
return false;
}
std::unique_lock<std::mutex> locker(o_dblock);
string udi;
@@ -59,9 +59,9 @@ bool DocSequence::getEnclosing(Rcl::Doc& doc, Rcl::Doc& pdoc)
void DocSource::stripStack()
{
if (!m_seq)
return;
return;
while (m_seq->getSourceSeq()) {
m_seq = m_seq->getSourceSeq();
m_seq = m_seq->getSourceSeq();
}
}
@@ -71,29 +71,29 @@ bool DocSource::buildStack()
stripStack();
if (!m_seq)
return false;
return false;
// Filtering must be done before sorting, (which may
// truncates the original list)
if (m_seq->canFilter()) {
if (!m_seq->setFiltSpec(m_fspec)) {
LOGERR("DocSource::buildStack: setfiltspec failed\n" );
}
if (!m_seq->setFiltSpec(m_fspec)) {
LOGERR("DocSource::buildStack: setfiltspec failed\n" );
}
} else {
if (m_fspec.isNotNull()) {
m_seq =
std::shared_ptr<DocSequence>(new DocSeqFiltered(m_config, m_seq, m_fspec));
}
if (m_fspec.isNotNull()) {
m_seq =
std::shared_ptr<DocSequence>(new DocSeqFiltered(m_config, m_seq, m_fspec));
}
}
if (m_seq->canSort()) {
if (!m_seq->setSortSpec(m_sspec)) {
LOGERR("DocSource::buildStack: setsortspec failed\n" );
}
if (!m_seq->setSortSpec(m_sspec)) {
LOGERR("DocSource::buildStack: setsortspec failed\n" );
}
} else {
if (m_sspec.isNotNull()) {
m_seq = std::shared_ptr<DocSequence>(new DocSeqSorted(m_seq, m_sspec));
}
if (m_sspec.isNotNull()) {
m_seq = std::shared_ptr<DocSequence>(new DocSeqSorted(m_seq, m_sspec));
}
}
return true;
}
@@ -101,14 +101,14 @@ bool DocSource::buildStack()
string DocSource::title()
{
if (!m_seq)
return string();
return string();
string qual;
if (m_fspec.isNotNull() && !m_sspec.isNotNull())
qual = string(" (") + o_filt_trans + string(")");
qual = string(" (") + o_filt_trans + string(")");
else if (!m_fspec.isNotNull() && m_sspec.isNotNull())
qual = string(" (") + o_sort_trans + string(")");
qual = string(" (") + o_sort_trans + string(")");
else if (m_fspec.isNotNull() && m_sspec.isNotNull())
qual = string(" (") + o_sort_trans + string(",") + o_filt_trans + string(")");
qual = string(" (") + o_sort_trans + string(",") + o_filt_trans + string(")");
return m_seq->title() + qual;
}
+2 -2
View File
@@ -28,7 +28,7 @@ class DocSequenceDb : public DocSequence {
public:
DocSequenceDb(std::shared_ptr<Rcl::Db> db,
std::shared_ptr<Rcl::Query> q, const std::string &t,
std::shared_ptr<Rcl::SearchData> sdata);
std::shared_ptr<Rcl::SearchData> sdata);
virtual ~DocSequenceDb() {}
virtual bool getDoc(int num, Rcl::Doc &doc, std::string * = 0) override;
virtual int getResCnt() override;
@@ -55,7 +55,7 @@ class DocSequenceDb : public DocSequence {
}
virtual bool snippetsCapable() override {
return true;
return true;
}
virtual std::string title() override;
+11 -11
View File
@@ -31,30 +31,30 @@ class DocSequenceDocs : public DocSequence {
public:
DocSequenceDocs(std::shared_ptr<Rcl::Db> d,
const std::vector<Rcl::Doc> docs, const string &t)
: DocSequence(t), m_db(d), m_docs(docs) {
: DocSequence(t), m_db(d), m_docs(docs) {
}
virtual ~DocSequenceDocs() {
}
virtual bool getDoc(int num, Rcl::Doc &doc, string *sh = 0) {
if (sh)
*sh = string();
if (num < 0 || num >= int(m_docs.size()))
return false;
doc = m_docs[num];
return true;
if (sh)
*sh = string();
if (num < 0 || num >= int(m_docs.size()))
return false;
doc = m_docs[num];
return true;
}
virtual int getResCnt() {
return m_docs.size();
return m_docs.size();
}
virtual string getDescription() {
return m_description;
return m_description;
}
void setDescription(const string& desc) {
m_description = desc;
m_description = desc;
}
protected:
virtual std::shared_ptr<Rcl::Db> getDb() {
return m_db;
return m_db;
}
private:
std::shared_ptr<Rcl::Db> m_db;
+14 -14
View File
@@ -125,31 +125,31 @@ bool DocSequenceHistory::getDoc(int num, Rcl::Doc &doc, string *sh)
{
// Retrieve history list
if (!m_hist)
return false;
return false;
if (m_history.empty())
m_history = getDocHistory(m_hist);
m_history = getDocHistory(m_hist);
if (num < 0 || num >= (int)m_history.size())
return false;
return false;
// We get the history oldest first, but our users expect newest first
RclDHistoryEntry& hentry = m_history[m_history.size() - 1 - num];
if (sh) {
if (m_prevtime < 0 || abs(m_prevtime - hentry.unixtime) > 86400) {
m_prevtime = hentry.unixtime;
time_t t = (time_t)(hentry.unixtime);
*sh = string(ctime(&t));
// Get rid of the final \n in ctime
sh->erase(sh->length()-1);
} else {
sh->erase();
if (m_prevtime < 0 || abs(m_prevtime - hentry.unixtime) > 86400) {
m_prevtime = hentry.unixtime;
time_t t = (time_t)(hentry.unixtime);
*sh = string(ctime(&t));
// Get rid of the final \n in ctime
sh->erase(sh->length()-1);
} else {
sh->erase();
}
}
bool ret = m_db->getDoc(hentry.udi, hentry.dbdir, doc);
if (!ret || doc.pc == -1) {
doc.url = "UNKNOWN";
doc.url = "UNKNOWN";
doc.ipath = "";
}
@@ -161,9 +161,9 @@ bool DocSequenceHistory::getDoc(int num, Rcl::Doc &doc, string *sh)
}
int DocSequenceHistory::getResCnt()
{
{
if (m_history.empty())
m_history = getDocHistory(m_hist);
m_history = getDocHistory(m_hist);
return int(m_history.size());
}
+2 -2
View File
@@ -33,7 +33,7 @@ class RclDHistoryEntry : public DynConfEntry {
public:
RclDHistoryEntry() : unixtime(0) {}
RclDHistoryEntry(time_t t, const std::string& u, const std::string& d)
: unixtime(t), udi(u), dbdir(d) {}
: unixtime(t), udi(u), dbdir(d) {}
virtual ~RclDHistoryEntry() {}
virtual bool decode(const std::string &value);
virtual bool encode(std::string& value);
@@ -50,7 +50,7 @@ class DocSequenceHistory : public DocSequence {
public:
DocSequenceHistory(std::shared_ptr<Rcl::Db> db, RclDynConf *h,
const std::string &t)
: DocSequence(t), m_db(db), m_hist(h) {}
: DocSequence(t), m_db(db), m_hist(h) {}
virtual ~DocSequenceHistory() {}
virtual bool getDoc(int num, Rcl::Doc &doc, std::string *sh = 0);
+57 -57
View File
@@ -47,7 +47,7 @@ RclDynConf::RclDynConf(const std::string &fn)
}
bool RclDynConf::insertNew(const string &sk, DynConfEntry &n, DynConfEntry &s,
int maxlen)
int maxlen)
{
if (!rw()) {
LOGDEB("RclDynConf::insertNew: not writable\n");
@@ -58,38 +58,38 @@ bool RclDynConf::insertNew(const string &sk, DynConfEntry &n, DynConfEntry &s,
vector<string>::const_iterator it;
bool changed = false;
for (it = names.begin(); it != names.end(); it++) {
string oval;
if (!m_data.get(*it, oval, sk)) {
LOGDEB("No data for " << *it << "\n");
continue;
}
s.decode(oval);
string oval;
if (!m_data.get(*it, oval, sk)) {
LOGDEB("No data for " << *it << "\n");
continue;
}
s.decode(oval);
if (s.equal(n)) {
LOGDEB("Erasing old entry\n");
m_data.erase(*it, sk);
changed = true;
}
if (s.equal(n)) {
LOGDEB("Erasing old entry\n");
m_data.erase(*it, sk);
changed = true;
}
}
// Maybe reget things
if (changed)
names = m_data.getNames(sk);
names = m_data.getNames(sk);
// Need to prune ?
if (maxlen > 0 && names.size() >= (unsigned int)maxlen) {
// Need to erase entries until we're back to size. Note that
// we don't ever reset numbers. Problems will arise when
// history is 4 billion entries old
it = names.begin();
for (unsigned int i = 0; i < names.size() - maxlen + 1; i++, it++) {
m_data.erase(*it, sk);
}
// Need to erase entries until we're back to size. Note that
// we don't ever reset numbers. Problems will arise when
// history is 4 billion entries old
it = names.begin();
for (unsigned int i = 0; i < names.size() - maxlen + 1; i++, it++) {
m_data.erase(*it, sk);
}
}
// Increment highest number
unsigned int hi = names.empty() ? 0 :
(unsigned int)atoi(names.back().c_str());
(unsigned int)atoi(names.back().c_str());
hi++;
char nname[20];
sprintf(nname, "%010u", hi);
@@ -98,8 +98,8 @@ bool RclDynConf::insertNew(const string &sk, DynConfEntry &n, DynConfEntry &s,
n.encode(value);
LOGDEB1("Encoded value [" << value << "] (" << value.size() << ")\n");
if (!m_data.set(string(nname), value, sk)) {
LOGERR("RclDynConf::insertNew: set failed\n");
return false;
LOGERR("RclDynConf::insertNew: set failed\n");
return false;
}
return true;
}
@@ -111,7 +111,7 @@ bool RclDynConf::eraseAll(const string &sk)
return false;
}
for (const auto& nm : m_data.getNames(sk)) {
m_data.erase(nm, sk);
m_data.erase(nm, sk);
}
return true;
}
@@ -173,25 +173,25 @@ int main(int argc, char **argv)
argc--; argv++;
while (argc > 0 && **argv == '-') {
(*argv)++;
if (!(**argv))
/* Cas du "adb - core" */
Usage();
while (**argv)
switch (*(*argv)++) {
case 'a': op_flags |= OPT_a; if (argc < 2) Usage();
value = *(++argv); argc--;
goto b1;
case 's': op_flags |= OPT_s; if (argc < 2) Usage();
sk = *(++argv); argc--;
goto b1;
case 'e': op_flags |= OPT_e; break;
default: Usage(); break;
}
(*argv)++;
if (!(**argv))
/* Cas du "adb - core" */
Usage();
while (**argv)
switch (*(*argv)++) {
case 'a': op_flags |= OPT_a; if (argc < 2) Usage();
value = *(++argv); argc--;
goto b1;
case 's': op_flags |= OPT_s; if (argc < 2) Usage();
sk = *(++argv); argc--;
goto b1;
case 'e': op_flags |= OPT_e; break;
default: Usage(); break;
}
b1: argc--; argv++;
}
if (argc != 1)
Usage();
Usage();
string filename = *argv++;argc--;
RclDynConf hist(filename, 5);
@@ -199,26 +199,26 @@ int main(int argc, char **argv)
DebugLog::setfilename("stderr");
if (op_flags & OPT_e) {
hist.eraseAll(sk);
hist.eraseAll(sk);
} else if (op_flags & OPT_a) {
if (!(op_flags & OPT_s))
Usage();
hist.enterString(sk, value);
if (!(op_flags & OPT_s))
Usage();
hist.enterString(sk, value);
} else {
for (int i = 0; i < 10; i++) {
char docname[200];
sprintf(docname, "A very long document document name"
"is very long indeed and this is the end of "
"it here and exactly here:\n%d", i);
hist.enterDoc(string(docname), "ipathx");
}
for (int i = 0; i < 10; i++) {
char docname[200];
sprintf(docname, "A very long document document name"
"is very long indeed and this is the end of "
"it here and exactly here:\n%d", i);
hist.enterDoc(string(docname), "ipathx");
}
list<RclDHistoryEntry> hlist = hist.getDocHistory();
for (list<RclDHistoryEntry>::const_iterator it = hlist.begin();
it != hlist.end(); it++) {
printf("[%ld] [%s] [%s]\n", it->unixtime,
it->fn.c_str(), it->ipath.c_str());
}
list<RclDHistoryEntry> hlist = hist.getDocHistory();
for (list<RclDHistoryEntry>::const_iterator it = hlist.begin();
it != hlist.end(); it++) {
printf("[%ld] [%s] [%s]\n", it->unixtime,
it->fn.c_str(), it->ipath.c_str());
}
}
}
+17 -17
View File
@@ -67,16 +67,16 @@ class RclSListEntry : public DynConfEntry {
: value(v) {
}
virtual bool decode(const std::string &enc) {
base64_decode(enc, value);
return true;
base64_decode(enc, value);
return true;
}
virtual bool encode(std::string& enc) {
base64_encode(value, enc);
return true;
base64_encode(value, enc);
return true;
}
virtual bool equal(const DynConfEntry& other) {
const RclSListEntry& e = dynamic_cast<const RclSListEntry&>(other);
return e.value == value;
const RclSListEntry& e = dynamic_cast<const RclSListEntry&>(other);
return e.value == value;
}
std::string value;
@@ -88,16 +88,16 @@ class RclDynConf {
RclDynConf(const std::string &fn);
bool ro() {
return m_data.getStatus() == ConfSimple::STATUS_RO;
return m_data.getStatus() == ConfSimple::STATUS_RO;
}
bool rw() {
return m_data.getStatus() == ConfSimple::STATUS_RW;
return m_data.getStatus() == ConfSimple::STATUS_RW;
}
bool ok() {
return m_data.getStatus() != ConfSimple::STATUS_ERROR;
return m_data.getStatus() != ConfSimple::STATUS_ERROR;
}
std::string getFilename() {
return m_data.getFilename();
return m_data.getFilename();
}
// Generic methods
@@ -140,12 +140,12 @@ Container<Type, std::allocator<Type>>
Type entry;
std::vector<std::string> names = m_data.getNames(sk);
for (const auto& name : names) {
std::string value;
if (m_data.get(name, value, sk)) {
if (!entry.decode(value))
continue;
out.push_back(entry);
}
std::string value;
if (m_data.get(name, value, sk)) {
if (!entry.decode(value))
continue;
out.push_back(entry);
}
}
return out;
}
@@ -157,7 +157,7 @@ Container<std::string, std::allocator<std::string>>
std::vector<RclSListEntry> el = getEntries<std::vector, RclSListEntry>(sk);
Container<std::string, std::allocator<std::string>> sl;
for (const auto& entry : el) {
sl.push_back(entry.value);
sl.push_back(entry.value);
}
return sl;
}
+60 -60
View File
@@ -28,27 +28,27 @@ static bool filter(const DocSeqFiltSpec& fs, const Rcl::Doc *x)
// Compare using each criterion in term. We're doing an or:
// 1st ok ends
for (unsigned int i = 0; i < fs.crits.size(); i++) {
switch (fs.crits[i]) {
case DocSeqFiltSpec::DSFS_MIMETYPE:
LOGDEB2(" filter: MIMETYPE: me [" << (fs.values[i]) << "] doc [" << (x->mimetype) << "]\n" );
if (x->mimetype == fs.values[i])
return true;
break;
case DocSeqFiltSpec::DSFS_QLANG:
{
LOGDEB(" filter: QLANG [" << (fs.values[i]) << "]!!\n" );
}
break;
case DocSeqFiltSpec::DSFS_PASSALL:
return true;
}
switch (fs.crits[i]) {
case DocSeqFiltSpec::DSFS_MIMETYPE:
LOGDEB2(" filter: MIMETYPE: me [" << (fs.values[i]) << "] doc [" << (x->mimetype) << "]\n" );
if (x->mimetype == fs.values[i])
return true;
break;
case DocSeqFiltSpec::DSFS_QLANG:
{
LOGDEB(" filter: QLANG [" << (fs.values[i]) << "]!!\n" );
}
break;
case DocSeqFiltSpec::DSFS_PASSALL:
return true;
}
}
// Did all comparisons
return false;
}
DocSeqFiltered::DocSeqFiltered(RclConfig *conf, std::shared_ptr<DocSequence> iseq,
DocSeqFiltSpec &filtspec)
DocSeqFiltSpec &filtspec)
: DocSeqModifier(iseq), m_config(conf)
{
setFiltSpec(filtspec);
@@ -58,35 +58,35 @@ bool DocSeqFiltered::setFiltSpec(const DocSeqFiltSpec &filtspec)
{
LOGDEB0("DocSeqFiltered::setFiltSpec\n" );
for (unsigned int i = 0; i < filtspec.crits.size(); i++) {
switch (filtspec.crits[i]) {
case DocSeqFiltSpec::DSFS_MIMETYPE:
m_spec.orCrit(filtspec.crits[i], filtspec.values[i]);
break;
case DocSeqFiltSpec::DSFS_QLANG:
{
// There are very few lang constructs that we can
// interpret. The default config uses rclcat:value
// only. That will be all for now...
string val = filtspec.values[i];
if (val.find("rclcat:") == 0) {
string catg = val.substr(7);
vector<string> tps;
m_config->getMimeCatTypes(catg, tps);
for (vector<string>::const_iterator it = tps.begin();
it != tps.end(); it++) {
LOGDEB2("Adding mime: [" << (it) << "]\n" );
m_spec.orCrit(DocSeqFiltSpec::DSFS_MIMETYPE, *it);
}
}
}
break;
default:
break;
}
switch (filtspec.crits[i]) {
case DocSeqFiltSpec::DSFS_MIMETYPE:
m_spec.orCrit(filtspec.crits[i], filtspec.values[i]);
break;
case DocSeqFiltSpec::DSFS_QLANG:
{
// There are very few lang constructs that we can
// interpret. The default config uses rclcat:value
// only. That will be all for now...
string val = filtspec.values[i];
if (val.find("rclcat:") == 0) {
string catg = val.substr(7);
vector<string> tps;
m_config->getMimeCatTypes(catg, tps);
for (vector<string>::const_iterator it = tps.begin();
it != tps.end(); it++) {
LOGDEB2("Adding mime: [" << (it) << "]\n" );
m_spec.orCrit(DocSeqFiltSpec::DSFS_MIMETYPE, *it);
}
}
}
break;
default:
break;
}
}
// If m_spec ends up empty, pass everything, better than filtering all.
if (m_spec.crits.empty()) {
m_spec.orCrit(DocSeqFiltSpec::DSFS_PASSALL, "");
m_spec.orCrit(DocSeqFiltSpec::DSFS_PASSALL, "");
}
m_dbindices.clear();
return true;
@@ -97,28 +97,28 @@ bool DocSeqFiltered::getDoc(int idx, Rcl::Doc &doc, string *)
LOGDEB2("DocSeqFiltered::getDoc() fetching " << (idx) << "\n" );
if (idx >= (int)m_dbindices.size()) {
// Have to fetch docs and filter until we get enough or
// fail
m_dbindices.reserve(idx+1);
// Have to fetch docs and filter until we get enough or
// fail
m_dbindices.reserve(idx+1);
// First backend seq doc we fetch is the one after last stored
int backend_idx = m_dbindices.size() > 0 ? m_dbindices.back() + 1 : 0;
// First backend seq doc we fetch is the one after last stored
int backend_idx = m_dbindices.size() > 0 ? m_dbindices.back() + 1 : 0;
// Loop until we get enough docs
Rcl::Doc tdoc;
while (idx >= (int)m_dbindices.size()) {
if (!m_seq->getDoc(backend_idx, tdoc))
return false;
if (filter(m_spec, &tdoc)) {
m_dbindices.push_back(backend_idx);
}
backend_idx++;
}
doc = tdoc;
// Loop until we get enough docs
Rcl::Doc tdoc;
while (idx >= (int)m_dbindices.size()) {
if (!m_seq->getDoc(backend_idx, tdoc))
return false;
if (filter(m_spec, &tdoc)) {
m_dbindices.push_back(backend_idx);
}
backend_idx++;
}
doc = tdoc;
} else {
// The corresponding backend indice is already known
if (!m_seq->getDoc(m_dbindices[idx], doc))
return false;
// The corresponding backend indice is already known
if (!m_seq->getDoc(m_dbindices[idx], doc))
return false;
}
return true;
}
+1 -1
View File
@@ -33,7 +33,7 @@ class RclConfig;
class DocSeqFiltered : public DocSeqModifier {
public:
DocSeqFiltered(RclConfig *conf, std::shared_ptr<DocSequence> iseq,
DocSeqFiltSpec &filtspec);
DocSeqFiltSpec &filtspec);
virtual ~DocSeqFiltered() {}
virtual bool canFilter() {return true;}
virtual bool setFiltSpec(const DocSeqFiltSpec &filtspec);
+13 -13
View File
@@ -33,13 +33,13 @@ public:
// behaves as operator<
int operator()(const Rcl::Doc *x, const Rcl::Doc *y)
{
LOGDEB1("Comparing .. \n" );
LOGDEB1("Comparing .. \n" );
const auto xit = x->meta.find(ss.field);
const auto yit = y->meta.find(ss.field);
if (xit == x->meta.end() || yit == y->meta.end())
return 0;
return ss.desc ? yit->second < xit->second : xit->second < yit->second;
const auto xit = x->meta.find(ss.field);
const auto yit = y->meta.find(ss.field);
if (xit == x->meta.end() || yit == y->meta.end())
return 0;
return ss.desc ? yit->second < xit->second : xit->second < yit->second;
}
};
@@ -52,16 +52,16 @@ bool DocSeqSorted::setSortSpec(const DocSeqSortSpec &sortspec)
m_docs.resize(count);
int i;
for (i = 0; i < count; i++) {
if (!m_seq->getDoc(i, m_docs[i])) {
LOGERR("DocSeqSorted: getDoc failed for doc " << (i) << "\n" );
count = i;
break;
}
if (!m_seq->getDoc(i, m_docs[i])) {
LOGERR("DocSeqSorted: getDoc failed for doc " << (i) << "\n" );
count = i;
break;
}
}
m_docs.resize(count);
m_docsp.resize(count);
for (i = 0; i < count; i++)
m_docsp[i] = &m_docs[i];
m_docsp[i] = &m_docs[i];
CompareDocs cmp(sortspec);
sort(m_docsp.begin(), m_docsp.end(), cmp);
@@ -72,7 +72,7 @@ bool DocSeqSorted::getDoc(int num, Rcl::Doc &doc, string *)
{
LOGDEB("DocSeqSorted::getDoc(" << (num) << ")\n" );
if (num < 0 || num >= int(m_docsp.size()))
return false;
return false;
doc = *m_docsp[num];
return true;
}
+2 -2
View File
@@ -31,9 +31,9 @@
class DocSeqSorted : public DocSeqModifier {
public:
DocSeqSorted(std::shared_ptr<DocSequence> iseq, DocSeqSortSpec &sortspec)
: DocSeqModifier(iseq)
: DocSeqModifier(iseq)
{
setSortSpec(sortspec);
setSortSpec(sortspec);
}
virtual ~DocSeqSorted() {}
virtual bool canSort() {return true;}
+2 -2
View File
@@ -1465,7 +1465,7 @@ static void qualify(Rcl::SearchDataClauseDist *cl, const string& quals)
case 's':
cl->addModifier(Rcl::SearchDataClause::SDCM_NOSYNS);
break;
case 'S':
case 'S':
break;
case '.':case '0':case '1':case '2':case '3':case '4':
case '5':case '6':case '7':case '8':case '9':
@@ -1528,7 +1528,7 @@ out:
int yylex(yy::parser::semantic_type *yylval, yy::parser::location_type *,
WasaParserDriver *d)
WasaParserDriver *d)
{
if (!d->qualifiers().empty()) {
yylval->str = new string();
+151 -151
View File
@@ -72,7 +72,7 @@ static int op_flags;
#define OPT_P 0x8
#define OPT_T 0x10
#define OPT_X 0x20
#define OPT_d 0x80
#define OPT_d 0x80
#define OPT_e 0x100
#define OPT_f 0x200
#define OPT_i 0x400
@@ -88,16 +88,16 @@ static int op_flags;
static string detailstring(const string& in)
{
if (!(op_flags & OPT_x))
return in;
return in;
string out;
Utf8Iter it(in);
for (; !it.eof(); it++) {
it.appendchartostring(out);
out += ' ';
it.appendchartostring(out);
out += ' ';
}
// Strip last space
if (!out.empty())
out.resize(out.size()-1);
out.resize(out.size()-1);
return out;
}
@@ -120,9 +120,9 @@ bool o_index_stripchars;
inline bool has_prefix(const string& trm)
{
if (o_index_stripchars) {
return trm.size() && 'A' <= trm[0] && trm[0] <= 'Z';
return trm.size() && 'A' <= trm[0] && trm[0] <= 'Z';
} else {
return trm.size() > 0 && trm[0] == ':';
return trm.size() > 0 && trm[0] == ':';
}
}
@@ -158,174 +158,174 @@ int main(int argc, char **argv)
argc--; argv++;
while (argc > 0 && **argv == '-') {
(*argv)++;
if (!(**argv))
/* Cas du "adb - core" */
Usage();
while (**argv)
switch (*(*argv)++) {
case 'D': op_flags |= OPT_D; break;
case 'd': op_flags |= OPT_d; if (argc < 2) Usage();
dbdir = *(++argv);
argc--;
goto b1;
case 'E': op_flags |= OPT_E; break;
case 'e': op_flags |= OPT_d; if (argc < 2) Usage();
outencoding = *(++argv);
argc--;
goto b1;
case 'F': op_flags |= OPT_F; break;
case 'f': op_flags |= OPT_f; break;
case 'i': op_flags |= OPT_i; if (argc < 2) Usage();
if (sscanf(*(++argv), "%d", &docid) != 1) Usage();
argc--;
goto b1;
case 'l': op_flags |= OPT_l; break;
case 'n': op_flags |= OPT_n; break;
case 'P': op_flags |= OPT_P; break;
case 'q': op_flags |= OPT_q; break;
case 'r': case 'b': op_flags |= OPT_r; break;
case 'T': op_flags |= OPT_T; break;
case 't': op_flags |= OPT_t; if (argc < 2) Usage();
aterm = *(++argv);
argc--;
goto b1;
case 'X': op_flags |= OPT_X; break;
case 'x': op_flags |= OPT_x; break;
default: Usage(); break;
}
(*argv)++;
if (!(**argv))
/* Cas du "adb - core" */
Usage();
while (**argv)
switch (*(*argv)++) {
case 'D': op_flags |= OPT_D; break;
case 'd': op_flags |= OPT_d; if (argc < 2) Usage();
dbdir = *(++argv);
argc--;
goto b1;
case 'E': op_flags |= OPT_E; break;
case 'e': op_flags |= OPT_d; if (argc < 2) Usage();
outencoding = *(++argv);
argc--;
goto b1;
case 'F': op_flags |= OPT_F; break;
case 'f': op_flags |= OPT_f; break;
case 'i': op_flags |= OPT_i; if (argc < 2) Usage();
if (sscanf(*(++argv), "%d", &docid) != 1) Usage();
argc--;
goto b1;
case 'l': op_flags |= OPT_l; break;
case 'n': op_flags |= OPT_n; break;
case 'P': op_flags |= OPT_P; break;
case 'q': op_flags |= OPT_q; break;
case 'r': case 'b': op_flags |= OPT_r; break;
case 'T': op_flags |= OPT_T; break;
case 't': op_flags |= OPT_t; if (argc < 2) Usage();
aterm = *(++argv);
argc--;
goto b1;
case 'X': op_flags |= OPT_X; break;
case 'x': op_flags |= OPT_x; break;
default: Usage(); break;
}
b1: argc--; argv++;
}
vector<string> qterms;
if (op_flags & OPT_q) {
fprintf(stderr, "q argc %d\n", argc);
if (argc < 1)
Usage();
while (argc > 0) {
qterms.push_back(*argv++); argc--;
}
fprintf(stderr, "q argc %d\n", argc);
if (argc < 1)
Usage();
while (argc > 0) {
qterms.push_back(*argv++); argc--;
}
}
if (argc != 0)
Usage();
Usage();
atexit(cleanup);
if (signal(SIGHUP, SIG_IGN) != SIG_IGN)
signal(SIGHUP, sigcleanup);
signal(SIGHUP, sigcleanup);
if (signal(SIGINT, SIG_IGN) != SIG_IGN)
signal(SIGINT, sigcleanup);
signal(SIGINT, sigcleanup);
if (signal(SIGQUIT, SIG_IGN) != SIG_IGN)
signal(SIGQUIT, sigcleanup);
signal(SIGQUIT, sigcleanup);
if (signal(SIGTERM, SIG_IGN) != SIG_IGN)
signal(SIGTERM, sigcleanup);
signal(SIGTERM, sigcleanup);
try {
db = new Xapian::Database(dbdir);
cout << "DB: ndocs " << db->get_doccount() << " lastdocid " <<
db->get_lastdocid() << " avglength " << db->get_avlength() << endl;
db = new Xapian::Database(dbdir);
cout << "DB: ndocs " << db->get_doccount() << " lastdocid " <<
db->get_lastdocid() << " avglength " << db->get_avlength() << endl;
// If we have terms with a leading ':' it's a new style,
// unstripped index
{
Xapian::TermIterator term = db->allterms_begin(":");
if (term == db->allterms_end())
o_index_stripchars = true;
else
o_index_stripchars = false;
cout<<"DB: terms are "<<(o_index_stripchars?"stripped":"raw")<<endl;
}
// If we have terms with a leading ':' it's a new style,
// unstripped index
{
Xapian::TermIterator term = db->allterms_begin(":");
if (term == db->allterms_end())
o_index_stripchars = true;
else
o_index_stripchars = false;
cout<<"DB: terms are "<<(o_index_stripchars?"stripped":"raw")<<endl;
}
if (op_flags & OPT_T) {
Xapian::TermIterator term;
string printable;
string op = (op_flags & OPT_n) ? string(): "[";
string cl = (op_flags & OPT_n) ? string(): "]";
if (op_flags & OPT_i) {
for (term = db->termlist_begin(docid);
term != db->termlist_end(docid);term++) {
const string& s = *term;
if ((op_flags&OPT_l) && has_prefix(s))
continue;
cout << op << detailstring(s) << cl << endl;
}
} else {
for (term = db->allterms_begin();
term != db->allterms_end();term++) {
const string& s = *term;
if ((op_flags&OPT_l) && has_prefix(s))
continue;
if (op_flags & OPT_f)
cout << db->get_collection_freq(*term) << " "
<< term.get_termfreq() << " ";
cout << op << detailstring(s) << cl << endl;
}
}
} else if (op_flags & OPT_D) {
Xapian::Document doc = db->get_document(docid);
string data = doc.get_data();
cout << data << endl;
} else if (op_flags & OPT_r) {
wholedoc(db, docid);
} else if (op_flags & OPT_X) {
Xapian::Document doc = db->get_document(docid);
string data = doc.get_data();
cout << data << endl;
cout << "Really delete xapian document ?" << endl;
string rep;
cin >> rep;
if (!rep.empty() && (rep[0] == 'y' || rep[0] == 'Y')) {
Xapian::WritableDatabase wdb(dbdir, Xapian::DB_OPEN);
cout << "Deleting" << endl;
wdb.delete_document(docid);
}
} else if (op_flags & OPT_P) {
Xapian::PostingIterator doc;
for (doc = db->postlist_begin(aterm);
doc != db->postlist_end(aterm); doc++) {
cout << *doc << "(" << doc.get_wdf() << ") : " ;
Xapian::PositionIterator pos;
for (pos = doc.positionlist_begin();
pos != doc.positionlist_end(); pos++) {
cout << *pos << " " ;
}
cout << endl;
}
} else if (op_flags & OPT_F) {
cout << "FreqFor " << aterm << " : " <<
db->get_termfreq(aterm) << endl;
} else if (op_flags & OPT_E) {
cout << "Exists [" << aterm << "] : " <<
db->term_exists(aterm) << endl;
} else if (op_flags & OPT_q) {
Xapian::Enquire enquire(*db);
if (op_flags & OPT_T) {
Xapian::TermIterator term;
string printable;
string op = (op_flags & OPT_n) ? string(): "[";
string cl = (op_flags & OPT_n) ? string(): "]";
if (op_flags & OPT_i) {
for (term = db->termlist_begin(docid);
term != db->termlist_end(docid);term++) {
const string& s = *term;
if ((op_flags&OPT_l) && has_prefix(s))
continue;
cout << op << detailstring(s) << cl << endl;
}
} else {
for (term = db->allterms_begin();
term != db->allterms_end();term++) {
const string& s = *term;
if ((op_flags&OPT_l) && has_prefix(s))
continue;
if (op_flags & OPT_f)
cout << db->get_collection_freq(*term) << " "
<< term.get_termfreq() << " ";
cout << op << detailstring(s) << cl << endl;
}
}
} else if (op_flags & OPT_D) {
Xapian::Document doc = db->get_document(docid);
string data = doc.get_data();
cout << data << endl;
} else if (op_flags & OPT_r) {
wholedoc(db, docid);
} else if (op_flags & OPT_X) {
Xapian::Document doc = db->get_document(docid);
string data = doc.get_data();
cout << data << endl;
cout << "Really delete xapian document ?" << endl;
string rep;
cin >> rep;
if (!rep.empty() && (rep[0] == 'y' || rep[0] == 'Y')) {
Xapian::WritableDatabase wdb(dbdir, Xapian::DB_OPEN);
cout << "Deleting" << endl;
wdb.delete_document(docid);
}
} else if (op_flags & OPT_P) {
Xapian::PostingIterator doc;
for (doc = db->postlist_begin(aterm);
doc != db->postlist_end(aterm); doc++) {
cout << *doc << "(" << doc.get_wdf() << ") : " ;
Xapian::PositionIterator pos;
for (pos = doc.positionlist_begin();
pos != doc.positionlist_end(); pos++) {
cout << *pos << " " ;
}
cout << endl;
}
} else if (op_flags & OPT_F) {
cout << "FreqFor " << aterm << " : " <<
db->get_termfreq(aterm) << endl;
} else if (op_flags & OPT_E) {
cout << "Exists [" << aterm << "] : " <<
db->term_exists(aterm) << endl;
} else if (op_flags & OPT_q) {
Xapian::Enquire enquire(*db);
Xapian::Query query(Xapian::Query::OP_AND, qterms.begin(),
qterms.end());
cout << "Performing query `" <<
query.get_description() << "'" << endl;
enquire.set_query(query);
Xapian::Query query(Xapian::Query::OP_AND, qterms.begin(),
qterms.end());
cout << "Performing query `" <<
query.get_description() << "'" << endl;
enquire.set_query(query);
Xapian::MSet matches = enquire.get_mset(0, 10);
cout << "Estimated results: " <<
matches.get_matches_lower_bound() << endl;
Xapian::MSetIterator i;
for (i = matches.begin(); i != matches.end(); ++i) {
cout << "Document ID " << *i << "\t";
cout << i.get_percent() << "% ";
Xapian::Document doc = i.get_document();
cout << "[" << doc.get_data() << "]" << endl;
}
}
Xapian::MSet matches = enquire.get_mset(0, 10);
cout << "Estimated results: " <<
matches.get_matches_lower_bound() << endl;
Xapian::MSetIterator i;
for (i = matches.begin(); i != matches.end(); ++i) {
cout << "Document ID " << *i << "\t";
cout << i.get_percent() << "% ";
Xapian::Document doc = i.get_document();
cout << "[" << doc.get_data() << "]" << endl;
}
}
} catch (const Xapian::Error &e) {
cout << "Exception: " << e.get_msg() << endl;
cout << "Exception: " << e.get_msg() << endl;
} catch (const string &s) {
cout << "Exception: " << s << endl;
cout << "Exception: " << s << endl;
} catch (const char *s) {
cout << "Exception: " << s << endl;
cout << "Exception: " << s << endl;
} catch (...) {
cout << "Caught unknown exception" << endl;
cout << "Caught unknown exception" << endl;
}
exit(0);
}