| 1 | #! /usr/bin/perl -w |
| 2 | # |
| 3 | # This file is part of DisOrder |
| 4 | # Copyright (C) 2020 Mark Wooding |
| 5 | # |
| 6 | # This program is free software: you can redistribute it and/or modify |
| 7 | # it under the terms of the GNU General Public License as published by |
| 8 | # the Free Software Foundation, either version 3 of the License, or |
| 9 | # (at your option) any later version. |
| 10 | # |
| 11 | # This program is distributed in the hope that it will be useful, |
| 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | # GNU General Public License for more details. |
| 15 | # |
| 16 | # You should have received a copy of the GNU General Public License |
| 17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | # |
| 19 | |
| 20 | use autodie; |
| 21 | use strict; |
| 22 | |
| 23 | (our $PROG = $0) =~ s:^.*/::; |
| 24 | sub usage (\*) { print {$_[0]} "usage: $PROG DELTA FIRST SECOND\n"; } |
| 25 | sub fail ($;$) { print STDERR "$PROG: $_[0]\n"; exit($_[1] // 2); } |
| 26 | |
| 27 | if (@ARGV != 3) { usage *STDERR; exit 2; } |
| 28 | my $delta = $ARGV[0]; |
| 29 | open my $f, "<", $ARGV[1]; binmode $f; |
| 30 | open my $g, "<", $ARGV[2]; binmode $g; |
| 31 | my $off = 0; |
| 32 | SAMPLE: for (;;) { |
| 33 | my $n = read $f, my $a, 2; |
| 34 | my $m = read $g, my $b, 2; |
| 35 | if (!$n) { |
| 36 | if ($m) { fail "$PROG: second file is longer (offset = $off)", 1; } |
| 37 | last SAMPLE; |
| 38 | } elsif (!$m) { fail "$PROG: first file is longer (offset = $off)", 1; } |
| 39 | |
| 40 | my ($x) = unpack "s>", $a; |
| 41 | my ($y) = unpack "s>", $b; |
| 42 | if (abs($x - $y) > $delta) |
| 43 | { fail "$PROG: content differs (offset = $off: $x != $y)", 1; } |
| 44 | $off += 2; |
| 45 | } |