[sword-svn] r1783 - in trunk: include scripts src/modules/filters src/utilfuns tests/cppunit utilities

scribe at crosswire.org scribe at crosswire.org
Fri Apr 29 17:49:01 MST 2005


Author: scribe
Date: 2005-04-29 17:49:01 -0700 (Fri, 29 Apr 2005)
New Revision: 1783

Modified:
   trunk/include/swbuf.h
   trunk/scripts/mkswordtar
   trunk/src/modules/filters/gbfosis.cpp
   trunk/src/modules/filters/osisrtf.cpp
   trunk/src/utilfuns/swbuf.cpp
   trunk/tests/cppunit/swbuf_test.cpp
   trunk/utilities/mod2osis.cpp
   trunk/utilities/osis2mod.cpp
Log:
Make SWBuf::insert match std::string::insert signature
Various other misc fixes and improvments.
Still in the middle of changes to osis2mod



Modified: trunk/include/swbuf.h
===================================================================
--- trunk/include/swbuf.h	2005-04-30 00:07:50 UTC (rev 1782)
+++ trunk/include/swbuf.h	2005-04-30 00:49:01 UTC (rev 1783)
@@ -228,27 +228,32 @@
 	/** 
 	* SWBuf::insert - inserts the given string at position into this string
 	* @param pos The position where to insert. pos=0 inserts at the beginning, pos=1 after the first char, etc. Using pos=length() is the same as calling append(s)
-	* @param str Insert this.
+	* @param str string to be inserted
+	* @param start start from this position in the string to be inserted
 	* @param max Insert only max chars.
 	*/
-	void insert(unsigned long pos, const char* str, signed long max = -1 );
+	void insert(unsigned long pos, const char* str, unsigned long start = 0, signed long max = -1);
+
 	/** 
 	* SWBuf::insert - inserts the given string at position into this string
 	* @param pos The position where to insert. pos=0 inserts at the beginning, pos=1 after the first char, etc. Using pos=length() is the same as calling append(s)
-	* @param str Insert this.
+	* @param str string to be inserted
+	* @param start start from this position in the string to be inserted
 	* @param max Insert only max chars.
 	*/
-	void insert(unsigned long pos, const SWBuf &str, signed long max = -1 ) {
-		insert(pos, str.c_str(), max);
+	inline void insert(unsigned long pos, const SWBuf &str, unsigned long start = 0, signed long max = -1) {
+		insert(pos, str.c_str(), start, max);
 	};
+
 	/** 
 	* SWBuf::insert - inserts the given character at position into this string
 	* @param pos The position where to insert. pos=0 inserts at the beginning, pos=1 after the first char, etc. Using pos=length() is the same as calling append(s)
 	* @param c Insert this.
 	*/
-	void insert(unsigned long pos, char c) {
+	inline void insert(unsigned long pos, char c) {
 		insert(pos, SWBuf(c));
 	}
+
 	/** SWBuf::getRawData
 	*
 	* @warning be careful! Probably setSize needs to be called in conjunction before and maybe after

Modified: trunk/scripts/mkswordtar
===================================================================
--- trunk/scripts/mkswordtar	2005-04-30 00:07:50 UTC (rev 1782)
+++ trunk/scripts/mkswordtar	2005-04-30 00:49:01 UTC (rev 1783)
@@ -1,6 +1,6 @@
 #!/bin/sh
 REV=`cd ..;basename \`pwd ..\`|cut -d\- -f2`
-SWORDVER=`grep "define SWORDVER" ../include/swversion.h |cut -f2 -d"\""`
+SWORDVER=`grep "define VERSI" ../include/config.h |cut -f2 -d"\""`
 
 if test `echo $REV` == `echo $SWORDVER`; then 
 	chmod +x *
@@ -10,7 +10,7 @@
 	cd ..; ./autogen.sh
 	cd ..; tar -v -c -p -s -z --exclude sword-$REV/bin -X sword-$REV/modlist -f sword-$REV.tar.gz sword-$REV/*
 else
-	echo $"Directory version is $REV, but swversion.h has $SWORDVER"
+	echo $"Directory version is $REV, but config.h has $SWORDVER"
 	exit 1
 
 fi

Modified: trunk/src/modules/filters/gbfosis.cpp
===================================================================
--- trunk/src/modules/filters/gbfosis.cpp	2005-04-30 00:07:50 UTC (rev 1782)
+++ trunk/src/modules/filters/gbfosis.cpp	2005-04-30 00:49:01 UTC (rev 1783)
@@ -253,27 +253,30 @@
 			}
 
 			// Morphology
-			else if (*token == 'W' && token[1] == 'T' && (token[2] == 'G' || token[2] == 'H')) {	// Strongs
-				value = token+2;
+			else if (*token == 'W' && token[1] == 'T') {
+				if (token[2] == 'G' || token[2] == 'H') {	// Strongs
+					value = token+2;
+				}
+				else value = token+1;
 				
 				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 ", "strongsMorph", value.c_str());
+						buf.appendFormatted("%s:%s ", "robinson", value.c_str());
 					}
 					else {
 						attStart = wordStart + 3;
 						buf = "";
-						buf.appendFormatted("morph=\"%s:%s\" ", "strongsMorph", value.c_str());
+						buf.appendFormatted("morph=\"%s:%s\" ", "robinson", value.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\">", "strongsMorph", value.c_str());
+					buf.appendFormatted("<w morph=\"%s:%s\">", "robinson", value.c_str());
 					
 					text.insert(wordStart - text.c_str(), buf);
 					

Modified: trunk/src/modules/filters/osisrtf.cpp
===================================================================
--- trunk/src/modules/filters/osisrtf.cpp	2005-04-30 00:07:50 UTC (rev 1782)
+++ trunk/src/modules/filters/osisrtf.cpp	2005-04-30 00:49:01 UTC (rev 1783)
@@ -226,7 +226,7 @@
 		// <catchWord> & <rdg> tags (italicize)
 		else if (!strcmp(tag.getName(), "rdg") || !strcmp(tag.getName(), "catchWord")) {
 			if ((!tag.isEndTag()) && (!tag.isEmpty())) {
-				buf += "{\i1 ";
+				buf += "{\\i1 ";
 			}
 			else if (tag.isEndTag()) {
 				buf += "}";

Modified: trunk/src/utilfuns/swbuf.cpp
===================================================================
--- trunk/src/utilfuns/swbuf.cpp	2005-04-30 00:07:50 UTC (rev 1782)
+++ trunk/src/utilfuns/swbuf.cpp	2005-04-30 00:49:01 UTC (rev 1783)
@@ -179,10 +179,11 @@
 	va_end(argptr);
 }
 
-void SWBuf::insert(unsigned long pos, const char* str, signed long max) {
+void SWBuf::insert(unsigned long pos, const char* str, unsigned long start, signed long max) {
 // 	if (!str) //A null string was passed
 // 		return;
 
+	str += start;
 	int len = (max > -1) ? max : strlen(str);
 
 	if (!len || (pos > length())) //nothing to do, return

Modified: trunk/tests/cppunit/swbuf_test.cpp
===================================================================
--- trunk/tests/cppunit/swbuf_test.cpp	2005-04-30 00:07:50 UTC (rev 1782)
+++ trunk/tests/cppunit/swbuf_test.cpp	2005-04-30 00:49:01 UTC (rev 1783)
@@ -70,7 +70,7 @@
 		for (int i = 0; i < 5000; ++i) {
 			t.insert(0, "a");
 			t.insert(1, "b");
-			t.insert(2, "ccccccc", 1); //only one c
+			t.insert(2, "ccccccc", 0, 1); //only one c
 		}		
 		CPPUNIT_ASSERT( t.length() == 3*5000+3 );
 		

Modified: trunk/utilities/mod2osis.cpp
===================================================================
--- trunk/utilities/mod2osis.cpp	2005-04-30 00:07:50 UTC (rev 1782)
+++ trunk/utilities/mod2osis.cpp	2005-04-30 00:49:01 UTC (rev 1783)
@@ -59,8 +59,8 @@
 		}
 	}
 
-	mgr.setGlobalOption("Strong's Numbers", "Off");
-	mgr.setGlobalOption("Morphological Tags", "Off");
+//	mgr.setGlobalOption("Strong's Numbers", "Off");
+//	mgr.setGlobalOption("Morphological Tags", "Off");
 
 	ModMap::iterator it = mgr.Modules.find(argv[1]);
 	if (it == mgr.Modules.end()) {

Modified: trunk/utilities/osis2mod.cpp
===================================================================
--- trunk/utilities/osis2mod.cpp	2005-04-30 00:07:50 UTC (rev 1782)
+++ trunk/utilities/osis2mod.cpp	2005-04-30 00:49:01 UTC (rev 1783)
@@ -11,6 +11,7 @@
 #include <unistd.h>
 #endif
 
+#include <utilstr.h>
 #include <swmgr.h>
 #include <rawtext.h>
 #include <iostream>
@@ -74,21 +75,23 @@
 	return !len;
 }
 
+
 char* deleteSubverses(char *buf) {
-        // remove subverse elements from osisIDs
-        // (this is a hack and should be handled better with VerseKey2)
-        for (int i = 0; buf[i]; i++) {
+	// remove subverse elements from osisIDs
+	// (this is a hack and should be handled better with VerseKey2)
+	for (int i = 0; buf[i]; i++) {
 		if (buf[i] == '!') {
 			while (buf[i] && buf[i] != ' ') {
-                        	buf[i] = ' ';
-                               	i++;
-                        }
-                        i--;
-                }
-        }
-        return buf;
+				buf[i] = ' ';
+				i++;
+			}
+			i--;
+		}
+	}
+	return buf;
 }
 
+
 bool isKJVRef(const char *buf) {
 	VerseKey vk, test;
 	vk.AutoNormalize(0);
@@ -124,22 +127,22 @@
 	VerseKey saveKey;
 	saveKey.AutoNormalize(0);
 	saveKey.Headings(1);
-        saveKey = key;
+	saveKey = key;
 
-        if (!isKJVRef(key)) {
+	if (!isKJVRef(key)) {
 		makeKJVRef(key);
-        }
+	}
 
 	SWBuf currentText = module->getRawEntry();
 	if (currentText.length()) {
-               	if (!suppressOutput) {
-                	cout << "Overwriting entry: " << key << endl;
-                }
+		if (!suppressOutput) {
+			cout << "Overwriting entry: " << key << endl;
+		}
 		text = currentText + " " + text;
-        }
+	}
 	module->setEntry(text);
 
-        key = saveKey;
+	key = saveKey;
 }
 
 void linkToEntry(VerseKey& dest) {
@@ -186,6 +189,8 @@
 // 		printf("text-lastTitle:	%s\n", text.c_str()+titleOffset);
 		return false; //don't add </title> to the text itself
 	}
+
+	// BOOK START
 	if (((!strcmp(token.getName(), "div")) && (!token.isEndTag() && !(token.getAttribute("eID"))) && (token.getAttribute("osisID"))) && (!strcmp(token.getAttribute("type"), "book"))) {
         	inVerse = false;
 		if (inHeader) {	// this one should never happen, but just in case
@@ -204,74 +209,87 @@
 		headerType = "book";
 		lastTitle = "";
 		text = "";
-	}
-	else if ((((!strcmp(token.getName(), "div")) && (!token.isEndTag()) && (token.getAttribute("osisID"))) && (!strcmp(token.getAttribute("type"), "chapter"))) || ((!strcmp(token.getName(), "chapter")) && (!token.isEndTag() || (token.getAttribute("eID"))) && (token.getAttribute("osisID")))) {
-        	inVerse = false;
-		if (inHeader) {
-//			cout << "HEADING ";
-			writeEntry(*currentVerse, text);
-			inHeader = false;
-		}
 
-		*currentVerse = token.getAttribute("osisID");
-		currentVerse->Verse(0);
-		inHeader = true;
-		headerType = "chap";
-		lastTitle = "";
-		text = "";
+		return true;
 	}
-	else if ((!strcmp(token.getName(), "verse")) && (!token.isEndTag() && !(token.getAttribute("eID")))) {
-		inVerse = true;
-		if (inHeader) {
-			//make sure we don't insert the preverse title which belongs to the first verse of this chapter!
-			const char* chapterTagEnd = strchr(text.c_str(), '>');
-			const char* titleTagStart = strstr(text.c_str(), "<title");
 
-			if (chapterTagEnd+1 == titleTagStart) {
-				const char* titleTagEnd = strstr(text.c_str(), "</title>");
-				while (strstr(titleTagEnd+8, "</title>")) {
-					titleTagEnd = strstr(titleTagEnd+8, "</title>");
-				}
 
-				
-				const char* textEnd = text.c_str() + text.length();
-				if (titleTagEnd+8 == textEnd) {
-					text.setSize(chapterTagEnd+1-text.c_str()); //only insert the <chapter...> part
-				}
+	// START TAG WITH OSIS ID
+	else if ((!token.isEndTag()) && (!token.getAttribute("eID")) && (token.getAttribute("osisID")))
+
+		// CHAPTER START
+		if (((!strcmp(token.getName(), "div")) && (!strcmp(token.getAttribute("type"), "chapter")))
+				|| (!strcmp(token.getName(), "chapter"))
+				) {
+			inVerse = false;
+			if (inHeader) {
+	//			cout << "HEADING ";
+				writeEntry(*currentVerse, text);
+				inHeader = false;
 			}
-			
-// 			cout << "HEADING "<< text.c_str() << endl;
-			writeEntry(*currentVerse, text);
-			
+
+			*currentVerse = token.getAttribute("osisID");
+			currentVerse->Verse(0);
+			inHeader = true;
+			headerType = "chap";
+			lastTitle = "";
 			text = "";
-			inHeader = false;
+
+			return true;
 		}
 
-		string str = token.getAttribute("osisID");
-                char *subverseBuf = new char[str.length()+1];
-                strcpy(subverseBuf, str.c_str());
-		str = deleteSubverses(subverseBuf);
-                delete []subverseBuf;
+		// VERSE START
+		else if (!strcmp(token.getName(), "verse")) {
+			inVerse = true;
+			if (inHeader) {
+				//make sure we don't insert the preverse title which belongs to the first verse of this chapter!
+				const char* chapterTagEnd = strchr(text.c_str(), '>');
+				const char* titleTagStart = strstr(text.c_str(), "<title");
 
-		*currentVerse = str.c_str();
+				if (chapterTagEnd+1 == titleTagStart) {
+					const char* titleTagEnd = strstr(text.c_str(), "</title>");
+					while (strstr(titleTagEnd+8, "</title>")) {
+						titleTagEnd = strstr(titleTagEnd+8, "</title>");
+					}
 
-		int pos = 0;
-		while ((pos = str.find(' ', pos)) != string::npos) {
-			str.replace(pos, 1, ";");
+					
+					const char* textEnd = text.c_str() + text.length();
+					if (titleTagEnd+8 == textEnd) {
+						text.setSize(chapterTagEnd+1-text.c_str()); //only insert the <chapter...> part
+					}
+				}
+				
+	// 			cout << "HEADING "<< text.c_str() << endl;
+				writeEntry(*currentVerse, text);
+			
+				text = "";
+				inHeader = false;
+			}
+
+			char *subverseBuf = 0;
+			stdstr(&subverseBuf, token.getAttribute("osisID"));
+			deleteSubverses(subverseBuf);
+			*currentVerse = subverseBuf;
+
+		char *pos = 0;
+		while ((pos = strchr(pos, ' '))) {
+			*pos = ';';
 		}
 
 		//cout << "set the list\n" << token.getAttribute("osisID");
-		lastVerseIDs = currentVerse->ParseVerseList(str.c_str());
+		lastVerseIDs = currentVerse->ParseVerseList(subverseBuf);
 //		if (lastVerseIDs.Count() > 1)
 //			cout << "count is" << lastVerseIDs.Count();
 
 		if (lastVerseIDs.Count())
 			*currentVerse = lastVerseIDs.getElement(0)->getText();
 
-		text.append( token );
+//		text.append(token);
 
 		return true;
 	}
+
+	// VERSE END
 	else if ((!strcmp(token.getName(), "verse")) && (token.isEndTag() || (token.getAttribute("eID")))) {
         	inVerse = false;
 		if (lastTitle.length()) {
@@ -328,7 +346,7 @@
 		text = "";
 		return true;
 	}
-        else if (!inVerse && (token.isEndTag() || (token.getAttribute("eID"))) && (!strcmp(token.getName(), "p") || !strcmp(token.getName(), "div") || !strcmp(token.getName(), "q")  || !strcmp(token.getName(), "l") || !strcmp(token.getName(), "lg"))) {
+	else if (!inVerse && (token.isEndTag() || (token.getAttribute("eID"))) && (!strcmp(token.getName(), "p") || !strcmp(token.getName(), "div") || !strcmp(token.getName(), "q")  || !strcmp(token.getName(), "l") || !strcmp(token.getName(), "lg"))) {
      
 // we really should decide how to handle end tags /e.g. of a chapter). There's no way for frontends to
 // see to what OSIS tag the end tag (which is added to the verse text!) belongs. It mixes up the rendering as a result 
@@ -402,7 +420,7 @@
 				// take this isalpha if out to check for bugs in text
 				if ((isalpha(token[1])) || (isalpha(token[2]))) {
 					if (!handleToken(text, token.c_str())) {
-						text.append( token );
+						text.append(token);
 					}
 				}
 				continue;



More information about the sword-cvs mailing list