home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 1999 May / pcp151c.iso / misc / src / trees / syslinux-1.40 / keytab-lilo.pl < prev    next >
Encoding:
Perl Script  |  1998-05-07  |  2.9 KB  |  110 lines

  1. #!/usr/bin/perl
  2. # --------------------------------------------------------------------------
  3. # This program was taken from the LILO-20 distribution; only this header
  4. # was added.
  5. #
  6. # LILO program code, documentation and auxiliary programs are
  7. # Copyright 1992-1997 Werner Almesberger.
  8. # All rights reserved.
  9. #
  10. # Redistribution and use in source and binary forms of parts of or the
  11. # whole original or derived work are permitted provided that the
  12. # original work is properly attributed to the author. The name of the
  13. # author may not be used to endorse or promote products derived from
  14. # this software without specific prior written permission. This work
  15. # is provided "as is" and without any express or implied warranties.
  16. # --------------------------------------------------------------------------
  17.  
  18. $DEFAULT_PATH = "/usr/lib/kbd/keytables";
  19. $DEFAULT_MAP = "us";
  20. $DEFAULT_EXT = ".map";
  21.  
  22. sub usage
  23. {
  24.     print STDERR
  25.       "usage: $0 [ -p old_code=new_code ] ...\n".
  26.       (" "x(8+length $0))."[path]default_layout[.map] ] ".
  27.       "[path]kbd_layout[.map]\n";
  28.     exit 1;
  29. }
  30.  
  31.  
  32. while ($ARGV[0] eq "-p") {
  33.     shift(@ARGV);
  34.     &usage unless $ARGV[0] =~ /=/;
  35.     $table[eval($`)] = eval($');
  36.     shift(@ARGV);
  37. }
  38. &usage unless defined $ARGV[0];
  39. load_map("def",defined $ARGV[1] ? $ARGV[0] : undef);
  40. load_map("kbd",defined $ARGV[1] ? $ARGV[1] : $ARGV[0]);
  41. &build_table("plain","shift","ctrl","altgr","shift_ctrl",
  42.   "altgr_ctrl","alt","shift_alt","ctrl_alt");
  43. for ($i = 0; $i < 256; $i++) {
  44.     printf("%c",$table[$i] ? $table[$i] : $i) || die "print: $!";
  45. }
  46. close STDOUT || die "close: $!";
  47.  
  48.  
  49. sub load_map
  50. {
  51.     local ($pfx,$map) = @_;
  52.     local ($empty,$current);
  53.  
  54.     $map = $DEFAULT_MAP unless defined $map;
  55.     $map = $DEFAULT_PATH."/".$map unless $map =~ m|/|;
  56.     $map .= $DEFAULT_EXT unless $map =~ m|/[^/]+\.[^/]+$|;
  57.     if (!open(FILE,"loadkeys -m $map |")) {
  58.     print STDERR "loadkeys -m $map: $!\n";
  59.     exit 1;
  60.     }
  61.     undef $current;
  62.     $empty = 1;
  63.     while (<FILE>) {
  64.     chop;
  65.     if (/^u_short\s+(\S+)_map\[\S+\]\s+=\s+{\s*$/) {
  66.         die "active at beginning of map" if defined $current;
  67.         $current = $pfx.":".$1;
  68.         next;
  69.     }
  70.     undef $current if /^};\s*$/;
  71.     next unless defined $current;
  72.     s/\s//g;
  73.     $map{$current} .= $_;
  74.     $empty = 0;
  75.     }
  76.     close FILE;
  77.     return unless $empty;
  78.     print STDERR "Keymap is empty\n";
  79.     exit 1;
  80. }
  81.  
  82.  
  83. sub build_table
  84. {
  85.     local (@maps) = @_;
  86.     local (@tmp);
  87.  
  88.     $set = 0;
  89.     for $map (@maps) {
  90.     $code = $set;
  91.     for (split(",",$map{"def:".$map})) {
  92.         die "bad map entry $_ (def, map $map)" unless /^0x\S\S(\S\S)$/;
  93.         $tmp[$code] = hex $1 unless $tmp[$code];
  94.         $code++;
  95.     }
  96.     $set += 256;
  97.     }
  98.     $set = 0;
  99.     for $map (@maps) {
  100.     $code = $set;
  101.     for (split(",",$map{"kbd:".$map})) {
  102.         die "bad map entry $_ (kbd, map $map)" unless /^0x\S\S(\S\S)$/;
  103.         $table[$tmp[$code]] = hex $1 unless $table[$tmp[$code]];
  104.         $code++;
  105.     }
  106.     $set += 256;
  107.     }
  108.     $table[0] = 0;
  109. }
  110.