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.

271 lines
8.3 KiB

  1. /*************************************************
  2. * gendtbl.c *
  3. * *
  4. * Copyright (C) 1999 Microsoft Inc. *
  5. * *
  6. *************************************************/
  7. // ---------------------------------------------------------------------------
  8. //
  9. // This program is used to generate Dayi IME tables from its text Code table
  10. //
  11. // History: 02-13-1998, Weibz, Created
  12. //
  13. // Usage: gendtbl <UniText File> <Phon.tbl> <Phonptr.tbl> <phoncode.tbl>
  14. //
  15. //
  16. // --------------------------------------------------------------------------
  17. #include <stdio.h>
  18. #include <windows.h>
  19. const DWORD dwChar2SeqTbl[0x42] = {
  20. // ' ' ! " # $ % & ' - char code
  21. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, // sequence code
  22. // ( ) * + , - . /
  23. 0x00, 0x00, 0x00, 0x00, 0x27, 0x33, 0x28, 0x29,
  24. // 0 1 2 3 4 5 6 7
  25. 0x0A, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  26. // 8 9 : ; < = > ?
  27. 0x08, 0x09, 0x00, 0x1E, 0x00, 0x2F, 0x00, 0x00,
  28. // @ A B C D E F G
  29. 0x00, 0x15, 0x24, 0x22, 0x17, 0x0D, 0x18, 0x19,
  30. // H I J K L M N O
  31. 0x1A, 0x12, 0x1B, 0x1C, 0x1D, 0x26, 0x25, 0x13,
  32. // P Q R S T U V W
  33. 0x14, 0x0B, 0x0E, 0x16, 0x0F, 0x11, 0x23, 0x0C,
  34. // X Y Z [ \ ] ^ _
  35. 0x21, 0x10, 0x20, 0x31, 0x34, 0x32, 0x00, 0x00,
  36. // ` a
  37. 0x35, 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, hDayi;
  45. HANDLE hInMap;
  46. LPWORD lpInFile, lpStart;
  47. DWORD dwInFileSize, BytesWritten;
  48. DWORD iLine, LineLen, NumLine;
  49. int i, iWord;
  50. WORD uCode;
  51. DWORD dwPattern;
  52. // WORD *pwStored;
  53. if ( argc != 3 ) {
  54. printf("usage: gendtbl <UTextFile> <msdayi.tbl>\n");
  55. return;
  56. }
  57. hInFile = CreateFile( argv[1], // pointer to name of the file
  58. GENERIC_READ, // access (read-write) mode
  59. FILE_SHARE_READ, // share mode
  60. NULL, // pointer to security attributes
  61. OPEN_EXISTING, // how to create
  62. FILE_ATTRIBUTE_NORMAL, // file attributes
  63. NULL);
  64. if ( hInFile == INVALID_HANDLE_VALUE ) return;
  65. hDayi = CreateFile( argv[2], // pointer to name of the file
  66. GENERIC_WRITE, // access (read-write) mode
  67. FILE_SHARE_WRITE, // share mode
  68. NULL, // pointer to security attributes
  69. CREATE_ALWAYS, // how to create
  70. FILE_ATTRIBUTE_NORMAL, // file attributes
  71. NULL);
  72. if ( hDayi == INVALID_HANDLE_VALUE ) {
  73. printf("hPhon is INVALID_HANDLE_VALUE\n");
  74. return;
  75. }
  76. hInMap = CreateFileMapping(hInFile, // handle to file to map
  77. NULL, // optional security attributes
  78. PAGE_READONLY, // protection for mapping object
  79. 0, // high-order 32 bits of object size
  80. 0, // low-order 32 bits of object size
  81. NULL); // name of file-mapping object);
  82. if ( !hInMap ) {
  83. printf("hInMap is NULL\n");
  84. return;
  85. }
  86. lpInFile = (LPWORD)MapViewOfFile(hInMap, FILE_MAP_READ, 0, 0, 0);
  87. lpStart = lpInFile + 1; // skip Unicode header signature 0xFEFF
  88. dwInFileSize = GetFileSize(hInFile, NULL) - 2; // sub head two bytes
  89. LineLen = 9 * sizeof(WORD);
  90. //
  91. // Every Line contains XXXXTCDA
  92. //
  93. // X stands for Sequent code
  94. // T Tab, 0x0009
  95. // C U Char Code
  96. // F Flag, L' 'or L'*'
  97. // D 0x000D
  98. // A 0x000A
  99. //
  100. NumLine = dwInFileSize / LineLen;
  101. // pwStored = (PWORD)LocalAlloc(LPTR, NumLine * sizeof(WORD) );
  102. //
  103. // if ( pwStored == NULL ) {
  104. // printf("Memory Alloc Error\n");
  105. // return;
  106. // }
  107. // ------------------------------
  108. // the first five Bytes of Dayi.tbl should be 00, 00,00,00,00.
  109. dwPattern = 0x00000000;
  110. WriteFile(hDayi, // handle to file to write to
  111. &dwPattern, // pointer to data to write to file
  112. 3, // number of bytes to write
  113. &BytesWritten, // pointer to number of bytes written
  114. NULL); // pointer to structure needed for
  115. // overlapped I/O
  116. uCode = 0x0000;
  117. WriteFile(hDayi, // handle to file to write to
  118. &uCode, // pointer to data to write to file
  119. 2, // number of bytes to write
  120. &BytesWritten, // pointer to number of bytes written
  121. NULL); // pointer to structure needed for
  122. // overlapped I/O
  123. iWord = 0;
  124. for (iLine=0; iLine < NumLine; iLine++) {
  125. DWORD dwSeq;
  126. BOOL fInverse;
  127. //Generate the pattern
  128. dwPattern = 0;
  129. for (i=0; i<4; i++) {
  130. dwSeq = dwChar2SeqTbl[ lpStart[i] - L' ' ];
  131. dwPattern = (dwPattern << 6) + dwSeq;
  132. }
  133. // Get the Char code
  134. // Skip one 0x0009
  135. uCode = lpStart[5];
  136. fInverse = FALSE;
  137. // we will base on the Flag of this line to determine reversion.
  138. if ( lpStart[6] == L'*' )
  139. fInverse = TRUE;
  140. /* // searh if we have already stored the char.
  141. // for (i=0; i<iWord; i++) {
  142. // if ( pwStored[i] == uCode ) {
  143. // fInverse = TRUE;
  144. // break;
  145. // }
  146. // }
  147. //
  148. // if ( fInverse == FALSE ) {
  149. // // put this new char to the stored list.
  150. // pwStored[iWord] = uCode;
  151. // iWord ++;
  152. // }
  153. */
  154. if (fInverse == TRUE ) {
  155. WORD wTmp;
  156. wTmp = bInverseEncode[ (uCode >> 12) & 0x000f ] ;
  157. uCode = (wTmp << 12) | (uCode & 0x0fff) ;
  158. }
  159. // write the Pattern and char code to Dayi.tbl
  160. WriteFile(hDayi, // handle to file to write to
  161. &dwPattern, // pointer to data to write to file
  162. 3, // number of bytes to write
  163. &BytesWritten, // pointer to number of bytes written
  164. NULL); // pointer to structure needed for
  165. // overlapped I/O
  166. WriteFile(hDayi, // handle to file to write to
  167. &uCode, // pointer to data to write to file
  168. 2, // number of bytes to write
  169. &BytesWritten, // pointer to number of bytes written
  170. NULL); // pointer to structure needed for
  171. // overlapped I/O
  172. lpStart += LineLen / sizeof(WORD);
  173. }
  174. // the Last three Bytes of Dayi.tbl should be 0xFF, 0xFF, 0xFF.
  175. dwPattern = 0x00FFFFFF;
  176. WriteFile(hDayi, // handle to file to write to
  177. &dwPattern, // pointer to data to write to file
  178. 3, // number of bytes to write
  179. &BytesWritten, // pointer to number of bytes written
  180. NULL); // pointer to structure needed for
  181. // overlapped I/O
  182. uCode = 0x0000;
  183. WriteFile(hDayi, // handle to file to write to
  184. &uCode, // 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. // ------------------------------
  190. UnmapViewOfFile(lpInFile);
  191. CloseHandle(hInMap);
  192. CloseHandle(hInFile);
  193. CloseHandle(hDayi);
  194. // LocalFree(pwStored);
  195. return;
  196. }