2 eval 'exec perl -S $0 ${1+"$@"}'
4 #*************************************************************************
6 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 # Copyright 2008 by Sun Microsystems, Inc.
10 # OpenOffice.org - a multi-platform office productivity suite
12 # $RCSfile: diffmv.pl,v $
16 # This file is part of OpenOffice.org.
18 # OpenOffice.org is free software: you can redistribute it and/or modify
19 # it under the terms of the GNU Lesser General Public License version 3
20 # only, as published by the Free Software Foundation.
22 # OpenOffice.org is distributed in the hope that it will be useful,
23 # but WITHOUT ANY WARRANTY; without even the implied warranty of
24 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 # GNU Lesser General Public License version 3 for more details
26 # (a copy is included in the LICENSE file that accompanied this code).
28 # You should have received a copy of the GNU Lesser General Public License
29 # version 3 along with OpenOffice.org. If not, see
30 # <http://www.openoffice.org/license.html>
31 # for a copy of the LGPLv3 License.
33 #*************************************************************************
36 my ( $srcfile, $destfile ) = @ARGV;
37 my ( @srclines, @destlines );
38 my $dest_existing = 0;
41 usage
() if ( ! defined $srcfile || ! defined $destfile);
43 open(SRCFILE
, "$srcfile") or die "ERROR: Can't open $srcfile\n";
44 @srclines = <SRCFILE
>;
48 open(DESTFILE
, "$destfile") or die "ERROR: Can't open $destfile\n";
49 @destlines = <DESTFILE
>;
54 if ( ! check_if_lists_equal
(\
@srclines, \
@destlines) ) {
55 print STDERR
"Updating \"$destfile\".\n";
56 unlink "$destfile" or die "ERROR: Can't remove old $destfile\n" if ( $dest_existing );
57 rename "$srcfile", "$destfile" or die "ERROR: Can't rename $srcfile to $destfile\n";
59 print STDERR
"\"$destfile\" unchanged.\n";
62 sub check_if_lists_equal
64 my ( $srclist_ref, $destlist_ref ) = @_;
65 my @srclist = @
{ $srclist_ref };
66 my @destlist = @
{ $destlist_ref };
67 return 0 if ( $#srclist != $#destlist );
68 for ( my $i = 0; $i < $#srclist; $i++ ) {
69 return 0 if ( $srclist[$i] ne $destlist[$i]);
76 print STDERR
"Usage: diffmv sourcefile destfile\n";
77 print STDERR
"Do move diffing file only\n";