Thomas Buck преди 10 години
родител
ревизия
821e17bee2
променени са 3 файла, в които са добавени 47 реда и са изтрити 39 реда
  1. 0
    5
      include/config.h.in
  2. 6
    0
      include/global.h
  3. 41
    34
      src/main.cpp

+ 0
- 5
include/config.h.in Целия файл

@@ -11,11 +11,6 @@
11 11
 #define VERSION "OpenRaider-@OpenRaider_VERSION_MAJOR@.@OpenRaider_VERSION_MINOR@.@OpenRaider_VERSION_MICRO@@OpenRaider_VERSION_RELEASE@ (@CMAKE_BUILD_TYPE@)"
12 12
 #define BUILD_HOST "@OpenRaider_BUILD_HOST@ @OpenRaider_HOSTNAME@"
13 13
 
14
-#define DEFAULT_CONFIG_PATH "~/.OpenRaider"
15
-#define DEFAULT_CONFIG_FILE "OpenRaider.ini"
16
-#define DEFAULT_WIDTH 640
17
-#define DEFAULT_HEIGHT 480
18
-
19 14
 #cmakedefine USING_AL
20 15
 
21 16
 #cmakedefine HAVE_EXECINFO_H

+ 6
- 0
include/global.h Целия файл

@@ -9,6 +9,12 @@
9 9
 
10 10
 #include "config.h"
11 11
 
12
+// Defaults
13
+#define DEFAULT_CONFIG_PATH "~/.OpenRaider"
14
+#define DEFAULT_CONFIG_FILE "OpenRaider.ini"
15
+#define DEFAULT_WIDTH 640
16
+#define DEFAULT_HEIGHT 480
17
+
12 18
 // Visual C++ does not understand __attribute__
13 19
 #ifdef _MSC_VER
14 20
 #define __attribute__(x)

+ 41
- 34
src/main.cpp Целия файл

@@ -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();

Loading…
Отказ
Запис