Skip to content

Commit 16665fd

Browse files
committed
main.cpp: error out when file/path provided by -I or -include= do not exist
1 parent b793919 commit 16665fd

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

main.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,33 @@ int main(int argc, char **argv)
9191
return 1;
9292
}
9393

94+
// TODO: move this logic into simplecpp?
95+
{
96+
bool inc_missing = false;
97+
for (const std::string& inc : dui.includes) {
98+
std::ifstream f(inc);
99+
if (!f.is_open()) {
100+
inc_missing = true;
101+
std::cout << "error: could not open include '" << inc << "'" << std::endl;
102+
}
103+
}
104+
if (inc_missing)
105+
return 1;
106+
}
107+
{
108+
bool inc_missing = false;
109+
for (const std::string& inc : dui.includePaths) {
110+
// TODO: check if this is a directory
111+
std::ifstream f(inc);
112+
if (!f.is_open()) {
113+
inc_missing = true;
114+
std::cout << "error: could not find include path '" << inc << "'" << std::endl;
115+
}
116+
}
117+
if (inc_missing)
118+
return 1;
119+
}
120+
94121
if (!filename) {
95122
std::cout << "Syntax:" << std::endl;
96123
std::cout << "simplecpp [options] filename" << std::endl;

0 commit comments

Comments
 (0)