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.

280 lines
8.1 KiB

  1. /*************************************************
  2. * convdayi.c *
  3. * *
  4. * Copyright (C) 1999 Microsoft Inc. *
  5. * *
  6. *************************************************/
  7. //
  8. // this program is used to convert a ansi Text table to Unicode table file
  9. //
  10. // the source file format: (every Line)
  11. // AAAATMMMMT[MMM]DA
  12. //
  13. // A : Ascii code
  14. // T: Tab Key, 09
  15. // M: Ma (at most Four Keys), there may be '"', we need to delet it.
  16. //
  17. // the destinate file format: (Every Line)
  18. //
  19. // UUUUTCFDA
  20. //
  21. // U : Unicode of Ma Key
  22. // T: 0x0009
  23. // C: Unicode of the candiadate char.
  24. // F: Flag, L' ' or L'*', '*' means reversion
  25. //
  26. //
  27. // History: Weibz, created, 02/13/1998
  28. //
  29. #include <stdio.h>
  30. #include <windows.h>
  31. const WORD wChar2SeqTbl[0x42]={
  32. // ' ' ! " # $ % & ' - char code
  33. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, // sequence code
  34. // ( ) * + , - . /
  35. 0x00, 0x00, 0x00, 0x00, 0x27, 0x33, 0x28, 0x29,
  36. // 0 1 2 3 4 5 6 7
  37. 0x0A, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  38. // 8 9 : ; < = > ?
  39. 0x08, 0x09, 0x00, 0x1E, 0x00, 0x2F, 0x00, 0x00,
  40. // @ A B C D E F G
  41. 0x00, 0x15, 0x24, 0x22, 0x17, 0x0D, 0x18, 0x19,
  42. // H I J K L M N O
  43. 0x1A, 0x12, 0x1B, 0x1C, 0x1D, 0x26, 0x25, 0x13,
  44. // P Q R S T U V W
  45. 0x14, 0x0B, 0x0E, 0x16, 0x0F, 0x11, 0x23, 0x0C,
  46. // X Y Z [ \ ] ^ _
  47. 0x21, 0x10, 0x20, 0x31, 0x34, 0x32, 0x00, 0x00,
  48. // ` a
  49. 0x35, 0x00 };
  50. void _cdecl main( int argc, TCHAR **argv) {
  51. HANDLE hInFile, hOutFile;
  52. HANDLE hInMap;
  53. LPBYTE lpInFile;
  54. WORD OutLine[20];
  55. DWORD dwInFileSize, i, NumberOfBytesWritten;
  56. DWORD iLine;
  57. if ( argc != 3 ) {
  58. printf("Usage: convdayi File1 File2\n");
  59. return;
  60. }
  61. hInFile = CreateFile( argv[1], // pointer to name of the file
  62. GENERIC_READ, // access (read-write) mode
  63. FILE_SHARE_READ, // share mode
  64. NULL, // pointer to security attributes
  65. OPEN_EXISTING, // how to create
  66. FILE_ATTRIBUTE_NORMAL, // file attributes
  67. NULL);
  68. if ( hInFile == INVALID_HANDLE_VALUE ) return;
  69. dwInFileSize = GetFileSize(hInFile, NULL);
  70. hOutFile=CreateFile( argv[2], // pointer to name of the file
  71. GENERIC_WRITE, // access (read-write) mode
  72. FILE_SHARE_WRITE, // share mode
  73. NULL, // pointer to security attributes
  74. CREATE_ALWAYS, // how to create
  75. FILE_ATTRIBUTE_NORMAL, // file attributes
  76. NULL);
  77. if ( hOutFile == INVALID_HANDLE_VALUE ) {
  78. printf("hOutFile is INVALID_HANDLE_VALUE\n");
  79. return;
  80. }
  81. hInMap = CreateFileMapping(hInFile, // handle to file to map
  82. NULL, // optional security attributes
  83. PAGE_READONLY, // protection for mapping object
  84. 0, // high-order 32 bits of object size
  85. 0, // low-order 32 bits of object size
  86. NULL); // name of file-mapping object);
  87. if ( !hInMap ) {
  88. printf("hInMap is NULL\n");
  89. return;
  90. }
  91. lpInFile = (LPBYTE) MapViewOfFile(hInMap, FILE_MAP_READ, 0, 0, 0);
  92. OutLine[0] = 0xFEFF;
  93. WriteFile(hOutFile, // handle to file to write to
  94. OutLine, // pointer to data to write to file
  95. 2, // number of bytes to write
  96. &NumberOfBytesWritten, // pointer to number of bytes written
  97. NULL); // pointer to structure needed for
  98. // overlapped I/O
  99. i = 0;
  100. iLine = 1;
  101. while ( i < dwInFileSize ) {
  102. WORD CharCode;
  103. DWORD iStart, iTmp;
  104. BOOL bFirstCode;
  105. CharCode = 0;
  106. bFirstCode = TRUE;
  107. if ( i >= dwInFileSize) break;
  108. for (iStart=0; iStart<4; iStart++) {
  109. BYTE ThisByte;
  110. ThisByte = lpInFile[i+iStart];
  111. if ( (ThisByte >= '0') && (ThisByte <= '9') )
  112. ThisByte = ThisByte - '0';
  113. else
  114. if ( (ThisByte >= 'A') && (ThisByte <= 'F') )
  115. ThisByte = ThisByte - 'A' + 10;
  116. else
  117. if ( (ThisByte >= 'a') && (ThisByte <= 'f') )
  118. ThisByte = ThisByte - 'a' + 10;
  119. else
  120. {
  121. printf("Line Num %d data error ThisByte is %c\n", iLine, ThisByte);
  122. return;
  123. }
  124. CharCode = CharCode * 16 + ThisByte;
  125. }
  126. i += 4;
  127. while ( (lpInFile[i]== 0x09) || (lpInFile[i] == ' ') ||
  128. (lpInFile[i] == '"') ) i++;
  129. iStart = 0;
  130. while ((lpInFile[i]!=0x0D) && (i<dwInFileSize)) {
  131. if ( (lpInFile[i] != 0x09) && (lpInFile[i] != ' ') &&
  132. (lpInFile[i] != '"') ) {
  133. //must be serial External key Code
  134. OutLine[iStart] = (WORD)(lpInFile[i]) & 0x00ff;
  135. iStart ++;
  136. i ++;
  137. }
  138. else // it is 0x09
  139. {
  140. while ( (lpInFile[i]== 0x09) || (lpInFile[i] == ' ') ||
  141. (lpInFile[i] == '"') ) i++;
  142. if ( iStart == 0 ) continue;
  143. if ( iStart < 4 ) {
  144. for ( iTmp=iStart; iTmp<4; iTmp++ )
  145. OutLine[iTmp] = 0x0020;
  146. }
  147. iStart = 4;
  148. OutLine[iStart++] = 0x0009; // Add Tab
  149. OutLine[iStart++] = CharCode; // Add char code
  150. if ( bFirstCode == TRUE ) {
  151. OutLine[iStart++] = L' ';
  152. bFirstCode = FALSE;
  153. }
  154. else
  155. OutLine[iStart++] = L'*';
  156. OutLine[iStart++] = 0x000D;
  157. OutLine[iStart++] = 0x000A;
  158. WriteFile(hOutFile, // handle to file to write to
  159. OutLine, // pointer to data to write to file
  160. iStart * sizeof(WORD), // number of bytes to write
  161. &NumberOfBytesWritten, // number of bytes written
  162. NULL); // pointer to structure needed for
  163. // overlapped I/O
  164. iStart = 0;
  165. }
  166. } // While lpInFile[i] != 0x0D
  167. if ( lpInFile[i] == 0x0D ) {
  168. iLine ++;
  169. if ( lpInFile[i+1] == 0x0A )
  170. i = i + 2;
  171. else
  172. i++;
  173. }
  174. if ( iStart > 0 ) {
  175. if ( iStart < 4 ) {
  176. for ( iTmp=iStart; iTmp<4; iTmp++ )
  177. OutLine[iTmp] = 0x0020;
  178. }
  179. iStart = 4;
  180. OutLine[iStart++] = 0x0009; // Add Tab
  181. OutLine[iStart++] = CharCode; // Add char code
  182. if ( bFirstCode == TRUE ) {
  183. OutLine[iStart++] = L' ';
  184. bFirstCode = FALSE;
  185. }
  186. else
  187. OutLine[iStart++] = L'*';
  188. OutLine[iStart++] = 0x000D;
  189. OutLine[iStart++] = 0x000A;
  190. WriteFile(hOutFile, // handle to file to write to
  191. OutLine, // pointer to data to write to file
  192. iStart * sizeof(WORD), // number of bytes to write
  193. &NumberOfBytesWritten, // number of bytes written
  194. NULL); // pointer to structure needed for
  195. // overlapped I/O
  196. iStart = 0;
  197. }
  198. } // while i<dwInFileSize
  199. UnmapViewOfFile(lpInFile);
  200. CloseHandle(hInMap);
  201. CloseHandle(hInFile);
  202. CloseHandle(hOutFile);
  203. return;
  204. }