You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

KeysymStr.c 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. Copyright 1990, 1998 The Open Group
  3. Permission to use, copy, modify, distribute, and sell this software and its
  4. documentation for any purpose is hereby granted without fee, provided that
  5. the above copyright notice appear in all copies and that both that
  6. copyright notice and this permission notice appear in supporting
  7. documentation.
  8. The above copyright notice and this permission notice shall be included in
  9. all copies or substantial portions of the Software.
  10. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  11. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  12. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  13. OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  14. AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  15. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  16. Except as contained in this notice, the name of The Open Group shall not be
  17. used in advertising or otherwise to promote the sale, use or other dealings
  18. in this Software without prior written authorization from The Open Group.
  19. */
  20. #ifdef HAVE_CONFIG_H
  21. #include <config.h>
  22. #endif
  23. #include <stdlib.h>
  24. #include "keysymdef.h"
  25. #include "KeysymStr.h"
  26. #define NEEDKTABLE
  27. #define NEEDVTABLE
  28. #include "ks_tables.h"
  29. static const char *_XKeysymToString(unsigned ks)
  30. {
  31. if (!ks || (ks & ((unsigned long) ~0x1fffffff)) != 0)
  32. return ((char *)NULL);
  33. if (ks == XK_VoidSymbol)
  34. ks = 0;
  35. if (ks <= 0x1fffffff)
  36. {
  37. unsigned char val1 = ks >> 24;
  38. unsigned char val2 = (ks >> 16) & 0xff;
  39. unsigned char val3 = (ks >> 8) & 0xff;
  40. unsigned char val4 = ks & 0xff;
  41. int i = ks % VTABLESIZE;
  42. int h = i + 1;
  43. int n = VMAXHASH;
  44. int idx;
  45. while ((idx = hashKeysym[i]))
  46. {
  47. const unsigned char *entry = &_XkeyTable[idx];
  48. if ((entry[0] == val1) && (entry[1] == val2) &&
  49. (entry[2] == val3) && (entry[3] == val4))
  50. return ((char *)entry + 4);
  51. if (!--n)
  52. break;
  53. i += h;
  54. if (i >= VTABLESIZE)
  55. i -= VTABLESIZE;
  56. }
  57. }
  58. if (ks >= 0x01000100 && ks <= 0x0110ffff) {
  59. unsigned val = ks & 0xffffff;
  60. char *s;
  61. int i;
  62. if (val & 0xff0000)
  63. i = 10;
  64. else
  65. i = 6;
  66. s = malloc(i);
  67. if (s == NULL)
  68. return s;
  69. i--;
  70. s[i--] = '\0';
  71. for (; i; i--){
  72. unsigned char val1 = val & 0xf;
  73. val >>= 4;
  74. if (val1 < 10)
  75. s[i] = '0'+ val1;
  76. else
  77. s[i] = 'A'+ val1 - 10;
  78. }
  79. s[i] = 'U';
  80. return s;
  81. }
  82. return ((char *) NULL);
  83. }
  84. const char* KeySymName(unsigned keysym)
  85. {
  86. const char* name;
  87. name = _XKeysymToString(keysym);
  88. if (name == NULL)
  89. return "[unknown keysym]";
  90. return name;
  91. }