X-Git-Url: https://git.distorted.org.uk/~mdw/disorder/blobdiff_plain/3b9aa3e57bc89946447e61db239fbd6965a0a137..63b86f2dd86f7c263c9e414314bf516895d61c6b:/scripts/compare-raw diff --git a/scripts/compare-raw b/scripts/compare-raw new file mode 100755 index 0000000..70c5280 --- /dev/null +++ b/scripts/compare-raw @@ -0,0 +1,45 @@ +#! /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; +}