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.

183 lines
4.8 KiB

  1. /*************************************************
  2. * winhk.c *
  3. * *
  4. * Copyright (C) 1995-1999 Microsoft Inc. *
  5. * *
  6. *************************************************/
  7. //
  8. //
  9. // this program converts Table source file for HK from NTGEN format to
  10. // UIMETOOL format
  11. //
  12. #include <stdio.h>
  13. #include <windows.h>
  14. void _cdecl main( int argc, TCHAR **argv) {
  15. HANDLE hInFile, hOutFile;
  16. HANDLE hInMap;
  17. LPWORD lpInFile, lpCur;
  18. WORD OutLine[30];
  19. DWORD dwInFileSize, i, NumberOfBytesWritten;
  20. if ( argc != 3 ) {
  21. printf("Usage: convhk <NTGEN-File> <UIMETOOL-File>\n");
  22. return;
  23. }
  24. hInFile = CreateFile( argv[1], // pointer to name of the file
  25. GENERIC_READ, // access (read-write) mode
  26. FILE_SHARE_READ, // share mode
  27. NULL, // pointer to security attributes
  28. OPEN_EXISTING, // how to create
  29. FILE_ATTRIBUTE_NORMAL, // file attributes
  30. NULL);
  31. if ( hInFile == INVALID_HANDLE_VALUE ) return;
  32. dwInFileSize = GetFileSize(hInFile, NULL);
  33. hOutFile=CreateFile( argv[2], // pointer to name of the file
  34. GENERIC_WRITE, // access (read-write) mode
  35. FILE_SHARE_WRITE, // share mode
  36. NULL, // pointer to security attributes
  37. CREATE_ALWAYS, // how to create
  38. FILE_ATTRIBUTE_NORMAL, // file attributes
  39. NULL);
  40. if ( hOutFile == INVALID_HANDLE_VALUE ) {
  41. printf("hOutFile is INVALID_HANDLE_VALUE\n");
  42. return;
  43. }
  44. hInMap = CreateFileMapping(hInFile, // handle to file to map
  45. NULL, // optional security attributes
  46. PAGE_READONLY, // protection for mapping object
  47. 0, // high-order 32 bits of object size
  48. 0, // low-order 32 bits of object size
  49. NULL); // name of file-mapping object);
  50. if ( !hInMap ) {
  51. printf("hInMap is NULL\n");
  52. return;
  53. }
  54. lpInFile = (LPWORD) MapViewOfFile(hInMap, FILE_MAP_READ, 0, 0, 0);
  55. OutLine[0] = 0xFEFF;
  56. WriteFile(hOutFile, // handle to file to write to
  57. OutLine, // pointer to data to write to file
  58. 2, // number of bytes to write
  59. &NumberOfBytesWritten, // pointer to number of bytes written
  60. NULL); // pointer to structure needed for
  61. // overlapped I/O
  62. WriteFile(hOutFile,
  63. L"/S A",
  64. 8,
  65. &NumberOfBytesWritten,
  66. NULL);
  67. for ( i=0; i<26; i++) {
  68. OutLine[i] = (WORD)0xff21 + (WORD)i;
  69. }
  70. OutLine[26] = 0x000D;
  71. OutLine[27] = 0x000A;
  72. WriteFile(hOutFile,
  73. OutLine,
  74. 28 * sizeof(WORD),
  75. &NumberOfBytesWritten,
  76. NULL);
  77. lpCur = lpInFile + 1; // skip FEFF
  78. i = 0;
  79. while ( i < (dwInFileSize / sizeof(WORD) -1)) {
  80. WORD iStart, *lpLineStart, ExtLen;
  81. iStart = 0;
  82. // get a line
  83. lpLineStart = lpCur;
  84. while ( *lpCur != 0x000D ) {
  85. lpCur ++;
  86. i++;
  87. }
  88. ExtLen = lpCur - lpLineStart - 1;
  89. //
  90. //
  91. // a line of Input file has following format:
  92. //
  93. // <Unicode>?????<0D><0A>
  94. //
  95. // ? stands for variable length external code
  96. //
  97. //
  98. // a line of output file has following format:
  99. //
  100. // XXXXXX<09><Unicode><0D><0A>
  101. //
  102. // it contains 6 external code, if there is less 6 external codes, the rest
  103. // will be fill in Blank.
  104. //
  105. for (iStart=0; iStart<ExtLen; iStart++)
  106. {
  107. WCHAR wch;
  108. wch = lpLineStart[iStart+1];
  109. if (( wch <= L'z') && (wch >= L'a') ) {
  110. wch -= L'a' - L'A' ;
  111. }
  112. OutLine[iStart] = wch;
  113. }
  114. if (ExtLen < 6) {
  115. for (iStart=ExtLen; iStart<6; iStart++)
  116. OutLine[iStart] = L' ';
  117. }
  118. OutLine[6] = 0x0009;
  119. OutLine[7] = lpLineStart[0];
  120. OutLine[8] = 0x000D;
  121. OutLine[9] = 0x000A;
  122. WriteFile(hOutFile, // handle to file to write to
  123. OutLine, // pointer to data to write to file
  124. 10 * sizeof(WORD), // number of bytes to write
  125. &NumberOfBytesWritten, // number of bytes written
  126. NULL); // pointer to structure needed for
  127. // overlapped I/O
  128. lpCur += 2;
  129. i += 2; //skip 000D and 000A
  130. } // while i<dwInFileSize
  131. UnmapViewOfFile(lpInFile);
  132. CloseHandle(hInMap);
  133. CloseHandle(hInFile);
  134. CloseHandle(hOutFile);
  135. return;
  136. }