From 4a17bac9e3f795976dd0983391aced3b94791075 Mon Sep 17 00:00:00 2001 From: Jean-Francois Dockes Date: Tue, 2 Oct 2012 16:26:18 +0200 Subject: [PATCH] improve message printed for aspell dictionary creation error --- src/aspell/rclaspell.cpp | 37 +++++++++++++++++++++++++++++++------ src/rcldb/rcldb.h | 5 +++++ 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/src/aspell/rclaspell.cpp b/src/aspell/rclaspell.cpp index 2c1eca39..0be63c7f 100644 --- a/src/aspell/rclaspell.cpp +++ b/src/aspell/rclaspell.cpp @@ -297,22 +297,47 @@ bool Aspell::buildDict(Rcl::Db &db, string &reason) args.push_back("create"); args.push_back("master"); args.push_back(dicPath()); - aspell.setStderr("/dev/null"); + + // Have to disable stderr, as numerous messages about bad strings are + // printed. We'd like to keep errors about missing databases though, so + // make it configurable for diags + bool keepStderr = false; + m_config->getConfParam("aspellKeepStderr", &keepStderr); + if (!keepStderr) + aspell.setStderr("/dev/null"); Rcl::TermIter *tit = db.termWalkOpen(); if (tit == 0) { reason = "termWalkOpen failed\n"; return false; } - string termbuf; AspExecPv pv(&termbuf, tit, db); aspell.setProvide(&pv); - + if (aspell.doexec(m_data->m_exec, args, &termbuf)) { - reason = string("aspell dictionary creation command failed.\n" - "One possible reason might be missing language " - "data files for lang = ") + m_lang; + ExecCmd cmd; + args.clear(); + args.push_back("dicts"); + string dicts; + bool hasdict = false; + if (!cmd.doexec(m_data->m_exec, args, 0, &dicts)) { + vector vdicts; + stringToTokens(dicts, vdicts, "\n\r\t "); + if (find(vdicts.begin(), vdicts.end(), m_lang) != vdicts.end()) { + hasdict = true; + } + } + if (hasdict) + reason = string( + "\naspell dictionary creation command failed. Reason unknown.\n" + "Try to set aspellKeepStderr = 1 in recoll.conf, and execute \n" + "the indexing command in a terminal to see the aspell " + "diagnostic output.\n"); + else + reason = string("aspell dictionary creation command failed.\n" + "One possible reason might be missing language " + "data files for lang = ") + m_lang; return false; } db.termWalkClose(tit); diff --git a/src/rcldb/rcldb.h b/src/rcldb/rcldb.h index d9145e25..7daf5a49 100644 --- a/src/rcldb/rcldb.h +++ b/src/rcldb/rcldb.h @@ -27,6 +27,8 @@ #include "rcldoc.h" #include "stoplist.h" #include "rclconfig.h" +#include "utf8iter.h" +#include "textsplit.h" using std::string; using std::vector; @@ -192,6 +194,9 @@ class Db { return false; if (has_prefix(term)) return false; + Utf8Iter u8i(term); + if (TextSplit::isCJK(*u8i)) + return false; if (term.find_first_of(" !\"#$%&()*+,-./0123456789:;<=>?@[\\]^_`{|}~") != string::npos) return false;