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

gbfstrongs.cpp

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

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