Source code of Windows XP (NT5)
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.

141 lines
5.3 KiB

  1. /* cmdkeyb.h - Keyboard layout support routines
  2. * include file for CMDKEYB.C
  3. *
  4. * Modification History:
  5. *
  6. * YST 14-Jan_1993 Created
  7. */
  8. #define DOSKEYBCODES "DOSKeybCodes" // section name in layout.inf
  9. #define LAYOUT_FILE "\\LAYOUT.INF" // INF file name
  10. #define DEFAULT_KB_ID "US" // Default keyboard ID
  11. #define KEYBOARD_SYS "\\KEYBOARD.SYS" // Data file for KEYB.COM
  12. #define US_CODE "00000409" // Code for US keyboard in REGISTER.INI
  13. #define KEYB_COM "\\KB16.COM" // File name for keyboard program
  14. #define KBDLAYOUT_PATH "System\\CurrentControlSet\\Control\\Keyboard Layout\\"
  15. #define DOSCODES_PATH "DosKeybCodes"
  16. #define DOSIDS_PATH "DosKeybIDs"
  17. #define REG_STR_ALTKDF_FILES "AlternativeKDFs"
  18. #define REG_STR_WOW "SYSTEM\\CurrentControlSet\\Control\\Wow"
  19. #define KDF_SIGNATURE "\xFFKEYB "
  20. #define LANGID_BUFFER_SIZE 20
  21. #define KEYBOARDID_BUFFER_SIZE 20
  22. #define KDF_AX "\\KEYAX.SYS" // AX standard keyboard
  23. #define KDF_106 "\\KEY01.SYS" // 106 keys
  24. #define KDF_IBM5576_02_03 "\\KEY02.SYS" // IBM 5576 002/003 keyboard
  25. #define KDF_TOSHIBA_J3100 "\\KEYJ31.SYS" // Toshiba J3100 keyboard
  26. //
  27. // Dos KDF(Keyboard Definition File) format description:
  28. //
  29. // The file starts with a header(KDF_HEADER), followed
  30. // by an array of KDF_LANGID_OFFSET and then by an array of
  31. // KDF_KEYBOARDID_OFFSET. The KDF_LANGID_OFFSET array size is
  32. // determined by KDF_HEADER.TotalLangIDs while the KDF_KEYBOARDID_OFFSET
  33. // array size is determined by KDF_HEADER.TotalKeybIDs
  34. //
  35. // Each KDF_LANGID_OFFSET contains a file offset to its KDF_LANGID_ENTRY.
  36. // Each KDF_LANGID_ENTRY is followed by an array of KDF_CODEPAGEID_OFFSET.
  37. // The KDF_CODEPAGEID_OFFSET array size is determined by its assocated
  38. // KDF_LANGID_ENTRY's TotalCodePageIDs.
  39. //
  40. // For a language ID with multiple keyboard IDs, Only one entry
  41. // will be in the KDF_LANGID_OFFSET table. The rest of them are
  42. // stored in the KDF_KEYBOARDID_OFFSET table.
  43. //
  44. // Each KDF_LANGID_ENTRY plus its code page table is enough
  45. // to determine if a (language id, keyboard id, code page id) is
  46. // support by the kdf file.
  47. //
  48. // KDF file header
  49. //
  50. // must pack the structures
  51. #pragma pack(1)
  52. typedef struct tagKDFHeader
  53. {
  54. CHAR Signature[8]; // signature, must be 0xFF"KEYB "
  55. CHAR Reserved1[8];
  56. WORD MaxCommXlatSize; // maximum common xlat section size
  57. WORD MaxSpecialXlatSize; // maximum special xlat section size
  58. WORD MaxStateLogicSize; // maximum state logic section size
  59. WORD Reserved2;
  60. WORD TotalKeybIDs; // total keyboard ids defined in this file
  61. WORD TotalLangIDs; // total language ids defined in this file
  62. }KDF_HEADER, *PKDF_HEADER;
  63. #define IS_LANGID_EQUAL(src, dst) (toupper(src[0]) == toupper(dst[0]) && \
  64. toupper(src[1]) == toupper(dst[1]) )
  65. //
  66. //
  67. //
  68. typedef struct tagKDFLangIdOffset
  69. {
  70. CHAR ID[2]; // the id, "us" for U.S.A
  71. DWORD DataOffset; // file offset to its KDF_LANGID_ENTRY
  72. }KDF_LANGID_OFFSET, *PKDF_LANGID_OFFSET;
  73. typedef struct tagKDFKeyboardIdOffset
  74. {
  75. WORD ID; // the id
  76. DWORD DataOffset; // file offset to its KDF_LANGID_ENTRY
  77. }KDF_KEYBOARDID_OFFSET, *PKDF_KEYBOARDID_OFFSET;
  78. // A single lang id may associate with multiple keyboard ids and for each
  79. // keyboard id, there is one KDF_LANGID_ENTRY allocated for it.
  80. // The TotalKaybordIDs is tricky. Suppose the language id has <n> different
  81. // keyboard ids, the <i>th KDF_LANGID_ENTRY's TotalKeyboardIDs contains
  82. // the value of <n - i + 1>. As far as we are only interested in if
  83. // the kdf supports a given (language id, keyboard id, code page id> combination
  84. // we donot care how the value is set by simply following these steps:
  85. // (1). Read the KDF_LANGID_OFFSET table and for each KDF_LANGID_OFFSET,
  86. // compare the language id. If it matches, go get its KDF_LANGID_ENTRY
  87. // and compare the primary keyboard id and all its code page. If
  88. // the combination matches, we are done, otherwise, go to step 2.
  89. // (2). Read KDF_KEYBOARDID_OFFSET table and for each KDF_KEYBOARDID_OFFSET,
  90. // compare the keyboard id. If the keyboard id matches, go get its
  91. // KDF_LANGID_ENTRY and compare the language id and code page against
  92. // the KDF_LANGID_ENTRY. If both the language id and the code page id
  93. // match, we are done, otherwise, goto step 3.
  94. // (3). We conclude that this kdf does not meet the requirement.
  95. //
  96. typedef struct tagLangEntry
  97. {
  98. CHAR ID[2]; // the id
  99. WORD PrimaryKeybId; // primary keyboard id
  100. DWORD DataOffset; // file offset to state logic section
  101. BYTE TotalKeyboardIDs; // total keyboard ids
  102. BYTE TotalCodePageIDs; // total code pages
  103. }KDF_LANGID_ENTRY, *PKDF_LANGID_ENTRY;
  104. //
  105. // An array of supported KDF_CODEPAGEID_OFFSET immediately follow its
  106. // KDF_LANGID_ENTRY. The size of the array is determined by
  107. // KDF_LANGID_ENTRY.TotalCodePageIDs
  108. typedef struct tagCodePageIdOffset
  109. {
  110. WORD ID; // the id
  111. DWORD DataOffset; // file offset to the xlat section
  112. }KDF_CODEPAGEID_OFFSET, *PKDF_CODEPAGEID_OFFSET;
  113. #pragma pack()
  114. BOOL
  115. LocateKDF(
  116. CHAR* LanguageID,
  117. WORD KeyboardID,
  118. WORD CodePageID,
  119. LPSTR Buffer,
  120. DWORD* BufferSize
  121. );
  122. BOOL
  123. MatchKDF(
  124. CHAR* LanguageID,
  125. WORD KeyboardID,
  126. WORD CodePageID,
  127. LPCSTR KDFPath
  128. );