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.

224 lines
7.4 KiB

  1. /*************************************************
  2. * genctbl.c *
  3. * *
  4. * Copyright (C) 1995-1999 Microsoft Inc. *
  5. * *
  6. *************************************************/
  7. // ---------------------------------------------------------------------------
  8. //
  9. // This program is used to generate Chajei IME tables from its text Code table
  10. //
  11. // History: 02-06-1998, Weibz, Created
  12. //
  13. // Usage: genctbl <Unicode Text File> <A15.tbl> <A234.tbl> <Acode.tbl>
  14. //
  15. //
  16. // --------------------------------------------------------------------------
  17. #include <stdio.h>
  18. #include <windows.h>
  19. void _cdecl main( int argc, TCHAR **argv) {
  20. HANDLE hInFile, hA15, hA234, hAcode;
  21. HANDLE hInMap;
  22. LPWORD lpInFile, lpStart, lpA1, lpA5, lpAcode;
  23. DWORD dwInFileSize, BytesWritten;
  24. DWORD iLine, LineLen, NumLine;
  25. int i;
  26. WORD wOutData, wOffset, wLastOffset;
  27. WORD wA1, wA5;
  28. WORD wPattern234, uCode;
  29. if ( argc != 5 ) {
  30. printf("usage: genctbl <U Text File> <A15.tbl> <A234.tbl> <Acode.tbl>\n");
  31. return;
  32. }
  33. hInFile = CreateFile( argv[1], // pointer to name of the file
  34. GENERIC_READ, // access (read-write) mode
  35. FILE_SHARE_READ, // share mode
  36. NULL, // pointer to security attributes
  37. OPEN_EXISTING, // how to create
  38. FILE_ATTRIBUTE_NORMAL, // file attributes
  39. NULL);
  40. if ( hInFile == INVALID_HANDLE_VALUE ) return;
  41. hA15 = CreateFile( argv[2], // pointer to name of the file
  42. GENERIC_WRITE, // access (read-write) mode
  43. FILE_SHARE_WRITE, // share mode
  44. NULL, // pointer to security attributes
  45. CREATE_ALWAYS, // how to create
  46. FILE_ATTRIBUTE_NORMAL, // file attributes
  47. NULL);
  48. if ( hA15 == INVALID_HANDLE_VALUE ) {
  49. printf("hA15 is INVALID_HANDLE_VALUE\n");
  50. return;
  51. }
  52. hA234 = CreateFile(argv[3], // pointer to name of the file
  53. GENERIC_WRITE, // access (read-write) mode
  54. FILE_SHARE_WRITE, // share mode
  55. NULL, // pointer to security attributes
  56. CREATE_ALWAYS, // how to create
  57. FILE_ATTRIBUTE_NORMAL, // file attributes
  58. NULL);
  59. if ( hA234 == INVALID_HANDLE_VALUE ) {
  60. printf("hA234 is INVALID_HANDLE_VALUE\n");
  61. return;
  62. }
  63. hAcode = CreateFile(argv[4], // pointer to name of the file
  64. GENERIC_WRITE, // access (read-write) mode
  65. FILE_SHARE_WRITE, // share mode
  66. NULL, // pointer to security attributes
  67. CREATE_ALWAYS, // how to create
  68. FILE_ATTRIBUTE_NORMAL, // file attributes
  69. NULL);
  70. if ( hAcode == INVALID_HANDLE_VALUE ) {
  71. printf("hAcode is INVALID_HANDLE_VALUE\n");
  72. return;
  73. }
  74. hInMap = CreateFileMapping(hInFile, // handle to file to map
  75. NULL, // optional security attributes
  76. PAGE_READONLY, // protection for mapping object
  77. 0, // high-order 32 bits of object size
  78. 0, // low-order 32 bits of object size
  79. NULL); // name of file-mapping object);
  80. if ( !hInMap ) {
  81. printf("hInMap is NULL\n");
  82. return;
  83. }
  84. lpInFile = (LPWORD)MapViewOfFile(hInMap, FILE_MAP_READ, 0, 0, 0);
  85. lpStart = lpInFile + 1; // skip Unicode header signature 0xFEFF
  86. dwInFileSize = GetFileSize(hInFile, NULL) - 2; // sub head two bytes
  87. LineLen = 9 * sizeof(WORD);
  88. NumLine = dwInFileSize / LineLen;
  89. // ------------------------------
  90. // For the first 27 words, we need to write 00 to A15.tbl
  91. wOutData = 0x0000;
  92. for (i=0; i<27; i++) {
  93. WriteFile(hA15, // handle to file to write to
  94. &wOutData, // pointer to data to write to file
  95. 2, // number of bytes to write
  96. &BytesWritten, // pointer to number of bytes written
  97. NULL); // pointer to structure needed for
  98. // overlapped I/O
  99. }
  100. wLastOffset = 26;
  101. for (iLine=0; iLine < NumLine; iLine++) {
  102. lpA1 = lpStart;
  103. lpA5 = lpStart + 4;
  104. lpAcode = lpStart + 6;
  105. wA1 = *lpA1; wA5 = *lpA5; uCode = *lpAcode;
  106. if (wA1 == 0x0020)
  107. wA1 = 0;
  108. else
  109. wA1 = wA1 - L'A' + 1;
  110. if (wA5 == 0x0020)
  111. wA5 = 0;
  112. else
  113. wA5 = wA5 - L'A' + 1;
  114. //Generate the pattern
  115. wPattern234 = 0;
  116. for (i=1; i<4; i++) {
  117. wPattern234 = wPattern234 << 5;
  118. if ( *(lpA1+i) != 0x0020 )
  119. wPattern234 += *(lpA1+i) - L'A' + 1;
  120. }
  121. // write this Pattern to A234.tbl
  122. WriteFile(hA234, // handle to file to write to
  123. &wPattern234, // pointer to data to write to file
  124. 2, // number of bytes to write
  125. &BytesWritten, // pointer to number of bytes written
  126. NULL); // pointer to structure needed for
  127. // overlapped I/O
  128. // write uCode to Acode.tbl
  129. WriteFile(hAcode, // handle to file to write to
  130. &uCode, // pointer to data to write to file
  131. 2, // number of bytes to write
  132. &BytesWritten, // pointer to number of bytes written
  133. NULL); // pointer to structure needed for
  134. // overlapped I/O
  135. wOffset = wA1 * 27 + wA5;
  136. if ( wOffset > wLastOffset ) {
  137. for (i=wLastOffset; i<wOffset; i++) {
  138. WriteFile(hA15, // handle to file to write to
  139. &iLine, // pointer to data to write to file
  140. 2, // number of bytes to write
  141. &BytesWritten, // pointer to number of bytes written
  142. NULL); // pointer to structure needed for
  143. // overlapped I/O
  144. }
  145. wLastOffset = wOffset;
  146. }
  147. lpStart += 9;
  148. }
  149. for (i=wLastOffset; i< (27*27 ); i++)
  150. WriteFile(hA15, // handle to file to write to
  151. &iLine, // pointer to data to write to file
  152. 2, // number of bytes to write
  153. &BytesWritten, // pointer to number of bytes written
  154. NULL); // pointer to structure needed for
  155. // overlapped I/O
  156. // ------------------------------------------------------------
  157. UnmapViewOfFile(lpInFile);
  158. CloseHandle(hInMap);
  159. CloseHandle(hInFile);
  160. CloseHandle(hA15);
  161. CloseHandle(hA234);
  162. CloseHandle(hAcode);
  163. return;
  164. }