#! /usr/bin/perl -w # # This file is part of DisOrder # Copyright (C) 2020 Mark Wooding # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # use autodie; use strict; (our $PROG = $0) =~ s:^.*/::; sub usage (\*) { print {$_[0]} "usage: $PROG DELTA FIRST SECOND\n"; } sub fail ($;$) { print STDERR "$PROG: $_[0]\n"; exit($_[1] // 2); } if (@ARGV != 3) { usage *STDERR; exit 2; } my $delta = $ARGV[0]; open my $f, "<", $ARGV[1]; binmode $f; open my $g, "<", $ARGV[2]; binmode $g; my $off = 0; SAMPLE: for (;;) { my $n = read $f, my $a, 2; my $m = read $g, my $b, 2; if (!$n) { if ($m) { fail "$PROG: second file is longer (offset = $off)", 1; } last SAMPLE; } elsif (!$m) { fail "$PROG: first file is longer (offset = $off)", 1; } my ($x) = unpack "s>", $a; my ($y) = unpack "s>", $b; if (abs($x - $y) > $delta) { fail "$PROG: content differs (offset = $off: $x != $y)", 1; } $off += 2; }