w3m

Unnamed repository; edit this file to name it for gitweb.
git clone https://logand.com/git/w3m.git/
Log | Files | Refs | README

mk_big5_ucs_map.pl (1366B)


      1 
      2 @NAME = ();
      3 while(<DATA>) {
      4 	chop;
      5 	s/\s+$//;
      6 	(($n, $m, $d) = split(" ", $_, 3)) >= 3 || next;
      7 	push(@NAME, $n);
      8 	$MAP{$n} = $m;
      9 	$DESC{$n} = $d;
     10 }
     11 
     12 @to_ucs = ();
     13 %from_ucs = ();
     14 
     15 foreach $name (@NAME) {
     16 
     17 $map = $MAP{$name};
     18 $desc = $DESC{$name};
     19 print STDERR "$name\t$map\t$desc\n";
     20 
     21 open(MAP, "< $map");
     22 while(<MAP>) {
     23 	(($c, $u) = split(" ")) || next;
     24 	$c = hex($c);
     25 	$u = hex($u);
     26 	$to_ucs[$c] && next;
     27 	if (($c >= 0xA140 && $c <= 0xF9FE) &&
     28 	    (($u > 0 && $u < 0xE000) || $u > 0xF8FF)) {
     29 		$to_ucs[$c] = $u;
     30 		$from_ucs{$u} = $c;
     31 		$i++;
     32 	}
     33 }
     34 close(MAP);
     35 
     36 }
     37 
     38 $name = $NAME[0];
     39 $desc = $DESC{$name};
     40 
     41 open(OUT, "> ${name}_ucs.map");
     42 
     43 print OUT <<EOF;
     44 /* $desc */
     45 
     46 static wc_uint16 ${name}_ucs_map[ 0x59 * 0x9D ] = {
     47 EOF
     48 
     49 for $i (0xA1 .. 0xF9) {
     50 for $j (0x40 .. 0x7E, 0xA1 .. 0xFE) {
     51   $_ = $i * 0x100 + $j;
     52   $u = $to_ucs[$_];
     53   if ($u) {
     54     printf OUT " 0x%.4X,", $u;
     55   } else {
     56     print OUT " 0,\t";
     57   }
     58   printf OUT "\t/* 0x%.4X */\n", $_;
     59 }
     60 }
     61 
     62 @ucs = sort { $a <=> $b } keys %from_ucs;
     63 $nucs = @ucs + 0;
     64 
     65 print OUT <<EOF;
     66 };
     67 
     68 #define N_ucs_${name}_map $nucs
     69 /*
     70     UCS-2   Big5
     71 */
     72 static wc_map ucs_${name}_map[ N_ucs_${name}_map ] = {
     73 EOF
     74 for(@ucs) {
     75   $x = $from_ucs{$_};
     76   printf OUT "  { 0x%.4X, 0x%.4X },\n", $_, $x;
     77 }
     78 
     79 print OUT <<EOF;
     80 };
     81 EOF
     82 
     83 __END__
     84 big5	private/big5.txt	Big5 (Chinese Taiwan)
     85 hkscs	private/hkscs.txt	HKSCS (Chinese Hong Kong)