/* =============== CG_ParseTrailFile Load the trail systems from a trail file =============== */ static bool CG_ParseTrailFile( const char *fileName ) { const char *text_p; int i; int len; char *token; char text[ 32000 ]; char tsName[ MAX_QPATH ]; bool tsNameSet = false; fileHandle_t f; // load the file len = trap_FS_FOpenFile( fileName, &f, fsMode_t::FS_READ ); if ( len <= 0 ) { return false; } if ( len == 0 || len + 1 >= (int) sizeof( text ) ) { trap_FS_FCloseFile( f ); Log::Warn( len ? "trail file %s is too long" : "trail file %s is empty", fileName ); return false; } trap_FS_Read( text, len, f ); text[ len ] = 0; trap_FS_FCloseFile( f ); // parse the text text_p = text; // read optional parameters while ( 1 ) { token = COM_Parse( &text_p ); if ( !*token ) { break; } if ( !Q_stricmp( token, "{" ) ) { if ( tsNameSet ) { //check for name space clashes for ( i = 0; i < numBaseTrailSystems; i++ ) { if ( !Q_stricmp( baseTrailSystems[ i ].name, tsName ) ) { Log::Warn( "a trail system is already named %s", tsName ); return false; } } Q_strncpyz( baseTrailSystems[ numBaseTrailSystems ].name, tsName, MAX_QPATH ); if ( !CG_ParseTrailSystem( &baseTrailSystems[ numBaseTrailSystems ], &text_p, tsName ) ) { Log::Warn( "%s: failed to parse trail system %s", fileName, tsName ); return false; } //start parsing trail systems again tsNameSet = false; if ( numBaseTrailSystems == MAX_BASETRAIL_SYSTEMS ) { Log::Warn( "maximum number of trail systems (%d) reached", MAX_BASETRAIL_SYSTEMS ); return false; } else { numBaseTrailSystems++; } continue; } else { Log::Warn( "unnamed trail system" ); return false; } } if ( !tsNameSet ) { Q_strncpyz( tsName, token, sizeof( tsName ) ); tsNameSet = true; } else { Log::Warn( "trail system already named" ); return false; } } return true; }
/* =============== CG_ParseTrailFile Load the trail systems from a trail file =============== */ static bool CG_ParseTrailFile( const char *fileName ) { char *text_p; int i; int len; char *token; char text[ 32000 ]; char tsName[ MAX_QPATH ]; bool tsNameSet = false; fileHandle_t f; // load the file len = trap_FS_FOpenFile( fileName, &f, FS_READ ); if( len <= 0 ) return false; if( len >= sizeof( text ) - 1 ) { CG_Printf( S_COLOR_RED "ERROR: trail file %s too long\n", fileName ); return false; } trap_FS_Read( text, len, f ); text[ len ] = 0; trap_FS_FCloseFile( f ); // parse the text text_p = text; // read optional parameters while( 1 ) { token = COM_Parse( &text_p ); if( !Q_stricmp( token, "" ) ) break; if( !Q_stricmp( token, "{" ) ) { if( tsNameSet ) { //check for name space clashes for( i = 0; i < numBaseTrailSystems; i++ ) { if( !Q_stricmp( baseTrailSystems[ i ].name, tsName ) ) { CG_Printf( S_COLOR_RED "ERROR: a trail system is already named %s\n", tsName ); return false; } } Q_strncpyz( baseTrailSystems[ numBaseTrailSystems ].name, tsName, MAX_QPATH ); if( !CG_ParseTrailSystem( &baseTrailSystems[ numBaseTrailSystems ], &text_p, tsName ) ) { CG_Printf( S_COLOR_RED "ERROR: %s: failed to parse trail system %s\n", fileName, tsName ); return false; } //start parsing trail systems again tsNameSet = false; if( numBaseTrailSystems == MAX_BASETRAIL_SYSTEMS ) { CG_Printf( S_COLOR_RED "ERROR: maximum number of trail systems (%d) reached\n", MAX_BASETRAIL_SYSTEMS ); return false; } else numBaseTrailSystems++; continue; } else { CG_Printf( S_COLOR_RED "ERROR: unamed trail system\n" ); return false; } } if( !tsNameSet ) { Q_strncpyz( tsName, token, sizeof( tsName ) ); tsNameSet = true; } else { CG_Printf( S_COLOR_RED "ERROR: trail system already named\n" ); return false; } } return true; }