summaryrefslogtreecommitdiffstats
path: root/versification/v11nexport.pl
blob: 5d79080bee360c9e3dc839f2d64fe55c478c54df (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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/usr/bin/perl

if (@ARGV[0] eq "") {
    print "This is an /extremely/ rudimentary utility for exporting a v11n definition (canon.h-type) file into a list of verses contained in that v11n.\nIt takes one mandatory argument: a canon.h-type file.\nIt can take two additional arugments.\nIf one of them is \"osis\" the output will be an OSIS file.\nThe other optional argument will be used as the name of the output file.";
    exit();
}

open (INF, @ARGV[0]);

$name = "v11n";
if (@ARGV[1] ne "") {
    $arg = @ARGV[1];
    if ($arg =~ /^osis$/i) {
	$osis = true;
    }
    else {
	$name = $arg;
    }
    if (@ARGV[2] ne "") {
	$arg = @ARGV[2];
	if ($arg =~ /osis/i && $osis == false) {
	    $osis = true;
	}
	else {
	    $name = $arg;
	}
    }
}

if ($osis) {
    open (OUTF, ">$name.osis.xml");
}
else {
    open (OUTF, ">$name.imp");
}

$mode = 0;

while (<INF>) {
    $line = $_;
    if ($line =~ /struct\s+sbook/) {
	$mode = 1;
    }
    elsif ($line =~ /int\s+vm/) {
	$mode = 2;
    }
    else {
	if ($mode == 1) {
	    if ($line =~ /{\".+?\", \".+?\", \"(.+?)\", (\d+)}/) {
		$book{$1} = $2;
		push @bookList, $1;
	    }
	}
	if ($mode == 2) {
	    if ($line =~ /^([\s\d,]+)$/) {
		$vssList .= "$1, ";
	    }
	}
    }
}

$vssList =~ s/\s*//g;
$vssList =~ s/,,/,/g;

if ($osis) {
    print OUTF "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<osis xmlns=\"http://www.bibletechnologies.net/2003/OSIS/namespace\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.bibletechnologies.net/2003/OSIS/namespace http://www.bibletechnologies.net/osisCore.2.1.1.xsd\">\n<osisText osisRefWork=\"Bible\" xml:lang=\"en\" osisIDWork=\"Bible.canondemo\">\n<header>\n<work osisWork=\"Bible.canondemo\"/>\n</header>\n";
}


while (@bookList != ()) {
    if ($osis && $thisBook ne "") {
	print OUTF "<\/chapter>\n";
	print OUTF "<\/div>\n";
    }
    
    $thisBook = shift @bookList;
    $cmax = $book{$thisBook};
    $thisChap = 0;

    if ($osis) {
	print OUTF "<div type=\"book\" osisID=\"$thisBook\">\n";
    }
    
    while ($thisChap < $cmax) {
	if ($osis && $thisChap != 0) {
	    print OUTF "<\/chapter>\n";
	}
	
	$thisChap++; 	

	if ($osis) {
	    print OUTF "<chapter osisID=\"$thisBook\.$thisChap\">\n";
	}

	$vssList =~ s/^(\d+),//;
	$vmax = $1;
	$thisVers = 0;
	    
	while ($thisVers < $vmax) {
	    $thisVers++;
	    
	    if ($osis) {
		print OUTF "<verse osisID=\"$thisBook\.$thisChap\.$thisVers\">\n$thisBook.$thisChap.$thisVers\n<\/verse>\n";
	    }
	    else {
		print OUTF "\$\$\$$thisBook $thisChap:$thisVers\n$thisBook.$thisChap.$thisVers\n";
	    }
	}
    }
}

if ($osis) {
    print OUTF "<\/chapter>\n";
    print OUTF "<\/div>\n";
    print OUTF "<\/osisText>\n";
    print OUTF "<\/osis>\n";
}