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.

306 lines
10 KiB

  1. /*************************************************
  2. * genptbl.c *
  3. * *
  4. * Copyright (C) 1995-1999 Microsoft Inc. *
  5. * *
  6. *************************************************/
  7. // ---------------------------------------------------------------------------
  8. //
  9. // This program is used to generate Phon IME tables from its text Code table
  10. //
  11. // History: 02-09-1998, Weibz, Created
  12. //
  13. // Usage: genptbl <UniText File> <Phon.tbl> <Phonptr.tbl> <phoncode.tbl>
  14. //
  15. //
  16. // --------------------------------------------------------------------------
  17. #include <stdio.h>
  18. #include <windows.h>
  19. const DWORD wChar2SeqTbl[0x42] = {
  20. // ' ' ! " # $ % & ' - char code
  21. 0x26, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // sequence code
  22. // ( ) * + , - . /
  23. 0x00, 0x00, 0x00, 0x00, 0x1C, 0x25, 0x20, 0x24,
  24. // 0 1 2 3 4 5 6 7
  25. 0x21, 0x01, 0x05, 0x28, 0x29, 0x0F, 0x27, 0x2A,
  26. // 8 9 : ; < = > ?
  27. 0x19, 0x1D, 0x00, 0x23, 0x00, 0x00, 0x00, 0x00,
  28. // @ A B C D E F G
  29. 0x00, 0x03, 0x12, 0x0B, 0x0A, 0x09, 0x0D, 0x11,
  30. // H I J K L M N O
  31. 0x14, 0x1A, 0x17, 0x1B, 0x1F, 0x18, 0x15, 0x1E,
  32. // P Q R S T U V W
  33. 0x22, 0x02, 0X0C, 0x07, 0x10, 0x16, 0x0E, 0x06,
  34. // X Y Z [ \ ] ^ _
  35. 0x08, 0x13, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00,
  36. // ` a
  37. 0x00, 0x00 };
  38. const BYTE bInverseEncode[] = {
  39. // 0 1 2 3 4 5 6 7
  40. 0x3, 0x4, 0x5, 0x0, 0x1, 0x2, 0xA, 0xB,
  41. // 8 9, A B C D E F
  42. 0xC, 0xD, 0x6, 0x7, 0x8, 0x9, 0xF, 0xE };
  43. void _cdecl main( int argc, TCHAR **argv) {
  44. HANDLE hInFile, hPhon, hPhonptr, hPhoncode;
  45. HANDLE hInMap;
  46. LPWORD lpInFile, lpStart;
  47. DWORD dwInFileSize, BytesWritten;
  48. DWORD iLine, LineLen, NumLine;
  49. int i;
  50. WORD wOutData, uCode;
  51. DWORD dwPattern, dwLastPattern;
  52. if ( argc != 5 ) {
  53. printf("usage: genptbl <UTextFile> <Phon.tbl> <phonptr.tbl> <phoncode.tbl>\n");
  54. return;
  55. }
  56. hInFile = CreateFile( argv[1], // pointer to name of the file
  57. GENERIC_READ, // access (read-write) mode
  58. FILE_SHARE_READ, // share mode
  59. NULL, // pointer to security attributes
  60. OPEN_EXISTING, // how to create
  61. FILE_ATTRIBUTE_NORMAL, // file attributes
  62. NULL);
  63. if ( hInFile == INVALID_HANDLE_VALUE ) return;
  64. hPhon = CreateFile( argv[2], // pointer to name of the file
  65. GENERIC_WRITE, // access (read-write) mode
  66. FILE_SHARE_WRITE, // share mode
  67. NULL, // pointer to security attributes
  68. CREATE_ALWAYS, // how to create
  69. FILE_ATTRIBUTE_NORMAL, // file attributes
  70. NULL);
  71. if ( hPhon == INVALID_HANDLE_VALUE ) {
  72. printf("hPhon is INVALID_HANDLE_VALUE\n");
  73. return;
  74. }
  75. hPhonptr = CreateFile(argv[3], // pointer to name of the file
  76. GENERIC_WRITE, // access (read-write) mode
  77. FILE_SHARE_WRITE, // share mode
  78. NULL, // pointer to security attributes
  79. CREATE_ALWAYS, // how to create
  80. FILE_ATTRIBUTE_NORMAL, // file attributes
  81. NULL);
  82. if ( hPhonptr == INVALID_HANDLE_VALUE ) {
  83. printf("hPhonptr is INVALID_HANDLE_VALUE\n");
  84. return;
  85. }
  86. hPhoncode = CreateFile(argv[4], // pointer to name of the file
  87. GENERIC_WRITE, // access (read-write) mode
  88. FILE_SHARE_WRITE, // share mode
  89. NULL, // pointer to security attributes
  90. CREATE_ALWAYS, // how to create
  91. FILE_ATTRIBUTE_NORMAL, // file attributes
  92. NULL);
  93. if ( hPhoncode == INVALID_HANDLE_VALUE ) {
  94. printf("hPhoncode is INVALID_HANDLE_VALUE\n");
  95. return;
  96. }
  97. hInMap = CreateFileMapping(hInFile, // handle to file to map
  98. NULL, // optional security attributes
  99. PAGE_READONLY, // protection for mapping object
  100. 0, // high-order 32 bits of object size
  101. 0, // low-order 32 bits of object size
  102. NULL); // name of file-mapping object);
  103. if ( !hInMap ) {
  104. printf("hInMap is NULL\n");
  105. return;
  106. }
  107. lpInFile = (LPWORD)MapViewOfFile(hInMap, FILE_MAP_READ, 0, 0, 0);
  108. lpStart = lpInFile + 1; // skip Unicode header signature 0xFEFF
  109. dwInFileSize = GetFileSize(hInFile, NULL) - 2; // sub head two bytes
  110. LineLen = 9 * sizeof(WORD);
  111. //
  112. // Every Line contains XXXXTCFDA
  113. //
  114. // X stands for Sequent code
  115. // T Tab, 0x0009
  116. // C U Char Code
  117. // F Flag, 0x0020 or L'*'
  118. // D 0x000D
  119. // A 0x000A
  120. //
  121. NumLine = dwInFileSize / LineLen;
  122. // ------------------------------
  123. // the first three Bytes of phon.tbl should be 0xFF, 0xFF, 0xFF.
  124. dwPattern = 0x00FFFFFF;
  125. WriteFile(hPhon, // handle to file to write to
  126. &dwPattern, // pointer to data to write to file
  127. 3, // number of bytes to write
  128. &BytesWritten, // pointer to number of bytes written
  129. NULL); // pointer to structure needed for
  130. // overlapped I/O
  131. // and write 0x0000 to phonptr.tbl
  132. wOutData = 0x0000;
  133. WriteFile(hPhonptr, // handle to file to write to
  134. &wOutData, // pointer to data to write to file
  135. 2, // number of bytes to write
  136. &BytesWritten, // pointer to number of bytes written
  137. NULL); // pointer to structure needed for
  138. // overlapped I/O
  139. dwPattern = dwLastPattern = 0x00FFFFFF;
  140. for (iLine=0; iLine < NumLine; iLine++) {
  141. DWORD dwSeq;
  142. BOOL fInverse;
  143. //Generate the pattern
  144. dwPattern = 0;
  145. for (i=0; i<3; i++) {
  146. dwSeq = 0;
  147. if ( lpStart[i] != L' ')
  148. dwSeq = wChar2SeqTbl[ lpStart[i] - L' ' ];
  149. dwPattern = (dwPattern << 6) + dwSeq;
  150. }
  151. // add the last key for tones
  152. dwSeq = wChar2SeqTbl[lpStart[3] - L' '];
  153. dwPattern = (dwPattern << 6) + dwSeq;
  154. // Get the Char code which will be stored in phoncode.tbl
  155. uCode = lpStart[5];
  156. fInverse = FALSE;
  157. if ( lpStart[6] == L'*')
  158. fInverse = TRUE;
  159. if (fInverse == TRUE ) {
  160. WORD wTmp;
  161. wTmp = bInverseEncode[ (uCode >> 12) & 0x000f ] ;
  162. uCode = (wTmp << 12) | (uCode & 0x0fff) ;
  163. }
  164. // write uCode to phoncode.tbl
  165. WriteFile(hPhoncode, // handle to file to write to
  166. &uCode, // pointer to data to write to file
  167. 2, // number of bytes to write
  168. &BytesWritten, // pointer to number of bytes written
  169. NULL); // pointer to structure needed for
  170. // overlapped I/O
  171. if ( dwPattern != dwLastPattern ) {
  172. // this is a different pattern, we will put this pattern to phon.tbl
  173. // and put the current line number (offset in phoncode.tbl in word)
  174. // to file phonptr.tbl
  175. WriteFile(hPhon, // handle to file to write to
  176. &dwPattern, // pointer to data to write to file
  177. 3, // number of bytes to write
  178. &BytesWritten, // pointer to number of bytes written
  179. NULL); // pointer to structure needed for
  180. // overlapped I/O
  181. // write Offset to phonptr.tbl
  182. wOutData = (WORD)iLine;
  183. WriteFile(hPhonptr, // handle to file to write to
  184. &wOutData, // pointer to data to write to file
  185. 2, // number of bytes to write
  186. &BytesWritten, // pointer to number of bytes written
  187. NULL); // pointer to structure needed for
  188. // overlapped I/O
  189. dwLastPattern = dwPattern;
  190. }
  191. lpStart += 9;
  192. }
  193. // the Last three Bytes of phon.tbl should be 0xFF, 0xFF, 0xFF.
  194. dwPattern = 0x00FFFFFF;
  195. WriteFile(hPhon, // handle to file to write to
  196. &dwPattern, // pointer to data to write to file
  197. 3, // number of bytes to write
  198. &BytesWritten, // pointer to number of bytes written
  199. NULL); // pointer to structure needed for
  200. // overlapped I/O
  201. wOutData = (WORD)iLine;
  202. WriteFile(hPhonptr, // handle to file to write to
  203. &wOutData, // pointer to data to write to file
  204. 2, // number of bytes to write
  205. &BytesWritten, // pointer to number of bytes written
  206. NULL); // pointer to structure needed for
  207. // overlapped I/O
  208. // ------------------------------
  209. UnmapViewOfFile(lpInFile);
  210. CloseHandle(hInMap);
  211. CloseHandle(hInFile);
  212. CloseHandle(hPhon);
  213. CloseHandle(hPhonptr);
  214. CloseHandle(hPhoncode);
  215. return;
  216. }