[sword-svn] r1804 - in trunk: include src/keys src/modules/filters utilities

scribe at crosswire.org scribe at crosswire.org
Fri May 6 23:26:11 MST 2005


Author: scribe
Date: 2005-05-06 23:26:10 -0700 (Fri, 06 May 2005)
New Revision: 1804

Modified:
   trunk/include/gbfosis.h
   trunk/include/thmlosis.h
   trunk/include/versekey.h
   trunk/src/keys/versekey.cpp
   trunk/src/modules/filters/gbfosis.cpp
   trunk/src/modules/filters/thmlosis.cpp
   trunk/utilities/mod2osis.cpp
   trunk/utilities/vs2osisref.cpp
Log:
Moved osis ref parsing to central location
Made thml osis filter actually work.  Outputs WHNU as valid osis, including variants
Turned on variants in mod2osis



Modified: trunk/include/gbfosis.h
===================================================================
--- trunk/include/gbfosis.h	2005-05-06 11:30:57 UTC (rev 1803)
+++ trunk/include/gbfosis.h	2005-05-07 06:26:10 UTC (rev 1804)
@@ -57,8 +57,6 @@
 /** this filter converts GBF text to OSIS text
  */
 class SWDLLEXPORT GBFOSIS : public SWFilter {
-protected:
-	virtual const char *convertToOSIS(const char *, const SWKey *key);
 public:
 	GBFOSIS();
 	virtual ~GBFOSIS();

Modified: trunk/include/thmlosis.h
===================================================================
--- trunk/include/thmlosis.h	2005-05-06 11:30:57 UTC (rev 1803)
+++ trunk/include/thmlosis.h	2005-05-07 06:26:10 UTC (rev 1804)
@@ -28,8 +28,6 @@
 /** this filter converts ThML text to OSIS text
  */
 class SWDLLEXPORT ThMLOSIS : public SWFilter {
-protected:
-	virtual const char *convertToOSIS(const char *, const SWKey *key);
 public:
 	ThMLOSIS();
 	virtual ~ThMLOSIS();

Modified: trunk/include/versekey.h
===================================================================
--- trunk/include/versekey.h	2005-05-06 11:30:57 UTC (rev 1803)
+++ trunk/include/versekey.h	2005-05-07 06:26:10 UTC (rev 1804)
@@ -380,6 +380,12 @@
 	virtual const char *getOSISRef() const;
 	static const int getOSISBookNum(const char *bookab);
 
+	/** Tries to parse a string and convert it into an OSIS reference
+	 * @param inRef reference string to try to parse
+	 * @param defaultKey @see ParseVerseList(..., defaultKey, ...)
+	 */
+	static const char *convertToOSIS(const char *inRef, const SWKey *defaultKey);
+
 	virtual ListKey ParseVerseList(const char *buf, const char *defaultKey = "Genesis 1:1", bool expandRange = false);
 	virtual const char *getRangeText() const;
 	/** Compares another	SWKey object

Modified: trunk/src/keys/versekey.cpp
===================================================================
--- trunk/src/keys/versekey.cpp	2005-05-06 11:30:57 UTC (rev 1803)
+++ trunk/src/keys/versekey.cpp	2005-05-07 06:26:10 UTC (rev 1804)
@@ -1559,4 +1559,55 @@
 	return rangeText;
 }
 
+
+const char *VerseKey::convertToOSIS(const char *inRef, const SWKey *lastKnownKey) {
+	static SWBuf outRef;
+
+	outRef = "";
+
+	VerseKey defLanguage;
+	ListKey verses = defLanguage.ParseVerseList(inRef, (*lastKnownKey), true);
+	const char *startFrag = inRef;
+	for (int i = 0; i < verses.Count(); i++) {
+		VerseKey *element = SWDYNAMIC_CAST(VerseKey, verses.GetElement(i));
+		char buf[5120];
+		char frag[800];
+		char preJunk[800];
+		char postJunk[800];
+		memset(buf, 0, 5120);
+		memset(frag, 0, 800);
+		memset(preJunk, 0, 800);
+		memset(postJunk, 0, 800);
+		while ((*startFrag) && (strchr(" {};,()[].", *startFrag))) {
+			outRef += *startFrag;
+			startFrag++;
+		}
+		if (element) {
+			memmove(frag, startFrag, ((const char *)element->userData - startFrag) + 1);
+			frag[((const char *)element->userData - startFrag) + 1] = 0;
+			int j;
+			for (j = strlen(frag)-1; j && (strchr(" {};,()[].", frag[j])); j--);
+			if (frag[j+1])
+				strcpy(postJunk, frag+j+1);
+			frag[j+1]=0;
+			startFrag += ((const char *)element->userData - startFrag) + 1;
+			sprintf(buf, "<reference osisRef=\"%s-%s\">%s</reference>%s", element->LowerBound().getOSISRef(), element->UpperBound().getOSISRef(), frag, postJunk);
+		}
+		else {
+			memmove(frag, startFrag, ((const char *)verses.GetElement(i)->userData - startFrag) + 1);
+			frag[((const char *)verses.GetElement(i)->userData - startFrag) + 1] = 0;
+			int j;
+			for (j = strlen(frag)-1; j && (strchr(" {};,()[].", frag[j])); j--);
+			if (frag[j+1])
+				strcpy(postJunk, frag+j+1);
+			frag[j+1]=0;
+			startFrag += ((const char *)verses.GetElement(i)->userData - startFrag) + 1;
+			sprintf(buf, "<reference osisRef=\"%s\">%s</reference>%s", VerseKey(*verses.GetElement(i)).getOSISRef(), frag, postJunk);
+		}
+		outRef+=buf;
+	}
+	if (startFrag < (inRef + strlen(inRef)))
+		outRef+=startFrag;
+	return outRef.c_str();
+}
 SWORD_NAMESPACE_END

Modified: trunk/src/modules/filters/gbfosis.cpp
===================================================================
--- trunk/src/modules/filters/gbfosis.cpp	2005-05-06 11:30:57 UTC (rev 1803)
+++ trunk/src/modules/filters/gbfosis.cpp	2005-05-07 06:26:10 UTC (rev 1804)
@@ -29,9 +29,9 @@
 	char token[2048]; //cheesy, we seem to like cheese :)
 	int tokpos = 0;
 	bool intoken = false;
-	bool keeptoken = false;
+	bool keepToken = false;
 	
-	static QuoteStack quoteStack;
+//	static QuoteStack quoteStack;
 
 	SWBuf orig = text;
 	SWBuf tmp;
@@ -40,17 +40,16 @@
 	bool newtext = false;
 	
 	bool suspendTextPassThru = false;
-	bool keepToken = false;
 	bool handled = false;
 	bool newWord = false;
 	bool newText = false;
 	bool lastspace = false;
 	
-	const char* wordStart = text.c_str();
-	const char* wordEnd;
+	const char *wordStart = text.c_str();
+	const char *wordEnd;
 	
-	const char* textStart;
-	const char* textEnd;
+	const char *textStart;
+	const char *textEnd;
 	
 	SWBuf textNode = "";
 
@@ -80,14 +79,12 @@
 			handled = false;
 
 			while (wordStart < (text.c_str() + text.length())) { //hack
-				if (strchr(";, .:?!()'\"", *wordStart) && wordStart[0] && wordStart[1])
+				if (strchr(";,. :?!()'\"", *wordStart) && wordStart[0] && wordStart[1])
 					wordStart++;
 				else break;
 			}			
-			
-			
 			while (wordEnd > wordStart) {
-				if (strchr(" ,;.:?!()'\"", *wordEnd))
+				if (strchr(" ,;:.?!()'\"", *wordEnd))
 					wordEnd--;
 				else break;
 			}
@@ -101,7 +98,7 @@
 			else if (!strncmp(token, "/scripRef", 9)) {
 				tmp = "";
 				tmp.append(textStart, (int)(textEnd - textStart)+1);
-				text += convertToOSIS(tmp.c_str(), key);
+				text += VerseKey::convertToOSIS(tmp.c_str(), key);
 				
 				lastspace = false;
 				suspendTextPassThru = false;
@@ -199,51 +196,48 @@
 			// Strongs numbers
 			else if (*token == 'W' && (token[1] == 'G' || token[1] == 'H')) {	// Strongs
 				bool divineName = false;
-				if (module->isProcessEntryAttributes()) {
-					value = token+1;
-				
-					// normal strongs number
-					//strstrip(val);
-					if (!strncmp(wordStart, "<w ", 3)) {
-						const char *attStart = strstr(wordStart, "lemma");
-						if (attStart) {
-							attStart += 7;
-							
-							buf = "";
-							buf.appendFormatted("strong:%s ", value.c_str());
-						}
-						else { // no lemma attribute
-							attStart = wordStart + 3;
-							
-							buf = "";
-							buf.appendFormatted(buf, "lemma=\"strong:%s\" ", value.c_str());
-						}
+				value = token+1;
+			
+				// normal strongs number
+				//strstrip(val);
+				if (!strncmp(wordStart, "<w ", 3)) {
+					const char *attStart = strstr(wordStart, "lemma");
+					if (attStart) {
+						attStart += 7;
+						
+						buf = "";
+						buf.appendFormatted("strong:%s ", value.c_str());
+					}
+					else { // no lemma attribute
+						attStart = wordStart + 3;
+						
+						buf = "";
+						buf.appendFormatted(buf, "lemma=\"strong:%s\" ", value.c_str());
+					}
 
-						text.insert(attStart - text.c_str(), buf);
+					text.insert(attStart - text.c_str(), buf);
+				}
+				else { //wordStart doesn't point to an existing <w> attribute!
+					if (!strcmp(value.c_str(), "H03068")) {	//divineName
+						buf = "";
+						buf.appendFormatted("<divineName><w lemma=\"strong:%s\">", value.c_str());
+						
+						divineName = true;
 					}
-					else { //wordStart doesn't point to an existing <w> attribute!
-						if (!strcmp(value.c_str(), "H03068")) {	//divineName
-							buf = "";
-							buf.appendFormatted("<divineName><w lemma=\"strong:%s\">", value.c_str());
-							
-							divineName = true;
-						}
-						else {
-							buf = "";
-							buf.appendFormatted("<w lemma=\"strong:%s\">", value.c_str());
-						}
+					else {
+						buf = "";
+						buf.appendFormatted("<w lemma=\"strong:%s\">", value.c_str());
+					}
 
-						text.insert(wordStart - text.c_str(), buf);
+					text.insert(wordStart - text.c_str(), buf);
 
-						if (divineName) {
-							wordStart += 12;
-							text += "</w></divineName>";
-						}
-						else	text += "</w>";
-
-						module->getEntryAttributes()["Word"][wordstr]["Strongs"] = value.c_str();
-						lastspace = false;
+					if (divineName) {
+						wordStart += 12;
+						text += "</w></divineName>";
 					}
+					else	text += "</w>";
+
+					lastspace = false;
 				}
 				handled = true;
 			}
@@ -262,7 +256,7 @@
 						buf = "";
 						buf.appendFormatted("%s:%s ", "robinson", value.c_str());
 					}
-					else {
+					else { // no lemma attribute
 						attStart = wordStart + 3;
 						buf = "";
 						buf.appendFormatted("morph=\"%s:%s\" ", "robinson", value.c_str());
@@ -273,9 +267,7 @@
 				else { //no existing <w> attribute fond
 					buf = "";
 					buf.appendFormatted("<w morph=\"%s:%s\">", "robinson", value.c_str());
-					
 					text.insert(wordStart - text.c_str(), buf);
-					
 					text += "</w>";
 					lastspace = false;
 
@@ -289,21 +281,22 @@
 //					exit(-1);
 				}
 				if (from[1] && strchr(" ,;.:?!()'\"", from[1])) {
-					if (lastspace)
+					if (lastspace) {
 						text--;
+					}
 				}
 				if (newText) {
 					textStart = from+1;
 					newText = false; 
 				}
-//				if (newWord) {wordStart = to; newWord = false; }
 				continue;
 			}
+
 			// if not a strongs token, keep token in text
 			text.appendFormatted("<%s>", token);
 			
 			if (newText) {
-				textStart = text.c_str() + text.length();  //hack, instad of textStart = to;
+				textStart = text.c_str() + text.length();
 				newWord = false; 
 			}
 			continue;
@@ -342,17 +335,13 @@
 	}
 
 	VerseKey *vkey = SWDYNAMIC_CAST(VerseKey, key);
-	if ( vkey ) {
+	if (vkey) {
 		SWBuf ref = "";
-		//char ref[254];
 		if (vkey->Verse()) {
 			ref.appendFormatted("\t\t<verse osisID=\"%s\">", vkey->getOSISRef());
 		}
 		
 		if (ref.length() > 0) {
-			//memmove(text+strlen(ref), text, maxlen-strlen(ref)-1);
-			//memcpy(text, ref, strlen(ref));
-			//to+=strlen(ref);
 			
 			text = ref + text;
 			
@@ -376,59 +365,25 @@
 						tmp.Verse(0);
 //						sprintf(ref, "\t</div>");
 //						pushString(&to, ref);
+/*
 						if (!quoteStack.empty()) {
 							SWLog::getSystemLog()->logError("popping unclosed quote at end of book");
 							quoteStack.clear();
 						}
+*/
 					}
 				}
 			}
-
-//
 //			else if (vkey->Chapter()) {
 //				sprintf(ref, "\t<div type=\"chapter\" osisID=\"%s\">", vkey->getOSISRef());
 //			}
 //			else sprintf(ref, "\t<div type=\"book\" osisID=\"%s\">", vkey->getOSISRef());
-//
 		}
 	}
-//	*to++ = 0;
-//	*to = 0;
-
 	return 0;
 }
 
 
-const char *GBFOSIS::convertToOSIS(const char *inRef, const SWKey *key) {
-	static SWBuf outRef;
-
-	outRef = "";
-
-	VerseKey defLanguage;
-	ListKey verses = defLanguage.ParseVerseList(inRef, (*key), true);
-	const char *startFrag = inRef;
-	for (int i = 0; i < verses.Count(); i++) {
-		VerseKey *element = SWDYNAMIC_CAST(VerseKey, verses.GetElement(i));
-		char buf[5120];
-		char frag[800];
-		if (element) {
-			memmove(frag, startFrag, ((const char *)element->userData - startFrag) + 1);
-			frag[((const char *)element->userData - startFrag) + 1] = 0;
-			startFrag = (const char *)element->userData + 1;
-			sprintf(buf, "<reference osisRef=\"%s-%s\">%s</reference>", element->LowerBound().getOSISRef(), element->UpperBound().getOSISRef(), frag);
-		}
-		else {
-			memmove(frag, startFrag, ((const char *)verses.GetElement(i)->userData - startFrag) + 1);
-			frag[((const char *)verses.GetElement(i)->userData - startFrag) + 1] = 0;
-			startFrag = (const char *)verses.GetElement(i)->userData + 1;
-			sprintf(buf, "<reference osisRef=\"%s\">%s</reference>", VerseKey(*verses.GetElement(i)).getOSISRef(), frag);
-		}
-		outRef+=buf;
-	}
-	return outRef.c_str();
-}
-
-
 QuoteStack::QuoteStack() {
 	clear();
 }

Modified: trunk/src/modules/filters/thmlosis.cpp
===================================================================
--- trunk/src/modules/filters/thmlosis.cpp	2005-05-06 11:30:57 UTC (rev 1803)
+++ trunk/src/modules/filters/thmlosis.cpp	2005-05-07 06:26:10 UTC (rev 1804)
@@ -14,6 +14,7 @@
 #include <versekey.h>
 #include <stdarg.h>
 #include <utilstr.h>
+#include <utilxml.h>
 
 
 SWORD_NAMESPACE_START
@@ -27,29 +28,27 @@
 
 
 char ThMLOSIS::processText(SWBuf &text, const SWKey *key, const SWModule *module) {
-// 	const char *from;
-	
 	char token[2048]; // cheese.  Fix.
 	int tokpos = 0;
 	bool intoken = false;
+	bool keepToken = false;
+
+//	static QuoteStack quoteStack;
 	
-	int len;
 	bool lastspace = false;
 	int word = 1;
 	char val[128];
-	char buf[128];
-	char wordstr[5];
+	SWBuf buf;
 	char *valto;
 	char *ch;
 	
-	const char*wordStart = text.c_str();
-	const char* wordEnd;
+	const char *wordStart = text.c_str();
+	const char *wordEnd;
 	
 	const char *textStart;
 	const char *textEnd;
 		
 	bool suspendTextPassThru = false;
-	bool keepToken = false;
 	bool handled = false;
 	bool newText = false;
 	bool newWord = false;
@@ -62,6 +61,13 @@
 
 	text = "";
 	for (from = orig.c_str(); *from; ++from) {
+
+		// handle silly <variant word> items in greek whnu, remove when module is fixed
+		if ((*from == '<') && (*(from+1) < 0)) {
+			text += "&lt;";
+			continue;
+		}
+
 		if (*from == '<') { //start of new token detected
 			intoken = true;
 			tokpos = 0;
@@ -75,6 +81,12 @@
 			continue;
 		}
 		
+		// handle silly <variant word> items in greek whnu, remove when module is fixed
+		if ((*from == '>') && (*(from-1) < 0)) {
+			text += "&gt;";
+			continue;
+		}
+
 		if (*from == '>') {	// process tokens
 			intoken = false;
 			keepToken = false;
@@ -82,10 +94,8 @@
 			newWord = true;
 			handled = false;
 
-// 			while (wordStart < (text+maxlen)) {
 			while (wordStart < (text.c_str() + text.length())) { //hack
-//				if (strchr(" ,;.?!()'\"", *wordStart))
-				if (strchr(";,: .?!()'\"", *wordStart) && wordStart[0] && wordStart[1])
+				if (strchr(";,. :?!()'\"", *wordStart) && wordStart[0] && wordStart[1])
 					wordStart++;
 				else break;
 			}
@@ -95,6 +105,21 @@
 				else break;
 			}
 
+			// variants
+			if (!strncmp(token, "div type=\"variant\"", 18)) {
+				XMLTag tag = token;
+				text.append("<seg type=\"x-variant\"");
+				SWBuf cls = "x-class:";
+				cls += tag.getAttribute("class");
+				if (cls.length()>8)
+					text.appendFormatted(" subType=\"%s\"", cls.c_str());
+
+				text += ">";
+				divEnd = "</seg>";
+				newText = true;
+				lastspace = false;
+				handled = true;
+			}
 			// section titles
 			if (!strcmp(token, "div class=\"sechead\"")) {
 // 				pushString(&to, "<title>");
@@ -122,7 +147,7 @@
 				tmp = "";
 				tmp.append(textStart, (int)(textEnd - textStart)+1);
 				//pushString(&to, convertToOSIS(tmp.c_str(), key));
-				text.append(convertToOSIS(tmp.c_str(), key));
+				text.append(VerseKey::convertToOSIS(tmp.c_str(), key));
 				suspendTextPassThru = false;
 				handled = true;
 			}
@@ -228,101 +253,115 @@
 
 			// Strongs numbers
 			else	if (!strnicmp(token, "sync type=\"Strongs\" ", 20)) {	// Strongs
-/*				if (module->isProcessEntryAttributes()) {
-					valto = val;
-					for (unsigned int i = 27; token[i] != '\"' && i < 150; i++)
-						*valto++ = token[i];
-					*valto = 0;
-					if (atoi((!isdigit(*val))?val+1:val) < 5627) {
-						// normal strongs number
-						strstrip(val);
-						sprintf(buf, "<w lemma=\"x-Strong:%s\">", val);
-						memmove(wordStart+strlen(buf), wordStart, (to-wordStart)+1);
-						memcpy(wordStart, buf, strlen(buf));
-						to+=strlen(buf);
-						pushString(&to, "</w>");
-						module->getEntryAttributes()["Word"][wordstr]["Strongs"] = val;
-//						tmp = "";
-//						tmp.append(textStart, (int)(wordEnd - wordStart));
-//						module->getEntryAttributes()["Word"][wordstr]["Text"] = tmp;
+				valto = val;
+				for (unsigned int i = 27; token[i] != '\"' && i < 150; i++)
+					*valto++ = token[i];
+				*valto = 0;
+				if (atoi((!isdigit(*val))?val+1:val) < 5627) {
+					// normal strongs number
+					strstrip(val);
+
+					if (!strncmp(wordStart, "<w ", 3)) {
+						const char *attStart = strstr(wordStart, "lemma");
+						if (attStart) { //existing morph attribute, append this one to it
+							attStart += 7;
+							buf = "";
+							buf.appendFormatted("strong:%s ", val);
+						}
+						else { // no lemma attribute
+							attStart = wordStart + 3;
+							buf = "";
+							buf.appendFormatted(buf, "lemma=\"strong:%s\" ", val);
+						}
+
+						text.insert(attStart - text.c_str(), buf);
 					}
-					else {
-						// verb morph
-						sprintf(wordstr, "%03d", word-1);
-						module->getEntryAttributes()["Word"][wordstr]["Morph"] = val;
+					else { //wordStart doesn't point to an existing <w> attribute!
+						buf = "";
+						buf.appendFormatted("<w lemma=\"strong:%s\">", val);
+						text.insert(wordStart - text.c_str(), buf);
+						text += "</w>";
+						lastspace = false;
 					}
-				}*/
+				}
+				// OLB verb morph, leave it out of OSIS tag
+				else {
+				}
 				handled = true;
 			}
 
 			// Morphology
 			else	if (!strncmp(token, "sync type=\"morph\"", 17)) {
-/*				for (ch = token+17; *ch; ch++) {
+				SWBuf cls = "";
+				SWBuf morph = "";
+				for (ch = token+17; *ch; ch++) {
 					if (!strncmp(ch, "class=\"", 7)) {
 						valto = val;
 						for (unsigned int i = 7; ch[i] != '\"' && i < 127; i++)
 							*valto++ = ch[i];
 						*valto = 0;
-						sprintf(wordstr, "%03d", word-1);
 						strstrip(val);
-						module->getEntryAttributes()["Word"][wordstr]["MorphClass"] = val;
+						cls = val;
 					}
 					if (!strncmp(ch, "value=\"", 7)) {
 						valto = val;
 						for (unsigned int i = 7; ch[i] != '\"' && i < 127; i++)
 							*valto++ = ch[i];
 						*valto = 0;
-						sprintf(wordstr, "%03d", word-1);
 						strstrip(val);
-						module->getEntryAttributes()["Word"][wordstr]["Morph"] = val;
+						morph = val;
 					}
 				}
 				if (!strncmp(wordStart, "<w ", 3)) {
+					const char *attStart = strstr(wordStart, "morph");
+					if (attStart) { //existing morph attribute, append this one to it
+						attStart += 7;
+						buf = "";
+						buf.appendFormatted("%s:%s ", ((cls.length())?cls.c_str():"robinson"), morph.c_str());
+					}
+					else { // no lemma attribute
+						attStart = wordStart + 3;
+						buf = "";
+						buf.appendFormatted("morph=\"%s:%s\" ", ((cls.length())?cls.c_str():"robinson"), morph.c_str());
+					}
+					
+					text.insert(attStart - text.c_str(), buf); //hack, we have to
+				}
+				else { //no existing <w> attribute fond
+					buf = "";
+					buf.appendFormatted("<w morph=\"%s:%s\">", ((cls.length())?cls.c_str():"robinson"), morph.c_str());
+					text.insert(wordStart - text.c_str(), buf);
+					text += "</w>";
+					lastspace = false;
 
-					const char *cls = "Unknown", *morph;
-
-					if (module->getEntryAttributes()["Word"][wordstr]["Morph"].size() > 0) {
-						if (module->getEntryAttributes()["Word"][wordstr]["MorphClass"].size() > 0)
-							cls = module->getEntryAttributes()["Word"][wordstr]["MorphClass"].c_str();
-						morph = module->getEntryAttributes()["Word"][wordstr]["Morph"].c_str();
-					
-						sprintf(buf, "morph=\"x-%s:%s\" ", cls, morph);
-						memmove(wordStart+3+strlen(buf), wordStart+3, (to-wordStart)+1);
-						memcpy(wordStart+3, buf, strlen(buf));
-						to+=strlen(buf);
-					}
-				}*/
+				}
 				handled = true;
 			}
 
-			if (!keepToken) {	// if we don't want strongs
+			if (!keepToken) {
 				if (!handled) {
-					SWLog::getSystemLog()->logError("Unprocessed Token: <%s>", token);
+					SWLog::getSystemLog()->logError("Unprocessed Token: <%s> in key %s", token, key ? (const char*)*key : "<unknown>");
 //					exit(-1);
 				}
-				if (strchr(" ,:;.?!()'\"", from[1])) {
+				if (from[1] && strchr(" ,;.:?!()'\"", from[1])) {
 					if (lastspace) {
-						text--;//to--;
+						text--;
 					}
 				}
 				if (newText) {
 					textStart = from+1; 
 					newText = false; 
 				}
-//				if (newWord) {wordStart = to; newWord = false; }
-					continue;
+				continue;
 			}
 			
 			// if not a strongs token, keep token in text
-			text.append('<');
-			text.append(token);
-			text.append('>');
+			text.appendFormatted("<%s>", token);
 			
 			if (newText) {
-				textStart = text.c_str()+text.length(); 
+				textStart = text.c_str() + text.length(); 
 				newWord = false; 
 			}
-//			if (newWord) {wordStart = to; newWord = false; }
 			continue;
 		}
 		if (intoken) {
@@ -332,36 +371,40 @@
 			}
 		}
 		else	{
-			if (newWord && (*from != ' ')) {
-				// wordStart = to; 
-				wordStart = text.c_str()+text.length();
-				newWord = false; 
-// 				memset(to, 0, 10); 
+			switch (*from) {
+			case '\'':
+			case '\"':
+			case '`':
+//				quoteStack.handleQuote(fromStart, from, &to);
+				text += *from;
+				//from++; //this line removes chars after an apostrophe! Needs fixing.
+				break;
+			default:
+				if (newWord && (*from != ' ')) {
+					wordStart = text.c_str() + text.length();
+					newWord = false;
+					
+					//fix this if required?
+					//memset(to, 0, 10); 
+					
+				}
+				
+				if (!suspendTextPassThru) {
+					text += (*from);
+					lastspace = (*from == ' ');
+				}
 			}
-			if (!suspendTextPassThru) {
-// 				*to++ = *from;
-				text.append(*from);
-				lastspace = (*from == ' ');
-			}
 		}
 	}
 
 	VerseKey *vkey = SWDYNAMIC_CAST(VerseKey, key);
 	if (vkey) {
-// 		char ref[254];
-		SWBuf ref;
+		SWBuf ref = "";
 		if (vkey->Verse()) {
-			ref.setFormatted("<verse osisID=\"%s\">", vkey->getOSISRef());
+			ref.appendFormatted("\t\t<verse osisID=\"%s\">", vkey->getOSISRef());
 		}
-		else {
-// 			*ref = 0;
-			ref = "";
-		}
 			
-		if (*ref) {
-/*			memmove(text+strlen(ref), text, maxlen-strlen(ref)-1);
-			memcpy(text, ref, strlen(ref));
-			to+=strlen(ref);*/
+		if (ref.length() > 0) {
 			
 			text = ref + text;
 			
@@ -371,9 +414,7 @@
 				tmp.AutoNormalize(0);
 				tmp.Headings(1);
 				
-// 				sprintf(ref, "</verse>");
-// 				pushString(&to, ref);
-				text.append("</verse>");
+				text += "</verse>";
 				
 				tmp = MAXVERSE;
 				if (*vkey == tmp) {
@@ -387,50 +428,23 @@
 						tmp.Verse(0);
 //						sprintf(ref, "\t</div>");
 //						pushString(&to, ref);
+/*
+						if (!quoteStack.empty()) {
+							SWLog::getSystemLog()->logError("popping unclosed quote at end of book");
+							quoteStack.clear();
+						}
+*/
 					}
 				}
 			}
-
-//			else if (vkey->Chapter())
+//			else if (vkey->Chapter()) {
 //				sprintf(ref, "\t<div type=\"chapter\" osisID=\"%s\">", vkey->getOSISRef());
+//			}
 //			else sprintf(ref, "\t<div type=\"book\" osisID=\"%s\">", vkey->getOSISRef());
 		}
 	}
-	
-// 	*to++ = 0;
-// 	*to = 0;
-
 	return 0;
 }
 
 
-const char *ThMLOSIS::convertToOSIS(const char *inRef, const SWKey *key) {
-	static SWBuf outRef;
-
-	outRef = "";
-
-	VerseKey defLanguage;
-	ListKey verses = defLanguage.ParseVerseList(inRef, (*key), true);
-	const char *startFrag = inRef;
-	for (int i = 0; i < verses.Count(); i++) {
-		VerseKey *element = SWDYNAMIC_CAST(VerseKey, verses.GetElement(i));
-		char buf[5120];
-		char frag[5120];
-		if (element) {
-			memmove(frag, startFrag, ((const char *)element->userData - startFrag) + 1);
-			frag[((const char *)element->userData - startFrag) + 1] = 0;
-			startFrag = (const char *)element->userData + 1;
-			sprintf(buf, "<reference osisRef=\"%s-%s\">%s</reference>", element->LowerBound().getOSISRef(), element->UpperBound().getOSISRef(), frag);
-		}
-		else {
-			memmove(frag, startFrag, ((const char *)verses.GetElement(i)->userData - startFrag) + 1);
-			frag[((const char *)verses.GetElement(i)->userData - startFrag) + 1] = 0;
-			startFrag = (const char *)verses.GetElement(i)->userData + 1;
-			sprintf(buf, "<reference osisRef=\"%s\">%s</reference>", VerseKey(*verses.GetElement(i)).getOSISRef(), frag);
-		}
-		outRef+=buf;
-	}
-	return outRef.c_str();
-}
-
 SWORD_NAMESPACE_END

Modified: trunk/utilities/mod2osis.cpp
===================================================================
--- trunk/utilities/mod2osis.cpp	2005-05-06 11:30:57 UTC (rev 1803)
+++ trunk/utilities/mod2osis.cpp	2005-05-07 06:26:10 UTC (rev 1804)
@@ -51,6 +51,9 @@
 		if (find(values.begin(), values.end(), "On") != values.end()) {
 			mgr.setGlobalOption(it->c_str(), "On");
 		}
+		if (find(values.begin(), values.end(), "All Readings") != values.end()) {
+			mgr.setGlobalOption(it->c_str(), "All Readings");
+		}
 	}
 
 //	mgr.setGlobalOption("Strong's Numbers", "Off");

Modified: trunk/utilities/vs2osisref.cpp
===================================================================
--- trunk/utilities/vs2osisref.cpp	2005-05-06 11:30:57 UTC (rev 1803)
+++ trunk/utilities/vs2osisref.cpp	2005-05-07 06:26:10 UTC (rev 1804)
@@ -29,57 +29,6 @@
 using std::cout;
 
 
-const char *convertToOSIS(const char *inRef, const SWKey *key) {
-	static SWBuf outRef;
-
-	outRef = "";
-
-	VerseKey defLanguage;
-	ListKey verses = defLanguage.ParseVerseList(inRef, (*key), true);
-	const char *startFrag = inRef;
-	for (int i = 0; i < verses.Count(); i++) {
-		VerseKey *element = SWDYNAMIC_CAST(VerseKey, verses.GetElement(i));
-		char buf[5120];
-		char frag[800];
-		char preJunk[800];
-		char postJunk[800];
-		memset(buf, 0, 5120);
-		memset(frag, 0, 800);
-		memset(preJunk, 0, 800);
-		memset(postJunk, 0, 800);
-		while ((*startFrag) && (strchr(" {};,()[].", *startFrag))) {
-			outRef += *startFrag;
-			startFrag++;
-		}
-		if (element) {
-			memmove(frag, startFrag, ((const char *)element->userData - startFrag) + 1);
-			frag[((const char *)element->userData - startFrag) + 1] = 0;
-			int j;
-			for (j = strlen(frag)-1; j && (strchr(" {};,()[].", frag[j])); j--);
-			if (frag[j+1])
-				strcpy(postJunk, frag+j+1);
-			frag[j+1]=0;
-			startFrag += ((const char *)element->userData - startFrag) + 1;
-			sprintf(buf, "<reference osisRef=\"%s-%s\">%s</reference>%s", element->LowerBound().getOSISRef(), element->UpperBound().getOSISRef(), frag, postJunk);
-		}
-		else {
-			memmove(frag, startFrag, ((const char *)verses.GetElement(i)->userData - startFrag) + 1);
-			frag[((const char *)verses.GetElement(i)->userData - startFrag) + 1] = 0;
-			int j;
-			for (j = strlen(frag)-1; j && (strchr(" {};,()[].", frag[j])); j--);
-			if (frag[j+1])
-				strcpy(postJunk, frag+j+1);
-			frag[j+1]=0;
-			startFrag += ((const char *)verses.GetElement(i)->userData - startFrag) + 1;
-			sprintf(buf, "<reference osisRef=\"%s\">%s</reference>%s", VerseKey(*verses.GetElement(i)).getOSISRef(), frag, postJunk);
-		}
-		outRef+=buf;
-	}
-	if (startFrag < (inRef + strlen(inRef)))
-		outRef+=startFrag;
-	return outRef.c_str();
-}
-
 int main(int argc, char **argv)
 {
         if (argc < 2) {
@@ -101,7 +50,7 @@
                 verseKey = "Gen 1:1";
         }
 
-        std::cout << convertToOSIS(verseString, &verseKey) << "\n";
+        std::cout << VerseKey::convertToOSIS(verseString, &verseKey) << "\n";
 
 	return 0;
 }



More information about the sword-cvs mailing list