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

thmlvariants.cpp

00001 /******************************************************************************
00002  *
00003  * thmlvariants -       SWFilter decendant to hide or show textual variants
00004  *                      in a ThML module.
00005  */
00006 
00007 
00008 #include <stdlib.h>
00009 #include <string.h>
00010 #include <thmlvariants.h>
00011 #ifndef __GNUC__
00012 #else
00013 #include <unixstr.h>
00014 #endif
00015 
00016 
00017 const char ThMLVariants::primary[] = "Primary Reading";
00018 const char ThMLVariants::secondary[] = "Secondary Reading";
00019 const char ThMLVariants::all[] = "All Readings";
00020 
00021 const char ThMLVariants::optName[] = "Textual Variants";
00022 const char ThMLVariants::optTip[] = "Switch between Textual Variants modes";
00023 
00024 
00025 ThMLVariants::ThMLVariants() {
00026         option = false;
00027         options.push_back(primary);
00028         options.push_back(secondary);
00029         options.push_back(all);
00030 }
00031 
00032 
00033 ThMLVariants::~ThMLVariants() {
00034 }
00035 
00036 void ThMLVariants::setOptionValue(const char *ival)
00037 {
00038         if (!stricmp(ival, primary)) option = 0;
00039         else if (!stricmp(ival, secondary)) option = 1;
00040         else option = 2;
00041 }
00042 
00043 const char *ThMLVariants::getOptionValue()
00044 {
00045         if (option == 0) {
00046                 return primary;
00047         }
00048         else if (option == 1) {
00049                 return secondary;
00050         }
00051         else {
00052                 return all;
00053         }
00054 }
00055 
00056 char ThMLVariants::ProcessText(char *text, int maxlen, const SWKey *key, const SWModule *module)
00057 {
00058         if (option == 0) { //we want primary only
00059                 char *to, *from, token[2048]; // cheese.  Fix.
00060                 int tokpos = 0;
00061                 bool intoken = false;
00062                 int len;
00063                 bool hide = false;
00064 
00065                 len = strlen(text) + 1; // shift string to right of buffer
00066                 if (len < maxlen) {
00067                         memmove(&text[maxlen - len], text, len);
00068                         from = &text[maxlen - len];
00069                 }
00070                 else    from = text;
00071                 
00072                 // -------------------------------
00073 
00074                 for (to = text; *from; from++) {
00075                         if (*from == '<') {
00076                                 intoken = true;
00077                                 tokpos = 0;
00078                                 token[0] = 0;
00079                                 token[1] = 0;
00080                                 token[2] = 0;
00081                                 continue;
00082                         }
00083                         if (*from == '>') {     // process tokens
00084                                 intoken = false;
00085                                 if (!strncmp(token, "div type=\"variant\" class=\"2\"", 28)) {
00086                                   hide = true;
00087                                   continue;
00088                                 }
00089                                 else if (!strncmp(token, "/div", 4)) {
00090                                   hide = false;
00091                                   continue;
00092                                 }
00093 
00094                                 // if not a footnote token, keep token in text
00095                                 if (!hide) {
00096                                         *to++ = '<';
00097                                         for (char *tok = token; *tok; tok++)
00098                                                 *to++ = *tok;
00099                                         *to++ = '>';
00100                                 }
00101                                 continue;
00102                         }
00103                         if (intoken) {
00104                                 if (tokpos < 2045)
00105                                         token[tokpos++] = *from;
00106                                         token[tokpos+2] = 0;
00107                         }
00108                         else    {
00109                                 if (!hide) {
00110                                         *to++ = *from;
00111                                 }
00112                         }
00113                 }
00114                 *to++ = 0;
00115                 *to = 0;
00116 
00117         }
00118         else if (option == 1) { //we want variant only
00119                 char *to, *from, token[2048]; // cheese.  Fix.
00120                 int tokpos = 0;
00121                 bool intoken = false;
00122                 int len;
00123                 bool hide = false;
00124 
00125                 len = strlen(text) + 1; // shift string to right of buffer
00126                 if (len < maxlen) {
00127                         memmove(&text[maxlen - len], text, len);
00128                         from = &text[maxlen - len];
00129                 }
00130                 else    from = text;
00131 
00132                 // -------------------------------
00133 
00134                 for (to = text; *from; from++) {
00135                         if (*from == '<') {
00136                                 intoken = true;
00137                                 tokpos = 0;
00138                                 token[0] = 0;
00139                                 token[1] = 0;
00140                                 token[2] = 0;
00141                                 continue;
00142                         }
00143                         if (*from == '>') {     // process tokens
00144                                 intoken = false;
00145                                 if (!strncmp(token, "div type=\"variant\" class=\"1\"", 28)) {
00146                                   hide = true;
00147                                   continue;
00148                                 }
00149                                 else if (!strncmp(token, "/div", 4)) {
00150                                   hide = false;
00151                                   continue;
00152                                 }
00153 
00154                                 // if not a footnote token, keep token in text
00155                                 if (!hide) {
00156                                         *to++ = '<';
00157                                         for (char *tok = token; *tok; tok++)
00158                                                 *to++ = *tok;
00159                                         *to++ = '>';
00160                                 }
00161                                 continue;
00162                         }
00163                         if (intoken) {
00164                                 if (tokpos < 2045)
00165                                         token[tokpos++] = *from;
00166                                         token[tokpos+2] = 0;
00167                         }
00168                         else    {
00169                                 if (!hide) {
00170                                         *to++ = *from;
00171                                 }
00172                         }
00173                 }
00174                 *to++ = 0;
00175                 *to = 0;
00176 
00177         }
00178         return 0;
00179 }
00180 
00181 
00182 
00183 
00184 
00185 

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