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

thmlheadings.cpp

00001 /******************************************************************************
00002  *
00003  * thmlheadings -       SWFilter decendant to hide or show headings
00004  *                      in a ThML module.
00005  */
00006 
00007 
00008 #include <stdlib.h>
00009 #include <string.h>
00010 #include <thmlheadings.h>
00011 #ifndef __GNUC__
00012 #else
00013 #include <unixstr.h>
00014 #endif
00015 
00016 
00017 const char ThMLHeadings::on[] = "On";
00018 const char ThMLHeadings::off[] = "Off";
00019 const char ThMLHeadings::optName[] = "Headings";
00020 const char ThMLHeadings::optTip[] = "Toggles Headings On and Off if they exist";
00021 
00022 
00023 ThMLHeadings::ThMLHeadings() {
00024         option = false;
00025         options.push_back(on);
00026         options.push_back(off);
00027 }
00028 
00029 
00030 ThMLHeadings::~ThMLHeadings() {
00031 }
00032 
00033 void ThMLHeadings::setOptionValue(const char *ival)
00034 {
00035         option = (!stricmp(ival, on));
00036 }
00037 
00038 const char *ThMLHeadings::getOptionValue()
00039 {
00040         return (option) ? on:off;
00041 }
00042 
00043 char ThMLHeadings::ProcessText(char *text, int maxlen, const SWKey *key, const SWModule *module)
00044 {
00045         if (!option) {  // if we don't want headings
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 (!strnicmp(token, "div class=\"sechead\"", 19)) {
00071                                                 hide = true;
00072                                                 continue;
00073                                 }
00074                                 if (!strnicmp(token, "div class=\"title\"", 17)) {
00075                                                 hide = true;
00076                                                 continue;
00077                                 }
00078                                 else if (hide && !strnicmp(token, "/div", 4)) {
00079                                                 hide = false;
00080                                                 continue;
00081                                 }
00082 
00083                                 // if not a heading token, keep token in text
00084                                 if (!hide) {
00085                                         *to++ = '<';
00086                                         for (char *tok = token; *tok; tok++)
00087                                                 *to++ = *tok;
00088                                         *to++ = '>';
00089                                 }
00090                                 continue;
00091                         }
00092                         if (intoken) {
00093                                 if (tokpos < 2045)
00094                                         token[tokpos++] = *from;
00095                                         token[tokpos+2] = 0;
00096                         }
00097                         else    {
00098                                 if (!hide) {
00099                                         *to++ = *from;
00100                                 }
00101                         }
00102                 }
00103                 *to++ = 0;
00104                 *to = 0;
00105         }
00106         return 0;
00107 }

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