Version 4.2.0.1, tag libreoffice-4.2.0.1
[LibreOffice.git] / solenv / bin / diffmv.pl
blob256368960d6fe835de597cb25f8583d2d6a177f9
2 eval 'exec perl -S $0 ${1+"$@"}'
3 if 0;
5 # This file is part of the LibreOffice project.
7 # This Source Code Form is subject to the terms of the Mozilla Public
8 # License, v. 2.0. If a copy of the MPL was not distributed with this
9 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
11 # This file incorporates work covered by the following license notice:
13 # Licensed to the Apache Software Foundation (ASF) under one or more
14 # contributor license agreements. See the NOTICE file distributed
15 # with this work for additional information regarding copyright
16 # ownership. The ASF licenses this file to you under the Apache
17 # License, Version 2.0 (the "License"); you may not use this file
18 # except in compliance with the License. You may obtain a copy of
19 # the License at http://www.apache.org/licenses/LICENSE-2.0 .
23 my ( $srcfile, $destfile ) = @ARGV;
24 my ( @srclines, @destlines );
25 my $dest_existing = 0;
26 @destlines = ();
28 usage() if ( ! defined $srcfile || ! defined $destfile);
30 open(SRCFILE, "$srcfile") or die "ERROR: Can't open $srcfile\n";
31 @srclines = <SRCFILE>;
32 close SRCFILE;
34 if ( -f $destfile ) {
35 open(DESTFILE, "$destfile") or die "ERROR: Can't open $destfile\n";
36 @destlines = <DESTFILE>;
37 close DESTFILE;
38 $dest_existing = 1;
41 if ( ! check_if_lists_equal(\@srclines, \@destlines) ) {
42 print STDERR "Updating \"$destfile\".\n";
43 unlink "$destfile" or die "ERROR: Can't remove old $destfile\n" if ( $dest_existing );
44 rename "$srcfile", "$destfile" or die "ERROR: Can't rename $srcfile to $destfile\n";
45 } else {
46 print STDERR "\"$destfile\" unchanged.\n";
49 sub check_if_lists_equal
51 my ( $srclist_ref, $destlist_ref ) = @_;
52 my @srclist = @{ $srclist_ref };
53 my @destlist = @{ $destlist_ref };
54 return 0 if ( $#srclist != $#destlist );
55 for ( my $i = 0; $i < $#srclist; $i++ ) {
56 return 0 if ( $srclist[$i] ne $destlist[$i]);
58 return 1;
61 sub usage
63 print STDERR "Usage: diffmv sourcefile destfile\n";
64 print STDERR "Do move diffing file only\n";
65 exit 1;