#!/usr/bin/perl #/* genkeymap.pl -- Guess # * # * Copyright (C) 2000 Marcus Schiesser, ymnk # * # * This program is free software; you can redistribute it and/or modify # * it under the terms of the GNU General Public License as published by # * the Free Software Foundation; either version 2 of the License, or # * (at your option) any later version. # * # * This program is distributed in the hope that it will be useful, # * but WITHOUT ANY WARRANTY; without even the implied warranty of # * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # * GNU General Public License for more details. # * # * You should have received a copy of the GNU General Public License # * along with this program; if not, write to the Free Software # * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # */ #/* # * Authors: Marcus Schiesser, # * ymnk # * # * 01-Aug-2000: This file is written by Marcus Schiesser. # * 02-Aug-2000: ymnk modifies for supporting variable width keymap tables. # * 21-Sep-2000: ymnk modifies for generating java classes. # */ # # usage: xmodmap -pk -pm | ./genkeymap.pl -n name # use Getopt::Std; getopts("n:"); $name=$opt_n; if($#ARGV>-1){ open(STDIN, "<$ARGV[0]") or die "can't open: $!"; } if($name eq ""){ $name=$ARGV[0]; } if($name eq ""){ $name="tmp"; } while(<>){ if(/^There are (\d+) KeySyms per KeyCode; KeyCodes range from (\d+) to (\d+)/){ open(STDOUT, ">Keymap_$name.java") or die "can't open output: $!"; &printkeymap($name, $1, $2, $3); close(STDOUT); next; } if(/^xmodmap: up to (\d+) keys per modifier/){ open(STDOUT, ">Keymodifier_$name.java") or die "can't open output: $!"; &printkeymod($name, $1); close(STDOUT); next; } } #close(STDIN); #close(STDOUT); sub printkeymap{ local($name, $keysyms, $from, $to)=@_; &printheader; local($result)=&keymap($keysyms, $from, $to); print <){ last if(/Value/); } <>; while(<>){ chop; s/\t/ /g; @array=split(' '); $result .= " "; for($i=1; $i<$#array; $i+=2){ $result .= $array[$i]; if($array[0]!=$to || ($i+1)/2!=$keysyms){ $result .= ", "; } else{ $result .= " "; } } $i/=2; if($i<$keysyms){ for($j=0; $j<$keysyms-$i; $j++){ $result .= "0x0000"; if($array[0]!=$to || ($j+1)<$keysyms-$i){ $result .= ", "; } else{ $result .= " "; } } } $result .= " // ".$array[0]; for($i=2; $i<=$#array; $i+=2){ $result .= " ". $array[$i]; } $result .= "\n"; } return $result; } sub printkeymod{ local($name, $kpm)=@_; &printheader; local($result)=&keymod($kpm); print <; while(<>){ last if(/^$/); chop; s/\t/ /g; @array=split(' '); $result .= " "; for($i=2; $i<=$#array; $i+=2){ if($array[$i]=~/\((.+)\)/){ $result .= "$1"; if($array[0] ne "mod5" || ($i/2)<$kpm){ $result .= ", "; } else{ $result .= " "; } } } $i/=2; if($i<=$kpm){ for($j=0; $j<=$kpm-$i; $j++){ $result .= "0x00"; if($array[0] ne "mod5" || ($j+1)<=$kpm-$i){ $result .= ", "; } else{ $result .= " "; } } } $result .= (" // [".$array[0]."] "); for($i=1; $i<=$#array; $i+=2){ $result .= (" ". $array[$i]); } $result .= "\n"; } return $result; } sub printheader{ print <