| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
#define BINARYNUMBERS |
| 34 |
|
| 35 |
#define NUMBERVALUE |
| 36 |
|
| 37 |
#define DOLLAR |
| 38 |
|
| 39 |
|
| 40 |
#define MAX_TOKEN 1024 |
| 41 |
|
| 42 |
#if defined(BSPC) && !defined(QDECL) |
| 43 |
#define QDECL |
| 44 |
#endif |
| 45 |
|
| 46 |
|
| 47 |
|
| 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 |
| 55 |
|
| 56 |
|
| 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 |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
#define TT_DECIMAL 0x0008 // decimal number |
| 72 |
#define TT_HEX 0x0100 // hexadecimal number |
| 73 |
#define TT_OCTAL 0x0200 // octal number |
| 74 |
#ifdef BINARYNUMBERS |
| 75 |
#define TT_BINARY 0x0400 // binary number |
| 76 |
#endif |
| 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 |
|
| 82 |
|
| 83 |
#define P_RSHIFT_ASSIGN 1 |
| 84 |
#define P_LSHIFT_ASSIGN 2 |
| 85 |
#define P_PARMS 3 |
| 86 |
#define P_PRECOMPMERGE 4 |
| 87 |
|
| 88 |
#define P_LOGIC_AND 5 |
| 89 |
#define P_LOGIC_OR 6 |
| 90 |
#define P_LOGIC_GEQ 7 |
| 91 |
#define P_LOGIC_LEQ 8 |
| 92 |
#define P_LOGIC_EQ 9 |
| 93 |
#define P_LOGIC_UNEQ 10 |
| 94 |
|
| 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 |
| 100 |
#define P_INC 16 |
| 101 |
#define P_DEC 17 |
| 102 |
|
| 103 |
#define P_BIN_AND_ASSIGN 18 |
| 104 |
#define P_BIN_OR_ASSIGN 19 |
| 105 |
#define P_BIN_XOR_ASSIGN 20 |
| 106 |
#define P_RSHIFT 21 |
| 107 |
#define P_LSHIFT 22 |
| 108 |
|
| 109 |
#define P_POINTERREF 23 |
| 110 |
#define P_CPP1 24 |
| 111 |
#define P_CPP2 25 |
| 112 |
#define P_MUL 26 |
| 113 |
#define P_DIV 27 |
| 114 |
#define P_MOD 28 |
| 115 |
#define P_ADD 29 |
| 116 |
#define P_SUB 30 |
| 117 |
#define P_ASSIGN 31 |
| 118 |
|
| 119 |
#define P_BIN_AND 32 |
| 120 |
#define P_BIN_OR 33 |
| 121 |
#define P_BIN_XOR 34 |
| 122 |
#define P_BIN_NOT 35 |
| 123 |
|
| 124 |
#define P_LOGIC_NOT 36 |
| 125 |
#define P_LOGIC_GREATER 37 |
| 126 |
#define P_LOGIC_LESS 38 |
| 127 |
|
| 128 |
#define P_REF 39 |
| 129 |
#define P_COMMA 40 |
| 130 |
#define P_SEMICOLON 41 |
| 131 |
#define P_COLON 42 |
| 132 |
#define P_QUESTIONMARK 43 |
| 133 |
|
| 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 |
| 141 |
|
| 142 |
#define P_PRECOMP 51 |
| 143 |
#define P_DOLLAR 52 |
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
typedef struct punctuation_s |
| 150 |
{ |
| 151 |
char *p; |
| 152 |
int n; |
| 153 |
struct punctuation_s *next; |
| 154 |
} punctuation_t; |
| 155 |
|
| 156 |
|
| 157 |
typedef struct token_s |
| 158 |
{ |
| 159 |
char string[MAX_TOKEN]; |
| 160 |
int type; |
| 161 |
int subtype; |
| 162 |
#ifdef NUMBERVALUE |
| 163 |
unsigned long int intvalue; |
| 164 |
float floatvalue; |
| 165 |
#endif |
| 166 |
char *whitespace_p; |
| 167 |
char *endwhitespace_p; |
| 168 |
int line; |
| 169 |
int linescrossed; |
| 170 |
struct token_s *next; |
| 171 |
} token_t; |
| 172 |
|
| 173 |
|
| 174 |
typedef struct script_s |
| 175 |
{ |
| 176 |
char filename[1024]; |
| 177 |
char *buffer; |
| 178 |
char *script_p; |
| 179 |
char *end_p; |
| 180 |
char *lastscript_p; |
| 181 |
char *whitespace_p; |
| 182 |
char *endwhitespace_p; |
| 183 |
int length; |
| 184 |
int line; |
| 185 |
int lastline; |
| 186 |
int tokenavailable; |
| 187 |
int flags; |
| 188 |
punctuation_t *punctuations; |
| 189 |
punctuation_t **punctuationtable; |
| 190 |
token_t token; |
| 191 |
struct script_s *next; |
| 192 |
} script_t; |
| 193 |
|
| 194 |
|
| 195 |
int PS_ReadToken(script_t *script, token_t *token); |
| 196 |
|
| 197 |
int PS_ExpectTokenString(script_t *script, char *string); |
| 198 |
|
| 199 |
int PS_ExpectTokenType(script_t *script, int type, int subtype, token_t *token); |
| 200 |
|
| 201 |
int PS_ExpectAnyToken(script_t *script, token_t *token); |
| 202 |
|
| 203 |
int PS_CheckTokenString(script_t *script, char *string); |
| 204 |
|
| 205 |
int PS_CheckTokenType(script_t *script, int type, int subtype, token_t *token); |
| 206 |
|
| 207 |
int PS_SkipUntilString(script_t *script, char *string); |
| 208 |
|
| 209 |
void PS_UnreadLastToken(script_t *script); |
| 210 |
|
| 211 |
void PS_UnreadToken(script_t *script, token_t *token); |
| 212 |
|
| 213 |
char PS_NextWhiteSpaceChar(script_t *script); |
| 214 |
|
| 215 |
void StripDoubleQuotes(char *string); |
| 216 |
|
| 217 |
void StripSingleQuotes(char *string); |
| 218 |
|
| 219 |
signed long int ReadSignedInt(script_t *script); |
| 220 |
|
| 221 |
float ReadSignedFloat(script_t *script); |
| 222 |
|
| 223 |
void SetScriptPunctuations(script_t *script, punctuation_t *p); |
| 224 |
|
| 225 |
void SetScriptFlags(script_t *script, int flags); |
| 226 |
|
| 227 |
int GetScriptFlags(script_t *script); |
| 228 |
|
| 229 |
void ResetScript(script_t *script); |
| 230 |
|
| 231 |
int EndOfScript(script_t *script); |
| 232 |
|
| 233 |
char *PunctuationFromNum(script_t *script, int num); |
| 234 |
|
| 235 |
script_t *LoadScriptFile(const char *filename); |
| 236 |
|
| 237 |
script_t *LoadScriptMemory(char *ptr, int length, char *name); |
| 238 |
|
| 239 |
void FreeScript(script_t *script); |
| 240 |
|
| 241 |
void PS_SetBaseFolder(char *path); |
| 242 |
|
| 243 |
void QDECL ScriptError(script_t *script, char *str, ...) Q_PRINTF_FUNC(2, 3); |
| 244 |
|
| 245 |
void QDECL ScriptWarning(script_t *script, char *str, ...) Q_PRINTF_FUNC(2, 3); |
| 246 |
|
| 247 |
|