home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 8 Other / 08-Other.zip / pmvnc100.zip / keymap.c < prev    next >
C/C++ Source or Header  |  1999-05-17  |  2KB  |  97 lines

  1. /*
  2.  * keymap.c - PM VNC Viewer, user defined scan key mapping
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8.  
  9. #define INCL_PM
  10. #include <os2.h>
  11.  
  12. #include "pmvncdef.h"
  13. #include "keysymdef.h"
  14.  
  15. /*
  16.  * Mapping Table, Scan KeyCode -> XKeySym
  17.  */
  18.  
  19. static  ULONG   usermap[256] ;
  20. static  BOOL    first = TRUE ;
  21.  
  22. /*
  23.  * kmapLoad - load user define keymap from file
  24.  */
  25.  
  26. BOOL    kmapLoad(PUCHAR name)
  27. {
  28.     int     i   ;
  29.     FILE    *fp ;
  30.     UCHAR   line[256]  ;
  31.     ULONG   scan, xkey ;    
  32.  
  33.     if (first) {
  34.         for (i = 0 ; i < 256 ; i++) {
  35.         usermap[i] = XK_VoidSymbol ;
  36.     }
  37.     first = FALSE ;
  38.     }
  39.     if ((fp = fopen(name, "r")) == NULL) {
  40.         return FALSE ;
  41.     }
  42.     
  43.     while (fgets(line, 256, fp) != NULL) {
  44.         if (line[0] == '#') {
  45.         continue ;
  46.     }
  47.     if (sscanf(line, "%x %x", &scan, &xkey) != 2) {
  48.         continue ;
  49.     }
  50.     if (scan >= 256) {
  51.         continue ;
  52.     }
  53.         TRACE("Map %x -> %x \n", scan, xkey) ;
  54.     usermap[scan] = xkey ;
  55.     }
  56.     fclose(fp)  ;
  57.  
  58. #ifdef  DEBUG
  59.     for (i = 0 ; i < 256 ; i++) {
  60.         if (usermap[i] != XK_VoidSymbol) {
  61.         printf("%02x -> %x\n", i, usermap[i]) ;
  62.     }
  63.     }
  64. #endif
  65.     return TRUE ;
  66. }
  67.  
  68. /*
  69.  * kmapFree - dispose user keymap (nothing to do now)
  70.  */
  71.  
  72. void    kmapFree(void)
  73. {
  74.     return ;
  75. }
  76.  
  77. /*
  78.  * kmapQuery - query user keymap
  79.  */
  80.  
  81. ULONG   kmapQuery(USHORT sc)
  82. {
  83.     int     i ;
  84.  
  85.     if (first) {
  86.         for (i = 0 ; i < 256 ; i++) {
  87.         usermap[i] = XK_VoidSymbol ;
  88.     }
  89.     first = FALSE ;
  90.     }
  91.  
  92.     TRACE("kmapQuery %02x %x\n", sc, usermap[sc & 0xff]) ;
  93.     return usermap[sc & 0xff];
  94. }
  95.  
  96.  
  97.