[sword-svn] r3767 - in trunk: bindings src/mgr

scribe at crosswire.org scribe at crosswire.org
Sun Jul 26 10:10:31 EDT 2020


Author: scribe
Date: 2020-07-26 10:10:31 -0400 (Sun, 26 Jul 2020)
New Revision: 3767

Modified:
   trunk/bindings/flatapi.cpp
   trunk/src/mgr/localemgr.cpp
Log:
Fixed LocaleMgr to use FileMgr getDirList
Fixed flatapi.cpp to not insert its own StringMgr by default


Modified: trunk/bindings/flatapi.cpp
===================================================================
--- trunk/bindings/flatapi.cpp	2020-07-26 13:10:56 UTC (rev 3766)
+++ trunk/bindings/flatapi.cpp	2020-07-26 14:10:31 UTC (rev 3767)
@@ -151,7 +151,7 @@
 	}
 }
 #endif
-    
+
 class MyStatusReporter : public StatusReporter {
 public:
 	unsigned long last;
@@ -159,19 +159,19 @@
 	MyStatusReporter() : last(0), statusReporter(0) {}
 	void init(org_crosswire_sword_InstallMgr_StatusCallback sr) { statusReporter = sr; last = 0xffffffff; }
 
-    virtual void update(unsigned long totalBytes, unsigned long completedBytes) {
+	virtual void update(unsigned long totalBytes, unsigned long completedBytes) {
 
 		if (!statusReporter) return;
 
 		if (completedBytes != last) {
 			statusReporter("update", totalBytes, completedBytes);
 			last = completedBytes;
-        }
+		}
 	}
-    
-    
-    virtual void preStatus(long totalBytes, long completedBytes, const char *message) {
 
+
+	virtual void preStatus(long totalBytes, long completedBytes, const char *message) {
+
 		if (!statusReporter) return;
 
 		statusReporter(message, totalBytes, completedBytes);
@@ -188,7 +188,7 @@
 */
 	}
 
-};      
+};
 
 class HandleSWModule {
 public:
@@ -369,7 +369,8 @@
 		HandleSWMgr::availableLocales = 0;
 
 		HandleInstMgr::remoteSources = 0;
-		StringMgr::setSystemStringMgr(new FlatStringMgr());
+		// add this stringmgr to allow you to supply a toUpperUTF8 method
+		// StringMgr::setSystemStringMgr(new FlatStringMgr());
 	}
 	~InitStatics() {
 
@@ -379,7 +380,7 @@
 		HandleInstMgr::clearRemoteSources();
 
 		clearStringArray(&tmpStringArrayRetVal);
-        sword::stdstr(&tmpStringRetVal, (const char *)0);
+		sword::stdstr(&tmpStringRetVal, (const char *)0);
 		
 	}
 } _initStatics;
@@ -458,15 +459,15 @@
 	hmod->peeuuu.init(progressReporter);
 	if ((scope) && (strlen(scope)) > 0) {
 		sword::SWKey *p = module->createKey();
-        	sword::VerseKey *parser = SWDYNAMIC_CAST(VerseKey, p);
-	        if (!parser) {
-        		delete p;
-	                parser = new VerseKey();
-	        }
-	        *parser = module->getKeyText();
+		sword::VerseKey *parser = SWDYNAMIC_CAST(VerseKey, p);
+		if (!parser) {
+			delete p;
+			parser = new VerseKey();
+		}
+		*parser = module->getKeyText();
 		lscope = parser->parseVerseList(scope, *parser, true);
 		result = module->search(searchString, searchType, flags, &lscope, 0, &percentUpdate, &(hmod->peeuuu));
-                delete parser;
+		delete parser;
 	}
 	else	result = module->search(searchString, searchType, flags, 0, 0, &percentUpdate, &(hmod->peeuuu));
 
@@ -1302,20 +1303,20 @@
 SWLog::getSystemLog()->logDebug("libsword: getConfigSections %s at path: %s", exists?"Exists":"Absent", confPath);
 	if (exists) {
 		SWConfig config(confPath);
-        SectionMap::const_iterator sit;
+		SectionMap::const_iterator sit;
 		for (sit = config.getSections().begin(); sit != config.getSections().end(); ++sit) {
 			count++;
 		}
-        SWLog::getSystemLog()->logDebug("libsword: %d sections found in config", count);
-        retVal = (const char **)calloc(count+1, sizeof(const char *));
+		SWLog::getSystemLog()->logDebug("libsword: %d sections found in config", count);
+		retVal = (const char **)calloc(count+1, sizeof(const char *));
 		count = 0;
 		for (sit = config.getSections().begin(); sit != config.getSections().end(); ++sit) {
 			stdstr((char **)&(retVal[count++]), assureValidUTF8(sit->first.c_str()));
 		}
 	}
-    else {
-        retVal = (const char **)calloc(1, sizeof(const char *));
-    }
+	else {
+		retVal = (const char **)calloc(1, sizeof(const char *));
+	}
 
 	tmpStringArrayRetVal = retVal;
 	return retVal;
@@ -1836,7 +1837,7 @@
 SWLog::getSystemLog()->logDebug("libsword: sendBibleSyncMessage() begin");
 
 #ifdef BIBLESYNC
-    if (!bibleSync) {
+	if (!bibleSync) {
 SWLog::getSystemLog()->logDebug("libsword: sendBibleSyncMessage() bibleSync not active; message not sent.");
 		return;
 	}

Modified: trunk/src/mgr/localemgr.cpp
===================================================================
--- trunk/src/mgr/localemgr.cpp	2020-07-26 13:10:56 UTC (rev 3766)
+++ trunk/src/mgr/localemgr.cpp	2020-07-26 14:10:31 UTC (rev 3767)
@@ -156,47 +156,42 @@
 
 
 void LocaleMgr::loadConfigDir(const char *ipath) {
-	DIR *dir;
-	struct dirent *ent;
-	SWBuf newmodfile;
 	LocaleMap::iterator it;
 	SWLog::getSystemLog()->logInformation("LocaleMgr::loadConfigDir loading %s", ipath);
  
-	if ((dir = opendir(ipath))) {
-		rewinddir(dir);
-		while ((ent = readdir(dir))) {
-			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;
-				SWLocale *locale = new SWLocale(newmodfile.c_str());
-				
-				if (locale->getName()) {					
-					bool supported = false;
-					if (StringMgr::hasUTF8Support()) {
-						supported = (locale->getEncoding() && (!strcmp(locale->getEncoding(), "UTF-8") || !strcmp(locale->getEncoding(), "ASCII")) );
-					}
-					else {
-						supported = !locale->getEncoding() || (locale->getEncoding() && (strcmp(locale->getEncoding(), "UTF-8") != 0)); //exclude UTF-8 locales
-					}
-					
-					if (!supported) { //not supported
-						delete locale;
-						continue;
-					}
-				
-					it = locales->find(locale->getName());
-					if (it != locales->end()) { // already present
-						*((*it).second) += *locale;
-						delete locale;
-					}
-					else locales->insert(LocaleMap::value_type(locale->getName(), locale));
+	SWBuf baseDir = ipath;
+	if (!baseDir.endsWith('/') && !baseDir.endsWith('\\')) baseDir += '/';
+
+	std::vector<DirEntry> dirList = FileMgr::getDirList(ipath);
+	for (unsigned int i = 0; i < dirList.size(); ++i) {
+		if (dirList[i].name.endsWith(".conf")) {
+			SWBuf localeFile;
+			localeFile = baseDir + dirList[i].name;
+			SWLocale *locale = new SWLocale(localeFile);
+
+			if (locale->getName()) {					
+				bool supported = false;
+				if (StringMgr::hasUTF8Support()) {
+					supported = (locale->getEncoding() && (!strcmp(locale->getEncoding(), "UTF-8") || !strcmp(locale->getEncoding(), "ASCII")) );
 				}
-				else	delete locale;
+				else {
+					supported = !locale->getEncoding() || (locale->getEncoding() && (strcmp(locale->getEncoding(), "UTF-8") != 0)); //exclude UTF-8 locales
+				}
+
+				if (!supported) { //not supported
+					delete locale;
+					continue;
+				}
+
+				it = locales->find(locale->getName());
+				if (it != locales->end()) { // already present
+					*((*it).second) += *locale;
+					delete locale;
+				}
+				else locales->insert(LocaleMap::value_type(locale->getName(), locale));
 			}
+			else	delete locale;
 		}
-		closedir(dir);
 	}
 }
 



More information about the sword-cvs mailing list