|
dvander@374
|
1 |
/** |
|
ds@475
|
2 |
* vim: set ts=4 : |
|
ds@1330
|
3 |
* ============================================================================= |
|
ds@1947
|
4 |
* SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved. |
|
ds@1330
|
5 |
* ============================================================================= |
|
ds@1330
|
6 |
* |
|
ds@1330
|
7 |
* This file is part of the SourceMod/SourcePawn SDK. |
|
dvander@374
|
8 |
* |
|
ds@1330
|
9 |
* This program is free software; you can redistribute it and/or modify it under |
|
ds@1330
|
10 |
* the terms of the GNU General Public License, version 3.0, as published by the |
|
ds@1330
|
11 |
* Free Software Foundation. |
|
ds@1330
|
12 |
* |
|
ds@1330
|
13 |
* This program is distributed in the hope that it will be useful, but WITHOUT |
|
ds@1330
|
14 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|
ds@1330
|
15 |
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
|
ds@1330
|
16 |
* details. |
|
ds@1330
|
17 |
* |
|
ds@1330
|
18 |
* You should have received a copy of the GNU General Public License along with |
|
ds@1330
|
19 |
* this program. If not, see <http://www.gnu.org/licenses/>. |
|
ds@1330
|
20 |
* |
|
ds@1330
|
21 |
* As a special exception, AlliedModders LLC gives you permission to link the |
|
ds@1330
|
22 |
* code of this program (as well as its derivative works) to "Half-Life 2," the |
|
ds@1330
|
23 |
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software |
|
ds@1330
|
24 |
* by the Valve Corporation. You must obey the GNU General Public License in |
|
ds@1330
|
25 |
* all respects for all other code used. Additionally, AlliedModders LLC grants |
|
ds@1330
|
26 |
* this exception to all derivative works. AlliedModders LLC defines further |
|
ds@1330
|
27 |
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), |
|
ds@1330
|
28 |
* or <http://www.sourcemod.net/license.php>. |
|
dvander@374
|
29 |
* |
|
dvander@374
|
30 |
* Version: $Id$ |
|
dvander@374
|
31 |
*/ |
|
dvander@374
|
32 |
|
|
dvander@345
|
33 |
#if defined _textparse_included |
|
dvander@345
|
34 |
#endinput |
|
dvander@345
|
35 |
#endif |
|
dvander@345
|
36 |
#define _textparse_included |
|
dvander@345
|
37 |
|
|
dvander@345
|
38 |
|
|
dvander@345
|
39 |
/******************************** |
|
dvander@345
|
40 |
* Everything below describes the SMC Parse, or "SourceMod Configuration" format. |
|
dvander@345
|
41 |
* This parser is entirely event based. You must hook events to receive data. |
|
dvander@345
|
42 |
* The file format itself is nearly identical to Valve's KeyValues format. |
|
dvander@345
|
43 |
********************************/ |
|
dvander@345
|
44 |
|
|
dvander@619
|
45 |
/** |
|
dvander@619
|
46 |
* Parse result directive. |
|
dvander@619
|
47 |
*/ |
|
dvander@345
|
48 |
enum SMCResult |
|
dvander@345
|
49 |
{ |
|
ds@475
|
50 |
SMCParse_Continue, /**< Continue parsing */ |
|
ds@475
|
51 |
SMCParse_Halt, /**< Stop parsing here */ |
|
ds@475
|
52 |
SMCParse_HaltFail /**< Stop parsing and return failure */ |
|
dvander@345
|
53 |
}; |
|
dvander@345
|
54 |
|
|
dvander@619
|
55 |
/** |
|
dvander@619
|
56 |
* Parse error codes. |
|
dvander@619
|
57 |
*/ |
|
dvander@345
|
58 |
enum SMCError |
|
dvander@345
|
59 |
{ |
|
ds@475
|
60 |
SMCError_Okay = 0, /**< No error */ |
|
ds@475
|
61 |
SMCError_StreamOpen, /**< Stream failed to open */ |
|
ds@475
|
62 |
SMCError_StreamError, /**< The stream died... somehow */ |
|
ds@475
|
63 |
SMCError_Custom, /**< A custom handler threw an error */ |
|
ds@475
|
64 |
SMCError_InvalidSection1, /**< A section was declared without quotes, and had extra tokens */ |
|
ds@475
|
65 |
SMCError_InvalidSection2, /**< A section was declared without any header */ |
|
ds@475
|
66 |
SMCError_InvalidSection3, /**< A section ending was declared with too many unknown tokens */ |
|
ds@475
|
67 |
SMCError_InvalidSection4, /**< A section ending has no matching beginning */ |
|
ds@475
|
68 |
SMCError_InvalidSection5, /**< A section beginning has no matching ending */ |
|
ds@475
|
69 |
SMCError_InvalidTokens, /**< There were too many unidentifiable strings on one line */ |
|
ds@475
|
70 |
SMCError_TokenOverflow, /**< The token buffer overflowed */ |
|
ds@475
|
71 |
SMCError_InvalidProperty1, /**< A property was declared outside of any section */ |
|
dvander@345
|
72 |
}; |
|
dvander@345
|
73 |
|
|
dvander@345
|
74 |
/** |
|
dvander@345
|
75 |
* Creates a new SMC file format parser. This is used to set parse hooks. |
|
dvander@345
|
76 |
* |
|
dvander@345
|
77 |
* @return A new Handle to an SMC Parse structure. |
|
dvander@345
|
78 |
*/ |
|
dvander@364
|
79 |
native Handle:SMC_CreateParser(); |
|
dvander@345
|
80 |
|
|
dvander@345
|
81 |
/** |
|
dvander@345
|
82 |
* Parses an SMC file. |
|
dvander@345
|
83 |
* |
|
ds@475
|
84 |
* @param smc A Handle to an SMC Parse structure. |
|
ds@475
|
85 |
* @param file A string containing the file path. |
|
ds@475
|
86 |
* @param line An optional by reference cell to store the last line number read. |
|
ds@475
|
87 |
* @param col An optional by reference cell to store the last column number read. |
|
ds@475
|
88 |
* @return An SMCParseError result. |
|
ds@475
|
89 |
* @error Invalid or corrupt Handle. |
|
dvander@345
|
90 |
*/ |
|
dvander@345
|
91 |
native SMCError:SMC_ParseFile(Handle:smc, const String:file[], &line=0, &col=0); |
|
dvander@345
|
92 |
|
|
dvander@345
|
93 |
/** |
|
dvander@345
|
94 |
* Gets an error string for an SMCError code. |
|
dvander@345
|
95 |
* @note SMCError_Okay returns false. |
|
dvander@345
|
96 |
* @note SMCError_Custom (which is thrown on SMCParse_HaltFail) returns false. |
|
dvander@345
|
97 |
* |
|
ds@475
|
98 |
* @param error The SMCParseError code. |
|
ds@475
|
99 |
* @param buffer A string buffer for the error (contents undefined on failure). |
|
ds@475
|
100 |
* @param buf_max The maximum size of the buffer. |
|
ds@475
|
101 |
* @return True on success, false otherwise. |
|
dvander@345
|
102 |
*/ |
|
dvander@345
|
103 |
native bool:SMC_GetErrorString(SMCError:error, String:buffer[], buf_max); |
|
dvander@345
|
104 |
|
|
dvander@345
|
105 |
/** |
|
dvander@345
|
106 |
* Called when parsing is started. |
|
dvander@345
|
107 |
* |
|
dvander@345
|
108 |
* @param smc The SMC Parse Handle. |
|
dvander@345
|
109 |
* @noreturn |
|
dvander@345
|
110 |
*/ |
|
dvander@345
|
111 |
functag SMC_ParseStart public(Handle:smc); |
|
dvander@345
|
112 |
|
|
dvander@345
|
113 |
/** |
|
dvander@345
|
114 |
* Sets the SMC_ParseStart function of a parse Handle. |
|
dvander@345
|
115 |
* |
|
ds@475
|
116 |
* @param smc Handle to an SMC Parse. |
|
ds@475
|
117 |
* @param func SMC_ParseStart function. |
|
dvander@345
|
118 |
* @noreturn |
|
ds@475
|
119 |
* @error Invalid or corrupt Handle. |
|
dvander@345
|
120 |
*/ |
|
dvander@345
|
121 |
native SMC_SetParseStart(Handle:smc, SMC_ParseStart:func); |
|
dvander@345
|
122 |
|
|
dvander@345
|
123 |
/** |
|
dvander@345
|
124 |
* Called when parsing is halted. |
|
dvander@345
|
125 |
* |
|
dvander@345
|
126 |
* @param smc The SMC Parse Handle. |
|
ds@475
|
127 |
* @param halted True if abnormally halted, false otherwise. |
|
ds@475
|
128 |
* @param failed True if parsing failed, false otherwise. |
|
dvander@345
|
129 |
* @noreturn |
|
dvander@345
|
130 |
*/ |
|
dvander@345
|
131 |
functag SMC_ParseEnd public(Handle:smc, bool:halted, bool:failed); |
|
dvander@345
|
132 |
|
|
dvander@345
|
133 |
/** |
|
dvander@345
|
134 |
* Sets the SMC_ParseEnd of a parse handle. |
|
dvander@345
|
135 |
* |
|
ds@475
|
136 |
* @param smc Handle to an SMC Parse. |
|
ds@475
|
137 |
* @param func SMC_ParseEnd function. |
|
dvander@345
|
138 |
* @noreturn |
|
ds@475
|
139 |
* @error Invalid or corrupt Handle. |
|
dvander@345
|
140 |
*/ |
|
dvander@345
|
141 |
native SMC_SetParseEnd(Handle:smc, SMC_ParseEnd:func); |
|
dvander@345
|
142 |
|
|
dvander@345
|
143 |
/** |
|
dvander@345
|
144 |
* Called when the parser is entering a new section or sub-section. |
|
dvander@345
|
145 |
* @note Enclosing quotes are always stripped. |
|
dvander@345
|
146 |
* |
|
dvander@345
|
147 |
* @param smc The SMC Parse Handle. |
|
dvander@345
|
148 |
* @param name String containing section name. |
|
dvander@345
|
149 |
* @param opt_quotes True if the section name was quote-enclosed in the file. |
|
dvander@345
|
150 |
* @return An SMCResult action to take. |
|
dvander@345
|
151 |
*/ |
|
dvander@345
|
152 |
functag SMC_NewSection SMCResult:public(Handle:smc, const String:name[], bool:opt_quotes); |
|
dvander@345
|
153 |
|
|
dvander@345
|
154 |
/** |
|
dvander@345
|
155 |
* Called when the parser finds a new key/value pair. |
|
dvander@345
|
156 |
* @note Enclosing quotes are always stripped. |
|
dvander@345
|
157 |
* |
|
dvander@345
|
158 |
* @param smc The SMC Parse Handle. |
|
dvander@345
|
159 |
* @param key String containing key name. |
|
dvander@345
|
160 |
* @param value String containing value name. |
|
dvander@345
|
161 |
* @param key_quotes Whether or not the key was enclosed in quotes. |
|
dvander@345
|
162 |
* @param value_quotes Whether or not the value was enclosed in quotes. |
|
dvander@345
|
163 |
* @return An SMCResult action to take. |
|
dvander@345
|
164 |
*/ |
|
dvander@345
|
165 |
functag SMC_KeyValue SMCResult:public(Handle:smc, const String:key[], const String:value[], bool:key_quotes, bool:value_quotes); |
|
dvander@345
|
166 |
|
|
dvander@345
|
167 |
/** |
|
dvander@345
|
168 |
* Called when the parser finds the end of the current section. |
|
dvander@345
|
169 |
* |
|
dvander@345
|
170 |
* @param smc The SMC Parse Handle. |
|
dvander@345
|
171 |
* @return An SMCResult action to take. |
|
dvander@345
|
172 |
*/ |
|
dvander@345
|
173 |
functag SMC_EndSection SMCResult:public(Handle:smc); |
|
dvander@345
|
174 |
|
|
dvander@345
|
175 |
/** |
|
dvander@345
|
176 |
* Sets the three main reader functions. |
|
dvander@345
|
177 |
* |
|
dvander@345
|
178 |
* @param smc An SMC parse Handle. |
|
dvander@345
|
179 |
* @param ns An SMC_NewSection function pointer. |
|
dvander@345
|
180 |
* @param kv An SMC_KeyValue function pointer. |
|
dvander@345
|
181 |
* @param es An SMC_EndSection function pointer. |
|
dvander@345
|
182 |
* @noreturn |
|
dvander@345
|
183 |
*/ |
|
dvander@345
|
184 |
native SMC_SetReaders(Handle:smc, SMC_NewSection:ns, SMC_KeyValue:kv, SMC_EndSection:es); |
|
dvander@345
|
185 |
|
|
dvander@345
|
186 |
/** |
|
dvander@345
|
187 |
* Called whenever a raw line is read. |
|
dvander@345
|
188 |
* |
|
dvander@345
|
189 |
* @param smc The SMC Parse Handle. |
|
dvander@345
|
190 |
* @param line A string containing the raw line from the file. |
|
dvander@345
|
191 |
* @param lineno The line number it occurs on. |
|
dvander@345
|
192 |
* @return An SMCResult action to take. |
|
dvander@345
|
193 |
*/ |
|
dvander@345
|
194 |
functag SMC_RawLine SMCResult:public(Handle:smc, const String:line[], lineno); |
|
dvander@345
|
195 |
|
|
dvander@345
|
196 |
/** |
|
dvander@345
|
197 |
* Sets a raw line reader on an SMC parser Handle. |
|
dvander@345
|
198 |
* |
|
ds@475
|
199 |
* @param smc Handle to an SMC Parse. |
|
ds@475
|
200 |
* @param func SMC_RawLine function. |
|
dvander@345
|
201 |
* @noreturn |
|
dvander@345
|
202 |
*/ |
|
faluco@427
|
203 |
native SMC_SetRawLine(Handle:smc, SMC_RawLine:func); |