00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #define BINARYNUMBERS
00034
00035 #define NUMBERVALUE
00036
00037 #define DOLLAR
00038
00039
00040 #define MAX_TOKEN 1024
00041
00042 #if defined(BSPC) && !defined(QDECL)
00043 #define QDECL
00044 #endif
00045
00046
00047
00048 #define SCFL_NOERRORS 0x0001
00049 #define SCFL_NOWARNINGS 0x0002
00050 #define SCFL_NOSTRINGWHITESPACES 0x0004
00051 #define SCFL_NOSTRINGESCAPECHARS 0x0008
00052 #define SCFL_PRIMITIVE 0x0010
00053 #define SCFL_NOBINARYNUMBERS 0x0020
00054 #define SCFL_NONUMBERVALUES 0x0040
00055
00056
00057 #define TT_STRING 1 // string
00058 #define TT_LITERAL 2 // literal
00059 #define TT_NUMBER 3 // number
00060 #define TT_NAME 4 // name
00061 #define TT_PUNCTUATION 5 // punctuation
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071 #define TT_DECIMAL 0x0008 // decimal number
00072 #define TT_HEX 0x0100 // hexadecimal number
00073 #define TT_OCTAL 0x0200 // octal number
00074 #ifdef BINARYNUMBERS
00075 #define TT_BINARY 0x0400 // binary number
00076 #endif //BINARYNUMBERS
00077 #define TT_FLOAT 0x0800 // floating point number
00078 #define TT_INTEGER 0x1000 // integer number
00079 #define TT_LONG 0x2000 // long number
00080 #define TT_UNSIGNED 0x4000 // unsigned number
00081
00082
00083 #define P_RSHIFT_ASSIGN 1
00084 #define P_LSHIFT_ASSIGN 2
00085 #define P_PARMS 3
00086 #define P_PRECOMPMERGE 4
00087
00088 #define P_LOGIC_AND 5
00089 #define P_LOGIC_OR 6
00090 #define P_LOGIC_GEQ 7
00091 #define P_LOGIC_LEQ 8
00092 #define P_LOGIC_EQ 9
00093 #define P_LOGIC_UNEQ 10
00094
00095 #define P_MUL_ASSIGN 11
00096 #define P_DIV_ASSIGN 12
00097 #define P_MOD_ASSIGN 13
00098 #define P_ADD_ASSIGN 14
00099 #define P_SUB_ASSIGN 15
00100 #define P_INC 16
00101 #define P_DEC 17
00102
00103 #define P_BIN_AND_ASSIGN 18
00104 #define P_BIN_OR_ASSIGN 19
00105 #define P_BIN_XOR_ASSIGN 20
00106 #define P_RSHIFT 21
00107 #define P_LSHIFT 22
00108
00109 #define P_POINTERREF 23
00110 #define P_CPP1 24
00111 #define P_CPP2 25
00112 #define P_MUL 26
00113 #define P_DIV 27
00114 #define P_MOD 28
00115 #define P_ADD 29
00116 #define P_SUB 30
00117 #define P_ASSIGN 31
00118
00119 #define P_BIN_AND 32
00120 #define P_BIN_OR 33
00121 #define P_BIN_XOR 34
00122 #define P_BIN_NOT 35
00123
00124 #define P_LOGIC_NOT 36
00125 #define P_LOGIC_GREATER 37
00126 #define P_LOGIC_LESS 38
00127
00128 #define P_REF 39
00129 #define P_COMMA 40
00130 #define P_SEMICOLON 41
00131 #define P_COLON 42
00132 #define P_QUESTIONMARK 43
00133
00134 #define P_PARENTHESESOPEN 44
00135 #define P_PARENTHESESCLOSE 45
00136 #define P_BRACEOPEN 46
00137 #define P_BRACECLOSE 47
00138 #define P_SQBRACKETOPEN 48
00139 #define P_SQBRACKETCLOSE 49
00140 #define P_BACKSLASH 50
00141
00142 #define P_PRECOMP 51
00143 #define P_DOLLAR 52
00144
00145
00146
00147
00148
00149 typedef struct punctuation_s
00150 {
00151 char *p;
00152 int n;
00153 struct punctuation_s *next;
00154 } punctuation_t;
00155
00156
00157 typedef struct token_s
00158 {
00159 char string[MAX_TOKEN];
00160 int type;
00161 int subtype;
00162 #ifdef NUMBERVALUE
00163 unsigned long int intvalue;
00164 long double floatvalue;
00165 #endif //NUMBERVALUE
00166 char *whitespace_p;
00167 char *endwhitespace_p;
00168 int line;
00169 int linescrossed;
00170 struct token_s *next;
00171 } token_t;
00172
00173
00174 typedef struct script_s
00175 {
00176 char filename[1024];
00177 char *buffer;
00178 char *script_p;
00179 char *end_p;
00180 char *lastscript_p;
00181 char *whitespace_p;
00182 char *endwhitespace_p;
00183 int length;
00184 int line;
00185 int lastline;
00186 int tokenavailable;
00187 int flags;
00188 punctuation_t *punctuations;
00189 punctuation_t **punctuationtable;
00190 token_t token;
00191 struct script_s *next;
00192 } script_t;
00193
00194
00195 int PS_ReadToken(script_t *script, token_t *token);
00196
00197 int PS_ExpectTokenString(script_t *script, char *string);
00198
00199 int PS_ExpectTokenType(script_t *script, int type, int subtype, token_t *token);
00200
00201 int PS_ExpectAnyToken(script_t *script, token_t *token);
00202
00203 int PS_CheckTokenString(script_t *script, char *string);
00204
00205 int PS_CheckTokenType(script_t *script, int type, int subtype, token_t *token);
00206
00207 int PS_SkipUntilString(script_t *script, char *string);
00208
00209 void PS_UnreadLastToken(script_t *script);
00210
00211 void PS_UnreadToken(script_t *script, token_t *token);
00212
00213 char PS_NextWhiteSpaceChar(script_t *script);
00214
00215 void StripDoubleQuotes(char *string);
00216
00217 void StripSingleQuotes(char *string);
00218
00219 signed long int ReadSignedInt(script_t *script);
00220
00221 long double ReadSignedFloat(script_t *script);
00222
00223 void SetScriptPunctuations(script_t *script, punctuation_t *p);
00224
00225 void SetScriptFlags(script_t *script, int flags);
00226
00227 int GetScriptFlags(script_t *script);
00228
00229 void ResetScript(script_t *script);
00230
00231 int EndOfScript(script_t *script);
00232
00233 char *PunctuationFromNum(script_t *script, int num);
00234
00235 script_t *LoadScriptFile(const char *filename);
00236
00237 script_t *LoadScriptMemory(char *ptr, int length, char *name);
00238
00239 void FreeScript(script_t *script);
00240
00241 void PS_SetBaseFolder(char *path);
00242
00243 void QDECL ScriptError(script_t *script, char *str, ...);
00244
00245 void QDECL ScriptWarning(script_t *script, char *str, ...);
00246
00247