示例#1
0
文件: scanner.c 项目: cdwensley/gap
/****************************************************************************
**
*F  SyntaxErrorOrWarning( <msg> ) . . . . . . raise a syntax error or warning
**
**  Helper function used by 'SyntaxError' and 'SyntaxWarning'.
**
*/
static void SyntaxErrorOrWarning(const Char * msg, UInt error)
{
    // do not print a message if we found one already on the current line
    if (STATE(NrErrLine) == 0) {

        // open error output
        OpenErrorOutput();

        // print the message ...
        if (error)
            Pr("Syntax error: %s", (Int)msg, 0);
        else
            Pr("Syntax warning: %s", (Int)msg, 0);

        // ... and the filename + line, unless it is '*stdin*'
        if (strcmp("*stdin*", GetInputFilename()) != 0)
            Pr(" in %s:%d", (Int)GetInputFilename(), GetInputLineNumber());
        Pr("\n", 0, 0);

        // print the current line
        const char * line = GetInputLineBuffer();
        const UInt len = strlen(line);
        if (len > 0 && line[len-1] != '\n')
            Pr("%s\n", (Int)line, 0);
        else
            Pr("%s", (Int)line, 0);

        // print a '^' pointing to the current position
        Int startPos = STATE(SymbolStartPos);
        Int pos = GetInputLinePosition();
        if (STATE(SymbolStartLine) != GetInputLineNumber())
            startPos = 0;
        if (startPos <= pos) {
            Int i;
            for (i = 0; i <= startPos; i++) {
                if (line[i] == '\t')
                    Pr("\t", 0, 0);
                else
                    Pr(" ", 0, 0);
            }

            for (; i <= pos; i++)
                Pr("^", 0, 0);
            Pr("\n", 0, 0);
        }

        // close error output
        CloseOutput();
    }

    if (error) {
        // one more error
        STATE(NrError)++;
        STATE(NrErrLine)++;
    }
}
示例#2
0
void CResourceCompilerHelper::ProcessIfNeeded(
	const char* originalFilename, 
	char* processedFilename, 
	size_t processedFilenameSizeInBytes)
{
	char sDestFile[512];
	GetOutputFilename(originalFilename, sDestFile, sizeof(sDestFile));

	for(uint32 dwIndex=0;;++dwIndex)		// check for all input files
	{
		char sSrcFile[512];
		GetInputFilename(originalFilename, dwIndex, sSrcFile, sizeof(sSrcFile));

		if(sSrcFile[0] == 0)
		{
			break;					// last input file
		}

		// compile if there is no destination
		// compare date of destination and source , recompile if needed
		// load dds header, check hash-value of the compile settings in the dds file, recompile if needed (not done yet)

		CDebugAllowFileAccess dafa;
		FILE* pDestFile = gEnv->pCryPak->FOpen(sDestFile,"rb");
		FILE* pSrcFile = gEnv->pCryPak->FOpen(sSrcFile,"rb");
		dafa.End();

		// files from the pak file do not count as date comparison do not seem to work there
		if(pDestFile)
		{
			if(gEnv->pCryPak->IsInPak(pDestFile))
			{
				gEnv->pCryPak->FClose(pDestFile);
				pDestFile=0;
			}
		}

		bool bInvokeResourceCompiler=false;

		// is there no destination file?
		if(pSrcFile && !pDestFile)
			bInvokeResourceCompiler=true;

		// if both files exist, is the source file newer?
		if(pDestFile && pSrcFile)
		{
			bInvokeResourceCompiler=true;

			ICryPak::FileTime timeSrc = gEnv->pCryPak->GetModificationTime(pSrcFile);
			ICryPak::FileTime timeDest = gEnv->pCryPak->GetModificationTime(pDestFile);

			if(timeDest>=timeSrc)
				bInvokeResourceCompiler=false;
		}

		if(pDestFile)
		{
			gEnv->pCryPak->FClose(pDestFile);pDestFile=0;
		}
		if(pSrcFile)
		{
			gEnv->pCryPak->FClose(pSrcFile);pSrcFile=0;
		}

		if(bInvokeResourceCompiler)
		{
			// Adjust filename so that they are global.
			char sFullSrcFilename[MAX_PATH];
			gEnv->pCryPak->AdjustFileName( sSrcFile,sFullSrcFilename,0 );
			// call rc.exe
			if(!InvokeResourceCompiler(sFullSrcFilename,false))		// false=no window
			{
				// rc failed
				m_bErrorFlag=true;
				assert(!pSrcFile);		// internal error
				assert(!pDestFile);
				strncpy_s(processedFilename, processedFilenameSizeInBytes, originalFilename, _TRUNCATE);
				return;
			}
		}

		assert(!pSrcFile);		// internal error
		assert(!pDestFile);
	}

	// load without using RC (e.g. TGA)
	strncpy_s(processedFilename, processedFilenameSizeInBytes, sDestFile, _TRUNCATE);
}