From 3234f57d5a00565f4fc6cff248d3c9261b719f7e Mon Sep 17 00:00:00 2001 From: Chris Little Date: Sat, 14 Mar 2009 09:58:38 +0000 Subject: added abbrevs array builder git-svn-id: https://www.crosswire.org/svn/sword-tools/trunk@173 07627401-56e2-0310-80f4-f8cd0041bdcd --- versification/canon.bible.xml | 3 +++ versification/v11nsys.pl | 49 ++++++++++++++++++++++++++++++------------- 2 files changed, 37 insertions(+), 15 deletions(-) (limited to 'versification') diff --git a/versification/canon.bible.xml b/versification/canon.bible.xml index 5a621e5..d8b4df7 100644 --- a/versification/canon.bible.xml +++ b/versification/canon.bible.xml @@ -568,7 +568,10 @@ Psx 2Ps Additional Psalm + Ps 151 + Ps151 Psalm 151 + Psalm151 EsthGr diff --git a/versification/v11nsys.pl b/versification/v11nsys.pl index fe0223d..60d487c 100644 --- a/versification/v11nsys.pl +++ b/versification/v11nsys.pl @@ -5,17 +5,16 @@ # When run without any arguments, this script reads the CCEL files: # Bible.*.xml. # -# Otherwise, supply the script with a list (or wildcard) of VPL files and it +# Otherwise, supply the script with a list (or wildcard) files and it # will attempt to create a v11n system definition on that basis. # -# If the --nosis switch is added as the first argument, the script will -# interpret book abbreviations rather than simply assume that they are OSIS -# abbreviations. +# The --vpl switch instructs the script to interpret files as VPL files. +# The --imp switch instructs the script to interpret files as IMP files. # ############################################################################### -sub buildBooks { +sub buildBooksArrays { if ($lastBook ne "" && $osis{lc($lastBook)} eq "") { print "ERROR: Unknown book abbreviation: $lastBook in $v11n\n"; } @@ -58,6 +57,7 @@ foreach $mapfile (@canons) { if ($line =~ /(.+?)<\/id>/) { $id = $1; $osis{lc($id)} = $id; + $abbrevs{lc($id)} = "$id;" } elsif ($line =~ /(.+?)<\/abbr>/) { $name = $1; @@ -65,16 +65,17 @@ foreach $mapfile (@canons) { $osis{lc($name)} = $id; } else { - print "ERROR: Duplicate mapping from $id found in $mapfile ().\n"; +# print "ERROR: Duplicate mapping from $id found in $mapfile ().\n"; } } elsif ($line =~ /(.+?)<\/name>/) { $name = $1; if ($osis{lc($name)} eq "") { $osis{lc($name)} = $id; + $abbrevs{lc($id)} .= "$name;" } else { - print "ERROR: Duplicate mapping from $id found in $mapfile ().\n"; +# print "ERROR: Duplicate mapping from $id found in $mapfile ().\n"; } if ($idmap{$id} eq "") { @@ -88,19 +89,18 @@ foreach $mapfile (@canons) { } close (MAP); } -die(); if (@ARGV[0] ne "") { $n = 0; $mode = "xml"; while (@ARGV[$n] ne "") { - if ($n == 0 && @ARGV[0] eq "--vpl") { + if (@ARGV[$n] eq "--vpl") { $mode = "vpl"; } - elsif ($n == 0 && @ARGV[0] eq "--imp") { + elsif (@ARGV[$n] eq "--imp") { $mode = "imp"; } - elsif ($n == 0 && @ARGV[0] eq "--xml") { + elsif (@ARGV[$n] eq "--xml") { $mode = "xml"; } else { @@ -134,7 +134,7 @@ foreach $infile (@srcfiles) { open OUTF, ">$outfile"; print OUTF "/******************************************************************************\n * $outfile.h - Versification data for the $v11n system\n *\n * Copyright 1998-2005 CrossWire Bible Society (http://www.crosswire.org)\n * CrossWire Bible Society\n * P. O. Box 2528\n * Tempe, AZ 85280-2528\n *\n * This program is free software; you can redistribute it and/or modify it\n * under the terms of the GNU General Public License as published by the\n * Free Software Foundation version 2.\n *\n * This program is distributed in the hope that it will be useful, but\n * WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * General Public License for more details.\n *\n"; - print OUTF "\n#ifndef V11N" . uc($v11n) . "_H\n#define V11N" . uc($v11n) . "_H\n\nSWORD_NAMESPACE_START\n\n"; + print OUTF "\n#ifndef V11N" . uc($v11n) . "_H\n#define V11N" . uc($v11n) . "_H\n\nSWORD_NAMESPACE_START\n\n\n"; $thisBook = ""; $thisChap = ""; @@ -144,6 +144,10 @@ foreach $infile (@srcfiles) { $cCount = 0; $vCount = 0; + $abbrevs = "/******************************************************************************\n * Abbreviations - MUST be in alphabetical order & by PRIORITY\n * RULE: first match of entire key\n * (e.g. key: \"1CH\"; match: \"1CHRONICLES\")\n */\n\nconst struct abbrev builtin_abbrevs$v11n\[\] = {\n"; + $abbrevsCloser = "\t{\"\", \"\"}\n};\n\n\n"; + $abbrevsList = ""; + $vm = "/******************************************************************************\n * Maximum verses per chapter\n */\n\nint vm$v11n\[\] = {"; $otbooks = "/******************************************************************************\n * [on]tbooks$v11n - initialize static instance for all canonical text names\n * and chapmax\n */\nstruct sbook otbooks$v11n\[\] = {\n"; $ntbooks = "struct sbook ntbooks$v11n\[\] = {\n"; @@ -184,8 +188,10 @@ foreach $infile (@srcfiles) { if ($thisBook ne $lastBook) { $bCount++; $vm .= "\n\t// $idmap{$osis{lc($thisBook)}}\n\t"; + $abbrevsList .= $abbrevs{lc($thisBook)}; + if ($lastBook ne "") { - buildBooks{}; + buildBooksArrays{}; } $cCount = 1; $vCount = 1; @@ -200,15 +206,28 @@ foreach $infile (@srcfiles) { } } $vm .= "$vCount\n};\n"; - buildBooks(); + buildBooksArrays(); $otbooks .= $booksCloser; $ntbooks .= $booksCloser; + $abbrevsList = lc($abbrevsList); + @abbrevsQueue = (); + while ($abbrevsList =~ /^(.+?);/) { + push @abbrevsQueue, $1; + $abbrevsList =~ s/^(.+?);//; + } + @abbrevsQueue = sort @abbrevsQueue; + foreach $a (@abbrevsQueue) { + $abbrevs .= "\t{\"" . uc($a) . "\", \"" . $osis{lc($a)} . "\"},\t\t//" . $idmap{$osis{lc($a)}} . "\n"; + } + $abbrevs .= $abbrevsCloser; + print OUTF $otbooks; print OUTF $ntbooks; + print OUTF $abbrevs; print OUTF $vm; - print OUTF "\nSWORD_NAMESPACE_END\n\n#endif\n"; + print OUTF "\n\nSWORD_NAMESPACE_END\n\n\n#endif\n"; close (INF); close (OUTF); -- cgit