[sword-cvs] sword/utilities osis2mod.cpp,1.9,1.10

sword at www.crosswire.org sword at www.crosswire.org
Wed May 19 12:40:41 MST 2004


Committed by: joachim

Update of /cvs/core/sword/utilities
In directory www:/tmp/cvs-serv3301/utilities

Modified Files:
	osis2mod.cpp 
Log Message:
better osisID support; links verse ranges togetjer

Index: osis2mod.cpp
===================================================================
RCS file: /cvs/core/sword/utilities/osis2mod.cpp,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- osis2mod.cpp	24 Jan 2004 18:42:40 -0000	1.9
+++ osis2mod.cpp	19 May 2004 19:40:39 -0000	1.10
@@ -3,6 +3,7 @@
 #include <fcntl.h>
 #include <errno.h>
 #include <stdlib.h>
+#include <string>
 
 #ifndef __GNUC__
 #include <io.h>
@@ -15,6 +16,7 @@
 #include <iostream>
 #include <swbuf.h>
 #include <utilxml.h>
+#include <listkey.h>
 
 #ifndef O_BINARY
 #define O_BINARY 0
@@ -99,6 +101,17 @@
 	module->setEntry(text);
 }
 
+void linkToEntry(VerseKey& dest) {
+//	cout << "Verse: " << key << "\n";
+//	cout << "TEXT: " << text << "\n\n";
+	//SWBuf currentText = module->getRawEntry();
+	//if (currentText.length())
+	//	text = currentText + " " + text;
+	
+	cout << "Linking " << module->KeyText() << " to " << dest.getText() << "\n";
+	module->linkEntry(&dest);
+}
+
 
 bool handleToken(SWBuf &text, XMLTag token) {
 	static bool inHeader = false;
@@ -106,6 +119,8 @@
 	static SWBuf header = "";
 	static SWBuf lastTitle = "";
 	static int titleOffset = -1;
+	
+	static ListKey lastVerseIDs = ListKey();
 
 	if ((!strcmp(token.getName(), "title")) && (!token.isEndTag())) {
 		titleOffset = text.length();
@@ -152,7 +167,23 @@
 		}
 
 		*currentVerse = token.getAttribute("osisID");
+		
+		string str = token.getAttribute("osisID");
+		int pos = 0;
+		while ((pos = str.find(' ', pos)) != string::npos) {
+			str.replace(pos, 1, ";");
+		}
+		
+		//cout << "set the list\n" << token.getAttribute("osisID");
+		lastVerseIDs = currentVerse->ParseVerseList(str.c_str());
+//		if (lastVerseIDs.Count() > 1)
+//			cout << "count is" << lastVerseIDs.Count();
+
+		if (lastVerseIDs.Count())
+			*currentVerse = lastVerseIDs.getElement(0)->getText();
+		
 		text = "";
+		
 		return true;
 	}
 	if ((!strcmp(token.getName(), "verse")) && (token.isEndTag())) {
@@ -166,6 +197,17 @@
 			text = SWBuf(titleTag) + SWBuf(end+1) + text;
 		}
 		writeEntry(*currentVerse, text);
+		
+		// If we found an osisID like osisID="Gen1.1 Gen1.2 Gen 1.3" we have to link Gen1.2 and Gen1.3 to Gen1.1
+		VerseKey dest = *currentVerse;
+		for (int i = 0; i < lastVerseIDs.Count(); ++i) {
+			VerseKey linkKey = lastVerseIDs.getElement(i)->getText();
+			if (linkKey != *currentVerse) {
+				*currentVerse = linkKey;
+				linkToEntry(dest);
+			}
+		}
+		
 		lastTitle = "";
 		text = "";
 		return true;



More information about the sword-cvs mailing list