common.h

changeset 34
0a9a5902beaa
parent 33
fd35f6cb5f28
child 36
a8838b5f1213
equal deleted inserted replaced
33:fd35f6cb5f28 34:0a9a5902beaa
45 #include <stdarg.h> 45 #include <stdarg.h>
46 #include <typeinfo> 46 #include <typeinfo>
47 #include "bots.h" 47 #include "bots.h"
48 #include "str.h" 48 #include "str.h"
49 49
50 // Application name and version
50 #define APPNAME "botc" 51 #define APPNAME "botc"
51 #define VERSION_MAJOR 0 52 #define VERSION_MAJOR 0
52 #define VERSION_MINOR 0 53 #define VERSION_MINOR 0
53 #define VERSION_REVISION 999 54 #define VERSION_REVISION 999
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
60 // Where is the parser at? 61 // Parser mode: where is the parser at?
61 enum parsermode { 62 enum parsermode {
62 MODE_TOPLEVEL, // at top level 63 MODE_TOPLEVEL, // at top level
63 MODE_EVENT, // inside event definition 64 MODE_EVENT, // inside event definition
64 MODE_MAINLOOP, // inside mainloop 65 MODE_MAINLOOP, // inside mainloop
65 MODE_ONENTER, // inside onenter 66 MODE_ONENTER, // inside onenter
66 MODE_ONEXIT, // inside onexit 67 MODE_ONEXIT, // inside onexit
67 }; 68 };
68 69
70 if (!pointer) { \ 71 if (!pointer) { \
71 error ("couldn't open %s for %s!\n", (char*)path, action); \ 72 error ("couldn't open %s for %s!\n", (char*)path, action); \
72 exit (1); \ 73 exit (1); \
73 } 74 }
74 75
76 // Shortcut for formatting
75 #define PERFORM_FORMAT(in, out) \ 77 #define PERFORM_FORMAT(in, out) \
76 va_list v; \ 78 va_list v; \
77 va_start (v, in); \ 79 va_start (v, in); \
78 char* out = vdynformat (in, v, 256); \ 80 char* out = vdynformat (in, v, 256); \
79 va_end (v); 81 va_end (v);
80 82
83 // Plural expression
81 #define PLURAL(n) (n != 1) ? "s" : "" 84 #define PLURAL(n) (n != 1) ? "s" : ""
82 85
83 void error (const char* text, ...); 86 void error (const char* text, ...);
84 char* ObjectFileName (str s); 87 char* ObjectFileName (str s);
85 bool fexists (char* path); 88 bool fexists (char* path);
86 89
90 // Make the parser's variables globally available
87 #ifndef __PARSER_CXX__ 91 #ifndef __PARSER_CXX__
88 extern int g_NumStates; 92 extern int g_NumStates;
89 extern int g_NumEvents; 93 extern int g_NumEvents;
90 extern int g_CurMode; 94 extern int g_CurMode;
91 extern str g_CurState; 95 extern str g_CurState;
92 #endif 96 #endif
93 97
94 // Power function 98 // Power function
95 template<class T> T pow (T a, T b) { 99 template<class T> T pow (T a, int b) {
96 if (!b) 100 if (!b)
97 return 1; 101 return 1;
98 102
99 T r = a; 103 T r = a;
100 while (b > 1) { 104 while (b > 1) {
110 // Whitespace check 114 // Whitespace check
111 inline bool IsCharWhitespace (char c) { 115 inline bool IsCharWhitespace (char c) {
112 return (c <= 32 || c == 127 || c == 255); 116 return (c <= 32 || c == 127 || c == 255);
113 } 117 }
114 118
119 // Byte datatype
120 typedef unsigned long int byte;
121
115 #endif // __COMMON_H__ 122 #endif // __COMMON_H__

mercurial