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

thmlfootnotes.cpp

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

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