00001 /***************************************************************************
00002 plainfootnotes.cpp - description
00003 -------------------
00004 begin : Wed Oct 13 1999
00005 copyright : (C) 1999 by The team of BibleTime
00006 email : info@bibletime.de
00007 ***************************************************************************/
00008
00009 /***************************************************************************
00010 * *
00011 * This program is free software; you can redistribute it and/or modify *
00012 * it under the terms of the GNU General Public License as published by *
00013 * the Free Software Foundation; either version 2 of the License, or *
00014 * (at your option) any later version. *
00015 * *
00016 ***************************************************************************/
00017
00018 #include <plainfootnotes.h>
00019 #include <swkey.h>
00020
00021 #include <stdlib.h>
00022 #include <string.h>
00023 #ifndef __GNUC__
00024 #else
00025 #include <unixstr.h>
00026 #endif
00027
00028 const char PLAINFootnotes::on[] = "On";
00029 const char PLAINFootnotes::off[] = "Off";
00030 const char PLAINFootnotes::optName[] = "Footnotes";
00031 const char PLAINFootnotes::optTip[] = "Toggles Footnotes On and Off In Bible Texts If They Exist";
00032
00033 PLAINFootnotes::PLAINFootnotes(){
00034 option = false;
00035 options.push_back(on);
00036 options.push_back(off);
00037 }
00038
00039 PLAINFootnotes::~PLAINFootnotes(){
00040 }
00041
00042
00043 void PLAINFootnotes::setOptionValue(const char *ival)
00044 {
00045 option = (!stricmp(ival, on));
00046 }
00047
00048 const char *PLAINFootnotes::getOptionValue()
00049 {
00050 return (option) ? on:off;
00051 }
00052
00053
00054 char PLAINFootnotes::ProcessText(char *text, int maxlen, const SWKey *key, const SWModule *module)
00055 {
00056 char token[2048];
00057 int tokpos = 0;
00058 bool intoken = false;
00059 bool lastspace = false;
00060
00061 if (!option) { // if we don't want footnotes
00062 char *to, *from;
00063 int len;
00064 bool hide = false;
00065
00066 len = strlen(text) + 1; // shift string to right of buffer
00067 if (len < maxlen)
00068 {
00069 memmove(&text[maxlen - len], text, len);
00070 from = &text[maxlen - len];
00071 }
00072 else from = text; // -------------------------------
00073
00074 for (to = text; *from; from++) {
00075 if (*from == '{') // Footnote start
00076 {
00077 hide = true;
00078 continue;
00079 }
00080 if (*from == '}') // Footnote end
00081 {
00082 hide=false;
00083 continue;
00084 }
00085 if (intoken) {
00086 if (tokpos < 2045)
00087 token[tokpos++] = *from;
00088 token[tokpos+2] = 0;
00089 }
00090 else {
00091 if (!hide) {
00092 *to++ = *from;
00093 lastspace = (*from == ' ');
00094 }
00095 }
00096 }
00097 *to++ = 0;
00098 *to = 0;
00099 }
00100 return 0;
00101 }
00102
1.2.15