This file is indexed.

/usr/share/perl5/Gedcom/Comparison.pm is in libgedcom-perl 1.19-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# Copyright 2003-2013, Paul Johnson (paul@pjcj.net)

# This software is free.  It is licensed under the same terms as Perl itself.

# The latest version of this software should be available from my homepage:
# http://www.pjcj.net

# documentation at __END__

use strict;

require 5.005;

package Gedcom::Comparison;

use vars qw($VERSION $Indent);
$VERSION = "1.19";
$Indent  = 0;

BEGIN { eval "use Date::Manip" }             # We'll use this if it is available

use Gedcom::Item 1.19;

my %cache;

sub new
{
  my $class     = shift;
  my ($r1, $r2) = @_;
  $r1           = "" unless defined $r1;
  $r2           = "" unless defined $r2;

  my $key ="$r1--$r2";

  return $cache{$key} if exists $cache{$key};

  my $self =
  {
    record1 => $r1,
    record2 => $r2,
  };

  bless $self, $class;

  if (!%cache && !$INC{"Date/Manip.pm"})
  {
    warn "Date::Manip.pm may be required to accurately compare dates\n";
  }

  $cache{$key} = $self->_compare
}


sub _compare
{
  my $self = shift;

  $self->{$_} = [] for qw( identical conflict only1 only2 );

  my $r1 = $self->{record1};
  my $r2 = $self->{record2};

  my ($v1, $v2) = ($r1->{value}, $r2->{value});

  # The values match if neither record has a value, or if both do and
  # they are the same.

  if (0)
  {
      $self->{value_match} = !(defined $v1 ^ defined $v2);
      $self->{value_match} &&= $v1 eq $v2 if defined $v1;
  }
  else
  {
      if ($r1->tag eq "DATE")
      {
          my $err;
          my $d = DateCalc($v1, $v2, \$err, 1);
          print "**** [$v1] [$v2] $d\n";
          my @d = split ":", $d;
          $self->{value_match} = grep (!($_ + 0), @d) / @d;
      }
      else
      {
          $self->{value_match} = !(defined $v1 ^ defined $v2);
          $self->{value_match} &&= $v1 eq $v2 if defined $v1;
      }
  }

  my @r1 = $r1 && UNIVERSAL::isa($r1, "Gedcom::Item") ? $r1->items : ();
  my @r2 = $r2 && UNIVERSAL::isa($r2, "Gedcom::Item") ? $r2->items : ();

  TAG1:
  for my $i1 (@r1)
  {
    my $tag       = $i1->tag;
    my @match     = (-1, -1);
    for my $i2 (0 .. $#r2)
    {
      next unless $r2[$i2]->tag eq $tag;
      my $comp = Gedcom::Comparison->new($i1, $r2[$i2]);  # TODO memoise
      my $m    = $comp->match;
      @match   = ($i2, $m, $comp) if $m > $match[1];
    }

    if ($match[2])
    {
      push @{$self->{$match[2]->identical ? "identical" : "conflict"}},
           $match[2];
      splice @r2, $match[0], 1;
      next
    }

    push @{$self->{only1}}, $i1;
  }

  $self->{only2} = \@r2;

  $self
}


sub identical
{
  my $self = shift;
  $self->match == 100
}

sub match
{
  my $self = shift;
  $self->{match} =
    100 *
    ($self->{value_match} + @{$self->{identical}}) /
    (1                    + @{$self->{identical}}
                          + @{$self->{conflict}}
                          + @{$self->{only1}}
                          + @{$self->{only2}})
    unless exists $self->{match};
  $self->{match}
}

sub print
{
  my $self = shift;

  local $Indent = $Indent + 1;
  my $i = "  " x ($Indent - 1);

  print $self->identical ? $i : "${i}not ";
  print "identical\n";

  printf "${i}match:       %5.2f%%\n", $self->match;
  printf "${i}value match: %d\n",      $self->{value_match};
  printf "${i}identical:   %d\n",      scalar @{$self->{identical}};
  printf "${i}conflict:    %d\n",      scalar @{$self->{conflict}};
  printf "${i}only1:       %d\n",      scalar @{$self->{only1}};
  printf "${i}only2:       %d\n",      scalar @{$self->{only2}};

  print "${i}record 1:\n";
  $self->{record1}->print;
  print "${i}record 2:\n";
  $self->{record2}->print;

  print "${i}conflicts:\n";
  my $c;
  print($i, ++$c, ":\n"), $_->print for @{$self->{conflict}};
}

1;

__END__

=head1 NAME

Gedcom::Comparison - a module to compare Gedcom records

Version 1.19 - 18th August 2013

=head1 SYNOPSIS

  use Gedcom::Comparison;

=head1 DESCRIPTION

=head1 METHODS

=cut