Better fix for #1371.

Now handles also system includes. And have couple of tests.
This commit is contained in:
Kimmo Varis 2010-07-21 14:16:42 +03:00
parent 9d29ee6edd
commit 618076a65f
2 changed files with 16 additions and 5 deletions

View File

@ -1322,6 +1322,9 @@ Preprocessor::HeaderTypes Preprocessor::getHeaderFileName(std::string &str)
result.append(1, str[i]);
}
// Linux can't open include paths with \ separator, so fix them
std::replace(result.begin(), result.end(), '\\', '/');
str = result;
if (c == '"')
return UserHeader;
@ -1397,11 +1400,7 @@ void Preprocessor::handleIncludes(std::string &code, const std::string &filePath
if (headerType == UserHeader && !fileOpened)
{
filename = paths.back() + filename;
// Linux can't open include paths with \ separator, so fix them
std::string fixedname(filename);
std::replace(fixedname.begin(), fixedname.end(), '\\', '/');
fin.open(fixedname.c_str());
fin.open(filename.c_str());
if (fin.is_open())
{
fileOpened = true;

View File

@ -2030,6 +2030,18 @@ private:
ASSERT_EQUALS(OurPreprocessor::SystemHeader, OurPreprocessor::getHeaderFileName(src));
ASSERT_EQUALS("c.h", src);
}
{
std::string src = "#include \"d/d.h\"";
ASSERT_EQUALS(OurPreprocessor::UserHeader, OurPreprocessor::getHeaderFileName(src));
ASSERT_EQUALS("d/d.h", src);
}
{
std::string src = "#include \"e\\e.h\"";
ASSERT_EQUALS(OurPreprocessor::UserHeader, OurPreprocessor::getHeaderFileName(src));
ASSERT_EQUALS("e/e.h", src);
}
}
void ifdef_ifdefined()