summaryrefslogtreecommitdiff
path: root/Master/tlpkg/bin/cmp-textfiles
blob: 439fa1c0f28f6d47c19ea5df3890c665fd266c28 (plain)
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
#!/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;
}