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
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;
}
addline (\%arrays, $chrmap, $letter, $shriek ? 'shrieking' : 'normal',
- $noone, $nocsum, $size, $condition);
+ $spare, $nocsum, $size, $condition);
}
my %earliest;
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;
}
print "#endif\n";
__DATA__
-#Symbol nooone nocsum size
+#Symbol spare nocsum size
c char
C unsigned char
U char
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
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