Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

thmlstrongs.cpp

00001 /******************************************************************************
00002  *
00003  * thmlstrongs -        SWFilter decendant to hide or show strongs number
00004  *                      in a ThML module.
00005  */
00006 
00007 
00008 #include <stdlib.h>
00009 #include <stdio.h>
00010 #include <string.h>
00011 #include <thmlstrongs.h>
00012 #include <swmodule.h>
00013 #ifndef __GNUC__
00014 #else
00015 #include <unixstr.h>
00016 #endif
00017 
00018 
00019 const char ThMLStrongs::on[] = "On";
00020 const char ThMLStrongs::off[] = "Off";
00021 const char ThMLStrongs::optName[] = "Strong's Numbers";
00022 const char ThMLStrongs::optTip[] = "Toggles Strong's Numbers On and Off if they exist";
00023 
00024 
00025 ThMLStrongs::ThMLStrongs() {
00026         option = false;
00027         options.push_back(on);
00028         options.push_back(off);
00029 }
00030 
00031 
00032 ThMLStrongs::~ThMLStrongs() {
00033 }
00034 
00035 void ThMLStrongs::setOptionValue(const char *ival)
00036 {
00037         option = (!stricmp(ival, on));
00038 }
00039 
00040 const char *ThMLStrongs::getOptionValue()
00041 {
00042         return (option) ? on:off;
00043 }
00044 
00045 char ThMLStrongs::ProcessText(char *text, int maxlen, const SWKey *key, const SWModule *module)
00046 {
00047         char *to, *from, token[2048]; // cheese.  Fix.
00048         int tokpos = 0;
00049         bool intoken = false;
00050         int len;
00051         bool lastspace = false;
00052         int word = 1;
00053         char val[128];
00054         char wordstr[5];
00055         char *valto;
00056         char *ch;
00057 
00058         len = strlen(text) + 1; // shift string to right of buffer
00059         if (len < maxlen) {
00060                 memmove(&text[maxlen - len], text, len);
00061                 from = &text[maxlen - len];
00062         }
00063         else    from = text;
00064         
00065         // -------------------------------
00066 
00067         for (to = text; *from; from++) {
00068                 if (*from == '<') {
00069                         intoken = true;
00070                         tokpos = 0;
00071                         token[0] = 0;
00072                         token[1] = 0;
00073                         token[2] = 0;
00074                         continue;
00075                 }
00076                 if (*from == '>') {     // process tokens
00077                         intoken = false;
00078                         if (!strnicmp(token, "sync type=\"Strongs\" ", 20)) {   // Strongs
00079                                 if (module->isProcessEntryAttributes()) {
00080                                         valto = val;
00081                                         for (unsigned int i = 27; token[i] != '\"' && i < 150; i++)
00082                                                 *valto++ = token[i];
00083                                         *valto = 0;
00084                                         if (atoi((!isdigit(*val))?val+1:val) < 5627) {
00085                                                 // normal strongs number
00086                                                 sprintf(wordstr, "%03d", word++);
00087                                                 module->getEntryAttributes()["Word"][wordstr]["Strongs"] = val;
00088                                         }
00089                                         else {
00090                                                 // verb morph
00091                                                 sprintf(wordstr, "%03d", word-1);
00092                                                 module->getEntryAttributes()["Word"][wordstr]["Morph"] = val;
00093                                         }
00094                                 }
00095 
00096                                 if (!option) {  // if we don't want strongs
00097                                         if ((from[1] == ' ') || (from[1] == ',') || (from[1] == ';') || (from[1] == '.') || (from[1] == '?') || (from[1] == '!') || (from[1] == ')') || (from[1] == '\'') || (from[1] == '\"')) {
00098                                                 if (lastspace)
00099                                                         to--;
00100                                         }
00101                                         continue;
00102                                 }
00103                         }
00104                         if (module->isProcessEntryAttributes()) {
00105                                 if (!strncmp(token, "sync type=\"morph\"", 17)) {
00106                                         for (ch = token+17; *ch; ch++) {
00107                                                 if (!strncmp(ch, "class=\"", 7)) {
00108                                                         valto = val;
00109                                                         for (unsigned int i = 7; ch[i] != '\"' && i < 127; i++)
00110                                                                 *valto++ = ch[i];
00111                                                         *valto = 0;
00112                                                         sprintf(wordstr, "%03d", word-1);
00113                                                         module->getEntryAttributes()["Word"][wordstr]["MorphClass"] = val;
00114                                                 }
00115                                                 if (!strncmp(ch, "value=\"", 7)) {
00116                                                         valto = val;
00117                                                         for (unsigned int i = 7; ch[i] != '\"' && i < 127; i++)
00118                                                                 *valto++ = ch[i];
00119                                                         *valto = 0;
00120                                                         sprintf(wordstr, "%03d", word-1);
00121                                                         module->getEntryAttributes()["Word"][wordstr]["Morph"] = val;
00122                                                 }
00123                                         }
00124                                 }
00125                         }
00126                         // if not a strongs token, keep token in text
00127                         *to++ = '<';
00128                         for (char *tok = token; *tok; tok++)
00129                                 *to++ = *tok;
00130                         *to++ = '>';
00131                         continue;
00132                 }
00133                 if (intoken) {
00134                         if (tokpos < 2045)
00135                                 token[tokpos++] = *from;
00136                                 token[tokpos+2] = 0;
00137                 }
00138                 else    {
00139                         *to++ = *from;
00140                         lastspace = (*from == ' ');
00141                 }
00142         }
00143         *to++ = 0;
00144         *to = 0;
00145         return 0;
00146 }

Generated on Wed Apr 3 22:34:15 2002 for The Sword Project by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002