home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / sdktools / mc / mc.c < prev    next >
C/C++ Source or Header  |  1997-10-05  |  6KB  |  216 lines

  1. /*++
  2.  
  3. Copyright (c) 1991-1997 Microsoft Corporation
  4.  
  5. Module Name:
  6.  
  7.     mc.c
  8.  
  9. Abstract:
  10.  
  11.     This is the main source file for the Win32 Message Compiler (MC)
  12.  
  13. --*/
  14.  
  15. #include "mc.h"
  16.  
  17. #include "windows.h"
  18.  
  19.  
  20. void
  21. ConvertAppToOem( unsigned argc, char* argv[] )
  22. /*++
  23.  
  24. Routine Description:
  25.  
  26.     Converts the command line from ANSI to OEM, and force the app
  27.     to use OEM APIs
  28.  
  29. Arguments:
  30.  
  31.     argc - Standard C argument count.
  32.  
  33.     argv - Standard C argument strings.
  34.  
  35. Return Value:
  36.  
  37.     None.
  38.  
  39. --*/
  40.  
  41. {
  42.     unsigned i;
  43.  
  44.     for( i=0; i<argc; i++ ) {
  45.        CharToOem( argv[i], argv[i] );
  46.     }
  47.     SetFileApisToOEM();
  48. }
  49.  
  50.  
  51.  
  52.  
  53. void
  54. McPrintUsage( void )
  55. {
  56.     fprintf( stderr, "usage: MC [-?vws] [-h dirspec] [-r dirspec] filename.mc\n" );
  57.     fprintf( stderr, "       -? - displays this message\n" );
  58.     fprintf( stderr, "       -v - gives verbose output.\n" );
  59.     fprintf( stderr, "       -c - sets the Customer bit in all the message Ids.\n" );
  60.     fprintf( stderr, "       -d - numeric values in header file in decimal.\n" );
  61.     fprintf( stderr, "       -w - warns if message text contains non-OS/2 compatible inserts.\n" );
  62.     fprintf( stderr, "       -s - insert symbolic name as first line of each message.\n" );
  63.     fprintf( stderr, "       -h pathspec - gives the path of where to create the C include file\n" );
  64.     fprintf( stderr, "                     Default is .\\\n" );
  65.     fprintf( stderr, "       -r pathspec - gives the path of where to create the RC include file\n" );
  66.     fprintf( stderr, "                     and the binary message resource files it includes.\n" );
  67.     fprintf( stderr, "                     Default is .\\\n" );
  68.     fprintf( stderr, "       filename.mc - gives the names of a message text file\n" );
  69.     fprintf( stderr, "                     to compile.\n" );
  70. }
  71.  
  72.  
  73. int
  74. _CRTAPI1 main(
  75.     int argc,
  76.     char *argv[]
  77.     )
  78. {
  79.     char c, *s, *s1;
  80.     int ShowUsage;
  81.  
  82.  
  83.     ConvertAppToOem( argc, argv );
  84.     FacilityNames = NULL;
  85.     SeverityNames = NULL;
  86.     LanguageNames = NULL;
  87.  
  88.     MessageIdTypeName = NULL;
  89.  
  90.     CurrentFacilityName =
  91.     McAddName( &FacilityNames, "Application",  0x0, NULL );
  92.     CurrentSeverityName =
  93.     McAddName( &SeverityNames, "Success",       0x0, NULL );
  94.  
  95.     McAddName( &SeverityNames, "Informational", 0x1, NULL );
  96.     McAddName( &SeverityNames, "Warning",       0x2, NULL );
  97.     McAddName( &SeverityNames, "Error",         0x3, NULL );
  98.  
  99.     McAddName( &LanguageNames,
  100.                "English",
  101.                MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
  102.                "MSG00001"
  103.              );
  104.  
  105.     strcpy( HeaderFileName, ".\\" );
  106.     strcpy( RcInclFileName, ".\\" );
  107.     strcpy( BinaryMessageFileName, ".\\" );
  108.     MessageFileName[ 0 ] = '\0';
  109.  
  110.     McInitLexer();
  111.  
  112.     VerboseOutput = FALSE;
  113.     WarnOs2Compatible = FALSE;
  114.     GenerateDecimalValues = FALSE;
  115.     ShowUsage = FALSE;
  116.     while (--argc) {
  117.         s = *++argv;
  118.         if (*s == '-' || *s == '/') {
  119.             while (c = *++s) {
  120.                 switch( c ) {
  121.                 case '?':
  122.                     McPrintUsage();
  123.                     exit( 0 );
  124.                     break;
  125.  
  126.                 case 'c':
  127.                     CustomerMsgIdBit = 0x1 << 29;
  128.                     break;
  129.  
  130.                 case 'v':
  131.                     VerboseOutput = TRUE;
  132.                     break;
  133.  
  134.                 case 'd':
  135.                     GenerateDecimalValues = TRUE;
  136.                     break;
  137.  
  138.                 case 'w':
  139.                     WarnOs2Compatible = TRUE;
  140.                     break;
  141.  
  142.                 case 's':
  143.                     InsertSymbolicName = TRUE;
  144.                     break;
  145.  
  146.                 case 'h':
  147.                     if (--argc) {
  148.                         strcpy( s1 = HeaderFileName, *++argv );
  149.             s1 += strlen( s1 );
  150.                         s1 = CharPrev( HeaderFileName, s1 );
  151.                         if (*s1 != '\\' && *s1 != '/') {
  152.                             s1 = CharNext( s1 );
  153.                             *s1 = '\\';
  154.                             *++s1 = '\0';
  155.                 }
  156.             }
  157.                     else {
  158.                         argc++;
  159.                         fprintf( stderr, "MC: missing argument for -%c switch\n", (USHORT)c );
  160.                         ShowUsage = TRUE;
  161.                         }
  162.                     break;
  163.  
  164.                 case 'r':
  165.                     if (--argc) {
  166.             strcpy( s1 = RcInclFileName, *++argv );
  167.                         s1 += strlen( s1 );
  168.                         s1 = CharPrev( HeaderFileName, s1 );
  169.                         if (*s1 != '\\' && *s1 != '/') {
  170.                             s1 = CharNext( s1 );
  171.                             *s1 = '\\';
  172.                             *++s1 = '\0';
  173.                         }
  174.             strcpy( BinaryMessageFileName, RcInclFileName );
  175.                         }
  176.                     else {
  177.                         argc++;
  178.                         fprintf( stderr, "MC: missing argument for -%c switch\n", (USHORT)c );
  179.                         ShowUsage = TRUE;
  180.                         }
  181.                     break;
  182.  
  183.                 default:
  184.                     fprintf( stderr, "MC: Invalid switch: %c\n", (USHORT)c );
  185.                     ShowUsage = TRUE;
  186.                     break;
  187.                     }
  188.                 }
  189.             }
  190.         else
  191.         if (strlen( MessageFileName )) {
  192.             fprintf( stderr, "MC: may only specify one message file to compile.\n" );
  193.             ShowUsage = TRUE;
  194.             }
  195.         else {
  196.             strcpy( MessageFileName, s );
  197.             }
  198.         }
  199.  
  200.     if (ShowUsage) {
  201.         McPrintUsage();
  202.         exit( 1 );
  203.         }
  204.  
  205.     ResultCode = 1;
  206.     if (McParseFile() && McBlockMessages() && McWriteBinaryFiles()) {
  207.         ResultCode = 0;
  208.         }
  209.     else {
  210.         McCloseInputFile();
  211.         McCloseOutputFiles();
  212.         }
  213.  
  214.     return( ResultCode );
  215. }
  216.