DeclPDA.cpp (12898B)
1 /* 2 =========================================================================== 3 4 Doom 3 BFG Edition GPL Source Code 5 Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company. 6 7 This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code"). 8 9 Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify 10 it under the terms of the GNU General Public License as published by 11 the Free Software Foundation, either version 3 of the License, or 12 (at your option) any later version. 13 14 Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful, 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 GNU General Public License for more details. 18 19 You should have received a copy of the GNU General Public License 20 along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>. 21 22 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. 23 24 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. 25 26 =========================================================================== 27 */ 28 29 #include "../idlib/precompiled.h" 30 #pragma hdrstop 31 32 idCVar g_useOldPDAStrings( "g_useOldPDAStrings", "0", CVAR_BOOL, "Read strings from the .pda files rather than from the .lang file" ); 33 34 /* 35 ================= 36 idDeclPDA::Size 37 ================= 38 */ 39 size_t idDeclPDA::Size() const { 40 return sizeof( idDeclPDA ); 41 } 42 43 /* 44 =============== 45 idDeclPDA::Print 46 =============== 47 */ 48 void idDeclPDA::Print() const { 49 common->Printf( "Implement me\n" ); 50 } 51 52 /* 53 =============== 54 idDeclPDA::List 55 =============== 56 */ 57 void idDeclPDA::List() const { 58 common->Printf( "Implement me\n" ); 59 } 60 61 /* 62 ================ 63 idDeclPDA::Parse 64 ================ 65 */ 66 bool idDeclPDA::Parse( const char *text, const int textLength, bool allowBinaryVersion ) { 67 idLexer src; 68 idToken token; 69 70 idStr baseStrId = va( "#str_%s_pda_", GetName() ); 71 72 src.LoadMemory( text, textLength, GetFileName(), GetLineNum() ); 73 src.SetFlags( DECL_LEXER_FLAGS ); 74 src.SkipUntilString( "{" ); 75 76 // scan through, identifying each individual parameter 77 while( 1 ) { 78 79 if ( !src.ReadToken( &token ) ) { 80 break; 81 } 82 83 if ( token == "}" ) { 84 break; 85 } 86 87 if ( !token.Icmp( "name") ) { 88 src.ReadToken( &token ); 89 90 if ( g_useOldPDAStrings.GetBool() ) { 91 pdaName = token; 92 } else { 93 pdaName = idLocalization::GetString( baseStrId + "name" ); 94 } 95 continue; 96 } 97 98 if ( !token.Icmp( "fullname") ) { 99 src.ReadToken( &token ); 100 101 if ( g_useOldPDAStrings.GetBool() ) { 102 fullName = token; 103 } else { 104 fullName = idLocalization::GetString( baseStrId + "fullname" ); 105 } 106 continue; 107 } 108 109 if ( !token.Icmp( "icon") ) { 110 src.ReadToken( &token ); 111 icon = token; 112 continue; 113 } 114 115 if ( !token.Icmp( "id") ) { 116 src.ReadToken( &token ); 117 if ( g_useOldPDAStrings.GetBool() ) { 118 id = token; 119 } else { 120 id = idLocalization::GetString( baseStrId + "id" ); 121 } 122 continue; 123 } 124 125 if ( !token.Icmp( "post") ) { 126 src.ReadToken( &token ); 127 if ( g_useOldPDAStrings.GetBool() ) { 128 post = token; 129 } else { 130 post = idLocalization::GetString( baseStrId + "post" ); 131 } 132 continue; 133 } 134 135 if ( !token.Icmp( "title") ) { 136 src.ReadToken( &token ); 137 if ( g_useOldPDAStrings.GetBool() ) { 138 title = token; 139 } else { 140 title = idLocalization::GetString( baseStrId + "title" ); 141 } 142 continue; 143 } 144 145 if ( !token.Icmp( "security") ) { 146 src.ReadToken( &token ); 147 if ( g_useOldPDAStrings.GetBool() ) { 148 security = token; 149 } else { 150 security = idLocalization::GetString( baseStrId + "security" ); 151 } 152 continue; 153 } 154 155 if ( !token.Icmp( "pda_email") ) { 156 src.ReadToken( &token ); 157 emails.Append( static_cast<const idDeclEmail *>( declManager->FindType( DECL_EMAIL, token ) ) ); 158 continue; 159 } 160 161 if ( !token.Icmp( "pda_audio") ) { 162 src.ReadToken( &token ); 163 audios.Append( static_cast<const idDeclAudio *>( declManager->FindType( DECL_AUDIO, token ) ) ); 164 continue; 165 } 166 167 if ( !token.Icmp( "pda_video") ) { 168 src.ReadToken( &token ); 169 videos.Append( static_cast<const idDeclVideo *>( declManager->FindType( DECL_VIDEO, token ) ) ); 170 continue; 171 } 172 173 } 174 175 if ( src.HadError() ) { 176 src.Warning( "PDA decl '%s' had a parse error", GetName() ); 177 return false; 178 } 179 180 originalVideos = videos.Num(); 181 originalEmails = emails.Num(); 182 return true; 183 } 184 185 /* 186 =================== 187 idDeclPDA::DefaultDefinition 188 =================== 189 */ 190 const char *idDeclPDA::DefaultDefinition() const { 191 return 192 "{\n" 193 "\t" "name \"default pda\"\n" 194 "}"; 195 } 196 197 /* 198 =================== 199 idDeclPDA::FreeData 200 =================== 201 */ 202 void idDeclPDA::FreeData() { 203 videos.Clear(); 204 audios.Clear(); 205 emails.Clear(); 206 originalEmails = 0; 207 originalVideos = 0; 208 } 209 210 /* 211 ================= 212 idDeclPDA::RemoveAddedEmailsAndVideos 213 ================= 214 */ 215 void idDeclPDA::RemoveAddedEmailsAndVideos() const { 216 int num = emails.Num(); 217 if ( originalEmails < num ) { 218 while ( num && num > originalEmails ) { 219 emails.RemoveIndex( --num ); 220 } 221 } 222 num = videos.Num(); 223 if ( originalVideos < num ) { 224 while ( num && num > originalVideos ) { 225 videos.RemoveIndex( --num ); 226 } 227 } 228 } 229 230 /* 231 ================= 232 idDeclPDA::SetSecurity 233 ================= 234 */ 235 void idDeclPDA::SetSecurity( const char *sec ) const { 236 security = sec; 237 } 238 239 /* 240 ================= 241 idDeclEmail::Size 242 ================= 243 */ 244 size_t idDeclEmail::Size() const { 245 return sizeof( idDeclEmail ); 246 } 247 248 /* 249 =============== 250 idDeclEmail::Print 251 =============== 252 */ 253 void idDeclEmail::Print() const { 254 common->Printf( "Implement me\n" ); 255 } 256 257 /* 258 =============== 259 idDeclEmail::List 260 =============== 261 */ 262 void idDeclEmail::List() const { 263 common->Printf( "Implement me\n" ); 264 } 265 266 /* 267 ================ 268 idDeclEmail::Parse 269 ================ 270 */ 271 bool idDeclEmail::Parse( const char *_text, const int textLength, bool allowBinaryVersion ) { 272 idLexer src; 273 idToken token; 274 275 idStr baseStrId = va( "#str_%s_email_", GetName() ); 276 277 src.LoadMemory( _text, textLength, GetFileName(), GetLineNum() ); 278 src.SetFlags( LEXFL_NOSTRINGCONCAT | LEXFL_ALLOWPATHNAMES | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_ALLOWBACKSLASHSTRINGCONCAT | LEXFL_NOFATALERRORS ); 279 src.SkipUntilString( "{" ); 280 281 text = ""; 282 // scan through, identifying each individual parameter 283 while( 1 ) { 284 285 if ( !src.ReadToken( &token ) ) { 286 break; 287 } 288 289 if ( token == "}" ) { 290 break; 291 } 292 293 if ( !token.Icmp( "subject") ) { 294 src.ReadToken( &token ); 295 if ( g_useOldPDAStrings.GetBool() ) { 296 subject = token; 297 } else { 298 subject = idLocalization::GetString( baseStrId + "subject" ); 299 } 300 continue; 301 } 302 303 if ( !token.Icmp( "to") ) { 304 src.ReadToken( &token ); 305 if ( g_useOldPDAStrings.GetBool() ) { 306 to = token; 307 } else { 308 to = idLocalization::GetString( baseStrId + "to" ); 309 } 310 continue; 311 } 312 313 if ( !token.Icmp( "from") ) { 314 src.ReadToken( &token ); 315 if ( g_useOldPDAStrings.GetBool() ) { 316 from = token; 317 } else { 318 from = idLocalization::GetString( baseStrId + "from" ); 319 } 320 continue; 321 } 322 323 if ( !token.Icmp( "date") ) { 324 src.ReadToken( &token ); 325 if ( g_useOldPDAStrings.GetBool() ) { 326 date = token; 327 } else { 328 date = idLocalization::GetString( baseStrId + "date" ); 329 } 330 continue; 331 } 332 333 if ( !token.Icmp( "text") ) { 334 src.ReadToken( &token ); 335 if ( token != "{" ) { 336 src.Warning( "Email decl '%s' had a parse error", GetName() ); 337 return false; 338 } 339 while ( src.ReadToken( &token ) && token != "}" ) { 340 text += token; 341 } 342 if ( !g_useOldPDAStrings.GetBool() ) { 343 text = idLocalization::GetString( baseStrId + "text" ); 344 } 345 continue; 346 } 347 } 348 349 if ( src.HadError() ) { 350 src.Warning( "Email decl '%s' had a parse error", GetName() ); 351 return false; 352 } 353 return true; 354 } 355 356 /* 357 =================== 358 idDeclEmail::DefaultDefinition 359 =================== 360 */ 361 const char *idDeclEmail::DefaultDefinition() const { 362 return 363 "{\n" 364 "\t" "{\n" 365 "\t\t" "to\t5Mail recipient\n" 366 "\t\t" "subject\t5Nothing\n" 367 "\t\t" "from\t5No one\n" 368 "\t" "}\n" 369 "}"; 370 } 371 372 /* 373 =================== 374 idDeclEmail::FreeData 375 =================== 376 */ 377 void idDeclEmail::FreeData() { 378 } 379 380 /* 381 ================= 382 idDeclVideo::Size 383 ================= 384 */ 385 size_t idDeclVideo::Size() const { 386 return sizeof( idDeclVideo ); 387 } 388 389 /* 390 =============== 391 idDeclVideo::Print 392 =============== 393 */ 394 void idDeclVideo::Print() const { 395 common->Printf( "Implement me\n" ); 396 } 397 398 /* 399 =============== 400 idDeclVideo::List 401 =============== 402 */ 403 void idDeclVideo::List() const { 404 common->Printf( "Implement me\n" ); 405 } 406 407 /* 408 ================ 409 idDeclVideo::Parse 410 ================ 411 */ 412 bool idDeclVideo::Parse( const char *text, const int textLength, bool allowBinaryVersion ) { 413 idLexer src; 414 idToken token; 415 416 idStr baseStrId = va( "#str_%s_video_", GetName() ); 417 418 src.LoadMemory( text, textLength, GetFileName(), GetLineNum() ); 419 src.SetFlags( LEXFL_NOSTRINGCONCAT | LEXFL_ALLOWPATHNAMES | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_ALLOWBACKSLASHSTRINGCONCAT | LEXFL_NOFATALERRORS ); 420 src.SkipUntilString( "{" ); 421 422 // scan through, identifying each individual parameter 423 while( 1 ) { 424 425 if ( !src.ReadToken( &token ) ) { 426 break; 427 } 428 429 if ( token == "}" ) { 430 break; 431 } 432 433 if ( !token.Icmp( "name") ) { 434 src.ReadToken( &token ); 435 if ( g_useOldPDAStrings.GetBool() ) { 436 videoName = token; 437 } else { 438 videoName = idLocalization::GetString( baseStrId + "name" ); 439 } 440 continue; 441 } 442 443 if ( !token.Icmp( "preview") ) { 444 src.ReadToken( &token ); 445 preview = declManager->FindMaterial( token ); 446 continue; 447 } 448 449 if ( !token.Icmp( "video") ) { 450 src.ReadToken( &token ); 451 video = declManager->FindMaterial( token ); 452 continue; 453 } 454 455 if ( !token.Icmp( "info") ) { 456 src.ReadToken( &token ); 457 if ( g_useOldPDAStrings.GetBool() ) { 458 info = token; 459 } else { 460 info = idLocalization::GetString( baseStrId + "info" ); 461 } 462 continue; 463 } 464 465 if ( !token.Icmp( "audio") ) { 466 src.ReadToken( &token ); 467 audio = declManager->FindSound( token ); 468 continue; 469 } 470 471 } 472 473 if ( src.HadError() ) { 474 src.Warning( "Video decl '%s' had a parse error", GetName() ); 475 return false; 476 } 477 return true; 478 } 479 480 /* 481 =================== 482 idDeclVideo::DefaultDefinition 483 =================== 484 */ 485 const char *idDeclVideo::DefaultDefinition() const { 486 return 487 "{\n" 488 "\t" "{\n" 489 "\t\t" "name\t5Default Video\n" 490 "\t" "}\n" 491 "}"; 492 } 493 494 /* 495 =================== 496 idDeclVideo::FreeData 497 =================== 498 */ 499 void idDeclVideo::FreeData() { 500 } 501 502 /* 503 ================= 504 idDeclAudio::Size 505 ================= 506 */ 507 size_t idDeclAudio::Size() const { 508 return sizeof( idDeclAudio ); 509 } 510 511 /* 512 =============== 513 idDeclAudio::Print 514 =============== 515 */ 516 void idDeclAudio::Print() const { 517 common->Printf( "Implement me\n" ); 518 } 519 520 /* 521 =============== 522 idDeclAudio::List 523 =============== 524 */ 525 void idDeclAudio::List() const { 526 common->Printf( "Implement me\n" ); 527 } 528 529 /* 530 ================ 531 idDeclAudio::Parse 532 ================ 533 */ 534 bool idDeclAudio::Parse( const char *text, const int textLength, bool allowBinaryVersion ) { 535 idLexer src; 536 idToken token; 537 538 idStr baseStrId = va( "#str_%s_audio_", GetName() ); 539 540 src.LoadMemory( text, textLength, GetFileName(), GetLineNum() ); 541 src.SetFlags( LEXFL_NOSTRINGCONCAT | LEXFL_ALLOWPATHNAMES | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_ALLOWBACKSLASHSTRINGCONCAT | LEXFL_NOFATALERRORS ); 542 src.SkipUntilString( "{" ); 543 544 // scan through, identifying each individual parameter 545 while( 1 ) { 546 547 if ( !src.ReadToken( &token ) ) { 548 break; 549 } 550 551 if ( token == "}" ) { 552 break; 553 } 554 555 if ( !token.Icmp( "name") ) { 556 src.ReadToken( &token ); 557 if ( g_useOldPDAStrings.GetBool() ) { 558 audioName = token; 559 } else { 560 audioName = idLocalization::GetString( baseStrId + "name" ); 561 } 562 continue; 563 } 564 565 if ( !token.Icmp( "audio") ) { 566 src.ReadToken( &token ); 567 audio = declManager->FindSound( token ); 568 continue; 569 } 570 571 if ( !token.Icmp( "info") ) { 572 src.ReadToken( &token ); 573 if ( g_useOldPDAStrings.GetBool() ) { 574 info = token; 575 } else { 576 info = idLocalization::GetString( baseStrId + "info" ); 577 } 578 continue; 579 } 580 } 581 582 if ( src.HadError() ) { 583 src.Warning( "Audio decl '%s' had a parse error", GetName() ); 584 return false; 585 } 586 return true; 587 } 588 589 /* 590 =================== 591 idDeclAudio::DefaultDefinition 592 =================== 593 */ 594 const char *idDeclAudio::DefaultDefinition() const { 595 return 596 "{\n" 597 "\t" "{\n" 598 "\t\t" "name\t5Default Audio\n" 599 "\t" "}\n" 600 "}"; 601 } 602 603 /* 604 =================== 605 idDeclAudio::FreeData 606 =================== 607 */ 608 void idDeclAudio::FreeData() { 609 }