4 eval { binmode STDOUT
; };
7 $DEFAULT_EXT = ".kmap";
12 "usage: $0 [ -p old_code=new_code ] ...\n".
13 (" "x
(8+length $0))."[path]default_layout[.kmap] ] ".
14 "[path]kbd_layout[.kmap]\n";
19 while ($ARGV[0] eq "-p") {
21 &usage
unless $ARGV[0] =~ /=/;
22 $table[eval($`)] = eval($');
25 &usage unless defined $ARGV[0];
26 load_map("def",defined $ARGV[1] ? $ARGV[0] : undef);
27 load_map("kbd",defined $ARGV[1] ? $ARGV[1] : $ARGV[0]);
28 &build_table("plain","shift","ctrl","altgr","shift_ctrl",
29 "altgr_ctrl","alt","shift_alt","ctrl_alt");
30 for ($i = 0; $i < 256; $i++) {
31 printf("%c",$table[$i] ? $table[$i] : $i) || die "print: $!";
33 close STDOUT || die "close: $!";
38 local ($pfx,$map) = @_;
39 local ($empty,$current);
41 $map = $DEFAULT_MAP unless defined $map;
42 $map .= $DEFAULT_EXT unless $map =~ m|/[^/]+\.[^/]+$|;
43 if (!open(FILE,"loadkeys -m $map |")) {
44 print STDERR "loadkeys -m $map: $!\n";
51 if (/^(static\s+)?u_short\s+(\S+)_map\[\S*\]\s+=\s+{\s*$/) {
52 die "active at beginning of map" if defined $current;
53 $current = $pfx.":".$2;
56 undef $current if /^};\s*$/;
57 next unless defined $current;
64 print STDERR "Keymap is empty\n";
77 for (split(",",$map{"def:".$map})) {
78 die "bad map entry $_ (def, map $map)" unless /^0x\S\S(\S\S)$/;
79 $tmp[$code] = hex $1 unless $tmp[$code];
87 for (split(",",$map{"kbd:".$map})) {
88 die "bad map entry $_ (kbd, map $map)" unless /^0x\S\S(\S\S)$/;
89 $table[$tmp[$code]] = hex $1 unless $table[$tmp[$code]];