userlibandfileserver/fatfilenameconversionplugins/group/cp54936_4byte_tounicode.pl
changeset 0 a41df078684a
child 2 4122176ea935
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     1 # Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 # All rights reserved.
       
     3 # This component and the accompanying materials are made available
       
     4 # under the terms of the License "Eclipse Public License v1.0"
       
     5 # which accompanies this distribution, and is available
       
     6 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 #
       
     8 # Initial Contributors:
       
     9 # Nokia Corporation - initial contribution.
       
    10 #
       
    11 # Contributors:
       
    12 #
       
    13 # Description:
       
    14 # See line 111 of this file.
       
    15 #
       
    16 
       
    17 if (@ARGV != 1 && @ARGV != 2)
       
    18 	{
       
    19 	print <<EOD;
       
    20 Usage: perl -w cp54936_4byte.pl cp54936_4byte.txt
       
    21 EOD
       
    22 	exit(1);
       
    23 	}
       
    24 
       
    25 # Removes the extenstion from the filename
       
    26 $ARGV[0] =~ m/(.*)\..*/;
       
    27 my $root = $1;
       
    28 $root =~ m/.*[\\\/]([^\\\/]*)$/;
       
    29 my $header_to_include = $1;
       
    30 
       
    31 if (@ARGV == 2)
       
    32 	{
       
    33 	$ARGV[1] =~ m/(.*)\..*/;
       
    34 	$root = $1;
       
    35 	}
       
    36 
       
    37 open (IN, "<$ARGV[0]") or die ("Error: $ARGV[0] $!");
       
    38 
       
    39 my $lineNumber = 0;
       
    40 my $acceptLineNumber = 0;
       
    41 my %lines;		# hash table of all characters in format with key=foreign(string) and value=unicode(string)
       
    42 while (!eof(IN))
       
    43 	{
       
    44 	my $line = <IN>;
       
    45 	$lineNumber++;
       
    46 	if ($line =~ /^(0[xX]8[1-4]3\d[\da-fA-F]{2}3\d)\s*(0[xX][\da-fA-F]{4}).*/)
       
    47 		{
       
    48 		# read a line like "0x81318133	0x060D"
       
    49 		$acceptLineNumber++;
       
    50 		my $foreign = $1;
       
    51 		my $unicode = $2;
       
    52 		$lines{$foreign} = $unicode;
       
    53 		}
       
    54 	else
       
    55 		{
       
    56 		#print "Ignore line: $line";
       
    57 		}
       
    58 	}
       
    59 close IN;
       
    60 print "Read $ARGV[0] done.\n";
       
    61 print "$acceptLineNumber of $lineNumber lines accepted.\n";
       
    62 
       
    63 
       
    64 # increase input cp54936 code by 1
       
    65 # param is a string like "0x81308439"
       
    66 # return a string like "0x81308530"
       
    67 sub IncreaseCP54936Code
       
    68 	{
       
    69 	my ($increaseme) = @_;
       
    70 	$increaseme =~ /0[xX]([\da-fA-F]{2})([\da-fA-F]{2})([\da-fA-F]{2})([\da-fA-F]{2})/;
       
    71 	($b1, $b2, $b3, $b4) = (hex($1), hex($2), hex($3), hex($4));
       
    72 	$b4++;
       
    73 	if ($b4 == 0x3A)
       
    74 		{
       
    75 		$b4 = 0x30;
       
    76 		$b3++;
       
    77 		if ($b3 == 0xFF)
       
    78 			{
       
    79 			$b3 = 0x81;
       
    80 			$b2++;
       
    81 			if ($b2 == 0x3A)
       
    82 				{
       
    83 				$b2 = 0x30;
       
    84 				$b1++;
       
    85 				}
       
    86 			}
       
    87 		}
       
    88 	return sprintf("0x%02X%02X%02X%02X", $b1, $b2, $b3, $b4);
       
    89 	}
       
    90 
       
    91 # return the offset from 0x81308130 to input "0x8234A235"
       
    92 sub OffsetOfCP54936Code
       
    93 	{
       
    94 	$_[0] =~ /0[xX]([\da-fA-F]{2})([\da-fA-F]{2})([\da-fA-F]{2})([\da-fA-F]{2})/;
       
    95 	($b1, $b2, $b3, $b4) = (hex($1), hex($2), hex($3), hex($4));
       
    96 	return ($b1-0x81)*12600 + ($b2-0x30)*1260 + ($b3-0x81)*10 + ($b4-0x30);
       
    97 	}
       
    98 
       
    99 # return the last byte of input "0x8234A235"
       
   100 sub Byte4OfCP54936Code
       
   101 	{
       
   102 	$_[0] =~ /0[xX]([\da-fA-F]{2})([\da-fA-F]{2})([\da-fA-F]{2})([\da-fA-F]{2})/;
       
   103 	return hex($4);
       
   104 	}
       
   105 
       
   106 
       
   107 print "Write to $root.cpp...\n";
       
   108 open (CPP, ">$root.cpp") or die ("Error: $ARGV[0] Can't open cpp file");
       
   109 
       
   110 print CPP <<EOD;
       
   111 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
   112 // All rights reserved.
       
   113 // This component and the accompanying materials are made available
       
   114 // under the terms of the License "Eclipse Public License v1.0"
       
   115 // which accompanies this distribution, and is available
       
   116 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
   117 //
       
   118 // Initial Contributors:
       
   119 // Nokia Corporation - initial contribution.
       
   120 //
       
   121 // Contributors:
       
   122 //
       
   123 // Description:
       
   124 //
       
   125 // Auto-generated by the cp54936_4byte_tounicode.pl tool - Do not edit!!!
       
   126 //
       
   127 
       
   128 #include <e32std.h>
       
   129 #include <e32def.h>
       
   130 #include "cp54936.h"
       
   131 
       
   132 
       
   133 // mapping table of: CP54936 4-byte in-BMP ---> Unicode
       
   134 // To calculate index: index=(b1-144)*12600+(b2-48)*1260+(b3-129)*10+(b4-48), in which,
       
   135 // b1,b2,b3,b4 is byte1,2,3,4 of CP54936 code.
       
   136 // For example, CP54936 code 0x8232EA38, the index=(0x82-144)*12600+(0x32-48)*1260+(0xEA-129)*10+(0x38-48)=16178
       
   137 // So we get the Unicode 0x42AB.
       
   138 // Generated with: \"perl -w ..\\group\\cp54936_4byte_tounicode.pl cp54936_4byte.txt cp54936_4byte_tounicode.cpp\".
       
   139 
       
   140 EOD
       
   141 
       
   142 my $bytecount = 0;
       
   143 my $expect = "0x81308130";
       
   144 my $last = "0x8431A439";
       
   145 my $totalCount = OffsetOfCP54936Code($last) + 1;
       
   146 
       
   147 
       
   148 print CPP "const TUint16 KMappingTable4ByteBmp2Unicode[$totalCount] =\n\t{\n\t";
       
   149 
       
   150 my $outIndex = 0;	# to wrap every 10 items
       
   151 while (OffsetOfCP54936Code($expect) <= OffsetOfCP54936Code($last))
       
   152 	{
       
   153 	if (!exists($lines{$expect}))
       
   154 		{
       
   155 		print CPP "0xFFFD, ";
       
   156 		}
       
   157 	else
       
   158 		{
       
   159 		print CPP "$lines{$expect}, ";
       
   160 		}
       
   161 	$bytecount += 2;
       
   162 	$outIndex++;
       
   163 	if ($outIndex % 10 == 0)
       
   164 		{
       
   165 		print CPP "\t// $expect\n\t";
       
   166 		}
       
   167 	# to next foreign
       
   168 	$expect = IncreaseCP54936Code($expect);
       
   169 	}
       
   170 
       
   171 print CPP "};\n";
       
   172 print CPP "// total byte count = $bytecount\n";
       
   173 print "\nTotal byte count: $bytecount.\n";
       
   174 close CPP;
       
   175 print "Done.\n";