home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / A / KEYTBLS / _KEYTBLS.TAR / usr / lib / kbd / keytables / mk_modmap < prev    next >
Encoding:
Text File  |  1994-04-16  |  3.1 KB  |  133 lines

  1. #!/bin/sh
  2. # mk_modmap
  3. # Tries to translate a keytable file into a file parseable by xmodmap
  4. #
  5. # This is a hack, and has a lot of magic numbers and names hardcoded
  6. # into it. Suggestions on how to avoid this are welcome.
  7. #
  8. # Kjetil T. Homme, University of Oslo 1993
  9. # <kjetilho@ifi.uio.no>
  10.  
  11.  
  12. case $1 in
  13.     -v*)    verbose=1; shift ;;
  14. esac
  15.  
  16. if test ! -f /usr/include/X11/X.h; then
  17.     echo Make sure you have a link to you X include files called
  18.     echo /usr/include/X11 first.
  19.     exit 1
  20. fi
  21.  
  22. cat <<__EOH__
  23. ! Converted keytable file to xmodmap file
  24. ! with `basename $0` by `whoami`@`hostname` `date`
  25. clear Mod1
  26. clear Mod2
  27. __EOH__
  28.  
  29. awk -F'#' '
  30.     /[a-z]+.*keycode/ { next }
  31.     /^[ \t]*$/ { next }
  32.     /^string/ { next }
  33.     { sub("^[ \t]*", "") }
  34.     NF > 1 {
  35.         printf("!");
  36.         for (i = 2; i <= NF; i++) {
  37.             printf(" " $i);
  38.             $i = "";
  39.         }
  40.         print "";
  41.         if ($1 == "")
  42.             next;
  43.     }
  44.     { print }
  45. ' "$@" | awk -v verbose=$verbose '
  46.     BEGIN {
  47.         while (getline < "/usr/include/X11/keysymdef.h" == 1) {
  48.             if ($0 ~ /XK_/) {
  49.                 sub(/.*XK_/, "");
  50.                 sub(/[\t ].*/, "");
  51.                 valid[$0] = 1;
  52.             }
  53.         }
  54.         valid["X386Sys_Req"] = 1;
  55.  
  56.         shifts["Control"] = shifts["Shift"] = 1;
  57.  
  58.         shift_keys[29]  = "Control_L";
  59.         shift_keys[97]  = "Control_R";
  60.         shift_keys[42]  = "Shift_L";
  61.         shift_keys[54]  = "Shift_R";
  62.  
  63.         trans_keys[ 96] = 108; # KP_Enter
  64.         trans_keys[ 97] = 109; # Control_R
  65.         trans_keys[ 98] = 112; # KP_Divide
  66.         trans_keys[100] = 113; # Mode_switch (AltGr)
  67.         trans_keys[101] = 114; # Break
  68.         trans_keys[103] =  98; # Up
  69.         trans_keys[104] =  99; # Prior
  70.         trans_keys[105] = 100; # Left
  71.         trans_keys[106] = 102; # Right
  72.         trans_keys[108] = 104; # Down
  73.         trans_keys[109] = 105; # Next
  74.         trans_keys[110] = 106; # Insert
  75.         trans_keys[111] = 107; # Delete
  76.  
  77.         trans_names["Alt"]    = "Alt_L Meta_L";
  78.         trans_names["AltGr"]    = "Mode_switch";
  79.         trans_names["one"]    = "1";
  80.         trans_names["two"]    = "2";
  81.         trans_names["three"]    = "3";
  82.         trans_names["four"]    = "4";
  83.         trans_names["five"]    = "5";
  84.         trans_names["six"]    = "6";
  85.         trans_names["seven"]    = "7";
  86.         trans_names["eight"]    = "8";
  87.         trans_names["nine"]    = "9";
  88.         trans_names["zero"]    = "0";
  89.         trans_names["KP_Comma"]    = "KP_Decimal";
  90.         trans_names["dead_tilde"]    = "asciitilde";
  91.         trans_names["dead_circumflex"]    = "asciicircum";
  92.         trans_names["dead_acute"]    = "acute";
  93.         trans_names["dead_grave"]    = "grave";
  94.         trans_names["dead_diaeresis"]    = "diaeresis";
  95.         trans_names["Last_Console"]    = "X386Sys_Req";
  96.     }
  97.     $1 == "keycode" {
  98.         output = "";
  99.         keycode = $2;
  100.         i = ($3 == "=") ? 4 : 3;
  101.         for ( ; i <= NF; i++) {
  102.             sub(/^\+/, "", $i);
  103.             n = $i;
  104.             if ($i in shifts)
  105.                 n = shift_keys[keycode];
  106.             else if ($i in trans_names)
  107.                 n = trans_names[$i];
  108.  
  109.             if (n in valid || n in valid || $i in trans_names)
  110.                 output = output " " n;
  111.             else
  112.                 msg("Skipped " $i);
  113.         }
  114.  
  115.         if (keycode in trans_keys)
  116.             keycode = trans_keys[keycode];
  117.         else
  118.             keycode += 8;
  119.  
  120.         if (keycode >= 115)
  121.             msg("Skipped keycode " keycode-8 ": " output);
  122.          else if (output)
  123.             printf("keycode %3d =%s\n", keycode, output);
  124.         next;
  125.     }
  126.     { print }
  127.     function msg(m) { if (verbose) print m > "/dev/stderr"; }'
  128.  
  129. cat <<__EOH__
  130. add Mod1 = Alt_L
  131. add Mod2 = Mode_switch
  132. __EOH__
  133.