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