/* ================ idDict::Parse ================ */ bool idDict::Parse( idParser &parser ) { idToken token; idToken token2; bool errors; errors = false; parser.ExpectTokenString( "{" ); parser.ReadToken( &token ); while( ( token.type != TT_PUNCTUATION ) || ( token != "}" ) ) { if ( token.type != TT_STRING ) { parser.Error( "Expected quoted string, but found '%s'", token.c_str() ); } if ( !parser.ReadToken( &token2 ) ) { parser.Error( "Unexpected end of file" ); } if ( FindKey( token ) ) { parser.Warning( "'%s' already defined", token.c_str() ); errors = true; } Set( token, token2 ); if ( !parser.ReadToken( &token ) ) { parser.Error( "Unexpected end of file" ); } } return !errors; }
/* ============ sdDemoCamera_Anim::Parse ============ */ bool sdDemoCamera_Anim::Parse( idParser& src ) { if ( !src.ExpectTokenString( "{" ) ) { return false; } idToken token; int cycle = 1; idVec3 offset( vec3_origin ); while( true ) { if ( !src.ExpectAnyToken( &token ) ) { return false; } if ( !token.Cmp( "}" ) ) { break; } else if ( !token.Icmp( "anim" ) ) { if ( !src.ExpectAnyToken( &token ) ) { return false; } if ( !cameraMD5.LoadAnim( token ) ) { return false; } } else if ( !token.Icmp( "cycle" ) ) { cycle = src.ParseInt(); } else if ( !token.Icmp( "offset" ) ) { if ( !src.Parse1DMatrix( 3, offset.ToFloatPtr() ) ) { return false; } } else if ( !sdDemoCamera::ParseKey( token, src ) ) { src.Error( "sdDemoCamera_Anim::Parse : Unknown keyword '%s'", token.c_str() ); return false; } } if ( !cycle ) { cycle = 1; } cameraMD5.SetCycle( cycle ); cameraMD5.SetOffset( offset ); return true; }
/* ============ sdDemoCamera_Fixed::Parse ============ */ bool sdDemoCamera_Fixed::Parse( idParser& src ) { if ( !src.ExpectTokenString( "{" ) ) { return false; } idToken token; while( true ) { if ( !src.ExpectAnyToken( &token ) ) { return false; } if ( !token.Cmp( "}" ) ) { break; } else if ( !token.Icmp( "origin" ) ) { if ( !src.Parse1DMatrix( 3, origin.ToFloatPtr() ) ) { return false; } } else if ( !token.Icmp( "axis" ) ) { if ( !src.Parse2DMatrix( 3, 3, axis.ToFloatPtr() ) ) { return false; } } else if ( !token.Icmp( "angles" ) ) { idAngles angles; if ( !src.Parse1DMatrix( 3, angles.ToFloatPtr() ) ) { return false; } axis = angles.ToMat3(); } else if ( !token.Icmp( "fov" ) ) { fov = src.ParseFloat(); } else if ( !sdDemoCamera::ParseKey( token, src ) ) { src.Error( "sdDemoCamera_Fixed::Parse : Unknown keyword '%s'", token.c_str() ); return false; } } return true; }
/* ================ idTypeInfoGen::ParseScope ================ */ void idTypeInfoGen::ParseScope( const char *scope, bool isTemplate, idParser &src, idClassTypeInfo *typeInfo ) { int indent; idToken token; idClassTypeInfo *classInfo; idEnumTypeInfo *enumInfo; idStr varType; bool isConst = false; bool isStatic = false; indent = 1; while( indent ) { if ( !src.ReadToken( &token ) ) { break; } if ( token == "{" ) { do { if ( token == "{" ) { indent++; } else if ( token == "}" ) { indent--; } varType += token + " "; } while( indent > 1 && src.ReadToken( &token ) ); } else if ( token == "}" ) { assert( indent == 1 ); indent--; } else if ( token == "<" ) { do { if ( token == "<" ) { indent++; } else if ( token == ">" ) { indent--; } varType += token + " "; } while( indent > 1 && src.ReadToken( &token ) ); } else if ( token == ";" ) { varType = ""; isConst = false; isStatic = false; } else if ( token == "public" || token == "protected" || token == "private" ) { if ( !src.ExpectTokenString( ":" ) ) { break; } varType = ""; isConst = false; isStatic = false; } else if ( token == "friend" ) { // skip friend classes/methods while( src.ReadToken( &token ) ) { if ( token == "{" ) { indent++; } else if ( token == "}" ) { indent--; if ( indent == 1 ) { break; } } else if ( token == ";" && indent == 1 ) { break; } } varType = ""; isConst = false; isStatic = false; } else if ( token == "template" ) { varType = ""; if ( src.CheckTokenString( "<" ) ) { int indent = 1; varType += "< "; while( src.ReadToken( &token ) ) { if ( token == "<" ) { indent++; } else if ( token == ">" ) { indent--; if ( indent == 0 ) { break; } } varType += token + " "; } varType += ">"; } if ( src.CheckTokenString( "class" ) ) { // parse template class classInfo = ParseClassType( scope, varType, true, false, src ); if ( classInfo ) { classes.Append( classInfo ); } } else { // skip template methods while( src.ReadToken( &token ) ) { if ( token == "{" ) { indent++; } else if ( token == "}" ) { indent--; if ( indent == 1 ) { break; } } else if ( token == ";" && indent == 1 ) { break; } } } varType = ""; isConst = false; isStatic = false; } else if ( token == "namespace" ) { // parse namespace classInfo = ParseClassType( scope, "", isTemplate, false, src ); delete classInfo; } else if ( token == "class" ) { // parse class classInfo = ParseClassType( scope, "", isTemplate, false, src ); if ( classInfo ) { classes.Append( classInfo ); } } else if ( token == "struct" ) { // parse struct classInfo = ParseClassType( scope, "", isTemplate, false, src ); if ( classInfo ) { classes.Append( classInfo ); varType = classInfo->scope + classInfo->typeName; } } else if ( token == "union" ) { // parse union classInfo = ParseClassType( scope, "", isTemplate, false, src ); if ( classInfo ) { classes.Append( classInfo ); } } else if ( token == "enum" ) { // parse enum enumInfo = ParseEnumType( scope, isTemplate, false, src ); if ( enumInfo ) { enums.Append( enumInfo ); varType = enumInfo->scope + enumInfo->typeName; } } else if ( token == "typedef" ) { if ( token == "class" ) { // parse typedef class classInfo = ParseClassType( scope, "", isTemplate, true, src ); if ( classInfo ) { classes.Append( classInfo ); } } else if ( src.CheckTokenString( "struct" ) ) { // parse typedef struct classInfo = ParseClassType( scope, "", isTemplate, true, src ); if ( classInfo ) { classes.Append( classInfo ); } } else if ( src.CheckTokenString( "union" ) ) { // parse typedef union classInfo = ParseClassType( scope, "", isTemplate, true, src ); if ( classInfo ) { classes.Append( classInfo ); } } else if ( src.CheckTokenString( "enum" ) ) { // parse typedef enum enumInfo = ParseEnumType( scope, isTemplate, true, src ); if ( enumInfo ) { enums.Append( enumInfo ); } } else { // skip other typedefs while( src.ReadToken( &token ) ) { if ( token == "{" ) { indent++; } else if ( token == "}" ) { indent--; } else if ( token == ";" && indent == 1 ) { break; } } } varType = ""; isConst = false; isStatic = false; } else if ( token == "const" ) { varType += token + " "; isConst = true; } else if ( token == "static" ) { varType += token + " "; isStatic = true; } else if ( token.type == TT_NAME ) { assert( indent == 1 ); // if this is a class operator if ( token == "operator" ) { while( src.ReadToken( &token ) ) { if ( token == "(" ) { src.UnreadToken( &token ); break; } } } // if this is a class method if ( src.CheckTokenString( "(" ) ) { indent++; while( indent > 1 && src.ReadToken( &token ) ) { if ( token == "(" ) { indent++; } else if ( token == ")" ) { indent--; } } if ( src.CheckTokenString( "(" ) ) { indent++; while( indent > 1 && src.ReadToken( &token ) ) { if ( token == "(" ) { indent++; } else if ( token == ")" ) { indent--; } } } if ( src.CheckTokenString( "const" ) ) { } if ( src.CheckTokenString( "=" ) ) { src.ExpectTokenString( "0" ); } else if ( src.CheckTokenString( "{" ) ) { indent++; while( indent > 1 && src.ReadToken( &token ) ) { if ( token == "{" ) { indent++; } else if ( token == "}" ) { indent--; } } } varType = ""; isConst = false; isStatic = false; } else if ( ( isStatic || isConst ) && src.CheckTokenString( "=" ) ) { // constant idConstantInfo *constantInfo = new idConstantInfo; constantInfo->name = scope + token; constantInfo->type = varType; constantInfo->type.StripTrailing( ' ' ); ParseConstantValue( scope, src, constantInfo->value ); constants.Append( constantInfo ); } else if ( isStatic ) { // static class variable varType += token + " "; } else { // check for class variables while( 1 ) { int arraySize = ParseArraySize( scope, src ); if ( arraySize ) { idClassVariableInfo var; var.name = token; var.type = varType; var.type.StripTrailing( ' ' ); var.type += va( "[%d]", arraySize ); var.bits = 0; typeInfo->variables.Append( var ); if ( !src.CheckTokenString( "," ) ) { varType = ""; isConst = false; isStatic = false; break; } varType.StripTrailing( "* " ); } else { int bits = 0; if ( src.CheckTokenString( ":" ) ) { idToken bitSize; src.ExpectTokenType( TT_NUMBER, TT_INTEGER, &bitSize ); bits = bitSize.GetIntValue(); } if ( src.CheckTokenString( "," ) ) { idClassVariableInfo var; var.name = token; var.type = varType; var.type.StripTrailing( ' ' ); var.bits = bits; typeInfo->variables.Append( var ); varType.StripTrailing( "* " ); } else if ( src.CheckTokenString( ";" ) ) { idClassVariableInfo var; var.name = token; var.type = varType; var.type.StripTrailing( ' ' ); var.bits = bits; typeInfo->variables.Append( var ); varType = ""; isConst = false; isStatic = false; break; } else { varType += token + " "; break; } } while( src.CheckTokenString( "*" ) ) { varType += "* "; } if ( !src.ExpectTokenType( TT_NAME, 0, &token ) ) { break; } } } } else { varType += token + " "; } } }
/* ==================== idModelExport::ParseExportSection ==================== */ int idModelExport::ParseExportSection( idParser &parser ) { idToken command; idToken token; idStr defaultCommands; idLexer lex; idStr temp; idStr parms; int count; // only export sections that match our export mask if( g_exportMask.GetString()[ 0 ] ) { if( parser.CheckTokenString( "{" ) ) { parser.SkipBracedSection( false ); return 0; } parser.ReadToken( &token ); if( token.Icmp( g_exportMask.GetString() ) ) { parser.SkipBracedSection(); return 0; } parser.ExpectTokenString( "{" ); } else if( !parser.CheckTokenString( "{" ) ) { // skip the export mask parser.ReadToken( &token ); parser.ExpectTokenString( "{" ); } count = 0; lex.SetFlags( LEXFL_NOSTRINGCONCAT | LEXFL_ALLOWPATHNAMES | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_ALLOWBACKSLASHSTRINGCONCAT ); while( 1 ) { if( !parser.ReadToken( &command ) ) { parser.Error( "Unexpoected end-of-file" ); break; } if( command == "}" ) { break; } if( command == "options" ) { parser.ParseRestOfLine( defaultCommands ); } else if( command == "addoptions" ) { parser.ParseRestOfLine( temp ); defaultCommands += " "; defaultCommands += temp; } else if( ( command == "mesh" ) || ( command == "anim" ) || ( command == "camera" ) ) { if( !parser.ReadToken( &token ) ) { parser.Error( "Expected filename" ); } temp = token; parser.ParseRestOfLine( parms ); if( defaultCommands.Length() ) { sprintf( temp, "%s %s", temp.c_str(), defaultCommands.c_str() ); } if( parms.Length() ) { sprintf( temp, "%s %s", temp.c_str(), parms.c_str() ); } lex.LoadMemory( temp, temp.Length(), parser.GetFileName() ); Reset(); if( ParseOptions( lex ) ) { const char *game = cvarSystem->GetCVarString( "fs_game" ); if( strlen( game ) == 0 ) { game = BASE_GAMEDIR; } if( command == "mesh" ) { dest.SetFileExtension( MD5_MESH_EXT ); } else if( command == "anim" ) { dest.SetFileExtension( MD5_ANIM_EXT ); } else if( command == "camera" ) { dest.SetFileExtension( MD5_CAMERA_EXT ); } else { dest.SetFileExtension( command ); } idStr back = commandLine; sprintf( commandLine, "%s %s -dest %s -game %s%s", command.c_str(), src.c_str(), dest.c_str(), game, commandLine.c_str() ); if( ConvertMayaToMD5() ) { count++; } else { parser.Warning( "Failed to export '%s' : %s", src.c_str(), Maya_Error.c_str() ); } } lex.FreeSource(); } else { parser.Error( "Unknown token: %s", command.c_str() ); parser.SkipBracedSection( false ); break; } } return count; }
/* ================ sdPersistentRankInfo::ParseBadge ================ */ bool sdPersistentRankInfo::ParseBadge( idParser& src ) { if ( !src.ExpectTokenString( "{" ) ) { return false; } sdBadge& badge = badges.Alloc(); badge.category = ""; badge.title = ""; idToken token; while ( true ) { if ( src.ReadToken( &token ) == 0 ) { src.Warning( "Unexpected End of File" ); return false; } if ( token.Icmp( "task" ) == 0 ) { idDict taskInfo; if ( !taskInfo.Parse( src ) ) { return false; } sdBadge::sdTask& task = badge.tasks.Alloc(); task.Clear(); task.total = taskInfo.GetFloat( "total" ); task.text = taskInfo.GetString( "text" ); const idKeyValue* match = NULL; while ( ( match = taskInfo.MatchPrefix( "field", match ) ) != NULL ) { task.fields.Alloc() = match->GetValue(); } } else if ( token.Icmp( "category" ) == 0 ) { if ( src.ReadToken( &token ) == 0 ) { return false; } badge.category = token; } else if ( token.Icmp( "title" ) == 0 ) { if ( src.ReadToken( &token ) == 0 ) { return false; } badge.title = token; } else if ( token.Icmp( "level" ) == 0 ) { if ( src.ReadToken( &token ) == 0 ) { return false; } badge.level = token.GetIntValue(); } else if ( token.Icmp( "alwaysAvailable" ) == 0 ) { badge.alwaysAvailable = true; } else if ( token.Icmp( "}" ) == 0 ) { break; } else { src.Warning( "Unexpected Token: '%s'", token.c_str() ); return false; } } return true; }