-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_blazons
executable file
·128 lines (106 loc) · 2.58 KB
/
check_blazons
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
118
119
120
121
122
123
124
125
126
127
#!/usr/local/bin/perl
use warnings;
use strict;
use Getopt::Euclid;
use Fatal qw(open close);
use Carp;
use Morsulus::Ordinary::Classic;
main();
sub main
{
my $input_fh = get_input($ARGV{-i});
my $output_fh = get_output($ARGV{-o});
print STDERR "fetching blazons...";
my $ord = Morsulus::Ordinary::Classic->new(dbname => $ARGV{-db});
print STDERR "fetched\n";
while (<$input_fh>)
{
chomp;
my $entry = Morsulus::Ordinary::Legacy->from_string($_);
next unless $entry->has_blazon;
#print STDERR "$_ has a blazon\n";
my @registrations = $ord->get_blazon_registrations($entry->text);
if ($entry->is_historical)
{
#print STDERR "...and it's historical\n";
if (! @registrations)
{
carp "$_\nblazon not found in database\n";
}
elsif (!grep {defined $_->descs} @registrations) # none have descs
{
carp "$_\nblazon has no descs in database\n";
}
}
else
{
#print STDERR "...and it exists in the database\n";
for my $reg (@registrations)
{
next unless defined $reg->descs;
$entry->descs($reg->descs);
last;
}
}
#no warnings 'uninitialized';
$_ = $entry->to_string;
}
continue
{
print $output_fh $_, "\n";
}
# get blazons from db
# for each input with a blazon
# if release then warn if blazon not in db
# if registration then append descs if found
# write record regardless
print "done\n" if $ARGV{'--noisy'};
}
sub get_input
{
my $file = shift;
if ($file eq '-')
{
return \*STDIN;
}
else
{
open my $fh, '<', $file;
return $fh;
}
}
sub get_output
{
my $file = shift;
if ($file eq '-')
{
return \*STDOUT;
}
else
{
open my $fh, '>', $file;
return $fh;
}
}
__END__
=head1 OPTIONS
=over
=item -db <file>
Master database file. Defaults to /Users/herveus/aux/oandab.db
SQLite database compatible with Morsulus::Ordinary::Classic::Schema
=for Euclid:
file.default: '/Users/herveus/aux/oandadb.db'
file.type: readable
=item -i[n] [-] <file>
Specify input file. Defaults to STDIN.
=for Euclid:
file.type: readable
file.default: '-'
=item -o[ut] [-] <file>
Specify output file. Defaults to STDOUT.
=for Euclid:
file.type: writable
file.default: '-'
=item --noisy
Make "noise"; at least, say "done".
=back