1 # |
|
2 # Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 # All rights reserved. |
|
4 # This component and the accompanying materials are made available |
|
5 # under the terms of "Eclipse Public License v1.0" |
|
6 # which accompanies this distribution, and is available |
|
7 # at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 # |
|
9 # Initial Contributors: |
|
10 # Nokia Corporation - initial contribution. |
|
11 # |
|
12 # Contributors: |
|
13 # |
|
14 # Description: |
|
15 # This tool takes a valid .txt file as an input parameter and converts it into a .cpp file |
|
16 # |
|
17 |
|
18 if (@ARGV != 1 && @ARGV != 2) |
|
19 { |
|
20 print <<EOD; |
|
21 Usage:explanation..... |
|
22 EOD |
|
23 exit(1); |
|
24 } |
|
25 |
|
26 # Removes the extenstion from the filename |
|
27 $ARGV[0] =~ m/(.*)\..*/; |
|
28 my $root = $1; |
|
29 $root =~ m/.*[\\\/]([^\\\/]*)$/; |
|
30 my $header_to_include = $1; |
|
31 |
|
32 if (@ARGV == 2) |
|
33 { |
|
34 $ARGV[1] =~ m/(.*)\..*/; |
|
35 $root = $1; |
|
36 } |
|
37 |
|
38 open (IN, "<$ARGV[0]") or die ("Error: $ARGV[0] $!"); |
|
39 |
|
40 open (CPP, ">$root.cpp") or die ("Error: $ARGV[0] Can't open cpp file"); |
|
41 |
|
42 print CPP <<EOD; |
|
43 // |
|
44 // Auto-generated by the FatConversiontable tool - Do not edit!!! |
|
45 // |
|
46 |
|
47 #include <e32std.h> |
|
48 #include <e32def.h> |
|
49 #include <e32des8.h> |
|
50 #include "convdatastruct.h" |
|
51 |
|
52 EOD |
|
53 print CPP "const TLeadOrSingle TConvDataStruct\:\:KFirstByteConversions\[\]=\n"; |
|
54 print CPP "\t\t\{\n"; |
|
55 |
|
56 my $input; |
|
57 my $count = 0; |
|
58 my $count2 = 0; |
|
59 my $tailIncrement = hex(40); |
|
60 my $index = 0; |
|
61 my $test = 0; |
|
62 my $leadByte = hex(00); |
|
63 |
|
64 until (eof IN) { #until end of file |
|
65 |
|
66 #ignore lines that start with a '#' or which are in the range of 0x00 - 0x7F |
|
67 do { |
|
68 $input = readline(IN) or die ("Error: Can't read line"); |
|
69 }while ($input =~ m/^$*#/ || $input=~ m/^0x[0-7][0-9A-F]\t/); |
|
70 |
|
71 #single bytes get stored into 'SingleByte' array |
|
72 if($input =~ m/^0x(..)\t(.*)\t(#.*)$/) |
|
73 { |
|
74 my $SingleByte = hex($1); |
|
75 my $Unicode = $2; |
|
76 my $Note = $3; |
|
77 |
|
78 if ($Unicode=~ m/0x..../) |
|
79 { |
|
80 @SingleByte[$count] = (["$SingleByte", "$Unicode"]); |
|
81 $count = $count + 1; |
|
82 } |
|
83 if($Note eq '#DBCS LEAD BYTE') |
|
84 { |
|
85 @SingleByte[$count] = (["$SingleByte", "0"]); |
|
86 $count = $count + 1; |
|
87 } |
|
88 if ($Note eq '#UNDEFINED') |
|
89 { |
|
90 @SingleByte[$count] = (["$SingleByte", "0xFFFD"]); |
|
91 $count = $count + 1; |
|
92 } |
|
93 } |
|
94 |
|
95 #double bytes get stored into 'DoubleByte' array, whereby the tail bytes |
|
96 #must not have any gaps from 0x40 to 0xFF; |
|
97 elsif($input=~ m/^0x(..)(..)\t(0x....)\t#.*/) |
|
98 { |
|
99 my $ForeignLead = hex($1); |
|
100 my $ForeignTail = hex($2); |
|
101 my $Unicode = $3; |
|
102 $test = 1; |
|
103 |
|
104 if($leadByte==0) |
|
105 { |
|
106 $leadByte=$ForeignLead; |
|
107 } |
|
108 |
|
109 if($leadByte!=$ForeignLead) |
|
110 { |
|
111 if($tailIncrement!=hex(40)) |
|
112 { |
|
113 while($tailIncrement<=hex(FF)) |
|
114 { |
|
115 @DoubleByte[$count2] = (["$leadByte", "0xFFFD","$tailIncrement"]); |
|
116 $count2++; |
|
117 $tailIncrement++; |
|
118 } |
|
119 } |
|
120 $tailIncrement=hex(40); |
|
121 $leadByte=$ForeignLead; |
|
122 } |
|
123 |
|
124 while($tailIncrement<=$ForeignTail) |
|
125 { |
|
126 if($tailIncrement==$ForeignTail) |
|
127 { |
|
128 @DoubleByte[$count2] = (["$ForeignLead", "$Unicode","$ForeignTail"]); |
|
129 } |
|
130 else |
|
131 { |
|
132 @DoubleByte[$count2] = (["$leadByte", "0xFFFD","$tailIncrement"]); |
|
133 } |
|
134 $count2++; |
|
135 if($tailIncrement==hex(FF)) |
|
136 { |
|
137 $tailIncrement=hex(40); |
|
138 $leadByte++; |
|
139 } |
|
140 else |
|
141 { |
|
142 $tailIncrement++; |
|
143 } |
|
144 } |
|
145 } |
|
146 } #end of loop |
|
147 |
|
148 #my $d=0; |
|
149 #for ($d=0;$d<$count2;$d++) |
|
150 #{ |
|
151 #print CPP"$DoubleByte[$d][0], $DoubleByte[$d][1], $DoubleByte[$d][2]\t\n"; |
|
152 #} |
|
153 |
|
154 #checks if tail byte ended uncompleted (i.e. ends with xFD) and completes it to xFF; |
|
155 if($test==1) |
|
156 { |
|
157 my $counter = $count2-1; |
|
158 $test=0; |
|
159 |
|
160 if($DoubleByte[$counter][2]<0xFF) |
|
161 { |
|
162 my $temp = $DoubleByte[$counter][0]; |
|
163 my $temp2 = $DoubleByte[$counter][2]; |
|
164 do |
|
165 { |
|
166 $temp2++; |
|
167 @DoubleByte[$count2] = (["$temp", "0xFFFD","$temp2"]); |
|
168 $count2 = $count2 + 1; |
|
169 }while($temp2<0xFF); |
|
170 } |
|
171 } |
|
172 |
|
173 my $position = 0; |
|
174 my $position2 = 0; |
|
175 my $x=0; |
|
176 my $y=0; |
|
177 |
|
178 #get the positions of single/lead bytes |
|
179 for($x=0; $x<$count; $x++) |
|
180 { |
|
181 my $found=0; |
|
182 if($SingleByte[$x][1] eq '0') #if lead-byte... |
|
183 { |
|
184 for($y=0; $y<$count2; $y++) |
|
185 { |
|
186 if($SingleByte[$x][0] == $DoubleByte[$y][0]) |
|
187 { |
|
188 $position = $y; |
|
189 $position2 = $y + 192; |
|
190 $found = 1; |
|
191 $y=$count2; |
|
192 } |
|
193 } |
|
194 if($found==1) |
|
195 { |
|
196 print CPP "\t\t\{$SingleByte[$x][1], $position\},\n"; |
|
197 } |
|
198 else |
|
199 { |
|
200 print CPP "\t\t\{0xFFFD, $position2\},\n"; |
|
201 } |
|
202 } |
|
203 else |
|
204 { |
|
205 print CPP "\t\t\{$SingleByte[$x][1], $position2\},\n"; |
|
206 } |
|
207 } |
|
208 print CPP "\t\t\};\n\n"; |
|
209 |
|
210 #print double bytes |
|
211 print CPP "const TUint16 TConvDataStruct\:\:KDoubleByteConversions\[\]=\n"; |
|
212 print CPP "\t\t\{"; |
|
213 my $newLine = 0; |
|
214 if($count2>0) |
|
215 { |
|
216 for ($i=0; $i<$count2; $i++) |
|
217 { |
|
218 if($newLine==15) #use a newline every 15 entries, to maintain user-friendliness |
|
219 { |
|
220 print CPP "\n\t\t"; |
|
221 $newLine = 0; |
|
222 } |
|
223 print CPP "$DoubleByte[$i][1],"; |
|
224 $newLine++; |
|
225 } |
|
226 } |
|
227 else |
|
228 { |
|
229 print CPP "0x00"; |
|
230 } |
|
231 print CPP "\};\n\n"; |
|
232 if($count2>0) |
|
233 { |
|
234 $count2=$count2-1; |
|
235 } |
|
236 print CPP "const TUint16 TConvDataStruct\:\:KDoubleByteConversionLength = $count2;\n\n"; |
|
237 print CPP "const TUint8 TConvDataStruct\:\:KMinTrailByte = 0x40;\n\n"; |
|
238 print CPP "const TUint8 TConvDataStruct\:\:KMaxTrailByte = 0xFF;\n\n"; |
|
239 |
|
240 print CPP <<EOD; |
|
241 TInt TConvDataStruct::ConvertSingleUnicode(TInt aUnicode, TInt& aTrailByte) |
|
242 { |
|
243 aTrailByte = KErrNotFound; |
|
244 |
|
245 //single byte conversion check |
|
246 for(TInt i=0;i!=0x80;++i) |
|
247 { |
|
248 if(KFirstByteConversions[i].iUnicodeIfSingle==aUnicode) |
|
249 return i+0x80; |
|
250 } |
|
251 //double byte conversion check |
|
252 for(TInt j=0;j<=KDoubleByteConversionLength;++j) |
|
253 { |
|
254 if(KDoubleByteConversions[j] == aUnicode) |
|
255 { |
|
256 for(TInt k=0x7F;k>=0;--k) |
|
257 { |
|
258 TInt temp = j-KFirstByteConversions[k].iDoubleByteIndex; |
|
259 if(0<=temp) |
|
260 { |
|
261 aTrailByte = KMinTrailByte + temp; |
|
262 return k+0x80; |
|
263 } |
|
264 } |
|
265 } |
|
266 } |
|
267 return KErrNotFound; |
|
268 EOD |
|
269 print CPP "\t\}\n"; |
|