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