]> git.tdb.fi Git - r2c2.git/blob - source/engineer/options.cpp
89e1fd109be155a3172aa488afc2619bf89d42fe
[r2c2.git] / source / engineer / options.cpp
1 #include <msp/core/getopt.h>
2 #include <msp/fs/utils.h>
3 #include <msp/strings/lexicalcast.h>
4 #include <msp/strings/regex.h>
5 #include "options.h"
6
7 using namespace std;
8 using namespace Msp;
9
10 Options::Options(int argc, char **argv):
11         screen_w(1280),
12         screen_h(960),
13         fullscreen(false),
14         debug(false),
15         network(false),
16         simulate(false)
17 {
18         string res;
19
20         GetOpt getopt;
21         getopt.add_option('r', "resolution",  res,         GetOpt::REQUIRED_ARG);
22         getopt.add_option('f', "fullscreen",  fullscreen,  GetOpt::NO_ARG);
23         getopt.add_option('g', "debug",       debug,       GetOpt::NO_ARG);
24         getopt.add_option('d', "driver",      driver,      GetOpt::REQUIRED_ARG);
25         getopt.add_option('s', "simulate",    simulate,    GetOpt::NO_ARG);
26         getopt.add_option('n', "network",     network,     GetOpt::NO_ARG);
27         getopt.add_option(     "state",       state_fn,    GetOpt::REQUIRED_ARG);
28         getopt(argc, argv);
29
30         if(!res.empty())
31         {
32                 if(RegMatch m=Regex("([1-9][0-9]*)x([1-9][0-9]*)").match(res))
33                 {
34                         screen_w = lexical_cast<unsigned>(m[1].str);
35                         screen_h = lexical_cast<unsigned>(m[2].str);
36                 }
37                 else
38                         throw usage_error("Invalid resolution");
39         }
40
41         const vector<string> &args = getopt.get_args();
42         if(args.empty())
43                 throw usage_error("No layout given");
44
45         layout_fn = args[0];
46
47         if(state_fn.empty())
48                 state_fn = FS::basepart(layout_fn)+".state";
49 }