-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathio.hpp
82 lines (73 loc) · 2.33 KB
/
io.hpp
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
* Copyright (C) 2013 George Wong
* GNU General Public License
*
*/
namespace IO {
// Forward declaration
bool load_macro (const char *fname,
uint32_t *repeats,
uint32_t *steps,
uint32_t *wait,
std::vector<MStep> *msteps);
// Load file
bool load_macro (const char *fname, uint32_t *repeats, uint32_t *steps,
uint32_t *wait, std::vector<MStep> *msteps) {
std::cout << "Loading macro from: " << fname << std::endl;
uint32_t lineno = 1;
std::string line;
std::ifstream fptr(fname);
if (fptr.is_open()) {
while (! fptr.eof() ) {
std::getline(fptr, line);
lineno++;
if (lineno==3) {
std::istringstream buffer( line.substr(8,line.length()) );
uint32_t val;
buffer >> val;
*repeats = val;
}
if (lineno==4) {
std::istringstream buffer( line.substr(5,line.length()) );
uint32_t val;
buffer >> val;
*wait = val;
}
if (lineno>6) {
if (line.length()==0) break;
const char *line_str = line.c_str();
// The below is a stupid way to do this
size_t sidx = 0; // Starting index
std::vector<std::string> argvs;
for (size_t i=0; i<strlen(line_str); i++) {
if (line_str[i]==' ') {
argvs.push_back(line.substr(sidx,i-sidx));
if (argvs.size()==1) {
// Special case for TYP, so that we can handle cases
if (argvs.at(0).compare("TYP")==0) {
argvs.push_back(line.substr(++i,strlen(line_str)-i-2));
i = strlen(line_str);
}
}
sidx = ++i;
}
}
if (argvs.size()==1) {
msteps->push_back(MStep(argvs.at(0)));
} else if (argvs.size()==2) {
msteps->push_back(MStep(argvs.at(0),argvs.at(1)));
} else {
msteps->push_back(MStep(argvs.at(0),argvs.at(1),argvs.at(2)));
}
*steps = *steps+1;
}
}
fptr.close();
std::cout << "Success!" << std::endl;
} else {
std::cout << "Unable to load file." << std::endl;
return 1;
}
return 0;
}
}