wok diff syslinux/stuff/tools/keytab-lilo.pl @ rev 20402
lzip, lziprecover: add README
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Thu Jun 28 11:52:57 2018 +0200 (2018-06-28) |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/syslinux/stuff/tools/keytab-lilo.pl Thu Jun 28 11:52:57 2018 +0200 1.3 @@ -0,0 +1,111 @@ 1.4 +#!/usr/bin/perl 1.5 +# -------------------------------------------------------------------------- 1.6 +# This program was taken from the LILO-20 distribution; only this header 1.7 +# was added. 1.8 +# 1.9 +# LILO program code, documentation and auxiliary programs are 1.10 +# Copyright 1992-1997 Werner Almesberger. 1.11 +# All rights reserved. 1.12 +# 1.13 +# Redistribution and use in source and binary forms of parts of or the 1.14 +# whole original or derived work are permitted provided that the 1.15 +# original work is properly attributed to the author. The name of the 1.16 +# author may not be used to endorse or promote products derived from 1.17 +# this software without specific prior written permission. This work 1.18 +# is provided "as is" and without any express or implied warranties. 1.19 +# -------------------------------------------------------------------------- 1.20 + 1.21 +eval { use bytes; }; eval { binmode STDOUT; }; 1.22 + 1.23 +$DEFAULT_PATH = "/usr/lib/kbd/keytables"; 1.24 +$DEFAULT_MAP = "us"; 1.25 +$DEFAULT_EXT = ".map"; 1.26 + 1.27 +sub usage 1.28 +{ 1.29 + print STDERR 1.30 + "usage: $0 [ -p old_code=new_code ] ...\n". 1.31 + (" "x(8+length $0))."[path]default_layout[.map] ] ". 1.32 + "[path]kbd_layout[.map]\n"; 1.33 + exit 1; 1.34 +} 1.35 + 1.36 + 1.37 +while ($ARGV[0] eq "-p") { 1.38 + shift(@ARGV); 1.39 + &usage unless $ARGV[0] =~ /=/; 1.40 + $table[eval($`)] = eval($'); 1.41 + shift(@ARGV); 1.42 +} 1.43 +&usage unless defined $ARGV[0]; 1.44 +load_map("def",defined $ARGV[1] ? $ARGV[0] : undef); 1.45 +load_map("kbd",defined $ARGV[1] ? $ARGV[1] : $ARGV[0]); 1.46 +&build_table("plain","shift","ctrl","altgr","shift_ctrl", 1.47 + "altgr_ctrl","alt","shift_alt","ctrl_alt"); 1.48 +for ($i = 0; $i < 256; $i++) { 1.49 + printf("%c",$table[$i] ? $table[$i] : $i) || die "print: $!"; 1.50 +} 1.51 +close STDOUT || die "close: $!"; 1.52 + 1.53 + 1.54 +sub load_map 1.55 +{ 1.56 + local ($pfx,$map) = @_; 1.57 + local ($empty,$current); 1.58 + 1.59 + $map = $DEFAULT_MAP unless defined $map; 1.60 + $map = $DEFAULT_PATH."/".$map unless $map =~ m|/|; 1.61 + $map .= $DEFAULT_EXT unless $map =~ m|/[^/]+\.[^/]+$|; 1.62 + if (!open(FILE,"loadkeys -m $map |")) { 1.63 + print STDERR "loadkeys -m $map: $!\n"; 1.64 + exit 1; 1.65 + } 1.66 + undef $current; 1.67 + $empty = 1; 1.68 + while (<FILE>) { 1.69 + chop; 1.70 + if (/^(static\s+)?u_short\s+(\S+)_map\[\S+\]\s+=\s+{\s*$/) { 1.71 + die "active at beginning of map" if defined $current; 1.72 + $current = $pfx.":".$2; 1.73 + next; 1.74 + } 1.75 + undef $current if /^};\s*$/; 1.76 + next unless defined $current; 1.77 + s/\s//g; 1.78 + $map{$current} .= $_; 1.79 + $empty = 0; 1.80 + } 1.81 + close FILE; 1.82 + return unless $empty; 1.83 + print STDERR "Keymap is empty\n"; 1.84 + exit 1; 1.85 +} 1.86 + 1.87 + 1.88 +sub build_table 1.89 +{ 1.90 + local (@maps) = @_; 1.91 + local (@tmp); 1.92 + 1.93 + $set = 0; 1.94 + for $map (@maps) { 1.95 + $code = $set; 1.96 + for (split(",",$map{"def:".$map})) { 1.97 + die "bad map entry $_ (def, map $map)" unless /^0x\S\S(\S\S)$/; 1.98 + $tmp[$code] = hex $1 unless $tmp[$code]; 1.99 + $code++; 1.100 + } 1.101 + $set += 256; 1.102 + } 1.103 + $set = 0; 1.104 + for $map (@maps) { 1.105 + $code = $set; 1.106 + for (split(",",$map{"kbd:".$map})) { 1.107 + die "bad map entry $_ (kbd, map $map)" unless /^0x\S\S(\S\S)$/; 1.108 + $table[$tmp[$code]] = hex $1 unless $table[$tmp[$code]]; 1.109 + $code++; 1.110 + } 1.111 + $set += 256; 1.112 + } 1.113 + $table[0] = 0; 1.114 +}