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 | #ifndef __STR_H__ | |
42 | #define __STR_H__ | |
43 | ||
44 | char* vdynformat (const char* c, va_list v, unsigned int size); | |
45 | ||
46 | #define SCCF_NUMBER 1<<0 | |
47 | #define SCCF_WORD 1<<1 | |
48 | ||
49 | // Dynamic string object, allocates memory when needed and | |
50 | // features a good bunch of manipulation methods | |
51 | class str { | |
52 | private: | |
53 | // The actual message | |
54 | char* text; | |
55 | ||
56 | // Where will append() place new characters? | |
57 | unsigned int curs; | |
58 | ||
59 | // Allocated length | |
60 | unsigned int alloclen; | |
61 | ||
62 | // Resize the text buffer to len characters | |
63 | void resize (unsigned int len); | |
64 | public: | |
65 | // ====================================================================== | |
66 | // CONSTRUCTORS | |
67 | str (); | |
68 | str (const char* c); | |
69 | str (char c); | |
70 | ||
71 | // ====================================================================== | |
72 | // METHODS | |
73 | ||
74 | // Empty the string | |
75 | void clear (); | |
76 | ||
77 | // Length of the string | |
78 | unsigned int len (); | |
79 | ||
80 | // The char* form of the string | |
81 | char* chars (); | |
82 | ||
83 | // Dumps the character table of the string | |
84 | void dump (); | |
85 | ||
86 | // Appends text to the string | |
87 | void append (char c); | |
88 | void append (const char* c); | |
89 | void append (str c); | |
90 | ||
91 | // Appends formatted text to the string. | |
92 | void appendformat (const char* c, ...); | |
93 | void appendformat (str c, ...); | |
94 | ||
95 | // Returns the first occurrence of c in the string, optionally starting | |
96 | // from a certain position rather than the start. | |
97 | unsigned int first (const char* c, unsigned int a = 0); | |
98 | ||
99 | // Returns the last occurrence of c in the string, optionally starting | |
100 | // from a certain position rather than the end. | |
101 | unsigned int last (const char* c, int a = -1); | |
102 | ||
103 | // Returns a substring of the string, from a to b. | |
104 | str substr (unsigned int a, unsigned int b); | |
105 | ||
106 | // Replace a substring with another substring. | |
107 | void replace (const char* o, const char* n, unsigned int a = 0); | |
108 | ||
109 | // Removes a given index from the string, optionally more characters than just 1. | |
110 | void remove (unsigned int idx, unsigned int dellen=1); | |
111 | ||
112 | void trim (int dellen); | |
113 | ||
114 | // Inserts a substring into a certain position. | |
115 | void insert (char* c, unsigned int pos); | |
116 | ||
117 | // Reverses the string. | |
118 | void reverse (); | |
119 | ||
120 | // Repeats the string a given amount of times. | |
121 | void repeat (unsigned int n); | |
122 | ||
123 | // Is the string a number? | |
124 | bool isnumber (); | |
125 | ||
126 | // Is the string a word, i.e consists only of alphabetic letters? | |
127 | bool isword (); | |
128 | ||
2
bb2c45522eb6
Added event definitions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
129 | // Convert string to lower case |
bb2c45522eb6
Added event definitions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
130 | str tolower (); |
bb2c45522eb6
Added event definitions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
131 | |
bb2c45522eb6
Added event definitions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
132 | // Convert string to upper case |
bb2c45522eb6
Added event definitions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
133 | str toupper (); |
bb2c45522eb6
Added event definitions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
134 | |
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
|
135 | // Compare this string with another |
0 | 136 | int compare (const char* c); |
137 | int compare (str c); | |
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
|
138 | int icompare (str 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
|
139 | int icompare (const char* c); |
0 | 140 | |
6
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
141 | // Counts the amount of substrings in the string |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
142 | unsigned int count (char* s); |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
143 | |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
144 | #if 0 |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
145 | str** split (char* del); |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
146 | #endif |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
147 | |
0 | 148 | // ====================================================================== |
149 | // OPERATORS | |
150 | str operator + (str& c); | |
151 | str& operator += (char c); | |
152 | str& operator += (const char* c); | |
153 | str& operator += (const str c); | |
154 | char operator [] (unsigned int pos); | |
155 | operator char* () const; | |
156 | operator int () const; | |
157 | operator unsigned int () const; | |
158 | }; | |
159 | ||
160 | #endif // __STR_H__ |