int main(int argc, char **argv) { const char *modName = "HunKar"; SWMgr library; SWModule *book = library.getModule(modName); if (!book) { cerr << "Can't find module: " << modName << endl; return -1; } VerseKey* key = ((VerseKey *)book->getKey()); key->setIntros(true); book->setSkipConsecutiveLinks(true); book->setPosition(TOP); cout << *key << endl; return 0; }
int main(int argc, char **argv) { if (argc < 2) { fprintf(stderr, "usage: %s <Mod Name>\n", argv[0]); std::exit(-1); } SWMgr mgr; auto const it = mgr.modules().find(argv[1]); if (it == mgr.modules().end()) { fprintf(stderr, "error: %s: couldn't find module: %s \n", argv[0], argv[1]); std::exit(-2); } SWModule & mod = *it->second; SWKey *key = mod.getKey(); VerseKey * vkey = nullptr; try { vkey = dynamic_cast<VerseKey *>(key); } catch (...) {} if (!vkey) { fprintf(stderr, "error: %s: %s module is not keyed to verses \n", argv[0], argv[1]); std::exit(-3); } vkey->setIntros(false); // turn on mod/testmnt/book/chap headings mod.positionToTop(); while (!mod.popError()) { if (vkey->getVerse()) { if (!mod.renderText().length()) { std::cout << vkey->getText() << std::endl; } mod.increment(); } } }
int main(int argc, char **argv) { if (argc < 2) { fprintf(stderr, "usage: %s <Mod Name>\n", argv[0]); exit(-1); } SWMgr mgr; ModMap::iterator it = mgr.Modules.find(argv[1]); if (it == mgr.Modules.end()) { fprintf(stderr, "error: %s: couldn't find module: %s \n", argv[0], argv[1]); exit(-2); } SWModule *mod = it->second; SWKey *key = (*mod); VerseKey *vkey = 0; SWTRY { vkey = dynamic_cast<VerseKey *>(key); } SWCATCH (...) {} if (!vkey) { fprintf(stderr, "error: %s: %s module is not keyed to verses \n", argv[0], argv[1]); exit(-3); } vkey->setIntros(false); // turn on mod/testmnt/book/chap headings (*mod) = TOP; while (!mod->popError()) { if (vkey->getVerse()) if (!mod->renderText().length()) std::cout << *vkey << std::endl; (*mod)++; } }
int main(int argc, char **argv) { // handle options if (argc < 2) usage(*argv); const char *progName = argv[0]; const char *inFileName = argv[1]; SWBuf v11n = "KJV"; SWBuf outPath = "./"; SWBuf locale = "en"; bool fourByteSize = false; bool append = false; int iType = 4; SWBuf cipherKey = ""; SWCompress *compressor = 0; SWBuf compType = ""; for (int i = 2; i < argc; i++) { if (!strcmp(argv[i], "-a")) { append = true; } else if (!strcmp(argv[i], "-z")) { if (fourByteSize) usage(*argv, "Cannot specify both -z and -4"); compType = "ZIP"; if (i+1 < argc && argv[i+1][0] != '-') { switch (argv[++i][0]) { case 'l': compType = "LZSS"; break; case 'z': compType = "ZIP"; break; case 'b': compType = "BZIP2"; break; case 'x': compType = "XZ"; break; } } } else if (!strcmp(argv[i], "-Z")) { if (compType.size()) usage(*argv, "Cannot specify both -z and -Z"); if (fourByteSize) usage(*argv, "Cannot specify both -Z and -4"); compType = "LZSS"; } else if (!strcmp(argv[i], "-4")) { fourByteSize = true; } else if (!strcmp(argv[i], "-b")) { if (i+1 < argc) { iType = atoi(argv[++i]); if ((iType >= 2) && (iType <= 4)) continue; } usage(*argv, "-b requires one of <2|3|4>"); } else if (!strcmp(argv[i], "-o")) { if (i+1 < argc) outPath = argv[++i]; else usage(progName, "-o requires <output_path>"); } else if (!strcmp(argv[i], "-v")) { if (i+1 < argc) v11n = argv[++i]; else usage(progName, "-v requires <v11n>"); } else if (!strcmp(argv[i], "-l")) { if (i+1 < argc) locale = argv[++i]; else usage(progName, "-l requires <locale>"); } else if (!strcmp(argv[i], "-c")) { if (i+1 < argc) cipherKey = argv[++i]; else usage(*argv, "-c requires <cipher_key>"); } else usage(progName, (((SWBuf)"Unknown argument: ")+ argv[i]).c_str()); } // ----------------------------------------------------- const VersificationMgr::System *v = VersificationMgr::getSystemVersificationMgr()->getVersificationSystem(v11n); if (!v) std::cout << "Warning: Versification " << v11n << " not found. Using KJV versification...\n"; if (compType == "LZSS") { compressor = new LZSSCompress(); } else if (compType == "ZIP") { #ifndef EXCLUDEZLIB compressor = new ZipCompress(); #else usage(*argv, "ERROR: SWORD library not compiled with ZIP compression support.\n\tBe sure libz is available when compiling SWORD library"); #endif } else if (compType == "BZIP2") { #ifndef EXCLUDEBZIP2 compressor = new Bzip2Compress(); #else usage(*argv, "ERROR: SWORD library not compiled with bzip2 compression support.\n\tBe sure libbz2 is available when compiling SWORD library"); #endif } else if (compType == "XZ") { #ifndef EXCLUDEXZ compressor = new XzCompress(); #else usage(*argv, "ERROR: SWORD library not compiled with xz compression support.\n\tBe sure liblzma is available when compiling SWORD library"); #endif } // setup module if (!append) { if (compressor) { if (zText::createModule(outPath, iType, v11n)) { fprintf(stderr, "ERROR: %s: couldn't create module at path: %s \n", *argv, outPath.c_str()); exit(-1); } } else { if (!fourByteSize) RawText::createModule(outPath, v11n); else RawText4::createModule(outPath, v11n); } } SWModule *module = 0; if (compressor) { // Create a compressed text module allowing very large entries // Taking defaults except for first, fourth, fifth and last argument module = new zText( outPath, // ipath 0, // iname 0, // idesc iType, // iblockType compressor, // icomp 0, // idisp ENC_UNKNOWN, // enc DIRECTION_LTR, // dir FMT_UNKNOWN, // markup 0, // lang v11n // versification ); } else { module = (!fourByteSize) ? (SWModule *)new RawText(outPath, 0, 0, 0, ENC_UNKNOWN, DIRECTION_LTR, FMT_UNKNOWN, 0, v11n) : (SWModule *)new RawText4(outPath, 0, 0, 0, ENC_UNKNOWN, DIRECTION_LTR, FMT_UNKNOWN, 0, v11n); } SWFilter *cipherFilter = 0; if (cipherKey.length()) { fprintf(stderr, "Adding cipher filter with phrase: %s\n", cipherKey.c_str() ); cipherFilter = new CipherFilter(cipherKey.c_str()); module->addRawFilter(cipherFilter); } // ----------------------------------------------------- // setup locale manager LocaleMgr::getSystemLocaleMgr()->setDefaultLocaleName(locale); // setup module key to allow full range of possible values, and then some VerseKey *vkey = (VerseKey *)module->createKey(); vkey->setIntros(true); vkey->setAutoNormalize(false); vkey->setPersist(true); module->setKey(*vkey); // ----------------------------------------------------- // process input file FileDesc *fd = FileMgr::getSystemFileMgr()->open(inFileName, FileMgr::RDONLY); SWBuf lineBuffer; SWBuf keyBuffer; SWBuf entBuffer; bool more = true; do { more = FileMgr::getLine(fd, lineBuffer)!=0; if (lineBuffer.startsWith("$$$")) { if ((keyBuffer.size()) && (entBuffer.size())) { writeEntry(module, keyBuffer, entBuffer); } keyBuffer = lineBuffer; keyBuffer << 3; keyBuffer.trim(); entBuffer.size(0); } else { if (keyBuffer.size()) { entBuffer += lineBuffer; entBuffer += "\n"; } } } while (more); if ((keyBuffer.size()) && (entBuffer.size())) { writeEntry(module, keyBuffer, entBuffer); } delete module; if (cipherFilter) delete cipherFilter; delete vkey; FileMgr::getSystemFileMgr()->close(fd); return 0; }
char RawVerse::createModule(const char *ipath, const char *v11n) { char *path = 0; char *buf = new char [ strlen (ipath) + 20 ]; FileDesc *fd, *fd2; stdstr(&path, ipath); if ((path[strlen(path)-1] == '/') || (path[strlen(path)-1] == '\\')) path[strlen(path)-1] = 0; sprintf(buf, "%s/ot", path); FileMgr::removeFile(buf); fd = FileMgr::getSystemFileMgr()->open(buf, FileMgr::CREAT|FileMgr::WRONLY, FileMgr::IREAD|FileMgr::IWRITE); fd->getFd(); FileMgr::getSystemFileMgr()->close(fd); sprintf(buf, "%s/nt", path); FileMgr::removeFile(buf); fd = FileMgr::getSystemFileMgr()->open(buf, FileMgr::CREAT|FileMgr::WRONLY, FileMgr::IREAD|FileMgr::IWRITE); fd->getFd(); FileMgr::getSystemFileMgr()->close(fd); sprintf(buf, "%s/ot.vss", path); FileMgr::removeFile(buf); fd = FileMgr::getSystemFileMgr()->open(buf, FileMgr::CREAT|FileMgr::WRONLY, FileMgr::IREAD|FileMgr::IWRITE); fd->getFd(); sprintf(buf, "%s/nt.vss", path); FileMgr::removeFile(buf); fd2 = FileMgr::getSystemFileMgr()->open(buf, FileMgr::CREAT|FileMgr::WRONLY, FileMgr::IREAD|FileMgr::IWRITE); fd2->getFd(); VerseKey vk; vk.setVersificationSystem(v11n); vk.setIntros(1); __s32 offset = 0; __u16 size = 0; offset = archtosword32(offset); size = archtosword16(size); for (vk = TOP; !vk.popError(); vk++) { if (vk.getTestament() < 2) { fd->write(&offset, 4); fd->write(&size, 2); } else { fd2->write(&offset, 4); fd2->write(&size, 2); } } fd2->write(&offset, 4); fd2->write(&size, 2); FileMgr::getSystemFileMgr()->close(fd); FileMgr::getSystemFileMgr()->close(fd2); delete [] path; delete [] buf; return 0; }
char GBFOSIS::processText(SWBuf &text, const SWKey *key, const SWModule *module) { char token[2048]; //cheesy, we seem to like cheese :) int tokpos = 0; bool intoken = false; bool keepToken = false; // static QuoteStack quoteStack; SWBuf orig = text; SWBuf tmp; SWBuf value; bool suspendTextPassThru = false; bool handled = false; bool newWord = false; bool newText = false; bool lastspace = false; const char *wordStart = text.c_str(); const char *wordEnd = NULL; const char *textStart = NULL; const char *textEnd = NULL; SWBuf textNode = ""; SWBuf buf; text = ""; for (const char* from = orig.c_str(); *from; ++from) { if (*from == '<') { //start of new token detected intoken = true; tokpos = 0; token[0] = 0; token[1] = 0; token[2] = 0; textEnd = from-1; //end of last text node found wordEnd = text.c_str() + text.length();//not good, instead of wordEnd = to! continue; } if (*from == '>') { // process tokens intoken = false; keepToken = false; suspendTextPassThru = false; newWord = true; handled = false; while (wordStart < (text.c_str() + text.length())) { //hack if (strchr(";,. :?!()'\"", *wordStart) && wordStart[0] && wordStart[1]) wordStart++; else break; } while (wordEnd > wordStart) { if (strchr(" ,;:.?!()'\"", *wordEnd)) wordEnd--; else break; } // Scripture Reference if (!strncmp(token, "scripRef", 8)) { suspendTextPassThru = true; newText = true; handled = true; } else if (!strncmp(token, "/scripRef", 9)) { tmp = ""; tmp.append(textStart, (int)(textEnd - textStart)+1); text += VerseKey::convertToOSIS(tmp.c_str(), key); lastspace = false; suspendTextPassThru = false; handled = true; } // Footnote if (!strcmp(token, "RF") || !strncmp(token, "RF ", 3)) { //the GBFFootnotes filter adds the attribute "swordFootnote", we want to catch that, too // pushString(buf, "<reference work=\"Bible.KJV\" reference=\""); text += "<note type=\"x-StudyNote\">"; newText = true; lastspace = false; handled = true; } else if (!strcmp(token, "Rf")) { text += "</note>"; lastspace = false; handled = true; } // hebrew titles if (!strcmp(token, "TH")) { text += "<title type=\"psalm\">"; newText = true; lastspace = false; handled = true; } else if (!strcmp(token, "Th")) { text += "</title>"; lastspace = false; handled = true; } // Italics assume transchange if (!strcmp(token, "FI")) { text += "<transChange type=\"added\">"; newText = true; lastspace = false; handled = true; } else if (!strcmp(token, "Fi")) { text += "</transChange>"; lastspace = false; handled = true; } // less than if (!strcmp(token, "CT")) { text += "<"; newText = true; lastspace = false; handled = true; } // greater than if (!strcmp(token, "CG")) { text += ">"; newText = true; lastspace = false; handled = true; } // Paragraph break. For now use empty paragraph element if (!strcmp(token, "CM")) { text += "<milestone type=\"x-p\" />"; newText = true; lastspace = false; handled = true; } // Figure else if (!strncmp(token, "img ", 4)) { const char *src = strstr(token, "src"); if (!src) // assert we have a src attribute continue; // return false; text += "<figure src=\""; const char *c; for (c = src;((*c) && (*c != '"')); c++); // uncomment for SWORD absolute path logic // if (*(c+1) == '/') { // pushString(buf, "file:"); // pushString(buf, module->getConfigEntry("AbsoluteDataPath")); // if (*((*buf)-1) == '/') // c++; // skip '/' // } // end of uncomment for asolute path logic for (c++;((*c) && (*c != '"')); c++) { text += *c; } text += "\" />"; lastspace = false; handled = true; } // Strongs numbers else if (*token == 'W' && (token[1] == 'G' || token[1] == 'H')) { // Strongs bool divineName = false; value = token+1; // normal strongs number //strstrip(val); if (!strncmp(wordStart, "<w ", 3)) { const char *attStart = strstr(wordStart, "lemma"); if (attStart) { attStart += 7; buf = ""; buf.appendFormatted("strong:%s ", value.c_str()); } else { // no lemma attribute attStart = wordStart + 3; buf = ""; buf.appendFormatted(buf, "lemma=\"strong:%s\" ", value.c_str()); } text.insert(attStart - text.c_str(), buf); } else { //wordStart doesn't point to an existing <w> attribute! if (!strcmp(value.c_str(), "H03068")) { //divineName buf = ""; buf.appendFormatted("<divineName><w lemma=\"strong:%s\">", value.c_str()); divineName = true; } else { buf = ""; buf.appendFormatted("<w lemma=\"strong:%s\">", value.c_str()); } text.insert(wordStart - text.c_str(), buf); if (divineName) { wordStart += 12; text += "</w></divineName>"; } else text += "</w>"; lastspace = false; } handled = true; } // Morphology else if (*token == 'W' && token[1] == 'T') { if (token[2] == 'G' || token[2] == 'H') { // Strongs value = token+2; } else value = token+1; if (!strncmp(wordStart, "<w ", 3)) { const char *attStart = strstr(wordStart, "morph"); if (attStart) { //existing morph attribute, append this one to it attStart += 7; buf = ""; buf.appendFormatted("%s:%s ", "robinson", value.c_str()); } else { // no lemma attribute attStart = wordStart + 3; buf = ""; buf.appendFormatted("morph=\"%s:%s\" ", "robinson", value.c_str()); } text.insert(attStart - text.c_str(), buf); //hack, we have to } else { //no existing <w> attribute fond buf = ""; buf.appendFormatted("<w morph=\"%s:%s\">", "robinson", value.c_str()); text.insert(wordStart - text.c_str(), buf); text += "</w>"; lastspace = false; } handled = true; } if (!keepToken) { if (!handled) { SWLog::getSystemLog()->logError("Unprocessed Token: <%s> in key %s", token, key ? (const char*)*key : "<unknown>"); // exit(-1); } if (from[1] && strchr(" ,;.:?!()'\"", from[1])) { if (lastspace) { text--; } } if (newText) { textStart = from+1; newText = false; } continue; } // if not a strongs token, keep token in text text.appendFormatted("<%s>", token); if (newText) { textStart = text.c_str() + text.length(); newWord = false; } continue; } if (intoken) { if ((tokpos < 2045) && ((*from != 10)&&(*from != 13))) { token[tokpos++] = *from; token[tokpos+2] = 0; } } else { switch (*from) { case '\'': case '\"': case '`': // quoteStack.handleQuote(fromStart, from, &to); text += *from; //from++; //this line removes chars after an apostrophe! Needs fixing. break; default: if (newWord && (*from != ' ')) { wordStart = text.c_str() + text.length(); newWord = false; //fix this if required? //memset(to, 0, 10); } if (!suspendTextPassThru) { text += (*from); lastspace = (*from == ' '); } } } } VerseKey *vkey = SWDYNAMIC_CAST(VerseKey, key); if (vkey) { SWBuf ref = ""; if (vkey->getVerse()) { ref.appendFormatted("\t\t<verse osisID=\"%s\">", vkey->getOSISRef()); } if (ref.length() > 0) { text = ref + text; if (vkey->getVerse()) { VerseKey *tmp = (VerseKey *)vkey->clone(); *tmp = *vkey; tmp->setAutoNormalize(false); tmp->setIntros(true); text += "</verse>"; *tmp = MAXVERSE; if (*vkey == *tmp) { tmp->setVerse(0); // sprintf(ref, "\t</div>"); // pushString(&to, ref); *tmp = MAXCHAPTER; *tmp = MAXVERSE; if (*vkey == *tmp) { tmp->setChapter(0); tmp->setVerse(0); // sprintf(ref, "\t</div>"); // pushString(&to, ref); /* if (!quoteStack.empty()) { SWLog::getSystemLog()->logError("popping unclosed quote at end of book"); quoteStack.clear(); } */ } } delete tmp; } // else if (vkey->Chapter()) { // sprintf(ref, "\t<div type=\"chapter\" osisID=\"%s\">", vkey->getOSISRef()); // } // else sprintf(ref, "\t<div type=\"book\" osisID=\"%s\">", vkey->getOSISRef()); } } return 0; }
char zVerse::createModule(const char *ipath, int blockBound, const char *v11n) { char *path = 0; char *buf = new char [ strlen (ipath) + 20 ]; char retVal = 0; FileDesc *fd, *fd2; __s32 offset = 0; __s16 size = 0; VerseKey vk; stdstr(&path, ipath); if ((path[strlen(path)-1] == '/') || (path[strlen(path)-1] == '\\')) path[strlen(path)-1] = 0; sprintf(buf, "%s/ot.%czs", path, uniqueIndexID[blockBound]); FileMgr::removeFile(buf); fd = FileMgr::getSystemFileMgr()->open(buf, FileMgr::CREAT|FileMgr::WRONLY, FileMgr::IREAD|FileMgr::IWRITE); if (fd->getFd() < 1) goto erroropen1; FileMgr::getSystemFileMgr()->close(fd); sprintf(buf, "%s/nt.%czs", path, uniqueIndexID[blockBound]); FileMgr::removeFile(buf); fd = FileMgr::getSystemFileMgr()->open(buf, FileMgr::CREAT|FileMgr::WRONLY, FileMgr::IREAD|FileMgr::IWRITE); if (fd->getFd() < 1) goto erroropen1; FileMgr::getSystemFileMgr()->close(fd); sprintf(buf, "%s/ot.%czz", path, uniqueIndexID[blockBound]); FileMgr::removeFile(buf); fd = FileMgr::getSystemFileMgr()->open(buf, FileMgr::CREAT|FileMgr::WRONLY, FileMgr::IREAD|FileMgr::IWRITE); if (fd->getFd() < 1) goto erroropen1; FileMgr::getSystemFileMgr()->close(fd); sprintf(buf, "%s/nt.%czz", path, uniqueIndexID[blockBound]); FileMgr::removeFile(buf); fd = FileMgr::getSystemFileMgr()->open(buf, FileMgr::CREAT|FileMgr::WRONLY, FileMgr::IREAD|FileMgr::IWRITE); if (fd->getFd() < 1) goto erroropen1; FileMgr::getSystemFileMgr()->close(fd); sprintf(buf, "%s/ot.%czv", path, uniqueIndexID[blockBound]); FileMgr::removeFile(buf); fd = FileMgr::getSystemFileMgr()->open(buf, FileMgr::CREAT|FileMgr::WRONLY, FileMgr::IREAD|FileMgr::IWRITE); if (fd->getFd() < 1) goto erroropen1; sprintf(buf, "%s/nt.%czv", path, uniqueIndexID[blockBound]); FileMgr::removeFile(buf); fd2 = FileMgr::getSystemFileMgr()->open(buf, FileMgr::CREAT|FileMgr::WRONLY, FileMgr::IREAD|FileMgr::IWRITE); if (fd2->getFd() < 1) goto erroropen2; vk.setVersificationSystem(v11n); vk.setIntros(true); offset = archtosword32(offset); size = archtosword16(size); for (vk = TOP; !vk.popError(); vk++) { if (vk.getTestament() < 2) { if (fd->write(&offset, 4) != 4) goto writefailure; //compBufIdxOffset if (fd->write(&offset, 4) != 4) goto writefailure; if (fd->write(&size, 2) != 2) goto writefailure; } else { if (fd2->write(&offset, 4) != 4) goto writefailure; //compBufIdxOffset if (fd2->write(&offset, 4) != 4) goto writefailure; if (fd2->write(&size, 2) != 2) goto writefailure; } } fd2->write(&offset, 4); //compBufIdxOffset fd2->write(&offset, 4); fd2->write(&size, 2); goto cleanup; erroropen1: retVal = -1; goto cleanup1; erroropen2: retVal = -1; goto cleanup; writefailure: retVal = -2; cleanup: FileMgr::getSystemFileMgr()->close(fd2); cleanup1: FileMgr::getSystemFileMgr()->close(fd); delete [] path; delete [] buf; return retVal; }
int main(int argc, char **argv) { SWCipher *zobj; VerseKey key; RawVerse *rawdrv; int ofd[2], oxfd[2]; long tmpoff = 0, offset, loffset = 0, lzoffset = 0; unsigned short size, lsize = 0, lzsize; char *tmpbuf; if (argc != 3) { fprintf(stderr, "usage: %s <datapath> \"<key>\"\n", argv[0]); exit(1); } rawdrv = new RawVerse(argv[1]); zobj = new SWCipher((unsigned char *)argv[2]); tmpbuf = new char [ strlen(argv[1]) + 11 ]; sprintf(tmpbuf, "%sot.zzz", argv[1]); ofd[0] = FileMgr::createPathAndFile(tmpbuf); sprintf(tmpbuf, "%sot.zzz.vss", argv[1]); oxfd[0] = FileMgr::createPathAndFile(tmpbuf); sprintf(tmpbuf, "%snt.zzz", argv[1]); ofd[1] = FileMgr::createPathAndFile(tmpbuf); sprintf(tmpbuf, "%snt.zzz.vss", argv[1]); oxfd[1] = FileMgr::createPathAndFile(tmpbuf); delete [] tmpbuf; printf("\n"); write(oxfd[0], &lzoffset, 4); write(oxfd[0], &lzsize, 2); write(oxfd[1], &lzoffset, 4); write(oxfd[1], &lzsize, 2); key.setAutoNormalize(false); key.setIntros(true); for (key.setIndex(0); (!key.popError()); key++) { rawdrv->findOffset(key.getTestament(), key.getIndex(), &offset, &size); printf("%s: OLD offset: %ld; size: %d\n", (const char *)key, offset, size); if ((offset == loffset) && (size == lsize)) { printf("using previous offset,size %d\n", size); offset = lseek(oxfd[key.getTestament() - 1], 0, SEEK_CUR); printf("%ld %ld %d \n", offset, lzoffset, lzsize); write(oxfd[key.getTestament() - 1], &lzoffset, 4); write(oxfd[key.getTestament() - 1], &lzsize, 2); } else { lsize = size; loffset = offset; if (size) { SWBuf tmpbuf; rawdrv->readText(key.getTestament(), offset, size, tmpbuf); zobj->Buf(tmpbuf.c_str(), size); unsigned long ulSize = size; zobj->cipherBuf(&ulSize); size = (unsigned int)ulSize; } offset = lseek(ofd[key.getTestament() - 1], 0, SEEK_CUR); tmpoff = lseek(oxfd[key.getTestament() - 1], 0, SEEK_CUR); printf("%s: (%ld) NEW offset: %ld; size: %d\n", (const char *)key, tmpoff, offset, size); write(oxfd[key.getTestament() - 1], &offset, 4); unsigned long ulSize = size; if (size) write(ofd[key.getTestament() - 1], zobj->cipherBuf(&ulSize), size); size = (unsigned int)ulSize; lzoffset = offset; write(oxfd[key.getTestament() - 1], &size, 2); lzsize = size; } } delete zobj; close(ofd[0]); close(oxfd[0]); close(ofd[1]); close(oxfd[1]); return 0; }
int main(int argc, char **argv) { // Let's test our command line arguments if (argc < 2) { // fprintf(stderr, "usage: %s <vpl_file> </path/to/mod> [0|1 - file includes prepended verse references]\n", argv[0]); fprintf(stderr, "usage: %s <source_vpl_file> </path/to/output/mod/> [0|1 - prepended verse refs] [0|1 - NT only]\n\n", argv[0]); fprintf(stderr, "\tWARNING: THIS IS CURRENTLY A KJV-VERSIFICATION-ONLY UTILITY\n"); fprintf(stderr, "\tWith no verse refs, source file must contain exactly 31102 lines.\n"); fprintf(stderr, "\tThis is KJV verse count plus headings for MODULE,\n"); fprintf(stderr, "\tTESTAMENT, BOOK, CHAPTER. An example snippet follows:\n\n"); fprintf(stderr, "\t\tMODULE HEADER\n"); fprintf(stderr, "\t\tOLD TESTAMENT HEADER\n"); fprintf(stderr, "\t\tGENESIS HEADER\n"); fprintf(stderr, "\t\tCHAPTER 1 HEADER\n"); fprintf(stderr, "\t\tIn the beginning...\n\n"); fprintf(stderr, "\t... implying there must also be a CHAPTER2 HEADER,\n"); fprintf(stderr, "\tEXODUS HEADER, NEW TESTAMENT HEADER, etc. If there is no text for\n"); fprintf(stderr, "\tthe header, a blank line must, at least, hold place.\n\n"); fprintf(stderr, "\tWith verse refs, source file must simply contain any number of lines,\n"); fprintf(stderr, "\tthat begin with the verse reference for which it is an entry. e.g.:\n\n"); fprintf(stderr, "\t\tgen 1:0 CHAPTER 1 HEADER\n"); fprintf(stderr, "\t\tgen 1:1 In the beginning...\n\n"); exit(-1); } // Let's see if we can open our input file int fd = FileMgr::openFileReadOnly(argv[1]); if (fd < 0) { fprintf(stderr, "error: %s: couldn't open input file: %s \n", argv[0], argv[1]); exit(-2); } // Try to initialize a default set of datafiles and indicies at our // datapath location passed to us from the user. if (RawText::createModule(argv[2])) { fprintf(stderr, "error: %s: couldn't create module at path: %s \n", argv[0], argv[2]); exit(-3); } // not used yet, but for future support of a vpl file with each line // prepended with verse reference, eg. "Gen 1:1 In the beginning..." bool vref = false; if (argc > 3) vref = (argv[3][0] == '0') ? false : true; // if 'nt' is the 4th arg, our vpl file only has the NT bool ntonly = false; if (argc > 4) ntonly = (argv[4][0] == '0') ? false : true; // Do some initialization stuff char *buffer = 0; RawText mod(argv[2]); // open our datapath with our RawText driver. VerseKey vk; vk.setAutoNormalize(false); vk.setIntros(true); // turn on mod/testmnt/book/chap headings vk.setPersist(true); mod.setKey(vk); // Loop through module from TOP to BOTTOM and set next line from // input file as text for this entry in the module mod = TOP; if (ntonly) vk = "Matthew 1:1"; int successive = 0; //part of hack below while ((!mod.popError()) && (!readline(fd, &buffer))) { if (*buffer == '|') // comments, ignore line continue; if (vref) { const char *verseText = parseVReg(buffer); if (!verseText) { // if we didn't find a valid verse ref std::cerr << "No valid verse ref found on line: " << buffer << "\n"; exit(-4); } vk = buffer; if (vk.popError()) { std::cerr << "Error parsing key: " << buffer << "\n"; exit(-5); } string orig = mod.getRawEntry(); if (!isKJVRef(buffer)) { VerseKey origVK = vk; /* This block is functioning improperly -- problem with AutoNormalize??? do { vk--; } while (!vk.popError() && !isKJVRef(vk)); */ //hack to replace above: successive++; vk -= successive; orig = mod.getRawEntry(); std::cerr << "Not a valid KJV ref: " << origVK << "\n"; std::cerr << "appending to ref: " << vk << "\n"; orig += " [ ("; orig += origVK; orig += ") "; orig += verseText; orig += " ] "; verseText = orig.c_str(); } else { successive = 0; } if (orig.length() > 1) std::cerr << "Warning, overwriting verse: " << vk << std::endl; // ------------- End verse tests ----------------- mod << verseText; // save text to module at current position } else { fixText(buffer); mod << buffer; // save text to module at current position mod++; // increment module position } } // clear up our buffer that readline might have allocated if (buffer) delete [] buffer; }
int main(int argc, char **argv) { BlockType iType = BOOKBLOCKS; int compType = 1; string cipherKey = ""; std::unique_ptr<SWCompress> compressor; int compLevel = 0; if ((argc < 3) || (argc > 7)) { errorOutHelp(argv[0]); } if (argc > 3) { switch (std::atoi(argv[3])) { case 2: iType = VERSEBLOCKS; break; case 3: iType = CHAPTERBLOCKS; break; case 4: iType = BOOKBLOCKS; break; default: std::cerr << "Argument 3 must be one of <2|3|4>\n"; errorOutHelp(*argv); } if (argc > 4) { compType = std::atoi(argv[4]); if (argc > 5) { compLevel = std::atoi(argv[5]); if (argc > 6) { cipherKey = argv[6]; } } } } if ((iType < 2) || (compType < 1) || (compType > 4) || compLevel < 0 || compLevel > 9 || (!std::strcmp(argv[1], "-h")) || (!std::strcmp(argv[1], "--help")) || (!std::strcmp(argv[1], "/?")) || (!std::strcmp(argv[1], "-?")) || (!std::strcmp(argv[1], "-help"))) { errorOutHelp(argv[0]); } SWMgr mgr; auto const it = mgr.modules().find(argv[1]); if (it == mgr.modules().end()) { fprintf(stderr, "error: %s: couldn't find module: %s\n", argv[0], argv[1]); std::exit(-2); } SWModule & inModule = *it->second; // Try to initialize a default set of datafiles and indicies at our // datapath location passed to us from the user. #define BIBLE 1 #define LEX 2 #define COM 3 int modType = 0; if (inModule.getType() == "Biblical Texts") { modType = BIBLE; } else if (inModule.getType() == "Lexicons / Dictionaries") { modType = LEX; } else if (inModule.getType() == "Commentaries") { modType = COM; } switch (compType) { // these are deleted by zText case 1: compressor = std::make_unique<LZSSCompress>(); break; case 2: compressor = std::make_unique<ZipCompress>(); break; case 3: compressor = std::make_unique<Bzip2Compress>(); break; case 4: compressor = std::make_unique<XzCompress>(); break; } if (compressor && compLevel > 0) { compressor->setLevel(compLevel); } int result = 0; switch (modType) { case BIBLE: case COM: { SWKey *k = inModule.getKey(); VerseKey *vk = dynamic_cast<VerseKey *>(k); result = zText::createModule(argv[2], iType, vk->getVersificationSystem().c_str()); break; } case LEX: result = zLD::createModule(argv[2]); break; } if (result) { fprintf(stderr, "error: %s: couldn't create module at path: %s\n", argv[0], argv[2]); std::exit(-3); } std::unique_ptr<SWModule> outModule; switch (modType) { case BIBLE: case COM: { SWKey *k = inModule.getKey(); VerseKey *vk = dynamic_cast<VerseKey *>(k); outModule = std::make_unique<zText>(argv[2], nullptr, nullptr, iType, std::move(compressor), ENC_UNKNOWN, DIRECTION_LTR, FMT_UNKNOWN, nullptr, vk->getVersificationSystem().c_str()); // open our datapath with our RawText driver. static_cast<VerseKey *>(inModule.getKey())->setIntros(true); break; } case LEX: outModule = std::make_unique<zLD>(argv[2], nullptr, nullptr, iType, std::move(compressor)); // open our datapath with our RawText driver. break; } if (!cipherKey.empty()) outModule->addRawFilter( std::make_shared<CipherFilter>(cipherKey.c_str())); string lastBuffer = "Something that would never be first module entry"; SWKey bufferKey; SWKey lastBufferKey; auto const outModuleKey(outModule->createKey()); VerseKey *vkey = dynamic_cast<VerseKey *>(outModuleKey.get()); outModuleKey->setPersist(true); if (vkey) { vkey->setIntros(true); vkey->setAutoNormalize(false); } outModule->setKey(*outModuleKey); inModule.setSkipConsecutiveLinks(false); inModule.positionToTop(); while (!inModule.popError()) { bufferKey.positionFrom(*inModule.getKey()); // pseudo-check for link. Will get most common links. if ((lastBuffer == inModule.getRawEntry()) &&(lastBuffer.length() > 0)) { outModuleKey->positionFrom(bufferKey); outModule->linkEntry(lastBufferKey); // link to last key cout << "Adding [" << bufferKey.getText() << "] link to: [" << lastBufferKey.getText() << "]\n"; } else { lastBuffer = inModule.getRawEntry(); lastBufferKey.setText(inModule.getKeyText()); if (lastBuffer.length() > 0) { cout << "Adding [" << bufferKey.getText() << "] new text.\n"; outModuleKey->positionFrom(bufferKey); // outModule->getRawEntry(); // snap // outModule->setKey(bufferKey); outModule->setEntry(lastBuffer.c_str()); // save new text; } else { cout << "Skipping [" << bufferKey.getText() << "] no entry in Module.\n"; } } inModule.increment(); } }
int main(int argc, char **argv) { int loop; int max; VerseKey yo("Gen.1.1", "Gen.1.2"); std::cout << yo.getRangeText(); if (argc > 1) LocaleMgr::getSystemLocaleMgr()->setDefaultLocaleName(argv[1]); VerseKey bla; long index; if (argc < 2) bla = "James 1:19"; else bla = argv[2]; std::cout << "\n Headings: " << (bool)bla.isIntros() << "\n"; std::cout << " (.Index(Index()+1))\n"; max = (argc < 4) ? 10 : atoi(argv[3]); for (loop = 0; loop < max; loop++) { index = bla.getIndex(); std::cout << (const char *)bla << "(" << index << ")"; bla.setIndex(index+1); std::cout << "-> " << (const char *)bla << "\n"; } std::cout << "-----------------\n"; std::cout << "\n (.Index(Index()-1))\n"; if (argc < 2) bla = "James 1:19"; else bla = argv[2]; for (loop = max; loop; loop--) { index = bla.getIndex(); std::cout << (const char *)bla << "(" << index << ")"; bla.setIndex(index-1); std::cout << "-> " << (const char *)bla << "\n"; } std::cout << "-----------------\n"; bla.setIntros(true); std::cout << "\n Headings: " << (bool)bla.isIntros() << "\n"; std::cout << " key++\n"; if (argc < 2) bla = "Matthew 1:5"; else bla = argv[2]; for (loop = 0; loop < max && !bla.popError(); loop++,bla++) { index = bla.getIndex(); std::cout << (const char *)bla << "(" << index << ")\n"; } std::cout << "-----------------\n"; bla.setIntros(true); std::cout << "\n Headings: " << (bool)bla.isIntros() << "\n"; std::cout << " key--\n"; if (argc < 2) bla = "Matthew 1:5"; else bla = argv[2]; for (loop = max; loop && !bla.popError(); loop--, bla--) { index = bla.getIndex(); std::cout << (const char *)bla << "(" << index << ")\n"; } std::cout << "-----------------\n"; if (argc < 2) bla = "Genesis 1:5"; else bla = argv[2]; for (loop = max; loop; loop--, bla--) { index = bla.getIndex(); std::cout << (const char *)bla << "(" << index << ")\n"; } std::cout << "-----------------\n"; if (argc < 2) bla = "Malachi 4:2"; else bla = argv[2]; for (loop = max; loop; loop--, bla++) { index = bla.getIndex(); std::cout << (const char *)bla << "(" << index << ")\n"; } std::cout << "-----------------\n"; if (argc < 2) bla = "Revelation of John 22:17"; else bla = argv[2]; for (loop = max; loop; loop--, bla++) { index = bla.getIndex(); std::cout << (const char *)bla << "(" << index << ")\n"; } std::cout << "-----------------\n"; std::cout << "-------- Headings ---------\n"; bla.setIntros(true); if (argc < 2) bla = "Matthew 1:5"; else bla = argv[2]; for (loop = max; loop; loop--, bla--) { index = bla.getIndex(); std::cout << (const char *)bla << "(" << index << ")\n"; } std::cout << "-----------------\n"; if (argc < 2) bla = "Genesis 1:5"; else bla = argv[2]; for (loop = max; loop; loop--, bla--) { index = bla.getIndex(); std::cout << (const char *)bla << "(" << index << ")\n"; } std::cout << "-----------------\n"; if (argc < 2) bla = "Malachi 4:2"; else bla = argv[2]; for (loop = max; loop; loop--, bla++) { index = bla.getIndex(); std::cout << (const char *)bla << "(" << index << ")\n"; } std::cout << "-----------------\n"; if (argc < 2) bla = "Revelation of John 22:17"; else bla = argv[2]; for (loop = max; loop; loop--, bla++) { index = bla.getIndex(); std::cout << (const char *)bla << "(" << index << ")\n"; } std::cout << "\n\n"; std::cout << "-------- Error Check ------------\n\n"; bla = "Revelation of John 23:19"; std::cout << "bla = \"Revelation of John 23:19\"\n"; std::cout << "(const char *)bla = " << (const char *)bla << "\n"; std::cout << "bla.popError() = " << (int)bla.popError() << " \n"; std::cout << "bla++ \n"; bla++; std::cout << "bla.popError() = " << (int)bla.popError() << " \n"; bla.setIntros(false); for (bla = BOTTOM; !bla.popError(); bla.setBook(bla.getBook()-1)) std::cout << (const char *)bla << "\n"; bla.setTestament(1); bla = BOTTOM; std::cout << bla.getTestamentIndex() << "\n"; std::cout << bla.getIndex() << "\n"; std::cout << bla << "\n"; bla.setTestament(2); bla = BOTTOM; std::cout << bla.getTestamentIndex() << "\n"; std::cout << bla.getIndex() << "\n"; std::cout << bla << "\n"; return 0; }
int main(int argc, char **argv) { SWMgr mymgr; RawText::createModule("."); RawText mod("."); VerseKey vk; vk.setIntros(true); vk.setAutoNormalize(false); vk.setPersist(true); mod.setKey(vk); vk.setVerse(0); vk.setChapter(0); vk.setBook(0); vk.setTestament(0); mod << "Module heading text"; vk.setVerse(0); vk.setChapter(0); vk.setBook(0); vk.setTestament(1); mod << "OT heading text"; vk.setTestament(1); vk.setBook(1); vk.setChapter(0); vk.setVerse(0); mod << "Gen heading text"; vk.setTestament(1); vk.setBook(1); vk.setChapter(1); vk.setVerse(0); mod << "Gen 1 heading text"; vk.setTestament(1); vk.setBook(1); vk.setChapter(1); vk.setVerse(1); mod << "Gen 1:1 text"; vk.setTestament(0); vk.setBook(0); vk.setChapter(0); vk.setVerse(0); std::cout << "Module heading text ?= " << (const char*)mod << std::endl; vk.setTestament(1); vk.setBook(0); vk.setChapter(0); vk.setVerse(0); std::cout << "OT heading text ?= " << (const char*)mod << std::endl; vk.setTestament(1); vk.setBook(1); vk.setChapter(0); vk.setVerse(0); std::cout << "Gen heading text ?= " << (const char*)mod << std::endl; vk.setTestament(1); vk.setBook(1); vk.setChapter(1); vk.setVerse(0); std::cout << "Gen 1 heading text ?= " << (const char*)mod << std::endl; vk.setTestament(1); vk.setBook(1); vk.setChapter(1); vk.setVerse(1); std::cout << "Gen 1:1 text ?= " << (const char*)mod << std::endl; /* old introtest SWModule *mhc = mymgr.Modules["MHC"]; if (mhc) { VerseKey vk; vk.setIntros(true); vk.setAutoNormalize(false); vk.setPersist(true); vk = "jas 0:0"; std::cout << vk << ":\n"; mhc->setKey(vk); std::cout << (const char *) mhc->Key() << ":\n"; std::cout << (const char *) *mhc << "\n"; } */ return 0; }
int main(int argc, char **argv) { const char * helptext = "addvs 1.1 Bible & Commentary module creation tool for the SWORD Project\nUse -a to add a new verse from standard input or a file, -d to delete a verse,\n-l to link two verses, -c to create a new module.\n usage:\n %s -a </path/to/module> <verse> [</path/to/file/with/verse>]\n %s -d </path/to/module> <key>\n %s -l </path/to/module> <first verse (already assigned)> <second verse>\n %s -c </path/to/module>\n"; long entrysize; if (argc < 3) { fprintf(stderr, helptext, argv[0], argv[0], argv[0], argv[0]); exit(-1); } if (!strcmp(argv[1], "-a") && (argc == 4 || argc == 5)) { // Do some initialization stuff char buffer[65536]; //this is the max size of any entry RawText * mod = new RawText(argv[2]); // open our datapath with our RawText driver. VerseKey *vkey = new VerseKey; vkey->setIntros(true); vkey->setAutoNormalize(false); vkey->setPersist(true); // the magical setting *vkey = argv[3]; // Set our VerseKey mod->setKey(*vkey); if (!vkey->getChapter()) { // bad hack >> // 0:0 is Book intro // (chapter):0 is Chapter intro // // 0:2 is Module intro // 0:1 is Testament intro int backstep = vkey->getVerse(); vkey->setVerse(0); *mod -= backstep; // << bad hack FILE *infile; // case: add from text file //Open our data file and read its contents into the buffer if (argc == 5) infile = fopen(argv[4], "r"); // case: add from stdin else infile = stdin; entrysize = fread(buffer, sizeof(char), sizeof(buffer), infile); mod->setEntry(buffer, entrysize); // save text to module at current position } else { ListKey listkey = vkey->parseVerseList(argv[3], "Gen1:1", true); int i; bool havefirst = false; VerseKey firstverse; for (i = 0; i < listkey.getCount(); i++) { VerseKey *element = SWDYNAMIC_CAST(VerseKey, listkey.getElement(i)); if (element) { mod->setKey(element->getLowerBound()); VerseKey finalkey = element->getUpperBound(); std::cout << mod->getKeyText() << "-" << (const char*)finalkey << std::endl; if (!havefirst) { havefirst = true; firstverse = *mod->getKey(); FILE *infile; // case: add from text file //Open our data file and read its contents into the buffer if (argc == 5) infile = fopen(argv[4], "r"); // case: add from stdin else infile = stdin; entrysize = fread(buffer, sizeof(char), sizeof(buffer), infile); mod->setEntry(buffer, entrysize); // save text to module at current position std::cout << "f" << (const char*)firstverse << std::endl; (*mod)++; } while (*mod->getKey() <= finalkey) { std::cout << mod->getKeyText() << std::endl; *(SWModule*)mod << &firstverse; (*mod)++; } } else { if (havefirst) { mod->setKey(*listkey.getElement(i)); *(SWModule*)mod << &firstverse; std::cout << mod->getKeyText() << std::endl; } else { mod->setKey(*listkey.getElement(i)); havefirst = true; firstverse = *mod->getKey(); FILE *infile; // case: add from text file //Open our data file and read its contents into the buffer if (argc == 5) infile = fopen(argv[4], "r"); // case: add from stdin else infile = stdin; entrysize = fread(buffer, sizeof(char), sizeof(buffer), infile); mod->setEntry(buffer, entrysize); // save text to module at current position std::cout << "f" << (const char*)firstverse << std::endl; } } } } delete vkey; } // Link 2 verses else if (!strcmp(argv[1], "-l") && argc == 5) { // Do some initialization stuff RawText *mod = new RawText(argv[2]); // open our datapath with our RawText driver. mod->setKey(argv[4]); // set key from argument SWKey tmpkey = (SWKey) argv[3]; *(SWModule*)mod << &(tmpkey); delete mod; } else if (!strcmp(argv[1], "-d") && argc == 4) { RawText mod(argv[2]); // open our datapath with our RawText driver. VerseKey *vkey = new VerseKey; vkey->setIntros(true); vkey->setAutoNormalize(false); vkey->setPersist(true); // the magical setting // Set our VerseKey mod.setKey(*vkey); *vkey = argv[3]; if (!vkey->getChapter()) { // bad hack >> // 0:0 is Book intro // (chapter):0 is Chapter intro // // 0:2 is Module intro // 0:1 is Testament intro int backstep = vkey->getVerse(); vkey->setVerse(0); mod -= backstep; // << bad hack } mod.deleteEntry(); delete vkey; } // Make a new module else if (!strcmp(argv[1], "-c") && argc == 3) { // Try to initialize a default set of datafiles and indicies at our // datapath location passed to us from the user. if (RawText::createModule(argv[2])) { fprintf(stderr, "error: %s: couldn't create module at path: %s \n", argv[0], argv[2]); exit(-2); } } // Bad arguments, print usage else { fprintf(stderr, helptext, argv[0], argv[0], argv[0], argv[0]); exit(-1); } }