userlibandfileserver/fatfilenameconversionplugins/group/cp54936_allbmp_fromunicode.pl
branchanywhere
changeset 41 d32f34975bbf
parent 40 04a1b74efd48
parent 37 a9bf1d2c555e
child 48 10816385149a
equal deleted inserted replaced
40:04a1b74efd48 41:d32f34975bbf
     1 #
       
     2 # Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 # All rights reserved.
       
     4 # This component and the accompanying materials are made available
       
     5 # under the terms of "Eclipse Public License v1.0"
       
     6 # which accompanies this distribution, and is available
       
     7 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 #
       
     9 # Initial Contributors:
       
    10 # Nokia Corporation - initial contribution.
       
    11 #
       
    12 # Contributors:
       
    13 #
       
    14 # Description: 
       
    15 # See line 99 of this file.
       
    16 #
       
    17 
       
    18 if (@ARGV != 2 && @ARGV != 3)
       
    19 	{
       
    20 	print <<EOD;
       
    21 Usage: cp54936_allbmp_fromunicode.pl cp54936_2byte.txt cp54936_4byte.txt cp54936_allbmp_fromunicode.cpp
       
    22 EOD
       
    23 	exit(1);
       
    24 	}
       
    25 
       
    26 my $root = "cp54936_allbmp_fromunicode.cpp";
       
    27 if (@ARGV == 3)
       
    28 	{
       
    29 	$root = $ARGV[3];
       
    30 	}
       
    31 
       
    32 
       
    33 my %lines;	# the hash table to hold all characters with key=unicode(dec) and value=foreign(string)
       
    34 
       
    35 
       
    36 # read 2 byte input file
       
    37 open (IN2, "<$ARGV[0]") or die ("Error: $ARGV[0] $!");
       
    38 my $lineNumber = 0;
       
    39 my $acceptLineNumber = 0;
       
    40 while (!eof(IN2))
       
    41 	{
       
    42 	my $line = <IN2>;
       
    43 	$lineNumber++;
       
    44 	if ($line =~ /^(0[xX][\da-fA-F]{1,4})\s*(0[xX][\da-fA-F]{1,4}).*/)
       
    45 		{
       
    46 		$acceptLineNumber++;
       
    47 		my $foreign = $1;
       
    48 		my $unicode = hex($2);
       
    49 		if (exists ($lines{$unicode}))
       
    50 			{
       
    51 			print "ERROR: Unicode $unicode is reused by $lines{$unicode} and $foreign.\n";
       
    52 			exit(1);
       
    53 			}
       
    54 		$lines{$unicode} = $foreign;
       
    55 		}
       
    56 	else
       
    57 		{
       
    58 		#print "Ignore line: $line";
       
    59 		}
       
    60 	}
       
    61 close IN2;
       
    62 print "\nRead $ARGV[0] done.\n";
       
    63 print "$acceptLineNumber of $lineNumber lines accepted.\n\n";
       
    64 
       
    65 
       
    66 # read 4 byte input file
       
    67 open (IN4, "<$ARGV[1]") or die ("Error: $ARGV[1] $!");
       
    68 $lineNumber = 0;
       
    69 $acceptLineNumber = 0;
       
    70 while (!eof(IN4))
       
    71 	{
       
    72 	my $line = <IN4>;
       
    73 	$lineNumber++;
       
    74 	if ($line =~ /^(0[xX]8[1-4]3\d[\da-fA-F]{2}3\d)\s*(0[xX][\da-fA-F]{4}).*/)
       
    75 		{
       
    76 		$acceptLineNumber++;
       
    77 		my $foreign = $1;
       
    78 		my $unicode = hex($2);
       
    79 		if (exists ($lines{$unicode}))
       
    80 			{
       
    81 			print "ERROR: Unicode $unicode is reused by $lines{$unicode} and $foreign.\n";
       
    82 			exit(1);
       
    83 			}
       
    84 		$lines{$unicode} = $foreign;
       
    85 		}
       
    86 	else
       
    87 		{
       
    88 		#print "Ignore line: $line";
       
    89 		}
       
    90 	}
       
    91 close IN4;
       
    92 print "Read $ARGV[1] done.\n";
       
    93 print "$acceptLineNumber of $lineNumber lines accepted.\n\n";
       
    94 
       
    95 
       
    96 # write to output file
       
    97 print "Write to $root...\n";
       
    98 open (CPP, ">$root") or die ("Error: Can't open cpp file");
       
    99 print CPP <<EOD;
       
   100 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
   101 // All rights reserved.
       
   102 // This component and the accompanying materials are made available
       
   103 // under the terms of the License "Eclipse Public License v1.0"
       
   104 // which accompanies this distribution, and is available
       
   105 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
   106 //
       
   107 // Initial Contributors:
       
   108 // Nokia Corporation - initial contribution.
       
   109 //
       
   110 // Contributors:
       
   111 //
       
   112 // Description:
       
   113 //
       
   114 // Generated by the cp54936_allbmp_fromunicode.pl tool - Do not edit!!!
       
   115 // Generated with \"perl -w ..\\group\\cp54936_allbmp_fromunicode.pl cp54936_2byte.txt cp54936_4byte.txt\".
       
   116 //
       
   117 
       
   118 #include <e32std.h>
       
   119 #include <e32def.h>
       
   120 #include "cp54936.h"
       
   121 
       
   122 const TUint8 KForeignReplacement = 0x5F;
       
   123 
       
   124 EOD
       
   125 print CPP "const TUint32 KMappingTableUnicodeBmp2CP54936\[65536\] = \n";
       
   126 print CPP "\t\{\n\t";
       
   127 
       
   128 my $bytecount = 0;
       
   129 my $expectUnicode = 0;
       
   130 while ($expectUnicode <= 0xFFFF)
       
   131 	{
       
   132 	if (exists ($lines{$expectUnicode}))
       
   133 		{
       
   134 		print CPP "$lines{$expectUnicode}, ";
       
   135 		}
       
   136 	else
       
   137 		{
       
   138 		print CPP "KForeignReplacement, ";
       
   139 		}
       
   140 	$bytecount += 4;
       
   141 	$expectUnicode++;
       
   142 	if (($expectUnicode % 16) == 0)
       
   143 		{
       
   144 		print CPP sprintf("// %04X - %04X\n\t", $expectUnicode-16, $expectUnicode-1);
       
   145 		}
       
   146 	}
       
   147 print CPP "};\t";
       
   148 
       
   149 $bytecount += 8;
       
   150 print CPP "// total byte count = $bytecount\n";
       
   151 print "\nTotal byte count: $bytecount.\n";
       
   152 close CPP;
       
   153 
       
   154 print "\nDone.";