Re: encoding neutral unpack
[p5sagit/p5-mst-13.2.git] / genpacksizetables.pl
index 334dece..2987499 100755 (executable)
@@ -7,10 +7,10 @@ use Encode;
 my @lines = grep {!/^#/} <DATA>;
 
 sub addline {
-  my ($arrays, $chrmap, $letter, $arrayname, $noone, $nocsum, $size,
+  my ($arrays, $chrmap, $letter, $arrayname, $spare, $nocsum, $size,
       $condition) = @_;
   my $line = "/* $letter */ $size";
-  $line .= " | PACK_SIZE_CANNOT_ONLY_ONE" if $noone;
+  $line .= " | PACK_SIZE_SPARE" if $spare;
   $line .= " | PACK_SIZE_CANNOT_CSUM" if $nocsum;
   $line .= ",";
   # And then the hack
@@ -24,7 +24,7 @@ sub output_tables {
 
   my $chrmap = shift;
   foreach (@_) {
-    my ($letter, $shriek, $noone, $nocsum, $size, $condition)
+    my ($letter, $shriek, $spare, $nocsum, $size, $condition)
       = /^([A-Za-z])(!?)\t(\S*)\t(\S*)\t([^\t\n]+)(?:\t+(.*))?$/;
     die "Can't parse '$_'" unless $size;
 
@@ -36,7 +36,7 @@ sub output_tables {
     }
 
     addline (\%arrays, $chrmap, $letter, $shriek ? 'shrieking' : 'normal',
-            $noone, $nocsum, $size, $condition);
+            $spare, $nocsum, $size, $condition);
   }
 
   my %earliest;
@@ -51,17 +51,22 @@ sub output_tables {
     print "unsigned char size_${arrayname}[", scalar @$array, "] = {\n";
     my @lines;
     foreach (@$array) {
-       # There is an assumption here that the last entry isn't conditonal
+       # Remove the assumption here that the last entry isn't conditonal
        if (ref $_) {
-           push @lines, "#if $_->[0]", "  $_->[1]", "#else", "  0,", "#endif";
+           push @lines,
+             ["#if $_->[0]", "  $_->[1]", "#else", "  0,", "#endif"];
        } else {
            push @lines, $_ ? "  $_" : "  0,";
        }
     }
     # remove the last, annoying, comma
-    die "Last entry was a conditional: '$lines[$#lines]'"
-       unless $lines[$#lines] =~ s/,$//;
-    print "$_\n" foreach @lines;
+    my $last = $lines[$#lines];
+    my $got;
+    foreach (ref $last ? @$last : $last) {
+      $got += s/,$//;
+    }
+    die "Last entry had no commas" unless $got;
+    print map {"$_\n"} ref $_ ? @$_ : $_ foreach @lines;
     print "};\n";
     $earliest{$arrayname} = $earliest;
   }
@@ -95,7 +100,7 @@ output_tables (\%ebcdicmap, @lines);
 print "#endif\n";
 
 __DATA__
-#Symbol        nooone  nocsum  size
+#Symbol        spare   nocsum  size
 c                      char
 C                      unsigned char
 U                      char
@@ -105,8 +110,8 @@ S!                  unsigned short
 v                      =SIZE16
 n                      =SIZE16
 S                      =SIZE16
-v!                     =SIZE16
-n!                     =SIZE16
+v!                     =SIZE16 PERL_PACK_CAN_SHRIEKSIGN
+n!                     =SIZE16 PERL_PACK_CAN_SHRIEKSIGN
 i                      int
 i!                     int
 I                      unsigned int
@@ -118,10 +123,10 @@ l                 =SIZE32
 L!                     unsigned long
 V                      =SIZE32
 N                      =SIZE32
-V!                     =SIZE32
-N!                     =SIZE32
+V!                     =SIZE32 PERL_PACK_CAN_SHRIEKSIGN
+N!                     =SIZE32 PERL_PACK_CAN_SHRIEKSIGN
 L                      =SIZE32
-p      *       *       char *
+p              *       char *
 w              *       char
 q                      Quad_t  HAS_QUAD
 Q                      Uquad_t HAS_QUAD