From 7a00574163029c0c2b649878c95d5acbd083564a Mon Sep 17 00:00:00 2001 From: "Roberto C. Sanchez" Date: Mon, 12 May 2014 08:21:30 -0400 Subject: Imported Upstream version 1.7.2+dfsg --- src/modules/filters/Makefile.am | 14 +- src/modules/filters/cipherfil.cpp | 11 +- src/modules/filters/gbffootnotes.cpp | 28 +- src/modules/filters/gbfheadings.cpp | 29 +- src/modules/filters/gbfhtml.cpp | 12 +- src/modules/filters/gbfhtmlhref.cpp | 22 +- src/modules/filters/gbfmorph.cpp | 26 +- src/modules/filters/gbfosis.cpp | 22 +- src/modules/filters/gbfplain.cpp | 11 +- src/modules/filters/gbfredletterwords.cpp | 26 +- src/modules/filters/gbfrtf.cpp | 7 +- src/modules/filters/gbfstrongs.cpp | 26 +- src/modules/filters/gbfthml.cpp | 13 +- src/modules/filters/gbfwebif.cpp | 17 +- src/modules/filters/gbfwordjs.cpp | 43 +- src/modules/filters/gbfxhtml.cpp | 236 ++++++++ src/modules/filters/greeklexattribs.cpp | 7 +- src/modules/filters/latin1utf16.cpp | 7 +- src/modules/filters/latin1utf8.cpp | 12 +- src/modules/filters/osisenum.cpp | 99 ++++ src/modules/filters/osisfootnotes.cpp | 29 +- src/modules/filters/osisglosses.cpp | 99 ++++ src/modules/filters/osisheadings.cpp | 228 ++++---- src/modules/filters/osishtmlhref.cpp | 157 +++--- src/modules/filters/osislemma.cpp | 28 +- src/modules/filters/osismorph.cpp | 27 +- src/modules/filters/osismorphsegmentation.cpp | 27 +- src/modules/filters/osisosis.cpp | 24 +- src/modules/filters/osisplain.cpp | 64 ++- src/modules/filters/osisredletterwords.cpp | 25 +- src/modules/filters/osisreferencelinks.cpp | 114 ++++ src/modules/filters/osisrtf.cpp | 25 +- src/modules/filters/osisruby.cpp | 93 ---- src/modules/filters/osisscripref.cpp | 26 +- src/modules/filters/osisstrongs.cpp | 29 +- src/modules/filters/osisvariants.cpp | 82 ++- src/modules/filters/osiswebif.cpp | 60 +- src/modules/filters/osiswordjs.cpp | 34 +- src/modules/filters/osisxhtml.cpp | 772 ++++++++++++++++++++++++++ src/modules/filters/osisxlit.cpp | 99 ++++ src/modules/filters/papyriplain.cpp | 6 +- src/modules/filters/plainfootnotes.cpp | 85 --- src/modules/filters/plainhtml.cpp | 89 --- src/modules/filters/rtfhtml.cpp | 38 +- src/modules/filters/scsuutf8.cpp | 246 ++++++++ src/modules/filters/swbasicfilter.cpp | 28 +- src/modules/filters/swoptfilter.cpp | 9 +- src/modules/filters/teihtmlhref.cpp | 22 +- src/modules/filters/teiplain.cpp | 10 +- src/modules/filters/teirtf.cpp | 416 +++++++------- src/modules/filters/teixhtml.cpp | 290 ++++++++++ src/modules/filters/thmlfootnotes.cpp | 30 +- src/modules/filters/thmlgbf.cpp | 9 +- src/modules/filters/thmlheadings.cpp | 26 +- src/modules/filters/thmlhtml.cpp | 11 +- src/modules/filters/thmlhtmlhref.cpp | 34 +- src/modules/filters/thmllemma.cpp | 26 +- src/modules/filters/thmlmorph.cpp | 25 +- src/modules/filters/thmlosis.cpp | 22 +- src/modules/filters/thmlplain.cpp | 7 +- src/modules/filters/thmlrtf.cpp | 17 +- src/modules/filters/thmlscripref.cpp | 32 +- src/modules/filters/thmlstrongs.cpp | 26 +- src/modules/filters/thmlvariants.cpp | 59 +- src/modules/filters/thmlwebif.cpp | 14 +- src/modules/filters/thmlwordjs.cpp | 43 +- src/modules/filters/thmlxhtml.cpp | 378 +++++++++++++ src/modules/filters/unicodertf.cpp | 6 +- src/modules/filters/utf16utf8.cpp | 10 +- src/modules/filters/utf8arabicpoints.cpp | 174 +++++- src/modules/filters/utf8arshaping.cpp | 9 +- src/modules/filters/utf8bidireorder.cpp | 15 +- src/modules/filters/utf8cantillation.cpp | 26 +- src/modules/filters/utf8greekaccents.cpp | 29 +- src/modules/filters/utf8hebrewpoints.cpp | 30 +- src/modules/filters/utf8html.cpp | 14 +- src/modules/filters/utf8latin1.cpp | 11 +- src/modules/filters/utf8nfc.cpp | 7 +- src/modules/filters/utf8nfkd.cpp | 12 +- src/modules/filters/utf8transliterator.cpp | 126 +++-- src/modules/filters/utf8utf16.cpp | 8 +- 81 files changed, 3802 insertions(+), 1383 deletions(-) create mode 100644 src/modules/filters/gbfxhtml.cpp create mode 100644 src/modules/filters/osisenum.cpp create mode 100644 src/modules/filters/osisglosses.cpp create mode 100644 src/modules/filters/osisreferencelinks.cpp delete mode 100644 src/modules/filters/osisruby.cpp create mode 100644 src/modules/filters/osisxhtml.cpp create mode 100644 src/modules/filters/osisxlit.cpp delete mode 100644 src/modules/filters/plainfootnotes.cpp delete mode 100644 src/modules/filters/plainhtml.cpp create mode 100644 src/modules/filters/scsuutf8.cpp create mode 100644 src/modules/filters/teixhtml.cpp create mode 100644 src/modules/filters/thmlxhtml.cpp (limited to 'src/modules/filters') diff --git a/src/modules/filters/Makefile.am b/src/modules/filters/Makefile.am index 80e65d9..a3d1154 100644 --- a/src/modules/filters/Makefile.am +++ b/src/modules/filters/Makefile.am @@ -5,6 +5,7 @@ libsword_la_SOURCES += $(filtersdir)/swoptfilter.cpp GBFFIL = $(filtersdir)/gbfhtml.cpp GBFFIL += $(filtersdir)/gbfhtmlhref.cpp +GBFFIL += $(filtersdir)/gbfxhtml.cpp GBFFIL += $(filtersdir)/gbfwebif.cpp GBFFIL += $(filtersdir)/gbfplain.cpp GBFFIL += $(filtersdir)/gbfrtf.cpp @@ -26,12 +27,14 @@ THMLFIL += $(filtersdir)/thmlgbf.cpp THMLFIL += $(filtersdir)/thmlrtf.cpp THMLFIL += $(filtersdir)/thmlhtml.cpp THMLFIL += $(filtersdir)/thmlhtmlhref.cpp +THMLFIL += $(filtersdir)/thmlxhtml.cpp THMLFIL += $(filtersdir)/thmlwebif.cpp THMLFIL += $(filtersdir)/thmlwordjs.cpp TEIFIL = $(filtersdir)/teiplain.cpp TEIFIL += $(filtersdir)/teirtf.cpp TEIFIL += $(filtersdir)/teihtmlhref.cpp +TEIFIL += $(filtersdir)/teixhtml.cpp CONVFIL = $(filtersdir)/gbfthml.cpp CONVFIL += $(filtersdir)/gbfosis.cpp @@ -42,6 +45,7 @@ CONVFIL += $(filtersdir)/osisosis.cpp OSISFIL = $(filtersdir)/osisheadings.cpp OSISFIL += $(filtersdir)/osisfootnotes.cpp OSISFIL += $(filtersdir)/osishtmlhref.cpp +OSISFIL += $(filtersdir)/osisxhtml.cpp OSISFIL += $(filtersdir)/osiswebif.cpp OSISFIL += $(filtersdir)/osismorph.cpp OSISFIL += $(filtersdir)/osisstrongs.cpp @@ -53,7 +57,10 @@ OSISFIL += $(filtersdir)/osisscripref.cpp OSISFIL += $(filtersdir)/osisvariants.cpp OSISFIL += $(filtersdir)/osiswordjs.cpp OSISFIL += $(filtersdir)/osismorphsegmentation.cpp -OSISFIL += $(filtersdir)/osisruby.cpp +OSISFIL += $(filtersdir)/osisglosses.cpp +OSISFIL += $(filtersdir)/osisenum.cpp +OSISFIL += $(filtersdir)/osisxlit.cpp +OSISFIL += $(filtersdir)/osisreferencelinks.cpp libsword_la_SOURCES += $(filtersdir)/latin1utf8.cpp libsword_la_SOURCES += $(filtersdir)/latin1utf16.cpp @@ -61,6 +68,8 @@ libsword_la_SOURCES += $(filtersdir)/utf8utf16.cpp libsword_la_SOURCES += $(filtersdir)/utf16utf8.cpp libsword_la_SOURCES += $(filtersdir)/utf8html.cpp libsword_la_SOURCES += $(filtersdir)/utf8latin1.cpp +libsword_la_SOURCES += $(filtersdir)/unicodertf.cpp +libsword_la_SOURCES += $(filtersdir)/scsuutf8.cpp libsword_la_SOURCES += $(filtersdir)/utf8cantillation.cpp libsword_la_SOURCES += $(filtersdir)/utf8hebrewpoints.cpp @@ -70,10 +79,7 @@ libsword_la_SOURCES += $(filtersdir)/utf8greekaccents.cpp libsword_la_SOURCES += $(filtersdir)/cipherfil.cpp PLFIL = $(filtersdir)/rtfhtml.cpp -PLFIL += $(filtersdir)/plainfootnotes.cpp -PLFIL += $(filtersdir)/plainhtml.cpp PLFIL += $(filtersdir)/greeklexattribs.cpp -PLFIL += $(filtersdir)/unicodertf.cpp PLFIL += $(filtersdir)/papyriplain.cpp diff --git a/src/modules/filters/cipherfil.cpp b/src/modules/filters/cipherfil.cpp index 34d0465..e5422f3 100644 --- a/src/modules/filters/cipherfil.cpp +++ b/src/modules/filters/cipherfil.cpp @@ -1,8 +1,11 @@ /****************************************************************************** * - * cipherfil - SWFilter descendant to decipher a module + * cipherfil.cpp - CipherFilter, a SWFilter descendant to decipher + * a module * - * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * $Id: cipherfil.cpp 2980 2013-09-14 21:51:47Z scribe $ + * + * Copyright 1999-2013 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society * P. O. Box 2528 * Tempe, AZ 85280-2528 @@ -24,8 +27,10 @@ #include #include + SWORD_NAMESPACE_START + CipherFilter::CipherFilter(const char *key) { cipher = new SWCipher((unsigned char *)key); } @@ -58,4 +63,6 @@ char CipherFilter::processText(SWBuf &text, const SWKey *key, const SWModule *mo return 0; } + SWORD_NAMESPACE_END + diff --git a/src/modules/filters/gbffootnotes.cpp b/src/modules/filters/gbffootnotes.cpp index a5384cb..7b867f1 100644 --- a/src/modules/filters/gbffootnotes.cpp +++ b/src/modules/filters/gbffootnotes.cpp @@ -1,9 +1,11 @@ /****************************************************************************** * - * gbffootnotes - SWFilter descendant to hide or show footnotes - * in a GBF module. + * gbffootnotes.cpp - SWFilter descendant to hide or show footnotes + * in a GBF module * - * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * $Id: gbffootnotes.cpp 2980 2013-09-14 21:51:47Z scribe $ + * + * Copyright 1999-2013 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society * P. O. Box 2528 * Tempe, AZ 85280-2528 @@ -28,17 +30,23 @@ #include #include + SWORD_NAMESPACE_START -const char oName[] = "Footnotes"; -const char oTip[] = "Toggles Footnotes On and Off if they exist"; +namespace { + + static const char oName[] = "Footnotes"; + static const char oTip[] = "Toggles Footnotes On and Off if they exist"; -const SWBuf choices[3] = {"Off", "On", ""}; -const StringList oValues(&choices[0], &choices[2]); + static const StringList *oValues() { + static const SWBuf choices[3] = {"Off", "On", ""}; + static const StringList oVals(&choices[0], &choices[2]); + return &oVals; + } +} -GBFFootnotes::GBFFootnotes() : SWOptionFilter(oName, oTip, &oValues) { - setOptionValue("Off"); +GBFFootnotes::GBFFootnotes() : SWOptionFilter(oName, oTip, oValues()) { } @@ -86,7 +94,7 @@ char GBFFootnotes::processText (SWBuf &text, const SWKey *key, const SWModule *m if (module->isProcessEntryAttributes()) { //tag = token; - if((tagText.length() == 1) || !strcmp(module->Name(), "IGNT")) { + if((tagText.length() == 1) || !strcmp(module->getName(), "IGNT")) { if (option) { // for ASV marks text in verse then put explanation at end of verse text.append(" ["); text.append(tagText); diff --git a/src/modules/filters/gbfheadings.cpp b/src/modules/filters/gbfheadings.cpp index 122445e..7e19ea1 100644 --- a/src/modules/filters/gbfheadings.cpp +++ b/src/modules/filters/gbfheadings.cpp @@ -1,9 +1,11 @@ /****************************************************************************** * - * gbfheadings - SWFilter descendant to hide or show headings - * in a GBF module. + * gbfheadings.cpp - SWFilter descendant to hide or show headings + * in a GBF module * - * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * $Id: gbfheadings.cpp 2980 2013-09-14 21:51:47Z scribe $ + * + * Copyright 2001-2013 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society * P. O. Box 2528 * Tempe, AZ 85280-2528 @@ -19,20 +21,27 @@ * */ + #include #include + SWORD_NAMESPACE_START +namespace { -const char oName[] = "Headings"; -const char oTip[] = "Toggles Headings On and Off if they exist"; + static const char oName[] = "Headings"; + static const char oTip[] = "Toggles Headings On and Off if they exist"; + + static const StringList *oValues() { + static const SWBuf choices[3] = {"Off", "On", ""}; + static const StringList oVals(&choices[0], &choices[2]); + return &oVals; + } +} -const SWBuf choices[3] = {"Off", "On", ""}; -const StringList oValues(&choices[0], &choices[2]); -GBFHeadings::GBFHeadings() : SWOptionFilter(oName, oTip, &oValues) { - setOptionValue("Off"); +GBFHeadings::GBFHeadings() : SWOptionFilter(oName, oTip, oValues()) { } @@ -40,7 +49,7 @@ GBFHeadings::~GBFHeadings() { } -char GBFHeadings::processText (SWBuf &text, const SWKey *key, const SWModule *module) { +char GBFHeadings::processText(SWBuf &text, const SWKey *key, const SWModule *module) { if (!option) { // if we don't want headings char token[2048]; // cheese. Fix. int tokpos = 0; diff --git a/src/modules/filters/gbfhtml.cpp b/src/modules/filters/gbfhtml.cpp index 2467e36..542c4c9 100644 --- a/src/modules/filters/gbfhtml.cpp +++ b/src/modules/filters/gbfhtml.cpp @@ -1,10 +1,10 @@ /*************************************************************************** - * gbfhtml.cpp - GBF to HTML filter - * ------------------- - * begin : 2001-09-03 - * copyright : 2001 by CrossWire Bible Society * - * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * gbfhtml.cpp - GBF to HTML filter + * + * $Id: gbfhtml.cpp 2833 2013-06-29 06:40:28Z chrislit $ + * + * Copyright 1999-2013 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society * P. O. Box 2528 * Tempe, AZ 85280-2528 @@ -54,7 +54,7 @@ GBFHTML::GBFHTML() { addTokenSubstitute("Pp", ""); addTokenSubstitute("Fn", ""); // font end addTokenSubstitute("CL", "
"); // new line - addTokenSubstitute("CM", "
"); // paragraph is a non showing comment that can be changed in the front end to

if desired + addTokenSubstitute("CM", "

"); // two new-lines addTokenSubstitute("CG", ""); // ??? addTokenSubstitute("CT", ""); // ??? addTokenSubstitute("JR", "

"); // right align begin diff --git a/src/modules/filters/gbfhtmlhref.cpp b/src/modules/filters/gbfhtmlhref.cpp index 3f25e3a..6df038e 100644 --- a/src/modules/filters/gbfhtmlhref.cpp +++ b/src/modules/filters/gbfhtmlhref.cpp @@ -1,11 +1,10 @@ /*************************************************************************** - * gbfhtmlhref.cpp - GBF to HTML filter with hrefs - * for strongs and morph tags - * ------------------- - * begin : 2001-09-03 - * copyright : 2001 by CrossWire Bible Society * - * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * gbfhtmlhref.cpp - GBF to HTML filter with hrefs + * + * $Id: gbfhtmlhref.cpp 2833 2013-06-29 06:40:28Z chrislit $ + * + * Copyright 2001-2013 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society * P. O. Box 2528 * Tempe, AZ 85280-2528 @@ -34,7 +33,7 @@ SWORD_NAMESPACE_START GBFHTMLHREF::MyUserData::MyUserData(const SWModule *module, const SWKey *key) : BasicFilterUserData(module, key) { if (module) { - version = module->Name(); + version = module->getName(); } } @@ -73,7 +72,8 @@ GBFHTMLHREF::GBFHTMLHREF() { addTokenSubstitute("JR", "
"); // right align begin addTokenSubstitute("JC", "
"); // center align begin addTokenSubstitute("JL", "
"); // align end - + + renderNoteNumbers = false; } @@ -231,6 +231,7 @@ bool GBFHTMLHREF::handleToken(SWBuf &buf, const char *token, BasicFilterUserData 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 { @@ -240,10 +241,11 @@ bool GBFHTMLHREF::handleToken(SWBuf &buf, const char *token, BasicFilterUserData 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("*n ", + buf.appendFormatted("*n%s ", URL::encode(footnoteNumber.c_str()).c_str(), URL::encode(u->version.c_str()).c_str(), - URL::encode(vkey->getText()).c_str()); + URL::encode(vkey->getText()).c_str(), + (renderNoteNumbers ? URL::encode(noteName.c_str()).c_str(): "")); } u->suspendTextPassThru = true; } diff --git a/src/modules/filters/gbfmorph.cpp b/src/modules/filters/gbfmorph.cpp index d7c8ab4..3399ae8 100644 --- a/src/modules/filters/gbfmorph.cpp +++ b/src/modules/filters/gbfmorph.cpp @@ -1,10 +1,11 @@ /****************************************************************************** * - * gbfmorph - SWFilter descendant to hide or show morph tags - * in a GBF module. + * gbfmorph.cpp - SWFilter descendant to hide or show morph tags + * in a GBF module * + * $Id: gbfmorph.cpp 2980 2013-09-14 21:51:47Z scribe $ * - * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * Copyright 2001-2013 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society * P. O. Box 2528 * Tempe, AZ 85280-2528 @@ -23,16 +24,23 @@ #include #include + SWORD_NAMESPACE_START -const char oName[] = "Morphological Tags"; -const char oTip[] = "Toggles Morphological Tags On and Off if they exist"; +namespace { + + static const char oName[] = "Morphological Tags"; + static const char oTip[] = "Toggles Morphological Tags On and Off if they exist"; + + static const StringList *oValues() { + static const SWBuf choices[3] = {"Off", "On", ""}; + static const StringList oVals(&choices[0], &choices[2]); + return &oVals; + } +} -const SWBuf choices[3] = {"Off", "On", ""}; -const StringList oValues(&choices[0], &choices[2]); -GBFMorph::GBFMorph() : SWOptionFilter(oName, oTip, &oValues) { - setOptionValue("Off"); +GBFMorph::GBFMorph() : SWOptionFilter(oName, oTip, oValues()) { } diff --git a/src/modules/filters/gbfosis.cpp b/src/modules/filters/gbfosis.cpp index 526167a..9333f62 100644 --- a/src/modules/filters/gbfosis.cpp +++ b/src/modules/filters/gbfosis.cpp @@ -1,10 +1,10 @@ /****************************************************************************** * - * gbfstrongs - SWFilter descendant to hide or show strongs number - * in a GBF module. + * gbfosis.cpp - GBF to OSIS filter * + * $Id: gbfosis.cpp 2980 2013-09-14 21:51:47Z scribe $ * - * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * Copyright 2002-2013 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society * P. O. Box 2528 * Tempe, AZ 85280-2528 @@ -29,8 +29,10 @@ #include #include + SWORD_NAMESPACE_START + GBFOSIS::GBFOSIS() { } @@ -347,7 +349,7 @@ char GBFOSIS::processText(SWBuf &text, const SWKey *key, const SWModule *module) VerseKey *vkey = SWDYNAMIC_CAST(VerseKey, key); if (vkey) { SWBuf ref = ""; - if (vkey->Verse()) { + if (vkey->getVerse()) { ref.appendFormatted("\t\t", vkey->getOSISRef()); } @@ -355,24 +357,24 @@ char GBFOSIS::processText(SWBuf &text, const SWKey *key, const SWModule *module) text = ref + text; - if (vkey->Verse()) { + if (vkey->getVerse()) { VerseKey *tmp = (VerseKey *)vkey->clone(); *tmp = *vkey; - tmp->AutoNormalize(0); - tmp->Headings(1); + tmp->setAutoNormalize(false); + tmp->setIntros(true); text += ""; *tmp = MAXVERSE; if (*vkey == *tmp) { - tmp->Verse(0); + tmp->setVerse(0); // sprintf(ref, "\t
"); // pushString(&to, ref); *tmp = MAXCHAPTER; *tmp = MAXVERSE; if (*vkey == *tmp) { - tmp->Chapter(0); - tmp->Verse(0); + tmp->setChapter(0); + tmp->setVerse(0); // sprintf(ref, "\t
"); // pushString(&to, ref); /* diff --git a/src/modules/filters/gbfplain.cpp b/src/modules/filters/gbfplain.cpp index e90bf94..b2a1ae4 100644 --- a/src/modules/filters/gbfplain.cpp +++ b/src/modules/filters/gbfplain.cpp @@ -1,10 +1,11 @@ /****************************************************************************** * - * gbfplain - SWFilter descendant to strip out all GBF tags or convert to - * ASCII rendered symbols. + * gbfplain.cpp - SWFilter descendant to strip out all GBF tags or + * convert to ASCII rendered symbols * + * $Id: gbfplain.cpp 2980 2013-09-14 21:51:47Z scribe $ * - * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * Copyright 1997-2013 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society * P. O. Box 2528 * Tempe, AZ 85280-2528 @@ -24,8 +25,10 @@ #include #include + SWORD_NAMESPACE_START + GBFPlain::GBFPlain() { } @@ -109,4 +112,6 @@ char GBFPlain::processText (SWBuf &text, const SWKey *key, const SWModule *modul return 0; } + SWORD_NAMESPACE_END + diff --git a/src/modules/filters/gbfredletterwords.cpp b/src/modules/filters/gbfredletterwords.cpp index 7397781..cac3cd9 100644 --- a/src/modules/filters/gbfredletterwords.cpp +++ b/src/modules/filters/gbfredletterwords.cpp @@ -1,10 +1,11 @@ /****************************************************************************** * - * GBFRedLetterWords - SWFilter descendant to toggle red coloring of words of - * Christ in a GBF module. + * gbfredletterwords.cpp - SWFilter descendant to toggle red coloring of + * words of Christ in a GBF module * + * $Id: gbfredletterwords.cpp 2980 2013-09-14 21:51:47Z scribe $ * - * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * Copyright 2003-2013 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society * P. O. Box 2528 * Tempe, AZ 85280-2528 @@ -25,16 +26,23 @@ #include #include + SWORD_NAMESPACE_START -const char oName[] = "Words of Christ in Red"; -const char oTip[] = "Toggles Red Coloring for Words of Christ On and Off if they are marked"; +namespace { + + static const char oName[] = "Words of Christ in Red"; + static const char oTip[] = "Toggles Red Coloring for Words of Christ On and Off if they are marked"; + + static const StringList *oValues() { + static const SWBuf choices[3] = {"Off", "On", ""}; + static const StringList oVals(&choices[0], &choices[2]); + return &oVals; + } +} -const SWBuf choices[3] = {"Off", "On", ""}; -const StringList oValues(&choices[0], &choices[2]); -GBFRedLetterWords::GBFRedLetterWords() : SWOptionFilter(oName, oTip, &oValues) { - setOptionValue("Off"); +GBFRedLetterWords::GBFRedLetterWords() : SWOptionFilter(oName, oTip, oValues()) { } diff --git a/src/modules/filters/gbfrtf.cpp b/src/modules/filters/gbfrtf.cpp index 7471d0b..8a8e1b1 100644 --- a/src/modules/filters/gbfrtf.cpp +++ b/src/modules/filters/gbfrtf.cpp @@ -1,9 +1,10 @@ /****************************************************************************** * - * gbfrtf - SWFilter descendant to convert all GBF tags to RTF tags + * gbfrtf.cpp - SWFilter descendant to convert all GBF tags to RTF tags * + * $Id: gbfrtf.cpp 2833 2013-06-29 06:40:28Z chrislit $ * - * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * Copyright 1997-2013 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society * P. O. Box 2528 * Tempe, AZ 85280-2528 @@ -42,7 +43,6 @@ char GBFRTF::processText(SWBuf &text, const SWKey *key, const SWModule *module) SWBuf strongnum; SWBuf strongtense; bool hideText = false; - int wordLen = 0; int wordCount = 0; const char *from; @@ -50,7 +50,6 @@ char GBFRTF::processText(SWBuf &text, const SWKey *key, const SWModule *module) from = orig.c_str(); for (text = ""; *from; from++) { if (*from == '<') { - wordLen = wordCount; wordCount = 0; intoken = true; tokpos = 0; diff --git a/src/modules/filters/gbfstrongs.cpp b/src/modules/filters/gbfstrongs.cpp index c7cf6c5..dd4e167 100644 --- a/src/modules/filters/gbfstrongs.cpp +++ b/src/modules/filters/gbfstrongs.cpp @@ -1,10 +1,11 @@ /****************************************************************************** * - * gbfstrongs - SWFilter descendant to hide or show strongs number - * in a GBF module. + * gbfstrongs.cpp - SWFilter descendant to hide or show Strong's number + * in a GBF module * + * $Id: gbfstrongs.cpp 2980 2013-09-14 21:51:47Z scribe $ * - * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * Copyright 1999-2013 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society * P. O. Box 2528 * Tempe, AZ 85280-2528 @@ -26,16 +27,23 @@ #include #include + SWORD_NAMESPACE_START -const char oName[] = "Strong's Numbers"; -const char oTip[] = "Toggles Strong's Numbers On and Off if they exist"; +namespace { + + static const char oName[] = "Strong's Numbers"; + static const char oTip[] = "Toggles Strong's Numbers On and Off if they exist"; + + static const StringList *oValues() { + static const SWBuf choices[3] = {"Off", "On", ""}; + static const StringList oVals(&choices[0], &choices[2]); + return &oVals; + } +} -const SWBuf choices[3] = {"Off", "On", ""}; -const StringList oValues(&choices[0], &choices[2]); -GBFStrongs::GBFStrongs() : SWOptionFilter(oName, oTip, &oValues) { - setOptionValue("Off"); +GBFStrongs::GBFStrongs() : SWOptionFilter(oName, oTip, oValues()) { } diff --git a/src/modules/filters/gbfthml.cpp b/src/modules/filters/gbfthml.cpp index 4feb1fa..303b240 100644 --- a/src/modules/filters/gbfthml.cpp +++ b/src/modules/filters/gbfthml.cpp @@ -1,10 +1,10 @@ /*************************************************************************** - * gbfthml.cpp - GBF to ThML filter - * ------------------- - * begin : 1999-10-27 - * copyright : 2001 by CrossWire Bible Society * - * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * gbfthml.cpp - GBF to ThML filter + * + * $Id: gbfthml.cpp 2980 2013-09-14 21:51:47Z scribe $ + * + * Copyright 1999-2013 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society * P. O. Box 2528 * Tempe, AZ 85280-2528 @@ -24,8 +24,10 @@ #include #include + SWORD_NAMESPACE_START + GBFThML::GBFThML() { } @@ -218,5 +220,4 @@ char GBFThML::processText(SWBuf &text, const SWKey *key, const SWModule *module) } - SWORD_NAMESPACE_END diff --git a/src/modules/filters/gbfwebif.cpp b/src/modules/filters/gbfwebif.cpp index b5ff798..b7b8a0f 100644 --- a/src/modules/filters/gbfwebif.cpp +++ b/src/modules/filters/gbfwebif.cpp @@ -1,11 +1,11 @@ /*************************************************************************** - * GBFWEBIF.cpp - GBF to HTML filter with hrefs - * for strongs and morph tags - * ------------------- - * begin : 2001-09-03 - * copyright : 2001 by CrossWire Bible Society * - * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * gbfwebif.cpp - GBF to HTML filter with hrefs for strongs and morph + * tags + * + * $Id: gbfwebif.cpp 2833 2013-06-29 06:40:28Z chrislit $ + * + * Copyright 2003-2013 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society * P. O. Box 2528 * Tempe, AZ 85280-2528 @@ -29,9 +29,6 @@ SWORD_NAMESPACE_START GBFWEBIF::GBFWEBIF() : baseURL(""), passageStudyURL(baseURL + "passagestudy.jsp") { -//all is done in GBFHTMLHREF since it inherits form this class - addTokenSubstitute("FR", ""); // words of Jesus begin - addTokenSubstitute("Fr", ""); } bool GBFWEBIF::handleToken(SWBuf &buf, const char *token, BasicFilterUserData *userData) { @@ -189,7 +186,7 @@ bool GBFWEBIF::handleToken(SWBuf &buf, const char *token, BasicFilterUserData *u } else { - return GBFHTMLHREF::handleToken(buf, token, userData); + return GBFXHTML::handleToken(buf, token, userData); } } return true; diff --git a/src/modules/filters/gbfwordjs.cpp b/src/modules/filters/gbfwordjs.cpp index c3ab166..c9d1bd3 100644 --- a/src/modules/filters/gbfwordjs.cpp +++ b/src/modules/filters/gbfwordjs.cpp @@ -1,10 +1,10 @@ /****************************************************************************** * - * gbfstrongs - SWFilter descendant to hide or show strongs number - * in a GBF module. + * gbfwordjs.cpp - SWFilter descendant for ??? * + * $Id: gbfwordjs.cpp 2980 2013-09-14 21:51:47Z scribe $ * - * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * Copyright 2005-2013 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society * P. O. Box 2528 * Tempe, AZ 85280-2528 @@ -28,17 +28,23 @@ #include #include + SWORD_NAMESPACE_START -const char oName[] = "Word Javascript"; -const char oTip[] = "Toggles Word Javascript data"; +namespace { + + static const char oName[] = "Word Javascript"; + static const char oTip[] = "Toggles Word Javascript data"; -const SWBuf choices[3] = {"Off", "On", ""}; -const StringList oValues(&choices[0], &choices[2]); + static const StringList *oValues() { + static const SWBuf choices[3] = {"Off", "On", ""}; + static const StringList oVals(&choices[0], &choices[2]); + return &oVals; + } +} -GBFWordJS::GBFWordJS() : SWOptionFilter(oName, oTip, &oValues) { - setOptionValue("Off"); +GBFWordJS::GBFWordJS() : SWOptionFilter(oName, oTip, oValues()) { defaultGreekLex = 0; defaultHebLex = 0; @@ -57,7 +63,6 @@ char GBFWordJS::processText(SWBuf &text, const SWKey *key, const SWModule *modul char token[2112]; // cheese. Fix. int tokpos = 0; bool intoken = false; - bool lastspace = false; int word = 1; char val[128]; char wordstr[5]; @@ -66,7 +71,7 @@ char GBFWordJS::processText(SWBuf &text, const SWKey *key, const SWModule *modul bool newText = false; bool needWordOut = false; AttributeValue *wordAttrs = 0; - SWBuf modName = (module)?module->Name():""; + SWBuf modName = (module)?module->getName():""; SWBuf wordSrcPrefix = modName; const SWBuf orig = text; @@ -146,7 +151,7 @@ char GBFWordJS::processText(SWBuf &text, const SWKey *key, const SWModule *modul gh = isdigit(strong[0]) ? 0:strong[0]; if (!gh) { if (vkey) { - gh = vkey->Testament() ? 'H' : 'G'; + gh = vkey->getTestament() ? 'H' : 'G'; } } else strong << 1; @@ -165,7 +170,7 @@ char GBFWordJS::processText(SWBuf &text, const SWKey *key, const SWModule *modul if (sLex) { // we can pass the real lex name in, but we have some // aliases in the javascript to optimize bandwidth - lexName = sLex->Name(); + lexName = sLex->getName(); if (lexName == "StrongsGreek") lexName = "G"; if (lexName == "StrongsHebrew") @@ -174,7 +179,7 @@ char GBFWordJS::processText(SWBuf &text, const SWKey *key, const SWModule *modul SWBuf wordID; if (vkey) { // optimize for bandwidth and use only the verse as the unique entry id - wordID.appendFormatted("%d", vkey->Verse()); + wordID.appendFormatted("%d", vkey->getVerse()); } else { wordID = key->getText(); @@ -192,10 +197,11 @@ char GBFWordJS::processText(SWBuf &text, const SWKey *key, const SWModule *modul + if (!sMorph) sMorph = 0; // to pass unused warning for now /* if (sMorph) { SWBuf popMorph = "%s", sMorph->Name(), morph.c_str(), wordID.c_str(), morph.c_str()); + popMorph.appendFormatted("p(\'%s\',\'%s\','%s','');\" >%s", sMorph->getName(), morph.c_str(), wordID.c_str(), morph.c_str()); morph = popMorph; } */ @@ -223,7 +229,6 @@ char GBFWordJS::processText(SWBuf &text, const SWKey *key, const SWModule *modul } else { text += *from; - lastspace = (*from == ' '); } } @@ -241,7 +246,7 @@ char GBFWordJS::processText(SWBuf &text, const SWKey *key, const SWModule *modul gh = isdigit(strong[0]) ? 0:strong[0]; if (!gh) { if (vkey) { - gh = vkey->Testament() ? 'H' : 'G'; + gh = vkey->getTestament() ? 'H' : 'G'; } } else strong << 1; @@ -257,7 +262,7 @@ char GBFWordJS::processText(SWBuf &text, const SWKey *key, const SWModule *modul if (sLex) { // we can pass the real lex name in, but we have some // aliases in the javascript to optimize bandwidth - lexName = sLex->Name(); + lexName = sLex->getName(); if (lexName == "StrongsGreek") lexName = "G"; if (lexName == "StrongsHebrew") @@ -266,7 +271,7 @@ char GBFWordJS::processText(SWBuf &text, const SWKey *key, const SWModule *modul SWBuf wordID; if (vkey) { // optimize for bandwidth and use only the verse as the unique entry id - wordID.appendFormatted("%d", vkey->Verse()); + wordID.appendFormatted("%d", vkey->getVerse()); } else { wordID = key->getText(); diff --git a/src/modules/filters/gbfxhtml.cpp b/src/modules/filters/gbfxhtml.cpp new file mode 100644 index 0000000..56d7663 --- /dev/null +++ b/src/modules/filters/gbfxhtml.cpp @@ -0,0 +1,236 @@ +/****************************************************************************** + * + * gbfxhtml.cpp - GBF to classed XHTML + * + * $Id: gbfxhtml.cpp 2833 2013-06-29 06:40:28Z chrislit $ + * + * Copyright 2011-2013 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 + +SWORD_NAMESPACE_START + +const char *GBFXHTML::getHeader() const { + return "\ + .wordsOfJesus {\ + color: red;\ + }\ + "; +} + +GBFXHTML::MyUserData::MyUserData(const SWModule *module, const SWKey *key) : BasicFilterUserData(module, key) { + if (module) { + version = module->getName(); + } +} + +GBFXHTML::GBFXHTML() { + setTokenStart("<"); + setTokenEnd(">"); + + setTokenCaseSensitive(true); + + //addTokenSubstitute("Rf", ")"); + addTokenSubstitute("FA", ""); // for ASV footnotes to mark text + addTokenSubstitute("Rx", ""); + addTokenSubstitute("FI", ""); // italics begin + addTokenSubstitute("Fi", ""); + addTokenSubstitute("FB", ""); // bold begin + addTokenSubstitute("Fb", ""); + addTokenSubstitute("FR", ""); // words of Jesus begin + addTokenSubstitute("Fr", ""); + addTokenSubstitute("FU", ""); // underline begin + addTokenSubstitute("Fu", ""); + addTokenSubstitute("FO", ""); // Old Testament quote begin + addTokenSubstitute("Fo", ""); + addTokenSubstitute("FS", ""); // Superscript begin// Subscript begin + addTokenSubstitute("Fs", ""); + addTokenSubstitute("FV", ""); // Subscript begin + addTokenSubstitute("Fv", ""); + addTokenSubstitute("TT", ""); // Book title begin + addTokenSubstitute("Tt", ""); + addTokenSubstitute("PP", ""); // poetry begin + addTokenSubstitute("Pp", ""); + addTokenSubstitute("Fn", ""); // font end + addTokenSubstitute("CL", "
"); // new line + addTokenSubstitute("CM", "
"); // paragraph is a non showing comment that can be changed in the front end to

if desired + addTokenSubstitute("CG", ""); // ??? + addTokenSubstitute("CT", ""); // ??? + addTokenSubstitute("JR", "

"); // right align begin + addTokenSubstitute("JC", "
"); // center align begin + addTokenSubstitute("JL", "
"); // align end + + renderNoteNumbers = false; +} + + +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 += " <<"; + for (tok = token + 2; *tok; tok++) + //if(token[i] != '\"') + buf += *tok; + buf += ">"; + } + else if (!strncmp(token, "WH", 2)) { // strong's numbers + //buf += " <<"; + for (tok = token + 2; *tok; tok++) + //if(token[i] != '\"') + buf += *tok; + buf += ">"; + } + else if (!strncmp(token, "WTG", 3)) { // strong's numbers tense + //buf += " (("; + for (tok = token + 3; *tok; tok++) + if(*tok != '\"') + buf += *tok; + buf += ")"; + } + else if (!strncmp(token, "WTH", 3)) { // strong's numbers tense + //buf += " (("; + for (tok = token + 3; *tok; tok++) + if(*tok != '\"') + buf += *tok; + buf += ")"; + } + + else if (!strncmp(token, "WT", 2) && strncmp(token, "WTH", 3) && strncmp(token, "WTG", 3)) { // morph tags + //buf += " (("; + for (tok = token + 2; *tok; tok++) + if(*tok != '\"') + buf += *tok; + buf += ")"; + } + + else if (!strcmp(tag.getName(), "RX")) { + 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("*n%s ", + 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; + } + else if (!strcmp(tag.getName(), "Rf")) { + u->suspendTextPassThru = false; + } +/* + else if (!strncmp(token, "RB", 2)) { + buf += " "; + u->hasFootnotePreTag = true; + } + + else if (!strncmp(token, "Rf", 2)) { + buf += " lastTextNode.c_str(); + buf += "\">"; + buf += "*n "; + // let's let text resume to output again + u->suspendTextPassThru = false; + } + + else if (!strncmp(token, "RF", 2)) { + if (u->hasFootnotePreTag) { + u->hasFootnotePreTag = false; + buf += " "; + } + u->suspendTextPassThru = true; + } +*/ + else if (!strncmp(token, "FN", 2)) { + buf += ""; + } + + else if (!strncmp(token, "CA", 2)) { // ASCII value + buf += (char)atoi(&token[2]); + } + + else { + return false; + } + } + return true; +} + +SWORD_NAMESPACE_END diff --git a/src/modules/filters/greeklexattribs.cpp b/src/modules/filters/greeklexattribs.cpp index e1a60a2..1c2533d 100644 --- a/src/modules/filters/greeklexattribs.cpp +++ b/src/modules/filters/greeklexattribs.cpp @@ -1,10 +1,11 @@ /****************************************************************************** * - * greeklexattribs - SWFilter descendant to set entry attributes for greek - * lexicons + * greeklexattribs.cpp - SWFilter descendant to set entry attributes + * for greek lexicons * + * $Id: greeklexattribs.cpp 2833 2013-06-29 06:40:28Z chrislit $ * - * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * Copyright 2002-2013 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society * P. O. Box 2528 * Tempe, AZ 85280-2528 diff --git a/src/modules/filters/latin1utf16.cpp b/src/modules/filters/latin1utf16.cpp index bf2f3f8..ef27245 100644 --- a/src/modules/filters/latin1utf16.cpp +++ b/src/modules/filters/latin1utf16.cpp @@ -1,10 +1,11 @@ /****************************************************************************** * - * Latin1UTF16 - SWFilter descendant to convert a Latin-1 character to UTF-16 + * latin1utf16.cpp - SWFilter descendant Latin1UTF16 to convert a Latin-1 + * character to UTF-16 * + * $Id: latin1utf16.cpp 2833 2013-06-29 06:40:28Z chrislit $ * - * - * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * Copyright 2001-2013 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society * P. O. Box 2528 * Tempe, AZ 85280-2528 diff --git a/src/modules/filters/latin1utf8.cpp b/src/modules/filters/latin1utf8.cpp index 784aafe..a784893 100644 --- a/src/modules/filters/latin1utf8.cpp +++ b/src/modules/filters/latin1utf8.cpp @@ -1,10 +1,11 @@ /****************************************************************************** * - * Latin1UTF8 - SWFilter descendant to convert a Latin-1 character to UTF-8 + * latin1utf8.cpp - SWFilter descendant Latin1UTF8 to convert a Latin-1 + * character to UTF-8 * + * $Id: latin1utf8.cpp 2980 2013-09-14 21:51:47Z scribe $ * - * - * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * Copyright 2001-2013 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society * P. O. Box 2528 * Tempe, AZ 85280-2528 @@ -25,8 +26,10 @@ #include #include + SWORD_NAMESPACE_START + Latin1UTF8::Latin1UTF8() { } @@ -35,7 +38,7 @@ char Latin1UTF8::processText(SWBuf &text, const SWKey *key, const SWModule *modu { const unsigned char *from; - if ((unsigned long)key < 2) // hack, we're en(1)/de(0)ciphering + if ((unsigned long)key < 2) // hack, we're en(1)/de(0)ciphering return (char)-1; SWBuf orig = text; @@ -185,4 +188,5 @@ char Latin1UTF8::processText(SWBuf &text, const SWKey *key, const SWModule *modu return 0; } + SWORD_NAMESPACE_END diff --git a/src/modules/filters/osisenum.cpp b/src/modules/filters/osisenum.cpp new file mode 100644 index 0000000..db433b0 --- /dev/null +++ b/src/modules/filters/osisenum.cpp @@ -0,0 +1,99 @@ +/****************************************************************************** + * + * osisenum.cpp - SWFilter descendant to hide or show word enumations + * in an OSIS module + * + * $Id: osisenum.cpp 2980 2013-09-14 21:51:47Z scribe $ + * + * Copyright 2013 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 + + +SWORD_NAMESPACE_START + +namespace { + + static const char oName[] = "Enumerations"; + static const char oTip[] = "Toggles Enumerations On and Off if they exist"; + + static const StringList *oValues() { + static const SWBuf choices[3] = {"Off", "On", ""}; + static const StringList oVals(&choices[0], &choices[2]); + return &oVals; + } +} + + +OSISEnum::OSISEnum() : SWOptionFilter(oName, oTip, oValues()) { +} + + +OSISEnum::~OSISEnum() { +} + + +char OSISEnum::processText(SWBuf &text, const SWKey *key, const SWModule *module) { + SWBuf token; + bool intoken = false; + + const SWBuf orig = text; + const char * from = orig.c_str(); + + if (!option) { + for (text = ""; *from; ++from) { + if (*from == '<') { + intoken = true; + token = ""; + continue; + } + if (*from == '>') { // process tokens + intoken = false; + if (token.startsWith("w ")) { // Word + XMLTag wtag(token); + const char *l = wtag.getAttribute("n"); + if (l) { + wtag.setAttribute("n", 0); + token = wtag; + token.trim(); + // drop <> + token << 1; + token--; + } + } + + // keep token in text + text.append('<'); + text.append(token); + text.append('>'); + + continue; + } + if (intoken) { + token += *from; + } + else { + text.append(*from); + } + } + } + return 0; +} + +SWORD_NAMESPACE_END diff --git a/src/modules/filters/osisfootnotes.cpp b/src/modules/filters/osisfootnotes.cpp index 3d0d2d4..8008d5c 100644 --- a/src/modules/filters/osisfootnotes.cpp +++ b/src/modules/filters/osisfootnotes.cpp @@ -1,10 +1,11 @@ /****************************************************************************** * - * osisfootnotes - SWFilter descendant to hide or show footnotes - * in an OSIS module. + * osisfootnotes.cpp - SWFilter descendant to hide or show footnotes + * in an OSIS module * + * $Id: osisfootnotes.cpp 2980 2013-09-14 21:51:47Z scribe $ * - * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * Copyright 2003-2013 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society * P. O. Box 2528 * Tempe, AZ 85280-2528 @@ -29,17 +30,23 @@ #include #include + SWORD_NAMESPACE_START -const char oName[] = "Footnotes"; -const char oTip[] = "Toggles Footnotes On and Off if they exist"; +namespace { + + static const char oName[] = "Footnotes"; + static const char oTip[] = "Toggles Footnotes On and Off if they exist"; -const SWBuf choices[3] = {"Off", "On", ""}; -const StringList oValues(&choices[0], &choices[2]); + static const StringList *oValues() { + static const SWBuf choices[3] = {"Off", "On", ""}; + static const StringList oVals(&choices[0], &choices[2]); + return &oVals; + } +} -OSISFootnotes::OSISFootnotes() : SWOptionFilter(oName, oTip, &oValues) { - setOptionValue("Off"); +OSISFootnotes::OSISFootnotes() : SWOptionFilter(oName, oTip, oValues()) { } @@ -56,7 +63,7 @@ char OSISFootnotes::processText(SWBuf &text, const SWKey *key, const SWModule *m SWBuf refs = ""; int footnoteNum = 1; char buf[254]; - SWKey *p = (module) ? module->CreateKey() : (key) ? key->clone() : new VerseKey(); + SWKey *p = (module) ? module->createKey() : (key) ? key->clone() : new VerseKey(); VerseKey *parser = SWDYNAMIC_CAST(VerseKey, p); if (!parser) { delete p; @@ -122,7 +129,7 @@ char OSISFootnotes::processText(SWBuf &text, const SWKey *key, const SWModule *m startTag.setAttribute("swordFootnote", buf); if ((startTag.getAttribute("type")) && (!strcmp(startTag.getAttribute("type"), "crossReference"))) { if (!refs.length()) - refs = parser->ParseVerseList(tagText.c_str(), *parser, true).getRangeText(); + refs = parser->parseVerseList(tagText.c_str(), *parser, true).getRangeText(); module->getEntryAttributes()["Footnote"][buf]["refList"] = refs.c_str(); } } diff --git a/src/modules/filters/osisglosses.cpp b/src/modules/filters/osisglosses.cpp new file mode 100644 index 0000000..d232acc --- /dev/null +++ b/src/modules/filters/osisglosses.cpp @@ -0,0 +1,99 @@ +/****************************************************************************** + * + * osisglosses.cpp - SWFilter descendant to hide or show glosses + * in an OSIS module + * + * $Id: osisglosses.cpp 2980 2013-09-14 21:51:47Z scribe $ + * + * Copyright 2013 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 + + +SWORD_NAMESPACE_START + +namespace { + + static const char oName[] = "Glosses"; + static const char oTip[] = "Toggles Glosses On and Off if they exist"; + + static const StringList *oValues() { + static const SWBuf choices[3] = {"Off", "On", ""}; + static const StringList oVals(&choices[0], &choices[2]); + return &oVals; + } +} + + +OSISGlosses::OSISGlosses() : SWOptionFilter(oName, oTip, oValues()) { +} + + +OSISGlosses::~OSISGlosses() { +} + + +char OSISGlosses::processText(SWBuf &text, const SWKey *key, const SWModule *module) { + SWBuf token; + bool intoken = false; + + const SWBuf orig = text; + const char * from = orig.c_str(); + + if (!option) { + for (text = ""; *from; ++from) { + if (*from == '<') { + intoken = true; + token = ""; + continue; + } + if (*from == '>') { // process tokens + intoken = false; + if (token.startsWith("w ")) { // Word + XMLTag wtag(token); + const char *l = wtag.getAttribute("gloss"); + if (l) { + wtag.setAttribute("gloss", 0); + token = wtag; + token.trim(); + // drop <> + token << 1; + token--; + } + } + + // keep token in text + text.append('<'); + text.append(token); + text.append('>'); + + continue; + } + if (intoken) { + token += *from; + } + else { + text.append(*from); + } + } + } + return 0; +} + +SWORD_NAMESPACE_END diff --git a/src/modules/filters/osisheadings.cpp b/src/modules/filters/osisheadings.cpp index 8872f24..783fa81 100644 --- a/src/modules/filters/osisheadings.cpp +++ b/src/modules/filters/osisheadings.cpp @@ -1,10 +1,11 @@ /****************************************************************************** * - *osisheadings - SWFilter descendant to hide or show headings - * in an OSIS module. + * osisheadings.cpp - SWFilter descendant to hide or show headings + * in an OSIS module * + * $Id: osisheadings.cpp 2980 2013-09-14 21:51:47Z scribe $ * - * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * Copyright 2003-2013 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society * P. O. Box 2528 * Tempe, AZ 85280-2528 @@ -27,151 +28,120 @@ #include #include + SWORD_NAMESPACE_START -const char oName[] = "Headings"; -const char oTip[] = "Toggles Headings On and Off if they exist"; +namespace { + + static const char oName[] = "Headings"; + static const char oTip[] = "Toggles Headings On and Off if they exist"; + + static const StringList *oValues() { + static const SWBuf choices[3] = {"Off", "On", ""}; + static const StringList oVals(&choices[0], &choices[2]); + return &oVals; + } + -const SWBuf choices[3] = {"Off", "On", ""}; -const StringList oValues(&choices[0], &choices[2]); + class MyUserData : public BasicFilterUserData { + public: + SWBuf currentHeadingName; + XMLTag currentHeadingTag; + const char *sID; + SWBuf heading; + int depth; + int headerNum; -OSISHeadings::OSISHeadings() : SWOptionFilter(oName, oTip, &oValues) { - setOptionValue("Off"); + MyUserData(const SWModule *module, const SWKey *key) : BasicFilterUserData(module, key) { + clear(); + } + void clear() { + currentHeadingName = ""; + currentHeadingTag = ""; + sID = 0; + heading = ""; + depth = 0; + headerNum = 0; + } + }; } -OSISHeadings::~OSISHeadings() { +BasicFilterUserData *OSISHeadings::createUserData(const SWModule *module, const SWKey *key) { + return new MyUserData(module, key); } -char OSISHeadings::processText(SWBuf &text, const SWKey *key, const SWModule *module) { - SWBuf token; - bool intoken = false; - bool hide = false; - bool preverse = false; - bool withinTitle = false; - bool withinPreverseDiv = false; - SWBuf preverseDivID = ""; - const char *pvDID = 0; - bool canonical = false; - SWBuf header; - int headerNum = 0; - int pvHeaderNum = 0; - char buf[254]; - XMLTag startTag; - - SWBuf orig = text; - const char *from = orig.c_str(); - - XMLTag tag; - - for (text = ""; *from; ++from) { - if (*from == '<') { - intoken = true; - token = ""; - - continue; - } - if (*from == '>') { // process tokens - intoken = false; - tag = token; - - //
(
## when in previous) - if ( (!withinPreverseDiv && !strcmp(tag.getName(), "title")) || - (!strcmp(tag.getName(), "div") && - ((withinPreverseDiv && (tag.isEndTag(pvDID))) || - (tag.getAttribute("subType") && !strcmp(tag.getAttribute("subType"), "x-preverse"))) - )) { - - withinTitle = (!tag.isEndTag(pvDID)); - if (!strcmp(tag.getName(), "div")) { - withinPreverseDiv = (!tag.isEndTag(pvDID)); - if (!pvDID) { - preverseDivID = tag.getAttribute("sID"); - pvDID = (preverseDivID.length())? preverseDivID.c_str() : 0; - } - } - - if (!tag.isEndTag(pvDID)) { //start tag - if (!tag.isEmpty() || pvDID) { - startTag = tag; - } - } - - if ( !tag.isEndTag(pvDID) && (withinPreverseDiv - || (tag.getAttribute("subType") && !stricmp(tag.getAttribute("subType"), "x-preverse")) - || (tag.getAttribute("subtype") && !stricmp(tag.getAttribute("subtype"), "x-preverse")) // deprecated - )) { - hide = true; - preverse = true; - header = ""; - canonical = (tag.getAttribute("canonical") && (!stricmp(tag.getAttribute("canonical"), "true"))); - continue; - } - if (!tag.isEndTag(pvDID)) { //start tag - hide = true; - header = ""; - if (option || canonical) { // we want the tag in the text - text.append('<'); - text.append(token); - text.append('>'); - } - continue; - } - if (hide && tag.isEndTag(pvDID)) { - if (module->isProcessEntryAttributes() && ((option || canonical) || (!preverse))) { - if (preverse) { - sprintf(buf, "%i", pvHeaderNum++); - module->getEntryAttributes()["Heading"]["Preverse"][buf] = header; - } - else { - sprintf(buf, "%i", headerNum++); - module->getEntryAttributes()["Heading"]["Interverse"][buf] = header; - if (option || canonical) { // we want the tag in the text - text.append(header); - } - } - - StringList attributes = startTag.getAttributeNames(); +OSISHeadings::OSISHeadings() : SWOptionFilter(oName, oTip, oValues()) { + setPassThruUnknownToken(true); +} + + +bool OSISHeadings::handleToken(SWBuf &buf, const char *token, BasicFilterUserData *userData) { + + MyUserData *u = (MyUserData *)userData; + XMLTag tag(token); + SWBuf name = tag.getName(); + + // we only care about titles and divs or if we're already in a heading + // + // are we currently in a heading? + if (u->currentHeadingName.size()) { + u->heading.append(u->lastTextNode); + if (name == u->currentHeadingName) { + if (tag.isEndTag(u->sID)) { + if (!u->depth-- || u->sID) { + // we've just finished a heading. It's all stored up in u->heading + bool canonical = (SWBuf("true") == u->currentHeadingTag.getAttribute("canonical")); + bool preverse = (SWBuf("x-preverse") == u->currentHeadingTag.getAttribute("subType") || SWBuf("x-preverse") == u->currentHeadingTag.getAttribute("subtype")); + + // do we want to put anything in EntryAttributes? + if (u->module->isProcessEntryAttributes() && (option || canonical || !preverse)) { + SWBuf buf; buf.appendFormatted("%i", u->headerNum++); + u->module->getEntryAttributes()["Heading"][(preverse)?"Preverse":"Interverse"][buf] = u->heading; + + StringList attributes = u->currentHeadingTag.getAttributeNames(); for (StringList::const_iterator it = attributes.begin(); it != attributes.end(); it++) { - module->getEntryAttributes()["Heading"][buf][it->c_str()] = startTag.getAttribute(it->c_str()); + u->module->getEntryAttributes()["Heading"][buf][it->c_str()] = u->currentHeadingTag.getAttribute(it->c_str()); } } - - hide = false; - if (!(option || canonical) || preverse) { // we don't want the tag in the text anymore - preverse = false; - continue; - } - preverse = false; - pvDID = 0; - } - } - if (withinTitle) { - header.append('<'); - header.append(token); - header.append('>'); - } else { - // if not a heading token, keep token in text - if (!hide) { - text.append('<'); - text.append(token); - text.append('>'); + // do we want the heading in the body? + if (!preverse && (option || canonical)) { + buf.append(u->currentHeadingTag); + buf.append(u->heading); + buf.append(tag); + } + u->suspendTextPassThru = false; + u->clear(); } } - continue; + else u->depth++; } - if (intoken) { //copy token - token.append(*from); - } - else if (!hide) { //copy text which is not inside a token - text.append(*from); - } - else header.append(*from); + u->heading.append(tag); + return true; } - return 0; + + // are we a title or a preverse div? + else if ( name == "title" + || (name == "div" + && ( SWBuf("x-preverse") == tag.getAttribute("subType") + || SWBuf("x-preverse") == tag.getAttribute("subtype")))) { + + u->currentHeadingName = name; + u->currentHeadingTag = tag; + u->heading = ""; + u->sID = u->currentHeadingTag.getAttribute("sID"); + u->depth = 0; + u->suspendTextPassThru = true; + + return true; + } + + return false; } + + SWORD_NAMESPACE_END diff --git a/src/modules/filters/osishtmlhref.cpp b/src/modules/filters/osishtmlhref.cpp index 3406e1b..74b2da7 100644 --- a/src/modules/filters/osishtmlhref.cpp +++ b/src/modules/filters/osishtmlhref.cpp @@ -1,11 +1,10 @@ /*************************************************************************** - * osishtmlhref.cpp - OSIS to HTML with hrefs filter - * ------------------- - * begin : 2003-06-24 - * copyright : 2003 by CrossWire Bible Society + * + * osishtmlhref.cpp - OSIS to HTML with hrefs filter * + * $Id: osishtmlhref.cpp 3005 2014-01-09 04:06:11Z greg.hellings $ * - * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * Copyright 2003-2013 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society * P. O. Box 2528 * Tempe, AZ 85280-2528 @@ -36,60 +35,6 @@ SWORD_NAMESPACE_START namespace { typedef std::stack TagStack; -} - -// TODO: this bridge pattern is to preserve binary compat on 1.6.x -class OSISHTMLHREF::TagStacks { -public: - TagStack quoteStack; - TagStack hiStack; -}; - -OSISHTMLHREF::MyUserData::MyUserData(const SWModule *module, const SWKey *key) : BasicFilterUserData(module, key) { - inXRefNote = false; - suspendLevel = 0; - tagStacks = new TagStacks(); - wordsOfChristStart = " "; - wordsOfChristEnd = " "; - if (module) { - osisQToTick = ((!module->getConfigEntry("OSISqToTick")) || (strcmp(module->getConfigEntry("OSISqToTick"), "false"))); - version = module->Name(); - BiblicalText = (!strcmp(module->Type(), "Biblical Texts")); - } - else { - osisQToTick = true; // default - version = ""; - } -} - -OSISHTMLHREF::MyUserData::~MyUserData() { - delete tagStacks; -} - -OSISHTMLHREF::OSISHTMLHREF() { - setTokenStart("<"); - setTokenEnd(">"); - - setEscapeStart("&"); - setEscapeEnd(";"); - - setEscapeStringCaseSensitive(true); - setPassThruNumericEscapeString(true); - - addAllowedEscapeString("quot"); - addAllowedEscapeString("apos"); - addAllowedEscapeString("amp"); - addAllowedEscapeString("lt"); - addAllowedEscapeString("gt"); - - setTokenCaseSensitive(true); - - // addTokenSubstitute("lg", "
"); - // addTokenSubstitute("/lg", "
"); - - morphFirst = false; -} - // though this might be slightly slower, possibly causing an extra bool check, this is a renderFilter // so speed isn't the absolute highest priority, and this is a very minor possible hit static inline void outText(const char *t, SWBuf &o, BasicFilterUserData *u) { if (!u->suspendTextPassThru) o += t; else u->lastSuspendSegment += t; } @@ -157,6 +102,61 @@ void processMorph(bool suspendTextPassThru, XMLTag &tag, SWBuf &buf) { //} } } +} // end anonymous namespace + +// TODO: this bridge pattern is to preserve binary compat on 1.6.x +class OSISHTMLHREF::TagStacks { +public: + TagStack quoteStack; + TagStack hiStack; +}; + +OSISHTMLHREF::MyUserData::MyUserData(const SWModule *module, const SWKey *key) : BasicFilterUserData(module, key) { + inXRefNote = false; + suspendLevel = 0; + tagStacks = new TagStacks(); + wordsOfChristStart = " "; + wordsOfChristEnd = " "; + if (module) { + osisQToTick = ((!module->getConfigEntry("OSISqToTick")) || (strcmp(module->getConfigEntry("OSISqToTick"), "false"))); + version = module->getName(); + BiblicalText = (!strcmp(module->getType(), "Biblical Texts")); + } + else { + osisQToTick = true; // default + version = ""; + } +} + +OSISHTMLHREF::MyUserData::~MyUserData() { + delete tagStacks; +} + +OSISHTMLHREF::OSISHTMLHREF() { + setTokenStart("<"); + setTokenEnd(">"); + + setEscapeStart("&"); + setEscapeEnd(";"); + + setEscapeStringCaseSensitive(true); + setPassThruNumericEscapeString(true); + + addAllowedEscapeString("quot"); + addAllowedEscapeString("apos"); + addAllowedEscapeString("amp"); + addAllowedEscapeString("lt"); + addAllowedEscapeString("gt"); + + setTokenCaseSensitive(true); + + // addTokenSubstitute("lg", "
"); + // addTokenSubstitute("/lg", "
"); + + morphFirst = false; + renderNoteNumbers = false; +} + bool OSISHTMLHREF::handleToken(SWBuf &buf, const char *token, BasicFilterUserData *userData) { MyUserData *u = (MyUserData *)userData; @@ -240,6 +240,7 @@ bool OSISHTMLHREF::handleToken(SWBuf &buf, const char *token, BasicFilterUserDat 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'); @@ -251,25 +252,14 @@ bool OSISHTMLHREF::handleToken(SWBuf &buf, const char *token, BasicFilterUserDat vkey = SWDYNAMIC_CAST(VerseKey, u->key); } SWCATCH ( ... ) { } - if (vkey) { - //printf("URL = %s\n",URL::encode(vkey->getText()).c_str()); - buf.appendFormatted("*%c", - ch, - URL::encode(footnoteNumber.c_str()).c_str(), - URL::encode(u->version.c_str()).c_str(), - URL::encode(vkey->getText()).c_str(), - ch, - ch); - } - else { - buf.appendFormatted("*%c", - 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); - } + buf.appendFormatted("*%c%s", + 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); @@ -381,7 +371,7 @@ bool OSISHTMLHREF::handleToken(SWBuf &buf, const char *token, BasicFilterUserDat } // - else if (!strcmp(tag.getName(), "lb")) { + else if (!strcmp(tag.getName(), "lb") && (!tag.getAttribute("type") || strcmp(tag.getAttribute("type"), "x-optional"))) { outText("
", buf, u); userData->supressAdjacentWhitespace = true; } @@ -485,10 +475,15 @@ bool OSISHTMLHREF::handleToken(SWBuf &buf, const char *token, BasicFilterUserDat // text highlighting else if (!strcmp(tag.getName(), "hi")) { SWBuf type = tag.getAttribute("type"); + // handle tei rend attribute + if (!type.length()) type = tag.getAttribute("rend"); if ((!tag.isEndTag()) && (!tag.isEmpty())) { if (type == "bold" || type == "b" || type == "x-b") { outText("", buf, u); } + else if (type == "ol") { + outText("", buf, u); + } else { // all other types outText("", buf, u); } @@ -500,10 +495,14 @@ bool OSISHTMLHREF::handleToken(SWBuf &buf, const char *token, BasicFilterUserDat XMLTag tag(u->tagStacks->hiStack.top()); u->tagStacks->hiStack.pop(); type = tag.getAttribute("type"); + if (!type.length()) type = tag.getAttribute("rend"); } if (type == "bold" || type == "b" || type == "x-b") { outText("", buf, u); } + else if (type == "ol") { + outText("", buf, u); + } else outText("", buf, u); } } diff --git a/src/modules/filters/osislemma.cpp b/src/modules/filters/osislemma.cpp index 7b56024..cf5d8f4 100644 --- a/src/modules/filters/osislemma.cpp +++ b/src/modules/filters/osislemma.cpp @@ -1,10 +1,11 @@ /****************************************************************************** * - * osislemma - SWFilter descendant to hide or show lemmata - * in a OSIS module. + * osislemma.cpp - SWFilter descendant to hide or show lemmata + * in a OSIS module * + * $Id: osislemma.cpp 2980 2013-09-14 21:51:47Z scribe $ * - * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * Copyright 2003-2013 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society * P. O. Box 2528 * Tempe, AZ 85280-2528 @@ -24,16 +25,23 @@ #include #include + SWORD_NAMESPACE_START -const char oName[] = "Lemmas"; -const char oTip[] = "Toggles Lemmas On and Off if they exist"; +namespace { + + static const char oName[] = "Lemmas"; + static const char oTip[] = "Toggles Lemmas On and Off if they exist"; + + static const StringList *oValues() { + static const SWBuf choices[3] = {"Off", "On", ""}; + static const StringList oVals(&choices[0], &choices[2]); + return &oVals; + } +} -const SWBuf choices[3] = {"Off", "On", ""}; -const StringList oValues(&choices[0], &choices[2]); -OSISLemma::OSISLemma() : SWOptionFilter(oName, oTip, &oValues) { - setOptionValue("Off"); +OSISLemma::OSISLemma() : SWOptionFilter(oName, oTip, oValues()) { } @@ -44,7 +52,6 @@ OSISLemma::~OSISLemma() { char OSISLemma::processText(SWBuf &text, const SWKey *key, const SWModule *module) { SWBuf token; bool intoken = false; - bool lastspace = false; const SWBuf orig = text; const char * from = orig.c_str(); @@ -90,7 +97,6 @@ char OSISLemma::processText(SWBuf &text, const SWKey *key, const SWModule *modul } else { text.append(*from); - lastspace = (*from == ' '); } } } diff --git a/src/modules/filters/osismorph.cpp b/src/modules/filters/osismorph.cpp index 7ceec79..71de8e5 100644 --- a/src/modules/filters/osismorph.cpp +++ b/src/modules/filters/osismorph.cpp @@ -1,10 +1,11 @@ /****************************************************************************** * - * osismorph - SWFilter descendant to hide or show morph tags - * in a OSIS module. + * osismorph.cpp - SWFilter descendant to hide or show morph tags + * in a OSIS module * + * $Id: osismorph.cpp 2980 2013-09-14 21:51:47Z scribe $ * - * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * Copyright 2003-2013 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society * P. O. Box 2528 * Tempe, AZ 85280-2528 @@ -25,14 +26,20 @@ SWORD_NAMESPACE_START -const char oName[] = "Morphological Tags"; -const char oTip[] = "Toggles Morphological Tags On and Off if they exist"; +namespace { -const SWBuf choices[3] = {"Off", "On", ""}; -const StringList oValues(&choices[0], &choices[2]); + static const char oName[] = "Morphological Tags"; + static const char oTip[] = "Toggles Morphological Tags On and Off if they exist"; -OSISMorph::OSISMorph() : SWOptionFilter(oName, oTip, &oValues) { - setOptionValue("Off"); + static const StringList *oValues() { + static const SWBuf choices[3] = {"Off", "On", ""}; + static const StringList oVals(&choices[0], &choices[2]); + return &oVals; + } + +} + +OSISMorph::OSISMorph() : SWOptionFilter(oName, oTip, oValues()) { } @@ -45,7 +52,6 @@ char OSISMorph::processText(SWBuf &text, const SWKey *key, const SWModule *modul char token[2048]; // cheese. Fix. int tokpos = 0; bool intoken = false; - bool lastspace = false; SWBuf orig = text; const char *from = orig.c_str(); @@ -90,7 +96,6 @@ char OSISMorph::processText(SWBuf &text, const SWKey *key, const SWModule *modul } else { text.append(*from); - lastspace = (*from == ' '); } } } diff --git a/src/modules/filters/osismorphsegmentation.cpp b/src/modules/filters/osismorphsegmentation.cpp index fef7af7..9afc0a1 100644 --- a/src/modules/filters/osismorphsegmentation.cpp +++ b/src/modules/filters/osismorphsegmentation.cpp @@ -1,10 +1,12 @@ /****************************************************************************** * - * osismorphsegmentation - SWFilter descendant to toggle splitting of morphemes - * (for morpheme segmented Hebrew in the WLC) + * osismorphsegmentation.cpp - SWFilter descendant to toggle splitting of + * morphemes (for morpheme segmented Hebrew in + * the WLC) * + * $Id: osismorphsegmentation.cpp 2980 2013-09-14 21:51:47Z scribe $ * - * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * Copyright 2006-2013 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society * P. O. Box 2528 * Tempe, AZ 85280-2528 @@ -26,16 +28,23 @@ #include #include + SWORD_NAMESPACE_START -const char oName[] = "Morpheme Segmentation"; -const char oTip[] = "Toggles Morpheme Segmentation On and Off, when present"; +namespace { + + static const char oName[] = "Morpheme Segmentation"; + static const char oTip[] = "Toggles Morpheme Segmentation On and Off, when present"; + + static const StringList *oValues() { + static const SWBuf choices[3] = {"Off", "On", ""}; + static const StringList oVals(&choices[0], &choices[2]); + return &oVals; + } +} -const SWBuf choices[3] = {"Off", "On", ""}; -const StringList oValues(&choices[0], &choices[2]); -OSISMorphSegmentation::OSISMorphSegmentation() : SWOptionFilter(oName, oTip, &oValues) { - setOptionValue("Off"); +OSISMorphSegmentation::OSISMorphSegmentation() : SWOptionFilter(oName, oTip, oValues()) { } diff --git a/src/modules/filters/osisosis.cpp b/src/modules/filters/osisosis.cpp index 82a6bfc..2bc5cbb 100644 --- a/src/modules/filters/osisosis.cpp +++ b/src/modules/filters/osisosis.cpp @@ -1,10 +1,10 @@ /*************************************************************************** - * osisosis.cpp - internal OSIS to public OSIS filter - * ------------------- - * begin : 2004-03-13 - * copyright : 2003 by CrossWire Bible Society * - * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * osisosis.cpp - internal OSIS to public OSIS filter + * + * $Id: osisosis.cpp 2833 2013-06-29 06:40:28Z chrislit $ + * + * Copyright 2004-2013 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society * P. O. Box 2528 * Tempe, AZ 85280-2528 @@ -59,7 +59,7 @@ char OSISOSIS::processText(SWBuf &text, const SWKey *key, const SWModule *module VerseKey *vkey = SWDYNAMIC_CAST(VerseKey, key); if (vkey) { SWBuf ref = ""; - if (vkey->Verse()) { + if (vkey->getVerse()) { ref.appendFormatted("\t\t", vkey->getOSISRef()); } @@ -67,24 +67,24 @@ char OSISOSIS::processText(SWBuf &text, const SWKey *key, const SWModule *module text = ref + text; - if (vkey->Verse()) { + if (vkey->getVerse()) { VerseKey *tmp = (VerseKey *)vkey->clone(); *tmp = *vkey; - tmp->AutoNormalize(0); - tmp->Headings(1); + tmp->setAutoNormalize(false); + tmp->setIntros(true); text += ""; *tmp = MAXVERSE; if (*vkey == *tmp) { - tmp->Verse(0); + tmp->setVerse(0); // sprintf(ref, "\t
"); // pushString(&to, ref); *tmp = MAXCHAPTER; *tmp = MAXVERSE; if (*vkey == *tmp) { - tmp->Chapter(0); - tmp->Verse(0); + tmp->setChapter(0); + tmp->setVerse(0); // sprintf(ref, "\t"); // pushString(&to, ref); } diff --git a/src/modules/filters/osisplain.cpp b/src/modules/filters/osisplain.cpp index 57105f0..6e583a4 100644 --- a/src/modules/filters/osisplain.cpp +++ b/src/modules/filters/osisplain.cpp @@ -1,10 +1,10 @@ /****************************************************************************** - * osisplain.cpp - An SWFilter - * impl that provides stripping of OSIS tags * - * $Id: osisplain.cpp 2334 2009-04-24 00:14:12Z scribe $ + * osisplain.cpp - An SWFilter that provides stripping of OSIS tags * - * Copyright 2001 CrossWire Bible Society (http://www.crosswire.org) + * $Id: osisplain.cpp 2984 2013-09-20 12:18:45Z scribe $ + * + * Copyright 2003-2013 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society * P. O. Box 2528 * Tempe, AZ 85280-2528 @@ -28,17 +28,21 @@ SWORD_NAMESPACE_START + namespace { -class MyUserData : public BasicFilterUserData { -public: - SWBuf w; - XMLTag tag; - VerseKey *vk; - char testament; - MyUserData(const SWModule *module, const SWKey *key) : BasicFilterUserData(module, key) {} -}; + + class MyUserData : public BasicFilterUserData { + public: + SWBuf w; + XMLTag tag; + VerseKey *vk; + char testament; + SWBuf hiType; + MyUserData(const SWModule *module, const SWKey *key) : BasicFilterUserData(module, key) {} + }; } + OSISPlain::OSISPlain() { setTokenStart("<"); setTokenEnd(">"); @@ -65,7 +69,7 @@ OSISPlain::OSISPlain() { BasicFilterUserData *OSISPlain::createUserData(const SWModule *module, const SWKey *key) { MyUserData *u = new MyUserData(module, key); u->vk = SWDYNAMIC_CAST(VerseKey, u->key); - u->testament = (u->vk) ? u->vk->Testament() : 2; // default to NT + u->testament = (u->vk) ? u->vk->getTestament() : 2; // default to NT return u; } @@ -202,6 +206,40 @@ bool OSISPlain::handleToken(SWBuf &buf, const char *token, BasicFilterUserData * end += buf.size() - u->lastTextNode.size(); toupperstr(end); } + else if (!strncmp(token, "hi", 2)) { + + // handle both OSIS 'type' and TEI 'rend' attributes + // there is no officially supported OSIS overline attribute, + // thus either TEI overline or OSIS x-overline would be best, + // but we have used "ol" in the past, as well. Once a valid + // OSIS overline attribute is made available, these should all + // eventually be deprecated and never documented that they are supported. + if (strstr(token, "rend=\"ol\"") || strstr(token, "rend=\"x-overline\"") || strstr(token, "rend=\"overline\"") + || strstr(token, "type=\"ol\"") || strstr(token, "type=\"x-overline\"") || strstr(token, "type=\"overline\"")) { + u->hiType = "overline"; + } + else u->hiType = ""; + u->suspendTextPassThru = true; + } + else if (!strncmp(token, "/hi", 3)) { + if (u->hiType == "overline") { + const unsigned char *b = (const unsigned char *)u->lastTextNode.c_str(); + while (*b) { + const unsigned char *o = b; + if (getUniCharFromUTF8(&b)) { + while (o != b) buf.append(*(o++)); + buf.append((unsigned char)0xCC); + buf.append((unsigned char)0x85); + } + } + } + else { + buf.append("*"); + buf.append(u->lastTextNode); + buf.append("*"); + } + u->suspendTextPassThru = false; + } // else if (!strncmp(token, "milestone", 9)) { diff --git a/src/modules/filters/osisredletterwords.cpp b/src/modules/filters/osisredletterwords.cpp index 9075fd8..e7c921c 100644 --- a/src/modules/filters/osisredletterwords.cpp +++ b/src/modules/filters/osisredletterwords.cpp @@ -1,10 +1,11 @@ /****************************************************************************** * - * OSISRedLetterWords - SWFilter descendant to toggle red coloring for words - * of Christ in an OSIS module. + * osisredletterwords.cpp - SWFilter descendant to toggle red coloring for + * words of Christ in an OSIS module * + * $Id: osisredletterwords.cpp 2980 2013-09-14 21:51:47Z scribe $ * - * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * Copyright 2003-2013 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society * P. O. Box 2528 * Tempe, AZ 85280-2528 @@ -27,14 +28,20 @@ SWORD_NAMESPACE_START -const char oName[] = "Words of Christ in Red"; -const char oTip[] = "Toggles Red Coloring for Words of Christ On and Off if they are marked"; +namespace { -const SWBuf choices[3] = {"Off", "On", ""}; -const StringList oValues(&choices[0], &choices[2]); + static const char oName[] = "Words of Christ in Red"; + static const char oTip[] = "Toggles Red Coloring for Words of Christ On and Off if they are marked"; -OSISRedLetterWords::OSISRedLetterWords() : SWOptionFilter(oName, oTip, &oValues) { - setOptionValue("On"); + static const StringList *oValues() { + static const SWBuf choices[3] = {"On", "Off", ""}; + static const StringList oVals(&choices[0], &choices[2]); + return &oVals; + } +} + + +OSISRedLetterWords::OSISRedLetterWords() : SWOptionFilter(oName, oTip, oValues()) { } diff --git a/src/modules/filters/osisreferencelinks.cpp b/src/modules/filters/osisreferencelinks.cpp new file mode 100644 index 0000000..83308e4 --- /dev/null +++ b/src/modules/filters/osisreferencelinks.cpp @@ -0,0 +1,114 @@ +/****************************************************************************** + * + * osisreferencelinks.cpp - SWFilter descendant to toggle OSIS reference + * links with specified type/subType + * + * $Id: osisreferencelinks.cpp 2995 2013-12-28 06:32:26Z greg.hellings $ + * + * Copyright 2001-2013 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 + + +SWORD_NAMESPACE_START + + +namespace { + + static const StringList *oValues() { + static const SWBuf choices[3] = {"On", "Off", ""}; + static const StringList oVals(&choices[0], &choices[2]); + return &oVals; + } +} + + +OSISReferenceLinks::OSISReferenceLinks(const char *optionName, const char *optionTip, const char *type, const char *subType, const char *defaultValue) + : SWOptionFilter(), + optionName(optionName), + optionTip(optionTip), + type(type), + subType(subType) { + + optName = this->optionName.c_str(); + optTip = this->optionTip.c_str(); + optValues = oValues(); + setOptionValue(defaultValue); +} + + +OSISReferenceLinks::~OSISReferenceLinks() { +} + + +char OSISReferenceLinks::processText(SWBuf &text, const SWKey *key, const SWModule *module) { + if (option) return 0; + + SWBuf token; + bool intoken = false; + bool stripThisToken = false; + + SWBuf orig = text; + const char *from = orig.c_str(); + + for (text = ""; *from; ++from) { + if (*from == '<') { + intoken = true; + token = ""; + continue; + } + else if (*from == '>') { // process tokens + intoken = false; + if (strncmp(token, "reference", 9) && strncmp(token.c_str(), "/reference", 10)) { + text.append('<'); + text.append(token); + text.append('>'); + } + else { + XMLTag tag; + tag = token; + if (!tag.isEndTag() && type == tag.getAttribute("type") && (!subType.size() || subType == tag.getAttribute("subType"))) { + stripThisToken = true; + continue; + } + else if (tag.isEndTag() && stripThisToken) { + stripThisToken = false; + continue; + } + text.append('<'); + text.append(token); + text.append('>'); + } + continue; + } + + if (intoken) { //copy token + token.append(*from); + } + else { //copy text which is not inside a token + text.append(*from); + } + } + return 0; +} + +SWORD_NAMESPACE_END + + diff --git a/src/modules/filters/osisrtf.cpp b/src/modules/filters/osisrtf.cpp index b8cf30c..291aa08 100644 --- a/src/modules/filters/osisrtf.cpp +++ b/src/modules/filters/osisrtf.cpp @@ -1,11 +1,10 @@ /*************************************************************************** - * osisrtf.cpp - OSIS to RTF filter - * ------------------- - * begin : 2003-02-15 - * copyright : 2003 by CrossWire Bible Society * + * osisrtf.cpp - OSIS to RTF filter * - * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * $Id: osisrtf.cpp 3005 2014-01-09 04:06:11Z greg.hellings $ * + * + * Copyright 2003-2013 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society * P. O. Box 2528 * Tempe, AZ 85280-2528 @@ -53,8 +52,8 @@ namespace { BiblicalText = false; suspendLevel = 0; if (module) { - version = module->Name(); - BiblicalText = (!strcmp(module->Type(), "Biblical Texts")); + version = module->getName(); + BiblicalText = (!strcmp(module->getType(), "Biblical Texts")); } osisQToTick = ((!module->getConfigEntry("OSISqToTick")) || (strcmp(module->getConfigEntry("OSISqToTick"), "false"))); } @@ -68,9 +67,11 @@ namespace { delete [] tagData; } } -static inline void outText(const char *t, SWBuf &o, BasicFilterUserData *u) { if (!u->suspendTextPassThru) o += t; else u->lastSuspendSegment += t; } -static inline void outText(char t, SWBuf &o, BasicFilterUserData *u) { if (!u->suspendTextPassThru) o += t; else u->lastSuspendSegment += t; } -}; + + static inline void outText(const char *t, SWBuf &o, BasicFilterUserData *u) { if (!u->suspendTextPassThru) o += t; else u->lastSuspendSegment += t; } + static inline void outText(char t, SWBuf &o, BasicFilterUserData *u) { if (!u->suspendTextPassThru) o += t; else u->lastSuspendSegment += t; } + +} OSISRTF::OSISRTF() { @@ -251,7 +252,7 @@ bool OSISRTF::handleToken(SWBuf &buf, const char *token, BasicFilterUserData *us SWCATCH ( ... ) { } if (vkey) { char ch = ((!strcmp(type.c_str(), "crossReference")) || (!strcmp(type.c_str(), "x-cross-ref"))) ? 'x':'n'; - scratch.setFormatted("{\\super *%c%i.%s} ", ch, vkey->Verse(), footnoteNumber.c_str()); + scratch.setFormatted("{\\super *%c%i.%s} ", ch, vkey->getVerse(), footnoteNumber.c_str()); outText(scratch.c_str(), buf, u); u->inXRefNote = (ch == 'x'); } @@ -325,7 +326,7 @@ bool OSISRTF::handleToken(SWBuf &buf, const char *token, BasicFilterUserData *us } // or - else if ((!strcmp(tag.getName(), "lb")) || ((!strcmp(tag.getName(), "milestone")) && (tag.getAttribute("type")) && (!strcmp(tag.getAttribute("type"), "line")))) { + else if ((!strcmp(tag.getName(), "lb") && (!tag.getAttribute("type") || strcmp(tag.getAttribute("type"), "x-optional"))) || ((!strcmp(tag.getName(), "milestone")) && (tag.getAttribute("type")) && (!strcmp(tag.getAttribute("type"), "line")))) { outText("{\\par}", buf, u); userData->supressAdjacentWhitespace = true; } diff --git a/src/modules/filters/osisruby.cpp b/src/modules/filters/osisruby.cpp deleted file mode 100644 index c17ea43..0000000 --- a/src/modules/filters/osisruby.cpp +++ /dev/null @@ -1,93 +0,0 @@ -/****************************************************************************** - * - * osisruby - SWFilter descendant to hide or show ruby - * in a OSIS module. - * - * - * Copyright 2009 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 - -SWORD_NAMESPACE_START - -const char oName[] = "Ruby"; -const char oTip[] = "Toggles Ruby On and Off if they exist"; - -const SWBuf choices[3] = {"Off", "On", ""}; -const StringList oValues(&choices[0], &choices[2]); - -OSISRuby::OSISRuby() : SWOptionFilter(oName, oTip, &oValues) { - setOptionValue("Off"); -} - - -OSISRuby::~OSISRuby() { -} - - -char OSISRuby::processText(SWBuf &text, const SWKey *key, const SWModule *module) { - SWBuf token; - bool intoken = false; - bool lastspace = false; - - const SWBuf orig = text; - const char * from = orig.c_str(); - - if (!option) { - for (text = ""; *from; ++from) { - if (*from == '<') { - intoken = true; - token = ""; - continue; - } - if (*from == '>') { // process tokens - intoken = false; - if (token.startsWith("w ")) { // Word - XMLTag wtag(token); - const char *l = wtag.getAttribute("gloss"); - if (l) { - wtag.setAttribute("gloss", 0); - token = wtag; - token.trim(); - // drop <> - token << 1; - token--; - } - } - - // keep token in text - text.append('<'); - text.append(token); - text.append('>'); - - continue; - } - if (intoken) { - token += *from; - } - else { - text.append(*from); - lastspace = (*from == ' '); - } - } - } - return 0; -} - -SWORD_NAMESPACE_END diff --git a/src/modules/filters/osisscripref.cpp b/src/modules/filters/osisscripref.cpp index 73c7309..2bb7d15 100644 --- a/src/modules/filters/osisscripref.cpp +++ b/src/modules/filters/osisscripref.cpp @@ -1,10 +1,11 @@ /****************************************************************************** * - * OSISScripref - SWFilter descendant to hide or show scripture references - * in an OSIS module. + * osisscripref.cpp - SWFilter descendant to hide or show scripture + * references in an OSIS module * + * $Id: osisscripref.cpp 2980 2013-09-14 21:51:47Z scribe $ * - * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * Copyright 2003-2013 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society * P. O. Box 2528 * Tempe, AZ 85280-2528 @@ -25,16 +26,23 @@ #include #include + SWORD_NAMESPACE_START -const char oName[] = "Cross-references"; -const char oTip[] = "Toggles Scripture Cross-references On and Off if they exist"; +namespace { + + static const char oName[] = "Cross-references"; + static const char oTip[] = "Toggles Scripture Cross-references On and Off if they exist"; + + static const StringList *oValues() { + static const SWBuf choices[3] = {"On", "Off", ""}; + static const StringList oVals(&choices[0], &choices[2]); + return &oVals; + } +} -const SWBuf choices[3] = {"Off", "On", ""}; -const StringList oValues(&choices[0], &choices[2]); -OSISScripref::OSISScripref() : SWOptionFilter(oName, oTip, &oValues) { - setOptionValue("On"); +OSISScripref::OSISScripref() : SWOptionFilter(oName, oTip, oValues()) { } diff --git a/src/modules/filters/osisstrongs.cpp b/src/modules/filters/osisstrongs.cpp index 8c06b07..b937883 100644 --- a/src/modules/filters/osisstrongs.cpp +++ b/src/modules/filters/osisstrongs.cpp @@ -1,10 +1,11 @@ /****************************************************************************** * - * osisstrongs - SWFilter descendant to hide or show strongs number - * in a OSIS module. + * osisstrongs.cpp - SWFilter descendant to hide or show Strong's number + * in a OSIS module * + * $Id: osisstrongs.cpp 2980 2013-09-14 21:51:47Z scribe $ * - * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * Copyright 2003-2013 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society * P. O. Box 2528 * Tempe, AZ 85280-2528 @@ -28,17 +29,23 @@ #include #include + SWORD_NAMESPACE_START -const char oName[] = "Strong's Numbers"; -const char oTip[] = "Toggles Strong's Numbers On and Off if they exist"; +namespace { + + static const char oName[] = "Strong's Numbers"; + static const char oTip[] = "Toggles Strong's Numbers On and Off if they exist"; -const SWBuf choices[3] = {"Off", "On", ""}; -const StringList oValues(&choices[0], &choices[2]); + static const StringList *oValues() { + static const SWBuf choices[3] = {"Off", "On", ""}; + static const StringList oVals(&choices[0], &choices[2]); + return &oVals; + } +} -OSISStrongs::OSISStrongs() : SWOptionFilter(oName, oTip, &oValues) { - setOptionValue("Off"); +OSISStrongs::OSISStrongs() : SWOptionFilter(oName, oTip, oValues()) { } @@ -49,7 +56,6 @@ OSISStrongs::~OSISStrongs() { char OSISStrongs::processText(SWBuf &text, const SWKey *key, const SWModule *module) { SWBuf token; bool intoken = false; - bool lastspace = false; int wordNum = 1; char wordstr[5]; const char *wordStart = 0; @@ -151,7 +157,7 @@ char OSISStrongs::processText(SWBuf &text, const SWKey *key, const SWModule *mod if ((lClass == "x-Strongs") || (lClass == "strong") || (lClass == "Strong")) { if (isdigit(attrib[0])) { if (vkey) { - gh = vkey->Testament() ? 'H' : 'G'; + gh = vkey->getTestament() ? 'H' : 'G'; } } else { @@ -280,7 +286,6 @@ char OSISStrongs::processText(SWBuf &text, const SWKey *key, const SWModule *mod } else { text.append(*from); - lastspace = (*from == ' '); } } return 0; diff --git a/src/modules/filters/osisvariants.cpp b/src/modules/filters/osisvariants.cpp index 16e0cfb..6cd3eda 100644 --- a/src/modules/filters/osisvariants.cpp +++ b/src/modules/filters/osisvariants.cpp @@ -1,10 +1,11 @@ /****************************************************************************** * - * osisvariants - SWFilter descendant to hide or show textual variants - * in an OSIS module. + * osisvariants.cpp - SWFilter descendant to hide or show textual variants + * in an OSIS module * + * $Id: osisvariants.cpp 2980 2013-09-14 21:51:47Z scribe $ * - * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * Copyright 2006-2013 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society * P. O. Box 2528 * Tempe, AZ 85280-2528 @@ -23,51 +24,41 @@ #include #include #include +#include -SWORD_NAMESPACE_START -const char OSISVariants::primary[] = "Primary Reading"; -const char OSISVariants::secondary[] = "Secondary Reading"; -const char OSISVariants::all[] = "All Readings"; +SWORD_NAMESPACE_START -const char OSISVariants::optName[] = "Textual Variants"; -const char OSISVariants::optTip[] = "Switch between Textual Variants modes"; +namespace { + static const char oName[] = "Textual Variants"; + static const char oTip[] = "Switch between Textual Variants modes"; + static const char *choices[4] = { "Primary Reading", "Secondary Reading", "All Readings", "" }; -OSISVariants::OSISVariants() { - option = false; - options.push_back(primary); - options.push_back(secondary); - options.push_back(all); + static const StringList *oValues() { + static const StringList oVals(&choices[0], &choices[3]); + return &oVals; + } } -OSISVariants::~OSISVariants() { +OSISVariants::OSISVariants() : SWOptionFilter(oName, oTip, oValues()) { } -void OSISVariants::setOptionValue(const char *ival) -{ - if (!stricmp(ival, primary)) option = 0; - else if (!stricmp(ival, secondary)) option = 1; - else option = 2; -} -const char *OSISVariants::getOptionValue() -{ - if (option == 0) { - return primary; - } - else if (option == 1) { - return secondary; - } - else { - return all; - } +OSISVariants::~OSISVariants() { } + char OSISVariants::processText(SWBuf &text, const SWKey *key, const SWModule *module) { - if (option == 0 || option == 1) { //we want primary or variant only + + int option = 0; + if (optionValue == choices[0]) option = 0; + else if (optionValue == choices[1]) option = 1; + else option = 2; + + if (option == 0 || option == 1) { //we want primary or variant only bool intoken = false; bool hide = false; bool invar = false; @@ -75,9 +66,10 @@ char OSISVariants::processText(SWBuf &text, const SWKey *key, const SWModule *mo SWBuf token; SWBuf orig = text; const char *from = orig.c_str(); + XMLTag tag; //we use a fixed comparision string to make sure the loop is as fast as the original two blocks with almost the same code - //const char* variantCompareString = (option == 0) ? "div type=\"variant\" class=\"1\"" : "div type=\"variant\" class=\"2\""; + const char* variantChoice = (option == 0) ? "x-2" : "x-1"; for (text = ""; *from; from++) { if (*from == '<') { @@ -88,16 +80,16 @@ char OSISVariants::processText(SWBuf &text, const SWKey *key, const SWModule *mo else if (*from == '>') { // process tokens intoken = false; - if (!strncmp(token.c_str(), "seg ", 4)) { //only one of the variants - invar = true; - hide = true; - continue; - } - if (!strncmp(token.c_str(), "div type=\"variant\"", 18)) { - invar = true; - continue; + if (!strncmp(token.c_str(), "seg", 3)) { + tag = token; + + if (tag.getAttribute("type") && !strcmp("x-variant", tag.getAttribute("type")) && tag.getAttribute("subType") && !strcmp(variantChoice, tag.getAttribute("subType"))) { + invar = true; + hide = true; + continue; + } } - if (!strncmp(token.c_str(), "/div", 4)) { + if (!strncmp(token.c_str(), "/seg", 4)) { hide = false; if (invar) { invar = false; @@ -126,8 +118,4 @@ char OSISVariants::processText(SWBuf &text, const SWKey *key, const SWModule *mo } - - - - SWORD_NAMESPACE_END diff --git a/src/modules/filters/osiswebif.cpp b/src/modules/filters/osiswebif.cpp index e313836..2cbca0b 100644 --- a/src/modules/filters/osiswebif.cpp +++ b/src/modules/filters/osiswebif.cpp @@ -1,11 +1,11 @@ /*************************************************************************** - * OSISWEBIF.cpp - OSIS to HTML filter with hrefs - * for strongs and morph tags - * ------------------- - * begin : 2003-10-23 - * copyright : 2003 by CrossWire Bible Society * - * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * osiswebif.cpp - OSIS to HTML filter with hrefs for strongs and + * morph tags + * + * $Id: osiswebif.cpp 2833 2013-06-29 06:40:28Z chrislit $ + * + * Copyright 2003-2013 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society * P. O. Box 2528 * Tempe, AZ 85280-2528 @@ -37,20 +37,13 @@ OSISWEBIF::OSISWEBIF() : baseURL(""), passageStudyURL(baseURL + "passagestudy.js } -BasicFilterUserData *OSISWEBIF::createUserData(const SWModule *module, const SWKey *key) { - MyUserData *u = new MyUserData(module, key); - u->wordsOfChristStart = " "; - u->wordsOfChristEnd = " "; - return u; -} - - bool OSISWEBIF::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 + + // manually process if it wasn't a simple substitution XMLTag tag(token); // tag @@ -143,7 +136,7 @@ bool OSISWEBIF::handleToken(SWBuf &buf, const char *token, BasicFilterUserData * 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 modName = (u->module) ? u->module->Name() : ""; + SWBuf modName = (u->module) ? u->module->getName() : ""; VerseKey *vkey = NULL; // see if we have a VerseKey * or descendant SWTRY { @@ -165,43 +158,10 @@ bool OSISWEBIF::handleToken(SWBuf &buf, const char *token, BasicFilterUserData * } } - // - else if (!strcmp(tag.getName(), "title")) { - if ((!tag.isEndTag()) && (!tag.isEmpty())) { - buf += "<h3>"; - } - else if (tag.isEndTag()) { - buf += "</h3>"; - } - } - - // Milestoned paragraphs, created by osis2mod - // <div type="paragraph" sID.../> - // <div type="paragraph" eID.../> - else if (tag.isEmpty() && !strcmp(tag.getName(), "div") && tag.getAttribute("type") && !strcmp(tag.getAttribute("type"), "paragraph")) { - // This is properly handled by base class. - return OSISHTMLHREF::handleToken(buf, token, userData); - } - - // ok to leave these in - else if (!strcmp(tag.getName(), "div")) { - buf += tag; - } - else if (!strcmp(tag.getName(), "span")) { - buf += tag; - } - else if (!strcmp(tag.getName(), "br")) { - buf += tag; - } // handled appropriately in base class - // <catchWord> & <rdg> tags (italicize) - // <hi> text highlighting - // <q> quote - // <milestone type="cQuote" marker="x"/> - // <transChange> else { - return OSISHTMLHREF::handleToken(buf, token, userData); + return OSISXHTML::handleToken(buf, token, userData); } } return true; diff --git a/src/modules/filters/osiswordjs.cpp b/src/modules/filters/osiswordjs.cpp index da573d3..75946a8 100644 --- a/src/modules/filters/osiswordjs.cpp +++ b/src/modules/filters/osiswordjs.cpp @@ -1,10 +1,10 @@ /****************************************************************************** * - * osisstrongs - SWFilter descendant to hide or show strongs number - * in a OSIS module. + * osiswordjs.cpp - SWFilter descendant for ??? * + * $Id: osiswordjs.cpp 2980 2013-09-14 21:51:47Z scribe $ * - * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * Copyright 2005-2013 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society * P. O. Box 2528 * Tempe, AZ 85280-2528 @@ -30,17 +30,23 @@ #include <versekey.h> #include <stdio.h> + SWORD_NAMESPACE_START -const char oName[] = "Word Javascript"; -const char oTip[] = "Toggles Word Javascript data"; +namespace { + + static const char oName[] = "Word Javascript"; + static const char oTip[] = "Toggles Word Javascript data"; -const SWBuf choices[3] = {"Off", "On", ""}; -const StringList oValues(&choices[0], &choices[2]); + static const StringList *oValues() { + static const SWBuf choices[3] = {"Off", "On", ""}; + static const StringList oVals(&choices[0], &choices[2]); + return &oVals; + } +} -OSISWordJS::OSISWordJS() : SWOptionFilter(oName, oTip, &oValues) { - setOptionValue("Off"); +OSISWordJS::OSISWordJS() : SWOptionFilter(oName, oTip, oValues()) { defaultGreekLex = 0; defaultHebLex = 0; @@ -59,10 +65,9 @@ char OSISWordJS::processText(SWBuf &text, const SWKey *key, const SWModule *modu char token[2112]; // cheese. Fix. int tokpos = 0; bool intoken = false; - bool lastspace = false; int wordNum = 1; char wordstr[5]; - SWBuf modName = (module)?module->Name():""; + SWBuf modName = (module)?module->getName():""; // add TR to w src in KJV then remove this next line SWBuf wordSrcPrefix = (modName == "KJV")?SWBuf("TR"):modName; @@ -135,10 +140,10 @@ char OSISWordJS::processText(SWBuf &text, const SWKey *key, const SWModule *modu // we can pass the real lex name in, but we have some // aliases in the javascript to optimize bandwidth if ((gh == 'G') && (defaultGreekLex)) { - lexName = (!strcmp(defaultGreekLex->Name(), "StrongsGreek"))?"G":defaultGreekLex->Name(); + lexName = (!strcmp(defaultGreekLex->getName(), "StrongsGreek"))?"G":defaultGreekLex->getName(); } else if ((gh == 'H') && (defaultHebLex)) { - lexName = (!strcmp(defaultHebLex->Name(), "StrongsHebrew"))?"H":defaultHebLex->Name(); + lexName = (!strcmp(defaultHebLex->getName(), "StrongsHebrew"))?"H":defaultHebLex->getName(); } SWBuf xlit = wtag.getAttribute("xlit"); @@ -151,7 +156,7 @@ char OSISWordJS::processText(SWBuf &text, const SWKey *key, const SWModule *modu SWBuf wordID; if (vkey) { // optimize for bandwidth and use only the verse as the unique entry id - wordID.appendFormatted("%d", vkey->Verse()); + wordID.appendFormatted("%d", vkey->getVerse()); } else { wordID = key->getText(); @@ -186,7 +191,6 @@ char OSISWordJS::processText(SWBuf &text, const SWKey *key, const SWModule *modu } else { text.append(*from); - lastspace = (*from == ' '); } } } diff --git a/src/modules/filters/osisxhtml.cpp b/src/modules/filters/osisxhtml.cpp new file mode 100644 index 0000000..b1040a9 --- /dev/null +++ b/src/modules/filters/osisxhtml.cpp @@ -0,0 +1,772 @@ +/****************************************************************************** + * + * osisxhtml.cpp - Render filter for classed XHTML of an OSIS module + * + * $Id: osisxhtml.cpp 3005 2014-01-09 04:06:11Z greg.hellings $ + * + * Copyright 2011-2013 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 <stdlib.h> +#include <ctype.h> +#include <osisxhtml.h> +#include <utilxml.h> +#include <utilstr.h> +#include <versekey.h> +#include <swmodule.h> +#include <url.h> +#include <stringmgr.h> +#include <stack> + +SWORD_NAMESPACE_START + +const char *OSISXHTML::getHeader() const { + const static char *header = "\ + .divineName { font-variant: small-caps; }\n\ + .wordsOfJesus { color: red; }\n\ + .transChangeSupplied { font-style: italic; }\n\ + .small, .sub, .sup { font-size: .83em }\n\ + .sub { vertical-align: sub }\n\ + .sup { vertical-align: super }\n\ + .indent1 { margin-left: 10px }\n\ + .indent2 { margin-left: 20px }\n\ + .indent3 { margin-left: 30px }\n\ + .indent4 { margin-left: 40px }\n\ + "; + return header; +} + + +namespace { + +// though this might be slightly slower, possibly causing an extra bool check, this is a renderFilter +// so speed isn't the absolute highest priority, and this is a very minor possible hit +static inline void outText(const char *t, SWBuf &o, BasicFilterUserData *u) { if (!u->suspendTextPassThru) o += t; else u->lastSuspendSegment += t; } +static inline void outText(char t, SWBuf &o, BasicFilterUserData *u) { if (!u->suspendTextPassThru) o += t; else u->lastSuspendSegment += t; } + +void processLemma(bool suspendTextPassThru, XMLTag &tag, SWBuf &buf) { + const char *attrib; + const char *val; + if ((attrib = tag.getAttribute("lemma"))) { + int count = tag.getAttributePartCount("lemma", ' '); + int i = (count > 1) ? 0 : -1; // -1 for whole value cuz it's faster, but does the same thing as 0 + do { + attrib = tag.getAttribute("lemma", i, ' '); + if (i < 0) i = 0; // to handle our -1 condition + val = strchr(attrib, ':'); + val = (val) ? (val + 1) : attrib; + SWBuf gh; + if(*val == 'G') + gh = "Greek"; + if(*val == 'H') + gh = "Hebrew"; + const char *val2 = val; + if ((strchr("GH", *val)) && (isdigit(val[1]))) + val2++; + //if ((!strcmp(val2, "3588")) && (lastText.length() < 1)) + // show = false; + //else { + if (!suspendTextPassThru) { + buf.appendFormatted("<small><em class=\"strongs\"><<a href=\"passagestudy.jsp?action=showStrongs&type=%s&value=%s\" class=\"strongs\">%s</a>></em></small>", + (gh.length()) ? gh.c_str() : "", + URL::encode(val2).c_str(), + val2); + } + //} + + } while (++i < count); + } +} + + + +void processMorph(bool suspendTextPassThru, XMLTag &tag, SWBuf &buf) { + const char * attrib; + const char *val; + if ((attrib = tag.getAttribute("morph"))) { // && (show)) { + SWBuf savelemma = tag.getAttribute("savlm"); + //if ((strstr(savelemma.c_str(), "3588")) && (lastText.length() < 1)) + // show = false; + //if (show) { + int count = tag.getAttributePartCount("morph", ' '); + int i = (count > 1) ? 0 : -1; // -1 for whole value cuz it's faster, but does the same thing as 0 + do { + attrib = tag.getAttribute("morph", i, ' '); + if (i < 0) i = 0; // to handle our -1 condition + val = strchr(attrib, ':'); + val = (val) ? (val + 1) : attrib; + const char *val2 = val; + if ((*val == 'T') && (strchr("GH", val[1])) && (isdigit(val[2]))) + val2+=2; + if (!suspendTextPassThru) { + buf.appendFormatted("<small><em class=\"morph\">(<a href=\"passagestudy.jsp?action=showMorph&type=%s&value=%s\" class=\"morph\">%s</a>)</em></small>", + URL::encode(tag.getAttribute("morph")).c_str(), + URL::encode(val).c_str(), + val2); + } + } while (++i < count); + //} + } +} + + +} // end anonymous namespace + +BasicFilterUserData *OSISXHTML::createUserData(const SWModule *module, const SWKey *key) { + return new MyUserData(module, key); +} + + +OSISXHTML::OSISXHTML() { + setTokenStart("<"); + setTokenEnd(">"); + + setEscapeStart("&"); + setEscapeEnd(";"); + + setEscapeStringCaseSensitive(true); + setPassThruNumericEscapeString(true); + + addAllowedEscapeString("quot"); + addAllowedEscapeString("apos"); + addAllowedEscapeString("amp"); + addAllowedEscapeString("lt"); + addAllowedEscapeString("gt"); + + setTokenCaseSensitive(true); + + // addTokenSubstitute("lg", "<br />"); + // addTokenSubstitute("/lg", "<br />"); + + morphFirst = false; + renderNoteNumbers = false; +} + +class OSISXHTML::TagStack : public std::stack<SWBuf> { +}; + +OSISXHTML::MyUserData::MyUserData(const SWModule *module, const SWKey *key) : BasicFilterUserData(module, key), quoteStack(new TagStack()), hiStack(new TagStack()), titleStack(new TagStack()), lineStack(new TagStack()) { + inXRefNote = false; + suspendLevel = 0; + wordsOfChristStart = "<span class=\"wordsOfJesus\"> "; + wordsOfChristEnd = "</span> "; + if (module) { + osisQToTick = ((!module->getConfigEntry("OSISqToTick")) || (strcmp(module->getConfigEntry("OSISqToTick"), "false"))); + version = module->getName(); + BiblicalText = (!strcmp(module->getType(), "Biblical Texts")); + } + else { + osisQToTick = true; // default + version = ""; + } + consecutiveNewlines = 0; +} + +OSISXHTML::MyUserData::~MyUserData() { + delete quoteStack; + delete hiStack; + delete titleStack; + delete lineStack; +} + +void OSISXHTML::MyUserData::outputNewline(SWBuf &buf) { + if (++consecutiveNewlines <= 2) { + outText("<br />\n", buf, this); + supressAdjacentWhitespace = true; + } +} +bool OSISXHTML::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 ( ... ) { } + if (vkey) { + //printf("URL = %s\n",URL::encode(vkey->getText()).c_str()); + 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 ? URL::encode(noteName.c_str()).c_str() : "")); + } + else { + 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 ? URL::encode(noteName.c_str()).c_str() : "")); + } + } + } + u->suspendTextPassThru = (++u->suspendLevel); + } + if (tag.isEndTag()) { + u->suspendTextPassThru = (--u->suspendLevel); + u->inXRefNote = false; + u->lastSuspendSegment = ""; // fix/work-around for nasb devineName in note bug + } + } + + // <p> paragraph and <lg> linegroup tags + else if (!strcmp(tag.getName(), "p") || !strcmp(tag.getName(), "lg")) { + if ((!tag.isEndTag()) && (!tag.isEmpty())) { // non-empty start tag + u->outputNewline(buf); + } + else if (tag.isEndTag()) { // end tag + u->outputNewline(buf); + } + else { // empty paragraph break marker + u->outputNewline(buf); + } + } + + // Milestoned paragraphs, created by osis2mod + // <div type="paragraph" sID.../> + // <div type="paragraph" eID.../> + else if (tag.isEmpty() && !strcmp(tag.getName(), "div") && tag.getAttribute("type") && !strcmp(tag.getAttribute("type"), "paragraph")) { + // <div type="paragraph" sID... /> + if (tag.getAttribute("sID")) { // non-empty start tag + u->outputNewline(buf); + } + // <div type="paragraph" eID... /> + else if (tag.getAttribute("eID")) { + u->outputNewline(buf); + } + } + + // <reference> tag + else if (!strcmp(tag.getName(), "reference")) { + if (!u->inXRefNote) { // only show these if we're not in an xref note + if (!tag.isEndTag()) { + SWBuf target; + SWBuf work; + SWBuf ref; + bool is_scripRef = false; + + target = tag.getAttribute("osisRef"); + const char* the_ref = strchr(target, ':'); + + if(!the_ref) { + // No work + ref = target; + is_scripRef = true; + } + else { + // Compensate for starting : + ref = the_ref + 1; + + int size = target.size() - ref.size() - 1; + work.setSize(size); + strncpy(work.getRawData(), target, size); + + // For Bible:Gen.3.15 or Bible.vulgate:Gen.3.15 + if(!strncmp(work, "Bible", 5)) + is_scripRef = true; + } + + if(is_scripRef) + { + buf.appendFormatted("<a href=\"passagestudy.jsp?action=showRef&type=scripRef&value=%s&module=\">", + URL::encode(ref.c_str()).c_str() +// (work.size()) ? URL::encode(work.c_str()).c_str() : "") + ); + } + else + { + // Dictionary link, or something + buf.appendFormatted("<a href=\"sword://%s/%s\">", + URL::encode(work.c_str()).c_str(), + URL::encode(ref.c_str()).c_str() + ); + } + } + else { + outText("</a>", buf, u); + } + } + } + + // <l> poetry, etc + else if (!strcmp(tag.getName(), "l")) { + // start line marker + if (tag.getAttribute("sID") || (!tag.isEndTag() && !tag.isEmpty())) { + // nested lines plus if the line itself has an x-indent type attribute value + outText(SWBuf("<span class=\"line indent").appendFormatted("%d\">", u->lineStack->size() + (SWBuf("x-indent") == tag.getAttribute("type")?1:0)).c_str(), buf, u); + u->lineStack->push(tag.toString()); + } + // end line marker + else if (tag.getAttribute("eID") || tag.isEndTag()) { + outText("</span>", buf, u); + u->outputNewline(buf); + if (u->lineStack->size()) u->lineStack->pop(); + } + // <l/> without eID or sID + // Note: this is improper osis. This should be <lb/> + else if (tag.isEmpty() && !tag.getAttribute("sID")) { + u->outputNewline(buf); + } + } + + // <lb.../> + else if (!strcmp(tag.getName(), "lb") && (!tag.getAttribute("type") || strcmp(tag.getAttribute("type"), "x-optional"))) { + u->outputNewline(buf); + } + // <milestone type="line"/> + // <milestone type="x-p"/> + // <milestone type="cQuote" marker="x"/> + else if ((!strcmp(tag.getName(), "milestone")) && (tag.getAttribute("type"))) { + if (!strcmp(tag.getAttribute("type"), "line")) { + u->outputNewline(buf); + if (tag.getAttribute("subType") && !strcmp(tag.getAttribute("subType"), "x-PM")) { + u->outputNewline(buf); + } + } + else if (!strcmp(tag.getAttribute("type"),"x-p")) { + if (tag.getAttribute("marker")) + outText(tag.getAttribute("marker"), buf, u); + else outText("<!p>", buf, u); + } + else if (!strcmp(tag.getAttribute("type"), "cQuote")) { + const char *tmp = tag.getAttribute("marker"); + bool hasMark = tmp; + SWBuf mark = tmp; + tmp = tag.getAttribute("level"); + int level = (tmp) ? atoi(tmp) : 1; + + // first check to see if we've been given an explicit mark + if (hasMark) + outText(mark, buf, u); + // finally, alternate " and ', if config says we should supply a mark + else if (u->osisQToTick) + outText((level % 2) ? '\"' : '\'', buf, u); + } + } + + // <title> + else if (!strcmp(tag.getName(), "title")) { + if ((!tag.isEndTag()) && (!tag.isEmpty())) { + VerseKey *vkey = SWDYNAMIC_CAST(VerseKey, u->key); + if (vkey && !vkey->getVerse()) { + if (!vkey->getChapter()) { + if (!vkey->getBook()) { + if (!vkey->getTestament()) { + buf += "<h1 class=\"moduleHeader\">"; + tag.setAttribute("pushed", "h1"); + } + else { + buf += "<h1 class=\"testamentHeader\">"; + tag.setAttribute("pushed", "h1"); + } + } + else { + buf += "<h1 class=\"bookHeader\">"; + tag.setAttribute("pushed", "h1"); + } + } + else { + buf += "<h2 class=\"chapterHeader\">"; + tag.setAttribute("pushed", "h2"); + } + } + else { + buf += "<h3>"; + tag.setAttribute("pushed", "h3"); + } + u->titleStack->push(tag.toString()); + } + else if (tag.isEndTag()) { + if (!u->titleStack->empty()) { + XMLTag tag(u->titleStack->top()); + if (u->titleStack->size()) u->titleStack->pop(); + SWBuf pushed = tag.getAttribute("pushed"); + if (pushed.size()) { + buf += (SWBuf)"</" + pushed + ">\n\n"; + } + else { + buf += "</h3>\n\n"; + } + ++u->consecutiveNewlines; + u->supressAdjacentWhitespace = true; + } + } + } + + // <list> + else if (!strcmp(tag.getName(), "list")) { + if((!tag.isEndTag()) && (!tag.isEmpty())) { + outText("<ul>\n", buf, u); + } + else if (tag.isEndTag()) { + outText("</ul>\n", buf, u); + ++u->consecutiveNewlines; + u->supressAdjacentWhitespace = true; + } + } + + // <item> + else if (!strcmp(tag.getName(), "item")) { + if((!tag.isEndTag()) && (!tag.isEmpty())) { + outText("\t<li>", buf, u); + } + else if (tag.isEndTag()) { + outText("</li>\n", buf, u); + ++u->consecutiveNewlines; + u->supressAdjacentWhitespace = true; + } + } + // <catchWord> & <rdg> tags (italicize) + else if (!strcmp(tag.getName(), "rdg") || !strcmp(tag.getName(), "catchWord")) { + if ((!tag.isEndTag()) && (!tag.isEmpty())) { + outText("<i>", buf, u); + } + else if (tag.isEndTag()) { + outText("</i>", buf, u); + } + } + + // divineName + else if (!strcmp(tag.getName(), "divineName")) { + if ((!tag.isEndTag()) && (!tag.isEmpty())) { + u->suspendTextPassThru = (++u->suspendLevel); + } + else if (tag.isEndTag()) { + SWBuf lastText = u->lastSuspendSegment.c_str(); + u->suspendTextPassThru = (--u->suspendLevel); + if (lastText.size()) { + scratch.setFormatted("<span class=\"divineName\">%s</span>", lastText.c_str()); + outText(scratch.c_str(), buf, u); + } + } + } + + // <hi> text highlighting + else if (!strcmp(tag.getName(), "hi")) { + SWBuf type = tag.getAttribute("type"); + + // handle tei rend attribute if type doesn't exist + if (!type.length()) type = tag.getAttribute("rend"); + + if ((!tag.isEndTag()) && (!tag.isEmpty())) { + if (type == "bold" || type == "b" || type == "x-b") { + outText("<b>", buf, u); + } + + // there is no officially supported OSIS overline attribute, + // thus either TEI overline or OSIS x-overline would be best, + // but we have used "ol" in the past, as well. Once a valid + // OSIS overline attribute is made available, these should all + // eventually be deprecated and never documented that they are supported. + else if (type == "ol" || type == "overline" || type == "x-overline") { + outText("<span style=\"text-decoration:overline\">", buf, u); + } + + else if (type == "super") { + outText("<span class=\"sup\">", buf, u); + } + else if (type == "sub") { + outText("<span class=\"sub\">", buf, u); + } + else { // all other types + outText("<i>", buf, u); + } + u->hiStack->push(tag.toString()); + } + else if (tag.isEndTag()) { + SWBuf type = ""; + if (!u->hiStack->empty()) { + XMLTag tag(u->hiStack->top()); + if (u->hiStack->size()) u->hiStack->pop(); + type = tag.getAttribute("type"); + if (!type.length()) type = tag.getAttribute("rend"); + } + if (type == "bold" || type == "b" || type == "x-b") { + outText("</b>", buf, u); + } + else if ( type == "ol" + || type == "super" + || type == "sub") { + outText("</span>", buf, u); + } + else outText("</i>", buf, u); + } + } + + // <q> quote + // Rules for a quote element: + // If the tag is empty with an sID or an eID then use whatever it specifies for quoting. + // Note: empty elements without sID or eID are ignored. + // If the tag is <q> then use it's specifications and push it onto a stack for </q> + // If the tag is </q> then use the pushed <q> for specification + // If there is a marker attribute, possibly empty, this overrides osisQToTick. + // If osisQToTick, then output the marker, using level to determine the type of mark. + else if (!strcmp(tag.getName(), "q")) { + SWBuf type = tag.getAttribute("type"); + SWBuf who = tag.getAttribute("who"); + const char *tmp = tag.getAttribute("level"); + int level = (tmp) ? atoi(tmp) : 1; + tmp = tag.getAttribute("marker"); + bool hasMark = tmp; + SWBuf mark = tmp; + + // open <q> or <q sID... /> + if ((!tag.isEmpty() && !tag.isEndTag()) || (tag.isEmpty() && tag.getAttribute("sID"))) { + // if <q> then remember it for the </q> + if (!tag.isEmpty()) { + u->quoteStack->push(tag.toString()); + } + + // Do this first so quote marks are included as WoC + if (who == "Jesus") + outText(u->wordsOfChristStart, buf, u); + + // first check to see if we've been given an explicit mark + if (hasMark) + outText(mark, buf, u); + //alternate " and ' + else if (u->osisQToTick) + outText((level % 2) ? '\"' : '\'', buf, u); + } + // close </q> or <q eID... /> + else if ((tag.isEndTag()) || (tag.isEmpty() && tag.getAttribute("eID"))) { + // if it is </q> then pop the stack for the attributes + if (tag.isEndTag() && !u->quoteStack->empty()) { + XMLTag qTag(u->quoteStack->top()); + if (u->quoteStack->size()) u->quoteStack->pop(); + + type = qTag.getAttribute("type"); + who = qTag.getAttribute("who"); + tmp = qTag.getAttribute("level"); + level = (tmp) ? atoi(tmp) : 1; + tmp = qTag.getAttribute("marker"); + hasMark = tmp; + mark = tmp; + } + + // first check to see if we've been given an explicit mark + if (hasMark) + outText(mark, buf, u); + // finally, alternate " and ', if config says we should supply a mark + else if (u->osisQToTick) + outText((level % 2) ? '\"' : '\'', buf, u); + + // Do this last so quote marks are included as WoC + if (who == "Jesus") + outText(u->wordsOfChristEnd, buf, u); + } + } + + // <transChange> + else if (!strcmp(tag.getName(), "transChange")) { + if ((!tag.isEndTag()) && (!tag.isEmpty())) { + SWBuf type = tag.getAttribute("type"); + u->lastTransChange = type; + + // just do all transChange tags this way for now + if ((type == "added") || (type == "supplied")) + outText("<span class=\"transChangeSupplied\">", buf, u); + else if (type == "tenseChange") + buf += "*"; + } + else if (tag.isEndTag()) { + SWBuf type = u->lastTransChange; + if ((type == "added") || (type == "supplied")) + outText("</span>", buf, u); + } + else { // empty transChange marker? + } + } + + // image + else if (!strcmp(tag.getName(), "figure")) { + const char *src = tag.getAttribute("src"); + if (src) { // assert we have a src attribute + SWBuf filepath; + if (userData->module) { + filepath = userData->module->getConfigEntry("AbsoluteDataPath"); + if ((filepath.size()) && (filepath[filepath.size()-1] != '/') && (src[0] != '/')) + filepath += '/'; + } + filepath += src; + + // images become clickable, if the UI supports showImage. + outText("<a href=\"passagestudy.jsp?action=showImage&value=", buf, u); + outText(URL::encode(filepath.c_str()).c_str(), buf, u); + outText("&module=", buf, u); + outText(URL::encode(u->version.c_str()).c_str(), buf, u); + outText("\">", buf, u); + + outText("<img src=\"file:", buf, u); + outText(filepath, buf, u); + outText("\" border=\"0\" />", buf, u); + + outText("</a>", buf, u); + } + } + + // ok to leave these in + else if (!strcmp(tag.getName(), "div")) { + SWBuf type = tag.getAttribute("type"); + if (type == "bookGroup") { + } + else if (type == "book") { + } + else if (type == "section") { + } + else if (type == "majorSection") { + } + else { + buf += tag; + } + } + else if (!strcmp(tag.getName(), "span")) { + buf += tag; + } + else if (!strcmp(tag.getName(), "br")) { + buf += tag; + } + else if (!strcmp(tag.getName(), "table")) { + if ((!tag.isEndTag()) && (!tag.isEmpty())) { + buf += "<table><tbody>\n"; + } + else if (tag.isEndTag()) { + buf += "</tbody></table>\n"; + ++u->consecutiveNewlines; + u->supressAdjacentWhitespace = true; + } + + } + else if (!strcmp(tag.getName(), "row")) { + if ((!tag.isEndTag()) && (!tag.isEmpty())) { + buf += "\t<tr>"; + } + else if (tag.isEndTag()) { + buf += "</tr>\n"; + } + + } + else if (!strcmp(tag.getName(), "cell")) { + if ((!tag.isEndTag()) && (!tag.isEmpty())) { + buf += "<td>"; + } + else if (tag.isEndTag()) { + buf += "</td>"; + } + } + else { + if (!u->supressAdjacentWhitespace) u->consecutiveNewlines = 0; + return false; // we still didn't handle token + } + } + if (!u->supressAdjacentWhitespace) u->consecutiveNewlines = 0; + return true; +} + + +SWORD_NAMESPACE_END diff --git a/src/modules/filters/osisxlit.cpp b/src/modules/filters/osisxlit.cpp new file mode 100644 index 0000000..d5ccbe4 --- /dev/null +++ b/src/modules/filters/osisxlit.cpp @@ -0,0 +1,99 @@ +/****************************************************************************** + * + * osisxlit.cpp - SWFilter descendant to hide or show xlit values + * (encoded transliterations) in an OSIS module + * + * $Id: osisxlit.cpp 2980 2013-09-14 21:51:47Z scribe $ + * + * Copyright 2013 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 <stdlib.h> +#include <osisxlit.h> +#include <utilxml.h> + + +SWORD_NAMESPACE_START + +namespace { + + static const char oName[] = "Transliterated Forms"; + static const char oTip[] = "Toggles transliterated forms On and Off if they exist"; + + static const StringList *oValues() { + static const SWBuf choices[3] = {"Off", "On", ""}; + static const StringList oVals(&choices[0], &choices[2]); + return &oVals; + } +} + + +OSISXlit::OSISXlit() : SWOptionFilter(oName, oTip, oValues()) { +} + + +OSISXlit::~OSISXlit() { +} + + +char OSISXlit::processText(SWBuf &text, const SWKey *key, const SWModule *module) { + SWBuf token; + bool intoken = false; + + const SWBuf orig = text; + const char * from = orig.c_str(); + + if (!option) { + for (text = ""; *from; ++from) { + if (*from == '<') { + intoken = true; + token = ""; + continue; + } + if (*from == '>') { // process tokens + intoken = false; + if (token.startsWith("w ")) { // Word + XMLTag wtag(token); + const char *l = wtag.getAttribute("xlit"); + if (l) { + wtag.setAttribute("xlit", 0); + token = wtag; + token.trim(); + // drop <> + token << 1; + token--; + } + } + + // keep token in text + text.append('<'); + text.append(token); + text.append('>'); + + continue; + } + if (intoken) { + token += *from; + } + else { + text.append(*from); + } + } + } + return 0; +} + +SWORD_NAMESPACE_END diff --git a/src/modules/filters/papyriplain.cpp b/src/modules/filters/papyriplain.cpp index 782b52a..bf6c9dd 100644 --- a/src/modules/filters/papyriplain.cpp +++ b/src/modules/filters/papyriplain.cpp @@ -1,9 +1,10 @@ /****************************************************************************** * - * papyriplain - SWFilter descendant to strip out all Papyri tags + * papyriplain.cpp - SWFilter descendant to strip out all Papyri tags * + * $Id: papyriplain.cpp 2980 2013-09-14 21:51:47Z scribe $ * - * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * Copyright 2005-2013 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society * P. O. Box 2528 * Tempe, AZ 85280-2528 @@ -24,6 +25,7 @@ SWORD_NAMESPACE_START + PapyriPlain::PapyriPlain() { } diff --git a/src/modules/filters/plainfootnotes.cpp b/src/modules/filters/plainfootnotes.cpp deleted file mode 100644 index 449f7da..0000000 --- a/src/modules/filters/plainfootnotes.cpp +++ /dev/null @@ -1,85 +0,0 @@ -/*************************************************************************** - * plainfootnotes.cpp - description - * ------------------- - * begin : Wed Oct 13 1999 - * copyright : (C) 1999 by The team of BibleTime - * email : info@bibletime.de - * - * Copyright 2009 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 <plainfootnotes.h> -#include <swkey.h> - -#include <stdlib.h> - -SWORD_NAMESPACE_START - -const char oName[] = "Footnotes"; -const char oTip[] = "Toggles Footnotes On and Off In Bible Texts If They Exist"; - -const SWBuf choices[3] = {"Off", "On", ""}; -const StringList oValues(&choices[0], &choices[2]); - -PLAINFootnotes::PLAINFootnotes() : SWOptionFilter(oName, oTip, &oValues) { - setOptionValue("Off"); -} - -PLAINFootnotes::~PLAINFootnotes(){ -} - - -char PLAINFootnotes::processText(SWBuf &text, const SWKey *key, const SWModule *module) { - if (!option) { // if we don't want footnotes - //char token[2048]; - //SWBuf token; - //int tokpos = 0; - //bool intoken = false; - //bool lastspace = false; - - bool hide = false; - - SWBuf orig = text; - const char *from = orig.c_str(); - for (text = ""; *from; from++) { - if (*from == '{') // Footnote start - { - hide = true; - continue; - } - else if (*from == '}') // Footnote end - { - hide = false; - continue; - } - - //if (intoken) { - //if (tokpos < 2045) - // token += *from; - // token[tokpos+2] = 0; - //} - //else { - if (!hide) { - text = *from; - //lastspace = (*from == ' '); - } - //} - } - } - return 0; -} - -SWORD_NAMESPACE_END diff --git a/src/modules/filters/plainhtml.cpp b/src/modules/filters/plainhtml.cpp deleted file mode 100644 index 3f989fa..0000000 --- a/src/modules/filters/plainhtml.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/*************************************************************************** - * plainhtml.cpp - description - * ------------------- - * begin : Thu Jun 24 1999 - * copyright : (C) 1999 by Torsten Uhlmann - * email : TUhlmann@gmx.de - * - * Copyright 2009 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 <plainhtml.h> -#include <swbuf.h> - -SWORD_NAMESPACE_START - -PLAINHTML::PLAINHTML() -{ -} - - -char PLAINHTML::processText(SWBuf &text, const SWKey *key, const SWModule *module) -{ - int count = 0; - - SWBuf orig = text; - const char *from = orig.c_str(); - for (text = ""; *from; from++) - { - if ((*from == '\n') && (from[1] == '\n')) // two newlinea are a paragraph - { - text += "<P>"; - from++; - continue; - } else { - if ((*from == '\n')) // && (from[1] != '\n')) // only one new line - { - text += "<BR>"; - continue; - } - } - - if (*from == '{') { //footnote start - text += "<FONT COLOR=\"#80000\"><SMALL> ("; - continue; - } - else if (*from == '}') //footnote end - { - text += ") </SMALL></FONT>"; - continue; - } - else if (*from == '<') { - text += "<"; - continue; - } - else if (*from == '>') { - text += ">"; - continue; - } - else if (*from == '&') { - text += "&"; - continue; - } - else if ((*from == ' ') && (count > 5000)) - { - text += "<WBR>"; - count = 0; - continue; - } - - text += *from; - count++; - } - return 0; -} - -SWORD_NAMESPACE_END diff --git a/src/modules/filters/rtfhtml.cpp b/src/modules/filters/rtfhtml.cpp index 7b55721..df02f38 100644 --- a/src/modules/filters/rtfhtml.cpp +++ b/src/modules/filters/rtfhtml.cpp @@ -1,11 +1,11 @@ /*************************************************************************** - * rtfhtml.cpp - description - * ------------------- - * begin : Wed Oct 13 1999 - * copyright : (C) 1999 by The team of BibleTime - * email : info@bibletime.de * - * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * rtfhtml.cpp - filter to convert RTF to HTML + * + * $Id: rtfhtml.cpp 2981 2013-09-15 00:05:26Z scribe $ + * + * Copyright 1999 The team of Bibletime (info@bibletime.de) + * Copyright 2000-2013 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society * P. O. Box 2528 * Tempe, AZ 85280-2528 @@ -24,11 +24,14 @@ #include <stdlib.h> #include <rtfhtml.h> #include <swbuf.h> +#include <utilstr.h> +#include <ctype.h> +#include <sysdata.h> SWORD_NAMESPACE_START -RTFHTML::RTFHTML() { - +RTFHTML::RTFHTML() +{ } @@ -43,12 +46,25 @@ char RTFHTML::processText(SWBuf &text, const SWKey *key, const SWModule *module) { if (*from == '\\') // a RTF command { + // \u12345? + if ( *(from+1) == 'u' && (*(from+2) == '-' || isdigit(*(from+2)))) { + from += 2; + const char *end = from; + while (isdigit(*++end)); + SWBuf num; + num.append(from, end-from); + __s16 n = atoi(num.c_str()); + __u32 u = (__u16)n; + text.append(getUTF8FromUniChar(u)); + from += (end-from); + continue; + } if ( !strncmp(from+1, "pard", 4) ) //(from[1] == 'p') && (from[2] == 'a') && (from[3] == 'r') && (from[4] == 'd')) { // switch all modifiers off if (center) { - text += "</CENTER>"; + text += "</center>"; center = false; } from += 4; @@ -57,7 +73,7 @@ char RTFHTML::processText(SWBuf &text, const SWKey *key, const SWModule *module) if ( !strncmp(from+1, "par", 3) ) //(from[1] == 'p') && (from[2] == 'a') && (from[3] == 'r')) { - text += "<P>\n"; + text += "<p/>\n"; from += 3; continue; } @@ -71,7 +87,7 @@ char RTFHTML::processText(SWBuf &text, const SWKey *key, const SWModule *module) { if (!center) { - text += "<CENTER>"; + text += "<center>"; center = true; } from += 2; diff --git a/src/modules/filters/scsuutf8.cpp b/src/modules/filters/scsuutf8.cpp new file mode 100644 index 0000000..c68ea1f --- /dev/null +++ b/src/modules/filters/scsuutf8.cpp @@ -0,0 +1,246 @@ +/****************************************************************************** + * + * scsuutf8.cpp - SWFilter descendant to convert a SCSU character to + * UTF-8 + * + * $Id: scsuutf8.cpp 2980 2013-09-14 21:51:47Z scribe $ + * + * Copyright 2001-2013 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. + * + */ + +/* This class is based on: + * http://czyborra.com/scsu/scsu.c written by Roman Czyborra@dds.nl + * on Andrea's balcony in North Amsterdam on 1998-08-04 + * Thanks to Richard Verhoeven <rcb5@win.tue.nl> for his suggestion + * to correct the haphazard "if" after UQU to "else if" on 1998-10-01 + * + * This is a deflator to UTF-8 output for input compressed in SCSU, + * the (Reuters) Standard Compression Scheme for Unicode as described + * in http://www.unicode.org/unicode/reports/tr6.html + */ + +#include <stdlib.h> +#include <stdio.h> +#include <swmodule.h> + +#include <scsuutf8.h> + + +SWORD_NAMESPACE_START + + +SCSUUTF8::SCSUUTF8() { +} + + +unsigned char* SCSUUTF8::UTF8Output(unsigned long uchar, unsigned char* text) +{ + /* join UTF-16 surrogates without any pairing sanity checks */ + + static int d; + + if (uchar >= 0xd800 && uchar <= 0xdbff) { d = uchar & 0x3f; return text; } + if (uchar >= 0xdc00 && uchar <= 0xdfff) { uchar = uchar + 0x2400 + d * 0x400; } + + /* output one character as UTF-8 multibyte sequence */ + + if (uchar < 0x80) { + *text++ = c; + } + else if (uchar < 0x800) { + *text++ = 0xc0 | uchar >> 6; + *text++ = 0x80 | (uchar & 0x3f); + } + else if (uchar < 0x10000) { + *text++ = 0xe0 | uchar >> 12; + *text++ = 0x80 | (uchar >> 6 & 0x3f); + *text++ = 0x80 | (uchar & 0x3f); + } + else if (uchar < 0x200000) { + *text++ = 0xf0 | uchar >> 18; + *text++ = 0x80 | (uchar >> 12 & 0x3f); + *text++ = 0x80 | (uchar >> 6 & 0x3f); + *text++ = 0x80 | (uchar & 0x3f); + } + + return text; +} + + +char SCSUUTF8::processText(SWBuf &text, const SWKey *key, const SWModule *module) { +/* + unsigned char *to, *from; + unsigned long buflen = len * FILTERPAD; + char active = 0, mode = 0; + if ((unsigned long)key < 2) // hack, we're en(1)/de(0)ciphering + return -1; + + static unsigned short start[8] = {0x0000,0x0080,0x0100,0x0300,0x2000,0x2080,0x2100,0x3000}; + static unsigned short slide[8] = {0x0080,0x00C0,0x0400,0x0600,0x0900,0x3040,0x30A0,0xFF00}; + static unsigned short win[256] = { + 0x0000, 0x0080, 0x0100, 0x0180, 0x0200, 0x0280, 0x0300, 0x0380, + 0x0400, 0x0480, 0x0500, 0x0580, 0x0600, 0x0680, 0x0700, 0x0780, + 0x0800, 0x0880, 0x0900, 0x0980, 0x0A00, 0x0A80, 0x0B00, 0x0B80, + 0x0C00, 0x0C80, 0x0D00, 0x0D80, 0x0E00, 0x0E80, 0x0F00, 0x0F80, + 0x1000, 0x1080, 0x1100, 0x1180, 0x1200, 0x1280, 0x1300, 0x1380, + 0x1400, 0x1480, 0x1500, 0x1580, 0x1600, 0x1680, 0x1700, 0x1780, + 0x1800, 0x1880, 0x1900, 0x1980, 0x1A00, 0x1A80, 0x1B00, 0x1B80, + 0x1C00, 0x1C80, 0x1D00, 0x1D80, 0x1E00, 0x1E80, 0x1F00, 0x1F80, + 0x2000, 0x2080, 0x2100, 0x2180, 0x2200, 0x2280, 0x2300, 0x2380, + 0x2400, 0x2480, 0x2500, 0x2580, 0x2600, 0x2680, 0x2700, 0x2780, + 0x2800, 0x2880, 0x2900, 0x2980, 0x2A00, 0x2A80, 0x2B00, 0x2B80, + 0x2C00, 0x2C80, 0x2D00, 0x2D80, 0x2E00, 0x2E80, 0x2F00, 0x2F80, + 0x3000, 0x3080, 0x3100, 0x3180, 0x3200, 0x3280, 0x3300, 0x3800, + 0xE000, 0xE080, 0xE100, 0xE180, 0xE200, 0xE280, 0xE300, 0xE380, + 0xE400, 0xE480, 0xE500, 0xE580, 0xE600, 0xE680, 0xE700, 0xE780, + 0xE800, 0xE880, 0xE900, 0xE980, 0xEA00, 0xEA80, 0xEB00, 0xEB80, + 0xEC00, 0xEC80, 0xED00, 0xED80, 0xEE00, 0xEE80, 0xEF00, 0xEF80, + 0xF000, 0xF080, 0xF100, 0xF180, 0xF200, 0xF280, 0xF300, 0xF380, + 0xF400, 0xF480, 0xF500, 0xF580, 0xF600, 0xF680, 0xF700, 0xF780, + 0xF800, 0xF880, 0xF900, 0xF980, 0xFA00, 0xFA80, 0xFB00, 0xFB80, + 0xFC00, 0xFC80, 0xFD00, 0xFD80, 0xFE00, 0xFE80, 0xFF00, 0xFF80, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x00C0, 0x0250, 0x0370, 0x0530, 0x3040, 0x30A0, 0xFF60 + }; + + if (!len) + return 0; + + memmove(&text[buflen - len], text, len); + from = (unsigned char*)&text[buflen - len]; + to = (unsigned char *)text; + + // ------------------------------- + + for (int i = 0; i < len;) { + + + if (i >= len) break; + c = from[i++]; + + if (c >= 0x80) + { + to = UTF8Output (c - 0x80 + slide[active], to); + } + else if (c >= 0x20 && c <= 0x7F) + { + to = UTF8Output (c, to); + } + else if (c == 0x0 || c == 0x9 || c == 0xA || c == 0xC || c == 0xD) + { + to = UTF8Output (c, to); + } + else if (c >= 0x1 && c <= 0x8) // SQn + { + if (i >= len) break; + d = from[i++]; // single quote + + to = UTF8Output (d < 0x80 ? d + start [c - 0x1] : + d - 0x80 + slide [c - 0x1], to); + } + else if (c >= 0x10 && c <= 0x17) // SCn + { + active = c - 0x10; // change window + } + else if (c >= 0x18 && c <= 0x1F) // SDn + { + active = c - 0x18; // define window + if (i >= len) break; + slide [active] = win [from[i++]]; + } + else if (c == 0xB) // SDX + { + if (i >= len) break; + c = from[i++]; + + if (i >= len) break; + d = from[i++]; + + slide [active = c>>5] = 0x10000 + (((c & 0x1F) << 8 | d) << 7); + } + else if (c == 0xE) // SQU + { + if (i >= len) break; + c = from[i++]; // SQU + + if (i >= len) break; + to = UTF8Output (c << 8 | from[i++], to); + } + else if (c == 0xF) // SCU + { + mode = 1; // change to Unicode mode + + while (mode) + { + if (i >= len) break; + c = from[i++]; + + if (c <= 0xDF || c >= 0xF3) + { + if (i >= len) break; + to = UTF8Output (c << 8 | from[i++], to); + } + else if (c == 0xF0) // UQU + { + if (i >= len) break; + c = from[i++]; + + if (i >= len) break; + to = UTF8Output (c << 8 | from[i++], to); + } + else if (c >= 0xE0 && c <= 0xE7) // UCn + { + active = c - 0xE0; mode = 0; + } + else if (c >= 0xE8 && c <= 0xEF) // UDn + { + if (i >= len) break; + slide [active=c-0xE8] = win [from[i++]]; mode = 0; + } + else if (c == 0xF1) // UDX + { + if (i >= len) break; + c = from[i++]; + + if (i >= len) break; + d = from[i++]; + + slide [active = c>>5] = + 0x10000 + (((c & 0x1F) << 8 | d) << 7); mode = 0; + } + } + } + + + } + + *to++ = 0; + *to = 0; +*/ + return 0; +} + + +SWORD_NAMESPACE_END diff --git a/src/modules/filters/swbasicfilter.cpp b/src/modules/filters/swbasicfilter.cpp index ef10e45..e66017e 100644 --- a/src/modules/filters/swbasicfilter.cpp +++ b/src/modules/filters/swbasicfilter.cpp @@ -1,12 +1,13 @@ /****************************************************************************** - * swbasicfilter.h - definition of class SWBasicFilter. An SWFilter - * impl that provides some basic methods that - * many filters will need and can use as a starting - * point. * - * $Id: swbasicfilter.cpp 2167 2008-05-16 23:23:39Z scribe $ + * swbasicfilter.cpp - definition of class SWBasicFilter. An SWFilter + * impl that provides some basic methods that + * many filters will need and can use as a starting + * point. * - * Copyright 2001 CrossWire Bible Society (http://www.crosswire.org) + * $Id: swbasicfilter.cpp 2980 2013-09-14 21:51:47Z scribe $ + * + * Copyright 2001-2013 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society * P. O. Box 2528 * Tempe, AZ 85280-2528 @@ -33,9 +34,11 @@ SWORD_NAMESPACE_START + typedef std::map<SWBuf, SWBuf> DualStringMap; typedef std::set<SWBuf> StringSet; + // I hate bridge patterns but this isolates std::map from a ton of filters class SWBasicFilter::Private { public: @@ -44,11 +47,13 @@ public: StringSet escPassSet; }; + const char SWBasicFilter::INITIALIZE = 1; const char SWBasicFilter::PRECHAR = 2; const char SWBasicFilter::POSTCHAR = 4; const char SWBasicFilter::FINALIZE = 8; + SWBasicFilter::SWBasicFilter() { p = new Private; @@ -98,6 +103,7 @@ void SWBasicFilter::setPassThruUnknownEscapeString(bool val) { passThruUnknownEsc = val; } + void SWBasicFilter::setPassThruNumericEscapeString(bool val) { passThruUnknownEsc = val; } @@ -132,6 +138,7 @@ void SWBasicFilter::removeTokenSubstitute(const char *findString) { } } + void SWBasicFilter::addAllowedEscapeString(const char *findString) { char *buf = 0; @@ -144,12 +151,14 @@ void SWBasicFilter::addAllowedEscapeString(const char *findString) { else p->escPassSet.insert(StringSet::value_type(findString)); } + void SWBasicFilter::removeAllowedEscapeString(const char *findString) { if (p->escPassSet.find(findString) != p->escPassSet.end()) { p->escPassSet.erase( p->escPassSet.find(findString) ); } } + void SWBasicFilter::addEscapeStringSubstitute(const char *findString, const char *replaceString) { char *buf = 0; @@ -162,12 +171,14 @@ void SWBasicFilter::addEscapeStringSubstitute(const char *findString, const char else p->escSubMap.insert(DualStringMap::value_type(findString, replaceString)); } + void SWBasicFilter::removeEscapeStringSubstitute(const char *findString) { if (p->escSubMap.find(findString) != p->escSubMap.end()) { p->escSubMap.erase( p->escSubMap.find(findString) ); } } + bool SWBasicFilter::substituteToken(SWBuf &buf, const char *token) { DualStringMap::iterator it; @@ -187,12 +198,14 @@ bool SWBasicFilter::substituteToken(SWBuf &buf, const char *token) { return false; } + void SWBasicFilter::appendEscapeString(SWBuf &buf, const char *escString) { buf += escStart; buf += escString; buf += escEnd; } + bool SWBasicFilter::passAllowedEscapeString(SWBuf &buf, const char *escString) { StringSet::iterator it; @@ -213,6 +226,7 @@ bool SWBasicFilter::passAllowedEscapeString(SWBuf &buf, const char *escString) { return false; } + bool SWBasicFilter::handleNumericEscapeString(SWBuf &buf, const char *escString) { if (passThruNumericEsc) { appendEscapeString(buf, escString); @@ -221,6 +235,7 @@ bool SWBasicFilter::handleNumericEscapeString(SWBuf &buf, const char *escString) return false; } + bool SWBasicFilter::substituteEscapeString(SWBuf &buf, const char *escString) { DualStringMap::iterator it; @@ -403,4 +418,5 @@ char SWBasicFilter::processText(SWBuf &text, const SWKey *key, const SWModule *m return 0; } + SWORD_NAMESPACE_END diff --git a/src/modules/filters/swoptfilter.cpp b/src/modules/filters/swoptfilter.cpp index 9d6dac4..5c205f5 100644 --- a/src/modules/filters/swoptfilter.cpp +++ b/src/modules/filters/swoptfilter.cpp @@ -1,9 +1,11 @@ /****************************************************************************** * - * swoptfilter - SWFilter descendant and base class for all option filters + * swoptfilter.cpp - SWFilter descendant and base class for all option + * filters * + * $Id: swoptfilter.cpp 2980 2013-09-14 21:51:47Z scribe $ * - * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * Copyright 2003-2013 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society * P. O. Box 2528 * Tempe, AZ 85280-2528 @@ -33,10 +35,13 @@ SWOptionFilter::SWOptionFilter() { optValues = ∅ } + SWOptionFilter::SWOptionFilter(const char *oName, const char *oTip, const StringList *oValues) { optName = oName; optTip = oTip; optValues = oValues; + if (optValues->begin() != optValues->end()) setOptionValue(*(optValues->begin())); + isBooleanVal = optValues->size() == 2 && (optionValue == "On" || optionValue == "Off"); } diff --git a/src/modules/filters/teihtmlhref.cpp b/src/modules/filters/teihtmlhref.cpp index 47bb7b9..43fe584 100644 --- a/src/modules/filters/teihtmlhref.cpp +++ b/src/modules/filters/teihtmlhref.cpp @@ -1,10 +1,10 @@ /*************************************************************************** - * teirtf.cpp - TEI to HTMLHREF filter - * ------------------- - * begin : 2006-07-03 - * copyright : 2006 by CrossWire Bible Society * - * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * teihtmlhref.cpp - TEI to HTML with hrefs filter + * + * $Id: teihtmlhref.cpp 2833 2013-06-29 06:40:28Z chrislit $ + * + * Copyright 2008-2013 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society * P. O. Box 2528 * Tempe, AZ 85280-2528 @@ -35,8 +35,8 @@ SWORD_NAMESPACE_START TEIHTMLHREF::MyUserData::MyUserData(const SWModule *module, const SWKey *key) : BasicFilterUserData(module, key) { BiblicalText = false; if (module) { - version = module->Name(); - BiblicalText = (!strcmp(module->Type(), "Biblical Texts")); + version = module->getName(); + BiblicalText = (!strcmp(module->getType(), "Biblical Texts")); } } @@ -57,6 +57,8 @@ TEIHTMLHREF::TEIHTMLHREF() { addAllowedEscapeString("gt"); setTokenCaseSensitive(true); + + renderNoteNumbers = false; } bool TEIHTMLHREF::handleToken(SWBuf &buf, const char *token, BasicFilterUserData *userData) { @@ -259,11 +261,13 @@ bool TEIHTMLHREF::handleToken(SWBuf &buf, const char *token, BasicFilterUserData } if (tag.isEndTag()) { SWBuf footnoteNumber = tag.getAttribute("swordFootnote"); + SWBuf noteName = tag.getAttribute("n"); - buf.appendFormatted("<a href=\"passagestudy.jsp?action=showNote&type=n&value=%s&module=%s&passage=%s\"><small><sup class=\"n\">*n</sup></small></a>", + 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(u->key->getText()).c_str()); + URL::encode(u->key->getText()).c_str(), + (renderNoteNumbers ? URL::encode(noteName.c_str()).c_str() : "")); u->suspendTextPassThru = false; } diff --git a/src/modules/filters/teiplain.cpp b/src/modules/filters/teiplain.cpp index 90b7c7c..954beb4 100644 --- a/src/modules/filters/teiplain.cpp +++ b/src/modules/filters/teiplain.cpp @@ -1,10 +1,10 @@ /*************************************************************************** - * teiplain.cpp - TEI to Plaintext filter - * ------------------- - * begin : 2006-07-05 - * copyright : 2006 by CrossWire Bible Society * - * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * teiplain.cpp - TEI to Plaintext filter + * + * $Id: teiplain.cpp 2833 2013-06-29 06:40:28Z chrislit $ + * + * Copyright 2006-2013 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society * P. O. Box 2528 * Tempe, AZ 85280-2528 diff --git a/src/modules/filters/teirtf.cpp b/src/modules/filters/teirtf.cpp index 8e135b5..979e4a6 100644 --- a/src/modules/filters/teirtf.cpp +++ b/src/modules/filters/teirtf.cpp @@ -1,208 +1,208 @@ -/*************************************************************************** - * teirtf.cpp - TEI to RTF filter - * ------------------- - * begin : 2006-07-03 - * copyright : 2006 by CrossWire Bible Society - * - * Copyright 2009 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 <stdlib.h> -#include <ctype.h> -#include <teirtf.h> -#include <utilxml.h> -#include <swmodule.h> -#include <versekey.h> - -SWORD_NAMESPACE_START - - -TEIRTF::MyUserData::MyUserData(const SWModule *module, const SWKey *key) : BasicFilterUserData(module, key) { - BiblicalText = false; - inOsisRef = false; - if (module) { - version = module->Name(); - BiblicalText = (!strcmp(module->Type(), "Biblical Texts")); - } -} - - -TEIRTF::TEIRTF() { - setTokenStart("<"); - setTokenEnd(">"); - - setEscapeStart("&"); - setEscapeEnd(";"); - - setEscapeStringCaseSensitive(true); - - addEscapeStringSubstitute("amp", "&"); - addEscapeStringSubstitute("apos", "'"); - addEscapeStringSubstitute("lt", "<"); - addEscapeStringSubstitute("gt", ">"); - addEscapeStringSubstitute("quot", "\""); - - setTokenCaseSensitive(true); -} - - -bool TEIRTF::handleToken(SWBuf &buf, const char *token, BasicFilterUserData *userData) { - // manually process if it wasn't a simple substitution - if (!substituteToken(buf, token)) { - MyUserData *u = (MyUserData *)userData; - XMLTag tag(token); - - // <p> paragraph tag - if (!strcmp(tag.getName(), "p")) { - if (!tag.isEndTag()) { // non-empty start tag - buf += "{\\sb100\\fi200\\par}"; - } - } - - // <hi> - else if (!strcmp(tag.getName(), "hi") || !strcmp(tag.getName(), "emph")) { - SWBuf rend = tag.getAttribute("rend"); - if ((!tag.isEndTag()) && (!tag.isEmpty())) { - if (rend == "ital" || rend == "italic") - buf += "{\\i1 "; - else if (rend == "bold") - buf += "{\\b1 "; - else if (rend == "sup") - buf += "{\\super "; - - } - else if (tag.isEndTag()) { - buf += "}"; - } - } - - // <entryFree> - else if (!strcmp(tag.getName(), "entryFree")) { - SWBuf n = tag.getAttribute("n"); - if ((!tag.isEndTag()) && (!tag.isEmpty())) { - if (n != "") { - buf += "{\\b1 "; - buf += n; - buf += ". }"; } - } - } - - // <sense> - else if (!strcmp(tag.getName(), "sense")) { - SWBuf n = tag.getAttribute("n"); - if ((!tag.isEndTag()) && (!tag.isEmpty())) { - if (n != "") { - buf += "{\\sb100\\par\\b1 "; - buf += n; - buf += ". }"; - } - } - } - - // <div> - else if (!strcmp(tag.getName(), "div")) { - - if ((!tag.isEndTag()) && (!tag.isEmpty())) { - buf.append("{\\pard\\sa300}"); - } - else if (tag.isEndTag()) { - } - } - - // <pos>, <gen>, <case>, <gram>, <number>, <mood> - else if (!strcmp(tag.getName(), "pos") || !strcmp(tag.getName(), "gen") || !strcmp(tag.getName(), "case") || !strcmp(tag.getName(), "gram") || !strcmp(tag.getName(), "number") || !strcmp(tag.getName(), "mood")) { - if ((!tag.isEndTag()) && (!tag.isEmpty())) { - buf += "{\\i1 "; - } - else if (tag.isEndTag()) { - buf += "}"; - } - } - - // <tr> - else if (!strcmp(tag.getName(), "tr")) { - if ((!tag.isEndTag()) && (!tag.isEmpty())) { - buf += "{\\i1 "; - } - else if (tag.isEndTag()) { - buf += "}"; - } - } - - // <etym> - else if (!strcmp(tag.getName(), "etym")) { - if ((!tag.isEndTag()) && (!tag.isEmpty())) { - buf += "["; - } - else if (tag.isEndTag()) { - buf += "]"; - } - } - - // <note> tag - else if (!strcmp(tag.getName(), "note")) { - if (!tag.isEndTag()) { - if (!tag.isEmpty()) { - SWBuf type = tag.getAttribute("type"); - - SWBuf footnoteNumber = tag.getAttribute("swordFootnote"); - VerseKey *vkey = 0; - // see if we have a VerseKey * or descendant - SWTRY { - vkey = SWDYNAMIC_CAST(VerseKey, u->key); - } - SWCATCH ( ... ) { } - if (vkey) { - buf.appendFormatted("{\\super <a href=\"\">*%s</a>} ", footnoteNumber.c_str()); - } - u->suspendTextPassThru = true; - } - } - if (tag.isEndTag()) { - u->suspendTextPassThru = false; - } - } - - // <lb/> tag - else if (!strcmp(tag.getName(), "lb")) { - buf += "{\\par}"; - userData->supressAdjacentWhitespace = true; - } - - // <ref> tag - else if (!strcmp(tag.getName(), "ref")) { - if (!tag.isEndTag() && tag.getAttribute("osisRef")) { - buf += "{<a href=\"\">"; - u->inOsisRef = true; - } - else if (tag.isEndTag() && u->inOsisRef) { - buf += "</a>}"; - u->inOsisRef = false; - } - } - - - else { - return false; // we still didn't handle token - } - - } - return true; -} - - -SWORD_NAMESPACE_END - +/*************************************************************************** + * + * teirtf.cpp - TEI to RTF filter + * + * $Id: teirtf.cpp 2833 2013-06-29 06:40:28Z chrislit $ + * + * Copyright 2006-2013 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 <stdlib.h> +#include <ctype.h> +#include <teirtf.h> +#include <utilxml.h> +#include <swmodule.h> +#include <versekey.h> + +SWORD_NAMESPACE_START + + +TEIRTF::MyUserData::MyUserData(const SWModule *module, const SWKey *key) : BasicFilterUserData(module, key) { + BiblicalText = false; + inOsisRef = false; + if (module) { + version = module->getName(); + BiblicalText = (!strcmp(module->getType(), "Biblical Texts")); + } +} + + +TEIRTF::TEIRTF() { + setTokenStart("<"); + setTokenEnd(">"); + + setEscapeStart("&"); + setEscapeEnd(";"); + + setEscapeStringCaseSensitive(true); + + addEscapeStringSubstitute("amp", "&"); + addEscapeStringSubstitute("apos", "'"); + addEscapeStringSubstitute("lt", "<"); + addEscapeStringSubstitute("gt", ">"); + addEscapeStringSubstitute("quot", "\""); + + setTokenCaseSensitive(true); +} + + +bool TEIRTF::handleToken(SWBuf &buf, const char *token, BasicFilterUserData *userData) { + // manually process if it wasn't a simple substitution + if (!substituteToken(buf, token)) { + MyUserData *u = (MyUserData *)userData; + XMLTag tag(token); + + // <p> paragraph tag + if (!strcmp(tag.getName(), "p")) { + if (!tag.isEndTag()) { // non-empty start tag + buf += "{\\sb100\\fi200\\par}"; + } + } + + // <hi> + else if (!strcmp(tag.getName(), "hi") || !strcmp(tag.getName(), "emph")) { + SWBuf rend = tag.getAttribute("rend"); + if ((!tag.isEndTag()) && (!tag.isEmpty())) { + if (rend == "ital" || rend == "italic") + buf += "{\\i1 "; + else if (rend == "bold") + buf += "{\\b1 "; + else if (rend == "sup") + buf += "{\\super "; + + } + else if (tag.isEndTag()) { + buf += "}"; + } + } + + // <entryFree> + else if (!strcmp(tag.getName(), "entryFree")) { + SWBuf n = tag.getAttribute("n"); + if ((!tag.isEndTag()) && (!tag.isEmpty())) { + if (n != "") { + buf += "{\\b1 "; + buf += n; + buf += ". }"; } + } + } + + // <sense> + else if (!strcmp(tag.getName(), "sense")) { + SWBuf n = tag.getAttribute("n"); + if ((!tag.isEndTag()) && (!tag.isEmpty())) { + if (n != "") { + buf += "{\\sb100\\par\\b1 "; + buf += n; + buf += ". }"; + } + } + } + + // <div> + else if (!strcmp(tag.getName(), "div")) { + + if ((!tag.isEndTag()) && (!tag.isEmpty())) { + buf.append("{\\pard\\sa300}"); + } + else if (tag.isEndTag()) { + } + } + + // <pos>, <gen>, <case>, <gram>, <number>, <mood> + else if (!strcmp(tag.getName(), "pos") || !strcmp(tag.getName(), "gen") || !strcmp(tag.getName(), "case") || !strcmp(tag.getName(), "gram") || !strcmp(tag.getName(), "number") || !strcmp(tag.getName(), "mood")) { + if ((!tag.isEndTag()) && (!tag.isEmpty())) { + buf += "{\\i1 "; + } + else if (tag.isEndTag()) { + buf += "}"; + } + } + + // <tr> + else if (!strcmp(tag.getName(), "tr")) { + if ((!tag.isEndTag()) && (!tag.isEmpty())) { + buf += "{\\i1 "; + } + else if (tag.isEndTag()) { + buf += "}"; + } + } + + // <etym> + else if (!strcmp(tag.getName(), "etym")) { + if ((!tag.isEndTag()) && (!tag.isEmpty())) { + buf += "["; + } + else if (tag.isEndTag()) { + buf += "]"; + } + } + + // <note> tag + else if (!strcmp(tag.getName(), "note")) { + if (!tag.isEndTag()) { + if (!tag.isEmpty()) { + SWBuf type = tag.getAttribute("type"); + + SWBuf footnoteNumber = tag.getAttribute("swordFootnote"); + VerseKey *vkey = 0; + // see if we have a VerseKey * or descendant + SWTRY { + vkey = SWDYNAMIC_CAST(VerseKey, u->key); + } + SWCATCH ( ... ) { } + if (vkey) { + buf.appendFormatted("{\\super <a href=\"\">*%s</a>} ", footnoteNumber.c_str()); + } + u->suspendTextPassThru = true; + } + } + if (tag.isEndTag()) { + u->suspendTextPassThru = false; + } + } + + // <lb/> tag + else if (!strcmp(tag.getName(), "lb")) { + buf += "{\\par}"; + userData->supressAdjacentWhitespace = true; + } + + // <ref> tag + else if (!strcmp(tag.getName(), "ref")) { + if (!tag.isEndTag() && tag.getAttribute("osisRef")) { + buf += "{<a href=\"\">"; + u->inOsisRef = true; + } + else if (tag.isEndTag() && u->inOsisRef) { + buf += "</a>}"; + u->inOsisRef = false; + } + } + + + else { + return false; // we still didn't handle token + } + + } + return true; +} + + +SWORD_NAMESPACE_END + diff --git a/src/modules/filters/teixhtml.cpp b/src/modules/filters/teixhtml.cpp new file mode 100644 index 0000000..6a390a1 --- /dev/null +++ b/src/modules/filters/teixhtml.cpp @@ -0,0 +1,290 @@ +/*************************************************************************** + * + * teixhtml.cpp - TEI to XHTML filter + * + * $Id: teixhtml.cpp 2984 2013-09-20 12:18:45Z scribe $ + * + * Copyright 2012-2013 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 <stdlib.h> +#include <ctype.h> +#include <teixhtml.h> +#include <utilxml.h> +#include <swmodule.h> +#include <url.h> +#include <iostream> + + +SWORD_NAMESPACE_START + + +TEIXHTML::MyUserData::MyUserData(const SWModule *module, const SWKey *key) : BasicFilterUserData(module, key) { + BiblicalText = false; + if (module) { + version = module->getName(); + BiblicalText = (!strcmp(module->getType(), "Biblical Texts")); + } +} + + +TEIXHTML::TEIXHTML() { + setTokenStart("<"); + setTokenEnd(">"); + + setEscapeStart("&"); + setEscapeEnd(";"); + + setEscapeStringCaseSensitive(true); + + addAllowedEscapeString("quot"); + addAllowedEscapeString("apos"); + addAllowedEscapeString("amp"); + addAllowedEscapeString("lt"); + addAllowedEscapeString("gt"); + + setTokenCaseSensitive(true); + + renderNoteNumbers = false; +} + +bool TEIXHTML::handleToken(SWBuf &buf, const char *token, BasicFilterUserData *userData) { + // manually process if it wasn't a simple substitution + if (!substituteToken(buf, token)) { + MyUserData *u = (MyUserData *)userData; + XMLTag tag(token); + + if (!strcmp(tag.getName(), "p")) { + if ((!tag.isEndTag()) && (!tag.isEmpty())) { // non-empty start tag + buf += "<!P><br />"; + } + else if (tag.isEndTag()) { // end tag + buf += "<!/P><br />"; + //userData->supressAdjacentWhitespace = true; + } + else { // empty paragraph break marker + buf += "<!P><br />"; + //userData->supressAdjacentWhitespace = true; + } + } + + // <hi> + else if (!strcmp(tag.getName(), "hi")) { + if ((!tag.isEndTag()) && (!tag.isEmpty())) { + SWBuf rend = tag.getAttribute("rend"); + + u->lastHi = rend; + if (rend == "ital") + buf += "<i>"; + else if (rend == "italic") + buf += "<i>"; + else if (rend == "bold") + buf += "<b>"; + else if (rend == "sup") + buf += "<small><sup>"; + else if (rend == "overline") + buf += "<span style=\"text-decoration:overline\">"; + + } + else if (tag.isEndTag()) { + SWBuf rend = u->lastHi; + if (rend == "ital") + buf += "</i>"; + else if (rend == "italic") + buf += "</i>"; + else if (rend == "bold") + buf += "</b>"; + else if (rend == "sup") + buf += "</sup></small>"; + else if (rend == "overline") + buf += "</span>"; + } + } + + // <entryFree> + else if (!strcmp(tag.getName(), "entryFree")) { + if ((!tag.isEndTag()) && (!tag.isEmpty())) { + SWBuf n = tag.getAttribute("n"); + if (n != "") { + buf += "<b>"; + buf += n; + buf += "</b>"; + } + } + } + + // <sense> + else if (!strcmp(tag.getName(), "sense")) { + if ((!tag.isEndTag()) && (!tag.isEmpty())) { + SWBuf n = tag.getAttribute("n"); + if (n != "") { + buf += "<br /><b>"; + buf += n; + buf += "</b>"; + } + } + } + + // <div> + else if (!strcmp(tag.getName(), "div")) { + + if ((!tag.isEndTag()) && (!tag.isEmpty())) { + buf += "<!P>"; + } + else if (tag.isEndTag()) { + } + } + + // <lb.../> + else if (!strcmp(tag.getName(), "lb")) { + buf += "<br />"; + } + + // <pos>, <gen>, <case>, <gram>, <number>, <mood>, <pron>, <def> + else if (!strcmp(tag.getName(), "pos") || + !strcmp(tag.getName(), "gen") || + !strcmp(tag.getName(), "case") || + !strcmp(tag.getName(), "gram") || + !strcmp(tag.getName(), "number") || + !strcmp(tag.getName(), "pron") /*|| + !strcmp(tag.getName(), "def")*/) { + if ((!tag.isEndTag()) && (!tag.isEmpty())) { + buf += "<i>"; + } + else if (tag.isEndTag()) { + buf += "</i>"; + } + } + + // <tr> + else if (!strcmp(tag.getName(), "tr")) { + if ((!tag.isEndTag()) && (!tag.isEmpty())) { + buf += "<i>"; + } + else if (tag.isEndTag()) { + buf += "</i>"; + } + } + + // orth + else if (!strcmp(tag.getName(), "orth")) { + if ((!tag.isEndTag()) && (!tag.isEmpty())) { + buf += "<b>"; + } + else if (tag.isEndTag()) { + buf += "</b>"; + } + } + + // <etym>, <usg> + else if (!strcmp(tag.getName(), "etym") || + !strcmp(tag.getName(), "usg")) { + // do nothing here + } + else if (!strcmp(tag.getName(), "ref")) { + if (!tag.isEndTag()) { + u->suspendTextPassThru = true; + SWBuf target; + SWBuf work; + SWBuf ref; + + int was_osisref = false; + if(tag.getAttribute("osisRef")) + { + target += tag.getAttribute("osisRef"); + was_osisref=true; + } + else if(tag.getAttribute("target")) + target += tag.getAttribute("target"); + + if(target.size()) + { + const char* the_ref = strchr(target, ':'); + + if(!the_ref) { + // No work + ref = target; + } + else { + // Compensate for starting : + ref = the_ref + 1; + + int size = target.size() - ref.size() - 1; + work.setSize(size); + strncpy(work.getRawData(), target, size); + } + + if(was_osisref) + { + buf.appendFormatted("<a href=\"passagestudy.jsp?action=showRef&type=scripRef&value=%s&module=%s\">", + (ref) ? URL::encode(ref.c_str()).c_str() : "", + (work.size()) ? URL::encode(work.c_str()).c_str() : ""); + } + else + { + // Dictionary link, or something + buf.appendFormatted("<a href=\"sword://%s/%s\">", + (work.size()) ? URL::encode(work.c_str()).c_str() : u->version.c_str(), + (ref) ? URL::encode(ref.c_str()).c_str() : "" + ); + } + } + else + { + //std::cout << "TARGET WASN'T\n"; + } + + } + else { + buf += u->lastTextNode.c_str(); + buf += "</a>"; + + u->suspendTextPassThru = false; + } + } + + // <note> tag + else if (!strcmp(tag.getName(), "note")) { + if (!tag.isEndTag()) { + if (!tag.isEmpty()) { + u->suspendTextPassThru = true; + } + } + if (tag.isEndTag()) { + SWBuf footnoteNumber = tag.getAttribute("swordFootnote"); + SWBuf noteName = tag.getAttribute("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(u->key->getText()).c_str(), + (renderNoteNumbers ? URL::encode(noteName.c_str()).c_str() : "")); + + u->suspendTextPassThru = false; + } + } + + else { + return false; // we still didn't handle token + } + + } + return true; +} + + +SWORD_NAMESPACE_END + diff --git a/src/modules/filters/thmlfootnotes.cpp b/src/modules/filters/thmlfootnotes.cpp index e75311a..566551f 100644 --- a/src/modules/filters/thmlfootnotes.cpp +++ b/src/modules/filters/thmlfootnotes.cpp @@ -1,10 +1,11 @@ /****************************************************************************** * - * thmlfootnotes - SWFilter descendant to hide or show footnotes - * in a ThML module. + * thmlfootnotes.cpp - SWFilter descendant to hide or show footnotes + * in a ThML module * + * $Id: thmlfootnotes.cpp 2980 2013-09-14 21:51:47Z scribe $ * - * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * Copyright 2001-2013 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society * P. O. Box 2528 * Tempe, AZ 85280-2528 @@ -30,16 +31,23 @@ #include <versekey.h> #include <utilxml.h> + SWORD_NAMESPACE_START -const char oName[] = "Footnotes"; -const char oTip[] = "Toggles Footnotes On and Off if they exist"; +namespace { + + static const char oName[] = "Footnotes"; + static const char oTip[] = "Toggles Footnotes On and Off if they exist"; + + static const StringList *oValues() { + static const SWBuf choices[3] = {"Off", "On", ""}; + static const StringList oVals(&choices[0], &choices[2]); + return &oVals; + } +} -const SWBuf choices[3] = {"Off", "On", ""}; -const StringList oValues(&choices[0], &choices[2]); -ThMLFootnotes::ThMLFootnotes() : SWOptionFilter(oName, oTip, &oValues) { - setOptionValue("Off"); +ThMLFootnotes::ThMLFootnotes() : SWOptionFilter(oName, oTip, oValues()) { } @@ -56,7 +64,7 @@ char ThMLFootnotes::processText(SWBuf &text, const SWKey *key, const SWModule *m SWBuf refs = ""; int footnoteNum = 1; char buf[254]; - SWKey *p = (module) ? module->CreateKey() : (key) ? key->clone() : new VerseKey(); + SWKey *p = (module) ? module->createKey() : (key) ? key->clone() : new VerseKey(); VerseKey *parser = SWDYNAMIC_CAST(VerseKey, p); if (!parser) { delete p; @@ -101,7 +109,7 @@ char ThMLFootnotes::processText(SWBuf &text, const SWKey *key, const SWModule *m startTag.setAttribute("swordFootnote", buf); if ((startTag.getAttribute("type")) && (!strcmp(startTag.getAttribute("type"), "crossReference"))) { if (!refs.length()) - refs = parser->ParseVerseList(tagText.c_str(), *parser, true).getRangeText(); + refs = parser->parseVerseList(tagText.c_str(), *parser, true).getRangeText(); module->getEntryAttributes()["Footnote"][buf]["refList"] = refs.c_str(); } } diff --git a/src/modules/filters/thmlgbf.cpp b/src/modules/filters/thmlgbf.cpp index e2e8e1c..e85fdef 100644 --- a/src/modules/filters/thmlgbf.cpp +++ b/src/modules/filters/thmlgbf.cpp @@ -1,11 +1,10 @@ /*************************************************************************** - * thmlgbf.cpp - ThML to GBF filter - * ------------------- - * begin : 1999-10-28 - * copyright : 2001 by CrossWire Bible Society * + * thmlgbf.cpp - ThML to GBF filter * - * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * $Id: thmlgbf.cpp 2833 2013-06-29 06:40:28Z chrislit $ + * + * Copyright 1999-2013 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society * P. O. Box 2528 * Tempe, AZ 85280-2528 diff --git a/src/modules/filters/thmlheadings.cpp b/src/modules/filters/thmlheadings.cpp index e2b7c97..46498d0 100644 --- a/src/modules/filters/thmlheadings.cpp +++ b/src/modules/filters/thmlheadings.cpp @@ -1,10 +1,11 @@ /****************************************************************************** * - * thmlheadings - SWFilter descendant to hide or show headings - * in a ThML module. + * thmlheadings.cpp - SWFilter descendant to hide or show headings + * in a ThML module * + * $Id: thmlheadings.cpp 2980 2013-09-14 21:51:47Z scribe $ * - * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * Copyright 2001-2013 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society * P. O. Box 2528 * Tempe, AZ 85280-2528 @@ -28,16 +29,23 @@ #include <swmodule.h> #include <stdio.h> + SWORD_NAMESPACE_START -const char oName[] = "Headings"; -const char oTip[] = "Toggles Headings On and Off if they exist"; +namespace { + + static const char oName[] = "Headings"; + static const char oTip[] = "Toggles Headings On and Off if they exist"; + + static const StringList *oValues() { + static const SWBuf choices[3] = {"Off", "On", ""}; + static const StringList oVals(&choices[0], &choices[2]); + return &oVals; + } +} -const SWBuf choices[3] = {"Off", "On", ""}; -const StringList oValues(&choices[0], &choices[2]); -ThMLHeadings::ThMLHeadings() : SWOptionFilter(oName, oTip, &oValues) { - setOptionValue("Off"); +ThMLHeadings::ThMLHeadings() : SWOptionFilter(oName, oTip, oValues()) { } diff --git a/src/modules/filters/thmlhtml.cpp b/src/modules/filters/thmlhtml.cpp index 4c66b87..b5f624e 100644 --- a/src/modules/filters/thmlhtml.cpp +++ b/src/modules/filters/thmlhtml.cpp @@ -1,11 +1,10 @@ /*************************************************************************** - * thmlhtml.cpp - ThML to HTML filter - * ------------------- - * begin : 1999-10-27 - * copyright : 2001 by CrossWire Bible Society * + * thmlhtml.cpp - ThML to HTML filter * - * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * $Id: thmlhtml.cpp 2980 2013-09-14 21:51:47Z scribe $ + * + * Copyright 1999-2013 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society * P. O. Box 2528 * Tempe, AZ 85280-2528 @@ -26,8 +25,10 @@ #include <swmodule.h> #include <utilxml.h> + SWORD_NAMESPACE_START + ThMLHTML::ThMLHTML() { setTokenStart("<"); setTokenEnd(">"); diff --git a/src/modules/filters/thmlhtmlhref.cpp b/src/modules/filters/thmlhtmlhref.cpp index c0887f1..f72a93e 100644 --- a/src/modules/filters/thmlhtmlhref.cpp +++ b/src/modules/filters/thmlhtmlhref.cpp @@ -1,11 +1,10 @@ /*************************************************************************** - * thmlhtmlhref.cpp - ThML to HTML filter with hrefs - * ------------------- - * begin : 2001-09-03 - * copyright : 2001 by CrossWire Bible Society * + * thmlhtmlhref.cpp - ThML to HTML filter with hrefs * - * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * $Id: thmlhtmlhref.cpp 2980 2013-09-14 21:51:47Z scribe $ + * + * Copyright 2001-2013 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society * P. O. Box 2528 * Tempe, AZ 85280-2528 @@ -29,13 +28,14 @@ #include <versekey.h> #include <url.h> + SWORD_NAMESPACE_START ThMLHTMLHREF::MyUserData::MyUserData(const SWModule *module, const SWKey *key) : BasicFilterUserData(module, key) { if (module) { - version = module->Name(); - BiblicalText = (!strcmp(module->Type(), "Biblical Texts")); + version = module->getName(); + BiblicalText = (!strcmp(module->getType(), "Biblical Texts")); SecHead = false; } } @@ -160,6 +160,8 @@ ThMLHTMLHREF::ThMLHTMLHREF() { setTokenCaseSensitive(true); // addTokenSubstitute("scripture", "<i> "); addTokenSubstitute("/scripture", "</i> "); + + renderNoteNumbers = false; } @@ -206,6 +208,7 @@ bool ThMLHTMLHREF::handleToken(SWBuf &buf, const char *token, BasicFilterUserDat 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 { @@ -215,23 +218,25 @@ bool ThMLHTMLHREF::handleToken(SWBuf &buf, const char *token, BasicFilterUserDat 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</sup></small></a>", + 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); + ch, + (renderNoteNumbers ? URL::encode(noteName.c_str()).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</sup></small></a>", + 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); + ch, + (renderNoteNumbers ? URL::encode(noteName.c_str()).c_str() : "")); } u->suspendTextPassThru = true; } @@ -265,6 +270,7 @@ bool ThMLHTMLHREF::handleToken(SWBuf &buf, const char *token, BasicFilterUserDat } else { SWBuf footnoteNumber = u->startTag.getAttribute("swordFootnote"); + SWBuf noteName = tag.getAttribute("n"); VerseKey *vkey = NULL; // see if we have a VerseKey * or descendant SWTRY { @@ -274,11 +280,11 @@ bool ThMLHTMLHREF::handleToken(SWBuf &buf, const char *token, BasicFilterUserDat if (vkey) { // leave this special osis type in for crossReference notes types? Might thml use this some day? Doesn't hurt. //buf.appendFormatted("<a href=\"noteID=%s.x.%s\"><small><sup>*x</sup></small></a> ", vkey->getText(), footnoteNumber.c_str()); - buf.appendFormatted("<a href=\"passagestudy.jsp?action=showNote&type=x&value=%s&module=%s&passage=%s\"><small><sup class=\"x\">*x</sup></small></a>", + buf.appendFormatted("<a href=\"passagestudy.jsp?action=showNote&type=x&value=%s&module=%s&passage=%s\"><small><sup class=\"x\">*x%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()); - + URL::encode(vkey->getText()).c_str(), + (renderNoteNumbers ? URL::encode(noteName.c_str()).c_str() : "")); } } diff --git a/src/modules/filters/thmllemma.cpp b/src/modules/filters/thmllemma.cpp index 53eec58..acc324f 100644 --- a/src/modules/filters/thmllemma.cpp +++ b/src/modules/filters/thmllemma.cpp @@ -1,10 +1,11 @@ /****************************************************************************** * - * thmllemma - SWFilter descendant to hide or show lemmas - * in a ThML module. + * thmllemma.cpp - SWFilter descendant to hide or show lemmas + * in a ThML module * + * $Id: thmllemma.cpp 2980 2013-09-14 21:51:47Z scribe $ * - * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * Copyright 2001-2013 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society * P. O. Box 2528 * Tempe, AZ 85280-2528 @@ -23,16 +24,23 @@ #include <stdlib.h> #include <thmllemma.h> + SWORD_NAMESPACE_START -const char oName[] = "Lemmas"; -const char oTip[] = "Toggles Lemmas On and Off if they exist"; +namespace { + + static const char oName[] = "Lemmas"; + static const char oTip[] = "Toggles Lemmas On and Off if they exist"; + + static const StringList *oValues() { + static const SWBuf choices[3] = {"Off", "On", ""}; + static const StringList oVals(&choices[0], &choices[2]); + return &oVals; + } +} -const SWBuf choices[3] = {"Off", "On", ""}; -const StringList oValues(&choices[0], &choices[2]); -ThMLLemma::ThMLLemma() : SWOptionFilter(oName, oTip, &oValues) { - setOptionValue("Off"); +ThMLLemma::ThMLLemma() : SWOptionFilter(oName, oTip, oValues()) { } diff --git a/src/modules/filters/thmlmorph.cpp b/src/modules/filters/thmlmorph.cpp index d3cf597..3259acc 100644 --- a/src/modules/filters/thmlmorph.cpp +++ b/src/modules/filters/thmlmorph.cpp @@ -1,10 +1,11 @@ /****************************************************************************** * - * thmlmorph - SWFilter descendant to hide or show morph tags - * in a ThML module. + * thmlmorph.cpp - SWFilter descendant to hide or show morph tags + * in a ThML module * + * $Id: thmlmorph.cpp 2980 2013-09-14 21:51:47Z scribe $ * - * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * Copyright 2001-2013 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society * P. O. Box 2528 * Tempe, AZ 85280-2528 @@ -25,14 +26,20 @@ SWORD_NAMESPACE_START -const char oName[] = "Morphological Tags"; -const char oTip[] = "Toggles Morphological Tags On and Off if they exist"; +namespace { -const SWBuf choices[3] = {"Off", "On", ""}; -const StringList oValues(&choices[0], &choices[2]); + static const char oName[] = "Morphological Tags"; + static const char oTip[] = "Toggles Morphological Tags On and Off if they exist"; -ThMLMorph::ThMLMorph() : SWOptionFilter(oName, oTip, &oValues) { - setOptionValue("Off"); + static const StringList *oValues() { + static const SWBuf choices[3] = {"Off", "On", ""}; + static const StringList oVals(&choices[0], &choices[2]); + return &oVals; + } +} + + +ThMLMorph::ThMLMorph() : SWOptionFilter(oName, oTip, oValues()) { } diff --git a/src/modules/filters/thmlosis.cpp b/src/modules/filters/thmlosis.cpp index 25fdf23..3acd959 100644 --- a/src/modules/filters/thmlosis.cpp +++ b/src/modules/filters/thmlosis.cpp @@ -1,10 +1,10 @@ /****************************************************************************** * - * thmlstrongs - SWFilter descendant to hide or show strongs number - * in a ThML module. + * thmlosis.cpp - filter to convert ThML to OSIS * + * $Id: thmlosis.cpp 2833 2013-06-29 06:40:28Z chrislit $ * - * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * Copyright 2002-2013 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society * P. O. Box 2528 * Tempe, AZ 85280-2528 @@ -540,7 +540,7 @@ char ThMLOSIS::processText(SWBuf &text, const SWKey *key, const SWModule *module VerseKey *vkey = SWDYNAMIC_CAST(VerseKey, key); if (vkey) { SWBuf ref = ""; - if (vkey->Verse()) { + if (vkey->getVerse()) { ref.appendFormatted("\t\t<verse osisID=\"%s\">", vkey->getOSISRef()); } @@ -548,24 +548,24 @@ char ThMLOSIS::processText(SWBuf &text, const SWKey *key, const SWModule *module text = ref + text; - if (vkey->Verse()) { + if (vkey->getVerse()) { VerseKey *tmp = (VerseKey *)vkey->clone(); *tmp = *vkey; - tmp->AutoNormalize(0); - tmp->Headings(1); + tmp->setAutoNormalize(false); + tmp->setIntros(true); text += "</verse>"; *tmp = MAXVERSE; if (*vkey == *tmp) { - tmp->Verse(0); + tmp->setVerse(0); // sprintf(ref, "\t</div>"); // pushString(&to, ref); *tmp = MAXCHAPTER; *tmp = MAXVERSE; if (*vkey == *tmp) { - tmp->Chapter(0); - tmp->Verse(0); + tmp->setChapter(0); + tmp->setVerse(0); // sprintf(ref, "\t</div>"); // pushString(&to, ref); /* @@ -578,7 +578,7 @@ char ThMLOSIS::processText(SWBuf &text, const SWKey *key, const SWModule *module } delete tmp; } -// else if (vkey->Chapter()) { +// else if (vkey->getChapter()) { // sprintf(ref, "\t<div type=\"chapter\" osisID=\"%s\">", vkey->getOSISRef()); // } // else sprintf(ref, "\t<div type=\"book\" osisID=\"%s\">", vkey->getOSISRef()); diff --git a/src/modules/filters/thmlplain.cpp b/src/modules/filters/thmlplain.cpp index 8c9358f..b9b9839 100644 --- a/src/modules/filters/thmlplain.cpp +++ b/src/modules/filters/thmlplain.cpp @@ -1,10 +1,11 @@ /****************************************************************************** * - * thmlplain - SWFilter descendant to strip out all ThML tags or convert to - * ASCII rendered symbols. + * thmlplain.cpp - SWFilter descendant to strip out all ThML tags or + * convert to ASCII rendered symbols * + * $Id: thmlplain.cpp 2833 2013-06-29 06:40:28Z chrislit $ * - * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * Copyright 1999-2013 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society * P. O. Box 2528 * Tempe, AZ 85280-2528 diff --git a/src/modules/filters/thmlrtf.cpp b/src/modules/filters/thmlrtf.cpp index fdb41df..dc50ae9 100644 --- a/src/modules/filters/thmlrtf.cpp +++ b/src/modules/filters/thmlrtf.cpp @@ -1,11 +1,10 @@ /*************************************************************************** - * thmlrtf.cpp - ThML to RTF filter - * ------------------- - * begin : 1999-10-27 - * copyright : 2001 by CrossWire Bible Society * + * thmlrtf.cpp - ThML to RTF filter * - * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * $Id: thmlrtf.cpp 2833 2013-06-29 06:40:28Z chrislit $ + * + * Copyright 1999-2013 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society * P. O. Box 2528 * Tempe, AZ 85280-2528 @@ -215,8 +214,8 @@ ThMLRTF::MyUserData::MyUserData(const SWModule *module, const SWKey *key) : Basi this->SecHead = false; XMLTag startTag = ""; if (module) { - version = module->Name(); - BiblicalText = (!strcmp(module->Type(), "Biblical Texts")); + version = module->getName(); + BiblicalText = (!strcmp(module->getType(), "Biblical Texts")); } } @@ -263,7 +262,7 @@ bool ThMLRTF::handleToken(SWBuf &buf, const char *token, BasicFilterUserData *us 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("{\\super <a href=\"\">*%c%i.%s</a>} ", ch, vkey->Verse(), footnoteNumber.c_str()); + buf.appendFormatted("{\\super <a href=\"\">*%c%i.%s</a>} ", ch, vkey->getVerse(), footnoteNumber.c_str()); } u->suspendTextPassThru = true; } @@ -301,7 +300,7 @@ bool ThMLRTF::handleToken(SWBuf &buf, const char *token, BasicFilterUserData *us SWCATCH ( ... ) {} if (vkey) { // leave this special osis type in for crossReference notes types? Might thml use this some day? Doesn't hurt. - buf.appendFormatted("{\\super <a href=\"\">*x%i.%s</a>} ", vkey->Verse(), footnoteNumber.c_str()); + buf.appendFormatted("{\\super <a href=\"\">*x%i.%s</a>} ", vkey->getVerse(), footnoteNumber.c_str()); } } diff --git a/src/modules/filters/thmlscripref.cpp b/src/modules/filters/thmlscripref.cpp index e46d679..1ea4a40 100644 --- a/src/modules/filters/thmlscripref.cpp +++ b/src/modules/filters/thmlscripref.cpp @@ -1,10 +1,11 @@ /****************************************************************************** * - * thmlscripref - SWFilter descendant to hide or show scripture - * referebces in a ThML module. + * thmlscripref.cpp - SWFilter descendant to hide or show scripture + * referebces in a ThML module * + * $Id: thmlscripref.cpp 2980 2013-09-14 21:51:47Z scribe $ * - * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * Copyright 2001-2013 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society * P. O. Box 2528 * Tempe, AZ 85280-2528 @@ -27,16 +28,23 @@ #include <versekey.h> #include <swmodule.h> + SWORD_NAMESPACE_START -const char oName[] = "Cross-references"; -const char oTip[] = "Toggles Scripture Cross-references On and Off if they exist"; +namespace { + + static const char oName[] = "Cross-references"; + static const char oTip[] = "Toggles Scripture Cross-references On and Off if they exist"; + + static const StringList *oValues() { + static const SWBuf choices[3] = {"On", "Off", ""}; + static const StringList oVals(&choices[0], &choices[2]); + return &oVals; + } +} -const SWBuf choices[3] = {"Off", "On", ""}; -const StringList oValues(&choices[0], &choices[2]); -ThMLScripref::ThMLScripref() : SWOptionFilter(oName, oTip, &oValues) { - setOptionValue("On"); +ThMLScripref::ThMLScripref() : SWOptionFilter(oName, oTip, oValues()) { } @@ -53,7 +61,7 @@ char ThMLScripref::processText(SWBuf &text, const SWKey *key, const SWModule *mo SWBuf refs = ""; int footnoteNum = 1; char buf[254]; - SWKey *p = (module) ? module->CreateKey() : (key) ? key->clone() : new VerseKey(); + SWKey *p = (module) ? module->createKey() : (key) ? key->clone() : new VerseKey(); VerseKey *parser = SWDYNAMIC_CAST(VerseKey, p); if (!parser) { delete p; @@ -98,8 +106,8 @@ char ThMLScripref::processText(SWBuf &text, const SWKey *key, const SWModule *mo startTag.setAttribute("swordFootnote", buf); SWBuf passage = startTag.getAttribute("passage"); if (passage.length()) - refs = parser->ParseVerseList(passage.c_str(), *parser, true).getRangeText(); - else refs = parser->ParseVerseList(tagText.c_str(), *parser, true).getRangeText(); + refs = parser->parseVerseList(passage.c_str(), *parser, true).getRangeText(); + else refs = parser->parseVerseList(tagText.c_str(), *parser, true).getRangeText(); module->getEntryAttributes()["Footnote"][buf]["refList"] = refs.c_str(); } hide = false; diff --git a/src/modules/filters/thmlstrongs.cpp b/src/modules/filters/thmlstrongs.cpp index 457e28b..09658a9 100644 --- a/src/modules/filters/thmlstrongs.cpp +++ b/src/modules/filters/thmlstrongs.cpp @@ -1,10 +1,11 @@ /****************************************************************************** * - * thmlstrongs - SWFilter descendant to hide or show strongs number - * in a ThML module. + * thmlstrongs.cpp - SWFilter descendant to hide or show Strong's number + * in a ThML module * + * $Id: thmlstrongs.cpp 2980 2013-09-14 21:51:47Z scribe $ * - * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * Copyright 2001-2013 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society * P. O. Box 2528 * Tempe, AZ 85280-2528 @@ -27,16 +28,23 @@ #include <utilstr.h> #include <ctype.h> + SWORD_NAMESPACE_START -const char oName[] = "Strong's Numbers"; -const char oTip[] = "Toggles Strong's Numbers On and Off if they exist"; +namespace { + + static const char oName[] = "Strong's Numbers"; + static const char oTip[] = "Toggles Strong's Numbers On and Off if they exist"; + + static const StringList *oValues() { + static const SWBuf choices[3] = {"Off", "On", ""}; + static const StringList oVals(&choices[0], &choices[2]); + return &oVals; + } +} -const SWBuf choices[3] = {"Off", "On", ""}; -const StringList oValues(&choices[0], &choices[2]); -ThMLStrongs::ThMLStrongs() : SWOptionFilter(oName, oTip, &oValues) { - setOptionValue("Off"); +ThMLStrongs::ThMLStrongs() : SWOptionFilter(oName, oTip, oValues()) { } diff --git a/src/modules/filters/thmlvariants.cpp b/src/modules/filters/thmlvariants.cpp index 4f28dbe..1a57971 100644 --- a/src/modules/filters/thmlvariants.cpp +++ b/src/modules/filters/thmlvariants.cpp @@ -1,10 +1,11 @@ /****************************************************************************** * - * thmlvariants - SWFilter descendant to hide or show textual variants - * in a ThML module. + * thmlvariants.cpp - SWFilter descendant to hide or show textual variants + * in a ThML module * + * $Id: thmlvariants.cpp 2980 2013-09-14 21:51:47Z scribe $ * - * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * Copyright 2002-2013 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society * P. O. Box 2528 * Tempe, AZ 85280-2528 @@ -24,50 +25,39 @@ #include <thmlvariants.h> #include <utilstr.h> -SWORD_NAMESPACE_START -const char ThMLVariants::primary[] = "Primary Reading"; -const char ThMLVariants::secondary[] = "Secondary Reading"; -const char ThMLVariants::all[] = "All Readings"; +SWORD_NAMESPACE_START -const char ThMLVariants::optName[] = "Textual Variants"; -const char ThMLVariants::optTip[] = "Switch between Textual Variants modes"; +namespace { + static const char oName[] = "Textual Variants"; + static const char oTip[] = "Switch between Textual Variants modes"; + static const char *choices[4] = { "Primary Reading", "Secondary Reading", "All Readings", "" }; -ThMLVariants::ThMLVariants() { - option = false; - options.push_back(primary); - options.push_back(secondary); - options.push_back(all); + static const StringList *oValues() { + static const StringList oVals(&choices[0], &choices[3]); + return &oVals; + } } -ThMLVariants::~ThMLVariants() { +ThMLVariants::ThMLVariants() : SWOptionFilter(oName, oTip, oValues()) { } -void ThMLVariants::setOptionValue(const char *ival) -{ - if (!stricmp(ival, primary)) option = 0; - else if (!stricmp(ival, secondary)) option = 1; - else option = 2; -} -const char *ThMLVariants::getOptionValue() -{ - if (option == 0) { - return primary; - } - else if (option == 1) { - return secondary; - } - else { - return all; - } +ThMLVariants::~ThMLVariants() { } + char ThMLVariants::processText(SWBuf &text, const SWKey *key, const SWModule *module) { - if ( option == 0 || option == 1) { //we want primary or variant only + + int option = 0; + if (optionValue == choices[0]) option = 0; + else if (optionValue == choices[1]) option = 1; + else option = 2; + + if (option == 0 || option == 1) { //we want primary or variant only bool intoken = false; bool hide = false; bool invar = false; @@ -127,7 +117,4 @@ char ThMLVariants::processText(SWBuf &text, const SWKey *key, const SWModule *mo - - - SWORD_NAMESPACE_END diff --git a/src/modules/filters/thmlwebif.cpp b/src/modules/filters/thmlwebif.cpp index 0192703..29d9ef5 100644 --- a/src/modules/filters/thmlwebif.cpp +++ b/src/modules/filters/thmlwebif.cpp @@ -1,11 +1,10 @@ /*************************************************************************** - * ThMLWEBIF.cpp - ThML to HTML filter with hrefs - * ------------------- - * begin : 2001-09-03 - * copyright : 2001 by CrossWire Bible Society * + * thmlwebif.cpp - ThML to HTML filter with hrefs * - * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * $Id: thmlwebif.cpp 2980 2013-09-14 21:51:47Z scribe $ + * + * Copyright 2003-2013 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society * P. O. Box 2528 * Tempe, AZ 85280-2528 @@ -30,10 +29,11 @@ SWORD_NAMESPACE_START + ThMLWEBIF::ThMLWEBIF() : baseURL(""), passageStudyURL(baseURL + "passagestudy.jsp") { - //all's done in ThMLHTMLHREF } + bool ThMLWEBIF::handleToken(SWBuf &buf, const char *token, BasicFilterUserData *userData) { if (!substituteToken(buf, token)) { // manually process if it wasn't a simple substitution @@ -100,7 +100,7 @@ bool ThMLWEBIF::handleToken(SWBuf &buf, const char *token, BasicFilterUserData * } } else { - return ThMLHTMLHREF::handleToken(buf,token,userData); + return ThMLXHTML::handleToken(buf, token, userData); } } return true; diff --git a/src/modules/filters/thmlwordjs.cpp b/src/modules/filters/thmlwordjs.cpp index 12fbeb1..7d80a00 100644 --- a/src/modules/filters/thmlwordjs.cpp +++ b/src/modules/filters/thmlwordjs.cpp @@ -1,10 +1,10 @@ /****************************************************************************** * - * thmlstrongs - SWFilter descendant to hide or show strongs number - * in a ThML module. + * thmlwordjs.cpp - SWFilter descendant to ??? * + * $Id: thmlwordjs.cpp 2980 2013-09-14 21:51:47Z scribe $ * - * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * Copyright 2005-2013 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society * P. O. Box 2528 * Tempe, AZ 85280-2528 @@ -29,17 +29,23 @@ #include <utilstr.h> #include <versekey.h> + SWORD_NAMESPACE_START -const char oName[] = "Word Javascript"; -const char oTip[] = "Toggles Word Javascript data"; +namespace { + + static const char oName[] = "Word Javascript"; + static const char oTip[] = "Toggles Word Javascript data"; -const SWBuf choices[3] = {"Off", "On", ""}; -const StringList oValues(&choices[0], &choices[2]); + static const StringList *oValues() { + static const SWBuf choices[3] = {"Off", "On", ""}; + static const StringList oVals(&choices[0], &choices[2]); + return &oVals; + } +} -ThMLWordJS::ThMLWordJS() : SWOptionFilter(oName, oTip, &oValues) { - setOptionValue("Off"); +ThMLWordJS::ThMLWordJS() : SWOptionFilter(oName, oTip, oValues()) { defaultGreekLex = 0; defaultHebLex = 0; @@ -58,7 +64,6 @@ char ThMLWordJS::processText(SWBuf &text, const SWKey *key, const SWModule *modu char token[2112]; // cheese. Fix. int tokpos = 0; bool intoken = false; - bool lastspace = false; int word = 1; char val[128]; char *valto; @@ -69,7 +74,7 @@ char ThMLWordJS::processText(SWBuf &text, const SWKey *key, const SWModule *modu bool newText = false; bool needWordOut = false; AttributeValue *wordAttrs = 0; - SWBuf modName = (module)?module->Name():""; + SWBuf modName = (module)?module->getName():""; SWBuf wordSrcPrefix = modName; const SWBuf orig = text; @@ -160,7 +165,7 @@ char ThMLWordJS::processText(SWBuf &text, const SWKey *key, const SWModule *modu gh = isdigit(strong[0]) ? 0:strong[0]; if (!gh) { if (vkey) { - gh = vkey->Testament() ? 'H' : 'G'; + gh = vkey->getTestament() ? 'H' : 'G'; } } else strong << 1; @@ -179,7 +184,7 @@ char ThMLWordJS::processText(SWBuf &text, const SWKey *key, const SWModule *modu if (sLex) { // we can pass the real lex name in, but we have some // aliases in the javascript to optimize bandwidth - lexName = sLex->Name(); + lexName = sLex->getName(); if (lexName == "StrongsGreek") lexName = "G"; if (lexName == "StrongsHebrew") @@ -188,7 +193,7 @@ char ThMLWordJS::processText(SWBuf &text, const SWKey *key, const SWModule *modu SWBuf wordID; if (vkey) { // optimize for bandwidth and use only the verse as the unique entry id - wordID.appendFormatted("%d", vkey->Verse()); + wordID.appendFormatted("%d", vkey->getVerse()); } else { wordID = key->getText(); @@ -206,10 +211,11 @@ char ThMLWordJS::processText(SWBuf &text, const SWKey *key, const SWModule *modu + if (!sMorph) sMorph = 0; // avoid unused warnings for now /* if (sMorph) { SWBuf popMorph = "<a onclick=\""; - popMorph.appendFormatted("p(\'%s\',\'%s\','%s','');\" >%s</a>", sMorph->Name(), morph.c_str(), wordID.c_str(), morph.c_str()); + popMorph.appendFormatted("p(\'%s\',\'%s\','%s','');\" >%s</a>", sMorph->getName(), morph.c_str(), wordID.c_str(), morph.c_str()); morph = popMorph; } */ @@ -237,7 +243,6 @@ char ThMLWordJS::processText(SWBuf &text, const SWKey *key, const SWModule *modu } else { text += *from; - lastspace = (*from == ' '); } } @@ -255,7 +260,7 @@ char ThMLWordJS::processText(SWBuf &text, const SWKey *key, const SWModule *modu gh = isdigit(strong[0]) ? 0:strong[0]; if (!gh) { if (vkey) { - gh = vkey->Testament() ? 'H' : 'G'; + gh = vkey->getTestament() ? 'H' : 'G'; } } else strong << 1; @@ -271,7 +276,7 @@ char ThMLWordJS::processText(SWBuf &text, const SWKey *key, const SWModule *modu if (sLex) { // we can pass the real lex name in, but we have some // aliases in the javascript to optimize bandwidth - lexName = sLex->Name(); + lexName = sLex->getName(); if (lexName == "StrongsGreek") lexName = "G"; if (lexName == "StrongsHebrew") @@ -280,7 +285,7 @@ char ThMLWordJS::processText(SWBuf &text, const SWKey *key, const SWModule *modu SWBuf wordID; if (vkey) { // optimize for bandwidth and use only the verse as the unique entry id - wordID.appendFormatted("%d", vkey->Verse()); + wordID.appendFormatted("%d", vkey->getVerse()); } else { wordID = key->getText(); diff --git a/src/modules/filters/thmlxhtml.cpp b/src/modules/filters/thmlxhtml.cpp new file mode 100644 index 0000000..b17eb50 --- /dev/null +++ b/src/modules/filters/thmlxhtml.cpp @@ -0,0 +1,378 @@ +/****************************************************************************** + * + * thmlxhtml.cpp - ThML to classed XHTML + * + * $Id: thmlxhtml.cpp 2980 2013-09-14 21:51:47Z scribe $ + * + * Copyright 2011-2013 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 <stdlib.h> +#include <thmlxhtml.h> +#include <swmodule.h> +#include <utilxml.h> +#include <utilstr.h> +#include <versekey.h> +#include <url.h> + +SWORD_NAMESPACE_START + + +const char *ThMLXHTML::getHeader() const { + return "\ + "; +} + + +ThMLXHTML::MyUserData::MyUserData(const SWModule *module, const SWKey *key) : BasicFilterUserData(module, key) { + if (module) { + version = module->getName(); + BiblicalText = (!strcmp(module->getType(), "Biblical Texts")); + SecHead = false; + } +} + + +ThMLXHTML::ThMLXHTML() { + setTokenStart("<"); + setTokenEnd(">"); + + setEscapeStart("&"); + setEscapeEnd(";"); + + setEscapeStringCaseSensitive(true); + setPassThruNumericEscapeString(true); + + addAllowedEscapeString("quot"); + addAllowedEscapeString("amp"); + addAllowedEscapeString("lt"); + addAllowedEscapeString("gt"); + + addAllowedEscapeString("nbsp"); + addAllowedEscapeString("brvbar"); // "Š" + addAllowedEscapeString("sect"); // "§" + addAllowedEscapeString("copy"); // "©" + addAllowedEscapeString("laquo"); // "«" + addAllowedEscapeString("reg"); // "®" + addAllowedEscapeString("acute"); // "Ž" + addAllowedEscapeString("para"); // "¶" + addAllowedEscapeString("raquo"); // "»" + + addAllowedEscapeString("Aacute"); // "Á" + addAllowedEscapeString("Agrave"); // "À" + addAllowedEscapeString("Acirc"); // "Â" + addAllowedEscapeString("Auml"); // "Ä" + addAllowedEscapeString("Atilde"); // "Ã" + addAllowedEscapeString("Aring"); // "Å" + addAllowedEscapeString("aacute"); // "á" + addAllowedEscapeString("agrave"); // "à" + addAllowedEscapeString("acirc"); // "â" + addAllowedEscapeString("auml"); // "ä" + addAllowedEscapeString("atilde"); // "ã" + addAllowedEscapeString("aring"); // "å" + addAllowedEscapeString("Eacute"); // "É" + addAllowedEscapeString("Egrave"); // "È" + addAllowedEscapeString("Ecirc"); // "Ê" + addAllowedEscapeString("Euml"); // "Ë" + addAllowedEscapeString("eacute"); // "é" + addAllowedEscapeString("egrave"); // "è" + addAllowedEscapeString("ecirc"); // "ê" + addAllowedEscapeString("euml"); // "ë" + addAllowedEscapeString("Iacute"); // "Í" + addAllowedEscapeString("Igrave"); // "Ì" + addAllowedEscapeString("Icirc"); // "Î" + addAllowedEscapeString("Iuml"); // "Ï" + addAllowedEscapeString("iacute"); // "í" + addAllowedEscapeString("igrave"); // "ì" + addAllowedEscapeString("icirc"); // "î" + addAllowedEscapeString("iuml"); // "ï" + addAllowedEscapeString("Oacute"); // "Ó" + addAllowedEscapeString("Ograve"); // "Ò" + addAllowedEscapeString("Ocirc"); // "Ô" + addAllowedEscapeString("Ouml"); // "Ö" + addAllowedEscapeString("Otilde"); // "Õ" + addAllowedEscapeString("oacute"); // "ó" + addAllowedEscapeString("ograve"); // "ò" + addAllowedEscapeString("ocirc"); // "ô" + addAllowedEscapeString("ouml"); // "ö" + addAllowedEscapeString("otilde"); // "õ" + addAllowedEscapeString("Uacute"); // "Ú" + addAllowedEscapeString("Ugrave"); // "Ù" + addAllowedEscapeString("Ucirc"); // "Û" + addAllowedEscapeString("Uuml"); // "Ü" + addAllowedEscapeString("uacute"); // "ú" + addAllowedEscapeString("ugrave"); // "ù" + addAllowedEscapeString("ucirc"); // "û" + addAllowedEscapeString("uuml"); // "ü" + addAllowedEscapeString("Yacute"); // "Ý" + addAllowedEscapeString("yacute"); // "ý" + addAllowedEscapeString("yuml"); // "ÿ" + + addAllowedEscapeString("deg"); // "°" + addAllowedEscapeString("plusmn"); // "±" + addAllowedEscapeString("sup2"); // "²" + addAllowedEscapeString("sup3"); // "³" + addAllowedEscapeString("sup1"); // "¹" + addAllowedEscapeString("nbsp"); // "º" + addAllowedEscapeString("pound"); // "£" + addAllowedEscapeString("cent"); // "¢" + addAllowedEscapeString("frac14"); // "Œ" + addAllowedEscapeString("frac12"); // "œ" + addAllowedEscapeString("frac34"); // "Ÿ" + addAllowedEscapeString("iquest"); // "¿" + addAllowedEscapeString("iexcl"); // "¡" + addAllowedEscapeString("ETH"); // "Ð" + addAllowedEscapeString("eth"); // "ð" + addAllowedEscapeString("THORN"); // "Þ" + addAllowedEscapeString("thorn"); // "þ" + addAllowedEscapeString("AElig"); // "Æ" + addAllowedEscapeString("aelig"); // "æ" + addAllowedEscapeString("Oslash"); // "Ø" + addAllowedEscapeString("curren"); // "€" + addAllowedEscapeString("Ccedil"); // "Ç" + addAllowedEscapeString("ccedil"); // "ç" + addAllowedEscapeString("szlig"); // "ß" + addAllowedEscapeString("Ntilde"); // "Ñ" + addAllowedEscapeString("ntilde"); // "ñ" + addAllowedEscapeString("yen"); // "¥" + addAllowedEscapeString("not"); // "¬" + addAllowedEscapeString("ordf"); // "ª" + addAllowedEscapeString("uml"); // "š" + addAllowedEscapeString("shy"); // "­" + addAllowedEscapeString("macr"); // "¯" + + addAllowedEscapeString("micro"); // "µ" + addAllowedEscapeString("middot"); // "·" + addAllowedEscapeString("cedil"); // "ž" + addAllowedEscapeString("ordm"); // "º" + addAllowedEscapeString("times"); // "×" + addAllowedEscapeString("divide"); // "÷" + addAllowedEscapeString("oslash"); // "ø" + + setTokenCaseSensitive(true); +// addTokenSubstitute("scripture", "<i> "); + addTokenSubstitute("/scripture", "</i> "); + + renderNoteNumbers = false; +} + + +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 ? URL::encode(noteName.c_str()).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 ? URL::encode(noteName.c_str()).c_str() : "")); + } + u->suspendTextPassThru = true; + } + } + if (tag.isEndTag()) { + u->suspendTextPassThru = false; + } + } + else if (!strcmp(tag.getName(), "scripture")) { + buf += (tag.isEndTag() ? "</i>" : "<i>"); + } + // <scripRef> tag + else if (!strcmp(tag.getName(), "scripRef")) { + if (!tag.isEndTag()) { + if (!tag.isEmpty()) { + u->suspendTextPassThru = true; + } + } + if (tag.isEndTag()) { // </scripRef> + if (!u->BiblicalText) { + SWBuf refList = u->startTag.getAttribute("passage"); + if (!refList.length()) + refList = u->lastTextNode; + SWBuf version = tag.getAttribute("version"); + + buf.appendFormatted("<a href=\"passagestudy.jsp?action=showRef&type=scripRef&value=%s&module=%s\">", + (refList.length()) ? URL::encode(refList.c_str()).c_str() : "", + (version.length()) ? URL::encode(version.c_str()).c_str() : ""); + buf += u->lastTextNode.c_str(); + buf += "</a>"; + } + else { + SWBuf footnoteNumber = u->startTag.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. + //buf.appendFormatted("<a href=\"noteID=%s.x.%s\"><small><sup>*x</sup></small></a> ", vkey->getText(), footnoteNumber.c_str()); + buf.appendFormatted("<a href=\"passagestudy.jsp?action=showNote&type=x&value=%s&module=%s&passage=%s\"><small><sup class=\"x\">*x%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() : "")); + } + } + + // let's let text resume to output again + u->suspendTextPassThru = false; + } + } + else if (tag.getName() && !strcmp(tag.getName(), "div")) { + if (tag.isEndTag() && u->SecHead) { + buf += "</i></b><br />"; + u->SecHead = false; + } + else if (tag.getAttribute("class")) { + if (!stricmp(tag.getAttribute("class"), "sechead")) { + u->SecHead = true; + buf += "<br /><b><i>"; + } + else if (!stricmp(tag.getAttribute("class"), "title")) { + u->SecHead = true; + buf += "<br /><b><i>"; + } + else { + buf += tag; + } + } + else { + buf += tag; + } + } + else if (tag.getName() && (!strcmp(tag.getName(), "img") || !strcmp(tag.getName(), "image"))) { + const char *src = strstr(token, "src"); + if (!src) // assert we have a src attribute + return false; + + const char *c, *d; + if (((c = strchr(src+3, '"')) == NULL) || + ((d = strchr( ++c , '"')) == NULL)) // identify endpoints. + return false; // abandon hope. + + SWBuf imagename = "file:"; + if (*c == '/') // as below, inside for loop. + imagename += userData->module->getConfigEntry("AbsoluteDataPath"); + while (c != d) // move bits into the name. + imagename += *(c++); + + // images become clickable, if the UI supports showImage. + buf.appendFormatted("<a href=\"passagestudy.jsp?action=showImage&value=%s&module=%s\"><", + URL::encode(imagename.c_str()).c_str(), + URL::encode(u->version.c_str()).c_str()); + + for (c = token; *c; c++) { + if ((*c == '/') && (*(c+1) == '\0')) + continue; + if (c == src) { + for (;((*c) && (*c != '"')); c++) + buf += *c; + + if (!*c) { c--; continue; } + + buf += '"'; + if (*(c+1) == '/') { + buf += "file:"; + buf += userData->module->getConfigEntry("AbsoluteDataPath"); + if (buf[buf.length()-2] == '/') + c++; // skip '/' + } + continue; + } + buf += *c; + } + buf += " border=0 /></a>"; + } + else { + buf += '<'; + /*for (const char *tok = token; *tok; tok++) + buf += *tok;*/ + buf += token; + buf += '>'; + //return false; // we still didn't handle token + } + } + return true; +} + + +SWORD_NAMESPACE_END diff --git a/src/modules/filters/unicodertf.cpp b/src/modules/filters/unicodertf.cpp index 768aecc..997597b 100644 --- a/src/modules/filters/unicodertf.cpp +++ b/src/modules/filters/unicodertf.cpp @@ -1,10 +1,10 @@ /****************************************************************************** * - * unicodertf - SWFilter descendant to convert a double byte unicode file - * to RTF tags + * unicodertf.cpp - SWFilter descendant to convert UTF-8 to RTF tags * + * $Id: unicodertf.cpp 2833 2013-06-29 06:40:28Z chrislit $ * - * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * Copyright 2001-2013 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society * P. O. Box 2528 * Tempe, AZ 85280-2528 diff --git a/src/modules/filters/utf16utf8.cpp b/src/modules/filters/utf16utf8.cpp index a488e18..6356284 100644 --- a/src/modules/filters/utf16utf8.cpp +++ b/src/modules/filters/utf16utf8.cpp @@ -1,10 +1,10 @@ /****************************************************************************** * - * UTF16UTF8 - SWFilter descendant to convert UTF-16 to UTF-8 + * utf16utf8.cpp - SWFilter descendant to convert UTF-16 to UTF-8 * + * $Id: utf16utf8.cpp 2980 2013-09-14 21:51:47Z scribe $ * - * - * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * Copyright 2001-2013 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society * P. O. Box 2528 * Tempe, AZ 85280-2528 @@ -27,8 +27,10 @@ #include <utf16utf8.h> #include <swbuf.h> + SWORD_NAMESPACE_START + UTF16UTF8::UTF16UTF8() { } @@ -102,6 +104,4 @@ char UTF16UTF8::processText(SWBuf &text, const SWKey *key, const SWModule *modul } - - SWORD_NAMESPACE_END diff --git a/src/modules/filters/utf8arabicpoints.cpp b/src/modules/filters/utf8arabicpoints.cpp index bd3169b..42bfaa5 100644 --- a/src/modules/filters/utf8arabicpoints.cpp +++ b/src/modules/filters/utf8arabicpoints.cpp @@ -1,10 +1,11 @@ /****************************************************************************** * - * UTF8ArabicPoints - SWFilter descendant to remove UTF-8 Arabic vowel points + * utf8arabicpoints.cpp - SWFilter descendant to remove UTF-8 + * Arabic vowel points * - * $Id: utf8arabicpoints.h 1688 2008-11-30 04:42:26Z refdoc $ + * $Id: utf8arabicpoints.cpp 2980 2013-09-14 21:51:47Z scribe $ * - * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * Copyright 2009-2013 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society * P. O. Box 2528 * Tempe, AZ 85280-2528 @@ -25,36 +26,163 @@ #include <stdio.h> #include <utf8arabicpoints.h> + SWORD_NAMESPACE_START -const char oName[] = "Arabic Vowel Points"; -const char oTip[] = "Toggles Arabic Vowel Points"; +namespace { + + static const char oName[] = "Arabic Vowel Points"; + static const char oTip[] = "Toggles Arabic Vowel Points"; + + static const StringList *oValues() { + static const SWBuf choices[3] = {"On", "Off", ""}; + static const StringList oVals(&choices[0], &choices[2]); + return &oVals; + } + + + static char *nextMark(const char* from, int* mark_size) { + // Arabic vowel points currently targeted for elimination: + // Table entries excerpted from + // http://www.utf8-chartable.de/unicode-utf8-table.pl. + // Code UTF-8 Description + // point + // ----- --------- ----------- + // U+064B d9 8b ARABIC FATHATAN + // U+064C d9 8c ARABIC DAMMATAN + // U+064D d9 8d ARABIC KASRATAN + // U+064E d9 8e ARABIC FATHA + // U+064F d9 8f ARABIC DAMMA + // U+0650 d9 90 ARABIC KASRA + // U+0651 d9 91 ARABIC SHADDA + // U+0652 d9 92 ARABIC SUKUN + // U+0653 d9 93 ARABIC MADDAH ABOVE + // U+0654 d9 94 ARABIC HAMZA ABOVE + // U+0655 d9 95 ARABIC HAMZA BELOW + // + // U+FC5E ef b1 9e ARABIC LIGATURE SHADDA WITH DAMMATAN ISOLATED FORM + // U+FC5F ef b1 9f ARABIC LIGATURE SHADDA WITH KASRATAN ISOLATED FORM + // U+FC60 ef b1 a0 ARABIC LIGATURE SHADDA WITH FATHA ISOLATED FORM + // U+FC61 ef b1 a1 ARABIC LIGATURE SHADDA WITH DAMMA ISOLATED FORM + // U+FC62 ef b1 a2 ARABIC LIGATURE SHADDA WITH KASRA ISOLATED FORM + // U+FC63 ef b1 a3 ARABIC LIGATURE SHADDA WITH SUPERSCRIPT ALEF ISOLATED FORM + // + // U+FE70 ef b9 b0 ARABIC FATHATAN ISOLATED FORM + // U+FE71 ef b9 b1 ARABIC TATWEEL WITH FATHATAN ABOVE + // U+FE72 ef b9 b2 ARABIC DAMMATAN ISOLATED FORM + // U+FE73 ef b9 b3 ARABIC TAIL FRAGMENT + // U+FE74 ef b9 b4 ARABIC KASRATAN ISOLATED FORM + // U+FE75 ef b9 b5 ??? + // U+FE76 ef b9 b6 ARABIC FATHA ISOLATED FORM + // U+FE77 ef b9 b7 ARABIC FATHA MEDIAL FORM + // U+FE78 ef b9 b8 ARABIC DAMMA ISOLATED FORM + // U+FE79 ef b9 b9 ARABIC DAMMA MEDIAL FORM + // U+FE7A ef b9 ba ARABIC KASRA ISOLATED FORM + // U+FE7B ef b9 bb ARABIC KASRA MEDIAL FORM + // U+FE7C ef b9 bc ARABIC SHADDA ISOLATED FORM + // U+FE7D ef b9 bd ARABIC SHADDA MEDIAL FORM + // U+FE7E ef b9 be ARABIC SUKUN ISOLATED FORM + // U+FE7F ef b9 bf ARABIC SUKUN MEDIAL FORM + + unsigned char* byte = (unsigned char*) from; + for (; *byte; ++byte) { + if (byte[0] == 0xD9) { + if (byte[1] >= 0x8B && byte[1] <= 0x95) { + *mark_size = 2; + break; + } + continue; + } + if (byte[0] == 0xEF) { + if (byte[1] == 0xB1) { + if (byte[2] >= 0x9E && byte[2] <= 0xA3) { + *mark_size = 3; + break; + } + continue; + } + if (byte[1] == 0xB9) { + if (byte[2] >= 0xB0 && byte[2] <= 0xBF) { + *mark_size = 3; + break; + } + continue; + } + } + } + return (char*)byte; + } +} -const SWBuf choices[3] = {"On", "Off", ""}; -const StringList oValues(&choices[0], &choices[2]); -UTF8ArabicPoints::UTF8ArabicPoints() : SWOptionFilter(oName, oTip, &oValues) { - setOptionValue("On"); +UTF8ArabicPoints::UTF8ArabicPoints() : SWOptionFilter(oName, oTip, oValues()) { } + UTF8ArabicPoints::~UTF8ArabicPoints(){}; -char UTF8ArabicPoints::processText(SWBuf &text, const SWKey *key, const SWModule *module) { - if (!option) { - //The UTF-8 range 0xFC 0xE5 to 0xFC 0x63 consist of Arabic vowel marks so block those out. - // Also ranges 0xFE70 til OxFE7F and 0x064b-0x0655 - SWBuf orig = text; - const unsigned char* from = (unsigned char*)orig.c_str(); - for (text = ""; *from; from++) { - if (((*from == 0xFC) && (*(from + 1) >= 0xE5 && *(from + 1) <= 0x63)) || ((*from == 0xFE) && (*(from + 1) >= 0x70 && *(from + 1) <= 0x7F)) || ((*from == 0x06) && (*(from + 1) >= 0x4B && *(from + 1) <= 0x55))){ - from++; - } - else { - text += *from; - } + +char UTF8ArabicPoints::processText(SWBuf &text, const SWKey *, const SWModule *) { + // A non-zero/true option setting means that setOptionValue("On") + // was called which apparently means that Arabic Vowel Marks are ENABLED, + // so the filter's actions are DISABLED. + if (option) + return 0; + + // Eliminate Arabic vowel marks from the text. + // The recognized marks are determined by the "nextMark" function. + + // If nextMark were polymorphic (a virtual function or a function + // pointer), this function could be generically used in any filter that + // only removed (vs. replaced) areas of text based on the arbitrary + // match criteria encapsulated in the specific nextMark + // implementation. + int mark_size = 0; + char* mark_pos = nextMark(text.c_str(), &mark_size); + + // Here and at the end of the loop, + // test BOTH mark_pos AND *mark_pos for safety and to give nextMark + // the option of returning either NULL or a pointer to the null + // terminator when done. + if (!mark_pos || !*mark_pos) + return 0; // no marks found. + + // Purposely granting write access into SWBuf internal buffer via + // "end_of_output" avoids a needless temporary SWBuf copy. + // Everything before the first mark is already in its final position + // and can be safely ignored. So start appending at the current mark. + char* end_of_output = mark_pos; + + // For consistency, input starts at (vs. after) the first mark as well + // -- not a problem since the mark itself gets skipped, anyway. + const char* start_of_input = mark_pos; + do { + // At this point, "mark_pos" and "mark_pos+mark_size" delimit + // the text to drop. + // "start_of_input" is either mark_pos or any text between the + // end of any previous mark and the current mark_pos. + // This text is now ready to be moved into the output. + int ready_size = mark_pos - start_of_input; + if (ready_size > 0) { + // Append the input text before the current mark to the + // output. + // Must use bcopy vs. strncpy because the final + // end_of_output may overtake the original + // start_of_input. + memmove(end_of_output, start_of_input, ready_size); + // Keep appending to end_of_output. + end_of_output += ready_size; } - } + // Ensure the mark never gets copied. + start_of_input = mark_pos + mark_size; + // Find the next mark. + mark_pos = nextMark(start_of_input, &mark_size); + + } while (mark_pos && *mark_pos); // No more marks. + + // Copy any trailing input text AND always the terminating null. + memmove(end_of_output, start_of_input, strlen(start_of_input)+1); return 0; } diff --git a/src/modules/filters/utf8arshaping.cpp b/src/modules/filters/utf8arshaping.cpp index 09d8973..04dea2d 100644 --- a/src/modules/filters/utf8arshaping.cpp +++ b/src/modules/filters/utf8arshaping.cpp @@ -1,10 +1,11 @@ /****************************************************************************** * - * utf8arshaping - SWFilter descendant to perform Arabic shaping on - * UTF-8 text + * utf8arshaping.cpp - SWFilter descendant to perform Arabic shaping on + * UTF-8 text * + * $Id: utf8arshaping.cpp 2931 2013-07-31 13:07:26Z scribe $ * - * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * Copyright 2001-2013 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society * P. O. Box 2528 * Tempe, AZ 85280-2528 @@ -31,7 +32,7 @@ SWORD_NAMESPACE_START -UTF8arShaping::UTF8arShaping() { +UTF8arShaping::UTF8arShaping() : err(U_ZERO_ERROR) { conv = ucnv_open("UTF-8", &err); } diff --git a/src/modules/filters/utf8bidireorder.cpp b/src/modules/filters/utf8bidireorder.cpp index 71dc804..b945a5b 100644 --- a/src/modules/filters/utf8bidireorder.cpp +++ b/src/modules/filters/utf8bidireorder.cpp @@ -1,10 +1,12 @@ /****************************************************************************** * - * utf8bidireorder - SWFilter descendant to perform reordering of UTF-8 - * text to visual order according to Unicode BiDi + * utf8bidireorder.cpp - SWFilter descendant to perform reordering of + * UTF-8 text to visual order according to the + * Unicode Bidirectional Algorithm (UBA) * + * $Id: utf8bidireorder.cpp 2980 2013-09-14 21:51:47Z scribe $ * - * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * Copyright 2001-2013 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society * P. O. Box 2528 * Tempe, AZ 85280-2528 @@ -29,18 +31,22 @@ #include <utf8bidireorder.h> #include <swbuf.h> + SWORD_NAMESPACE_START -UTF8BiDiReorder::UTF8BiDiReorder() { + +UTF8BiDiReorder::UTF8BiDiReorder() : err(U_ZERO_ERROR) { conv = ucnv_open("UTF-8", &err); } + UTF8BiDiReorder::~UTF8BiDiReorder() { ucnv_close(conv); } + char UTF8BiDiReorder::processText(SWBuf &text, const SWKey *key, const SWModule *module) { UChar *ustr, *ustr2; @@ -72,5 +78,6 @@ char UTF8BiDiReorder::processText(SWBuf &text, const SWKey *key, const SWModule return 0; } + SWORD_NAMESPACE_END #endif diff --git a/src/modules/filters/utf8cantillation.cpp b/src/modules/filters/utf8cantillation.cpp index 73785b4..91ca58a 100644 --- a/src/modules/filters/utf8cantillation.cpp +++ b/src/modules/filters/utf8cantillation.cpp @@ -1,10 +1,11 @@ /****************************************************************************** * - * UTF8Cantillation - SWFilter descendant to remove UTF-8 Hebrew cantillation + * utf8cantillation.cpp - SWFilter descendant to remove UTF-8 Hebrew + * cantillation * + * $Id: utf8cantillation.cpp 2980 2013-09-14 21:51:47Z scribe $ * - * - * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * Copyright 2001-2013 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society * P. O. Box 2528 * Tempe, AZ 85280-2528 @@ -24,16 +25,23 @@ #include <stdio.h> #include <utf8cantillation.h> + SWORD_NAMESPACE_START -const char oName[] = "Hebrew Cantillation"; -const char oTip[] = "Toggles Hebrew Cantillation Marks"; +namespace { + + static const char oName[] = "Hebrew Cantillation"; + static const char oTip[] = "Toggles Hebrew Cantillation Marks"; + + static const StringList *oValues() { + static const SWBuf choices[3] = {"Off", "On", ""}; + static const StringList oVals(&choices[0], &choices[2]); + return &oVals; + } +} -const SWBuf choices[3] = {"On", "Off", ""}; -const StringList oValues(&choices[0], &choices[2]); -UTF8Cantillation::UTF8Cantillation() : SWOptionFilter(oName, oTip, &oValues) { - setOptionValue("Off"); +UTF8Cantillation::UTF8Cantillation() : SWOptionFilter(oName, oTip, oValues()) { } diff --git a/src/modules/filters/utf8greekaccents.cpp b/src/modules/filters/utf8greekaccents.cpp index 5fdb047..039f9a4 100644 --- a/src/modules/filters/utf8greekaccents.cpp +++ b/src/modules/filters/utf8greekaccents.cpp @@ -1,10 +1,11 @@ /****************************************************************************** * - * UTF8GreekAccents - SWFilter descendant to remove UTF-8 Greek accents + * utf8greekaccents.cpp - SWFilter descendant to remove UTF-8 Greek + * accents * + * $Id: utf8greekaccents.cpp 2980 2013-09-14 21:51:47Z scribe $ * - * - * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * Copyright 2001-2013 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society * P. O. Box 2528 * Tempe, AZ 85280-2528 @@ -30,19 +31,27 @@ sword::UTF8NFKD decompose; #endif + SWORD_NAMESPACE_START -const char oName[] = "Greek Accents"; -const char oTip[] = "Toggles Greek Accents"; +namespace { -const SWBuf choices[3] = {"On", "Off", ""}; -const StringList oValues(&choices[0], &choices[2]); + static const char oName[] = "Greek Accents"; + static const char oTip[] = "Toggles Greek Accents"; -UTF8GreekAccents::UTF8GreekAccents() : SWOptionFilter(oName, oTip, &oValues) { - setOptionValue("On"); + static const StringList *oValues() { + static const SWBuf choices[3] = {"On", "Off", ""}; + static const StringList oVals(&choices[0], &choices[2]); + return &oVals; + } } -UTF8GreekAccents::~UTF8GreekAccents(){}; + +UTF8GreekAccents::UTF8GreekAccents() : SWOptionFilter(oName, oTip, oValues()) { +} + + +UTF8GreekAccents::~UTF8GreekAccents() {}; char UTF8GreekAccents::processText(SWBuf &text, const SWKey *key, const SWModule *module) { diff --git a/src/modules/filters/utf8hebrewpoints.cpp b/src/modules/filters/utf8hebrewpoints.cpp index ba7c746..ff53e4f 100644 --- a/src/modules/filters/utf8hebrewpoints.cpp +++ b/src/modules/filters/utf8hebrewpoints.cpp @@ -1,10 +1,11 @@ /****************************************************************************** * - * UTF8HebrewPoints - SWFilter descendant to remove UTF-8 Hebrew vowel points + * utf8hebrewpoints.cpp - SWFilter descendant to remove UTF-8 Hebrew + * vowel points * + * $Id: utf8hebrewpoints.cpp 2980 2013-09-14 21:51:47Z scribe $ * - * - * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * Copyright 2001-2013 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society * P. O. Box 2528 * Tempe, AZ 85280-2528 @@ -24,24 +25,32 @@ #include <stdio.h> #include <utf8hebrewpoints.h> + SWORD_NAMESPACE_START -const char oName[] = "Hebrew Vowel Points"; -const char oTip[] = "Toggles Hebrew Vowel Points"; +namespace { -const SWBuf choices[3] = {"On", "Off", ""}; -const StringList oValues(&choices[0], &choices[2]); + static const char oName[] = "Hebrew Vowel Points"; + static const char oTip[] = "Toggles Hebrew Vowel Points"; -UTF8HebrewPoints::UTF8HebrewPoints() : SWOptionFilter(oName, oTip, &oValues) { - setOptionValue("On"); + static const StringList *oValues() { + static const SWBuf choices[3] = {"On", "Off", ""}; + static const StringList oVals(&choices[0], &choices[2]); + return &oVals; + } } + +UTF8HebrewPoints::UTF8HebrewPoints() : SWOptionFilter(oName, oTip, oValues()) { +} + + UTF8HebrewPoints::~UTF8HebrewPoints(){}; char UTF8HebrewPoints::processText(SWBuf &text, const SWKey *key, const SWModule *module) { if (!option) { - //The UTF-8 range 0xD6 0xB0 to 0xD6 0xBF excluding 0xD6 0x consist of Hebrew cantillation marks so block those out. + //The UTF-8 range 0xD6 0xB0 to 0xD6 0xBF excluding 0xD6 0xBE consist of Hebrew cantillation marks so block those out. SWBuf orig = text; const unsigned char* from = (unsigned char*)orig.c_str(); for (text = ""; *from; from++) { @@ -56,4 +65,5 @@ char UTF8HebrewPoints::processText(SWBuf &text, const SWKey *key, const SWModule return 0; } + SWORD_NAMESPACE_END diff --git a/src/modules/filters/utf8html.cpp b/src/modules/filters/utf8html.cpp index 0d1dce3..1f05ac7 100644 --- a/src/modules/filters/utf8html.cpp +++ b/src/modules/filters/utf8html.cpp @@ -1,10 +1,11 @@ /****************************************************************************** * - * utf8html - SWFilter descendant to convert a UTF-8 stream to HTML escapes + * utf8html.cpp - SWFilter descendant to convert a UTF-8 stream to + * HTML escapes * + * $Id: utf8html.cpp 2980 2013-09-14 21:51:47Z scribe $ * - * - * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * Copyright 2001-2013 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society * P. O. Box 2528 * Tempe, AZ 85280-2528 @@ -25,8 +26,10 @@ #include <utf8html.h> #include <swbuf.h> + SWORD_NAMESPACE_START + UTF8HTML::UTF8HTML() { } @@ -34,14 +37,11 @@ UTF8HTML::UTF8HTML() { char UTF8HTML::processText(SWBuf &text, const SWKey *key, const SWModule *module) { unsigned char *from; - int len; char digit[10]; unsigned long ch; if ((unsigned long)key < 2) // hack, we're en(1)/de(0)ciphering return (char)-1; - len = strlen(text.c_str()) + 2; // shift string to right of buffer - SWBuf orig = text; from = (unsigned char *)orig.c_str(); @@ -82,4 +82,6 @@ char UTF8HTML::processText(SWBuf &text, const SWKey *key, const SWModule *module return 0; } + SWORD_NAMESPACE_END + diff --git a/src/modules/filters/utf8latin1.cpp b/src/modules/filters/utf8latin1.cpp index 25df0c1..1bf8d3b 100644 --- a/src/modules/filters/utf8latin1.cpp +++ b/src/modules/filters/utf8latin1.cpp @@ -1,10 +1,10 @@ /****************************************************************************** * - * UTF8Latin1 - SWFilter descendant to convert UTF-8 to Latin-1 + * utf8latin1.cpp - SWFilter descendant to convert UTF-8 to Latin-1 * + * $Id: utf8latin1.cpp 2980 2013-09-14 21:51:47Z scribe $ * - * - * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * Copyright 2001-2013 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society * P. O. Box 2528 * Tempe, AZ 85280-2528 @@ -26,8 +26,10 @@ #include <utf8latin1.h> #include <swbuf.h> + SWORD_NAMESPACE_START + UTF8Latin1::UTF8Latin1(char rchar) : replacementChar(rchar) { } @@ -36,14 +38,12 @@ char UTF8Latin1::processText(SWBuf &text, const SWKey *key, const SWModule *modu { unsigned char *from; - int len; unsigned long uchar; unsigned char significantFirstBits, subsequent; if ((unsigned long)key < 2) {// hack, we're en(1)/de(0)ciphering return (char)-1; } - len = strlen(text.c_str()) + 1; // shift string to right of buffer SWBuf orig = text; from = (unsigned char*)orig.c_str(); @@ -87,5 +87,6 @@ char UTF8Latin1::processText(SWBuf &text, const SWKey *key, const SWModule *modu return 0; } + SWORD_NAMESPACE_END diff --git a/src/modules/filters/utf8nfc.cpp b/src/modules/filters/utf8nfc.cpp index 82d404e..49f12bb 100644 --- a/src/modules/filters/utf8nfc.cpp +++ b/src/modules/filters/utf8nfc.cpp @@ -1,10 +1,11 @@ /****************************************************************************** * - * utf8nfc - SWFilter descendant to perform NFC (canonical composition - * normalization) on UTF-8 text + * utf8nfc.cpp - SWFilter descendant to perform NFC (canonical + * composition normalization) on UTF-8 text * + * $Id: utf8nfc.cpp 2833 2013-06-29 06:40:28Z chrislit $ * - * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * Copyright 2001-2013 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society * P. O. Box 2528 * Tempe, AZ 85280-2528 diff --git a/src/modules/filters/utf8nfkd.cpp b/src/modules/filters/utf8nfkd.cpp index 1d6acf3..e4454d2 100644 --- a/src/modules/filters/utf8nfkd.cpp +++ b/src/modules/filters/utf8nfkd.cpp @@ -1,10 +1,11 @@ /****************************************************************************** * - * utf8nfkd - SWFilter descendant to perform NFKD (compatability decomposition - * normalization) on UTF-8 text + * utf8nfkd.cpp - SWFilter descendant to perform NFKD (compatability + * decomposition normalization) on UTF-8 text * + * $Id: utf8nfkd.cpp 2980 2013-09-14 21:51:47Z scribe $ * - * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * Copyright 2001-2013 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society * P. O. Box 2528 * Tempe, AZ 85280-2528 @@ -29,16 +30,20 @@ #include <utf8nfkd.h> #include <swbuf.h> + SWORD_NAMESPACE_START + UTF8NFKD::UTF8NFKD() { conv = ucnv_open("UTF-8", &err); } + UTF8NFKD::~UTF8NFKD() { ucnv_close(conv); } + char UTF8NFKD::processText(SWBuf &text, const SWKey *key, const SWModule *module) { if ((unsigned long)key < 2) // hack, we're en(1)/de(0)ciphering @@ -64,5 +69,6 @@ char UTF8NFKD::processText(SWBuf &text, const SWKey *key, const SWModule *module return 0; } + SWORD_NAMESPACE_END #endif diff --git a/src/modules/filters/utf8transliterator.cpp b/src/modules/filters/utf8transliterator.cpp index d6aafe2..b5b1902 100644 --- a/src/modules/filters/utf8transliterator.cpp +++ b/src/modules/filters/utf8transliterator.cpp @@ -1,10 +1,11 @@ /****************************************************************************** * - * utf8transliterators - SWFilter descendant to transliterate between - * ICU-supported scripts. + * utf8transliterator.cpp - SWFilter descendant to transliterate between + * ICU-supported scripts * + * $Id: utf8transliterator.cpp 2908 2013-07-17 22:44:29Z chrislit $ * - * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * Copyright 2001-2013 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society * P. O. Box 2528 * Tempe, AZ 85280-2528 @@ -41,54 +42,57 @@ SWORD_NAMESPACE_START const char UTF8Transliterator::optionstring[NUMTARGETSCRIPTS][16] = { "Off", "Latin", - // "IPA", - // "Basic Latin", - // "SBL", - // "TC", - // "Beta", - // "BGreek", - // "SERA", - // "Hugoye", - // "UNGEGN", - // "ISO", - // "ALA-LC", - // "BGN", - // "Greek", - // "Hebrew", - // "Cyrillic", - // "Arabic", - // "Syriac", - // "Katakana", - // "Hiragana", - // "Hangul", - // "Devanagari", - // "Tamil", - // "Bengali", - // "Gurmukhi", - // "Gujarati", - // "Oriya", - // "Telugu", - // "Kannada", - // "Malayalam", - // "Thai", - // "Georgian", - // "Armenian", - // "Ethiopic", - // "Gothic", - // "Ugaritic", - // "Coptic", - // "Linear B", - // "Cypriot", - // "Runic", - // "Ogham", - // "Thaana", - // "Glagolitic", - // "Cherokee", + /* + "IPA", + "Basic Latin", + "SBL", + "TC", + "Beta", + "BGreek", + "SERA", + "Hugoye", + "UNGEGN", + "ISO", + "ALA-LC", + "BGN", + "Greek", + "Hebrew", + "Cyrillic", + "Arabic", + "Syriac", + "Katakana", + "Hiragana", + "Hangul", + "Devanagari", + "Tamil", + "Bengali", + "Gurmukhi", + "Gujarati", + "Oriya", + "Telugu", + "Kannada", + "Malayalam", + "Thai", + "Georgian", + "Armenian", + "Ethiopic", + "Gothic", + "Ugaritic", + "Coptic", + "Linear B", + "Cypriot", + "Runic", + "Ogham", + "Thaana", + "Glagolitic", + "Cherokee", + */ }; const char UTF8Transliterator::optName[] = "Transliteration"; const char UTF8Transliterator::optTip[] = "Transliterates between scripts"; +#ifdef ICU_CUSTOM_RESOURCE_BUILDING SWTransMap UTF8Transliterator::transMap; #ifndef _ICUSWORD_ @@ -128,7 +132,7 @@ SWCharString::~SWCharString() { } #endif // _ICUSWORD_ - +#endif // ICU_CUSTOM_RESOURCE_BUILDING UTF8Transliterator::UTF8Transliterator() { option = 0; @@ -136,17 +140,19 @@ UTF8Transliterator::UTF8Transliterator() { for (i = 0; i < NUMTARGETSCRIPTS; i++) { options.push_back(optionstring[i]); } +#ifdef ICU_CUSTOM_RESOURCE_BUILDING #ifndef _ICUSWORD_ utf8status = U_ZERO_ERROR; Load(utf8status); #endif +#endif } UTF8Transliterator::~UTF8Transliterator() { } - +#ifdef ICU_CUSTOM_RESOURCE_BUILDING void UTF8Transliterator::Load(UErrorCode &status) { #ifndef _ICUSWORD_ @@ -299,23 +305,29 @@ bool UTF8Transliterator::checkTrans(const UnicodeString& ID, UErrorCode &status return true; #endif // _ICUSWORD_ } +#endif // ICU_CUSTOM_RESOURCE_BUILDING bool UTF8Transliterator::addTrans(const char* newTrans, SWBuf* transList) { +#ifdef ICU_CUSTOM_RESOURCE_BUILDING #ifdef _ICUSWORD_ - UErrorCode status; + UErrorCode status; if (checkTrans(UnicodeString(newTrans), status)) { #endif +#endif // ICU_CUSTOM_RESOURCE_BUILDING *transList += newTrans; - *transList += ";"; - return true; + *transList += ";"; + return true; +#ifdef ICU_CUSTOM_RESOURCE_BUILDING #ifdef _ICUSWORD_ - } - else { - return false; - } + } + else { + return false; + } #endif +#endif // ICU_CUSTOM_RESOURCE_BUILDING } + Transliterator * UTF8Transliterator::createTrans(const UnicodeString& ID, UTransDirection dir, UErrorCode &status ) { Transliterator *trans = Transliterator::createInstance(ID,UTRANS_FORWARD,status); @@ -450,7 +462,7 @@ char UTF8Transliterator::processText(SWBuf &text, const SWKey *key, const SWModu //Simple X to Latin transliterators if (scripts[SE_GREEK]) { - if (strnicmp (((SWModule*)module)->Lang(), "cop", 3)) { + if (strnicmp (((SWModule*)module)->getLanguage(), "cop", 3)) { if (option == SE_SBL) addTrans("Greek-Latin/SBL", &ID); else if (option == SE_TC) @@ -653,7 +665,7 @@ char UTF8Transliterator::processText(SWBuf &text, const SWKey *key, const SWModu } if (scripts[SE_HAN]) { - if (!strnicmp (((SWModule*)module)->Lang(), "ja", 2)) { + if (!strnicmp (((SWModule*)module)->getLanguage(), "ja", 2)) { addTrans("Kanji-Romaji", &ID); } else { diff --git a/src/modules/filters/utf8utf16.cpp b/src/modules/filters/utf8utf16.cpp index e5b96d7..be8ad4b 100644 --- a/src/modules/filters/utf8utf16.cpp +++ b/src/modules/filters/utf8utf16.cpp @@ -1,10 +1,10 @@ /****************************************************************************** * - * UTF8UTF16 - SWFilter descendant to convert UTF-8 to UTF-16 + * utf8utf16.cpp - SWFilter descendant to convert UTF-8 to UTF-16 * + * $Id: utf8utf16.cpp 2980 2013-09-14 21:51:47Z scribe $ * - * - * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * Copyright 2001-2013 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society * P. O. Box 2528 * Tempe, AZ 85280-2528 @@ -28,8 +28,10 @@ #include <utilstr.h> #include <swbuf.h> + SWORD_NAMESPACE_START + UTF8UTF16::UTF8UTF16() { } -- cgit v1.2.3