]> mj.ucw.cz Git - libucw.git/blob - charset/misc/gentab
Added functions for reading/writing UTF-8 characters on fastbuf streams.
[libucw.git] / charset / misc / gentab
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         ($i,$j) = split/\s+/;
13         ($i =~ /^(..)(..)$/) || die "Syntax error at $i";
14         $table{$1} = "$name" . "_$1";
15         $val{$i} = $j;
16 }
17
18 print "/* Generated automatically by gentab. Please don't edit. */\n\n";
19
20 for($i=0; $i<256; $i++) {
21         $x = sprintf("%02X", $i);
22         if (defined($table{$x})) {
23                 print "static $type $table{$x}\[256\] = \{\n";
24                 for($j=0; $j<256; $j++) {
25                         $y = $x . sprintf("%02X", $j);
26                         if ($val{$y}) { print $val{$y}; }
27                         else { print "0"; }
28                         if ($j != 255) { print ","; }
29                         if ($j % 16 == 15) { print "\n"; }
30                 }
31                 print "\};\n\n";
32         }
33 }
34
35 print "$type \*$name\[256\] = \{\n";
36 for($j=0; $j<256; $j++) {
37         $y = sprintf("%02X", $j);
38         if (defined $table{$y}) { print $table{$y}; }
39         else { print "NULL"; }
40         if ($j != 255) { print ","; }
41         if ($j % 16 == 15) { print "\n"; }
42 }
43 print "\};\n";