w3m

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

mk_viet_ucs_map.pl (1673B)


      1 
      2 @NAME = ();
      3 while(<DATA>) {
      4   chop;
      5   s/\s*$//;
      6   (($n, $m, $c) = split(" ", $_, 3)) >= 3 || next;
      7   push(@NAME, $n);
      8   $MAP{$n} = $m;
      9   $CODE{$n} = $c;
     10 }
     11 
     12 foreach $name (@NAME) {
     13 
     14 $code = $CODE{$name};
     15 $map = $MAP{$name};
     16 
     17 print "$name\t$map\t$code\n";
     18 
     19 @to_ucs = ();
     20 %from_ucs = ();
     21 open(MAP, "< $map");
     22 open(OUT, "> ${name}_ucs.map");
     23 while(<MAP>) {
     24   /^0/ || next;
     25   (($i, $u) = split(" ")) || next;
     26   $i = hex($i);
     27   $u = hex($u);
     28   if ($u > 0x7f) {
     29     $to_ucs[$i] = $u;
     30     $from_ucs{$u} = $i;
     31   }
     32 }
     33 
     34 # print OUT <<EOF;
     35 # /*
     36 #   These conversion tables between $code and
     37 #   Unicode were made from
     38 # 
     39 #     http://www.vnet.org/vanlangsj/mozilla/$map.
     40 # */
     41 print OUT <<EOF;
     42 /* $code */
     43 
     44 static wc_uint16 ${name}1_ucs_map[ 0x80 ] = {
     45 EOF
     46 
     47 foreach $i (0x10 .. 0x1F) {
     48   print OUT " ";
     49 foreach $j (0 .. 7) {
     50   $_ = $i * 8 + $j;
     51   $u = $to_ucs[$_];
     52   if ($u) {
     53     printf OUT " 0x%.4X,", $u;
     54   } else {
     55     print OUT " 0,     ";
     56   }
     57 }
     58   print OUT "\n";
     59 }
     60 
     61 print OUT <<EOF;
     62 };
     63 
     64 static wc_uint16 ${name}2_ucs_map[ 0x20 ] = {
     65 EOF
     66 
     67 foreach $i (0x0 .. 0x3) {
     68   print OUT " ";
     69 foreach $j (0 .. 7) {
     70   $_ = $i * 8 + $j;
     71   $u = $to_ucs[$_];
     72   if ($u) {
     73     printf OUT " 0x%.4X,", $u;
     74   } else {
     75     print OUT " 0,     ";
     76   }
     77 }
     78   print OUT "\n";
     79 }
     80 
     81 
     82 @ucs = sort { $a <=> $b } keys %from_ucs;
     83 $nucs = @ucs + 0;
     84 
     85 print OUT <<EOF;
     86 };
     87 
     88 #define N_ucs_${name}_map $nucs
     89 
     90 static wc_map ucs_${name}_map[ N_ucs_${name}_map ] = {
     91 EOF
     92 for(@ucs) {
     93   printf OUT "  { 0x%.4X, 0x%.2X },\n", $_, $from_ucs{$_};
     94 }
     95 
     96 print OUT <<EOF;
     97 };
     98 EOF
     99 
    100 close(MAP);
    101 }
    102 
    103 __END__
    104 tcvn5712	tcvn_uni.txt		TCVN-5712 VN-1 (Vietnamese)
    105 viscii11	vis_uni.txt		VISCII 1.1 (Vietnamese)
    106 vps		vps_uni.txt		VPS (Vietnamese)
    107