1*4882a593Smuzhiyun#!/usr/bin/perl -w 2*4882a593Smuzhiyun# 3*4882a593Smuzhiyun# winucase_convert.pl -- convert "Windows 8 Upper Case Mapping Table.txt" to 4*4882a593Smuzhiyun# a two-level set of C arrays. 5*4882a593Smuzhiyun# 6*4882a593Smuzhiyun# Copyright 2013: Jeff Layton <jlayton@redhat.com> 7*4882a593Smuzhiyun# 8*4882a593Smuzhiyun# This program is free software: you can redistribute it and/or modify 9*4882a593Smuzhiyun# it under the terms of the GNU General Public License as published by 10*4882a593Smuzhiyun# the Free Software Foundation, either version 3 of the License, or 11*4882a593Smuzhiyun# (at your option) any later version. 12*4882a593Smuzhiyun# 13*4882a593Smuzhiyun# This program is distributed in the hope that it will be useful, 14*4882a593Smuzhiyun# but WITHOUT ANY WARRANTY; without even the implied warranty of 15*4882a593Smuzhiyun# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16*4882a593Smuzhiyun# GNU General Public License for more details. 17*4882a593Smuzhiyun# 18*4882a593Smuzhiyun# You should have received a copy of the GNU General Public License 19*4882a593Smuzhiyun# along with this program. If not, see <https://www.gnu.org/licenses/>. 20*4882a593Smuzhiyun# 21*4882a593Smuzhiyun 22*4882a593Smuzhiyunwhile(<>) { 23*4882a593Smuzhiyun next if (!/^0x(..)(..)\t0x(....)\t/); 24*4882a593Smuzhiyun $firstchar = hex($1); 25*4882a593Smuzhiyun $secondchar = hex($2); 26*4882a593Smuzhiyun $uppercase = hex($3); 27*4882a593Smuzhiyun 28*4882a593Smuzhiyun $top[$firstchar][$secondchar] = $uppercase; 29*4882a593Smuzhiyun} 30*4882a593Smuzhiyun 31*4882a593Smuzhiyunfor ($i = 0; $i < 256; $i++) { 32*4882a593Smuzhiyun next if (!$top[$i]); 33*4882a593Smuzhiyun 34*4882a593Smuzhiyun printf("static const wchar_t t2_%2.2x[256] = {", $i); 35*4882a593Smuzhiyun for ($j = 0; $j < 256; $j++) { 36*4882a593Smuzhiyun if (($j % 8) == 0) { 37*4882a593Smuzhiyun print "\n\t"; 38*4882a593Smuzhiyun } else { 39*4882a593Smuzhiyun print " "; 40*4882a593Smuzhiyun } 41*4882a593Smuzhiyun printf("0x%4.4x,", $top[$i][$j] ? $top[$i][$j] : 0); 42*4882a593Smuzhiyun } 43*4882a593Smuzhiyun print "\n};\n\n"; 44*4882a593Smuzhiyun} 45*4882a593Smuzhiyun 46*4882a593Smuzhiyunprintf("static const wchar_t *const toplevel[256] = {", $i); 47*4882a593Smuzhiyunfor ($i = 0; $i < 256; $i++) { 48*4882a593Smuzhiyun if (($i % 8) == 0) { 49*4882a593Smuzhiyun print "\n\t"; 50*4882a593Smuzhiyun } elsif ($top[$i]) { 51*4882a593Smuzhiyun print " "; 52*4882a593Smuzhiyun } else { 53*4882a593Smuzhiyun print " "; 54*4882a593Smuzhiyun } 55*4882a593Smuzhiyun 56*4882a593Smuzhiyun if ($top[$i]) { 57*4882a593Smuzhiyun printf("t2_%2.2x,", $i); 58*4882a593Smuzhiyun } else { 59*4882a593Smuzhiyun print "NULL,"; 60*4882a593Smuzhiyun } 61*4882a593Smuzhiyun} 62*4882a593Smuzhiyunprint "\n};\n\n"; 63