/****************************************************************************** * * thmlcgi.cpp - ThMLCGI: ThML to Diatheke/CGI format filter * * $Id$ * * Copyright 2001-2013 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society * P. O. Box 2528 * Tempe, AZ 85280-2528 * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation version 2. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * */ #include #include #include #include #include "thmlcgi.h" SWORD_NAMESPACE_START typedef std::map DualStringMap; namespace { class MyUserData : public BasicFilterUserData { public: MyUserData(const SWModule *module, const SWKey *key) : BasicFilterUserData(module, key) {} DualStringMap properties; }; } BasicFilterUserData *ThMLCGI::createUserData(const SWModule *module, const SWKey *key) { return new MyUserData(module, key); } ThMLCGI::ThMLCGI() { setTokenStart("<"); setTokenEnd(">"); setTokenCaseSensitive(true); addTokenSubstitute("note", " ("); addTokenSubstitute("/note", ") "); } bool ThMLCGI::handleToken(SWBuf &buf, const char *token, BasicFilterUserData *baseUserData) { MyUserData *userData = (MyUserData *) baseUserData; unsigned long i; if (!substituteToken(buf, token)) { // manually process if it wasn't a simple substitution if (!strncmp(token, "sync ", 5)) { buf += ""; if (*val) { buf += val; } buf += ""; } else if (!strncmp(token, "scripRef p", 10) || !strncmp(token, "scripRef v", 10)) { userData->properties["inscriptRef"] = "true"; buf += ""; } // we're starting a scripRef like "John 3:16" else if (!strcmp(token, "scripRef")) { userData->properties["inscriptRef"] = "false"; // let's stop text from going to output userData->properties["suspendTextPassThru"] = "true"; } // we've ended a scripRef else if (!strcmp(token, "/scripRef")) { if (userData->properties["inscriptRef"] == "true") { // like "John 3:16" userData->properties["inscriptRef"] = "false"; buf += ""; } else { // like "John 3:16" buf += "properties["lastTextNode"].c_str(); while (*vref) { if (*vref == ' ') buf += '+'; else buf += *vref; vref++; } buf += "\">"; buf += userData->properties["lastTextNode"].c_str(); // let's let text resume to output again userData->properties["suspendTextPassThru"] = "false"; buf += ""; } } else if (!strncmp(token, "div class=\"sechead\"", 19)) { userData->properties["SecHead"] = "true"; buf += "
"; } else if (!strncmp(token, "div class=\"title\"", 19)) { userData->properties["SecHead"] = "true"; buf += "
"; } else if (!strncmp(token, "/div", 4)) { if (userData->properties["SecHead"] == "true") { buf += "
"; userData->properties["SecHead"] = "false"; } } else if(!strncmp(token, "note", 4)) { buf += " {"; } else { buf += '<'; for (i = 0; i < strlen(token); i++) buf += token[i]; buf += '>'; //return false; // we still didn't handle token } } return true; } SWORD_NAMESPACE_END