[sword-svn] r1852 - in trunk: bindings/corba/orbitcpp include src/modules/filters

scribe at crosswire.org scribe at crosswire.org
Sun Sep 25 23:41:18 MST 2005


Author: scribe
Date: 2005-09-25 23:41:17 -0700 (Sun, 25 Sep 2005)
New Revision: 1852

Added:
   trunk/include/gbfwordjs.h
   trunk/src/modules/filters/gbfwordjs.cpp
Modified:
   trunk/bindings/corba/orbitcpp/webmgr.hpp
   trunk/include/Makefile.am
   trunk/src/modules/filters/Makefile.am
   trunk/src/modules/filters/gbfstrongs.cpp
Log:
Added support for GBF javascript markup so we can get lemma/morph help with LXX


Modified: trunk/bindings/corba/orbitcpp/webmgr.hpp
===================================================================
--- trunk/bindings/corba/orbitcpp/webmgr.hpp	2005-09-21 17:32:19 UTC (rev 1851)
+++ trunk/bindings/corba/orbitcpp/webmgr.hpp	2005-09-26 06:41:17 UTC (rev 1852)
@@ -5,12 +5,14 @@
 #include <markupfiltmgr.h>
 #include <osiswordjs.h>
 #include <thmlwordjs.h>
+#include <gbfwordjs.h>
 
 using namespace sword;
 
 class WebMgr : public SWMgr {
 	OSISWordJS *osisWordJS;
 	ThMLWordJS *thmlWordJS;
+	GBFWordJS *gbfWordJS;
 	SWModule *defaultGreekLex;
 	SWModule *defaultHebLex;
 	SWModule *defaultGreekParse;
@@ -25,17 +27,21 @@
 
 		osisWordJS = new OSISWordJS();
 		thmlWordJS = new ThMLWordJS();
+		gbfWordJS = new GBFWordJS();
 		Load();
 		osisWordJS->setDefaultModules(defaultGreekLex, defaultHebLex, defaultGreekParse, defaultHebParse);
 		thmlWordJS->setDefaultModules(defaultGreekLex, defaultHebLex, defaultGreekParse, defaultHebParse);
+		gbfWordJS->setDefaultModules(defaultGreekLex, defaultHebLex, defaultGreekParse, defaultHebParse);
 		osisWordJS->setMgr(this);
 		thmlWordJS->setMgr(this);
+		gbfWordJS->setMgr(this);
 		setGlobalOption("Textual Variants", "Primary Reading");
 	}
 
 	~WebMgr() {
 		delete osisWordJS;
 		delete thmlWordJS;
+		delete gbfWordJS;
 	}
 
 
@@ -65,6 +71,9 @@
 		if (module->Markup() == FMT_THML) {
 			module->AddOptionFilter(thmlWordJS);
 		}
+		if (module->Markup() == FMT_GBF) {
+			module->AddOptionFilter(gbfWordJS);
+		}
 		SWMgr::AddGlobalOptions(module, section, start, end);
 	}
 
@@ -72,6 +81,7 @@
 	void setJavascript(bool val) {
 		osisWordJS->setOptionValue((val)?"On":"Off");
 		thmlWordJS->setOptionValue((val)?"On":"Off");
+		gbfWordJS->setOptionValue((val)?"On":"Off");
 	}
 };
 

Modified: trunk/include/Makefile.am
===================================================================
--- trunk/include/Makefile.am	2005-09-21 17:32:19 UTC (rev 1851)
+++ trunk/include/Makefile.am	2005-09-26 06:41:17 UTC (rev 1852)
@@ -28,6 +28,7 @@
 pkginclude_HEADERS += $(swincludedir)/gbfredletterwords.h
 pkginclude_HEADERS += $(swincludedir)/gbfrtf.h
 pkginclude_HEADERS += $(swincludedir)/gbfstrongs.h
+pkginclude_HEADERS += $(swincludedir)/gbfwordjs.h
 pkginclude_HEADERS += $(swincludedir)/gbfthml.h
 pkginclude_HEADERS += $(swincludedir)/greeklexattribs.h
 

Added: trunk/include/gbfwordjs.h
===================================================================
--- trunk/include/gbfwordjs.h	2005-09-21 17:32:19 UTC (rev 1851)
+++ trunk/include/gbfwordjs.h	2005-09-26 06:41:17 UTC (rev 1852)
@@ -0,0 +1,52 @@
+/***************************************************************************
+ *
+ * $Id: gbfwordjs.h 1688 2005-01-01 04:42:26Z scribe $
+ *
+ * Copyright 1998 CrossWire Bible Society (http://www.crosswire.org)
+ *	CrossWire Bible Society
+ *	P. O. Box 2528
+ *	Tempe, AZ  85280-2528
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation version 2.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ */
+
+#ifndef GBFWORDSJS_H
+#define GBFWORDSJS_H
+
+#include <swoptfilter.h>
+
+SWORD_NAMESPACE_START
+
+class SWMgr;
+  /** This Filter shows/hides strong's numbers in a GBF text
+  */
+class SWDLLEXPORT GBFWordJS : public SWOptionFilter {
+     SWModule *defaultGreekLex;
+     SWModule *defaultHebLex;
+     SWModule *defaultGreekParse;
+     SWModule *defaultHebParse;
+     SWMgr *mgr;
+
+public:
+	GBFWordJS();
+	virtual ~GBFWordJS();
+	virtual char processText(SWBuf &text, const SWKey *key = 0, const SWModule *module = 0);
+	void setDefaultModules(SWModule *defaultGreekLex = 0, SWModule *defaultHebLex = 0, SWModule *defaultGreekParse = 0, SWModule *defaultHebParse = 0) {
+		this->defaultGreekLex   = defaultGreekLex;
+		this->defaultHebLex     = defaultHebLex;
+		this->defaultGreekParse = defaultGreekParse;
+		this->defaultHebParse   = defaultHebParse;
+	}
+	void setMgr(SWMgr *mgr) { this->mgr = mgr; }
+};
+
+SWORD_NAMESPACE_END
+#endif

Modified: trunk/src/modules/filters/Makefile.am
===================================================================
--- trunk/src/modules/filters/Makefile.am	2005-09-21 17:32:19 UTC (rev 1851)
+++ trunk/src/modules/filters/Makefile.am	2005-09-26 06:41:17 UTC (rev 1852)
@@ -13,6 +13,7 @@
 GBFFIL += $(filtersdir)/gbfheadings.cpp
 GBFFIL += $(filtersdir)/gbfredletterwords.cpp
 GBFFIL += $(filtersdir)/gbfmorph.cpp
+GBFFIL += $(filtersdir)/gbfwordjs.cpp
 
 THMLFIL = $(filtersdir)/thmlstrongs.cpp
 THMLFIL += $(filtersdir)/thmlfootnotes.cpp

Modified: trunk/src/modules/filters/gbfstrongs.cpp
===================================================================
--- trunk/src/modules/filters/gbfstrongs.cpp	2005-09-21 17:32:19 UTC (rev 1851)
+++ trunk/src/modules/filters/gbfstrongs.cpp	2005-09-26 06:41:17 UTC (rev 1852)
@@ -92,7 +92,7 @@
 				}
 			}
 			if (module->isProcessEntryAttributes()) {
-				if ((*token == 'W') && (token[1] == 'T')) {	// Strongs
+				if ((*token == 'W') && (token[1] == 'T')) {	// Morph
 					valto = val;
 					for (unsigned int i = 2; ((token[i]) && (i < 150)); i++)
 						*valto++ = token[i];

Added: trunk/src/modules/filters/gbfwordjs.cpp
===================================================================
--- trunk/src/modules/filters/gbfwordjs.cpp	2005-09-21 17:32:19 UTC (rev 1851)
+++ trunk/src/modules/filters/gbfwordjs.cpp	2005-09-26 06:41:17 UTC (rev 1852)
@@ -0,0 +1,281 @@
+/******************************************************************************
+ *
+ * gbfstrongs -	SWFilter descendant to hide or show strongs number
+ *			in a GBF module.
+ */
+
+
+#include <stdlib.h>
+#include <gbfwordjs.h>
+#include <swmodule.h>
+#include <ctype.h>
+#include <utilxml.h>
+#include <utilstr.h>
+#include <versekey.h>
+
+SWORD_NAMESPACE_START
+
+const char oName[] = "Word Javascript";
+const char oTip[] = "Toggles Word Javascript data";
+
+const SWBuf choices[3] = {"Off", "On", ""};
+const StringList oValues(&choices[0], &choices[2]);
+
+
+GBFWordJS::GBFWordJS() : SWOptionFilter(oName, oTip, &oValues) {
+	setOptionValue("Off");
+
+     defaultGreekLex   = 0;
+     defaultHebLex     = 0;
+     defaultGreekParse = 0;
+     defaultHebParse   = 0;
+     mgr               = 0;
+}
+
+
+GBFWordJS::~GBFWordJS() {
+}
+
+
+char GBFWordJS::processText(SWBuf &text, const SWKey *key, const SWModule *module) {
+	if (option) {
+		char token[2112]; // cheese.  Fix.
+		int tokpos = 0;
+		bool intoken = false;
+		bool lastspace = false;
+		int word = 1;
+		char val[128];
+		char *valto;
+		char *ch;
+		char wordstr[5];
+		unsigned int textStart = 0, lastAppendLen = 0, textEnd = 0;
+		char gh = 0;
+		SWBuf tmp;
+		bool newText = false;
+		bool needWordOut = false;
+		AttributeValue *wordAttrs = 0;
+		SWBuf modName = (module)?module->Name():"";
+		SWBuf wordSrcPrefix = modName;
+		
+		const SWBuf orig = text;
+		const char * from = orig.c_str();
+		VerseKey *vkey = 0;
+		if (key) {
+			vkey = SWDYNAMIC_CAST(VerseKey, key);
+		}
+
+		for (text = ""; *from; from++) {
+			if (*from == '<') {
+				intoken = true;
+				tokpos = 0;
+				token[0] = 0;
+				token[1] = 0;
+				token[2] = 0;
+				textEnd = text.length();
+				continue;
+			}
+			if (*from == '>') {	// process tokens
+				intoken = false;
+				if (*token == 'W' && (token[1] == 'G' || token[1] == 'H')) {	// Strongs
+					strcpy(val,token+1);
+					if (atoi((!isdigit(*val))?val+1:val) < 5627) {
+						// normal strongs number
+						sprintf(wordstr, "%03d", word++);
+						needWordOut = (word > 2);
+						wordAttrs = &(module->getEntryAttributes()["Word"][wordstr]);
+						(*wordAttrs)["Lemma"] = val;
+	//printf("Adding: [\"Word\"][%s][\"Strongs\"] = %s\n", wordstr, val);
+						tmp = "";
+						tmp.append(text.c_str()+textStart, (int)(textEnd - textStart));
+						(*wordAttrs)["Text"] = tmp;
+						text.append("</span>");
+						SWBuf ts;
+						ts.appendFormatted("%d", textStart);
+						(*wordAttrs)["TextStart"] = ts;
+	//printf("Adding: [\"Word\"][%s][\"Text\"] = %s\n", wordstr, tmp.c_str());
+						newText = true;
+					}
+					else {
+						// verb morph
+						(*wordAttrs)["Morph"] = val;
+	//printf("Adding: [\"Word\"][%s][\"Morph\"] = %s\n", wordstr, val);
+					}
+
+				}
+				if (*token == 'W' && token[1] == 'T') {	// Morph
+					if (token[2] == 'G' || token[2] == 'H') {
+						strcpy(val, token+2);
+					}
+					else strcpy(val, token+1);
+					(*wordAttrs)["Morph"] = val;
+					(*wordAttrs)["MorphClass"] = "StrongsMorph";
+					newText = true;
+				}
+				// if not a strongs token, keep token in text
+				text += '<';
+				text += token;
+				text += '>';
+				if (needWordOut) {
+					char wstr[10];
+					sprintf(wstr, "%03d", word-2);
+					AttributeValue *wAttrs = &(module->getEntryAttributes()["Word"][wstr]);
+					needWordOut = false;
+					SWBuf strong = (*wAttrs)["Lemma"];
+					SWBuf morph = (*wAttrs)["Morph"];
+					SWBuf morphClass = (*wAttrs)["MorphClass"];
+					SWBuf wordText = (*wAttrs)["Text"];
+					SWBuf textSt = (*wAttrs)["TextStart"];
+					if (strong.size()) {
+						char gh = 0;
+						gh = isdigit(strong[0]) ? 0:strong[0];
+						if (!gh) {
+							if (vkey) {
+								gh = vkey->Testament() ? 'H' : 'G';
+							}
+						}
+						else strong << 1;
+
+						SWModule *sLex = 0;
+						SWModule *sMorph = 0;
+						if (gh == 'G') {
+							sLex = defaultGreekLex;
+							sMorph = defaultGreekParse;
+						}
+						if (gh == 'H') {
+							sLex = defaultHebLex;
+							sMorph = defaultHebParse;
+						}
+						SWBuf lexName = "";
+						if (sLex) {
+							// we can pass the real lex name in, but we have some
+							// aliases in the javascript to optimize bandwidth
+							lexName = sLex->Name();
+							if (lexName == "StrongsGreek")
+								lexName = "G";
+							if (lexName == "StrongsHebrew")
+								lexName = "H";
+						}
+						SWBuf wordID;
+						if (vkey) {
+							// optimize for bandwidth and use only the verse as the unique entry id
+							wordID.appendFormatted("%d", vkey->Verse());
+						}
+						else {
+							wordID = key->getText();
+						}
+						for (int i = 0; i < wordID.size(); i++) {
+							if ((!isdigit(wordID[i])) && (!isalpha(wordID[i]))) {
+								wordID[i] = '_';
+							}
+						}
+						wordID.appendFormatted("_%s%d", wordSrcPrefix.c_str(), atoi(wstr));
+						if (textSt.size()) {
+							int textStr = atoi(textSt.c_str());
+							textStr += lastAppendLen;
+							SWBuf spanStart = "";
+
+
+
+/*
+							if (sMorph) {
+								SWBuf popMorph = "<a onclick=\"";
+								popMorph.appendFormatted("p(\'%s\',\'%s\','%s','');\" >%s</a>", sMorph->Name(), morph.c_str(), wordID.c_str(), morph.c_str());
+								morph = popMorph;
+							}
+*/
+
+							// 'p' = 'fillpop' to save bandwidth
+							const char *m = strchr(morph.c_str(), ':');
+							if (m) m++;
+							else m = morph.c_str();
+							spanStart.appendFormatted("<span onclick=\"p(\'%s\',\'%s\','%s','%s');\" >", lexName.c_str(), strong.c_str(), wordID.c_str(), m);
+							text.insert(textStr, spanStart);
+							lastAppendLen = spanStart.length();
+						}
+					}
+
+				}
+				if (newText) {
+					textStart = text.length(); newText = false;
+				}
+				continue;
+			}
+			if (intoken) {
+				if (tokpos < 2045)
+					token[tokpos++] = *from;
+					token[tokpos+2] = 0;
+			}
+			else	{
+				text += *from;
+				lastspace = (*from == ' ');
+			}
+		}
+
+		char wstr[10];
+		sprintf(wstr, "%03d", word-1);
+		AttributeValue *wAttrs = &(module->getEntryAttributes()["Word"][wstr]);
+		needWordOut = false;
+		SWBuf strong = (*wAttrs)["Lemma"];
+		SWBuf morph = (*wAttrs)["Morph"];
+		SWBuf morphClass = (*wAttrs)["MorphClass"];
+		SWBuf wordText = (*wAttrs)["Text"];
+		SWBuf textSt = (*wAttrs)["TextStart"];
+		if (strong.size()) {
+			char gh = 0;
+			gh = isdigit(strong[0]) ? 0:strong[0];
+			if (!gh) {
+				if (vkey) {
+					gh = vkey->Testament() ? 'H' : 'G';
+				}
+			}
+			else strong << 1;
+
+			SWModule *sLex = 0;
+			if (gh == 'G') {
+				sLex = defaultGreekLex;
+			}
+			if (gh == 'H') {
+				sLex = defaultHebLex;
+			}
+			SWBuf lexName = "";
+			if (sLex) {
+				// we can pass the real lex name in, but we have some
+				// aliases in the javascript to optimize bandwidth
+				lexName = sLex->Name();
+				if (lexName == "StrongsGreek")
+					lexName = "G";
+				if (lexName == "StrongsHebrew")
+					lexName = "H";
+			}
+			SWBuf wordID;
+			if (vkey) {
+				// optimize for bandwidth and use only the verse as the unique entry id
+				wordID.appendFormatted("%d", vkey->Verse());
+			}
+			else {
+				wordID = key->getText();
+			}
+			for (int i = 0; i < wordID.size(); i++) {
+				if ((!isdigit(wordID[i])) && (!isalpha(wordID[i]))) {
+					wordID[i] = '_';
+				}
+			}
+			wordID.appendFormatted("_%s%d", wordSrcPrefix.c_str(), atoi(wstr));
+			if (textSt.size()) {
+				int textStr = atoi(textSt.c_str());
+				textStr += lastAppendLen;
+				SWBuf spanStart = "";
+				// 'p' = 'fillpop' to save bandwidth
+				const char *m = strchr(morph.c_str(), ':');
+				if (m) m++;
+				else m = morph.c_str();
+				spanStart.appendFormatted("<span onclick=\"p(\'%s\',\'%s\','%s','%s');\" >", lexName.c_str(), strong.c_str(), wordID.c_str(), m);
+				text.insert(textStr, spanStart);
+			}
+		}
+	}
+
+	return 0;
+}
+
+SWORD_NAMESPACE_END



More information about the sword-cvs mailing list