[sword-svn] r1762 - in trunk: src/modules/filters tests
scribe at crosswire.org
scribe at crosswire.org
Sun Apr 3 00:41:19 MST 2005
Author: scribe
Date: 2005-04-03 00:41:18 -0700 (Sun, 03 Apr 2005)
New Revision: 1762
Modified:
trunk/src/modules/filters/osishtmlhref.cpp
trunk/tests/filtertest.cpp
Log:
Updated filter to work when module and key are not passed
Modified: trunk/src/modules/filters/osishtmlhref.cpp
===================================================================
--- trunk/src/modules/filters/osishtmlhref.cpp 2005-04-01 19:39:25 UTC (rev 1761)
+++ trunk/src/modules/filters/osishtmlhref.cpp 2005-04-03 07:41:18 UTC (rev 1762)
@@ -25,9 +25,14 @@
OSISHTMLHREF::MyUserData::MyUserData(const SWModule *module, const SWKey *key) : BasicFilterUserData(module, key) {
- osisQToTick = ((!module->getConfigEntry("OSISqToTick")) || (strcmp(module->getConfigEntry("OSISqToTick"), "false")));
- if (module)
+ if (module) {
+ osisQToTick = ((!module->getConfigEntry("OSISqToTick")) || (strcmp(module->getConfigEntry("OSISqToTick"), "false")));
version = module->Name();
+ }
+ else {
+ osisQToTick = true; // default
+ version = "";
+ }
}
@@ -344,10 +349,13 @@
if (!src) // assert we have a src attribute
return false;
- char* filepath = new char[strlen(u->module->getConfigEntry("AbsoluteDataPath")) + strlen(token)];
- *filepath = 0;
- strcpy(filepath, userData->module->getConfigEntry("AbsoluteDataPath"));
- strcat(filepath, src);
+ SWBuf filepath;
+ if (userData->module) {
+ filepath = userData->module->getConfigEntry("AbsoluteDataPath");
+ if ((filepath.size()) && (filepath[filepath.size()-1] != '/') && (src[0] != '/'))
+ filepath += '/';
+ }
+ filepath += src;
// we do this because BibleCS looks for this EXACT format for an image tag
if (!u->suspendTextPassThru) {
@@ -355,29 +363,6 @@
buf+=filepath;
buf+="\" />";
}
-/*
- char imgc;
- for (c = filepath + strlen(filepath); c > filepath && *c != '.'; c--);
- c++;
- FILE* imgfile;
- if (stricmp(c, "jpg") || stricmp(c, "jpeg")) {
- imgfile = fopen(filepath, "r");
- if (imgfile != NULL) {
- buf += "{\\nonshppict {\\pict\\jpegblip ";
- while (feof(imgfile) != EOF) {
- buf.appendFormatted("%2x", fgetc(imgfile));
- }
- fclose(imgfile);
- buf += "}}";
- }
- }
- else if (stricmp(c, "png")) {
- buf += "{\\*\\shppict {\\pict\\pngblip ";
-
- buf += "}}";
- }
-*/
- delete [] filepath;
}
else {
Modified: trunk/tests/filtertest.cpp
===================================================================
--- trunk/tests/filtertest.cpp 2005-04-01 19:39:25 UTC (rev 1761)
+++ trunk/tests/filtertest.cpp 2005-04-03 07:41:18 UTC (rev 1762)
@@ -1,107 +1,23 @@
-#ifndef __GNUC__
-#include <io.h>
-#else
-#include <unistd.h>
-#endif
-#ifndef O_BINARY
-#define O_BINARY 0
-#endif
-#include <fcntl.h>
-#include <errno.h>
#include <iostream>
-#include <thmlhtmlhref.h>
-#include <unicodertf.h>
-#include <thmlosis.h>
-#include <gbfosis.h>
-#include <thmlosis.h>
-#include <versekey.h>
-#include <swmgr.h>
-#include <markupfiltmgr.h>
+#include <swbuf.h>
+#include <osishtmlhref.h>
+//#include <swmgr.h>
#ifndef NO_SWORD_NAMESPACE
using namespace sword;
#endif
using namespace std;
-#define MAXBUF 30000
-char readline(int fd, char **buf) {
- char ch;
- if (*buf)
- delete [] *buf;
- *buf = 0;
- int len;
-
- long index = lseek(fd, 0, SEEK_CUR);
- // clean up any preceding white space
- while ((len = read(fd, &ch, 1)) == 1) {
- if ((ch != 13) && (ch != ' ') && (ch != '\t'))
- break;
- else index++;
- }
-
-
- while (ch != 10) {
- if ((len = read(fd, &ch, 1)) != 1)
- break;
- }
-
- int size = (lseek(fd, 0, SEEK_CUR) - index) - 1;
-
- *buf = new char [ size + 1 ];
-
- if (size > 0) {
- lseek(fd, index, SEEK_SET);
- read(fd, *buf, size);
- read(fd, &ch, 1); //pop terminating char
- (*buf)[size] = 0;
-
- // clean up any trailing junk on buf
- for (char *it = *buf+(strlen(*buf)-1); it > *buf; it--) {
- if ((*it != 10) && (*it != 13) && (*it != ' ') && (*it != '\t'))
- break;
- else *it = 0;
- }
- }
- else **buf = 0;
- return !len;
-}
int main(int argc, char **argv) {
-/*
- SWMgr mgr(0, 0, true, new MarkupFilterMgr(FMT_HTMLHREF, ENC_RTF));
- mgr.setGlobalOption("Strong's Numbers", "on");
- mgr.setGlobalOption("Morphological Tags", "on");
- SWModule *module = mgr.Modules["KJV2003"];
- if (!module)
- module = mgr.Modules.begin()->second;
-*/
+// SWMgr mgr;
+// SWModule *module = mgr.getModule("KJV");
+ OSISHTMLHREF filter;
+ SWBuf buf;
+ buf = "This is OSIS text with a <figure src=\"images/scroll.png\"/>";
+ std::cout << "Original:\n\n" << buf << "\n\n-------\n\n";
+ filter.processText(buf);
+// filter.processText(buf, module->getKey(), module);
+ std::cout << buf << "\n\n+++++++\n";
- //ThMLOSIS filter;
- int fd = open(argv[1], O_RDONLY|O_BINARY);
- if (fd < 0) {
- fprintf(stderr, "error: %s: couldn't open input file: %s \n", argv[0], argv[2]);
- exit(-2);
- }
- UnicodeRTF filter;
- char *buffer = 0;
- while (!readline(fd, &buffer)) {
- SWBuf buf = buffer;
- filter.processText(buf);
- cout << buf << "\n";
- }
-// module->Key() = ((argc > 1) ? argv[1] : "john 1:1");
- /*
- char *buf = new char [ MAXBUF ];
- memset(buf, 0, MAXBUF);
-// strcpy(buf, "This is a verse reference: <scripRef>jas1:22,23-25;3;5:1;rom1-9</scripRef> with an <img src=\"/images/yoyo.jpg\">");
- module->getRawEntry();
- memcpy(buf, module->getRawEntry(), module->getEntrySize());
- std::cout << "Original:\n\n" << buf << "\n\n-------\n\n";
- filter.ProcessText(buf, MAXBUF - 3, *module, module);
-
- std::cout << buf << "\n\n+++++++\n";
- delete [] buf;
- cout << module->Name() << " : " << module->KeyText() << "\n";
- cout << module->RenderText() << "\n";
- */
- return 0;
+ return 0;
}
More information about the sword-cvs
mailing list