diff --git a/tools/tools/vt/keymaps/KBDFILES.map b/tools/tools/vt/keymaps/KBDFILES.map new file mode 100644 index 000000000000..4494b85052e7 --- /dev/null +++ b/tools/tools/vt/keymaps/KBDFILES.map @@ -0,0 +1,149 @@ +# $FreeBSD$ +# +# The Files are converted by "convert-keymaps.pl" from the given encoding to UCS. +# +# An additional "+EURO" causes the translation of the generic currency symbol to +# an Euro symbol, even if the source locale does not support an Euro symbol. +# This conversion is only performed for the "E" key (not e.g. on Shift-4, which +# still generates the currency symbol). +# +# Encoding syscons file name newcons (vt) file name +ISO8859-1+EURO be.iso.kbd be.kbd +ISO8859-1+EURO be.iso.acc.kbd be.acc.kbd + +ISO8859-5 bg.bds.ctrlcaps.kbd bg.bds.kbd +ISO8859-5 bg.phonetic.ctrlcaps.kbd bg.phonetic.kbd + +#ISO8859-1 br275.iso.kbd br.kbd.from-iso1 (only AltGr-Shift-6 differs from CP850) +ISO8859-1 br275.iso.acc.kbd br.kbd +CP850 br275.cp850.kbd br.noacc.kbd + +#CP1131 by.cp1131.kbd by.kbd.from-cp1131 (Shift-3 not OK) +#CP1251 by.cp1251.kbd by.kbd.from-cp1251 (result identical to CP1251) +ISO8859-5 by.iso5.kbd by.kbd + +ISO8859-2 ce.iso2.kbd centraleuropean.qwerty.kbd + +ISO8859-1 colemak.iso15.acc.kbd colemak.acc.kbd + +ISO8859-2 cs.latin2.qwertz.kbd cz.kbd +ISO8859-2 cz.iso2.kbd cz.qwerty.kbd.from-ce + +ISO8859-1+EURO danish.iso.kbd dk.kbd +ISO8859-1+EURO danish.iso.acc.kbd dk.acc.kbd +CP865 danish.cp865.kbd dk.kbd.from-cp865 +ISO8859-1 danish.iso.macbook.kbd dk.macbook.kbd + +ISO8859-1 dutch.iso.acc.kbd nl.kbd + +ISO8859-15 eee_nordic.kbd nordic.asus-eee.kbd + +ISO8859-7 el.iso07.kbd gr.kbd + +ISO8859-1 estonian.iso.kbd ee.kbd.from-iso1 +ISO8859-15 estonian.iso15.kbd ee.kbd +CP850 estonian.cp850.kbd ee.kbd.from-cp850 + +ISO8859-1+EURO finnish.iso.kbd fi.kbd +CP850 finnish.cp850.kbd fi.kbd.from-cp850 + +ISO8859-1+EURO fr.iso.kbd fr.kbd +ISO8859-1+EURO fr.iso.acc.kbd fr.acc.kbd +ISO8859-1+EURO fr.macbook.acc.kbd fr.macbook.kbd +ISO8859-1+EURO fr.dvorak.kbd fr.dvorak.kbd +ISO8859-1 fr.dvorak.acc.kbd fr.dvorak.acc.kbd + +ISO8859-1+EURO fr_CA.iso.acc.kbd ca-fr.kbd + +ISO8859-1+EURO german.iso.kbd de.noacc.kbd +ISO8859-1+EURO german.iso.acc.kbd de.acc.kbd +CP850 german.cp850.kbd de.kbd.from-cp850 + +ISO8859-7 gr.elot.acc.kbd gr.elot.acc.kbd +ISO8859-7 gr.us101.acc.kbd gr.101.acc.kbd + +ISO8859-8 iw.iso8.kbd il.kbd + +ISO8859-2 hr.iso.kbd hr.kbd + +ISO8859-2 hu.iso2.101keys.kbd hu.101.kbd +ISO8859-2 hu.iso2.102keys.kbd hu.102.kbd + +ARMSCII-8 hy.armscii-8.kbd am.kbd + +ISO8859-1 icelandic.iso.kbd is.kbd +ISO8859-1 icelandic.iso.acc.kbd is.acc.kbd + +ISO8859-1+EURO it.iso.kbd it.kbd + +ISO8859-1+YEN jp.106.kbd jp.kbd +ISO8859-1+YEN jp.106x.kbd jp.capsctrl.kbd +ISO8859-1+YEN jp.pc98.kbd jp.pc98.kbd +ISO8859-1+YEN jp.pc98.iso.kbd jp.pc98.iso.kbd + +PT154 kk.pt154.kst.kbd kz.kst.kbd +PT154 kk.pt154.io.kbd kz.io.kbd + +ISO8859-1 latinamerican.kbd latinamerican.kbd +ISO8859-1 latinamerican.iso.acc.kbd latinamerican.acc.kbd + +ISO8859-4 lt.iso4.kbd lt.kbd + +ISO8859-1 norwegian.iso.kbd no.kbd +ISO8859-1 norwegian.dvorak.kbd no.dvorak.kbd + +ISO8859-2 pl_PL.ISO8859-2.kbd pl.kbd +ISO8859-2 pl_PL.dvorak.kbd pl.dvorak.kbd + +ISO8859-1+EURO pt.iso.kbd pt.kbd +ISO8859-1+EURO pt.iso.acc.kbd pt.acc.kbd + +CP866 ru.cp866.kbd ru.kbd.from-cp866 +ISO8859-5 ru.iso5.kbd ru.kbd.from-iso5 +KOI8-R ru.koi8-r.kbd ru.kbd +KOI8-R ru.koi8-r.shift.kbd ru.shift.kbd +KOI8-R ru.koi8-r.win.kbd ru.win.kbd + +ISO8859-1+EURO spanish.dvorak.kbd es.dvorak.kbd +ISO8859-1+EURO spanish.iso.kbd es.kbd.from-iso1 +ISO8859-1+EURO spanish.iso.acc.kbd es.acc.kbd +ISO8859-1+EURO spanish.iso15.acc.kbd es.kbd + +ISO8859-2 si.iso.kbd si.kbd + +ISO8859-2 sk.iso2.kbd sk.kbd + +ISO8859-1+EURO swedish.iso.kbd se.kbd +CP850 swedish.cp850.kbd se.kbd.from-cp850 + +ISO8859-1+EURO swissfrench.iso.kbd ch-fr.kbd +ISO8859-1+EURO swissfrench.iso.acc.kbd ch-fr.acc.kbd +CP850 swissfrench.cp850.kbd ch-fr.kbd.from-cp850 + +ISO8859-1+EURO swissgerman.iso.kbd ch.kbd +ISO8859-1+EURO swissgerman.iso.acc.kbd ch.acc.kbd +CP850 swissgerman.cp850.kbd ch.kbd.from-cp850 +ISO8859-1+EURO swissgerman.macbook.acc.kbd ch.macbook.acc.kbd + +ISO8859-9 tr.iso9.q.kbd tr.kbd + +ISO8859-1+EURO uk.iso.kbd uk.kbd +ISO8859-1+EURO uk.iso-ctrl.kbd uk.capsctrl.kbd +#CP850 uk.cp850.kbd uk.kbd.from-cp850 (no ¤ and different Alt/Alt-Shift encodings) +#CP850 uk.cp850-ctrl.kbd uk.capsctrl.kbd.from-cp850 (no ¤ and different Alt/Alt-Shift encodings) +ISO8859-15 uk.dvorak.kbd uk.dvorak.kbd + +ISO8859-1 us.iso.kbd us.kbd +ISO8859-1 us.iso.acc.kbd us.acc.kbd +ISO8859-1 us.dvorak.kbd us.dvorak.kbd +ISO8859-1 us.dvorakr.kbd us.dvorakr.kbd +ISO8859-1 us.dvorakl.kbd us.dvorakl.kbd +ISO8859-1 us.dvorakp.kbd us.dvorakp.kbd +ISO8859-1 us.dvorakx.kbd us.dvorakx.kbd +ISO8859-1 us.emacs.kbd us.emacs.kbd +ISO8859-1 us.pc-ctrl.kbd us.ctrl.kbd +ISO8859-1 us.unix.kbd us.unix.kbd + +ISO8859-5 ua.iso5.kbd ua.kbd.from-iso5 +KOI8-U ua.koi8-u.kbd ua.kbd +KOI8-U ua.koi8-u.shift.alt.kbd ua.shift.alt.kbd diff --git a/tools/tools/vt/keymaps/LANG.map b/tools/tools/vt/keymaps/LANG.map new file mode 100644 index 000000000000..29ecbe8da5a7 --- /dev/null +++ b/tools/tools/vt/keymaps/LANG.map @@ -0,0 +1,29 @@ +# $FreeBSD$ +bg bg ISO8859-5 +cs cs ISO8859-2 +da da ISO8859-15 +de de ISO8859-15 +el el ISO8859-7 +en en ISO8859-1 +es es ISO8859-1 +fi fi ISO8859-1 +fr fr ISO8859-1 +hr hr ISO8859-2 +hu hu ISO8859-2 +hy hy ARMSCII-8 +is is ISO8859-1 +it it ISO8859-15 +iw he ISO8859-8 +ja ja ISO8859-1 +kk kk PT154 +nl nl ISO8859-15 +no no ISO8859-1 +pl pl ISO8859-2 +pt pt ISO8859-15 +ro ro ISO8859-1 +ru ru KOI8-R +sk sk ISO8859-2 +sl sl ISO8859-2 +sv sv ISO8859-1 +tr tr ISO8859-9 +uk uk KOI8-U diff --git a/tools/tools/vt/keymaps/convert-INDEX.pl b/tools/tools/vt/keymaps/convert-INDEX.pl new file mode 100755 index 000000000000..ec88fc338620 --- /dev/null +++ b/tools/tools/vt/keymaps/convert-INDEX.pl @@ -0,0 +1,94 @@ +#!/usr/local/bin/perl +# $FreeBSD$ + +use Text::Iconv; +use Encode; +use strict; +use utf8; + +# directories and filenames +$0 =~ m:^(.*)/:; +my $dir_convtool = $1 || "."; + +my $dir_keymaps_syscons = "/usr/src/share/syscons/keymaps"; +my $dir_keymaps_config = "$dir_convtool"; + +my $dir_keymaps_vt = "/usr/src/share/vt/keymaps"; +my $dir_keymaps_output = "$dir_keymaps_vt/OUTPUT"; + +my $keymap_index = "$dir_keymaps_syscons/INDEX.keymaps"; + +my $language_map = "$dir_keymaps_config/LANG.map"; +my $keymapfile_map = "$dir_keymaps_config/KBDFILES.map"; + +# global variables +my %LANG_NEW; # index: lang_old +my %ENCODING; # index: lang_old, file_old +my %FILE_NEW; # index: file_old + +# subroutines +sub local_to_UCS_string +{ + my ($string, $old_enc) = @_; + my $converter = Text::Iconv->new($old_enc, "UTF-8"); + my $result = $converter->convert($string); + printf "!!! conversion failed for '$string' ($old_enc)\n" + unless $result; + return $result; +} + +sub lang_fixup { + my ($langlist) = @_; + my $result; + my $lang; + for $lang (split(/,/, $langlist)) { + $result .= "," + if $result; + $result .= $LANG_NEW{$lang}; + } + return $result; +} + +# main program +open LANGMAP, "<$language_map" + or die "$!"; +while () { + next + if m/^#/; + my ($lang_old, $lang_new, $encoding) = split(" "); +# print "$lang_old|$lang_new|$encoding\n"; + $LANG_NEW{$lang_old} = $lang_new; + $ENCODING{$lang_old} = $encoding; + $ENCODING{$lang_new} = $encoding; +} +close LANGMAP; + +$FILE_NEW{"MENU"} = "MENU"; # dummy identity mapping +$FILE_NEW{"FONT"} = "FONT"; # dummy identity mapping +open FILEMAP, "<$keymapfile_map" + or die "$!"; +while () { + next + if m/^#/; + my ($encoding, $file_old, $file_new) = split(" "); +# print "--> ", join("|", $encoding, $file_old, $file_new, $file_locale), "\n"; + if ($encoding and $file_old and $file_new) { + $ENCODING{$file_old} = $encoding; + $FILE_NEW{$file_old} = $file_new; + } +} +close FILEMAP; + +open MENUFILE, "<$keymap_index" + or die "$!"; +while () { + if (m/^$/ or m/^#/) { + print; + } else { + my ($file_old, $langlist, $menutext) = split(/:/); + my ($lang) = split(/,/, $langlist); # first language in list selects encoding + $menutext = local_to_UCS_string($menutext, $ENCODING{$lang}) + unless $file_old eq "FONT"; + printf "%s:%s:%s", $FILE_NEW{$file_old}, lang_fixup($langlist), $menutext; + } +} diff --git a/tools/tools/vt/keymaps/convert-keymap.pl b/tools/tools/vt/keymaps/convert-keymap.pl new file mode 100755 index 000000000000..778ae10bb530 --- /dev/null +++ b/tools/tools/vt/keymaps/convert-keymap.pl @@ -0,0 +1,155 @@ +#!/usr/bin/perl +# $FreeBSD$ + +use Text::Iconv; +use Encode; +use strict; +use utf8; + +# command line parsing +die "Usage: $0 filename.kbd CHARSET [EURO]" + unless ($ARGV[1]); + +my $inputfile = shift; # first command argument +my $converter = Text::Iconv->new(shift, "UTF-8"); # second argument +my $use_euro; +my $use_yen; +my $current_char; +my $current_scancode; + +while (my $arg = shift) { + $use_euro = 1, next + if $arg eq "EURO"; + $use_yen = 1, next + if $arg eq "YEN"; + die "Unknown encoding option '$arg'\n"; +} + +# converter functions +sub local_to_UCS_string +{ + my ($string) = @_; + + return $converter->convert($string); +} + +sub prettyprint_token +{ + my ($ucs_char) = @_; + + return "'" . chr($ucs_char) . "'" + if 32 <= $ucs_char and $ucs_char <= 126; # print as ASCII if possible +# return sprintf "%d", $ucs_char; # <---- temporary decimal + return sprintf "0x%02x", $ucs_char + if $ucs_char <= 255; # print as hex number, else + return sprintf "0x%04x", $ucs_char; +} + +sub local_to_UCS_code +{ + my ($char) = @_; + + my $ucs_char = ord(Encode::decode("UTF-8", local_to_UCS_string($char))); + + $current_char = lc(chr($ucs_char)), print("SETCUR: $ucs_char\n") + if $current_char eq ""; + + $ucs_char = 0x20ac # replace with Euro character + if $ucs_char == 0xa4 and $use_euro and $current_char eq "e"; + + $ucs_char = 0xa5 # replace with Jap. Yen character on PC kbd + if $ucs_char == ord('\\') and $use_yen and $current_scancode == 125; + + $ucs_char = 0xa5 # replace with Jap. Yen character on PC98x1 kbd + if $ucs_char == ord('\\') and $use_yen and $current_scancode == 13; + + return prettyprint_token($ucs_char); +} + +sub malformed_to_UCS_code +{ + my ($char) = @_; + + return prettyprint_token(ord(Encode::decode("UTF-8", $char))); +} + +sub convert_token +{ + my ($C) = @_; + + return $1 + if $C =~ m/^([a-z][a-z0-9]*)$/; # key token + return local_to_UCS_code(chr($1)) + if $C =~ m/^(\d+)$/; # decimal number + return local_to_UCS_code(chr(hex($1))) + if $C =~ m/^0x([0-9a-f]+)$/i; # hex number + return local_to_UCS_code(chr(ord($1))) + if $C =~ m/^'(.)'$/; # character + return malformed_to_UCS_code($1) + if $C =~ m/^'(.+)'$/; # character + return ""; # uncovered case +} + +sub tokenize { # split on white space and parentheses (but not within token) + my ($line) = @_; + + $line =~ s/'\('/ _lpar_ /g; # prevent splitting of '(' + $line =~ s/'\)'/ _rpar_ /g; # prevent splitting of ')' + $line =~ s/'''/'_squote_'/g; # remove quoted single quotes from matches below + $line =~ s/([()])/ $1 /g; # insert blanks around remaining parentheses + my $matches; + do { + $matches = ($line =~ s/^([^']*)'([^']+)'/$1_squoteL_$2_squoteR_/g); + } while $matches; + $line =~ s/_squoteL_ _squoteR_/ _spc_ /g; # prevent splitting of ' ' + my @KEYTOKEN = split (" ", $line); + grep(s/_squote[LR]?_/'/g, @KEYTOKEN); + grep(s/_spc_/' '/, @KEYTOKEN); + grep(s/_lpar_/'('/, @KEYTOKEN); + grep(s/_rpar_/')'/, @KEYTOKEN); + return @KEYTOKEN; +} + +# main program +open FH, "<$inputfile"; +while () { + if (m/^#/) { + print local_to_UCS_string($_); + } elsif (m/^\s*$/) { + print "\n"; + } else { + my @KEYTOKEN = tokenize($_); + my $at_bol = 1; + my $C; + foreach $C (@KEYTOKEN) { + if ($at_bol) { + $current_char = ""; + $current_scancode = -1; + if ($C =~ m/^\s*\d/) { # line begins with key code number + $current_scancode = $C; + printf " %03d ", $C; + } elsif ($C =~ m/^[a-z]/) { # line begins with accent name or paren + printf " %-4s ", $C; # accent name starts accent definition + } elsif ($C eq "(") { + printf "%17s", "( "; # paren continues accent definition + } else { + print "Unknown input line format: $_"; + } + $at_bol = 0; + } else { + if ($C =~ m/^([BCNO])$/) { + print " $1"; # special case: effect of Caps Lock/Num Lock + } elsif ($C eq "(") { + $current_char = ""; + print " ( "; + } elsif ($C eq ")") { + print " )"; + } else { + printf "%-6s ", convert_token($C); + } + } + } + print "\n"; + } +} +close FH; diff --git a/tools/tools/vt/keymaps/convert-keymaps.pl b/tools/tools/vt/keymaps/convert-keymaps.pl new file mode 100755 index 000000000000..ea8fbc2b09c3 --- /dev/null +++ b/tools/tools/vt/keymaps/convert-keymaps.pl @@ -0,0 +1,100 @@ +#!/usr/local/bin/perl +# $FreeBSD$ + +use Text::Iconv; +use Encode; +use strict; +use utf8; + +# directories and filenames +$0 =~ m:^(.*)/:; +my $dir_convtool = $1 || "."; + +my $dir_keymaps_syscons = "/usr/src/share/syscons/keymaps"; +my $dir_keymaps_config = "$dir_convtool"; + +my $dir_keymaps_vt = "/usr/src/share/vt/keymaps"; +my $dir_keymaps_output = "$dir_keymaps_vt/OUTPUT"; + +my $keymap_index = "$dir_keymaps_syscons/INDEX.keymaps"; + +my $language_map = "$dir_keymaps_config/LANG.map"; +my $keymapfile_map = "$dir_keymaps_config/KBDFILES.map"; + +# global variables +my %LANG_NEW; # index: lang_old +my %ENCODING; # index: lang_old, file_old +my %FILE_NEW; # index: file_old + +# subroutines +sub local_to_UCS_string +{ + my ($string, $old_enc) = @_; + my $converter = Text::Iconv->new($old_enc, "UTF-8"); + my $result = $converter->convert($string); + printf "!!! conversion failed for '$string' ($old_enc)\n" + unless $result; + return $result; +} + +sub lang_fixup { + my ($langlist) = @_; + my $result; + my $lang; + for $lang (split(/,/, $langlist)) { + $result .= "," + if $result; + $result .= $LANG_NEW{$lang}; + } + return $result; +} + +# main program +open LANGMAP, "<$language_map" + or die "$!"; +while () { + next + if m/^#/; + my ($lang_old, $lang_new, $encoding) = split(" "); +# print "$lang_old|$lang_new|$encoding\n"; + $LANG_NEW{$lang_old} = $lang_new; + $ENCODING{$lang_old} = $encoding; + $ENCODING{$lang_new} = $encoding; +} +close LANGMAP; + +$FILE_NEW{"MENU"} = "MENU"; # dummy identity mapping +$FILE_NEW{"FONT"} = "FONT"; # dummy identity mapping +open FILEMAP, "<$keymapfile_map" + or die "$!"; +while () { + next + if m/^#/; + my ($encoding, $file_old, $file_new) = split(" "); +# print "--> ", join("|", $encoding, $file_old, $file_new, $file_locale), "\n"; + if ($encoding and $file_old and $file_new) { + $ENCODING{$file_old} = $encoding; + $FILE_NEW{$file_old} = $file_new; + } +} +close FILEMAP; + +my $kbdfile; +foreach $kbdfile (glob("$dir_keymaps_syscons/*.kbd")) { + my $basename; + ($basename = $kbdfile) =~ s:.*/::; + my ($encoding) = $ENCODING{$basename}; + $encoding =~ s/\+/ /g; # e.g. "ISO8859-1+EURO" -> "ISO8859-1 EURO" + my $outfile = $FILE_NEW{$basename}; + if ($encoding and $outfile) { + if (-r $kbdfile) { + print "converting from '$basename' ($encoding) to '$outfile' (UCS)\n"; + my $cmdline = "$dir_convtool/convert-keymap.pl $kbdfile $encoding > $dir_keymaps_output/$outfile"; + system "$cmdline"; + } else { + print "$kbdfile not found\n"; + } + } else { + print "Ignore '$basename': No encoding defined in KBDFILES.map\n"; + } +}