Example #1
0
Bool CCompiler::OnCompileFail( )
{
    CL_TRACE("Enter CCompiler::OnCompileFail");

    FileSystem::FileHandle compileLogFile = FileSystem::CreateFile(EFileType::E_FILE_TYPE_MEMORY);
    
    if( !compileLogFile->Open( m_compilerOutputFile, EAccesMode::E_ACCES_MODE_READ ) )
    {
        CL_ERROR( "failed to open file:[%s]", m_compilerOutputFile.GetBuffer() );
        return false;
    }

    u64 fileSize = compileLogFile->GetSize();
    CString fileContent;
    fileContent.Resize(fileSize);

    if( !compileLogFile->Read( fileContent.GetBuffer(), fileSize, 1 ) )
    {
        CL_ERROR( "failed to read file content for:[%s]" ,m_compilerOutputFile.GetBuffer() );
        return false;
    }

#define COMPILER_USE_FULL_DEVENV_OUTPUT

#if !defined(COMPILER_USE_FULL_DEVENV_OUTPUT)
    //replace CompilerDummy.cpp with our file
    CString slnCppFileName = GetSolutionCppFileRaw();
    CString sourceFileName = "CodSursa.cpp";

    CRegex regexReplace( slnCppFileName );
    fileContent = regexReplace.Replace( fileContent, sourceFileName);

    CL_TRACE("fileContent:\n[%s]\n=======================", fileContent.GetBuffer());
    //CL_ERROR("fileContent:\n[%s]\n=======================", fileContent.GetBuffer());

    const CString regexString = sourceFileName + "\\([0-9]+\\):.*error C[0-9]+:[^\n]*";
    CRegex errorRegex( regexString, true );
    CRegex::TCaptures errors;

    if( !errorRegex.Find( fileContent, errors ) )
    {
        CL_ERROR( "failed to find errors in file:[%s]",m_compilerOutputFile.GetBuffer() );
        return false;
    }

    for( u64 i=0; i<errors.GetSize(); i++ )
    {
        const CString& error = errors[i];
        m_compileErrors += error;
    }
#else
    m_compileErrors = fileContent;
#endif //COMPILER_USE_FULL_DEVENV_OUTPUT

    return true;    // The OnCompileFailed step succeeded;
}
Example #2
0
CString CColor::Print(_IN ColorRGBA& rValue)
{
	ColorRGBA Color = rValue;

	CString RetVal;
	RetVal.Resize(9);
	RetVal.AtPut(0, '#');

	for (UINT i = 8; i > 0; i--)
	{
		if ((Color & 0x0f) > 9)
		{
			RetVal.AtPut(i, 'A' + (BYTE)(Color & 0x0f) - 10);
		}
		else
		{
			RetVal.AtPut(i, '0' + (BYTE)(Color & 0x0f));
		}

		Color >>= 4;
	}

	return RetVal;
}
Example #3
0
Bool CCompiler::OnCompileSucceeded( )
{
    CString exePath = GetCompiledExeFilePath();
    if( !CPath::FileExists(exePath) )
    {
        CL_ERROR( "Compiled succeeded but the file:[%s] was not found", exePath.GetBuffer() );
        return false;
    }
    
    CString inputFileName = GetExePath() + "input.in";
    CString outputFileName = GetExePath() + "output.out";

    CPath::DeleteFile( inputFileName );
    CPath::DeleteFile( outputFileName );

    // write the program input to the file
    FileSystem::FileHandle inputFileHandle = FileSystem::CreateFile( EFileType::E_FILE_TYPE_MEMORY );
    if(!inputFileHandle->Open( inputFileName, EAccesMode::E_ACCES_MODE_WRITE ) )
    {
        CL_ERROR("failed to set the program input");
        return false;
    }

    if( !inputFileHandle->Write( m_programInput, m_programInput.GetLenght(), 1 ) )
    {
        CL_ERROR("failed to set the program input");
        return false;
    }

    // close the input file so that the new program can read from it;
    inputFileHandle->Close();

#if !defined (CL_USE_PROCESS)

    CString command = "call " +  StringUtils::Quote(exePath) + " < " + StringUtils::Quote( inputFileName ) + " > " + StringUtils::Quote( outputFileName );

    RunCommand( command );

    Sleep( 3000 );//sleep 3 second so we can let the process to do the job;
    FileSystem::FileHandle outputFileHandle = FileSystem::CreateFile( EFileType::E_FILE_TYPE_MEMORY );

    if( !outputFileHandle->Open( outputFileName, EAccesMode::E_ACCES_MODE_READ ) )
    {
        CL_ERROR("failed to get the output of the your program" );
        return false;
    }

    u64 fileSize = outputFileHandle->GetSize();
    if(fileSize == 0)
    {
        CL_ERROR("failed to get the output of your program");
        return false;
    }
    
    CString outputFileContent;
    outputFileContent.Resize( fileSize + 1 );

    if( !outputFileHandle->Read( outputFileContent.GetBuffer(), fileSize, 1 ) )
    {
        CL_ERROR( "failed to get the output of your program" );
        return false;
    }

    m_programOutput = outputFileContent;

#elif defined( CL_USE_PROCESS )
    SECURITY_ATTRIBUTES sa;
    ThZeroMemoryTmpl(sa);
    sa.nLength = sizeof(sa);
    sa.lpSecurityDescriptor = NULL;
    sa.bInheritHandle = TRUE; 



    HANDLE inputFileHandle = CreateFileA(   inputFile.GetBuffer(),
                                            FILE_APPEND_DATA,
                                            FILE_SHARE_WRITE | FILE_SHARE_READ,
                                            &sa,
                                            OPEN_ALWAYS,
                                            FILE_ATTRIBUTE_NORMAL,
                                            NULL
                                        );

    if( inputFileHandle == INVALID_HANDLE_VALUE )
    {
        CL_ERROR("failed to redirect child process stdin ");
        CL_ERROR("WIN last error = %d", GetLastError());
        return false;
    }

    HANDLE outputFileHandle = CreateFileA(outputFile.GetBuffer(),
                                            GENERIC_READ | GENERIC_WRITE,
                                            FILE_SHARE_WRITE | FILE_SHARE_READ,
                                            &sa,
                                            CREATE_ALWAYS,
                                            FILE_ATTRIBUTE_NORMAL,
                                            NULL
                                        );

    if( outputFileHandle == INVALID_HANDLE_VALUE )
    {
        CL_ERROR("failed to redirect child process stout ");
        CL_ERROR("WIN last error = %d", GetLastError());
        return false;
    }


    SetHandleInformation(inputFileHandle, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT);

    // setup startup info
    STARTUPINFO processStartupInfo;
    ThZeroMemoryTmpl(processStartupInfo);
    processStartupInfo.cb = sizeof(processStartupInfo);
    processStartupInfo.dwFlags |= STARTF_USESTDHANDLES;
    processStartupInfo.hStdInput = inputFileHandle;
    processStartupInfo.hStdOutput = outputFileHandle;


    PROCESS_INFORMATION processInfo;

    if( !CreateProcessA( exePath.GetBuffer() // application name  
                        ,exePath.GetBuffer()
                        ,NULL
                        ,NULL
                        ,TRUE
                        ,0
                        ,NULL
                        ,NULL
                        ,&processStartupInfo
                        ,&processInfo) 
        )
    {
        CL_ERROR("Cannot start process:[%s]", exePath.GetBuffer());
        return false;
    }

    WaitForSingleObject(processInfo.hProcess, 3000 );
    CloseHandle( processInfo.hThread );
    CloseHandle( processInfo.hProcess );
#endif
    return true;
}