aboutsummaryrefslogtreecommitdiff
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
parent350a11b05c6496b3628dd18704b9f7e0b3f29403 (diff)
downloadlibbible-b8a4092aaa48d00d88765021a82d5f396ba08f0f.tar.gz
libbible-b8a4092aaa48d00d88765021a82d5f396ba08f0f.tar.bz2
libbible-b8a4092aaa48d00d88765021a82d5f396ba08f0f.zip
Moved to c++20, reports full language name
-rw-r--r--Makefile2
-rw-r--r--bible.cc7
-rw-r--r--libbible.h5
-rw-r--r--mods.cc39
4 files changed, 50 insertions, 3 deletions
diff --git a/Makefile b/Makefile
index 3189adc..4fe1ffc 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
CC=g++
LIBS=sword minizip
-CFLAGS=-c -Wall -fPIC -std=c++17
+CFLAGS=-c -Wall -fPIC -std=c++20
LDFLAGS=-lstdc++fs
SOURCES=libbible.cc mods.cc settings.cc
OBJECTS=$(SOURCES:.cc=.o)
diff --git a/bible.cc b/bible.cc
index 943d6d0..fe2c828 100644
--- a/bible.cc
+++ b/bible.cc
@@ -72,11 +72,16 @@ void listChapters(string modname, string book) {
void listInstallable(string language) {
map<string, vector<string>> installable = libbible::downloadModsAvailable();
+ map<string, string> languages = libbible::getLanguageNames();
for(auto pair : installable) {
if(!language.empty() && language != pair.first) {
continue;
}
- printf("For language %s:\n", pair.first.c_str());
+ printf("For language %s:", pair.first.c_str());
+ if(!languages[pair.first].empty()) {
+ printf(" (%s)", languages[pair.first].c_str());
+ }
+ printf("\n");
for(string name : pair.second) {
printf(" %s\n", name.c_str());
}
diff --git a/libbible.h b/libbible.h
index 82a15ab..f77dc8c 100644
--- a/libbible.h
+++ b/libbible.h
@@ -65,6 +65,11 @@ namespace libbible {
std::map<std::string, std::vector<std::string>> downloadModsAvailable();
/**
+ * @return A mapping from language abbreviations to full language names
+ */
+ std::map<std::string, std::string> getLanguageNames();
+
+ /**
* Cancel an in-progress download
*/
void terminateDownload(void);
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();
}