a180a41bba1d50822df23fff0099e90b86638b89vboxsync#!/usr/bin/env python2
a180a41bba1d50822df23fff0099e90b86638b89vboxsync# -*-Python-*-
a180a41bba1d50822df23fff0099e90b86638b89vboxsync#
a180a41bba1d50822df23fff0099e90b86638b89vboxsync# Copyright 2001 Peter Åstrand <astrand@cendio.se> for Cendio AB
a180a41bba1d50822df23fff0099e90b86638b89vboxsync#
a180a41bba1d50822df23fff0099e90b86638b89vboxsync# This program is free software; you can redistribute it and/or modify
a180a41bba1d50822df23fff0099e90b86638b89vboxsync# it under the terms of the GNU General Public License as published by
a180a41bba1d50822df23fff0099e90b86638b89vboxsync# the Free Software Foundation; version 2 of the License.
a180a41bba1d50822df23fff0099e90b86638b89vboxsync#
a180a41bba1d50822df23fff0099e90b86638b89vboxsync# This program is distributed in the hope that it will be useful,
a180a41bba1d50822df23fff0099e90b86638b89vboxsync# but WITHOUT ANY WARRANTY; without even the implied warranty of
a180a41bba1d50822df23fff0099e90b86638b89vboxsync# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a180a41bba1d50822df23fff0099e90b86638b89vboxsync# GNU General Public License for more details.
a180a41bba1d50822df23fff0099e90b86638b89vboxsync#
a180a41bba1d50822df23fff0099e90b86638b89vboxsync# You should have received a copy of the GNU General Public License
a180a41bba1d50822df23fff0099e90b86638b89vboxsync# along with this program; if not, write to the Free Software
a180a41bba1d50822df23fff0099e90b86638b89vboxsync# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsyncimport sys
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsyncdef main():
a180a41bba1d50822df23fff0099e90b86638b89vboxsync f = open(sys.argv[1])
a180a41bba1d50822df23fff0099e90b86638b89vboxsync while 1:
a180a41bba1d50822df23fff0099e90b86638b89vboxsync line = f.readline()
a180a41bba1d50822df23fff0099e90b86638b89vboxsync if not line: break
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsync if line.startswith("#") or line.startswith("include"):
a180a41bba1d50822df23fff0099e90b86638b89vboxsync print line,
a180a41bba1d50822df23fff0099e90b86638b89vboxsync continue
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsync fields = line.split()
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsync if line.startswith("map"):
a180a41bba1d50822df23fff0099e90b86638b89vboxsync print "map 0x%s" % fields[1]
a180a41bba1d50822df23fff0099e90b86638b89vboxsync continue
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsync scancode = fields[0]
a180a41bba1d50822df23fff0099e90b86638b89vboxsync for pos in range(1, len(fields)):
a180a41bba1d50822df23fff0099e90b86638b89vboxsync keysym = fields[pos]
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsync if pos == 1:
a180a41bba1d50822df23fff0099e90b86638b89vboxsync modifiers = ""
a180a41bba1d50822df23fff0099e90b86638b89vboxsync elif pos == 2:
a180a41bba1d50822df23fff0099e90b86638b89vboxsync modifiers = "shift"
a180a41bba1d50822df23fff0099e90b86638b89vboxsync elif pos == 3:
a180a41bba1d50822df23fff0099e90b86638b89vboxsync modifiers = "altgr"
a180a41bba1d50822df23fff0099e90b86638b89vboxsync elif pos == 4:
a180a41bba1d50822df23fff0099e90b86638b89vboxsync modifiers = "shift altgr"
a180a41bba1d50822df23fff0099e90b86638b89vboxsync else:
a180a41bba1d50822df23fff0099e90b86638b89vboxsync raise("Invalid line: %s" % line)
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsync print "%s 0x%s %s" % (keysym, scancode, modifiers)
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsyncif __name__ == "__main__":
a180a41bba1d50822df23fff0099e90b86638b89vboxsync if len(sys.argv) < 2:
a180a41bba1d50822df23fff0099e90b86638b89vboxsync print "Convert old-style keymaps to new style"
a180a41bba1d50822df23fff0099e90b86638b89vboxsync print "Usage: %s <old-style-keymap>" % sys.argv[0]
a180a41bba1d50822df23fff0099e90b86638b89vboxsync sys.exit(1)
a180a41bba1d50822df23fff0099e90b86638b89vboxsync else:
a180a41bba1d50822df23fff0099e90b86638b89vboxsync main()