doom3-bfg/neo/framework/DeclPDA.cpp

724 lines
13 KiB
C++
Raw Normal View History

2012-11-26 18:58:24 +00:00
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
2012-11-26 18:58:24 +00:00
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
2012-11-26 18:58:24 +00:00
Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#include "precompiled.h"
2012-11-26 18:58:24 +00:00
#pragma hdrstop
idCVar g_useOldPDAStrings( "g_useOldPDAStrings", "0", CVAR_BOOL, "Read strings from the .pda files rather than from the .lang file" );
/*
=================
idDeclPDA::Size
=================
*/
size_t idDeclPDA::Size() const
{
2012-11-26 18:58:24 +00:00
return sizeof( idDeclPDA );
}
/*
===============
idDeclPDA::Print
===============
*/
void idDeclPDA::Print() const
{
2012-11-26 18:58:24 +00:00
common->Printf( "Implement me\n" );
}
/*
===============
idDeclPDA::List
===============
*/
void idDeclPDA::List() const
{
2012-11-26 18:58:24 +00:00
common->Printf( "Implement me\n" );
}
/*
================
idDeclPDA::Parse
================
*/
bool idDeclPDA::Parse( const char* text, const int textLength, bool allowBinaryVersion )
{
2012-11-26 18:58:24 +00:00
idLexer src;
idToken token;
2012-11-26 18:58:24 +00:00
idStr baseStrId = va( "#str_%s_pda_", GetName() );
2012-11-26 18:58:24 +00:00
src.LoadMemory( text, textLength, GetFileName(), GetLineNum() );
src.SetFlags( DECL_LEXER_FLAGS );
src.SkipUntilString( "{" );
2012-11-26 18:58:24 +00:00
// scan through, identifying each individual parameter
while( 1 )
{
if( !src.ReadToken( &token ) )
{
2012-11-26 18:58:24 +00:00
break;
}
if( token == "}" )
{
2012-11-26 18:58:24 +00:00
break;
}
if( !token.Icmp( "name" ) )
{
2012-11-26 18:58:24 +00:00
src.ReadToken( &token );
if( g_useOldPDAStrings.GetBool() )
{
2012-11-26 18:58:24 +00:00
pdaName = token;
}
else
{
2012-11-26 18:58:24 +00:00
pdaName = idLocalization::GetString( baseStrId + "name" );
}
continue;
}
if( !token.Icmp( "fullname" ) )
{
2012-11-26 18:58:24 +00:00
src.ReadToken( &token );
if( g_useOldPDAStrings.GetBool() )
{
2012-11-26 18:58:24 +00:00
fullName = token;
}
else
{
2012-11-26 18:58:24 +00:00
fullName = idLocalization::GetString( baseStrId + "fullname" );
}
continue;
}
if( !token.Icmp( "icon" ) )
{
2012-11-26 18:58:24 +00:00
src.ReadToken( &token );
icon = token;
continue;
}
if( !token.Icmp( "id" ) )
{
2012-11-26 18:58:24 +00:00
src.ReadToken( &token );
if( g_useOldPDAStrings.GetBool() )
{
2012-11-26 18:58:24 +00:00
id = token;
}
else
{
2012-11-26 18:58:24 +00:00
id = idLocalization::GetString( baseStrId + "id" );
}
continue;
}
if( !token.Icmp( "post" ) )
{
2012-11-26 18:58:24 +00:00
src.ReadToken( &token );
if( g_useOldPDAStrings.GetBool() )
{
2012-11-26 18:58:24 +00:00
post = token;
}
else
{
2012-11-26 18:58:24 +00:00
post = idLocalization::GetString( baseStrId + "post" );
}
continue;
}
if( !token.Icmp( "title" ) )
{
2012-11-26 18:58:24 +00:00
src.ReadToken( &token );
if( g_useOldPDAStrings.GetBool() )
{
2012-11-26 18:58:24 +00:00
title = token;
}
else
{
2012-11-26 18:58:24 +00:00
title = idLocalization::GetString( baseStrId + "title" );
}
continue;
}
if( !token.Icmp( "security" ) )
{
2012-11-26 18:58:24 +00:00
src.ReadToken( &token );
if( g_useOldPDAStrings.GetBool() )
{
2012-11-26 18:58:24 +00:00
security = token;
}
else
{
2012-11-26 18:58:24 +00:00
security = idLocalization::GetString( baseStrId + "security" );
}
continue;
}
if( !token.Icmp( "pda_email" ) )
{
2012-11-26 18:58:24 +00:00
src.ReadToken( &token );
emails.Append( static_cast<const idDeclEmail*>( declManager->FindType( DECL_EMAIL, token ) ) );
2012-11-26 18:58:24 +00:00
continue;
}
if( !token.Icmp( "pda_audio" ) )
{
2012-11-26 18:58:24 +00:00
src.ReadToken( &token );
audios.Append( static_cast<const idDeclAudio*>( declManager->FindType( DECL_AUDIO, token ) ) );
2012-11-26 18:58:24 +00:00
continue;
}
if( !token.Icmp( "pda_video" ) )
{
2012-11-26 18:58:24 +00:00
src.ReadToken( &token );
videos.Append( static_cast<const idDeclVideo*>( declManager->FindType( DECL_VIDEO, token ) ) );
2012-11-26 18:58:24 +00:00
continue;
}
2012-11-26 18:58:24 +00:00
}
if( src.HadError() )
{
2012-11-26 18:58:24 +00:00
src.Warning( "PDA decl '%s' had a parse error", GetName() );
return false;
}
2012-11-26 18:58:24 +00:00
originalVideos = videos.Num();
originalEmails = emails.Num();
return true;
}
/*
===================
idDeclPDA::DefaultDefinition
===================
*/
const char* idDeclPDA::DefaultDefinition() const
{
2012-11-26 18:58:24 +00:00
return
"{\n"
"\t" "name \"default pda\"\n"
"}";
2012-11-26 18:58:24 +00:00
}
/*
===================
idDeclPDA::FreeData
===================
*/
void idDeclPDA::FreeData()
{
2012-11-26 18:58:24 +00:00
videos.Clear();
audios.Clear();
emails.Clear();
originalEmails = 0;
originalVideos = 0;
}
/*
=================
idDeclPDA::RemoveAddedEmailsAndVideos
=================
*/
void idDeclPDA::RemoveAddedEmailsAndVideos() const
{
2012-11-26 18:58:24 +00:00
int num = emails.Num();
if( originalEmails < num )
{
while( num && num > originalEmails )
{
2012-11-26 18:58:24 +00:00
emails.RemoveIndex( --num );
}
}
num = videos.Num();
if( originalVideos < num )
{
while( num && num > originalVideos )
{
2012-11-26 18:58:24 +00:00
videos.RemoveIndex( --num );
}
}
}
/*
=================
idDeclPDA::SetSecurity
=================
*/
void idDeclPDA::SetSecurity( const char* sec ) const
{
2012-11-26 18:58:24 +00:00
security = sec;
}
/*
=================
idDeclEmail::Size
=================
*/
size_t idDeclEmail::Size() const
{
2012-11-26 18:58:24 +00:00
return sizeof( idDeclEmail );
}
/*
===============
idDeclEmail::Print
===============
*/
void idDeclEmail::Print() const
{
2012-11-26 18:58:24 +00:00
common->Printf( "Implement me\n" );
}
/*
===============
idDeclEmail::List
===============
*/
void idDeclEmail::List() const
{
2012-11-26 18:58:24 +00:00
common->Printf( "Implement me\n" );
}
/*
================
idDeclEmail::Parse
================
*/
bool idDeclEmail::Parse( const char* _text, const int textLength, bool allowBinaryVersion )
{
2012-11-26 18:58:24 +00:00
idLexer src;
idToken token;
2012-11-26 18:58:24 +00:00
idStr baseStrId = va( "#str_%s_email_", GetName() );
2012-11-26 18:58:24 +00:00
src.LoadMemory( _text, textLength, GetFileName(), GetLineNum() );
src.SetFlags( LEXFL_NOSTRINGCONCAT | LEXFL_ALLOWPATHNAMES | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_ALLOWBACKSLASHSTRINGCONCAT | LEXFL_NOFATALERRORS );
src.SkipUntilString( "{" );
2012-11-26 18:58:24 +00:00
text = "";
// scan through, identifying each individual parameter
while( 1 )
{
if( !src.ReadToken( &token ) )
{
2012-11-26 18:58:24 +00:00
break;
}
if( token == "}" )
{
2012-11-26 18:58:24 +00:00
break;
}
if( !token.Icmp( "subject" ) )
{
2012-11-26 18:58:24 +00:00
src.ReadToken( &token );
if( g_useOldPDAStrings.GetBool() )
{
2012-11-26 18:58:24 +00:00
subject = token;
}
else
{
2012-11-26 18:58:24 +00:00
subject = idLocalization::GetString( baseStrId + "subject" );
}
continue;
}
if( !token.Icmp( "to" ) )
{
2012-11-26 18:58:24 +00:00
src.ReadToken( &token );
if( g_useOldPDAStrings.GetBool() )
{
2012-11-26 18:58:24 +00:00
to = token;
}
else
{
2012-11-26 18:58:24 +00:00
to = idLocalization::GetString( baseStrId + "to" );
}
continue;
}
if( !token.Icmp( "from" ) )
{
2012-11-26 18:58:24 +00:00
src.ReadToken( &token );
if( g_useOldPDAStrings.GetBool() )
{
2012-11-26 18:58:24 +00:00
from = token;
}
else
{
2012-11-26 18:58:24 +00:00
from = idLocalization::GetString( baseStrId + "from" );
}
continue;
}
if( !token.Icmp( "date" ) )
{
2012-11-26 18:58:24 +00:00
src.ReadToken( &token );
if( g_useOldPDAStrings.GetBool() )
{
2012-11-26 18:58:24 +00:00
date = token;
}
else
{
2012-11-26 18:58:24 +00:00
date = idLocalization::GetString( baseStrId + "date" );
}
continue;
}
if( !token.Icmp( "text" ) )
{
2012-11-26 18:58:24 +00:00
src.ReadToken( &token );
if( token != "{" )
{
2012-11-26 18:58:24 +00:00
src.Warning( "Email decl '%s' had a parse error", GetName() );
return false;
}
while( src.ReadToken( &token ) && token != "}" )
{
2012-11-26 18:58:24 +00:00
text += token;
}
if( !g_useOldPDAStrings.GetBool() )
{
2012-11-26 18:58:24 +00:00
text = idLocalization::GetString( baseStrId + "text" );
}
continue;
}
}
if( src.HadError() )
{
2012-11-26 18:58:24 +00:00
src.Warning( "Email decl '%s' had a parse error", GetName() );
return false;
}
return true;
}
/*
===================
idDeclEmail::DefaultDefinition
===================
*/
const char* idDeclEmail::DefaultDefinition() const
{
2012-11-26 18:58:24 +00:00
return
"{\n"
"\t" "{\n"
"\t\t" "to\t5Mail recipient\n"
"\t\t" "subject\t5Nothing\n"
"\t\t" "from\t5No one\n"
"\t" "}\n"
"}";
2012-11-26 18:58:24 +00:00
}
/*
===================
idDeclEmail::FreeData
===================
*/
void idDeclEmail::FreeData()
{
2012-11-26 18:58:24 +00:00
}
/*
=================
idDeclVideo::Size
=================
*/
size_t idDeclVideo::Size() const
{
2012-11-26 18:58:24 +00:00
return sizeof( idDeclVideo );
}
/*
===============
idDeclVideo::Print
===============
*/
void idDeclVideo::Print() const
{
2012-11-26 18:58:24 +00:00
common->Printf( "Implement me\n" );
}
/*
===============
idDeclVideo::List
===============
*/
void idDeclVideo::List() const
{
2012-11-26 18:58:24 +00:00
common->Printf( "Implement me\n" );
}
/*
================
idDeclVideo::Parse
================
*/
bool idDeclVideo::Parse( const char* text, const int textLength, bool allowBinaryVersion )
{
2012-11-26 18:58:24 +00:00
idLexer src;
idToken token;
2012-11-26 18:58:24 +00:00
idStr baseStrId = va( "#str_%s_video_", GetName() );
2012-11-26 18:58:24 +00:00
src.LoadMemory( text, textLength, GetFileName(), GetLineNum() );
src.SetFlags( LEXFL_NOSTRINGCONCAT | LEXFL_ALLOWPATHNAMES | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_ALLOWBACKSLASHSTRINGCONCAT | LEXFL_NOFATALERRORS );
src.SkipUntilString( "{" );
2012-11-26 18:58:24 +00:00
// scan through, identifying each individual parameter
while( 1 )
{
if( !src.ReadToken( &token ) )
{
2012-11-26 18:58:24 +00:00
break;
}
if( token == "}" )
{
2012-11-26 18:58:24 +00:00
break;
}
if( !token.Icmp( "name" ) )
{
2012-11-26 18:58:24 +00:00
src.ReadToken( &token );
if( g_useOldPDAStrings.GetBool() )
{
2012-11-26 18:58:24 +00:00
videoName = token;
}
else
{
2012-11-26 18:58:24 +00:00
videoName = idLocalization::GetString( baseStrId + "name" );
}
continue;
}
if( !token.Icmp( "preview" ) )
{
2012-11-26 18:58:24 +00:00
src.ReadToken( &token );
preview = declManager->FindMaterial( token );
continue;
}
if( !token.Icmp( "video" ) )
{
2012-11-26 18:58:24 +00:00
src.ReadToken( &token );
video = declManager->FindMaterial( token );
continue;
}
if( !token.Icmp( "info" ) )
{
2012-11-26 18:58:24 +00:00
src.ReadToken( &token );
if( g_useOldPDAStrings.GetBool() )
{
2012-11-26 18:58:24 +00:00
info = token;
}
else
{
2012-11-26 18:58:24 +00:00
info = idLocalization::GetString( baseStrId + "info" );
}
continue;
}
if( !token.Icmp( "audio" ) )
{
2012-11-26 18:58:24 +00:00
src.ReadToken( &token );
audio = declManager->FindSound( token );
continue;
}
2012-11-26 18:58:24 +00:00
}
if( src.HadError() )
{
2012-11-26 18:58:24 +00:00
src.Warning( "Video decl '%s' had a parse error", GetName() );
return false;
}
return true;
}
/*
===================
idDeclVideo::DefaultDefinition
===================
*/
const char* idDeclVideo::DefaultDefinition() const
{
2012-11-26 18:58:24 +00:00
return
"{\n"
"\t" "{\n"
"\t\t" "name\t5Default Video\n"
"\t" "}\n"
"}";
2012-11-26 18:58:24 +00:00
}
/*
===================
idDeclVideo::FreeData
===================
*/
void idDeclVideo::FreeData()
{
2012-11-26 18:58:24 +00:00
}
/*
=================
idDeclAudio::Size
=================
*/
size_t idDeclAudio::Size() const
{
2012-11-26 18:58:24 +00:00
return sizeof( idDeclAudio );
}
/*
===============
idDeclAudio::Print
===============
*/
void idDeclAudio::Print() const
{
2012-11-26 18:58:24 +00:00
common->Printf( "Implement me\n" );
}
/*
===============
idDeclAudio::List
===============
*/
void idDeclAudio::List() const
{
2012-11-26 18:58:24 +00:00
common->Printf( "Implement me\n" );
}
/*
================
idDeclAudio::Parse
================
*/
bool idDeclAudio::Parse( const char* text, const int textLength, bool allowBinaryVersion )
{
2012-11-26 18:58:24 +00:00
idLexer src;
idToken token;
2012-11-26 18:58:24 +00:00
idStr baseStrId = va( "#str_%s_audio_", GetName() );
2012-11-26 18:58:24 +00:00
src.LoadMemory( text, textLength, GetFileName(), GetLineNum() );
src.SetFlags( LEXFL_NOSTRINGCONCAT | LEXFL_ALLOWPATHNAMES | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_ALLOWBACKSLASHSTRINGCONCAT | LEXFL_NOFATALERRORS );
src.SkipUntilString( "{" );
2012-11-26 18:58:24 +00:00
// scan through, identifying each individual parameter
while( 1 )
{
if( !src.ReadToken( &token ) )
{
2012-11-26 18:58:24 +00:00
break;
}
if( token == "}" )
{
2012-11-26 18:58:24 +00:00
break;
}
if( !token.Icmp( "name" ) )
{
2012-11-26 18:58:24 +00:00
src.ReadToken( &token );
if( g_useOldPDAStrings.GetBool() )
{
2012-11-26 18:58:24 +00:00
audioName = token;
}
else
{
2012-11-26 18:58:24 +00:00
audioName = idLocalization::GetString( baseStrId + "name" );
}
continue;
}
if( !token.Icmp( "audio" ) )
{
2012-11-26 18:58:24 +00:00
src.ReadToken( &token );
audio = declManager->FindSound( token );
continue;
}
if( !token.Icmp( "info" ) )
{
2012-11-26 18:58:24 +00:00
src.ReadToken( &token );
if( g_useOldPDAStrings.GetBool() )
{
2012-11-26 18:58:24 +00:00
info = token;
}
else
{
2012-11-26 18:58:24 +00:00
info = idLocalization::GetString( baseStrId + "info" );
}
continue;
}
}
if( src.HadError() )
{
2012-11-26 18:58:24 +00:00
src.Warning( "Audio decl '%s' had a parse error", GetName() );
return false;
}
return true;
}
/*
===================
idDeclAudio::DefaultDefinition
===================
*/
const char* idDeclAudio::DefaultDefinition() const
{
2012-11-26 18:58:24 +00:00
return
"{\n"
"\t" "{\n"
"\t\t" "name\t5Default Audio\n"
"\t" "}\n"
"}";
2012-11-26 18:58:24 +00:00
}
/*
===================
idDeclAudio::FreeData
===================
*/
void idDeclAudio::FreeData()
{
2012-11-26 18:58:24 +00:00
}