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.

348 lines
13 KiB

  1. /*************************************************
  2. * genndsrc.c *
  3. * *
  4. * Copyright (C) 1999 Microsoft Inc. *
  5. * *
  6. *************************************************/
  7. //
  8. // This file is used to Generate a new source Dayi Table File.
  9. //
  10. // it will read two files, one for Big5 and one for GB, to generate a new
  11. // Dayi code table file.
  12. //
  13. // the two input files are sorted on the external keystroke pattern,
  14. // and both are complete Unicode files, ( there is 0xFEFF
  15. // in its first two bytes),
  16. //
  17. // the two input files contain lots of lines,every line follows below format:
  18. // XXXXTCFRL
  19. // X: Key Code,
  20. // T: Tab, 0x0009
  21. // C: Unicode for this Character
  22. // F: Flag: L' 'or L'*'
  23. // R: 0x000D
  24. // L: 0x000A
  25. //
  26. // we will generate a new table source file, if the same pattern exists in both
  27. // Big5 file and GB file, all those lines will be appended to the new file, and// the lines of Big5 will be written first, then GB Lines
  28. //
  29. // the new generated file must be sorted on the pattern.
  30. //
  31. // Created by weibz, March 03, 1998
  32. //
  33. #include <stdio.h>
  34. #include <stdlib.h>
  35. #include <windows.h>
  36. #define LINELEN (9 * sizeof(WORD) )
  37. const DWORD dwChar2SeqTbl[0x42] = {
  38. // ' ' ! " # $ % & ' - char code
  39. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, // sequence code
  40. // ( ) * + , - . /
  41. 0x00, 0x00, 0x00, 0x00, 0x27, 0x33, 0x28, 0x29,
  42. // 0 1 2 3 4 5 6 7
  43. 0x0A, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  44. // 8 9 : ; < = > ?
  45. 0x08, 0x09, 0x00, 0x1E, 0x00, 0x2F, 0x00, 0x00,
  46. // @ A B C D E F G
  47. 0x00, 0x15, 0x24, 0x22, 0x17, 0x0D, 0x18, 0x19,
  48. // H I J K L M N O
  49. 0x1A, 0x12, 0x1B, 0x1C, 0x1D, 0x26, 0x25, 0x13,
  50. // P Q R S T U V W
  51. 0x14, 0x0B, 0x0E, 0x16, 0x0F, 0x11, 0x23, 0x0C,
  52. // X Y Z [ \ ] ^ _
  53. 0x21, 0x10, 0x20, 0x31, 0x34, 0x32, 0x00, 0x00,
  54. // ` a
  55. 0x35, 0x00 };
  56. DWORD GetPattern( WORD *pWord )
  57. {
  58. int i;
  59. DWORD dwPat, dwSeq;
  60. dwPat = 0;
  61. for (i=0; i<4; i++) {
  62. dwSeq = dwChar2SeqTbl[ pWord[i] - L' '];
  63. dwPat = (dwPat << 6) + dwSeq;
  64. }
  65. return dwPat;
  66. }
  67. void _cdecl main( int argc, TCHAR **argv) {
  68. HANDLE hInBig5File, hInGBFile, hOutSrcFile;
  69. HANDLE hInBig5Map, hInGBMap;
  70. LPWORD lpInBig5File, lpInGBFile, lpStartBig5, lpStartGB;
  71. DWORD dwBig5Line, dwGBLine;
  72. DWORD iBig5Line, iGBLine, i;
  73. DWORD dwInFileSize, BytesWritten;
  74. WORD wOutData;
  75. DWORD dwPatternBig5, dwPatternGB;
  76. if ( argc != 4 ) {
  77. printf("Usage: genndsrc <Big5> <GB File> <New UnicdFile> \n");
  78. return;
  79. }
  80. hInBig5File = CreateFile( argv[1], // pointer to name of the file
  81. GENERIC_READ, // access (read-write) mode
  82. FILE_SHARE_READ, // share mode
  83. NULL, // pointer to security attributes
  84. OPEN_EXISTING, // how to create
  85. FILE_ATTRIBUTE_NORMAL, // file attributes
  86. NULL);
  87. if ( hInBig5File == INVALID_HANDLE_VALUE ) return;
  88. hInGBFile = CreateFile( argv[2], // pointer to name of the file
  89. GENERIC_READ, // access (read-write) mode
  90. FILE_SHARE_READ, // share mode
  91. NULL, // pointer to security attributes
  92. OPEN_EXISTING, // how to create
  93. FILE_ATTRIBUTE_NORMAL, // file attributes
  94. NULL);
  95. if ( hInGBFile == INVALID_HANDLE_VALUE ) {
  96. printf("hInGBFile is INVALID_HANDLE_VALUE\n");
  97. return;
  98. }
  99. hOutSrcFile = CreateFile(argv[3], // pointer to name of the file
  100. GENERIC_WRITE, // access (read-write) mode
  101. FILE_SHARE_WRITE, // share mode
  102. NULL, // pointer to security attributes
  103. CREATE_ALWAYS, // how to create
  104. FILE_ATTRIBUTE_NORMAL, // file attributes
  105. NULL);
  106. if ( hOutSrcFile == INVALID_HANDLE_VALUE ) {
  107. printf("hOutSrcFile is INVALID_HANDLE_VALUE\n");
  108. return;
  109. }
  110. hInBig5Map = CreateFileMapping(hInBig5File, // handle to file to map
  111. NULL, // optional security attributes
  112. PAGE_READONLY, // protection for mapping object
  113. 0, // high-order 32 bits of object size
  114. 0, // low-order 32 bits of object size
  115. NULL); // name of file-mapping object);
  116. if ( !hInBig5Map ) {
  117. printf("hInBig5Map is NULL\n");
  118. return;
  119. }
  120. hInGBMap = CreateFileMapping(hInGBFile, // handle to file to map
  121. NULL, // optional security attributes
  122. PAGE_READONLY, // protection for mapping object
  123. 0, // high-order 32 bits of object size
  124. 0, // low-order 32 bits of object size
  125. NULL); // name of file-mapping object);
  126. if ( !hInGBMap ) {
  127. printf("hInGBMap is NULL\n");
  128. return;
  129. }
  130. lpInBig5File = (LPWORD)MapViewOfFile(hInBig5Map, FILE_MAP_READ, 0, 0, 0);
  131. lpInGBFile = (LPWORD)MapViewOfFile(hInGBMap, FILE_MAP_READ, 0, 0, 0);
  132. lpStartBig5 = lpInBig5File + 1; // skip Unicode header signature 0xFEFF
  133. lpStartGB = lpInGBFile + 1; // skip Unicode header signature 0xFEFF
  134. dwInFileSize = GetFileSize(hInBig5File, NULL) - 2; // sub head two bytes
  135. dwBig5Line = dwInFileSize / LINELEN;
  136. dwInFileSize = GetFileSize(hInGBFile, NULL) - 2;
  137. dwGBLine = dwInFileSize / LINELEN;
  138. wOutData = 0xFEFF;
  139. WriteFile(hOutSrcFile, // handle to file to write to
  140. &wOutData, // pointer to data to write to file
  141. 2, // number of bytes to write
  142. &BytesWritten, // pointer to number of bytes written
  143. NULL); // pointer to structure needed for
  144. // overlapped I/O
  145. iBig5Line=iGBLine=0;
  146. while ((iBig5Line < dwBig5Line) && (iGBLine < dwGBLine)) {
  147. dwPatternBig5 = GetPattern(lpStartBig5);
  148. dwPatternGB = GetPattern(lpStartGB);
  149. if (dwPatternBig5 < dwPatternGB ) {
  150. // in this case, we just keep all lines in Big5 File which have same
  151. // dwpattern to new generated file.
  152. // write lpStartBig5 to OutSrcFile
  153. WriteFile(hOutSrcFile, // handle to file to write to
  154. lpStartBig5, // pointer to data to write to file
  155. LINELEN, // number of bytes to write
  156. &BytesWritten, // pointer to number of bytes written
  157. NULL); // pointer to structure needed for
  158. // overlapped I/O
  159. lpStartBig5 += LINELEN/sizeof(WORD);
  160. iBig5Line ++;
  161. while ( (iBig5Line < dwBig5Line) &&
  162. (GetPattern(lpStartBig5) == dwPatternBig5) ) {
  163. WriteFile(hOutSrcFile, // handle to file to write to
  164. lpStartBig5, // pointer to data to write to file
  165. LINELEN, // number of bytes to write
  166. &BytesWritten, // pointer to number of bytes written
  167. NULL); // pointer to structure needed for
  168. // overlapped I/O
  169. lpStartBig5 += LINELEN/sizeof(WORD);
  170. iBig5Line ++;
  171. }
  172. }
  173. else if ( dwPatternBig5 == dwPatternGB ) {
  174. // in this case, we will put all the lines in BIG5 and then in GB with
  175. // the same dwpattern to the new generated file.
  176. WriteFile(hOutSrcFile, // handle to file to write to
  177. lpStartBig5, // pointer to data to write to file
  178. LINELEN, // 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. lpStartBig5 += LINELEN/sizeof(WORD);
  183. iBig5Line ++;
  184. while ( (iBig5Line < dwBig5Line) &&
  185. (GetPattern(lpStartBig5) == dwPatternBig5) ) {
  186. WriteFile(hOutSrcFile, // handle to file to write to
  187. lpStartBig5, // pointer to data to write to file
  188. LINELEN, // number of bytes to write
  189. &BytesWritten, // pointer to number of bytes written
  190. NULL); // pointer to structure needed for
  191. // overlapped I/O
  192. lpStartBig5 += LINELEN/sizeof(WORD);
  193. iBig5Line ++;
  194. }
  195. WriteFile(hOutSrcFile, // handle to file to write to
  196. lpStartGB, // pointer to data to write to file
  197. LINELEN, // 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. lpStartGB += LINELEN/sizeof(WORD);
  202. iGBLine ++;
  203. while ( (iGBLine < dwGBLine) &&
  204. (GetPattern(lpStartGB) == dwPatternGB) ) {
  205. WriteFile(hOutSrcFile, // handle to file to write to
  206. lpStartGB, // pointer to data to write to file
  207. LINELEN, // number of bytes to write
  208. &BytesWritten, // pointer to number of bytes written
  209. NULL); // pointer to structure needed for
  210. // overlapped I/O
  211. lpStartGB += LINELEN/sizeof(WORD);
  212. iGBLine ++;
  213. }
  214. } else {
  215. // in this case, we just put all the lines with same pattern in file
  216. // GB to the new generated file.
  217. WriteFile(hOutSrcFile, // handle to file to write to
  218. lpStartGB, // pointer to data to write to file
  219. LINELEN, // number of bytes to write
  220. &BytesWritten, // pointer to number of bytes written
  221. NULL); // pointer to structure needed for
  222. // overlapped I/O
  223. lpStartGB += LINELEN/sizeof(WORD);
  224. iGBLine ++;
  225. while ( (iGBLine < dwGBLine) &&
  226. (GetPattern(lpStartGB) == dwPatternGB) ) {
  227. WriteFile(hOutSrcFile, // handle to file to write to
  228. lpStartGB, // pointer to data to write to file
  229. LINELEN, // number of bytes to write
  230. &BytesWritten, // pointer to number of bytes written
  231. NULL); // pointer to structure needed for
  232. // overlapped I/O
  233. lpStartGB += LINELEN/sizeof(WORD);
  234. iGBLine ++;
  235. }
  236. }
  237. } // while ...
  238. if ( iBig5Line < dwBig5Line ) {
  239. while ( iBig5Line < dwBig5Line ) {
  240. WriteFile(hOutSrcFile, // handle to file to write to
  241. lpStartBig5, // pointer to data to write to file
  242. LINELEN, // number of bytes to write
  243. &BytesWritten, // pointer to number of bytes written
  244. NULL); // pointer to structure needed for
  245. // overlapped I/O
  246. lpStartBig5 += LINELEN/sizeof(WORD);
  247. iBig5Line ++;
  248. }
  249. }
  250. if ( iGBLine < dwGBLine ) {
  251. while ( iGBLine < dwGBLine ) {
  252. WriteFile(hOutSrcFile, // handle to file to write to
  253. lpStartGB, // pointer to data to write to file
  254. LINELEN, // number of bytes to write
  255. &BytesWritten, // pointer to number of bytes written
  256. NULL); // pointer to structure needed for
  257. // overlapped I/O
  258. lpStartGB += LINELEN/sizeof(WORD);
  259. iGBLine ++;
  260. }
  261. }
  262. UnmapViewOfFile(lpInBig5File);
  263. UnmapViewOfFile(lpInGBFile);
  264. CloseHandle(hInBig5Map);
  265. CloseHandle(hInGBMap);
  266. CloseHandle(hInBig5File);
  267. CloseHandle(hInGBFile);
  268. CloseHandle(hOutSrcFile);
  269. return;
  270. }