This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Gisle points out that it's ok to ignore the return value of newSVrv.
[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
a9b610e9 14my %seen;
81d555a2 15my $maxl = 30; # make up a limit for a maximum filename length
9a715e86 16
9e371ce5 17sub eight_dot_three {
81d555a2
RGS
18 return () if $seen{$_[0]}++;
19 my ($dir, $base, $ext) = ($_[0] =~ m{^(?:(.+)/)?([^/.]+)(?:\.([^/.]+))?$});
a9b610e9 20 my $file = $base . ( defined $ext ? ".$ext" : "" );
9e371ce5
JH
21 $base = substr($base, 0, 8);
22 $ext = substr($ext, 0, 3) if defined $ext;
81d555a2 23 if (defined $dir && $dir =~ /\./) {
a9b610e9 24 print "directory name contains '.': $dir\n";
4d8cc5f8
JH
25 }
26 if ($file =~ /[^A-Za-z0-9\._-]/) {
a9b610e9 27 print "filename contains non-portable characters: $_[0]\n";
4d8cc5f8 28 }
81d555a2
RGS
29 if (length $file > $maxl) {
30 print "filename longer than $maxl characters: $file\n";
4d8cc5f8 31 }
9e371ce5
JH
32 if (defined $dir) {
33 return ($dir, defined $ext ? "$dir/$base.$ext" : "$dir/$base");
34 } else {
35 return ('.', defined $ext ? "$base.$ext" : $base);
36 }
37}
38
39my %dir;
40
41if (open(MANIFEST, "MANIFEST")) {
42 while (<MANIFEST>) {
43 chomp;
44 s/\s.+//;
45 unless (-f) {
a9b610e9 46 print "missing: $_\n";
9e371ce5
JH
47 next;
48 }
49 if (tr/././ > 1) {
a9b610e9 50 print "more than one dot: $_\n";
9e371ce5
JH
51 next;
52 }
a9b610e9
YST
53 while (m!/|\z!g) {
54 my ($dir, $edt) = eight_dot_three($`);
81d555a2 55 next unless defined $dir;
a9b610e9
YST
56 ($dir, $edt) = map { lc } ($dir, $edt);
57 push @{$dir{$dir}->{$edt}}, $_;
58 }
9e371ce5
JH
59 }
60} else {
61 die "$0: MANIFEST: $!\n";
62}
63
64for my $dir (sort keys %dir) {
65 for my $edt (keys %{$dir{$dir}}) {
66 my @files = @{$dir{$dir}->{$edt}};
67 if (@files > 1) {
a9b610e9 68 print "directory $dir conflict $edt: @files\n";
9e371ce5
JH
69 }
70 }
71}