[sword-devel] rwphtml filter

Terry Biggs sword-devel@crosswire.org
03 Mar 2001 19:08:58 -0500


--=-M5WXEDBIs43fRQZeFfHm
Content-Type: multipart/alternative; boundary="=-zb6kx198hcPavB7JGqJi"


--=-zb6kx198hcPavB7JGqJi
Content-Type: text/plain

Troy,

Here is the rwphtml filter patch.

Terry

--=-zb6kx198hcPavB7JGqJi
Content-Type: text/html; charset=utf-8

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
  <META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
  <META NAME="GENERATOR" CONTENT="GtkHTML/0.8.2">
</HEAD>
<BODY>Troy,<br>
<br>
Here is the rwphtml filter patch.<br>
<br>
Terry</BODY>
</HTML>

--=-zb6kx198hcPavB7JGqJi--

--=-M5WXEDBIs43fRQZeFfHm
Content-Type: text/plain
Content-Disposition: attachment; filename=rwphtml.cpp.dif
Content-Transfer-Encoding: quoted-printable

--- /tmp/gedit-983664200-24178-1	Sat Mar  3 19:03:20 2001
+++ /tmp/gedit-983664200-24178-2	Sat Mar  3 19:03:20 2001
@@ -19,7 +19,6 @@
 #include <string.h>
 #include <rwphtml.h>
=20
-
 RWPHTML::RWPHTML()
 {
 }
@@ -27,118 +26,160 @@
=20
 char RWPHTML::ProcessText(char *text, int maxlen, const SWKey *key)
 {
-	char *to, *from;
-	bool ingreek =3D false;
+	char *to, *from, greek_str[500];
 	bool inverse =3D false;
+	bool first_letter =3D false;
 	int len;
+	char buf[240];=09
=20
-	len =3D strlen(text) + 1;						// shift string to right of buffer
+	len =3D strlen(text) + 1;	// shift string to right of buffer
 	if (len < maxlen) {
 		memmove(&text[maxlen - len], text, len);
 		from =3D &text[maxlen - len];
-	}
-	else	from =3D text;							// -------------------------------
+	} else
+		from =3D text;=09
 	for (to =3D text; *from; from++) {
-		if (*from =3D=3D '\\')
-		{
-			if(!ingreek) {
-				ingreek =3D true;
-				// don=B4t know what this means, find out later
-				//*to++ =3D ' ';
-				continue;
-			}
-			else {
-				ingreek =3D false;
-				continue;
+		if (*from =3D=3D '\\') {
+			++from;
+			int i=3D0;
+			first_letter =3D true;
+			greek_str[0] =3D '\0';		=09
+			while (*from !=3D '\\') { /* get the greek word or phrase */
+				greek_str[i++] =3D *from;
+				greek_str[i + 1] =3D '\0';
+				from++;
+			} /* convert to symbol font as best we can */
+			strcpy(to,"<I> </I><FONT FACE=3D\"symbol\">");
+			to +=3D strlen(to);
+			for (int j =3D 0; j < i; j++) {
+				if ((first_letter)
+				    && (greek_str[j] =3D=3D 'h')) {
+					if (greek_str[j + 1] =3D=3D 'o') {
+						*to++ =3D 'o';
+						first_letter =3D false;
+						++j;
+						continue;
+					} else if (greek_str[j + 1] =3D=3D 'a') {
+						*to++ =3D 'a';
+						first_letter =3D false;
+						++j;
+						continue;
+					} else if (greek_str[j + 1] =3D=3D 'w') {
+						*to++ =3D 'w';
+						first_letter =3D false;
+						++j;
+						continue;
+					} else if (greek_str[j + 1] =3D=3D 'u') {
+						*to++ =3D 'u';
+						first_letter =3D false;
+						++j;
+						continue;
+					} else if (greek_str[j + 1] =3D=3D
+						   -109) {
+						*to++ =3D 'w';
+						first_letter =3D false;
+						++j;
+						continue;
+					} else if (greek_str[j + 1] =3D=3D
+						   -120) {
+						*to++ =3D 'h';
+						first_letter =3D false;
+						++j;
+						continue;
+					} else if (greek_str[j + 1] =3D=3D 'i') {
+						*to++ =3D 'i';
+						first_letter =3D false;
+						++j;
+						continue;
+					}else if (greek_str[j + 1] =3D=3D 'e') {
+						*to++ =3D 'e';
+						first_letter =3D false;
+						++j;
+						continue;
+					}
+					first_letter =3D false;
+				}
+				if ((greek_str[j] =3D=3D 't')
+				    && (greek_str[j + 1] =3D=3D 'h')) {
+					*to++ =3D 'q';
+					++j;
+					continue;
+				}
+				if ((greek_str[j] =3D=3D 'c')
+				    && (greek_str[j + 1] =3D=3D 'h')) {
+					*to++ =3D 'c';
+					++j;
+					continue;
+				}
+				if ((greek_str[j] =3D=3D 'p')
+				    && (greek_str[j + 1] =3D=3D 'h')) {
+				    	++j;
+					*to++ =3D 'f';
+					continue;
+				}
+				if (greek_str[j] =3D=3D -120) {
+					*to++ =3D 'h';
+					continue;
+				}
+				if (greek_str[j] =3D=3D -125) {
+					*to++ =3D 'a';
+					continue;
+				}
+				if (greek_str[j] =3D=3D -109) {
+					if(greek_str[j+1] =3D=3D 'i') ++j;
+					*to++ =3D 'w';
+					continue;
+				}
+				if (greek_str[j] =3D=3D ' ')
+					first_letter =3D true;
+				if (greek_str[j] =3D=3D 's') {
+					if(isalpha(greek_str[j + 1])) *to++ =3D 's';
+					else if(!isprint(greek_str[j] )) *to++ =3D 's';					=09
+					else *to++ =3D 'V';
+					continue;				=09
+				}
+				if (greek_str[j] =3D=3D '\'') {				=09
+					continue;
+				}
+				*to++ =3D greek_str[j];
 			}
+			strcpy(to,"</FONT><I> </I>");
+			to +=3D strlen(to);
+			continue;
 		}
-
-		if ((ingreek) && ((*from =3D=3D 'h') || (*from =3D=3D 'H')))
-			continue;		// 'h's are mostly useless in RWP translitterations.  The gr=
eek is more correct without them.
-
-		if (*from =3D=3D '#') {	// verse markings (e.g. "#Mark 1:1|")
+		if ((*from =3D=3D '#') || (*from =3D=3D -81)) {	// verse markings (e.g. =
"#Mark 1:1|")
 			inverse =3D true;
-			*to++ =3D '<';
-			*to++ =3D 'F';
-			*to++ =3D 'O';
-			*to++ =3D 'N';
-			*to++ =3D 'T';
-			*to++ =3D ' ';
-			*to++ =3D 'C';
-			*to++ =3D 'O';
-			*to++ =3D 'L';
-			*to++ =3D 'O';
-			*to++ =3D 'R';
-			*to++ =3D '=3D';
-			*to++ =3D '#';
-			*to++ =3D '0';
-			*to++ =3D '0';
-			*to++ =3D '0';
-			*to++ =3D '0';
-			*to++ =3D 'F';
-			*to++ =3D 'F';
-			*to++ =3D '>';
+			strcpy(to,"<FONT COLOR=3D#0000FF>");
+			to +=3D strlen(to);		=09
 			continue;
 		}
 		if ((*from =3D=3D '|') && (inverse)) {
 			inverse =3D false;
-			*to++ =3D '<';
-			*to++ =3D '/';
-			*to++ =3D 'F';
-			*to++ =3D 'O';
-			*to++ =3D 'N';
-			*to++ =3D 'T';
-			*to++ =3D '>';
+			strcpy(to,"</FONT>");
+			to +=3D strlen(to);
 			continue;
 		}
-	=09
 		if (*from =3D=3D '{') {
-			*to++ =3D '<';
-			*to++ =3D 'B';
-			*to++ =3D 'R';
-			*to++ =3D '>';
-			*to++ =3D '<';
-			*to++ =3D 'S';
-			*to++ =3D 'T';
-			*to++ =3D 'R';
-			*to++ =3D 'O';
-			*to++ =3D 'N';
-			*to++ =3D 'G';
-			*to++ =3D '>';
-			if ((from - &text[maxlen - len]) > 10) {	// not the beginning of the en=
try
-				*to++ =3D '<';
-				*to++ =3D 'P';
-				*to++ =3D '>';
+			strcpy(to,"<BR><STRONG>");
+			to +=3D strlen(to);
+			if ((from - &text[maxlen - len]) > 10) { // not the beginning of the en=
try
+				strcpy(to,"<P>");
+				to +=3D strlen(to);
 			}
 			continue;
 		}
-
-		if (*from =3D=3D '}')
-		{
-			// this is kinda neat... DO NOTHING
-				*to++ =3D ' ';
-				*to++ =3D '<';
-				*to++ =3D '/';
-				*to++ =3D 'S';
-				*to++ =3D 'T';
-				*to++ =3D 'R';
-				*to++ =3D 'O';
-				*to++ =3D 'N';
-				*to++ =3D 'G';
-				*to++ =3D '>';
+		if (*from =3D=3D '}') {
+			strcpy(to," </STRONG>");
+			to +=3D strlen(to);
 			continue;
 		}
 		if ((*from =3D=3D '\n') && (from[1] =3D=3D '\n')) {
-			*to++ =3D '<';
-			*to++ =3D 'P';
-			*to++ =3D '>';
+			strcpy(to,"<P>");
+			to +=3D strlen(to);
 			continue;
 		}
-
 		*to++ =3D *from;
 	}
 	*to =3D 0;
 	return 0;
 }
-
-

--=-M5WXEDBIs43fRQZeFfHm--