be6b9826ac04db6fd2326f9afb1b08f5221e9cee
[p5sagit/p5-mst-13.2.git] / Porting / check83.pl
1 #!/usr/bin/perl
2
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.
5
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".
11
12 my %seen;
13
14 sub eight_dot_three {
15     next if $seen{$_[0]}++;
16     my ($dir, $base, $ext) = ($_[0] =~ m!^(?:(.+)/)?([^/.]+)(?:\.([^/.]+))?$!);
17     my $file = $base . ( defined $ext ? ".$ext" : "" );
18     $base = substr($base, 0, 8);
19     $ext  = substr($ext,  0, 3) if defined $ext;
20     if ($dir =~ /\./)  {
21         print "directory name contains '.': $dir\n";
22     }
23     if ($file =~ /[^A-Za-z0-9\._-]/) {
24         print "filename contains non-portable characters: $_[0]\n";
25     }
26     if (length $file > 30) {
27         print "filename longer than 30 characters: $_[0]\n"; # make up a limit
28     }
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
36 my %dir;
37
38 if (open(MANIFEST, "MANIFEST")) {
39     while (<MANIFEST>) {
40         chomp;
41         s/\s.+//;
42         unless (-f) {
43             print "missing: $_\n";
44             next;
45         }
46         if (tr/././ > 1) {
47             print "more than one dot: $_\n";
48             next;
49         }
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         }
55     }
56 } else {
57     die "$0: MANIFEST: $!\n";
58 }
59
60 for my $dir (sort keys %dir) {
61     for my $edt (keys %{$dir{$dir}}) {
62         my @files = @{$dir{$dir}->{$edt}};
63         if (@files > 1) {
64             print "directory $dir conflict $edt: @files\n";
65         }
66     }
67 }