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.

224 lines
6.3 KiB

  1. /*************************************************
  2. * convdayi.c *
  3. * *
  4. * Copyright (C) 1999 Microsoft Inc. *
  5. * *
  6. *************************************************/
  7. //
  8. // Generate a Source Unicode table file from its msdayi.tbl file.
  9. //
  10. // the MSDayi.tbl file format: (every Line)
  11. // PPPC
  12. //
  13. // P : Pattern ( 3 Bytes)
  14. // C: Unicode of the char.
  15. //
  16. // the destinate file format: (Every Line)
  17. //
  18. // UUUUTCFDA
  19. //
  20. // U : Unicode of Ma Key
  21. // T: 0x0009
  22. // C: Unicode of the candiadate char.
  23. // F: L' ' or L'*', L'*' means reverse the code
  24. //
  25. //
  26. // History: Weibz, created, 03/03/1998
  27. //
  28. #include <stdio.h>
  29. #include <windows.h>
  30. const BYTE wChar2SeqTbl[0x42]={
  31. // ' ' ! " # $ % & ' - char code
  32. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, // sequence code
  33. // ( ) * + , - . /
  34. 0x00, 0x00, 0x00, 0x00, 0x27, 0x33, 0x28, 0x29,
  35. // 0 1 2 3 4 5 6 7
  36. 0x0A, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  37. // 8 9 : ; < = > ?
  38. 0x08, 0x09, 0x00, 0x1E, 0x00, 0x2F, 0x00, 0x00,
  39. // @ A B C D E F G
  40. 0x00, 0x15, 0x24, 0x22, 0x17, 0x0D, 0x18, 0x19,
  41. // H I J K L M N O
  42. 0x1A, 0x12, 0x1B, 0x1C, 0x1D, 0x26, 0x25, 0x13,
  43. // P Q R S T U V W
  44. 0x14, 0x0B, 0x0E, 0x16, 0x0F, 0x11, 0x23, 0x0C,
  45. // X Y Z [ \ ] ^ _
  46. 0x21, 0x10, 0x20, 0x31, 0x34, 0x32, 0x00, 0x00,
  47. // ` a
  48. 0x35, 0x00 };
  49. const BYTE bInverseEncode[] = {
  50. // 0 1 2 3 4 5 6 7
  51. 0x3, 0x4, 0x5, 0x0, 0x1, 0x2, 0xA, 0xB,
  52. // 8 9, A B C D E F
  53. 0xC, 0xD, 0x6, 0x7, 0x8, 0x9, 0xF, 0xE };
  54. const BYTE bValidFirstHex[] = {
  55. // 0 1 2 3 4 5 6 7 8 9, A B C D E F
  56. 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1
  57. };
  58. void _cdecl main( int argc, TCHAR **argv) {
  59. HANDLE hInFile, hOutFile;
  60. HANDLE hInMap;
  61. LPBYTE lpInFile, lpStart;
  62. WORD OutLine[20], i;
  63. DWORD dwInFileSize, NumberOfBytesWritten, dwPattern;
  64. DWORD iLine, dwLine;
  65. if ( argc != 3 ) {
  66. printf("Usage: dayisrc File1.tbl File2\n");
  67. return;
  68. }
  69. hInFile = CreateFile( argv[1], // pointer to name of the file
  70. GENERIC_READ, // access (read-write) mode
  71. FILE_SHARE_READ, // share mode
  72. NULL, // pointer to security attributes
  73. OPEN_EXISTING, // how to create
  74. FILE_ATTRIBUTE_NORMAL, // file attributes
  75. NULL);
  76. if ( hInFile == INVALID_HANDLE_VALUE ) return;
  77. dwInFileSize = GetFileSize(hInFile, NULL);
  78. hOutFile=CreateFile( argv[2], // pointer to name of the file
  79. GENERIC_WRITE, // access (read-write) mode
  80. FILE_SHARE_WRITE, // share mode
  81. NULL, // pointer to security attributes
  82. CREATE_ALWAYS, // how to create
  83. FILE_ATTRIBUTE_NORMAL, // file attributes
  84. NULL);
  85. if ( hOutFile == INVALID_HANDLE_VALUE ) {
  86. printf("hOutFile is INVALID_HANDLE_VALUE\n");
  87. return;
  88. }
  89. hInMap = CreateFileMapping(hInFile, // handle to file to map
  90. NULL, // optional security attributes
  91. PAGE_READONLY, // protection for mapping object
  92. 0, // high-order 32 bits of object size
  93. 0, // low-order 32 bits of object size
  94. NULL); // name of file-mapping object);
  95. if ( !hInMap ) {
  96. printf("hInMap is NULL\n");
  97. return;
  98. }
  99. lpInFile = (LPBYTE) MapViewOfFile(hInMap, FILE_MAP_READ, 0, 0, 0);
  100. OutLine[0] = 0xFEFF;
  101. WriteFile(hOutFile, // handle to file to write to
  102. OutLine, // pointer to data to write to file
  103. 2, // number of bytes to write
  104. &NumberOfBytesWritten, // pointer to number of bytes written
  105. NULL); // pointer to structure needed for
  106. // overlapped I/O
  107. iLine = 1;
  108. lpStart = lpInFile + 5;
  109. // skip the first record, because it is 00 00 00 00 00.
  110. dwLine = dwInFileSize / 5;
  111. // skip the last line, because it is FF FF FF 00 00
  112. while ( iLine < (dwLine -1) ) {
  113. WORD Code1, Code2, uCode;
  114. DWORD dwP1, dwP2, dwP3;
  115. WORD iStart, wFlag;
  116. dwP1 = *lpStart;
  117. dwP2 = *(lpStart+1);
  118. dwP3 = *(lpStart+2);
  119. dwPattern = dwP1 + (dwP2 << 8) + (dwP3 << 16);
  120. if ( i >= dwInFileSize) break;
  121. Code1 = *(lpStart+3);
  122. Code2 = *(lpStart+4);
  123. uCode = Code1 + Code2 * 256;
  124. iLine++;
  125. lpStart += 5;
  126. for (iStart=4; iStart>0; iStart--) {
  127. BYTE ThisByte;
  128. ThisByte = (BYTE)(dwPattern & 0x0000003f);
  129. dwPattern = dwPattern >> 6;
  130. for (i=0; i< 0x42; i++)
  131. if ( ThisByte == wChar2SeqTbl[i] ) break;
  132. OutLine[iStart-1] = L' ' + i;
  133. }
  134. iStart = 4;
  135. Code1 = uCode >> 12;
  136. wFlag = L' ';
  137. if ( !bValidFirstHex[Code1] ) {
  138. Code1 = bInverseEncode[Code1];
  139. wFlag = L'*';
  140. }
  141. Code1 = Code1 << 12;
  142. uCode = Code1 | (uCode & 0x0fff);
  143. OutLine[iStart++] = 0x0009; // Add Tab
  144. OutLine[iStart++] = uCode; // Add char code
  145. OutLine[iStart++] = wFlag;
  146. OutLine[iStart++] = 0x000D;
  147. OutLine[iStart++] = 0x000A;
  148. WriteFile(hOutFile, // handle to file to write to
  149. OutLine, // pointer to data to write to file
  150. iStart * sizeof(WORD), // number of bytes to write
  151. &NumberOfBytesWritten, // number of bytes written
  152. NULL); // pointer to structure needed for
  153. }
  154. UnmapViewOfFile(lpInFile);
  155. CloseHandle(hInMap);
  156. CloseHandle(hInFile);
  157. CloseHandle(hOutFile);
  158. return;
  159. }