1 /* 2 =========================================================================== 3 4 Return to Castle Wolfenstein single player GPL Source Code 5 Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. 6 7 This file is part of the Return to Castle Wolfenstein single player GPL Source Code (RTCW SP Source Code). 8 9 RTCW SP 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 RTCW SP 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 RTCW SP Source Code. If not, see <http://www.gnu.org/licenses/>. 21 22 In addition, the RTCW SP 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 RTCW SP 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 30 /***************************************************************************** 31 * name: l_precomp.h 32 * 33 * desc: pre compiler 34 * 35 * 36 *****************************************************************************/ 37 38 #ifndef PATH_SEPERATORSTR 39 #if defined( WIN32 ) | defined( _WIN32 ) | defined( __NT__ ) | defined( __WINDOWS__ ) | defined( __WINDOWS_386__ ) 40 #define PATHSEPERATOR_STR "\\" 41 #else 42 #define PATHSEPERATOR_STR "/" 43 #endif 44 #endif 45 #ifndef PATH_SEPERATORCHAR 46 #if defined( WIN32 ) | defined( _WIN32 ) | defined( __NT__ ) | defined( __WINDOWS__ ) | defined( __WINDOWS_386__ ) 47 #define PATHSEPERATOR_CHAR '\\' 48 #else 49 #define PATHSEPERATOR_CHAR '/' 50 #endif 51 #endif 52 53 54 #define DEFINE_FIXED 0x0001 55 56 #define BUILTIN_LINE 1 57 #define BUILTIN_FILE 2 58 #define BUILTIN_DATE 3 59 #define BUILTIN_TIME 4 60 #define BUILTIN_STDC 5 61 62 #define INDENT_IF 0x0001 63 #define INDENT_ELSE 0x0002 64 #define INDENT_ELIF 0x0004 65 #define INDENT_IFDEF 0x0008 66 #define INDENT_IFNDEF 0x0010 67 68 //macro definitions 69 typedef struct define_s 70 { 71 char *name; //define name 72 int flags; //define flags 73 int builtin; // > 0 if builtin define 74 int numparms; //number of define parameters 75 token_t *parms; //define parameters 76 token_t *tokens; //macro tokens (possibly containing parm tokens) 77 struct define_s *next; //next defined macro in a list 78 struct define_s *hashnext; //next define in the hash chain 79 } define_t; 80 81 //indents 82 //used for conditional compilation directives: 83 //#if, #else, #elif, #ifdef, #ifndef 84 typedef struct indent_s 85 { 86 int type; //indent type 87 int skip; //true if skipping current indent 88 script_t *script; //script the indent was in 89 struct indent_s *next; //next indent on the indent stack 90 } indent_t; 91 92 //source file 93 typedef struct source_s 94 { 95 char filename[MAX_QPATH]; //file name of the script 96 char includepath[MAX_QPATH]; //path to include files 97 punctuation_t *punctuations; //punctuations to use 98 script_t *scriptstack; //stack with scripts of the source 99 token_t *tokens; //tokens to read first 100 define_t *defines; //list with macro definitions 101 define_t **definehash; //hash chain with defines 102 indent_t *indentstack; //stack with indents 103 int skip; // > 0 if skipping conditional code 104 token_t token; //last read token 105 } source_t; 106 107 108 //read a token from the source 109 int PC_ReadToken( source_t *source, token_t *token ); 110 //expect a certain token 111 int PC_ExpectTokenString( source_t *source, char *string ); 112 //expect a certain token type 113 int PC_ExpectTokenType( source_t *source, int type, int subtype, token_t *token ); 114 //expect a token 115 int PC_ExpectAnyToken( source_t *source, token_t *token ); 116 //returns true when the token is available 117 int PC_CheckTokenString( source_t *source, char *string ); 118 //returns true and reads the token when a token with the given type is available 119 int PC_CheckTokenType( source_t *source, int type, int subtype, token_t *token ); 120 //skip tokens until the given token string is read 121 int PC_SkipUntilString( source_t *source, char *string ); 122 //unread the last token read from the script 123 void PC_UnreadLastToken( source_t *source ); 124 //unread the given token 125 void PC_UnreadToken( source_t *source, token_t *token ); 126 //read a token only if on the same line, lines are concatenated with a slash 127 int PC_ReadLine( source_t *source, token_t *token ); 128 //returns true if there was a white space in front of the token 129 int PC_WhiteSpaceBeforeToken( token_t *token ); 130 //add a define to the source 131 int PC_AddDefine( source_t *source, char *string ); 132 //add a globals define that will be added to all opened sources 133 int PC_AddGlobalDefine( char *string ); 134 //remove the given global define 135 int PC_RemoveGlobalDefine( char *name ); 136 //remove all globals defines 137 void PC_RemoveAllGlobalDefines( void ); 138 //add builtin defines 139 void PC_AddBuiltinDefines( source_t *source ); 140 //set the source include path 141 void PC_SetIncludePath( source_t *source, char *path ); 142 //set the punction set 143 void PC_SetPunctuations( source_t *source, punctuation_t *p ); 144 //set the base folder to load files from 145 void PC_SetBaseFolder( char *path ); 146 //load a source file 147 source_t *LoadSourceFile( const char *filename ); 148 //load a source from memory 149 source_t *LoadSourceMemory( char *ptr, int length, char *name ); 150 //free the given source 151 void FreeSource( source_t *source ); 152 //print a source error 153 void QDECL SourceError(source_t *source, char *str, ...) __attribute__ ((format (printf, 2, 3))); 154 //print a source warning 155 void QDECL SourceWarning(source_t *source, char *str, ...) __attribute__ ((format (printf, 2, 3))); 156 157 // 158 int PC_LoadSourceHandle( const char *filename ); 159 int PC_FreeSourceHandle( int handle ); 160 int PC_ReadTokenHandle( int handle, struct pc_token_s *pc_token ); 161 int PC_SourceFileAndLine( int handle, char *filename, int *line ); 162 void PC_CheckOpenSourceHandles( void ); 163