1#!/usr/bin/env python2
2# -*-Python-*-
3#
4#
5# Copyright (C) 2001  Peter �strand <peter@cendio.se>
6#
7# This program is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; version 2 of the License.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License along
17# with this program; if not, write to the Free Software Foundation, Inc.,
18# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20import sys
21
22def main():
23    f = open(sys.argv[1])
24    while 1:
25        line = f.readline()
26        if not line: break
27
28        if line.startswith("#") or line.startswith("include"):
29            print line,
30            continue
31
32        fields = line.split()
33
34        if line.startswith("map"):
35            print "map 0x%s" % fields[1]
36            continue
37
38        scancode = fields[0]
39        for pos in range(1, len(fields)):
40            keysym = fields[pos]
41
42            if pos == 1:
43                modifiers = ""
44            elif pos == 2:
45                modifiers = "shift"
46            elif pos == 3:
47                modifiers = "altgr"
48            elif pos == 4:
49                modifiers = "shift altgr"
50            else:
51                raise("Invalid line: %s" % line)
52
53            print "%s 0x%s %s" % (keysym, scancode, modifiers)
54
55
56
57if __name__ == "__main__":
58    if len(sys.argv) < 2:
59        print "Convert old-style keymaps to new style"
60        print "Usage: %s <old-style-keymap>" % sys.argv[0]
61        sys.exit(1)
62    else:
63        main()
64