MCOUT.C
上传用户:bangxh
上传日期:2007-01-31
资源大小:42235k
文件大小:7k
源码类别:

Windows编程

开发平台:

Visual C++

  1. /*++
  2. Copyright (c) 1991-1997 Microsoft Corporation
  3. Module Name:
  4.     mcout.c
  5. Abstract:
  6.     This file contains the output functions of the Win32 Message Compiler (MC)
  7. --*/
  8. #include "mc.h"
  9. PMESSAGE_BLOCK MessageBlocks = NULL;
  10. int NumberOfBlocks = 0;
  11. /*++
  12. Routine Description:
  13. Arguments:
  14. Return Value:
  15. --*/
  16. BOOLEAN
  17. McBlockMessages( void )
  18. {
  19.     PMESSAGE_BLOCK p, *pp;
  20.     PMESSAGE_INFO MessageInfo;
  21.     pp = &MessageBlocks;
  22.     p = NULL;
  23.     MessageInfo = Messages;
  24.     while (MessageInfo) {
  25.         if (p) {
  26.             if (p->HighId+1 == MessageInfo->Id) {
  27.                 p->HighId += 1;
  28.                 }
  29.             else {
  30.                 pp = &p->Next;
  31.                 }
  32.             }
  33.         if (!*pp) {
  34.             NumberOfBlocks += 1;
  35.             p = malloc( sizeof( *p ) );
  36.             p->Next = NULL;
  37.             p->LowId = MessageInfo->Id;
  38.             p->HighId = MessageInfo->Id;
  39.             p->LowInfo = MessageInfo;
  40.             *pp = p;
  41.             }
  42.         MessageInfo = MessageInfo->Next;
  43.         }
  44.     return( TRUE );
  45. }
  46. /*++
  47. Routine Description:
  48. Arguments:
  49. Return Value:
  50. --*/
  51. BOOLEAN
  52. McWriteBinaryFiles( void )
  53. {
  54.     PNAME_INFO LanguageName, *pp;
  55.     PLANGUAGE_INFO LanguageInfo;
  56.     PMESSAGE_INFO MessageInfo;
  57.     PMESSAGE_BLOCK BlockInfo;
  58.     char *FileName;
  59.     ULONG cb;
  60.     ULONG MessageOffset;
  61.     MESSAGE_RESOURCE_ENTRY MessageEntry;
  62.     MESSAGE_RESOURCE_BLOCK MessageBlock;
  63.     MESSAGE_RESOURCE_DATA  MessageData;
  64.     ULONG Zeroes = 0;
  65.     ULONG NumberOfMessages;
  66.     FileName = BinaryMessageFileName;
  67.     FileName += strlen( FileName );
  68.     pp = &LanguageNames;
  69.     while (LanguageName = *pp) {
  70.         pp = &LanguageName->Next;
  71.         if (!LanguageName->Used) {
  72.             continue;
  73.             }
  74.         strcpy( FileName, LanguageName->Value );
  75.         strcat( FileName, ".bin" );
  76.         if (!(BinaryMessageFile = fopen( BinaryMessageFileName, "wb" ))) {
  77.             McInputError( "unable to open output file - %s", TRUE, BinaryMessageFileName );
  78.             return( FALSE );
  79.             }
  80.         if (VerboseOutput) {
  81.             fprintf( stderr, "Writing %sn", BinaryMessageFileName );
  82.             }
  83.         fprintf( RcInclFile, "LANGUAGE 0x%x,0x%xrn",
  84.                              PRIMARYLANGID( LanguageName->Id ),
  85.                              SUBLANGID( LanguageName->Id )
  86.                );
  87.         fprintf( RcInclFile, "1 11 %srn", FileName );
  88.         NumberOfMessages = 0L;
  89.         MessageData.NumberOfBlocks = NumberOfBlocks;
  90.         MessageOffset = fwrite( &MessageData,
  91.                                 1,
  92.                                 (size_t)FIELD_OFFSET( MESSAGE_RESOURCE_DATA,
  93.                                                       Blocks[ 0 ]
  94.                                                     ),
  95.                                 BinaryMessageFile
  96.                               );
  97.         MessageOffset += NumberOfBlocks * sizeof( MessageBlock );
  98.         BlockInfo = MessageBlocks;
  99.         while (BlockInfo) {
  100.             MessageBlock.LowId = BlockInfo->LowId;
  101.             MessageBlock.HighId = BlockInfo->HighId;
  102.             MessageBlock.OffsetToEntries = MessageOffset;
  103.             fwrite( &MessageBlock, 1, sizeof( MessageBlock ), BinaryMessageFile );
  104.             BlockInfo->InfoLength = 0;
  105.             MessageInfo = BlockInfo->LowInfo;
  106.             while (MessageInfo != NULL && MessageInfo->Id <= BlockInfo->HighId) {
  107.                 LanguageInfo = MessageInfo->MessageText;
  108.                 while (LanguageInfo) {
  109.                     if (LanguageInfo->Id == LanguageName->Id) {
  110.                         break;
  111.                         }
  112.                     else {
  113.                         LanguageInfo = LanguageInfo->Next;
  114.                         }
  115.                     }
  116.                 if (LanguageInfo != NULL) {
  117.                     cb = FIELD_OFFSET( MESSAGE_RESOURCE_ENTRY, Text[ 0 ] ) +
  118.                          LanguageInfo->Length + 1;
  119.                     cb = (cb + 3) & ~3;
  120.                     BlockInfo->InfoLength += cb;
  121.                     }
  122.                 else {
  123.                     fprintf( stderr,
  124.                              "MC: No %s language text for %sn",
  125.                              LanguageName->Name,
  126.                              MessageInfo->SymbolicName
  127.                            );
  128.                     fclose( BinaryMessageFile );
  129.                     return( FALSE );
  130.                     }
  131.                 MessageInfo = MessageInfo->Next;
  132.                 }
  133.             if (VerboseOutput) {
  134.                 fprintf( stderr, "    [%08lx .. %08lx] - %lu bytesn",
  135.                          BlockInfo->LowId,
  136.                          BlockInfo->HighId,
  137.                          BlockInfo->InfoLength
  138.                        );
  139.                 }
  140.             MessageOffset += BlockInfo->InfoLength;
  141.             BlockInfo = BlockInfo->Next;
  142.             }
  143.         BlockInfo = MessageBlocks;
  144.         while (BlockInfo) {
  145.             MessageInfo = BlockInfo->LowInfo;
  146.             while (MessageInfo != NULL && MessageInfo->Id <= BlockInfo->HighId) {
  147.                 LanguageInfo = MessageInfo->MessageText;
  148.                 while (LanguageInfo) {
  149.                     if (LanguageInfo->Id == LanguageName->Id) {
  150.                         break;
  151.                         }
  152.                     else {
  153.                         LanguageInfo = LanguageInfo->Next;
  154.                         }
  155.                     }
  156.                 if (LanguageInfo != NULL) {
  157.                     cb = FIELD_OFFSET( MESSAGE_RESOURCE_ENTRY, Text[ 0 ] ) +
  158.                          LanguageInfo->Length + 1;
  159.                     cb = (cb + 3) & ~3;
  160.                     MessageEntry.Length = (USHORT)cb;
  161.                     MessageEntry.Flags = 0;
  162.                     cb = fwrite( &MessageEntry,
  163.                                  1,
  164.                                  (size_t)FIELD_OFFSET( MESSAGE_RESOURCE_ENTRY,
  165.                                                        Text[ 0 ]
  166.                                                      ),
  167.                                  BinaryMessageFile
  168.                                );
  169.                     cb += fwrite( LanguageInfo->Text,
  170.                                   1,
  171.                                   (size_t)LanguageInfo->Length,
  172.                                   BinaryMessageFile
  173.                                 );
  174.                     NumberOfMessages++;
  175.                     cb = MessageEntry.Length - cb;
  176.                     if (cb) {
  177.                         fwrite( &Zeroes,
  178.                                 1,
  179.                                 (size_t)cb,
  180.                                 BinaryMessageFile
  181.                               );
  182.                         }
  183.                     }
  184.                 MessageInfo = MessageInfo->Next;
  185.                 }
  186.             BlockInfo = BlockInfo->Next;
  187.             }
  188.         if (VerboseOutput) {
  189.             fprintf( stderr, "    Total of %lu messages, %lu bytesn",
  190.                              NumberOfMessages,
  191.                              ftell( BinaryMessageFile )
  192.                    );
  193.             }
  194.         fclose( BinaryMessageFile );
  195.         }
  196.     return( TRUE );
  197. }