-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchoose-verse.pl
executable file
·99 lines (69 loc) · 1.88 KB
/
choose-verse.pl
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
#!/usr/bin/env perl
use strict;
use Getopt::Long;
Getopt::Long::Configure("bundling");
my $verseNumbers;
my $countQ;
GetOptions (
"v|verses=s" => \$verseNumbers,
"c|count" => \$countQ,
);
my $file = $ARGV[0];
die "ERROR: no file!\n\tchose-verse.pl [filename] -v \"verse numbers (eg. 1 2 .. 99)\"\n" if !$file;
if ($countQ) {
$verseNumbers = "x";
}
die "ERROR: no verse numbers!\n\tchose-verse.pl [filename] -v \"verse numbers (eg. 1 2 .. 99)\"\n" if !$verseNumbers;
my @VNum = split(" ", $verseNumbers);
open(FILE, $file);
my @content = <FILE>;
close(FILE);
my @kernGrep = grep "\*\*kern", @content;
my @filemap = split("\t", $kernGrep[0]);
my $countVerses;
my $tempCountVerses;
for (my $i = 0; $i < @filemap; $i++) {
if ($filemap[$i] =~ /\*\*kern/) {
if ($tempCountVerses > $countVerses) {
$countVerses = $tempCountVerses;
}
$tempCountVerses = 0;
} elsif ($filemap[$i] =~ /\*\*text/) {
$tempCountVerses++;
if ($i == @filemap) {
if ($tempCountVerses > $countVerses) {
$countVerses = $tempCountVerses;
}
}
}
}
if ($countQ) {
print "Number of verses: $countVerses\n";
exit;
}
for (my $i = 0; $i < @VNum; $i++) {
die "ERROR: one or more given verse numbers exceed total number of verses\n" if ($VNum[$i] > $countVerses);
}
my @spines;
my $kernNumber;
for (my $i = 0; $i < @filemap; $i++) {
my $spinenumber = $i+1;
if ($filemap[$i] =~ /\*\*kern/) {
push(@spines, $spinenumber);
$kernNumber = $spinenumber;
} elsif ($filemap[$i] =~ /\*\*text/) {
my $currentVerseNo = $spinenumber - $kernNumber;
for (my $j = 0; $j < @VNum; $j++) {
if ($VNum[$j] eq $currentVerseNo) {
push(@spines, $spinenumber);
last;
}
}
} else {
push(@spines, $spinenumber);
}
}
my $spineList = join(",", @spines);
my $command = "extractx -s $spineList $file";
my $output = `$command`;
print $output;