[sword-cvs] sword/src/modules/filters osislemma.cpp,NONE,1.1 osisredletterwords.cpp,NONE,1.1 osisscripref.cpp,NONE,1.1

sword@www.crosswire.org sword@www.crosswire.org
Thu, 26 Jun 2003 23:18:07 -0700


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

Added Files:
	osislemma.cpp osisredletterwords.cpp osisscripref.cpp 
Log Message:
OSIS filters for lemmas, scripture references, & red words of Christ

--- NEW FILE: osislemma.cpp ---
/******************************************************************************
 *
 * osislemma          -	SWFilter descendant to hide or show lemmata
 *			in a OSIS module.
 */


#include <stdlib.h>
#include <osislemma.h>
#include <utilxml.h>
#ifndef __GNUC__
#else
#include <unixstr.h>
#endif

SWORD_NAMESPACE_START

const char OSISLemma::on[] = "On";
const char OSISLemma::off[] = "Off";
const char OSISLemma::optName[] = "Lemmas";
const char OSISLemma::optTip[] = "Toggles Lemmas On and Off if they exist";


OSISLemma::OSISLemma() {
	option = false;
	options.push_back(on);
	options.push_back(off);
}


OSISLemma::~OSISLemma() {
}

void OSISLemma::setOptionValue(const char *ival)
{
	option = (!stricmp(ival, on));
}

const char *OSISLemma::getOptionValue()
{
	return (option) ? on:off;
}

char OSISLemma::processText(SWBuf &text, const SWKey *key, const SWModule *module)
{
	if (!option) {	// if we don't want lemmas
		const char *from;
		char token[2048]; // cheese.  Fix.
		int tokpos = 0;
		bool intoken = false;
		bool lastspace = false;
		SWBuf orig = text;
		from = orig.c_str();

		for (text = ""; *from; from++) {
			if (*from == '<') {
				intoken = true;
				tokpos = 0;
				token[0] = 0;
				continue;
			}
			if (*from == '>') {	// process tokens
				intoken = false;
				XMLTag tag(token);
				if ((!strcmp(tag.getName(), "w")) && (!tag.isEndTag())) {	// Lemma
					if (tag.getAttribute("lemma"))
						tag.setAttribute("lemma", 0);
				}
				// keep tag, possibly with the lemma removed
				text += tag;
				continue;
			}
			if (intoken) {
				if (tokpos < 2045)
					token[tokpos++] = *from;
					token[tokpos] = 0;
			}
			else	{
				text += *from;
				lastspace = (*from == ' ');
			}
		}
	}
	return 0;
}

SWORD_NAMESPACE_END

--- NEW FILE: osisredletterwords.cpp ---
/******************************************************************************
 *
 * OSISRedLetterWords -	SWFilter descendant to toggle red coloring for words
 *			of Christ in an OSIS module.
 */


#include <stdlib.h>
#include <osisredletterwords.h>
#include <swmodule.h>
#include <utilxml.h>
#ifndef __GNUC__
#else
#include <unixstr.h>
#endif

SWORD_NAMESPACE_START

const char OSISRedLetterWords::on[] = "On";
const char OSISRedLetterWords::off[] = "Off";
const char OSISRedLetterWords::optName[] = "Words of Christ in Red";
const char OSISRedLetterWords::optTip[] = "Toggles Red Coloring for Words of Christ On and Off if they are marked";


OSISRedLetterWords::OSISRedLetterWords() {
	option = false;
	options.push_back(on);
	options.push_back(off);
}


OSISRedLetterWords::~OSISRedLetterWords() {
}

void OSISRedLetterWords::setOptionValue(const char *ival)
{
	option = (!stricmp(ival, on));
}

const char *OSISRedLetterWords::getOptionValue()
{
	return (option) ? on:off;
}

char OSISRedLetterWords::processText(SWBuf &text, const SWKey *key, const SWModule *module)
{
	SWBuf token;
	bool intoken    = false;
	char buf[254];

	SWBuf orig = text;
	const char *from = orig.c_str();

	if (!option)
	for (text = ""; *from; from++) {
		if (*from == '<') {
			intoken = true;
			token = "";
			continue;
		}
		if (*from == '>') {	// process tokens
			intoken = false;

			XMLTag tag(token);
			if (!stricmp(tag.getName(), "q")) {
				if ((tag.getAttribute("who")) && (!stricmp(tag.getAttribute("who"), "Jesus"))) {
				        tag.setAttribute("who", 0);
				}
			}

			text += '<';
			text.append(token);
			text += '>';
			continue;
		}
		if (intoken) { //copy token
			token += *from;
		}
		else { //copy text which is not inside a token
			text += *from;
		}
	}
	return 0;
}

SWORD_NAMESPACE_END


--- NEW FILE: osisscripref.cpp ---
/******************************************************************************
 *
 * OSISScripref -	SWFilter descendant to hide or show scripture references
 *			in an OSIS module.
 */


#include <stdlib.h>
#include <osisscripref.h>
#include <swmodule.h>
#include <utilxml.h>
#ifndef __GNUC__
#else
#include <unixstr.h>
#endif

SWORD_NAMESPACE_START

const char OSISScripref::on[] = "On";
const char OSISScripref::off[] = "Off";
const char OSISScripref::optName[] = "Scripture Cross-references";
const char OSISScripref::optTip[] = "Toggles Scripture Cross-references On and Off if they exist";

OSISScripref::OSISScripref() {
	option = true;
	options.push_back(on);
	options.push_back(off);
}


OSISScripref::~OSISScripref() {
}

void OSISScripref::setOptionValue(const char *ival)
{
	option = (!stricmp(ival, on));
}

const char *OSISScripref::getOptionValue()
{
	return (option) ? on:off;
}

char OSISScripref::processText(SWBuf &text, const SWKey *key, const SWModule *module) {
	SWBuf token;
	bool intoken    = false;
	bool hide       = false;
	SWBuf tagText;
	XMLTag startTag;
	int tagTextNum  = 1;
	int footnoteNum = 1;
	char buf[254];

	SWBuf orig = text;
	const char *from = orig.c_str();

	for (text = ""; *from; from++) {
		if (*from == '<') {
			intoken = true;
			token = "";
			continue;
		}
		if (*from == '>') {	// process tokens
			intoken = false;

			XMLTag tag(token);
			if (!strcmp(tag.getName(), "note") && !strcmp(tag.getAttribute("type"), "crossReference")) {
				if (!tag.isEndTag() && (!tag.isEmpty())) {
					startTag = tag;
					hide = true;
					tagText = "";
					if (option) {	// we want the tag in the text
						text += '<';
						text.append(token);
						text += '>';
					}
					continue;
				}
				if (hide && tag.isEndTag()) {
					if (module->isProcessEntryAttributes() && option) {
						sprintf(buf, "%i", footnoteNum++);
						ListString attributes = startTag.getAttributeNames();
						for (ListString::iterator it = attributes.begin(); it != attributes.end(); it++) {
							module->getEntryAttributes()["Footnote"][buf][it->c_str()] = startTag.getAttribute(it->c_str());
						}
						module->getEntryAttributes()["Footnote"][buf]["body"] = tagText;
						if (option) {	// we want the tag in the text
							text.append(tagText);
						}
					}
					hide = false;
					if (!option) {	// we don't want the tag in the text anymore
						continue;
					}
				}
			}

			// if not a heading token, keep token in text
			if (!hide) {
				text += '<';
				text.append(token);
				text += '>';
			}
			continue;
		}
		if (intoken) { //copy token
			token += *from;
		}
		else if (!hide) { //copy text which is not inside a token
			text += *from;
		}
		else tagText += *from;
	}
	return 0;
}

SWORD_NAMESPACE_END