[sword-svn] r2187 - in trunk: . examples/classes examples/cmdline include src/mgr src/modules src/modules/common src/modules/filters src/modules/genbook/rawgenbook src/modules/texts/ztext

scribe at www.crosswire.org scribe at www.crosswire.org
Tue Jul 22 04:00:17 MST 2008


Author: scribe
Date: 2008-07-22 04:00:16 -0700 (Tue, 22 Jul 2008)
New Revision: 2187

Added:
   trunk/examples/cmdline/outplain.cpp
Removed:
   trunk/examples/classes/outplain.cpp
Modified:
   trunk/configure.ac
   trunk/examples/classes/Makefile
   trunk/examples/cmdline/Makefile.am
   trunk/include/osisplain.h
   trunk/include/rawstr.h
   trunk/include/rawstr4.h
   trunk/include/rawverse.h
   trunk/include/rawverse4.h
   trunk/include/swmodule.h
   trunk/include/zstr.h
   trunk/include/zverse.h
   trunk/src/mgr/localemgr.cpp
   trunk/src/modules/common/rawstr.cpp
   trunk/src/modules/common/rawstr4.cpp
   trunk/src/modules/common/rawverse.cpp
   trunk/src/modules/common/rawverse4.cpp
   trunk/src/modules/common/zstr.cpp
   trunk/src/modules/common/zverse.cpp
   trunk/src/modules/filters/osisplain.cpp
   trunk/src/modules/genbook/rawgenbook/rawgenbook.cpp
   trunk/src/modules/swmodule.cpp
   trunk/src/modules/texts/ztext/ztext.cpp
   trunk/usrinst.sh
Log:
Optimizations and bug fixes


Modified: trunk/configure.ac
===================================================================
--- trunk/configure.ac	2008-07-21 11:28:48 UTC (rev 2186)
+++ trunk/configure.ac	2008-07-22 11:00:16 UTC (rev 2187)
@@ -90,8 +90,8 @@
     AM_CXXFLAGS="-O0 -Wall"
   fi
 else
-  AM_CFLAGS="-O2"
-  AM_CXXFLAGS="-O2"
+  AM_CFLAGS="-O3"
+  AM_CXXFLAGS="-O3"
 fi
 
 # ---------------------------------------------------------------------

Modified: trunk/examples/classes/Makefile
===================================================================
--- trunk/examples/classes/Makefile	2008-07-21 11:28:48 UTC (rev 2186)
+++ trunk/examples/classes/Makefile	2008-07-22 11:00:16 UTC (rev 2187)
@@ -5,6 +5,6 @@
 	rm $(TARGETS)
 
 .cpp:
-	g++ -g `pkg-config --cflags sword` $< -o $@ `pkg-config --libs sword`
+	g++ -O3 `pkg-config --cflags sword` $< -o $@ `pkg-config --libs sword`
 
 

Deleted: trunk/examples/classes/outplain.cpp
===================================================================
--- trunk/examples/classes/outplain.cpp	2008-07-21 11:28:48 UTC (rev 2186)
+++ trunk/examples/classes/outplain.cpp	2008-07-22 11:00:16 UTC (rev 2187)
@@ -1,32 +0,0 @@
-/******************************************************************************
- * Class SWMgr manages installed modules for a frontend.
- * SWMgr reads a mods.conf file to discover its information.
- * It then instantiates the correct decendent of SWModule for each
- * module entry in mods.conf
- * The developer may use this class to query what modules are installed
- * and to retrieve an (SWModule *) for any one of these modules
- *
- * SWMgr makes its modules available as an STL Map.
- * The Map definition is typedef'ed as ModMap
- * ModMap consists of: FIRST : SWBuf moduleName
- *                     SECOND: SWModule *module
- *
- */
-
-#include <iostream>
-
-#include <swmgr.h>
-#include <swmodule.h>
-
-using namespace sword;
-using namespace std;
-
-int main(int argc, char **argv) {
-	SWMgr manager;		// create a default manager that looks in the current directory for mods.conf
-
-	const char *bookName = (argc > 1) ? argv[1] : "WLC";
-	SWModule &book = *manager.getModule(bookName);
-	for (book = TOP; !book.Error(); book++) {
-		cout << book.StripText() << "\n";
-	}
-}

Modified: trunk/examples/cmdline/Makefile.am
===================================================================
--- trunk/examples/cmdline/Makefile.am	2008-07-21 11:28:48 UTC (rev 2186)
+++ trunk/examples/cmdline/Makefile.am	2008-07-22 11:00:16 UTC (rev 2187)
@@ -2,11 +2,12 @@
 INCLUDES = -I $(top_srcdir)/include
 LDADD = $(top_builddir)/lib/libsword.la
 
-noinst_PROGRAMS = lookup search threaded_search listoptions verserangeparse
+noinst_PROGRAMS = lookup search threaded_search listoptions verserangeparse outplain
 
 lookup_SOURCES = lookup.cpp
 search_SOURCES = search.cpp
 listoptions_SOURCES = listoptions.cpp
 verserangeparse_SOURCES = verserangeparse.cpp
 threaded_search_SOURCES = threaded_search.cpp
+outplain_SOURCES = outplain.cpp
 threaded_search_LDADD = $(LDADD) -lpthread

Copied: trunk/examples/cmdline/outplain.cpp (from rev 2180, trunk/examples/classes/outplain.cpp)
===================================================================
--- trunk/examples/cmdline/outplain.cpp	                        (rev 0)
+++ trunk/examples/cmdline/outplain.cpp	2008-07-22 11:00:16 UTC (rev 2187)
@@ -0,0 +1,33 @@
+/******************************************************************************
+ * Class SWMgr manages installed modules for a frontend.
+ * SWMgr reads a mods.conf file to discover its information.
+ * It then instantiates the correct decendent of SWModule for each
+ * module entry in mods.conf
+ * The developer may use this class to query what modules are installed
+ * and to retrieve an (SWModule *) for any one of these modules
+ *
+ * SWMgr makes its modules available as an STL Map.
+ * The Map definition is typedef'ed as ModMap
+ * ModMap consists of: FIRST : SWBuf moduleName
+ *                     SECOND: SWModule *module
+ *
+ */
+
+#include <iostream>
+
+#include <swmgr.h>
+#include <swmodule.h>
+
+using namespace sword;
+using namespace std;
+
+int main(int argc, char **argv) {
+	SWMgr manager;		// create a default manager that looks in the current directory for mods.conf
+
+	const char *bookName = (argc > 1) ? argv[1] : "WLC";
+	SWModule &book = *manager.getModule(bookName);
+	book.processEntryAttributes(false);
+	for (book = TOP; !book.Error(); book++) {
+		cout << book.getKeyText() << " " << book.StripText() << "\n";
+	}
+}

Modified: trunk/include/osisplain.h
===================================================================
--- trunk/include/osisplain.h	2008-07-21 11:28:48 UTC (rev 2186)
+++ trunk/include/osisplain.h	2008-07-22 11:00:16 UTC (rev 2187)
@@ -31,15 +31,7 @@
 class SWDLLEXPORT OSISPlain : public SWBasicFilter {
 public:
 protected:
-	class MyUserData : public BasicFilterUserData {
-	public:
-		SWBuf w;
-		XMLTag tag;
-		MyUserData(const SWModule *module, const SWKey *key) : BasicFilterUserData(module, key) {}
-	};
-	virtual BasicFilterUserData *createUserData(const SWModule *module, const SWKey *key) {
-		return new MyUserData(module, key);
-	}
+	virtual BasicFilterUserData *createUserData(const SWModule *module, const SWKey *key);
 	virtual bool handleToken(SWBuf &buf, const char *token, BasicFilterUserData *userData);
 public:
 	OSISPlain();

Modified: trunk/include/rawstr.h
===================================================================
--- trunk/include/rawstr.h	2008-07-21 11:28:48 UTC (rev 2186)
+++ trunk/include/rawstr.h	2008-07-22 11:00:16 UTC (rev 2187)
@@ -43,7 +43,6 @@
 	void doSetText(const char *key, const char *buf, long len = -1);
 	void doLinkEntry(const char *destkey, const char *srckey);
 public:
-	static void prepText(SWBuf &buf);
 	static char nl;
 	RawStr(const char *ipath, int fileMode = -1);
 	virtual ~RawStr();

Modified: trunk/include/rawstr4.h
===================================================================
--- trunk/include/rawstr4.h	2008-07-21 11:28:48 UTC (rev 2186)
+++ trunk/include/rawstr4.h	2008-07-22 11:00:16 UTC (rev 2187)
@@ -40,7 +40,6 @@
 protected:
 	FileDesc *idxfd;
 	FileDesc *datfd;
-	void prepText(SWBuf &buf);
 	void doSetText(const char *key, const char *buf, long len = -1);
 	void doLinkEntry(const char *destkey, const char *srckey);
 public:

Modified: trunk/include/rawverse.h
===================================================================
--- trunk/include/rawverse.h	2008-07-21 11:28:48 UTC (rev 2186)
+++ trunk/include/rawverse.h	2008-07-22 11:00:16 UTC (rev 2187)
@@ -25,7 +25,6 @@
 	FileDesc *textfp[2];
 
 	char *path;
-	void prepText(SWBuf &buf);
 	void doSetText(char testmt, long idxoff, const char *buf, long len = -1);
 	void doLinkEntry(char testmt, long destidxoff, long srcidxoff);
 

Modified: trunk/include/rawverse4.h
===================================================================
--- trunk/include/rawverse4.h	2008-07-21 11:28:48 UTC (rev 2186)
+++ trunk/include/rawverse4.h	2008-07-22 11:00:16 UTC (rev 2187)
@@ -25,7 +25,6 @@
 	FileDesc *textfp[2];
 
 	char *path;
-	void prepText(SWBuf &buf);
 	void doSetText(char testmt, long idxoff, const char *buf, long len = -1);
 	void doLinkEntry(char testmt, long destidxoff, long srcidxoff);
 

Modified: trunk/include/swmodule.h
===================================================================
--- trunk/include/swmodule.h	2008-07-21 11:28:48 UTC (rev 2186)
+++ trunk/include/swmodule.h	2008-07-22 11:00:16 UTC (rev 2187)
@@ -133,7 +133,9 @@
 	int entrySize;
 	mutable long entryIndex;	 // internal common storage for index
 
+	static void prepText(SWBuf &buf);
 
+
 public:
 
 	/**

Modified: trunk/include/zstr.h
===================================================================
--- trunk/include/zstr.h	2008-07-21 11:28:48 UTC (rev 2186)
+++ trunk/include/zstr.h	2008-07-22 11:00:16 UTC (rev 2187)
@@ -56,7 +56,6 @@
 
 	void getCompressedText(long block, long entry, char **buf);
 	void flushCache();
-	void prepText(SWBuf &buf);
 	void getKeyFromDatOffset(long ioffset, char **buf);
 	void getKeyFromIdxOffset(long ioffset, char **buf);
 

Modified: trunk/include/zverse.h
===================================================================
--- trunk/include/zverse.h	2008-07-21 11:28:48 UTC (rev 2186)
+++ trunk/include/zverse.h	2008-07-22 11:00:16 UTC (rev 2187)
@@ -26,11 +26,11 @@
 	FileDesc *textfp[2];
 	FileDesc *compfp[2];
 	char *path;
-	void prepText(SWBuf &buf);
 	void doSetText(char testmt, long idxoff, const char *buf, long len = 0);
 	void doLinkEntry(char testmt, long destidxoff, long srcidxoff);
 	void flushCache();
 	char *cacheBuf;
+	unsigned int cacheBufSize;
 	char cacheTestament;
 	long cacheBufIdx;
 	bool dirtyCache;

Modified: trunk/src/mgr/localemgr.cpp
===================================================================
--- trunk/src/mgr/localemgr.cpp	2008-07-21 11:28:48 UTC (rev 2186)
+++ trunk/src/mgr/localemgr.cpp	2008-07-22 11:00:16 UTC (rev 2187)
@@ -49,10 +49,11 @@
 
 
 LocaleMgr *LocaleMgr::getSystemLocaleMgr() {
-	if (!systemLocaleMgr)
+	if (!systemLocaleMgr) {
 		systemLocaleMgr = new LocaleMgr();
 		SWLocale *locale = new SWLocale(0);
 		systemLocaleMgr->locales->insert(LocaleMap::value_type(locale->getName(), locale));
+	}
 
 	return systemLocaleMgr;
 }

Modified: trunk/src/modules/common/rawstr.cpp
===================================================================
--- trunk/src/modules/common/rawstr.cpp	2008-07-21 11:28:48 UTC (rev 2186)
+++ trunk/src/modules/common/rawstr.cpp	2008-07-22 11:00:16 UTC (rev 2187)
@@ -271,65 +271,6 @@
 
 
 /******************************************************************************
- * RawStr::preptext	- Prepares the text before returning it to external
- *					objects
- *
- * ENT:	buf	- buffer where text is stored and where to store the prep'd
- *				text.
- */
-
-void RawStr::prepText(SWBuf &buf) {
-	unsigned int to, from; 
-	char space = 0, cr = 0, realdata = 0, nlcnt = 0;
-	char *rawBuf = buf.getRawData();
-	for (to = from = 0; rawBuf[from]; from++) {
-		switch (rawBuf[from]) {
-		case 10:
-			if (!realdata)
-				continue;
-			space = (cr) ? 0 : 1;
-			cr = 0;
-			nlcnt++;
-			if (nlcnt > 1) {
-//				*to++ = nl;
-				rawBuf[to++] = 10;
-//				*to++ = nl[1];
-//				nlcnt = 0;
-			}
-			continue;
-		case 13:
-			if (!realdata)
-				continue;
-//			*to++ = nl[0];
-			rawBuf[to++] = 10;
-			space = 0;
-			cr = 1;
-			continue;
-		}
-		realdata = 1;
-		nlcnt = 0;
-		if (space) {
-			space = 0;
-			if (rawBuf[from] != ' ') {
-				rawBuf[to++] = ' ';
-				from--;
-				continue;
-			}
-		}
-		rawBuf[to++] = rawBuf[from];
-	}
-	buf.setSize(to);
-
-	while (to > 1) {			// remove trailing excess
-		to--;
-		if ((rawBuf[to] == 10) || (rawBuf[to] == ' '))
-			buf.setSize(to);
-		else break;
-	}
-}
-
-
-/******************************************************************************
  * RawStr::readtext	- gets text at a given offset
  *
  * ENT:

Modified: trunk/src/modules/common/rawstr4.cpp
===================================================================
--- trunk/src/modules/common/rawstr4.cpp	2008-07-21 11:28:48 UTC (rev 2186)
+++ trunk/src/modules/common/rawstr4.cpp	2008-07-22 11:00:16 UTC (rev 2187)
@@ -279,65 +279,6 @@
 
 
 /******************************************************************************
- * RawStr4::preptext	- Prepares the text before returning it to external
- *					objects
- *
- * ENT:	buf	- buffer where text is stored and where to store the prep'd
- *				text.
- */
-
-void RawStr4::prepText(SWBuf &buf) {
-	unsigned int to, from; 
-	char space = 0, cr = 0, realdata = 0, nlcnt = 0;
-	char *rawBuf = buf.getRawData();
-	for (to = from = 0; rawBuf[from]; from++) {
-		switch (rawBuf[from]) {
-		case 10:
-			if (!realdata)
-				continue;
-			space = (cr) ? 0 : 1;
-			cr = 0;
-			nlcnt++;
-			if (nlcnt > 1) {
-//				*to++ = nl;
-				rawBuf[to++] = 10;
-//				*to++ = nl[1];
-//				nlcnt = 0;
-			}
-			continue;
-		case 13:
-			if (!realdata)
-				continue;
-//			*to++ = nl[0];
-			rawBuf[to++] = 10;
-			space = 0;
-			cr = 1;
-			continue;
-		}
-		realdata = 1;
-		nlcnt = 0;
-		if (space) {
-			space = 0;
-			if (rawBuf[from] != ' ') {
-				rawBuf[to++] = ' ';
-				from--;
-				continue;
-			}
-		}
-		rawBuf[to++] = rawBuf[from];
-	}
-	buf.setSize(to);
-
-	while (to > 1) {			// remove trailing excess
-		to--;
-		if ((rawBuf[to] == 10) || (rawBuf[to] == ' '))
-			buf.setSize(to);
-		else break;
-	}
-}
-
-
-/******************************************************************************
  * RawStr4::readtext	- gets text at a given offset
  *
  * ENT:

Modified: trunk/src/modules/common/rawverse.cpp
===================================================================
--- trunk/src/modules/common/rawverse.cpp	2008-07-21 11:28:48 UTC (rev 2186)
+++ trunk/src/modules/common/rawverse.cpp	2008-07-22 11:00:16 UTC (rev 2187)
@@ -121,65 +121,6 @@
 
 
 /******************************************************************************
- * RawVerse::preptext	- Prepares the text before returning it to external
- *				objects
- *
- * ENT:	buf	- buffer where text is stored and where to store the prep'd
- *			text.
- */
-
-void RawVerse::prepText(SWBuf &buf) {
-	unsigned int to, from; 
-	char space = 0, cr = 0, realdata = 0, nlcnt = 0;
-	char *rawBuf = buf.getRawData();
-	for (to = from = 0; rawBuf[from]; from++) {
-		switch (rawBuf[from]) {
-		case 10:
-			if (!realdata)
-				continue;
-			space = (cr) ? 0 : 1;
-			cr = 0;
-			nlcnt++;
-			if (nlcnt > 1) {
-//				*to++ = nl;
-				rawBuf[to++] = 10;
-//				*to++ = nl[1];
-//				nlcnt = 0;
-			}
-			continue;
-		case 13:
-			if (!realdata)
-				continue;
-//			*to++ = nl[0];
-			rawBuf[to++] = 10;
-			space = 0;
-			cr = 1;
-			continue;
-		}
-		realdata = 1;
-		nlcnt = 0;
-		if (space) {
-			space = 0;
-			if (rawBuf[from] != ' ') {
-				rawBuf[to++] = ' ';
-				from--;
-				continue;
-			}
-		}
-		rawBuf[to++] = rawBuf[from];
-	}
-	buf.setSize(to);
-
-	while (to > 1) {			// remove trailing excess
-		to--;
-		if ((rawBuf[to] == 10) || (rawBuf[to] == ' '))
-			buf.setSize(to);
-		else break;
-	}
-}
-
-
-/******************************************************************************
  * RawVerse::readtext	- gets text at a given offset
  *
  * ENT:	testmt	- testament file to search in (0 - Old; 1 - New)

Modified: trunk/src/modules/common/rawverse4.cpp
===================================================================
--- trunk/src/modules/common/rawverse4.cpp	2008-07-21 11:28:48 UTC (rev 2186)
+++ trunk/src/modules/common/rawverse4.cpp	2008-07-22 11:00:16 UTC (rev 2187)
@@ -121,65 +121,6 @@
 
 
 /******************************************************************************
- * RawVerse4::preptext	- Prepares the text before returning it to external
- *				objects
- *
- * ENT:	buf	- buffer where text is stored and where to store the prep'd
- *			text.
- */
-
-void RawVerse4::prepText(SWBuf &buf) {
-	unsigned int to, from; 
-	char space = 0, cr = 0, realdata = 0, nlcnt = 0;
-	char *rawBuf = buf.getRawData();
-	for (to = from = 0; rawBuf[from]; from++) {
-		switch (rawBuf[from]) {
-		case 10:
-			if (!realdata)
-				continue;
-			space = (cr) ? 0 : 1;
-			cr = 0;
-			nlcnt++;
-			if (nlcnt > 1) {
-//				*to++ = nl;
-				rawBuf[to++] = 10;
-//				*to++ = nl[1];
-//				nlcnt = 0;
-			}
-			continue;
-		case 13:
-			if (!realdata)
-				continue;
-//			*to++ = nl[0];
-			rawBuf[to++] = 10;
-			space = 0;
-			cr = 1;
-			continue;
-		}
-		realdata = 1;
-		nlcnt = 0;
-		if (space) {
-			space = 0;
-			if (rawBuf[from] != ' ') {
-				rawBuf[to++] = ' ';
-				from--;
-				continue;
-			}
-		}
-		rawBuf[to++] = rawBuf[from];
-	}
-	buf.setSize(to);
-
-	while (to > 1) {			// remove trailing excess
-		to--;
-		if ((rawBuf[to] == 10) || (rawBuf[to] == ' '))
-			buf.setSize(to);
-		else break;
-	}
-}
-
-
-/******************************************************************************
  * RawVerse4::readtext	- gets text at a given offset
  *
  * ENT:	testmt	- testament file to search in (0 - Old; 1 - New)

Modified: trunk/src/modules/common/zstr.cpp
===================================================================
--- trunk/src/modules/common/zstr.cpp	2008-07-21 11:28:48 UTC (rev 2186)
+++ trunk/src/modules/common/zstr.cpp	2008-07-22 11:00:16 UTC (rev 2187)
@@ -287,65 +287,6 @@
 
 
 /******************************************************************************
- * zStr::preptext	- Prepares the text before returning it to external
- *					objects
- *
- * ENT:	buf	- buffer where text is stored and where to store the prep'd
- *				text.
- */
-
-void zStr::prepText(SWBuf &buf) {
-	unsigned int to, from; 
-	char space = 0, cr = 0, realdata = 0, nlcnt = 0;
-	char *rawBuf = buf.getRawData();
-	for (to = from = 0; rawBuf[from]; from++) {
-		switch (rawBuf[from]) {
-		case 10:
-			if (!realdata)
-				continue;
-			space = (cr) ? 0 : 1;
-			cr = 0;
-			nlcnt++;
-			if (nlcnt > 1) {
-//				*to++ = nl;
-				rawBuf[to++] = 10;
-//				*to++ = nl[1];
-//				nlcnt = 0;
-			}
-			continue;
-		case 13:
-			if (!realdata)
-				continue;
-//			*to++ = nl[0];
-			rawBuf[to++] = 10;
-			space = 0;
-			cr = 1;
-			continue;
-		}
-		realdata = 1;
-		nlcnt = 0;
-		if (space) {
-			space = 0;
-			if (rawBuf[from] != ' ') {
-				rawBuf[to++] = ' ';
-				from--;
-				continue;
-			}
-		}
-		rawBuf[to++] = rawBuf[from];
-	}
-	buf.setSize(to);
-
-	while (to > 1) {			// remove trailing excess
-		to--;
-		if ((rawBuf[to] == 10) || (rawBuf[to] == ' '))
-			buf.setSize(to);
-		else break;
-	}
-}
-
-
-/******************************************************************************
  * zStr::getText	- gets text at a given offset
  *
  * ENT:

Modified: trunk/src/modules/common/zverse.cpp
===================================================================
--- trunk/src/modules/common/zverse.cpp	2008-07-21 11:28:48 UTC (rev 2186)
+++ trunk/src/modules/common/zverse.cpp	2008-07-22 11:00:16 UTC (rev 2187)
@@ -237,7 +237,7 @@
 		compressor->Buf(0, &len);
 		cacheBuf = (char *)calloc(len + 1, 1);
 		memcpy(cacheBuf, compressor->Buf(), len);
-
+		cacheBufSize = strlen(cacheBuf);  // TODO: can we just use len?
 		cacheTestament = testmt;
 		cacheBufIdx = ulBuffNum;
 	}
@@ -256,7 +256,7 @@
 
 void zVerse::zReadText(char testmt, long start, unsigned short size, SWBuf &inBuf) {
 	inBuf = "";
-	if ( (size > 0) && cacheBuf && ((unsigned)start < strlen(cacheBuf)) ){ //TODO: optimize this, remove strlen
+	if ((size > 0) && cacheBuf && ((unsigned)start < cacheBufSize)) {
 		inBuf.setFillByte(0);
 		inBuf.setSize(size+1);
 		strncpy(inBuf.getRawData(), &(cacheBuf[start]), size);
@@ -476,63 +476,4 @@
 }
 
 
-/******************************************************************************
- * zVerse::preptext	- Prepares the text before returning it to external
- *				objects
- *
- * ENT:	buf	- buffer where text is stored and where to store the prep'd
- *			text.
- */
-
-void zVerse::prepText(SWBuf &buf) {
-	unsigned int to, from; 
-	char space = 0, cr = 0, realdata = 0, nlcnt = 0;
-	char *rawBuf = buf.getRawData();
-	for (to = from = 0; rawBuf[from]; from++) {
-		switch (rawBuf[from]) {
-		case 10:
-			if (!realdata)
-				continue;
-			space = (cr) ? 0 : 1;
-			cr = 0;
-			nlcnt++;
-			if (nlcnt > 1) {
-//				*to++ = nl;
-				rawBuf[to++] = 10;
-//				*to++ = nl[1];
-//				nlcnt = 0;
-			}
-			continue;
-		case 13:
-			if (!realdata)
-				continue;
-//			*to++ = nl[0];
-			rawBuf[to++] = 10;
-			space = 0;
-			cr = 1;
-			continue;
-		}
-		realdata = 1;
-		nlcnt = 0;
-		if (space) {
-			space = 0;
-			if (rawBuf[from] != ' ') {
-				rawBuf[to++] = ' ';
-				from--;
-				continue;
-			}
-		}
-		rawBuf[to++] = rawBuf[from];
-	}
-	buf.setSize(to);
-
-	while (to > 1) {			// remove trailing excess
-		to--;
-		if ((rawBuf[to] == 10) || (rawBuf[to] == ' '))
-			buf.setSize(to);
-		else break;
-	}
-}
-
-
 SWORD_NAMESPACE_END

Modified: trunk/src/modules/filters/osisplain.cpp
===================================================================
--- trunk/src/modules/filters/osisplain.cpp	2008-07-21 11:28:48 UTC (rev 2186)
+++ trunk/src/modules/filters/osisplain.cpp	2008-07-22 11:00:16 UTC (rev 2187)
@@ -1,19 +1,25 @@
-/***************************************************************************
-                     osisplain.cpp  -  OSIS to Plaintext filter
-                             -------------------
-    begin                : 2003-02-15
-    copyright            : 2003 by CrossWire Bible Society
- ***************************************************************************/
+/******************************************************************************
+ *  osisplain.cpp	- An SWFilter
+ *  				impl that provides stripping of OSIS tags
+ *
+ * $Id$
+ *
+ * Copyright 2001 CrossWire Bible Society (http://www.crosswire.org)
+ *	CrossWire Bible Society
+ *	P. O. Box 2528
+ *	Tempe, AZ  85280-2528
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation version 2.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ */
 
-/***************************************************************************
- *                                                                         *
- *   This program is free software; you can redistribute it and/or modify  *
- *   it under the terms of the GNU General Public License as published by  *
- *   the Free Software Foundation; either version 2 of the License, or     *
- *   (at your option) any later version.                                   *
- *                                                                         *
- ***************************************************************************/
-
 #include <stdlib.h>
 #include <osisplain.h>
 #include <ctype.h>
@@ -22,6 +28,17 @@
 
 SWORD_NAMESPACE_START
 
+namespace {
+class MyUserData : public BasicFilterUserData {
+public:
+	SWBuf w;
+	XMLTag tag;
+	VerseKey *vk;
+	char testament;
+	MyUserData(const SWModule *module, const SWKey *key) : BasicFilterUserData(module, key) {}
+};
+}
+
 OSISPlain::OSISPlain() {
 	setTokenStart("<");
 	setTokenEnd(">");
@@ -45,13 +62,18 @@
 	   addTokenSubstitute("/lg", "\n");
 }
 
+BasicFilterUserData *OSISPlain::createUserData(const SWModule *module, const SWKey *key) {
+	MyUserData *u = new MyUserData(module, key);
+	u->vk = SWDYNAMIC_CAST(VerseKey, u->key);
+	u->testament = (u->vk) ? u->vk->Testament() : 2;	// default to NT
+	return u;
+}
 
+
 bool OSISPlain::handleToken(SWBuf &buf, const char *token, BasicFilterUserData *userData) {
 	   // manually process if it wasn't a simple substitution
 	if (!substituteToken(buf, token)) {
 		MyUserData *u = (MyUserData *)userData;
-		VerseKey *vk = SWDYNAMIC_CAST(VerseKey, u->key);
-		char testament = (vk) ? vk ->Testament() : 2;	// default to NT
 		if (((*token == 'w') && (token[1] == ' ')) ||
 		    ((*token == '/') && (token[1] == 'w') && (!token[2]))) {
 				 u->tag = token;
@@ -99,7 +121,7 @@
 						val++;
 					}
 					else {
-						gh = (testament>1) ? 'G' : 'H';
+						gh = (u->testament>1) ? 'G' : 'H';
 					}
 					if ((!strcmp(val, "3588")) && (lastText.length() < 1))
 						show = false;

Modified: trunk/src/modules/genbook/rawgenbook/rawgenbook.cpp
===================================================================
--- trunk/src/modules/genbook/rawgenbook/rawgenbook.cpp	2008-07-21 11:28:48 UTC (rev 2186)
+++ trunk/src/modules/genbook/rawgenbook/rawgenbook.cpp	2008-07-22 11:00:16 UTC (rev 2187)
@@ -125,7 +125,7 @@
 		rawFilter(entryBuf, key);
 
 //		   if (!isUnicode())
-			RawStr::prepText(entryBuf);
+			SWModule::prepText(entryBuf);
 	}
 
 	if (freeKey) // free our key if we created a VerseKey

Modified: trunk/src/modules/swmodule.cpp
===================================================================
--- trunk/src/modules/swmodule.cpp	2008-07-21 11:28:48 UTC (rev 2186)
+++ trunk/src/modules/swmodule.cpp	2008-07-22 11:00:16 UTC (rev 2187)
@@ -1279,4 +1279,63 @@
 void SWModule::linkEntry(const SWKey*) {
 }
 
+
+/******************************************************************************
+ * SWModule::prepText	- Prepares the text before returning it to external
+ *					objects
+ *
+ * ENT:	buf	- buffer where text is stored and where to store the prep'd
+ *				text.
+ */
+
+void SWModule::prepText(SWBuf &buf) {
+	unsigned int to, from; 
+	char space = 0, cr = 0, realdata = 0, nlcnt = 0;
+	char *rawBuf = buf.getRawData();
+	for (to = from = 0; rawBuf[from]; from++) {
+		switch (rawBuf[from]) {
+		case 10:
+			if (!realdata)
+				continue;
+			space = (cr) ? 0 : 1;
+			cr = 0;
+			nlcnt++;
+			if (nlcnt > 1) {
+//				*to++ = nl;
+				rawBuf[to++] = 10;
+//				*to++ = nl[1];
+//				nlcnt = 0;
+			}
+			continue;
+		case 13:
+			if (!realdata)
+				continue;
+//			*to++ = nl[0];
+			rawBuf[to++] = 10;
+			space = 0;
+			cr = 1;
+			continue;
+		}
+		realdata = 1;
+		nlcnt = 0;
+		if (space) {
+			space = 0;
+			if (rawBuf[from] != ' ') {
+				rawBuf[to++] = ' ';
+				from--;
+				continue;
+			}
+		}
+		rawBuf[to++] = rawBuf[from];
+	}
+	buf.setSize(to);
+
+	while (to > 1) {			// remove trailing excess
+		to--;
+		if ((rawBuf[to] == 10) || (rawBuf[to] == ' '))
+			buf.setSize(to);
+		else break;
+	}
+}
+
 SWORD_NAMESPACE_END

Modified: trunk/src/modules/texts/ztext/ztext.cpp
===================================================================
--- trunk/src/modules/texts/ztext/ztext.cpp	2008-07-21 11:28:48 UTC (rev 2186)
+++ trunk/src/modules/texts/ztext/ztext.cpp	2008-07-22 11:00:16 UTC (rev 2187)
@@ -68,8 +68,8 @@
 	entrySize = size;        // support getEntrySize call
 			  
 	entryBuf = "";
+	
 	zReadText(key.Testament(), start, size, entryBuf);
-
 	rawFilter(entryBuf, &key);
 
 //	if (!isUnicode())

Modified: trunk/usrinst.sh
===================================================================
--- trunk/usrinst.sh	2008-07-21 11:28:48 UTC (rev 2186)
+++ trunk/usrinst.sh	2008-07-22 11:00:16 UTC (rev 2187)
@@ -5,7 +5,7 @@
 OPTIONS="--without-conf $OPTIONS"
 OPTIONS="--sysconfdir=/etc $OPTIONS"
 #OPTIONS="--with-vcl $OPTIONS"
-OPTIONS="--enable-debug $OPTIONS"
+#OPTIONS="--enable-debug $OPTIONS"
 #OPTIONS="--enable-profile $OPTIONS"
 OPTIONS="--with-icu $OPTIONS"
 #OPTIONS="--without-clucene $OPTIONS"




More information about the sword-cvs mailing list