00001
00002
00003
00004
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];
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 char *textStart = text, *textEnd = 0;
00057 bool newText = false;
00058 string tmp;
00059
00060 len = strlen(text) + 1;
00061 if (len < maxlen) {
00062 memmove(&text[maxlen - len], text, len);
00063 from = &text[maxlen - len];
00064 }
00065 else from = text;
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 textEnd = to;
00075 continue;
00076 }
00077 if (*from == '>') {
00078 intoken = false;
00079 if (*token == 'W' && (token[1] == 'G' || token[1] == 'H')) {
00080 if (module->isProcessEntryAttributes()) {
00081 valto = val;
00082 for (unsigned int i = 2; ((token[i]) && (i < 150)); i++)
00083 *valto++ = token[i];
00084 *valto = 0;
00085 if (atoi((!isdigit(*val))?val+1:val) < 5627) {
00086
00087 sprintf(wordstr, "%03d", word++);
00088 module->getEntryAttributes()["Word"][wordstr]["Strongs"] = val;
00089 tmp = "";
00090 tmp.append(textStart, (int)(textEnd - textStart));
00091 module->getEntryAttributes()["Word"][wordstr]["Text"] = tmp;
00092 newText = true;
00093 }
00094 else {
00095
00096 sprintf(wordstr, "%03d", word-1);
00097 module->getEntryAttributes()["Word"][wordstr]["Morph"] = val;
00098 }
00099 }
00100 if (!option) {
00101 if ((from[1] == ' ') || (from[1] == ',') || (from[1] == ';') || (from[1] == '.') || (from[1] == '?') || (from[1] == '!') || (from[1] == ')') || (from[1] == '\'') || (from[1] == '\"')) {
00102 if (lastspace)
00103 to--;
00104 }
00105 if (newText) {textStart = to; newText = false; }
00106 continue;
00107 }
00108 }
00109
00110 *to++ = '<';
00111 for (char *tok = token; *tok; tok++)
00112 *to++ = *tok;
00113 *to++ = '>';
00114 if (newText) {textStart = to; newText = false; }
00115 continue;
00116 }
00117 if (intoken) {
00118 if (tokpos < 2045)
00119 token[tokpos++] = *from;
00120 token[tokpos+2] = 0;
00121 }
00122 else {
00123 *to++ = *from;
00124 lastspace = (*from == ' ');
00125 }
00126 }
00127 *to++ = 0;
00128 *to = 0;
00129 return 0;
00130 }