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

gbffootnotes.cpp

00001 /******************************************************************************
00002  *
00003  * gbffootnotes -       SWFilter decendant to hide or show footnotes
00004  *                      in a GBF module.
00005  */
00006 
00007 
00008 #include <stdlib.h>
00009 #include <string.h>
00010 #include <gbffootnotes.h>
00011 #ifndef __GNUC__
00012 #else
00013 #include <unixstr.h>
00014 #endif
00015 
00016 
00017 const char GBFFootnotes::on[] = "On";
00018 const char GBFFootnotes::off[] = "Off";
00019 const char GBFFootnotes::optName[] = "Footnotes";
00020 const char GBFFootnotes::optTip[] = "Toggles Footnotes On and Off if they exist";
00021 
00022 
00023 GBFFootnotes::GBFFootnotes() {
00024         option = false;
00025         options.push_back(on);
00026         options.push_back(off);
00027 }
00028 
00029 
00030 GBFFootnotes::~GBFFootnotes() {
00031 }
00032 
00033 void GBFFootnotes::setOptionValue(const char *ival)
00034 {
00035         option = (!stricmp(ival, on));
00036 }
00037 
00038 const char *GBFFootnotes::getOptionValue()
00039 {
00040         return (option) ? on:off;
00041 }
00042 
00043 char GBFFootnotes::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[4096]; // 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 //                              memset(token, 0, 4096);
00064                                 token[0] = 0;
00065                                 token[1] = 0;
00066                                 token[2] = 0;
00067                                 continue;
00068                         }
00069                         if (*from == '>') {     // process tokens
00070                                 intoken = false;
00071                                 switch (*token) {
00072                                 case 'R':                               // Reference
00073                                         switch(token[1]) {
00074                                         case 'F':               // Begin footnote
00075                                                 hide = true;
00076                                                 break;
00077                                         case 'f':               // end footnote
00078                                                 hide = false;
00079                                                 break;
00080                                         }
00081                                         continue;       // skip token
00082                                 case 'W':
00083                                         if (token[1] == 'T') {
00084                                                 switch (token[2]) {
00085                                                 case 'P':
00086                                                 case 'S':
00087                                                 case 'A':
00088                                                         continue; // remove this token
00089                                                 default:
00090                                                         break;
00091                                                 }
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 < 4090)
00105                                         token[tokpos++] = *from;
00106                                         token[tokpos+2] = 0;    // +2 cuz we init token with 2 extra '0' because of switch statement
00107                         }
00108                         else    {
00109                                 if (!hide) {
00110                                         *to++ = *from;
00111                                 }
00112                         }
00113                 }
00114                 *to++ = 0;
00115                 *to = 0;
00116         }
00117         return 0;
00118 }

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