[sword-svn] r2303 - in trunk: . include lib src/mgr src/modules/comments/rawcom src/modules/comments/rawcom4 src/modules/comments/zcom src/modules/common src/modules/genbook src/modules/genbook/rawgenbook src/modules/lexdict src/modules/lexdict/rawld src/modules/lexdict/rawld4 src/modules/lexdict/zld src/modules/texts/rawtext src/modules/texts/rawtext4 src/modules/texts/ztext

scribe at crosswire.org scribe at crosswire.org
Mon Apr 6 06:38:34 MST 2009


Author: scribe
Date: 2009-04-06 06:38:34 -0700 (Mon, 06 Apr 2009)
New Revision: 2303

Modified:
   trunk/ChangeLog
   trunk/include/rawcom.h
   trunk/include/rawcom4.h
   trunk/include/rawgenbook.h
   trunk/include/rawld.h
   trunk/include/rawld4.h
   trunk/include/rawstr.h
   trunk/include/rawstr4.h
   trunk/include/rawtext.h
   trunk/include/rawtext4.h
   trunk/include/swgenbook.h
   trunk/include/swld.h
   trunk/include/swmodule.h
   trunk/include/zcom.h
   trunk/include/zld.h
   trunk/include/zstr.h
   trunk/include/ztext.h
   trunk/lib/Makefile.am
   trunk/src/mgr/localemgr.cpp
   trunk/src/mgr/swmgr.cpp
   trunk/src/modules/comments/rawcom/rawcom.cpp
   trunk/src/modules/comments/rawcom4/rawcom4.cpp
   trunk/src/modules/comments/zcom/zcom.cpp
   trunk/src/modules/common/rawstr.cpp
   trunk/src/modules/common/rawstr4.cpp
   trunk/src/modules/common/zstr.cpp
   trunk/src/modules/genbook/rawgenbook/rawgenbook.cpp
   trunk/src/modules/genbook/swgenbook.cpp
   trunk/src/modules/lexdict/rawld/rawld.cpp
   trunk/src/modules/lexdict/rawld4/rawld4.cpp
   trunk/src/modules/lexdict/swld.cpp
   trunk/src/modules/lexdict/zld/zld.cpp
   trunk/src/modules/texts/rawtext/rawtext.cpp
   trunk/src/modules/texts/rawtext4/rawtext4.cpp
   trunk/src/modules/texts/ztext/ztext.cpp
Log:
Applied more Ben Morgan patches, slightly modified



Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2009-04-06 11:35:05 UTC (rev 2302)
+++ trunk/ChangeLog	2009-04-06 13:38:34 UTC (rev 2303)
@@ -1,5 +1,23 @@
 API ChangeLog 
 
+30-Mar-2009	Ben Morgan
+	Added new methods to SWModule:
+		bool isLinked(SWKey *k1, SWKey *k2)
+			- are two entries linked
+		bool hasEntry(SWKey *k1)
+			- does an entry for the given key exist?
+	Added new methods to SWLD:
+		long getEntryCount()
+			- number of entries in the dictionary
+		getKeyForEntry(long entry)
+			- get the key for the nth entry
+		getEntryForKey(const char *key)
+			- get the index for the given key
+	Updated strongsPad to work with keys with a prefix of G or H
+	Fixed a bug in SWMgr which would load certain files in the mods.d
+		directory which shouldn't have been loaded.
+	Fix for divineName with non-ascii text in OSISHTMLHREF filter
+
 07-Feb-2008	Troy A. Griffitts <scribe at crosswire.org>
 	Added fallback checks for OS specific module
 		locations:

Modified: trunk/include/rawcom.h
===================================================================
--- trunk/include/rawcom.h	2009-04-06 11:35:05 UTC (rev 2302)
+++ trunk/include/rawcom.h	2009-04-06 13:38:34 UTC (rev 2303)
@@ -55,6 +55,7 @@
 	// end write interface ------------------------
 
 	virtual bool isLinked(const SWKey *k1, const SWKey *k2) const;
+	virtual bool hasEntry(const SWKey *k) const;
 
 
 	SWMODULE_OPERATORS

Modified: trunk/include/rawcom4.h
===================================================================
--- trunk/include/rawcom4.h	2009-04-06 11:35:05 UTC (rev 2302)
+++ trunk/include/rawcom4.h	2009-04-06 13:38:34 UTC (rev 2303)
@@ -55,6 +55,7 @@
 	// end write interface ------------------------
 
 	virtual bool isLinked(const SWKey *k1, const SWKey *k2) const;
+	virtual bool hasEntry(const SWKey *k) const;
 	
 	SWMODULE_OPERATORS
 

Modified: trunk/include/rawgenbook.h
===================================================================
--- trunk/include/rawgenbook.h	2009-04-06 11:35:05 UTC (rev 2302)
+++ trunk/include/rawgenbook.h	2009-04-06 13:38:34 UTC (rev 2303)
@@ -54,6 +54,7 @@
 	virtual SWKey *CreateKey() const;
 	// end write interface ------------------------
 
+	virtual bool hasEntry(const SWKey *k) const;
 
 	// OPERATORS -----------------------------------------------------------------
 	

Modified: trunk/include/rawld.h
===================================================================
--- trunk/include/rawld.h	2009-04-06 11:35:05 UTC (rev 2302)
+++ trunk/include/rawld.h	2009-04-06 13:38:34 UTC (rev 2303)
@@ -54,9 +54,9 @@
 	virtual void linkEntry(const SWKey *linkKey);	// Link current module entry to other module entry
 	virtual void deleteEntry();	// Delete current module entry
 	// end write interface ------------------------
-	virtual long getEntryCount();
-	virtual long getEntryForKey(const char *key);
-	virtual char *getKeyForEntry(long entry);
+	virtual long getEntryCount() const;
+	virtual long getEntryForKey(const char *key) const;
+	virtual char *getKeyForEntry(long entry) const;
 
 
 	// OPERATORS -----------------------------------------------------------------

Modified: trunk/include/rawld4.h
===================================================================
--- trunk/include/rawld4.h	2009-04-06 11:35:05 UTC (rev 2302)
+++ trunk/include/rawld4.h	2009-04-06 13:38:34 UTC (rev 2303)
@@ -54,9 +54,9 @@
 	virtual void linkEntry(const SWKey *linkKey);	// Link current module entry to other module entry
 	virtual void deleteEntry();	// Delete current module entry
 	// end write interface ------------------------
-	virtual long getEntryCount();
-	virtual long getEntryForKey(const char *key);
-	virtual char *getKeyForEntry(long entry);
+	virtual long getEntryCount() const;
+	virtual long getEntryForKey(const char *key) const;
+	virtual char *getKeyForEntry(long entry) const;
 
 
 	// OPERATORS -----------------------------------------------------------------

Modified: trunk/include/rawstr.h
===================================================================
--- trunk/include/rawstr.h	2009-04-06 11:35:05 UTC (rev 2302)
+++ trunk/include/rawstr.h	2009-04-06 13:38:34 UTC (rev 2303)
@@ -36,7 +36,7 @@
 class SWDLLEXPORT RawStr {
 	static int instance;		// number of instantiated RawStr objects or derivitives
 	char *path;
-	long lastoff;
+	mutable long lastoff;	 // for caching and optimizing
 	
 
 protected:
@@ -50,9 +50,9 @@
 	static char nl;
 	RawStr(const char *ipath, int fileMode = -1);
 	virtual ~RawStr();
-	void getIDXBuf(long ioffset, char **buf);
-	void getIDXBufDat(long ioffset, char **buf);
-	signed char findOffset(const char *key, __u32 *start, __u16 *size, long away = 0, __u32 *idxoff = 0);
+	void getIDXBuf(long ioffset, char **buf) const;
+	void getIDXBufDat(long ioffset, char **buf) const;
+	signed char findOffset(const char *key, __u32 *start, __u16 *size, long away = 0, __u32 *idxoff = 0) const;
 	void readText(__u32 start, __u16 *size, char **idxbuf, SWBuf &buf);
 	static signed char createModule(const char *path);
 };

Modified: trunk/include/rawstr4.h
===================================================================
--- trunk/include/rawstr4.h	2009-04-06 11:35:05 UTC (rev 2302)
+++ trunk/include/rawstr4.h	2009-04-06 13:38:34 UTC (rev 2303)
@@ -36,7 +36,7 @@
 class SWDLLEXPORT RawStr4 {
 	static int instance;		// number of instantiated RawStr4 objects or derivitives
 	char *path;
-	long lastoff;
+	mutable long lastoff;		// for caching and optimizations
 
 protected:
 	static const int IDXENTRYSIZE;
@@ -49,9 +49,9 @@
 	char nl;
 	RawStr4(const char *ipath, int fileMode = -1);
 	virtual ~RawStr4();
-	void getIDXBuf(long ioffset, char **buf);
-	void getIDXBufDat(long ioffset, char **buf);
-	signed char findOffset(const char *key, __u32 *start, __u32 *size, long away = 0, __u32 *idxoff = 0);
+	void getIDXBuf(long ioffset, char **buf) const;
+	void getIDXBufDat(long ioffset, char **buf) const;
+	signed char findOffset(const char *key, __u32 *start, __u32 *size, long away = 0, __u32 *idxoff = 0) const;
 	void readText(__u32 start, __u32 *size, char **idxbuf, SWBuf &buf);
 	static signed char createModule(const char *path);
 };

Modified: trunk/include/rawtext.h
===================================================================
--- trunk/include/rawtext.h	2009-04-06 11:35:05 UTC (rev 2302)
+++ trunk/include/rawtext.h	2009-04-06 13:38:34 UTC (rev 2303)
@@ -50,6 +50,7 @@
 	// end write interface ------------------------
 
 	virtual bool isLinked(const SWKey *k1, const SWKey *k2) const;
+	virtual bool hasEntry(const SWKey *k) const;
 	
 
 	SWMODULE_OPERATORS

Modified: trunk/include/rawtext4.h
===================================================================
--- trunk/include/rawtext4.h	2009-04-06 11:35:05 UTC (rev 2302)
+++ trunk/include/rawtext4.h	2009-04-06 13:38:34 UTC (rev 2303)
@@ -51,6 +51,7 @@
 	// end write interface ------------------------
 
 	virtual bool isLinked(const SWKey *k1, const SWKey *k2) const;
+	virtual bool hasEntry(const SWKey *k) const;
 
 	SWMODULE_OPERATORS
 

Modified: trunk/include/swgenbook.h
===================================================================
--- trunk/include/swgenbook.h	2009-04-06 11:35:05 UTC (rev 2302)
+++ trunk/include/swgenbook.h	2009-04-06 13:38:34 UTC (rev 2303)
@@ -37,7 +37,7 @@
 protected:
 	char *entkeytxt;
 	mutable TreeKey *tmpTreeKey;
-	TreeKey &getTreeKey() const;
+	TreeKey &getTreeKey(const SWKey *k = 0) const;
 
 public:
 	/** Initializes data for instance of SWGenBook

Modified: trunk/include/swld.h
===================================================================
--- trunk/include/swld.h	2009-04-06 11:35:05 UTC (rev 2302)
+++ trunk/include/swld.h	2009-04-06 13:38:34 UTC (rev 2303)
@@ -57,10 +57,11 @@
 	virtual void setPosition(SW_POSITION pos);
 
 
-	virtual long getEntryCount() = 0;
-	virtual long getEntryForKey(const char *key) = 0;
-	virtual char *getKeyForEntry(long entry) = 0;
+	virtual long getEntryCount() const = 0;
+	virtual long getEntryForKey(const char *key) const = 0;
+	virtual char *getKeyForEntry(long entry) const = 0;
 	
+	virtual bool hasEntry(const SWKey *k) const;
 
 	// OPERATORS -----------------------------------------------------------------
 	

Modified: trunk/include/swmodule.h
===================================================================
--- trunk/include/swmodule.h	2009-04-06 11:35:05 UTC (rev 2302)
+++ trunk/include/swmodule.h	2009-04-06 13:38:34 UTC (rev 2303)
@@ -641,6 +641,7 @@
 	virtual bool getSkipConsecutiveLinks() { return skipConsecutiveLinks; }
 	
 	virtual bool isLinked(const SWKey *k1, const SWKey *k2) const { return false; }
+	virtual bool hasEntry(const SWKey *k) const { return getEntrySize(); }
 
 	/** Entry Attributes are special data pertaining to the current entry.
 	 *	To see what Entry Attributes exists for a specific entry of a module,

Modified: trunk/include/zcom.h
===================================================================
--- trunk/include/zcom.h	2009-04-06 11:35:05 UTC (rev 2302)
+++ trunk/include/zcom.h	2009-04-06 13:38:34 UTC (rev 2303)
@@ -66,6 +66,7 @@
 	// end swcacher interface ----------------------
 
 	virtual bool isLinked(const SWKey *k1, const SWKey *k2) const;
+	virtual bool hasEntry(const SWKey *k) const;
 	
 	SWMODULE_OPERATORS
 

Modified: trunk/include/zld.h
===================================================================
--- trunk/include/zld.h	2009-04-06 11:35:05 UTC (rev 2302)
+++ trunk/include/zld.h	2009-04-06 13:38:34 UTC (rev 2303)
@@ -61,9 +61,9 @@
 	virtual void flush() { flushCache(); }
 	// end swcacher interface ----------------------
 
-	virtual long getEntryCount();
-	virtual long getEntryForKey(const char *key);
-	virtual char *getKeyForEntry(long entry);
+	virtual long getEntryCount() const;
+	virtual long getEntryForKey(const char *key) const;
+	virtual char *getKeyForEntry(long entry) const;
 
 
 	// OPERATORS -----------------------------------------------------------------

Modified: trunk/include/zstr.h
===================================================================
--- trunk/include/zstr.h	2009-04-06 11:35:05 UTC (rev 2302)
+++ trunk/include/zstr.h	2009-04-06 13:38:34 UTC (rev 2303)
@@ -42,7 +42,7 @@
 	long cacheBlockIndex;
 	bool cacheDirty;
 	char *path;
-	long lastoff;
+	mutable long lastoff;		// for caching and optimization
 	long blockCount;
 	SWCompress *compressor;
 
@@ -56,14 +56,14 @@
 
 	void getCompressedText(long block, long entry, char **buf);
 	void flushCache();
-	void getKeyFromDatOffset(long ioffset, char **buf);
-	void getKeyFromIdxOffset(long ioffset, char **buf);
+	void getKeyFromDatOffset(long ioffset, char **buf) const;
+	void getKeyFromIdxOffset(long ioffset, char **buf) const;
 
 public:
 	char nl;
 	zStr(const char *ipath, int fileMode = -1, long blockCount = 100, SWCompress *icomp = 0);
 	virtual ~zStr();
-	signed char findKeyIndex(const char *ikey, long *idxoff, long away = 0);
+	signed char findKeyIndex(const char *ikey, long *idxoff, long away = 0) const;
 	void getText(long index, char **idxbuf, char **buf);
 	void setText(const char *ikey, const char *buf, long len = -1);
 	void linkEntry(const char *destkey, const char *srckey);

Modified: trunk/include/ztext.h
===================================================================
--- trunk/include/ztext.h	2009-04-06 11:35:05 UTC (rev 2302)
+++ trunk/include/ztext.h	2009-04-06 13:38:34 UTC (rev 2303)
@@ -82,6 +82,8 @@
 	// end swcacher interface ----------------------
 
 	virtual bool isLinked(const SWKey *k1, const SWKey *k2) const;
+	virtual bool hasEntry(const SWKey *k) const;
+	
 	SWMODULE_OPERATORS
 
 };

Modified: trunk/lib/Makefile.am
===================================================================
--- trunk/lib/Makefile.am	2009-04-06 11:35:05 UTC (rev 2302)
+++ trunk/lib/Makefile.am	2009-04-06 13:38:34 UTC (rev 2303)
@@ -1,5 +1,5 @@
 AUTOMAKE_OPTIONS = 1.6
-AM_CPPFLAGS = -I$(top_srcdir)/include
+AM_CPPFLAGS = -I$(top_srcdir)/include -I$(includedir) 
 AM_CPPFLAGS += -DUSE_AUTOTOOLS -DUNIX -Dunix -D__unix__
 
 if ZLIB

Modified: trunk/src/mgr/localemgr.cpp
===================================================================
--- trunk/src/mgr/localemgr.cpp	2009-04-06 11:35:05 UTC (rev 2302)
+++ trunk/src/mgr/localemgr.cpp	2009-04-06 13:38:34 UTC (rev 2303)
@@ -81,7 +81,9 @@
 		SWMgr::findConfig(&configType, &prefixPath, &configPath, &augPaths);
 		SWLog::getSystemLog()->logDebug("LOOKING UP LOCALE DIRECTORY COMPLETE.");
 	}
-	else configPath = (char *)iConfigPath;
+	else {
+		loadConfigDir(iConfigPath);
+	}
 	
 	if (prefixPath) {
 		switch (configType) {

Modified: trunk/src/mgr/swmgr.cpp
===================================================================
--- trunk/src/mgr/swmgr.cpp	2009-04-06 11:35:05 UTC (rev 2302)
+++ trunk/src/mgr/swmgr.cpp	2009-04-06 13:38:34 UTC (rev 2303)
@@ -622,21 +622,19 @@
 		rewinddir(dir);
 		while ((ent = readdir(dir))) {
 			//check whether it ends with .conf, if it doesn't skip it!
-			if (ent->d_name && (strlen(ent->d_name) > 5) && strncmp(".conf", (ent->d_name + strlen(ent->d_name) - 5), 5 )) {
+			if (!ent->d_name || (strlen(ent->d_name) <= 5) || strncmp(".conf", (ent->d_name + strlen(ent->d_name) - 5), 5 )) {
 				continue;
 			}
 			
-			if ((strcmp(ent->d_name, ".")) && (strcmp(ent->d_name, ".."))) {
-				newmodfile = ipath;
-				if ((ipath[strlen(ipath)-1] != '\\') && (ipath[strlen(ipath)-1] != '/'))
-					newmodfile += "/";
-				newmodfile += ent->d_name;
-				if (config) {
-					SWConfig tmpConfig(newmodfile.c_str());
-					*config += tmpConfig;
-				}
-				else	config = myconfig = new SWConfig(newmodfile.c_str());
+			newmodfile = ipath;
+			if ((ipath[strlen(ipath)-1] != '\\') && (ipath[strlen(ipath)-1] != '/'))
+				newmodfile += "/";
+			newmodfile += ent->d_name;
+			if (config) {
+				SWConfig tmpConfig(newmodfile.c_str());
+				*config += tmpConfig;
 			}
+			else	config = myconfig = new SWConfig(newmodfile.c_str());
 		}
 		closedir(dir);
 		

Modified: trunk/src/modules/comments/rawcom/rawcom.cpp
===================================================================
--- trunk/src/modules/comments/rawcom/rawcom.cpp	2009-04-06 11:35:05 UTC (rev 2302)
+++ trunk/src/modules/comments/rawcom/rawcom.cpp	2009-04-06 13:38:34 UTC (rev 2303)
@@ -178,5 +178,13 @@
 	return start1 == start2;
 }
 
+bool RawCom::hasEntry(const SWKey *k) const {
+	long start;
+	unsigned short size;
+	VerseKey *vk = &getVerseKey(k);
 
+	findOffset(vk->Testament(), vk->TestamentIndex(), &start, &size);
+	return size;
+}
+
 SWORD_NAMESPACE_END

Modified: trunk/src/modules/comments/rawcom4/rawcom4.cpp
===================================================================
--- trunk/src/modules/comments/rawcom4/rawcom4.cpp	2009-04-06 11:35:05 UTC (rev 2302)
+++ trunk/src/modules/comments/rawcom4/rawcom4.cpp	2009-04-06 13:38:34 UTC (rev 2303)
@@ -177,5 +177,13 @@
 	return start1 == start2;
 }
 
+bool RawCom4::hasEntry(const SWKey *k) const {
+	long start;
+	unsigned long size;
+	VerseKey *vk = &getVerseKey(k);
 
+	findOffset(vk->Testament(), vk->TestamentIndex(), &start, &size);
+	return size;
+}
+
 SWORD_NAMESPACE_END

Modified: trunk/src/modules/comments/zcom/zcom.cpp
===================================================================
--- trunk/src/modules/comments/zcom/zcom.cpp	2009-04-06 11:35:05 UTC (rev 2302)
+++ trunk/src/modules/comments/zcom/zcom.cpp	2009-04-06 13:38:34 UTC (rev 2303)
@@ -214,5 +214,14 @@
 	return start1 == start2 && buffnum1 == buffnum2;
 }
 
+bool zCom::hasEntry(const SWKey *k) const {
+	long start;
+	unsigned short size;
+	unsigned long buffnum;
+	VerseKey *vk = &getVerseKey(k);
 
+	findOffset(vk->Testament(), vk->TestamentIndex(), &start, &size, &buffnum);
+	return size;
+}
+
 SWORD_NAMESPACE_END

Modified: trunk/src/modules/common/rawstr.cpp
===================================================================
--- trunk/src/modules/common/rawstr.cpp	2009-04-06 11:35:05 UTC (rev 2302)
+++ trunk/src/modules/common/rawstr.cpp	2009-04-06 13:38:34 UTC (rev 2303)
@@ -105,7 +105,7 @@
  *		buf		- address of pointer to allocate for storage of string
  */
 
-void RawStr::getIDXBufDat(long ioffset, char **buf)
+void RawStr::getIDXBufDat(long ioffset, char **buf) const
 {
 	int size;
 	char ch;
@@ -139,7 +139,7 @@
  *		buf		- address of pointer to allocate for storage of string
  */
 
-void RawStr::getIDXBuf(long ioffset, char **buf)
+void RawStr::getIDXBuf(long ioffset, char **buf) const
 {
 	__u32 offset;
 	
@@ -166,7 +166,7 @@
  * RET: error status -1 general error; -2 new file
  */
 
-signed char RawStr::findOffset(const char *ikey, __u32 *start, __u16 *size, long away, __u32 *idxoff)
+signed char RawStr::findOffset(const char *ikey, __u32 *start, __u16 *size, long away, __u32 *idxoff) const
 {
 	char *trybuf, *maxbuf, *key = 0, quitflag = 0;
 	signed char retval = -1;

Modified: trunk/src/modules/common/rawstr4.cpp
===================================================================
--- trunk/src/modules/common/rawstr4.cpp	2009-04-06 11:35:05 UTC (rev 2302)
+++ trunk/src/modules/common/rawstr4.cpp	2009-04-06 13:38:34 UTC (rev 2303)
@@ -105,7 +105,8 @@
  *		buf		- address of pointer to allocate for storage of string
  */
 
-void RawStr4::getIDXBufDat(long ioffset, char **buf) {
+void RawStr4::getIDXBufDat(long ioffset, char **buf) const
+{
 	int size;
 	char ch;
 	if (datfd > 0) {
@@ -138,7 +139,7 @@
  *		buf		- address of pointer to allocate for storage of string
  */
 
-void RawStr4::getIDXBuf(long ioffset, char **buf)
+void RawStr4::getIDXBuf(long ioffset, char **buf) const
 {
 	__u32 offset;
 	
@@ -174,7 +175,7 @@
  * RET: error status -1 general error; -2 new file
  */
 
-signed char RawStr4::findOffset(const char *ikey, __u32 *start, __u32 *size, long away, __u32 *idxoff)
+signed char RawStr4::findOffset(const char *ikey, __u32 *start, __u32 *size, long away, __u32 *idxoff) const
 {
 	char *trybuf, *maxbuf, *key = 0, quitflag = 0;
 	signed char retval = -1;

Modified: trunk/src/modules/common/zstr.cpp
===================================================================
--- trunk/src/modules/common/zstr.cpp	2009-04-06 11:35:05 UTC (rev 2302)
+++ trunk/src/modules/common/zstr.cpp	2009-04-06 13:38:34 UTC (rev 2303)
@@ -128,7 +128,8 @@
  *		buf		- address of pointer to allocate for storage of string
  */
 
-void zStr::getKeyFromDatOffset(long ioffset, char **buf) {
+void zStr::getKeyFromDatOffset(long ioffset, char **buf) const
+{
 	int size;
 	char ch;
 	if (datfd > 0) {
@@ -161,7 +162,8 @@
  *		buf		- address of pointer to allocate for storage of string
  */
 
-void zStr::getKeyFromIdxOffset(long ioffset, char **buf) {
+void zStr::getKeyFromIdxOffset(long ioffset, char **buf) const
+{
 	__u32 offset;
 	
 	if (idxfd > 0) {
@@ -185,7 +187,8 @@
  * RET: error status
  */
 
-signed char zStr::findKeyIndex(const char *ikey, long *idxoff, long away) {
+signed char zStr::findKeyIndex(const char *ikey, long *idxoff, long away) const
+{
 	char *maxbuf = 0, *trybuf = 0, *key = 0, quitflag = 0;
 	signed char retval = 0;
 	__s32 headoff, tailoff, tryoff = 0, maxoff = 0;

Modified: trunk/src/modules/genbook/rawgenbook/rawgenbook.cpp
===================================================================
--- trunk/src/modules/genbook/rawgenbook/rawgenbook.cpp	2009-04-06 11:35:05 UTC (rev 2302)
+++ trunk/src/modules/genbook/rawgenbook/rawgenbook.cpp	2009-04-06 13:38:34 UTC (rev 2303)
@@ -213,4 +213,12 @@
 	return tKey;
 }
 
+bool RawGenBook::hasEntry(const SWKey *k) const {
+	TreeKey &key = getTreeKey(k);
+
+	int dsize;
+	key.getUserData(&dsize);
+	return (dsize > 7) && key.Error() == '\x00';
+}
+
 SWORD_NAMESPACE_END

Modified: trunk/src/modules/genbook/swgenbook.cpp
===================================================================
--- trunk/src/modules/genbook/swgenbook.cpp	2009-04-06 11:35:05 UTC (rev 2302)
+++ trunk/src/modules/genbook/swgenbook.cpp	2009-04-06 13:38:34 UTC (rev 2303)
@@ -47,19 +47,20 @@
 }
 
 
-TreeKey &SWGenBook::getTreeKey() const {
+TreeKey &SWGenBook::getTreeKey(const SWKey *k) const {
+	const SWKey* thiskey = k?k:this->key;
 
 	TreeKey *key = 0;
 
 	SWTRY {
-		key = SWDYNAMIC_CAST(TreeKey, (this->key));
+		key = SWDYNAMIC_CAST(TreeKey, (thiskey));
 	}
 	SWCATCH ( ... ) {}
 
 	if (!key) {
 		ListKey *lkTest = 0;
 		SWTRY {
-			lkTest = SWDYNAMIC_CAST(ListKey, this->key);
+			lkTest = SWDYNAMIC_CAST(ListKey, thiskey);
 		}
 		SWCATCH ( ... ) {	}
 		if (lkTest) {
@@ -80,7 +81,7 @@
 	if (!key) {
 		VerseTreeKey *tkey = 0;
 		SWTRY {
-			tkey = SWDYNAMIC_CAST(VerseTreeKey, (this->key));
+			tkey = SWDYNAMIC_CAST(VerseTreeKey, (thiskey));
 		}
 		SWCATCH ( ... ) {}
 		if (tkey) key = tkey->getTreeKey();
@@ -89,7 +90,7 @@
 	if (!key) {
 		delete tmpTreeKey;
 		tmpTreeKey = (TreeKey *)CreateKey();
-		(*tmpTreeKey) = *(this->key);
+		(*tmpTreeKey) = *(thiskey);
 		return (*tmpTreeKey);
 	}
 	else	return *key;

Modified: trunk/src/modules/lexdict/rawld/rawld.cpp
===================================================================
--- trunk/src/modules/lexdict/rawld/rawld.cpp	2009-04-06 11:35:05 UTC (rev 2302)
+++ trunk/src/modules/lexdict/rawld/rawld.cpp	2009-04-06 13:38:34 UTC (rev 2303)
@@ -161,13 +161,13 @@
 }
 
 
-long RawLD::getEntryCount() {
+long RawLD::getEntryCount() const {
 	if (idxfd < 0) return 0;
 	return idxfd->seek(0, SEEK_END) / IDXENTRYSIZE;
 }
 
 
-long RawLD::getEntryForKey(const char *key) {
+long RawLD::getEntryForKey(const char *key) const {
 	__u32 start, offset;
 	__u16 size;
 	
@@ -177,11 +177,14 @@
 	strongsPad(buf);
 	
 	findOffset(buf, &start, &size, 0, &offset);
+
+	delete [] buf;
+
 	return offset / IDXENTRYSIZE;
 }
 
 
-char *RawLD::getKeyForEntry(long entry) {
+char *RawLD::getKeyForEntry(long entry) const {
 	char *key = 0;
 	getIDXBuf(entry * IDXENTRYSIZE, &key);
 	return key;

Modified: trunk/src/modules/lexdict/rawld4/rawld4.cpp
===================================================================
--- trunk/src/modules/lexdict/rawld4/rawld4.cpp	2009-04-06 11:35:05 UTC (rev 2302)
+++ trunk/src/modules/lexdict/rawld4/rawld4.cpp	2009-04-06 13:38:34 UTC (rev 2303)
@@ -158,12 +158,12 @@
 	doSetText(*key, "");
 }
 
-long RawLD4::getEntryCount() {
+long RawLD4::getEntryCount() const {
 	if (idxfd < 0) return 0;
 	return idxfd->seek(0, SEEK_END) / IDXENTRYSIZE;
 }
 
-long RawLD4::getEntryForKey(const char *key) {
+long RawLD4::getEntryForKey(const char *key) const {
 	__u32 start, offset;
 	__u32 size;
 
@@ -173,10 +173,13 @@
 	strongsPad(buf);
 	
 	findOffset(buf, &start, &size, 0, &offset);
+
+	delete [] buf;
+
 	return offset / IDXENTRYSIZE;
 }
 
-char *RawLD4::getKeyForEntry(long entry) {
+char *RawLD4::getKeyForEntry(long entry) const {
 	char *key = 0;
 	getIDXBuf(entry * IDXENTRYSIZE, &key);
 	return key;

Modified: trunk/src/modules/lexdict/swld.cpp
===================================================================
--- trunk/src/modules/lexdict/swld.cpp	2009-04-06 11:35:05 UTC (rev 2302)
+++ trunk/src/modules/lexdict/swld.cpp	2009-04-06 13:38:34 UTC (rev 2303)
@@ -96,7 +96,19 @@
 	getRawEntryBuf();
 }
 
+bool SWLD::hasEntry(const SWKey *key) const {
+	const char *key_str = *key;
+	char *buf = new char [ strlen(key_str) + 6 ];
+	strcpy(buf, key_str);
 
+	strongsPad(buf);
+	
+	bool retVal = !strcmp(buf, getKeyForEntry(getEntryForKey(buf)));
+	delete buf;
+
+	return retVal;
+}
+
 /******************************************************************************
  * SWLD::strongsPad	- Pads a key if (it-1) is 100% digits to 5 places
  *						allows for final to be alpha, e.g. '123B'

Modified: trunk/src/modules/lexdict/zld/zld.cpp
===================================================================
--- trunk/src/modules/lexdict/zld/zld.cpp	2009-04-06 11:35:05 UTC (rev 2302)
+++ trunk/src/modules/lexdict/zld/zld.cpp	2009-04-06 13:38:34 UTC (rev 2303)
@@ -157,13 +157,15 @@
 }
 
 
-long zLD::getEntryCount() {
+long zLD::getEntryCount() const
+{
 	if (idxfd < 0) return 0;
 	return idxfd->seek(0, SEEK_END) / IDXENTRYSIZE;
 }
 
 
-long zLD::getEntryForKey(const char* key) {
+long zLD::getEntryForKey(const char* key) const
+{
 	long offset;
 	char *buf = new char [ strlen(key) + 6 ];
 	strcpy(buf, key);
@@ -171,11 +173,15 @@
 	strongsPad(buf);
 	
 	findKeyIndex(buf, &offset);
+
+	delete [] buf;
+
 	return offset/IDXENTRYSIZE;
 }
 
 
-char *zLD::getKeyForEntry(long entry) {
+char *zLD::getKeyForEntry(long entry) const
+{
 	char *key = 0;
 	getKeyFromIdxOffset(entry * IDXENTRYSIZE, &key);
 	return key;

Modified: trunk/src/modules/texts/rawtext/rawtext.cpp
===================================================================
--- trunk/src/modules/texts/rawtext/rawtext.cpp	2009-04-06 11:35:05 UTC (rev 2302)
+++ trunk/src/modules/texts/rawtext/rawtext.cpp	2009-04-06 13:38:34 UTC (rev 2303)
@@ -195,6 +195,15 @@
 	return start1 == start2;
 }
 
+bool RawText::hasEntry(const SWKey *k) const {
+	long start;
+	unsigned short size;
+	VerseKey *vk = &getVerseKey(k);
+
+	findOffset(vk->Testament(), vk->TestamentIndex(), &start, &size);
+	return size;
+}
+
 	
 
 SWORD_NAMESPACE_END

Modified: trunk/src/modules/texts/rawtext4/rawtext4.cpp
===================================================================
--- trunk/src/modules/texts/rawtext4/rawtext4.cpp	2009-04-06 11:35:05 UTC (rev 2302)
+++ trunk/src/modules/texts/rawtext4/rawtext4.cpp	2009-04-06 13:38:34 UTC (rev 2303)
@@ -194,4 +194,13 @@
 	return start1 == start2;
 }
 
+bool RawText4::hasEntry(const SWKey *k) const {
+	long start;
+	unsigned long size;
+	VerseKey *vk = &getVerseKey(k);
+
+	findOffset(vk->Testament(), vk->TestamentIndex(), &start, &size);
+	return size;
+}
+
 SWORD_NAMESPACE_END

Modified: trunk/src/modules/texts/ztext/ztext.cpp
===================================================================
--- trunk/src/modules/texts/ztext/ztext.cpp	2009-04-06 11:35:05 UTC (rev 2302)
+++ trunk/src/modules/texts/ztext/ztext.cpp	2009-04-06 13:38:34 UTC (rev 2303)
@@ -220,4 +220,15 @@
 	return start1 == start2 && buffnum1 == buffnum2;
 }
 
+bool zText::hasEntry(const SWKey *k) const {
+	long start;
+	unsigned short size;
+	unsigned long buffnum;
+	VerseKey *vk = &getVerseKey(k);
+
+	findOffset(vk->Testament(), vk->TestamentIndex(), &start, &size, &buffnum);
+	return size;
+}
+
+
 SWORD_NAMESPACE_END




More information about the sword-cvs mailing list