| 7 | //////////////////////////////////////// |
| 8 | |
| 9 | std::string process_includes_recursive(const std::string & source, const std::string & includeSearchPath, std::vector<std::string> & includes, int depth) |
| 10 | { |
| 11 | if (depth > 2) throw std::runtime_error("exceeded max include recursion depth"); |
| 12 | |
| 13 | static const std::regex re("^[ ]*#[ ]*include[ ]+[\"<](.*)[\">].*"); |
| 14 | std::stringstream input; |
| 15 | std::stringstream output; |
| 16 | |
| 17 | input << source; |
| 18 | |
| 19 | size_t lineNumber = 1; |
| 20 | std::smatch matches; |
| 21 | std::string line; |
| 22 | |
| 23 | while (std::getline(input, line)) |
| 24 | { |
| 25 | if (std::regex_search(line, matches, re)) |
| 26 | { |
| 27 | std::string includeFile = matches[1]; |
| 28 | std::string includeString = read_file_text(includeSearchPath + "/" + includeFile); |
| 29 | |
| 30 | if (!includeFile.empty()) |
| 31 | { |
| 32 | includes.push_back(includeSearchPath + "/" + includeFile); |
| 33 | output << process_includes_recursive(includeString, includeSearchPath, includes, depth++) << std::endl; |
| 34 | } |
| 35 | } |
| 36 | else |
| 37 | { |
| 38 | output << "#line " << lineNumber << std::endl; |
| 39 | output << line << std::endl; |
| 40 | } |
| 41 | ++lineNumber; |
| 42 | } |
| 43 | return output.str(); |
| 44 | } |
| 45 | |
| 46 | std::string preprocess_version(const std::string & source) |
| 47 | { |
no test coverage detected