PageRenderTime 39ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/neo/framework/DeclPDA.cpp

http://github.com/TTimo/doom3.gpl
C++ | 668 lines | 377 code | 85 blank | 206 comment | 73 complexity | db6b992e98dfb30b657e95c4b527b88e MD5 | raw file
Possible License(s): BSD-3-Clause, CC0-1.0, GPL-2.0
  1. /*
  2. ===========================================================================
  3. Doom 3 GPL Source Code
  4. Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
  6. Doom 3 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 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 Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 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 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. /*
  23. =================
  24. idDeclPDA::Size
  25. =================
  26. */
  27. size_t idDeclPDA::Size( void ) const {
  28. return sizeof( idDeclPDA );
  29. }
  30. /*
  31. ===============
  32. idDeclPDA::Print
  33. ===============
  34. */
  35. void idDeclPDA::Print( void ) const {
  36. common->Printf( "Implement me\n" );
  37. }
  38. /*
  39. ===============
  40. idDeclPDA::List
  41. ===============
  42. */
  43. void idDeclPDA::List( void ) const {
  44. common->Printf( "Implement me\n" );
  45. }
  46. /*
  47. ================
  48. idDeclPDA::Parse
  49. ================
  50. */
  51. bool idDeclPDA::Parse( const char *text, const int textLength ) {
  52. idLexer src;
  53. idToken token;
  54. src.LoadMemory( text, textLength, GetFileName(), GetLineNum() );
  55. src.SetFlags( DECL_LEXER_FLAGS );
  56. src.SkipUntilString( "{" );
  57. // scan through, identifying each individual parameter
  58. while( 1 ) {
  59. if ( !src.ReadToken( &token ) ) {
  60. break;
  61. }
  62. if ( token == "}" ) {
  63. break;
  64. }
  65. if ( !token.Icmp( "name") ) {
  66. src.ReadToken( &token );
  67. pdaName = token;
  68. continue;
  69. }
  70. if ( !token.Icmp( "fullname") ) {
  71. src.ReadToken( &token );
  72. fullName = token;
  73. continue;
  74. }
  75. if ( !token.Icmp( "icon") ) {
  76. src.ReadToken( &token );
  77. icon = token;
  78. continue;
  79. }
  80. if ( !token.Icmp( "id") ) {
  81. src.ReadToken( &token );
  82. id = token;
  83. continue;
  84. }
  85. if ( !token.Icmp( "post") ) {
  86. src.ReadToken( &token );
  87. post = token;
  88. continue;
  89. }
  90. if ( !token.Icmp( "title") ) {
  91. src.ReadToken( &token );
  92. title = token;
  93. continue;
  94. }
  95. if ( !token.Icmp( "security") ) {
  96. src.ReadToken( &token );
  97. security = token;
  98. continue;
  99. }
  100. if ( !token.Icmp( "pda_email") ) {
  101. src.ReadToken( &token );
  102. emails.Append( token );
  103. declManager->FindType(DECL_EMAIL, token);
  104. continue;
  105. }
  106. if ( !token.Icmp( "pda_audio") ) {
  107. src.ReadToken( &token );
  108. audios.Append( token );
  109. declManager->FindType(DECL_AUDIO, token);
  110. continue;
  111. }
  112. if ( !token.Icmp( "pda_video") ) {
  113. src.ReadToken( &token );
  114. videos.Append( token );
  115. declManager->FindType(DECL_VIDEO, token);
  116. continue;
  117. }
  118. }
  119. if ( src.HadError() ) {
  120. src.Warning( "PDA decl '%s' had a parse error", GetName() );
  121. return false;
  122. }
  123. originalVideos = videos.Num();
  124. originalEmails = emails.Num();
  125. return true;
  126. }
  127. /*
  128. ===================
  129. idDeclPDA::DefaultDefinition
  130. ===================
  131. */
  132. const char *idDeclPDA::DefaultDefinition( void ) const {
  133. return
  134. "{\n"
  135. "\t" "name \"default pda\"\n"
  136. "}";
  137. }
  138. /*
  139. ===================
  140. idDeclPDA::FreeData
  141. ===================
  142. */
  143. void idDeclPDA::FreeData( void ) {
  144. videos.Clear();
  145. audios.Clear();
  146. emails.Clear();
  147. originalEmails = 0;
  148. originalVideos = 0;
  149. }
  150. /*
  151. =================
  152. idDeclPDA::AddVideo
  153. =================
  154. */
  155. void idDeclPDA::AddVideo( const char *name, bool unique ) const {
  156. if ( unique && ( videos.Find( name ) != NULL ) ) {
  157. return;
  158. }
  159. if ( declManager->FindType( DECL_VIDEO, name, false ) == NULL ) {
  160. common->Printf( "Video %s not found\n", name );
  161. return;
  162. }
  163. videos.Append( name );
  164. }
  165. /*
  166. =================
  167. idDeclPDA::AddAudio
  168. =================
  169. */
  170. void idDeclPDA::AddAudio( const char *name, bool unique ) const {
  171. if ( unique && ( audios.Find( name ) != NULL ) ) {
  172. return;
  173. }
  174. if ( declManager->FindType( DECL_AUDIO, name, false ) == NULL ) {
  175. common->Printf( "Audio log %s not found\n", name );
  176. return;
  177. }
  178. audios.Append( name );
  179. }
  180. /*
  181. =================
  182. idDeclPDA::AddEmail
  183. =================
  184. */
  185. void idDeclPDA::AddEmail( const char *name, bool unique ) const {
  186. if ( unique && ( emails.Find( name ) != NULL ) ) {
  187. return;
  188. }
  189. if ( declManager->FindType( DECL_EMAIL, name, false ) == NULL ) {
  190. common->Printf( "Email %s not found\n", name );
  191. return;
  192. }
  193. emails.Append( name );
  194. }
  195. /*
  196. =================
  197. idDeclPDA::RemoveAddedEmailsAndVideos
  198. =================
  199. */
  200. void idDeclPDA::RemoveAddedEmailsAndVideos() const {
  201. int num = emails.Num();
  202. if ( originalEmails < num ) {
  203. while ( num && num > originalEmails ) {
  204. emails.RemoveIndex( --num );
  205. }
  206. }
  207. num = videos.Num();
  208. if ( originalVideos < num ) {
  209. while ( num && num > originalVideos ) {
  210. videos.RemoveIndex( --num );
  211. }
  212. }
  213. }
  214. /*
  215. =================
  216. idDeclPDA::SetSecurity
  217. =================
  218. */
  219. void idDeclPDA::SetSecurity( const char *sec ) const {
  220. security = sec;
  221. }
  222. /*
  223. =================
  224. idDeclPDA::GetNumVideos
  225. =================
  226. */
  227. const int idDeclPDA::GetNumVideos() const {
  228. return videos.Num();
  229. }
  230. /*
  231. =================
  232. idDeclPDA::GetNumAudios
  233. =================
  234. */
  235. const int idDeclPDA::GetNumAudios() const {
  236. return audios.Num();
  237. }
  238. /*
  239. =================
  240. idDeclPDA::GetNumEmails
  241. =================
  242. */
  243. const int idDeclPDA::GetNumEmails() const {
  244. return emails.Num();
  245. }
  246. /*
  247. =================
  248. idDeclPDA::GetVideoByIndex
  249. =================
  250. */
  251. const idDeclVideo* idDeclPDA::GetVideoByIndex( int index ) const {
  252. if ( index >= 0 && index < videos.Num() ) {
  253. return static_cast< const idDeclVideo* >( declManager->FindType( DECL_VIDEO, videos[index], false ) );
  254. }
  255. return NULL;
  256. }
  257. /*
  258. =================
  259. idDeclPDA::GetAudioByIndex
  260. =================
  261. */
  262. const idDeclAudio* idDeclPDA::GetAudioByIndex( int index ) const {
  263. if ( index >= 0 && index < audios.Num() ) {
  264. return static_cast< const idDeclAudio* >( declManager->FindType( DECL_AUDIO, audios[index], false ) );
  265. }
  266. return NULL;
  267. }
  268. /*
  269. =================
  270. idDeclPDA::GetEmailByIndex
  271. =================
  272. */
  273. const idDeclEmail* idDeclPDA::GetEmailByIndex( int index ) const {
  274. if ( index >= 0 && index < emails.Num() ) {
  275. return static_cast< const idDeclEmail* >( declManager->FindType( DECL_EMAIL, emails[index], false ) );
  276. }
  277. return NULL;
  278. }
  279. /*
  280. =================
  281. idDeclEmail::Size
  282. =================
  283. */
  284. size_t idDeclEmail::Size( void ) const {
  285. return sizeof( idDeclEmail );
  286. }
  287. /*
  288. ===============
  289. idDeclEmail::Print
  290. ===============
  291. */
  292. void idDeclEmail::Print( void ) const {
  293. common->Printf( "Implement me\n" );
  294. }
  295. /*
  296. ===============
  297. idDeclEmail::List
  298. ===============
  299. */
  300. void idDeclEmail::List( void ) const {
  301. common->Printf( "Implement me\n" );
  302. }
  303. /*
  304. ================
  305. idDeclEmail::Parse
  306. ================
  307. */
  308. bool idDeclEmail::Parse( const char *_text, const int textLength ) {
  309. idLexer src;
  310. idToken token;
  311. src.LoadMemory( _text, textLength, GetFileName(), GetLineNum() );
  312. src.SetFlags( LEXFL_NOSTRINGCONCAT | LEXFL_ALLOWPATHNAMES | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_ALLOWBACKSLASHSTRINGCONCAT | LEXFL_NOFATALERRORS );
  313. src.SkipUntilString( "{" );
  314. text = "";
  315. // scan through, identifying each individual parameter
  316. while( 1 ) {
  317. if ( !src.ReadToken( &token ) ) {
  318. break;
  319. }
  320. if ( token == "}" ) {
  321. break;
  322. }
  323. if ( !token.Icmp( "subject") ) {
  324. src.ReadToken( &token );
  325. subject = token;
  326. continue;
  327. }
  328. if ( !token.Icmp( "to") ) {
  329. src.ReadToken( &token );
  330. to = token;
  331. continue;
  332. }
  333. if ( !token.Icmp( "from") ) {
  334. src.ReadToken( &token );
  335. from = token;
  336. continue;
  337. }
  338. if ( !token.Icmp( "date") ) {
  339. src.ReadToken( &token );
  340. date = token;
  341. continue;
  342. }
  343. if ( !token.Icmp( "text") ) {
  344. src.ReadToken( &token );
  345. if ( token != "{" ) {
  346. src.Warning( "Email decl '%s' had a parse error", GetName() );
  347. return false;
  348. }
  349. while ( src.ReadToken( &token ) && token != "}" ) {
  350. text += token;
  351. }
  352. continue;
  353. }
  354. if ( !token.Icmp( "image") ) {
  355. src.ReadToken( &token );
  356. image = token;
  357. continue;
  358. }
  359. }
  360. if ( src.HadError() ) {
  361. src.Warning( "Email decl '%s' had a parse error", GetName() );
  362. return false;
  363. }
  364. return true;
  365. }
  366. /*
  367. ===================
  368. idDeclEmail::DefaultDefinition
  369. ===================
  370. */
  371. const char *idDeclEmail::DefaultDefinition( void ) const {
  372. return
  373. "{\n"
  374. "\t" "{\n"
  375. "\t\t" "to\t5Mail recipient\n"
  376. "\t\t" "subject\t5Nothing\n"
  377. "\t\t" "from\t5No one\n"
  378. "\t" "}\n"
  379. "}";
  380. }
  381. /*
  382. ===================
  383. idDeclEmail::FreeData
  384. ===================
  385. */
  386. void idDeclEmail::FreeData( void ) {
  387. }
  388. /*
  389. =================
  390. idDeclVideo::Size
  391. =================
  392. */
  393. size_t idDeclVideo::Size( void ) const {
  394. return sizeof( idDeclVideo );
  395. }
  396. /*
  397. ===============
  398. idDeclVideo::Print
  399. ===============
  400. */
  401. void idDeclVideo::Print( void ) const {
  402. common->Printf( "Implement me\n" );
  403. }
  404. /*
  405. ===============
  406. idDeclVideo::List
  407. ===============
  408. */
  409. void idDeclVideo::List( void ) const {
  410. common->Printf( "Implement me\n" );
  411. }
  412. /*
  413. ================
  414. idDeclVideo::Parse
  415. ================
  416. */
  417. bool idDeclVideo::Parse( const char *text, const int textLength ) {
  418. idLexer src;
  419. idToken token;
  420. src.LoadMemory( text, textLength, GetFileName(), GetLineNum() );
  421. src.SetFlags( LEXFL_NOSTRINGCONCAT | LEXFL_ALLOWPATHNAMES | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_ALLOWBACKSLASHSTRINGCONCAT | LEXFL_NOFATALERRORS );
  422. src.SkipUntilString( "{" );
  423. // scan through, identifying each individual parameter
  424. while( 1 ) {
  425. if ( !src.ReadToken( &token ) ) {
  426. break;
  427. }
  428. if ( token == "}" ) {
  429. break;
  430. }
  431. if ( !token.Icmp( "name") ) {
  432. src.ReadToken( &token );
  433. videoName = token;
  434. continue;
  435. }
  436. if ( !token.Icmp( "preview") ) {
  437. src.ReadToken( &token );
  438. preview = token;
  439. continue;
  440. }
  441. if ( !token.Icmp( "video") ) {
  442. src.ReadToken( &token );
  443. video = token;
  444. declManager->FindMaterial( video );
  445. continue;
  446. }
  447. if ( !token.Icmp( "info") ) {
  448. src.ReadToken( &token );
  449. info = token;
  450. continue;
  451. }
  452. if ( !token.Icmp( "audio") ) {
  453. src.ReadToken( &token );
  454. audio = token;
  455. declManager->FindSound(audio);
  456. continue;
  457. }
  458. }
  459. if ( src.HadError() ) {
  460. src.Warning( "Video decl '%s' had a parse error", GetName() );
  461. return false;
  462. }
  463. return true;
  464. }
  465. /*
  466. ===================
  467. idDeclVideo::DefaultDefinition
  468. ===================
  469. */
  470. const char *idDeclVideo::DefaultDefinition( void ) const {
  471. return
  472. "{\n"
  473. "\t" "{\n"
  474. "\t\t" "name\t5Default Video\n"
  475. "\t" "}\n"
  476. "}";
  477. }
  478. /*
  479. ===================
  480. idDeclVideo::FreeData
  481. ===================
  482. */
  483. void idDeclVideo::FreeData( void ) {
  484. }
  485. /*
  486. =================
  487. idDeclAudio::Size
  488. =================
  489. */
  490. size_t idDeclAudio::Size( void ) const {
  491. return sizeof( idDeclAudio );
  492. }
  493. /*
  494. ===============
  495. idDeclAudio::Print
  496. ===============
  497. */
  498. void idDeclAudio::Print( void ) const {
  499. common->Printf( "Implement me\n" );
  500. }
  501. /*
  502. ===============
  503. idDeclAudio::List
  504. ===============
  505. */
  506. void idDeclAudio::List( void ) const {
  507. common->Printf( "Implement me\n" );
  508. }
  509. /*
  510. ================
  511. idDeclAudio::Parse
  512. ================
  513. */
  514. bool idDeclAudio::Parse( const char *text, const int textLength ) {
  515. idLexer src;
  516. idToken token;
  517. src.LoadMemory( text, textLength, GetFileName(), GetLineNum() );
  518. src.SetFlags( LEXFL_NOSTRINGCONCAT | LEXFL_ALLOWPATHNAMES | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_ALLOWBACKSLASHSTRINGCONCAT | LEXFL_NOFATALERRORS );
  519. src.SkipUntilString( "{" );
  520. // scan through, identifying each individual parameter
  521. while( 1 ) {
  522. if ( !src.ReadToken( &token ) ) {
  523. break;
  524. }
  525. if ( token == "}" ) {
  526. break;
  527. }
  528. if ( !token.Icmp( "name") ) {
  529. src.ReadToken( &token );
  530. audioName = token;
  531. continue;
  532. }
  533. if ( !token.Icmp( "audio") ) {
  534. src.ReadToken( &token );
  535. audio = token;
  536. declManager->FindSound(audio);
  537. continue;
  538. }
  539. if ( !token.Icmp( "info") ) {
  540. src.ReadToken( &token );
  541. info = token;
  542. continue;
  543. }
  544. if ( !token.Icmp( "preview") ) {
  545. src.ReadToken( &token );
  546. preview = token;
  547. continue;
  548. }
  549. }
  550. if ( src.HadError() ) {
  551. src.Warning( "Audio decl '%s' had a parse error", GetName() );
  552. return false;
  553. }
  554. return true;
  555. }
  556. /*
  557. ===================
  558. idDeclAudio::DefaultDefinition
  559. ===================
  560. */
  561. const char *idDeclAudio::DefaultDefinition( void ) const {
  562. return
  563. "{\n"
  564. "\t" "{\n"
  565. "\t\t" "name\t5Default Audio\n"
  566. "\t" "}\n"
  567. "}";
  568. }
  569. /*
  570. ===================
  571. idDeclAudio::FreeData
  572. ===================
  573. */
  574. void idDeclAudio::FreeData( void ) {
  575. }