Commit | Line | Data |
017e2add |
1 | #!../../perl -w |
508a30f1 |
2 | BEGIN { |
b0bf7e4c |
3 | unshift @INC, qw(../../lib ../../../lib); |
4 | $ENV{PATH} .= ';../..;../../..' if $^O eq 'MSWin32'; |
508a30f1 |
5 | } |
017e2add |
6 | use strict; |
afdae191 |
7 | use Getopt::Std; |
8 | my @orig_ARGV = @ARGV; |
dcda1f94 |
9 | |
017e2add |
10 | sub encode_U |
11 | { |
9b37254d |
12 | # UTF-8 encode long hand - only covers part of perl's range |
7ba7f87b |
13 | ## my $uv = shift; |
1b026014 |
14 | # chr() works in native space so convert value from table |
15 | # into that space before using chr(). |
7ba7f87b |
16 | my $ch = chr(utf8::unicode_to_native($_[0])); |
1b026014 |
17 | # Now get core perl to encode that the way it likes. |
18 | utf8::encode($ch); |
19 | return $ch; |
017e2add |
20 | } |
21 | |
22 | sub encode_S |
23 | { |
14a8264b |
24 | # encode single byte |
7ba7f87b |
25 | ## my ($ch,$page) = @_; return chr($ch); |
26 | return chr $_[0]; |
017e2add |
27 | } |
28 | |
29 | sub encode_D |
30 | { |
14a8264b |
31 | # encode double byte MS byte first |
7ba7f87b |
32 | ## my ($ch,$page) = @_; return chr($page).chr($ch); |
33 | return chr ($_[1]) . chr $_[0]; |
017e2add |
34 | } |
35 | |
36 | sub encode_M |
37 | { |
14a8264b |
38 | # encode Multi-byte - single for 0..255 otherwise double |
7ba7f87b |
39 | ## my ($ch,$page) = @_; |
40 | ## return &encode_D if $page; |
41 | ## return &encode_S; |
42 | return chr ($_[1]) . chr $_[0] if $_[1]; |
43 | return chr $_[0]; |
017e2add |
44 | } |
45 | |
7ba7f87b |
46 | my %encode_types = (U => \&encode_U, |
47 | S => \&encode_S, |
48 | D => \&encode_D, |
49 | M => \&encode_M, |
50 | ); |
51 | |
14a8264b |
52 | # Win32 does not expand globs on command line |
252a8565 |
53 | eval "\@ARGV = map(glob(\$_),\@ARGV)" if ($^O eq 'MSWin32'); |
18b7339f |
54 | |
afdae191 |
55 | my %opt; |
4cfc977c |
56 | getopts('qOo:f:n:',\%opt); |
afdae191 |
57 | my $cname = (exists $opt{'o'}) ? $opt{'o'} : shift(@ARGV); |
2f2b4ff2 |
58 | chmod(0666,$cname) if -f $cname && !-w $cname; |
017e2add |
59 | open(C,">$cname") || die "Cannot open $cname:$!"; |
afdae191 |
60 | |
61 | |
2f2b4ff2 |
62 | my $dname = $cname; |
023d8852 |
63 | $dname =~ s/(\.[^\.]*)?$/_def.h/; |
e0c49a6b |
64 | |
dcda1f94 |
65 | my ($doC,$doEnc,$doUcm,$doPet); |
e0c49a6b |
66 | |
67 | if ($cname =~ /\.(c|xs)$/) |
68 | { |
69 | $doC = 1; |
70 | chmod(0666,$dname) if -f $cname && !-w $dname; |
71 | open(D,">$dname") || die "Cannot open $dname:$!"; |
72 | my $hname = $cname; |
73 | $hname =~ s/(\.[^\.]*)?$/.h/; |
74 | chmod(0666,$hname) if -f $cname && !-w $hname; |
75 | open(H,">$hname") || die "Cannot open $hname:$!"; |
76 | |
77 | foreach my $fh (\*C,\*D,\*H) |
78 | { |
afdae191 |
79 | print $fh <<"END" unless $opt{'q'}; |
14a8264b |
80 | /* |
81 | !!!!!!! DO NOT EDIT THIS FILE !!!!!!! |
82 | This file was autogenerated by: |
023d8852 |
83 | $^X $0 @orig_ARGV |
14a8264b |
84 | */ |
85 | END |
e0c49a6b |
86 | } |
14a8264b |
87 | |
e0c49a6b |
88 | if ($cname =~ /(\w+)\.xs$/) |
89 | { |
90 | print C "#include <EXTERN.h>\n"; |
91 | print C "#include <perl.h>\n"; |
92 | print C "#include <XSUB.h>\n"; |
93 | print C "#define U8 U8\n"; |
94 | } |
95 | print C "#include \"encode.h\"\n"; |
d811239c |
96 | |
e0c49a6b |
97 | } |
98 | elsif ($cname =~ /\.enc$/) |
99 | { |
100 | $doEnc = 1; |
101 | } |
102 | elsif ($cname =~ /\.ucm$/) |
2f2b4ff2 |
103 | { |
e0c49a6b |
104 | $doUcm = 1; |
2f2b4ff2 |
105 | } |
dcda1f94 |
106 | elsif ($cname =~ /\.pet$/) |
107 | { |
108 | $doPet = 1; |
109 | } |
017e2add |
110 | |
afdae191 |
111 | my @encfiles; |
3865e8e1 |
112 | if (exists $opt{'f'}) |
afdae191 |
113 | { |
114 | # -F is followed by name of file containing list of filenames |
3865e8e1 |
115 | my $flist = $opt{'f'}; |
afdae191 |
116 | open(FLIST,$flist) || die "Cannot open $flist:$!"; |
117 | chomp(@encfiles = <FLIST>); |
118 | close(FLIST); |
119 | } |
120 | else |
121 | { |
122 | @encfiles = @ARGV; |
123 | } |
c6fdb90a |
124 | |
017e2add |
125 | my %encoding; |
126 | my %strings; |
b1e7e56f |
127 | my $saved = 0; |
128 | my $subsave = 0; |
129 | my $strings = 0; |
017e2add |
130 | |
2f2b4ff2 |
131 | sub cmp_name |
132 | { |
133 | if ($a =~ /^.*-(\d+)/) |
134 | { |
135 | my $an = $1; |
136 | if ($b =~ /^.*-(\d+)/) |
137 | { |
138 | my $r = $an <=> $1; |
139 | return $r if $r; |
140 | } |
141 | } |
142 | return $a cmp $b; |
143 | } |
144 | |
dcda1f94 |
145 | |
c6fdb90a |
146 | foreach my $enc (sort cmp_name @encfiles) |
017e2add |
147 | { |
9b37254d |
148 | my ($name,$sfx) = $enc =~ /^.*?([\w-]+)\.(enc|ucm)$/; |
51ef4e11 |
149 | $name = $opt{'n'} if exists $opt{'n'}; |
017e2add |
150 | if (open(E,$enc)) |
151 | { |
9b37254d |
152 | if ($sfx eq 'enc') |
153 | { |
dcda1f94 |
154 | compile_enc(\*E,lc($name)); |
9b37254d |
155 | } |
156 | else |
157 | { |
dcda1f94 |
158 | compile_ucm(\*E,lc($name)); |
9b37254d |
159 | } |
017e2add |
160 | } |
161 | else |
162 | { |
163 | warn "Cannot open $enc for $name:$!"; |
164 | } |
165 | } |
166 | |
e0c49a6b |
167 | if ($doC) |
2f2b4ff2 |
168 | { |
b1e7e56f |
169 | print STDERR "Writing compiled form\n"; |
dcda1f94 |
170 | foreach my $name (sort cmp_name keys %encoding) |
171 | { |
172 | my ($e2u,$u2e,$erep,$min_el,$max_el) = @{$encoding{$name}}; |
173 | output(\*C,$name.'_utf8',$e2u); |
174 | output(\*C,'utf8_'.$name,$u2e); |
175 | push(@{$encoding{$name}},outstring(\*C,$e2u->{Cname}.'_def',$erep)); |
176 | } |
e0c49a6b |
177 | foreach my $enc (sort cmp_name keys %encoding) |
178 | { |
dcda1f94 |
179 | my ($e2u,$u2e,$rep,$min_el,$max_el,$rsym) = @{$encoding{$enc}}; |
180 | my @info = ($e2u->{Cname},$u2e->{Cname},$rsym,length($rep),$min_el,$max_el); |
e0c49a6b |
181 | my $sym = "${enc}_encoding"; |
182 | $sym =~ s/\W+/_/g; |
183 | print C "encode_t $sym = \n"; |
dcda1f94 |
184 | print C " {",join(',',@info,"{\"$enc\",(const char *)0}"),"};\n\n"; |
e0c49a6b |
185 | } |
2f2b4ff2 |
186 | |
e0c49a6b |
187 | foreach my $enc (sort cmp_name keys %encoding) |
188 | { |
189 | my $sym = "${enc}_encoding"; |
190 | $sym =~ s/\W+/_/g; |
191 | print H "extern encode_t $sym;\n"; |
d811239c |
192 | print D " Encode_XSEncoding(aTHX_ &$sym);\n"; |
e0c49a6b |
193 | } |
017e2add |
194 | |
e0c49a6b |
195 | if ($cname =~ /(\w+)\.xs$/) |
196 | { |
197 | my $mod = $1; |
d811239c |
198 | print C <<'END'; |
199 | |
023d8852 |
200 | static void |
d811239c |
201 | Encode_XSEncoding(pTHX_ encode_t *enc) |
202 | { |
203 | dSP; |
204 | HV *stash = gv_stashpv("Encode::XS", TRUE); |
205 | SV *sv = sv_bless(newRV_noinc(newSViv(PTR2IV(enc))),stash); |
206 | int i = 0; |
207 | PUSHMARK(sp); |
208 | XPUSHs(sv); |
209 | while (enc->name[i]) |
210 | { |
211 | const char *name = enc->name[i++]; |
212 | XPUSHs(sv_2mortal(newSVpvn(name,strlen(name)))); |
213 | } |
214 | PUTBACK; |
215 | call_pv("Encode::define_encoding",G_DISCARD); |
216 | SvREFCNT_dec(sv); |
217 | } |
218 | |
219 | END |
220 | |
e0c49a6b |
221 | print C "\nMODULE = Encode::$mod\tPACKAGE = Encode::$mod\n\n"; |
222 | print C "BOOT:\n{\n"; |
223 | print C "#include \"$dname\"\n"; |
224 | print C "}\n"; |
225 | } |
226 | close(D); |
227 | close(H); |
b1e7e56f |
228 | printf STDERR "%d bytes in string tables\n",$strings; |
229 | printf STDERR "%d bytes (%.3g%%) saved spotting duplicates\n",$saved,100*$saved/$strings if $saved; |
230 | printf STDERR "%d bytes (%.3g%%) saved using substrings\n",$subsave,100*$subsave/$strings if $subsave; |
2f2b4ff2 |
231 | } |
dcda1f94 |
232 | elsif ($doEnc) |
233 | { |
234 | foreach my $name (sort cmp_name keys %encoding) |
235 | { |
236 | my ($e2u,$u2e,$erep,$min_el,$max_el) = @{$encoding{$name}}; |
237 | output_enc(\*C,$name,$e2u); |
238 | } |
239 | } |
240 | elsif ($doUcm) |
241 | { |
242 | foreach my $name (sort cmp_name keys %encoding) |
243 | { |
244 | my ($e2u,$u2e,$erep,$min_el,$max_el) = @{$encoding{$name}}; |
245 | output_ucm(\*C,$name,$u2e,$erep,$min_el,$max_el); |
246 | } |
247 | } |
248 | |
017e2add |
249 | close(C); |
250 | |
9b37254d |
251 | |
b1e7e56f |
252 | |
9b37254d |
253 | sub compile_ucm |
254 | { |
dcda1f94 |
255 | my ($fh,$name) = @_; |
9b37254d |
256 | my $e2u = {}; |
257 | my $u2e = {}; |
258 | my $cs; |
259 | my %attr; |
260 | while (<$fh>) |
261 | { |
262 | s/#.*$//; |
263 | last if /^\s*CHARMAP\s*$/i; |
7ba7f87b |
264 | if (/^\s*<(\w+)>\s+"?([^"]*)"?\s*$/i) # " # Grrr |
9b37254d |
265 | { |
266 | $attr{$1} = $2; |
267 | } |
268 | } |
269 | if (!defined($cs = $attr{'code_set_name'})) |
270 | { |
271 | warn "No <code_set_name> in $name\n"; |
272 | } |
273 | else |
274 | { |
51ef4e11 |
275 | $name = $cs unless exists $opt{'n'}; |
9b37254d |
276 | } |
277 | my $erep; |
278 | my $urep; |
afdae191 |
279 | my $max_el; |
280 | my $min_el; |
9b37254d |
281 | if (exists $attr{'subchar'}) |
282 | { |
afdae191 |
283 | my @byte; |
284 | $attr{'subchar'} =~ /^\s*/cg; |
285 | push(@byte,$1) while $attr{'subchar'} =~ /\G\\x([0-9a-f]+)/icg; |
286 | $erep = join('',map(chr(hex($_)),@byte)); |
9b37254d |
287 | } |
b1e7e56f |
288 | print "Reading $name ($cs)\n"; |
9b37254d |
289 | my $nfb = 0; |
290 | my $hfb = 0; |
291 | while (<$fh>) |
292 | { |
293 | s/#.*$//; |
294 | last if /^\s*END\s+CHARMAP\s*$/i; |
295 | next if /^\s*$/; |
afdae191 |
296 | my ($u,@byte); |
297 | my $fb = ''; |
298 | $u = $1 if (/^<U([0-9a-f]+)>\s+/igc); |
299 | push(@byte,$1) while /\G\\x([0-9a-f]+)/igc; |
300 | $fb = $1 if /\G\s*(\|[0-3])/gc; |
301 | # warn "$_: $u @byte | $fb\n"; |
302 | die "Bad line:$_" unless /\G\s*(#.*)?$/gc; |
9b37254d |
303 | if (defined($u)) |
304 | { |
305 | my $uch = encode_U(hex($u)); |
e0c49a6b |
306 | my $ech = join('',map(chr(hex($_)),@byte)); |
afdae191 |
307 | my $el = length($ech); |
308 | $max_el = $el if (!defined($max_el) || $el > $max_el); |
309 | $min_el = $el if (!defined($min_el) || $el < $min_el); |
9b37254d |
310 | if (length($fb)) |
311 | { |
312 | $fb = substr($fb,1); |
313 | $hfb++; |
314 | } |
315 | else |
316 | { |
317 | $nfb++; |
318 | $fb = '0'; |
319 | } |
320 | # $fb is fallback flag |
321 | # 0 - round trip safe |
322 | # 1 - fallback for unicode -> enc |
323 | # 2 - skip sub-char mapping |
324 | # 3 - fallback enc -> unicode |
325 | enter($u2e,$uch,$ech,$u2e,$fb+0) if ($fb =~ /[01]/); |
326 | enter($e2u,$ech,$uch,$e2u,$fb+0) if ($fb =~ /[03]/); |
327 | } |
328 | else |
329 | { |
330 | warn $_; |
331 | } |
9b37254d |
332 | } |
333 | if ($nfb && $hfb) |
334 | { |
335 | die "$nfb entries without fallback, $hfb entries with\n"; |
336 | } |
dcda1f94 |
337 | $encoding{$name} = [$e2u,$u2e,$erep,$min_el,$max_el]; |
9b37254d |
338 | } |
339 | |
14a8264b |
340 | sub compile_enc |
017e2add |
341 | { |
dcda1f94 |
342 | my ($fh,$name) = @_; |
017e2add |
343 | my $e2u = {}; |
344 | my $u2e = {}; |
345 | |
346 | my $type; |
347 | while ($type = <$fh>) |
348 | { |
349 | last if $type !~ /^\s*#/; |
350 | } |
351 | chomp($type); |
352 | return if $type eq 'E'; |
353 | my ($def,$sym,$pages) = split(/\s+/,scalar(<$fh>)); |
14a8264b |
354 | warn "$type encoded $name\n"; |
017e2add |
355 | my $rep = ''; |
7ba7f87b |
356 | # Save a defined test by setting these to defined values. |
357 | my $min_el = ~0; # A very big integer |
358 | my $max_el = 0; # Anything must be longer than 0 |
017e2add |
359 | { |
360 | my $v = hex($def); |
7ba7f87b |
361 | $rep = &{$encode_types{$type}}($v & 0xFF, ($v >> 8) & 0xffe); |
017e2add |
362 | } |
e03ac092 |
363 | my %seen; |
017e2add |
364 | while ($pages--) |
365 | { |
366 | my $line = <$fh>; |
367 | chomp($line); |
368 | my $page = hex($line); |
369 | my $ch = 0; |
7ba7f87b |
370 | for (0..15) |
017e2add |
371 | { |
372 | my $line = <$fh>; |
7ba7f87b |
373 | die "Line should be exactly 65 characters long including newline" |
374 | unless length ($line) == 65; |
375 | # Split line into groups of 4 hex digits, convert groups to ints |
376 | for my $val (map {hex $_} $line =~ /(....)/g) |
017e2add |
377 | { |
e03ac092 |
378 | next if $val == 0xFFFD; |
7ba7f87b |
379 | my $ech = &{$encode_types{$type}}($ch,$page); |
017e2add |
380 | if ($val || (!$ch && !$page)) |
381 | { |
afdae191 |
382 | my $el = length($ech); |
7ba7f87b |
383 | $max_el = $el if $el > $max_el; |
384 | $min_el = $el if $el < $min_el; |
017e2add |
385 | my $uch = encode_U($val); |
e03ac092 |
386 | if (exists $seen{$uch}) |
387 | { |
388 | warn sprintf("U%04X is %02X%02X and %02X%02X\n", |
389 | $val,$page,$ch,@{$seen{$uch}}); |
390 | } |
391 | else |
392 | { |
393 | $seen{$uch} = [$page,$ch]; |
394 | } |
9b37254d |
395 | enter($e2u,$ech,$uch,$e2u,0); |
396 | enter($u2e,$uch,$ech,$u2e,0); |
017e2add |
397 | } |
398 | else |
399 | { |
400 | # No character at this position |
401 | # enter($e2u,$ech,undef,$e2u); |
402 | } |
403 | $ch++; |
404 | } |
405 | } |
406 | } |
7ba7f87b |
407 | die "\$min_el=$min_el, \$max_el=$max_el - seems we read no lines" |
408 | if $min_el > $max_el; |
dcda1f94 |
409 | $encoding{$name} = [$e2u,$u2e,$rep,$min_el,$max_el]; |
017e2add |
410 | } |
411 | |
412 | sub enter |
413 | { |
9b37254d |
414 | my ($a,$s,$d,$t,$fb) = @_; |
017e2add |
415 | $t = $a if @_ < 4; |
de745a2e |
416 | |
417 | while (1) { |
418 | $s =~ s/(.)//s; |
419 | my $b = $1; |
420 | my $e = $a->{$b}; |
421 | # 0 1 2 3 4 5 |
422 | $a->{$b} = $e = [$b,$b,'',{},1+length($s),0,$fb] unless $e; |
423 | unless (length($s)) { |
017e2add |
424 | $e->[2] = $d; |
425 | $e->[3] = $t; |
426 | $e->[5] = length($d); |
de745a2e |
427 | return; |
017e2add |
428 | } |
de745a2e |
429 | # Tail recursion. |
430 | $a = $e->[3]; |
431 | } |
017e2add |
432 | } |
433 | |
b1e7e56f |
434 | |
435 | |
017e2add |
436 | sub outstring |
437 | { |
438 | my ($fh,$name,$s) = @_; |
439 | my $sym = $strings{$s}; |
b1e7e56f |
440 | if ($sym) |
441 | { |
442 | $saved += length($s); |
443 | } |
444 | else |
017e2add |
445 | { |
4cfc977c |
446 | if ($opt{'O'}) { |
447 | foreach my $o (keys %strings) |
448 | { |
449 | my $i = index($o,$s); |
450 | if ($i >= 0) |
451 | { |
452 | $sym = $strings{$o}; |
453 | $sym .= sprintf("+0x%02x",$i) if ($i); |
454 | $subsave += length($s); |
455 | $strings{$s} = $sym; |
456 | return $sym; |
457 | } |
458 | } |
459 | } |
017e2add |
460 | $strings{$s} = $sym = $name; |
b1e7e56f |
461 | $strings += length($s); |
de745a2e |
462 | my $definition = sprintf "static const U8 %s[%d] = { ",$name,length($s); |
463 | # Maybe we should assert that these are all <256. |
464 | $definition .= join(',',unpack "C*",$s); |
465 | # We have a single long line. Split it at convenient commas. |
466 | $definition =~ s/(.{74,77},)/$1\n/g; |
467 | print $fh "$definition };\n\n"; |
017e2add |
468 | } |
469 | return $sym; |
470 | } |
471 | |
14a8264b |
472 | sub process |
017e2add |
473 | { |
14a8264b |
474 | my ($name,$a) = @_; |
017e2add |
475 | $name =~ s/\W+/_/g; |
476 | $a->{Cname} = $name; |
7ba7f87b |
477 | my @keys = sort grep(ref($a->{$_}),keys %$a); |
017e2add |
478 | my $l; |
479 | my @ent; |
480 | foreach my $b (@keys) |
481 | { |
7ba7f87b |
482 | my ($s,undef,undef,$t,undef) = @{$a->{$b}}; |
017e2add |
483 | if (defined($l) && |
484 | ord($b) == ord($a->{$l}[1])+1 && |
485 | $a->{$l}[3] == $a->{$b}[3] && |
486 | $a->{$l}[4] == $a->{$b}[4] && |
9b37254d |
487 | $a->{$l}[5] == $a->{$b}[5] && |
488 | $a->{$l}[6] == $a->{$b}[6] |
2f2b4ff2 |
489 | # && length($a->{$l}[2]) < 16 |
490 | ) |
017e2add |
491 | { |
492 | my $i = ord($b)-ord($a->{$l}[0]); |
493 | $a->{$l}[1] = $b; |
494 | $a->{$l}[2] .= $a->{$b}[2]; |
495 | } |
496 | else |
497 | { |
498 | $l = $b; |
499 | push(@ent,$b); |
500 | } |
14a8264b |
501 | if (exists $t->{Cname}) |
017e2add |
502 | { |
14a8264b |
503 | $t->{'Forward'} = 1 if $t != $a; |
504 | } |
505 | else |
506 | { |
507 | process(sprintf("%s_%02x",$name,ord($s)),$t); |
017e2add |
508 | } |
509 | } |
510 | if (ord($keys[-1]) < 255) |
511 | { |
512 | my $t = chr(ord($keys[-1])+1); |
513 | $a->{$t} = [$t,chr(255),undef,$a,0,0]; |
514 | push(@ent,$t); |
515 | } |
14a8264b |
516 | $a->{'Entries'} = \@ent; |
517 | } |
518 | |
519 | sub outtable |
520 | { |
521 | my ($fh,$a) = @_; |
522 | my $name = $a->{'Cname'}; |
017e2add |
523 | # String tables |
14a8264b |
524 | foreach my $b (@{$a->{'Entries'}}) |
017e2add |
525 | { |
526 | next unless $a->{$b}[5]; |
527 | my $s = ord($a->{$b}[0]); |
528 | my $e = ord($a->{$b}[1]); |
529 | outstring($fh,sprintf("%s__%02x_%02x",$name,$s,$e),$a->{$b}[2]); |
530 | } |
14a8264b |
531 | if ($a->{'Forward'}) |
532 | { |
533 | print $fh "\nstatic encpage_t $name\[",scalar(@{$a->{'Entries'}}),"];\n"; |
534 | } |
535 | $a->{'Done'} = 1; |
536 | foreach my $b (@{$a->{'Entries'}}) |
537 | { |
538 | my ($s,$e,$out,$t,$end,$l) = @{$a->{$b}}; |
539 | outtable($fh,$t) unless $t->{'Done'}; |
540 | } |
541 | print $fh "\nstatic encpage_t $name\[",scalar(@{$a->{'Entries'}}),"] = {\n"; |
542 | foreach my $b (@{$a->{'Entries'}}) |
017e2add |
543 | { |
9b37254d |
544 | my ($s,$e,$out,$t,$end,$l,$fb) = @{$a->{$b}}; |
017e2add |
545 | my $sc = ord($s); |
546 | my $ec = ord($e); |
e0c49a6b |
547 | $end |= 0x80 if $fb; |
017e2add |
548 | print $fh "{"; |
549 | if ($l) |
550 | { |
551 | printf $fh outstring($fh,'',$out); |
552 | } |
553 | else |
554 | { |
555 | print $fh "0"; |
556 | } |
557 | print $fh ",",$t->{Cname}; |
2f2b4ff2 |
558 | printf $fh ",0x%02x,0x%02x,$l,$end},\n",$sc,$ec; |
017e2add |
559 | } |
14a8264b |
560 | print $fh "};\n"; |
561 | } |
562 | |
563 | sub output |
564 | { |
565 | my ($fh,$name,$a) = @_; |
566 | process($name,$a); |
567 | # Sub-tables |
568 | outtable($fh,$a); |
017e2add |
569 | } |
570 | |
e0c49a6b |
571 | sub output_enc |
572 | { |
573 | my ($fh,$name,$a) = @_; |
574 | foreach my $b (sort keys %$a) |
575 | { |
576 | my ($s,$e,$out,$t,$end,$l,$fb) = @{$a->{$b}}; |
577 | } |
578 | } |
579 | |
580 | sub decode_U |
581 | { |
582 | my $s = shift; |
e0c49a6b |
583 | } |
584 | |
f39fb8cc |
585 | my @uname; |
586 | sub char_names |
587 | { |
9fb51cbc |
588 | my $s = do "unicore/Name.pl"; |
589 | die "char_names: unicore/Name.pl: $!\n" unless defined $s; |
f39fb8cc |
590 | pos($s) = 0; |
591 | while ($s =~ /\G([0-9a-f]+)\t([0-9a-f]*)\t(.*?)\s*\n/igc) |
592 | { |
593 | my $name = $3; |
594 | my $s = hex($1); |
595 | last if $s >= 0x10000; |
596 | my $e = length($2) ? hex($2) : $s; |
597 | for (my $i = $s; $i <= $e; $i++) |
598 | { |
599 | $uname[$i] = $name; |
600 | # print sprintf("U%04X $name\n",$i); |
601 | } |
602 | } |
603 | } |
604 | |
e0c49a6b |
605 | sub output_ucm_page |
606 | { |
f39fb8cc |
607 | my ($cmap,$a,$t,$pre) = @_; |
e0c49a6b |
608 | # warn sprintf("Page %x\n",$pre); |
609 | foreach my $b (sort keys %$t) |
610 | { |
611 | my ($s,$e,$out,$n,$end,$l,$fb) = @{$t->{$b}}; |
612 | die "oops $s $e" unless $s eq $e; |
613 | my $u = ord($s); |
614 | if ($n != $a && $n != $t) |
615 | { |
f39fb8cc |
616 | output_ucm_page($cmap,$a,$n,(($pre|($u &0x3F)) << 6)&0xFFFF); |
e0c49a6b |
617 | } |
618 | elsif (length($out)) |
619 | { |
620 | if ($pre) |
621 | { |
622 | $u = $pre|($u &0x3f); |
623 | } |
f39fb8cc |
624 | my $s = sprintf "<U%04X> ",$u; |
e0c49a6b |
625 | foreach my $c (split(//,$out)) |
626 | { |
f39fb8cc |
627 | $s .= sprintf "\\x%02X",ord($c); |
e0c49a6b |
628 | } |
f39fb8cc |
629 | $s .= sprintf " |%d # %s\n",($fb ? 1 : 0),$uname[$u]; |
630 | push(@$cmap,$s); |
e0c49a6b |
631 | } |
632 | else |
633 | { |
634 | warn join(',',@{$t->{$b}},$a,$t); |
635 | } |
636 | } |
637 | } |
638 | |
639 | sub output_ucm |
640 | { |
f39fb8cc |
641 | my ($fh,$name,$h,$rep,$min_el,$max_el) = @_; |
df1df145 |
642 | print $fh "# $0 @orig_ARGV\n" unless $opt{'q'}; |
afdae191 |
643 | print $fh "<code_set_name> \"$name\"\n"; |
f39fb8cc |
644 | char_names(); |
afdae191 |
645 | if (defined $min_el) |
646 | { |
647 | print $fh "<mb_cur_min> $min_el\n"; |
648 | } |
649 | if (defined $max_el) |
650 | { |
651 | print $fh "<mb_cur_max> $max_el\n"; |
652 | } |
653 | if (defined $rep) |
654 | { |
655 | print $fh "<subchar> "; |
656 | foreach my $c (split(//,$rep)) |
657 | { |
658 | printf $fh "\\x%02X",ord($c); |
659 | } |
660 | print $fh "\n"; |
661 | } |
f39fb8cc |
662 | my @cmap; |
663 | output_ucm_page(\@cmap,$h,$h,0); |
afdae191 |
664 | print $fh "#\nCHARMAP\n"; |
f39fb8cc |
665 | foreach my $line (sort { substr($a,8) cmp substr($b,8) } @cmap) |
666 | { |
667 | print $fh $line; |
668 | } |
e0c49a6b |
669 | print $fh "END CHARMAP\n"; |
670 | } |
017e2add |
671 | |