// these two functions aren't needed other than to make Quake-type games happy and/or stop memory managers
//	complaining about leaks if they report them before the global StringEd package object calls it's own dtor.
//
// but here they are for completeness's sake I guess...
//
void SE_Init(void)
{
	TheStringPackage.Clear( SE_FALSE );

#ifdef _DEBUG
//	int iNumLanguages = SE_GetNumLanguages();
#endif

	se_language = Cvar_Get("se_language", "english", CVAR_ARCHIVE | CVAR_NORESTART);
	se_debug = Cvar_Get("se_debug", "0", 0);
	sp_leet = Cvar_Get("sp_leet", "0", CVAR_ROM );

	// if doing a buildscript, load all languages...
	//
	extern cvar_t *com_buildScript;
	if (com_buildScript->integer == 2)
	{
		int iLanguages = SE_GetNumLanguages();
		for (int iLang = 0; iLang < iLanguages; iLang++)
		{
            LPCSTR psLanguage = SE_GetLanguageName( iLang );	// eg "german"			
			Com_Printf( "com_buildScript(2): Loading language \"%s\"...\n", psLanguage );
			SE_LoadLanguage( psLanguage );
		}
	}

	LPCSTR psErrorMessage = SE_LoadLanguage( se_language->string );
	if (psErrorMessage)
	{
		Com_Error( ERR_DROP, "SE_Init() Unable to load language: \"%s\"!\nError: \"%s\"\n", se_language->string,psErrorMessage );
	}

}
// filename is local here, eg:	"strings/german/obj.str"
//
// return is either NULL for good else error message to display...
//
static LPCSTR SE_Load_Actual( LPCSTR psFileName, SE_BOOL bLoadDebug, SE_BOOL bSpeculativeLoad )
{
	LPCSTR psErrorMessage = NULL;
	
	unsigned char *psLoadedData = SE_LoadFileData( psFileName );
	if ( psLoadedData )
	{
		// now parse the data...
		//
		char *psParsePos = (char *) psLoadedData;

		TheStringPackage.SetupNewFileParse( psFileName, bLoadDebug );

		char sLineBuffer[16384];	// should be enough for one line of text (some of them can be BIG though)
		while ( !psErrorMessage && TheStringPackage.ReadLine((LPCSTR &) psParsePos, sLineBuffer ) )
		{
			if (strlen(sLineBuffer))
			{
//				__DEBUGOUT( sLineBuffer );
//				__DEBUGOUT( "\n" );

				psErrorMessage = TheStringPackage.ParseLine( sLineBuffer );
			}
		}

		SE_FreeFileDataAfterLoad( psLoadedData);
		
		if (!psErrorMessage && !TheStringPackage.EndMarkerFoundDuringParse())
		{
			psErrorMessage = va("Truncated file, failed to find \"%s\" at file end!", sSE_KEYWORD_ENDMARKER);
		}
	}
	else
	{
		if ( bSpeculativeLoad )
		{
			// then it's ok to not find the file, so do nothing...
		}
		else
		{
			psErrorMessage = va("Unable to load \"%s\"!", psFileName);
		}
	}

	return psErrorMessage;
}
int SE_GetNumLanguages(void)
{
	if ( gvLanguagesAvailable.empty() )
	{
		string strResults;
		/*int iFilesFound = */SE_BuildFileList( 
												#ifdef _STRINGED
													va("C:\\Source\\Tools\\StringEd\\test_data\\%s",sSE_STRINGS_DIR)
												#else
													sSE_STRINGS_DIR
												#endif
												, strResults 
											);

		set<string> strUniqueStrings;	// laziness <g>
		LPCSTR p;
		while ((p=SE_GetFoundFile (strResults)) != NULL)
		{
			LPCSTR psLanguage = TheStringPackage.ExtractLanguageFromPath( p );

	//		__DEBUGOUT( p );
	//		__DEBUGOUT( "\n" );
	//		__DEBUGOUT( psLanguage );
	//		__DEBUGOUT( "\n" );

			if (!strUniqueStrings.count( psLanguage ))
			{
				strUniqueStrings.insert( psLanguage );

				// if english is available, it should always be first... ( I suppose )
				//
				if (!stricmp(psLanguage,"english"))
				{
					gvLanguagesAvailable.insert( gvLanguagesAvailable.begin(), psLanguage );
				}
				else
				{
					gvLanguagesAvailable.push_back( psLanguage );
				}
			}
		}
	}

	return gvLanguagesAvailable.size();
}
// returns error message else NULL for ok.
//
// Any errors that result from this should probably be treated as game-fatal, since an asset file is fuxored.
//
LPCSTR SE_LoadLanguage( LPCSTR psLanguage, SE_BOOL bLoadDebug /* = SE_TRUE */ )
{
	LPCSTR psErrorMessage = NULL;

	if (psLanguage && psLanguage[0])
	{
		SE_NewLanguage();

		string strResults;
		/*int iFilesFound = */SE_BuildFileList( 
												#ifdef _STRINGED
													va("C:\\Source\\Tools\\StringEd\\test_data\\%s",sSE_STRINGS_DIR)
												#else
													sSE_STRINGS_DIR
												#endif
												, strResults 
											);

		LPCSTR p;
		while ( (p=SE_GetFoundFile (strResults)) != NULL && !psErrorMessage )
		{
			LPCSTR psThisLang = TheStringPackage.ExtractLanguageFromPath( p );

			if ( !stricmp( psLanguage, psThisLang ) )
			{
				psErrorMessage = SE_Load( p, bLoadDebug );
			}
		}
	}
	else
	{
		__ASSERT( 0 && "SE_LoadLanguage(): Bad language name!" );
	}

	return psErrorMessage;
}
void SE_ShutDown(void)
{
	TheStringPackage.Clear( SE_FALSE );
}
void SE_NewLanguage(void)
{
	TheStringPackage.Clear( SE_TRUE );
}
// returns flag bitmask (eg 00000010b), else 0 for not found
//
int SE_GetFlagMask( LPCSTR psFlagName )
{
	return TheStringPackage.GetFlagMask( psFlagName );
}
Beispiel #8
0
// returns flag bitmask (eg 00000010b), else 0 for not found
//
int SE_GetFlagMask( const char *psFlagName )
{
	return TheStringPackage.GetFlagMask( psFlagName );
}