#! /usr/bin/perl -w use strict; =head1 Notices Originally developed for Perforce by VIZIM (www.vizim.com) Copyright (c) 2014 Perforce Software, Inc. and VIZIM Worldwide, Inc. All rights reserved. Please see LICENSE.txt in top-level folder of this distribution for license information =cut use v5.14.0; # Earliest version testing was performed against my $APPNAME = "profileCompare.pl"; my $APPWHAT = "Compare directory profiles; version 1.05"; my $APPNOTICES = "Copyright (c) 2014 Perforce Software, Inc. and VIZIM Worldwide, Inc. All rights reserved. See LICENSE.txt for license information."; =head1 Compare directory profiles Compare profiles generated by profile.pl =cut =head2 Tool output Output identifies differences in existence and content. Lines prefixed with <<< indicate that the entry is only found in the first profile. The full entry follows the prefix. Lines prefixed with >>> indicate that the entry is only found in the second profile. The full entry follows the prefix. Lines prefixed with <=> indicate that the name is found in both profiles. However, the values are different. The prefix is followed by the name, the value from the first profile, then the value from the second profile. As an option, directory existence can be ignored to avoid issues associated with empty directories. =cut if( defined $ARGV[0] && ($ARGV[0] =~ m!\-+V!) ) { print "$APPWHAT\n"; exit(0); } my $ifIgnoreDirectories = 0; if( defined $ARGV[0] && ($ARGV[0] =~ m!\-+d!i) ) { $ifIgnoreDirectories = 1; shift @ARGV; } if( (defined $ARGV[0] && ($ARGV[0] =~ m!\-+[h\?]!i)) || (scalar @ARGV != 2) ) { print "$APPWHAT $APPNOTICES Usage: $APPNAME -V $APPNAME [-h|-?] $APPNAME [-d] profile1 profile2\n"; exit(0); } die "$ARGV[0] does not exist" if ! -e $ARGV[0]; die "$ARGV[0] is not a file" if ! -f $ARGV[0]; die "$ARGV[1] does not exist" if ! -e $ARGV[1]; die "$ARGV[1] is not a file" if ! -f $ARGV[1]; my $hP1; open ($hP1, '<', $ARGV[0]) || die "Can't open $ARGV[0] $!"; my $hP2; open ($hP2, '<', $ARGV[1]) || die "Can't open $ARGV[1] $!"; print "$ARGV[0] <<< >>> $ARGV[1]\n"; my $doneP1 = 0; my $doneP2 = 0; my $p1 = ''; my $p2 = ''; while( ! $doneP1 && ! $doneP2 ) { $p1 = <$hP1> if $p1 eq ''; $doneP1 = 1 if ! defined $p1; $p2 = <$hP2> if $p2 eq ''; $doneP2 = 1 if ! defined $p2; last if !defined $p1 || ! defined $p2; my ($name1, $value1) = ($1, $2) if $p1 =~ m!^(.+) (\S+)$!; my ($name2, $value2) = ($1, $2) if $p2 =~ m!^(.+) (\S+)$!; if( $p1 eq $p2 ) { $p1 = ''; $p2 = ''; } elsif( $name1 eq $name2 && $value1 ne $value2) { $p1 = ''; $p2 = ''; print "<=> $name1 $value1 $value2\n"; } elsif( $name1 gt $name2 ) { print ">>> $p2" unless $value2 eq 'Directory' && $ifIgnoreDirectories; $p2 = ''; } elsif( $name2 gt $name1 ) { print "<<< $p1" unless $value1 eq 'Directory' && $ifIgnoreDirectories; $p1 = ''; } } while(defined $p1) { next if $p1 =~ m! Directory$! && $ifIgnoreDirectories; print "<<< $p1"; $p1 = <$hP1>; } while(defined $p2) { next if $p2 =~ m! Directory$! && $ifIgnoreDirectories; print ">>> $p2"; $p2 = <$hP2>; } close $hP1; close $hP2;