/****************************************************************************** * * parallelBibles.cpp - This examples demonstrates a strategy for * displaying Bibles in parallel * * $Id: parallelbibles.cpp 3030 2014-02-28 02:14:44Z scribe $ * * Copyright 2013-2014 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society * P. O. Box 2528 * Tempe, AZ 85280-2528 * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation version 2. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * */ #include #include #include #include #include #include #include using namespace sword; using namespace std; const bool o = 1; void parallelDisplay(vectormodules, const char *key) { //cout << "Start key:" << key; // We'll use the first module's key as our master key to position all other modules. VerseKey *master = (VerseKey *)modules[0]->createKey(); master->setText(key); //cout << "\t key:" << master->getText(); int curVerse = master->getVerse(); int curChapter = master->getChapter(); int curBook = master->getBook(); for (master->setVerse(1); (master->getBook() == curBook) && (master->getChapter() == curChapter) && !master->popError(); (*master)++) { if(o) cout << "getVerse() == curVerse ? "currentverse":"verse") << "\">"; for (vector::iterator module = modules.begin(); module != modules.end(); ++module) { //cout << "\n\n====================\nfromKey" << master->getOSISRef(); (*module)->setKey(master); VerseKey slave((*module)->getKey()); //cout << "setKey" << (*module)->getName() << slave.getBookName() << slave.getRangeText() << slave.getShortText(); if(o) cout << "" << ""; //cout << "[" << (int)slave.getBook() << " " << (int)master->getBook() << " " << (int)slave.getTestament() << " " << (int)master->getTestament() << "]"; if (!(*module)->popError()) { if(strcmp(slave.getBookName(), master->getBookName())) { if(o) cout << slave.getShortText(); } else if(slave.getChapter() != master->getChapter()) { if(o) cout << slave.getChapter() << ":" << slave.getVerse(); } else { if(o) cout << slave.getVerse(); } if(slave.isBoundSet()) { if(o) cout << "-"; if(slave.getUpperBound().getBook() != slave.getLowerBound().getBook()) { if(o) cout << slave.getUpperBound().getShortText(); } else if(slave.getUpperBound().getChapter() != slave.getLowerBound().getChapter()) { if(o) cout << slave.getUpperBound().getChapter() << ":" << slave.getUpperBound().getVerse(); } else { if(o) cout << slave.getUpperBound().getVerse(); } } if(o) cout << " "; if(slave.isBoundSet()) { VerseKey temp(slave); for(int i = slave.getLowerBound().getIndex(); i <= slave.getUpperBound().getIndex(); ++i) { if(i > 0) if(o) cout << " "; temp.setIndex(i); (*module)->setKey(temp); if(o) cout << (*module)->renderText(); } } else { if(o) cout << (*module)->renderText(); } if(o) cout << ""; } } if(o) cout << ""; } delete master; } void outputHeader(vectormodules, const char *key) { modules[0]->setKey(key); // force a render so our key snaps to a module entry and we get nicely formatted keytext output later // otherwise we just get what the user typed modules[0]->renderText(); cout << "" << "" << "" << "" << "" << "" << "OSIS Web: " << modules[0]->getKeyText() << " - Parallel Bible study" << "" << "" << "" << "" << "" << "" << "" << "" << "" << "" << "" << "" << "" << "
" << "
" << "

The Bible Tool

" << "
" << "
" << "
" << "" << "

Parallel Viewing: " << modules[0]->getKeyText() << "


" << ""; for (vector::iterator module = modules.begin(); module != modules.end(); ++module) { cout << ""; } cout << ""; } void outputFooter(vectormodules) { cout << ""; for (vector::iterator module = modules.begin(); module != modules.end(); ++module) { SWBuf copyLine = (*module)->getConfigEntry("ShortCopyright"); SWBuf promoLine = (*module)->getConfigEntry("ShortPromo"); cout << ""; } cout << "
" << (*module)->getDescription() << "
" << "
" << copyLine << "
" << "
" << promoLine << "
" << "
" << "
" << "
" << "
" << "

" << "\"American" << "\"CrossWire" << "\"Society" << "

" << "

Copyright © 2003-2011 CrossWire Bible Society

" << "

" << "
" << "" << ""; } int main(int argc, char **argv) { SWMgr library(new MarkupFilterMgr(FMT_XHTML)); if (argc < 3) { fprintf(stderr, "\nusage: %s [modname ...] <\"key\">\n" "\tExample: %s KJV ESV \"James 1:19\"\n\n", argv[0], argv[0]); exit(-1); } vector modules; for (int i = 1; i < argc-1; ++i) { SWModule *bible = library.getModule(argv[i]); if (!bible) { fprintf(stderr, "Could not find module [%s]. Available modules:\n", argv[i]); ModMap::iterator it; for (it = library.Modules.begin(); it != library.Modules.end(); ++it) { fprintf(stderr, "[%s]\t - %s\n", (*it).second->getName(), (*it).second->getDescription()); } exit(-2); } modules.push_back(bible); } if(o) outputHeader(modules, argv[argc-1]); parallelDisplay(modules, argv[argc-1]); if(o) outputFooter(modules); return 0; }