home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1996 October / PCO_10.ISO / filesbbs / bsrc_260.arj / SRC.ZIP / keymap.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-21  |  4.6 KB  |  102 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*                                                                          */
  4. /*      ------------         Bit-Bucket Software, Co.                       */
  5. /*      \ 10001101 /         Writers and Distributors of                    */
  6. /*       \ 011110 /          Freely Available<tm> Software.                 */
  7. /*        \ 1011 /                                                          */
  8. /*         ------                                                           */
  9. /*                                                                          */
  10. /*              (C) Copyright 1987-96, Bit Bucket Software Co.              */
  11. /*                                                                          */
  12. /*                    This module was written by Harry Lee                  */
  13. /*                                                                          */
  14. /*                        Keyboard Remapping Routine                        */
  15. /*                                                                          */
  16. /*                                                                          */
  17. /*    For complete  details  of the licensing restrictions, please refer    */
  18. /*    to the License  agreement,  which  is published in its entirety in    */
  19. /*    the MAKEFILE and BT.C, and also contained in the file LICENSE.260.    */
  20. /*                                                                          */
  21. /*    USE  OF THIS FILE IS SUBJECT TO THE  RESTRICTIONS CONTAINED IN THE    */
  22. /*    BINKLEYTERM  LICENSING  AGREEMENT.  IF YOU DO NOT FIND THE TEXT OF    */
  23. /*    THIS  AGREEMENT IN ANY OF THE  AFOREMENTIONED FILES,  OR IF YOU DO    */
  24. /*    NOT HAVE THESE FILES,  YOU  SHOULD  IMMEDIATELY CONTACT BIT BUCKET    */
  25. /*    SOFTWARE CO.  AT ONE OF THE  ADDRESSES  LISTED BELOW.  IN NO EVENT    */
  26. /*    SHOULD YOU  PROCEED TO USE THIS FILE  WITHOUT HAVING  ACCEPTED THE    */
  27. /*    TERMS  OF  THE  BINKLEYTERM  LICENSING  AGREEMENT,  OR  SUCH OTHER    */
  28. /*    AGREEMENT AS YOU ARE ABLE TO REACH WITH BIT BUCKET SOFTWARE, CO.      */
  29. /*                                                                          */
  30. /*                                                                          */
  31. /* You can contact Bit Bucket Software Co. at any one of the following      */
  32. /* addresses:                                                               */
  33. /*                                                                          */
  34. /* Bit Bucket Software Co.        FidoNet  1:104/501, 1:343/491             */
  35. /* P.O. Box 460398                AlterNet 7:42/1491                        */
  36. /* Aurora, CO 80046               BBS-Net  86:2030/1                        */
  37. /*                                Internet f491.n343.z1.fidonet.org         */
  38. /*                                                                          */
  39. /* Please feel free to contact us at any time to share your comments about  */
  40. /* our software and/or licensing policies.                                  */
  41. /*                                                                          */
  42. /*--------------------------------------------------------------------------*/
  43.  
  44. /* Include this file before any other includes or defines! */
  45.  
  46. #include "includes.h"
  47.  
  48. static struct _key_fnc_hdr *CrntKeyFncHdr;
  49.  
  50. struct _key_fnc_hdr *
  51. KbMapSet (struct _key_fnc_hdr *KeyFncHdr)
  52. {
  53.     struct _key_fnc_hdr *OldKeyFncHdr = CrntKeyFncHdr;
  54.  
  55.     CrntKeyFncHdr = KeyFncHdr;
  56.     return OldKeyFncHdr;
  57. }
  58.  
  59. short 
  60. ScanCompare (struct _key_fnc *x, struct _key_fnc *y)
  61. {
  62.     return (short) (x->ScanCode - y->ScanCode);
  63. }
  64.  
  65. unsigned short pascal 
  66. KbRemap (unsigned short ScanCode)
  67. {
  68.     struct _key_fnc InFnc;
  69.     struct _key_fnc *KeyFnc;
  70.     int i;
  71.  
  72. /*
  73.  * FOSSIL keyboarding is so wierd.
  74.  *
  75.  * The spec is really clear about what you're supposed to do with
  76.  * letter and function keys. Some of the IBM FOSSILs didn't give a
  77.  * damn and put scan codes in the high order part of the character
  78.  * keys. That breaks this guy utterly. So we'll get rid of the
  79.  * bits if they happen to be there.
  80.  */
  81.  
  82.     if (ScanCode & 0xff)
  83.         ScanCode &= 0xff;        /* Clean up after Opus!Comm */
  84.  
  85.     /* If the table is empty, searching it is sort of pointless. */
  86.  
  87.     if (!CrntKeyFncHdr->KeyFncCnt)
  88.         return ScanCode;
  89.  
  90.     InFnc.ScanCode = ScanCode;
  91.  
  92.     KeyFnc = CrntKeyFncHdr->KeyFncTbl;
  93.  
  94.     for (i = CrntKeyFncHdr->KeyFncCnt; i > 0; i--, KeyFnc++)
  95.     {
  96.         if (ScanCompare (KeyFnc, &InFnc) == 0)
  97.             return KeyFnc->FncIdx;
  98.     }
  99.  
  100.     return ScanCode;
  101. }
  102.