summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjörn Steinbrink <B.Steinbrink@gmx.de>2005-08-19 13:46:58 +0000
committerBjörn Steinbrink <B.Steinbrink@gmx.de>2005-08-19 13:46:58 +0000
commit06f587714bfef58adc608f72662bf5ea2df00ee8 (patch)
treea69a2f0411def5fb90b21e4daa689b5ee1ee0c5c
parent44cf0fd601f9f3f0bb51871dfe7b5645090f41e0 (diff)
downloadmana-client-06f587714bfef58adc608f72662bf5ea2df00ee8.tar.gz
mana-client-06f587714bfef58adc608f72662bf5ea2df00ee8.tar.bz2
mana-client-06f587714bfef58adc608f72662bf5ea2df00ee8.tar.xz
mana-client-06f587714bfef58adc608f72662bf5ea2df00ee8.zip
Added support for parsing command line options. Added option to skip the update process. Made the logger being created immediately after start, because some destructors use it.
-rw-r--r--ChangeLog6
-rw-r--r--src/log.cpp18
-rw-r--r--src/log.h8
-rw-r--r--src/main.cpp66
4 files changed, 83 insertions, 15 deletions
diff --git a/ChangeLog b/ChangeLog
index b8064dca..3cc60e15 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2005-08-19 Björn Steinbrink <B.Steinbrink@gmx.de>
+
+ * src/log.cpp, src/log.h, src/main.cpp: Added support for parsing command
+ line options. Added option to skip the update process. Made logger being
+ created immediately after startup, because some destructors use it.
+
2005-08-18 Eugenio Favalli <elvenprogrammer@gmail.com>
* The Mana World.dev, src/game.cpp, src/gui/skill.h, src/gui/skill.cpp:
diff --git a/src/log.cpp b/src/log.cpp
index 07c12516..3222c856 100644
--- a/src/log.cpp
+++ b/src/log.cpp
@@ -29,22 +29,22 @@
#include <sstream>
-Logger::Logger(const std::string &logFilename)
+Logger::~Logger()
{
- logFile.open(logFilename.c_str(), std::ios_base::trunc);
-
- if (!logFile.is_open())
+ if (logFile.is_open())
{
- std::cout << "Warning: error while opening " << logFilename <<
- " for writing.\n";
+ logFile.close();
}
}
-Logger::~Logger()
+void Logger::setLogFile(const std::string &logFilename)
{
- if (logFile.is_open())
+ logFile.open(logFilename.c_str(), std::ios_base::trunc);
+
+ if (!logFile.is_open())
{
- logFile.close();
+ std::cout << "Warning: error while opening " << logFilename <<
+ " for writing.\n";
}
}
diff --git a/src/log.h b/src/log.h
index 9f6988c0..297df88f 100644
--- a/src/log.h
+++ b/src/log.h
@@ -32,14 +32,14 @@ class Logger
{
public:
/**
- * Constructor, opens log file for writing.
+ * Destructor, closes log file.
*/
- Logger(const std::string &logFilename);
+ ~Logger();
/**
- * Destructor, closes log file.
+ * Sets the file to log to and opens it
*/
- ~Logger();
+ void setLogFile(const std::string &logFilename);
/**
* Enters a message in the log. The message will be timestamped.
diff --git a/src/main.cpp b/src/main.cpp
index 42212b25..d2a8d964 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -23,8 +23,10 @@
#include "main.h"
+#include <getopt.h>
#include <iostream>
#include <physfs.h>
+#include <unistd.h>
#include <SDL_image.h>
#include <guichan/sdl/sdlinput.hpp>
@@ -153,8 +155,8 @@ void init_engine()
}
#endif
- // Initialize logger
- logger = new Logger(homeDir + std::string("/tmw.log"));
+ // Set log file
+ logger->setLogFile(homeDir + std::string("/tmw.log"));
ResourceManager *resman = ResourceManager::getInstance();
@@ -331,9 +333,65 @@ int exists(const std::string &file)
}
}
+struct Options
+{
+ Options():printHelp(false),skipUpdate(false) {};
+
+ bool printHelp;
+ bool skipUpdate;
+};
+
+void printHelp()
+{
+ std::cout << "tmw" << std::endl << std::endl;
+ std::cout << "Options: " << std::endl;
+ std::cout << " -h --help : Display this help" << std::endl;
+ std::cout << " --skipupdate : Skip the update process" << std::endl;
+}
+
+void parseOptions(int argc, char *argv[], Options &options)
+{
+ const char *optstring = "h";
+
+ const struct option long_options[] = {
+ { "help", no_argument, 0, 'h' },
+ { "skipupdate", no_argument, 0, 'u' },
+ 0
+ };
+
+ while (optind < argc) {
+ int result = getopt_long(argc, argv, optstring, long_options, NULL);
+
+ if (result == -1) {
+ break;
+ }
+
+ switch (result) {
+ default: // Unknown option
+ case 'h':
+ options.printHelp = true;
+ break;
+ case 'u':
+ options.skipUpdate = true;
+ break;
+ }
+ }
+}
+
/** Main */
int main(int argc, char *argv[])
{
+ logger = new Logger();
+
+ Options options;
+
+ parseOptions(argc, argv, options);
+
+ if (options.printHelp) {
+ printHelp();
+ return 0;
+ }
+
UpdaterWindow *uw;
// Initialize libxml2 and check for potential ABI mismatches between
@@ -352,6 +410,10 @@ int main(int argc, char *argv[])
SDL_Event event;
+ if (options.skipUpdate && state != ERROR) {
+ state = LOGIN;
+ }
+
while (state != EXIT)
{
// Handle SDL events