示例#1
0
int main(int argc, char* argv[])
{
#ifdef _WIN32
    struct _finddata_t fileinfo;
    bool	error_pause = false;
#endif
    char	*filename, error_msg[MAX_STRING_LENGTH], newfilename[MAX_FILENAME_LENGTH];
    int		handle;

    //Init the tokenizer and pass the symbols we require
    Tokenizer.Create( 0 );
    Tokenizer.SetSymbols( (keywordArray_t *) Interpreter.GetSymbols() );
    Tokenizer.SetErrorProc( (void (__cdecl *)(const char *)) NULL_Error );

    //Init the block streaming class
    BlockStream.Init();

    //No script arguments, print the banner
    if (argc < 2)
    {
        printf("\n\nIBIze v%1.2f -- jweier\n", IBIZE_VERSION );
        printf("ICARUS v%1.2f\n", ICARUS_VERSION );
        printf("Copyright (c) 1999, Raven Software\n");
        printf("------------------------------\n");
        printf("\nIBIze [script1.txt] [script2.txt] [script3.txt] ...\n\n");

        return 0;
    }

    int iErrorBlock = 0;

    //Interpret all files passed on the command line
    for (int i=1; i<argc; i++)
    {
        filename = (char *) argv[i];

        //FIXME: There could be better ways to do this...
        if ( filename[0] == '-' )
        {
#ifdef _WIN32
            if ( tolower(filename[1]) == 'e' )
                error_pause = true;
//Can just use a wildcard in the commandline on non-windows
            if ( tolower(filename[1]) == 'a' )
            {
                handle = _findfirst ( "*.txt", &fileinfo);

                while ( handle != -1 )
                {
                    if (Tokenizer.AddParseFile( (char*) &fileinfo.name ))
                    {
                        //Interpret the file
                        if ( (iErrorBlock=InterpretFile( (char *) &fileinfo.name )) !=0 )
                        {
                            // failed
                            //
                            BlockStream.Free();

                            if (error_pause)
                                getch();
                        }
                    }

                    if ( _findnext( handle, &fileinfo ) == -1 )
                        break;
                }

                _findclose (handle);
            }
#endif

            continue;
        }

        //Tokenize the file
        if (Tokenizer.AddParseFile( filename ))
        {
            //Interpret the file
            if ( (iErrorBlock=InterpretFile( filename )) !=0 )
            {
                // failed
                //
                BlockStream.Free();

#ifdef _WIN32
                if (error_pause)
                    getch();
#endif

                return iErrorBlock;
            }
        }
        else
        {
            //Try adding on the SCR extension if it was left off
            strcpy((char *) &newfilename, filename);
            strcat((char *) &newfilename, SCRIPT_EXTENSION);

            if (Tokenizer.AddParseFile( (char*) &newfilename ))
            {
                //Interpret the file
                if ( (iErrorBlock=InterpretFile( (char *) &newfilename )) !=0 )
                {
                    // failed
                    //
                    BlockStream.Free();

#ifdef _WIN32
                    if (error_pause)
                        getch();
#endif
                    return iErrorBlock;
                }
            }
            else
            {
                //File wasn't found
                sprintf(error_msg, "ERROR: File '%s' not found!\n", filename);
                printf(error_msg);

#ifdef _WIN32
                if (error_pause)
                    getch();
#endif

                return 1;	// this will technically mean that there was a problem with cblock 1, but wtf?
            }
        }
    }

    printf("Done\n\n");

    return 0;
}
示例#2
0
//
// this actually reads XSI or GLA headers...  historical mutation strikes again...
//
static void ReadASEHeader_Actual(LPCSTR psFilename, int &iStartFrame, int &iFrameCount, int &iFrameSpeed, bool bReadingGLA, bool bCanSkipXSIRead /* = false */)
{
	// since the XSI loader is so damn slow and flakey I'm going to have to cache the info to avoid re-reading...
	//

	// do we have it in the cache?...
	//
	if (strstr(psFilename,".xsi") || strstr(psFilename,".XSI"))
	{
		ASECachedInfo_t::iterator iter = ASECachedInfo.find(psFilename);
		if (iter != ASECachedInfo.end())
		{
			iStartFrame = 0;
			iFrameCount = (*iter).second.first;
			iFrameSpeed = (*iter).second.second;
			return;
		}
	}

	// is it a GLA file?...
	//
	if (bReadingGLA)
	{
		char sTemp[1024];
		strcpy(sTemp,psFilename);
		if (!(strstr(psFilename,".gla") || strstr(psFilename,".GLA")))
		{
			strcat(sTemp,".gla");
		}

		iStartFrame = 0;
		iFrameCount = GLA_ReadHeader(sTemp);
		iFrameSpeed = 20;	// any old value for GLA file
		return;
	}


	// it's not in the cache, but we may be able to avoid having to read it under some circumstances...
	//
	bool bXSIShouldBeRead = true;

	if (gbCarWash_DoingScan)
	{
		bCanSkipXSIRead = false;	// stop it asking the question
		bXSIShouldBeRead= gbCarWash_YesToXSIScan;
	}

	if ( (strstr(psFilename,".xsi") || strstr(psFilename,".XSI"))
		&& bCanSkipXSIRead
		)
	{
		if (!gbSkipXSIRead && !gbSkipXSIRead_QuestionAsked)
		{
			gbSkipXSIRead_QuestionAsked = true;
			gbSkipXSIRead = !GetYesNo(va("Model file: \"%s\"\n\n... is an XSI, and they can be damn slow to read in\n\nDo you want to scan all the XSIs?",psFilename));
		}
					
		bXSIShouldBeRead = !gbSkipXSIRead;
	}

	if (strstr(psFilename,".xsi") || strstr(psFilename,".XSI"))
	{
		if (bXSIShouldBeRead)
		{
			ReadXSIHeader(psFilename, iStartFrame, iFrameCount, iFrameSpeed);
	
			if (iFrameCount!=0)
			{
				// cache it for future...
				//
				ASECachedInfo[psFilename] = FrameCountAndSpeed_t(iFrameCount,iFrameSpeed);
			}
		}
		return;
	}

	// it must be an ASE file then instead....
	//
	CTokenizer* tokenizer = CTokenizer::Create();
	tokenizer->AddParseFile(psFilename, ((CAssimilateApp*)AfxGetApp())->GetBufferSize());
	tokenizer->SetSymbols(CSequence_s_Symbols);
	tokenizer->SetKeywords(CSequence_s_Keywords);

	CToken* curToken = tokenizer->GetToken();
	while(curToken != NULL)
	{
		switch (curToken->GetType())
		{
		case TK_EOF:
			curToken->Delete();
			curToken = NULL;
			break;
		case TK_ASTERISK:
			curToken->Delete();
			curToken = tokenizer->GetToken();
			switch(curToken->GetType())
			{
			case TK_ASE_FIRSTFRAME:
				curToken->Delete();
				curToken = tokenizer->GetToken();
				if (curToken->GetType() == TK_INTEGER)
				{
					iStartFrame = curToken->GetIntValue();
					curToken->Delete();
					curToken = tokenizer->GetToken();
				}
				break;
			case TK_ASE_LASTFRAME:
				curToken->Delete();
				curToken = tokenizer->GetToken();
				if (curToken->GetType() == TK_INTEGER)
				{
					iFrameCount = curToken->GetIntValue() + 1;
					curToken->Delete();
					curToken = NULL;	// tells outer loop to finish
				}
				break;
			case TK_ASE_FRAMESPEED:
				curToken->Delete();
				curToken = tokenizer->GetToken();
				if (curToken->GetType() == TK_INTEGER)
				{
					iFrameSpeed = curToken->GetIntValue();
					curToken->Delete();
					curToken = tokenizer->GetToken();
				}
				break;
			case TK_EOF:
				curToken->Delete();
				curToken = NULL;
				break;
			default:
				curToken->Delete();
				curToken = tokenizer->GetToken();
				break;
			}
			break;
		default:
			curToken->Delete();
			curToken = tokenizer->GetToken();
			break;
		}
	}
	tokenizer->Delete();

	iFrameCount -= iStartFrame;	
	iStartFrame  = 0;
}
示例#3
0
void CASEFile::Parse()
{
	if (m_file == NULL)
	{
		return;
	}
	CAlertErrHandler errhandler;
	CTokenizer* tokenizer = CTokenizer::Create(TKF_USES_EOL | TKF_NUMERICIDENTIFIERSTART);
	tokenizer->SetErrHandler(&errhandler);
	tokenizer->SetKeywords(s_keywords);
	tokenizer->SetSymbols(s_symbols);
	tokenizer->AddParseFile(m_file, 16 * 1024);
	int tokType = TK_UNDEFINED;
	while(tokType != TK_EOF)
	{
		CToken* curToken = tokenizer->GetToken();
		if (curToken->GetType() == TK_EOF)
		{
			curToken->Delete();
			tokType = TK_EOF;
			break;
		}
		if (curToken->GetType() == TK_EOL)
		{
			curToken->Delete();
			continue;
		}
		if (curToken->GetType() != TK_ASE_ASTERISK)
		{
			tokenizer->Error(TKERR_UNEXPECTED_TOKEN);
			curToken->Delete();
			tokenizer->GetToEndOfLine()->Delete();
			continue;
		}
		curToken->Delete();
		curToken = tokenizer->GetToken();
		tokType = curToken->GetType();
		curToken->Delete();
		switch(tokType)
		{
		case TK_EOF:
			break;
		case TK_GEOMOBJECT:
			ParseGeomObject(tokenizer);
			break;
		case TK_SCENE:
			ParseScene(tokenizer);
			break;
		case TK_MATERIAL_LIST:
			ParseMaterialList(tokenizer);
			break;
		case TK_ASE_COMMENT:
			ParseComment(tokenizer);
			break;
		case TK_3DSMAX_ASCIIEXPORT:
			ParseAsciiExport(tokenizer);
			break;
		default:
			tokenizer->Error(TKERR_UNEXPECTED_TOKEN);
			tokenizer->GetToEndOfLine()->Delete();
			break;
		}
	}
}