[sword-svn] r338 - in trunk: . intf

scribe at crosswire.org scribe at crosswire.org
Tue Oct 25 11:51:54 MST 2011


Author: scribe
Date: 2011-10-25 11:51:54 -0700 (Tue, 25 Oct 2011)
New Revision: 338

Added:
   trunk/intf/
   trunk/intf/Makefile
   trunk/intf/collate2imp.cpp
   trunk/intf/prepare.sh
   trunk/intf/replaces.sed
Log:
Added tools to process INTF base text


Added: trunk/intf/Makefile
===================================================================
--- trunk/intf/Makefile	                        (rev 0)
+++ trunk/intf/Makefile	2011-10-25 18:51:54 UTC (rev 338)
@@ -0,0 +1,10 @@
+TARGETS= collate2imp
+all: $(TARGETS)
+
+clean:
+	rm $(TARGETS)
+
+.cpp:
+	g++ -O0 -g `pkg-config --cflags sword` $< -o $@ `pkg-config --libs sword`
+
+

Added: trunk/intf/collate2imp.cpp
===================================================================
--- trunk/intf/collate2imp.cpp	                        (rev 0)
+++ trunk/intf/collate2imp.cpp	2011-10-25 18:51:54 UTC (rev 338)
@@ -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);
+}
+
+
+

Added: trunk/intf/prepare.sh
===================================================================
--- trunk/intf/prepare.sh	                        (rev 0)
+++ trunk/intf/prepare.sh	2011-10-25 18:51:54 UTC (rev 338)
@@ -0,0 +1,2 @@
+#!/bin/sh
+sed -f replaces.sed $1 | awk '{gsub(/\r/,"\n");print}'


Property changes on: trunk/intf/prepare.sh
___________________________________________________________________
Added: svn:executable
   + *

Added: trunk/intf/replaces.sed
===================================================================
--- trunk/intf/replaces.sed	                        (rev 0)
+++ trunk/intf/replaces.sed	2011-10-25 18:51:54 UTC (rev 338)
@@ -0,0 +1,5 @@
+/<\/ab> /s//<\/ab>
+/g
+/\(.\)<ab /s//\1
+<ab /g
+




More information about the sword-cvs mailing list