summaryrefslogtreecommitdiffstats
path: root/intf
diff options
context:
space:
mode:
authorTroy A. Griffitts <scribe@crosswire.org>2011-10-25 18:51:54 +0000
committerTroy A. Griffitts <scribe@crosswire.org>2011-10-25 18:51:54 +0000
commit35f68cd9bac0d172c7e8170a71714eb873dce6db (patch)
treee88210c26d452124b396b88b2140dab7a4abba6e /intf
parent74d70192c9a8b216c4d0f5c5854d2dab1d8bd12f (diff)
downloadsword-tools-35f68cd9bac0d172c7e8170a71714eb873dce6db.tar.gz
Added tools to process INTF base text
git-svn-id: https://www.crosswire.org/svn/sword-tools/trunk@338 07627401-56e2-0310-80f4-f8cd0041bdcd
Diffstat (limited to 'intf')
-rw-r--r--intf/Makefile10
-rw-r--r--intf/collate2imp.cpp80
-rwxr-xr-xintf/prepare.sh2
-rw-r--r--intf/replaces.sed3
4 files changed, 95 insertions, 0 deletions
diff --git a/intf/Makefile b/intf/Makefile
new file mode 100644
index 0000000..4552ec1
--- /dev/null
+++ b/intf/Makefile
@@ -0,0 +1,10 @@
+TARGETS= collate2imp
+all: $(TARGETS)
+
+clean:
+ rm $(TARGETS)
+
+.cpp:
+ g++ -O0 -g `pkg-config --cflags sword` $< -o $@ `pkg-config --libs sword`
+
+
diff --git a/intf/collate2imp.cpp b/intf/collate2imp.cpp
new file mode 100644
index 0000000..ee5a359
--- /dev/null
+++ b/intf/collate2imp.cpp
@@ -0,0 +1,80 @@
+#include <filemgr.h>
+#include <versekey.h>
+#include <stdio.h>
+#include <iostream>
+
+
+using namespace sword;
+using namespace std;
+
+void usage(const char *app, const char *error = 0) {
+
+ if (error) fprintf(stderr, "\n%s: %s\n", app, error);
+
+ fprintf(stderr, "Convert Collate Plain Text collation to imp format\n");
+ fprintf(stderr, "\nusage: %s <input_file>\n", app);
+ fprintf(stderr, "\n");
+ exit(-1);
+}
+
+int main(int argc, char **argv) {
+
+ if (argc < 2) usage(*argv);
+
+ SWBuf inFile = argv[1];
+ SWBuf lineBuffer;
+ SWBuf bookTag="<div type=\"book\" n=\"";
+ SWBuf chapTag="<div type=\"chapter\" n=\"";
+ SWBuf verseTag="<ab n=\"";
+
+ VerseKey vk("Mat.1.1");
+ vk.setAutoNormalize(false);
+
+ bool inVerse = false;
+
+ // Let's see if we can open our input file
+ FileDesc *fd = FileMgr::getSystemFileMgr()->open(inFile, FileMgr::RDONLY);
+ if (fd->getFd() < 0) {
+ fprintf(stderr, "error: %s: couldn't open input file: %s \n", argv[0], inFile.c_str());
+ exit(-2);
+ }
+ bool more = true;
+ do {
+ more = FileMgr::getLine(fd, lineBuffer)!=0;
+ if (inVerse) {
+ if (lineBuffer.indexOf("</ab>") > -1) {
+ lineBuffer.setSize(lineBuffer.indexOf("</ab>"));
+ inVerse = false;
+ }
+ cout << lineBuffer.trim() << endl;
+ }
+ if (lineBuffer.startsWith(bookTag)) {
+ lineBuffer << bookTag.length();
+ SWBuf book = lineBuffer.stripPrefix('"');
+ vk.setBook(atoi(book.c_str()));
+ }
+ else if (lineBuffer.startsWith(chapTag)) {
+ lineBuffer << chapTag.length();
+ SWBuf chapter = lineBuffer.stripPrefix('"');
+ vk.setChapter(atoi(chapter.c_str()));
+ }
+ else if (lineBuffer.startsWith(verseTag)) {
+ lineBuffer << verseTag.length();
+ SWBuf verse = lineBuffer.stripPrefix('"');
+ vk.setVerse(atoi(verse.c_str()));
+ lineBuffer.stripPrefix('>');
+ if (lineBuffer.indexOf("</ab>") > -1) {
+ lineBuffer.setSize(lineBuffer.indexOf("</ab>"));
+ inVerse = false;
+ }
+ else {
+ inVerse = true;
+ }
+ cout << "$$$" << vk.getOSISRef() << "\n";
+ cout << lineBuffer.trim() << endl;
+ }
+ } while (more);
+}
+
+
+
diff --git a/intf/prepare.sh b/intf/prepare.sh
new file mode 100755
index 0000000..c83a985
--- /dev/null
+++ b/intf/prepare.sh
@@ -0,0 +1,2 @@
+#!/bin/sh
+sed -f replaces.sed $1 | awk '{gsub(/\r/,"\n");print}'
diff --git a/intf/replaces.sed b/intf/replaces.sed
new file mode 100644
index 0000000..26b5f80
--- /dev/null
+++ b/intf/replaces.sed
@@ -0,0 +1,3 @@
+/<\/ab> /s//<\/ab> /g
+/\(.\)<ab /s//\1 <ab /g
+