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.

309 lines
9.6 KiB

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