[sword-svn] r2078 - in trunk: include src/mgr src/modules/filters
scribe at www.crosswire.org
scribe at www.crosswire.org
Thu Sep 13 20:31:44 MST 2007
Author: scribe
Date: 2007-09-13 20:31:44 -0700 (Thu, 13 Sep 2007)
New Revision: 2078
Modified:
trunk/include/curlftpt.h
trunk/include/ftplibftpt.h
trunk/include/ftptrans.h
trunk/include/teiplain.h
trunk/include/teirtf.h
trunk/src/mgr/curlftpt.cpp
trunk/src/mgr/ftplibftpt.cpp
trunk/src/mgr/ftptrans.cpp
trunk/src/modules/filters/teiplain.cpp
trunk/src/modules/filters/teirtf.cpp
Log:
Fixed CRLF mixups in some files
Modified: trunk/include/curlftpt.h
===================================================================
--- trunk/include/curlftpt.h 2007-09-14 01:34:37 UTC (rev 2077)
+++ trunk/include/curlftpt.h 2007-09-14 03:31:44 UTC (rev 2078)
@@ -1,32 +1,32 @@
-#ifndef CURLFTPT_H
-#define CURLFTPT_H
-
-#include <defs.h>
-#include <ftptrans.h>
-
-SWORD_NAMESPACE_START
-
-class CURL;
-
-// initialize/cleanup SYSTEMWIDE library with life of this static.
-class CURLFTPTransport_init {
-public:
- CURLFTPTransport_init();
- ~CURLFTPTransport_init();
-};
-
-
-class SWDLLEXPORT CURLFTPTransport : public FTPTransport {
- CURL *session;
-
-public:
- CURLFTPTransport(const char *host, StatusReporter *statusReporter = 0);
- ~CURLFTPTransport();
-
- virtual char getURL(const char *destPath, const char *sourceURL);
-};
-
-
-SWORD_NAMESPACE_END
-
-#endif
+#ifndef CURLFTPT_H
+#define CURLFTPT_H
+
+#include <defs.h>
+#include <ftptrans.h>
+
+SWORD_NAMESPACE_START
+
+class CURL;
+
+// initialize/cleanup SYSTEMWIDE library with life of this static.
+class CURLFTPTransport_init {
+public:
+ CURLFTPTransport_init();
+ ~CURLFTPTransport_init();
+};
+
+
+class SWDLLEXPORT CURLFTPTransport : public FTPTransport {
+ CURL *session;
+
+public:
+ CURLFTPTransport(const char *host, StatusReporter *statusReporter = 0);
+ ~CURLFTPTransport();
+
+ virtual char getURL(const char *destPath, const char *sourceURL);
+};
+
+
+SWORD_NAMESPACE_END
+
+#endif
Modified: trunk/include/ftplibftpt.h
===================================================================
--- trunk/include/ftplibftpt.h 2007-09-14 01:34:37 UTC (rev 2077)
+++ trunk/include/ftplibftpt.h 2007-09-14 03:31:44 UTC (rev 2078)
@@ -1,29 +1,29 @@
-#ifndef FTPLIBFTPT_H
-#define FTPLIBFTPT_H
-
-#include <defs.h>
-#include <ftptrans.h>
-
-SWORD_NAMESPACE_START
-
-// initialize/cleanup SYSTEMWIDE library with life of this static.
-class FTPLibFTPTransport_init {
-public:
- FTPLibFTPTransport_init();
- ~FTPLibFTPTransport_init();
-};
-
-
-class SWDLLEXPORT FTPLibFTPTransport : public FTPTransport {
- void *nControl;
-
-public:
- FTPLibFTPTransport(const char *host, StatusReporter *statusReporter = 0);
- ~FTPLibFTPTransport();
- char getURL(const char *destPath, const char *sourceURL);
-};
-
-
-SWORD_NAMESPACE_END
-
-#endif
+#ifndef FTPLIBFTPT_H
+#define FTPLIBFTPT_H
+
+#include <defs.h>
+#include <ftptrans.h>
+
+SWORD_NAMESPACE_START
+
+// initialize/cleanup SYSTEMWIDE library with life of this static.
+class FTPLibFTPTransport_init {
+public:
+ FTPLibFTPTransport_init();
+ ~FTPLibFTPTransport_init();
+};
+
+
+class SWDLLEXPORT FTPLibFTPTransport : public FTPTransport {
+ void *nControl;
+
+public:
+ FTPLibFTPTransport(const char *host, StatusReporter *statusReporter = 0);
+ ~FTPLibFTPTransport();
+ char getURL(const char *destPath, const char *sourceURL);
+};
+
+
+SWORD_NAMESPACE_END
+
+#endif
Modified: trunk/include/ftptrans.h
===================================================================
--- trunk/include/ftptrans.h 2007-09-14 01:34:37 UTC (rev 2077)
+++ trunk/include/ftptrans.h 2007-09-14 03:31:44 UTC (rev 2078)
@@ -1,61 +1,61 @@
-#ifndef FTPTRANS_H
-#define FTPTRANS_H
-
-#include <vector>
-#include <defs.h>
-#include <swbuf.h>
-
-//SWORD_NAMESPACE_START
-
-
-// move this include to cpp once struct ftpparse isn't exposed anymore
-extern "C" {
-#include <ftpparse.h>
-}
-
-SWORD_NAMESPACE_START
-
-/** Class for reporting status
-*/
-class SWDLLEXPORT StatusReporter {
+#ifndef FTPTRANS_H
+#define FTPTRANS_H
+
+#include <vector>
+#include <defs.h>
+#include <swbuf.h>
+
+//SWORD_NAMESPACE_START
+
+
+// move this include to cpp once struct ftpparse isn't exposed anymore
+extern "C" {
+#include <ftpparse.h>
+}
+
+SWORD_NAMESPACE_START
+
+/** Class for reporting status
+*/
+class SWDLLEXPORT StatusReporter {
public:
- virtual ~StatusReporter() {};
- /** Messages before stages of a batch download */
- virtual void preStatus(long totalBytes, long completedBytes, const char *message);
-
- /** frequently called throughout a download, to report status */
- virtual void statusUpdate(double dtTotal, double dlNow);
-};
-
-
-/** TODO: document
-* A base class to be used for reimplementation of network services.
-*/
-class SWDLLEXPORT FTPTransport {
-
-protected:
- StatusReporter *statusReporter;
- bool passive;
- bool term;
- SWBuf host;
-
-public:
- FTPTransport(const char *host, StatusReporter *statusReporter = 0);
- virtual ~FTPTransport();
- virtual char getURL(const char *destPath, const char *sourceURL);
-
- int copyDirectory(const char *urlPrefix, const char *dir, const char *dest, const char *suffix);
-
- // probably change to not expose struct ftpparse. We probably need our
- // own FTPFile class or something that contains things like file name,
- // size, type (dir, file, special). Then change to vector of this class
- // instead of ftpparse
- virtual std::vector<struct ftpparse> getDirList(const char *dirURL);
- void setPassive(bool passive) { this->passive = passive; }
- void terminate() { term = true; }
-};
-
-
-SWORD_NAMESPACE_END
-
-#endif
+ virtual ~StatusReporter() {};
+ /** Messages before stages of a batch download */
+ virtual void preStatus(long totalBytes, long completedBytes, const char *message);
+
+ /** frequently called throughout a download, to report status */
+ virtual void statusUpdate(double dtTotal, double dlNow);
+};
+
+
+/** TODO: document
+* A base class to be used for reimplementation of network services.
+*/
+class SWDLLEXPORT FTPTransport {
+
+protected:
+ StatusReporter *statusReporter;
+ bool passive;
+ bool term;
+ SWBuf host;
+
+public:
+ FTPTransport(const char *host, StatusReporter *statusReporter = 0);
+ virtual ~FTPTransport();
+ virtual char getURL(const char *destPath, const char *sourceURL);
+
+ int copyDirectory(const char *urlPrefix, const char *dir, const char *dest, const char *suffix);
+
+ // probably change to not expose struct ftpparse. We probably need our
+ // own FTPFile class or something that contains things like file name,
+ // size, type (dir, file, special). Then change to vector of this class
+ // instead of ftpparse
+ virtual std::vector<struct ftpparse> getDirList(const char *dirURL);
+ void setPassive(bool passive) { this->passive = passive; }
+ void terminate() { term = true; }
+};
+
+
+SWORD_NAMESPACE_END
+
+#endif
Modified: trunk/include/teiplain.h
===================================================================
--- trunk/include/teiplain.h 2007-09-14 01:34:37 UTC (rev 2077)
+++ trunk/include/teiplain.h 2007-09-14 03:31:44 UTC (rev 2078)
@@ -1,49 +1,49 @@
-/******************************************************************************
- *
- * $Id:
- *
- * Copyright 1998 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.
- *
- */
-
-#ifndef TEIPLAIN_H
-#define TEIPLAIN_H
-
-#include <swbasicfilter.h>
-#include <utilxml.h>
-
-SWORD_NAMESPACE_START
-
-/** this filter converts TEI text to plain text
- */
-class SWDLLEXPORT TEIPlain : public SWBasicFilter {
-public:
-protected:
- class MyUserData : public BasicFilterUserData {
- public:
- SWBuf w;
- XMLTag tag;
- MyUserData(const SWModule *module, const SWKey *key) : BasicFilterUserData(module, key) {}
- };
- virtual BasicFilterUserData *createUserData(const SWModule *module, const SWKey *key) {
- return new MyUserData(module, key);
- }
- virtual bool handleToken(SWBuf &buf, const char *token, BasicFilterUserData *userData);
-public:
- TEIPlain();
-};
-
-SWORD_NAMESPACE_END
-#endif
+/******************************************************************************
+ *
+ * $Id:
+ *
+ * Copyright 1998 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.
+ *
+ */
+
+#ifndef TEIPLAIN_H
+#define TEIPLAIN_H
+
+#include <swbasicfilter.h>
+#include <utilxml.h>
+
+SWORD_NAMESPACE_START
+
+/** this filter converts TEI text to plain text
+ */
+class SWDLLEXPORT TEIPlain : public SWBasicFilter {
+public:
+protected:
+ class MyUserData : public BasicFilterUserData {
+ public:
+ SWBuf w;
+ XMLTag tag;
+ MyUserData(const SWModule *module, const SWKey *key) : BasicFilterUserData(module, key) {}
+ };
+ virtual BasicFilterUserData *createUserData(const SWModule *module, const SWKey *key) {
+ return new MyUserData(module, key);
+ }
+ virtual bool handleToken(SWBuf &buf, const char *token, BasicFilterUserData *userData);
+public:
+ TEIPlain();
+};
+
+SWORD_NAMESPACE_END
+#endif
Modified: trunk/include/teirtf.h
===================================================================
--- trunk/include/teirtf.h 2007-09-14 01:34:37 UTC (rev 2077)
+++ trunk/include/teirtf.h 2007-09-14 03:31:44 UTC (rev 2078)
@@ -1,50 +1,50 @@
-/******************************************************************************
- *
- * $Id:
- *
- * Copyright 1998 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.
- *
- */
-
-#ifndef TEIRTF_H
-#define TEIRTF_H
-
-#include <swbasicfilter.h>
-
-SWORD_NAMESPACE_START
-
-/** this filter converts TEI text to RTF text
- */
-class SWDLLEXPORT TEIRTF : public SWBasicFilter {
-private:
-
-protected:
- class MyUserData : public BasicFilterUserData {
- public:
- bool BiblicalText;
- SWBuf w;
- SWBuf version;
- MyUserData(const SWModule *module, const SWKey *key);
- };
- virtual BasicFilterUserData *createUserData(const SWModule *module, const SWKey *key) {
- return new MyUserData(module, key);
- }
- virtual bool handleToken(SWBuf &buf, const char *token, BasicFilterUserData *userData);
-public:
- TEIRTF();
-};
-
-SWORD_NAMESPACE_END
-#endif
+/******************************************************************************
+ *
+ * $Id:
+ *
+ * Copyright 1998 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.
+ *
+ */
+
+#ifndef TEIRTF_H
+#define TEIRTF_H
+
+#include <swbasicfilter.h>
+
+SWORD_NAMESPACE_START
+
+/** this filter converts TEI text to RTF text
+ */
+class SWDLLEXPORT TEIRTF : public SWBasicFilter {
+private:
+
+protected:
+ class MyUserData : public BasicFilterUserData {
+ public:
+ bool BiblicalText;
+ SWBuf w;
+ SWBuf version;
+ MyUserData(const SWModule *module, const SWKey *key);
+ };
+ virtual BasicFilterUserData *createUserData(const SWModule *module, const SWKey *key) {
+ return new MyUserData(module, key);
+ }
+ virtual bool handleToken(SWBuf &buf, const char *token, BasicFilterUserData *userData);
+public:
+ TEIRTF();
+};
+
+SWORD_NAMESPACE_END
+#endif
Modified: trunk/src/mgr/curlftpt.cpp
===================================================================
--- trunk/src/mgr/curlftpt.cpp 2007-09-14 01:34:37 UTC (rev 2077)
+++ trunk/src/mgr/curlftpt.cpp 2007-09-14 03:31:44 UTC (rev 2078)
@@ -1,116 +1,116 @@
- /*****************************************************************************
- * CURLFTPTransport functions
- *
- */
-
-
-#include <curlftpt.h>
-
-#include <fcntl.h>
-
-#include <curl/curl.h>
-#include <curl/types.h>
-#include <curl/easy.h>
-
-SWORD_NAMESPACE_START
-
-
-struct FtpFile {
- const char *filename;
- FILE *stream;
-};
-
-
-int my_fwrite(void *buffer, size_t size, size_t nmemb, void *stream);
-int my_fprogress(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow);
-
-static CURLFTPTransport_init _CURLFTPTransport_init;
-
-CURLFTPTransport_init::CURLFTPTransport_init() {
- //curl_global_init(CURL_GLOBAL_DEFAULT); // curl_easy_init automatically calls it if needed
-}
-
-CURLFTPTransport_init::~CURLFTPTransport_init() {
- curl_global_cleanup();
-}
-
-int my_fwrite(void *buffer, size_t size, size_t nmemb, void *stream) {
- struct FtpFile *out=(struct FtpFile *)stream;
- if (out && !out->stream) {
- /* open file for writing */
- out->stream=fopen(out->filename, "wb");
- if (!out->stream)
- return -1; /* failure, can't open file to write */
- }
- return fwrite(buffer, size, nmemb, out->stream);
-}
-
-
-int my_fprogress(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow) {
- if (clientp) {
- ((StatusReporter *)clientp)->statusUpdate(dltotal, dlnow);
- }
- return 0;
-}
-
-
-CURLFTPTransport::CURLFTPTransport(const char *host, StatusReporter *sr) : FTPTransport(host, sr) {
- session = (CURL *)curl_easy_init();
-}
-
-
-CURLFTPTransport::~CURLFTPTransport() {
- curl_easy_cleanup(session);
-}
-
-
-char CURLFTPTransport::getURL(const char *destPath, const char *sourceURL) {
- signed char retVal = 0;
- struct FtpFile ftpfile = {destPath, NULL};
-
- CURLcode res;
-
- if (session) {
- curl_easy_setopt(session, CURLOPT_URL, sourceURL);
-
- curl_easy_setopt(session, CURLOPT_USERPWD, "ftp:installmgr at user.com");
- curl_easy_setopt(session, CURLOPT_WRITEFUNCTION, my_fwrite);
- if (!passive)
- curl_easy_setopt(session, CURLOPT_FTPPORT, "-");
- curl_easy_setopt(session, CURLOPT_NOPROGRESS, 0);
- curl_easy_setopt(session, CURLOPT_PROGRESSDATA, statusReporter);
- curl_easy_setopt(session, CURLOPT_PROGRESSFUNCTION, my_fprogress);
- /* Set a pointer to our struct to pass to the callback */
- curl_easy_setopt(session, CURLOPT_FILE, &ftpfile);
-
- /* Switch on full protocol/debug output */
- curl_easy_setopt(session, CURLOPT_VERBOSE, true);
-
- /* FTP connection settings */
-
-#if (LIBCURL_VERSION_MAJOR > 7) || \
- ((LIBCURL_VERSION_MAJOR == 7) && (LIBCURL_VERSION_MINOR > 10)) || \
- ((LIBCURL_VERSION_MAJOR == 7) && (LIBCURL_VERSION_MINOR == 10) && (LIBCURL_VERSION_PATCH >= 5))
-# define EPRT_AVAILABLE 1
-#endif
-
-#ifdef EPRT_AVAILABLE
- curl_easy_setopt(session, CURLOPT_FTP_USE_EPRT, 0);
-#endif
-
- res = curl_easy_perform(session);
-
- if(CURLE_OK != res) {
- retVal = -1;
- }
- }
-
- if (ftpfile.stream)
- fclose(ftpfile.stream); /* close the local file */
-
- return retVal;
-}
-
-
-SWORD_NAMESPACE_END
-
+ /*****************************************************************************
+ * CURLFTPTransport functions
+ *
+ */
+
+
+#include <curlftpt.h>
+
+#include <fcntl.h>
+
+#include <curl/curl.h>
+#include <curl/types.h>
+#include <curl/easy.h>
+
+SWORD_NAMESPACE_START
+
+
+struct FtpFile {
+ const char *filename;
+ FILE *stream;
+};
+
+
+int my_fwrite(void *buffer, size_t size, size_t nmemb, void *stream);
+int my_fprogress(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow);
+
+static CURLFTPTransport_init _CURLFTPTransport_init;
+
+CURLFTPTransport_init::CURLFTPTransport_init() {
+ //curl_global_init(CURL_GLOBAL_DEFAULT); // curl_easy_init automatically calls it if needed
+}
+
+CURLFTPTransport_init::~CURLFTPTransport_init() {
+ curl_global_cleanup();
+}
+
+int my_fwrite(void *buffer, size_t size, size_t nmemb, void *stream) {
+ struct FtpFile *out=(struct FtpFile *)stream;
+ if (out && !out->stream) {
+ /* open file for writing */
+ out->stream=fopen(out->filename, "wb");
+ if (!out->stream)
+ return -1; /* failure, can't open file to write */
+ }
+ return fwrite(buffer, size, nmemb, out->stream);
+}
+
+
+int my_fprogress(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow) {
+ if (clientp) {
+ ((StatusReporter *)clientp)->statusUpdate(dltotal, dlnow);
+ }
+ return 0;
+}
+
+
+CURLFTPTransport::CURLFTPTransport(const char *host, StatusReporter *sr) : FTPTransport(host, sr) {
+ session = (CURL *)curl_easy_init();
+}
+
+
+CURLFTPTransport::~CURLFTPTransport() {
+ curl_easy_cleanup(session);
+}
+
+
+char CURLFTPTransport::getURL(const char *destPath, const char *sourceURL) {
+ signed char retVal = 0;
+ struct FtpFile ftpfile = {destPath, NULL};
+
+ CURLcode res;
+
+ if (session) {
+ curl_easy_setopt(session, CURLOPT_URL, sourceURL);
+
+ curl_easy_setopt(session, CURLOPT_USERPWD, "ftp:installmgr at user.com");
+ curl_easy_setopt(session, CURLOPT_WRITEFUNCTION, my_fwrite);
+ if (!passive)
+ curl_easy_setopt(session, CURLOPT_FTPPORT, "-");
+ curl_easy_setopt(session, CURLOPT_NOPROGRESS, 0);
+ curl_easy_setopt(session, CURLOPT_PROGRESSDATA, statusReporter);
+ curl_easy_setopt(session, CURLOPT_PROGRESSFUNCTION, my_fprogress);
+ /* Set a pointer to our struct to pass to the callback */
+ curl_easy_setopt(session, CURLOPT_FILE, &ftpfile);
+
+ /* Switch on full protocol/debug output */
+ curl_easy_setopt(session, CURLOPT_VERBOSE, true);
+
+ /* FTP connection settings */
+
+#if (LIBCURL_VERSION_MAJOR > 7) || \
+ ((LIBCURL_VERSION_MAJOR == 7) && (LIBCURL_VERSION_MINOR > 10)) || \
+ ((LIBCURL_VERSION_MAJOR == 7) && (LIBCURL_VERSION_MINOR == 10) && (LIBCURL_VERSION_PATCH >= 5))
+# define EPRT_AVAILABLE 1
+#endif
+
+#ifdef EPRT_AVAILABLE
+ curl_easy_setopt(session, CURLOPT_FTP_USE_EPRT, 0);
+#endif
+
+ res = curl_easy_perform(session);
+
+ if(CURLE_OK != res) {
+ retVal = -1;
+ }
+ }
+
+ if (ftpfile.stream)
+ fclose(ftpfile.stream); /* close the local file */
+
+ return retVal;
+}
+
+
+SWORD_NAMESPACE_END
+
Modified: trunk/src/mgr/ftplibftpt.cpp
===================================================================
--- trunk/src/mgr/ftplibftpt.cpp 2007-09-14 01:34:37 UTC (rev 2077)
+++ trunk/src/mgr/ftplibftpt.cpp 2007-09-14 03:31:44 UTC (rev 2078)
@@ -1,71 +1,71 @@
- /*****************************************************************************
- * FTPLibFTPTransport functions
- *
- */
-
-#include <stdio.h>
-#include <ftplibftpt.h>
-
-#include <fcntl.h>
-
-#include <ftplib.h>
-
-
-SWORD_NAMESPACE_START
-
-
-static FTPLibFTPTransport_init _FTPLibFTPTransport_init;
-
-FTPLibFTPTransport_init::FTPLibFTPTransport_init() {
- FtpInit();
-}
-
-FTPLibFTPTransport_init::~FTPLibFTPTransport_init() {
-}
-
-
-FTPLibFTPTransport::FTPLibFTPTransport(const char *host, StatusReporter *sr) : FTPTransport(host, sr) {
- void *retVal = 0;
-
- fprintf(stderr, "connecting to host %s\n", host);
- if (FtpConnect(host, (netbuf **)&nControl))
- retVal = nControl;
- else
- fprintf(stderr, "Failed to connect to %s\n", host);
- if (!FtpLogin("anonymous", "installmgr at user.com", (netbuf *)nControl))
- fprintf(stderr, "Failed to login to %s\n", host);
-}
-
-
-FTPLibFTPTransport::~FTPLibFTPTransport() {
- FtpQuit((netbuf *) nControl);
-}
-
-
-char FTPLibFTPTransport::getURL(const char *destPath, const char *sourceURL) {
- char retVal = 0;
- SWBuf sourcePath = sourceURL;
- sourcePath << (6 + host.length()); // shift << "ftp://hostname";
- fprintf(stderr, "getting file %s to %s\n", sourcePath.c_str(), destPath);
- if (passive)
- FtpOptions(FTPLIB_CONNMODE, FTPLIB_PASSIVE, (netbuf *)nControl);
- else
- FtpOptions(FTPLIB_CONNMODE, FTPLIB_PORT, (netbuf *)nControl);
- // !!!WDG also want to set callback options
- if (!strcmp(destPath, "dirlist")) {
- fprintf(stderr, "getting test directory %s\n", sourcePath.c_str());
- FtpDir(NULL, sourcePath, (netbuf *)nControl);
- fprintf(stderr, "getting real directory %s\n", sourcePath.c_str());
- retVal = FtpDir(destPath, sourcePath, (netbuf *)nControl) - 1;
- }
- else {
- fprintf(stderr, "getting file %s\n", sourcePath.c_str());
- retVal = FtpGet(destPath, sourcePath, FTPLIB_IMAGE, (netbuf *)nControl) - 1;
- }
-
- return retVal;
-}
-
-
-SWORD_NAMESPACE_END
-
+ /*****************************************************************************
+ * FTPLibFTPTransport functions
+ *
+ */
+
+#include <stdio.h>
+#include <ftplibftpt.h>
+
+#include <fcntl.h>
+
+#include <ftplib.h>
+
+
+SWORD_NAMESPACE_START
+
+
+static FTPLibFTPTransport_init _FTPLibFTPTransport_init;
+
+FTPLibFTPTransport_init::FTPLibFTPTransport_init() {
+ FtpInit();
+}
+
+FTPLibFTPTransport_init::~FTPLibFTPTransport_init() {
+}
+
+
+FTPLibFTPTransport::FTPLibFTPTransport(const char *host, StatusReporter *sr) : FTPTransport(host, sr) {
+ void *retVal = 0;
+
+ fprintf(stderr, "connecting to host %s\n", host);
+ if (FtpConnect(host, (netbuf **)&nControl))
+ retVal = nControl;
+ else
+ fprintf(stderr, "Failed to connect to %s\n", host);
+ if (!FtpLogin("anonymous", "installmgr at user.com", (netbuf *)nControl))
+ fprintf(stderr, "Failed to login to %s\n", host);
+}
+
+
+FTPLibFTPTransport::~FTPLibFTPTransport() {
+ FtpQuit((netbuf *) nControl);
+}
+
+
+char FTPLibFTPTransport::getURL(const char *destPath, const char *sourceURL) {
+ char retVal = 0;
+ SWBuf sourcePath = sourceURL;
+ sourcePath << (6 + host.length()); // shift << "ftp://hostname";
+ fprintf(stderr, "getting file %s to %s\n", sourcePath.c_str(), destPath);
+ if (passive)
+ FtpOptions(FTPLIB_CONNMODE, FTPLIB_PASSIVE, (netbuf *)nControl);
+ else
+ FtpOptions(FTPLIB_CONNMODE, FTPLIB_PORT, (netbuf *)nControl);
+ // !!!WDG also want to set callback options
+ if (!strcmp(destPath, "dirlist")) {
+ fprintf(stderr, "getting test directory %s\n", sourcePath.c_str());
+ FtpDir(NULL, sourcePath, (netbuf *)nControl);
+ fprintf(stderr, "getting real directory %s\n", sourcePath.c_str());
+ retVal = FtpDir(destPath, sourcePath, (netbuf *)nControl) - 1;
+ }
+ else {
+ fprintf(stderr, "getting file %s\n", sourcePath.c_str());
+ retVal = FtpGet(destPath, sourcePath, FTPLIB_IMAGE, (netbuf *)nControl) - 1;
+ }
+
+ return retVal;
+}
+
+
+SWORD_NAMESPACE_END
+
Modified: trunk/src/mgr/ftptrans.cpp
===================================================================
--- trunk/src/mgr/ftptrans.cpp 2007-09-14 01:34:37 UTC (rev 2077)
+++ trunk/src/mgr/ftptrans.cpp 2007-09-14 03:31:44 UTC (rev 2078)
@@ -1,168 +1,168 @@
- /*****************************************************************************
- * FTPTransport functions
- *
- */
-
-
-#include <ftptrans.h>
-#include <filemgr.h>
-
-#include <fcntl.h>
-#include <dirent.h>
-#include <swlog.h>
-
-
-using std::vector;
-
-
-SWORD_NAMESPACE_START
-
-
-namespace {
-
-void removeTrailingSlash(SWBuf &buf) {
- int len = buf.size();
- if ((buf[len-1] == '/')
- || (buf[len-1] == '\\'))
- buf.size(len-1);
-}
-
-};
-
-
-void StatusReporter::preStatus(long totalBytes, long completedBytes, const char *message) {
-}
-
-void StatusReporter::statusUpdate(double dtTotal, double dlNow) {
-}
-
-
-FTPTransport::FTPTransport(const char *host, StatusReporter *statusReporter) {
- this->statusReporter = statusReporter;
- this->host = host;
- term = false;
-}
-
-
-FTPTransport::~FTPTransport() {
-}
-
-
-// override this method in your real transport class
-char FTPTransport::getURL(const char *destPath, const char *sourceURL) {
- char retVal = 0;
- return retVal;
-}
-
-
-vector<struct ftpparse> FTPTransport::getDirList(const char *dirURL) {
-
- vector<struct ftpparse> dirList;
-
- if (!getURL("dirlist", dirURL)) {
- FileDesc *fd = FileMgr::getSystemFileMgr()->open("dirlist", FileMgr::RDONLY);
- long size = fd->seek(0, SEEK_END);
- fd->seek(0, SEEK_SET);
- char *buf = new char [ size + 1 ];
- fd->read(buf, size);
- FileMgr::getSystemFileMgr()->close(fd);
- char *start = buf;
- char *end = start;
- while (start < (buf+size)) {
- struct ftpparse item;
- bool looking = true;
- for (end = start; *end; end++) {
- if (looking) {
- if ((*end == 10) || (*end == 13)) {
- *end = 0;
- looking = false;
- }
- }
- else if ((*end != 10) && (*end != 13))
- break;
- }
- SWLog::getSystemLog()->logWarning("FTPURLGetDir: parsing item %s(%d)\n", start, end-start);
- int status = ftpparse(&item, start, end - start);
- SWLog::getSystemLog()->logWarning("FTPURLGetDir: got item %s\n", item.name);
- if (status)
- dirList.push_back(item);
- start = end;
- }
- }
- else
- {
- SWLog::getSystemLog()->logWarning("FTPURLGetDir: failed to get dir %s\n", dirURL);
- }
- return dirList;
-}
-
-
-int FTPTransport::copyDirectory(const char *urlPrefix, const char *dir, const char *dest, const char *suffix) {
- unsigned int i;
- int retVal = 0;
-
- SWBuf url = SWBuf(urlPrefix) + SWBuf(dir);
- removeTrailingSlash(url);
- url += '/';
-
- SWLog::getSystemLog()->logWarning("FTPCopy: getting dir %s\n", url.c_str());
- vector<struct ftpparse> dirList = getDirList(url.c_str());
-
- if (!dirList.size()) {
- SWLog::getSystemLog()->logWarning("FTPCopy: failed to read dir %s\n", url.c_str());
- return -1;
- }
-
- long totalBytes = 0;
- for (i = 0; i < dirList.size(); i++)
- totalBytes += dirList[i].size;
- long completedBytes = 0;
- for (i = 0; i < dirList.size(); i++) {
- struct ftpparse &dirEntry = dirList[i];
- SWBuf buffer = (SWBuf)dest;
- removeTrailingSlash(buffer);
- buffer += (SWBuf)"/" + (dirEntry.name);
- if (!strcmp(&buffer.c_str()[buffer.length()-strlen(suffix)], suffix)) {
- SWBuf buffer2 = "Downloading (";
- buffer2.appendFormatted("%d", i+1);
- buffer2 += " of ";
- buffer2.appendFormatted("%d", dirList.size());
- buffer2 += "): ";
- buffer2 += (dirEntry.name);
- if (statusReporter)
- statusReporter->preStatus(totalBytes, completedBytes, buffer2.c_str());
- FileMgr::createParent(buffer.c_str()); // make sure parent directory exists
- SWTRY {
- SWBuf url = (SWBuf)urlPrefix + (SWBuf)dir;
- removeTrailingSlash(url);
- url += (SWBuf)"/" + dirEntry.name; //dont forget the final slash
- if (dirEntry.flagtrycwd != 1) {
- if (getURL(buffer.c_str(), url.c_str())) {
- SWLog::getSystemLog()->logWarning("FTPCopy: failed to get file %s\n", url.c_str());
- return -2;
- }
- completedBytes += dirEntry.size;
- }
- else {
- SWBuf subdir = (SWBuf)dir;
- removeTrailingSlash(subdir);
- subdir += (SWBuf)"/" + dirEntry.name;
- if (copyDirectory(urlPrefix, subdir, buffer.c_str(), suffix)) {
- SWLog::getSystemLog()->logWarning("FTPCopy: failed to get file %s\n", subdir.c_str());
- return -2;
- }
- }
- }
- SWCATCH (...) {}
- if (term) {
- retVal = -3;
- break;
- }
- }
- }
- return retVal;
-}
-
-
-SWORD_NAMESPACE_END
-
+ /*****************************************************************************
+ * FTPTransport functions
+ *
+ */
+
+
+#include <ftptrans.h>
+#include <filemgr.h>
+
+#include <fcntl.h>
+#include <dirent.h>
+#include <swlog.h>
+
+
+using std::vector;
+
+
+SWORD_NAMESPACE_START
+
+
+namespace {
+
+void removeTrailingSlash(SWBuf &buf) {
+ int len = buf.size();
+ if ((buf[len-1] == '/')
+ || (buf[len-1] == '\\'))
+ buf.size(len-1);
+}
+
+};
+
+
+void StatusReporter::preStatus(long totalBytes, long completedBytes, const char *message) {
+}
+
+void StatusReporter::statusUpdate(double dtTotal, double dlNow) {
+}
+
+
+FTPTransport::FTPTransport(const char *host, StatusReporter *statusReporter) {
+ this->statusReporter = statusReporter;
+ this->host = host;
+ term = false;
+}
+
+
+FTPTransport::~FTPTransport() {
+}
+
+
+// override this method in your real transport class
+char FTPTransport::getURL(const char *destPath, const char *sourceURL) {
+ char retVal = 0;
+ return retVal;
+}
+
+
+vector<struct ftpparse> FTPTransport::getDirList(const char *dirURL) {
+
+ vector<struct ftpparse> dirList;
+
+ if (!getURL("dirlist", dirURL)) {
+ FileDesc *fd = FileMgr::getSystemFileMgr()->open("dirlist", FileMgr::RDONLY);
+ long size = fd->seek(0, SEEK_END);
+ fd->seek(0, SEEK_SET);
+ char *buf = new char [ size + 1 ];
+ fd->read(buf, size);
+ FileMgr::getSystemFileMgr()->close(fd);
+ char *start = buf;
+ char *end = start;
+ while (start < (buf+size)) {
+ struct ftpparse item;
+ bool looking = true;
+ for (end = start; *end; end++) {
+ if (looking) {
+ if ((*end == 10) || (*end == 13)) {
+ *end = 0;
+ looking = false;
+ }
+ }
+ else if ((*end != 10) && (*end != 13))
+ break;
+ }
+ SWLog::getSystemLog()->logWarning("FTPURLGetDir: parsing item %s(%d)\n", start, end-start);
+ int status = ftpparse(&item, start, end - start);
+ SWLog::getSystemLog()->logWarning("FTPURLGetDir: got item %s\n", item.name);
+ if (status)
+ dirList.push_back(item);
+ start = end;
+ }
+ }
+ else
+ {
+ SWLog::getSystemLog()->logWarning("FTPURLGetDir: failed to get dir %s\n", dirURL);
+ }
+ return dirList;
+}
+
+
+int FTPTransport::copyDirectory(const char *urlPrefix, const char *dir, const char *dest, const char *suffix) {
+ unsigned int i;
+ int retVal = 0;
+
+ SWBuf url = SWBuf(urlPrefix) + SWBuf(dir);
+ removeTrailingSlash(url);
+ url += '/';
+
+ SWLog::getSystemLog()->logWarning("FTPCopy: getting dir %s\n", url.c_str());
+ vector<struct ftpparse> dirList = getDirList(url.c_str());
+
+ if (!dirList.size()) {
+ SWLog::getSystemLog()->logWarning("FTPCopy: failed to read dir %s\n", url.c_str());
+ return -1;
+ }
+
+ long totalBytes = 0;
+ for (i = 0; i < dirList.size(); i++)
+ totalBytes += dirList[i].size;
+ long completedBytes = 0;
+ for (i = 0; i < dirList.size(); i++) {
+ struct ftpparse &dirEntry = dirList[i];
+ SWBuf buffer = (SWBuf)dest;
+ removeTrailingSlash(buffer);
+ buffer += (SWBuf)"/" + (dirEntry.name);
+ if (!strcmp(&buffer.c_str()[buffer.length()-strlen(suffix)], suffix)) {
+ SWBuf buffer2 = "Downloading (";
+ buffer2.appendFormatted("%d", i+1);
+ buffer2 += " of ";
+ buffer2.appendFormatted("%d", dirList.size());
+ buffer2 += "): ";
+ buffer2 += (dirEntry.name);
+ if (statusReporter)
+ statusReporter->preStatus(totalBytes, completedBytes, buffer2.c_str());
+ FileMgr::createParent(buffer.c_str()); // make sure parent directory exists
+ SWTRY {
+ SWBuf url = (SWBuf)urlPrefix + (SWBuf)dir;
+ removeTrailingSlash(url);
+ url += (SWBuf)"/" + dirEntry.name; //dont forget the final slash
+ if (dirEntry.flagtrycwd != 1) {
+ if (getURL(buffer.c_str(), url.c_str())) {
+ SWLog::getSystemLog()->logWarning("FTPCopy: failed to get file %s\n", url.c_str());
+ return -2;
+ }
+ completedBytes += dirEntry.size;
+ }
+ else {
+ SWBuf subdir = (SWBuf)dir;
+ removeTrailingSlash(subdir);
+ subdir += (SWBuf)"/" + dirEntry.name;
+ if (copyDirectory(urlPrefix, subdir, buffer.c_str(), suffix)) {
+ SWLog::getSystemLog()->logWarning("FTPCopy: failed to get file %s\n", subdir.c_str());
+ return -2;
+ }
+ }
+ }
+ SWCATCH (...) {}
+ if (term) {
+ retVal = -3;
+ break;
+ }
+ }
+ }
+ return retVal;
+}
+
+
+SWORD_NAMESPACE_END
+
Modified: trunk/src/modules/filters/teiplain.cpp
===================================================================
--- trunk/src/modules/filters/teiplain.cpp 2007-09-14 01:34:37 UTC (rev 2077)
+++ trunk/src/modules/filters/teiplain.cpp 2007-09-14 03:31:44 UTC (rev 2078)
@@ -1,116 +1,116 @@
-/***************************************************************************
- teiplain.cpp - TEI to Plaintext filter
- -------------------
- begin : 2006-07-05
- copyright : 2006 by CrossWire Bible Society
- ***************************************************************************/
-
-/***************************************************************************
- * *
- * 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; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- ***************************************************************************/
-
-#include <stdlib.h>
-#include <teiplain.h>
-#include <ctype.h>
-
-SWORD_NAMESPACE_START
-
-TEIPlain::TEIPlain() {
- setTokenStart("<");
- setTokenEnd(">");
-
- setEscapeStart("&");
- setEscapeEnd(";");
-
- setEscapeStringCaseSensitive(true);
-
- addEscapeStringSubstitute("amp", "&");
- addEscapeStringSubstitute("apos", "'");
- addEscapeStringSubstitute("lt", "<");
- addEscapeStringSubstitute("gt", ">");
- addEscapeStringSubstitute("quot", "\"");
-
- setTokenCaseSensitive(true);
-}
-
-
-bool TEIPlain::handleToken(SWBuf &buf, const char *token, BasicFilterUserData *userData) {
- // manually process if it wasn't a simple substitution
- if (!substituteToken(buf, token)) {
- //MyUserData *u = (MyUserData *)userData;
- XMLTag tag(token);
-
- // <p> paragraph tag
- if (!strcmp(tag.getName(), "p")) {
- if ((!tag.isEndTag()) && (!tag.isEmpty())) { // non-empty start tag
- buf += "\n";
- }
- else if (tag.isEndTag()) { // end tag
- buf += "\n";
- userData->supressAdjacentWhitespace = true;
- }
- else { // empty paragraph break marker
- buf += "\n\n";
- userData->supressAdjacentWhitespace = true;
- }
- }
-
- // <entryFree>
- else if (!strcmp(tag.getName(), "entryFree")) {
- SWBuf n = tag.getAttribute("n");
- if ((!tag.isEndTag()) && (!tag.isEmpty())) {
- if (n != "") {
- buf += n;
- buf += ". ";
- }
- }
- }
-
- // <sense>
- else if (!strcmp(tag.getName(), "sense")) {
- SWBuf n = tag.getAttribute("n");
- if ((!tag.isEndTag()) && (!tag.isEmpty())) {
- if (n != "") {
- buf += n;
- buf += ". ";
- }
- }
- else if (tag.isEndTag()) {
- buf += "\n";
- }
- }
-
- // <div>
- else if (!strcmp(tag.getName(), "div")) {
-
- if ((!tag.isEndTag()) && (!tag.isEmpty())) {
- buf.append("\n\n\n");
- }
- else if (tag.isEndTag()) {
- }
- }
-
- // <etym>
- else if (!strcmp(tag.getName(), "etym")) {
- if ((!tag.isEndTag()) && (!tag.isEmpty())) {
- buf += "[";
- }
- else if (tag.isEndTag()) {
- buf += "]";
- }
- }
-
- else {
- return false; // we still didn't handle token
- }
- }
- return true;
-}
-
-
-SWORD_NAMESPACE_END
+/***************************************************************************
+ teiplain.cpp - TEI to Plaintext filter
+ -------------------
+ begin : 2006-07-05
+ copyright : 2006 by CrossWire Bible Society
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * 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; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include <stdlib.h>
+#include <teiplain.h>
+#include <ctype.h>
+
+SWORD_NAMESPACE_START
+
+TEIPlain::TEIPlain() {
+ setTokenStart("<");
+ setTokenEnd(">");
+
+ setEscapeStart("&");
+ setEscapeEnd(";");
+
+ setEscapeStringCaseSensitive(true);
+
+ addEscapeStringSubstitute("amp", "&");
+ addEscapeStringSubstitute("apos", "'");
+ addEscapeStringSubstitute("lt", "<");
+ addEscapeStringSubstitute("gt", ">");
+ addEscapeStringSubstitute("quot", "\"");
+
+ setTokenCaseSensitive(true);
+}
+
+
+bool TEIPlain::handleToken(SWBuf &buf, const char *token, BasicFilterUserData *userData) {
+ // manually process if it wasn't a simple substitution
+ if (!substituteToken(buf, token)) {
+ //MyUserData *u = (MyUserData *)userData;
+ XMLTag tag(token);
+
+ // <p> paragraph tag
+ if (!strcmp(tag.getName(), "p")) {
+ if ((!tag.isEndTag()) && (!tag.isEmpty())) { // non-empty start tag
+ buf += "\n";
+ }
+ else if (tag.isEndTag()) { // end tag
+ buf += "\n";
+ userData->supressAdjacentWhitespace = true;
+ }
+ else { // empty paragraph break marker
+ buf += "\n\n";
+ userData->supressAdjacentWhitespace = true;
+ }
+ }
+
+ // <entryFree>
+ else if (!strcmp(tag.getName(), "entryFree")) {
+ SWBuf n = tag.getAttribute("n");
+ if ((!tag.isEndTag()) && (!tag.isEmpty())) {
+ if (n != "") {
+ buf += n;
+ buf += ". ";
+ }
+ }
+ }
+
+ // <sense>
+ else if (!strcmp(tag.getName(), "sense")) {
+ SWBuf n = tag.getAttribute("n");
+ if ((!tag.isEndTag()) && (!tag.isEmpty())) {
+ if (n != "") {
+ buf += n;
+ buf += ". ";
+ }
+ }
+ else if (tag.isEndTag()) {
+ buf += "\n";
+ }
+ }
+
+ // <div>
+ else if (!strcmp(tag.getName(), "div")) {
+
+ if ((!tag.isEndTag()) && (!tag.isEmpty())) {
+ buf.append("\n\n\n");
+ }
+ else if (tag.isEndTag()) {
+ }
+ }
+
+ // <etym>
+ else if (!strcmp(tag.getName(), "etym")) {
+ if ((!tag.isEndTag()) && (!tag.isEmpty())) {
+ buf += "[";
+ }
+ else if (tag.isEndTag()) {
+ buf += "]";
+ }
+ }
+
+ else {
+ return false; // we still didn't handle token
+ }
+ }
+ return true;
+}
+
+
+SWORD_NAMESPACE_END
Modified: trunk/src/modules/filters/teirtf.cpp
===================================================================
--- trunk/src/modules/filters/teirtf.cpp 2007-09-14 01:34:37 UTC (rev 2077)
+++ trunk/src/modules/filters/teirtf.cpp 2007-09-14 03:31:44 UTC (rev 2078)
@@ -1,207 +1,207 @@
-/***************************************************************************
- teirtf.cpp - TEI to RTF filter
- -------------------
- begin : 2006-07-03
- copyright : 2006 by CrossWire Bible Society
- ***************************************************************************/
-
-/***************************************************************************
- * *
- * 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; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- ***************************************************************************/
-
-#include <stdlib.h>
-#include <ctype.h>
-#include <teirtf.h>
-#include <utilxml.h>
-#include <swmodule.h>
-
-SWORD_NAMESPACE_START
-
-
-TEIRTF::MyUserData::MyUserData(const SWModule *module, const SWKey *key) : BasicFilterUserData(module, key) {
- BiblicalText = false;
- if (module) {
- version = module->Name();
- BiblicalText = (!strcmp(module->Type(), "Biblical Texts"));
- }
-}
-
-
-TEIRTF::TEIRTF() {
- setTokenStart("<");
- setTokenEnd(">");
-
- setEscapeStart("&");
- setEscapeEnd(";");
-
- setEscapeStringCaseSensitive(true);
-
- addEscapeStringSubstitute("amp", "&");
- addEscapeStringSubstitute("apos", "'");
- addEscapeStringSubstitute("lt", "<");
- addEscapeStringSubstitute("gt", ">");
- addEscapeStringSubstitute("quot", "\"");
-
- setTokenCaseSensitive(true);
-}
-
-
-bool TEIRTF::handleToken(SWBuf &buf, const char *token, BasicFilterUserData *userData) {
- // manually process if it wasn't a simple substitution
- if (!substituteToken(buf, token)) {
- //MyUserData *u = (MyUserData *)userData;
- XMLTag tag(token);
-
- // <p> paragraph tag
- if (!strcmp(tag.getName(), "p")) {
- if ((!tag.isEndTag()) && (!tag.isEmpty())) { // non-empty start tag
- buf += "{\\par}";
- }
- else if (tag.isEndTag()) { // end tag
- buf += "{\\par}";
- userData->supressAdjacentWhitespace = true;
- }
- else { // empty paragraph break marker
- buf += "{\\par\\par}";
- userData->supressAdjacentWhitespace = true;
- }
- }
-
- // <hi>
- else if (!strcmp(tag.getName(), "hi")) {
- SWBuf rend = tag.getAttribute("rend");
- if ((!tag.isEndTag()) && (!tag.isEmpty())) {
- if (rend == "ital")
- buf += "{\\i1 ";
- else if (rend == "bold")
- buf += "{\\b1 ";
- else if (rend == "sup")
- buf += "{\\super ";
-
- }
- else if (tag.isEndTag()) {
- buf += "}";
- }
- }
-
- // <entryFree>
- else if (!strcmp(tag.getName(), "entryFree")) {
- SWBuf n = tag.getAttribute("n");
- if ((!tag.isEndTag()) && (!tag.isEmpty())) {
- if (n != "") {
- buf += "{\\b1 ";
- buf += n;
- buf += ". }"; }
- }
- }
-
- // <sense>
- else if (!strcmp(tag.getName(), "sense")) {
- SWBuf n = tag.getAttribute("n");
- if ((!tag.isEndTag()) && (!tag.isEmpty())) {
- if (n != "") {
- buf += "{\\par\\b1 ";
- buf += n;
- buf += ". }";
- }
- }
- else if (tag.isEndTag()) {
- buf += "\\par ";
- }
- }
-
- // <div>
- else if (!strcmp(tag.getName(), "div")) {
-
- if ((!tag.isEndTag()) && (!tag.isEmpty())) {
- buf.append("\\par\\par\\pard ");
- }
- else if (tag.isEndTag()) {
- }
- }
-
- // <pos>
- else if (!strcmp(tag.getName(), "pos")) {
- if ((!tag.isEndTag()) && (!tag.isEmpty())) {
- buf += "{\\i1 ";
- }
- else if (tag.isEndTag()) {
- buf += "}";
- }
- }
-
- // <gen>
- else if (!strcmp(tag.getName(), "gen")) {
- if ((!tag.isEndTag()) && (!tag.isEmpty())) {
- buf += "{\\i1 ";
- }
- else if (tag.isEndTag()) {
- buf += "}";
- }
- }
-
- // <case>
- else if (!strcmp(tag.getName(), "case")) {
- if ((!tag.isEndTag()) && (!tag.isEmpty())) {
- buf += "{\\i1 ";
- }
- else if (tag.isEndTag()) {
- buf += "}";
- }
- }
-
- // <tr>
- else if (!strcmp(tag.getName(), "tr")) {
- if ((!tag.isEndTag()) && (!tag.isEmpty())) {
- buf += "{\\i1 ";
- }
- else if (tag.isEndTag()) {
- buf += "}";
- }
- }
-
- // <number>
- else if (!strcmp(tag.getName(), "number")) {
- if ((!tag.isEndTag()) && (!tag.isEmpty())) {
- buf += "{\\i1 ";
- }
- else if (tag.isEndTag()) {
- buf += "}";
- }
- }
-
- // <mood>
- else if (!strcmp(tag.getName(), "mood")) {
- if ((!tag.isEndTag()) && (!tag.isEmpty())) {
- buf += "{\\i1 ";
- }
- else if (tag.isEndTag()) {
- buf += "}";
- }
- }
-
- // <etym>
- else if (!strcmp(tag.getName(), "etym")) {
- if ((!tag.isEndTag()) && (!tag.isEmpty())) {
- buf += "[";
- }
- else if (tag.isEndTag()) {
- buf += "]";
- }
- }
-
- else {
- return false; // we still didn't handle token
- }
- }
- return true;
-}
-
-
-SWORD_NAMESPACE_END
-
+/***************************************************************************
+ teirtf.cpp - TEI to RTF filter
+ -------------------
+ begin : 2006-07-03
+ copyright : 2006 by CrossWire Bible Society
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * 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; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include <stdlib.h>
+#include <ctype.h>
+#include <teirtf.h>
+#include <utilxml.h>
+#include <swmodule.h>
+
+SWORD_NAMESPACE_START
+
+
+TEIRTF::MyUserData::MyUserData(const SWModule *module, const SWKey *key) : BasicFilterUserData(module, key) {
+ BiblicalText = false;
+ if (module) {
+ version = module->Name();
+ BiblicalText = (!strcmp(module->Type(), "Biblical Texts"));
+ }
+}
+
+
+TEIRTF::TEIRTF() {
+ setTokenStart("<");
+ setTokenEnd(">");
+
+ setEscapeStart("&");
+ setEscapeEnd(";");
+
+ setEscapeStringCaseSensitive(true);
+
+ addEscapeStringSubstitute("amp", "&");
+ addEscapeStringSubstitute("apos", "'");
+ addEscapeStringSubstitute("lt", "<");
+ addEscapeStringSubstitute("gt", ">");
+ addEscapeStringSubstitute("quot", "\"");
+
+ setTokenCaseSensitive(true);
+}
+
+
+bool TEIRTF::handleToken(SWBuf &buf, const char *token, BasicFilterUserData *userData) {
+ // manually process if it wasn't a simple substitution
+ if (!substituteToken(buf, token)) {
+ //MyUserData *u = (MyUserData *)userData;
+ XMLTag tag(token);
+
+ // <p> paragraph tag
+ if (!strcmp(tag.getName(), "p")) {
+ if ((!tag.isEndTag()) && (!tag.isEmpty())) { // non-empty start tag
+ buf += "{\\par}";
+ }
+ else if (tag.isEndTag()) { // end tag
+ buf += "{\\par}";
+ userData->supressAdjacentWhitespace = true;
+ }
+ else { // empty paragraph break marker
+ buf += "{\\par\\par}";
+ userData->supressAdjacentWhitespace = true;
+ }
+ }
+
+ // <hi>
+ else if (!strcmp(tag.getName(), "hi")) {
+ SWBuf rend = tag.getAttribute("rend");
+ if ((!tag.isEndTag()) && (!tag.isEmpty())) {
+ if (rend == "ital")
+ buf += "{\\i1 ";
+ else if (rend == "bold")
+ buf += "{\\b1 ";
+ else if (rend == "sup")
+ buf += "{\\super ";
+
+ }
+ else if (tag.isEndTag()) {
+ buf += "}";
+ }
+ }
+
+ // <entryFree>
+ else if (!strcmp(tag.getName(), "entryFree")) {
+ SWBuf n = tag.getAttribute("n");
+ if ((!tag.isEndTag()) && (!tag.isEmpty())) {
+ if (n != "") {
+ buf += "{\\b1 ";
+ buf += n;
+ buf += ". }"; }
+ }
+ }
+
+ // <sense>
+ else if (!strcmp(tag.getName(), "sense")) {
+ SWBuf n = tag.getAttribute("n");
+ if ((!tag.isEndTag()) && (!tag.isEmpty())) {
+ if (n != "") {
+ buf += "{\\par\\b1 ";
+ buf += n;
+ buf += ". }";
+ }
+ }
+ else if (tag.isEndTag()) {
+ buf += "\\par ";
+ }
+ }
+
+ // <div>
+ else if (!strcmp(tag.getName(), "div")) {
+
+ if ((!tag.isEndTag()) && (!tag.isEmpty())) {
+ buf.append("\\par\\par\\pard ");
+ }
+ else if (tag.isEndTag()) {
+ }
+ }
+
+ // <pos>
+ else if (!strcmp(tag.getName(), "pos")) {
+ if ((!tag.isEndTag()) && (!tag.isEmpty())) {
+ buf += "{\\i1 ";
+ }
+ else if (tag.isEndTag()) {
+ buf += "}";
+ }
+ }
+
+ // <gen>
+ else if (!strcmp(tag.getName(), "gen")) {
+ if ((!tag.isEndTag()) && (!tag.isEmpty())) {
+ buf += "{\\i1 ";
+ }
+ else if (tag.isEndTag()) {
+ buf += "}";
+ }
+ }
+
+ // <case>
+ else if (!strcmp(tag.getName(), "case")) {
+ if ((!tag.isEndTag()) && (!tag.isEmpty())) {
+ buf += "{\\i1 ";
+ }
+ else if (tag.isEndTag()) {
+ buf += "}";
+ }
+ }
+
+ // <tr>
+ else if (!strcmp(tag.getName(), "tr")) {
+ if ((!tag.isEndTag()) && (!tag.isEmpty())) {
+ buf += "{\\i1 ";
+ }
+ else if (tag.isEndTag()) {
+ buf += "}";
+ }
+ }
+
+ // <number>
+ else if (!strcmp(tag.getName(), "number")) {
+ if ((!tag.isEndTag()) && (!tag.isEmpty())) {
+ buf += "{\\i1 ";
+ }
+ else if (tag.isEndTag()) {
+ buf += "}";
+ }
+ }
+
+ // <mood>
+ else if (!strcmp(tag.getName(), "mood")) {
+ if ((!tag.isEndTag()) && (!tag.isEmpty())) {
+ buf += "{\\i1 ";
+ }
+ else if (tag.isEndTag()) {
+ buf += "}";
+ }
+ }
+
+ // <etym>
+ else if (!strcmp(tag.getName(), "etym")) {
+ if ((!tag.isEndTag()) && (!tag.isEmpty())) {
+ buf += "[";
+ }
+ else if (tag.isEndTag()) {
+ buf += "]";
+ }
+ }
+
+ else {
+ return false; // we still didn't handle token
+ }
+ }
+ return true;
+}
+
+
+SWORD_NAMESPACE_END
+
More information about the sword-cvs
mailing list