aboutsummaryrefslogtreecommitdiff
path: root/mods.cc
diff options
context:
space:
mode:
authorYour Name <you@example.com>2022-01-22 11:04:16 -0500
committerYour Name <you@example.com>2022-01-22 11:04:16 -0500
commitb8a4092aaa48d00d88765021a82d5f396ba08f0f (patch)
treec83c6316669dee1ea12a14b32b08f4ac1b6b712e /mods.cc
parent350a11b05c6496b3628dd18704b9f7e0b3f29403 (diff)
downloadlibbible-b8a4092aaa48d00d88765021a82d5f396ba08f0f.tar.gz
libbible-b8a4092aaa48d00d88765021a82d5f396ba08f0f.tar.bz2
libbible-b8a4092aaa48d00d88765021a82d5f396ba08f0f.zip
Moved to c++20, reports full language name
Diffstat (limited to 'mods.cc')
-rw-r--r--mods.cc39
1 files changed, 38 insertions, 1 deletions
diff --git a/mods.cc b/mods.cc
index 30b24f8..708f3f1 100644
--- a/mods.cc
+++ b/mods.cc
@@ -42,6 +42,7 @@ void myStatusReporter::update(unsigned long totalBytes, unsigned long completedB
string basedir = (getenv("HOME")) + string("/.sword/");
sword::InstallMgr *installMgr = new sword::InstallMgr((basedir + std::string("InstallMgr")).c_str(), nullptr);
map<string, vector<pair<string, sword::InstallSource *>>> installSources;
+map<string, string> languageNames; // maps abbreviation to full name
void libbible::setStatusReporter(libbible::Status& status) {
myStatusReporter *msr = new myStatusReporter(&status);
@@ -52,6 +53,7 @@ void libbible::setStatusReporter(libbible::Status& status) {
map<string, vector<string>> libbible::downloadModsAvailable() {
installSources.clear();
+ languageNames.clear();
mkdir((basedir + std::string("mods.d/")).c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
mkdir((basedir + std::string("modules/")).c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
installMgr->setUserDisclaimerConfirmed(true);
@@ -71,6 +73,7 @@ map<string, vector<string>> libbible::downloadModsAvailable() {
}
installMgr->readInstallConf();
map<string, vector<string>> modsAvailable;
+ map<string, vector<string>> languagesToFull;
//printf("Getting langs...\n");
for(auto src : installMgr->sources) {
if(src.second->getMgr()->Modules.empty()) {
@@ -82,7 +85,19 @@ map<string, vector<string>> libbible::downloadModsAvailable() {
string type(curMod->getType());
if(type == "Biblical Texts") {
string language(curMod->getLanguage());
- //printf("Got language %s\n", language.c_str());
+ string fullLang;
+ if(curMod->getConfigEntry("LCSH")) {
+ // Split on periods, last field, strip
+ fullLang = string(curMod->getConfigEntry("LCSH"));
+ // If ends with ., remove
+ if(fullLang.ends_with('.')) fullLang = fullLang.substr(0, fullLang.size()-1);
+ if(fullLang.find('.') != string::npos) fullLang = fullLang.substr(fullLang.find_last_of('.')+1);
+ while(fullLang.starts_with(' ')) fullLang = fullLang.substr(1);
+ while(fullLang.ends_with(' ')) fullLang = fullLang.substr(0, fullLang.size()-1);
+ }
+ vector<string> newLangs;
+ languagesToFull.emplace(language, newLangs);
+ languagesToFull[language].push_back(fullLang);
vector<string> newMods;
vector<pair<string, sword::InstallSource *>> newSources;
// emplace only adds if key is unique
@@ -94,9 +109,31 @@ map<string, vector<string>> libbible::downloadModsAvailable() {
}
}
}
+ // Now use majority voting to move languagesToFull -> languageNames
+ for(const auto& [abbrev, fulls] : languagesToFull) {
+ std::map<string, int> majVote;
+ for(auto full : fulls) {
+ majVote.try_emplace(full, 0);
+ majVote[full]++;
+ }
+ string selected = fulls[0];
+ for(auto full : fulls) {
+ if(majVote[full] > majVote[selected] or (majVote[full] == majVote[selected] and full.size() < selected.size())) {
+ selected = full;
+ }
+ }
+ languageNames[abbrev] = selected;
+ }
return modsAvailable;
}
+std::map<std::string, std::string> libbible::getLanguageNames() {
+ if(languageNames.empty()) {
+ downloadModsAvailable();
+ }
+ return languageNames;
+}
+
void libbible::terminateDownload() {
installMgr->terminate();
}