void ImportProject::import(const std::string &filename) { std::ifstream fin(filename); if (!fin.is_open()) return; if (filename.find("compile_commands.json") != std::string::npos) { importCompileCommands(fin); } else if (filename.find(".sln") != std::string::npos) { std::string path(Path::getPathFromFilename(Path::fromNativeSeparators(filename))); if (!path.empty() && !endsWith(path,'/')) path += '/'; importSln(fin,path); } else if (filename.find(".vcxproj") != std::string::npos) { std::map<std::string, std::string, cppcheck::stricmp> variables; importVcxproj(filename, variables, emptyString); } }
void ImportProject::importSln(std::istream &istr, const std::string &path) { std::map<std::string,std::string> variables; variables["SolutionDir"] = path; std::string additionalIncludeDirectories; std::string line; while (std::getline(istr,line)) { if (line.compare(0,8,"Project(")!=0) continue; const std::string::size_type pos = line.find(".vcxproj"); if (pos == std::string::npos) continue; const std::string::size_type pos1 = line.rfind("\"",pos); if (pos == std::string::npos) continue; const std::string vcxproj(line.substr(pos1+1, pos-pos1+7)); importVcxproj(path + Path::fromNativeSeparators(vcxproj), variables, additionalIncludeDirectories); } }
void ImportProject::importSln(std::istream &istr, const std::string &path) { std::map<std::string,std::string,cppcheck::stricmp> variables; variables["SolutionDir"] = path; std::string line; while (std::getline(istr,line)) { if (line.compare(0,8,"Project(")!=0) continue; const std::string::size_type pos = line.find(".vcxproj"); if (pos == std::string::npos) continue; const std::string::size_type pos1 = line.rfind('\"',pos); if (pos1 == std::string::npos) continue; std::string vcxproj(line.substr(pos1+1, pos-pos1+7)); if (!Path::isAbsolute(vcxproj)) vcxproj = path + vcxproj; importVcxproj(Path::fromNativeSeparators(vcxproj), variables, emptyString); } }