blob: 3e6957e3b2ab7d4de88feaeb0680054b2f34965c (
plain)
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
|
#!/usr/bin/env perl
use strict;
use warnings;
use 5.020;
use utf8;
use File::Slurp qw(read_file);
use JSON;
sub show_usage {
my ($exit_code) = @_;
say STDERR "Usage: sanity-check <zugbildung.json>";
exit $exit_code;
}
binmode( STDOUT, ':encoding(utf-8)' );
if ( @ARGV < 1 ) {
show_usage(1);
}
my ($file) = @ARGV;
my $file_content = read_file($file);
my $json = JSON->new->utf8->decode($file_content);
my $map = $json->{train};
for my $train_number ( sort { $a <=> $b } keys %{$map} ) {
for my $cycle_from ( @{ $map->{$train_number}{cycle}{from} // [] } ) {
if ( not exists $map->{$cycle_from} ) {
printf(
"%s %d references unknown train %d\n",
$map->{$train_number}{raw},
$train_number, $cycle_from
);
}
}
for my $cycle_to ( @{ $map->{$train_number}{cycle}{to} // [] } ) {
if ( not exists $map->{$cycle_to} ) {
printf(
"%s %d references unknown train %d\n",
$map->{$train_number}{raw},
$train_number, $cycle_to
);
}
}
}
|