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         char *textStart = text, *textEnd = 0;
00058         string tmp;
00059         bool newText = false;
00060 
00061         len = strlen(text) + 1; // shift string to right of buffer
00062         if (len < maxlen) {
00063                 memmove(&text[maxlen - len], text, len);
00064                 from = &text[maxlen - len];
00065         }
00066         else    from = text;
00067         
00068         // -------------------------------
00069 
00070         for (to = text; *from; from++) {
00071                 if (*from == '<') {
00072                         intoken = true;
00073                         tokpos = 0;
00074                         token[0] = 0;
00075                         token[1] = 0;
00076                         token[2] = 0;
00077                         textEnd = to;
00078                         continue;
00079                 }
00080                 if (*from == '>') {     // process tokens
00081                         intoken = false;
00082                         if (!strnicmp(token, "sync type=\"Strongs\" ", 20)) {   // Strongs
00083                                 if (module->isProcessEntryAttributes()) {
00084                                         valto = val;
00085                                         for (unsigned int i = 27; token[i] != '\"' && i < 150; i++)
00086                                                 *valto++ = token[i];
00087                                         *valto = 0;
00088                                         if (atoi((!isdigit(*val))?val+1:val) < 5627) {
00089                                                 // normal strongs number
00090                                                 sprintf(wordstr, "%03d", word++);
00091                                                 module->getEntryAttributes()["Word"][wordstr]["Strongs"] = val;
00092                                                 tmp = "";
00093                                                 tmp.append(textStart, (int)(textEnd - textStart));
00094                                                 module->getEntryAttributes()["Word"][wordstr]["Text"] = tmp;
00095                                                 newText = true;
00096                                         }
00097                                         else {
00098                                                 // verb morph
00099                                                 sprintf(wordstr, "%03d", word-1);
00100                                                 module->getEntryAttributes()["Word"][wordstr]["Morph"] = val;
00101                                         }
00102                                 }
00103 
00104                                 if (!option) {  // if we don't want strongs
00105                                         if ((from[1] == ' ') || (from[1] == ',') || (from[1] == ';') || (from[1] == '.') || (from[1] == '?') || (from[1] == '!') || (from[1] == ')') || (from[1] == '\'') || (from[1] == '\"')) {
00106                                                 if (lastspace)
00107                                                         to--;
00108                                         }
00109                                         if (newText) {textStart = to; newText = false; }
00110                                         continue;
00111                                 }
00112                         }
00113                         if (module->isProcessEntryAttributes()) {
00114                                 if (!strncmp(token, "sync type=\"morph\"", 17)) {
00115                                         for (ch = token+17; *ch; ch++) {
00116                                                 if (!strncmp(ch, "class=\"", 7)) {
00117                                                         valto = val;
00118                                                         for (unsigned int i = 7; ch[i] != '\"' && i < 127; i++)
00119                                                                 *valto++ = ch[i];
00120                                                         *valto = 0;
00121                                                         sprintf(wordstr, "%03d", word-1);
00122                                                         module->getEntryAttributes()["Word"][wordstr]["MorphClass"] = val;
00123                                                 }
00124                                                 if (!strncmp(ch, "value=\"", 7)) {
00125                                                         valto = val;
00126                                                         for (unsigned int i = 7; ch[i] != '\"' && i < 127; i++)
00127                                                                 *valto++ = ch[i];
00128                                                         *valto = 0;
00129                                                         sprintf(wordstr, "%03d", word-1);
00130                                                         module->getEntryAttributes()["Word"][wordstr]["Morph"] = val;
00131                                                 }
00132                                         }
00133                                 }
00134                         }
00135                         // if not a strongs token, keep token in text
00136                         *to++ = '<';
00137                         for (char *tok = token; *tok; tok++)
00138                                 *to++ = *tok;
00139                         *to++ = '>';
00140                         if (newText) {textStart = to; newText = false; }
00141                         continue;
00142                 }
00143                 if (intoken) {
00144                         if (tokpos < 2045)
00145                                 token[tokpos++] = *from;
00146                                 token[tokpos+2] = 0;
00147                 }
00148                 else    {
00149                         *to++ = *from;
00150                         lastspace = (*from == ' ');
00151                 }
00152         }
00153         *to++ = 0;
00154         *to = 0;
00155         return 0;
00156 }

Generated on Thu Jun 20 22:13:01 2002 for The Sword Project by doxygen1.2.15