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.

genkeyuscmap.py 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/usr/bin/python3
  2. import os
  3. import re
  4. origin = os.path.realpath(os.path.dirname(__file__))
  5. fn = os.path.join(origin, '..', 'common', 'rfb', 'keysymdef.h')
  6. keys = {}
  7. prog = re.compile('#define\s+XK_([^\s]+)\s*0x([0-9A-Fa-f]+)\s*/[*].\s*U[+]([0-9A-Fa-f]+)\s+([^*]+)\s*.[*]/')
  8. with open(fn) as f:
  9. for line in f:
  10. m = prog.search(line)
  11. if m is None:
  12. continue
  13. (ksname, ks, ucs, ucsname) = m.group(1, 2, 3, 4)
  14. ks = int(ks, 16)
  15. ucs = int(ucs, 16)
  16. if (ks == ucs) and \
  17. (((ks >= 0x20) and (ks <= 0x7f)) or \
  18. ((ks >= 0xa0) and (ks <= 0xff))):
  19. continue
  20. if (ks & 0xff000000) == 0x01000000:
  21. assert ks == ucs | 0x01000000
  22. continue
  23. assert ks not in keys
  24. keys[ks] = { 'name': ksname, 'ucs': ucs, 'ucsname': ucsname }
  25. print("""/*
  26. * This file is auto-generated from keysymdef.h
  27. */
  28. struct codepair {
  29. unsigned short keysym;
  30. unsigned short ucs;
  31. };
  32. static const struct codepair keysymtab[] = {""")
  33. maxlen = max([ len(keys[ks]['name']) for ks in keys ])
  34. for ks in sorted(keys):
  35. key = keys[ks]
  36. if (key['ucs'] < 0x20) or key['ucs'] == 0x7f:
  37. ch = ' '
  38. else:
  39. ch = chr(key['ucs'])
  40. print(" { 0x%04x, 0x%04x }, /* %0*s %s %s */" %
  41. (ks, key['ucs'], maxlen, key['name'], ch, key['ucsname']))
  42. print("};")