Sun, 15 Jul 2012 18:56:26 +0300
Mainloop and onenter definitions are now written into separate buffers first and only written to file after state ends. Why? Zandronum seems to demand that mainloop definitions MUST be written right after any onenter one. This way, mainloop and onenter definitions can be written without this restriction in the script. Also now I have a cool uchar-buffer class :)
0 | 1 | /* |
2 | * botc source code | |
3 | * Copyright (C) 2012 Santeri `Dusk` Piippo | |
4 | * All rights reserved. | |
5 | * | |
6 | * Redistribution and use in source and binary forms, with or without | |
7 | * modification, are permitted provided that the following conditions are met: | |
8 | * | |
9 | * 1. Redistributions of source code must retain the above copyright notice, | |
10 | * this list of conditions and the following disclaimer. | |
11 | * 2. Redistributions in binary form must reproduce the above copyright notice, | |
12 | * this list of conditions and the following disclaimer in the documentation | |
13 | * and/or other materials provided with the distribution. | |
3 | 14 | * 3. Neither the name of the developer nor the names of its contributors may |
15 | * be used to endorse or promote products derived from this software without | |
16 | * specific prior written permission. | |
0 | 17 | * 4. Redistributions in any form must be accompanied by information on how to |
18 | * obtain complete source code for the software and any accompanying | |
19 | * software that uses the software. The source code must either be included | |
20 | * in the distribution or be available for no more than the cost of | |
21 | * distribution plus a nominal fee, and must be freely redistributable | |
22 | * under reasonable conditions. For an executable file, complete source | |
23 | * code means the source code for all modules it contains. It does not | |
24 | * include source code for modules or files that typically accompany the | |
25 | * major components of the operating system on which the executable file | |
26 | * runs. | |
27 | * | |
28 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
29 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
30 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
31 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | |
32 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
33 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
34 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
35 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
36 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
37 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
38 | * POSSIBILITY OF SUCH DAMAGE. | |
39 | */ | |
40 | ||
41 | #include <stdio.h> | |
42 | #include <stdlib.h> | |
43 | #include "string.h" | |
44 | #include "str.h" | |
45 | #include "common.h" | |
46 | #include "scriptreader.h" | |
47 | ||
19
66993500719f
Commands w/ arguments are now written correctly.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
48 | static bool IsWhitespace (char c) { |
0 | 49 | // These characters are invisible, thus considered whitespace |
50 | if (c <= 32 || c == 127 || c == 255) | |
51 | return true; | |
52 | ||
53 | return false; | |
54 | } | |
55 | ||
7
118d3d5db64f
Improved error handling; added parser warnings
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
56 | ScriptReader::ScriptReader (str path) { |
118d3d5db64f
Improved error handling; added parser warnings
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
57 | atnewline = false; |
118d3d5db64f
Improved error handling; added parser warnings
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
58 | filepath = path; |
2
bb2c45522eb6
Added event definitions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1
diff
changeset
|
59 | if (!(fp = fopen (path, "r"))) { |
7
118d3d5db64f
Improved error handling; added parser warnings
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
60 | error ("couldn't open %s for reading!\n", path.chars ()); |
2
bb2c45522eb6
Added event definitions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1
diff
changeset
|
61 | exit (1); |
bb2c45522eb6
Added event definitions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1
diff
changeset
|
62 | } |
0 | 63 | |
64 | curline = 1; | |
10
2c0f76090372
Restructured the command def parser, added parameter lists to definition file.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
9
diff
changeset
|
65 | curchar = 1; |
0 | 66 | pos = 0; |
67 | token = ""; | |
68 | } | |
69 | ||
1
f0c61c204bc8
Added support for #include directives, added basic header and statistics printing.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
70 | ScriptReader::~ScriptReader () { |
f0c61c204bc8
Added support for #include directives, added basic header and statistics printing.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
71 | fclose (fp); |
f0c61c204bc8
Added support for #include directives, added basic header and statistics printing.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
72 | } |
f0c61c204bc8
Added support for #include directives, added basic header and statistics printing.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
73 | |
0 | 74 | char ScriptReader::ReadChar () { |
75 | char* c = (char*)malloc (sizeof (char)); | |
76 | if (!fread (c, sizeof (char), 1, fp)) | |
77 | return 0; | |
78 | ||
7
118d3d5db64f
Improved error handling; added parser warnings
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
79 | // We're at a newline, thus next char read will begin the next line |
118d3d5db64f
Improved error handling; added parser warnings
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
80 | if (atnewline) { |
118d3d5db64f
Improved error handling; added parser warnings
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
81 | atnewline = false; |
118d3d5db64f
Improved error handling; added parser warnings
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
82 | curline++; |
10
2c0f76090372
Restructured the command def parser, added parameter lists to definition file.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
9
diff
changeset
|
83 | curchar = 0; // gets incremented to 1 |
7
118d3d5db64f
Improved error handling; added parser warnings
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
84 | } |
118d3d5db64f
Improved error handling; added parser warnings
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
85 | |
0 | 86 | if (c[0] == '\n') |
7
118d3d5db64f
Improved error handling; added parser warnings
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
87 | atnewline = true; |
0 | 88 | |
10
2c0f76090372
Restructured the command def parser, added parameter lists to definition file.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
9
diff
changeset
|
89 | curchar++; |
0 | 90 | return c[0]; |
91 | } | |
92 | ||
93 | // true if was found, false if not. | |
94 | bool ScriptReader::Next () { | |
95 | str tmp = ""; | |
96 | while (!feof (fp)) { | |
10
2c0f76090372
Restructured the command def parser, added parameter lists to definition file.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
9
diff
changeset
|
97 | c = ReadChar (); |
0 | 98 | |
11
f08abacb46c9
Removed extdelimeters member, said delimeters are always enabled now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
10
diff
changeset
|
99 | // Non-alphanumber characters (sans underscore) break the word too. |
f08abacb46c9
Removed extdelimeters member, said delimeters are always enabled now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
10
diff
changeset
|
100 | // If there was prior data, the delimeter pushes the cursor back so |
f08abacb46c9
Removed extdelimeters member, said delimeters are always enabled now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
10
diff
changeset
|
101 | // that the next character will be the same delimeter. If there isn't, |
f08abacb46c9
Removed extdelimeters member, said delimeters are always enabled now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
10
diff
changeset
|
102 | // the delimeter itself is included (and thus becomes a token itself.) |
f08abacb46c9
Removed extdelimeters member, said delimeters are always enabled now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
10
diff
changeset
|
103 | if ((c >= 33 && c <= 47) || |
f08abacb46c9
Removed extdelimeters member, said delimeters are always enabled now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
10
diff
changeset
|
104 | (c >= 58 && c <= 64) || |
f08abacb46c9
Removed extdelimeters member, said delimeters are always enabled now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
10
diff
changeset
|
105 | (c >= 91 && c <= 96 && c != '_') || |
f08abacb46c9
Removed extdelimeters member, said delimeters are always enabled now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
10
diff
changeset
|
106 | (c >= 123 && c <= 126)) { |
f08abacb46c9
Removed extdelimeters member, said delimeters are always enabled now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
10
diff
changeset
|
107 | if (tmp.len()) |
f08abacb46c9
Removed extdelimeters member, said delimeters are always enabled now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
10
diff
changeset
|
108 | fseek (fp, ftell (fp) - 1, SEEK_SET); |
f08abacb46c9
Removed extdelimeters member, said delimeters are always enabled now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
10
diff
changeset
|
109 | else |
f08abacb46c9
Removed extdelimeters member, said delimeters are always enabled now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
10
diff
changeset
|
110 | tmp += c; |
f08abacb46c9
Removed extdelimeters member, said delimeters are always enabled now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
10
diff
changeset
|
111 | break; |
8
c8bfa7e6ae1b
Commands are now read properly.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
7
diff
changeset
|
112 | } |
c8bfa7e6ae1b
Commands are now read properly.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
7
diff
changeset
|
113 | |
19
66993500719f
Commands w/ arguments are now written correctly.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
114 | if (IsWhitespace (c)) { |
0 | 115 | // Don't break if we haven't gathered anything yet. |
116 | if (tmp.len()) | |
117 | break; | |
118 | } else { | |
119 | tmp += c; | |
120 | } | |
121 | } | |
122 | ||
19
66993500719f
Commands w/ arguments are now written correctly.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
123 | // If we got nothing here, read failed. This should |
66993500719f
Commands w/ arguments are now written correctly.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
124 | // only hapen in the case of EOF. |
0 | 125 | if (!tmp.len()) { |
126 | token = ""; | |
127 | return false; | |
128 | } | |
129 | ||
130 | pos++; | |
131 | token = tmp; | |
132 | return true; | |
133 | } | |
134 | ||
135 | // Returns the next token without advancing the cursor. | |
136 | str ScriptReader::PeekNext () { | |
137 | // Store current position | |
138 | int cpos = ftell (fp); | |
139 | ||
140 | // Advance on the token. | |
141 | if (!Next ()) | |
142 | return ""; | |
143 | ||
144 | str tmp = token; | |
145 | ||
146 | // Restore position | |
147 | fseek (fp, cpos, SEEK_SET); | |
148 | pos--; | |
149 | ||
150 | return tmp; | |
151 | } | |
152 | ||
153 | void ScriptReader::Seek (unsigned int n, int origin) { | |
154 | switch (origin) { | |
155 | case SEEK_SET: | |
156 | fseek (fp, 0, SEEK_SET); | |
157 | pos = 0; | |
158 | break; | |
159 | case SEEK_CUR: | |
160 | break; | |
161 | case SEEK_END: | |
162 | printf ("ScriptReader::Seek: SEEK_END not yet supported.\n"); | |
163 | break; | |
164 | } | |
165 | ||
166 | for (unsigned int i = 0; i < n+1; i++) | |
167 | Next(); | |
168 | } | |
169 | ||
170 | void ScriptReader::MustNext (const char* c) { | |
171 | if (!Next()) { | |
172 | if (strlen (c)) | |
7
118d3d5db64f
Improved error handling; added parser warnings
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
173 | ParserError ("expected `%s`, reached end of file instead\n", c); |
0 | 174 | else |
7
118d3d5db64f
Improved error handling; added parser warnings
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
175 | ParserError ("expected a token, reached end of file instead\n"); |
0 | 176 | } |
177 | ||
178 | if (strlen (c) && token.compare (c) != 0) { | |
7
118d3d5db64f
Improved error handling; added parser warnings
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
179 | ParserError ("expected `%s`, got `%s` instead", c, token.chars()); |
0 | 180 | } |
181 | } | |
182 | ||
7
118d3d5db64f
Improved error handling; added parser warnings
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
183 | void ScriptReader::ParserError (const char* message, ...) { |
118d3d5db64f
Improved error handling; added parser warnings
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
184 | PERFORM_FORMAT (message, outmessage); |
118d3d5db64f
Improved error handling; added parser warnings
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
185 | ParserMessage ("\nParse error\n", outmessage); |
118d3d5db64f
Improved error handling; added parser warnings
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
186 | exit (1); |
118d3d5db64f
Improved error handling; added parser warnings
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
187 | } |
118d3d5db64f
Improved error handling; added parser warnings
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
188 | |
118d3d5db64f
Improved error handling; added parser warnings
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
189 | void ScriptReader::ParserWarning (const char* message, ...) { |
0 | 190 | PERFORM_FORMAT (message, outmessage); |
7
118d3d5db64f
Improved error handling; added parser warnings
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
191 | ParserMessage ("Warning: ", outmessage); |
118d3d5db64f
Improved error handling; added parser warnings
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
192 | } |
118d3d5db64f
Improved error handling; added parser warnings
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
193 | |
118d3d5db64f
Improved error handling; added parser warnings
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
194 | void ScriptReader::ParserMessage (const char* header, char* message) { |
10
2c0f76090372
Restructured the command def parser, added parameter lists to definition file.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
9
diff
changeset
|
195 | fprintf (stderr, "%sIn file %s, at line %u, col %u: %s\n", |
2c0f76090372
Restructured the command def parser, added parameter lists to definition file.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
9
diff
changeset
|
196 | header, filepath.chars(), curline, curchar, message); |
9
d279af9afd6d
Added proper string checking
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
197 | } |
d279af9afd6d
Added proper string checking
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
198 | |
12
1bdbfcca2fc6
MustString now behaves more like its siblings - sets token to result rather than returning it
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
199 | void ScriptReader::MustString () { |
9
d279af9afd6d
Added proper string checking
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
200 | MustNext ("\""); |
d279af9afd6d
Added proper string checking
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
201 | |
d279af9afd6d
Added proper string checking
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
202 | str string; |
d279af9afd6d
Added proper string checking
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
203 | // Keep reading characters until we find a terminating quote. |
d279af9afd6d
Added proper string checking
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
204 | while (1) { |
d279af9afd6d
Added proper string checking
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
205 | // can't end here! |
d279af9afd6d
Added proper string checking
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
206 | if (feof (fp)) |
d279af9afd6d
Added proper string checking
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
207 | ParserError ("unterminated string"); |
d279af9afd6d
Added proper string checking
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
208 | |
d279af9afd6d
Added proper string checking
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
209 | char c = ReadChar (); |
d279af9afd6d
Added proper string checking
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
210 | if (c == '"') |
d279af9afd6d
Added proper string checking
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
211 | break; |
d279af9afd6d
Added proper string checking
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
212 | |
d279af9afd6d
Added proper string checking
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
213 | string += c; |
d279af9afd6d
Added proper string checking
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
214 | } |
d279af9afd6d
Added proper string checking
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
215 | |
12
1bdbfcca2fc6
MustString now behaves more like its siblings - sets token to result rather than returning it
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
216 | token = string; |
10
2c0f76090372
Restructured the command def parser, added parameter lists to definition file.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
9
diff
changeset
|
217 | } |
2c0f76090372
Restructured the command def parser, added parameter lists to definition file.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
9
diff
changeset
|
218 | |
2c0f76090372
Restructured the command def parser, added parameter lists to definition file.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
9
diff
changeset
|
219 | void ScriptReader::MustNumber () { |
2c0f76090372
Restructured the command def parser, added parameter lists to definition file.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
9
diff
changeset
|
220 | MustNext (); |
2c0f76090372
Restructured the command def parser, added parameter lists to definition file.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
9
diff
changeset
|
221 | if (!token.isnumber()) |
2c0f76090372
Restructured the command def parser, added parameter lists to definition file.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
9
diff
changeset
|
222 | ParserError ("expected a number, got `%s`", token.chars()); |
2c0f76090372
Restructured the command def parser, added parameter lists to definition file.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
9
diff
changeset
|
223 | } |
2c0f76090372
Restructured the command def parser, added parameter lists to definition file.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
9
diff
changeset
|
224 | |
2c0f76090372
Restructured the command def parser, added parameter lists to definition file.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
9
diff
changeset
|
225 | void ScriptReader::MustBool () { |
2c0f76090372
Restructured the command def parser, added parameter lists to definition file.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
9
diff
changeset
|
226 | MustNext(); |
2c0f76090372
Restructured the command def parser, added parameter lists to definition file.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
9
diff
changeset
|
227 | if (!token.compare ("0") || !token.compare ("1") || |
2c0f76090372
Restructured the command def parser, added parameter lists to definition file.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
9
diff
changeset
|
228 | !token.compare ("true") || !token.compare ("false") || |
2c0f76090372
Restructured the command def parser, added parameter lists to definition file.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
9
diff
changeset
|
229 | !token.compare ("yes") || !token.compare ("no")) { |
2c0f76090372
Restructured the command def parser, added parameter lists to definition file.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
9
diff
changeset
|
230 | return; |
2c0f76090372
Restructured the command def parser, added parameter lists to definition file.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
9
diff
changeset
|
231 | } |
2c0f76090372
Restructured the command def parser, added parameter lists to definition file.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
9
diff
changeset
|
232 | |
2c0f76090372
Restructured the command def parser, added parameter lists to definition file.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
9
diff
changeset
|
233 | ParserError ("expected a boolean value, got `%s`", token.chars()); |
20
d7b13805d1e0
Added string table and support for string parameters in commands.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
19
diff
changeset
|
234 | } |
d7b13805d1e0
Added string table and support for string parameters in commands.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
19
diff
changeset
|
235 | |
d7b13805d1e0
Added string table and support for string parameters in commands.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
19
diff
changeset
|
236 | bool ScriptReader::BoolValue () { |
d7b13805d1e0
Added string table and support for string parameters in commands.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
19
diff
changeset
|
237 | return (!token.compare ("1") || !token.compare ("true") || !token.compare ("yes")); |
22
b48e10ca8832
Added rudimentary global var support
Teemu Piippo <crimsondusk64@gmail.com>
parents:
20
diff
changeset
|
238 | } |
b48e10ca8832
Added rudimentary global var support
Teemu Piippo <crimsondusk64@gmail.com>
parents:
20
diff
changeset
|
239 | |
b48e10ca8832
Added rudimentary global var support
Teemu Piippo <crimsondusk64@gmail.com>
parents:
20
diff
changeset
|
240 | void ScriptReader::MustValue (int type) { |
b48e10ca8832
Added rudimentary global var support
Teemu Piippo <crimsondusk64@gmail.com>
parents:
20
diff
changeset
|
241 | switch (type) { |
b48e10ca8832
Added rudimentary global var support
Teemu Piippo <crimsondusk64@gmail.com>
parents:
20
diff
changeset
|
242 | case RETURNVAL_INT: MustNumber (); break; |
b48e10ca8832
Added rudimentary global var support
Teemu Piippo <crimsondusk64@gmail.com>
parents:
20
diff
changeset
|
243 | case RETURNVAL_STRING: MustString (); break; |
b48e10ca8832
Added rudimentary global var support
Teemu Piippo <crimsondusk64@gmail.com>
parents:
20
diff
changeset
|
244 | case RETURNVAL_BOOLEAN: MustBool (); break; |
b48e10ca8832
Added rudimentary global var support
Teemu Piippo <crimsondusk64@gmail.com>
parents:
20
diff
changeset
|
245 | } |
0 | 246 | } |