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.

220 lines
7.3 KiB

  1. /*************************************************
  2. * chajei.c *
  3. * *
  4. * Copyright (C) 1995-1999 Microsoft Inc. *
  5. * *
  6. *************************************************/
  7. // ---------------------------------------------------------------------------
  8. //
  9. // This program generateis Chajei Source Unicode file from its table files
  10. //
  11. // History: 03-24-1998, Weibz, Created
  12. //
  13. // Usage: chajeisrc <A15.tbl> <A234.tbl> <Acode.tbl> <Unicode Text File>
  14. //
  15. //
  16. // --------------------------------------------------------------------------
  17. #include <stdio.h>
  18. #include <windows.h>
  19. void _cdecl main( int argc, TCHAR **argv) {
  20. HANDLE hA15, hA234, hAcode, hOutFile;
  21. HANDLE hA15Map, hA234Map, hAcodeMap;
  22. LPWORD lpA15, lpAcode, lpA234;
  23. DWORD BytesWritten;
  24. WORD iA15Pattern;
  25. int i;
  26. WORD wOutData, wA1, wA5;
  27. WORD wPattern234, uCode;
  28. WORD OutLine[9];
  29. if ( argc != 5 ) {
  30. printf("usage: chajeisrc <A15.tbl> <A234.tbl> <Acode.tbl> <U Text File>\n");
  31. return;
  32. }
  33. hA15 = 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 ( hA15 == INVALID_HANDLE_VALUE ) {
  41. printf("hA15 is INVALID_HANDLE_VALUE\n");
  42. return;
  43. }
  44. hA234 = CreateFile(argv[2], // pointer to name of the file
  45. GENERIC_READ, // access (read-write) mode
  46. FILE_SHARE_READ, // share mode
  47. NULL, // pointer to security attributes
  48. OPEN_EXISTING, // how to create
  49. FILE_ATTRIBUTE_NORMAL, // file attributes
  50. NULL);
  51. if ( hA234 == INVALID_HANDLE_VALUE ) {
  52. printf("hA234 is INVALID_HANDLE_VALUE\n");
  53. return;
  54. }
  55. hAcode = CreateFile(argv[3], // pointer to name of the file
  56. GENERIC_READ, // access (read-write) mode
  57. FILE_SHARE_READ, // share mode
  58. NULL, // pointer to security attributes
  59. OPEN_EXISTING, // how to create
  60. FILE_ATTRIBUTE_NORMAL, // file attributes
  61. NULL);
  62. if ( hAcode == INVALID_HANDLE_VALUE ) {
  63. printf("hAcode is INVALID_HANDLE_VALUE\n");
  64. return;
  65. }
  66. hOutFile = CreateFile( argv[4], // pointer to name of the file
  67. GENERIC_WRITE, // access (read-write) mode
  68. FILE_SHARE_WRITE, // share mode
  69. NULL, // pointer to security attributes
  70. CREATE_ALWAYS , // how to create
  71. FILE_ATTRIBUTE_NORMAL, // file attributes
  72. NULL);
  73. if ( hOutFile == INVALID_HANDLE_VALUE ) return;
  74. hA15Map = CreateFileMapping(hA15, // 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 ( !hA15Map ) {
  81. printf("hA15Map is NULL\n");
  82. return;
  83. }
  84. hA234Map = CreateFileMapping(hA234, // handle to file to map
  85. NULL, // optional security attributes
  86. PAGE_READONLY, // protection for mapping object
  87. 0, // high-order 32 bits of object size
  88. 0, // low-order 32 bits of object size
  89. NULL); // name of file-mapping object);
  90. if ( !hA234Map ) {
  91. printf("hA234Map is NULL\n");
  92. return;
  93. }
  94. hAcodeMap = CreateFileMapping(hAcode, // handle to file to map
  95. NULL, // optional security attributes
  96. PAGE_READONLY, // protection for mapping object
  97. 0, // high-order 32 bits of object size
  98. 0, // low-order 32 bits of object size
  99. NULL); // name of file-mapping object);
  100. if ( !hAcodeMap ) {
  101. printf("hAcodeMap is NULL\n");
  102. return;
  103. }
  104. lpA15 = (LPWORD)MapViewOfFile(hA15Map, FILE_MAP_READ, 0, 0, 0);
  105. lpA234 = (LPWORD)MapViewOfFile(hA234Map, FILE_MAP_READ, 0, 0, 0);
  106. lpAcode = (LPWORD)MapViewOfFile(hAcodeMap, FILE_MAP_READ, 0, 0, 0);
  107. // ------------------------------
  108. wOutData = 0xFEFF;
  109. WriteFile(hOutFile, // handle to file to write to
  110. &wOutData, // pointer to data to write to file
  111. 2, // number of bytes to write
  112. &BytesWritten, // pointer to number of bytes written
  113. NULL); // pointer to structure needed for
  114. // overlapped I/O
  115. for (i=0; i<5; i++)
  116. OutLine[i] = 0x0020;
  117. OutLine[5] = 0x0009;
  118. OutLine[7] = 0x000D;
  119. OutLine[8] = 0x000A;
  120. for (iA15Pattern=0; iA15Pattern < 27 * 27 - 1; iA15Pattern++) {
  121. WORD A234Start, A234End, Offset;
  122. WORD wSeq;
  123. A234Start = lpA15[iA15Pattern];
  124. A234End = lpA15[iA15Pattern+1];
  125. if ( A234End > A234Start ) {
  126. wA1 = iA15Pattern / 27;
  127. wA5 = iA15Pattern % 27;
  128. if ( wA1 == 0 )
  129. wA1 = 0x0020;
  130. else
  131. wA1 = wA1 + L'A' - 1;
  132. if ( wA5 == 0 )
  133. wA5 = 0x0020;
  134. else
  135. wA5 = wA5 + L'A' - 1;
  136. OutLine[0] = wA1;
  137. OutLine[4] = wA5;
  138. for (Offset=A234Start; Offset<A234End; Offset++) {
  139. wPattern234 = lpA234[Offset];
  140. uCode = lpAcode[Offset];
  141. for (i=3; i>0; i--) {
  142. wSeq = wPattern234 & 0x1f;
  143. if ( wSeq == 0 )
  144. OutLine[i] = 0x0020;
  145. else
  146. OutLine[i] = wSeq + L'A' - 1;
  147. wPattern234 = wPattern234 >> 5;
  148. }
  149. OutLine[6] = uCode;
  150. WriteFile(hOutFile, // handle to file to write to
  151. OutLine, // pointer to data to write to file
  152. 18, // 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. }
  158. }
  159. // ------------------------------------------------------------
  160. UnmapViewOfFile(lpA15);
  161. UnmapViewOfFile(lpA234);
  162. UnmapViewOfFile(lpAcode);
  163. CloseHandle(hA15Map);
  164. CloseHandle(hA234Map);
  165. CloseHandle(hAcodeMap);
  166. CloseHandle(hOutFile);
  167. CloseHandle(hA15);
  168. CloseHandle(hA234);
  169. CloseHandle(hAcode);
  170. return;
  171. }