mktables: Try harder to find a good table name
authorKarl Williamson <public@khwilliamson.com>
Sun, 21 Aug 2011 16:18:20 +0000 (10:18 -0600)
committerKarl Williamson <public@khwilliamson.com>
Tue, 8 Nov 2011 15:09:08 +0000 (08:09 -0700)
The short name of a table is used to generate the file name in which it
is to be stored.  If the short name is a null string, the file is given
the name of '_.pl'.  A more meaningful name would be preferred.  If the
table is equivalent to other tables, we can use their name instead of
its.  This commit does that.

lib/unicore/mktables

index 73802ba..0873b8e 100644 (file)
@@ -4805,6 +4805,33 @@ sub trace { return main::trace(@_); }
             }
         }
 
+        # If the short name isn't a nice one, perhaps an equivalent table has
+        # a better one.
+        if (! defined $short_name{$addr}
+            || $short_name{$addr} eq ""
+            || $short_name{$addr} eq "_")
+        {
+            my $return;
+            foreach my $follower ($self->children) {    # All equivalents
+                my $follower_name = $follower->short_name;
+                next unless defined $follower_name;
+
+                # Anything (except undefined) is better than underscore or
+                # empty
+                if (! defined $return || $return eq "_") {
+                    $return = $follower_name;
+                    next;
+                }
+
+                # If the new follower name isn't "_" and is shorter than the
+                # current best one, prefer the new one.
+                next if $follower_name eq "_";
+                next if length $follower_name > length $return;
+                $return = $follower_name;
+            }
+            $short_name{$addr} = $return if defined $return;
+        }
+
         # If no suitable external name return undef
         if (! defined $short_name{$addr}) {
             $$nominal_length_ptr = undef if $nominal_length_ptr;