void writeEntry(SWModule & module, std::string const & key, std::string const & entry, bool const replace) { if (key.size() && entry.size()) { std::cout << "from file: " << key << std::endl; VerseKey *vkey = (VerseKey *)module.getKey(); std::unique_ptr<VerseKey> linkMaster( static_cast<VerseKey *>(module.createKey().release())); ListKey listKey = vkey->parseVerseList(key.c_str(), "Gen1:1", true); bool first = true; for (listKey.positionToTop(); !listKey.popError(); listKey.increment()) { vkey->positionFrom(listKey); if (first) { *linkMaster = *vkey; std::string text; if (!replace) text = module.getRawEntry(); text += entry; std::cout << "adding entry: " << vkey->getText() << " length " << entry.size() << "/" << (unsigned short)text.size() << std::endl; module.setEntry(text.c_str()); first = false; } else { std::cout << "linking entry: " << vkey->getText() << " to " << linkMaster->getText() << std::endl; module.linkEntry(*linkMaster); } } } }
int main(int argc, char **argv) { const char *range = (argc > 1) ? argv[1] : "Mat 2:10,12-15"; VerseKey parser; ListKey result; result = parser.parseVerseList(range, parser.getText().c_str(), true); // let's iterate the key and display for (result.positionToTop(); !result.popError(); result.increment()) { cout << result.getText() << "\n"; } cout << endl; // Now let's output a module with the entries from the result // we'll initialize our library of books SWMgr library(std::make_shared<MarkupFilterMgr>(FMT_PLAIN)); // render plain without fancy markup // Let's get a book; auto const book(library.getModule("KJV")); // couldn't find our test module if (!book) return -1; // now let's iterate the book and display for (result.positionToTop(); !result.popError(); result.increment()) { book->setKey(result); cout << "*** " << book->getKeyText() << ": " << book->renderText() << "\n"; } return 0; }
int main() { SWMgr library; auto const book(library.getModule("KJV")); VerseKey *vk = (VerseKey *) book->getKey(); for (;!vk->popError();vk->setChapter(vk->getChapter()+1)) { vk->setVerse(vk->getVerseMax()); std::string text = book->stripText(); trimString(text); if (!text.empty() && (*text.rbegin()) == ',') { cout << vk->getText() << ":\n\n"; cout << text << endl; } } return 0; }
int main(int argc, char **argv) { SWMgr library; SWModule *book = library.getModule("KJV"); VerseKey *vk = (VerseKey *) book->getKey(); for (;!vk->popError();vk->setChapter(vk->getChapter()+1)) { vk->setVerse(vk->getVerseMax()); SWBuf text = book->stripText(); text = text.trim(); if (text.endsWith(",")) { cout << vk->getText() << ":\n\n"; cout << text << 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(); } } }
bool OSISHTMLHREF::handleToken(SWBuf &buf, const char *token, BasicFilterUserData *userData) { MyUserData *u = (MyUserData *)userData; SWBuf scratch; bool sub = (u->suspendTextPassThru) ? substituteToken(scratch, token) : substituteToken(buf, token); if (!sub) { // manually process if it wasn't a simple substitution XMLTag tag(token); // <w> tag if (!strcmp(tag.getName(), "w")) { // start <w> tag if ((!tag.isEmpty()) && (!tag.isEndTag())) { u->w = token; } // end or empty <w> tag else { bool endTag = tag.isEndTag(); SWBuf lastText; //bool show = true; // to handle unplaced article in kjv2003-- temporary till combined if (endTag) { tag = u->w.c_str(); lastText = u->lastTextNode.c_str(); } else lastText = "stuff"; const char *attrib; const char *val; if ((attrib = tag.getAttribute("xlit"))) { val = strchr(attrib, ':'); val = (val) ? (val + 1) : attrib; outText(" ", buf, u); outText(val, buf, u); } if ((attrib = tag.getAttribute("gloss"))) { // I'm sure this is not the cleanest way to do it, but it gets the job done // for rendering ruby chars properly ^_^ buf -= lastText.length(); outText("<ruby><rb>", buf, u); outText(lastText, buf, u); val = strchr(attrib, ':'); val = (val) ? (val + 1) : attrib; outText("</rb><rp>(</rp><rt>", buf, u); outText(val, buf, u); outText("</rt><rp>)</rp></ruby>", buf, u); } if (!morphFirst) { processLemma(u->suspendTextPassThru, tag, buf); processMorph(u->suspendTextPassThru, tag, buf); } else { processMorph(u->suspendTextPassThru, tag, buf); processLemma(u->suspendTextPassThru, tag, buf); } if ((attrib = tag.getAttribute("POS"))) { val = strchr(attrib, ':'); val = (val) ? (val + 1) : attrib; outText(" ", buf, u); outText(val, buf, u); } /*if (endTag) buf += "}";*/ } } // <note> tag else if (!strcmp(tag.getName(), "note")) { if (!tag.isEndTag()) { SWBuf type = tag.getAttribute("type"); bool strongsMarkup = (type == "x-strongsMarkup" || type == "strongsMarkup"); // the latter is deprecated if (strongsMarkup) { tag.setEmpty(false); // handle bug in KJV2003 module where some note open tags were <note ... /> } if (!tag.isEmpty()) { if (!strongsMarkup) { // leave strong's markup notes out, in the future we'll probably have different option filters to turn different note types on or off SWBuf footnoteNumber = tag.getAttribute("swordFootnote"); SWBuf noteName = tag.getAttribute("n"); VerseKey *vkey = NULL; char ch = ((tag.getAttribute("type") && ((!strcmp(tag.getAttribute("type"), "crossReference")) || (!strcmp(tag.getAttribute("type"), "x-cross-ref")))) ? 'x':'n'); u->inXRefNote = true; // Why this change? Ben Morgan: Any note can have references in, so we need to set this to true for all notes // u->inXRefNote = (ch == 'x'); // see if we have a VerseKey * or descendant SWTRY { vkey = SWDYNAMIC_CAST(VerseKey, u->key); } SWCATCH ( ... ) { } buf.appendFormatted("<a href=\"passagestudy.jsp?action=showNote&type=%c&value=%s&module=%s&passage=%s\"><small><sup class=\"%c\">*%c%s</sup></small></a>", ch, URL::encode(footnoteNumber.c_str()).c_str(), URL::encode(u->version.c_str()).c_str(), URL::encode(vkey ? vkey->getText() : u->key->getText()).c_str(), ch, ch, (renderNoteNumbers ? noteName.c_str() : "")); } } u->suspendTextPassThru = (++u->suspendLevel); }
bool GBFXHTML::handleToken(SWBuf &buf, const char *token, BasicFilterUserData *userData) { const char *tok; MyUserData *u = (MyUserData *)userData; if (!substituteToken(buf, token)) { XMLTag tag(token); if (!strncmp(token, "WG", 2)) { // strong's numbers //buf += " <small><em><<a href=\"type=Strongs value="; buf += " <small><em class=\"strongs\"><<a href=\"passagestudy.jsp?action=showStrongs&type=Greek&value="; for (tok = token+2; *tok; tok++) //if(token[i] != '\"') buf += *tok; buf += "\" class=\"strongs\">"; for (tok = token + 2; *tok; tok++) //if(token[i] != '\"') buf += *tok; buf += "</a>></em></small>"; } else if (!strncmp(token, "WH", 2)) { // strong's numbers //buf += " <small><em><<a href=\"type=Strongs value="; buf += " <small><em class=\"strongs\"><<a href=\"passagestudy.jsp?action=showStrongs&type=Hebrew&value="; for (tok = token+2; *tok; tok++) //if(token[i] != '\"') buf += *tok; buf += "\" class=\"strongs\">"; for (tok = token + 2; *tok; tok++) //if(token[i] != '\"') buf += *tok; buf += "</a>></em></small>"; } else if (!strncmp(token, "WTG", 3)) { // strong's numbers tense //buf += " <small><em>(<a href=\"type=Strongs value="; buf += " <small><em class=\"strongs\">(<a href=\"passagestudy.jsp?action=showStrongs&type=Greek&value="; for (tok = token + 3; *tok; tok++) if(*tok != '\"') buf += *tok; buf += "\" class=\"strongs\">"; for (tok = token + 3; *tok; tok++) if(*tok != '\"') buf += *tok; buf += "</a>)</em></small>"; } else if (!strncmp(token, "WTH", 3)) { // strong's numbers tense //buf += " <small><em>(<a href=\"type=Strongs value="; buf += " <small><em class=\"strongs\">(<a href=\"passagestudy.jsp?action=showStrongs&type=Hebrew&value="; for (tok = token + 3; *tok; tok++) if(*tok != '\"') buf += *tok; buf += "\" class=\"strongs\">"; for (tok = token + 3; *tok; tok++) if(*tok != '\"') buf += *tok; buf += "</a>)</em></small>"; } else if (!strncmp(token, "WT", 2) && strncmp(token, "WTH", 3) && strncmp(token, "WTG", 3)) { // morph tags //buf += " <small><em>(<a href=\"type=morph class=none value="; buf += " <small><em class=\"morph\">(<a href=\"passagestudy.jsp?action=showMorph&type=Greek&value="; for (tok = token + 2; *tok; tok++) if(*tok != '\"') buf += *tok; buf += "\" class=\"morph\">"; for (tok = token + 2; *tok; tok++) if(*tok != '\"') buf += *tok; buf += "</a>)</em></small>"; } else if (!strcmp(tag.getName(), "RX")) { buf += "<a href=\""; for (tok = token + 3; *tok; tok++) { if(*tok != '<' && *tok+1 != 'R' && *tok+2 != 'x') { buf += *tok; } else { break; } } buf += "\">"; } else if (!strcmp(tag.getName(), "RF")) { SWBuf type = tag.getAttribute("type"); SWBuf footnoteNumber = tag.getAttribute("swordFootnote"); SWBuf noteName = tag.getAttribute("n"); VerseKey *vkey = NULL; // see if we have a VerseKey * or descendant SWTRY { vkey = SWDYNAMIC_CAST(VerseKey, u->key); } SWCATCH ( ... ) { } if (vkey) { // leave this special osis type in for crossReference notes types? Might thml use this some day? Doesn't hurt. //char ch = ((tag.getAttribute("type") && ((!strcmp(tag.getAttribute("type"), "crossReference")) || (!strcmp(tag.getAttribute("type"), "x-cross-ref")))) ? 'x':'n'); buf.appendFormatted("<a href=\"passagestudy.jsp?action=showNote&type=n&value=%s&module=%s&passage=%s\"><small><sup class=\"n\">*n%s</sup></small></a> ", URL::encode(footnoteNumber.c_str()).c_str(), URL::encode(u->version.c_str()).c_str(), URL::encode(vkey->getText()).c_str(), (renderNoteNumbers ? URL::encode(noteName.c_str()).c_str(): "")); } u->suspendTextPassThru = true; }
bool ThMLXHTML::handleToken(SWBuf &buf, const char *token, BasicFilterUserData *userData) { if (!substituteToken(buf, token)) { // manually process if it wasn't a simple substitution MyUserData *u = (MyUserData *)userData; XMLTag tag(token); if ((!tag.isEndTag()) && (!tag.isEmpty())) u->startTag = tag; if (tag.getName() && !strcmp(tag.getName(), "sync")) { SWBuf value = tag.getAttribute("value"); if (tag.getAttribute("type") && !strcmp(tag.getAttribute("type"), "morph")) { //> if(value.length()) buf.appendFormatted("<small><em class=\"morph\">(<a href=\"passagestudy.jsp?action=showMorph&type=Greek&value=%s\" class=\"morph\">%s</a>)</em></small>", URL::encode(value.c_str()).c_str(), value.c_str()); } else if (tag.getAttribute("type") && !strcmp(tag.getAttribute("type"), "lemma")) { //> if(value.length()) // empty "type=" is deliberate. buf.appendFormatted("<small><em class=\"strongs\"><<a href=\"passagestudy.jsp?action=showStrongs&type=&value=%s\" class=\"strongs\">%s</a>></em></small>", URL::encode(value.c_str()).c_str(), value.c_str()); } else if (tag.getAttribute("type") && !strcmp(tag.getAttribute("type"), "Strongs")) { char ch = *value; value<<1; buf.appendFormatted("<small><em class=\"strongs\"><<a href=\"passagestudy.jsp?action=showStrongs&type=%s&value=%s\" class=\"strongs\">", ((ch == 'H') ? "Hebrew" : "Greek"), URL::encode(value.c_str()).c_str()); buf += (value.length()) ? value.c_str() : ""; buf += "</a>></em></small>"; } else if (tag.getAttribute("type") && !strcmp(tag.getAttribute("type"), "Dict")) { buf += (tag.isEndTag() ? "</b>" : "<b>"); } } // <note> tag else if (!strcmp(tag.getName(), "note")) { if (!tag.isEndTag()) { if (!tag.isEmpty()) { SWBuf type = tag.getAttribute("type"); SWBuf footnoteNumber = tag.getAttribute("swordFootnote"); SWBuf noteName = tag.getAttribute("n"); VerseKey *vkey = NULL; // see if we have a VerseKey * or descendant SWTRY { vkey = SWDYNAMIC_CAST(VerseKey, u->key); } SWCATCH ( ... ) { } if (vkey) { // leave this special osis type in for crossReference notes types? Might thml use this some day? Doesn't hurt. char ch = ((tag.getAttribute("type") && ((!strcmp(tag.getAttribute("type"), "crossReference")) || (!strcmp(tag.getAttribute("type"), "x-cross-ref")))) ? 'x':'n'); buf.appendFormatted("<a href=\"passagestudy.jsp?action=showNote&type=%c&value=%s&module=%s&passage=%s\"><small><sup class=\"%c\">*%c%s</sup></small></a>", ch, URL::encode(footnoteNumber.c_str()).c_str(), URL::encode(u->version.c_str()).c_str(), URL::encode(vkey->getText()).c_str(), ch, ch, (renderNoteNumbers ? noteName.c_str() : "")); } else { char ch = ((tag.getAttribute("type") && ((!strcmp(tag.getAttribute("type"), "crossReference")) || (!strcmp(tag.getAttribute("type"), "x-cross-ref")))) ? 'x':'n'); buf.appendFormatted("<a href=\"passagestudy.jsp?action=showNote&type=%c&value=%s&module=%s&passage=%s\"><small><sup class=\"%c\">*%c%s</sup></small></a>", ch, URL::encode(footnoteNumber.c_str()).c_str(), URL::encode(u->version.c_str()).c_str(), URL::encode(u->key->getText()).c_str(), ch, ch, (renderNoteNumbers ? noteName.c_str() : "")); } u->suspendTextPassThru = true; } } if (tag.isEndTag()) { u->suspendTextPassThru = false; } }
bool GBFHTMLHREF::handleToken(SWBuf &buf, const char *token, BasicFilterUserData *userData) { const char *tok; MyUserData *u = (MyUserData *)userData; if (!substituteToken(buf, token)) { XMLTag tag(token); /*if (!strncmp(token, "w", 1)) { // OSIS Word (temporary until OSISRTF is done) valto = val; num = strstr(token, "lemma=\"x-Strongs:"); if (num) { for (num+=17; ((*num) && (*num != '\"')); num++) *valto++ = *num; *valto = 0; if (atoi((!isdigit(*val))?val+1:val) < 5627) { buf += " <small><em><<a href=\"type=Strongs value="; for (tok = val; *tok; tok++) buf += *tok; buf += "\">"; for (tok = (!isdigit(*val))?val+1:val; *tok; tok++) buf += *tok; buf += "</a>></em></small> "; //cout << buf; } // forget these for now //else { // verb morph //sprintf(wordstr, "%03d", word-1); //module->getEntryAttributes()["Word"][wordstr]["Morph"] = val; //} } else { num = strstr(token, "lemma=\"strong:"); if (num) { for (num+=14; ((*num) && (*num != '\"')); num++) *valto++ = *num; *valto = 0; if (atoi((!isdigit(*val))?val+1:val) < 5627) { buf += " <small><em><<a href=\"type=Strongs value="; for (tok = val; *tok; tok++) buf += *tok; buf += "\">"; for (tok = (!isdigit(*val))?val+1:val; *tok; tok++) buf += *tok; buf += "</a>></em></small> "; //cout << buf; } // forget these for now //else { // verb morph //sprintf(wordstr, "%03d", word-1); //module->getEntryAttributes()["Word"][wordstr]["Morph"] = val; //} } } valto = val; num = strstr(token, "morph=\"x-Robinson:"); if (num) { for (num+=18; ((*num) && (*num != '\"')); num++) *valto++ = *num; *valto = 0; buf += " <small><em>(<a href=\"type=morph class=Robinson value="; for (tok = val; *tok; tok++) // normal robinsons tense buf += *tok; buf += "\">"; for (tok = val; *tok; tok++) //if(*tok != '\"') buf += *tok; buf += "</a>)</em></small> "; } }*/ // else if (!strncmp(token, "WG", 2)) { // strong's numbers //buf += " <small><em><<a href=\"type=Strongs value="; buf += " <a href=\"passagestudy.jsp?action=showStrongs&type=Greek&value="; for (tok = token+2; *tok; tok++) //if(token[i] != '\"') buf += *tok; buf += "\" class=\"strongs\"><"; for (tok = token + 2; *tok; tok++) //if(token[i] != '\"') buf += *tok; buf += "></a>"; } else if (!strncmp(token, "WH", 2)) { // strong's numbers //buf += " <small><em><<a href=\"type=Strongs value="; buf += " <a href=\"passagestudy.jsp?action=showStrongs&type=Hebrew&value="; for (tok = token+2; *tok; tok++) //if(token[i] != '\"') buf += *tok; buf += "\" class=\"strongs\"><"; for (tok = token + 2; *tok; tok++) //if(token[i] != '\"') buf += *tok; buf += "></a>"; } else if (!strncmp(token, "WTG", 3)) { // strong's numbers tense //buf += " <small><em>(<a href=\"type=Strongs value="; buf += " <a href=\"passagestudy.jsp?action=showStrongs&type=Greek&value="; for (tok = token + 3; *tok; tok++) if(*tok != '\"') buf += *tok; buf += "\" class=\"strongs\">("; for (tok = token + 3; *tok; tok++) if(*tok != '\"') buf += *tok; buf += ")</a>"; } else if (!strncmp(token, "WTH", 3)) { // strong's numbers tense //buf += " <small><em>(<a href=\"type=Strongs value="; buf += " <a href=\"passagestudy.jsp?action=showStrongs&type=Hebrew&value="; for (tok = token + 3; *tok; tok++) if(*tok != '\"') buf += *tok; buf += "\" class=\"strongs\">("; for (tok = token + 3; *tok; tok++) if(*tok != '\"') buf += *tok; buf += ")</a>"; } else if (!strncmp(token, "WT", 2) && strncmp(token, "WTH", 3) && strncmp(token, "WTG", 3)) { // morph tags //buf += " <small><em>(<a href=\"type=morph class=none value="; buf += " <a href=\"passagestudy.jsp?action=showMorph&type=Greek&value="; for (tok = token + 2; *tok; tok++) if(*tok != '\"') buf += *tok; buf += "\" class=\"morph\">("; for (tok = token + 2; *tok; tok++) if(*tok != '\"') buf += *tok; buf += ")</a>"; } else if (!strcmp(tag.getName(), "RX")) { buf += "<a href=\""; for (tok = token + 3; *tok; tok++) { if(*tok != '<' && *tok+1 != 'R' && *tok+2 != 'x') { buf += *tok; } else { break; } } buf += "\">"; } else if (!strcmp(tag.getName(), "RF")) { SWBuf type = tag.getAttribute("type"); SWBuf footnoteNumber = tag.getAttribute("swordFootnote"); SWBuf noteName = tag.getAttribute("n"); VerseKey *vkey = NULL; // see if we have a VerseKey * or descendant SWTRY { vkey = SWDYNAMIC_CAST(VerseKey, u->key); } SWCATCH ( ... ) { } if (vkey) { // leave this special osis type in for crossReference notes types? Might thml use this some day? Doesn't hurt. //char ch = ((tag.getAttribute("type") && ((!strcmp(tag.getAttribute("type"), "crossReference")) || (!strcmp(tag.getAttribute("type"), "x-cross-ref")))) ? 'x':'n'); buf.appendFormatted("<a href=\"passagestudy.jsp?action=showNote&type=n&value=%s&module=%s&passage=%s\"><small><sup class=\"n\">*n%s</sup></small></a> ", URL::encode(footnoteNumber.c_str()).c_str(), URL::encode(u->version.c_str()).c_str(), URL::encode(vkey->getText()).c_str(), (renderNoteNumbers ? URL::encode(noteName.c_str()).c_str(): "")); } u->suspendTextPassThru = true; }