1 /*
2 ===========================================================================
3 
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
6 
7 This file is part of the Doom 3 GPL Source Code ("Doom 3 Source Code").
8 
9 Doom 3 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 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 Source Code.  If not, see <http://www.gnu.org/licenses/>.
21 
22 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.
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 "sys/platform.h"
30 #include "idlib/containers/StrList.h"
31 #include "framework/Common.h"
32 
33 #include "framework/DeclPDA.h"
34 
35 /*
36 =================
37 idDeclPDA::Size
38 =================
39 */
Size(void) const40 size_t idDeclPDA::Size( void ) const {
41 	return sizeof( idDeclPDA );
42 }
43 
44 /*
45 ===============
46 idDeclPDA::Print
47 ===============
48 */
Print(void) const49 void idDeclPDA::Print( void ) const {
50 	common->Printf( "Implement me\n" );
51 }
52 
53 /*
54 ===============
55 idDeclPDA::List
56 ===============
57 */
List(void) const58 void idDeclPDA::List( void ) const {
59 	common->Printf( "Implement me\n" );
60 }
61 
62 /*
63 ================
64 idDeclPDA::Parse
65 ================
66 */
Parse(const char * text,const int textLength)67 bool idDeclPDA::Parse( const char *text, const int textLength ) {
68 	idLexer src;
69 	idToken token;
70 
71 	src.LoadMemory( text, textLength, GetFileName(), GetLineNum() );
72 	src.SetFlags( DECL_LEXER_FLAGS );
73 	src.SkipUntilString( "{" );
74 
75 	// scan through, identifying each individual parameter
76 	while( 1 ) {
77 
78 		if ( !src.ReadToken( &token ) ) {
79 			break;
80 		}
81 
82 		if ( token == "}" ) {
83 			break;
84 		}
85 
86 		if ( !token.Icmp( "name") ) {
87 			src.ReadToken( &token );
88 			pdaName = token;
89 			continue;
90 		}
91 
92 		if ( !token.Icmp( "fullname") ) {
93 			src.ReadToken( &token );
94 			fullName = token;
95 			continue;
96 		}
97 
98 		if ( !token.Icmp( "icon") ) {
99 			src.ReadToken( &token );
100 			icon = token;
101 			continue;
102 		}
103 
104 		if ( !token.Icmp( "id") ) {
105 			src.ReadToken( &token );
106 			id = token;
107 			continue;
108 		}
109 
110 		if ( !token.Icmp( "post") ) {
111 			src.ReadToken( &token );
112 			post = token;
113 			continue;
114 		}
115 
116 		if ( !token.Icmp( "title") ) {
117 			src.ReadToken( &token );
118 			title = token;
119 			continue;
120 		}
121 
122 		if ( !token.Icmp( "security") ) {
123 			src.ReadToken( &token );
124 			security = token;
125 			continue;
126 		}
127 
128 		if ( !token.Icmp( "pda_email") ) {
129 			src.ReadToken( &token );
130 			emails.Append( token );
131 			declManager->FindType(DECL_EMAIL, token);
132 			continue;
133 		}
134 
135 		if ( !token.Icmp( "pda_audio") ) {
136 			src.ReadToken( &token );
137 			audios.Append( token );
138 			declManager->FindType(DECL_AUDIO, token);
139 			continue;
140 		}
141 
142 		if ( !token.Icmp( "pda_video") ) {
143 			src.ReadToken( &token );
144 			videos.Append( token );
145 			declManager->FindType(DECL_VIDEO, token);
146 			continue;
147 		}
148 
149 	}
150 
151 	if ( src.HadError() ) {
152 		src.Warning( "PDA decl '%s' had a parse error", GetName() );
153 		return false;
154 	}
155 
156 	originalVideos = videos.Num();
157 	originalEmails = emails.Num();
158 	return true;
159 }
160 
161 /*
162 ===================
163 idDeclPDA::DefaultDefinition
164 ===================
165 */
DefaultDefinition(void) const166 const char *idDeclPDA::DefaultDefinition( void ) const {
167 	return
168 		"{\n"
169 		"\t"		"name  \"default pda\"\n"
170 		"}";
171 }
172 
173 /*
174 ===================
175 idDeclPDA::FreeData
176 ===================
177 */
FreeData(void)178 void idDeclPDA::FreeData( void ) {
179 	videos.Clear();
180 	audios.Clear();
181 	emails.Clear();
182 	originalEmails = 0;
183 	originalVideos = 0;
184 }
185 
186 /*
187 =================
188 idDeclPDA::AddVideo
189 =================
190 */
AddVideo(const char * name,bool unique) const191 void idDeclPDA::AddVideo( const char *name, bool unique ) const {
192 	if ( unique && ( videos.Find( name ) != NULL ) ) {
193 		return;
194 	}
195 	if ( declManager->FindType( DECL_VIDEO, name, false ) == NULL ) {
196 		common->Printf( "Video %s not found\n", name );
197 		return;
198 	}
199 	videos.Append( name );
200 }
201 
202 /*
203 =================
204 idDeclPDA::AddAudio
205 =================
206 */
AddAudio(const char * name,bool unique) const207 void idDeclPDA::AddAudio( const char *name, bool unique ) const {
208 	if ( unique && ( audios.Find( name ) != NULL ) ) {
209 		return;
210 	}
211 	if ( declManager->FindType( DECL_AUDIO, name, false ) == NULL ) {
212 		common->Printf( "Audio log %s not found\n", name );
213 		return;
214 	}
215 	audios.Append( name );
216 }
217 
218 /*
219 =================
220 idDeclPDA::AddEmail
221 =================
222 */
AddEmail(const char * name,bool unique) const223 void idDeclPDA::AddEmail( const char *name, bool unique ) const {
224 	if ( unique && ( emails.Find( name ) != NULL ) ) {
225 		return;
226 	}
227 	if ( declManager->FindType( DECL_EMAIL, name, false ) == NULL ) {
228 		common->Printf( "Email %s not found\n", name );
229 		return;
230 	}
231 	emails.Append( name );
232 }
233 
234 /*
235 =================
236 idDeclPDA::RemoveAddedEmailsAndVideos
237 =================
238 */
RemoveAddedEmailsAndVideos() const239 void idDeclPDA::RemoveAddedEmailsAndVideos() const {
240 	int num = emails.Num();
241 	if ( originalEmails < num ) {
242 		while ( num && num > originalEmails ) {
243 			emails.RemoveIndex( --num );
244 		}
245 	}
246 	num = videos.Num();
247 	if ( originalVideos < num ) {
248 		while ( num && num > originalVideos ) {
249 			videos.RemoveIndex( --num );
250 		}
251 	}
252 }
253 
254 /*
255 =================
256 idDeclPDA::SetSecurity
257 =================
258 */
SetSecurity(const char * sec) const259 void idDeclPDA::SetSecurity( const char *sec ) const {
260 	security = sec;
261 }
262 
263 /*
264 =================
265 idDeclPDA::GetNumVideos
266 =================
267 */
GetNumVideos() const268 const int idDeclPDA::GetNumVideos() const {
269 	return videos.Num();
270 }
271 
272 /*
273 =================
274 idDeclPDA::GetNumAudios
275 =================
276 */
GetNumAudios() const277 const int idDeclPDA::GetNumAudios() const {
278 	return audios.Num();
279 }
280 
281 /*
282 =================
283 idDeclPDA::GetNumEmails
284 =================
285 */
GetNumEmails() const286 const int idDeclPDA::GetNumEmails() const {
287 	return emails.Num();
288 }
289 
290 /*
291 =================
292 idDeclPDA::GetVideoByIndex
293 =================
294 */
GetVideoByIndex(int index) const295 const idDeclVideo* idDeclPDA::GetVideoByIndex( int index ) const {
296 	if ( index >= 0 && index < videos.Num() ) {
297 		return static_cast< const idDeclVideo* >( declManager->FindType( DECL_VIDEO, videos[index], false ) );
298 	}
299 	return NULL;
300 }
301 
302 /*
303 =================
304 idDeclPDA::GetAudioByIndex
305 =================
306 */
GetAudioByIndex(int index) const307 const idDeclAudio* idDeclPDA::GetAudioByIndex( int index ) const {
308 	if ( index >= 0 && index < audios.Num() ) {
309 		return static_cast< const idDeclAudio* >( declManager->FindType( DECL_AUDIO, audios[index], false ) );
310 	}
311 	return NULL;
312 }
313 
314 /*
315 =================
316 idDeclPDA::GetEmailByIndex
317 =================
318 */
GetEmailByIndex(int index) const319 const idDeclEmail* idDeclPDA::GetEmailByIndex( int index ) const {
320 	if ( index >= 0 && index < emails.Num() ) {
321 		return static_cast< const idDeclEmail* >( declManager->FindType( DECL_EMAIL, emails[index], false ) );
322 	}
323 	return NULL;
324 }
325 
326 /*
327 =================
328 idDeclEmail::Size
329 =================
330 */
Size(void) const331 size_t idDeclEmail::Size( void ) const {
332 	return sizeof( idDeclEmail );
333 }
334 
335 /*
336 ===============
337 idDeclEmail::Print
338 ===============
339 */
Print(void) const340 void idDeclEmail::Print( void ) const {
341 	common->Printf( "Implement me\n" );
342 }
343 
344 /*
345 ===============
346 idDeclEmail::List
347 ===============
348 */
List(void) const349 void idDeclEmail::List( void ) const {
350 	common->Printf( "Implement me\n" );
351 }
352 
353 /*
354 ================
355 idDeclEmail::Parse
356 ================
357 */
Parse(const char * _text,const int textLength)358 bool idDeclEmail::Parse( const char *_text, const int textLength ) {
359 	idLexer src;
360 	idToken token;
361 
362 	src.LoadMemory( _text, textLength, GetFileName(), GetLineNum() );
363 	src.SetFlags( LEXFL_NOSTRINGCONCAT | LEXFL_ALLOWPATHNAMES |	LEXFL_ALLOWMULTICHARLITERALS | LEXFL_ALLOWBACKSLASHSTRINGCONCAT | LEXFL_NOFATALERRORS );
364 	src.SkipUntilString( "{" );
365 
366 	text = "";
367 	// scan through, identifying each individual parameter
368 	while( 1 ) {
369 
370 		if ( !src.ReadToken( &token ) ) {
371 			break;
372 		}
373 
374 		if ( token == "}" ) {
375 			break;
376 		}
377 
378 		if ( !token.Icmp( "subject") ) {
379 			src.ReadToken( &token );
380 			subject = token;
381 			continue;
382 		}
383 
384 		if ( !token.Icmp( "to") ) {
385 			src.ReadToken( &token );
386 			to = token;
387 			continue;
388 		}
389 
390 		if ( !token.Icmp( "from") ) {
391 			src.ReadToken( &token );
392 			from = token;
393 			continue;
394 		}
395 
396 		if ( !token.Icmp( "date") ) {
397 			src.ReadToken( &token );
398 			date = token;
399 			continue;
400 		}
401 
402 		if ( !token.Icmp( "text") ) {
403 			src.ReadToken( &token );
404 			if ( token != "{" ) {
405 				src.Warning( "Email decl '%s' had a parse error", GetName() );
406 				return false;
407 			}
408 			while ( src.ReadToken( &token ) && token != "}" ) {
409 				text += token;
410 			}
411 			continue;
412 		}
413 
414 		if ( !token.Icmp( "image") ) {
415 			src.ReadToken( &token );
416 			image = token;
417 			continue;
418 		}
419 	}
420 
421 	if ( src.HadError() ) {
422 		src.Warning( "Email decl '%s' had a parse error", GetName() );
423 		return false;
424 	}
425 	return true;
426 }
427 
428 /*
429 ===================
430 idDeclEmail::DefaultDefinition
431 ===================
432 */
DefaultDefinition(void) const433 const char *idDeclEmail::DefaultDefinition( void ) const {
434 	return
435 		"{\n"
436 		"\t"	"{\n"
437 		"\t\t"		"to\t5Mail recipient\n"
438 		"\t\t"		"subject\t5Nothing\n"
439 		"\t\t"		"from\t5No one\n"
440 		"\t"	"}\n"
441 		"}";
442 }
443 
444 /*
445 ===================
446 idDeclEmail::FreeData
447 ===================
448 */
FreeData(void)449 void idDeclEmail::FreeData( void ) {
450 }
451 
452 /*
453 =================
454 idDeclVideo::Size
455 =================
456 */
Size(void) const457 size_t idDeclVideo::Size( void ) const {
458 	return sizeof( idDeclVideo );
459 }
460 
461 /*
462 ===============
463 idDeclVideo::Print
464 ===============
465 */
Print(void) const466 void idDeclVideo::Print( void ) const {
467 	common->Printf( "Implement me\n" );
468 }
469 
470 /*
471 ===============
472 idDeclVideo::List
473 ===============
474 */
List(void) const475 void idDeclVideo::List( void ) const {
476 	common->Printf( "Implement me\n" );
477 }
478 
479 /*
480 ================
481 idDeclVideo::Parse
482 ================
483 */
Parse(const char * text,const int textLength)484 bool idDeclVideo::Parse( const char *text, const int textLength ) {
485 	idLexer src;
486 	idToken token;
487 
488 	src.LoadMemory( text, textLength, GetFileName(), GetLineNum() );
489 	src.SetFlags( LEXFL_NOSTRINGCONCAT | LEXFL_ALLOWPATHNAMES |	LEXFL_ALLOWMULTICHARLITERALS | LEXFL_ALLOWBACKSLASHSTRINGCONCAT | LEXFL_NOFATALERRORS );
490 	src.SkipUntilString( "{" );
491 
492 	// scan through, identifying each individual parameter
493 	while( 1 ) {
494 
495 		if ( !src.ReadToken( &token ) ) {
496 			break;
497 		}
498 
499 		if ( token == "}" ) {
500 			break;
501 		}
502 
503 		if ( !token.Icmp( "name") ) {
504 			src.ReadToken( &token );
505 			videoName = token;
506 			continue;
507 		}
508 
509 		if ( !token.Icmp( "preview") ) {
510 			src.ReadToken( &token );
511 			preview = token;
512 			continue;
513 		}
514 
515 		if ( !token.Icmp( "video") ) {
516 			src.ReadToken( &token );
517 			video = token;
518 			declManager->FindMaterial( video );
519 			continue;
520 		}
521 
522 		if ( !token.Icmp( "info") ) {
523 			src.ReadToken( &token );
524 			info = token;
525 			continue;
526 		}
527 
528 		if ( !token.Icmp( "audio") ) {
529 			src.ReadToken( &token );
530 			audio = token;
531 			declManager->FindSound(audio);
532 			continue;
533 		}
534 
535 	}
536 
537 	if ( src.HadError() ) {
538 		src.Warning( "Video decl '%s' had a parse error", GetName() );
539 		return false;
540 	}
541 	return true;
542 }
543 
544 /*
545 ===================
546 idDeclVideo::DefaultDefinition
547 ===================
548 */
DefaultDefinition(void) const549 const char *idDeclVideo::DefaultDefinition( void ) const {
550 	return
551 		"{\n"
552 		"\t"	"{\n"
553 		"\t\t"		"name\t5Default Video\n"
554 		"\t"	"}\n"
555 		"}";
556 }
557 
558 /*
559 ===================
560 idDeclVideo::FreeData
561 ===================
562 */
FreeData(void)563 void idDeclVideo::FreeData( void ) {
564 }
565 
566 /*
567 =================
568 idDeclAudio::Size
569 =================
570 */
Size(void) const571 size_t idDeclAudio::Size( void ) const {
572 	return sizeof( idDeclAudio );
573 }
574 
575 /*
576 ===============
577 idDeclAudio::Print
578 ===============
579 */
Print(void) const580 void idDeclAudio::Print( void ) const {
581 	common->Printf( "Implement me\n" );
582 }
583 
584 /*
585 ===============
586 idDeclAudio::List
587 ===============
588 */
List(void) const589 void idDeclAudio::List( void ) const {
590 	common->Printf( "Implement me\n" );
591 }
592 
593 /*
594 ================
595 idDeclAudio::Parse
596 ================
597 */
Parse(const char * text,const int textLength)598 bool idDeclAudio::Parse( const char *text, const int textLength ) {
599 	idLexer src;
600 	idToken token;
601 
602 	src.LoadMemory( text, textLength, GetFileName(), GetLineNum() );
603 	src.SetFlags( LEXFL_NOSTRINGCONCAT | LEXFL_ALLOWPATHNAMES |	LEXFL_ALLOWMULTICHARLITERALS | LEXFL_ALLOWBACKSLASHSTRINGCONCAT | LEXFL_NOFATALERRORS );
604 	src.SkipUntilString( "{" );
605 
606 	// scan through, identifying each individual parameter
607 	while( 1 ) {
608 
609 		if ( !src.ReadToken( &token ) ) {
610 			break;
611 		}
612 
613 		if ( token == "}" ) {
614 			break;
615 		}
616 
617 		if ( !token.Icmp( "name") ) {
618 			src.ReadToken( &token );
619 			audioName = token;
620 			continue;
621 		}
622 
623 		if ( !token.Icmp( "audio") ) {
624 			src.ReadToken( &token );
625 			audio = token;
626 			declManager->FindSound(audio);
627 			continue;
628 		}
629 
630 		if ( !token.Icmp( "info") ) {
631 			src.ReadToken( &token );
632 			info = token;
633 			continue;
634 		}
635 
636 		if ( !token.Icmp( "preview") ) {
637 			src.ReadToken( &token );
638 			preview = token;
639 			continue;
640 		}
641 
642 	}
643 
644 	if ( src.HadError() ) {
645 		src.Warning( "Audio decl '%s' had a parse error", GetName() );
646 		return false;
647 	}
648 	return true;
649 }
650 
651 /*
652 ===================
653 idDeclAudio::DefaultDefinition
654 ===================
655 */
DefaultDefinition(void) const656 const char *idDeclAudio::DefaultDefinition( void ) const {
657 	return
658 		"{\n"
659 		"\t"	"{\n"
660 		"\t\t"		"name\t5Default Audio\n"
661 		"\t"	"}\n"
662 		"}";
663 }
664 
665 /*
666 ===================
667 idDeclAudio::FreeData
668 ===================
669 */
FreeData(void)670 void idDeclAudio::FreeData( void ) {
671 }
672