2
===========================================================================
3
Copyright (C) 1999-2005 Id Software, Inc.
5
This file is part of Quake III Arena source code.
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.
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.
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
===========================================================================
23
/*****************************************************************************
26
* desc: lexicographical parser
28
* $Archive: /source/code/botlib/l_script.h $
30
*****************************************************************************/
32
//undef if binary numbers of the form 0b... or 0B... are not allowed
34
//undef if not using the token.intvalue and token.floatvalue
36
//use dollar sign also as punctuation
39
//maximum token length
40
#define MAX_TOKEN 1024
42
#if defined(BSPC) && !defined(QDECL)
48
#define SCFL_NOERRORS 0x0001
49
#define SCFL_NOWARNINGS 0x0002
50
#define SCFL_NOSTRINGWHITESPACES 0x0004
51
#define SCFL_NOSTRINGESCAPECHARS 0x0008
52
#define SCFL_PRIMITIVE 0x0010
53
#define SCFL_NOBINARYNUMBERS 0x0020
54
#define SCFL_NONUMBERVALUES 0x0040
57
#define TT_STRING 1 // string
58
#define TT_LITERAL 2 // literal
59
#define TT_NUMBER 3 // number
60
#define TT_NAME 4 // name
61
#define TT_PUNCTUATION 5 // punctuation
65
// the length of the string
68
// the ASCII code of the literal
71
#define TT_DECIMAL 0x0008 // decimal number
72
#define TT_HEX 0x0100 // hexadecimal number
73
#define TT_OCTAL 0x0200 // octal number
75
#define TT_BINARY 0x0400 // binary number
76
#endif //BINARYNUMBERS
77
#define TT_FLOAT 0x0800 // floating point number
78
#define TT_INTEGER 0x1000 // integer number
79
#define TT_LONG 0x2000 // long number
80
#define TT_UNSIGNED 0x4000 // unsigned number
81
//punctuation sub type
82
//--------------------
83
#define P_RSHIFT_ASSIGN 1
84
#define P_LSHIFT_ASSIGN 2
86
#define P_PRECOMPMERGE 4
93
#define P_LOGIC_UNEQ 10
95
#define P_MUL_ASSIGN 11
96
#define P_DIV_ASSIGN 12
97
#define P_MOD_ASSIGN 13
98
#define P_ADD_ASSIGN 14
99
#define P_SUB_ASSIGN 15
103
#define P_BIN_AND_ASSIGN 18
104
#define P_BIN_OR_ASSIGN 19
105
#define P_BIN_XOR_ASSIGN 20
109
#define P_POINTERREF 23
124
#define P_LOGIC_NOT 36
125
#define P_LOGIC_GREATER 37
126
#define P_LOGIC_LESS 38
130
#define P_SEMICOLON 41
132
#define P_QUESTIONMARK 43
134
#define P_PARENTHESESOPEN 44
135
#define P_PARENTHESESCLOSE 45
136
#define P_BRACEOPEN 46
137
#define P_BRACECLOSE 47
138
#define P_SQBRACKETOPEN 48
139
#define P_SQBRACKETCLOSE 49
140
#define P_BACKSLASH 50
146
// the length of the name
149
typedef struct punctuation_s
151
char *p; //punctuation character(s)
152
int n; //punctuation indication
153
struct punctuation_s *next; //next punctuation
157
typedef struct token_s
159
char string[MAX_TOKEN]; //available token
160
int type; //last read token type
161
int subtype; //last read token sub type
163
unsigned long int intvalue; //integer value
164
double floatvalue; //floating point value
166
char *whitespace_p; //start of white space before token
167
char *endwhitespace_p; //start of white space before token
168
int line; //line the token was on
169
int linescrossed; //lines crossed in white space
170
struct token_s *next; //next token in chain
174
typedef struct script_s
176
char filename[1024]; //file name of the script
177
char *buffer; //buffer containing the script
178
char *script_p; //current pointer in the script
179
char *end_p; //pointer to the end of the script
180
char *lastscript_p; //script pointer before reading token
181
char *whitespace_p; //begin of the white space
182
char *endwhitespace_p; //end of the white space
183
int length; //length of the script in bytes
184
int line; //current line in script
185
int lastline; //line before reading token
186
int tokenavailable; //set by UnreadLastToken
187
int flags; //several script flags
188
punctuation_t *punctuations; //the punctuations used in the script
189
punctuation_t **punctuationtable;
190
token_t token; //available token
191
struct script_s *next; //next script in a chain
194
//read a token from the script
195
int PS_ReadToken(script_t *script, token_t *token);
196
//expect a certain token
197
int PS_ExpectTokenString(script_t *script, char *string);
198
//expect a certain token type
199
int PS_ExpectTokenType(script_t *script, int type, int subtype, token_t *token);
201
int PS_ExpectAnyToken(script_t *script, token_t *token);
202
//returns true when the token is available
203
int PS_CheckTokenString(script_t *script, char *string);
204
//returns true an reads the token when a token with the given type is available
205
int PS_CheckTokenType(script_t *script, int type, int subtype, token_t *token);
206
//skip tokens until the given token string is read
207
int PS_SkipUntilString(script_t *script, char *string);
208
//unread the last token read from the script
209
void PS_UnreadLastToken(script_t *script);
210
//unread the given token
211
void PS_UnreadToken(script_t *script, token_t *token);
212
//returns the next character of the read white space, returns NULL if none
213
char PS_NextWhiteSpaceChar(script_t *script);
214
//remove any leading and trailing double quotes from the token
215
void StripDoubleQuotes(char *string);
216
//remove any leading and trailing single quotes from the token
217
void StripSingleQuotes(char *string);
218
//read a possible signed integer
219
signed long int ReadSignedInt(script_t *script);
220
//read a possible signed floating point number
221
double ReadSignedFloat(script_t *script);
222
//set an array with punctuations, NULL restores default C/C++ set
223
void SetScriptPunctuations(script_t *script, punctuation_t *p);
225
void SetScriptFlags(script_t *script, int flags);
227
int GetScriptFlags(script_t *script);
229
void ResetScript(script_t *script);
230
//returns true if at the end of the script
231
int EndOfScript(script_t *script);
232
//returns a pointer to the punctuation with the given number
233
char *PunctuationFromNum(script_t *script, int num);
234
//load a script from the given file at the given offset with the given length
235
script_t *LoadScriptFile(const char *filename);
236
//load a script from the given memory with the given length
237
script_t *LoadScriptMemory(char *ptr, int length, char *name);
239
void FreeScript(script_t *script);
240
//set the base folder to load files from
241
void PS_SetBaseFolder(char *path);
242
//print a script error with filename and line number
243
void QDECL ScriptError(script_t *script, char *str, ...);
244
//print a script warning with filename and line number
245
void QDECL ScriptWarning(script_t *script, char *str, ...);