Imported Upstream version 0.63.0
[hcoop/debian/courier-authlib.git] / unicode / mkibm864.pl
1 # Copyright 2000-2002 Double Precision, Inc.
2 # See COPYING for distribution information.
3 #
4 # $Id: mkibm864.pl,v 1.2 2002/11/18 00:54:22 mrsam Exp $
5 #
6 # Generate iso-8859* unicode tables
7
8 my $set=shift;
9
10 open (U, "UnicodeData.txt") || die "$!\n";
11
12 while (<U>)
13 {
14 chomp;
15
16 my @fields= split /;/;
17
18 my ($code, $uc, $lc, $tc);
19
20 $code="0x$fields[0]";
21 eval "\$code=$code;";
22
23 $uc=$fields[12];
24 if ($uc ne "")
25 {
26 eval "\$uc=0x$uc;";
27 $UC{$code}=$uc;
28 }
29
30 $lc=$fields[13];
31 if ($lc ne "")
32 {
33 eval "\$lc=0x$lc;";
34 $LC{$code}=$lc;
35 }
36
37 $tc=$fields[14];
38 if ($tc ne "")
39 {
40 eval "\$tc=0x$tc;";
41 $TC{$code}=$tc;
42 }
43 }
44
45 close(U);
46
47 my @fwd;
48
49 my $rev;
50
51 open (SET, $set) || die "$set: $!\n";
52 while (<SET>)
53 {
54 chomp;
55 s/\#.*//;
56
57 my ($code, $unicode)=split /[ \t]+/;
58
59 next unless $code ne "";
60
61 eval "\$code=$code;";
62 eval "\$unicode=$unicode;";
63
64 die if $code < 0 || $code > 255;
65
66 $fwd[$code]=$unicode;
67 $rev{$unicode}=$code;
68 }
69 close(SET);
70
71 my $fwdname=shift;
72
73 print '
74 /*
75 ** Copyright 2000-2002 Double Precision, Inc.
76 ** See COPYING for distribution information.
77 **
78 ** $Id: mkibm864.pl,v 1.2 2002/11/18 00:54:22 mrsam Exp $
79 */
80
81 #include "unicode.h"
82 ';
83
84
85 print "static const unicode_char $fwdname [256]={\n";
86
87 for ($i=0; $i<256; $i++)
88 {
89 my $n=$fwd[$i];
90
91 $n=0 unless $n;
92
93 print "$n";
94 print "," if $i < 255;
95 print "\n" if ($i % 16) == 15;
96 }
97
98 print "};\n";
99
100 my $ucname=shift;
101
102 print "static const char $ucname [256]={\n";
103
104 for ($i=0; $i<256; $i++)
105 {
106 my $unicode=$fwd[$i];
107
108 $unicode=$UC{$unicode} && $rev{$UC{$unicode}} ? $rev{$UC{$unicode}}:$i;
109
110 printf("(char)0x%02x", $unicode);
111 print "," if $i < 255;
112 print "\n" if ($i % 8) == 7;
113 }
114
115 print "};\n";
116
117 my $lcname=shift;
118
119 print "static const char $lcname [256]={\n";
120
121 for ($i=0; $i<256; $i++)
122 {
123 my $unicode=$fwd[$i];
124
125 $unicode=$LC{$unicode} && $rev{$LC{$unicode}} ? $rev{$LC{$unicode}}:$i;
126
127 printf("(char)0x%02x", $unicode);
128 print "," if $i < 255;
129 print "\n" if ($i % 8) == 7;
130 }
131
132 print "};\n";
133
134 my $tcname=shift;
135
136 print "static const char $tcname [256]={\n";
137
138 for ($i=0; $i<256; $i++)
139 {
140 my $unicode=$fwd[$i];
141
142 $unicode=$TC{$unicode} && $rev{$TC{$unicode}} ? $rev{$TC{$unicode}}:$i;
143
144 printf("(char)0x%02x", $unicode);
145 print "," if $i < 255;
146 print "\n" if ($i % 8) == 7;
147 }
148
149 my $structname=shift;
150 my $chsetname=shift;
151
152 print "};
153
154
155 static unicode_char *c2u(const struct unicode_info *u, const char *cp, int *ip)
156 {
157 return (unicode_ibm864_c2u(cp, ip, $fwdname));
158 }
159
160 static char *u2c(const struct unicode_info *u, const unicode_char *cp, int *ip)
161 {
162 return (unicode_ibm864_u2c(cp, ip, $fwdname));
163 }
164
165 static char *toupper_func(const struct unicode_info *u, const char *cp, int *ip)
166 {
167 return (unicode_iso8859_convert(cp, ip, $ucname));
168 }
169
170 static char *tolower_func(const struct unicode_info *u, const char *cp, int *ip)
171 {
172 return (unicode_iso8859_convert(cp, ip, $lcname));
173 }
174
175 static char *totitle_func(const struct unicode_info *u, const char *cp, int *ip)
176 {
177 return (unicode_iso8859_convert(cp, ip, $tcname));
178 }
179
180 const struct unicode_info $structname = {
181 \"$chsetname\",
182 0,
183 c2u,
184 u2c,
185 toupper_func,
186 tolower_func,
187 totitle_func};
188 ";