source: branches/2015/dev_r5021_UKMO1_CICE_coupling/NEMOGCM/EXTERNAL/fcm/bin/fcm_graphic_diff @ 5445

Last change on this file since 5445 was 5445, checked in by davestorkey, 5 years ago

Clear SVN keywords from 2015/dev_r5021_UKMO1_CICE_coupling branch.

File size: 2.5 KB
Line 
1#!/usr/bin/env perl
2#-------------------------------------------------------------------------------
3# (C) Crown copyright Met Office. All rights reserved.
4# For further details please refer to the file COPYRIGHT.txt
5# which you should have received as part of this distribution.
6#-------------------------------------------------------------------------------
7
8use strict;
9use warnings;
10
11use Getopt::Long qw{GetOptions};
12
13# ------------------------------------------------------------------------------
14
15my ($u, @label);
16GetOptions ('u' => \$u, 'L=s' => \@label);
17
18# Check existence of files
19for my $i (0 .. 1) {
20  die $ARGV[$i], ': not found, abort' unless $ARGV[$i] and -f $ARGV[$i];
21}
22
23my ($old, $new) = @ARGV;
24
25if ($old =~ m#.svn/empty-file$#) {
26  print 'Skipping new file', "\n\n";
27
28} elsif ($new =~ m#.svn/empty-file$#) {
29  print 'Skipping deleted file', "\n\n";
30
31} elsif (-z $old) {
32  print 'Skipping as old file is empty (or does not exist)', "\n\n";
33
34} elsif (-z $new) {
35  print 'Skipping as new file is empty (or deleted)', "\n\n";
36
37} elsif (-B $new) {
38  print 'Skipping binary file', "\n\n";
39
40} else {
41  # Print descriptions of files
42  if (@label >= 2) {
43    print '--- ', $label[0], "\n", '+++ ', $label[1], "\n\n";
44  }
45
46  # FCM_GRAPHIC_DIFF is the graphical diff tool command
47  my $cmd = (exists $ENV{FCM_GRAPHIC_DIFF} ? $ENV{FCM_GRAPHIC_DIFF} : 'xxdiff');
48
49  if ($cmd) {
50    my @options = ();
51
52    # Set options for labels if appropriate
53    if (@label >= 2) {
54      if ($cmd eq 'tkdiff') {
55        # Use tkdiff
56        @options = ('-L', $label[0], '-L', $label[1]);
57
58      } elsif ($cmd eq 'xxdiff') {
59        # Use xxdiff
60        @options = ('--title1', $label[0], '--title2', $label[1]);
61      }
62    }
63
64    # Execute the command
65    my @command = ($cmd, @options, $old, $new);
66    exec (@command) or die 'Cannot execute: ', join (' ', @command);
67  }
68
69  exit;
70}
71
72__END__
73
74=head1 NAME
75
76fcm_graphic_diff
77
78=head1 SYNOPSIS
79
80    fcm_graphic_diff [-u] [-L OLD_DESC] [-L NEW_DESC] OLD NEW
81
82=head1 DESCRIPTION
83
84Wrapper script which invokes a graphical diff tool. Its interface is
85compatible with the "svn diff" command and can be used in combination with
86its "--diff-cmd" option. The command prints the OLD_DESC and NEW_DESC if
87they are both set. The two arguments OLD and NEW must be set and are the
88files to compare. The graphical diff tool invoked depends on the value of
89the FCM_GRAPHIC_DIFF environment variable. The command exits if the
90environment variable is not set.
91
92=head1 COPYRIGHT
93
94(C) Crown copyright Met Office. All rights reserved.
95
96=cut
Note: See TracBrowser for help on using the repository browser.