Build tool
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SourceFile.cc 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #include "SourceFile.h"
  2. #include <iostream>
  3. #include <fstream>
  4. #include <sstream>
  5. static bool startsWith(const std::string &a, const std::string &b, std::string &after) {
  6. if (a.size() < b.size())
  7. return false;
  8. for (size_t i = 0; i < b.size(); ++i) {
  9. if (a[i] != b[i])
  10. return false;
  11. }
  12. after = a.substr(b.size());
  13. return true;
  14. }
  15. static void parseParts(std::vector<std::string> &vec, const std::string &str) {
  16. std::istringstream ss(str);
  17. std::string part;
  18. while (ss >> part) {
  19. vec.push_back(part);
  20. }
  21. }
  22. SourceFile::SourceFile(std::string dir, std::string name):
  23. dir_(std::move(dir)), name_(std::move(name)) {
  24. std::ifstream file(dir_ + "/" + name_);
  25. std::string line;
  26. std::string content;
  27. while (std::getline(file, line)) {
  28. if (line.size() < 4) continue;
  29. if (line[0] != '/' || line[1] != '/' || line[2] != '#') continue;
  30. if (startsWith(line, "//# pkgs:", content)) {
  31. parseParts(pkgs_, content);
  32. } else if (startsWith(line, "//# cflags:", content)) {
  33. parseParts(pkgs_, content);
  34. } else if (startsWith(line, "//# ldflags:", content)) {
  35. parseParts(pkgs_, content);
  36. }
  37. }
  38. }