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 <stdarg.h> | |
45 | #include "str.h" | |
46 | #include "common.h" | |
47 | ||
48 | #define ITERATE_STRING(u) for (unsigned int u = 0; u < strlen (text); u++) | |
49 | ||
50 | // ============================================================================ | |
51 | // vdynformat: Try to write to a formatted string with size bytes first, if | |
52 | // that fails, double the size and keep recursing until it works. | |
53 | char* vdynformat (const char* c, va_list v, unsigned int size) { | |
54 | char* buffer = new char[size]; | |
55 | int r = vsnprintf (buffer, size-1, c, v); | |
56 | if (r > (int)size-1 || r < 0) { | |
57 | delete buffer; | |
58 | buffer = vdynformat (c, v, size*2); | |
59 | } | |
60 | return buffer; | |
61 | } | |
62 | ||
63 | // ============================================================================ | |
64 | str::str () { | |
65 | text = new char[1]; | |
66 | clear(); | |
67 | alloclen = strlen (text); | |
68 | } | |
69 | ||
70 | str::str (const char* c) { | |
71 | text = new char[1]; | |
72 | clear (); | |
73 | alloclen = strlen (text); | |
74 | append (c); | |
75 | } | |
76 | ||
77 | str::str (char c) { | |
78 | text = new char[1]; | |
79 | clear (); | |
80 | alloclen = strlen (text); | |
81 | append (c); | |
82 | } | |
83 | ||
84 | // ============================================================================ | |
85 | void str::clear () { | |
86 | delete text; | |
87 | text = new char[1]; | |
88 | text[0] = '\0'; | |
89 | curs = 0; | |
90 | } | |
91 | ||
92 | unsigned int str::len () {return strlen(text);} | |
93 | ||
94 | // ============================================================================ | |
95 | void str::resize (unsigned int len) { | |
96 | unsigned int oldlen = strlen (text); | |
97 | char* oldtext = new char[oldlen]; | |
98 | strncpy (oldtext, text, oldlen); | |
99 | ||
100 | delete text; | |
101 | text = new char[len+1]; | |
2
bb2c45522eb6
Added event definitions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
102 | for (unsigned int u = 0; u < len+1; u++) |
bb2c45522eb6
Added event definitions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
103 | text[u] = 0; |
0 | 104 | strncpy (text, oldtext, len); |
105 | ||
106 | alloclen = len; | |
107 | } | |
108 | ||
109 | // ============================================================================ | |
110 | void str::dump () { | |
111 | for (unsigned int u = 0; u <= alloclen; u++) | |
2
bb2c45522eb6
Added event definitions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
112 | printf ("\t%u. %u (%c)\n", u, text[u], text[u]); |
0 | 113 | } |
114 | ||
115 | // ============================================================================ | |
116 | // Adds a new character at the end of the string. | |
117 | void str::append (char c) { | |
118 | // Out of space, thus resize | |
119 | if (curs == alloclen) | |
120 | resize (alloclen+1); | |
121 | text[curs] = c; | |
122 | curs++; | |
123 | } | |
124 | ||
125 | void str::append (const char* c) { | |
126 | resize (alloclen + strlen (c)); | |
127 | ||
128 | for (unsigned int u = 0; u < strlen (c); u++) { | |
129 | if (c[u] != 0) | |
130 | append (c[u]); | |
131 | } | |
132 | } | |
133 | ||
134 | void str::append (str c) { | |
135 | append (c.chars()); | |
136 | } | |
137 | ||
138 | // ============================================================================ | |
139 | void str::appendformat (const char* c, ...) { | |
140 | va_list v; | |
141 | ||
142 | va_start (v, c); | |
143 | char* buf = vdynformat (c, v, 256); | |
144 | va_end (v); | |
145 | ||
146 | append (buf); | |
147 | } | |
148 | ||
149 | void str::appendformat (str c, ...) { | |
150 | va_list v; | |
151 | ||
152 | va_start (v, c); | |
153 | char* buf = vdynformat (c.chars(), v, 256); | |
154 | va_end (v); | |
155 | ||
156 | append (buf); | |
157 | } | |
158 | ||
159 | // ============================================================================ | |
160 | char* str::chars () { | |
161 | return text; | |
162 | } | |
163 | ||
164 | // ============================================================================ | |
165 | unsigned int str::first (const char* c, unsigned int a) { | |
166 | unsigned int r = 0; | |
167 | unsigned int index = 0; | |
168 | for (; a < alloclen; a++) { | |
169 | if (text[a] == c[r]) { | |
170 | if (r == 0) | |
171 | index = a; | |
172 | ||
173 | r++; | |
174 | if (r == strlen (c)) | |
175 | return index; | |
176 | } else { | |
177 | if (r != 0) { | |
178 | // If the string sequence broke at this point, we need to | |
179 | // check this character again, for a new sequence just | |
180 | // might start right here. | |
181 | a--; | |
182 | } | |
183 | ||
184 | r = 0; | |
185 | } | |
186 | } | |
187 | ||
188 | return len (); | |
189 | } | |
190 | ||
191 | // ============================================================================ | |
192 | unsigned int str::last (const char* c, int a) { | |
193 | if (a == -1) | |
194 | a = len(); | |
195 | ||
196 | int max = strlen (c)-1; | |
197 | ||
198 | int r = max; | |
199 | for (; a >= 0; a--) { | |
200 | if (text[a] == c[r]) { | |
201 | r--; | |
202 | if (r == -1) | |
203 | return a; | |
204 | } else { | |
205 | if (r != max) | |
206 | a++; | |
207 | ||
208 | r = max; | |
209 | } | |
210 | } | |
211 | ||
212 | return len (); | |
213 | } | |
214 | ||
215 | // ============================================================================ | |
216 | str str::substr (unsigned int a, unsigned int b) { | |
217 | if (a > len()) a = len(); | |
218 | if (b > len()) b = len(); | |
219 | ||
220 | if (b == a) | |
221 | return ""; | |
222 | ||
223 | if (b < a) { | |
224 | printf ("str::substr: indices %u and %u given, should be the other way around, swapping..\n", a, b); | |
225 | ||
226 | // Swap the variables | |
227 | unsigned int c = a; | |
228 | a = b; | |
229 | b = c; | |
230 | } | |
231 | ||
232 | char* s = new char[b-a]; | |
233 | strncpy (s, text+a, b-a); | |
234 | return str(s); | |
235 | } | |
236 | ||
237 | // ============================================================================ | |
238 | void str::remove (unsigned int idx, unsigned int dellen) { | |
239 | str s1 = substr (0, idx); | |
240 | str s2 = substr (idx + dellen, len()); | |
241 | ||
242 | clear(); | |
243 | ||
244 | append (s1); | |
245 | append (s2); | |
246 | } | |
247 | ||
248 | // ============================================================================ | |
249 | void str::trim (int dellen) { | |
250 | if (!dellen) | |
251 | return; | |
252 | ||
253 | str s; | |
254 | // If dellen is positive, trim from the end, | |
255 | // if negative, trim from beginning. | |
256 | if (dellen > 0) | |
257 | s = substr (0, len()-dellen); | |
258 | else | |
259 | s = substr (-dellen, len()); | |
260 | ||
261 | clear(); | |
262 | append (s); | |
263 | } | |
264 | ||
265 | // ============================================================================ | |
266 | void str::replace (const char* o, const char* n, unsigned int a) { | |
267 | unsigned int idx; | |
268 | ||
269 | while ((idx = first (o, a)) != len()) { | |
270 | str s1 = substr (0, idx); | |
271 | str s2 = substr (idx + strlen (o), len()); | |
272 | ||
273 | clear(); | |
274 | ||
275 | append (s1); | |
276 | append (n); | |
277 | append (s2); | |
278 | } | |
279 | } | |
280 | ||
281 | void str::insert (char* c, unsigned int pos) { | |
282 | str s1 = substr (0, pos); | |
283 | str s2 = substr (pos, len()); | |
284 | ||
285 | clear(); | |
286 | append (s1); | |
287 | append (c); | |
288 | append (s2); | |
289 | } | |
290 | ||
291 | void str::reverse () { | |
292 | char* tmp = new char[alloclen]; | |
293 | strcpy (tmp, text); | |
294 | ||
295 | clear(); | |
296 | curs = 0; | |
297 | resize (alloclen); | |
298 | for (int i = alloclen-1; i >= 0; i--) | |
299 | append (tmp[i]); | |
300 | } | |
301 | ||
302 | void str::repeat (unsigned int n) { | |
303 | char* tmp = new char[alloclen]; | |
304 | strcpy (tmp, text); | |
305 | ||
306 | for (; n > 0; n--) | |
307 | append (tmp); | |
308 | } | |
309 | ||
310 | // ============================================================================ | |
311 | bool str::isnumber () { | |
8
c8bfa7e6ae1b
Commands are now read properly.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
6
diff
changeset
|
312 | ITERATE_STRING (u) |
c8bfa7e6ae1b
Commands are now read properly.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
6
diff
changeset
|
313 | if (text[u] < '0' || text[u] > '9') |
c8bfa7e6ae1b
Commands are now read properly.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
6
diff
changeset
|
314 | return false; |
c8bfa7e6ae1b
Commands are now read properly.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
6
diff
changeset
|
315 | return true; |
0 | 316 | } |
317 | ||
318 | // ============================================================================ | |
319 | bool str::isword () { | |
320 | ITERATE_STRING (u) { | |
8
c8bfa7e6ae1b
Commands are now read properly.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
6
diff
changeset
|
321 | // lowercase letters |
c8bfa7e6ae1b
Commands are now read properly.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
6
diff
changeset
|
322 | if (text[u] >= 'a' || text[u] <= 'z') |
c8bfa7e6ae1b
Commands are now read properly.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
6
diff
changeset
|
323 | continue; |
0 | 324 | |
8
c8bfa7e6ae1b
Commands are now read properly.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
6
diff
changeset
|
325 | // uppercase letters |
c8bfa7e6ae1b
Commands are now read properly.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
6
diff
changeset
|
326 | if (text[u] >= 'A' || text[u] <= 'Z') |
c8bfa7e6ae1b
Commands are now read properly.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
6
diff
changeset
|
327 | continue; |
0 | 328 | |
329 | return false; | |
330 | } | |
331 | return true; | |
332 | } | |
333 | ||
334 | // ============================================================================ | |
335 | int str::compare (const char* c) { | |
336 | return strcmp (text, c); | |
337 | } | |
338 | ||
339 | int str::compare (str c) { | |
340 | return compare (c.chars()); | |
341 | } | |
342 | ||
16
393359908179
Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
343 | int str::icompare (const char* c) { |
393359908179
Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
344 | return icompare (str ((char*)c)); |
393359908179
Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
345 | } |
393359908179
Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
346 | |
17
b4fcc69e426a
Events and commands are now treated properly case-insensitively.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
16
diff
changeset
|
347 | int str::icompare (str b) { |
b4fcc69e426a
Events and commands are now treated properly case-insensitively.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
16
diff
changeset
|
348 | return strcmp (tolower().chars(), b.tolower().chars()); |
16
393359908179
Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
349 | } |
393359908179
Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
350 | |
0 | 351 | // ============================================================================ |
2
bb2c45522eb6
Added event definitions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
352 | str str::tolower () { |
bb2c45522eb6
Added event definitions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
353 | str n = text; |
bb2c45522eb6
Added event definitions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
354 | |
bb2c45522eb6
Added event definitions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
355 | for (uint u = 0; u < len(); u++) { |
bb2c45522eb6
Added event definitions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
356 | if (n[u] > 'A' && n[u] < 'Z') |
bb2c45522eb6
Added event definitions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
357 | n.text[u] += ('a' - 'A'); |
bb2c45522eb6
Added event definitions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
358 | } |
bb2c45522eb6
Added event definitions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
359 | |
bb2c45522eb6
Added event definitions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
360 | return n; |
bb2c45522eb6
Added event definitions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
361 | } |
bb2c45522eb6
Added event definitions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
362 | |
bb2c45522eb6
Added event definitions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
363 | // ============================================================================ |
bb2c45522eb6
Added event definitions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
364 | str str::toupper () { |
bb2c45522eb6
Added event definitions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
365 | str n = text; |
bb2c45522eb6
Added event definitions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
366 | |
bb2c45522eb6
Added event definitions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
367 | for (uint u = 0; u < len(); u++) { |
bb2c45522eb6
Added event definitions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
368 | if (n[u] > 'a' && n[u] < 'z') |
bb2c45522eb6
Added event definitions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
369 | n.text[u] -= ('A' - 'a'); |
bb2c45522eb6
Added event definitions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
370 | } |
bb2c45522eb6
Added event definitions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
371 | |
bb2c45522eb6
Added event definitions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
372 | return n; |
bb2c45522eb6
Added event definitions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
373 | } |
bb2c45522eb6
Added event definitions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
374 | |
bb2c45522eb6
Added event definitions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
375 | // ============================================================================ |
6
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
376 | unsigned int str::count (char* c) { |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
377 | unsigned int r = 0; |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
378 | unsigned int tmp = 0; |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
379 | ITERATE_STRING (u) { |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
380 | if (text[u] == c[r]) { |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
381 | r++; |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
382 | if (r == strlen (c)) { |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
383 | r = 0; |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
384 | tmp++; |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
385 | } |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
386 | } else { |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
387 | if (r != 0) |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
388 | u--; |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
389 | r = 0; |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
390 | } |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
391 | } |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
392 | |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
393 | return tmp; |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
394 | } |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
395 | |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
396 | // ============================================================================ |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
397 | #if 0 |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
398 | str** str::split (char* del) { |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
399 | unsigned int arrcount = count (del) + 1; |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
400 | str** arr = new str* [arrcount]; |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
401 | |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
402 | unsigned int a = 0; |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
403 | unsigned int index = 0; |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
404 | while (1) { |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
405 | unsigned int b = first (del, a+1); |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
406 | printf ("next: %u (<-> %u)\n", b, len()); |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
407 | |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
408 | if (b == len()) |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
409 | break; |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
410 | |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
411 | str* x = new str; |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
412 | x->append (substr (a, b)); |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
413 | arr[index] = x; |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
414 | index++; |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
415 | a = b; |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
416 | } |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
417 | |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
418 | return arr; |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
419 | } |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
420 | #endif |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
421 | |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
422 | // ============================================================================ |
0 | 423 | // OPERATORS |
424 | str str::operator + (str& c) { | |
425 | append (c); | |
426 | return *this; | |
427 | } | |
428 | ||
429 | str& str::operator += (char c) { | |
430 | append (c); | |
431 | return *this; | |
432 | } | |
433 | ||
434 | str& str::operator += (const char* c) { | |
435 | append (c); | |
436 | return *this; | |
437 | } | |
438 | ||
439 | str& str::operator += (const str c) { | |
440 | append (c); | |
441 | return *this; | |
442 | } | |
443 | ||
444 | char str::operator [] (unsigned int pos) { | |
445 | return text[pos]; | |
446 | } | |
447 | ||
448 | str::operator char* () const { | |
449 | return text; | |
450 | } | |
451 | ||
452 | str::operator int () const {return atoi(text);} | |
453 | str::operator unsigned int () const {return atoi(text);} |