-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsim.cpp
More file actions
58 lines (53 loc) · 1.6 KB
/
sim.cpp
File metadata and controls
58 lines (53 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <iostream>
#include <fstream>
#include <exception>
#include <stdexcept>
#include "simulator.h"
int main(int argc, char **argv) {
try {
string filename, mode;
argv++;
argc--;
if ( argc % 2 ) {
throw invalid_argument("Lack of Arguments!");
} else {
map<char, string> arg_map;
for (int i = 0; i < argc; i+=2) {
if (argv[i][0] != '-') {
throw invalid_argument("Option should start with '-'!");
}
arg_map[argv[i][1]] = argv[i+1];
}
// -m (run|debug) -f (filename)
if ( arg_map.count('m') ) {
mode = arg_map['m'];
} else {
throw invalid_argument("Mode should be specified with -m (run|debug).");
}
if ( arg_map.count('f') ) {
filename = arg_map['f'];
} else {
throw invalid_argument("File should be specified with -f filename.");
}
}
fstream fin(filename, ios::in);
fin.exceptions(fin.failbit);
string ins, content;
while(!fin.eof()) {
getline(fin, ins);
content += ins + "\n";
}
Simulator sim(content);
sim.init();
if ( mode == "run" ) {
sim.run();
} else if ( mode == "debug" ) {
sim.debug();
} else {
throw invalid_argument("Mode should be specified with -m (run|debug).");
}
} catch (exception &err) {
cerr << err.what() << endl;
}
return 0;
}