1#!/usr/local/bin/perl 2 3use Text::Iconv; 4use Encode; 5use strict; 6use utf8; 7 8# directories and filenames 9$0 =~ m:^(.*)/:; 10my $dir_convtool = $1 || "."; 11 12my $dir_keymaps_syscons = "/usr/src/share/syscons/keymaps"; 13my $dir_keymaps_config = "$dir_convtool"; 14 15my $dir_keymaps_vt = "/usr/src/share/vt/keymaps"; 16my $dir_keymaps_output = "$dir_keymaps_vt/OUTPUT"; 17 18my $keymap_index = "$dir_keymaps_syscons/INDEX.keymaps"; 19 20my $language_map = "$dir_keymaps_config/LANG.map"; 21my $keymapfile_map = "$dir_keymaps_config/KBDFILES.map"; 22 23# global variables 24my %LANG_NEW; # index: lang_old 25my %ENCODING; # index: lang_old, file_old 26my %FILE_NEW; # index: file_old 27 28# subroutines 29sub local_to_UCS_string 30{ 31 my ($string, $old_enc) = @_; 32 my $converter = Text::Iconv->new($old_enc, "UTF-8"); 33 my $result = $converter->convert($string); 34 printf "!!! conversion failed for '$string' ($old_enc)\n" 35 unless $result; 36 return $result; 37} 38 39sub lang_fixup { 40 my ($langlist) = @_; 41 my $result; 42 my $lang; 43 for $lang (split(/,/, $langlist)) { 44 $result .= "," 45 if $result; 46 $result .= $LANG_NEW{$lang}; 47 } 48 return $result; 49} 50 51# main program 52open LANGMAP, "<$language_map" 53 or die "$!"; 54while (<LANGMAP>) { 55 next 56 if m/^#/; 57 my ($lang_old, $lang_new, $encoding) = split(" "); 58# print "$lang_old|$lang_new|$encoding\n"; 59 $LANG_NEW{$lang_old} = $lang_new; 60 $ENCODING{$lang_old} = $encoding; 61 $ENCODING{$lang_new} = $encoding; 62} 63close LANGMAP; 64 65$FILE_NEW{"MENU"} = "MENU"; # dummy identity mapping 66$FILE_NEW{"FONT"} = "FONT"; # dummy identity mapping 67open FILEMAP, "<$keymapfile_map" 68 or die "$!"; 69while (<FILEMAP>) { 70 next 71 if m/^#/; 72 my ($encoding, $file_old, $file_new) = split(" "); 73# print "--> ", join("|", $encoding, $file_old, $file_new, $file_locale), "\n"; 74 if ($encoding and $file_old and $file_new) { 75 $ENCODING{$file_old} = $encoding; 76 $FILE_NEW{$file_old} = $file_new; 77 } 78} 79close FILEMAP; 80 81my $kbdfile; 82foreach $kbdfile (glob("$dir_keymaps_syscons/*.kbd")) { 83 my $basename; 84 ($basename = $kbdfile) =~ s:.*/::; 85 my ($encoding) = $ENCODING{$basename}; 86 $encoding =~ s/\+/ /g; # e.g. "ISO8859-1+EURO" -> "ISO8859-1 EURO" 87 my $outfile = $FILE_NEW{$basename}; 88 if ($encoding and $outfile) { 89 if (-r $kbdfile) { 90 print "converting from '$basename' ($encoding) to '$outfile' (UCS)\n"; 91 my $cmdline = "$dir_convtool/convert-keymap.pl $kbdfile $encoding > $dir_keymaps_output/$outfile"; 92 system "$cmdline"; 93 } else { 94 print "$kbdfile not found\n"; 95 } 96 } else { 97 print "Ignore '$basename': No encoding defined in KBDFILES.map\n"; 98 } 99} 100