aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYour Name <you@example.com>2020-11-07 07:56:08 -0500
committerYour Name <you@example.com>2020-11-07 07:56:08 -0500
commit67207e20f3dc8b9e92e45560776b5b304f964cc1 (patch)
tree1c766f0869194b2ae0adf4b57d7470140a3a5d6c
parent44f16b6cd5b9cd9641c0c5df1c671c9e610ad7ac (diff)
downloadlibbible-67207e20f3dc8b9e92e45560776b5b304f964cc1.tar.gz
libbible-67207e20f3dc8b9e92e45560776b5b304f964cc1.tar.bz2
libbible-67207e20f3dc8b9e92e45560776b5b304f964cc1.zip
Fixed segfaults for invalid module names
-rw-r--r--Makefile7
-rw-r--r--bible.cc8
-rw-r--r--libbible.cc10
-rw-r--r--readme.md14
4 files changed, 22 insertions, 17 deletions
diff --git a/Makefile b/Makefile
index 61957d7..c10be48 100644
--- a/Makefile
+++ b/Makefile
@@ -5,17 +5,20 @@ LDFLAGS=
SOURCES=libbible.cc mods.cc settings.cc
OBJECTS=$(SOURCES:.cc=.o)
LIBRARY=libbible.so
+EXECUTABLE=bible
ifeq ($(PREFIX),)
PREFIX := /usr
endif
-all: $(SOURCES) $(LIBRARY)
+all: $(SOURCES) $(LIBRARY) $(EXECUTABLE)
-install: $(LIBRARY)
+install: $(LIBRARY) $(EXECUTABLE)
install -d $(DESTDIR)$(PREFIX)/lib/
install -m 644 $(LIBRARY) $(DESTDIR)$(PREFIX)/lib/
install -d $(DESTDIR)$(PREFIX)/include/
install -m 644 libbible.h $(DESTDIR)$(PREFIX)/include/
+ install -d $(DESTDIR)$(PREFIX)/bin/
+ install -m 644 bible $(DESTDIR)$(PREFIX)/bin/
test: $(OBJECTS) testLibbible.o
$(CC) $(LDFLAGS) $(OBJECTS) testLibbible.o -o $@ `pkg-config $(LIBS) --libs` -lcppunit
diff --git a/bible.cc b/bible.cc
index b0e3ed3..3388364 100644
--- a/bible.cc
+++ b/bible.cc
@@ -19,7 +19,7 @@ void usage() {
printf(" --list-installable=<lang> list bible versions available for download and install. Default lists for all languages.\n");
printf(" --install-network <mod> install module from the network where <mod> is LANG:NAME as provided by --list-installable\n");
printf(" --install-zip <path> install module from a zip file\n");
- printf(" --remove-mod <mod> delete a mod from the system\n");
+ printf(" --remove-module <mod> delete a module from the system\n");
printf("\n\nExamples:\n bible Gal 5:22-23\n");
printf(" bible John 3:16\n bible Romans 12\n bible Matt 5:3-7:27\n");
printf(" bible Genesis 1-3\n");
@@ -49,7 +49,7 @@ void setDefaultModule(string modname) {
void listBooks(string modname) {
map<string, vector<string>> mods = libbible::getModules();
if(mods.find(modname) == mods.end()) {
- printf("ERROR: Module \"%s\" not installed!", modname.c_str());
+ printf("ERROR: Module \"%s\" not installed!\n", modname.c_str());
} else {
printf("Books in Module %s:\n", modname.c_str());
for(string book : mods[modname]) {
@@ -113,7 +113,7 @@ int main(int argc, char* argv[]) {
{"list-installable", optional_argument, 0, 0},
{"install-network", required_argument, 0, 0},
{"install-zip", required_argument, 0, 0},
- {"remove-mod", required_argument, 0, 0}
+ {"remove-module", required_argument, 0, 0}
};
int opt, option_index;
string modname;
@@ -153,7 +153,7 @@ int main(int argc, char* argv[]) {
installNetwork(string(optarg));
} else if(option == "install-zip") {
installZip(string(optarg));
- } else if(option == "remove-mod") {
+ } else if(option == "remove-module") {
removeMod(string(optarg));
}
break;
diff --git a/libbible.cc b/libbible.cc
index 7b08174..29e8873 100644
--- a/libbible.cc
+++ b/libbible.cc
@@ -42,6 +42,10 @@ map<string, vector<string>> libbible::getModules() {
vector<libbible::passage> libbible::getPassages(string modName, string book) {
vector<libbible::passage> passages;
SWModule *target = library.getModule(modName.c_str());
+ if(target == nullptr) {
+ // Module doesn't exist
+ return passages;
+ }
target->setKey((book + " " + "1").c_str());
VerseKey *key = (VerseKey *) target->getKey();
int maxChapter = key->getChapterMax();
@@ -124,13 +128,17 @@ void inferMissing(libbible::passage *pass, SWModule *target) {
}
vector<libbible::text> libbible::getText(libbible::passage pass) {
+ vector<libbible::text> texts;
SWModule *target = library.getModule(pass.modName.c_str());
+ if(target == nullptr) {
+ // Module doesn't exist
+ return texts;
+ }
inferMissing(&pass, target);
target->setKey((pass.book
+ " " + to_string(pass.chapterStart)
+ ":" + to_string(pass.verseStart)).c_str());
VerseKey *key = (VerseKey *) target->getKey();
- vector<libbible::text> texts;
bool endOfParagraph = false;
diff --git a/readme.md b/readme.md
index 21be739..7eca841 100644
--- a/readme.md
+++ b/readme.md
@@ -4,7 +4,7 @@ This library provides a simplified interface to the SWORD project.
##libbible.so
-The library can be compiled into a sharable object file and installed to the system. This is the default make option:
+The library can be compiled into a sharable object file and installed to the system:
```console
make
@@ -15,16 +15,10 @@ The full interface is available in libbible.h.
##bible
-An example cli is included with libbible, which can be compiled using:
+An example cli is included with libbible. It is designed to showcase the functionality of libbible:
```console
-make bible
-```
-
-The interface is simplistic, and uses a subset of libbible's functionality:
-
-```console
-./bible --help
+bible --help
Usage:
bible [options] [reference]
@@ -42,7 +36,7 @@ Options:
--list-installable=<lang> list bible versions available for download and install. Default lists for all languages.
--install-network <mod> install module from the network where <mod> is LANG:NAME as provided by --list-installable
--install-zip <path> install module from a zip file
- --remove-mod <mod> delete a mod from the system
+ --remove-module <mod> delete a mod from the system
Examples: