Leaked source code of windows server 2003
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.

195 lines
5.3 KiB

  1. #include <windows.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <tchar.h>
  5. #include <locale.h>
  6. #include "..\..\lib\i386\bootfont.h"
  7. #include "fonttable.h"
  8. int
  9. __cdecl
  10. main(
  11. IN int argc,
  12. IN char *argv[]
  13. )
  14. {
  15. HANDLE hFile;
  16. DWORD BytesWritten;
  17. BOOL b;
  18. BOOTFONTBIN_HEADER Header;
  19. unsigned u;
  20. unsigned char SBCSBuffer[MAX_SBCS_BYTES+2];
  21. unsigned char DBCSBuffer[MAX_DBCS_BYTES+2];
  22. if(argc != 2) {
  23. fprintf(stderr,"Usage: %s <outputfile>\n",argv[0]);
  24. return(1);
  25. }
  26. //
  27. // Fill in the header.
  28. //
  29. Header.Signature = BOOTFONTBIN_SIGNATURE;
  30. Header.LanguageId = LANGUAGE_ID;
  31. Header.NumSbcsChars = MAX_SBCS_NUM;
  32. Header.NumDbcsChars = MAX_DBCS_NUM;
  33. // Add 2 bytes for each entry for our unicode appendage
  34. Header.SbcsEntriesTotalSize = (MAX_SBCS_BYTES + 2) * MAX_SBCS_NUM;
  35. Header.DbcsEntriesTotalSize = (MAX_DBCS_BYTES + 2) * MAX_DBCS_NUM;
  36. ZeroMemory(Header.DbcsLeadTable,sizeof(Header.DbcsLeadTable));
  37. MoveMemory(Header.DbcsLeadTable,LeadByteTable,sizeof(LeadByteTable));
  38. Header.CharacterImageHeight = 16;
  39. Header.CharacterTopPad = 1;
  40. Header.CharacterBottomPad = 2;
  41. Header.CharacterImageSbcsWidth = 8;
  42. Header.CharacterImageDbcsWidth = 16;
  43. Header.SbcsOffset = sizeof(BOOTFONTBIN_HEADER);
  44. Header.DbcsOffset = Header.SbcsOffset + Header.SbcsEntriesTotalSize;
  45. //
  46. // Create the output file.
  47. //
  48. hFile = CreateFile(
  49. argv[1],
  50. FILE_GENERIC_WRITE,
  51. 0,
  52. NULL,
  53. CREATE_ALWAYS,
  54. 0,
  55. NULL
  56. );
  57. if(hFile == INVALID_HANDLE_VALUE) {
  58. printf("Unable to create output file (%u)\n",GetLastError());
  59. return(1);
  60. }
  61. //
  62. // Write the header.
  63. //
  64. b = WriteFile(hFile,&Header,sizeof(BOOTFONTBIN_HEADER),&BytesWritten,NULL);
  65. if(!b) {
  66. printf("Error writing output file (%u)\n",GetLastError());
  67. CloseHandle(hFile);
  68. return(1);
  69. }
  70. //
  71. // We're about to convert SBCS and DBCS characters into
  72. // unicode, so we need to figure out what to set our
  73. // locale to, so that mbtowc will work correctly.
  74. //
  75. if( _tsetlocale(LC_ALL, LocaleString) == NULL ) {
  76. printf( "_tsetlocale failed!\n" );
  77. return(0);
  78. }
  79. //
  80. // Write the sbcs images.
  81. //
  82. for(u=0; u<MAX_SBCS_NUM; u++) {
  83. //
  84. // Copy the SBCSImage info into our SBCSBuffer, append our
  85. // unicode encoding onto the last 2 bytes of SBCSImage, then
  86. // write it out.
  87. //
  88. RtlCopyMemory( SBCSBuffer, SBCSImage[u], MAX_SBCS_BYTES );
  89. //
  90. // We must use MultiByteToWideChar to convert from SBCS to unicode.
  91. //
  92. // MultiByteToWideChar doesn't seem to work when converting
  93. // from DBCS to unicode, so there we use mbtowc.
  94. //
  95. #if 0
  96. if( !mbtowc( (WCHAR *)&SBCSBuffer[MAX_SBCS_BYTES], SBCSBuffer, 1 ) ) {
  97. #else
  98. if( !MultiByteToWideChar( CP_OEMCP,
  99. MB_ERR_INVALID_CHARS,
  100. SBCSBuffer,
  101. 1,
  102. (WCHAR *)&SBCSBuffer[MAX_SBCS_BYTES],
  103. sizeof(WCHAR) ) ) {
  104. #endif
  105. SBCSBuffer[MAX_SBCS_BYTES] = 0;
  106. SBCSBuffer[MAX_SBCS_BYTES+1] = 0x3F;
  107. }
  108. b = WriteFile(hFile,SBCSBuffer,MAX_SBCS_BYTES+2,&BytesWritten,NULL);
  109. if(!b) {
  110. printf("Error writing output file (%u)\n",GetLastError());
  111. CloseHandle(hFile);
  112. return(1);
  113. }
  114. }
  115. //
  116. // Write the dbcs images.
  117. //
  118. for(u=0; u<MAX_DBCS_NUM; u++) {
  119. //
  120. // Copy the DBCSImage info into our DBCSBuffer, append our
  121. // unicode encoding onto the last 2 bytes of DBCSImage, then
  122. // write it out.
  123. //
  124. RtlCopyMemory( DBCSBuffer, DBCSImage[u], MAX_DBCS_BYTES );
  125. //
  126. // We must use mbtowc to convert from DBCS to unicode.
  127. //
  128. // Whereas, mbtowc doesn't seem to work when converting
  129. // from SBCS to unicode, so there we use MultiByteToWideChar.
  130. //
  131. #if 0
  132. if( !mbtowc( (WCHAR *)&DBCSBuffer[MAX_DBCS_BYTES], DBCSBuffer, 2 ) ) {
  133. #else
  134. if( !MultiByteToWideChar( CP_OEMCP,
  135. MB_ERR_INVALID_CHARS,
  136. DBCSBuffer,
  137. 2,
  138. (WCHAR *)&DBCSBuffer[MAX_DBCS_BYTES],
  139. sizeof(WCHAR) ) ) {
  140. #endif
  141. DBCSBuffer[MAX_DBCS_BYTES] = 0;
  142. DBCSBuffer[MAX_DBCS_BYTES+1] = 0x3F;
  143. }
  144. b = WriteFile(hFile,DBCSBuffer,MAX_DBCS_BYTES+2,&BytesWritten,NULL);
  145. if(!b) {
  146. printf("Error writing output file (%u)\n",GetLastError());
  147. CloseHandle(hFile);
  148. return(1);
  149. }
  150. }
  151. // restore the local to the one the system is using.
  152. _tsetlocale(LC_ALL, "");
  153. //
  154. // Done.
  155. //
  156. CloseHandle(hFile);
  157. printf("Output file sucessfully generated\n");
  158. return(0);
  159. }