summaryrefslogtreecommitdiffstats
path: root/versification/makeabbrevs.pl
blob: f04d276f9ccbf1e6714dd52bda8388403a361514 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/perl

# $finalBook = "Rev"; # quit reading canon files after we reach this book (an OSIS id)-- this is a temporary measure for 1.6.0, since we don't support any apocrypha yet anyway

# @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 = (); 

if ($finalBook eq "") {
    $finalBook = "\#PARSE ALL BOOKS\#";
}
 
foreach $mapfile (@canons) {
    open MAP, "$mapfile";
    while (<MAP>) {
	$line = $_;
	
	$line =~ s/<!\-\-.+?\-\->//g;
	$line =~ s/\&amp;/\&/g;

	if ($line =~ /<id>(.+?)<\/id>/) {
	    if ($id eq $finalBook) {
		last;
	    }
	    $id = $1;
	    $osis{lc($id)} = $id;
	    push @abbrevsQueue, uc($id);
	}
	elsif ($line =~ /<name>(.+?)<\/name>/) {
	    $name = $1;
	    if ($osis{lc($name)} eq "") {
		$osis{lc($name)} = $id;
		push @abbrevsQueue, uc($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 * canon_abbrevs.h - Canonical text information to be included by VerseKey.cpp\n *\n * Copyright 1998-2009 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 */\n\n#ifndef CANON_ABBREVS_H\n#define CANON_ABBREVS_H\n\nSWORD_NAMESPACE_START\n\n\n/******************************************************************************\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 .= "  {\"" . $a . "\", \"" . $osis{lc($a)} . "\"},\t\t// " . $idmap{$osis{lc($a)}} . "\n";
}
$abbrevs .= "  {\"\", \"\"}\n};\n\n\nSWORD_NAMESPACE_END\n\n\n#endif\n";

open OUTF, ">canon_abbrevs.h";
print OUTF $abbrevs;
close OUTF;