summaryrefslogtreecommitdiffstats
path: root/bootloader/make-kbd-info
blob: 95560b68c6a8c7de95c4f688af5d07b85a38d79d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/perl

# Copyright (C) 2017 Mageia
#
# 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.

# SYNOPSIS
#
# This program gets the list of supported keyboards from libDrakX and
# generates the keyboard names file and the language to keyboard mapping
# file that are used when generating the bootloader menus for the Mageia
# ISOs.
#
# The keyboard names file consists of a list of paired identifier and
# description strings. The identifier is the keyboard identifier used
# in libDrakX. The description is the canonical keyboard description
# provided by libDrakX. The file (kbd-names.txt) is stored in the
# current working directory.
# 
# The language to keyboard mapping file consists of a map of language
# identifier to keyboard identifier strings. The language identifier
# is the standard language/country code used for specifying a locale
# (e.g. en_US). The keyboard identifier is the default keyboard for
# that language, as provided by libDrakX. The file (lang-kbds.txt) is
# stored in the current working directory.
#
# The list of supported languages is read from the language names file
# (lang-names.txt) that is used when generating the bootloader menus.
# This file is expected to be found in the current working directory.
#
# NOTE: An older version of this program also generated GRUB2 keyboard
# layout files for each supported language, but it was found that the
# GRUB2 at_keyboard driver did not work on all hardware, so this feature
# was dropped.

use lib qw(/usr/lib/libDrakX);

use strict;

use Cwd qw(getcwd);
use MDK::Common;
use common;
use keyboard;

# Make sure we get the canonical description for the keyboard.
$ENV{LANGUAGE} = 'C';

# Collect the keyboard descriptions. For keyboards with multiple layouts,
# only use the first layout.
my %names;
my @keyboards = map { { KEYBOARD => $_ } } keyboard::KEYBOARDs();
foreach (@keyboards) {
    my $id = $_->{KEYBOARD};
    $names{$id} = translate(keyboard::keyboard2text($_));
}

# Generate the keyboard names file.
my $filename = getcwd() . '/kbd-names.txt';
open(my $f, '>' . $filename) or die "couldn't open $filename";
print $f "(\n";
foreach my $id (sort keys %names) {
   my $name = $names{$id};
   printf $f "    '$id'%s => '$name',\n", ' ' x (16 - length($id));
}
print $f ")\n";
close($f);

# Read the list of supported languages.
my $lang_names = getcwd() . '/lang-names.txt';
-e $lang_names or die "cannot find language names file $lang_names\n";
my @langs = group_by2(eval(cat_($lang_names)))
  or die "error in language names file $lang_names\n";

# Generate the language to keyboard mapping file.
$filename = getcwd() . '/lang-kbds.txt';
open($f, '>' . $filename) or die "couldn't open $filename";
print $f "{\n";
foreach (@langs) {
    my ($lang) = @$_;
    my $kbd = keyboard::lang2keyboard($lang)->{KEYBOARD};
    $kbd = '' if !$names{$kbd};
    printf $f "    '$lang' => '$kbd',\n";
}
print $f "}\n";
close($f);