Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

l_script.h

Go to the documentation of this file.
00001 /*
00002 ===========================================================================
00003 Copyright (C) 1999-2005 Id Software, Inc.
00004 
00005 This file is part of Quake III Arena source code.
00006 
00007 Quake III Arena source code is free software; you can redistribute it
00008 and/or modify it under the terms of the GNU General Public License as
00009 published by the Free Software Foundation; either version 2 of the License,
00010 or (at your option) any later version.
00011 
00012 Quake III Arena source code is distributed in the hope that it will be
00013 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 GNU General Public License for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Foobar; if not, write to the Free Software
00019 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00020 ===========================================================================
00021 */
00022 
00023 /*****************************************************************************
00024  * name:        l_script.h
00025  *
00026  * desc:        lexicographical parser
00027  *
00028  * $Archive: /source/code/botlib/l_script.h $
00029  *
00030  *****************************************************************************/
00031 
00032 //undef if binary numbers of the form 0b... or 0B... are not allowed
00033 #define BINARYNUMBERS
00034 //undef if not using the token.intvalue and token.floatvalue
00035 #define NUMBERVALUE
00036 //use dollar sign also as punctuation
00037 #define DOLLAR
00038 
00039 //maximum token length
00040 #define MAX_TOKEN                   1024
00041 
00042 #if defined(BSPC) && !defined(QDECL)
00043 #define QDECL
00044 #endif
00045 
00046 
00047 //script flags
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 //token types
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 //string sub type
00064 //---------------
00065 //      the length of the string
00066 //literal sub type
00067 //----------------
00068 //      the ASCII code of the literal
00069 //number sub type
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 //punctuation sub type
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 //name sub type
00145 //-------------
00146 //      the length of the name
00147 
00148 //punctuation
00149 typedef struct punctuation_s
00150 {
00151     char *p;                        //punctuation character(s)
00152     int n;                          //punctuation indication
00153     struct punctuation_s *next;     //next punctuation
00154 } punctuation_t;
00155 
00156 //token
00157 typedef struct token_s
00158 {
00159     char string[MAX_TOKEN];         //available token
00160     int type;                       //last read token type
00161     int subtype;                    //last read token sub type
00162 #ifdef NUMBERVALUE
00163     unsigned long int intvalue; //integer value
00164     long double floatvalue;         //floating point value
00165 #endif //NUMBERVALUE
00166     char *whitespace_p;             //start of white space before token
00167     char *endwhitespace_p;          //start of white space before token
00168     int line;                       //line the token was on
00169     int linescrossed;               //lines crossed in white space
00170     struct token_s *next;           //next token in chain
00171 } token_t;
00172 
00173 //script file
00174 typedef struct script_s
00175 {
00176     char filename[1024];            //file name of the script
00177     char *buffer;                   //buffer containing the script
00178     char *script_p;                 //current pointer in the script
00179     char *end_p;                    //pointer to the end of the script
00180     char *lastscript_p;             //script pointer before reading token
00181     char *whitespace_p;             //begin of the white space
00182     char *endwhitespace_p;          //end of the white space
00183     int length;                     //length of the script in bytes
00184     int line;                       //current line in script
00185     int lastline;                   //line before reading token
00186     int tokenavailable;             //set by UnreadLastToken
00187     int flags;                      //several script flags
00188     punctuation_t *punctuations;    //the punctuations used in the script
00189     punctuation_t **punctuationtable;
00190     token_t token;                  //available token
00191     struct script_s *next;          //next script in a chain
00192 } script_t;
00193 
00194 //read a token from the script
00195 int PS_ReadToken(script_t *script, token_t *token);
00196 //expect a certain token
00197 int PS_ExpectTokenString(script_t *script, char *string);
00198 //expect a certain token type
00199 int PS_ExpectTokenType(script_t *script, int type, int subtype, token_t *token);
00200 //expect a token
00201 int PS_ExpectAnyToken(script_t *script, token_t *token);
00202 //returns true when the token is available
00203 int PS_CheckTokenString(script_t *script, char *string);
00204 //returns true an reads the token when a token with the given type is available
00205 int PS_CheckTokenType(script_t *script, int type, int subtype, token_t *token);
00206 //skip tokens until the given token string is read
00207 int PS_SkipUntilString(script_t *script, char *string);
00208 //unread the last token read from the script
00209 void PS_UnreadLastToken(script_t *script);
00210 //unread the given token
00211 void PS_UnreadToken(script_t *script, token_t *token);
00212 //returns the next character of the read white space, returns NULL if none
00213 char PS_NextWhiteSpaceChar(script_t *script);
00214 //remove any leading and trailing double quotes from the token
00215 void StripDoubleQuotes(char *string);
00216 //remove any leading and trailing single quotes from the token
00217 void StripSingleQuotes(char *string);
00218 //read a possible signed integer
00219 signed long int ReadSignedInt(script_t *script);
00220 //read a possible signed floating point number
00221 long double ReadSignedFloat(script_t *script);
00222 //set an array with punctuations, NULL restores default C/C++ set
00223 void SetScriptPunctuations(script_t *script, punctuation_t *p);
00224 //set script flags
00225 void SetScriptFlags(script_t *script, int flags);
00226 //get script flags
00227 int GetScriptFlags(script_t *script);
00228 //reset a script
00229 void ResetScript(script_t *script);
00230 //returns true if at the end of the script
00231 int EndOfScript(script_t *script);
00232 //returns a pointer to the punctuation with the given number
00233 char *PunctuationFromNum(script_t *script, int num);
00234 //load a script from the given file at the given offset with the given length
00235 script_t *LoadScriptFile(const char *filename);
00236 //load a script from the given memory with the given length
00237 script_t *LoadScriptMemory(char *ptr, int length, char *name);
00238 //free a script
00239 void FreeScript(script_t *script);
00240 //set the base folder to load files from
00241 void PS_SetBaseFolder(char *path);
00242 //print a script error with filename and line number
00243 void QDECL ScriptError(script_t *script, char *str, ...);
00244 //print a script warning with filename and line number
00245 void QDECL ScriptWarning(script_t *script, char *str, ...);
00246 
00247 

Generated on Thu Aug 25 12:37:13 2005 for Quake III Arena by  doxygen 1.3.9.1