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

gbfheadings.cpp

00001 /******************************************************************************
00002  *
00003  * gbfheadings -        SWFilter decendant to hide or show headings
00004  *                      in a GBF module.
00005  */
00006 
00007 
00008 #include <stdlib.h>
00009 #include <string.h>
00010 #include <gbfheadings.h>
00011 #ifndef __GNUC__
00012 #else
00013 #include <unixstr.h>
00014 #endif
00015 
00016 
00017 const char GBFHeadings::on[] = "On";
00018 const char GBFHeadings::off[] = "Off";
00019 const char GBFHeadings::optName[] = "Headings";
00020 const char GBFHeadings::optTip[] = "Toggles Headings On and Off if they exist";
00021 
00022 
00023 GBFHeadings::GBFHeadings() {
00024         option = false;
00025         options.push_back(on);
00026         options.push_back(off);
00027 }
00028 
00029 
00030 GBFHeadings::~GBFHeadings() {
00031 }
00032 
00033 void GBFHeadings::setOptionValue(const char *ival)
00034 {
00035         option = (!stricmp(ival, on));
00036 }
00037 
00038 const char *GBFHeadings::getOptionValue()
00039 {
00040         return (option) ? on:off;
00041 }
00042 
00043 char GBFHeadings::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 //                              memset(token, 0, 2048);
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 'T':                               // Reference
00073                                         switch(token[1]) {
00074                                         case 'S':               // Begin heading
00075                                                 hide = true;
00076                                                 break;
00077                                         case 's':               // end heading
00078                                                 hide = false;
00079                                                 break;
00080                                         }
00081                                         continue;       // skip token
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:12:59 2002 for The Sword Project by doxygen1.2.15