00001
00002
00003
00004
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) {
00046 char *to, *from, token[2048];
00047 int tokpos = 0;
00048 bool intoken = false;
00049 int len;
00050 bool hide = false;
00051
00052 len = strlen(text) + 1;
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 == '>') {
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
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 }