summaryrefslogtreecommitdiff
path: root/Master/tlpkg/bin/cmp-textfiles
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2008-08-04 00:53:19 +0000
committerKarl Berry <karl@freefriends.org>2008-08-04 00:53:19 +0000
commitebf95d1a539a67d13d805b20a21b80fc311e8229 (patch)
tree1b4418ab527c3e09fb1776c80e67c3d98dbd8c6c /Master/tlpkg/bin/cmp-textfiles
parentfce534655df057bec4988cf7850018db3b8a5452 (diff)
do not consider text files with just CR (Mac) line endings different from files with LF or CRLF line endings
git-svn-id: svn://tug.org/texlive/trunk@10058 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/tlpkg/bin/cmp-textfiles')
-rwxr-xr-xMaster/tlpkg/bin/cmp-textfiles45
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;
+}