merge the formfield patch from ooo-build
[ooovba.git] / solenv / bin / diffmv.pl
blobbe987d9ca35f8457bc95bf27e2b33bbef3782ee8
2 eval 'exec perl -S $0 ${1+"$@"}'
3 if 0;
4 #*************************************************************************
6 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7 #
8 # Copyright 2008 by Sun Microsystems, Inc.
10 # OpenOffice.org - a multi-platform office productivity suite
12 # $RCSfile: diffmv.pl,v $
14 # $Revision: 1.4 $
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;
39 @destlines = ();
41 usage() if ( ! defined $srcfile || ! defined $destfile);
43 open(SRCFILE, "$srcfile") or die "ERROR: Can't open $srcfile\n";
44 @srclines = <SRCFILE>;
45 close SRCFILE;
47 if ( -f $destfile ) {
48 open(DESTFILE, "$destfile") or die "ERROR: Can't open $destfile\n";
49 @destlines = <DESTFILE>;
50 close DESTFILE;
51 $dest_existing = 1;
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";
58 } else {
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]);
71 return 1;
74 sub usage
76 print STDERR "Usage: diffmv sourcefile destfile\n";
77 print STDERR "Do move diffing file only\n";
78 exit 1;