This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Re: check83.pl
[perl5.git] / Porting / check83.pl
CommitLineData
23b3bd7f 1#!/usr/bin/perl
8c284f99 2
4d8cc5f8
JH
3# Check whether there are naming conflicts when names are truncated to
4# the DOSish case-ignoring 8.3 format, plus other portability no-nos.
8c284f99 5
9c406a46
PN
6# The "8.3 rule" is loose: "if reducing the directory entry names
7# within one directory to lowercase and 8.3-truncated causes
8# conflicts, that's a bad thing". So the rule is NOT the strict
9# "no filename shall be longer than eight and a suffix if present
10# not longer than three".
9a715e86 11
a9b610e9 12my %seen;
9a715e86 13
9e371ce5 14sub eight_dot_three {
a9b610e9 15 next if $seen{$_[0]}++;
9e371ce5 16 my ($dir, $base, $ext) = ($_[0] =~ m!^(?:(.+)/)?([^/.]+)(?:\.([^/.]+))?$!);
a9b610e9 17 my $file = $base . ( defined $ext ? ".$ext" : "" );
9e371ce5
JH
18 $base = substr($base, 0, 8);
19 $ext = substr($ext, 0, 3) if defined $ext;
4d8cc5f8 20 if ($dir =~ /\./) {
a9b610e9 21 print "directory name contains '.': $dir\n";
4d8cc5f8
JH
22 }
23 if ($file =~ /[^A-Za-z0-9\._-]/) {
a9b610e9 24 print "filename contains non-portable characters: $_[0]\n";
4d8cc5f8
JH
25 }
26 if (length $file > 30) {
a9b610e9 27 print "filename longer than 30 characters: $_[0]\n"; # make up a limit
4d8cc5f8 28 }
9e371ce5
JH
29 if (defined $dir) {
30 return ($dir, defined $ext ? "$dir/$base.$ext" : "$dir/$base");
31 } else {
32 return ('.', defined $ext ? "$base.$ext" : $base);
33 }
34}
35
36my %dir;
37
38if (open(MANIFEST, "MANIFEST")) {
39 while (<MANIFEST>) {
40 chomp;
41 s/\s.+//;
42 unless (-f) {
a9b610e9 43 print "missing: $_\n";
9e371ce5
JH
44 next;
45 }
46 if (tr/././ > 1) {
a9b610e9 47 print "more than one dot: $_\n";
9e371ce5
JH
48 next;
49 }
a9b610e9
YST
50 while (m!/|\z!g) {
51 my ($dir, $edt) = eight_dot_three($`);
52 ($dir, $edt) = map { lc } ($dir, $edt);
53 push @{$dir{$dir}->{$edt}}, $_;
54 }
9e371ce5
JH
55 }
56} else {
57 die "$0: MANIFEST: $!\n";
58}
59
60for my $dir (sort keys %dir) {
61 for my $edt (keys %{$dir{$dir}}) {
62 my @files = @{$dir{$dir}->{$edt}};
63 if (@files > 1) {
a9b610e9 64 print "directory $dir conflict $edt: @files\n";
9e371ce5
JH
65 }
66 }
67}