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.

203 lines
6.0 KiB

  1. /*************************************************
  2. * convert.c *
  3. * *
  4. * Copyright (C) 1995-1999 Microsoft Inc. *
  5. * *
  6. *************************************************/
  7. //
  8. // this program is used to convert Chajei TXT file to Unicode Table file
  9. //
  10. #include <stdio.h>
  11. #include <windows.h>
  12. void _cdecl main( int argc, TCHAR **argv) {
  13. HANDLE hInFile, hOutFile;
  14. HANDLE hInMap;
  15. LPBYTE lpInFile;
  16. WORD OutLine[20];
  17. DWORD dwInFileSize, i, NumberOfBytesWritten;
  18. DWORD iLine;
  19. if ( argc != 3 ) {
  20. printf("usage: Convctbl File1 File2\n");
  21. return;
  22. }
  23. hInFile = CreateFile( argv[1], // pointer to name of the file
  24. GENERIC_READ, // access (read-write) mode
  25. FILE_SHARE_READ, // share mode
  26. NULL, // pointer to security attributes
  27. OPEN_EXISTING, // how to create
  28. FILE_ATTRIBUTE_NORMAL, // file attributes
  29. NULL);
  30. if ( hInFile == INVALID_HANDLE_VALUE ) return;
  31. dwInFileSize = GetFileSize(hInFile, NULL);
  32. hOutFile=CreateFile( argv[2], // pointer to name of the file
  33. GENERIC_WRITE, // access (read-write) mode
  34. FILE_SHARE_WRITE, // share mode
  35. NULL, // pointer to security attributes
  36. CREATE_ALWAYS, // how to create
  37. FILE_ATTRIBUTE_NORMAL, // file attributes
  38. NULL);
  39. if ( hOutFile == INVALID_HANDLE_VALUE ) {
  40. printf("hOutFile is NULL\n");
  41. return;
  42. }
  43. hInMap = CreateFileMapping(hInFile, // handle to file to map
  44. NULL, // optional security attributes
  45. PAGE_READONLY, // protection for mapping object
  46. 0, // high-order 32 bits of object size
  47. 0, // low-order 32 bits of object size
  48. NULL); // name of file-mapping object);
  49. if ( !hInMap ) {
  50. printf("hInMap is NULL\n");
  51. return;
  52. }
  53. lpInFile = (LPBYTE) MapViewOfFile(hInMap, FILE_MAP_READ, 0, 0, 0);
  54. OutLine[0] = 0xFEFF;
  55. WriteFile(hOutFile, // handle to file to write to
  56. OutLine, // pointer to data to write to file
  57. 2, // number of bytes to write
  58. &NumberOfBytesWritten, // pointer to number of bytes written
  59. NULL); // pointer to structure needed for
  60. // overlapped I/O
  61. i = 0;
  62. iLine = 1;
  63. while ( i < dwInFileSize ) {
  64. WORD CharCode;
  65. DWORD iStart, iTmp;
  66. CharCode = 0;
  67. for (iStart=0; iStart<4; iStart++) {
  68. BYTE ThisByte;
  69. ThisByte = lpInFile[i+iStart];
  70. if ( (ThisByte >= '0') && (ThisByte <= '9') )
  71. ThisByte = ThisByte - '0';
  72. else
  73. if ( (ThisByte >= 'A') && (ThisByte <= 'F') )
  74. ThisByte = ThisByte - 'A' + 10;
  75. else
  76. {
  77. printf("Line Num %d data error ThisByte is %c\n", iLine, ThisByte);
  78. return;
  79. }
  80. CharCode = CharCode * 16 + ThisByte;
  81. }
  82. i += 4;
  83. while ( lpInFile[i] == 0x20 ) i++;
  84. iStart = 0;
  85. while ((lpInFile[i]!=0x0D) && (i<dwInFileSize)) {
  86. if (lpInFile[i] != 0x20) {
  87. OutLine[iStart] = (WORD)(lpInFile[i]) & 0x00ff;
  88. i++;
  89. iStart ++;
  90. }
  91. else // it is 0x20
  92. {
  93. while ( lpInFile[i] == 0x20 ) i++;
  94. if ( (iStart < 5) && (iStart != 1 ) ) {
  95. OutLine[4] = OutLine[iStart-1];
  96. for (iTmp=iStart-1; iTmp<4; iTmp++)
  97. OutLine[iTmp] = 0x0020;
  98. }
  99. if (iStart == 1)
  100. for (iTmp=1; iTmp<5; iTmp++)
  101. OutLine[iTmp] = 0x0020;
  102. iStart = 5;
  103. OutLine[iStart++] = 0x0009; // Add Tab
  104. OutLine[iStart++] = CharCode; // Add char code
  105. OutLine[iStart++] = 0x000D;
  106. OutLine[iStart++] = 0x000A;
  107. WriteFile(hOutFile, // handle to file to write to
  108. OutLine, // pointer to data to write to file
  109. iStart * sizeof(WORD), // number of bytes to write
  110. &NumberOfBytesWritten, // number of bytes written
  111. NULL); // pointer to structure needed for
  112. // overlapped I/O
  113. iStart = 0;
  114. }
  115. } // lpInFile[i] != 0x0D
  116. if ( lpInFile[i] == 0x0D ) {
  117. iLine ++;
  118. if ( lpInFile[i+1] == 0x0A )
  119. i = i + 2;
  120. else
  121. i++;
  122. }
  123. if ( iStart > 0 ) {
  124. if ( (iStart < 5) && (iStart != 1) ) {
  125. OutLine[4] = OutLine[iStart-1];
  126. for (iTmp=iStart-1; iTmp<4; iTmp++)
  127. OutLine[iTmp] = 0x0020;
  128. }
  129. if (iStart == 1)
  130. for (iTmp=1; iTmp<5; iTmp++)
  131. OutLine[iTmp] = 0x0020;
  132. iStart = 5;
  133. OutLine[iStart++] = 0x0009; // Add Tab
  134. OutLine[iStart++] = CharCode; // Add char code
  135. OutLine[iStart++] = 0x000D;
  136. OutLine[iStart++] = 0x000A;
  137. WriteFile(hOutFile, // handle to file to write to
  138. OutLine, // pointer to data to write to file
  139. iStart * sizeof(WORD), // number of bytes to write
  140. &NumberOfBytesWritten, // number of bytes written
  141. NULL); // pointer to structure needed for
  142. // overlapped I/O
  143. iStart = 0;
  144. }
  145. } // while i<dwInFileSize
  146. UnmapViewOfFile(lpInFile);
  147. CloseHandle(hInMap);
  148. CloseHandle(hInFile);
  149. CloseHandle(hOutFile);
  150. return;
  151. }