Browse Source

main uses iostream

Thomas Buck 10 years ago
parent
commit
821e17bee2
3 changed files with 47 additions and 39 deletions
  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 View File

11
 #define VERSION "OpenRaider-@OpenRaider_VERSION_MAJOR@.@OpenRaider_VERSION_MINOR@.@OpenRaider_VERSION_MICRO@@OpenRaider_VERSION_RELEASE@ (@CMAKE_BUILD_TYPE@)"
11
 #define VERSION "OpenRaider-@OpenRaider_VERSION_MAJOR@.@OpenRaider_VERSION_MINOR@.@OpenRaider_VERSION_MICRO@@OpenRaider_VERSION_RELEASE@ (@CMAKE_BUILD_TYPE@)"
12
 #define BUILD_HOST "@OpenRaider_BUILD_HOST@ @OpenRaider_HOSTNAME@"
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
 #cmakedefine USING_AL
14
 #cmakedefine USING_AL
20
 
15
 
21
 #cmakedefine HAVE_EXECINFO_H
16
 #cmakedefine HAVE_EXECINFO_H

+ 6
- 0
include/global.h View File

9
 
9
 
10
 #include "config.h"
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
 // Visual C++ does not understand __attribute__
18
 // Visual C++ does not understand __attribute__
13
 #ifdef _MSC_VER
19
 #ifdef _MSC_VER
14
 #define __attribute__(x)
20
 #define __attribute__(x)

+ 41
- 34
src/main.cpp View File

5
  * \author xythobuz
5
  * \author xythobuz
6
  */
6
  */
7
 
7
 
8
+#include <iostream>
8
 #include <cstdlib>
9
 #include <cstdlib>
9
-#include <cstdio>
10
 #include <cstring>
10
 #include <cstring>
11
 
11
 
12
 #include "global.h"
12
 #include "global.h"
94
 
94
 
95
 void cleanupHandler(void) {
95
 void cleanupHandler(void) {
96
 #ifdef DEBUG
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
 #endif
103
 #endif
103
 }
104
 }
104
 
105
 
105
 int main(int argc, char *argv[]) {
106
 int main(int argc, char *argv[]) {
106
-    const char *config = NULL;
107
+    bool configArg = false;
107
 
108
 
108
     // Handle arguments
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
         // Check for command line switches
111
         // Check for command line switches
114
         if ((strcmp("-h", argv[1]) == 0)
112
         if ((strcmp("-h", argv[1]) == 0)
115
                 || (strcmp("--help", argv[1]) == 0)) {
113
                 || (strcmp("--help", argv[1]) == 0)) {
116
             // Display help text
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
             return 0;
125
             return 0;
124
         } else if ((strcmp("-v", argv[1]) == 0)
126
         } else if ((strcmp("-v", argv[1]) == 0)
125
                 || (strcmp("--version", argv[1]) == 0)) {
127
                 || (strcmp("--version", argv[1]) == 0)) {
126
             // Display version
128
             // Display version
127
-            printf(VERSION "\n");
129
+            std::cout << VERSION << std::endl;
128
             return 0;
130
             return 0;
129
         } else {
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
         return 1;
137
         return 1;
136
     }
138
     }
137
 
139
 
138
 #ifdef DEBUG
140
 #ifdef DEBUG
139
-    printf("Initializing %s\n", VERSION);
141
+    std::cout << "Initializing " << VERSION << std::endl;
140
 #endif
142
 #endif
141
 
143
 
142
     atexit(cleanupHandler);
144
     atexit(cleanupHandler);
143
 
145
 
144
     // Try to load a configuration
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
     // Initialize everything
161
     // Initialize everything
155
     int error = gOpenRaider.initialize();
162
     int error = gOpenRaider.initialize();
156
     if (error != 0) {
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
     // Enter Main loop
168
     // Enter Main loop
175
     int frames = backtrace(callstack, maxSize);
182
     int frames = backtrace(callstack, maxSize);
176
     char **strs = backtrace_symbols(callstack, frames);
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
     for (int i = 0; i < frames; i++)
189
     for (int i = 0; i < frames; i++)
183
-        printf("%s\n", strs[i]);
190
+        std::cout << strs[i] << std::endl;
184
 
191
 
185
     delete [] strs;
192
     delete [] strs;
186
     abort();
193
     abort();

Loading…
Cancel
Save