[sword-svn] r2262 - in trunk: examples/cmdline src/mgr

scribe at crosswire.org scribe at crosswire.org
Mon Feb 16 19:11:54 MST 2009


Author: scribe
Date: 2009-02-16 19:11:54 -0700 (Mon, 16 Feb 2009)
New Revision: 2262

Added:
   trunk/examples/cmdline/outrender.cpp
Modified:
   trunk/examples/cmdline/Makefile.am
   trunk/examples/cmdline/outplain.cpp
   trunk/src/mgr/swmgr.cpp
Log:
Added new example outrender.cpp, mostly for profiling, but also a good example
Completed the circuit for specifying an alternate versification in a .conf


Modified: trunk/examples/cmdline/Makefile.am
===================================================================
--- trunk/examples/cmdline/Makefile.am	2009-02-16 12:11:41 UTC (rev 2261)
+++ trunk/examples/cmdline/Makefile.am	2009-02-17 02:11:54 UTC (rev 2262)
@@ -2,7 +2,7 @@
 INCLUDES = -I $(top_srcdir)/include
 LDADD = $(top_builddir)/lib/libsword.la
 
-noinst_PROGRAMS = lookup search threaded_search listoptions verserangeparse outplain
+noinst_PROGRAMS = lookup search threaded_search listoptions verserangeparse outplain outrender
 
 lookup_SOURCES = lookup.cpp
 search_SOURCES = search.cpp
@@ -10,4 +10,5 @@
 verserangeparse_SOURCES = verserangeparse.cpp
 threaded_search_SOURCES = threaded_search.cpp
 outplain_SOURCES = outplain.cpp
+outrender = outrender.cpp
 threaded_search_LDADD = $(LDADD) -lpthread

Modified: trunk/examples/cmdline/outplain.cpp
===================================================================
--- trunk/examples/cmdline/outplain.cpp	2009-02-16 12:11:41 UTC (rev 2261)
+++ trunk/examples/cmdline/outplain.cpp	2009-02-17 02:11:54 UTC (rev 2262)
@@ -18,12 +18,13 @@
 #include <swmgr.h>
 #include <swmodule.h>
 #include <versekey.h>
+#include <markupfiltmgr.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
+	SWMgr manager(new MarkupFilterMgr(sword::FMT_HTMLHREF, sword::ENC_UTF16));
 
 	const char *bookName = (argc > 1) ? argv[1] : "WLC";
 	SWModule *b = manager.getModule(bookName);
@@ -35,8 +36,9 @@
 	if (!book.getRawEntryBuf().size()) return -2; 	// empty module
 	for (;!book.Error(); book++) {
 		cout << "$$$";
-		if (vk) cout << vk->getOSISRef();
-		else	cout << book.getKeyText();
-		cout << "\n" << book.StripText() << "\n\n";
+//		if (vk) cout << vk->getOSISRef();
+//		else
+			cout << book.getKeyText();
+		cout << "\n" << book.RenderText() << "\n\n";
 	}
 }

Added: trunk/examples/cmdline/outrender.cpp
===================================================================
--- trunk/examples/cmdline/outrender.cpp	                        (rev 0)
+++ trunk/examples/cmdline/outrender.cpp	2009-02-17 02:11:54 UTC (rev 2262)
@@ -0,0 +1,44 @@
+/******************************************************************************
+ * 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>
+#include <versekey.h>
+#include <markupfiltmgr.h>
+
+using namespace sword;
+using namespace std;
+
+int main(int argc, char **argv) {
+	SWMgr manager(new MarkupFilterMgr(sword::FMT_HTMLHREF, sword::ENC_UTF16));
+
+	const char *bookName = (argc > 1) ? argv[1] : "WLC";
+	SWModule *b = manager.getModule(bookName);
+	if (!b) return -1;
+	SWModule &book = *b;
+	book.processEntryAttributes(false);
+	VerseKey *vk = SWDYNAMIC_CAST(VerseKey, book.getKey());
+	for (book = TOP; !book.Error() && !book.getRawEntryBuf().size(); book++);
+	if (!book.getRawEntryBuf().size()) return -2; 	// empty module
+	for (;!book.Error(); book++) {
+		cout << "$$$";
+//		if (vk) cout << vk->getOSISRef();
+//		else
+			cout << book.getKeyText();
+		cout << "\n" << book.RenderText() << "\n\n";
+	}
+}

Modified: trunk/src/mgr/swmgr.cpp
===================================================================
--- trunk/src/mgr/swmgr.cpp	2009-02-16 12:11:41 UTC (rev 2261)
+++ trunk/src/mgr/swmgr.cpp	2009-02-17 02:11:54 UTC (rev 2262)
@@ -790,6 +790,8 @@
 	if ((prefixPath[strlen(prefixPath)-1] != '\\') && (prefixPath[strlen(prefixPath)-1] != '/'))
 		datapath += "/";
 
+	SWBuf versification = ((entry = section.find("Versification"))  != section.end()) ? (*entry).second : (SWBuf)"KJV";
+
 	// DataPath - relative path to data used by module driver.  May be a directory, may be a File.
 	//   Typically not useful by outside world.  See AbsoluteDataPath, PrefixPath, and RelativePrefixPath
 	//   below.
@@ -865,17 +867,17 @@
 
 		if (compress) {
 			if (!stricmp(driver, "zText"))
-				newmod = new zText(datapath.c_str(), name, description.c_str(), blockType, compress, 0, enc, direction, markup, lang.c_str());
-			else	newmod = new zCom(datapath.c_str(), name, description.c_str(), blockType, compress, 0, enc, direction, markup, lang.c_str());
+				newmod = new zText(datapath.c_str(), name, description.c_str(), blockType, compress, 0, enc, direction, markup, lang.c_str(), versification);
+			else	newmod = new zCom(datapath.c_str(), name, description.c_str(), blockType, compress, 0, enc, direction, markup, lang.c_str(), versification);
 		}
 	}
 
 	if (!stricmp(driver, "RawText")) {
-		newmod = new RawText(datapath.c_str(), name, description.c_str(), 0, enc, direction, markup, lang.c_str());
+		newmod = new RawText(datapath.c_str(), name, description.c_str(), 0, enc, direction, markup, lang.c_str(), versification);
 	}
 
 	if (!stricmp(driver, "RawText4")) {
-		newmod = new RawText4(datapath.c_str(), name, description.c_str(), 0, enc, direction, markup, lang.c_str());
+		newmod = new RawText4(datapath.c_str(), name, description.c_str(), 0, enc, direction, markup, lang.c_str(), versification);
 	}
 
 	// backward support old drivers
@@ -884,11 +886,11 @@
 	}
 
 	if (!stricmp(driver, "RawCom")) {
-		newmod = new RawCom(datapath.c_str(), name, description.c_str(), 0, enc, direction, markup, lang.c_str());
+		newmod = new RawCom(datapath.c_str(), name, description.c_str(), 0, enc, direction, markup, lang.c_str(), versification);
 	}
 
 	if (!stricmp(driver, "RawCom4")) {
-		newmod = new RawCom4(datapath.c_str(), name, description.c_str(), 0, enc, direction, markup, lang.c_str());
+		newmod = new RawCom4(datapath.c_str(), name, description.c_str(), 0, enc, direction, markup, lang.c_str(), versification);
 	}
 
 	if (!stricmp(driver, "RawFiles")) {




More information about the sword-cvs mailing list