[sword-cvs] sword/src/modules/filters gbfwebif.cpp,NONE,1.1 thmlwebif.cpp,NONE,1.1 Makefile.am,1.17,1.18

sword@www.crosswire.org sword@www.crosswire.org
Sun, 1 Jun 2003 07:32:16 -0700


Update of /usr/local/cvsroot/sword/src/modules/filters
In directory www:/tmp/cvs-serv1646/src/modules/filters

Modified Files:
	Makefile.am 
Added Files:
	gbfwebif.cpp thmlwebif.cpp 
Log Message:
added webif stuff, updated makefile.am files

--- NEW FILE: gbfwebif.cpp ---
/***************************************************************************
                          GBFWEBIF.cpp  -   GBF to HTML filter with hrefs 
			        for strongs and morph tags
                             -------------------
    begin                    : 2001-09-03
    copyright            : 2001 by CrossWire Bible Society
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include <gbfwebif.h>
#include <ctype.h>
#include <utilweb.h>

SWORD_NAMESPACE_START

GBFWEBIF::GBFWEBIF() : baseURL("/"), passageStudyURL(baseURL + "passagestudy.jsp") {
//all is done in GBFHTMLHREF since it inherits form this class
}

bool GBFWEBIF::handleToken(SWBuf &buf, const char *token, DualStringMap &userData) {
	const char *tok;
	char val[128];
	char *valto;
	const char *num;
	std::string url;

	if (!substituteToken(buf, token)) {
		if (!strncmp(token, "w", 1)) {
			// OSIS Word (temporary until OSISRTF is done)
			valto = val;
			num = strstr(token, "lemma=\"x-Strongs:");

			if (num) {
				for (num+=17; ((*num) && (*num != '\"')); num++)
					*valto++ = *num;
				*valto = 0;

				if (atoi((!isdigit(*val))?val+1:val) < 5627) {
					buf += " <small><em>&lt;";
					url = "";
					for (tok = val; *tok; tok++) {
						url += *tok;
					}
					buf.appendFormatted("<a href=\"%s?key=%s\">", passageStudyURL.c_str(), encodeURL(url).c_str());

					for (tok = (!isdigit(*val))?val+1:val; *tok; tok++) {
						buf += *tok;
					}
					buf += "</a>&gt;</em></small> ";
				}
			}
			valto = val;
			num = strstr(token, "morph=\"x-Robinson:");
			if (num) {
				for (num+=18; ((*num) && (*num != '\"')); num++)
					*valto++ = *num;
				*valto = 0;
				buf += " <small><em>(";
				url = "";
				for (tok = val; *tok; tok++) {
				// normal robinsons tense
					buf += *tok;
				}
				buf.appendFormatted("<a href=\"%s?key=%s\">", passageStudyURL.c_str(), encodeURL(url).c_str());

				for (tok = val; *tok; tok++) {
					buf += *tok;
				}
				buf += "</a>)</em></small> ";
			}
		}

		else if (!strncmp(token, "WG", 2) || !strncmp(token, "WH", 2)) { // strong's numbers
			buf += " <small><em>&lt;";
			url = "";

			for (tok = token+1; *tok; tok++) {
				url += *tok;
			}
			buf.appendFormatted("<a href=\"%s?key=%s\">", passageStudyURL.c_str(), encodeURL(url).c_str());

			for (tok = token + 2; *tok; tok++) {
				buf += *tok;
			}
			buf += "</a>&gt;</em></small>";
		}

		else if (!strncmp(token, "WTG", 3) || !strncmp(token, "WTH", 3)) { // strong's numbers tense
			buf += " <small><em>(";
			url = "";
			for (tok = token + 2; *tok; tok++) {
				if(*tok != '\"')
					url += *tok;
			}
			buf.appendFormatted("<a href=\"%s?key=%s\">", passageStudyURL.c_str(), encodeURL(url).c_str());

			for (tok = token + 3; *tok; tok++)
				if(*tok != '\"')
					buf += *tok;
			buf += "</a>)</em></small>";
		}

		else if (!strncmp(token, "WT", 2) && strncmp(token, "WTH", 3) && strncmp(token, "WTG", 3)) { // morph tags
			buf += " <small><em>(";
			for (tok = token + 2; *tok; tok++) {
				if(*tok != '\"')
					buf += *tok;
			}
			buf.appendFormatted("<a href=\"%s?key=%s\">", passageStudyURL.c_str(), encodeURL(url).c_str());

			for (tok = token + 2; *tok; tok++) {
				if(*tok != '\"')
					buf += *tok;
			}
			buf += "</a>)</em></small>";
		}

		else if (!strncmp(token, "RX", 2)) {
			buf += "<a href=\"";
			for (tok = token + 3; *tok; tok++) {
			  if(*tok != '<' && *tok+1 != 'R' && *tok+2 != 'x') {
			    buf += *tok;
			  }
			  else {
			    break;
			  }
			}

			buf.appendFormatted("a href=\"%s?key=%s\">", passageStudyURL.c_str(), encodeURL(url).c_str());
		}

		else {
			return GBFHTMLHREF::handleToken(buf, token, userData);
		}
	}
	return true;
}

SWORD_NAMESPACE_END

--- NEW FILE: thmlwebif.cpp ---
/***************************************************************************
                     ThMLWEBIF.cpp  -  ThML to HTML filter with hrefs  
                             -------------------
    begin                    : 2001-09-03
    copyright            : 2001 by CrossWire Bible Society
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include <stdlib.h>
#include <string.h>
#include <thmlwebif.h>
#include <swmodule.h>
#include <utilweb.h>

SWORD_NAMESPACE_START

ThMLWEBIF::ThMLWEBIF() : baseURL("/"), passageStudyURL(baseURL + "passagestudy.jsp") {
  //all's done in ThMLHTMLHREF
}

bool ThMLWEBIF::handleToken(SWBuf &buf, const char *token, DualStringMap &userData) {
	const char *tok;
	std::string url;

	if (!substituteToken(buf, token)) {
	// manually process if it wasn't a simple substitution
		if (!strncmp(token, "sync ", 5)) {
			url = "";

			if(strstr(token,"type=\"morph\"")){
				buf += "<small><em> (";
			}
			else {
				buf += "<small><em> &lt;";
			}

			for (tok = token + 5; *(tok+1); tok++) {
				if(*tok != '\"') {
					url += *tok;
				}
			}
			buf.appendFormatted("<a href=\"%s?sync_key=%s\">", passageStudyURL.c_str(), encodeURL(url).c_str() );

                        //scan for value and add it to the buffer
			for (tok = token + 5; *tok; tok++) {
				if (!strncmp(tok, "value=\"", 7)) {
					if(strstr(token,"type=\"morph\""))
						tok += 7;
					else
						tok += 8;
					for (;*tok != '\"'; tok++)
						buf += *tok;
					break;
				}
			}
			if(strstr(token,"type=\"morph\""))
				buf += "</a>) </em></small>";
			else
				buf += "</a>&gt; </em></small>";
		}

		else if (!strncmp(token, "scripRef p", 10) || !strncmp(token, "scripRef v", 10)) {
			userData["inscriptRef"] = "true";
			url = "";

			for (const char *tok = token + 9; *(tok+1); tok++) {
				if(*tok != '\"')
					url += *tok;
			}

			buf.appendFormatted("<a href=\"%s?p_key=%s\">", passageStudyURL.c_str(), encodeURL(url).c_str());
		}

		// we've ended a scripRef
		else if (!strcmp(token, "/scripRef")) {
			if (userData["inscriptRef"] == "true") { // like  "<scripRef passage="John 3:16">John 3:16</scripRef>"
				userData["inscriptRef"] = "false";
				buf +="</a>";
			}

			else { // like "<scripRef>John 3:16</scripRef>"
				url = userData["lastTextNode"].c_str();

				buf.appendFormatted("<a href=\"%s?key=%s\">", passageStudyURL.c_str(), encodeURL(url).c_str() );

				buf += userData["lastTextNode"].c_str();

				// let's let text resume to output again
				userData["suspendTextPassThru"] = "false";

				buf += "</a>";
			}
		}

		else {
			return ThMLHTMLHREF::handleToken(buf,token,userData);
		}
	}
	return true;
}


SWORD_NAMESPACE_END

Index: Makefile.am
===================================================================
RCS file: /usr/local/cvsroot/sword/src/modules/filters/Makefile.am,v
retrieving revision 1.17
retrieving revision 1.18
diff -C2 -d -r1.17 -r1.18
*** Makefile.am	1 May 2003 10:59:45 -0000	1.17
--- Makefile.am	1 Jun 2003 14:32:09 -0000	1.18
***************
*** 5,8 ****
--- 5,9 ----
  libsword_la_SOURCES += $(filtersdir)/gbfhtml.cpp
  libsword_la_SOURCES += $(filtersdir)/gbfhtmlhref.cpp
+ libsword_la_SOURCES += $(filtersdir)/gbfwebif.cpp
  libsword_la_SOURCES += $(filtersdir)/gbfplain.cpp
  libsword_la_SOURCES += $(filtersdir)/gbfrtf.cpp
***************
*** 17,20 ****
--- 18,22 ----
  libsword_la_SOURCES += $(filtersdir)/gbfmorph.cpp
  libsword_la_SOURCES += $(filtersdir)/plainfootnotes.cpp
+ 
  libsword_la_SOURCES += $(filtersdir)/thmlstrongs.cpp
  libsword_la_SOURCES += $(filtersdir)/thmlfootnotes.cpp
***************
*** 30,33 ****
--- 32,37 ----
  libsword_la_SOURCES += $(filtersdir)/thmlhtml.cpp
  libsword_la_SOURCES += $(filtersdir)/thmlhtmlhref.cpp
+ libsword_la_SOURCES += $(filtersdir)/thmlwebif.cpp
+ 
  libsword_la_SOURCES += $(filtersdir)/thmlosis.cpp
  libsword_la_SOURCES += $(filtersdir)/gbfosis.cpp