This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
PATCH: [perl #121292] wrong perlunicode BOM claims
[perl5.git] / Porting / check83.pl
CommitLineData
81d555a2
RGS
1#!/usr/bin/perl -w
2
3use strict;
8c284f99 4
4d8cc5f8
JH
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.
8c284f99 7
9c406a46
PN
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".
9a715e86 13
4a6f7383
CB
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
a9b610e9 18my %seen;
81d555a2 19my $maxl = 30; # make up a limit for a maximum filename length
9a715e86 20
9e371ce5 21sub eight_dot_three {
81d555a2 22 return () if $seen{$_[0]}++;
cf14ed9b 23 my ($dir, $base, $ext) = ($_[0] =~ m{^(?:(.+)/)?([^/.]*)(?:\.([^/.]+))?$});
a9b610e9 24 my $file = $base . ( defined $ext ? ".$ext" : "" );
9e371ce5
JH
25 $base = substr($base, 0, 8);
26 $ext = substr($ext, 0, 3) if defined $ext;
81d555a2 27 if (defined $dir && $dir =~ /\./) {
a9b610e9 28 print "directory name contains '.': $dir\n";
4d8cc5f8 29 }
cf14ed9b
GA
30 if ($base eq "") {
31 print "filename starts with dot: $_[0]\n";
32 }
4d8cc5f8 33 if ($file =~ /[^A-Za-z0-9\._-]/) {
a9b610e9 34 print "filename contains non-portable characters: $_[0]\n";
4d8cc5f8 35 }
81d555a2
RGS
36 if (length $file > $maxl) {
37 print "filename longer than $maxl characters: $file\n";
4d8cc5f8 38 }
9e371ce5
JH
39 if (defined $dir) {
40 return ($dir, defined $ext ? "$dir/$base.$ext" : "$dir/$base");
41 } else {
42 return ('.', defined $ext ? "$base.$ext" : $base);
43 }
44}
45
46my %dir;
47
1ae6ead9 48if (open(MANIFEST, '<', 'MANIFEST')) {
9e371ce5
JH
49 while (<MANIFEST>) {
50 chomp;
51 s/\s.+//;
52 unless (-f) {
a9b610e9 53 print "missing: $_\n";
9e371ce5
JH
54 next;
55 }
56 if (tr/././ > 1) {
a9b610e9 57 print "more than one dot: $_\n";
9e371ce5
JH
58 next;
59 }
4a6f7383
CB
60 if ((my $slashes = $_ =~ tr|\/|\/|) > 7) {
61 print "more than eight levels deep: $_\n";
62 next;
63 }
a9b610e9 64 while (m!/|\z!g) {
6348b76e 65 my ($dir, $edt) = eight_dot_three("$`");
81d555a2 66 next unless defined $dir;
a9b610e9
YST
67 ($dir, $edt) = map { lc } ($dir, $edt);
68 push @{$dir{$dir}->{$edt}}, $_;
69 }
9e371ce5
JH
70 }
71} else {
72 die "$0: MANIFEST: $!\n";
73}
74
75for my $dir (sort keys %dir) {
76 for my $edt (keys %{$dir{$dir}}) {
479ac4eb 77 my @files = @{$dir{$dir}{$edt}};
9e371ce5 78 if (@files > 1) {
479ac4eb 79 print "conflict on filename $edt:\n", map " $_\n", @files;
9e371ce5
JH
80 }
81 }
82}