Пример #1
0
void Exclusions::setExclusions(const ExclusionFileName & fileName)
{
    std::ifstream exclusionsFile(fileName.c_str());
    if (exclusionsFile.is_open() == false)
    {
        std::ostringstream ss;
        ss << "Cannot open exclusions file " << fileName << ": "
           << strerror(errno);
        throw ExclusionError(ss.str());
    }

    Tcl::interpreter interp;
    interp.eval(exclusionsFile);
    if (exclusionsFile.bad())
    {
        throw std::ios::failure(
            "Cannot read from " + fileName + ": " + strerror(errno));
    }

    const Tcl::object ruleNames = interp.eval("array names ruleExclusions");
    const size_t ruleNamesLength = ruleNames.length(interp);
    for (size_t i = 0; i != ruleNamesLength; ++i)
    {
        const std::string ruleName = ruleNames.at(interp, i).get();

        const Tcl::object exceptionList = interp.eval("set ruleExclusions(" + ruleName + ")");
        const size_t exceptionListLength = exceptionList.length(interp);

        FileNameSet files;
        for (size_t j = 0; j != exceptionListLength; ++j)
        {
            const Structures::SourceFiles::FileName file = exceptionList.at(interp, j).get();
            files.insert(file);
        }

        exclusions[ruleName] = files;
    }
}
Пример #2
0
Profiles::RuleNameCollection Profiles::getListOfScriptNamesTcl(
  const Vera::Plugins::Profiles::ProfileName & profile)
{
    RuleNameCollection allRules;

    // name of the profile is also the name of the profile file

    const Vera::Plugins::RootDirectory::DirectoryName veraRoot =
            Vera::Plugins::RootDirectory::getRootDirectory();

    std::string fileName(veraRoot + "/profiles/");
    fileName += profile;

    std::ifstream profileFile(fileName.c_str());
    if (profileFile.is_open() == false)
    {
        std::ostringstream ss;
        ss << "Cannot open profile description for profile '" << profile
            << "': "<< strerror(errno);
        throw Vera::Plugins::ProfileError(ss.str());
    }

    Tcl::interpreter interp;
    interp.eval(profileFile);
    if (profileFile.bad())
    {
        throw std::runtime_error(
            "Cannot read from " + fileName + ": " + strerror(errno));
    }

    const Tcl::object ruleList = interp.eval("set rules");

    const size_t ruleListLength = ruleList.length(interp);
    for (size_t i = 0; i != ruleListLength; ++i)
    {
        const Vera::Plugins::Rules::RuleName rName = ruleList.at(interp, i).get();
        allRules.push_back(rName);
    }

    return allRules;
}