File: getkmapchoice.pl.in

package info (click to toggle)
console-common 0.7.14
  • links: PTS
  • area: main
  • in suites: woody
  • size: 188 kB
  • ctags: 52
  • sloc: perl: 450; sh: 219; awk: 134; makefile: 108
file content (101 lines) | stat: -rwxr-xr-x 2,739 bytes parent folder | download
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
98
99
100
101
#!/usr/bin/perl

use Debconf::Client::ConfModule ':all';

#####COMMON#####

sub readfiles($) {
  my ($path) = @_;

  opendir (DIR, $path) or die "Can't open directory \`$path': $!";
  my @files = grep { ! /^\./ && -f "$path/$_" } readdir(DIR);
  closedir DIR;

  foreach my $file (@files) {
#    print STDERR "Loading $defsdir/$file\n";
    require "$defsdir/$file";
  }
}


($ret, $policy) = get ('console-data/keymap/policy');
if ($policy eq 'Don\'t touch keymap') {
  # No keymap
  $filename = 'NONE';
} elsif ($policy eq 'Select keymap from full list') {
  ($ret, $filename) = get ('console-data/keymap/full');
  if (! $filename) {
      $filename = 'NONE';
  }
} elsif ($policy eq 'Keep kernel keymap') {
  # No keymap
  $filename = 'KERNEL';
} else {
  # Get infos about selected keymap
  ($ret, $family) = get ('console-data/keymap/family');
  $cfamily = correctname $family;
  die "No keyboard family selected: $family" unless $ret == 0;

  # This should only occur when no keymap is available
  if ($family eq '') {
    # Tell other programs (eg. install-keymap) not to do anything
    print STDERR "NONE";
    exit 0;
  }

  ($ret, $layout) = get ("console-data/keymap/$cfamily/layout");
  $clayout = correctname $layout;
#  die "No keyboard layout selected: $layout" unless $ret == 0;
  if ($ret != 0) {
    print STDERR "NONE";
    exit 0;
  }

  ($ret, $kbdvariant) = get ("console-data/keymap/$cfamily/$clayout/variant");
  $ckbdvariant = correctname $kbdvariant;
  die "No keyboard variant selected: $kbdvariant" unless $ret == 0;

  ($ret, $mapvariant) = get ("console-data/keymap/$cfamily/$clayout/$ckbdvariant/keymap");
  die "No keymap variant selected: $mapvariant" unless $ret == 0;


  # Get list of keymap definitions
  $defsdir = "/usr/share/console/lists/keymaps";
  $keymaps = {};
  readfiles ($defsdir);


  # Find the right one
  foreach my $kbdarch (@{$keymap_defs->{archsets}->{guess_arch($keymap_defs)}}) {
    my $maps = $keymaps->{$kbdarch};

    $maps = $maps->{$family};
    unless (defined $maps) {
      warn "Family not found ($family)"; next;
    }

    # 'Norwegian' had a typo in a previous version thus some people still
    # have this string in their debconf database.
    $layout =~ s/Norvegian/Norwegian/;

    $maps = $maps->{$layout};
    unless (defined $maps) {
      warn "Layout not found ($layout)"; next;
    }

    $maps = $maps->{$kbdvariant};
    unless (defined $maps) {
      warn "Keyboard variant not found ($kbdvariant)"; next;
    }

    $filename = $maps->{$mapvariant};
    unless (defined $filename) {
      warn "Keymap variant not found ($mapvariant)"; next;
    }
  }
}

die "No matching map found" unless defined $filename;

# output result
print STDERR "$filename\n";