imgtools/romtools/rombuild/fcw.pl
changeset 0 044383f39525
equal deleted inserted replaced
-1:000000000000 0:044383f39525
       
     1 #
       
     2 # Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 # All rights reserved.
       
     4 # This component and the accompanying materials are made available
       
     5 # under the terms of the License "Eclipse Public License v1.0"
       
     6 # which accompanies this distribution, and is available
       
     7 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 #
       
     9 # Initial Contributors:
       
    10 # Nokia Corporation - initial contribution.
       
    11 #
       
    12 # Contributors:
       
    13 #
       
    14 # Description: 
       
    15 # fcw.pl - compare two files as 32-bit words
       
    16 #
       
    17 
       
    18 use strict;
       
    19 
       
    20 if (@ARGV!=2)
       
    21 	{
       
    22 #........1.........2.........3.........4.........5.........6.........7.....
       
    23 	print <<USAGE_EOF;
       
    24 
       
    25 Usage:
       
    26   fcw file1 file2     -- compare two files
       
    27 
       
    28 USAGE_EOF
       
    29 	exit 1;
       
    30 	}
       
    31 
       
    32 my $left=@ARGV[0];
       
    33 my $right=@ARGV[1];
       
    34 
       
    35 open LEFT, $left or problem("Cannot open $left") and return;
       
    36 open RIGHT, $right or problem("Cannot open $right") and return;
       
    37 
       
    38 binmode LEFT;
       
    39 binmode RIGHT;
       
    40 
       
    41 if (compare_streams())
       
    42 	{
       
    43 	print "Files are identical\n";
       
    44 	}
       
    45 
       
    46 sub compare_streams
       
    47 	{
       
    48 	my $same = 1;
       
    49 	my $offset = 0;
       
    50 	my $leftbuf;
       
    51 	my $rightbuf;
       
    52 
       
    53 	BINARY_COMPARISON: while (1)
       
    54 		{
       
    55 		my $leftlen = read LEFT,  $leftbuf,  4096;
       
    56 		my $rightlen= read RIGHT, $rightbuf, 4096;
       
    57 		if ($rightlen == 0 && $leftlen == 0)
       
    58 			{
       
    59 			return $same;
       
    60 			}
       
    61 		if ($leftbuf eq $rightbuf)
       
    62 			{
       
    63 			$offset += $leftlen;
       
    64 			}
       
    65 		else
       
    66 			{
       
    67 			my @leftwords = unpack "V*", $leftbuf;
       
    68 			my @rightwords = unpack "V*", $rightbuf;
       
    69 			foreach $_ (@leftwords)
       
    70 				{
       
    71 				if ($_ != @rightwords[0])
       
    72 					{
       
    73 					printf "%06x: %08x != %08x\n", $offset, $_, @rightwords[0];
       
    74 					}
       
    75 				shift @rightwords;
       
    76 				$offset+=4;
       
    77 				}
       
    78 			$same=0;
       
    79 			}
       
    80 		}
       
    81 	}
       
    82 
       
    83 
       
    84