[sword-svn] r256 - trunk/modules/perlconverters

chrislit at crosswire.org chrislit at crosswire.org
Sat Dec 19 16:39:08 MST 2009


Author: chrislit
Date: 2009-12-19 16:39:08 -0700 (Sat, 19 Dec 2009)
New Revision: 256

Modified:
   trunk/modules/perlconverters/usfm2osis.pl
Log:
added option to create commentaries (patch from refdoc)


Modified: trunk/modules/perlconverters/usfm2osis.pl
===================================================================
--- trunk/modules/perlconverters/usfm2osis.pl	2009-12-19 23:33:48 UTC (rev 255)
+++ trunk/modules/perlconverters/usfm2osis.pl	2009-12-19 23:39:08 UTC (rev 256)
@@ -42,7 +42,7 @@
 use utf8;
 
 # Stores the script version and date
-$version = "1.7.1";
+$version = "1.7.2";
 
 $date = '$Date$';
 $rev = '$Rev$';
@@ -85,6 +85,9 @@
  "BLT" => "Bel", "ADE" => "AddEsth"
  );
 
+$divOpen=false;
+
+
 # Generates a list of available encodings.
 use Encode;
 @encodingList = Encode->encodings(":all");
@@ -126,6 +129,14 @@
 else {
     $inputEncoding = "utf8";
 }
+
+if (@ARGV[$nextarg] eq "-t") {
+    $moduleType = "@ARGV[$nextarg+1]";
+    $nextarg += 2;
+}
+else {
+    $moduleType = "bible";
+}
 $encFound = 0;
 foreach $enc (@encodingList) {
     if ($enc eq $inputEncoding) {
@@ -454,7 +465,9 @@
 
 	    push (@outdata, $versClose);
 	    $versClose = "";
-	    push (@outdata, closeTag("<\/p>"));
+	    if ($moduleType eq "bible") {
+	        push (@outdata, closeTag("<\/p>"))
+	        }
 	    if ($chapClose =~ /<chapter/) {
 		push (@outdata, $chapClose); # close previous chapter
 		$chapClose = "";
@@ -482,6 +495,7 @@
 	    }
 
 	    push (@outdata, $versClose);
+	    $divOpen=false;
 	    $versClose = "";
 
 	    if ($vers =~ /(\d+[^\\\- ]*)\-(\d+[^\\ ]*)/) {
@@ -502,9 +516,21 @@
 	    else {
 		$osisID = "$book.$chap.$vers";
 	    }
-	    push (@outdata, "<verse sID=\"$osisID\" osisID=\"$osisID\"\/>\n");
-	    $versClose = "<verse eID=\"$osisID\"\/>\n";
-	    $line =~ s/\\v\b\s*(\d[^\\ ]*)? *//;
+	    if ($moduleType eq "bible") {
+        	    push (@outdata, "<verse sID=\"$osisID\" osisID=\"$osisID\"\/>\n");
+	            $versClose = "<verse eID=\"$osisID\"\/>\n";
+	            $line =~ s/\\v\b\s*(\d[^\\ ]*)? *//;
+	            }
+            elsif ($moduleType eq "comment") {
+                    closeTag("<\/p>");
+                    push (@outdata, "<div type=\"section\" annotateType=\"commentary\" annotateRef=\"$osisID\">\n");
+	            $versClose = "<\/p>\n<\/div>\n";
+	            $line =~ s/\\v\b\s*(\d[^\\ ]*)? *//;
+	            $divOpen=true;
+	            }
+            else { print "usfm2osis.pl supports only the module types \"bible\" and \"comment\" \n";
+                    exit 1;
+            }
 	}
 
         # \vp...\vp# published verse numbers (just delete for now)
@@ -519,7 +545,9 @@
 
 	# \p paragraph (From Chapters and Verses)
 	if ($line =~ /^\\p\b\s*/) {
-	    push (@outdata, closeTag("<\/p>"));
+	    if ((($moduleType eq "comment") && ($divOpen))||($moduleType eq "bible")){
+	        push (@outdata, closeTag("<\/p>"));
+	        }
 	    push (@outdata, "<p>\n");
 	    openTag("<\/p>");
 	    $line =~ s/\\p\b\s*//;
@@ -527,7 +555,9 @@
 
 	# \pc paragraph centered (From Chapters and Verses)
 	if ($line =~ /^\\pc\b\s*/) {
-	    push (@outdata, closeTag("<\/p>"));
+	    if ((($moduleType eq "comment") && ($divOpen))||($moduleType eq "bible")){
+	        push (@outdata, closeTag("<\/p>"));
+	        }
 	    push (@outdata, "<p type=\"x-center\">\n");
 	    openTag("<\/p>");
 	    $line =~ s/\\pc\b\s*//;
@@ -535,7 +565,9 @@
 
 	# \mi2 paragraph flush left, no indentation
 	if ($line =~ /^\\mi2\b\s*/) {
-	    push (@outdata, closeTag("<\/p>"));
+	    if ((($moduleType eq "comment") && ($divOpen))||($moduleType eq "bible")){
+	        push (@outdata, closeTag("<\/p>"));
+	        }
 	    push (@outdata, "<p type=\"x-noindent\">\n");
 	    openTag("<\/p>");
 	    $line =~ s/\\mi2\b\s*//;




More information about the sword-cvs mailing list