]> git.localhorst.tv Git - l2e.git/blob - Arguments.cpp
9afe59a4ef6ddd397a591e6989775b704738b569
[l2e.git] / Arguments.cpp
1 #include "Arguments.h"
2
3 #include <stdexcept>
4 #include <string>
5
6 namespace app {
7
8 Arguments::Arguments()
9 : outfile(0)
10 , runlevel(PLAY) {
11
12 }
13
14
15 void Arguments::Read(int argc, char **argv) {
16         for (int i(1); i < argc; ++i) {
17                 char *arg(argv[i]);
18                 if (arg[0] == '-') {
19                         switch (arg[1]) {
20                                 case 'd':
21                                         runlevel = DUMP;
22                                         break;
23                                 case 'o':
24                                         if (i + 1 >= argc) {
25                                                 throw std::runtime_error("missing argument to -o");
26                                         }
27                                         ++i;
28                                         outfile = argv[i];
29                                         runlevel = WRITE;
30                                         break;
31                                 case 'B':
32                                         runlevel = BATTLE;
33                                         break;
34                                 case 'M':
35                                         runlevel = MAP;
36                                         break;
37                                 case 'S':
38                                         runlevel = SOURCE_WIKI;
39                                         break;
40                                 default:
41                                         throw std::runtime_error(std::string("unknown option ") + arg[1]);
42                                         break;
43                         }
44                 } else {
45                         infiles.push_back(arg);
46                 }
47         }
48 }
49
50 }