OOO330
[LibreOffice.git] / solenv / bin / diffmv.pl
blob89e5e4fd9ffb89165ac704c70c83e4a10378ec03
2 eval 'exec perl -S $0 ${1+"$@"}'
3 if 0;
4 #*************************************************************************
6 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 # Copyright 2000, 2010 Oracle and/or its affiliates.
10 # OpenOffice.org - a multi-platform office productivity suite
12 # This file is part of OpenOffice.org.
14 # OpenOffice.org is free software: you can redistribute it and/or modify
15 # it under the terms of the GNU Lesser General Public License version 3
16 # only, as published by the Free Software Foundation.
18 # OpenOffice.org is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # GNU Lesser General Public License version 3 for more details
22 # (a copy is included in the LICENSE file that accompanied this code).
24 # You should have received a copy of the GNU Lesser General Public License
25 # version 3 along with OpenOffice.org. If not, see
26 # <http://www.openoffice.org/license.html>
27 # for a copy of the LGPLv3 License.
29 #*************************************************************************
32 my ( $srcfile, $destfile ) = @ARGV;
33 my ( @srclines, @destlines );
34 my $dest_existing = 0;
35 @destlines = ();
37 usage() if ( ! defined $srcfile || ! defined $destfile);
39 open(SRCFILE, "$srcfile") or die "ERROR: Can't open $srcfile\n";
40 @srclines = <SRCFILE>;
41 close SRCFILE;
43 if ( -f $destfile ) {
44 open(DESTFILE, "$destfile") or die "ERROR: Can't open $destfile\n";
45 @destlines = <DESTFILE>;
46 close DESTFILE;
47 $dest_existing = 1;
50 if ( ! check_if_lists_equal(\@srclines, \@destlines) ) {
51 print STDERR "Updating \"$destfile\".\n";
52 unlink "$destfile" or die "ERROR: Can't remove old $destfile\n" if ( $dest_existing );
53 rename "$srcfile", "$destfile" or die "ERROR: Can't rename $srcfile to $destfile\n";
54 } else {
55 print STDERR "\"$destfile\" unchanged.\n";
58 sub check_if_lists_equal
60 my ( $srclist_ref, $destlist_ref ) = @_;
61 my @srclist = @{ $srclist_ref };
62 my @destlist = @{ $destlist_ref };
63 return 0 if ( $#srclist != $#destlist );
64 for ( my $i = 0; $i < $#srclist; $i++ ) {
65 return 0 if ( $srclist[$i] ne $destlist[$i]);
67 return 1;
70 sub usage
72 print STDERR "Usage: diffmv sourcefile destfile\n";
73 print STDERR "Do move diffing file only\n";
74 exit 1;