65 lines
1.3 KiB
C++
65 lines
1.3 KiB
C++
|
|
#include <fstream>
|
|
#include <iostream>
|
|
#include <sstream>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
using namespace std;
|
|
|
|
static inline string trim(string &s) {
|
|
s.erase(s.begin(), find_if(s.begin(), s.end(), [](unsigned char ch) {
|
|
return !isspace(ch);
|
|
}));
|
|
s.erase(find_if(s.rbegin(), s.rend(), [](unsigned char ch) {
|
|
return !isspace(ch);
|
|
}).base(), s.end());
|
|
}
|
|
|
|
void loadfile(vector<string[2]> &scripts) {
|
|
ifstream infile("bots");
|
|
string line;
|
|
int linenum = 0;
|
|
while (getline(infile, line)) {
|
|
linenum++;
|
|
istringstream iss(line);
|
|
string str = iss.str();
|
|
|
|
if (str.length() == 0 || str.substr(0,1) == "#")
|
|
break;
|
|
|
|
string loc = "";
|
|
string script = "start";
|
|
|
|
size_t pos = 0;
|
|
string token;
|
|
while ((pos = str.find(":")) != string::npos) {
|
|
token = str.substr(0, pos);
|
|
trim(token);
|
|
if (loc.length() == 0)
|
|
loc = token;
|
|
else
|
|
script = token;
|
|
str.erase(0, pos + 1);
|
|
}
|
|
|
|
if (loc.length() == 0) {
|
|
cout << "WARNING: skipping line " << linenum << endl;
|
|
break;
|
|
}
|
|
|
|
scripts.push_back({ loc, script });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int main() {
|
|
|
|
vector<string[2]> scripts;
|
|
|
|
loadfile(scripts);
|
|
|
|
|
|
|
|
} |