1#!/usr/bin/perl -w
2
3use 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
14my %seen;
15my $maxl = 30; # make up a limit for a maximum filename length
16
17sub eight_dot_three {
18    return () if $seen{$_[0]}++;
19    my ($dir, $base, $ext) = ($_[0] =~ m{^(?:(.+)/)?([^/.]+)(?:\.([^/.]+))?$});
20    my $file = $base . ( defined $ext ? ".$ext" : "" );
21    $base = substr($base, 0, 8);
22    $ext  = substr($ext,  0, 3) if defined $ext;
23    if (defined $dir && $dir =~ /\./)  {
24	print "directory name contains '.': $dir\n";
25    }
26    if ($file =~ /[^A-Za-z0-9\._-]/) {
27	print "filename contains non-portable characters: $_[0]\n";
28    }
29    if (length $file > $maxl) {
30	print "filename longer than $maxl characters: $file\n";
31    }
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) {
46	    print "missing: $_\n";
47	    next;
48	}
49	if (tr/././ > 1) {
50	    print "more than one dot: $_\n";
51	    next;
52	}
53	while (m!/|\z!g) {
54	    my ($dir, $edt) = eight_dot_three($`);
55	    next unless defined $dir;
56	    ($dir, $edt) = map { lc } ($dir, $edt);
57	    push @{$dir{$dir}->{$edt}}, $_;
58	}
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) {
68	    print "directory $dir conflict $edt: @files\n";
69	}
70    }
71}
72