--- /dev/null
+/* $Id$
+
+This file is part of the MSP Märklin suite
+Copyright © 2010 Mikkosoft Productions, Mikko Rasa
+Distributed under the GPL
+*/
+
+#include <msp/core/getopt.h>
+#include <msp/strings/lexicalcast.h>
+#include <msp/strings/regex.h>
+#include "options.h"
+
+using namespace std;
+using namespace Msp;
+
+Options::Options(int argc, char **argv):
+ screen_w(1280),
+ screen_h(960),
+ fullscreen(false),
+ debug(false),
+ network(false),
+ simulate(false)
+{
+ string res;
+
+ GetOpt getopt;
+ getopt.add_option('r', "resolution", res, GetOpt::REQUIRED_ARG);
+ getopt.add_option('f', "fullscreen", fullscreen, GetOpt::NO_ARG);
+ getopt.add_option('g', "debug", debug, GetOpt::NO_ARG);
+ getopt.add_option('d', "driver", driver, GetOpt::REQUIRED_ARG);
+ getopt.add_option('s', "simulate", simulate, GetOpt::NO_ARG);
+ getopt.add_option('n', "network", network, GetOpt::NO_ARG);
+ getopt(argc, argv);
+
+ if(!res.empty())
+ {
+ if(RegMatch m=Regex("([1-9][0-9]*)x([1-9][0-9]*)").match(res))
+ {
+ screen_w = lexical_cast<unsigned>(m[1].str);
+ screen_h = lexical_cast<unsigned>(m[2].str);
+ }
+ else
+ throw UsageError("Invalid resolution");
+ }
+
+ const vector<string> &args = getopt.get_args();
+ if(args.empty())
+ throw UsageError("No layout given");
+
+ layout_fn = args[0];
+}