|
@@ -5,8 +5,8 @@
|
5
|
5
|
* \author xythobuz
|
6
|
6
|
*/
|
7
|
7
|
|
|
8
|
+#include <iostream>
|
8
|
9
|
#include <cstdlib>
|
9
|
|
-#include <cstdio>
|
10
|
10
|
#include <cstring>
|
11
|
11
|
|
12
|
12
|
#include "global.h"
|
|
@@ -94,59 +94,66 @@ World &getWorld() {
|
94
|
94
|
|
95
|
95
|
void cleanupHandler(void) {
|
96
|
96
|
#ifdef DEBUG
|
97
|
|
- printf("\nThanks for testing %s\n", VERSION);
|
98
|
|
- printf("Build date: %s @ %s\n", __DATE__, __TIME__);
|
99
|
|
- printf("Build host: %s\n", BUILD_HOST);
|
100
|
|
- printf("Web site : http://github.com/xythobuz/OpenRaider\n");
|
101
|
|
- printf("Contact : xythobuz@xythobuz.de\n");
|
|
97
|
+ std::cout << std::endl;
|
|
98
|
+ std::cout << "Thanks for testing " << VERSION << std::endl;
|
|
99
|
+ std::cout << "Build date: " << __DATE__ << " @ " << __TIME__ << std::endl;
|
|
100
|
+ std::cout << "Build host: " << BUILD_HOST << std::endl;
|
|
101
|
+ std::cout << "Web site : http://github.com/xythobuz/OpenRaider" << std::endl;
|
|
102
|
+ std::cout << "Contact : xythobuz@xythobuz.de" << std::endl;
|
102
|
103
|
#endif
|
103
|
104
|
}
|
104
|
105
|
|
105
|
106
|
int main(int argc, char *argv[]) {
|
106
|
|
- const char *config = NULL;
|
|
107
|
+ bool configArg = false;
|
107
|
108
|
|
108
|
109
|
// Handle arguments
|
109
|
|
- if (argc == 1) {
|
110
|
|
- // Use default rc file path
|
111
|
|
- config = DEFAULT_CONFIG_PATH "/" DEFAULT_CONFIG_FILE;
|
112
|
|
- } else if (argc == 2) {
|
|
110
|
+ if (argc == 2) {
|
113
|
111
|
// Check for command line switches
|
114
|
112
|
if ((strcmp("-h", argv[1]) == 0)
|
115
|
113
|
|| (strcmp("--help", argv[1]) == 0)) {
|
116
|
114
|
// Display help text
|
117
|
|
- printf("%s [OPTIONS | /path/to/config]\n"
|
118
|
|
- "Options:\n"
|
119
|
|
- "\t--help\n\t-h\tDisplay this help text\n"
|
120
|
|
- "\t--version\n\t-v\tDisplay version information\n"
|
121
|
|
- "If no options are given, the default config will be loaded from:\n"
|
122
|
|
- "\t" DEFAULT_CONFIG_PATH "/" DEFAULT_CONFIG_FILE "\n", argv[0]);
|
|
115
|
+ std::cout << argv[0] << " [OPTIONS | /path/to/config]" << std::endl;
|
|
116
|
+ std::cout << "Options:" << std::endl;
|
|
117
|
+ std::cout << "\t--help" << std::endl;
|
|
118
|
+ std::cout << "\t-h\tDisplay this help text" << std::endl;
|
|
119
|
+ std::cout << "\t--version" << std::endl;
|
|
120
|
+ std::cout << "\t-v\tDisplay version information" << std::endl;
|
|
121
|
+ std::cout << "If no options are given, the default config will be loaded from:" << std::endl;
|
|
122
|
+ std::cout << "\t" << DEFAULT_CONFIG_FILE << std::endl;
|
|
123
|
+ std::cout << "or" << std::endl;
|
|
124
|
+ std::cout << "\t" << DEFAULT_CONFIG_PATH << "/" << DEFAULT_CONFIG_FILE << std::endl;
|
123
|
125
|
return 0;
|
124
|
126
|
} else if ((strcmp("-v", argv[1]) == 0)
|
125
|
127
|
|| (strcmp("--version", argv[1]) == 0)) {
|
126
|
128
|
// Display version
|
127
|
|
- printf(VERSION "\n");
|
|
129
|
+ std::cout << VERSION << std::endl;
|
128
|
130
|
return 0;
|
129
|
131
|
} else {
|
130
|
|
- // Interpret as rc file name
|
131
|
|
- config = argv[1];
|
|
132
|
+ configArg = true;
|
132
|
133
|
}
|
133
|
|
- } else {
|
134
|
|
- printf("Usage:\n%s -h\n", argv[0]);
|
|
134
|
+ } else if (argc > 2) {
|
|
135
|
+ std::cout << "Usage:" << std::endl;
|
|
136
|
+ std::cout << argv[0] << " -h" << std::endl;
|
135
|
137
|
return 1;
|
136
|
138
|
}
|
137
|
139
|
|
138
|
140
|
#ifdef DEBUG
|
139
|
|
- printf("Initializing %s\n", VERSION);
|
|
141
|
+ std::cout << "Initializing " << VERSION << std::endl;
|
140
|
142
|
#endif
|
141
|
143
|
|
142
|
144
|
atexit(cleanupHandler);
|
143
|
145
|
|
144
|
146
|
// Try to load a configuration
|
145
|
|
- if (gOpenRaider.loadConfig(config) != 0) {
|
146
|
|
- if (gOpenRaider.loadConfig(DEFAULT_CONFIG_PATH "/" DEFAULT_CONFIG_FILE) != 0) {
|
147
|
|
- if (gOpenRaider.loadConfig(DEFAULT_CONFIG_FILE) != 0) {
|
148
|
|
- printf("Could not find a config file. Aborting...\n");
|
149
|
|
- return 2;
|
|
147
|
+ if (configArg) {
|
|
148
|
+ if (gOpenRaider.loadConfig(argv[1]) != 0) {
|
|
149
|
+ std::cout << "Could not find the specified config file. Aborting..." << std::endl;
|
|
150
|
+ return 2;
|
|
151
|
+ }
|
|
152
|
+ } else {
|
|
153
|
+ if (gOpenRaider.loadConfig(DEFAULT_CONFIG_FILE) != 0) {
|
|
154
|
+ if (gOpenRaider.loadConfig(DEFAULT_CONFIG_PATH "/" DEFAULT_CONFIG_FILE) != 0) {
|
|
155
|
+ std::cout << "Could not find a config file. Aborting..." << std::endl;
|
|
156
|
+ return 3;
|
150
|
157
|
}
|
151
|
158
|
}
|
152
|
159
|
}
|
|
@@ -154,8 +161,8 @@ int main(int argc, char *argv[]) {
|
154
|
161
|
// Initialize everything
|
155
|
162
|
int error = gOpenRaider.initialize();
|
156
|
163
|
if (error != 0) {
|
157
|
|
- printf("Could not initialize OpenRaider (%d)!\n", error);
|
158
|
|
- return 3;
|
|
164
|
+ std::cout << "Could not initialize OpenRaider (" << error << ")!" << std::endl;
|
|
165
|
+ return 4;
|
159
|
166
|
}
|
160
|
167
|
|
161
|
168
|
// Enter Main loop
|
|
@@ -175,12 +182,12 @@ void assertImplementation(const char *exp, const char *file, int line) {
|
175
|
182
|
int frames = backtrace(callstack, maxSize);
|
176
|
183
|
char **strs = backtrace_symbols(callstack, frames);
|
177
|
184
|
|
178
|
|
- printf("\nassertion failed:\n");
|
179
|
|
- printf("\t%s\n", exp);
|
180
|
|
- printf("in %s:%d\n\n", file, line);
|
|
185
|
+ std::cout << std::endl << "assertion failed:" << std::endl;
|
|
186
|
+ std::cout << "\t" << exp << std::endl;
|
|
187
|
+ std::cout << "in " << file << ":" << line << std::endl << std::endl;
|
181
|
188
|
|
182
|
189
|
for (int i = 0; i < frames; i++)
|
183
|
|
- printf("%s\n", strs[i]);
|
|
190
|
+ std::cout << strs[i] << std::endl;
|
184
|
191
|
|
185
|
192
|
delete [] strs;
|
186
|
193
|
abort();
|