Debian Codegraph @

util/unicode/x11/makeencodings

raw
1 #!/usr/bin/perl
2
3 use strict;
4
5 open IN, "encodings.in"
6 or die "Can't open in\n";
7 open out, ">encodings.c"
8 or die "Can't open out\n";
9
10 my @qwritingSystems = (
11 "Any",
12 "Latin",
13 "Greek",
14 "Cyrillic",
15 "Armenian",
16 "Hebrew",
17 "Arabic",
18 "Syriac",
19 "Thaana",
20 "Devanagari",
21 "Bengali",
22 "Gurmukhi",
23 "Gujarati",
24 "Oriya",
25 "Tamil",
26 "Telugu",
27 "Kannada",
28 "Malayalam",
29 "Sinhala",
30 "Thai",
31 "Lao",
32 "Tibetan",
33 "Myanmar",
34 "Georgian",
35 "Khmer",
36 "SimplifiedChinese",
37 "TraditionalChinese",
38 "Japanese",
39 "Korean",
40 "Vietnamese",
41 "Yi",
42 "Tagalog",
43 "Hanunoo",
44 "Buhid",
45 "Tagbanwa",
46 "Limbu",
47 "TaiLe",
48 "Braille",
49 "Other"
50 );
51
52 my $writingSystemsCount = @qwritingSystems;
53
54 my $num = 0;
55 my @xlfd = ();
56 my @mib = ();
57 my @writingSystems = ();
58
59 my $i;
60
61 while (<IN>) {
62 chomp;
63 s/#.*//;
64 if ( index( $_, ' ' ) > -1 ) {
65 chomp;
66 my @line = split( / /, $_ );
67 $xlfd[$num] = $line[0];
68 $mib[$num] = $line[1];
69 $writingSystems[$num] = $line[2];
70
71 $num = $num + 1;
72 }
73
74 }
75
76 print out "#define make_tag( c1, c2, c3, c4 ) \\\n";
77 print out " ((((unsigned int)c1)<<24) | (((unsigned int)c2)<<16) | \\\n";
78 print out " (((unsigned int)c3)<<8) | ((unsigned int)c4))\n\n";
79
80 print out "struct XlfdEncoding {\n const char *name;\n int id;\n";
81 print out " int mib;\n unsigned int hash1;\n unsigned int hash2;\n};\n\n";
82
83 print out "static const XlfdEncoding xlfd_encoding[] = {\n";
84 $i = 0;
85 while( $i < $num ) {
86 my $x = $xlfd[$i];
87 my $hash1 = "make_tag('".substr($x,0,1)."','".substr($x,1,1)."','".substr($x,2,1)."','".substr($x,3,1)."')";
88 if( index( $x, "*" ) > -1 && index( $x, "*" ) < 4 ) {
89 $hash1 = "0";
90 }
91 my $idx = length( $x ) - 4;
92 my $hash2 = "make_tag('".substr($x,$idx,1)."','".substr($x,$idx+1,1)."','".substr($x,$idx+2,1)."','".substr($x,$idx+3,1)."')";
93 if( index( $x, "*", $idx ) > -1 ) {
94 $hash2 = "0";
95 }
96 print out " { \"".$xlfd[$i]."\", ".$i.", ".$mib[$i].
97 ", ".$hash1.", ".$hash2." },\n";
98 $i = $i + 1;
99 }
100 print out " { 0, 0, 0, 0, 0 }\n};\n\n";
101
102 print out "static const char writingSystems_for_xlfd_encoding[".$num."][".$writingSystemsCount.
103 "] = { \n";
104 $i = 0;
105 while( $i < $num ) {
106 my $j = 0;
107 my @s = split( /,/, $writingSystems[$i] );
108 print out " // ".$xlfd[$i]."\n";
109 print out " { ";
110 while( $j < $writingSystemsCount ) {
111 if( grep( /^$qwritingSystems[$j]$/, @s ) ) {
112 print out "1";
113 } else {
114 print out "0";
115 }
116 $j = $j + 1;
117 if ( $j < $writingSystemsCount ) {
118 print out ", ";
119 if ( !(($j) % 10) ) {
120 print out "\n ";
121 }
122 }
123 }
124 $i = $i + 1;
125 if ( $i < $num ) {
126 print out " },\n";
127 } else {
128 print out " }\n";
129 }
130 }
131 print out "\n};\n\n";
132
133
134
135 close out;