[sword-svn] r2212 - trunk/utilities

dmsmith at www.crosswire.org dmsmith at www.crosswire.org
Tue Dec 2 08:42:51 MST 2008


Author: dmsmith
Date: 2008-12-02 08:42:49 -0700 (Tue, 02 Dec 2008)
New Revision: 2212

Modified:
   trunk/utilities/osis2mod.cpp
Log:
fixed a chapter heading problem in osis2mod

Modified: trunk/utilities/osis2mod.cpp
===================================================================
--- trunk/utilities/osis2mod.cpp	2008-11-27 04:42:53 UTC (rev 2211)
+++ trunk/utilities/osis2mod.cpp	2008-12-02 15:42:49 UTC (rev 2212)
@@ -33,7 +33,7 @@
 //#define DEBUG_XFORM
 
 // Debug for Words of Christ (aka WOC)
-#define DEBUG_QUOTE
+//#define DEBUG_QUOTE
 
 // Debug for parsing osisRefs
 //#define DEBUG_REF
@@ -41,6 +41,10 @@
 // Debug for tag stack
 //#define DEBUG_STACK
 
+// Debug for titles
+//#define DEBUG_TITLE
+
+//Include all tags starting with the first div in the module
 //#define INCLUDE_TAGS
 
 #ifndef NO_SWORD_NAMESPACE
@@ -554,7 +558,7 @@
 		lastTitle.append(text.c_str() + titleOffset); //<title ...> up to the end </title>
 		lastTitle.append(token); //</title>
 
-#ifdef DEBUG
+#ifdef DEBUG_TITLE
 		cout << currentOsisID << ":" << endl;
 		cout << "\tlastTitle:      " << lastTitle.c_str() << endl;
 		cout << "\ttext-lastTitle: " << text.c_str()+titleOffset << endl;
@@ -586,6 +590,9 @@
 		// throw away everything up to the first div
 		if (!firstDiv && !strcmp(tokenName, "div")) {
 			firstDiv = true;
+#ifdef DEBUG
+			cout << "Found first div and pitching prior material: " << text << endl;
+#endif
 			text     = "";
 		}
 
@@ -597,7 +604,7 @@
 			if ((!strcmp(tokenName, "div")) && (typeAttr && !strcmp(typeAttr, "book"))) {
 				inVerse = false;
 				if (inBookHeader || inChapterHeader) {	// this one should never happen, but just in case
-#ifdef DEBUG
+#ifdef DEBUG_TITLE
 					cout << currentOsisID << ": HEADING ";
 #endif
 					currentVerse.Testament(0);
@@ -606,10 +613,15 @@
 					currentVerse.Verse(0);
 					writeEntry(text);
 				}
-				strcpy(currentOsisID, token.getAttribute("osisID"));
-				currentVerse = currentOsisID;
+				// Initializing a temporary and copying that because there were problems with setting the text directly
+				VerseKey t;
+				t.AutoNormalize(0);
+				t.Headings(1);
+				t = token.getAttribute("osisID");
+				currentVerse = t;
 				currentVerse.Chapter(0);
 				currentVerse.Verse(0);
+				strcpy(currentOsisID, currentVerse.getOSISRef());
 				inBookHeader = true;
 				inChapterHeader = false;
 				lastTitle = "";
@@ -618,6 +630,9 @@
 				verseDepth = 0;
 
 				inCanonicalOSISBook = isOSISAbbrev(token.getAttribute("osisID"));
+#ifdef DEBUG
+				cout << "Current book is " << currentVerse << (!inCanonicalOSISBook ? "not in KJV, ignoring" : "") << endl;
+#endif
 
 #ifndef INCLUDE_TAGS
 				return true;
@@ -632,15 +647,25 @@
 			   ) {
 				inVerse = false;
 				if (inBookHeader) {
-#ifdef DEBUG
+#ifdef DEBUG_TITLE
 					cout << currentOsisID << ": BOOK HEADING "<< text.c_str() << endl;
 #endif
 					writeEntry(text);
 				}
 
-				strcpy(currentOsisID, token.getAttribute("osisID"));
-				currentVerse = currentOsisID;
+				// I don't know why, but I cannot do the following,
+				// as it does not change the content of VerseKey!
+				// currentVerse = token.getAttribute("osisID");
+				VerseKey t;
+				t.AutoNormalize(0);
+				t.Headings(1);
+				t = token.getAttribute("osisID");
+				currentVerse = t;
 				currentVerse.Verse(0);
+#ifdef DEBUG
+				cout << "Current chapter is " << currentVerse << " (" << token.getAttribute("osisID") << ")" << endl;
+#endif
+				strcpy(currentOsisID, currentVerse.getOSISRef());
 				inBookHeader = false;
 				inChapterHeader = true;
 				lastTitle = "";
@@ -691,7 +716,7 @@
 
 
 					if (heading.length()) {
-#ifdef DEBUG
+#ifdef DEBUG_TITLE
 						cout << currentOsisID << ": CHAPTER HEADING "<< heading.c_str() << endl;
 #endif
 						writeEntry(heading);
@@ -761,7 +786,8 @@
 		// Whitespace producing empty tokens are appended to prior entry
 		// Also the quote
 		// This is a hack to get ESV to work
-		if (!inTitle && !inVerse && token.isEmpty()) {
+		// Don't write if there is not a valid osisID yet.
+		if (!inTitle && !inVerse && token.isEmpty() && strcmp(currentOsisID, "N/A")) {
 			if (!strcmp(tokenName, "div") ||
 			    !strcmp(tokenName, "q")   ||
 			    !strcmp(tokenName, "l")   ||
@@ -815,7 +841,7 @@
 
 			if (lastTitle.length()) {
 				const char* end = strchr(lastTitle, '>');
-#ifdef DEBUG
+#ifdef DEBUG_TITLE
 				cout << currentOsisID << ":" << endl;
 				cout << "\t" << lastTitle << endl;
 	 			cout << "\tlength=" << int(end+1 - lastTitle.c_str()) << ", tag:" << lastTitle.c_str() << endl;
@@ -823,7 +849,7 @@
 
 				SWBuf titleTagText;
 				titleTagText.append(lastTitle.c_str(), end+1 - lastTitle.c_str());
-#ifdef DEBUG
+#ifdef DEBUG_TITLE
 				cout << currentOsisID << ": tagText: " << titleTagText.c_str() << endl;;
 #endif
 
@@ -930,6 +956,7 @@
 			// OTHER MISC END TAGS WHEN !INVERSE
 			// Test that is between verses, or after the last is appended to the preceeding verse.
 			if (!strcmp(tokenName, "div") ||
+			    !strcmp(tokenName, "chapter") ||
 			    !strcmp(tokenName, "q")   ||
 			    !strcmp(tokenName, "l")   ||
 			    !strcmp(tokenName, "lb")  ||




More information about the sword-cvs mailing list