DeclPDA.cpp 13 KB

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