|
@@ -5,27 +5,73 @@
|
5
|
5
|
* \author xythobuz
|
6
|
6
|
*/
|
7
|
7
|
|
8
|
|
-#include <stdlib.h>
|
9
|
|
-#include <stdio.h>
|
|
8
|
+#include <cstdlib>
|
|
9
|
+#include <cstdio>
|
|
10
|
+#include <cstring>
|
10
|
11
|
|
11
|
12
|
#include "config.h"
|
|
13
|
+#include "OpenRaider.h"
|
12
|
14
|
#include "main.h"
|
13
|
15
|
|
14
|
|
-void cleanupHandler() {
|
|
16
|
+#define DEFAULT_CONFIG_PATH "~/.OpenRaider/"
|
|
17
|
+#define DEFAULT_CONFIG_FILE "OpenRaider.init"
|
|
18
|
+
|
|
19
|
+OpenRaider *gOpenRaider = NULL;
|
15
|
20
|
|
|
21
|
+void cleanupHandler() {
|
|
22
|
+ if (gOpenRaider)
|
|
23
|
+ delete gOpenRaider;
|
16
|
24
|
}
|
17
|
25
|
|
18
|
26
|
int main(int argc, char *argv[]) {
|
|
27
|
+ const char *config = NULL;
|
|
28
|
+
|
|
29
|
+ // Handle arguments
|
19
|
30
|
if (argc == 1) {
|
20
|
31
|
// Use default rc file path
|
|
32
|
+ config = DEFAULT_CONFIG_PATH DEFAULT_CONFIG_FILE;
|
21
|
33
|
} else if (argc == 2) {
|
22
|
|
- // Use provided rc file
|
|
34
|
+ // Check for command line switches
|
|
35
|
+ if ((strcmp("-h", argv[1]) == 0)
|
|
36
|
+ || (strcmp("--help", argv[1]) == 0)) {
|
|
37
|
+ // Display help text
|
|
38
|
+ printf("%s [OPTIONS | /path/to/config]\n"
|
|
39
|
+ "Options:\n"
|
|
40
|
+ "\t--help\n\t-h\tDisplay this help text\n"
|
|
41
|
+ "\t--version\n\t-v\tDisplay version information\n"
|
|
42
|
+ "If no options are given, the default config will be loaded from:\n"
|
|
43
|
+ "\t" DEFAULT_CONFIG_PATH DEFAULT_CONFIG_FILE "\n", argv[0]);
|
|
44
|
+ return 0;
|
|
45
|
+ } else if ((strcmp("-v", argv[1]) == 0)
|
|
46
|
+ || (strcmp("--version", argv[1]) == 0)) {
|
|
47
|
+ // Display version
|
|
48
|
+ printf(VERSION "\n");
|
|
49
|
+ return 0;
|
|
50
|
+ } else {
|
|
51
|
+ // Interpret as rc file name
|
|
52
|
+ config = argv[1];
|
|
53
|
+ }
|
23
|
54
|
} else {
|
24
|
|
- printf("Usage:\n%s [/path/to/config.file]\n", argv[0]);
|
|
55
|
+ printf("Usage:\n%s -h\n", argv[0]);
|
25
|
56
|
return 1;
|
26
|
57
|
}
|
27
|
58
|
|
|
59
|
+ // Create globals
|
28
|
60
|
atexit(cleanupHandler);
|
|
61
|
+ printf("Initializing " VERSION "\n");
|
|
62
|
+ gOpenRaider = new OpenRaider();
|
|
63
|
+
|
|
64
|
+ // Try to load a configuration
|
|
65
|
+ if (gOpenRaider->loadConfig(config) != 0) {
|
|
66
|
+ if (gOpenRaider->loadConfig(DEFAULT_CONFIG_PATH DEFAULT_CONFIG_FILE) != 0) {
|
|
67
|
+ if (gOpenRaider->loadConfig(DEFAULT_CONFIG_FILE) != 0) {
|
|
68
|
+ printf("Could not find a config file. Aborting...\n");
|
|
69
|
+ return 2;
|
|
70
|
+ }
|
|
71
|
+ }
|
|
72
|
+ }
|
|
73
|
+
|
|
74
|
+ // Initialize the "subsystems"
|
29
|
75
|
|
30
|
76
|
return 0;
|
31
|
77
|
}
|