| 1 |
/* |
| 2 |
=========================================================================== |
| 3 |
Copyright (C) 1999-2005 Id Software, Inc. |
| 4 |
|
| 5 |
This file is part of Quake III Arena source code. |
| 6 |
|
| 7 |
Quake III Arena source code is free software; you can redistribute it |
| 8 |
and/or modify it under the terms of the GNU General Public License as |
| 9 |
published by the Free Software Foundation; either version 2 of the License, |
| 10 |
or (at your option) any later version. |
| 11 |
|
| 12 |
Quake III Arena source code is distributed in the hope that it will be |
| 13 |
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
GNU General Public License for more details. |
| 16 |
|
| 17 |
You should have received a copy of the GNU General Public License |
| 18 |
along with Quake III Arena source code; if not, write to the Free Software |
| 19 |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 |
=========================================================================== |
| 21 |
*/ |
| 22 |
|
| 23 |
/***************************************************************************** |
| 24 |
* name: l_precomp.h |
| 25 |
* |
| 26 |
* desc: pre compiler |
| 27 |
* |
| 28 |
* $Archive: /source/code/botlib/l_precomp.h $ |
| 29 |
* |
| 30 |
*****************************************************************************/ |
| 31 |
|
| 32 |
#ifndef MAX_PATH |
| 33 |
#define MAX_PATH MAX_QPATH |
| 34 |
#endif |
| 35 |
|
| 36 |
#ifndef PATH_SEPERATORSTR |
| 37 |
#if defined(WIN32)|defined(_WIN32)|defined(__NT__)|defined(__WINDOWS__)|defined(__WINDOWS_386__) |
| 38 |
#define PATHSEPERATOR_STR "\\" |
| 39 |
#else |
| 40 |
#define PATHSEPERATOR_STR "/" |
| 41 |
#endif |
| 42 |
#endif |
| 43 |
#ifndef PATH_SEPERATORCHAR |
| 44 |
#if defined(WIN32)|defined(_WIN32)|defined(__NT__)|defined(__WINDOWS__)|defined(__WINDOWS_386__) |
| 45 |
#define PATHSEPERATOR_CHAR '\\' |
| 46 |
#else |
| 47 |
#define PATHSEPERATOR_CHAR '/' |
| 48 |
#endif |
| 49 |
#endif |
| 50 |
|
| 51 |
#if defined(BSPC) && !defined(QDECL) |
| 52 |
#define QDECL |
| 53 |
#endif |
| 54 |
|
| 55 |
|
| 56 |
#define DEFINE_FIXED 0x0001 |
| 57 |
|
| 58 |
#define BUILTIN_LINE 1 |
| 59 |
#define BUILTIN_FILE 2 |
| 60 |
#define BUILTIN_DATE 3 |
| 61 |
#define BUILTIN_TIME 4 |
| 62 |
#define BUILTIN_STDC 5 |
| 63 |
|
| 64 |
#define INDENT_IF 0x0001 |
| 65 |
#define INDENT_ELSE 0x0002 |
| 66 |
#define INDENT_ELIF 0x0004 |
| 67 |
#define INDENT_IFDEF 0x0008 |
| 68 |
#define INDENT_IFNDEF 0x0010 |
| 69 |
|
| 70 |
//macro definitions |
| 71 |
typedef struct define_s |
| 72 |
{ |
| 73 |
char *name; //define name |
| 74 |
int flags; //define flags |
| 75 |
int builtin; // > 0 if builtin define |
| 76 |
int numparms; //number of define parameters |
| 77 |
token_t *parms; //define parameters |
| 78 |
token_t *tokens; //macro tokens (possibly containing parm tokens) |
| 79 |
struct define_s *next; //next defined macro in a list |
| 80 |
struct define_s *hashnext; //next define in the hash chain |
| 81 |
} define_t; |
| 82 |
|
| 83 |
//indents |
| 84 |
//used for conditional compilation directives: |
| 85 |
//#if, #else, #elif, #ifdef, #ifndef |
| 86 |
typedef struct indent_s |
| 87 |
{ |
| 88 |
int type; //indent type |
| 89 |
int skip; //true if skipping current indent |
| 90 |
script_t *script; //script the indent was in |
| 91 |
struct indent_s *next; //next indent on the indent stack |
| 92 |
} indent_t; |
| 93 |
|
| 94 |
//source file |
| 95 |
typedef struct source_s |
| 96 |
{ |
| 97 |
char filename[1024]; //file name of the script |
| 98 |
char includepath[1024]; //path to include files |
| 99 |
punctuation_t *punctuations; //punctuations to use |
| 100 |
script_t *scriptstack; //stack with scripts of the source |
| 101 |
token_t *tokens; //tokens to read first |
| 102 |
define_t *defines; //list with macro definitions |
| 103 |
define_t **definehash; //hash chain with defines |
| 104 |
indent_t *indentstack; //stack with indents |
| 105 |
int skip; // > 0 if skipping conditional code |
| 106 |
token_t token; //last read token |
| 107 |
} source_t; |
| 108 |
|
| 109 |
|
| 110 |
//read a token from the source |
| 111 |
int PC_ReadToken(source_t *source, token_t *token); |
| 112 |
//expect a certain token |
| 113 |
int PC_ExpectTokenString(source_t *source, char *string); |
| 114 |
//expect a certain token type |
| 115 |
int PC_ExpectTokenType(source_t *source, int type, int subtype, token_t *token); |
| 116 |
//expect a token |
| 117 |
int PC_ExpectAnyToken(source_t *source, token_t *token); |
| 118 |
//returns true when the token is available |
| 119 |
int PC_CheckTokenString(source_t *source, char *string); |
| 120 |
//returns true an reads the token when a token with the given type is available |
| 121 |
int PC_CheckTokenType(source_t *source, int type, int subtype, token_t *token); |
| 122 |
//skip tokens until the given token string is read |
| 123 |
int PC_SkipUntilString(source_t *source, char *string); |
| 124 |
//unread the last token read from the script |
| 125 |
void PC_UnreadLastToken(source_t *source); |
| 126 |
//unread the given token |
| 127 |
void PC_UnreadToken(source_t *source, token_t *token); |
| 128 |
//read a token only if on the same line, lines are concatenated with a slash |
| 129 |
int PC_ReadLine(source_t *source, token_t *token); |
| 130 |
//returns true if there was a white space in front of the token |
| 131 |
int PC_WhiteSpaceBeforeToken(token_t *token); |
| 132 |
//add a define to the source |
| 133 |
int PC_AddDefine(source_t *source, char *string); |
| 134 |
//add a globals define that will be added to all opened sources |
| 135 |
int PC_AddGlobalDefine(char *string); |
| 136 |
//remove the given global define |
| 137 |
int PC_RemoveGlobalDefine(char *name); |
| 138 |
//remove all globals defines |
| 139 |
void PC_RemoveAllGlobalDefines(void); |
| 140 |
//add builtin defines |
| 141 |
void PC_AddBuiltinDefines(source_t *source); |
| 142 |
//set the source include path |
| 143 |
void PC_SetIncludePath(source_t *source, char *path); |
| 144 |
//set the punction set |
| 145 |
void PC_SetPunctuations(source_t *source, punctuation_t *p); |
| 146 |
//set the base folder to load files from |
| 147 |
void PC_SetBaseFolder(char *path); |
| 148 |
//load a source file |
| 149 |
source_t *LoadSourceFile(const char *filename); |
| 150 |
//load a source from memory |
| 151 |
source_t *LoadSourceMemory(char *ptr, int length, char *name); |
| 152 |
//free the given source |
| 153 |
void FreeSource(source_t *source); |
| 154 |
//print a source error |
| 155 |
void QDECL SourceError(source_t *source, char *str, ...); |
| 156 |
//print a source warning |
| 157 |
void QDECL SourceWarning(source_t *source, char *str, ...); |
| 158 |
|
| 159 |
#ifdef BSPC |
| 160 |
// some of BSPC source does include game/q_shared.h and some does not |
| 161 |
// we define pc_token_s pc_token_t if needed (yes, it's ugly) |
| 162 |
#ifndef __Q_SHARED_H |
| 163 |
#define MAX_TOKENLENGTH 1024 |
| 164 |
typedef struct pc_token_s |
| 165 |
{ |
| 166 |
int type; |
| 167 |
int subtype; |
| 168 |
int intvalue; |
| 169 |
float floatvalue; |
| 170 |
char string[MAX_TOKENLENGTH]; |
| 171 |
} pc_token_t; |
| 172 |
#endif //!_Q_SHARED_H |
| 173 |
#endif //BSPC |
| 174 |
|
| 175 |
// |
| 176 |
int PC_LoadSourceHandle(const char *filename); |
| 177 |
int PC_FreeSourceHandle(int handle); |
| 178 |
int PC_ReadTokenHandle(int handle, pc_token_t *pc_token); |
| 179 |
int PC_SourceFileAndLine(int handle, char *filename, int *line); |
| 180 |
void PC_CheckOpenSourceHandles(void); |