[sword-svn] r2080 - in trunk: include src/frontend src/mgr src/modules/filters tests utilities

scribe at www.crosswire.org scribe at www.crosswire.org
Sun Sep 16 23:21:30 MST 2007


Author: scribe
Date: 2007-09-16 23:21:29 -0700 (Sun, 16 Sep 2007)
New Revision: 2080

Modified:
   trunk/include/curlftpt.h
   trunk/include/filemgr.h
   trunk/include/ftplibftpt.h
   trunk/include/ftptrans.h
   trunk/include/swlog.h
   trunk/src/frontend/swlog.cpp
   trunk/src/mgr/curlftpt.cpp
   trunk/src/mgr/ftplibftpt.cpp
   trunk/src/mgr/ftptrans.cpp
   trunk/src/mgr/installmgr.cpp
   trunk/src/mgr/localemgr.cpp
   trunk/src/mgr/swmgr.cpp
   trunk/src/modules/filters/utf8transliterator.cpp
   trunk/tests/mgrtest.cpp
   trunk/utilities/installmgr.cpp
Log:
Added new log level logDebug
Added ability to ftpget to a buffer instead of a file
Removed exposure of parseftp struct


Modified: trunk/include/curlftpt.h
===================================================================
--- trunk/include/curlftpt.h	2007-09-15 22:38:41 UTC (rev 2079)
+++ trunk/include/curlftpt.h	2007-09-17 06:21:29 UTC (rev 2080)
@@ -23,7 +23,7 @@
 	CURLFTPTransport(const char *host, StatusReporter *statusReporter = 0);
 	~CURLFTPTransport();
 	
-	virtual char getURL(const char *destPath, const char *sourceURL);
+	virtual char getURL(const char *destPath, const char *sourceURL, SWBuf *destBuf = 0);
 };
 
 

Modified: trunk/include/filemgr.h
===================================================================
--- trunk/include/filemgr.h	2007-09-15 22:38:41 UTC (rev 2079)
+++ trunk/include/filemgr.h	2007-09-17 06:21:29 UTC (rev 2080)
@@ -27,13 +27,18 @@
 
 #include <defs.h>
 #include <swcacher.h>
+#include <swbuf.h>
 
 SWORD_NAMESPACE_START
 
-class SWBuf;
-
 class SWDLLEXPORT FileMgr;
 
+struct SWDLLEXPORT DirEntry {
+public:
+	SWBuf name;
+	unsigned long size;
+	bool isDirectory;
+};
 /**
 * This class represents one file. It works with the FileMgr object.
 */

Modified: trunk/include/ftplibftpt.h
===================================================================
--- trunk/include/ftplibftpt.h	2007-09-15 22:38:41 UTC (rev 2079)
+++ trunk/include/ftplibftpt.h	2007-09-17 06:21:29 UTC (rev 2080)
@@ -20,7 +20,7 @@
 public:
 	FTPLibFTPTransport(const char *host, StatusReporter *statusReporter = 0);
 	~FTPLibFTPTransport();
-	char getURL(const char *destPath, const char *sourceURL);
+	char getURL(const char *destPath, const char *sourceURL, SWBuf *destBuf = 0);
 };
 
 

Modified: trunk/include/ftptrans.h
===================================================================
--- trunk/include/ftptrans.h	2007-09-15 22:38:41 UTC (rev 2079)
+++ trunk/include/ftptrans.h	2007-09-17 06:21:29 UTC (rev 2080)
@@ -42,15 +42,18 @@
 public:
 	FTPTransport(const char *host, StatusReporter *statusReporter = 0);
 	virtual ~FTPTransport();
-	virtual char getURL(const char *destPath, const char *sourceURL);
 
+	/***********
+	 * override this method in your real impl
+	 * 
+	 * if destBuf then write to buffer instead of file
+	 */
+	virtual char getURL(const char *destPath, const char *sourceURL, SWBuf *destBuf = 0);
+
+
 	int copyDirectory(const char *urlPrefix, const char *dir, const char *dest, const char *suffix);
 
-	// probably change to not expose struct ftpparse.  We probably need our
-	// own FTPFile class or something that contains things like file name,
-	// size, type (dir, file, special).  Then change to vector of this class
-	// instead of ftpparse
-	virtual std::vector<struct ftpparse> getDirList(const char *dirURL);
+	virtual std::vector<struct DirEntry> getDirList(const char *dirURL);
 	void setPassive(bool passive) { this->passive = passive; }
 	void terminate() { term = true; }
 };

Modified: trunk/include/swlog.h
===================================================================
--- trunk/include/swlog.h	2007-09-15 22:38:41 UTC (rev 2079)
+++ trunk/include/swlog.h	2007-09-17 06:21:29 UTC (rev 2080)
@@ -35,6 +35,12 @@
 
 public:
 
+	static const int LOG_ERROR;
+	static const int LOG_WARN;
+	static const int LOG_INFO;
+	static const int LOG_TIMEDINFO;
+	static const int LOG_DEBUG;
+
 	static SWLog *getSystemLog();
 	static void setSystemLog(SWLog *newLogger);
 
@@ -46,8 +52,8 @@
 	void logWarning(const char *fmt, ...) const;
 	void logError(const char *fmt, ...) const;
 	void logInformation(const char *fmt, ...) const;
-
 	virtual void logTimedInformation(const char *fmt, ...) const;
+	void logDebug(const char *fmt, ...) const;
 
 	// Override this method if you want to have a custom logger
 	virtual void logMessage(const char *message, int level) const;

Modified: trunk/src/frontend/swlog.cpp
===================================================================
--- trunk/src/frontend/swlog.cpp	2007-09-15 22:38:41 UTC (rev 2079)
+++ trunk/src/frontend/swlog.cpp	2007-09-17 06:21:29 UTC (rev 2080)
@@ -18,6 +18,11 @@
 
 SWLog *SWLog::systemLog = 0;
 
+const int SWLog::LOG_ERROR     = 1;
+const int SWLog::LOG_WARN      = 2;
+const int SWLog::LOG_INFO      = 3;
+const int SWLog::LOG_TIMEDINFO = 4;
+const int SWLog::LOG_DEBUG     = 5;
 
 SWLog *SWLog::getSystemLog() {
 	static class __staticSystemLog {
@@ -44,11 +49,11 @@
 	char msg[2048];
 	va_list argptr;
 
-	if (logLevel >= 2) {
+	if (logLevel >= LOG_WARN) {
 		va_start(argptr, fmt);
 		vsprintf(msg, fmt, argptr);
 		va_end(argptr);
-		logMessage(msg, 2);
+		logMessage(msg, LOG_WARN);
 	}
 }
 
@@ -61,33 +66,46 @@
 		va_start(argptr, fmt);
 		vsprintf(msg, fmt, argptr);
 		va_end(argptr);
-		logMessage(msg, 1);
+		logMessage(msg, LOG_ERROR);
 	}
 }
 
 
+void SWLog::logInformation(const char *fmt, ...) const {
+	char msg[2048];
+	va_list argptr;
+
+	if (logLevel >= LOG_INFO) {
+		va_start(argptr, fmt);
+		vsprintf(msg, fmt, argptr);
+		va_end(argptr);
+		logMessage(msg, LOG_INFO);
+	}
+}
+
+
 void SWLog::logTimedInformation(const char *fmt, ...) const {
 	char msg[2048];
 	va_list argptr;
 
-	if (logLevel >= 4) {
+	if (logLevel >= LOG_TIMEDINFO) {
 		va_start(argptr, fmt);
 		vsprintf(msg, fmt, argptr);
 		va_end(argptr);
-		logMessage(msg, 4);
+		logMessage(msg, LOG_TIMEDINFO);
 	}
 }
 
 
-void SWLog::logInformation(const char *fmt, ...) const {
+void SWLog::logDebug(const char *fmt, ...) const {
 	char msg[2048];
 	va_list argptr;
 
-	if (logLevel >= 3) {
+	if (logLevel >= LOG_DEBUG) {
 		va_start(argptr, fmt);
 		vsprintf(msg, fmt, argptr);
 		va_end(argptr);
-		logMessage(msg, 3);
+		logMessage(msg, LOG_DEBUG);
 	}
 }
 

Modified: trunk/src/mgr/curlftpt.cpp
===================================================================
--- trunk/src/mgr/curlftpt.cpp	2007-09-15 22:38:41 UTC (rev 2079)
+++ trunk/src/mgr/curlftpt.cpp	2007-09-17 06:21:29 UTC (rev 2080)
@@ -12,12 +12,15 @@
 #include <curl/types.h>
 #include <curl/easy.h>
 
+#include <swlog.h>
+
 SWORD_NAMESPACE_START
 
 
 struct FtpFile {
   const char *filename;
   FILE *stream;
+  SWBuf *destBuf;
 };
 
 
@@ -36,12 +39,18 @@
 
 int my_fwrite(void *buffer, size_t size, size_t nmemb, void *stream) {
 	struct FtpFile *out=(struct FtpFile *)stream;
-	if (out && !out->stream) {
+	if (out && !out->stream && !out->destBuf) {
 		/* open file for writing */
 		out->stream=fopen(out->filename, "wb");
 		if (!out->stream)
 			return -1; /* failure, can't open file to write */
 	}
+	if (out->destBuf) {
+		int s = out->destBuf->size();
+		out->destBuf->size(s+(size*nmemb));
+		memcpy(out->destBuf->getRawData()+s, buffer, size*nmemb);
+		return nmemb;
+	}
 	return fwrite(buffer, size, nmemb, out->stream);
 }
 
@@ -54,6 +63,33 @@
 }
 
 
+static int my_trace(CURL *handle, curl_infotype type, unsigned char *data, size_t size, void *userp) {
+	SWBuf header;
+	(void)userp; /* prevent compiler warning */
+	(void)handle; /* prevent compiler warning */
+
+	switch (type) {
+	case CURLINFO_TEXT: header = "TEXT"; break;
+	case CURLINFO_HEADER_OUT: header = "=> Send header"; break;
+	case CURLINFO_HEADER_IN: header = "<= Recv header"; break;
+	
+	// these we don't want to log (HUGE)
+	case CURLINFO_DATA_OUT: header = "=> Send data";
+	case CURLINFO_SSL_DATA_OUT: header = "=> Send SSL data";
+	case CURLINFO_DATA_IN: header = "<= Recv data"; 
+	case CURLINFO_SSL_DATA_IN: header = "<= Recv SSL data";
+	default: /* in case a new one is introduced to shock us */
+		return 0;
+	}
+	
+	if (size > 120) size = 120;
+	SWBuf text;
+	text.size(size);
+	memcpy(text.getRawData(), data, size);
+	SWLog::getSystemLog()->logDebug("CURLFTPTransport: %s: %s", header.c_str(), text.c_str());
+	return 0;
+}
+
 CURLFTPTransport::CURLFTPTransport(const char *host, StatusReporter *sr) : FTPTransport(host, sr) {
 	session = (CURL *)curl_easy_init();
 }
@@ -64,9 +100,9 @@
 }
 
 
-char CURLFTPTransport::getURL(const char *destPath, const char *sourceURL) {
+char CURLFTPTransport::getURL(const char *destPath, const char *sourceURL, SWBuf *destBuf) {
 	signed char retVal = 0;
-	struct FtpFile ftpfile = {destPath, NULL};
+	struct FtpFile ftpfile = {destPath, 0, destBuf};
 
 	CURLcode res;
 	
@@ -80,6 +116,7 @@
 		curl_easy_setopt(session, CURLOPT_NOPROGRESS, 0);
 		curl_easy_setopt(session, CURLOPT_PROGRESSDATA, statusReporter);
 		curl_easy_setopt(session, CURLOPT_PROGRESSFUNCTION, my_fprogress);
+		curl_easy_setopt(session, CURLOPT_DEBUGFUNCTION, my_trace);
 		/* Set a pointer to our struct to pass to the callback */
 		curl_easy_setopt(session, CURLOPT_FILE, &ftpfile);
 
@@ -96,15 +133,15 @@
 
 #ifdef EPRT_AVAILABLE
 		curl_easy_setopt(session, CURLOPT_FTP_USE_EPRT, 0);
-fprintf(stderr, "***** using CURLOPT_FTP_USE_EPRT\n");
+		SWLog::getSystemLog()->logDebug("***** using CURLOPT_FTP_USE_EPRT\n");
 #endif
 
 		
-fprintf(stderr, "***** About to perform curl easy action. \n");
-fprintf(stderr, "***** destPath: %s \n", destPath);
-fprintf(stderr, "***** sourceURL: %s \n", sourceURL);
+		SWLog::getSystemLog()->logDebug("***** About to perform curl easy action. \n");
+		SWLog::getSystemLog()->logDebug("***** destPath: %s \n", destPath);
+		SWLog::getSystemLog()->logDebug("***** sourceURL: %s \n", sourceURL);
 		res = curl_easy_perform(session);
-fprintf(stderr, "***** Finished performing curl easy action. \n");
+		SWLog::getSystemLog()->logDebug("***** Finished performing curl easy action. \n");
 
 		if(CURLE_OK != res) {
 			retVal = -1;

Modified: trunk/src/mgr/ftplibftpt.cpp
===================================================================
--- trunk/src/mgr/ftplibftpt.cpp	2007-09-15 22:38:41 UTC (rev 2079)
+++ trunk/src/mgr/ftplibftpt.cpp	2007-09-17 06:21:29 UTC (rev 2080)
@@ -4,13 +4,15 @@
  */
  
 #include <stdio.h>
-#include <ftplibftpt.h>
-
 #include <fcntl.h>
 
 #include <ftplib.h>
 
+#include <ftplibftpt.h>
+#include <swlog.h>
+#include <filemgr.h>
 
+
 SWORD_NAMESPACE_START
 
 
@@ -27,13 +29,13 @@
 FTPLibFTPTransport::FTPLibFTPTransport(const char *host, StatusReporter *sr) : FTPTransport(host, sr) {
 	void *retVal = 0;
 
-	fprintf(stderr, "connecting to host %s\n", host);
+	SWLog::getSystemLog()->logDebug("connecting to host %s\n", host);
 	if (FtpConnect(host, (netbuf **)&nControl))
 		retVal = nControl;
 	else
-		fprintf(stderr, "Failed to connect to %s\n", host);
+		SWLog::getSystemLog()->logDebug("Failed to connect to %s\n", host);
 	if (!FtpLogin("anonymous", "installmgr at user.com", (netbuf *)nControl))
-		fprintf(stderr, "Failed to login to %s\n", host);
+		SWLog::getSystemLog()->logDebug("Failed to login to %s\n", host);
 }
 
 
@@ -42,27 +44,41 @@
 }
 
 
-char FTPLibFTPTransport::getURL(const char *destPath, const char *sourceURL) {
+char FTPLibFTPTransport::getURL(const char *destPath, const char *sourceURL, SWBuf *destBuf) {
 	char retVal = 0;
 	SWBuf sourcePath = sourceURL;
+	SWBuf outFile = (!destBuf) ? destPath : "swftplib.tmp";
 	sourcePath << (6 + host.length()); // shift << "ftp://hostname";
-	fprintf(stderr, "getting file %s to %s\n", sourcePath.c_str(), destPath);
+	SWLog::getSystemLog()->logDebug("getting file %s to %s\n", sourcePath.c_str(), outFile.c_str());
 	if (passive)
 		FtpOptions(FTPLIB_CONNMODE, FTPLIB_PASSIVE, (netbuf *)nControl);
 	else
 		FtpOptions(FTPLIB_CONNMODE, FTPLIB_PORT, (netbuf *)nControl);
 	// !!!WDG also want to set callback options
-	if (!strcmp(destPath, "dirlist")) {
-		fprintf(stderr, "getting test directory %s\n", sourcePath.c_str());
+	if (sourcePath.endsWith("/") || sourcePath.endsWith("\\")) {
+		SWLog::getSystemLog()->logDebug("getting test directory %s\n", sourcePath.c_str());
 		FtpDir(NULL, sourcePath, (netbuf *)nControl);
-		fprintf(stderr, "getting real directory %s\n", sourcePath.c_str());
-		retVal = FtpDir(destPath, sourcePath, (netbuf *)nControl) - 1;
+		SWLog::getSystemLog()->logDebug("getting real directory %s\n", sourcePath.c_str());
+		retVal = FtpDir(outFile.c_str(), sourcePath, (netbuf *)nControl) - 1;
 	}
 	else {
-		fprintf(stderr, "getting file %s\n", sourcePath.c_str());
-		retVal = FtpGet(destPath, sourcePath, FTPLIB_IMAGE, (netbuf *)nControl) - 1;
+		SWLog::getSystemLog()->logDebug("getting file %s\n", sourcePath.c_str());
+		retVal = FtpGet(outFile.c_str(), sourcePath, FTPLIB_IMAGE, (netbuf *)nControl) - 1;
 	}
 
+	// Is there a way to FTPGet directly to a buffer?
+	// If not, we probably want to add x-platform way to open a tmp file with FileMgr
+	// This wreaks and will easily fail if a user's CWD is not writable.
+	if (destBuf) {
+		FileDesc *fd = FileMgr::getSystemFileMgr()->open("swftplib.tmp", FileMgr::RDONLY);
+		long size = fd->seek(0, SEEK_END);
+		fd->seek(0, SEEK_SET);
+		destBuf->size(size);
+		fd->read(destBuf->getRawData(), size);
+		FileMgr::getSystemFileMgr()->close(fd);
+		FileMgr::removeFile("swftplib.tmp");
+	}
+
 	return retVal;
 }
 

Modified: trunk/src/mgr/ftptrans.cpp
===================================================================
--- trunk/src/mgr/ftptrans.cpp	2007-09-15 22:38:41 UTC (rev 2079)
+++ trunk/src/mgr/ftptrans.cpp	2007-09-17 06:21:29 UTC (rev 2080)
@@ -49,26 +49,21 @@
 
 
 // override this method in your real transport class
-char FTPTransport::getURL(const char *destPath, const char *sourceURL) {
+char FTPTransport::getURL(const char *destPath, const char *sourceURL, SWBuf *destBuf) {
 	char retVal = 0;
 	return retVal;
 }
 
 
-vector<struct ftpparse> FTPTransport::getDirList(const char *dirURL) {
+vector<struct DirEntry> FTPTransport::getDirList(const char *dirURL) {
 
-	vector<struct ftpparse> dirList;
+	vector<struct DirEntry> dirList;
 	
-	if (!getURL("dirlist", dirURL)) {
-		FileDesc *fd = FileMgr::getSystemFileMgr()->open("dirlist", FileMgr::RDONLY);
-		long size = fd->seek(0, SEEK_END);
-		fd->seek(0, SEEK_SET);
-		char *buf = new char [ size + 1 ];
-		fd->read(buf, size);
-		FileMgr::getSystemFileMgr()->close(fd);
-		char *start = buf;
+	SWBuf dirBuf;
+	if (!getURL("", dirURL, &dirBuf)) {
+		char *start = dirBuf.getRawData();
 		char *end = start;
-		while (start < (buf+size)) {
+		while (start < (dirBuf.getRawData()+dirBuf.size())) {
 			struct ftpparse item;
 			bool looking = true;
 			for (end = start; *end; end++) {
@@ -84,8 +79,13 @@
 			SWLog::getSystemLog()->logWarning("FTPURLGetDir: parsing item %s(%d)\n", start, end-start);
 			int status = ftpparse(&item, start, end - start);
 			SWLog::getSystemLog()->logWarning("FTPURLGetDir: got item %s\n", item.name);
-			if (status)
-				dirList.push_back(item);
+			if (status) {
+				struct DirEntry i;
+				i.name = item.name;
+				i.size = item.size;
+				i.isDirectory = (item.flagtrycwd == 1);
+				dirList.push_back(i);
+			}
 			start = end;
 		}
 	}
@@ -106,7 +106,7 @@
 	url += '/';
 	
 	SWLog::getSystemLog()->logWarning("FTPCopy: getting dir %s\n", url.c_str());
-	vector<struct ftpparse> dirList = getDirList(url.c_str());
+	vector<struct DirEntry> dirList = getDirList(url.c_str());
 
 	if (!dirList.size()) {
 		SWLog::getSystemLog()->logWarning("FTPCopy: failed to read dir %s\n", url.c_str());
@@ -118,25 +118,27 @@
 		totalBytes += dirList[i].size;
 	long completedBytes = 0;
 	for (i = 0; i < dirList.size(); i++) {
-		struct ftpparse &dirEntry = dirList[i];
+		struct DirEntry &dirEntry = dirList[i];
 		SWBuf buffer = (SWBuf)dest;
 		removeTrailingSlash(buffer);
-		buffer += (SWBuf)"/" + (dirEntry.name);
+		buffer += "/";
+		buffer += dirEntry.name;
 		if (!strcmp(&buffer.c_str()[buffer.length()-strlen(suffix)], suffix)) {
 			SWBuf buffer2 = "Downloading (";
 			buffer2.appendFormatted("%d", i+1);
 			buffer2 += " of ";
 			buffer2.appendFormatted("%d", dirList.size());
 			buffer2 += "): ";
-			buffer2 += (dirEntry.name);
+			buffer2 += dirEntry.name;
 			if (statusReporter)
 				statusReporter->preStatus(totalBytes, completedBytes, buffer2.c_str());
 			FileMgr::createParent(buffer.c_str());	// make sure parent directory exists
 			SWTRY {
 				SWBuf url = (SWBuf)urlPrefix + (SWBuf)dir;
 				removeTrailingSlash(url);
-				url += (SWBuf)"/" + dirEntry.name; //dont forget the final slash
-				if (dirEntry.flagtrycwd != 1) {
+				url += "/";
+				url += dirEntry.name; //dont forget the final slash
+				if (!dirEntry.isDirectory) {
 					if (getURL(buffer.c_str(), url.c_str())) {
 						SWLog::getSystemLog()->logWarning("FTPCopy: failed to get file %s\n", url.c_str());
 						return -2;

Modified: trunk/src/mgr/installmgr.cpp
===================================================================
--- trunk/src/mgr/installmgr.cpp	2007-09-15 22:38:41 UTC (rev 2079)
+++ trunk/src/mgr/installmgr.cpp	2007-09-17 06:21:29 UTC (rev 2080)
@@ -20,6 +20,7 @@
 #include <swmgr.h>
 #include <swmodule.h>
 #include <swversion.h>
+#include <swlog.h>
 #include <dirent.h>
 
 #include <stdio.h>
@@ -209,8 +210,8 @@
 
 	// let's be sure we can connect.  This seems to be necessary but sucks
 //	SWBuf url = urlPrefix + is->directory.c_str() + "/"; //dont forget the final slash
-//	if (trans->getURL("dirlist", url.c_str())) {
-//		 fprintf(stderr, "FTPCopy: failed to get dir %s\n", url.c_str());
+//	if (trans->getURL("swdirlist.tmp", url.c_str())) {
+//		 SWLog::getSystemLog()->logDebug("FTPCopy: failed to get dir %s\n", url.c_str());
 //		 return -1;
 //	}
 
@@ -230,7 +231,7 @@
 			removeTrailingSlash(url);
 			url += (SWBuf)"/" + src; //dont forget the final slash
 			if (trans->getURL(dest, url.c_str())) {
-				fprintf(stderr, "FTPCopy: failed to get file %s", url.c_str());
+				SWLog::getSystemLog()->logDebug("FTPCopy: failed to get file %s", url.c_str());
 				retVal = -1;
 			}
 		}
@@ -263,6 +264,10 @@
 	struct dirent *ent;
 	SWBuf modFile;
 
+	SWLog::getSystemLog()->logDebug("***** InstallMgr::installModule\n");
+	if (fromLocation)
+		SWLog::getSystemLog()->logDebug("***** fromLocation: %s \n", fromLocation);
+	SWLog::getSystemLog()->logDebug("***** modName: %s \n", modName);
 
 	if (is)
 		sourceDir = (SWBuf)privatePath + "/" + is->source;
@@ -340,6 +345,10 @@
 				SWBuf absolutePath = entry->second.c_str();
 				SWBuf relativePath = absolutePath;
 				relativePath << strlen(mgr.prefixPath);
+				SWLog::getSystemLog()->logDebug("***** mgr.prefixPath: %s \n", mgr.prefixPath);
+				SWLog::getSystemLog()->logDebug("***** destMgr->prefixPath: %s \n", destMgr->prefixPath);
+				SWLog::getSystemLog()->logDebug("***** absolutePath: %s \n", absolutePath.c_str());
+				SWLog::getSystemLog()->logDebug("***** relativePath: %s \n", relativePath.c_str());
 
 				if (is) {
 					if (ftpCopy(is, relativePath.c_str(), absolutePath.c_str(), true)) {

Modified: trunk/src/mgr/localemgr.cpp
===================================================================
--- trunk/src/mgr/localemgr.cpp	2007-09-15 22:38:41 UTC (rev 2079)
+++ trunk/src/mgr/localemgr.cpp	2007-09-17 06:21:29 UTC (rev 2080)
@@ -37,13 +37,6 @@
 #include <swlog.h>
 
 
-#ifdef _MSC_VER
-#define DEBUGSTR(x)
-#else
-#include<iostream>
-#define DEBUGSTR(x) if (SWMgr::debug) std::cerr << x;
-#endif  
-
 SWORD_NAMESPACE_START
 
 LocaleMgr *LocaleMgr::systemLocaleMgr = 0;
@@ -81,9 +74,9 @@
 	defaultLocaleName = 0;
 	
 	if (!iConfigPath) {
-		DEBUGSTR("LOOKING UP LOCALE DIRECTORY...\n");
+		SWLog::getSystemLog()->logDebug("LOOKING UP LOCALE DIRECTORY...");
 		SWMgr::findConfig(&configType, &prefixPath, &configPath, &augPaths);
-		DEBUGSTR("LOOKING UP LOCALE DIRECTORY COMPLETE.\n\n");
+		SWLog::getSystemLog()->logDebug("LOOKING UP LOCALE DIRECTORY COMPLETE.");
 	}
 	else configPath = (char *)iConfigPath;
 	

Modified: trunk/src/mgr/swmgr.cpp
===================================================================
--- trunk/src/mgr/swmgr.cpp	2007-09-15 22:38:41 UTC (rev 2079)
+++ trunk/src/mgr/swmgr.cpp	2007-09-17 06:21:29 UTC (rev 2080)
@@ -100,20 +100,12 @@
 #endif
 
 
-bool SWMgr::debug = false;
-
 #ifdef GLOBCONFPATH
 const char *SWMgr::globalConfPath = GLOBCONFPATH;
 #else
 const char *SWMgr::globalConfPath = "/etc/sword.conf:/usr/local/etc/sword.conf";
 #endif
 
-#ifdef _MSC_VER
-#define DEBUGSTR(x)
-#else
-#define DEBUGSTR(x) if (SWMgr::debug) std::cerr << x;
-#endif  
-
 void SWMgr::init() {
 	SWOptionFilter *tmpFilter = 0;
 	configPath  = 0;
@@ -365,30 +357,30 @@
 	//debug=1;
 
 	// check for a sysConf passed in to us
-	DEBUGSTR("Checking for provided SWConfig(\"sword.conf\")...");
+	SWLog::getSystemLog()->logDebug("Checking for provided SWConfig(\"sword.conf\")...");
 	if (providedSysConf) {
 		sysConf = providedSysConf;
-		DEBUGSTR("found.\n");
+		SWLog::getSystemLog()->logDebug("found.");
 	}
 	else {
 		// check working directory
-		DEBUGSTR("\nChecking working directory for sword.conf...");
+		SWLog::getSystemLog()->logDebug("Checking working directory for sword.conf...");
 		if (FileMgr::existsFile(".", "sword.conf")) {
-			DEBUGSTR("\nOverriding any systemwide or ~/.sword/ sword.conf with one found in current directory.\n");
+			SWLog::getSystemLog()->logDebug("Overriding any systemwide or ~/.sword/ sword.conf with one found in current directory.");
 			sysConfPath = "./sword.conf";
 		}
 		else {
-			DEBUGSTR("\nChecking working directory for mods.conf...");
+			SWLog::getSystemLog()->logDebug("Checking working directory for mods.conf...");
 			if (FileMgr::existsFile(".", "mods.conf")) {
-				DEBUGSTR("found\n");
+				SWLog::getSystemLog()->logDebug("found.");
 				stdstr(prefixPath, "./");
 				stdstr(configPath, "./mods.conf");
 				return;
 			}
 
-			DEBUGSTR("\nChecking working directory for mods.d...");
+			SWLog::getSystemLog()->logDebug("Checking working directory for mods.d...");
 			if (FileMgr::existsDir(".", "mods.d")) {
-				DEBUGSTR("found\n");
+				SWLog::getSystemLog()->logDebug("found.");
 				stdstr(prefixPath, "./");
 				stdstr(configPath, "./mods.d");
 				*configType = 1;
@@ -396,9 +388,9 @@
 			}
 
 		   // check working directory ../library/
-			DEBUGSTR("\nChecking working directory ../library/ for mods.d...");
+			SWLog::getSystemLog()->logDebug("Checking working directory ../library/ for mods.d...");
 			if (FileMgr::existsDir("../library", "mods.d")) {
-				DEBUGSTR("found\n");
+				SWLog::getSystemLog()->logDebug("found.");
 				stdstr(prefixPath, "../library/");
 				stdstr(configPath, "../library/mods.d");
 				*configType = 1;
@@ -406,27 +398,27 @@
 			}
 
 			// check environment variable SWORD_PATH
-			DEBUGSTR("\nChecking SWORD_PATH...");
+			SWLog::getSystemLog()->logDebug("Checking SWORD_PATH...");
 
 			if (envsworddir != NULL) {
 				
-				DEBUGSTR("found (" << envsworddir << ")\n");
+				SWLog::getSystemLog()->logDebug("found (%s).", envsworddir);
 				path = envsworddir;
 				if ((envsworddir[strlen(envsworddir)-1] != '\\') && (envsworddir[strlen(envsworddir)-1] != '/'))
 					path += "/";
 
-				DEBUGSTR("\nChecking $SWORD_PATH for mods.conf...");
+				SWLog::getSystemLog()->logDebug("Checking $SWORD_PATH for mods.conf...");
 				if (FileMgr::existsFile(path.c_str(), "mods.conf")) {
-					DEBUGSTR("found\n");
+					SWLog::getSystemLog()->logDebug("found.");
 					stdstr(prefixPath, path.c_str());
 					path += "mods.conf";
 					stdstr(configPath, path.c_str());
 					return;
 				}
 
-				DEBUGSTR("\nChecking $SWORD_PATH for mods.d...");
+				SWLog::getSystemLog()->logDebug("Checking $SWORD_PATH for mods.d...");
 				if (FileMgr::existsDir(path.c_str(), "mods.d")) {
-					DEBUGSTR("found\n");
+					SWLog::getSystemLog()->logDebug("found.");
 					stdstr(prefixPath, path.c_str());
 					path += "mods.d";
 					stdstr(configPath, path.c_str());
@@ -438,14 +430,14 @@
 
 			// check for systemwide globalConfPath
 
-			DEBUGSTR("\nParsing " << globalConfPath << "...");
+			SWLog::getSystemLog()->logDebug("Parsing %s...", globalConfPath);
 			char *globPaths = 0;
 			char *gfp;
 			stdstr(&globPaths, globalConfPath);
 			for (gfp = strtok(globPaths, ":"); gfp; gfp = strtok(0, ":")) {
-				DEBUGSTR("\nChecking for " << gfp << "...");
+				SWLog::getSystemLog()->logDebug("Checking for %s...", gfp);
 				if (FileMgr::existsFile(gfp)) {
-					DEBUGSTR("found\n");
+					SWLog::getSystemLog()->logDebug("found.");
 					break;
 				}
 			}
@@ -459,7 +451,7 @@
 					homeDir += "/";
 				homeDir += ".sword/sword.conf";
 				if (FileMgr::existsFile(homeDir)) {
-					DEBUGSTR("\nOverriding any systemwide sword.conf with one found in users home directory.\n");
+					SWLog::getSystemLog()->logDebug("Overriding any systemwide sword.conf with one found in users home directory.");
 					sysConfPath = homeDir;
 				}
 			}
@@ -476,21 +468,21 @@
 			if (((*entry).second.c_str()[strlen((*entry).second.c_str())-1] != '\\') && ((*entry).second.c_str()[strlen((*entry).second.c_str())-1] != '/'))
 				path += "/";
 
-			DEBUGSTR("DataPath in " << sysConfPath << " is set to: " << path);
-			DEBUGSTR("\nChecking for mods.conf in DataPath...");
+			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...");
 			
 			if (FileMgr::existsFile(path.c_str(), "mods.conf")) {
-				DEBUGSTR("found\n");
+				SWLog::getSystemLog()->logDebug("found.");
 				stdstr(prefixPath, path.c_str());
 				path += "mods.conf";
 				stdstr(configPath, path.c_str());
 				*configType = 1;
 			}
 
-			DEBUGSTR("\nChecking for mods.d in DataPath...");
+			SWLog::getSystemLog()->logDebug("Checking for mods.d in DataPath...");
 
 			if (FileMgr::existsDir(path.c_str(), "mods.d")) {
-				DEBUGSTR("found\n");
+				SWLog::getSystemLog()->logDebug("found.");
 				stdstr(prefixPath, path.c_str());
 				path += "mods.d";
 				stdstr(configPath, path.c_str());
@@ -519,25 +511,25 @@
 
 	// check ~/.sword/
 
-	DEBUGSTR("\nChecking home directory for ~/.sword...");
+	SWLog::getSystemLog()->logDebug("Checking home directory for ~/.sword...");
 
 	if (envhomedir != NULL) {
 		path = envhomedir;
 		if ((envhomedir[strlen(envhomedir)-1] != '\\') && (envhomedir[strlen(envhomedir)-1] != '/'))
 			path += "/";
 		path += ".sword/";
-		DEBUGSTR("\n  Checking for " << path << "mods.conf...");
+		SWLog::getSystemLog()->logDebug("  Checking for %smods.conf...", path.c_str());
 		if (FileMgr::existsFile(path.c_str(), "mods.conf")) {
-			DEBUGSTR("found\n");
+			SWLog::getSystemLog()->logDebug("found.");
 			stdstr(prefixPath, path.c_str());
 			path += "mods.conf";
 			stdstr(configPath, path.c_str());
 			return;
 		}
 
-		DEBUGSTR("\n  Checking for " << path << "mods.d...");
+		SWLog::getSystemLog()->logDebug("  Checking for %smods.d...", path.c_str());
 		if (FileMgr::existsDir(path.c_str(), "mods.d")) {
-			DEBUGSTR("found\n");
+			SWLog::getSystemLog()->logDebug("found.");
 			stdstr(prefixPath, path.c_str());
 			path += "mods.d";
 			stdstr(configPath, path.c_str());
@@ -652,9 +644,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...
-			DEBUGSTR("LOOKING UP MODULE CONFIGURATION...\n");
+			SWLog::getSystemLog()->logDebug("LOOKING UP MODULE CONFIGURATION...");
 			findConfig(&configType, &prefixPath, &configPath, &augPaths, sysconfig);
-			DEBUGSTR("LOOKING UP MODULE CONFIGURATION COMPLETE.\n\n");
+			SWLog::getSystemLog()->logDebug("LOOKING UP MODULE CONFIGURATION COMPLETE.");
 		}
 		if (configPath) {
 			if (configType)

Modified: trunk/src/modules/filters/utf8transliterator.cpp
===================================================================
--- trunk/src/modules/filters/utf8transliterator.cpp	2007-09-15 22:38:41 UTC (rev 2079)
+++ trunk/src/modules/filters/utf8transliterator.cpp	2007-09-17 06:21:29 UTC (rev 2080)
@@ -136,8 +136,8 @@
 	UResourceBundle *bundle, *transIDs, *colBund;
 	bundle = ures_openDirect(SW_RESDATA, translit_swordindex, &status);
 	if (U_FAILURE(status)) {
-		SWLog::getSystemLog()->logError("no resource index to load");
-		SWLog::getSystemLog()->logError("status %s", u_errorName(status));
+		SWLog::getSystemLog()->logError("UTF8Transliterator: ICU: no resource index to load");
+		SWLog::getSystemLog()->logError("UTF8Transliterator: ICU: status %s", u_errorName(status));
 		return;
 	}
 
@@ -154,7 +154,7 @@
 				UnicodeString id = ures_getUnicodeStringByIndex(colBund, 0, &status);
                         	UChar type = ures_getUnicodeStringByIndex(colBund, 1, &status).charAt(0);
 				UnicodeString resString = ures_getUnicodeStringByIndex(colBund, 2, &status);
-                        	SWLog::getSystemLog()->logInformation("ok so far");
+                        	SWLog::getSystemLog()->logDebug("ok so far");
 
 				 if (U_SUCCESS(status)) {
 					switch (type) {
@@ -169,9 +169,9 @@
 								0x0046 /*F*/) ?
 								UTRANS_FORWARD : UTRANS_REVERSE;
 		                                        //registry->put(id, resString, dir, visible);
-							SWLog::getSystemLog()->logInformation("instantiating %s ...", resString.getBuffer());
+							SWLog::getSystemLog()->logDebug("instantiating %s ...", resString.getBuffer());
 					    		registerTrans(id, resString, dir, status);
-							SWLog::getSystemLog()->logInformation("done.");
+							SWLog::getSystemLog()->logDebug("done.");
 	                                	}
 						break;
 					case 0x61: // 'a'
@@ -180,16 +180,16 @@
                                 		break;
 					}
         	                 }
-                	         else SWLog::getSystemLog()->logError("Failed to get resString");
+                	         else SWLog::getSystemLog()->logError("UTF8Transliterator: ICU: Failed to get resString");
 	                }
-			else SWLog::getSystemLog()->logError("Failed to get row");
+			else SWLog::getSystemLog()->logError("UTF8Transliterator: ICU: Failed to get row");
 			ures_close(colBund);
 		}
 	}
 	else
 	{
-		SWLog::getSystemLog()->logError("no resource index to load");
-		SWLog::getSystemLog()->logError("status %s", u_errorName(status));
+		SWLog::getSystemLog()->logError("UTF8Transliterator: ICU: no resource index to load");
+		SWLog::getSystemLog()->logError("UTF8Transliterator: ICU: status %s", u_errorName(status));
 	}
 
 	ures_close(transIDs);
@@ -202,7 +202,7 @@
 		UTransDirection dir, UErrorCode &status )
 {
 #ifndef _ICUSWORD_
-		SWLog::getSystemLog()->logInformation("registering ID locally %s", ID.getBuffer());
+		SWLog::getSystemLog()->logDebug("registering ID locally %s", ID.getBuffer());
 		SWTransData swstuff;
 		swstuff.resource = resource;
 		swstuff.dir = dir;
@@ -220,7 +220,7 @@
 		if (!U_FAILURE(status))
 		{
 			// already have it, clean up and return true
-			SWLog::getSystemLog()->logInformation("already have it %s", ID.getBuffer());
+			SWLog::getSystemLog()->logDebug("already have it %s", ID.getBuffer());
 			delete trans;
 			return true;
 		}
@@ -229,13 +229,13 @@
 	SWTransMap::iterator swelement;
 	if ((swelement = transMap.find(ID)) != transMap.end())
 	{
-		SWLog::getSystemLog()->logInformation("found element in map");
+		SWLog::getSystemLog()->logDebug("found element in map");
 		SWTransData swstuff = (*swelement).second;
 		UParseError parseError;
 		//UErrorCode status;
 		//std::cout << "unregistering " << ID << std::endl;
 		//Transliterator::unregister(ID);
-		SWLog::getSystemLog()->logInformation("resource is %s", swstuff.resource.getBuffer());
+		SWLog::getSystemLog()->logDebug("resource is %s", swstuff.resource.getBuffer());
 
 		// Get the rules
 		//std::cout << "importing: " << ID << ", " << resource << std::endl;
@@ -246,8 +246,8 @@
 		//parser.parse(rules, isReverse ? UTRANS_REVERSE : UTRANS_FORWARD,
 		//        parseError, status);
 		if (U_FAILURE(status)) {
-			SWLog::getSystemLog()->logError("Failed to get rules");
-			SWLog::getSystemLog()->logError("status %s", u_errorName(status));
+			SWLog::getSystemLog()->logError("UTF8Transliterator: ICU: Failed to get rules");
+			SWLog::getSystemLog()->logError("UTF8Transliterator: ICU: status %s", u_errorName(status));
 			return false;
 		}
 
@@ -255,13 +255,13 @@
 		Transliterator *trans = Transliterator::createFromRules(ID, rules, swstuff.dir,
 			parseError,status);
 		if (U_FAILURE(status)) {
-			SWLog::getSystemLog()->logError("Failed to create transliterator");
-			SWLog::getSystemLog()->logError("status %s", u_errorName(status));
-			SWLog::getSystemLog()->logError("Parse error: line %s", parseError.line);
-			SWLog::getSystemLog()->logError("Parse error: offset %d", parseError.offset);
-			SWLog::getSystemLog()->logError("Parse error: preContext %s", *parseError.preContext);
-			SWLog::getSystemLog()->logError("Parse error: postContext %s", *parseError.postContext);
-			SWLog::getSystemLog()->logError("rules were");
+			SWLog::getSystemLog()->logError("UTF8Transliterator: ICU: Failed to create transliterator");
+			SWLog::getSystemLog()->logError("UTF8Transliterator: ICU: status %s", u_errorName(status));
+			SWLog::getSystemLog()->logError("UTF8Transliterator: ICU: Parse error: line %s", parseError.line);
+			SWLog::getSystemLog()->logError("UTF8Transliterator: ICU: Parse error: offset %d", parseError.offset);
+			SWLog::getSystemLog()->logError("UTF8Transliterator: ICU: Parse error: preContext %s", *parseError.preContext);
+			SWLog::getSystemLog()->logError("UTF8Transliterator: ICU: Parse error: postContext %s", *parseError.postContext);
+			SWLog::getSystemLog()->logError("UTF8Transliterator: ICU: rules were");
 //			SWLog::getSystemLog()->logError((const char *)rules);
 			return false;
 		}

Modified: trunk/tests/mgrtest.cpp
===================================================================
--- trunk/tests/mgrtest.cpp	2007-09-15 22:38:41 UTC (rev 2079)
+++ trunk/tests/mgrtest.cpp	2007-09-17 06:21:29 UTC (rev 2080)
@@ -1,4 +1,5 @@
 #include <swmgr.h>
+#include <swlog.h>
 #include <iostream>
 #include <versekey.h>
 #include <swmodule.h>
@@ -9,7 +10,7 @@
 
 int main(int argc, char **argv) {
 	std::cerr << "\n";
-	SWMgr::debug = true;
+	SWLog::getSystemLog()->setLogLevel(SWLog::LOG_DEBUG);
 	SWConfig *sysConf = 0;
 	if (argc > 1) {
 		sysConf = new SWConfig(argv[1]);

Modified: trunk/utilities/installmgr.cpp
===================================================================
--- trunk/utilities/installmgr.cpp	2007-09-15 22:38:41 UTC (rev 2079)
+++ trunk/utilities/installmgr.cpp	2007-09-17 06:21:29 UTC (rev 2080)
@@ -5,6 +5,7 @@
 #include <map>
 #include <swmodule.h>
 #include <stdio.h>
+#include <swlog.h>
 
 using namespace sword;
 using std::cout;
@@ -210,6 +211,8 @@
 	baseDir += "/.sword/InstallMgr";
 	installMgr = new InstallMgr(baseDir);
 
+	SWLog::getSystemLog()->setLogLevel(SWLog::LOG_DEBUG);
+
 	cout << "\n";
 
 	if (argc < 2)




More information about the sword-cvs mailing list