]> mj.ucw.cz Git - libucw.git/blob - charset/misc/table2h
XTypes: Fixed dump of configuration.
[libucw.git] / charset / misc / table2h
1 #!/usr/bin/perl
2 #
3 #  Generate C Language Table for UniCode Data
4 #  (c) 1997 Martin Mares <mj@atrey.karlin.mff.cuni.cz>
5 #
6
7 $name=$ARGV[0];
8 $type=$ARGV[1];
9
10 while (<STDIN>) {
11         chomp;
12         /^#/ && next;
13         /^\s*$/ && next;
14         s/^0x//;
15         ($i,$j) = split/\s+/;
16         ($i =~ /^(..)(..)$/) || die "Syntax error at $i";
17         $table{$1} = "$name" . "_$1";
18         die if defined $val{$i};
19         $val{$i} = $j;
20 }
21
22 print "/* Generated automatically by gentab. Please don't edit. */\n\n";
23
24 for($i=0; $i<256; $i++) {
25         $x = sprintf("%02X", $i);
26         if (defined($table{$x})) {
27                 print "static const $type $table{$x}\[256\] = \{\n";
28                 for($j=0; $j<256; $j++) {
29                         $y = $x . sprintf("%02X", $j);
30                         if ($val{$y}) { print $val{$y}; }
31                         else { print "0"; }
32                         if ($j != 255) { print ","; }
33                         if ($j % 16 == 15) { print "\n"; }
34                 }
35                 print "\};\n\n";
36         }
37 }
38
39 print "const $type \*$name\[256\] = \{\n";
40 for($j=0; $j<256; $j++) {
41         $y = sprintf("%02X", $j);
42         if (defined $table{$y}) { print $table{$y}; }
43         else { print "NULL"; }
44         if ($j != 255) { print ","; }
45         if ($j % 16 == 15) { print "\n"; }
46 }
47 print "\};\n";