1 /* 2 Copyright (C) 1997-2001 Id Software, Inc. 3 4 This program is free software; you can redistribute it and/or 5 modify it under the terms of the GNU General Public License 6 as published by the Free Software Foundation; either version 2 7 of the License, or (at your option) any later version. 8 9 This program is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 13 See the GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program; if not, write to the Free Software 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 */ 19 20 // 21 // parse.h 22 // 23 24 /* 25 ============================================================================== 26 27 PARSE SESSIONS 28 29 ============================================================================== 30 */ 31 32 #define MAX_PARSE_SESSIONS 256 33 #define MAX_PS_TOKCHARS 512 34 35 // PS_Parse* flags 36 enum { 37 PSF_ALLOW_NEWLINES = 1 << 0, // Allow token parsing to go onto the next line 38 PSF_CONVERT_NEWLINE = 1 << 1, // Convert newline characters in quoted tokens to their escape character 39 PSF_TO_LOWER = 1 << 2, // Lower-case the token before returning 40 PSF_WARNINGS_AS_ERRORS = 1 << 3, // Treat all warnings as errors 41 }; 42 43 // PS_ParseDataType types 44 enum { 45 PSDT_CHAR, 46 PSDT_BOOLEAN, 47 PSDT_BYTE, 48 PSDT_DOUBLE, 49 PSDT_FLOAT, 50 PSDT_INTEGER, 51 PSDT_UINTEGER, 52 }; 53 54 // Session properties 55 enum { 56 PSP_COMMENT_BLOCK = 1 << 0, // Treat "/*" "*/" as block-comment marker 57 PSP_COMMENT_LINE = 1 << 1, // Treat "//" as a line-comment marker 58 PSP_COMMENT_POUND = 1 << 2, // Treat "#" as a line-comment marker 59 }; 60 61 #define PSP_COMMENT_MASK (PSP_COMMENT_BLOCK|PSP_COMMENT_LINE|PSP_COMMENT_POUND) 62 63 // Session struct 64 typedef struct parse_s { 65 uint32 currentCol; 66 uint32 currentLine; 67 char currentToken[MAX_PS_TOKCHARS]; 68 69 char *dataPtr; 70 char *dataPtrLast; 71 qBool inUse; 72 73 uint32 numErrors; 74 uint32 numWarnings; 75 76 uint32 properties; 77 } parse_t; 78 79 // Session handling 80 parse_t *PS_StartSession (char *dataPtr, uint32 properties); 81 void PS_EndSession (parse_t *ps); 82 83 // Error handling 84 void PS_AddErrorCount (parse_t *ps, uint32 *errors, uint32 *warnings); // Adds 85 void PS_GetErrorCount (parse_t *ps, uint32 *errors, uint32 *warnings); // Sets 86 void PS_GetPosition (parse_t *ps, uint32 *line, uint32 *col); 87 88 // Parsers 89 qBool PS_ParseToken (parse_t *ps, uint32 flags, char **target); 90 void PS_UndoParse (parse_t *ps); 91 void PS_SkipLine (parse_t *ps); 92 qBool PS_ParseDataType (parse_t *ps, uint32 flags, uint32 dataType, void *target, uint32 numVecs); 93