From c22a0e81ca1c65425ee45cdcc2eea68eea955590 Mon Sep 17 00:00:00 2001 From: Chris Little Date: Sun, 15 Mar 2009 02:23:28 +0000 Subject: generate a builtin_abbrevs from XML canon definitions git-svn-id: https://www.crosswire.org/svn/sword-tools/trunk@175 07627401-56e2-0310-80f4-f8cd0041bdcd --- versification/makeabbrevs.pl | 72 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 versification/makeabbrevs.pl (limited to 'versification/makeabbrevs.pl') diff --git a/versification/makeabbrevs.pl b/versification/makeabbrevs.pl new file mode 100644 index 0000000..7789ce7 --- /dev/null +++ b/versification/makeabbrevs.pl @@ -0,0 +1,72 @@ +#!/usr/bin/perl + +# @canons will contain this list of files, these are in a basic XML format. +# Each file lists osisIDs along with the English names associated with the +# osisID. These aren't exhaustive, and may or may not overlap (but hopefully +# don't). We are only using these to load mappings from osisIDs. +@canons = ( + "canon.bible.xml", # the Bible, broadly defined +# "canon.af.xml", # Apostolic Fathers +# "canon.otp.xml", # OT pseudepigrapha +# "canon.nta.xml", # NT apocrypha +# "canon.lds.xml", # Mormon books +# "canon.naghammadi.xml", # Nag Hammadi Library +# "canon.qumran.xml", # Qumran mss +# "canon.classical.xml", # intended for classical works, currently just Josephus +); + +@abbrevsQueue = (); + +foreach $mapfile (@canons) { + open MAP, "$mapfile"; + while () { + $line = $_; + + $line =~ s///g; + $line =~ s/\&/\&/g; + + if ($line =~ /(.+?)<\/id>/) { + $id = $1; + $osis{lc($id)} = $id; + push @abbrevsQueue, "$id" + } + elsif ($line =~ /(.+?)<\/name>/) { + $name = $1; + if ($osis{lc($name)} eq "") { + $osis{lc($name)} = $id; + push @abbrevsQueue, "$name" + } + else { + if ($warn) { + print "ERROR: Duplicate mapping from $id found in $mapfile.\n"; + } + } + + if ($idmap{$id} eq "") { + $idmap{$id} = $name; + } + else { + # Duplicates most likely indicate alternate names, so ignore them. + if ($warn) { + print "ERROR: Duplicate mapping from $id found in $mapfile.\n"; + } + } + } + } + close (MAP); +} + +$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\[\] = {\n"; + +@abbrevsQueue = sort @abbrevsQueue; +foreach $a (@abbrevsQueue) { + if ($a =~ /^.+\d/) { + $abbrevs .= "//"; + } + $abbrevs .= " {\"" . uc($a) . "\", \"" . $osis{lc($a)} . "\"},\t\t//" . $idmap{$osis{lc($a)}} . "\n"; +} +$abbrevs .= " {\"\", \"\"}\n};\n\n\n"; + +open OUTF, ">builtin_abbrevs.h"; +print OUTF $abbrevs; +close OUTF; -- cgit