2 # I'm assuming that you're running this on some kind of ASCII system, but
3 # it will generate EDCDIC too. (TODO)
13 my ($arrays, $chrmap, $letter, $arrayname, $unpredictable, $nocsum, $size,
15 my $line = "/* $letter */ $size";
16 $line .= " | PACK_SIZE_UNPREDICTABLE" if $unpredictable;
17 $line .= " | PACK_SIZE_CANNOT_CSUM" if $nocsum;
20 $line = [$condition, $line] if $condition;
21 $arrays->{$arrayname}->[ord $chrmap->{$letter}] = $line;
22 # print ord $chrmap->{$letter}, " $line\n";
30 my ($letter, $shriek, $unpredictable, $nocsum, $size, $condition)
31 = /^([A-Za-z])(!?)\t(\S*)\t(\S*)\t([^\t\n]+)(?:\t+(.*))?$/;
32 die "Can't parse '$_'" unless $size;
34 if (defined $condition) {
35 $condition = join " && ", map {"defined($_)"} split ' ', $condition;
37 unless ($size =~ s/^=//) {
38 $size = "sizeof($size)";
41 addline (\%arrays, $chrmap, $letter, $shriek ? 'shrieking' : 'normal',
42 $unpredictable, $nocsum, $size, $condition);
46 foreach my $arrayname (sort keys %arrays) {
47 my $array = $arrays{$arrayname};
48 die "No defined entries in $arrayname" unless $array->[$#$array];
49 # Find the first used entry
51 $earliest++ while (!$array->[$earliest]);
52 # Remove all the empty elements.
53 splice @$array, 0, $earliest;
54 print "unsigned char size_${arrayname}[", scalar @$array, "] = {\n";
57 # Remove the assumption here that the last entry isn't conditonal
60 ["#if $_->[0]", " $_->[1]", "#else", " 0,", "#endif"];
62 push @lines, $_ ? " $_" : " 0,";
65 # remove the last, annoying, comma
66 my $last = $lines[$#lines];
68 foreach (ref $last ? @$last : $last) {
71 die "Last entry had no commas" unless $got;
72 print map {"$_\n"} ref $_ ? @$_ : $_ foreach @lines;
74 $earliest{$arrayname} = $earliest;
77 print "struct packsize_t packsize[2] = {\n";
80 foreach (qw(normal shrieking)) {
81 my $array = $arrays{$_};
82 push @lines, " {size_$_, $earliest{$_}, " . (scalar @$array) . "},";
84 # remove the last, annoying, comma
86 print "$_\n" foreach @lines;
90 my %asciimap = (map {chr $_, chr $_} 0..255);
91 my %ebcdicmap = (map {chr $_, Encode::encode ("posix-bc", chr $_)} 0..255);
97 output_tables (\%asciimap, @lines);
100 /* EBCDIC (or bust) */
102 output_tables (\%ebcdicmap, @lines);
106 #Symbol unpredictable
118 v! =SIZE16 PERL_PACK_CAN_SHRIEKSIGN
119 n! =SIZE16 PERL_PACK_CAN_SHRIEKSIGN
131 V! =SIZE32 PERL_PACK_CAN_SHRIEKSIGN
132 N! =SIZE32 PERL_PACK_CAN_SHRIEKSIGN
141 D =LONG_DOUBLESIZE HAS_LONG_DOUBLE USE_LONG_DOUBLE