Skip to content

Commit

Permalink
Auto-increments verses when no input is given.
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheosh committed Jun 29, 2015
1 parent 253df49 commit 48e61d6
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ project(cbible)
include_directories("/usr/include/sword")
link_directories("/usr/lib")
link_libraries(sword readline)
set(gcc_cflags "-std=c++11")
set(gcc_cflags "-g3 -std=c++11")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${gcc_cflags}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${gcc_cflags}")
add_executable(cbible SwordFuncs.cpp cbible.cpp)
Expand Down
23 changes: 22 additions & 1 deletion src/SwordFuncs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ void SwordFuncs::SetModule(std::string module_name)
{
manager = new SWMgr(new MarkupFilterMgr(FMT_PLAIN));
module = manager->getModule(module_name.c_str());
module->setKey(vkey);

if (!module) {
std::cout << listModules() << std::endl;
Expand All @@ -61,6 +62,22 @@ void SwordFuncs::SetModule(std::string module_name)
}
}

std::string SwordFuncs::currentRef()
{
if (vkey.isTraversable())
vkey++;

module->setKey(vkey);
std::string ret = "";

ret += std::to_string(vkey.getVerse());
ret += " ";
ret += module->RenderText();
ret += "\n";
ret += module->getKey()->getText();
return ret;
}

std::string SwordFuncs::parseInput(char * input)
{
std::string str = input;
Expand All @@ -71,6 +88,8 @@ std::string SwordFuncs::parseInput(char * input)
SetModule(mod);
return(mod);
}
else if (str.empty())
return currentRef();
else
return lookup(str);
}
Expand All @@ -93,7 +112,8 @@ std::string SwordFuncs::modname()
std::string SwordFuncs::lookup(std::string ref)
{
std::string output = "";
//Module variables

// Set up module specific variables
sword::VerseKey vk;

//Variables related to splitting up the reference for iteration
Expand All @@ -113,6 +133,7 @@ std::string SwordFuncs::lookup(std::string ref)
}
output += "\n";
output += module->getKey()->getRangeText();
vkey = module->getKey();
}
catch(const std::runtime_error& re)
{
Expand Down
2 changes: 2 additions & 0 deletions src/SwordFuncs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class SwordFuncs
private:
sword::SWMgr *manager;
sword::SWModule *module;
sword::VerseKey vkey;
std::string mod_name;

std::string listModules();
Expand All @@ -43,6 +44,7 @@ class SwordFuncs
SwordFuncs();
SwordFuncs(std::string);
virtual ~SwordFuncs();
std::string currentRef();
std::string modname();
std::string parseInput(char * input);
std::string lookup(std::string);
Expand Down
2 changes: 1 addition & 1 deletion src/cbible.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ int main(int argc, char *argv[])
rl_bind_key('\t',rl_abort); //disable auto-complete

std::string prompt = "\n" + sw->modname() + " >> ";

std::cout << sw->parseInput(const_cast<char *>("Gen 1:1")) << std::endl;
while((buf = readline(prompt.c_str()))!=NULL)
{
if ((strcmp(buf,"quit")==0) ||
Expand Down

0 comments on commit 48e61d6

Please sign in to comment.