package scanner; # scanner.pm $Id$ # Yves Duret # Copyright (C) 2001-2002 MandrakeSoft # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2, or (at your option) # any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # # pbs/TODO: # - scsi mis-configuration (should work better now) # - devfs use dev_is_devfs() # - with 2 scanners same manufacturer -> will overwrite previous conf -> only 1 conf !! (should work now) # - lp: see printerdrake # - install: prefix --> done (partially) use common; use detect_devices; use log; use handle_configs; my $sanedir = "$::prefix/etc/sane.d"; my $scannerDBdir = "$::prefix$ENV{SHARE_PATH}/ldetect-lst"; our $scannerDB = readScannerDB("$scannerDBdir/ScannerDB"); sub confScanner { my ($model, $port, $vendor, $product, $firmware) = @_; $port ||= detect_devices::dev_is_devfs() ? "$::prefix/dev/usb/scanner0" : "$::prefix/dev/scanner"; my $a = $scannerDB->{$model}{server}; #print "file:[$a]\t[$model]\t[$port]\n| ", (join "\n| ", @{$scannerDB->{$model}{lines}}),"\n"; my @driverconf = cat_("$sanedir/$a.conf"); my @configlines = @{$scannerDB->{$model}{lines}}; foreach my $line (@configlines) { $line =~ s/\$DEVICE/$port/g if $port; next if $line =~ /\$DEVICE/; $line =~ s/\$VENDOR/$vendor/g if $vendor; next if $line =~ /\$VENDOR/; $line =~ s/\$PRODUCT/$product/g if $product; next if $line =~ /\$PRODUCT/; $line =~ s/\$FIRMWARE/$firmware/g if $firmware; next if $line =~ /\$FIRMWARE/; my $linetype; if ($line =~ /^(\S*)LINE\s+(.*?)$/) { $linetype = $1; $line = $2; } next if !$line; if (!$linetype || ($linetype eq "USB" && ($port =~ /usb/i || $vendor)) || ($linetype eq "PARPORT" && !$vendor && $port =~ /(parport|pt_drv|parallel)/i) || ($linetype eq "SCSI" && !$vendor && $port =~ m!(/sg|scsi|/scanner)!i)) { handle_configs::set_directive(\@driverconf, $line, 1); } elsif ($linetype eq "FIRMWARE" && $firmware) { handle_configs::set_directive(\@driverconf, $line, 0); } } output("$sanedir/$a.conf", @driverconf); add2dll($a); } sub add2dll { return if member($_[0], chomp_(cat_("$sanedir/dll.conf"))); my @dllconf = cat_("$sanedir/dll.conf"); handle_configs::add_directive(\@dllconf, $_[0]); output("$sanedir/dll.conf", @dllconf); } sub setfirmware { my ($backend, $firmwareline) = @_; my @driverconf = cat_("$sanedir/$backend.conf"); handle_configs::set_directive(\@driverconf, $firmwareline, 0); output("$sanedir/$backend.conf", @driverconf); } sub installfirmware { # Install the firmware file in /usr/share/sane/firmware my ($firmware) = @_; return "" if !$firmware; # Install firmware run_program::rooted($::prefix, "mkdir", "-p", "/usr/share/sane/firmware") || do { $in->ask_warn('Scannerdrake', N("Could not create directory /usr/share/sane/firmware!")); return ""; }; run_program::rooted($::prefix, "cp", "-f", "$firmware", "/usr/share/sane/firmware") || do { $in->ask_warn('Scannerdrake', N("Could not copy firmware file %s to /usr/share/sane/firmware!", $firmware)); return ""; }; $firmware =~ s!^(.*)(/[^/]+)$!/usr/share/sane/firmware$2!; run_program::rooted($::prefix, "chmod", "644", $firmware) || do { $in->ask_warn('Scannerdrake', N("Could not set permissions of firmware file %s!", $firmware)); return ""; }; return $firmware; } sub configured() { my @res; my $parportscannerfound = 0; # Run "scanimage -L", to find the scanners which are already working local *LIST; open LIST, "LC_ALL=C scanimage -L |"; while (my $line = ) { if ($line =~ /^\s*device\s*`([^`']+)'\s+is\s+a\s+(\S.*)$/) { # Extract port and description my $port = $1; my $description = $2; # Remove duplicate scanners appearing through saned and the # "net" backend next if $port =~ /^net:(localhost|127.0.0.1):/; # Is the scanner hooked to a parallel or serial port? if ($port =~ /(parport|pt_drv|parallel|ttys)/i) { $parportscannerfound = 1; } # Determine which SANE backend the scanner in question uses $port =~ /^([^:]+):/; my $backend = $1; # Does the scanner need a firmware file my $firmwareline = firmwareline($backend); # Store collected data push @res, { port => $port, val => { DESCRIPTION => $description, ($backend ? ( BACKEND => $backend ) : ()), ($firmwareline ? ( FIRMWARELINE => $firmwareline ) : ()), } } } } close LIST; # We have a parallel port scanner, make it working for non-root users nonroot_access_for_parport($parportscannerfound); return @res; } sub nonroot_access_for_parport { # This function configures a non-root access for parallel port # scanners by running saned as root, esporting the scanner to # localhost and letting the user's frontend use the "net" backend # to access the scanner through the loopback network device. # See also # http://www.linuxprinting.org/download/digitalimage/Scanning-as-Normal-User-on-Wierd-Scanner-Mini-HOWTO.txt # Desired state of this facility: 1: Enable, 0: Disable my ($enable) = @_; # Is saned running? my $sanedrunning = services::starts_on_boot("saned"); # Is the "net" SANE backend active my $netbackendactive = grep { /^\s*net\s*$/ } cat_("/etc/sane.d/dll.conf"); # Set this to 1 to tell the caller that the list of locally available # scanners has changed (Here if the SANE client configuration has # changed) my $changed = 0; my $importschanged = 0; if ($enable) { # Enable non-root access # Install/start saned if (!$sanedrunning) { # Make sure saned and xinetd is installed and # running if (!files_exist('/usr/sbin/xinetd', '/usr/sbin/saned')) { if (!$in->do_pkgs->install('xinetd', 'saned')) { $in->ask_warn(N("Scannerdrake"), N("Could not install the packages needed to share your scanner(s).") . " " . N("Your scanner(s) will not be available for non-root users.")); } return 0; } } # Modify /etc/xinetd.d/saned to let saned run as root my @sanedxinetdconf = cat_("/etc/xinetd.d/saned"); ( s/(user\s*=\s*).*$/$1root/ ) foreach @sanedxinetdconf; ( s/(group\s*=\s*).*$/$1root/ ) foreach @sanedxinetdconf; output("/etc/xinetd.d/saned", @sanedxinetdconf); # Read list of hosts to where to export the local scanners my @exports = cat_("/etc/sane.d/saned.conf"); # Read list of hosts from where to import scanners my @imports = cat_("/etc/sane.d/net.conf"); # Add "localhost" to the machines which saned exports handle_configs::set_directive(\@exports, "localhost") if !member("localhost\n", @exports); # Add "localhost" to the machines which "net" imports handle_configs::set_directive(\@imports, "localhost") if !member("localhost\n", @imports); # Write /etc/sane.d/saned.conf output("/etc/sane.d/saned.conf", @exports); # Write /etc/sane.d/net.conf output("/etc/sane.d/net.conf", @imports); # Make sure that the "net" backend is active scanner::add2dll("net"); # (Re)start saned and make sure that it gets started on # every boot services::start_service_on_boot("saned"); services::start_service_on_boot("xinetd"); services::restart("xinetd"); } else { # Disable non-root access if (-r "/etc/xinetd.d/saned") { # Modify /etc/xinetd.d/saned to let saned run as saned my @sanedxinetdconf = cat_("/etc/xinetd.d/saned"); ( s/(user\s*=\s*).*$/$1saned/ ) foreach @sanedxinetdconf; ( s/(group\s*=\s*).*$/$1saned/ ) foreach @sanedxinetdconf; output("/etc/xinetd.d/saned", @sanedxinetdconf); # Restart xinetd services::restart("xinetd") if $sanedrunning; } } return 1; } sub detect { my @configured = @_; my @res; # Run "sane-find-scanner", this also detects USB scanners which only # work with libusb. local *DETECT; open DETECT, "LC_ALL=C sane-find-scanner -q |"; while (my $line = ) { my ($vendorid, $productid, $make, $model, $description, $port); if ($line =~ /^\s*found\s+USB\s+scanner/i) { # Found an USB scanner if ($line =~ /vendor=(0x[0-9a-f]+)[^0-9a-f\[]+[^\[]*\[([^\[\]]+)\].*prod(|uct)=(0x[0-9a-f]+)[^0-9a-f\[]+[^\[]*\[([^\[\]]+)\]/) { # Scanner connected via libusb $vendorid = $1; $make = $2; $productid = $4; $model = $5; $description = "$make|$model"; } elsif ($line =~ /vendor=(0x[0-9a-f]+)[^0-9a-f]+.*prod(|uct)=(0x[0-9a-f]+)[^0-9a-f]+/) { # Scanner connected via scanner.o kernel module $vendorid = $1; $productid = $3; } if ($vendorid && $productid) { # We have vendor and product ID, look up the scanner in # the usbtable foreach my $entry (cat_("$scannerDBdir/usbtable")) { if ($entry =~ /^\s*$vendorid\s+$productid\s+.*\"([^\"]+)\"\s*$/) { $description = $1; $description =~ s/Seiko\s+Epson/Epson/i; if ($description =~ /^([^\|]+)\|(.*)$/) { $make = $1; $model = $2; } last; } } } } elsif ($line =~ /^\s*found\s+SCSI/i) { # SCSI scanner if ($line =~ /\"([^\"\s]+)\s+([^\"]+?)\s+([^\"\s]+)\"/) { $make = $1; $model = $2; $description = "$make|$model"; } } else { # Comment line in output of "sane-find-scanner" next; } # The Alcatel Speed Touch internet scanner is not supported by # SANE next if $description =~ /Alcatel.*Speed.*Touch|Camera|ISDN|ADSL/i; # Extract port $port = $1 if $line =~ /\s+(\S+)\s*$/; # Check for duplicate (scanner.o/libusb) if ($port =~ /^libusb/) { my $duplicate = 0; foreach (@res) { if ($_->{val}{vendor} eq $vendorid && $_->{val}{id} eq $productid && $_->{port} =~ /dev.*usb.*scanner/ && !defined($_->{port2})) { # Duplicate entry found, merge the entries $_->{port2} = $port; $_->{val}{MANUFACTURER} ||= $make; $_->{val}{MODEL} ||= $model; $_->{val}{DESCRIPTION} ||= $description; $duplicate = 1; last; } } next if $duplicate; } # Store collected data push @res, { port => $port, val => { CLASS => 'SCANNER', MODEL => $model, MANUFACTURER => $make, DESCRIPTION => $description, id => $productid, vendor => $vendorid, } }; } close DETECT; if (@configured) { # Remove scanners which are already working foreach my $d (@res) { my $searchport1 = handle_configs::searchstr(resolve_symlinks($d->{port})); my $searchport2 = handle_configs::searchstr(resolve_symlinks($d->{port2})); foreach my $c (@configured) { my $currentport = resolve_symlinks($c->{port}); if ($currentport =~ /$searchport1$/ || $searchport2 && $currentport =~ /$searchport2$/) { $d->{configured} = 1; last; } } } @res = grep { ! $_->{configured} } @res; } return @res; } sub resolve_symlinks { # Check if a given file (either the pure filename or in a SANE device # string as ":") is a symlink, if so expand the link. # If the new file name is a link, expand again, until finding the # physical file. my ($file) = @_; my $prefix = ""; if ($file =~ m!^([^/]*)(/.*)$!) { $prefix = $1; $file = $2; } else { return $file; } while (1) { my $ls = `ls -l $file`; if ($ls =~ m!\s($file)\s*\->\s*(\S+)\s*$!) { my $target = $2; if ($target !~ m!^/! && $file =~ m!^(.*)/[^/]+$!) { $target = "$1/$target"; } $file = $target; } else { last; } } return $prefix . $file; } sub get_usb_ids_for_port { my ($port) = @_; local *DETECT; if ($port =~ /^\s*libusb:(\d+):(\d+)\s*$/) { # Use "lsusb" to find the USB IDs open DETECT, "LC_ALL=C lsusb -s $1:$2 |"; while (my $line = ) { if ($line =~ /ID\s+([0-9a-f]+):(0x[0-9a-f]+)($|\s+)/) { # Scanner connected via scanner.o kernel module return "0x$1", "0x$2"; last; } } } else { # Run "sane-find-scanner" on the port open DETECT, "LC_ALL=C sane-find-scanner -q $port |"; while (my $line = ) { if ($line =~ /^\s*found\s+USB\s+scanner/i) { if ($line =~ /vendor=(0x[0-9a-f]+)[^0-9a-f]+.*prod(|uct)=(0x[0-9a-f]+)[^0-9a-f]+/) { # Scanner connected via scanner.o kernel module return $1, $3; } } } } } sub readconfiglinetemplates { # Read templates for configuration file lines my %configlines; my $backend; foreach my $line (cat_("$scannerDBdir/scannerconfigs")) { chomp $line; if ($line =~ /^\s*SERVER\s+(\S+)\s*$/) { $backend = $1; } elsif ($backend) { push @{$configlines{$backend}}, $line; } } return \%configlines; } sub firmwareline { # Determine whether the given SANE backend supports a firmware file # and return the line needed in the config file my ($backend) = @_; # Read templates for configuration file lines my %configlines = %{readconfiglinetemplates()}; # Does the backend support a line for the firmware? my @firmwarelines = (grep { s/^FIRMWARELINE // } @{$configlines{$backend}}); return join("\n", @firmwarelines); } sub readScannerDB { my ($file) = @_; my ($card, %cards); my $F = common::openFileMaybeCompressed($file); my ($lineno, $cmd, $val) = 0; my $fs = { LINE => sub { push @{$card->{lines}}, "LINE $val" }, SCSILINE => sub { push @{$card->{lines}}, "SCSILINE $val" }, USBLINE => sub { push @{$card->{lines}}, "USBLINE $val" }, PARPORTLINE => sub { push @{$card->{lines}}, "PARPORTLINE $val" }, FIRMWARELINE => sub { push @{$card->{lines}}, "FIRMWARELINE $val" }, NAME => sub { #$cards{$card->{type}} = $card if ($card and !$card->{flags}{unsupported}); $cards{$card->{type}} = $card if $card; $val =~ s/Seiko\s+Epson/Epson/i; $card = { type => $val }; }, SEE => sub { $val =~ s/Seiko\s+Epson/Epson/i; my $c = $cards{$val} or die "Error in database, invalid reference $val at line $lineno"; push @{$card->{lines}}, @{$c->{lines} || []}; add2hash($card->{flags}, $c->{flags}); add2hash($card, $c); }, ASK => sub { $card->{ask} = $val }, SERVER => sub { $card->{server} = $val }, DRIVER => sub { $card->{driver} = $val }, UNSUPPORTED => sub { $card->{flags}{unsupported} = 1 }, COMMENT => sub {}, }; local $_; while (<$F>) { $lineno++; s/\s+$//; /^#/ and next; /^$/ and next; /^END/ and do { $cards{$card->{type}} = $card if $card; last }; ($cmd, $val) = /(\S+)\s*(.*)/ or next; #log::l("bad line $lineno ($_)"), next; my $f = $fs->{$cmd}; $f ? $f->() : log::l("unknown line $lineno ($_)"); } \%cards; } sub updateScannerDBfromUsbtable() { substInFile { s/^END// } "ScannerDB"; my $to_add = "# generated from usbtable by scannerdrake\n"; foreach (cat_("$ENV{SHARE_PATH}/ldetect-lst/usbtable")) { my ($vendor_id, $product_id, $mod, $name) = chomp_(split /\s/,$_,4); next if $mod ne '"scanner"'; $name =~ s/\"(.*)\"$/$1/; if (member($name, keys %$scanner::scannerDB)) { print "#[$name] already in ScannerDB!\n"; next; } $to_add .= "NAME $name\nDRIVER USB\nCOMMENT usb $vendor_id $product_id\nUNSUPPORTED\n\n"; } $to_add .= "END\n"; append_to_file("ScannerDB", $to_add); } sub updateScannerDBfromSane { my ($sanesrcdir) = @_; substInFile { s/^END// } "ScannerDB"; my $to_add = "# generated from Sane by scannerdrake\n"; # for compat with our usbtable my $sane2DB = { "Acer" => "Acer Peripherals Inc.", "AGFA" => "AGFA-Gevaert NV", "Agfa" => "AGFA-Gevaert NV", "Epson" => "Epson Corp.", "Fujitsu Computer Products of America" => "Fujitsu", "HP" => sub { $_[0] =~ s/HP\s/Hewlett-Packard|/; $_[0] =~ s/HP4200/Hewlett-Packard|ScanJet 4200C/; $_[0] }, "Hewlett-Packard" => sub { $_[0] =~ s/HP 3200 C/Hewlett-Packard|ScanJet 3200C/ or $_[0] = "Hewlett-Packard|$_[0]"; $_[0] }, "Kodak" => "Kodak Co.", "Mustek" => "Mustek Systems Inc.", "NEC" => "NEC Systems", "Nikon" => "Nikon Corp.", "Plustek" => "Plustek, Inc.", "Primax" => "Primax Electronics", "Siemens" => "Siemens Information and Communication Products", "Trust" => "Trust Technologies", "UMAX" => "Umax", "Vobis/Highscreen" => "Vobis", }; # Read templates for configuration file lines my %configlines = %{readconfiglinetemplates()}; foreach my $ff (glob_("$sanesrcdir/doc/descriptions/*.desc"), glob_("$sanesrcdir/doc/descriptions-external/*.desc"), "UNSUPPORTED") { my $f = $ff; # unsupported.desc must be treated separately, as the list of # unsupported scanners in SANE is out of date. next if $f =~ /unsupported.desc$/; # Treat unsupported.desc in the end $f = "$sanesrcdir/doc/descriptions/unsupported.desc" if ($f eq "UNSUPPORTED"); my $F = common::openFileMaybeCompressed($f); $to_add .= "\n# from $f"; my ($lineno, $cmd, $val) = 0; my ($name, $intf, $comment, $mfg, $backend); my $fs = { backend => sub { $backend = $val }, mfg => sub { $mfg = $val; $name = undef },#bug when a new mfg comes. should called $fs->{ $name }(); but ?? model => sub { unless ($name) { $name = $val; return } $name = member($mfg, keys %$sane2DB) ? ref($sane2DB->{$mfg}) ? $sane2DB->{$mfg}($name) : "$sane2DB->{ $mfg }|$name" : "$mfg|$name"; # When adding the unsupported scanner models, check # whether the model is not already supported. To # compare the names ignore upper/lower case. my $searchname = quotemeta($name); if (($backend =~ /unsupported/i) && ($to_add =~ /^NAME $searchname$/im)) { $to_add .= "# $name already supported!\n"; } else { # SANE bug: "snapscan" calls itself "SnapScan" $backend =~ s/SnapScan/snapscan/g; $to_add .= "\nNAME $name\nSERVER $backend\nDRIVER $intf\n"; # Go through the configuration lines of # this backend and add what is needed for the # interfaces of this scanner foreach my $line (@{$configlines{$backend}}) { my $i = $1 if $line =~ /^\s*(\S*?)LINE/; if (!$i || $i eq "FIRMWARE" || $intf =~ /$i/i) { $to_add .= "$line\n"; } } if ($backend =~ /(unsupported|mustek_pp|gphoto2)/i) { $to_add .= "UNSUPPORTED\n"; } $to_add .= "COMMENT $comment\n" if $comment; $comment = undef; } $name = $val; }, interface => sub { $intf = $val }, comment => sub { $comment = $val }, }; local $_; while (<$F>) { $lineno++; s/\s+$//; /^;/ and next; ($cmd, $val) = /:(\S+)\s*\"([^;]*)\"/ or next; #log::l("bad line $lineno ($_)"), next; my $f = $fs->{$cmd}; $f ? $f->() : log::l("unknown line $lineno ($_)"); } $fs->{model}(); # the last one } $to_add .= "\nEND\n"; append_to_file("ScannerDB", $to_add); } 1; # ' href='#n399'>399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677
package keyboard; # $Id$

use diagnostics;
use strict;

#-######################################################################################
#- misc imports
#-######################################################################################
use common;
use detect_devices;
use run_program;
use lang;
use log;
use c;


#-######################################################################################
#- Globals
#-######################################################################################
my $KMAP_MAGIC = 0x8B39C07F;

#- a best guess of the keyboard layout, based on the choosen locale
#- beware only the first 5 characters of the locale are used
our %lang2keyboard =
(
  'af'  => 'us_intl',
  'am'  => 'us:90',
  'ar'  => 'ar:90',
  'as'  => 'ben:90 ben2:80 us_intl:5',
  'az'  => 'az:90 tr_q:10 us_intl:5',
'az_IR' => 'ir:90',
  'be'  => 'by:90 ru:50 ru_yawerty:40',
# 'ber' => 'tifinagh:80 tifinagh_p:70',
  'ber' => 'tifinagh_p:90',
  'bg'  => 'bg_phonetic:60 bg:50',
  'bn'  => 'ben:90 ben2:80 dev:20 us_intl:5',
  'bo'	=> 'dz',
  'br'  => 'fr:90',
  'bs'  => 'bs:90',
  'ca'  => 'es:90 fr:15',
  'chr' => 'chr:80 us:60 us_intl:60',
  'cs'  => 'cz_qwerty:70 cz:50',
  'cy'  => 'uk:90',
  'da'  => 'dk:90',
  'de'  => 'de_nodeadkeys:70 de:50 be:50 ch_de:50',
  'dz'	=> 'dz',
  'el'  => 'gr:90',
  'en'  => 'us:89 us_intl:50 qc:50 uk:50',
'en_IE' => 'ie:80 uk:70 dvorak_gb:10',
'en_US' => 'us:90 us_intl:50 dvorak:10',
'en_GB' => 'uk:89 us:60 us_intl:50 dvorak_gb:10',
  'eo'  => 'us_intl:89 dvorak_eo:30 dvorak:10',
  'es'  => 'es:85 la:80 us_intl:50',
  'et'  => 'ee:90',
  'eu'  => 'es:90 fr:15',
  'fa'  => 'ir:90',
  'fi'  => 'fi:90',
  'fo'  => 'fo:80 is:70 dk:60',
  'fr'  => 'fr:89 qc:85 be:85 ch_fr:70 dvorak_fr:20',
  'fur' => 'it:90',
  'ga'  => 'ie:80 uk:70 dvorak_gb:10',
  'gd'  => 'uk:80 ie:70 dvorak_gb:10',
  'gl'  => 'es:90',
  'gn'  => 'la:85 es:80 us_intl:50',
  'gu'  => 'guj:90',
  'gv'  => 'uk:80 ie:70',
  'he'  => 'il:90 il_phonetic:10',
  'hi'  => 'dev:90',
  'hr'  => 'hr:90 si:50',
  'hu'  => 'hu:90',
  'hy'  => 'am:90 am_old:10 am_phonetic:5',
  'ia'  => 'us:90 us_intl:20',
  'id'  => 'us:90 us_intl:20',
  'is'  => 'is:90',
  'it'  => 'it:90 ch_fr:50 ch_de:50',
  'iu'  => 'iu:90',
  'ja'  => 'jp:90 us:50 us_intl:20',
  'ka'  => 'ge_la:90 ge_ru:50',
  'kl'  => 'dk:80 us_intl:30',
  'kn'  => 'kan:90',
  'ko'  => 'kr:90 us:60',
  'ku'  => 'tr_q:90 tr_f:30',
'ku_IQ' => 'ku:90',
  'kw'  => 'uk:80 ie:70',
  'ky'  => 'ky:90 ru_yawerty:40',
  'lb'  => 'ch_fr:89 be:85 us_intl:70 fr:60 dvorak_fr:20',
  'li'  => 'us_intl:80 be:70 nl:10 us:5',
  'lo'  => 'lao:90',
  'lt'  => 'lt:80 lt_new:70 lt_b:60 lt_p:50',
  'ltg' => 'lv:90 lt:40 lt_new:30 lt_b:20 lt_p:10 ee:5',
  'lv'  => 'lv:90 lt:40 lt_new:30 lt_b:20 lt_p:10 ee:5',
  'mi'  => 'us_intl:90 uk:20 us:10',
  'mk'  => 'mk:90',
  'ml'  => 'mal:90',
  'mn'  => 'mng:90 ru:20 ru_yawerty:5',
  'mr'  => 'dev:90',
  'ms'  => 'us:90 us_intl:20',
  'mt'  => 'mt:90 mt_us:35 us_intl:10',
  'my'  => 'mm:90',
  'nb'  => 'no:90 dvorak_no:10',
  'nds' => 'de_nodeadkeys:70 de:50 us_intl:40 nl:10 us:5',
  'ne'  => 'dev:90',
  'nl'  => 'us_intl:80 be:70 nl:10 us:5',
  'nn'  => 'no:90 dvorak_no:10',
  'no'  => 'no:90 dvorak_no:10', # for compatiblity only
  'oc'  => 'fr:90',
  'or'  => 'ori:90',
  'pa'  => 'gur:90',
  'ph'  => 'us:90 us_intl:20',
  'pl'  => 'pl:90 pl2:60 dvorak_pl:10',
  'pp'  => 'br:80 la:20 pt:10 us_intl:30',
  'ps'  => 'ps:80 sd:60',
'pt_BR' => 'br:90 la:20 pt:10 us_intl:30',
  'pt'  => 'pt:90',
  'ro'  => 'ro2:80 ro:40 us_intl:10',
  'ru'  => 'ru:85 ru_yawerty:80 ua:50',
  'sc'  => 'it:90',
  'sd'  => 'sd:80 ar:20',
  'se'  => 'sapmi:70 sapmi_sefi:50',
  'sh'  => 'yu:80',
  'sk'  => 'sk_qwerty:80 sk:70',
  'sl'  => 'si:90 hr:50',
  'sq'  => 'al:90',
  'sr'  => 'sr:80',
  'ss'  => 'us_intl',
  'st'  => 'us_intl',
  'sv'  => 'se:90 fi:30 dvorak_se:10',
  'ta'  => 'tscii:80 tml:20',
  'te'  => 'tel:90',
  'tg'  => 'tj:90 ru_yawerty:40',
  'th'  => 'th:80 th_pat:50 th_tis:60',
  'tk'  => 'tk:80 tr_q:50 tr_f:40',
  'tl'  => 'us:90 us_intl:20',
  'tr'  => 'tr_q:90 tr_f:30',
  'tt'  => 'ru:50 ru_yawerty:40',
  'uk'  => 'ua:90 ru:50 ru_yawerty:40',
  'ur'  => 'ur:80 sd:60 ar:20',
  'uz'  => 'uz:80 ru_yawerty:40',
  'uz\@Cyrl'  => 'uz:80 ru_yawerty:40',
  'uz\@Latn'  => 'us:80 uz:80',
  've'  => 'us_intl',
  'vi'  => 'vn:80 us:70 us_intl:60',
  'wa'  => 'be:90 fr:5',
  'xh'  => 'us_intl',
  'yi'  => 'il_phonetic:90 il:10 us_intl:10',
'zh_CN' => 'us:90',
'zh_TW' => 'us:90',
  'zu'  => 'us_intl',
);

# USB kbd table
# The numeric values are the bCountryCode field (5th byte)  of HID descriptor
# NOTE: we do not trust when the layout is declared as US layout (0x21)
# as most manufacturers just use that value when selling physical devices
# with different layouts printed on the keys.
my @usb2keyboard =
(
  qw(SKIP ar_SKIP be ca_SKIP qc cz dk fi fr de gr il hu us_intl it jp),
#- 0x10
  qw(kr la nl no ir pl pt ru sk es se ch_de ch_de ch_de tw_SKIP tr_q),
#- 0x20
  qw(uk us_SKIP yu tr_f),
#- higher codes not attribued as of 2002-02
);

#- key = extension for Xmodmap file, [0] = description of the keyboard,
#- [1] = name for loadkeys, [2] = name for XKB, [3] = "1" if it is
#- a multigroup layout (eg: one with latin/non-latin letters)
my %keyboards = (
arch() =~ /^sparc/ ? (
 "cz" => [ N_("_: keyboard\nCzech (QWERTZ)"), "sunt5-cz-us",	 "cz",    0 ],
 "de" => [ N_("_: keyboard\nGerman"),         "sunt5-de-latin1", "de",    0 ],
 "dvorak" => [ N_("_: keyboard\nDvorak"),     "sundvorak",       "dvorak",0 ],
 "es" => [ N_("_: keyboard\nSpanish"),        "sunt5-es",        "es",    0 ],
 "fi" => [ N_("_: keyboard\nFinnish"),        "sunt5-fi-latin1", "fi",    0 ],
 "fr" => [ N_("_: keyboard\nFrench"),         "sunt5-fr-latin1", "fr",    0 ],
 "no" => [ N_("_: keyboard\nNorwegian"),      "sunt4-no-latin1", "no",    0 ],
 "pl" => [ N_("_: keyboard\nPolish"),         "sun-pl-altgraph", "pl",    0 ],
 "ru" => [ N_("_: keyboard\nRussian"),        "sunt5-ru",        "ru",    1 ],
# TODO: check the console map
 "se" => [ N_("_: keyboard\nSwedish"),        "sunt5-fi-latin1", "se",    0 ],
 "uk" => [ N_("UK keyboard"),    "sunt5-uk",        "gb",    0 ],
 "us" => [ N_("US keyboard"),    "sunkeymap",       "us",    0 ],
) : (
 "al" => [ N_("_: keyboard\nAlbanian"),       "al",              "al",    0 ],
 "am_old" => [ N_("_: keyboard\nArmenian (old)"), "am_old",	 "am(old)", 1 ],
 "am" => [ N_("_: keyboard\nArmenian (typewriter)"), "am-armscii8", "am",   1 ],
 "am_phonetic" => [ N_("_: keyboard\nArmenian (phonetic)"), "am_phonetic", "am(phonetic)",1 ],
 "ar" => [ N_("_: keyboard\nArabic"),          "us",             "ara(digits)",   1 ],
 "az" => [ N_("_: keyboard\nAzerbaidjani (latin)"), "az",        "az",    0 ],
 "be" => [ N_("_: keyboard\nBelgian"),        "be2-latin1",      "be",    0 ],
 "ben" => [ N_("_: keyboard\nBengali (Inscript-layout)"), "us",  "ben",   1 ],
 "ben2" => [ N_("_: keyboard\nBengali (Probhat)"), "us", "ben(probhat)",  1 ],
"bg_phonetic" => [ N_("_: keyboard\nBulgarian (phonetic)"), "bg", "bg(phonetic)", 1 ],
 "bg" => [ N_("_: keyboard\nBulgarian (BDS)"), "bg",             "bg",    1 ],
 "br" => [ N_("_: keyboard\nBrazilian (ABNT-2)"), "br-abnt2",    "br",    0 ],
 "bs" => [ N_("_: keyboard\nBosnian"),	 "croat",           "bs",    0 ],
 "by" => [ N_("_: keyboard\nBelarusian"),     "by-cp1251",       "by",    1 ],
# old XKB layout
 "ch_de" => [ N_("_: keyboard\nSwiss (German layout)"), "sg-latin1", "de_CH", 0 ],
# old XKB layout
 "ch_fr" => [ N_("_: keyboard\nSwiss (French layout)"), "fr_CH-latin1", "fr_CH", 0 ],
# TODO: console map
 "chr" => [ N_("_: keyboard\nCherokee syllabics"), "us",         "chr",   1 ],
 "cz" => [ N_("_: keyboard\nCzech (QWERTZ)"), "cz",              "cz",    0 ],
 "cz_qwerty" => [ N_("_: keyboard\nCzech (QWERTY)"), "cz-lat2", "cz(qwerty)", 0 ],
 "de" => [ N_("_: keyboard\nGerman"),         "de-latin1",       "de",    0 ],