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         option = (!stricmp(ival, primary));
00039 }
00040 
00041 const char *ThMLVariants::getOptionValue()
00042 {
00043         if (option == 0) {
00044                 return primary;
00045         }
00046         else if (option == 1) {
00047                 return secondary;
00048         }
00049         else {
00050                 return all;
00051         }
00052 }
00053 
00054 char ThMLVariants::ProcessText(char *text, int maxlen, const SWKey *key, const SWModule *module)
00055 {
00056         if (option == 0) { //we want primary only
00057                 char *to, *from, token[2048]; // cheese.  Fix.
00058                 int tokpos = 0;
00059                 bool intoken = false;
00060                 int len;
00061                 bool hide = false;
00062 
00063                 len = strlen(text) + 1; // shift string to right of buffer
00064                 if (len < maxlen) {
00065                         memmove(&text[maxlen - len], text, len);
00066                         from = &text[maxlen - len];
00067                 }
00068                 else    from = text;
00069                 
00070                 // -------------------------------
00071 
00072                 for (to = text; *from; from++) {
00073                         if (*from == '<') {
00074                                 intoken = true;
00075                                 tokpos = 0;
00076                                 token[0] = 0;
00077                                 token[1] = 0;
00078                                 token[2] = 0;
00079                                 continue;
00080                         }
00081                         if (*from == '>') {     // process tokens
00082                                 intoken = false;
00083                                 if (!strncmp(token, "div type=\"variant\"", 19)) {
00084                                   hide = true;
00085                                   continue;
00086                                 }
00087                                 else if (!strncmp(token, "/div", 4)) {
00088                                   hide = false;
00089                                   continue;
00090                                 }
00091 
00092                                 // if not a footnote token, keep token in text
00093                                 if (!hide) {
00094                                         *to++ = '<';
00095                                         for (char *tok = token; *tok; tok++)
00096                                                 *to++ = *tok;
00097                                         *to++ = '>';
00098                                 }
00099                                 continue;
00100                         }
00101                         if (intoken) {
00102                                 if (tokpos < 2045)
00103                                         token[tokpos++] = *from;
00104                                         token[tokpos+2] = 0;
00105                         }
00106                         else    {
00107                                 if (!hide) {
00108                                         *to++ = *from;
00109                                 }
00110                         }
00111                 }
00112                 *to++ = 0;
00113                 *to = 0;
00114 
00115         }
00116         else if (option == 1) { //we want variant only
00117                 char *to, *from, token[2048]; // cheese.  Fix.
00118                 int tokpos = 0;
00119                 bool intoken = false;
00120                 int len;
00121                 bool hide = false;
00122 
00123                 len = strlen(text) + 1; // shift string to right of buffer
00124                 if (len < maxlen) {
00125                         memmove(&text[maxlen - len], text, len);
00126                         from = &text[maxlen - len];
00127                 }
00128                 else    from = text;
00129                 
00130                 // -------------------------------
00131 
00132                 for (to = text; *from; from++) {
00133                         if (*from == '<') {
00134                                 intoken = true;
00135                                 tokpos = 0;
00136                                 token[0] = 0;
00137                                 token[1] = 0;
00138                                 token[2] = 0;
00139                                 continue;
00140                         }
00141                         if (*from == '>') {     // process tokens
00142                                 intoken = false;
00143                                 if (!strncmp(token, "div type=\"primary\"", 19)) {
00144                                   hide = true;
00145                                   continue;
00146                                 }
00147                                 else if (!strncmp(token, "/div", 4)) {
00148                                   hide = false;
00149                                   continue;
00150                                 }
00151 
00152                                 // if not a footnote token, keep token in text
00153                                 if (!hide) {
00154                                         *to++ = '<';
00155                                         for (char *tok = token; *tok; tok++)
00156                                                 *to++ = *tok;
00157                                         *to++ = '>';
00158                                 }
00159                                 continue;
00160                         }
00161                         if (intoken) {
00162                                 if (tokpos < 2045)
00163                                         token[tokpos++] = *from;
00164                                         token[tokpos+2] = 0;
00165                         }
00166                         else    {
00167                                 if (!hide) {
00168                                         *to++ = *from;
00169                                 }
00170                         }
00171                 }
00172                 *to++ = 0;
00173                 *to = 0;
00174 
00175         }
00176         return 0;
00177 }
00178 
00179 
00180 
00181 
00182 
00183 

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