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