12e5b6d6dSopenharmony_ci#!/usr/bin/perl
22e5b6d6dSopenharmony_ci
32e5b6d6dSopenharmony_ci#
42e5b6d6dSopenharmony_ci# Copyright (C) 2017 and later: Unicode, Inc. and others.
52e5b6d6dSopenharmony_ci# License & terms of use: http://www.unicode.org/copyright.html
62e5b6d6dSopenharmony_ci#
72e5b6d6dSopenharmony_ci
82e5b6d6dSopenharmony_ciuse strict;
92e5b6d6dSopenharmony_ci
102e5b6d6dSopenharmony_cimy $file;
112e5b6d6dSopenharmony_cimy $secondfile;
122e5b6d6dSopenharmony_cimy %secondfilelist;
132e5b6d6dSopenharmony_cimy @same;
142e5b6d6dSopenharmony_cimy %list;
152e5b6d6dSopenharmony_cimy $samefile;
162e5b6d6dSopenharmony_ci
172e5b6d6dSopenharmony_ciforeach $secondfile (@ARGV) {
182e5b6d6dSopenharmony_ci  $secondfilelist{$secondfile} = "";
192e5b6d6dSopenharmony_ci}
202e5b6d6dSopenharmony_ci
212e5b6d6dSopenharmony_ciforeach $file (sort keys(%secondfilelist)) {
222e5b6d6dSopenharmony_ci  if(exists $secondfilelist{$file}) {
232e5b6d6dSopenharmony_ci    delete $secondfilelist{$file};
242e5b6d6dSopenharmony_ci    foreach $secondfile (sort(keys %secondfilelist)) {
252e5b6d6dSopenharmony_ci      #print "diffing: $file and $secondfile\n";
262e5b6d6dSopenharmony_ci      if (!`diff $file $secondfile`) {
272e5b6d6dSopenharmony_ci        #print "$file and $secondfile are the same\n";
282e5b6d6dSopenharmony_ci        push @same, $secondfile;
292e5b6d6dSopenharmony_ci      }
302e5b6d6dSopenharmony_ci    }
312e5b6d6dSopenharmony_ci#    if ($#same > -1) {
322e5b6d6dSopenharmony_ci      print "Adding @same to $file\n";
332e5b6d6dSopenharmony_ci      $list{$file} =  [@same] ;
342e5b6d6dSopenharmony_ci      foreach $samefile (@same) {
352e5b6d6dSopenharmony_ci        delete $secondfilelist{$samefile};
362e5b6d6dSopenharmony_ci      }
372e5b6d6dSopenharmony_ci      delete @same[0..$#same];
382e5b6d6dSopenharmony_ci#    }
392e5b6d6dSopenharmony_ci  }
402e5b6d6dSopenharmony_ci}
412e5b6d6dSopenharmony_ci
422e5b6d6dSopenharmony_ci
432e5b6d6dSopenharmony_cimy $i = 0;
442e5b6d6dSopenharmony_cimy $j = 0;
452e5b6d6dSopenharmony_ci foreach $file (sort( keys %list)) {
462e5b6d6dSopenharmony_ci   #print "$file -> "; #@{list{$file}}\n";
472e5b6d6dSopenharmony_ci   print "<$file> <$j>\n";
482e5b6d6dSopenharmony_ci   foreach $i ( 0 .. $#{ $list{$file} } ) {
492e5b6d6dSopenharmony_ci     #print "$list{$file}[$i] ";
502e5b6d6dSopenharmony_ci     print "<$list{$file}[$i]> <$j>\n ";
512e5b6d6dSopenharmony_ci   }
522e5b6d6dSopenharmony_ci   $j++;
532e5b6d6dSopenharmony_ci }
542e5b6d6dSopenharmony_ci
55