summaryrefslogtreecommitdiff
path: root/utilities/osis2mod.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'utilities/osis2mod.cpp')
-rw-r--r--utilities/osis2mod.cpp381
1 files changed, 189 insertions, 192 deletions
diff --git a/utilities/osis2mod.cpp b/utilities/osis2mod.cpp
index 473a90f..3dea0c4 100644
--- a/utilities/osis2mod.cpp
+++ b/utilities/osis2mod.cpp
@@ -50,9 +50,7 @@ using namespace sword;
using namespace std;
-// Turn debugging on and off
-//#define DEBUG
-int debug = 0;
+int debug = 0; // mask of debug flags
const int DEBUG_WRITE = 1; // writing to module
const int DEBUG_VERSE = 2; // verse start and end
const int DEBUG_QUOTE = 4; // quotes, especially Words of Christ (WOC)
@@ -232,11 +230,10 @@ void prepareSWVerseKey(SWBuf &buf) {
bool inRange = false;
while (*p) {
if (inRange) {
-#ifdef DEBUG
- if (debug & DEBUG_REF) {
- cout << "DEBUG(REF): Copy range marker:" << *p << endl;;
- }
-#endif
+ if (debug & DEBUG_REF) {
+ cout << "DEBUG(REF): Copy range marker:" << *p << endl;;
+ }
+
// Range markers are copied as is
*s++ = *p++;
}
@@ -252,7 +249,7 @@ void prepareSWVerseKey(SWBuf &buf) {
if (*n == ':') {
// set p to skip the work prefix
p = n + 1;
-#ifdef DEBUG
+
if (debug & DEBUG_REF) {
cout << "DEBUG(REF): Found a work prefix ";
for (char *x = s; x <= n; x++) {
@@ -260,29 +257,25 @@ void prepareSWVerseKey(SWBuf &buf) {
}
cout << endl;
}
-#endif
}
// Now we are in the meat of an osisID.
// Copy it to its end but stop on a grain marker of '!'
-#ifdef DEBUG
if (debug & DEBUG_REF) {
cout << "DEBUG(REF): Copy osisID:";
}
-#endif
+
while (*p && *p != '!' && *p != ' ' && *p != '-') {
-#ifdef DEBUG
if (debug & DEBUG_REF) {
cout << *p;
}
-#endif
+
*s++ = *p++;
}
-#ifdef DEBUG
+
if (debug & DEBUG_REF) {
cout << endl;
}
-#endif
// The ! and everything following until we hit
// the end of the osisID is part of the grain reference
@@ -291,7 +284,7 @@ void prepareSWVerseKey(SWBuf &buf) {
while (*n && *n != ' ' && *n != '-') {
n++;
}
-#ifdef DEBUG
+
if (debug & DEBUG_REF) {
cout << "DEBUG(REF): Found a grain suffix ";
for (char *x = p; x < n; x++) {
@@ -299,7 +292,7 @@ void prepareSWVerseKey(SWBuf &buf) {
}
cout << endl;
}
-#endif
+
p = n;
}
@@ -309,13 +302,11 @@ void prepareSWVerseKey(SWBuf &buf) {
// then we are entering a range
inRange = !inRange && *p == '-';
-#ifdef DEBUG
if (debug & DEBUG_REF) {
if (inRange) {
cout << "DEBUG(REF): Found a range" << endl;
}
}
-#endif
// between ranges and stand alone osisIDs we might have whitespace
if (!inRange && *p == ' ') {
@@ -323,13 +314,13 @@ void prepareSWVerseKey(SWBuf &buf) {
while (*p == ' ') {
p++;
}
+
// replacing them all with a ';'
*s++ = ';';
-#ifdef DEBUG
+
if (debug & DEBUG_REF) {
cout << "DEBUG(REF): replacing space with ;. Remaining: " << p << endl;
}
-#endif
}
}
@@ -340,11 +331,10 @@ void prepareSWVerseKey(SWBuf &buf) {
*s = '\0';
// Since we modified the swbuf, we need to tell it what we have done
buf.setSize(s - buf.c_str());
-#ifdef DEBUG
+
if (debug & DEBUG_REF) {
cout << "DEBUG(REF): shortended keyVal to`" << buf.c_str() << "`"<< endl;
}
-#endif
}
}
@@ -383,11 +373,9 @@ bool isValidRef(const char *buf) {
// If we have gotten here the reference is not in the selected versification.
cout << "INFO(V11N): " << before << " is not in the " << currentVerse.getVersificationSystem() << " versification." << endl;
-#ifdef DEBUG
if (debug & DEBUG_REV11N) {
cout << "DEBUG(V11N): " << before << " normalizes to " << after << endl;
}
-#endif
return false;
}
@@ -421,11 +409,9 @@ void makeValidRef(VerseKey &key) {
int chapterMax = key.getChapterMax();
int verseMax = key.getVerseMax();
-#ifdef DEBUG
if (debug & DEBUG_REV11N) {
cout << "DEBUG(V11N) Chapter max:" << chapterMax << ", Verse Max:" << verseMax << endl;
}
-#endif
cout << "INFO(V11N): " << key.getOSISRef() << " is not in the " << key.getVersificationSystem() << " versification.";
// Since isValidRef returned false constrain the key to the nearest prior reference.
@@ -466,7 +452,7 @@ void makeValidRef(VerseKey &key) {
void writeEntry(SWBuf &text, bool force = false) {
char keyOsisID[255];
- static const char* revision = "<milestone type=\"x-importer\" subType=\"x-osis2mod\" n=\"$Rev: 2400 $\"/>";
+ static const char* revision = "<milestone type=\"x-importer\" subType=\"x-osis2mod\" n=\"$Rev: 2478 $\"/>";
static bool firstOT = true;
static bool firstNT = true;
@@ -535,11 +521,9 @@ void writeEntry(SWBuf &text, bool force = false) {
activeVerseText = currentText + " " + activeVerseText;
}
-#ifdef DEBUG
if (debug & DEBUG_WRITE) {
cout << "DEBUG(WRITE): " << activeOsisID << ":" << currentVerse.getOSISRef() << ": " << activeVerseText << endl;
}
-#endif
module->setEntry(activeVerseText);
activeVerseText = "";
@@ -588,11 +572,11 @@ void linkToEntry(VerseKey &linkKey, VerseKey &dest) {
// false if the what has been seen is to be accumulated and considered later.
bool handleToken(SWBuf &text, XMLTag token) {
- // Everything between the begin book tag and the first begin chapter tag is inBookHeader
- static bool inBookHeader = false;
+ // Everything between the begin book tag and the first begin chapter tag is inBookIntro
+ static bool inBookIntro = false;
- // Everything between the begin chapter tag and the first begin verse tag is inChapterHeader
- static bool inChapterHeader = false;
+ // Everything between the begin chapter tag and the first begin verse tag is inChapterIntro
+ static bool inChapterIntro = false;
// Flags indicating whether we are processing the content of a chapter
static bool inChapter = false;
@@ -612,6 +596,12 @@ bool handleToken(SWBuf &text, XMLTag token) {
// Flag used to indicate where useful text begins
static bool firstDiv = false;
+ // Retain the sID of book, chapter and verse (commentary) divs so that we can find them again.
+ // This relies on transformBSP.
+ static SWBuf sidBook = "";
+ static SWBuf sidChapter = "";
+ static SWBuf sidVerse = "";
+
// Stack of quote elements used to handle Words of Christ
static std::stack<XMLTag> quoteStack;
@@ -628,9 +618,10 @@ bool handleToken(SWBuf &text, XMLTag token) {
static int verseDepth = 0;
int tagDepth = tagStack.size();
- const char *tokenName = token.getName();
+ SWBuf tokenName = token.getName();
bool isEndTag = token.isEndTag() || token.getAttribute("eID");
- const char *typeAttr = token.getAttribute("type");
+ SWBuf typeAttr = token.getAttribute("type");
+ SWBuf eidAttr = token.getAttribute("eID");
// process start tags
if (!isEndTag) {
@@ -638,21 +629,19 @@ bool handleToken(SWBuf &text, XMLTag token) {
// Remember non-empty start tags
if (!token.isEmpty()) {
tagStack.push(token);
-#ifdef DEBUG
+
if (debug & DEBUG_STACK) {
cout << "DEBUG(STACK): " << currentOsisID << ": push (" << tagStack.size() << ") " << token.getName() << endl;
}
-#endif
}
// throw away everything up to the first div
if (!firstDiv) {
- if (!strcmp(tokenName, "div")) {
-#ifdef DEBUG
+ if (tokenName == "div") {
if (debug & DEBUG_OTHER) {
cout << "DEBUG(FOUND): Found first div and pitching prior material: " << text << endl;
}
-#endif
+
// TODO: Save off the content to use it to suggest the module's conf.
firstDiv = true;
text = "";
@@ -668,15 +657,15 @@ bool handleToken(SWBuf &text, XMLTag token) {
if (token.getAttribute("osisID") || token.getAttribute("annotateRef")) {
// BOOK START, <div type="book" ...>
- if ((!strcmp(tokenName, "div")) && (typeAttr && !strcmp(typeAttr, "book"))) {
- if (inBookHeader || inChapterHeader) { // this one should never happen, but just in case
-#ifdef DEBUG
+ if (tokenName == "div" && typeAttr == "book") {
+ if (inBookIntro || inChapterIntro) { // this one should never happen, but just in case
+
if (debug & DEBUG_TITLE) {
- cout << "DEBUG(TITLE): " << currentOsisID << ": OOPS HEADING " << endl;
- cout << "\tinChapterHeader = " << inChapterHeader << endl;
- cout << "\tinBookHeader = " << inBookHeader << endl;
+ cout << "DEBUG(TITLE): " << currentOsisID << ": OOPS INTRO " << endl;
+ cout << "\tinChapterIntro = " << inChapterIntro << endl;
+ cout << "\tinBookIntro = " << inBookIntro << endl;
}
-#endif
+
currentVerse.Testament(0);
currentVerse.Book(0);
currentVerse.Chapter(0);
@@ -688,11 +677,16 @@ bool handleToken(SWBuf &text, XMLTag token) {
currentVerse.Verse(0);
strcpy(currentOsisID, currentVerse.getOSISRef());
+ sidBook = token.getAttribute("sID");
inChapter = false;
inVerse = false;
inPreVerse = false;
- inBookHeader = true;
- inChapterHeader = false;
+ inBookIntro = true;
+ inChapterIntro = false;
+
+ if (debug & DEBUG_TITLE) {
+ cout << "DEBUG(TITLE): " << currentOsisID << ": Looking for book introduction" << endl;
+ }
bookDepth = tagStack.size();
chapterDepth = 0;
@@ -702,42 +696,44 @@ bool handleToken(SWBuf &text, XMLTag token) {
if (!inCanonicalOSISBook) {
cout << "WARNING(V11N): New book is " << token.getAttribute("osisID") << " and is not in " << v11n << " versification, ignoring" << endl;
}
-#ifdef DEBUG
else if (debug & DEBUG_OTHER) {
cout << "DEBUG(FOUND): New book is " << currentVerse.getOSISRef() << endl;
}
-#endif
return false;
}
- // CHAPTER START, <div type="chapter" ...> or <chapter ...>
- if (((!strcmp(tokenName, "div")) && (typeAttr && !strcmp(typeAttr, "chapter"))) ||
- (!strcmp(tokenName, "chapter"))
- ) {
- if (inBookHeader) {
-#ifdef DEBUG
+ // CHAPTER START, <chapter> or <div type="chapter" ...>
+ if ((tokenName == "chapter") ||
+ (tokenName == "div" && typeAttr == "chapter")
+ ) {
+ if (inBookIntro) {
if (debug & DEBUG_TITLE) {
- cout << "DEBUG(TITLE): " << currentOsisID << ": BOOK HEADING "<< text.c_str() << endl;
+ cout << "DEBUG(TITLE): " << currentOsisID << ": BOOK INTRO "<< text << endl;
}
-#endif
+
writeEntry(text);
}
currentVerse = token.getAttribute("osisID");
currentVerse.Verse(0);
-#ifdef DEBUG
+
if (debug & DEBUG_OTHER) {
cout << "DEBUG(FOUND): Current chapter is " << currentVerse.getOSISRef() << " (" << token.getAttribute("osisID") << ")" << endl;
}
-#endif
+
strcpy(currentOsisID, currentVerse.getOSISRef());
+ sidChapter = token.getAttribute("sID");
inChapter = true;
inVerse = false;
inPreVerse = false;
- inBookHeader = false;
- inChapterHeader = true;
+ inBookIntro = false;
+ inChapterIntro = true;
+
+ if (debug & DEBUG_TITLE) {
+ cout << "DEBUG(TITLE): " << currentOsisID << ": Looking for chapter introduction" << endl;
+ }
chapterDepth = tagStack.size();
verseDepth = 0;
@@ -746,27 +742,25 @@ bool handleToken(SWBuf &text, XMLTag token) {
}
// VERSE, <verse ...> OR COMMENTARY START, <div annotateType="xxx" ...>
- if (!strcmp(tokenName, "verse") ||
- (!strcmp(tokenName, "div") && token.getAttribute("annotateType"))) {
-#ifdef DEBUG
+ if ((tokenName == "verse") ||
+ (tokenName == "div" && token.getAttribute("annotateType"))
+ ) {
if (debug & DEBUG_OTHER) {
cout << "DEBUG(FOUND): Entering verse" << endl;
}
-#endif
- if (inChapterHeader) {
- SWBuf heading = text;
- text = "";
- if (heading.length()) {
-#ifdef DEBUG
+ if (inChapterIntro) {
+ if (debug & DEBUG_TITLE) {
+ cout << "DEBUG(TITLE): " << currentOsisID << ": Done looking for chapter introduction" << endl;
+ }
+
+ if (text.length()) {
if (debug & DEBUG_TITLE) {
- cout << "DEBUG(TITLE): " << currentOsisID << ": CHAPTER HEADING "<< heading.c_str() << endl;
+ cout << "DEBUG(TITLE): " << currentOsisID << ": CHAPTER INTRO "<< text << endl;
}
-#endif
- writeEntry(heading);
- }
- inChapterHeader = false;
+ writeEntry(text);
+ }
}
// Did we have pre-verse material that needs to be marked?
@@ -777,7 +771,7 @@ bool handleToken(SWBuf &text, XMLTag token) {
}
// Get osisID for verse or annotateRef for commentary
- SWBuf keyVal = token.getAttribute(strcmp(tokenName, "verse") ? "annotateRef" : "osisID");
+ SWBuf keyVal = token.getAttribute(tokenName == "verse" ? "osisID" : "annotateRef");
// Massage the key into a form that ParseVerseList can accept
prepareSWVerseKey(keyVal);
@@ -802,28 +796,27 @@ bool handleToken(SWBuf &text, XMLTag token) {
}
}
else {
- cout << "ERROR(REF): Invalid osisID/annotateRef: " << token.getAttribute(strcmp(tokenName, "verse") ? "annotateRef" : "osisID") << endl;
+ cout << "ERROR(REF): Invalid osisID/annotateRef: " << token.getAttribute((tokenName == "verse") ? "osisID" : "annotateRef") << endl;
}
strcpy(currentOsisID, currentVerse.getOSISRef());
-#ifdef DEBUG
+
if (debug & DEBUG_OTHER) {
cout << "DEBUG(FOUND): New current verse is " << currentVerse.getOSISRef() << endl;
cout << "DEBUG(FOUND): osisID/annotateRef is adjusted to: " << keyVal << endl;
}
-#endif
+ sidVerse = token.getAttribute("sID");
inVerse = true;
inPreVerse = false;
- inBookHeader = false;
- inChapterHeader = false;
+ inBookIntro = false;
+ inChapterIntro = false;
verseDepth = tagStack.size();
// Include the token if it is not a verse
- if (strcmp(tokenName, "verse")) {
+ if (tokenName != "verse") {
text.append(token);
}
-#ifdef DEBUG
else if (debug & DEBUG_VERSE)
{
// transform the verse into a milestone
@@ -836,7 +829,6 @@ bool handleToken(SWBuf &text, XMLTag token) {
}
text.append(t);
}
-#endif
if (inWOC) {
text.append(wocTag);
@@ -850,13 +842,13 @@ bool handleToken(SWBuf &text, XMLTag token) {
// Handle WOC quotes.
// Note this requires transformBSP to make them into milestones
// Otherwise have to do it here
- if (!strcmp(tokenName, "q")) {
+ if (tokenName == "q") {
quoteStack.push(token);
-#ifdef DEBUG
+
if (debug & DEBUG_QUOTE) {
cout << "DEBUG(QUOTE): " << currentOsisID << ": quote top(" << quoteStack.size() << ") " << token << endl;
}
-#endif
+
if (token.getAttribute("who") && !strcmp(token.getAttribute("who"), "Jesus")) {
inWOC = true;
@@ -882,30 +874,35 @@ bool handleToken(SWBuf &text, XMLTag token) {
// 1) Between the opening of a book and the first chapter, all the material is handled as an introduction to the book.
// 2) Between the opening of a chapter and the first verse, the material is split between the introduction of the chapter
// and the first verse of the chapter.
- // A <div> with a type other than section will be taken as a chapter introduction.
- // A <title> of type acrostic, psalm or no type, will be taken as a title for the verse.
- // A <title> of type main or chapter will be seen as a chapter title.
+ // A <div> with a type of section will be taken as surrounding verses.
+ // A <title> of type other than main, chapter or sub, will be taken as a title for the verse.
+ // Once one of these conditions is met, the division between chapter introduction and pre-verse is set.
// 3) Between verses, the material is split between the prior verse and the next verse.
// Basically, while end and empty tags are found, they belong to the prior verse.
// Once a begin tag is found, it belongs to the next verse.
- // If the title has an attribute type of "main" or "chapter"
- // it belongs to its <div> or <chapter> and is treated as part of its heading
- // Otherwise if it a title in a chapter before the first the first verse it
- // is put into the verse as a preverse title.
-
- if (!inPreVerse && !inBookHeader) {
- if (inChapterHeader) {
+ if (!inPreVerse && !inBookIntro) {
+ if (inChapterIntro) {
// Determine when we are no longer in a chapter heading, but in pre-verse material:
// If we see one of the following:
// a section div
- // a title that is not main or chapter
- if ((!strcmp(tokenName, "div") && (typeAttr && !strcmp(typeAttr, "section"))) ||
- (!strcmp(tokenName, "title") && (!typeAttr || (strcmp(typeAttr, "main") && strcmp(typeAttr, "chapter"))))
- ) {
- // Since we have found the boundary, we need to write out the chapter heading
- writeEntry(text);
+ // a title that is not main, chapter or sub or unclassified (no type attribute)
+ if ((tokenName == "div" && typeAttr == "section") ||
+ (tokenName == "title" && typeAttr.length() != 0 && typeAttr != "main" && typeAttr != "chapter" && typeAttr != "sub")
+ ) {
+ if (debug & DEBUG_TITLE) {
+ cout << "DEBUG(TITLE): " << currentOsisID << ": Done looking for chapter introduction" << endl;
+ }
+
+ if (text.length()) {
+ if (debug & DEBUG_TITLE) {
+ cout << "DEBUG(TITLE): " << currentOsisID << ": CHAPTER INTRO "<< text << endl;
+ }
+
+ // Since we have found the boundary, we need to write out the chapter heading
+ writeEntry(text);
+ }
// And we are no longer in the chapter heading
- inChapterHeader = false;
+ inChapterIntro = false;
// But rather, we are now in pre-verse material
inPreVerse = true;
}
@@ -916,18 +913,16 @@ bool handleToken(SWBuf &text, XMLTag token) {
if (inPreVerse) {
char genBuf[200];
- sprintf(genBuf, "<div type=\"x-milestone\" subType=\"x-preverse\" sID=\"pv%d\"/>", genID++);
+ sprintf(genBuf, "<div type=\"x-milestone\" subType=\"x-preverse\" sID=\"pv%d\"/>", genID);
text.append(genBuf);
}
}
-#ifdef DEBUG
if (debug & DEBUG_INTERVERSE) {
- if (!inVerse && !inBookHeader && !inChapterHeader) {
+ if (!inVerse && !inBookIntro && !inChapterIntro) {
cout << "DEBUG(INTERVERSE): " << currentOsisID << ": interverse start token " << token << ":" << text.c_str() << endl;
}
}
-#endif
return false;
} // Done with procesing start and empty tags
@@ -944,14 +939,14 @@ bool handleToken(SWBuf &text, XMLTag token) {
if (!token.isEmpty()) {
XMLTag topToken = tagStack.top();
tagDepth = tagStack.size();
-#ifdef DEBUG
+
if (debug & DEBUG_STACK) {
cout << "DEBUG(STACK): " << currentOsisID << ": pop(" << tagDepth << ") " << topToken.getName() << endl;
}
-#endif
+
tagStack.pop();
- if (strcmp(topToken.getName(), tokenName)) {
+ if (tokenName != topToken.getName()) {
cout << "FATAL(NESTING): " << currentOsisID << ": Expected " << topToken.getName() << " found " << tokenName << endl;
// exit(EXIT_BAD_NESTING); // (OSK) I'm sure this validity check is a good idea, but there's a but somewhere that's killing the converter here.
// So I'm disabling this line. Unvalidated OSIS files shouldn't be run through the converter anyway.
@@ -966,7 +961,9 @@ bool handleToken(SWBuf &text, XMLTag token) {
}
// VERSE and COMMENTARY END
- if (!strcmp(tokenName, "verse") || (inVerse && !strcmp(tokenName, "div"))) {
+ if ((tokenName == "verse") ||
+ (tokenName == "div" && eidAttr == sidVerse)
+ ) {
if (tagDepth != verseDepth) {
cout << "WARNING(NESTING): verse " << currentOsisID << " is not well formed:(" << verseDepth << "," << tagDepth << ")" << endl;
@@ -979,10 +976,9 @@ bool handleToken(SWBuf &text, XMLTag token) {
// Include the token if it is not a verse
- if (strcmp(tokenName, "verse")) {
+ if (tokenName != "verse") {
text.append(token);
}
-#ifdef DEBUG
else if (debug & DEBUG_VERSE)
{
// transform the verse into a milestone
@@ -995,7 +991,6 @@ bool handleToken(SWBuf &text, XMLTag token) {
}
text.append(t);
}
-#endif
writeEntry(text);
@@ -1009,23 +1004,23 @@ bool handleToken(SWBuf &text, XMLTag token) {
// Handle WOC quotes.
// Note this requires transformBSP to make them into milestones
// Otherwise have to manage it here
- if (!strcmp(tokenName, "q")) {
+ if (tokenName == "q") {
XMLTag topToken = quoteStack.top();
-#ifdef DEBUG
+
if (debug & DEBUG_QUOTE) {
cout << "DEBUG(QUOTE): " << currentOsisID << ": quote pop(" << quoteStack.size() << ") " << topToken << " -- " << token << endl;
}
-#endif
+
quoteStack.pop();
// If we have found an end tag for a <q who="Jesus"> then we are done with the WOC
// and we need to terminate the <q who="Jesus" marker=""> that was added earlier in the verse.
if (token.getAttribute("who") && !strcmp(token.getAttribute("who"), "Jesus")) {
-#ifdef DEBUG
+
if (debug & DEBUG_QUOTE) {
cout << "DEBUG(QUOTE): " << currentOsisID << ": (" << quoteStack.size() << ") " << topToken << " -- " << token << endl;
}
-#endif
+
inWOC = false;
const char *sID = topToken.getAttribute("sID");
const char *eID = token.getAttribute("eID");
@@ -1059,19 +1054,22 @@ bool handleToken(SWBuf &text, XMLTag token) {
// Look for the end of document, book and chapter
// Also for material that goes with last entry
- if (!inVerse && !inBookHeader && !inChapterHeader) {
+ if (!inVerse && !inBookIntro && !inChapterIntro) {
// Is this the end of a chapter.
- if (tagDepth == chapterDepth && (!strcmp(tokenName, "div") || !strcmp(tokenName, "chapter"))) {
+ if ((tokenName == "chapter") ||
+ (tokenName == "div" && eidAttr == sidChapter)
+ ) {
text.append(token);
writeEntry(text);
inChapter = false;
+ sidChapter = "";
chapterDepth = 0;
verseDepth = 0;
return true;
}
// Is it the end of a book
- if (tagDepth == bookDepth && (!strcmp(tokenName, "div"))) {
+ if (tokenName == "div" && eidAttr == sidBook) {
text.append(token);
writeEntry(text);
bookDepth = 0;
@@ -1081,7 +1079,7 @@ bool handleToken(SWBuf &text, XMLTag token) {
}
// Do not include the end of an osis document
- if (!strcmp(tokenName, "osisText") || !strcmp(tokenName, "osis")) {
+ if (tokenName == "osisText" || tokenName == "osis") {
bookDepth = 0;
chapterDepth = 0;
verseDepth = 0;
@@ -1093,21 +1091,19 @@ bool handleToken(SWBuf &text, XMLTag token) {
if (!inPreVerse) {
text.append(token);
writeEntry(text);
-#ifdef DEBUG
+
if (debug & DEBUG_INTERVERSE) {
cout << "DEBUG(INTERVERSE): " << currentOsisID << ": appending interverse end tag: " << tokenName << "(" << tagDepth << "," << chapterDepth << "," << bookDepth << ")" << endl;
}
-#endif
+
return true;
}
-#ifdef DEBUG
if (debug & DEBUG_INTERVERSE) {
cout << "DEBUG(INTERVERSE): " << currentOsisID << ": interverse end tag: " << tokenName << "(" << tagDepth << "," << chapterDepth << "," << bookDepth << ")" << endl;
}
-#endif
- return false;
+ return false;
}
return false;
@@ -1135,18 +1131,18 @@ XMLTag transformBSP(XMLTag t) {
// Support simplification transformations
if (t.isEmpty()) {
-#ifdef DEBUG
+
if (debug & DEBUG_XFORM) {
cout << "DEBUG(XFORM): " << currentOsisID << ": xform empty " << t << endl;
}
-#endif
+
return t;
}
- const char* tagName = t.getName();
+ SWBuf tagName = t.getName();
if (!t.isEndTag()) {
// Transform <p> into <div type="paragraph"> and milestone it
- if (!strcmp(tagName, "p")) {
+ if (tagName == "p") {
t.setText("<div type=\"paragraph\" />");
sprintf(buf, "gen%d", sID++);
t.setAttribute("sID", buf);
@@ -1159,52 +1155,51 @@ XMLTag transformBSP(XMLTag t) {
// abbr When would this ever cross a boundary?
// seg as it is used for a divineName hack
// foreign so that it can be easily italicized
- else if (!strcmp(tagName, "chapter") ||
- !strcmp(tagName, "closer") ||
- !strcmp(tagName, "div") ||
- !strcmp(tagName, "l") ||
- !strcmp(tagName, "lg") ||
- !strcmp(tagName, "q") ||
- !strcmp(tagName, "salute") ||
- !strcmp(tagName, "signed") ||
- !strcmp(tagName, "speech") ||
- !strcmp(tagName, "verse")
- ) {
+ else if (tagName == "chapter" ||
+ tagName == "closer" ||
+ tagName == "div" ||
+ tagName == "l" ||
+ tagName == "lg" ||
+ tagName == "q" ||
+ tagName == "salute" ||
+ tagName == "signed" ||
+ tagName == "speech" ||
+ tagName == "verse"
+ ) {
t.setEmpty(true);
sprintf(buf, "gen%d", sID++);
t.setAttribute("sID", buf);
}
bspTagStack.push(t);
-#ifdef DEBUG
+
if (debug & DEBUG_XFORM) {
cout << "DEBUG(XFORM): " << currentOsisID << ": xform push (" << bspTagStack.size() << ") " << t << " (tagname=" << tagName << ")" << endl;
XMLTag topToken = bspTagStack.top();
cout << "DEBUG(XFORM): " << currentOsisID << ": xform top(" << bspTagStack.size() << ") " << topToken << endl;
}
-#endif
}
else {
XMLTag topToken = bspTagStack.top();
-#ifdef DEBUG
+
if (debug & DEBUG_XFORM) {
cout << "DEBUG(XFORM): " << currentOsisID << ": xform pop(" << bspTagStack.size() << ") " << topToken << endl;
}
-#endif
+
bspTagStack.pop();
// Look for the milestoneable container tags handled above.
- if (!strcmp(tagName, "chapter") ||
- !strcmp(tagName, "closer") ||
- !strcmp(tagName, "div") ||
- !strcmp(tagName, "l") ||
- !strcmp(tagName, "lg") ||
- !strcmp(tagName, "p") ||
- !strcmp(tagName, "q") ||
- !strcmp(tagName, "salute") ||
- !strcmp(tagName, "signed") ||
- !strcmp(tagName, "speech") ||
- !strcmp(tagName, "verse")
- ) {
+ if (tagName == "chapter" ||
+ tagName == "closer" ||
+ tagName == "div" ||
+ tagName == "l" ||
+ tagName == "lg" ||
+ tagName == "p" ||
+ tagName == "q" ||
+ tagName == "salute" ||
+ tagName == "signed" ||
+ tagName == "speech" ||
+ tagName == "verse"
+ ) {
// make this a clone of the start tag with sID changed to eID
// Note: in the case of </p> the topToken is a <div type="paragraph">
t = topToken;
@@ -1261,9 +1256,11 @@ void usage(const char *app, const char *error = 0) {
if (error) fprintf(stderr, "\n%s: %s\n", app, error);
+ fprintf(stderr, "OSIS Bible/commentary module creation tool for The SWORD Project\n");
fprintf(stderr, "\nusage: %s <output/path> <osisDoc> [OPTIONS]\n", app);
fprintf(stderr, " <output/path>\t\t an existing folder that the module will be written\n");
- fprintf(stderr, " <osisDoc>\t\t path to the validated OSIS document, or '-' to read from standard input\n");
+ fprintf(stderr, " <osisDoc>\t\t path to the validated OSIS document, or '-' to\n");
+ fprintf(stderr, "\t\t\t\t read from standard input\n");
fprintf(stderr, " -a\t\t\t augment module if exists (default is to create new)\n");
fprintf(stderr, " -z\t\t\t use ZIP compression (default no compression)\n");
fprintf(stderr, " -Z\t\t\t use LZSS compression (default no compression)\n");
@@ -1275,24 +1272,24 @@ void usage(const char *app, const char *error = 0) {
fprintf(stderr, "\t\t\t\t (default is to convert to UTF-8, if needed,\n");
fprintf(stderr, "\t\t\t\t and then normalize to NFC)\n");
fprintf(stderr, "\t\t\t\t Note: UTF-8 texts should be normalized to NFC.\n");
- fprintf(stderr, " -s <2|4>\t\t max text size per entry (default is 2).\n");
- fprintf(stderr, "\t\t\t\t Note: useful for commentaries with very large entries\n");
- fprintf(stderr, "\t\t\t\t in uncompressed modules (default is 65535 bytes)\n");
+ fprintf(stderr, " -s <2|4>\t\t bytes used to store entry size (default is 2).\n");
+ fprintf(stderr, "\t\t\t\t Note: useful for commentaries with very large\n");
+ fprintf(stderr, "\t\t\t\t entries in uncompressed modules\n");
+ fprintf(stderr, "\t\t\t\t (2 bytes to store size equal 65535 characters)\n");
fprintf(stderr, " -v <v11n>\t\t specify a versification scheme to use (default is KJV)\n");
fprintf(stderr, "\t\t\t\t Note: The following are valid values for v11n:\n");
VerseMgr *vmgr = VerseMgr::getSystemVerseMgr();
StringList av11n = vmgr->getVersificationSystems();
for (StringList::iterator loop = av11n.begin(); loop != av11n.end(); loop++) {
fprintf(stderr, "\t\t\t\t\t%s\n", (*loop).c_str());
- }
-#ifdef DEBUG
+ }
fprintf(stderr, " -d <flags>\t\t turn on debugging (default is 0)\n");
fprintf(stderr, "\t\t\t\t Note: This flag may change in the future.\n");
fprintf(stderr, "\t\t\t\t Flags: The following are valid values:\n");
fprintf(stderr, "\t\t\t\t\t0 - no debugging\n");
fprintf(stderr, "\t\t\t\t\t1 - writes to module, very verbose\n");
fprintf(stderr, "\t\t\t\t\t2 - verse start and end\n");
- fprintf(stderr, "\t\t\t\t\t4 - quotes, especially Words of Christ (WOC)\n");
+ fprintf(stderr, "\t\t\t\t\t4 - quotes, esp. Words of Christ\n");
fprintf(stderr, "\t\t\t\t\t8 - titles\n");
fprintf(stderr, "\t\t\t\t\t16 - inter-verse material\n");
fprintf(stderr, "\t\t\t\t\t32 - BSP to BCV transformations\n");
@@ -1300,8 +1297,8 @@ void usage(const char *app, const char *error = 0) {
fprintf(stderr, "\t\t\t\t\t128 - parsing of osisID and osisRef\n");
fprintf(stderr, "\t\t\t\t\t256 - internal stack\n");
fprintf(stderr, "\t\t\t\t\t512 - miscellaneous\n");
- fprintf(stderr, "\t\t\t\t This flag can be used more than once.\n");
-#endif
+ fprintf(stderr, "\t\t\t\t This argument can be used more than once. (Or\n");
+ fprintf(stderr, "\t\t\t\t the flags may be added together.)\n");
fprintf(stderr, "\n");
fprintf(stderr, "See http://www.crosswire.org/wiki/osis2mod for more details.\n");
fprintf(stderr, "\n");
@@ -1397,7 +1394,7 @@ void processOSIS(istream& infile) {
int main(int argc, char **argv) {
- fprintf(stderr, "You are running osis2mod: $Rev: 2400 $\n");
+ fprintf(stderr, "You are running osis2mod: $Rev: 2478 $\n");
// Let's test our command line arguments
if (argc < 3) {
@@ -1450,32 +1447,34 @@ int main(int argc, char **argv) {
}
else if (!strcmp(argv[i], "-s")) {
if (compType.size()) usage(*argv, "Cannot specify -s and -z or -Z");
- if (i+1 < argc) {
- entrySize = atoi(argv[++i]);
- if (entrySize == 2 || entrySize == 4) {
- continue;
- }
- }
- usage(*argv, "-s requires one of <2|4>");
+ if (i+1 < argc) {
+ entrySize = atoi(argv[++i]);
+ if (entrySize == 2 || entrySize == 4) {
+ continue;
+ }
+ }
+ usage(*argv, "-s requires one of <2|4>");
}
else if (!strcmp(argv[i], "-C")) {
isCommentary = true;
}
-#ifdef DEBUG
else if (!strcmp(argv[i], "-d")) {
if (i+1 < argc) debug |= atoi(argv[++i]);
else usage(*argv, "-d requires <flags>");
}
-#endif
else usage(*argv, (((SWBuf)"Unknown argument: ")+ argv[i]).c_str());
}
- if (compType == "ZIP") {
- compressor = new ZipCompress();
- }
- else if (compType = "LZSS") {
- compressor = new LZSSCompress();
- }
+ if (compType == "ZIP") {
+#ifndef EXCLUDEZLIB
+ compressor = new ZipCompress();
+#else
+ usage(*argv, "ERROR: SWORD library not compiled with ZIP compression support.\n\tBe sure libzip is available when compiling SWORD library");
+#endif
+ }
+ else if (compType == "LZSS") {
+ compressor = new LZSSCompress();
+ }
#ifndef _ICU_
if (normalize) {
@@ -1484,11 +1483,9 @@ int main(int argc, char **argv) {
}
#endif
-#ifdef DEBUG
if (debug & DEBUG_OTHER) {
cout << "DEBUG(ARGS):\n\tpath: " << path << "\n\tosisDoc: " << osisDoc << "\n\tcreate: " << append << "\n\tcompressType: " << compType << "\n\tblockType: " << iType << "\n\tcipherKey: " << cipherKey.c_str() << "\n\tnormalize: " << normalize << endl;
}
-#endif
if (!append) { // == 0 then create module
// Try to initialize a default set of datafiles and indicies at our
@@ -1529,7 +1526,7 @@ int main(int argc, char **argv) {
FMT_UNKNOWN, // markup
0, // lang
v11n // versification
- );
+ );
}
else if (entrySize == 4) {
// Create a raw text module allowing very large entries