| 71 | } |
| 72 | |
| 73 | static void getDeps(std::string filename, std::vector<std::string> &depfiles) |
| 74 | { |
| 75 | static const std::array<std::string, 3> externalfolders{"externals/picojson", "externals/simplecpp", "externals/tinyxml2"}; |
| 76 | static const std::array<std::string, 3> externalfolders_rel{"../externals/picojson", "../externals/simplecpp", "../externals/tinyxml2"}; |
| 77 | |
| 78 | // Is the dependency already included? |
| 79 | if (std::find(depfiles.cbegin(), depfiles.cend(), filename) != depfiles.cend()) |
| 80 | return; |
| 81 | |
| 82 | const bool relative = startsWith(filename, "../"); // oss-fuzz |
| 83 | if (relative) |
| 84 | filename = filename.substr(3); |
| 85 | |
| 86 | std::ifstream f(filename.c_str()); |
| 87 | if (!f.is_open()) { |
| 88 | /* |
| 89 | * Recursively search for includes in other directories. |
| 90 | * Files are searched according to the following priority: |
| 91 | * [test, tools] -> cli -> lib -> externals |
| 92 | */ |
| 93 | if (startsWith(filename, "frontend/")) |
| 94 | getDeps("lib" + filename.substr(filename.find('/')), depfiles); |
| 95 | if (startsWith(filename, "cli/")) |
| 96 | getDeps("lib" + filename.substr(filename.find('/')), depfiles); |
| 97 | else if (startsWith(filename, "test/")) |
| 98 | getDeps("cli" + filename.substr(filename.find('/')), depfiles); |
| 99 | else if (startsWith(filename, "tools")) |
| 100 | getDeps("cli" + filename.substr(filename.find('/')), depfiles); |
| 101 | else if (startsWith(filename, "lib/")) { |
| 102 | const auto& extfolders = relative ? externalfolders_rel : externalfolders; |
| 103 | for (const std::string & external : extfolders) |
| 104 | getDeps(external + filename.substr(filename.find('/')), depfiles); |
| 105 | } |
| 106 | return; |
| 107 | } |
| 108 | if (filename.find(".c") == std::string::npos) |
| 109 | { |
| 110 | if (relative) |
| 111 | depfiles.push_back("../" + filename); |
| 112 | else |
| 113 | depfiles.push_back(filename); |
| 114 | } |
| 115 | |
| 116 | std::string path(filename); |
| 117 | if (path.find('/') != std::string::npos) |
| 118 | path.erase(1 + path.rfind('/')); |
| 119 | |
| 120 | std::string line; |
| 121 | while (std::getline(f, line)) { |
| 122 | std::string::size_type pos1 = line.find("#include \""); |
| 123 | char rightBracket = '\"'; |
| 124 | if (pos1 == std::string::npos) { |
| 125 | pos1 = line.find("#include <"); |
| 126 | rightBracket = '>'; |
| 127 | if (pos1 == std::string::npos) |
| 128 | continue; |
| 129 | } |
| 130 |
no test coverage detected