~ubuntu-branches/ubuntu/raring/freerdp/raring

« back to all changes in this revision

Viewing changes to keymaps/xkb.pl

  • Committer: Bazaar Package Importer
  • Author(s): Otavio Salvador
  • Date: 2010-06-23 21:39:09 UTC
  • Revision ID: james.westby@ubuntu.com-20100623213909-bb9pvvv03913tdv6
Tags: upstream-0.7.1
ImportĀ upstreamĀ versionĀ 0.7.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
 
 
3
# rdesktop: A Remote Desktop Protocol client.
 
4
# User interface services - XKB Configuration Files Exporter
 
5
 
 
6
# Copyright (C) Marc-Andre Moreau <marcandre.moreau@gmail.com> 2009
 
7
 
 
8
# This program is free software; you can redistribute it and/or modify
 
9
# it under the terms of the GNU General Public License as published by
 
10
# the Free Software Foundation; either version 2 of the License, or
 
11
# (at your option) any later version.
 
12
 
 
13
# This program is distributed in the hope that it will be useful,
 
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
# GNU General Public License for more details.
 
17
 
 
18
# You should have received a copy of the GNU General Public License
 
19
# along with this program; if not, write to the Free Software
 
20
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
21
 
 
22
# Description:
 
23
# Script to export XKB configuration files to keycode -> virtual key code keymaps that are
 
24
# easy to use in rdesktop. This makes keymap maintenance easier to make as all bugs can
 
25
# simply be reported to the XKB Configuration Database project, and then this script can
 
26
# be used to export newer (and fixed) version of the XKB Configuration Database.
 
27
 
 
28
use Cwd;
 
29
 
 
30
my %sym2virt = (
 
31
        "AE00" => "VK_TILDE",
 
32
        "AE01" => "VK_KEY_1",
 
33
        "AE02" => "VK_KEY_2",
 
34
        "AE03" => "VK_KEY_3",
 
35
        "AE04" => "VK_KEY_4",
 
36
        "AE05" => "VK_KEY_5",
 
37
        "AE06" => "VK_KEY_6",
 
38
        "AE07" => "VK_KEY_7",
 
39
        "AE08" => "VK_KEY_8",
 
40
        "AE09" => "VK_KEY_9",
 
41
        "AE10" => "VK_KEY_0",
 
42
        "AE11" => "VK_OEM_MINUS",
 
43
        "AE12" => "VK_OEM_PLUS",
 
44
 
 
45
        "AD01" => "VK_KEY_Q",
 
46
        "AD02" => "VK_KEY_W",
 
47
        "AD03" => "VK_KEY_E",
 
48
        "AD04" => "VK_KEY_R",
 
49
        "AD05" => "VK_KEY_T",
 
50
        "AD06" => "VK_KEY_Y",
 
51
        "AD07" => "VK_KEY_U",
 
52
        "AD08" => "VK_KEY_I",
 
53
        "AD09" => "VK_KEY_O",
 
54
        "AD10" => "VK_KEY_P",
 
55
        "AD11" => "VK_OEM_4",
 
56
        "AD12" => "VK_OEM_6",
 
57
 
 
58
        "AC01" => "VK_KEY_A",
 
59
        "AC02" => "VK_KEY_S",
 
60
        "AC03" => "VK_KEY_D",
 
61
        "AC04" => "VK_KEY_F",
 
62
        "AC05" => "VK_KEY_G",
 
63
        "AC06" => "VK_KEY_H",
 
64
        "AC07" => "VK_KEY_J",
 
65
        "AC08" => "VK_KEY_K",
 
66
        "AC09" => "VK_KEY_L",
 
67
        "AC10" => "VK_OEM_1",
 
68
        "AC11" => "VK_OEM_7",
 
69
        "AC12" => "VK_OEM_5",
 
70
 
 
71
        "AB00" => "VK_LSHIFT",
 
72
        "AB01" => "VK_KEY_Z",
 
73
        "AB02" => "VK_KEY_X",
 
74
        "AB03" => "VK_KEY_C",
 
75
        "AB04" => "VK_KEY_V",
 
76
        "AB05" => "VK_KEY_B",
 
77
        "AB06" => "VK_KEY_N",
 
78
        "AB07" => "VK_KEY_M",
 
79
        "AB08" => "VK_OEM_COMMA",
 
80
        "AB09" => "VK_OEM_PERIOD",
 
81
        "AB10" => "VK_OEM_2",
 
82
        "AB11" => "VK_RSHIFT",
 
83
 
 
84
        "FK01" => "VK_F1",
 
85
        "FK02" => "VK_F2",
 
86
        "FK03" => "VK_F3",
 
87
        "FK04" => "VK_F4",
 
88
        "FK05" => "VK_F5",
 
89
        "FK06" => "VK_F6",
 
90
        "FK07" => "VK_F7",
 
91
        "FK08" => "VK_F8",
 
92
        "FK09" => "VK_F9",
 
93
        "FK10" => "VK_F10",
 
94
        "FK11" => "VK_F11",
 
95
        "FK12" => "VK_F12",
 
96
        "FK13" => "VK_F13",
 
97
        "FK14" => "VK_F14",
 
98
        "FK15" => "VK_F15",
 
99
        "FK16" => "VK_F16",
 
100
        "FK17" => "VK_F17",
 
101
        "FK18" => "VK_F18",
 
102
        "FK19" => "VK_F19",
 
103
        "FK20" => "VK_F20",
 
104
        "FK21" => "VK_F21",
 
105
        "FK22" => "VK_F22",
 
106
        "FK23" => "VK_F23",
 
107
        "FK24" => "VK_F24",
 
108
 
 
109
        "KP0" => "VK_NUMPAD0",
 
110
        "KP1" => "VK_NUMPAD1",
 
111
        "KP2" => "VK_NUMPAD2",
 
112
        "KP3" => "VK_NUMPAD3",
 
113
        "KP4" => "VK_NUMPAD4",
 
114
        "KP5" => "VK_NUMPAD5",
 
115
        "KP6" => "VK_NUMPAD6",
 
116
        "KP7" => "VK_NUMPAD7",
 
117
        "KP8" => "VK_NUMPAD8",
 
118
        "KP9" => "VK_NUMPAD9",
 
119
 
 
120
        "KPDV" => "VK_DIVIDE",
 
121
        "KPMU" => "VK_MULTIPLY",
 
122
        "KPSU" => "VK_SUBTRACT",
 
123
        "KPAD" => "VK_ADD",
 
124
        "KPDL" => "VK_DECIMAL",
 
125
        "KPEN" => "VK_RETURN",
 
126
 
 
127
        "RTRN" => "VK_RETURN",
 
128
        "SPCE" => "VK_SPACE",
 
129
        "BKSP" => "VK_BACK",
 
130
        "BKSL" => "VK_OEM_5",
 
131
        "LSGT" => "VK_OEM_102",
 
132
        "ESC" => "VK_ESCAPE",
 
133
        "TLDE" => "VK_OEM_3",
 
134
        "CAPS" => "VK_CAPITAL",
 
135
        "TAB" => "VK_TAB",
 
136
        "LFSH" => "VK_LSHIFT",
 
137
        "RTSH" => "VK_RSHIFT",
 
138
        "LCTL" => "VK_LCONTROL",
 
139
        "RCTL" => "VK_RCONTROL",
 
140
        "LWIN" => "VK_LWIN",
 
141
        "RWIN" => "VK_RWIN",
 
142
        "LALT" => "VK_LMENU",
 
143
        "RALT" => "VK_RMENU",
 
144
        "COMP" => "VK_APPS",
 
145
        "MENU" => "VK_APPS",
 
146
        "UP" => "VK_UP",
 
147
        "DOWN" => "VK_DOWN",
 
148
        "LEFT" => "VK_LEFT",
 
149
        "RGHT" => "VK_RIGHT",
 
150
        "INS" => "VK_INSERT",
 
151
        "DELE" => "VK_DELETE",
 
152
        "PGUP" => "VK_PRIOR",
 
153
        "PGDN" => "VK_NEXT",
 
154
        "HOME" => "VK_HOME",
 
155
        "END" => "VK_END",
 
156
        "PAUS" => "VK_PAUSE",
 
157
        "NMLK" => "VK_NUMLOCK",
 
158
        "SCLK" => "VK_SCROLL",
 
159
 
 
160
        # This page helps understanding the keys that follow:
 
161
        # http://www.stanford.edu/class/cs140/projects/pintos/specs/kbd/scancodes-7.html
 
162
 
 
163
        "KANJ" => "VK_KANJI",
 
164
        "HANJ" => "VK_HANJA",
 
165
        "MUHE" => "VK_NONCONVERT",
 
166
        "HIRA" => "VK_KANA",
 
167
        "PRSC" => "VK_SNAPSHOT",
 
168
 
 
169
        "KPF1" => "VK_NUMLOCK",
 
170
        "KPF2" => "VK_DIVIDE",
 
171
        "KPF3" => "VK_MULTIPLY",
 
172
        "KPF4" => "VK_SUBTRACT",
 
173
        "KPCO" => "VK_ADD",
 
174
 
 
175
        "HELP" => "VK_HELP",
 
176
        "SELE" => "VK_SELECT",
 
177
 
 
178
        # We can ignore LDM (Lock Down Modifier)
 
179
        # What are LCMP/RCMP?
 
180
        # DO, FIND?
 
181
 
 
182
);
 
183
 
 
184
my $inDir;
 
185
my $outDir;
 
186
 
 
187
if(@ARGV < 1) {
 
188
        $inDir = getcwd() . "/";
 
189
        $outDir = $inDir;
 
190
} elsif(@ARGV == 1) {
 
191
        $inDir = $ARGV[0];
 
192
        $outDir = getcwd() . "/";
 
193
} elsif(@ARGV == 2) {
 
194
        $inDir = $ARGV[0];
 
195
        $outDir = $ARGV[1];
 
196
} else {
 
197
        print   "Error: Too many arguments\n" .
 
198
                "Usage:\n" .
 
199
                "perl xkb.pl <XKB Directory>\n" .
 
200
                "perl xkb.pl <XKB Directory> <Output Directory>\n\n" .
 
201
                "In Linux, the XKB directory usually is /usr/share/X11/xkb/\n" .
 
202
                "The latest version of XKB can always be downloaded at:\n" .
 
203
                "http://freedesktop.org/wiki/Software/XKeyboardConfig\n";
 
204
                exit 0;
 
205
}
 
206
 
 
207
 
 
208
 
 
209
open("SPEC", $inDir . "xkeyboard-config.spec");
 
210
 
 
211
$xkbVersion = "";
 
212
while($line = <SPEC>) {
 
213
        if($line =~ m/Version:\s+(.\..)/) {
 
214
                $xkbVersion = "version $1";
 
215
        }
 
216
}
 
217
 
 
218
# Create directory if it does not exists
 
219
if(not -e $outDir) {
 
220
        mkdir $outDir or die("Error: Can't create directory $outDir\n");
 
221
}
 
222
 
 
223
open("KCD", $inDir . "keycodes/keycodes.dir") or die("Error: Can't open $inDir" . "keycodes/keycodes.dir\n");
 
224
 
 
225
$previousFile = "";
 
226
while($line = <KCD>) {
 
227
        if($line =~ m/........ -------- (.+)\((.+)\)/) {
 
228
                if($1 ne $previousFile) {
 
229
                        push(@keymapFiles, $1);
 
230
                        $previousFile = $1;
 
231
                }
 
232
        }       
 
233
}
 
234
close("KCD");
 
235
 
 
236
foreach $keymapFile (@keymapFiles) {
 
237
 
 
238
                print "File $keymapFile:\n";
 
239
 
 
240
                @directories = split(/\//, $keymapFile);
 
241
                splice(@directories, @directories - 1, 1); 
 
242
 
 
243
                if(@directories > 0) {
 
244
                        $directory = $outDir;           
 
245
                        for($i = 0; $i < @directories; $i++) {
 
246
                                $directory .= $directories[$i] . "/";
 
247
                                if(not -e $directory) {
 
248
                                        mkdir $directory or die("Can't create directory $directory\n");                         
 
249
                                }                       
 
250
                        }
 
251
                }
 
252
 
 
253
                open("IN", $inDir . "keycodes/" . $keymapFile);
 
254
                open("OUT", ">" . "$outDir" . $keymapFile);
 
255
 
 
256
                $time = localtime();
 
257
                print OUT "# This file was generated with xkb.pl ($time)\n";
 
258
                print OUT "# and is based on the X Keyboard Configuration Database $xkbVersion\n";
 
259
                print OUT "# Please use xkb.pl to re-export newer versions of XKB\n";
 
260
                print OUT "\n\n";
 
261
 
 
262
                while($line = <IN>) {
 
263
                        if($line =~ m/xkb_keycodes \"(\w+)\"/) {
 
264
 
 
265
                                print "Exporting \"$1\"\n";
 
266
                                print OUT "keyboard \"$1\"";
 
267
 
 
268
 
 
269
                                while($line = <IN>) {
 
270
                                        if($line =~ m/include\W+\"(.+)\"/) {
 
271
                                                print OUT "\n: extends \"$1\"";
 
272
                                                last;
 
273
                                        } else {
 
274
                                                last;
 
275
                                        }
 
276
                                }
 
277
                                print OUT "\n{\n";              
 
278
 
 
279
                                while($line = <IN>) {
 
280
                                        if($line =~ m/<(\w{1,4})>\W+=\W+(\w+);/) {
 
281
                                                if($sym2virt{$1} ne undef) {
 
282
                                                        $vkcode = $sym2virt{$1};
 
283
                                                        print OUT "\t$vkcode";
 
284
 
 
285
                                                        if(length($vkcode) < 8) {
 
286
                                                                print OUT "\t";
 
287
                                                        }
 
288
                                                        print OUT "\t<$2>\n";
 
289
                                                } else {
 
290
                                                        # If undef, then this symbolic key code is
 
291
                                                        # missing from the sym2virt hash table
 
292
                                                        # print "\t$1\t$2\n";
 
293
                                                }
 
294
                                        } elsif($line =~ m/};/) {
 
295
                                                print OUT "};\n\n";
 
296
                                                last;
 
297
                                        }
 
298
                                }
 
299
                        }
 
300
                }
 
301
 
 
302
                close("IN");
 
303
                close("OUT");
 
304
}
 
305
 
 
306