1: 2 eval 'exec perl -S $0 ${1+"$@"}' 3 if 0; 4#************************************************************************* 5# 6# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 7# 8# Copyright 2000, 2010 Oracle and/or its affiliates. 9# 10# OpenOffice.org - a multi-platform office productivity suite 11# 12# This file is part of OpenOffice.org. 13# 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. 17# 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). 23# 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. 28# 29#************************************************************************* 30 31 32my ( $srcfile, $destfile ) = @ARGV; 33my ( @srclines, @destlines ); 34my $dest_existing = 0; 35@destlines = (); 36 37usage() if ( ! defined $srcfile || ! defined $destfile); 38 39open(SRCFILE, "$srcfile") or die "ERROR: Can't open $srcfile\n"; 40@srclines = <SRCFILE>; 41close SRCFILE; 42 43if ( -f $destfile ) { 44 open(DESTFILE, "$destfile") or die "ERROR: Can't open $destfile\n"; 45 @destlines = <DESTFILE>; 46 close DESTFILE; 47 $dest_existing = 1; 48} 49 50if ( ! 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"; 56} 57 58sub check_if_lists_equal 59{ 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]); 66 } 67 return 1; 68} 69 70sub usage 71{ 72 print STDERR "Usage: diffmv sourcefile destfile\n"; 73 print STDERR "Do move diffing file only\n"; 74 exit 1; 75} 76 77