|
|
@@ -4,44 +4,28 @@ |
|
|
|
#include <fstream> |
|
|
|
#include <sstream> |
|
|
|
|
|
|
|
static bool startsWith(const std::string &a, const std::string &b, std::string &after) { |
|
|
|
if (a.size() < b.size()) |
|
|
|
return false; |
|
|
|
|
|
|
|
for (size_t i = 0; i < b.size(); ++i) { |
|
|
|
if (a[i] != b[i]) |
|
|
|
static bool startsWith(BBBParser &parser, const char *str) { |
|
|
|
for (size_t i = 0; str[i] != '\0'; ++i) { |
|
|
|
if (parser.get() != str[i]) |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
after = a.substr(b.size()); |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
static void parseParts(std::vector<std::string> &vec, const std::string &str) { |
|
|
|
std::istringstream ss(str); |
|
|
|
std::string part; |
|
|
|
while (ss >> part) { |
|
|
|
vec.push_back(part); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
SourceFile::SourceFile(std::string dir, std::string name): |
|
|
|
dir_(std::move(dir)), name_(std::move(name)) { |
|
|
|
SourceFile::SourceFile(std::string dir, std::string name, BBBParser::Variables vars): |
|
|
|
dir_(std::move(dir)), name_(std::move(name)), vars_(std::move(vars)) { |
|
|
|
|
|
|
|
std::ifstream file(dir_ + "/" + name_); |
|
|
|
|
|
|
|
std::string line; |
|
|
|
std::string content; |
|
|
|
while (std::getline(file, line)) { |
|
|
|
if (line.size() < 4) continue; |
|
|
|
if (line[0] != '/' || line[1] != '/' || line[2] != '#') continue; |
|
|
|
|
|
|
|
if (startsWith(line, "//# pkgs:", content)) { |
|
|
|
parseParts(pkgs_, content); |
|
|
|
} else if (startsWith(line, "//# cflags:", content)) { |
|
|
|
parseParts(pkgs_, content); |
|
|
|
} else if (startsWith(line, "//# ldflags:", content)) { |
|
|
|
parseParts(pkgs_, content); |
|
|
|
BBBParser parser(file, BBBParser::FLAG_ONE_LINE); |
|
|
|
|
|
|
|
bool freshLine = true; |
|
|
|
while (file.good()) { |
|
|
|
if (freshLine && startsWith(parser, "//#bb")) { |
|
|
|
parser.parse(vars_); |
|
|
|
} else { |
|
|
|
while (file.good() && parser.get() != '\n'); |
|
|
|
freshLine = true; |
|
|
|
} |
|
|
|
} |
|
|
|
} |