24 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 */ |
27 */ |
28 |
28 |
29 #ifndef BOTC_COMMON_H |
29 #ifndef BOTC_MAIN_H |
30 #define BOTC_COMMON_H |
30 #define BOTC_MAIN_H |
31 |
31 |
32 #if !defined (__cplusplus) || __cplusplus < 201103L |
32 #if !defined (__cplusplus) || __cplusplus < 201103L |
33 # error botc requires a C++11-compliant compiler to be built |
33 # error botc requires a C++11-compliant compiler to be built |
34 #endif |
34 #endif |
35 |
35 |
36 #include <cstdio> |
36 #include <cstdio> |
37 #include <cstdarg> |
37 #include <cstdarg> |
38 #include <cstdint> |
38 #include <cstdint> |
|
39 #include "property.h" |
39 #include "types.h" |
40 #include "types.h" |
40 #include "containers.h" |
41 #include "containers.h" |
41 #include "str.h" |
42 #include "str.h" |
42 #include "format.h" |
43 #include "format.h" |
43 #include "botstuff.h" |
44 #include "botstuff.h" |
54 |
55 |
55 // On Windows, files are case-insensitive |
56 // On Windows, files are case-insensitive |
56 #if (defined(WIN32) || defined(_WIN32) || defined(__WIN32)) && !defined(__CYGWIN__) |
57 #if (defined(WIN32) || defined(_WIN32) || defined(__WIN32)) && !defined(__CYGWIN__) |
57 #define FILE_CASEINSENSITIVE |
58 #define FILE_CASEINSENSITIVE |
58 #endif |
59 #endif |
59 |
|
60 // Parser mode: where is the parser at? |
|
61 enum parsermode_e |
|
62 { |
|
63 MODE_TOPLEVEL, // at top level |
|
64 MODE_EVENT, // inside event definition |
|
65 MODE_MAINLOOP, // inside mainloop |
|
66 MODE_ONENTER, // inside onenter |
|
67 MODE_ONEXIT, // inside onexit |
|
68 }; |
|
69 |
|
70 enum type_e |
|
71 { |
|
72 TYPE_UNKNOWN = 0, |
|
73 TYPE_VOID, |
|
74 TYPE_INT, |
|
75 TYPE_STRING, |
|
76 TYPE_BOOL, |
|
77 }; |
|
78 |
60 |
79 #define elif else if |
61 #define elif else if |
80 |
62 |
81 #define CHECK_FILE(pointer,path,action) \ |
63 #define CHECK_FILE(pointer,path,action) \ |
82 if (!pointer) { \ |
64 if (!pointer) { \ |
99 type_e GetTypeByName (string token); |
81 type_e GetTypeByName (string token); |
100 string GetTypeName (type_e type); |
82 string GetTypeName (type_e type); |
101 string get_version_string (form_length_e len); |
83 string get_version_string (form_length_e len); |
102 string make_version_string (int major, int minor, int patch); |
84 string make_version_string (int major, int minor, int patch); |
103 |
85 |
104 // Make the parser's variables globally available |
|
105 extern int g_NumStates; |
|
106 extern int g_NumEvents; |
|
107 extern parsermode_e g_current_mode; |
|
108 extern string g_CurState; |
|
109 |
|
110 #ifndef __GNUC__ |
86 #ifndef __GNUC__ |
111 #define __attribute__(X) |
87 #define __attribute__(X) |
112 #endif |
88 #endif |
113 #define deprecated __attribute__ ((deprecated)) |
89 #define deprecated __attribute__ ((deprecated)) |
114 |
90 |
115 // Byte datatype |
91 #endif // BOTC_MAIN_H |
116 typedef int32_t word; |
|
117 typedef unsigned char byte; |
|
118 |
|
119 // Keywords |
|
120 extern const string_list g_Keywords; |
|
121 |
|
122 bool IsKeyword (string s); |
|
123 int NumKeywords (); |
|
124 |
|
125 // Script mark and reference |
|
126 struct ScriptMark |
|
127 { |
|
128 string name; |
|
129 size_t pos; |
|
130 }; |
|
131 |
|
132 struct ScriptMarkReference |
|
133 { |
|
134 int num; |
|
135 size_t pos; |
|
136 }; |
|
137 |
|
138 // ==================================================================== |
|
139 // Generic union |
|
140 template <class T> union generic_union |
|
141 { |
|
142 T as_t; |
|
143 byte as_bytes[sizeof (T)]; |
|
144 char as_chars[sizeof (T)]; |
|
145 double as_double; |
|
146 float as_float; |
|
147 int as_int; |
|
148 word as_word; |
|
149 }; |
|
150 |
|
151 // ==================================================================== |
|
152 // Finds a byte in the given value. |
|
153 template <class T> inline unsigned char GetByteIndex (T a, int b) |
|
154 { |
|
155 generic_union<T> uni; |
|
156 uni.as_t = a; |
|
157 return uni.as_bytes[b]; |
|
158 } |
|
159 |
|
160 #endif // BOTC_COMMON_H |
|