[sword-svn] r2321 - in trunk: . include src/mgr src/modules

scribe at crosswire.org scribe at crosswire.org
Sun Apr 12 18:17:00 MST 2009


Author: scribe
Date: 2009-04-12 18:17:00 -0700 (Sun, 12 Apr 2009)
New Revision: 2321

Modified:
   trunk/ChangeLog
   trunk/include/swmgr.h
   trunk/src/mgr/localemgr.cpp
   trunk/src/mgr/swmgr.cpp
   trunk/src/modules/swmodule.cpp
Log:
	Added '.' feature for entryAttrib search, e.g,
		Word//Lemma./G932/ will find in Lemma, Lemma.1, etc.
	Added LocalePath feature in sword.conf



Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2009-04-11 09:26:27 UTC (rev 2320)
+++ trunk/ChangeLog	2009-04-13 01:17:00 UTC (rev 2321)
@@ -1,5 +1,10 @@
 API ChangeLog 
 
+12-Apr-2009	Troy A. Griffitts <scribe at crosswire.org>
+	Added '.' feature for entryAttrib search, e.g,
+		Word//Lemma./G932/ will find in Lemma, Lemma.1, etc.
+	Added LocalePath feature in sword.conf
+
 06-Apr-2009	Joachim A. <jansorg at crosswire.org>
 	Added Maltese bookname translation prepared by C. S.
 
@@ -21,7 +26,7 @@
 		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>
+07-Feb-2009	Troy A. Griffitts <scribe at crosswire.org>
 	Added fallback checks for OS specific module
 		locations:
 			$ALLUSERSPROFILE/Application Data/sword

Modified: trunk/include/swmgr.h
===================================================================
--- trunk/include/swmgr.h	2009-04-11 09:26:27 UTC (rev 2320)
+++ trunk/include/swmgr.h	2009-04-13 01:17:00 UTC (rev 2321)
@@ -162,10 +162,10 @@
 	/**
 	 *
 	 */
-	static void findConfig(char *configType, char **prefixPath, char **configPath, StringList *augPaths = 0, SWConfig *providedSysConf = 0);
+	static void findConfig(char *configType, char **prefixPath, char **configPath, StringList *augPaths = 0, SWConfig **providedSysConf = 0);
 
 	SWConfig *config;
-	SWConfig *sysconfig;
+	SWConfig *sysConfig;
 
 	/** The path to main module set and locales
 	 */

Modified: trunk/src/mgr/localemgr.cpp
===================================================================
--- trunk/src/mgr/localemgr.cpp	2009-04-11 09:26:27 UTC (rev 2320)
+++ trunk/src/mgr/localemgr.cpp	2009-04-13 01:17:00 UTC (rev 2321)
@@ -70,15 +70,24 @@
 	locales = new LocaleMap();
 	char *prefixPath = 0;
 	char *configPath = 0;
+	SWConfig *sysConf = 0;
 	char configType = 0;
 	SWBuf path;
 	std::list<SWBuf> augPaths;
+	ConfigEntMap::iterator entry;
 	
 	defaultLocaleName = 0;
 	
 	if (!iConfigPath) {
 		SWLog::getSystemLog()->logDebug("LOOKING UP LOCALE DIRECTORY...");
-		SWMgr::findConfig(&configType, &prefixPath, &configPath, &augPaths);
+		SWMgr::findConfig(&configType, &prefixPath, &configPath, &augPaths, &sysConf);
+		if (sysConf) {
+			if ((entry = sysConf->Sections["Install"].find("LocalePath")) != sysConf->Sections["Install"].end()) {
+				configType = 9;	// our own
+				stdstr(&prefixPath, (char *)entry->second.c_str());
+				SWLog::getSystemLog()->logDebug("LocalePath provided in sysConfig.");
+			}
+		}
 		SWLog::getSystemLog()->logDebug("LOOKING UP LOCALE DIRECTORY COMPLETE.");
 	}
 	else {
@@ -107,7 +116,7 @@
 		}
 	}
 	
-	if (augPaths.size()) { //load locale files from all augmented paths
+	if (augPaths.size() && configType != 9) { //load locale files from all augmented paths
 		std::list<SWBuf>::iterator it = augPaths.begin();
 		std::list<SWBuf>::iterator end = augPaths.end();
 		
@@ -129,6 +138,9 @@
 
 	if (configPath)
 		delete [] configPath;
+
+	if (sysConf)
+		delete sysConf;
 }
 
 

Modified: trunk/src/mgr/swmgr.cpp
===================================================================
--- trunk/src/mgr/swmgr.cpp	2009-04-11 09:26:27 UTC (rev 2320)
+++ trunk/src/mgr/swmgr.cpp	2009-04-13 01:17:00 UTC (rev 2321)
@@ -285,10 +285,10 @@
 	}
 	else config = 0;
 	if (isysconfig) {
-		sysconfig   = isysconfig;
+		sysConfig   = isysconfig;
 		mysysconfig = 0;
 	}
-	else sysconfig = 0;
+	else sysConfig = 0;
 
 	if (autoload)
 		Load();
@@ -337,7 +337,7 @@
 	}
 
 	config = 0;
-	sysconfig = 0;
+	sysConfig = 0;
 
 	if (autoload && configPath)
 		Load();
@@ -371,13 +371,14 @@
 }
 
 
-void SWMgr::findConfig(char *configType, char **prefixPath, char **configPath, std::list<SWBuf> *augPaths, SWConfig *providedSysConf) {
+void SWMgr::findConfig(char *configType, char **prefixPath, char **configPath, std::list<SWBuf> *augPaths, SWConfig **providedSysConf) {
 	SWBuf path;
 	SWBuf sysConfPath;
 	ConfigEntMap::iterator entry;
 	ConfigEntMap::iterator lastEntry;
 
 	SWConfig *sysConf = 0;
+	SWBuf sysConfDataPath = "";
 
 	*configType = 0;
 
@@ -385,18 +386,24 @@
 
 	// check for a sysConf passed in to us
 	SWLog::getSystemLog()->logDebug("Checking for provided SWConfig(\"sword.conf\")...");
-	if (providedSysConf) {
-		sysConf = providedSysConf;
+	if (providedSysConf && *providedSysConf) {
+		sysConf = *providedSysConf;
 		SWLog::getSystemLog()->logDebug("found.");
 	}
-	else {
+
+	// if we haven't been given our datapath in a sysconf, we need to track it down
+	if (!sysConf) {
 		// check working directory
 		SWLog::getSystemLog()->logDebug("Checking working directory for sword.conf...");
 		if (FileMgr::existsFile(".", "sword.conf")) {
 			SWLog::getSystemLog()->logDebug("Overriding any systemwide or ~/.sword/ sword.conf with one found in current directory.");
 			sysConfPath = "./sword.conf";
+			sysConf = new SWConfig(sysConfPath);
+			if ((entry = sysConf->Sections["Install"].find("DataPath")) != sysConf->Sections["Install"].end()) {
+				sysConfDataPath = (*entry).second;
+			}
 		}
-		else {
+		if (!sysConfDataPath.size()) {
 			SWLog::getSystemLog()->logDebug("Checking working directory for mods.conf...");
 			if (FileMgr::existsFile(".", "mods.conf")) {
 				SWLog::getSystemLog()->logDebug("found.");
@@ -492,16 +499,19 @@
 		}
 	}
 
-	if (sysConfPath.size()) {
+	if (!sysConf && sysConfPath.size()) {
 		sysConf = new SWConfig(sysConfPath);
 	}
 
 	if (sysConf) {
 		if ((entry = sysConf->Sections["Install"].find("DataPath")) != sysConf->Sections["Install"].end()) {
-			path = (*entry).second;
-			if (((*entry).second.c_str()[strlen((*entry).second.c_str())-1] != '\\') && ((*entry).second.c_str()[strlen((*entry).second.c_str())-1] != '/'))
-				path += "/";
+			sysConfDataPath = (*entry).second;
+		}
+		if (sysConfDataPath.size()) {
+			if ((!sysConfDataPath.endsWith("\\")) && (!sysConfDataPath.endsWith("/")))
+				sysConfDataPath += "/";
 
+			path = sysConfDataPath;
 			SWLog::getSystemLog()->logDebug("DataPath in %s is set to %s.", sysConfPath.c_str(), path.c_str());
 			SWLog::getSystemLog()->logDebug("Checking for mods.conf in DataPath...");
 			
@@ -523,6 +533,10 @@
 				*configType = 1;
 			}
 		}
+	}
+
+	// do some extra processing of sysConf if we have one
+	if (sysConf) {
 		if (augPaths) {
 			augPaths->clear();
 			entry     = sysConf->Sections["Install"].lower_bound("AugmentPath");
@@ -534,12 +548,12 @@
 				augPaths->push_back(path);
 			}
 		}
+		if (providedSysConf) {
+			*providedSysConf = sysConf;
+		}
+		else delete sysConf;
 	}
 
-	if ((sysConf) && (!providedSysConf)) {
-		delete sysConf;
-	}
-
 	if (*configType)
 		return;
 
@@ -715,7 +729,9 @@
 	if (!config) {	// If we weren't passed a config object at construction, find a config file
 		if (!configPath) {	// If we weren't passed a config path at construction...
 			SWLog::getSystemLog()->logDebug("LOOKING UP MODULE CONFIGURATION...");
-			findConfig(&configType, &prefixPath, &configPath, &augPaths, sysconfig);
+			SWConfig *externalSysConf = sysConfig;	// if we have a sysConf before findConfig, then we were provided one from an external source.
+			findConfig(&configType, &prefixPath, &configPath, &augPaths, &sysConfig);
+			if (!externalSysConf) mysysconfig = sysConfig;	// remind us to delete our own sysConfig in d-tor
 			SWLog::getSystemLog()->logDebug("LOOKING UP MODULE CONFIGURATION COMPLETE.");
 		}
 		if (configPath) {

Modified: trunk/src/modules/swmodule.cpp
===================================================================
--- trunk/src/modules/swmodule.cpp	2009-04-11 09:26:27 UTC (rev 2320)
+++ trunk/src/modules/swmodule.cpp	2009-04-13 01:17:00 UTC (rev 2321)
@@ -414,7 +414,7 @@
  *				>=0 - regex
  *				-1  - phrase
  *				-2  - multiword
- *				-3  - entryAttrib (eg. Word//Lemma/G1234/)
+ *				-3  - entryAttrib (eg. Word//Lemma./G1234/)	 (Lemma with dot means check components (Lemma.[1-9]) also)
  *				-4  - clucene
  *				-5  - multilemma window; flags = window size
  * 	flags		- options flags for search
@@ -428,6 +428,7 @@
 
 	listKey.ClearList();
 	SWBuf term = istr;
+	bool includeComponents = false;	// for entryAttrib e.g., /Lemma.1/ 
 
 #ifdef USELUCENE
 	SWBuf target = getConfigEntry("AbsoluteDataPath");
@@ -589,6 +590,10 @@
 			}
 			words.push_back(word);
 		}
+		if ((words.size()>2) && words[2].endsWith(".")) {
+			includeComponents = true;
+			words[2]--;
+		}
 		break;
 	}
 
@@ -699,7 +704,7 @@
 						i2End   = i1Start->second.end();
 					}
 					for (;i2Start != i2End; i2Start++) {
-						if ((words.size()>2) && (words[2].length())) {
+						if ((words.size()>2) && (words[2].length()) && (!includeComponents)) {
 							i3Start = i2Start->second.find(words[2]);
 							i3End = i3Start;
 							if (i3End != i2Start->second.end())
@@ -711,6 +716,13 @@
 						}
 						for (;i3Start != i3End; i3Start++) {
 							if ((words.size()>3) && (words[3].length())) {
+								if (includeComponents) {
+									SWBuf key = i3Start->first.c_str();
+									key = key.stripPrefix('.', true);
+									// we're iterating all 3 level keys, so be sure we match our
+									// prefix (e.g., Lemma, Lemma.1, Lemma.2, etc.)
+									if (key != words[2]) continue;
+								}
 								if (flags & SEARCHFLAG_MATCHWHOLEENTRY) {
 									bool found = !(((flags & REG_ICASE) == REG_ICASE) ? sword::stricmp(i3Start->second.c_str(), words[3]) : strcmp(i3Start->second.c_str(), words[3]));
 									sres = (found) ? i3Start->second.c_str() : 0;




More information about the sword-cvs mailing list