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

thmllemma.cpp

00001 /******************************************************************************
00002  *
00003  * thmllemma -  SWFilter decendant to hide or show lemmas
00004  *                      in a ThML module.
00005  */
00006 
00007 
00008 #include <stdlib.h>
00009 #include <string.h>
00010 #include <thmllemma.h>
00011 #ifndef __GNUC__
00012 #else
00013 #include <unixstr.h>
00014 #endif
00015 
00016 
00017 const char ThMLLemma::on[] = "On";
00018 const char ThMLLemma::off[] = "Off";
00019 const char ThMLLemma::optName[] = "Lemmas";
00020 const char ThMLLemma::optTip[] = "Toggles Lemmas On and Off if they exist";
00021 
00022 ThMLLemma::ThMLLemma() {
00023         option = false;
00024         options.push_back(on);
00025         options.push_back(off);
00026 }
00027 
00028 
00029 ThMLLemma::~ThMLLemma() {
00030 }
00031 
00032 void ThMLLemma::setOptionValue(const char *ival)
00033 {
00034         option = (!stricmp(ival, on));
00035 }
00036 
00037 const char *ThMLLemma::getOptionValue()
00038 {
00039         return (option) ? on:off;
00040 }
00041 
00042 char ThMLLemma::ProcessText(char *text, int maxlen, const SWKey *key, const SWModule *module)
00043 {
00044         if (!option) {  // if we don't want lemmas
00045                 char *to, *from, token[2048]; // cheese.  Fix.
00046                 int tokpos = 0;
00047                 bool intoken = false;
00048                 int len;
00049                 bool lastspace = false;
00050 
00051                 len = strlen(text) + 1; // shift string to right of buffer
00052                 if (len < maxlen) {
00053                         memmove(&text[maxlen - len], text, len);
00054                         from = &text[maxlen - len];
00055                 }
00056                 else    from = text;    // -------------------------------
00057 
00058                 for (to = text; *from; from++) {
00059                         if (*from == '<') {
00060                                 intoken = true;
00061                                 tokpos = 0;
00062                                 token[0] = 0;
00063                                 token[1] = 0;
00064                                 token[2] = 0;
00065                                 continue;
00066                         }
00067                         if (*from == '>') {     // process tokens
00068                                 intoken = false;
00069                                 if (!strnicmp(token, "sync type=\"lemma\" ", 18)) {     // Lemma
00070                                   if ((from[1] == ' ') || (from[1] == ',') || (from[1] == ';') || (from[1] == '.') || (from[1] == '?') || (from[1] == '!') || (from[1] == ')') || (from[1] == '\'') || (from[1] == '\"')) {
00071                                     if (lastspace)
00072                                       to--;
00073                                   }
00074                                   continue;
00075                                 }
00076                                 // if not a lemma token, keep token in text
00077                                 *to++ = '<';
00078                                 for (char *tok = token; *tok; tok++)
00079                                         *to++ = *tok;
00080                                 *to++ = '>';
00081                                 continue;
00082                         }
00083                         if (intoken) {
00084                                 if (tokpos < 2045)
00085                                         token[tokpos++] = *from;
00086                                         token[tokpos+2] = 0;
00087                         }
00088                         else    {
00089                                 *to++ = *from;
00090                                 lastspace = (*from == ' ');
00091                         }
00092                 }
00093                 *to++ = 0;
00094                 *to = 0;
00095         }
00096         return 0;
00097 }

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