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