diff options
Diffstat (limited to 'Master/tlpkg/bin/cmp-textfiles')
-rwxr-xr-x | Master/tlpkg/bin/cmp-textfiles | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/Master/tlpkg/bin/cmp-textfiles b/Master/tlpkg/bin/cmp-textfiles new file mode 100755 index 00000000000..439fa1c0f28 --- /dev/null +++ b/Master/tlpkg/bin/cmp-textfiles @@ -0,0 +1,45 @@ +#!/usr/bin/env perl +# $Id$ +# Public domain. Originally written 2008, Karl Berry. +# Compare two files considering CR, LF, and CRLF as equivalent. +# Used in place and tlpkg-ctan-check in TeX Live. + +exit (&main ()); + +sub main +{ + if (@ARGV != 2) { + warn <<END_USAGE; +Usage: $0 FILE1 FILE2. +Compare as text files, ignoring line endings. +Exit status is zero if the same, 1 if different, something else if trouble. +END_USAGE + exit $ARGV[0] eq "--help" ? 0 : 2; + } + + my $file1 = &read_file ($ARGV[0]); + my $file2 = &read_file ($ARGV[1]); + + return $file1 eq $file2 ? 0 : 1; +} + + +# Return contents of FNAME as a string, converting all of CR, LF, and +# CRLF to just LF. +# +sub read_file +{ + my ($fname) = @_; + my $ret = ""; + + local *FILE; + open (FILE, $fname) || die "open($fname) failed: $!"; + while (<FILE>) { + s/\r\n?/\n/g; + #warn "line is |$_|"; + $ret .= $_; + } + close (FILE) || warn "close($fname) failed: $!"; + + return $ret; +} |