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