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.

178 lines
5.3 KiB

  1. #pragma warning ( disable : 4514 )
  2. #include <stdio.h>
  3. #include <malloc.h>
  4. #include <excpt.h>
  5. #include <process.h>
  6. #include <string.h>
  7. #include "cmdline.h"
  8. #include "errdb.h"
  9. #ifdef MIDL_INTERNAL
  10. #define MIDL_FREE_BUILD 0
  11. #define MIDL_INTERNAL_PRINTF(x) printf(x)
  12. #else
  13. #define MIDL_FREE_BUILD 1
  14. #define MIDL_INTERNAL_PRINTF(x)
  15. #endif
  16. const char *pSignon1 = "Microsoft (R) 32b/64b MIDL Compiler Version %s \n";
  17. const char *pSignon2 = "Copyright (c) Microsoft Corp 1991-2000. All rights reserved.\n";
  18. STATUS_T Execute( char* szCmd, char* szCmdLine );
  19. void RpcError( char* pFile, short Line, STATUS_T status, char* pSuffix );
  20. void ReportError( STATUS_T status, char* szMsg );
  21. void WriteCommandAnaFile(char *pszFilename, CommandLine *pCmdLine);
  22. extern "C" long __stdcall GetTempPathA( long, char * );
  23. extern "C" long __stdcall GetTempFileNameA( const char*, const char*, unsigned int, char * );
  24. CMD_ARG* pCommand;
  25. bool fCommandLineErrors = false;
  26. inline bool BadIntermediateFileError( STATUS_T status )
  27. {
  28. return ( BAD_CMD_FILE == status )
  29. || ( UNABLE_TO_OPEN_CMD_FILE == status );
  30. }
  31. int
  32. main(
  33. int argc,
  34. char** argv
  35. )
  36. {
  37. STATUS_T status = STATUS_OK;
  38. char szTempCmdFile[_MAX_PATH];
  39. _try
  40. {
  41. CommandLine* pCmdLine = new CommandLine;
  42. pCommand = pCmdLine;
  43. // /nologo is specially detected by RegisterArgs
  44. pCmdLine->RegisterArgs( argv+1, short(argc -1) );
  45. char* szVersion = pCmdLine->GetCompilerVersion();
  46. pCmdLine->GetCompileTime();
  47. if ( pCmdLine->ShowLogo() )
  48. {
  49. // the signon
  50. fprintf( stderr, pSignon1, szVersion );
  51. fprintf( stderr, pSignon2 );
  52. fflush( stderr );
  53. }
  54. status = pCmdLine->ProcessArgs();
  55. if( status == STATUS_OK && ! fCommandLineErrors )
  56. {
  57. if( pCmdLine->IsSwitchDefined( SWITCH_CONFIRM ) )
  58. {
  59. pCmdLine->Confirm();
  60. }
  61. else if( pCmdLine->IsSwitchDefined( SWITCH_HELP ) )
  62. {
  63. pCmdLine->Help();
  64. }
  65. else
  66. {
  67. char path_buffer[_MAX_PATH];
  68. char drive[_MAX_DRIVE];
  69. char dir[_MAX_DIR];
  70. char fname[_MAX_FNAME];
  71. char ext[_MAX_EXT];
  72. // Create the core intermediate file
  73. GetTempPathA( _MAX_PATH, path_buffer );
  74. if ( !GetTempFileNameA(path_buffer, "MIDLC", 0, szTempCmdFile) )
  75. {
  76. status = INTERMEDIATE_FILE_CREATE;
  77. RpcError( NULL, 0, status, path_buffer);
  78. return status;
  79. }
  80. WriteCommandAnaFile( szTempCmdFile, pCmdLine );
  81. // The path to midlc.exe should be the same as the path to
  82. // midl.exe
  83. _splitpath( argv[0], drive, dir, fname, ext );
  84. _makepath( path_buffer, drive, dir, "midlc", "exe" );
  85. // if -debugline is present, spit out the midlcore command
  86. // line and quit; the command ana file is preserved.
  87. if ( pCmdLine->IsSwitchDefined( SWITCH_DEBUGLINE ) )
  88. {
  89. printf( "\ndebugline: %s %s\n", path_buffer, szTempCmdFile );
  90. return 0;
  91. }
  92. // spawn 32b MIDL run
  93. status = ( STATUS_T ) Execute( path_buffer, szTempCmdFile );
  94. if ( ! BadIntermediateFileError( status ) )
  95. _unlink( szTempCmdFile );
  96. if ( !pCmdLine->IsSwitchDefined( SWITCH_ENV ) && status == STATUS_OK )
  97. {
  98. // spawn 64b MIDL run
  99. pCmdLine->SetEnv( ENV_WIN64 );
  100. pCmdLine->SetHasAppend64( TRUE );
  101. pCmdLine->SwitchDefined( SWITCH_APPEND64 );
  102. pCmdLine->SetPostDefaults64();
  103. if ( status == STATUS_OK && ! fCommandLineErrors )
  104. {
  105. WriteCommandAnaFile( szTempCmdFile, pCmdLine );
  106. status = ( STATUS_T ) Execute( path_buffer, szTempCmdFile );
  107. if ( ! BadIntermediateFileError( status ) )
  108. _unlink( szTempCmdFile );
  109. }
  110. }
  111. }
  112. }
  113. if ( status == SPAWN_ERROR )
  114. {
  115. RpcError( 0, 0, status, 0 );
  116. }
  117. }
  118. __except( MIDL_FREE_BUILD && ! pCommand->IsSwitchDefined( SWITCH_DEBUGEXC ) )
  119. {
  120. // Catch exceptions only for free builds run without -debugexc switch.
  121. status = (STATUS_T) GetExceptionCode();
  122. printf( "\nmidl : error MIDL%d : internal compiler problem -",
  123. I_ERR_UNEXPECTED_INTERNAL_PROBLEM );
  124. printf( " See documentation for suggestions on how to find a workaround.\n" );
  125. }
  126. return status;
  127. }
  128. void WriteCommandAnaFile(
  129. char *pszFilename,
  130. CommandLine *pCmdLine
  131. )
  132. {
  133. STREAM stream( pszFilename );
  134. stream.SetStreamMode( STREAM_BINARY );
  135. pCmdLine->StreamOut( &stream );
  136. fflush( NULL );
  137. }
  138. void
  139. IncrementErrorCount()
  140. {
  141. fCommandLineErrors = true;
  142. }